diff --git a/deploy/test/005_deploy_roles_postage.ts b/deploy/test/005_deploy_roles_postage.ts index 3e0eb25b..e4e89ccf 100644 --- a/deploy/test/005_deploy_roles_postage.ts +++ b/deploy/test/005_deploy_roles_postage.ts @@ -20,6 +20,10 @@ const func: DeployFunction = async function ({ deployments, getNamedAccounts }) ).address ); + // Set default price for postageStamp + const currentPrice = await read('PriceOracle', 'currentPrice'); + await execute('PriceOracle', { from: deployer }, 'setPrice', currentPrice); + log('----------------------------------------------------'); }; diff --git a/deployments/testnet/PriceOracle.json b/deployments/testnet/PriceOracle.json index 6c4466f8..830fff15 100644 --- a/deployments/testnet/PriceOracle.json +++ b/deployments/testnet/PriceOracle.json @@ -1,5 +1,5 @@ { - "address": "0xf19F9d88e963A61c735C1716F8A689Dc2887F463", + "address": "0xC5241172f010AB24ff3eeC61B4c684E1A9482D2b", "abi": [ { "inputs": [ @@ -120,6 +120,19 @@ "name": "RoleRevoked", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "attemptedPrice", + "type": "uint256" + } + ], + "name": "StampPriceUpdateFailed", + "type": "event" + }, { "inputs": [], "name": "DEFAULT_ADMIN_ROLE", @@ -155,7 +168,13 @@ } ], "name": "adjustPrice", - "outputs": [], + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], "stateMutability": "nonpayable", "type": "function" }, @@ -408,7 +427,13 @@ } ], "name": "setPrice", - "outputs": [], + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], "stateMutability": "nonpayable", "type": "function" }, @@ -439,22 +464,22 @@ "type": "function" } ], - "transactionHash": "0x2d90d4ba363f45dd178b1730f7a5c813489af279353760c7486dc2b897d0256d", + "transactionHash": "0xfd15dbd97eb977ecbcbf78a79dbc57fc0ce3306201fbbc8b6ab51329594753e9", "receipt": { "to": null, "from": "0xb1C7F17Ed88189Abf269Bf68A3B2Ed83C5276aAe", - "contractAddress": "0xf19F9d88e963A61c735C1716F8A689Dc2887F463", - "transactionIndex": 55, - "gasUsed": "1218934", - "logsBloom": "0x00000004800000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000800000000010000000000000000002000000000040000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000100000000000020000000000000000000000000000000000000000000000000000000000000000000", - "blockHash": "0xa0587cf1298b8f8d0d742ab5de0509931a56183455470ca59dadb61c5a2d827b", - "transactionHash": "0x2d90d4ba363f45dd178b1730f7a5c813489af279353760c7486dc2b897d0256d", + "contractAddress": "0xC5241172f010AB24ff3eeC61B4c684E1A9482D2b", + "transactionIndex": 83, + "gasUsed": "1307759", + "logsBloom": "0x00000004000000000000000000000000000000000008000000000000000000000400000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000800000000010000000000000000002000000000040000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000400100000000000020000000000000000000000000000000000000000000000000000000000000000000", + "blockHash": "0xa0768ad24dde065516bb89fc6fac5a3f14a4dcbb3783b6db02b2516a5ecf520a", + "transactionHash": "0xfd15dbd97eb977ecbcbf78a79dbc57fc0ce3306201fbbc8b6ab51329594753e9", "logs": [ { - "transactionIndex": 55, - "blockNumber": 6596284, - "transactionHash": "0x2d90d4ba363f45dd178b1730f7a5c813489af279353760c7486dc2b897d0256d", - "address": "0xf19F9d88e963A61c735C1716F8A689Dc2887F463", + "transactionIndex": 83, + "blockNumber": 7036312, + "transactionHash": "0xfd15dbd97eb977ecbcbf78a79dbc57fc0ce3306201fbbc8b6ab51329594753e9", + "address": "0xC5241172f010AB24ff3eeC61B4c684E1A9482D2b", "topics": [ "0x2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d", "0x0000000000000000000000000000000000000000000000000000000000000000", @@ -462,23 +487,35 @@ "0x000000000000000000000000b1c7f17ed88189abf269bf68a3b2ed83c5276aae" ], "data": "0x", - "logIndex": 51, - "blockHash": "0xa0587cf1298b8f8d0d742ab5de0509931a56183455470ca59dadb61c5a2d827b" + "logIndex": 187, + "blockHash": "0xa0768ad24dde065516bb89fc6fac5a3f14a4dcbb3783b6db02b2516a5ecf520a" + }, + { + "transactionIndex": 83, + "blockNumber": 7036312, + "transactionHash": "0xfd15dbd97eb977ecbcbf78a79dbc57fc0ce3306201fbbc8b6ab51329594753e9", + "address": "0xC5241172f010AB24ff3eeC61B4c684E1A9482D2b", + "topics": [ + "0xae46785019700e30375a5d7b4f91e32f8060ef085111f896ebf889450aa2ab5a" + ], + "data": "0x0000000000000000000000000000000000000000000000000000000000005dc0", + "logIndex": 188, + "blockHash": "0xa0768ad24dde065516bb89fc6fac5a3f14a4dcbb3783b6db02b2516a5ecf520a" } ], - "blockNumber": 6596284, - "cumulativeGasUsed": "9864687", + "blockNumber": 7036312, + "cumulativeGasUsed": "27320843", "status": 1, "byzantium": true }, "args": [ "0xcdfdC3752caaA826fE62531E0000C40546eC56A6" ], - "numDeployments": 2, - "solcInputHash": "c39ceb5ddfc36744a77362b8ce122638", - "metadata": "{\"compiler\":{\"version\":\"0.8.19+commit.7dd6d404\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_postageStamp\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[],\"name\":\"CallerNotAdmin\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"CallerNotPriceUpdater\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"PriceAlreadyAdjusted\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"UnexpectedZero\",\"type\":\"error\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"price\",\"type\":\"uint256\"}],\"name\":\"PriceUpdate\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"previousAdminRole\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"newAdminRole\",\"type\":\"bytes32\"}],\"name\":\"RoleAdminChanged\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"}],\"name\":\"RoleGranted\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"}],\"name\":\"RoleRevoked\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"DEFAULT_ADMIN_ROLE\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"PRICE_UPDATER_ROLE\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"redundancy\",\"type\":\"uint16\"}],\"name\":\"adjustPrice\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"changeRate\",\"outputs\":[{\"internalType\":\"uint32\",\"name\":\"\",\"type\":\"uint32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentPrice\",\"outputs\":[{\"internalType\":\"uint32\",\"name\":\"\",\"type\":\"uint32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentPriceUpScaled\",\"outputs\":[{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentRound\",\"outputs\":[{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"}],\"name\":\"getRoleAdmin\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"grantRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"hasRole\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"isPaused\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"lastAdjustedRound\",\"outputs\":[{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"minimumPrice\",\"outputs\":[{\"internalType\":\"uint32\",\"name\":\"\",\"type\":\"uint32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"minimumPriceUpscaled\",\"outputs\":[{\"internalType\":\"uint32\",\"name\":\"\",\"type\":\"uint32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"pause\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"postageStamp\",\"outputs\":[{\"internalType\":\"contract IPostageStamp\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"priceBase\",\"outputs\":[{\"internalType\":\"uint32\",\"name\":\"\",\"type\":\"uint32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"renounceRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"revokeRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"_price\",\"type\":\"uint32\"}],\"name\":\"setPrice\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes4\",\"name\":\"interfaceId\",\"type\":\"bytes4\"}],\"name\":\"supportsInterface\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"unPause\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}],\"devdoc\":{\"author\":\"The Swarm Authors.\",\"details\":\"The price oracle contract emits a price feed using events.\",\"events\":{\"PriceUpdate(uint256)\":{\"details\":\"Emitted on every price update.\"},\"RoleAdminChanged(bytes32,bytes32,bytes32)\":{\"details\":\"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._\"},\"RoleGranted(bytes32,address,address)\":{\"details\":\"Emitted when `account` is granted `role`. `sender` is the account that originated the contract call, an admin role bearer except when using {AccessControl-_setupRole}.\"},\"RoleRevoked(bytes32,address,address)\":{\"details\":\"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`)\"}},\"kind\":\"dev\",\"methods\":{\"getRoleAdmin(bytes32)\":{\"details\":\"Returns the admin role that controls `role`. See {grantRole} and {revokeRole}. To change a role's admin, use {_setRoleAdmin}.\"},\"grantRole(bytes32,address)\":{\"details\":\"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.\"},\"hasRole(bytes32,address)\":{\"details\":\"Returns `true` if `account` has been granted `role`.\"},\"renounceRole(bytes32,address)\":{\"details\":\"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.\"},\"revokeRole(bytes32,address)\":{\"details\":\"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.\"},\"setPrice(uint32)\":{\"details\":\"Can only be called by the admin role.\",\"params\":{\"_price\":\"The new price.\"}},\"supportsInterface(bytes4)\":{\"details\":\"See {IERC165-supportsInterface}.\"}},\"title\":\"PriceOracle contract.\",\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{\"currentPrice()\":{\"notice\":\"Return the price downscaled\"},\"currentRound()\":{\"notice\":\"Return the number of the current round.\"},\"minimumPrice()\":{\"notice\":\"Return the price downscaled\"},\"setPrice(uint32)\":{\"notice\":\"Manually set the price.\"}},\"version\":1}},\"settings\":{\"compilationTarget\":{\"src/PriceOracle.sol\":\"PriceOracle\"},\"evmVersion\":\"paris\",\"libraries\":{\":__CACHE_BREAKER__\":\"0x00000000d41867734bbee4c6863d9255b2b06ac1\"},\"metadata\":{\"bytecodeHash\":\"ipfs\",\"useLiteralContent\":true},\"optimizer\":{\"enabled\":true,\"runs\":1000},\"remappings\":[]},\"sources\":{\"@openzeppelin/contracts/access/AccessControl.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (access/AccessControl.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./IAccessControl.sol\\\";\\nimport \\\"../utils/Context.sol\\\";\\nimport \\\"../utils/Strings.sol\\\";\\nimport \\\"../utils/introspection/ERC165.sol\\\";\\n\\n/**\\n * @dev Contract module that allows children to implement role-based access\\n * control mechanisms. This is a lightweight version that doesn't allow enumerating role\\n * members except through off-chain means by accessing the contract event logs. Some\\n * applications may benefit from on-chain enumerability, for those cases see\\n * {AccessControlEnumerable}.\\n *\\n * Roles are referred to by their `bytes32` identifier. These should be exposed\\n * in the external API and be unique. The best way to achieve this is by\\n * using `public constant` hash digests:\\n *\\n * ```\\n * bytes32 public constant MY_ROLE = keccak256(\\\"MY_ROLE\\\");\\n * ```\\n *\\n * Roles can be used to represent a set of permissions. To restrict access to a\\n * function call, use {hasRole}:\\n *\\n * ```\\n * function foo() public {\\n * require(hasRole(MY_ROLE, msg.sender));\\n * ...\\n * }\\n * ```\\n *\\n * Roles can be granted and revoked dynamically via the {grantRole} and\\n * {revokeRole} functions. Each role has an associated admin role, and only\\n * accounts that have a role's admin role can call {grantRole} and {revokeRole}.\\n *\\n * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means\\n * that only accounts with this role will be able to grant or revoke other\\n * roles. More complex role relationships can be created by using\\n * {_setRoleAdmin}.\\n *\\n * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to\\n * grant and revoke this role. Extra precautions should be taken to secure\\n * accounts that have been granted it.\\n */\\nabstract contract AccessControl is Context, IAccessControl, ERC165 {\\n struct RoleData {\\n mapping(address => bool) members;\\n bytes32 adminRole;\\n }\\n\\n mapping(bytes32 => RoleData) private _roles;\\n\\n bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;\\n\\n /**\\n * @dev Modifier that checks that an account has a specific role. Reverts\\n * with a standardized message including the required role.\\n *\\n * The format of the revert reason is given by the following regular expression:\\n *\\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\\n *\\n * _Available since v4.1._\\n */\\n modifier onlyRole(bytes32 role) {\\n _checkRole(role);\\n _;\\n }\\n\\n /**\\n * @dev See {IERC165-supportsInterface}.\\n */\\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);\\n }\\n\\n /**\\n * @dev Returns `true` if `account` has been granted `role`.\\n */\\n function hasRole(bytes32 role, address account) public view virtual override returns (bool) {\\n return _roles[role].members[account];\\n }\\n\\n /**\\n * @dev Revert with a standard message if `_msgSender()` is missing `role`.\\n * Overriding this function changes the behavior of the {onlyRole} modifier.\\n *\\n * Format of the revert message is described in {_checkRole}.\\n *\\n * _Available since v4.6._\\n */\\n function _checkRole(bytes32 role) internal view virtual {\\n _checkRole(role, _msgSender());\\n }\\n\\n /**\\n * @dev Revert with a standard message if `account` is missing `role`.\\n *\\n * The format of the revert reason is given by the following regular expression:\\n *\\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\\n */\\n function _checkRole(bytes32 role, address account) internal view virtual {\\n if (!hasRole(role, account)) {\\n revert(\\n string(\\n abi.encodePacked(\\n \\\"AccessControl: account \\\",\\n Strings.toHexString(account),\\n \\\" is missing role \\\",\\n Strings.toHexString(uint256(role), 32)\\n )\\n )\\n );\\n }\\n }\\n\\n /**\\n * @dev Returns the admin role that controls `role`. See {grantRole} and\\n * {revokeRole}.\\n *\\n * To change a role's admin, use {_setRoleAdmin}.\\n */\\n function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {\\n return _roles[role].adminRole;\\n }\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * If `account` had not been already granted `role`, emits a {RoleGranted}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n *\\n * May emit a {RoleGranted} event.\\n */\\n function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\\n _grantRole(role, account);\\n }\\n\\n /**\\n * @dev Revokes `role` from `account`.\\n *\\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n *\\n * May emit a {RoleRevoked} event.\\n */\\n function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\\n _revokeRole(role, account);\\n }\\n\\n /**\\n * @dev Revokes `role` from the calling account.\\n *\\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\\n * purpose is to provide a mechanism for accounts to lose their privileges\\n * if they are compromised (such as when a trusted device is misplaced).\\n *\\n * If the calling account had been revoked `role`, emits a {RoleRevoked}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must be `account`.\\n *\\n * May emit a {RoleRevoked} event.\\n */\\n function renounceRole(bytes32 role, address account) public virtual override {\\n require(account == _msgSender(), \\\"AccessControl: can only renounce roles for self\\\");\\n\\n _revokeRole(role, account);\\n }\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * If `account` had not been already granted `role`, emits a {RoleGranted}\\n * event. Note that unlike {grantRole}, this function doesn't perform any\\n * checks on the calling account.\\n *\\n * May emit a {RoleGranted} event.\\n *\\n * [WARNING]\\n * ====\\n * This function should only be called from the constructor when setting\\n * up the initial roles for the system.\\n *\\n * Using this function in any other way is effectively circumventing the admin\\n * system imposed by {AccessControl}.\\n * ====\\n *\\n * NOTE: This function is deprecated in favor of {_grantRole}.\\n */\\n function _setupRole(bytes32 role, address account) internal virtual {\\n _grantRole(role, account);\\n }\\n\\n /**\\n * @dev Sets `adminRole` as ``role``'s admin role.\\n *\\n * Emits a {RoleAdminChanged} event.\\n */\\n function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {\\n bytes32 previousAdminRole = getRoleAdmin(role);\\n _roles[role].adminRole = adminRole;\\n emit RoleAdminChanged(role, previousAdminRole, adminRole);\\n }\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * Internal function without access restriction.\\n *\\n * May emit a {RoleGranted} event.\\n */\\n function _grantRole(bytes32 role, address account) internal virtual {\\n if (!hasRole(role, account)) {\\n _roles[role].members[account] = true;\\n emit RoleGranted(role, account, _msgSender());\\n }\\n }\\n\\n /**\\n * @dev Revokes `role` from `account`.\\n *\\n * Internal function without access restriction.\\n *\\n * May emit a {RoleRevoked} event.\\n */\\n function _revokeRole(bytes32 role, address account) internal virtual {\\n if (hasRole(role, account)) {\\n _roles[role].members[account] = false;\\n emit RoleRevoked(role, account, _msgSender());\\n }\\n }\\n}\\n\",\"keccak256\":\"0x67e3daf189111d6d5b0464ed09cf9f0605a22c4b965a7fcecd707101faff008a\",\"license\":\"MIT\"},\"@openzeppelin/contracts/access/IAccessControl.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev External interface of AccessControl declared to support ERC165 detection.\\n */\\ninterface IAccessControl {\\n /**\\n * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`\\n *\\n * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite\\n * {RoleAdminChanged} not being emitted signaling this.\\n *\\n * _Available since v3.1._\\n */\\n event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);\\n\\n /**\\n * @dev Emitted when `account` is granted `role`.\\n *\\n * `sender` is the account that originated the contract call, an admin role\\n * bearer except when using {AccessControl-_setupRole}.\\n */\\n event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);\\n\\n /**\\n * @dev Emitted when `account` is revoked `role`.\\n *\\n * `sender` is the account that originated the contract call:\\n * - if using `revokeRole`, it is the admin role bearer\\n * - if using `renounceRole`, it is the role bearer (i.e. `account`)\\n */\\n event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);\\n\\n /**\\n * @dev Returns `true` if `account` has been granted `role`.\\n */\\n function hasRole(bytes32 role, address account) external view returns (bool);\\n\\n /**\\n * @dev Returns the admin role that controls `role`. See {grantRole} and\\n * {revokeRole}.\\n *\\n * To change a role's admin, use {AccessControl-_setRoleAdmin}.\\n */\\n function getRoleAdmin(bytes32 role) external view returns (bytes32);\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * If `account` had not been already granted `role`, emits a {RoleGranted}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n */\\n function grantRole(bytes32 role, address account) external;\\n\\n /**\\n * @dev Revokes `role` from `account`.\\n *\\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n */\\n function revokeRole(bytes32 role, address account) external;\\n\\n /**\\n * @dev Revokes `role` from the calling account.\\n *\\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\\n * purpose is to provide a mechanism for accounts to lose their privileges\\n * if they are compromised (such as when a trusted device is misplaced).\\n *\\n * If the calling account had been granted `role`, emits a {RoleRevoked}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must be `account`.\\n */\\n function renounceRole(bytes32 role, address account) external;\\n}\\n\",\"keccak256\":\"0x59ce320a585d7e1f163cd70390a0ef2ff9cec832e2aa544293a00692465a7a57\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/Context.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Provides information about the current execution context, including the\\n * sender of the transaction and its data. While these are generally available\\n * via msg.sender and msg.data, they should not be accessed in such a direct\\n * manner, since when dealing with meta-transactions the account sending and\\n * paying for execution may not be the actual sender (as far as an application\\n * is concerned).\\n *\\n * This contract is only required for intermediate, library-like contracts.\\n */\\nabstract contract Context {\\n function _msgSender() internal view virtual returns (address) {\\n return msg.sender;\\n }\\n\\n function _msgData() internal view virtual returns (bytes calldata) {\\n return msg.data;\\n }\\n}\\n\",\"keccak256\":\"0xe2e337e6dde9ef6b680e07338c493ebea1b5fd09b43424112868e9cc1706bca7\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/Strings.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./math/Math.sol\\\";\\n\\n/**\\n * @dev String operations.\\n */\\nlibrary Strings {\\n bytes16 private constant _SYMBOLS = \\\"0123456789abcdef\\\";\\n uint8 private constant _ADDRESS_LENGTH = 20;\\n\\n /**\\n * @dev Converts a `uint256` to its ASCII `string` decimal representation.\\n */\\n function toString(uint256 value) internal pure returns (string memory) {\\n unchecked {\\n uint256 length = Math.log10(value) + 1;\\n string memory buffer = new string(length);\\n uint256 ptr;\\n /// @solidity memory-safe-assembly\\n assembly {\\n ptr := add(buffer, add(32, length))\\n }\\n while (true) {\\n ptr--;\\n /// @solidity memory-safe-assembly\\n assembly {\\n mstore8(ptr, byte(mod(value, 10), _SYMBOLS))\\n }\\n value /= 10;\\n if (value == 0) break;\\n }\\n return buffer;\\n }\\n }\\n\\n /**\\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\\n */\\n function toHexString(uint256 value) internal pure returns (string memory) {\\n unchecked {\\n return toHexString(value, Math.log256(value) + 1);\\n }\\n }\\n\\n /**\\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\\n */\\n function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\\n bytes memory buffer = new bytes(2 * length + 2);\\n buffer[0] = \\\"0\\\";\\n buffer[1] = \\\"x\\\";\\n for (uint256 i = 2 * length + 1; i > 1; --i) {\\n buffer[i] = _SYMBOLS[value & 0xf];\\n value >>= 4;\\n }\\n require(value == 0, \\\"Strings: hex length insufficient\\\");\\n return string(buffer);\\n }\\n\\n /**\\n * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.\\n */\\n function toHexString(address addr) internal pure returns (string memory) {\\n return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);\\n }\\n}\\n\",\"keccak256\":\"0xa4d1d62251f8574deb032a35fc948386a9b4de74b812d4f545a1ac120486b48a\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/introspection/ERC165.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./IERC165.sol\\\";\\n\\n/**\\n * @dev Implementation of the {IERC165} interface.\\n *\\n * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check\\n * for the additional interface id that will be supported. For example:\\n *\\n * ```solidity\\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\\n * }\\n * ```\\n *\\n * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.\\n */\\nabstract contract ERC165 is IERC165 {\\n /**\\n * @dev See {IERC165-supportsInterface}.\\n */\\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n return interfaceId == type(IERC165).interfaceId;\\n }\\n}\\n\",\"keccak256\":\"0xd10975de010d89fd1c78dc5e8a9a7e7f496198085c151648f20cba166b32582b\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/introspection/IERC165.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Interface of the ERC165 standard, as defined in the\\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\\n *\\n * Implementers can declare support of contract interfaces, which can then be\\n * queried by others ({ERC165Checker}).\\n *\\n * For an implementation, see {ERC165}.\\n */\\ninterface IERC165 {\\n /**\\n * @dev Returns true if this contract implements the interface defined by\\n * `interfaceId`. See the corresponding\\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\\n * to learn more about how these ids are created.\\n *\\n * This function call must use less than 30 000 gas.\\n */\\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\\n}\\n\",\"keccak256\":\"0x447a5f3ddc18419d41ff92b3773fb86471b1db25773e07f877f548918a185bf1\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/math/Math.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Standard math utilities missing in the Solidity language.\\n */\\nlibrary Math {\\n enum Rounding {\\n Down, // Toward negative infinity\\n Up, // Toward infinity\\n Zero // Toward zero\\n }\\n\\n /**\\n * @dev Returns the largest of two numbers.\\n */\\n function max(uint256 a, uint256 b) internal pure returns (uint256) {\\n return a > b ? a : b;\\n }\\n\\n /**\\n * @dev Returns the smallest of two numbers.\\n */\\n function min(uint256 a, uint256 b) internal pure returns (uint256) {\\n return a < b ? a : b;\\n }\\n\\n /**\\n * @dev Returns the average of two numbers. The result is rounded towards\\n * zero.\\n */\\n function average(uint256 a, uint256 b) internal pure returns (uint256) {\\n // (a + b) / 2 can overflow.\\n return (a & b) + (a ^ b) / 2;\\n }\\n\\n /**\\n * @dev Returns the ceiling of the division of two numbers.\\n *\\n * This differs from standard division with `/` in that it rounds up instead\\n * of rounding down.\\n */\\n function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {\\n // (a + b - 1) / b can overflow on addition, so we distribute.\\n return a == 0 ? 0 : (a - 1) / b + 1;\\n }\\n\\n /**\\n * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0\\n * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)\\n * with further edits by Uniswap Labs also under MIT license.\\n */\\n function mulDiv(\\n uint256 x,\\n uint256 y,\\n uint256 denominator\\n ) internal pure returns (uint256 result) {\\n unchecked {\\n // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use\\n // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256\\n // variables such that product = prod1 * 2^256 + prod0.\\n uint256 prod0; // Least significant 256 bits of the product\\n uint256 prod1; // Most significant 256 bits of the product\\n assembly {\\n let mm := mulmod(x, y, not(0))\\n prod0 := mul(x, y)\\n prod1 := sub(sub(mm, prod0), lt(mm, prod0))\\n }\\n\\n // Handle non-overflow cases, 256 by 256 division.\\n if (prod1 == 0) {\\n return prod0 / denominator;\\n }\\n\\n // Make sure the result is less than 2^256. Also prevents denominator == 0.\\n require(denominator > prod1);\\n\\n ///////////////////////////////////////////////\\n // 512 by 256 division.\\n ///////////////////////////////////////////////\\n\\n // Make division exact by subtracting the remainder from [prod1 prod0].\\n uint256 remainder;\\n assembly {\\n // Compute remainder using mulmod.\\n remainder := mulmod(x, y, denominator)\\n\\n // Subtract 256 bit number from 512 bit number.\\n prod1 := sub(prod1, gt(remainder, prod0))\\n prod0 := sub(prod0, remainder)\\n }\\n\\n // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.\\n // See https://cs.stackexchange.com/q/138556/92363.\\n\\n // Does not overflow because the denominator cannot be zero at this stage in the function.\\n uint256 twos = denominator & (~denominator + 1);\\n assembly {\\n // Divide denominator by twos.\\n denominator := div(denominator, twos)\\n\\n // Divide [prod1 prod0] by twos.\\n prod0 := div(prod0, twos)\\n\\n // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.\\n twos := add(div(sub(0, twos), twos), 1)\\n }\\n\\n // Shift in bits from prod1 into prod0.\\n prod0 |= prod1 * twos;\\n\\n // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such\\n // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for\\n // four bits. That is, denominator * inv = 1 mod 2^4.\\n uint256 inverse = (3 * denominator) ^ 2;\\n\\n // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works\\n // in modular arithmetic, doubling the correct bits in each step.\\n inverse *= 2 - denominator * inverse; // inverse mod 2^8\\n inverse *= 2 - denominator * inverse; // inverse mod 2^16\\n inverse *= 2 - denominator * inverse; // inverse mod 2^32\\n inverse *= 2 - denominator * inverse; // inverse mod 2^64\\n inverse *= 2 - denominator * inverse; // inverse mod 2^128\\n inverse *= 2 - denominator * inverse; // inverse mod 2^256\\n\\n // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.\\n // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is\\n // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1\\n // is no longer required.\\n result = prod0 * inverse;\\n return result;\\n }\\n }\\n\\n /**\\n * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.\\n */\\n function mulDiv(\\n uint256 x,\\n uint256 y,\\n uint256 denominator,\\n Rounding rounding\\n ) internal pure returns (uint256) {\\n uint256 result = mulDiv(x, y, denominator);\\n if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {\\n result += 1;\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.\\n *\\n * Inspired by Henry S. Warren, Jr.'s \\\"Hacker's Delight\\\" (Chapter 11).\\n */\\n function sqrt(uint256 a) internal pure returns (uint256) {\\n if (a == 0) {\\n return 0;\\n }\\n\\n // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.\\n //\\n // We know that the \\\"msb\\\" (most significant bit) of our target number `a` is a power of 2 such that we have\\n // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.\\n //\\n // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`\\n // \\u2192 `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`\\n // \\u2192 `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`\\n //\\n // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.\\n uint256 result = 1 << (log2(a) >> 1);\\n\\n // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,\\n // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at\\n // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision\\n // into the expected uint128 result.\\n unchecked {\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n return min(result, a / result);\\n }\\n }\\n\\n /**\\n * @notice Calculates sqrt(a), following the selected rounding direction.\\n */\\n function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = sqrt(a);\\n return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);\\n }\\n }\\n\\n /**\\n * @dev Return the log in base 2, rounded down, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log2(uint256 value) internal pure returns (uint256) {\\n uint256 result = 0;\\n unchecked {\\n if (value >> 128 > 0) {\\n value >>= 128;\\n result += 128;\\n }\\n if (value >> 64 > 0) {\\n value >>= 64;\\n result += 64;\\n }\\n if (value >> 32 > 0) {\\n value >>= 32;\\n result += 32;\\n }\\n if (value >> 16 > 0) {\\n value >>= 16;\\n result += 16;\\n }\\n if (value >> 8 > 0) {\\n value >>= 8;\\n result += 8;\\n }\\n if (value >> 4 > 0) {\\n value >>= 4;\\n result += 4;\\n }\\n if (value >> 2 > 0) {\\n value >>= 2;\\n result += 2;\\n }\\n if (value >> 1 > 0) {\\n result += 1;\\n }\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Return the log in base 2, following the selected rounding direction, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = log2(value);\\n return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);\\n }\\n }\\n\\n /**\\n * @dev Return the log in base 10, rounded down, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log10(uint256 value) internal pure returns (uint256) {\\n uint256 result = 0;\\n unchecked {\\n if (value >= 10**64) {\\n value /= 10**64;\\n result += 64;\\n }\\n if (value >= 10**32) {\\n value /= 10**32;\\n result += 32;\\n }\\n if (value >= 10**16) {\\n value /= 10**16;\\n result += 16;\\n }\\n if (value >= 10**8) {\\n value /= 10**8;\\n result += 8;\\n }\\n if (value >= 10**4) {\\n value /= 10**4;\\n result += 4;\\n }\\n if (value >= 10**2) {\\n value /= 10**2;\\n result += 2;\\n }\\n if (value >= 10**1) {\\n result += 1;\\n }\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = log10(value);\\n return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);\\n }\\n }\\n\\n /**\\n * @dev Return the log in base 256, rounded down, of a positive value.\\n * Returns 0 if given 0.\\n *\\n * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.\\n */\\n function log256(uint256 value) internal pure returns (uint256) {\\n uint256 result = 0;\\n unchecked {\\n if (value >> 128 > 0) {\\n value >>= 128;\\n result += 16;\\n }\\n if (value >> 64 > 0) {\\n value >>= 64;\\n result += 8;\\n }\\n if (value >> 32 > 0) {\\n value >>= 32;\\n result += 4;\\n }\\n if (value >> 16 > 0) {\\n value >>= 16;\\n result += 2;\\n }\\n if (value >> 8 > 0) {\\n result += 1;\\n }\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = log256(value);\\n return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);\\n }\\n }\\n}\\n\",\"keccak256\":\"0xa1e8e83cd0087785df04ac79fb395d9f3684caeaf973d9e2c71caef723a3a5d6\",\"license\":\"MIT\"},\"src/PriceOracle.sol\":{\"content\":\"// SPDX-License-Identifier: BSD-3-Clause\\npragma solidity ^0.8.19;\\nimport \\\"@openzeppelin/contracts/access/AccessControl.sol\\\";\\nimport \\\"./interface/IPostageStamp.sol\\\";\\n\\n/**\\n * @title PriceOracle contract.\\n * @author The Swarm Authors.\\n * @dev The price oracle contract emits a price feed using events.\\n */\\n\\ncontract PriceOracle is AccessControl {\\n // ----------------------------- State variables ------------------------------\\n\\n // The address of the linked PostageStamp contract\\n IPostageStamp public postageStamp;\\n\\n uint16 targetRedundancy = 4;\\n uint16 maxConsideredExtraRedundancy = 4;\\n\\n // When the contract is paused, price changes are not effective\\n bool public isPaused = false;\\n\\n // The number of the last round price adjusting happend\\n uint64 public lastAdjustedRound;\\n\\n // The minimum price allowed\\n uint32 public minimumPriceUpscaled = 24000 << 10; // we upscale it by 2^10\\n\\n // The priceBase to modulate the price\\n uint32 public priceBase = 524288;\\n\\n uint64 public currentPriceUpScaled = minimumPriceUpscaled;\\n\\n // Constants used to modulate the price, see below usage\\n uint32[9] public changeRate = [524324, 524315, 524306, 524297, 524288, 524279, 524270, 524261, 524252];\\n\\n // Role allowed to update price\\n bytes32 public immutable PRICE_UPDATER_ROLE;\\n\\n // The length of a round in blocks.\\n uint8 private constant ROUND_LENGTH = 152;\\n\\n // ----------------------------- Events ------------------------------\\n\\n /**\\n *@dev Emitted on every price update.\\n */\\n event PriceUpdate(uint256 price);\\n\\n // ----------------------------- Custom Errors ------------------------------\\n error CallerNotAdmin(); // Caller is not the admin\\n error CallerNotPriceUpdater(); // Caller is not a price updater\\n error PriceAlreadyAdjusted(); // Price already adjusted in this round\\n error UnexpectedZero(); // Redundancy needs to be higher then 0\\n\\n // ----------------------------- CONSTRUCTOR ------------------------------\\n\\n constructor(address _postageStamp) {\\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\\n postageStamp = IPostageStamp(_postageStamp);\\n lastAdjustedRound = currentRound();\\n PRICE_UPDATER_ROLE = keccak256(\\\"PRICE_UPDATER_ROLE\\\");\\n }\\n\\n ////////////////////////////////////////\\n // STATE SETTING //\\n ////////////////////////////////////////\\n\\n /**\\n * @notice Manually set the price.\\n * @dev Can only be called by the admin role.\\n * @param _price The new price.\\n */ function setPrice(uint32 _price) external {\\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\\n revert CallerNotAdmin();\\n }\\n\\n uint64 _currentPriceUpScaled = _price << 10;\\n uint64 _minimumPriceUpscaled = minimumPriceUpscaled;\\n\\n // Enforce minimum price\\n if (_currentPriceUpScaled < _minimumPriceUpscaled) {\\n _currentPriceUpScaled = _minimumPriceUpscaled;\\n }\\n currentPriceUpScaled = _currentPriceUpScaled;\\n\\n // Price in postagestamp is set at 256 so we need to upcast it\\n postageStamp.setPrice(uint256(currentPrice()));\\n emit PriceUpdate(currentPrice());\\n }\\n\\n function adjustPrice(uint16 redundancy) external {\\n if (isPaused == false) {\\n if (!hasRole(PRICE_UPDATER_ROLE, msg.sender)) {\\n revert CallerNotPriceUpdater();\\n }\\n\\n uint16 usedRedundancy = redundancy;\\n uint64 currentRoundNumber = currentRound();\\n\\n // Price can only be adjusted once per round\\n if (currentRoundNumber <= lastAdjustedRound) {\\n revert PriceAlreadyAdjusted();\\n }\\n // Redundancy may not be zero\\n if (redundancy == 0) {\\n revert UnexpectedZero();\\n }\\n\\n // Enforce maximum considered extra redundancy\\n uint16 maxConsideredRedundancy = targetRedundancy + maxConsideredExtraRedundancy;\\n if (redundancy > maxConsideredRedundancy) {\\n usedRedundancy = maxConsideredRedundancy;\\n }\\n\\n uint64 _currentPriceUpScaled = currentPriceUpScaled;\\n uint64 _minimumPriceUpscaled = minimumPriceUpscaled;\\n uint32 _priceBase = priceBase;\\n\\n // Set the number of rounds that were skipped\\n uint64 skippedRounds = currentRoundNumber - lastAdjustedRound - 1;\\n\\n // We first apply the increase/decrease rate for the current round\\n uint32 _changeRate = changeRate[usedRedundancy];\\n _currentPriceUpScaled = (_changeRate * _currentPriceUpScaled) / _priceBase;\\n\\n // If previous rounds were skipped, use MAX price increase for the previous rounds\\n if (skippedRounds > 0) {\\n _changeRate = changeRate[0];\\n for (uint64 i = 0; i < skippedRounds; i++) {\\n _currentPriceUpScaled = (_changeRate * _currentPriceUpScaled) / _priceBase;\\n }\\n }\\n\\n // Enforce minimum price\\n if (_currentPriceUpScaled < _minimumPriceUpscaled) {\\n _currentPriceUpScaled = _minimumPriceUpscaled;\\n }\\n\\n currentPriceUpScaled = _currentPriceUpScaled;\\n lastAdjustedRound = currentRoundNumber;\\n postageStamp.setPrice(uint256(currentPrice()));\\n emit PriceUpdate(currentPrice());\\n }\\n }\\n\\n function pause() external {\\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\\n revert CallerNotAdmin();\\n }\\n isPaused = true;\\n }\\n\\n function unPause() external {\\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\\n revert CallerNotAdmin();\\n }\\n isPaused = false;\\n }\\n\\n ////////////////////////////////////////\\n // STATE READING //\\n ////////////////////////////////////////\\n\\n /**\\n * @notice Return the number of the current round.\\n */\\n function currentRound() public view returns (uint64) {\\n // We downcasted to uint64 as uint64 has 18,446,744,073,709,551,616 places\\n // as each round is 152 x 5 = 760, each day has around 113 rounds which is 41245 in a year\\n // it results 4.4724801e+14 years to run this game\\n return uint64(block.number / uint256(ROUND_LENGTH));\\n }\\n\\n /**\\n * @notice Return the price downscaled\\n */\\n function currentPrice() public view returns (uint32) {\\n // We downcasted to uint32 and bitshift it by 2^10\\n return uint32((currentPriceUpScaled) >> 10);\\n }\\n\\n /**\\n * @notice Return the price downscaled\\n */\\n function minimumPrice() public view returns (uint32) {\\n // We downcasted to uint32 and bitshift it by 2^10\\n return uint32((minimumPriceUpscaled) >> 10);\\n }\\n}\\n\",\"keccak256\":\"0x46220a921dcbac1f300a12aa0c441bbebf340485e9bbd9514163ac600fc1d64d\",\"license\":\"BSD-3-Clause\"},\"src/interface/IPostageStamp.sol\":{\"content\":\"// SPDX-License-Identifier: BSD-3-Clause\\npragma solidity ^0.8.19;\\n\\ninterface IPostageStamp {\\n function withdraw(address beneficiary) external;\\n\\n function validChunkCount() external view returns (uint256);\\n\\n function batchOwner(bytes32 _batchId) external view returns (address);\\n\\n function batchDepth(bytes32 _batchId) external view returns (uint8);\\n\\n function batchBucketDepth(bytes32 _batchId) external view returns (uint8);\\n\\n function remainingBalance(bytes32 _batchId) external view returns (uint256);\\n\\n function minimumInitialBalancePerChunk() external view returns (uint256);\\n\\n function setPrice(uint256 _price) external;\\n\\n function batches(\\n bytes32\\n )\\n external\\n view\\n returns (\\n address owner,\\n uint8 depth,\\n uint8 bucketDepth,\\n bool immutableFlag,\\n uint256 normalisedBalance,\\n uint256 lastUpdatedBlockNumber\\n );\\n}\\n\",\"keccak256\":\"0xc018ff96e75e773e76e6245a930acc3679667250e345415a38196f1e2ad1de76\",\"license\":\"BSD-3-Clause\"}},\"version\":1}", - "bytecode": "0x600180546201000160a21b64ffffffffff60a01b1990911617905560028054600160401b600160c01b0319811663ffffffff68010000000000000000600160401b600160801b03199093166e0800000177000000000000000000009081179390930416600160801b02171790556101c06040526208002460a09081526208001b60c0526208001260e052620800096101005262080000610120526207fff7610140526207ffee610160526207ffe5610180526207ffdc6101a052620000c99060039060096200023b565b50348015620000d757600080fd5b506040516200163438038062001634833981016040819052620000fa91620002f4565b6200010760003362000177565b600180546001600160a01b0319166001600160a01b0383161790556200012c62000187565b600280546001600160401b0319166001600160401b0392909216919091179055507fd96ba01d6560c2ab35f2940dd8d70c5f5fe06236c72674237120515918198fb060805262000349565b6200018382826200019b565b5050565b60006200019660984362000326565b905090565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1662000183576000828152602081815260408083206001600160a01b03851684529091529020805460ff19166001179055620001f73390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b600283019183908215620002cb5791602002820160005b838211156200029757835183826101000a81548163ffffffff021916908362ffffff160217905550926020019260040160208160030104928301926001030262000252565b8015620002c95782816101000a81549063ffffffff021916905560040160208160030104928301926001030262000297565b505b50620002d9929150620002dd565b5090565b5b80821115620002d95760008155600101620002de565b6000602082840312156200030757600080fd5b81516001600160a01b03811681146200031f57600080fd5b9392505050565b6000826200034457634e487b7160e01b600052601260045260246000fd5b500490565b6080516112c86200036c600039600081816103ac015261080d01526112c86000f3fe608060405234801561001057600080fd5b50600436106101825760003560e01c806391d14854116100d8578063daafe0a51161008c578063f7b188a511610066578063f7b188a51461039f578063fb8d8101146103a7578063ffb98fe3146103ce57600080fd5b8063daafe0a514610346578063dcd8ffb814610359578063e0632c641461037457600080fd5b8063a217fddf116100bd578063a217fddf14610317578063b187bd261461031f578063d547741f1461033357600080fd5b806391d14854146102c55780639d1b464a146102fc57600080fd5b80637310561b1161013a5780637f386b6c116101145780637f386b6c146102995780638456cb59146102b55780638a19c8bc146102bd57600080fd5b80637310561b1461023557806374e7493b1461026a5780637e8effdd1461027d57600080fd5b80632f2ff15d1161016b5780632f2ff15d146101e057806336568abe146101f557806355bdcd231461020857600080fd5b806301ffc9a714610187578063248a9ca3146101af575b600080fd5b61019a610195366004610f6f565b6103e1565b60405190151581526020015b60405180910390f35b6101d26101bd366004610fb1565b60009081526020819052604090206001015490565b6040519081526020016101a6565b6101f36101ee366004610fca565b61047a565b005b6101f3610203366004610fca565b6104a4565b60025461021c9067ffffffffffffffff1681565b60405167ffffffffffffffff90911681526020016101a6565b600254610255906c01000000000000000000000000900463ffffffff1681565b60405163ffffffff90911681526020016101a6565b610255610278366004610fb1565b610535565b6002546102559068010000000000000000900463ffffffff1681565b600254680100000000000000009004600a1c623fffff16610255565b6101f3610565565b61021c6105c9565b61019a6102d3366004610fca565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b600254600160801b9004600a1c663fffffffffffff16610255565b6101d2600081565b60015461019a90600160c01b900460ff1681565b6101f3610341366004610fca565b6105db565b6101f3610354366004611006565b610600565b60025461021c90600160801b900467ffffffffffffffff1681565b600154610387906001600160a01b031681565b6040516001600160a01b0390911681526020016101a6565b6101f3610797565b6101d27f000000000000000000000000000000000000000000000000000000000000000081565b6101f36103dc36600461102c565b6107f5565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f7965db0b00000000000000000000000000000000000000000000000000000000148061047457507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008316145b92915050565b60008281526020819052604090206001015461049581610bdb565b61049f8383610be5565b505050565b6001600160a01b03811633146105275760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b6105318282610c83565b5050565b6003816009811061054557600080fd5b60089182820401919006600402915054906101000a900463ffffffff1681565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff166105b45760405163036c8cf960e11b815260040160405180910390fd5b6001805460ff60c01b1916600160c01b179055565b60006105d660984361107c565b905090565b6000828152602081905260409020600101546105f681610bdb565b61049f8383610c83565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff1661064f5760405163036c8cf960e11b815260040160405180910390fd5b60025463fffffc00600a83901b169068010000000000000000900463ffffffff168082101561067c578091505b6002805467ffffffffffffffff8416600160801b027fffffffffffffffff0000000000000000ffffffffffffffffffffffffffffffff9091161790556001546001600160a01b03166391b7f5ed6106e6600254663fffffffffffff600160801b909104600a1c1690565b63ffffffff166040518263ffffffff1660e01b815260040161070a91815260200190565b600060405180830381600087803b15801561072457600080fd5b505af1158015610738573d6000803e3d6000fd5b505050507fae46785019700e30375a5d7b4f91e32f8060ef085111f896ebf889450aa2ab5a61077a600254663fffffffffffff600160801b909104600a1c1690565b60405163ffffffff909116815260200160405180910390a1505050565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff166107e65760405163036c8cf960e11b815260040160405180910390fd5b6001805460ff60c01b19169055565b600154600160c01b900460ff161515600003610bd8577f000000000000000000000000000000000000000000000000000000000000000060009081526020818152604080832033845290915290205460ff1661087d576040517f262791ec00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8060006108886105c9565b60025490915067ffffffffffffffff908116908216116108d4576040517f08a5cb4c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8261ffff16600003610912576040517fb5ca2d7100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60015460009061095a9061ffff760100000000000000000000000000000000000000000000820481169174010000000000000000000000000000000000000000900416611090565b90508061ffff168461ffff161115610970578092505b60025467ffffffffffffffff600160801b820481169163ffffffff6801000000000000000082048116926c010000000000000000000000008304909116916000916001916109bf9116886110b2565b6109c991906110b2565b9050600060038861ffff16600981106109e4576109e46110d3565b60088104919091015460079091166004026101000a900463ffffffff90811691508316610a1186836110e9565b610a1b9190611115565b945067ffffffffffffffff821615610a8f575060035463ffffffff1660005b8267ffffffffffffffff168167ffffffffffffffff161015610a8d578363ffffffff16868363ffffffff16610a6f91906110e9565b610a799190611115565b955080610a858161113c565b915050610a3a565b505b8367ffffffffffffffff168567ffffffffffffffff161015610aaf578394505b600280547fffffffffffffffff0000000000000000ffffffffffffffff000000000000000016600160801b67ffffffffffffffff888116820267ffffffffffffffff191692909217918a1691909117918290556001546001600160a01b0316916391b7f5ed919004600a1c663fffffffffffff1663ffffffff166040518263ffffffff1660e01b8152600401610b4791815260200190565b600060405180830381600087803b158015610b6157600080fd5b505af1158015610b75573d6000803e3d6000fd5b505050507fae46785019700e30375a5d7b4f91e32f8060ef085111f896ebf889450aa2ab5a610bb7600254663fffffffffffff600160801b909104600a1c1690565b60405163ffffffff909116815260200160405180910390a150505050505050505b50565b610bd88133610d02565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610531576000828152602081815260408083206001600160a01b03851684529091529020805460ff19166001179055610c3f3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1615610531576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1661053157610d3381610d75565b610d3e836020610d87565b604051602001610d4f929190611187565b60408051601f198184030181529082905262461bcd60e51b825261051e91600401611208565b60606104746001600160a01b03831660145b60606000610d9683600261123b565b610da1906002611252565b67ffffffffffffffff811115610db957610db9611265565b6040519080825280601f01601f191660200182016040528015610de3576020820181803683370190505b5090507f300000000000000000000000000000000000000000000000000000000000000081600081518110610e1a57610e1a6110d3565b60200101906001600160f81b031916908160001a9053507f780000000000000000000000000000000000000000000000000000000000000081600181518110610e6557610e656110d3565b60200101906001600160f81b031916908160001a9053506000610e8984600261123b565b610e94906001611252565b90505b6001811115610f19577f303132333435363738396162636465660000000000000000000000000000000085600f1660108110610ed557610ed56110d3565b1a60f81b828281518110610eeb57610eeb6110d3565b60200101906001600160f81b031916908160001a90535060049490941c93610f128161127b565b9050610e97565b508315610f685760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e74604482015260640161051e565b9392505050565b600060208284031215610f8157600080fd5b81357fffffffff0000000000000000000000000000000000000000000000000000000081168114610f6857600080fd5b600060208284031215610fc357600080fd5b5035919050565b60008060408385031215610fdd57600080fd5b8235915060208301356001600160a01b0381168114610ffb57600080fd5b809150509250929050565b60006020828403121561101857600080fd5b813563ffffffff81168114610f6857600080fd5b60006020828403121561103e57600080fd5b813561ffff81168114610f6857600080fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b60008261108b5761108b611050565b500490565b61ffff8181168382160190808211156110ab576110ab611066565b5092915050565b67ffffffffffffffff8281168282160390808211156110ab576110ab611066565b634e487b7160e01b600052603260045260246000fd5b67ffffffffffffffff81811683821602808216919082811461110d5761110d611066565b505092915050565b600067ffffffffffffffff8084168061113057611130611050565b92169190910492915050565b600067ffffffffffffffff80831681810361115957611159611066565b6001019392505050565b60005b8381101561117e578181015183820152602001611166565b50506000910152565b7f416363657373436f6e74726f6c3a206163636f756e74200000000000000000008152600083516111bf816017850160208801611163565b7f206973206d697373696e6720726f6c652000000000000000000000000000000060179184019182015283516111fc816028840160208801611163565b01602801949350505050565b6020815260008251806020840152611227816040850160208701611163565b601f01601f19169190910160400192915050565b808202811582820484141761047457610474611066565b8082018082111561047457610474611066565b634e487b7160e01b600052604160045260246000fd5b60008161128a5761128a611066565b50600019019056fea2646970667358221220ae138e65b6afda072afc2642ba44cd4f0dba23acc91686a94131453ad482fce464736f6c63430008130033", - "deployedBytecode": "0x608060405234801561001057600080fd5b50600436106101825760003560e01c806391d14854116100d8578063daafe0a51161008c578063f7b188a511610066578063f7b188a51461039f578063fb8d8101146103a7578063ffb98fe3146103ce57600080fd5b8063daafe0a514610346578063dcd8ffb814610359578063e0632c641461037457600080fd5b8063a217fddf116100bd578063a217fddf14610317578063b187bd261461031f578063d547741f1461033357600080fd5b806391d14854146102c55780639d1b464a146102fc57600080fd5b80637310561b1161013a5780637f386b6c116101145780637f386b6c146102995780638456cb59146102b55780638a19c8bc146102bd57600080fd5b80637310561b1461023557806374e7493b1461026a5780637e8effdd1461027d57600080fd5b80632f2ff15d1161016b5780632f2ff15d146101e057806336568abe146101f557806355bdcd231461020857600080fd5b806301ffc9a714610187578063248a9ca3146101af575b600080fd5b61019a610195366004610f6f565b6103e1565b60405190151581526020015b60405180910390f35b6101d26101bd366004610fb1565b60009081526020819052604090206001015490565b6040519081526020016101a6565b6101f36101ee366004610fca565b61047a565b005b6101f3610203366004610fca565b6104a4565b60025461021c9067ffffffffffffffff1681565b60405167ffffffffffffffff90911681526020016101a6565b600254610255906c01000000000000000000000000900463ffffffff1681565b60405163ffffffff90911681526020016101a6565b610255610278366004610fb1565b610535565b6002546102559068010000000000000000900463ffffffff1681565b600254680100000000000000009004600a1c623fffff16610255565b6101f3610565565b61021c6105c9565b61019a6102d3366004610fca565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b600254600160801b9004600a1c663fffffffffffff16610255565b6101d2600081565b60015461019a90600160c01b900460ff1681565b6101f3610341366004610fca565b6105db565b6101f3610354366004611006565b610600565b60025461021c90600160801b900467ffffffffffffffff1681565b600154610387906001600160a01b031681565b6040516001600160a01b0390911681526020016101a6565b6101f3610797565b6101d27f000000000000000000000000000000000000000000000000000000000000000081565b6101f36103dc36600461102c565b6107f5565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f7965db0b00000000000000000000000000000000000000000000000000000000148061047457507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008316145b92915050565b60008281526020819052604090206001015461049581610bdb565b61049f8383610be5565b505050565b6001600160a01b03811633146105275760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b6105318282610c83565b5050565b6003816009811061054557600080fd5b60089182820401919006600402915054906101000a900463ffffffff1681565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff166105b45760405163036c8cf960e11b815260040160405180910390fd5b6001805460ff60c01b1916600160c01b179055565b60006105d660984361107c565b905090565b6000828152602081905260409020600101546105f681610bdb565b61049f8383610c83565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff1661064f5760405163036c8cf960e11b815260040160405180910390fd5b60025463fffffc00600a83901b169068010000000000000000900463ffffffff168082101561067c578091505b6002805467ffffffffffffffff8416600160801b027fffffffffffffffff0000000000000000ffffffffffffffffffffffffffffffff9091161790556001546001600160a01b03166391b7f5ed6106e6600254663fffffffffffff600160801b909104600a1c1690565b63ffffffff166040518263ffffffff1660e01b815260040161070a91815260200190565b600060405180830381600087803b15801561072457600080fd5b505af1158015610738573d6000803e3d6000fd5b505050507fae46785019700e30375a5d7b4f91e32f8060ef085111f896ebf889450aa2ab5a61077a600254663fffffffffffff600160801b909104600a1c1690565b60405163ffffffff909116815260200160405180910390a1505050565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff166107e65760405163036c8cf960e11b815260040160405180910390fd5b6001805460ff60c01b19169055565b600154600160c01b900460ff161515600003610bd8577f000000000000000000000000000000000000000000000000000000000000000060009081526020818152604080832033845290915290205460ff1661087d576040517f262791ec00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8060006108886105c9565b60025490915067ffffffffffffffff908116908216116108d4576040517f08a5cb4c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8261ffff16600003610912576040517fb5ca2d7100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60015460009061095a9061ffff760100000000000000000000000000000000000000000000820481169174010000000000000000000000000000000000000000900416611090565b90508061ffff168461ffff161115610970578092505b60025467ffffffffffffffff600160801b820481169163ffffffff6801000000000000000082048116926c010000000000000000000000008304909116916000916001916109bf9116886110b2565b6109c991906110b2565b9050600060038861ffff16600981106109e4576109e46110d3565b60088104919091015460079091166004026101000a900463ffffffff90811691508316610a1186836110e9565b610a1b9190611115565b945067ffffffffffffffff821615610a8f575060035463ffffffff1660005b8267ffffffffffffffff168167ffffffffffffffff161015610a8d578363ffffffff16868363ffffffff16610a6f91906110e9565b610a799190611115565b955080610a858161113c565b915050610a3a565b505b8367ffffffffffffffff168567ffffffffffffffff161015610aaf578394505b600280547fffffffffffffffff0000000000000000ffffffffffffffff000000000000000016600160801b67ffffffffffffffff888116820267ffffffffffffffff191692909217918a1691909117918290556001546001600160a01b0316916391b7f5ed919004600a1c663fffffffffffff1663ffffffff166040518263ffffffff1660e01b8152600401610b4791815260200190565b600060405180830381600087803b158015610b6157600080fd5b505af1158015610b75573d6000803e3d6000fd5b505050507fae46785019700e30375a5d7b4f91e32f8060ef085111f896ebf889450aa2ab5a610bb7600254663fffffffffffff600160801b909104600a1c1690565b60405163ffffffff909116815260200160405180910390a150505050505050505b50565b610bd88133610d02565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610531576000828152602081815260408083206001600160a01b03851684529091529020805460ff19166001179055610c3f3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1615610531576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1661053157610d3381610d75565b610d3e836020610d87565b604051602001610d4f929190611187565b60408051601f198184030181529082905262461bcd60e51b825261051e91600401611208565b60606104746001600160a01b03831660145b60606000610d9683600261123b565b610da1906002611252565b67ffffffffffffffff811115610db957610db9611265565b6040519080825280601f01601f191660200182016040528015610de3576020820181803683370190505b5090507f300000000000000000000000000000000000000000000000000000000000000081600081518110610e1a57610e1a6110d3565b60200101906001600160f81b031916908160001a9053507f780000000000000000000000000000000000000000000000000000000000000081600181518110610e6557610e656110d3565b60200101906001600160f81b031916908160001a9053506000610e8984600261123b565b610e94906001611252565b90505b6001811115610f19577f303132333435363738396162636465660000000000000000000000000000000085600f1660108110610ed557610ed56110d3565b1a60f81b828281518110610eeb57610eeb6110d3565b60200101906001600160f81b031916908160001a90535060049490941c93610f128161127b565b9050610e97565b508315610f685760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e74604482015260640161051e565b9392505050565b600060208284031215610f8157600080fd5b81357fffffffff0000000000000000000000000000000000000000000000000000000081168114610f6857600080fd5b600060208284031215610fc357600080fd5b5035919050565b60008060408385031215610fdd57600080fd5b8235915060208301356001600160a01b0381168114610ffb57600080fd5b809150509250929050565b60006020828403121561101857600080fd5b813563ffffffff81168114610f6857600080fd5b60006020828403121561103e57600080fd5b813561ffff81168114610f6857600080fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b60008261108b5761108b611050565b500490565b61ffff8181168382160190808211156110ab576110ab611066565b5092915050565b67ffffffffffffffff8281168282160390808211156110ab576110ab611066565b634e487b7160e01b600052603260045260246000fd5b67ffffffffffffffff81811683821602808216919082811461110d5761110d611066565b505092915050565b600067ffffffffffffffff8084168061113057611130611050565b92169190910492915050565b600067ffffffffffffffff80831681810361115957611159611066565b6001019392505050565b60005b8381101561117e578181015183820152602001611166565b50506000910152565b7f416363657373436f6e74726f6c3a206163636f756e74200000000000000000008152600083516111bf816017850160208801611163565b7f206973206d697373696e6720726f6c652000000000000000000000000000000060179184019182015283516111fc816028840160208801611163565b01602801949350505050565b6020815260008251806020840152611227816040850160208701611163565b601f01601f19169190910160400192915050565b808202811582820484141761047457610474611066565b8082018082111561047457610474611066565b634e487b7160e01b600052604160045260246000fd5b60008161128a5761128a611066565b50600019019056fea2646970667358221220ae138e65b6afda072afc2642ba44cd4f0dba23acc91686a94131453ad482fce464736f6c63430008130033", + "numDeployments": 4, + "solcInputHash": "294e4684ec82046939090fa9e468f317", + "metadata": "{\"compiler\":{\"version\":\"0.8.19+commit.7dd6d404\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_postageStamp\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[],\"name\":\"CallerNotAdmin\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"CallerNotPriceUpdater\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"PriceAlreadyAdjusted\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"UnexpectedZero\",\"type\":\"error\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"price\",\"type\":\"uint256\"}],\"name\":\"PriceUpdate\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"previousAdminRole\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"newAdminRole\",\"type\":\"bytes32\"}],\"name\":\"RoleAdminChanged\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"}],\"name\":\"RoleGranted\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"}],\"name\":\"RoleRevoked\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"attemptedPrice\",\"type\":\"uint256\"}],\"name\":\"StampPriceUpdateFailed\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"DEFAULT_ADMIN_ROLE\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"PRICE_UPDATER_ROLE\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"redundancy\",\"type\":\"uint16\"}],\"name\":\"adjustPrice\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"changeRate\",\"outputs\":[{\"internalType\":\"uint32\",\"name\":\"\",\"type\":\"uint32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentPrice\",\"outputs\":[{\"internalType\":\"uint32\",\"name\":\"\",\"type\":\"uint32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentPriceUpScaled\",\"outputs\":[{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentRound\",\"outputs\":[{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"}],\"name\":\"getRoleAdmin\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"grantRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"hasRole\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"isPaused\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"lastAdjustedRound\",\"outputs\":[{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"minimumPrice\",\"outputs\":[{\"internalType\":\"uint32\",\"name\":\"\",\"type\":\"uint32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"minimumPriceUpscaled\",\"outputs\":[{\"internalType\":\"uint32\",\"name\":\"\",\"type\":\"uint32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"pause\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"postageStamp\",\"outputs\":[{\"internalType\":\"contract IPostageStamp\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"priceBase\",\"outputs\":[{\"internalType\":\"uint32\",\"name\":\"\",\"type\":\"uint32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"renounceRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"revokeRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"_price\",\"type\":\"uint32\"}],\"name\":\"setPrice\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes4\",\"name\":\"interfaceId\",\"type\":\"bytes4\"}],\"name\":\"supportsInterface\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"unPause\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}],\"devdoc\":{\"author\":\"The Swarm Authors.\",\"details\":\"The price oracle contract emits a price feed using events.\",\"events\":{\"PriceUpdate(uint256)\":{\"details\":\"Emitted on every price update.\"},\"RoleAdminChanged(bytes32,bytes32,bytes32)\":{\"details\":\"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._\"},\"RoleGranted(bytes32,address,address)\":{\"details\":\"Emitted when `account` is granted `role`. `sender` is the account that originated the contract call, an admin role bearer except when using {AccessControl-_setupRole}.\"},\"RoleRevoked(bytes32,address,address)\":{\"details\":\"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`)\"}},\"kind\":\"dev\",\"methods\":{\"getRoleAdmin(bytes32)\":{\"details\":\"Returns the admin role that controls `role`. See {grantRole} and {revokeRole}. To change a role's admin, use {_setRoleAdmin}.\"},\"grantRole(bytes32,address)\":{\"details\":\"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.\"},\"hasRole(bytes32,address)\":{\"details\":\"Returns `true` if `account` has been granted `role`.\"},\"renounceRole(bytes32,address)\":{\"details\":\"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.\"},\"revokeRole(bytes32,address)\":{\"details\":\"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.\"},\"setPrice(uint32)\":{\"details\":\"Can only be called by the admin role.\",\"params\":{\"_price\":\"The new price.\"}},\"supportsInterface(bytes4)\":{\"details\":\"See {IERC165-supportsInterface}.\"}},\"title\":\"PriceOracle contract.\",\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{\"currentPrice()\":{\"notice\":\"Return the price downscaled\"},\"currentRound()\":{\"notice\":\"Return the number of the current round.\"},\"minimumPrice()\":{\"notice\":\"Return the price downscaled\"},\"setPrice(uint32)\":{\"notice\":\"Manually set the price.\"}},\"version\":1}},\"settings\":{\"compilationTarget\":{\"src/PriceOracle.sol\":\"PriceOracle\"},\"evmVersion\":\"paris\",\"libraries\":{\":__CACHE_BREAKER__\":\"0x00000000d41867734bbee4c6863d9255b2b06ac1\"},\"metadata\":{\"bytecodeHash\":\"ipfs\",\"useLiteralContent\":true},\"optimizer\":{\"enabled\":true,\"runs\":1000},\"remappings\":[]},\"sources\":{\"@openzeppelin/contracts/access/AccessControl.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (access/AccessControl.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./IAccessControl.sol\\\";\\nimport \\\"../utils/Context.sol\\\";\\nimport \\\"../utils/Strings.sol\\\";\\nimport \\\"../utils/introspection/ERC165.sol\\\";\\n\\n/**\\n * @dev Contract module that allows children to implement role-based access\\n * control mechanisms. This is a lightweight version that doesn't allow enumerating role\\n * members except through off-chain means by accessing the contract event logs. Some\\n * applications may benefit from on-chain enumerability, for those cases see\\n * {AccessControlEnumerable}.\\n *\\n * Roles are referred to by their `bytes32` identifier. These should be exposed\\n * in the external API and be unique. The best way to achieve this is by\\n * using `public constant` hash digests:\\n *\\n * ```\\n * bytes32 public constant MY_ROLE = keccak256(\\\"MY_ROLE\\\");\\n * ```\\n *\\n * Roles can be used to represent a set of permissions. To restrict access to a\\n * function call, use {hasRole}:\\n *\\n * ```\\n * function foo() public {\\n * require(hasRole(MY_ROLE, msg.sender));\\n * ...\\n * }\\n * ```\\n *\\n * Roles can be granted and revoked dynamically via the {grantRole} and\\n * {revokeRole} functions. Each role has an associated admin role, and only\\n * accounts that have a role's admin role can call {grantRole} and {revokeRole}.\\n *\\n * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means\\n * that only accounts with this role will be able to grant or revoke other\\n * roles. More complex role relationships can be created by using\\n * {_setRoleAdmin}.\\n *\\n * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to\\n * grant and revoke this role. Extra precautions should be taken to secure\\n * accounts that have been granted it.\\n */\\nabstract contract AccessControl is Context, IAccessControl, ERC165 {\\n struct RoleData {\\n mapping(address => bool) members;\\n bytes32 adminRole;\\n }\\n\\n mapping(bytes32 => RoleData) private _roles;\\n\\n bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;\\n\\n /**\\n * @dev Modifier that checks that an account has a specific role. Reverts\\n * with a standardized message including the required role.\\n *\\n * The format of the revert reason is given by the following regular expression:\\n *\\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\\n *\\n * _Available since v4.1._\\n */\\n modifier onlyRole(bytes32 role) {\\n _checkRole(role);\\n _;\\n }\\n\\n /**\\n * @dev See {IERC165-supportsInterface}.\\n */\\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);\\n }\\n\\n /**\\n * @dev Returns `true` if `account` has been granted `role`.\\n */\\n function hasRole(bytes32 role, address account) public view virtual override returns (bool) {\\n return _roles[role].members[account];\\n }\\n\\n /**\\n * @dev Revert with a standard message if `_msgSender()` is missing `role`.\\n * Overriding this function changes the behavior of the {onlyRole} modifier.\\n *\\n * Format of the revert message is described in {_checkRole}.\\n *\\n * _Available since v4.6._\\n */\\n function _checkRole(bytes32 role) internal view virtual {\\n _checkRole(role, _msgSender());\\n }\\n\\n /**\\n * @dev Revert with a standard message if `account` is missing `role`.\\n *\\n * The format of the revert reason is given by the following regular expression:\\n *\\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\\n */\\n function _checkRole(bytes32 role, address account) internal view virtual {\\n if (!hasRole(role, account)) {\\n revert(\\n string(\\n abi.encodePacked(\\n \\\"AccessControl: account \\\",\\n Strings.toHexString(account),\\n \\\" is missing role \\\",\\n Strings.toHexString(uint256(role), 32)\\n )\\n )\\n );\\n }\\n }\\n\\n /**\\n * @dev Returns the admin role that controls `role`. See {grantRole} and\\n * {revokeRole}.\\n *\\n * To change a role's admin, use {_setRoleAdmin}.\\n */\\n function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {\\n return _roles[role].adminRole;\\n }\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * If `account` had not been already granted `role`, emits a {RoleGranted}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n *\\n * May emit a {RoleGranted} event.\\n */\\n function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\\n _grantRole(role, account);\\n }\\n\\n /**\\n * @dev Revokes `role` from `account`.\\n *\\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n *\\n * May emit a {RoleRevoked} event.\\n */\\n function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\\n _revokeRole(role, account);\\n }\\n\\n /**\\n * @dev Revokes `role` from the calling account.\\n *\\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\\n * purpose is to provide a mechanism for accounts to lose their privileges\\n * if they are compromised (such as when a trusted device is misplaced).\\n *\\n * If the calling account had been revoked `role`, emits a {RoleRevoked}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must be `account`.\\n *\\n * May emit a {RoleRevoked} event.\\n */\\n function renounceRole(bytes32 role, address account) public virtual override {\\n require(account == _msgSender(), \\\"AccessControl: can only renounce roles for self\\\");\\n\\n _revokeRole(role, account);\\n }\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * If `account` had not been already granted `role`, emits a {RoleGranted}\\n * event. Note that unlike {grantRole}, this function doesn't perform any\\n * checks on the calling account.\\n *\\n * May emit a {RoleGranted} event.\\n *\\n * [WARNING]\\n * ====\\n * This function should only be called from the constructor when setting\\n * up the initial roles for the system.\\n *\\n * Using this function in any other way is effectively circumventing the admin\\n * system imposed by {AccessControl}.\\n * ====\\n *\\n * NOTE: This function is deprecated in favor of {_grantRole}.\\n */\\n function _setupRole(bytes32 role, address account) internal virtual {\\n _grantRole(role, account);\\n }\\n\\n /**\\n * @dev Sets `adminRole` as ``role``'s admin role.\\n *\\n * Emits a {RoleAdminChanged} event.\\n */\\n function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {\\n bytes32 previousAdminRole = getRoleAdmin(role);\\n _roles[role].adminRole = adminRole;\\n emit RoleAdminChanged(role, previousAdminRole, adminRole);\\n }\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * Internal function without access restriction.\\n *\\n * May emit a {RoleGranted} event.\\n */\\n function _grantRole(bytes32 role, address account) internal virtual {\\n if (!hasRole(role, account)) {\\n _roles[role].members[account] = true;\\n emit RoleGranted(role, account, _msgSender());\\n }\\n }\\n\\n /**\\n * @dev Revokes `role` from `account`.\\n *\\n * Internal function without access restriction.\\n *\\n * May emit a {RoleRevoked} event.\\n */\\n function _revokeRole(bytes32 role, address account) internal virtual {\\n if (hasRole(role, account)) {\\n _roles[role].members[account] = false;\\n emit RoleRevoked(role, account, _msgSender());\\n }\\n }\\n}\\n\",\"keccak256\":\"0x67e3daf189111d6d5b0464ed09cf9f0605a22c4b965a7fcecd707101faff008a\",\"license\":\"MIT\"},\"@openzeppelin/contracts/access/IAccessControl.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev External interface of AccessControl declared to support ERC165 detection.\\n */\\ninterface IAccessControl {\\n /**\\n * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`\\n *\\n * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite\\n * {RoleAdminChanged} not being emitted signaling this.\\n *\\n * _Available since v3.1._\\n */\\n event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);\\n\\n /**\\n * @dev Emitted when `account` is granted `role`.\\n *\\n * `sender` is the account that originated the contract call, an admin role\\n * bearer except when using {AccessControl-_setupRole}.\\n */\\n event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);\\n\\n /**\\n * @dev Emitted when `account` is revoked `role`.\\n *\\n * `sender` is the account that originated the contract call:\\n * - if using `revokeRole`, it is the admin role bearer\\n * - if using `renounceRole`, it is the role bearer (i.e. `account`)\\n */\\n event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);\\n\\n /**\\n * @dev Returns `true` if `account` has been granted `role`.\\n */\\n function hasRole(bytes32 role, address account) external view returns (bool);\\n\\n /**\\n * @dev Returns the admin role that controls `role`. See {grantRole} and\\n * {revokeRole}.\\n *\\n * To change a role's admin, use {AccessControl-_setRoleAdmin}.\\n */\\n function getRoleAdmin(bytes32 role) external view returns (bytes32);\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * If `account` had not been already granted `role`, emits a {RoleGranted}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n */\\n function grantRole(bytes32 role, address account) external;\\n\\n /**\\n * @dev Revokes `role` from `account`.\\n *\\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n */\\n function revokeRole(bytes32 role, address account) external;\\n\\n /**\\n * @dev Revokes `role` from the calling account.\\n *\\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\\n * purpose is to provide a mechanism for accounts to lose their privileges\\n * if they are compromised (such as when a trusted device is misplaced).\\n *\\n * If the calling account had been granted `role`, emits a {RoleRevoked}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must be `account`.\\n */\\n function renounceRole(bytes32 role, address account) external;\\n}\\n\",\"keccak256\":\"0x59ce320a585d7e1f163cd70390a0ef2ff9cec832e2aa544293a00692465a7a57\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/Context.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Provides information about the current execution context, including the\\n * sender of the transaction and its data. While these are generally available\\n * via msg.sender and msg.data, they should not be accessed in such a direct\\n * manner, since when dealing with meta-transactions the account sending and\\n * paying for execution may not be the actual sender (as far as an application\\n * is concerned).\\n *\\n * This contract is only required for intermediate, library-like contracts.\\n */\\nabstract contract Context {\\n function _msgSender() internal view virtual returns (address) {\\n return msg.sender;\\n }\\n\\n function _msgData() internal view virtual returns (bytes calldata) {\\n return msg.data;\\n }\\n}\\n\",\"keccak256\":\"0xe2e337e6dde9ef6b680e07338c493ebea1b5fd09b43424112868e9cc1706bca7\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/Strings.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./math/Math.sol\\\";\\n\\n/**\\n * @dev String operations.\\n */\\nlibrary Strings {\\n bytes16 private constant _SYMBOLS = \\\"0123456789abcdef\\\";\\n uint8 private constant _ADDRESS_LENGTH = 20;\\n\\n /**\\n * @dev Converts a `uint256` to its ASCII `string` decimal representation.\\n */\\n function toString(uint256 value) internal pure returns (string memory) {\\n unchecked {\\n uint256 length = Math.log10(value) + 1;\\n string memory buffer = new string(length);\\n uint256 ptr;\\n /// @solidity memory-safe-assembly\\n assembly {\\n ptr := add(buffer, add(32, length))\\n }\\n while (true) {\\n ptr--;\\n /// @solidity memory-safe-assembly\\n assembly {\\n mstore8(ptr, byte(mod(value, 10), _SYMBOLS))\\n }\\n value /= 10;\\n if (value == 0) break;\\n }\\n return buffer;\\n }\\n }\\n\\n /**\\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\\n */\\n function toHexString(uint256 value) internal pure returns (string memory) {\\n unchecked {\\n return toHexString(value, Math.log256(value) + 1);\\n }\\n }\\n\\n /**\\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\\n */\\n function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\\n bytes memory buffer = new bytes(2 * length + 2);\\n buffer[0] = \\\"0\\\";\\n buffer[1] = \\\"x\\\";\\n for (uint256 i = 2 * length + 1; i > 1; --i) {\\n buffer[i] = _SYMBOLS[value & 0xf];\\n value >>= 4;\\n }\\n require(value == 0, \\\"Strings: hex length insufficient\\\");\\n return string(buffer);\\n }\\n\\n /**\\n * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.\\n */\\n function toHexString(address addr) internal pure returns (string memory) {\\n return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);\\n }\\n}\\n\",\"keccak256\":\"0xa4d1d62251f8574deb032a35fc948386a9b4de74b812d4f545a1ac120486b48a\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/introspection/ERC165.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./IERC165.sol\\\";\\n\\n/**\\n * @dev Implementation of the {IERC165} interface.\\n *\\n * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check\\n * for the additional interface id that will be supported. For example:\\n *\\n * ```solidity\\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\\n * }\\n * ```\\n *\\n * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.\\n */\\nabstract contract ERC165 is IERC165 {\\n /**\\n * @dev See {IERC165-supportsInterface}.\\n */\\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n return interfaceId == type(IERC165).interfaceId;\\n }\\n}\\n\",\"keccak256\":\"0xd10975de010d89fd1c78dc5e8a9a7e7f496198085c151648f20cba166b32582b\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/introspection/IERC165.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Interface of the ERC165 standard, as defined in the\\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\\n *\\n * Implementers can declare support of contract interfaces, which can then be\\n * queried by others ({ERC165Checker}).\\n *\\n * For an implementation, see {ERC165}.\\n */\\ninterface IERC165 {\\n /**\\n * @dev Returns true if this contract implements the interface defined by\\n * `interfaceId`. See the corresponding\\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\\n * to learn more about how these ids are created.\\n *\\n * This function call must use less than 30 000 gas.\\n */\\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\\n}\\n\",\"keccak256\":\"0x447a5f3ddc18419d41ff92b3773fb86471b1db25773e07f877f548918a185bf1\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/math/Math.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Standard math utilities missing in the Solidity language.\\n */\\nlibrary Math {\\n enum Rounding {\\n Down, // Toward negative infinity\\n Up, // Toward infinity\\n Zero // Toward zero\\n }\\n\\n /**\\n * @dev Returns the largest of two numbers.\\n */\\n function max(uint256 a, uint256 b) internal pure returns (uint256) {\\n return a > b ? a : b;\\n }\\n\\n /**\\n * @dev Returns the smallest of two numbers.\\n */\\n function min(uint256 a, uint256 b) internal pure returns (uint256) {\\n return a < b ? a : b;\\n }\\n\\n /**\\n * @dev Returns the average of two numbers. The result is rounded towards\\n * zero.\\n */\\n function average(uint256 a, uint256 b) internal pure returns (uint256) {\\n // (a + b) / 2 can overflow.\\n return (a & b) + (a ^ b) / 2;\\n }\\n\\n /**\\n * @dev Returns the ceiling of the division of two numbers.\\n *\\n * This differs from standard division with `/` in that it rounds up instead\\n * of rounding down.\\n */\\n function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {\\n // (a + b - 1) / b can overflow on addition, so we distribute.\\n return a == 0 ? 0 : (a - 1) / b + 1;\\n }\\n\\n /**\\n * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0\\n * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)\\n * with further edits by Uniswap Labs also under MIT license.\\n */\\n function mulDiv(\\n uint256 x,\\n uint256 y,\\n uint256 denominator\\n ) internal pure returns (uint256 result) {\\n unchecked {\\n // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use\\n // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256\\n // variables such that product = prod1 * 2^256 + prod0.\\n uint256 prod0; // Least significant 256 bits of the product\\n uint256 prod1; // Most significant 256 bits of the product\\n assembly {\\n let mm := mulmod(x, y, not(0))\\n prod0 := mul(x, y)\\n prod1 := sub(sub(mm, prod0), lt(mm, prod0))\\n }\\n\\n // Handle non-overflow cases, 256 by 256 division.\\n if (prod1 == 0) {\\n return prod0 / denominator;\\n }\\n\\n // Make sure the result is less than 2^256. Also prevents denominator == 0.\\n require(denominator > prod1);\\n\\n ///////////////////////////////////////////////\\n // 512 by 256 division.\\n ///////////////////////////////////////////////\\n\\n // Make division exact by subtracting the remainder from [prod1 prod0].\\n uint256 remainder;\\n assembly {\\n // Compute remainder using mulmod.\\n remainder := mulmod(x, y, denominator)\\n\\n // Subtract 256 bit number from 512 bit number.\\n prod1 := sub(prod1, gt(remainder, prod0))\\n prod0 := sub(prod0, remainder)\\n }\\n\\n // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.\\n // See https://cs.stackexchange.com/q/138556/92363.\\n\\n // Does not overflow because the denominator cannot be zero at this stage in the function.\\n uint256 twos = denominator & (~denominator + 1);\\n assembly {\\n // Divide denominator by twos.\\n denominator := div(denominator, twos)\\n\\n // Divide [prod1 prod0] by twos.\\n prod0 := div(prod0, twos)\\n\\n // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.\\n twos := add(div(sub(0, twos), twos), 1)\\n }\\n\\n // Shift in bits from prod1 into prod0.\\n prod0 |= prod1 * twos;\\n\\n // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such\\n // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for\\n // four bits. That is, denominator * inv = 1 mod 2^4.\\n uint256 inverse = (3 * denominator) ^ 2;\\n\\n // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works\\n // in modular arithmetic, doubling the correct bits in each step.\\n inverse *= 2 - denominator * inverse; // inverse mod 2^8\\n inverse *= 2 - denominator * inverse; // inverse mod 2^16\\n inverse *= 2 - denominator * inverse; // inverse mod 2^32\\n inverse *= 2 - denominator * inverse; // inverse mod 2^64\\n inverse *= 2 - denominator * inverse; // inverse mod 2^128\\n inverse *= 2 - denominator * inverse; // inverse mod 2^256\\n\\n // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.\\n // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is\\n // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1\\n // is no longer required.\\n result = prod0 * inverse;\\n return result;\\n }\\n }\\n\\n /**\\n * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.\\n */\\n function mulDiv(\\n uint256 x,\\n uint256 y,\\n uint256 denominator,\\n Rounding rounding\\n ) internal pure returns (uint256) {\\n uint256 result = mulDiv(x, y, denominator);\\n if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {\\n result += 1;\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.\\n *\\n * Inspired by Henry S. Warren, Jr.'s \\\"Hacker's Delight\\\" (Chapter 11).\\n */\\n function sqrt(uint256 a) internal pure returns (uint256) {\\n if (a == 0) {\\n return 0;\\n }\\n\\n // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.\\n //\\n // We know that the \\\"msb\\\" (most significant bit) of our target number `a` is a power of 2 such that we have\\n // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.\\n //\\n // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`\\n // \\u2192 `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`\\n // \\u2192 `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`\\n //\\n // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.\\n uint256 result = 1 << (log2(a) >> 1);\\n\\n // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,\\n // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at\\n // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision\\n // into the expected uint128 result.\\n unchecked {\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n return min(result, a / result);\\n }\\n }\\n\\n /**\\n * @notice Calculates sqrt(a), following the selected rounding direction.\\n */\\n function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = sqrt(a);\\n return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);\\n }\\n }\\n\\n /**\\n * @dev Return the log in base 2, rounded down, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log2(uint256 value) internal pure returns (uint256) {\\n uint256 result = 0;\\n unchecked {\\n if (value >> 128 > 0) {\\n value >>= 128;\\n result += 128;\\n }\\n if (value >> 64 > 0) {\\n value >>= 64;\\n result += 64;\\n }\\n if (value >> 32 > 0) {\\n value >>= 32;\\n result += 32;\\n }\\n if (value >> 16 > 0) {\\n value >>= 16;\\n result += 16;\\n }\\n if (value >> 8 > 0) {\\n value >>= 8;\\n result += 8;\\n }\\n if (value >> 4 > 0) {\\n value >>= 4;\\n result += 4;\\n }\\n if (value >> 2 > 0) {\\n value >>= 2;\\n result += 2;\\n }\\n if (value >> 1 > 0) {\\n result += 1;\\n }\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Return the log in base 2, following the selected rounding direction, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = log2(value);\\n return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);\\n }\\n }\\n\\n /**\\n * @dev Return the log in base 10, rounded down, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log10(uint256 value) internal pure returns (uint256) {\\n uint256 result = 0;\\n unchecked {\\n if (value >= 10**64) {\\n value /= 10**64;\\n result += 64;\\n }\\n if (value >= 10**32) {\\n value /= 10**32;\\n result += 32;\\n }\\n if (value >= 10**16) {\\n value /= 10**16;\\n result += 16;\\n }\\n if (value >= 10**8) {\\n value /= 10**8;\\n result += 8;\\n }\\n if (value >= 10**4) {\\n value /= 10**4;\\n result += 4;\\n }\\n if (value >= 10**2) {\\n value /= 10**2;\\n result += 2;\\n }\\n if (value >= 10**1) {\\n result += 1;\\n }\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = log10(value);\\n return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);\\n }\\n }\\n\\n /**\\n * @dev Return the log in base 256, rounded down, of a positive value.\\n * Returns 0 if given 0.\\n *\\n * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.\\n */\\n function log256(uint256 value) internal pure returns (uint256) {\\n uint256 result = 0;\\n unchecked {\\n if (value >> 128 > 0) {\\n value >>= 128;\\n result += 16;\\n }\\n if (value >> 64 > 0) {\\n value >>= 64;\\n result += 8;\\n }\\n if (value >> 32 > 0) {\\n value >>= 32;\\n result += 4;\\n }\\n if (value >> 16 > 0) {\\n value >>= 16;\\n result += 2;\\n }\\n if (value >> 8 > 0) {\\n result += 1;\\n }\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = log256(value);\\n return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);\\n }\\n }\\n}\\n\",\"keccak256\":\"0xa1e8e83cd0087785df04ac79fb395d9f3684caeaf973d9e2c71caef723a3a5d6\",\"license\":\"MIT\"},\"src/PriceOracle.sol\":{\"content\":\"// SPDX-License-Identifier: BSD-3-Clause\\npragma solidity ^0.8.19;\\nimport \\\"@openzeppelin/contracts/access/AccessControl.sol\\\";\\nimport \\\"./interface/IPostageStamp.sol\\\";\\n\\n/**\\n * @title PriceOracle contract.\\n * @author The Swarm Authors.\\n * @dev The price oracle contract emits a price feed using events.\\n */\\n\\ncontract PriceOracle is AccessControl {\\n // ----------------------------- State variables ------------------------------\\n\\n // The address of the linked PostageStamp contract\\n IPostageStamp public postageStamp;\\n\\n uint16 targetRedundancy = 4;\\n uint16 maxConsideredExtraRedundancy = 4;\\n\\n // When the contract is paused, price changes are not effective\\n bool public isPaused = false;\\n\\n // The number of the last round price adjusting happend\\n uint64 public lastAdjustedRound;\\n\\n // The minimum price allowed\\n uint32 public minimumPriceUpscaled = 24000 << 10; // we upscale it by 2^10\\n\\n // The priceBase to modulate the price\\n uint32 public priceBase = 1048576;\\n\\n uint64 public currentPriceUpScaled = minimumPriceUpscaled;\\n\\n // Constants used to modulate the price, see below usage\\n uint32[9] public changeRate = [1049417, 1049206, 1048996, 1048786, 1048576, 1048366, 1048156, 1047946, 1047736];\\n\\n // Role allowed to update price\\n bytes32 public immutable PRICE_UPDATER_ROLE;\\n\\n // The length of a round in blocks.\\n uint8 private constant ROUND_LENGTH = 152;\\n\\n // ----------------------------- Events ------------------------------\\n\\n /**\\n *@dev Emitted on every price update.\\n */\\n event PriceUpdate(uint256 price);\\n event StampPriceUpdateFailed(uint256 attemptedPrice);\\n\\n // ----------------------------- Custom Errors ------------------------------\\n error CallerNotAdmin(); // Caller is not the admin\\n error CallerNotPriceUpdater(); // Caller is not a price updater\\n error PriceAlreadyAdjusted(); // Price already adjusted in this round\\n error UnexpectedZero(); // Redundancy needs to be higher then 0\\n\\n // ----------------------------- CONSTRUCTOR ------------------------------\\n\\n constructor(address _postageStamp) {\\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\\n postageStamp = IPostageStamp(_postageStamp);\\n lastAdjustedRound = currentRound();\\n PRICE_UPDATER_ROLE = keccak256(\\\"PRICE_UPDATER_ROLE\\\");\\n emit PriceUpdate(currentPrice());\\n }\\n\\n ////////////////////////////////////////\\n // STATE SETTING //\\n ////////////////////////////////////////\\n\\n /**\\n * @notice Manually set the price.\\n * @dev Can only be called by the admin role.\\n * @param _price The new price.\\n */ function setPrice(uint32 _price) external returns (bool) {\\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\\n revert CallerNotAdmin();\\n }\\n\\n uint64 _currentPriceUpScaled = _price << 10;\\n uint64 _minimumPriceUpscaled = minimumPriceUpscaled;\\n\\n // Enforce minimum price\\n if (_currentPriceUpScaled < _minimumPriceUpscaled) {\\n _currentPriceUpScaled = _minimumPriceUpscaled;\\n }\\n currentPriceUpScaled = _currentPriceUpScaled;\\n\\n // Check if the setting of price in postagestamp succeded\\n (bool success, ) = address(postageStamp).call(\\n abi.encodeWithSignature(\\\"setPrice(uint256)\\\", uint256(currentPrice()))\\n );\\n if (!success) {\\n emit StampPriceUpdateFailed(currentPrice());\\n return false;\\n }\\n emit PriceUpdate(currentPrice());\\n return true;\\n }\\n\\n function adjustPrice(uint16 redundancy) external returns (bool) {\\n if (isPaused == false) {\\n if (!hasRole(PRICE_UPDATER_ROLE, msg.sender)) {\\n revert CallerNotPriceUpdater();\\n }\\n\\n uint16 usedRedundancy = redundancy;\\n uint64 currentRoundNumber = currentRound();\\n\\n // Price can only be adjusted once per round\\n if (currentRoundNumber <= lastAdjustedRound) {\\n revert PriceAlreadyAdjusted();\\n }\\n // Redundancy may not be zero\\n if (redundancy == 0) {\\n revert UnexpectedZero();\\n }\\n\\n // Enforce maximum considered extra redundancy\\n uint16 maxConsideredRedundancy = targetRedundancy + maxConsideredExtraRedundancy;\\n if (redundancy > maxConsideredRedundancy) {\\n usedRedundancy = maxConsideredRedundancy;\\n }\\n\\n uint64 _currentPriceUpScaled = currentPriceUpScaled;\\n uint64 _minimumPriceUpscaled = minimumPriceUpscaled;\\n uint32 _priceBase = priceBase;\\n\\n // Set the number of rounds that were skipped, we substract 1 as lastAdjustedRound is set below and default results is 1\\n uint64 skippedRounds = currentRoundNumber - lastAdjustedRound - 1;\\n\\n // We first apply the increase/decrease rate for the current round\\n uint32 _changeRate = changeRate[usedRedundancy];\\n _currentPriceUpScaled = (_changeRate * _currentPriceUpScaled) / _priceBase;\\n\\n // If previous rounds were skipped, use MAX price increase for the previous rounds\\n if (skippedRounds > 0) {\\n _changeRate = changeRate[0];\\n for (uint64 i = 0; i < skippedRounds; i++) {\\n _currentPriceUpScaled = (_changeRate * _currentPriceUpScaled) / _priceBase;\\n }\\n }\\n\\n // Enforce minimum price\\n if (_currentPriceUpScaled < _minimumPriceUpscaled) {\\n _currentPriceUpScaled = _minimumPriceUpscaled;\\n }\\n\\n currentPriceUpScaled = _currentPriceUpScaled;\\n lastAdjustedRound = currentRoundNumber;\\n\\n // Check if the price set in postagestamp succeded\\n (bool success, ) = address(postageStamp).call(\\n abi.encodeWithSignature(\\\"setPrice(uint256)\\\", uint256(currentPrice()))\\n );\\n if (!success) {\\n emit StampPriceUpdateFailed(currentPrice());\\n return false;\\n }\\n emit PriceUpdate(currentPrice());\\n return true;\\n }\\n return false;\\n }\\n\\n function pause() external {\\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\\n revert CallerNotAdmin();\\n }\\n isPaused = true;\\n }\\n\\n function unPause() external {\\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\\n revert CallerNotAdmin();\\n }\\n isPaused = false;\\n }\\n\\n ////////////////////////////////////////\\n // STATE READING //\\n ////////////////////////////////////////\\n\\n /**\\n * @notice Return the number of the current round.\\n */\\n function currentRound() public view returns (uint64) {\\n // We downcasted to uint64 as uint64 has 18,446,744,073,709,551,616 places\\n // as each round is 152 x 5 = 760, each day has around 113 rounds which is 41245 in a year\\n // it results 4.4724801e+14 years to run this game\\n return uint64(block.number / uint256(ROUND_LENGTH));\\n }\\n\\n /**\\n * @notice Return the price downscaled\\n */\\n function currentPrice() public view returns (uint32) {\\n // We downcasted to uint32 and bitshift it by 2^10\\n return uint32((currentPriceUpScaled) >> 10);\\n }\\n\\n /**\\n * @notice Return the price downscaled\\n */\\n function minimumPrice() public view returns (uint32) {\\n // We downcasted to uint32 and bitshift it by 2^10\\n return uint32((minimumPriceUpscaled) >> 10);\\n }\\n}\\n\",\"keccak256\":\"0x8e0cdeb0e0e5571e5c8a8e4b6a6928b9a25676e5699297f487b6a43adcd10b22\",\"license\":\"BSD-3-Clause\"},\"src/interface/IPostageStamp.sol\":{\"content\":\"// SPDX-License-Identifier: BSD-3-Clause\\npragma solidity ^0.8.19;\\n\\ninterface IPostageStamp {\\n function withdraw(address beneficiary) external;\\n\\n function setPrice(uint256 _price) external;\\n\\n function validChunkCount() external view returns (uint256);\\n\\n function batchOwner(bytes32 _batchId) external view returns (address);\\n\\n function batchDepth(bytes32 _batchId) external view returns (uint8);\\n\\n function batchBucketDepth(bytes32 _batchId) external view returns (uint8);\\n\\n function remainingBalance(bytes32 _batchId) external view returns (uint256);\\n\\n function minimumInitialBalancePerChunk() external view returns (uint256);\\n\\n function batches(\\n bytes32\\n )\\n external\\n view\\n returns (\\n address owner,\\n uint8 depth,\\n uint8 bucketDepth,\\n bool immutableFlag,\\n uint256 normalisedBalance,\\n uint256 lastUpdatedBlockNumber\\n );\\n}\\n\",\"keccak256\":\"0xb46f1043bf7fdc22d5f719ab97341211fa30fff499de3cf079be715079b965ad\",\"license\":\"BSD-3-Clause\"}},\"version\":1}", + "bytecode": "0x600180546201000160a21b64ffffffffff60a01b1990911617905560028054600160401b600160c01b0319811663ffffffff68010000000000000000600160401b600160801b03199093166e1000000177000000000000000000009081179390930416600160801b02171790556101c06040526210034960a09081526210027660c052621001a460e052621000d2610100526210000061012052620fff2e61014052620ffe5c61016052620ffd8a61018052620ffcb86101a052620000c990600390600962000291565b50348015620000d757600080fd5b506040516200181938038062001819833981016040819052620000fa916200034a565b62000107600033620001cd565b600180546001600160a01b0319166001600160a01b0383161790556200012c620001dd565b600280546001600160401b0319166001600160401b03929092169190911790557fd96ba01d6560c2ab35f2940dd8d70c5f5fe06236c72674237120515918198fb06080527fae46785019700e30375a5d7b4f91e32f8060ef085111f896ebf889450aa2ab5a620001ae600254600160801b9004600a1c663fffffffffffff1690565b60405163ffffffff909116815260200160405180910390a1506200039f565b620001d98282620001f1565b5050565b6000620001ec6098436200037c565b905090565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16620001d9576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556200024d3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b600283019183908215620003215791602002820160005b83821115620002ed57835183826101000a81548163ffffffff021916908362ffffff1602179055509260200192600401602081600301049283019260010302620002a8565b80156200031f5782816101000a81549063ffffffff0219169055600401602081600301049283019260010302620002ed565b505b506200032f92915062000333565b5090565b5b808211156200032f576000815560010162000334565b6000602082840312156200035d57600080fd5b81516001600160a01b03811681146200037557600080fd5b9392505050565b6000826200039a57634e487b7160e01b600052601260045260246000fd5b500490565b608051611457620003c2600039600081816103ac01526108bf01526114576000f3fe608060405234801561001057600080fd5b50600436106101825760003560e01c806391d14854116100d8578063daafe0a51161008c578063f7b188a511610066578063f7b188a51461039f578063fb8d8101146103a7578063ffb98fe3146103ce57600080fd5b8063daafe0a514610346578063dcd8ffb814610359578063e0632c641461037457600080fd5b8063a217fddf116100bd578063a217fddf14610317578063b187bd261461031f578063d547741f1461033357600080fd5b806391d14854146102c55780639d1b464a146102fc57600080fd5b80637310561b1161013a5780637f386b6c116101145780637f386b6c146102995780638456cb59146102b55780638a19c8bc146102bd57600080fd5b80637310561b1461023557806374e7493b1461026a5780637e8effdd1461027d57600080fd5b80632f2ff15d1161016b5780632f2ff15d146101e057806336568abe146101f557806355bdcd231461020857600080fd5b806301ffc9a714610187578063248a9ca3146101af575b600080fd5b61019a6101953660046110e2565b6103e1565b60405190151581526020015b60405180910390f35b6101d26101bd366004611124565b60009081526020819052604090206001015490565b6040519081526020016101a6565b6101f36101ee36600461113d565b61047a565b005b6101f361020336600461113d565b6104a4565b60025461021c9067ffffffffffffffff1681565b60405167ffffffffffffffff90911681526020016101a6565b600254610255906c01000000000000000000000000900463ffffffff1681565b60405163ffffffff90911681526020016101a6565b610255610278366004611124565b610535565b6002546102559068010000000000000000900463ffffffff1681565b600254680100000000000000009004600a1c623fffff16610255565b6101f3610565565b61021c6105c9565b61019a6102d336600461113d565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b600254600160801b9004600a1c663fffffffffffff16610255565b6101d2600081565b60015461019a90600160c01b900460ff1681565b6101f361034136600461113d565b6105db565b61019a610354366004611179565b610600565b60025461021c90600160801b900467ffffffffffffffff1681565b600154610387906001600160a01b031681565b6040516001600160a01b0390911681526020016101a6565b6101f3610847565b6101d27f000000000000000000000000000000000000000000000000000000000000000081565b61019a6103dc36600461119f565b6108a5565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f7965db0b00000000000000000000000000000000000000000000000000000000148061047457507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008316145b92915050565b60008281526020819052604090206001015461049581610d4b565b61049f8383610d58565b505050565b6001600160a01b03811633146105275760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b6105318282610df6565b5050565b6003816009811061054557600080fd5b60089182820401919006600402915054906101000a900463ffffffff1681565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff166105b45760405163036c8cf960e11b815260040160405180910390fd5b6001805460ff60c01b1916600160c01b179055565b60006105d66098436111ef565b905090565b6000828152602081905260409020600101546105f681610d4b565b61049f8383610df6565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604081205460ff1661064f5760405163036c8cf960e11b815260040160405180910390fd5b60025463fffffc00600a84901b169068010000000000000000900463ffffffff168082101561067c578091505b6002805467ffffffffffffffff8416600160801b027fffffffffffffffff0000000000000000ffffffffffffffffffffffffffffffff9091161790556001546000906001600160a01b03166106e4600254663fffffffffffff600160801b909104600a1c1690565b63ffffffff166040516024016106fc91815260200190565b60408051601f198184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff166391b7f5ed60e01b179052516107469190611227565b6000604051808303816000865af19150503d8060008114610783576040519150601f19603f3d011682016040523d82523d6000602084013e610788565b606091505b50509050806107ec576002547fd2821f4adadf1d64076091cc92984c0f001a300541dd58cff8e8e29d6290c33d90600160801b9004600a1c663fffffffffffff1660405163ffffffff909116815260200160405180910390a1506000949350505050565b6002547fae46785019700e30375a5d7b4f91e32f8060ef085111f896ebf889450aa2ab5a90600160801b9004600a1c663fffffffffffff1660405163ffffffff909116815260200160405180910390a1506001949350505050565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff166108965760405163036c8cf960e11b815260040160405180910390fd5b6001805460ff60c01b19169055565b600154600090600160c01b900460ff1615158103610d43577f000000000000000000000000000000000000000000000000000000000000000060009081526020818152604080832033845290915290205460ff1661092f576040517f262791ec00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b81600061093a6105c9565b60025490915067ffffffffffffffff90811690821611610986576040517f08a5cb4c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8361ffff166000036109c4576040517fb5ca2d7100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600154600090610a0c9061ffff760100000000000000000000000000000000000000000000820481169174010000000000000000000000000000000000000000900416611243565b90508061ffff168561ffff161115610a22578092505b60025467ffffffffffffffff600160801b820481169163ffffffff6801000000000000000082048116926c01000000000000000000000000830490911691600091600191610a71911688611265565b610a7b9190611265565b9050600060038861ffff1660098110610a9657610a96611286565b60088104919091015460079091166004026101000a900463ffffffff90811691508316610ac3868361129c565b610acd91906112c8565b945067ffffffffffffffff821615610b41575060035463ffffffff1660005b8267ffffffffffffffff168167ffffffffffffffff161015610b3f578363ffffffff16868363ffffffff16610b21919061129c565b610b2b91906112c8565b955080610b37816112ef565b915050610aec565b505b8367ffffffffffffffff168567ffffffffffffffff161015610b61578394505b600280547fffffffffffffffff0000000000000000ffffffffffffffff000000000000000016600160801b67ffffffffffffffff888116820267ffffffffffffffff191692909217918a1691909117918290556001546000926001600160a01b03909116919004600a1c663fffffffffffff1663ffffffff16604051602401610bec91815260200190565b60408051601f198184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff166391b7f5ed60e01b17905251610c369190611227565b6000604051808303816000865af19150503d8060008114610c73576040519150601f19603f3d011682016040523d82523d6000602084013e610c78565b606091505b5050905080610ce2576002547fd2821f4adadf1d64076091cc92984c0f001a300541dd58cff8e8e29d6290c33d90600160801b9004600a1c663fffffffffffff1660405163ffffffff909116815260200160405180910390a15060009a9950505050505050505050565b6002547fae46785019700e30375a5d7b4f91e32f8060ef085111f896ebf889450aa2ab5a90600160801b9004600a1c663fffffffffffff1660405163ffffffff909116815260200160405180910390a15060019a9950505050505050505050565b506000919050565b610d558133610e75565b50565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610531576000828152602081815260408083206001600160a01b03851684529091529020805460ff19166001179055610db23390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1615610531576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1661053157610ea681610ee8565b610eb1836020610efa565b604051602001610ec2929190611316565b60408051601f198184030181529082905262461bcd60e51b825261051e91600401611397565b60606104746001600160a01b03831660145b60606000610f098360026113ca565b610f149060026113e1565b67ffffffffffffffff811115610f2c57610f2c6113f4565b6040519080825280601f01601f191660200182016040528015610f56576020820181803683370190505b5090507f300000000000000000000000000000000000000000000000000000000000000081600081518110610f8d57610f8d611286565b60200101906001600160f81b031916908160001a9053507f780000000000000000000000000000000000000000000000000000000000000081600181518110610fd857610fd8611286565b60200101906001600160f81b031916908160001a9053506000610ffc8460026113ca565b6110079060016113e1565b90505b600181111561108c577f303132333435363738396162636465660000000000000000000000000000000085600f166010811061104857611048611286565b1a60f81b82828151811061105e5761105e611286565b60200101906001600160f81b031916908160001a90535060049490941c936110858161140a565b905061100a565b5083156110db5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e74604482015260640161051e565b9392505050565b6000602082840312156110f457600080fd5b81357fffffffff00000000000000000000000000000000000000000000000000000000811681146110db57600080fd5b60006020828403121561113657600080fd5b5035919050565b6000806040838503121561115057600080fd5b8235915060208301356001600160a01b038116811461116e57600080fd5b809150509250929050565b60006020828403121561118b57600080fd5b813563ffffffff811681146110db57600080fd5b6000602082840312156111b157600080fd5b813561ffff811681146110db57600080fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b6000826111fe576111fe6111c3565b500490565b60005b8381101561121e578181015183820152602001611206565b50506000910152565b60008251611239818460208701611203565b9190910192915050565b61ffff81811683821601908082111561125e5761125e6111d9565b5092915050565b67ffffffffffffffff82811682821603908082111561125e5761125e6111d9565b634e487b7160e01b600052603260045260246000fd5b67ffffffffffffffff8181168382160280821691908281146112c0576112c06111d9565b505092915050565b600067ffffffffffffffff808416806112e3576112e36111c3565b92169190910492915050565b600067ffffffffffffffff80831681810361130c5761130c6111d9565b6001019392505050565b7f416363657373436f6e74726f6c3a206163636f756e742000000000000000000081526000835161134e816017850160208801611203565b7f206973206d697373696e6720726f6c6520000000000000000000000000000000601791840191820152835161138b816028840160208801611203565b01602801949350505050565b60208152600082518060208401526113b6816040850160208701611203565b601f01601f19169190910160400192915050565b8082028115828204841417610474576104746111d9565b80820180821115610474576104746111d9565b634e487b7160e01b600052604160045260246000fd5b600081611419576114196111d9565b50600019019056fea2646970667358221220d9f2bae3059a195fbe106eecfa17d7818ae58f76c3efa4ab6bd7920ebaaf271664736f6c63430008130033", + "deployedBytecode": "0x608060405234801561001057600080fd5b50600436106101825760003560e01c806391d14854116100d8578063daafe0a51161008c578063f7b188a511610066578063f7b188a51461039f578063fb8d8101146103a7578063ffb98fe3146103ce57600080fd5b8063daafe0a514610346578063dcd8ffb814610359578063e0632c641461037457600080fd5b8063a217fddf116100bd578063a217fddf14610317578063b187bd261461031f578063d547741f1461033357600080fd5b806391d14854146102c55780639d1b464a146102fc57600080fd5b80637310561b1161013a5780637f386b6c116101145780637f386b6c146102995780638456cb59146102b55780638a19c8bc146102bd57600080fd5b80637310561b1461023557806374e7493b1461026a5780637e8effdd1461027d57600080fd5b80632f2ff15d1161016b5780632f2ff15d146101e057806336568abe146101f557806355bdcd231461020857600080fd5b806301ffc9a714610187578063248a9ca3146101af575b600080fd5b61019a6101953660046110e2565b6103e1565b60405190151581526020015b60405180910390f35b6101d26101bd366004611124565b60009081526020819052604090206001015490565b6040519081526020016101a6565b6101f36101ee36600461113d565b61047a565b005b6101f361020336600461113d565b6104a4565b60025461021c9067ffffffffffffffff1681565b60405167ffffffffffffffff90911681526020016101a6565b600254610255906c01000000000000000000000000900463ffffffff1681565b60405163ffffffff90911681526020016101a6565b610255610278366004611124565b610535565b6002546102559068010000000000000000900463ffffffff1681565b600254680100000000000000009004600a1c623fffff16610255565b6101f3610565565b61021c6105c9565b61019a6102d336600461113d565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b600254600160801b9004600a1c663fffffffffffff16610255565b6101d2600081565b60015461019a90600160c01b900460ff1681565b6101f361034136600461113d565b6105db565b61019a610354366004611179565b610600565b60025461021c90600160801b900467ffffffffffffffff1681565b600154610387906001600160a01b031681565b6040516001600160a01b0390911681526020016101a6565b6101f3610847565b6101d27f000000000000000000000000000000000000000000000000000000000000000081565b61019a6103dc36600461119f565b6108a5565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f7965db0b00000000000000000000000000000000000000000000000000000000148061047457507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008316145b92915050565b60008281526020819052604090206001015461049581610d4b565b61049f8383610d58565b505050565b6001600160a01b03811633146105275760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b6105318282610df6565b5050565b6003816009811061054557600080fd5b60089182820401919006600402915054906101000a900463ffffffff1681565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff166105b45760405163036c8cf960e11b815260040160405180910390fd5b6001805460ff60c01b1916600160c01b179055565b60006105d66098436111ef565b905090565b6000828152602081905260409020600101546105f681610d4b565b61049f8383610df6565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604081205460ff1661064f5760405163036c8cf960e11b815260040160405180910390fd5b60025463fffffc00600a84901b169068010000000000000000900463ffffffff168082101561067c578091505b6002805467ffffffffffffffff8416600160801b027fffffffffffffffff0000000000000000ffffffffffffffffffffffffffffffff9091161790556001546000906001600160a01b03166106e4600254663fffffffffffff600160801b909104600a1c1690565b63ffffffff166040516024016106fc91815260200190565b60408051601f198184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff166391b7f5ed60e01b179052516107469190611227565b6000604051808303816000865af19150503d8060008114610783576040519150601f19603f3d011682016040523d82523d6000602084013e610788565b606091505b50509050806107ec576002547fd2821f4adadf1d64076091cc92984c0f001a300541dd58cff8e8e29d6290c33d90600160801b9004600a1c663fffffffffffff1660405163ffffffff909116815260200160405180910390a1506000949350505050565b6002547fae46785019700e30375a5d7b4f91e32f8060ef085111f896ebf889450aa2ab5a90600160801b9004600a1c663fffffffffffff1660405163ffffffff909116815260200160405180910390a1506001949350505050565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff166108965760405163036c8cf960e11b815260040160405180910390fd5b6001805460ff60c01b19169055565b600154600090600160c01b900460ff1615158103610d43577f000000000000000000000000000000000000000000000000000000000000000060009081526020818152604080832033845290915290205460ff1661092f576040517f262791ec00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b81600061093a6105c9565b60025490915067ffffffffffffffff90811690821611610986576040517f08a5cb4c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8361ffff166000036109c4576040517fb5ca2d7100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600154600090610a0c9061ffff760100000000000000000000000000000000000000000000820481169174010000000000000000000000000000000000000000900416611243565b90508061ffff168561ffff161115610a22578092505b60025467ffffffffffffffff600160801b820481169163ffffffff6801000000000000000082048116926c01000000000000000000000000830490911691600091600191610a71911688611265565b610a7b9190611265565b9050600060038861ffff1660098110610a9657610a96611286565b60088104919091015460079091166004026101000a900463ffffffff90811691508316610ac3868361129c565b610acd91906112c8565b945067ffffffffffffffff821615610b41575060035463ffffffff1660005b8267ffffffffffffffff168167ffffffffffffffff161015610b3f578363ffffffff16868363ffffffff16610b21919061129c565b610b2b91906112c8565b955080610b37816112ef565b915050610aec565b505b8367ffffffffffffffff168567ffffffffffffffff161015610b61578394505b600280547fffffffffffffffff0000000000000000ffffffffffffffff000000000000000016600160801b67ffffffffffffffff888116820267ffffffffffffffff191692909217918a1691909117918290556001546000926001600160a01b03909116919004600a1c663fffffffffffff1663ffffffff16604051602401610bec91815260200190565b60408051601f198184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff166391b7f5ed60e01b17905251610c369190611227565b6000604051808303816000865af19150503d8060008114610c73576040519150601f19603f3d011682016040523d82523d6000602084013e610c78565b606091505b5050905080610ce2576002547fd2821f4adadf1d64076091cc92984c0f001a300541dd58cff8e8e29d6290c33d90600160801b9004600a1c663fffffffffffff1660405163ffffffff909116815260200160405180910390a15060009a9950505050505050505050565b6002547fae46785019700e30375a5d7b4f91e32f8060ef085111f896ebf889450aa2ab5a90600160801b9004600a1c663fffffffffffff1660405163ffffffff909116815260200160405180910390a15060019a9950505050505050505050565b506000919050565b610d558133610e75565b50565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610531576000828152602081815260408083206001600160a01b03851684529091529020805460ff19166001179055610db23390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1615610531576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1661053157610ea681610ee8565b610eb1836020610efa565b604051602001610ec2929190611316565b60408051601f198184030181529082905262461bcd60e51b825261051e91600401611397565b60606104746001600160a01b03831660145b60606000610f098360026113ca565b610f149060026113e1565b67ffffffffffffffff811115610f2c57610f2c6113f4565b6040519080825280601f01601f191660200182016040528015610f56576020820181803683370190505b5090507f300000000000000000000000000000000000000000000000000000000000000081600081518110610f8d57610f8d611286565b60200101906001600160f81b031916908160001a9053507f780000000000000000000000000000000000000000000000000000000000000081600181518110610fd857610fd8611286565b60200101906001600160f81b031916908160001a9053506000610ffc8460026113ca565b6110079060016113e1565b90505b600181111561108c577f303132333435363738396162636465660000000000000000000000000000000085600f166010811061104857611048611286565b1a60f81b82828151811061105e5761105e611286565b60200101906001600160f81b031916908160001a90535060049490941c936110858161140a565b905061100a565b5083156110db5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e74604482015260640161051e565b9392505050565b6000602082840312156110f457600080fd5b81357fffffffff00000000000000000000000000000000000000000000000000000000811681146110db57600080fd5b60006020828403121561113657600080fd5b5035919050565b6000806040838503121561115057600080fd5b8235915060208301356001600160a01b038116811461116e57600080fd5b809150509250929050565b60006020828403121561118b57600080fd5b813563ffffffff811681146110db57600080fd5b6000602082840312156111b157600080fd5b813561ffff811681146110db57600080fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b6000826111fe576111fe6111c3565b500490565b60005b8381101561121e578181015183820152602001611206565b50506000910152565b60008251611239818460208701611203565b9190910192915050565b61ffff81811683821601908082111561125e5761125e6111d9565b5092915050565b67ffffffffffffffff82811682821603908082111561125e5761125e6111d9565b634e487b7160e01b600052603260045260246000fd5b67ffffffffffffffff8181168382160280821691908281146112c0576112c06111d9565b505092915050565b600067ffffffffffffffff808416806112e3576112e36111c3565b92169190910492915050565b600067ffffffffffffffff80831681810361130c5761130c6111d9565b6001019392505050565b7f416363657373436f6e74726f6c3a206163636f756e742000000000000000000081526000835161134e816017850160208801611203565b7f206973206d697373696e6720726f6c6520000000000000000000000000000000601791840191820152835161138b816028840160208801611203565b01602801949350505050565b60208152600082518060208401526113b6816040850160208701611203565b601f01601f19169190910160400192915050565b8082028115828204841417610474576104746111d9565b80820180821115610474576104746111d9565b634e487b7160e01b600052604160045260246000fd5b600081611419576114196111d9565b50600019019056fea2646970667358221220d9f2bae3059a195fbe106eecfa17d7818ae58f76c3efa4ab6bd7920ebaaf271664736f6c63430008130033", "devdoc": { "author": "The Swarm Authors.", "details": "The price oracle contract emits a price feed using events.", @@ -560,7 +597,7 @@ "label": "postageStamp", "offset": 0, "slot": "1", - "type": "t_contract(IPostageStamp)11149" + "type": "t_contract(IPostageStamp)11359" }, { "astId": 6719, @@ -649,7 +686,7 @@ "label": "bytes32", "numberOfBytes": "32" }, - "t_contract(IPostageStamp)11149": { + "t_contract(IPostageStamp)11359": { "encoding": "inplace", "label": "contract IPostageStamp", "numberOfBytes": "20" diff --git a/deployments/testnet/Redistribution.json b/deployments/testnet/Redistribution.json index c256132c..5657f76e 100644 --- a/deployments/testnet/Redistribution.json +++ b/deployments/testnet/Redistribution.json @@ -1,5 +1,5 @@ { - "address": "0xB648ad6EE25ad0EDF295E3cFf3799969B28A18D7", + "address": "0x18C415Ff11f05ae935Bc12caC0f4419440c60DE5", "abi": [ { "inputs": [ @@ -279,6 +279,12 @@ "internalType": "bytes32", "name": "overlay", "type": "bytes32" + }, + { + "indexed": false, + "internalType": "uint8", + "name": "height", + "type": "uint8" } ], "name": "Committed", @@ -342,6 +348,19 @@ "name": "Paused", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint16", + "name": "redundancyCount", + "type": "uint16" + } + ], + "name": "PriceAdjustmentSkipped", + "type": "event" + }, { "anonymous": false, "inputs": [ @@ -537,6 +556,19 @@ "name": "WinnerSelected", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "owner", + "type": "address" + } + ], + "name": "WithdrawFailed", + "type": "event" + }, { "anonymous": false, "inputs": [ @@ -958,6 +990,11 @@ "name": "revealed", "type": "bool" }, + { + "internalType": "uint8", + "name": "height", + "type": "uint8" + }, { "internalType": "uint256", "name": "stake", @@ -1530,22 +1567,22 @@ "type": "function" } ], - "transactionHash": "0xca54300fc2a58ae790fd930e2ec4dd5c9f0f9867e4b94c8ddb48a0f46a82f639", + "transactionHash": "0x3ffe66fb89cc8d13e1cc27f5495d089bc96fcd3111821b4015e5793d422147b9", "receipt": { "to": null, "from": "0xb1C7F17Ed88189Abf269Bf68A3B2Ed83C5276aAe", - "contractAddress": "0xB648ad6EE25ad0EDF295E3cFf3799969B28A18D7", - "transactionIndex": 157, - "gasUsed": "4224929", - "logsBloom": "0x00000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000800000000010000080000000000002000000000040000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000100000000000020000000000000000000000000000400000000000000000000000000000000000000", - "blockHash": "0xf9d527d0c0729e53acad8528713405e3dfa3650ea03d80a2038bc5194f640438", - "transactionHash": "0xca54300fc2a58ae790fd930e2ec4dd5c9f0f9867e4b94c8ddb48a0f46a82f639", + "contractAddress": "0x18C415Ff11f05ae935Bc12caC0f4419440c60DE5", + "transactionIndex": 40, + "gasUsed": "4394017", + "logsBloom": "0x00000004000000000000010000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000800000000010000000000000000002000000000040000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000100000000000020000000000000000000000000000000000000000000000000000000000000000000", + "blockHash": "0x96fcc9bc76d8a33d454b1bc29281326b624a3e658b2db3795a509a40fd093ecb", + "transactionHash": "0x3ffe66fb89cc8d13e1cc27f5495d089bc96fcd3111821b4015e5793d422147b9", "logs": [ { - "transactionIndex": 157, - "blockNumber": 6661233, - "transactionHash": "0xca54300fc2a58ae790fd930e2ec4dd5c9f0f9867e4b94c8ddb48a0f46a82f639", - "address": "0xB648ad6EE25ad0EDF295E3cFf3799969B28A18D7", + "transactionIndex": 40, + "blockNumber": 7036326, + "transactionHash": "0x3ffe66fb89cc8d13e1cc27f5495d089bc96fcd3111821b4015e5793d422147b9", + "address": "0x18C415Ff11f05ae935Bc12caC0f4419440c60DE5", "topics": [ "0x2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d", "0x0000000000000000000000000000000000000000000000000000000000000000", @@ -1553,25 +1590,25 @@ "0x000000000000000000000000b1c7f17ed88189abf269bf68a3b2ed83c5276aae" ], "data": "0x", - "logIndex": 167, - "blockHash": "0xf9d527d0c0729e53acad8528713405e3dfa3650ea03d80a2038bc5194f640438" + "logIndex": 57, + "blockHash": "0x96fcc9bc76d8a33d454b1bc29281326b624a3e658b2db3795a509a40fd093ecb" } ], - "blockNumber": 6661233, - "cumulativeGasUsed": "11938159", + "blockNumber": 7036326, + "cumulativeGasUsed": "8745119", "status": 1, "byzantium": true }, "args": [ - "0x5CF39e699b601c2EBc3e25b19Fd4102d8366b56F", + "0x4353A36f4376A273a65595Acd9bE6c63D90fC352", "0xcdfdC3752caaA826fE62531E0000C40546eC56A6", - "0xf19F9d88e963A61c735C1716F8A689Dc2887F463" + "0xC5241172f010AB24ff3eeC61B4c684E1A9482D2b" ], - "numDeployments": 8, - "solcInputHash": "61a68bd215ba2141fb06ecc444ca0734", - "metadata": "{\"compiler\":{\"version\":\"0.8.19+commit.7dd6d404\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"staking\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"postageContract\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"oracleContract\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[],\"name\":\"AlreadyClaimed\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"AlreadyCommitted\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"AlreadyRevealed\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"BatchDoesNotExist\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"BucketDiffers\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"CommitRoundNotStarted\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"CommitRoundOver\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"FirstRevealDone\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"uint8\",\"name\":\"\",\"type\":\"uint8\"},{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"InclusionProofFailed\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"IndexOutsideSet\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"InvalidSignatureLength\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"LastElementCheckFailed\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"MustStake2Rounds\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NoCommitsReceived\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NoMatchingCommit\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NoReveals\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NotAdmin\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NotClaimPhase\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NotCommitPhase\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NotMatchingOwner\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NotRevealPhase\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NotStaked\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"OnlyPauser\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"OutOfDepth\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"uint8\",\"name\":\"\",\"type\":\"uint8\"}],\"name\":\"OutOfDepthClaim\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"OutOfDepthReveal\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"PhaseLastBlock\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"RandomElementCheckFailed\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"trALast\",\"type\":\"bytes32\"}],\"name\":\"ReserveCheckFailed\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"SigRecoveryFailed\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"SocCalcNotMatching\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"SocVerificationFailed\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"WrongPhase\",\"type\":\"error\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"validChunkCount\",\"type\":\"uint256\"}],\"name\":\"ChunkCount\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"roundNumber\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"}],\"name\":\"Committed\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"_count\",\"type\":\"uint256\"}],\"name\":\"CountCommits\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"_count\",\"type\":\"uint256\"}],\"name\":\"CountReveals\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"roundNumber\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"anchor\",\"type\":\"bytes32\"}],\"name\":\"CurrentRevealAnchor\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"Paused\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"roundNumber\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"stake\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"stakeDensity\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"reserveCommitment\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint8\",\"name\":\"depth\",\"type\":\"uint8\"}],\"name\":\"Revealed\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"previousAdminRole\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"newAdminRole\",\"type\":\"bytes32\"}],\"name\":\"RoleAdminChanged\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"}],\"name\":\"RoleGranted\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"}],\"name\":\"RoleRevoked\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"hash\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint8\",\"name\":\"depth\",\"type\":\"uint8\"}],\"name\":\"TruthSelected\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"Unpaused\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"components\":[{\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"uint8\",\"name\":\"depth\",\"type\":\"uint8\"},{\"internalType\":\"uint256\",\"name\":\"stake\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"stakeDensity\",\"type\":\"uint256\"},{\"internalType\":\"bytes32\",\"name\":\"hash\",\"type\":\"bytes32\"}],\"indexed\":false,\"internalType\":\"struct Redistribution.Reveal\",\"name\":\"winner\",\"type\":\"tuple\"}],\"name\":\"WinnerSelected\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"indexInRC\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"chunkAddress\",\"type\":\"bytes32\"}],\"name\":\"transformedChunkAddressFromInclusionProof\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"DEFAULT_ADMIN_ROLE\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"OracleContract\",\"outputs\":[{\"internalType\":\"contract IPriceOracle\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"PostageContract\",\"outputs\":[{\"internalType\":\"contract IPostageStamp\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"Stakes\",\"outputs\":[{\"internalType\":\"contract IStakeRegistry\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"components\":[{\"internalType\":\"bytes32[]\",\"name\":\"proofSegments\",\"type\":\"bytes32[]\"},{\"internalType\":\"bytes32\",\"name\":\"proveSegment\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32[]\",\"name\":\"proofSegments2\",\"type\":\"bytes32[]\"},{\"internalType\":\"bytes32\",\"name\":\"proveSegment2\",\"type\":\"bytes32\"},{\"internalType\":\"uint64\",\"name\":\"chunkSpan\",\"type\":\"uint64\"},{\"internalType\":\"bytes32[]\",\"name\":\"proofSegments3\",\"type\":\"bytes32[]\"},{\"components\":[{\"internalType\":\"bytes\",\"name\":\"signature\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"postageId\",\"type\":\"bytes32\"},{\"internalType\":\"uint64\",\"name\":\"index\",\"type\":\"uint64\"},{\"internalType\":\"uint64\",\"name\":\"timeStamp\",\"type\":\"uint64\"}],\"internalType\":\"struct Redistribution.PostageProof\",\"name\":\"postageProof\",\"type\":\"tuple\"},{\"components\":[{\"internalType\":\"address\",\"name\":\"signer\",\"type\":\"address\"},{\"internalType\":\"bytes\",\"name\":\"signature\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"identifier\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"chunkAddr\",\"type\":\"bytes32\"}],\"internalType\":\"struct Redistribution.SOCProof[]\",\"name\":\"socProof\",\"type\":\"tuple[]\"}],\"internalType\":\"struct Redistribution.ChunkInclusionProof\",\"name\":\"entryProof1\",\"type\":\"tuple\"},{\"components\":[{\"internalType\":\"bytes32[]\",\"name\":\"proofSegments\",\"type\":\"bytes32[]\"},{\"internalType\":\"bytes32\",\"name\":\"proveSegment\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32[]\",\"name\":\"proofSegments2\",\"type\":\"bytes32[]\"},{\"internalType\":\"bytes32\",\"name\":\"proveSegment2\",\"type\":\"bytes32\"},{\"internalType\":\"uint64\",\"name\":\"chunkSpan\",\"type\":\"uint64\"},{\"internalType\":\"bytes32[]\",\"name\":\"proofSegments3\",\"type\":\"bytes32[]\"},{\"components\":[{\"internalType\":\"bytes\",\"name\":\"signature\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"postageId\",\"type\":\"bytes32\"},{\"internalType\":\"uint64\",\"name\":\"index\",\"type\":\"uint64\"},{\"internalType\":\"uint64\",\"name\":\"timeStamp\",\"type\":\"uint64\"}],\"internalType\":\"struct Redistribution.PostageProof\",\"name\":\"postageProof\",\"type\":\"tuple\"},{\"components\":[{\"internalType\":\"address\",\"name\":\"signer\",\"type\":\"address\"},{\"internalType\":\"bytes\",\"name\":\"signature\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"identifier\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"chunkAddr\",\"type\":\"bytes32\"}],\"internalType\":\"struct Redistribution.SOCProof[]\",\"name\":\"socProof\",\"type\":\"tuple[]\"}],\"internalType\":\"struct Redistribution.ChunkInclusionProof\",\"name\":\"entryProof2\",\"type\":\"tuple\"},{\"components\":[{\"internalType\":\"bytes32[]\",\"name\":\"proofSegments\",\"type\":\"bytes32[]\"},{\"internalType\":\"bytes32\",\"name\":\"proveSegment\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32[]\",\"name\":\"proofSegments2\",\"type\":\"bytes32[]\"},{\"internalType\":\"bytes32\",\"name\":\"proveSegment2\",\"type\":\"bytes32\"},{\"internalType\":\"uint64\",\"name\":\"chunkSpan\",\"type\":\"uint64\"},{\"internalType\":\"bytes32[]\",\"name\":\"proofSegments3\",\"type\":\"bytes32[]\"},{\"components\":[{\"internalType\":\"bytes\",\"name\":\"signature\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"postageId\",\"type\":\"bytes32\"},{\"internalType\":\"uint64\",\"name\":\"index\",\"type\":\"uint64\"},{\"internalType\":\"uint64\",\"name\":\"timeStamp\",\"type\":\"uint64\"}],\"internalType\":\"struct Redistribution.PostageProof\",\"name\":\"postageProof\",\"type\":\"tuple\"},{\"components\":[{\"internalType\":\"address\",\"name\":\"signer\",\"type\":\"address\"},{\"internalType\":\"bytes\",\"name\":\"signature\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"identifier\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"chunkAddr\",\"type\":\"bytes32\"}],\"internalType\":\"struct Redistribution.SOCProof[]\",\"name\":\"socProof\",\"type\":\"tuple[]\"}],\"internalType\":\"struct Redistribution.ChunkInclusionProof\",\"name\":\"entryProofLast\",\"type\":\"tuple\"}],\"name\":\"claim\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"_obfuscatedHash\",\"type\":\"bytes32\"},{\"internalType\":\"uint64\",\"name\":\"_roundNumber\",\"type\":\"uint64\"}],\"name\":\"commit\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentClaimRound\",\"outputs\":[{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentCommitRound\",\"outputs\":[{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"currentCommits\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"revealed\",\"type\":\"bool\"},{\"internalType\":\"uint256\",\"name\":\"stake\",\"type\":\"uint256\"},{\"internalType\":\"bytes32\",\"name\":\"obfuscatedHash\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"revealIndex\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentMinimumDepth\",\"outputs\":[{\"internalType\":\"uint8\",\"name\":\"\",\"type\":\"uint8\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentPhaseClaim\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentPhaseCommit\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentPhaseReveal\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentRevealRound\",\"outputs\":[{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"currentReveals\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"uint8\",\"name\":\"depth\",\"type\":\"uint8\"},{\"internalType\":\"uint256\",\"name\":\"stake\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"stakeDensity\",\"type\":\"uint256\"},{\"internalType\":\"bytes32\",\"name\":\"hash\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentRound\",\"outputs\":[{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentRoundAnchor\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"returnVal\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentRoundReveals\",\"outputs\":[{\"components\":[{\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"uint8\",\"name\":\"depth\",\"type\":\"uint8\"},{\"internalType\":\"uint256\",\"name\":\"stake\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"stakeDensity\",\"type\":\"uint256\"},{\"internalType\":\"bytes32\",\"name\":\"hash\",\"type\":\"bytes32\"}],\"internalType\":\"struct Redistribution.Reveal[]\",\"name\":\"\",\"type\":\"tuple[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentSeed\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"}],\"name\":\"getRoleAdmin\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"grantRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"hasRole\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"A\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"B\",\"type\":\"bytes32\"},{\"internalType\":\"uint8\",\"name\":\"minimum\",\"type\":\"uint8\"}],\"name\":\"inProximity\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"pure\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_owner\",\"type\":\"address\"},{\"internalType\":\"uint8\",\"name\":\"_depth\",\"type\":\"uint8\"}],\"name\":\"isParticipatingInUpcomingRound\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"_overlay\",\"type\":\"bytes32\"}],\"name\":\"isWinner\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"nextSeed\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"pause\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"paused\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"renounceRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint8\",\"name\":\"_depth\",\"type\":\"uint8\"},{\"internalType\":\"bytes32\",\"name\":\"_hash\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"_revealNonce\",\"type\":\"bytes32\"}],\"name\":\"reveal\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"revokeRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint8\",\"name\":\"_penaltyMultiplierDisagreement\",\"type\":\"uint8\"},{\"internalType\":\"uint8\",\"name\":\"_penaltyMultiplierNonRevealed\",\"type\":\"uint8\"},{\"internalType\":\"uint8\",\"name\":\"_penaltyRandomFactor\",\"type\":\"uint8\"}],\"name\":\"setFreezingParams\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_sampleMaxValue\",\"type\":\"uint256\"}],\"name\":\"setSampleMaxValue\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes4\",\"name\":\"interfaceId\",\"type\":\"bytes4\"}],\"name\":\"supportsInterface\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"unPause\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"winner\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"uint8\",\"name\":\"depth\",\"type\":\"uint8\"},{\"internalType\":\"uint256\",\"name\":\"stake\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"stakeDensity\",\"type\":\"uint256\"},{\"internalType\":\"bytes32\",\"name\":\"hash\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"_overlay\",\"type\":\"bytes32\"},{\"internalType\":\"uint8\",\"name\":\"_depth\",\"type\":\"uint8\"},{\"internalType\":\"bytes32\",\"name\":\"_hash\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"revealNonce\",\"type\":\"bytes32\"}],\"name\":\"wrapCommit\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"pure\",\"type\":\"function\"}],\"devdoc\":{\"author\":\"The Swarm Authors\",\"details\":\"Implements a Schelling Co-ordination game to form consensus around the Reserve Commitment hash. This takes place in three phases: _commit_, _reveal_ and _claim_. A node, upon establishing that it _isParticipatingInUpcomingRound_, i.e. it's overlay falls within proximity order of its reported depth with the _currentRoundAnchor_, prepares a \\\"reserve commitment hash\\\" using the chunks it currently stores in its reserve and calculates the \\\"storage depth\\\" (see Bee for details). These values, if calculated honestly, and with the right chunks stored, should be the same for every node in a neighbourhood. This is the Schelling point. Each eligible node can then use these values, together with a random, single use, secret _revealNonce_ and their _overlay_ as the pre-image values for the obsfucated _commit_, using the _wrapCommit_ method. Once the _commit_ round has elapsed, participating nodes must provide the values used to calculate their obsfucated _commit_ hash, which, once verified for correctness and proximity to the anchor are retained in the _currentReveals_. Nodes that have committed but do not reveal the correct values used to create the pre-image will have their stake \\\"frozen\\\" for a period of rounds proportional to their reported depth. During the _reveal_ round, randomness is updated after every successful reveal. Once the reveal round is concluded, the _currentRoundAnchor_ is updated and users can determine if they will be eligible their overlay will be eligible for the next commit phase using _isParticipatingInUpcomingRound_. When the _reveal_ phase has been concluded, the claim phase can begin. At this point, the truth teller and winner are already determined. By calling _isWinner_, an applicant node can run the relevant logic to determine if they have been selected as the beneficiary of this round. When calling _claim_, the current pot from the PostageStamp contract is withdrawn and transferred to that beneficiaries address. Nodes that have revealed values that differ from the truth, have their stakes \\\"frozen\\\" for a period of rounds proportional to their reported depth.\",\"events\":{\"ChunkCount(uint256)\":{\"details\":\"Emit from Postagestamp contract valid chunk count at the end of claim\"},\"Committed(uint256,bytes32)\":{\"details\":\"Logs that an overlay has committed\"},\"CountCommits(uint256)\":{\"details\":\"Emits the number of commits being processed by the claim phase.\"},\"CountReveals(uint256)\":{\"details\":\"Emits the number of reveals being processed by the claim phase.\"},\"CurrentRevealAnchor(uint256,bytes32)\":{\"details\":\"Bytes32 anhor of current reveal round\"},\"Paused(address)\":{\"details\":\"Emitted when the pause is triggered by `account`.\"},\"Revealed(uint256,bytes32,uint256,uint256,bytes32,uint8)\":{\"details\":\"Logs that an overlay has revealed\"},\"RoleAdminChanged(bytes32,bytes32,bytes32)\":{\"details\":\"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._\"},\"RoleGranted(bytes32,address,address)\":{\"details\":\"Emitted when `account` is granted `role`. `sender` is the account that originated the contract call, an admin role bearer except when using {AccessControl-_setupRole}.\"},\"RoleRevoked(bytes32,address,address)\":{\"details\":\"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`)\"},\"TruthSelected(bytes32,uint8)\":{\"details\":\"Emitted when the truth oracle of a round is selected in the claim phase.\"},\"Unpaused(address)\":{\"details\":\"Emitted when the pause is lifted by `account`.\"},\"WinnerSelected((bytes32,address,uint8,uint256,uint256,bytes32))\":{\"details\":\"Emitted when the winner of a round is selected in the claim phase\"},\"transformedChunkAddressFromInclusionProof(uint256,bytes32)\":{\"details\":\"Logs for inclusion proof\"}},\"kind\":\"dev\",\"methods\":{\"commit(bytes32,uint64)\":{\"details\":\"If a node's overlay is _inProximity_(_depth_) of the _currentRoundAnchor_, that node may compute an _obfuscatedHash_ by providing their _overlay_, reported storage _depth_, reserve commitment _hash_ and a randomly generated, and secret _revealNonce_ to the _wrapCommit_ method.\",\"params\":{\"_obfuscatedHash\":\"The calculated hash resultant of the required pre-image values. and be derived from the same key pair as the message sender.\",\"_roundNumber\":\"Node needs to provide round number for which commit is valid\"}},\"constructor\":{\"params\":{\"oracleContract\":\"the address of the linked PriceOracle contract.\",\"postageContract\":\"the address of the linked PostageStamp contract.\",\"staking\":\"the address of the linked Staking contract.\"}},\"currentRoundAnchor()\":{\"details\":\"A node must be within proximity order of less than or equal to the storage depth they intend to report.\"},\"getRoleAdmin(bytes32)\":{\"details\":\"Returns the admin role that controls `role`. See {grantRole} and {revokeRole}. To change a role's admin, use {_setRoleAdmin}.\"},\"grantRole(bytes32,address)\":{\"details\":\"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.\"},\"hasRole(bytes32,address)\":{\"details\":\"Returns `true` if `account` has been granted `role`.\"},\"inProximity(bytes32,bytes32,uint8)\":{\"params\":{\"A\":\"An overlay address to compare.\",\"B\":\"An overlay address to compare.\",\"minimum\":\"Minimum proximity order.\"}},\"isParticipatingInUpcomingRound(address,uint8)\":{\"params\":{\"_depth\":\"The storage depth the applicant intends to report.\",\"_owner\":\"The address of the applicant from.\"}},\"isWinner(bytes32)\":{\"params\":{\"_overlay\":\"The overlay address of the applicant.\"}},\"pause()\":{\"details\":\"Pause the contract. The contract is provably stopped by renouncing the pauser role and the admin role after pausing, can only be called by the `PAUSER`\"},\"paused()\":{\"details\":\"Returns true if the contract is paused, and false otherwise.\"},\"renounceRole(bytes32,address)\":{\"details\":\"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.\"},\"reveal(uint8,bytes32,bytes32)\":{\"params\":{\"_depth\":\"The reported depth.\",\"_hash\":\"The reserve commitment hash.\",\"_revealNonce\":\"The nonce used to generate the commit that is being revealed.\"}},\"revokeRole(bytes32,address)\":{\"details\":\"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.\"},\"supportsInterface(bytes4)\":{\"details\":\"See {IERC165-supportsInterface}.\"},\"unPause()\":{\"details\":\"Unpause the contract, can only be called by the pauser when paused\"},\"wrapCommit(bytes32,uint8,bytes32,bytes32)\":{\"details\":\"_revealNonce_ must be randomly generated, used once and kept secret until the reveal phase.\",\"params\":{\"_depth\":\"The reported depth.\",\"_hash\":\"The reserve commitment hash.\",\"_overlay\":\"The overlay address of the applicant.\",\"revealNonce\":\"A random, single use, secret nonce.\"}}},\"title\":\"Redistribution contract\",\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{\"claim((bytes32[],bytes32,bytes32[],bytes32,uint64,bytes32[],(bytes,bytes32,uint64,uint64),(address,bytes,bytes32,bytes32)[]),(bytes32[],bytes32,bytes32[],bytes32,uint64,bytes32[],(bytes,bytes32,uint64,uint64),(address,bytes,bytes32,bytes32)[]),(bytes32[],bytes32,bytes32[],bytes32,uint64,bytes32[],(bytes,bytes32,uint64,uint64),(address,bytes,bytes32,bytes32)[]))\":{\"notice\":\"Helper function to get this round truth\"},\"commit(bytes32,uint64)\":{\"notice\":\"Begin application for a round if eligible. Commit a hashed value for which the pre-image will be subsequently revealed.\"},\"currentMinimumDepth()\":{\"notice\":\"Returns minimum depth reveal has to have to participate in this round\"},\"currentPhaseClaim()\":{\"notice\":\"Returns true if current block is during claim phase.\"},\"currentPhaseCommit()\":{\"notice\":\"Returns true if current block is during commit phase.\"},\"currentPhaseReveal()\":{\"notice\":\"Returns true if current block is during reveal phase.\"},\"currentRound()\":{\"notice\":\"The number of the current round.\"},\"currentRoundAnchor()\":{\"notice\":\"The anchor used to determine eligibility for the current round.\"},\"currentRoundReveals()\":{\"notice\":\"Returns true if current block is during reveal phase.\"},\"currentSeed()\":{\"notice\":\"Returns the current random seed which is used to determine later utilised random numbers. If rounds have elapsed without reveals, hash the seed with an incremented nonce to produce a new random seed and hence a new round anchor.\"},\"inProximity(bytes32,bytes32,uint8)\":{\"notice\":\"Returns true if an overlay address _A_ is within proximity order _minimum_ of _B_.\"},\"isParticipatingInUpcomingRound(address,uint8)\":{\"notice\":\"Determine if a the owner of a given overlay can participate in the upcoming round.\"},\"isWinner(bytes32)\":{\"notice\":\"Determine if a the owner of a given overlay will be the beneficiary of the claim phase.\"},\"nextSeed()\":{\"notice\":\"Returns the seed which will become current once the next commit phase begins. Used to determine what the next round's anchor will be.\"},\"reveal(uint8,bytes32,bytes32)\":{\"notice\":\"Reveal the pre-image values used to generate commit provided during this round's commit phase.\"},\"setFreezingParams(uint8,uint8,uint8)\":{\"notice\":\"Set freezing parameters\"},\"setSampleMaxValue(uint256)\":{\"notice\":\"changes the max sample value used for reserve estimation\"},\"wrapCommit(bytes32,uint8,bytes32,bytes32)\":{\"notice\":\"Hash the pre-image values to the obsfucated hash.\"}},\"version\":1}},\"settings\":{\"compilationTarget\":{\"src/Redistribution.sol\":\"Redistribution\"},\"evmVersion\":\"paris\",\"libraries\":{\":__CACHE_BREAKER__\":\"0x00000000d41867734bbee4c6863d9255b2b06ac1\"},\"metadata\":{\"bytecodeHash\":\"ipfs\",\"useLiteralContent\":true},\"optimizer\":{\"enabled\":true,\"runs\":1000},\"remappings\":[]},\"sources\":{\"@openzeppelin/contracts/access/AccessControl.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (access/AccessControl.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./IAccessControl.sol\\\";\\nimport \\\"../utils/Context.sol\\\";\\nimport \\\"../utils/Strings.sol\\\";\\nimport \\\"../utils/introspection/ERC165.sol\\\";\\n\\n/**\\n * @dev Contract module that allows children to implement role-based access\\n * control mechanisms. This is a lightweight version that doesn't allow enumerating role\\n * members except through off-chain means by accessing the contract event logs. Some\\n * applications may benefit from on-chain enumerability, for those cases see\\n * {AccessControlEnumerable}.\\n *\\n * Roles are referred to by their `bytes32` identifier. These should be exposed\\n * in the external API and be unique. The best way to achieve this is by\\n * using `public constant` hash digests:\\n *\\n * ```\\n * bytes32 public constant MY_ROLE = keccak256(\\\"MY_ROLE\\\");\\n * ```\\n *\\n * Roles can be used to represent a set of permissions. To restrict access to a\\n * function call, use {hasRole}:\\n *\\n * ```\\n * function foo() public {\\n * require(hasRole(MY_ROLE, msg.sender));\\n * ...\\n * }\\n * ```\\n *\\n * Roles can be granted and revoked dynamically via the {grantRole} and\\n * {revokeRole} functions. Each role has an associated admin role, and only\\n * accounts that have a role's admin role can call {grantRole} and {revokeRole}.\\n *\\n * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means\\n * that only accounts with this role will be able to grant or revoke other\\n * roles. More complex role relationships can be created by using\\n * {_setRoleAdmin}.\\n *\\n * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to\\n * grant and revoke this role. Extra precautions should be taken to secure\\n * accounts that have been granted it.\\n */\\nabstract contract AccessControl is Context, IAccessControl, ERC165 {\\n struct RoleData {\\n mapping(address => bool) members;\\n bytes32 adminRole;\\n }\\n\\n mapping(bytes32 => RoleData) private _roles;\\n\\n bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;\\n\\n /**\\n * @dev Modifier that checks that an account has a specific role. Reverts\\n * with a standardized message including the required role.\\n *\\n * The format of the revert reason is given by the following regular expression:\\n *\\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\\n *\\n * _Available since v4.1._\\n */\\n modifier onlyRole(bytes32 role) {\\n _checkRole(role);\\n _;\\n }\\n\\n /**\\n * @dev See {IERC165-supportsInterface}.\\n */\\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);\\n }\\n\\n /**\\n * @dev Returns `true` if `account` has been granted `role`.\\n */\\n function hasRole(bytes32 role, address account) public view virtual override returns (bool) {\\n return _roles[role].members[account];\\n }\\n\\n /**\\n * @dev Revert with a standard message if `_msgSender()` is missing `role`.\\n * Overriding this function changes the behavior of the {onlyRole} modifier.\\n *\\n * Format of the revert message is described in {_checkRole}.\\n *\\n * _Available since v4.6._\\n */\\n function _checkRole(bytes32 role) internal view virtual {\\n _checkRole(role, _msgSender());\\n }\\n\\n /**\\n * @dev Revert with a standard message if `account` is missing `role`.\\n *\\n * The format of the revert reason is given by the following regular expression:\\n *\\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\\n */\\n function _checkRole(bytes32 role, address account) internal view virtual {\\n if (!hasRole(role, account)) {\\n revert(\\n string(\\n abi.encodePacked(\\n \\\"AccessControl: account \\\",\\n Strings.toHexString(account),\\n \\\" is missing role \\\",\\n Strings.toHexString(uint256(role), 32)\\n )\\n )\\n );\\n }\\n }\\n\\n /**\\n * @dev Returns the admin role that controls `role`. See {grantRole} and\\n * {revokeRole}.\\n *\\n * To change a role's admin, use {_setRoleAdmin}.\\n */\\n function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {\\n return _roles[role].adminRole;\\n }\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * If `account` had not been already granted `role`, emits a {RoleGranted}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n *\\n * May emit a {RoleGranted} event.\\n */\\n function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\\n _grantRole(role, account);\\n }\\n\\n /**\\n * @dev Revokes `role` from `account`.\\n *\\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n *\\n * May emit a {RoleRevoked} event.\\n */\\n function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\\n _revokeRole(role, account);\\n }\\n\\n /**\\n * @dev Revokes `role` from the calling account.\\n *\\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\\n * purpose is to provide a mechanism for accounts to lose their privileges\\n * if they are compromised (such as when a trusted device is misplaced).\\n *\\n * If the calling account had been revoked `role`, emits a {RoleRevoked}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must be `account`.\\n *\\n * May emit a {RoleRevoked} event.\\n */\\n function renounceRole(bytes32 role, address account) public virtual override {\\n require(account == _msgSender(), \\\"AccessControl: can only renounce roles for self\\\");\\n\\n _revokeRole(role, account);\\n }\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * If `account` had not been already granted `role`, emits a {RoleGranted}\\n * event. Note that unlike {grantRole}, this function doesn't perform any\\n * checks on the calling account.\\n *\\n * May emit a {RoleGranted} event.\\n *\\n * [WARNING]\\n * ====\\n * This function should only be called from the constructor when setting\\n * up the initial roles for the system.\\n *\\n * Using this function in any other way is effectively circumventing the admin\\n * system imposed by {AccessControl}.\\n * ====\\n *\\n * NOTE: This function is deprecated in favor of {_grantRole}.\\n */\\n function _setupRole(bytes32 role, address account) internal virtual {\\n _grantRole(role, account);\\n }\\n\\n /**\\n * @dev Sets `adminRole` as ``role``'s admin role.\\n *\\n * Emits a {RoleAdminChanged} event.\\n */\\n function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {\\n bytes32 previousAdminRole = getRoleAdmin(role);\\n _roles[role].adminRole = adminRole;\\n emit RoleAdminChanged(role, previousAdminRole, adminRole);\\n }\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * Internal function without access restriction.\\n *\\n * May emit a {RoleGranted} event.\\n */\\n function _grantRole(bytes32 role, address account) internal virtual {\\n if (!hasRole(role, account)) {\\n _roles[role].members[account] = true;\\n emit RoleGranted(role, account, _msgSender());\\n }\\n }\\n\\n /**\\n * @dev Revokes `role` from `account`.\\n *\\n * Internal function without access restriction.\\n *\\n * May emit a {RoleRevoked} event.\\n */\\n function _revokeRole(bytes32 role, address account) internal virtual {\\n if (hasRole(role, account)) {\\n _roles[role].members[account] = false;\\n emit RoleRevoked(role, account, _msgSender());\\n }\\n }\\n}\\n\",\"keccak256\":\"0x67e3daf189111d6d5b0464ed09cf9f0605a22c4b965a7fcecd707101faff008a\",\"license\":\"MIT\"},\"@openzeppelin/contracts/access/IAccessControl.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev External interface of AccessControl declared to support ERC165 detection.\\n */\\ninterface IAccessControl {\\n /**\\n * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`\\n *\\n * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite\\n * {RoleAdminChanged} not being emitted signaling this.\\n *\\n * _Available since v3.1._\\n */\\n event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);\\n\\n /**\\n * @dev Emitted when `account` is granted `role`.\\n *\\n * `sender` is the account that originated the contract call, an admin role\\n * bearer except when using {AccessControl-_setupRole}.\\n */\\n event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);\\n\\n /**\\n * @dev Emitted when `account` is revoked `role`.\\n *\\n * `sender` is the account that originated the contract call:\\n * - if using `revokeRole`, it is the admin role bearer\\n * - if using `renounceRole`, it is the role bearer (i.e. `account`)\\n */\\n event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);\\n\\n /**\\n * @dev Returns `true` if `account` has been granted `role`.\\n */\\n function hasRole(bytes32 role, address account) external view returns (bool);\\n\\n /**\\n * @dev Returns the admin role that controls `role`. See {grantRole} and\\n * {revokeRole}.\\n *\\n * To change a role's admin, use {AccessControl-_setRoleAdmin}.\\n */\\n function getRoleAdmin(bytes32 role) external view returns (bytes32);\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * If `account` had not been already granted `role`, emits a {RoleGranted}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n */\\n function grantRole(bytes32 role, address account) external;\\n\\n /**\\n * @dev Revokes `role` from `account`.\\n *\\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n */\\n function revokeRole(bytes32 role, address account) external;\\n\\n /**\\n * @dev Revokes `role` from the calling account.\\n *\\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\\n * purpose is to provide a mechanism for accounts to lose their privileges\\n * if they are compromised (such as when a trusted device is misplaced).\\n *\\n * If the calling account had been granted `role`, emits a {RoleRevoked}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must be `account`.\\n */\\n function renounceRole(bytes32 role, address account) external;\\n}\\n\",\"keccak256\":\"0x59ce320a585d7e1f163cd70390a0ef2ff9cec832e2aa544293a00692465a7a57\",\"license\":\"MIT\"},\"@openzeppelin/contracts/security/Pausable.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"../utils/Context.sol\\\";\\n\\n/**\\n * @dev Contract module which allows children to implement an emergency stop\\n * mechanism that can be triggered by an authorized account.\\n *\\n * This module is used through inheritance. It will make available the\\n * modifiers `whenNotPaused` and `whenPaused`, which can be applied to\\n * the functions of your contract. Note that they will not be pausable by\\n * simply including this module, only once the modifiers are put in place.\\n */\\nabstract contract Pausable is Context {\\n /**\\n * @dev Emitted when the pause is triggered by `account`.\\n */\\n event Paused(address account);\\n\\n /**\\n * @dev Emitted when the pause is lifted by `account`.\\n */\\n event Unpaused(address account);\\n\\n bool private _paused;\\n\\n /**\\n * @dev Initializes the contract in unpaused state.\\n */\\n constructor() {\\n _paused = false;\\n }\\n\\n /**\\n * @dev Modifier to make a function callable only when the contract is not paused.\\n *\\n * Requirements:\\n *\\n * - The contract must not be paused.\\n */\\n modifier whenNotPaused() {\\n _requireNotPaused();\\n _;\\n }\\n\\n /**\\n * @dev Modifier to make a function callable only when the contract is paused.\\n *\\n * Requirements:\\n *\\n * - The contract must be paused.\\n */\\n modifier whenPaused() {\\n _requirePaused();\\n _;\\n }\\n\\n /**\\n * @dev Returns true if the contract is paused, and false otherwise.\\n */\\n function paused() public view virtual returns (bool) {\\n return _paused;\\n }\\n\\n /**\\n * @dev Throws if the contract is paused.\\n */\\n function _requireNotPaused() internal view virtual {\\n require(!paused(), \\\"Pausable: paused\\\");\\n }\\n\\n /**\\n * @dev Throws if the contract is not paused.\\n */\\n function _requirePaused() internal view virtual {\\n require(paused(), \\\"Pausable: not paused\\\");\\n }\\n\\n /**\\n * @dev Triggers stopped state.\\n *\\n * Requirements:\\n *\\n * - The contract must not be paused.\\n */\\n function _pause() internal virtual whenNotPaused {\\n _paused = true;\\n emit Paused(_msgSender());\\n }\\n\\n /**\\n * @dev Returns to normal state.\\n *\\n * Requirements:\\n *\\n * - The contract must be paused.\\n */\\n function _unpause() internal virtual whenPaused {\\n _paused = false;\\n emit Unpaused(_msgSender());\\n }\\n}\\n\",\"keccak256\":\"0x0849d93b16c9940beb286a7864ed02724b248b93e0d80ef6355af5ef15c64773\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/Context.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Provides information about the current execution context, including the\\n * sender of the transaction and its data. While these are generally available\\n * via msg.sender and msg.data, they should not be accessed in such a direct\\n * manner, since when dealing with meta-transactions the account sending and\\n * paying for execution may not be the actual sender (as far as an application\\n * is concerned).\\n *\\n * This contract is only required for intermediate, library-like contracts.\\n */\\nabstract contract Context {\\n function _msgSender() internal view virtual returns (address) {\\n return msg.sender;\\n }\\n\\n function _msgData() internal view virtual returns (bytes calldata) {\\n return msg.data;\\n }\\n}\\n\",\"keccak256\":\"0xe2e337e6dde9ef6b680e07338c493ebea1b5fd09b43424112868e9cc1706bca7\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/Strings.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./math/Math.sol\\\";\\n\\n/**\\n * @dev String operations.\\n */\\nlibrary Strings {\\n bytes16 private constant _SYMBOLS = \\\"0123456789abcdef\\\";\\n uint8 private constant _ADDRESS_LENGTH = 20;\\n\\n /**\\n * @dev Converts a `uint256` to its ASCII `string` decimal representation.\\n */\\n function toString(uint256 value) internal pure returns (string memory) {\\n unchecked {\\n uint256 length = Math.log10(value) + 1;\\n string memory buffer = new string(length);\\n uint256 ptr;\\n /// @solidity memory-safe-assembly\\n assembly {\\n ptr := add(buffer, add(32, length))\\n }\\n while (true) {\\n ptr--;\\n /// @solidity memory-safe-assembly\\n assembly {\\n mstore8(ptr, byte(mod(value, 10), _SYMBOLS))\\n }\\n value /= 10;\\n if (value == 0) break;\\n }\\n return buffer;\\n }\\n }\\n\\n /**\\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\\n */\\n function toHexString(uint256 value) internal pure returns (string memory) {\\n unchecked {\\n return toHexString(value, Math.log256(value) + 1);\\n }\\n }\\n\\n /**\\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\\n */\\n function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\\n bytes memory buffer = new bytes(2 * length + 2);\\n buffer[0] = \\\"0\\\";\\n buffer[1] = \\\"x\\\";\\n for (uint256 i = 2 * length + 1; i > 1; --i) {\\n buffer[i] = _SYMBOLS[value & 0xf];\\n value >>= 4;\\n }\\n require(value == 0, \\\"Strings: hex length insufficient\\\");\\n return string(buffer);\\n }\\n\\n /**\\n * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.\\n */\\n function toHexString(address addr) internal pure returns (string memory) {\\n return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);\\n }\\n}\\n\",\"keccak256\":\"0xa4d1d62251f8574deb032a35fc948386a9b4de74b812d4f545a1ac120486b48a\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/introspection/ERC165.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./IERC165.sol\\\";\\n\\n/**\\n * @dev Implementation of the {IERC165} interface.\\n *\\n * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check\\n * for the additional interface id that will be supported. For example:\\n *\\n * ```solidity\\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\\n * }\\n * ```\\n *\\n * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.\\n */\\nabstract contract ERC165 is IERC165 {\\n /**\\n * @dev See {IERC165-supportsInterface}.\\n */\\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n return interfaceId == type(IERC165).interfaceId;\\n }\\n}\\n\",\"keccak256\":\"0xd10975de010d89fd1c78dc5e8a9a7e7f496198085c151648f20cba166b32582b\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/introspection/IERC165.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Interface of the ERC165 standard, as defined in the\\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\\n *\\n * Implementers can declare support of contract interfaces, which can then be\\n * queried by others ({ERC165Checker}).\\n *\\n * For an implementation, see {ERC165}.\\n */\\ninterface IERC165 {\\n /**\\n * @dev Returns true if this contract implements the interface defined by\\n * `interfaceId`. See the corresponding\\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\\n * to learn more about how these ids are created.\\n *\\n * This function call must use less than 30 000 gas.\\n */\\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\\n}\\n\",\"keccak256\":\"0x447a5f3ddc18419d41ff92b3773fb86471b1db25773e07f877f548918a185bf1\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/math/Math.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Standard math utilities missing in the Solidity language.\\n */\\nlibrary Math {\\n enum Rounding {\\n Down, // Toward negative infinity\\n Up, // Toward infinity\\n Zero // Toward zero\\n }\\n\\n /**\\n * @dev Returns the largest of two numbers.\\n */\\n function max(uint256 a, uint256 b) internal pure returns (uint256) {\\n return a > b ? a : b;\\n }\\n\\n /**\\n * @dev Returns the smallest of two numbers.\\n */\\n function min(uint256 a, uint256 b) internal pure returns (uint256) {\\n return a < b ? a : b;\\n }\\n\\n /**\\n * @dev Returns the average of two numbers. The result is rounded towards\\n * zero.\\n */\\n function average(uint256 a, uint256 b) internal pure returns (uint256) {\\n // (a + b) / 2 can overflow.\\n return (a & b) + (a ^ b) / 2;\\n }\\n\\n /**\\n * @dev Returns the ceiling of the division of two numbers.\\n *\\n * This differs from standard division with `/` in that it rounds up instead\\n * of rounding down.\\n */\\n function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {\\n // (a + b - 1) / b can overflow on addition, so we distribute.\\n return a == 0 ? 0 : (a - 1) / b + 1;\\n }\\n\\n /**\\n * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0\\n * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)\\n * with further edits by Uniswap Labs also under MIT license.\\n */\\n function mulDiv(\\n uint256 x,\\n uint256 y,\\n uint256 denominator\\n ) internal pure returns (uint256 result) {\\n unchecked {\\n // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use\\n // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256\\n // variables such that product = prod1 * 2^256 + prod0.\\n uint256 prod0; // Least significant 256 bits of the product\\n uint256 prod1; // Most significant 256 bits of the product\\n assembly {\\n let mm := mulmod(x, y, not(0))\\n prod0 := mul(x, y)\\n prod1 := sub(sub(mm, prod0), lt(mm, prod0))\\n }\\n\\n // Handle non-overflow cases, 256 by 256 division.\\n if (prod1 == 0) {\\n return prod0 / denominator;\\n }\\n\\n // Make sure the result is less than 2^256. Also prevents denominator == 0.\\n require(denominator > prod1);\\n\\n ///////////////////////////////////////////////\\n // 512 by 256 division.\\n ///////////////////////////////////////////////\\n\\n // Make division exact by subtracting the remainder from [prod1 prod0].\\n uint256 remainder;\\n assembly {\\n // Compute remainder using mulmod.\\n remainder := mulmod(x, y, denominator)\\n\\n // Subtract 256 bit number from 512 bit number.\\n prod1 := sub(prod1, gt(remainder, prod0))\\n prod0 := sub(prod0, remainder)\\n }\\n\\n // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.\\n // See https://cs.stackexchange.com/q/138556/92363.\\n\\n // Does not overflow because the denominator cannot be zero at this stage in the function.\\n uint256 twos = denominator & (~denominator + 1);\\n assembly {\\n // Divide denominator by twos.\\n denominator := div(denominator, twos)\\n\\n // Divide [prod1 prod0] by twos.\\n prod0 := div(prod0, twos)\\n\\n // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.\\n twos := add(div(sub(0, twos), twos), 1)\\n }\\n\\n // Shift in bits from prod1 into prod0.\\n prod0 |= prod1 * twos;\\n\\n // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such\\n // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for\\n // four bits. That is, denominator * inv = 1 mod 2^4.\\n uint256 inverse = (3 * denominator) ^ 2;\\n\\n // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works\\n // in modular arithmetic, doubling the correct bits in each step.\\n inverse *= 2 - denominator * inverse; // inverse mod 2^8\\n inverse *= 2 - denominator * inverse; // inverse mod 2^16\\n inverse *= 2 - denominator * inverse; // inverse mod 2^32\\n inverse *= 2 - denominator * inverse; // inverse mod 2^64\\n inverse *= 2 - denominator * inverse; // inverse mod 2^128\\n inverse *= 2 - denominator * inverse; // inverse mod 2^256\\n\\n // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.\\n // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is\\n // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1\\n // is no longer required.\\n result = prod0 * inverse;\\n return result;\\n }\\n }\\n\\n /**\\n * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.\\n */\\n function mulDiv(\\n uint256 x,\\n uint256 y,\\n uint256 denominator,\\n Rounding rounding\\n ) internal pure returns (uint256) {\\n uint256 result = mulDiv(x, y, denominator);\\n if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {\\n result += 1;\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.\\n *\\n * Inspired by Henry S. Warren, Jr.'s \\\"Hacker's Delight\\\" (Chapter 11).\\n */\\n function sqrt(uint256 a) internal pure returns (uint256) {\\n if (a == 0) {\\n return 0;\\n }\\n\\n // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.\\n //\\n // We know that the \\\"msb\\\" (most significant bit) of our target number `a` is a power of 2 such that we have\\n // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.\\n //\\n // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`\\n // \\u2192 `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`\\n // \\u2192 `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`\\n //\\n // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.\\n uint256 result = 1 << (log2(a) >> 1);\\n\\n // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,\\n // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at\\n // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision\\n // into the expected uint128 result.\\n unchecked {\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n return min(result, a / result);\\n }\\n }\\n\\n /**\\n * @notice Calculates sqrt(a), following the selected rounding direction.\\n */\\n function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = sqrt(a);\\n return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);\\n }\\n }\\n\\n /**\\n * @dev Return the log in base 2, rounded down, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log2(uint256 value) internal pure returns (uint256) {\\n uint256 result = 0;\\n unchecked {\\n if (value >> 128 > 0) {\\n value >>= 128;\\n result += 128;\\n }\\n if (value >> 64 > 0) {\\n value >>= 64;\\n result += 64;\\n }\\n if (value >> 32 > 0) {\\n value >>= 32;\\n result += 32;\\n }\\n if (value >> 16 > 0) {\\n value >>= 16;\\n result += 16;\\n }\\n if (value >> 8 > 0) {\\n value >>= 8;\\n result += 8;\\n }\\n if (value >> 4 > 0) {\\n value >>= 4;\\n result += 4;\\n }\\n if (value >> 2 > 0) {\\n value >>= 2;\\n result += 2;\\n }\\n if (value >> 1 > 0) {\\n result += 1;\\n }\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Return the log in base 2, following the selected rounding direction, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = log2(value);\\n return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);\\n }\\n }\\n\\n /**\\n * @dev Return the log in base 10, rounded down, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log10(uint256 value) internal pure returns (uint256) {\\n uint256 result = 0;\\n unchecked {\\n if (value >= 10**64) {\\n value /= 10**64;\\n result += 64;\\n }\\n if (value >= 10**32) {\\n value /= 10**32;\\n result += 32;\\n }\\n if (value >= 10**16) {\\n value /= 10**16;\\n result += 16;\\n }\\n if (value >= 10**8) {\\n value /= 10**8;\\n result += 8;\\n }\\n if (value >= 10**4) {\\n value /= 10**4;\\n result += 4;\\n }\\n if (value >= 10**2) {\\n value /= 10**2;\\n result += 2;\\n }\\n if (value >= 10**1) {\\n result += 1;\\n }\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = log10(value);\\n return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);\\n }\\n }\\n\\n /**\\n * @dev Return the log in base 256, rounded down, of a positive value.\\n * Returns 0 if given 0.\\n *\\n * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.\\n */\\n function log256(uint256 value) internal pure returns (uint256) {\\n uint256 result = 0;\\n unchecked {\\n if (value >> 128 > 0) {\\n value >>= 128;\\n result += 16;\\n }\\n if (value >> 64 > 0) {\\n value >>= 64;\\n result += 8;\\n }\\n if (value >> 32 > 0) {\\n value >>= 32;\\n result += 4;\\n }\\n if (value >> 16 > 0) {\\n value >>= 16;\\n result += 2;\\n }\\n if (value >> 8 > 0) {\\n result += 1;\\n }\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = log256(value);\\n return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);\\n }\\n }\\n}\\n\",\"keccak256\":\"0xa1e8e83cd0087785df04ac79fb395d9f3684caeaf973d9e2c71caef723a3a5d6\",\"license\":\"MIT\"},\"src/Redistribution.sol\":{\"content\":\"// SPDX-License-Identifier: BSD-3-Clause\\npragma solidity ^0.8.19;\\nimport \\\"@openzeppelin/contracts/access/AccessControl.sol\\\";\\nimport \\\"@openzeppelin/contracts/security/Pausable.sol\\\";\\nimport \\\"./Util/TransformedChunkProof.sol\\\";\\nimport \\\"./Util/ChunkProof.sol\\\";\\nimport \\\"./Util/Signatures.sol\\\";\\nimport \\\"./interface/IPostageStamp.sol\\\";\\n\\ninterface IPriceOracle {\\n function adjustPrice(uint16 redundancy) external;\\n}\\n\\ninterface IStakeRegistry {\\n struct Stake {\\n bytes32 overlay;\\n uint256 stakeAmount;\\n uint256 lastUpdatedBlockNumber;\\n }\\n\\n function freezeDeposit(address _owner, uint256 _time) external;\\n\\n function lastUpdatedBlockNumberOfAddress(address _owner) external view returns (uint256);\\n\\n function overlayOfAddress(address _owner) external view returns (bytes32);\\n\\n function nodeEffectiveStake(address _owner) external view returns (uint256);\\n}\\n\\n/**\\n * @title Redistribution contract\\n * @author The Swarm Authors\\n * @dev Implements a Schelling Co-ordination game to form consensus around the Reserve Commitment hash. This takes\\n * place in three phases: _commit_, _reveal_ and _claim_.\\n *\\n * A node, upon establishing that it _isParticipatingInUpcomingRound_, i.e. it's overlay falls within proximity order\\n * of its reported depth with the _currentRoundAnchor_, prepares a \\\"reserve commitment hash\\\" using the chunks\\n * it currently stores in its reserve and calculates the \\\"storage depth\\\" (see Bee for details). These values, if calculated\\n * honestly, and with the right chunks stored, should be the same for every node in a neighbourhood. This is the Schelling point.\\n * Each eligible node can then use these values, together with a random, single use, secret _revealNonce_ and their\\n * _overlay_ as the pre-image values for the obsfucated _commit_, using the _wrapCommit_ method.\\n *\\n * Once the _commit_ round has elapsed, participating nodes must provide the values used to calculate their obsfucated\\n * _commit_ hash, which, once verified for correctness and proximity to the anchor are retained in the _currentReveals_.\\n * Nodes that have committed but do not reveal the correct values used to create the pre-image will have their stake\\n * \\\"frozen\\\" for a period of rounds proportional to their reported depth.\\n *\\n * During the _reveal_ round, randomness is updated after every successful reveal. Once the reveal round is concluded,\\n * the _currentRoundAnchor_ is updated and users can determine if they will be eligible their overlay will be eligible\\n * for the next commit phase using _isParticipatingInUpcomingRound_.\\n *\\n * When the _reveal_ phase has been concluded, the claim phase can begin. At this point, the truth teller and winner\\n * are already determined. By calling _isWinner_, an applicant node can run the relevant logic to determine if they have\\n * been selected as the beneficiary of this round. When calling _claim_, the current pot from the PostageStamp contract\\n * is withdrawn and transferred to that beneficiaries address. Nodes that have revealed values that differ from the truth,\\n * have their stakes \\\"frozen\\\" for a period of rounds proportional to their reported depth.\\n */\\n\\ncontract Redistribution is AccessControl, Pausable {\\n // ----------------------------- Type declarations ------------------------------\\n\\n // An eligible user may commit to an _obfuscatedHash_ during the commit phase...\\n struct Commit {\\n bytes32 overlay;\\n address owner;\\n bool revealed;\\n uint256 stake;\\n bytes32 obfuscatedHash;\\n uint256 revealIndex;\\n }\\n // ...then provide the actual values that are the constituents of the pre-image of the _obfuscatedHash_\\n // during the reveal phase.\\n struct Reveal {\\n bytes32 overlay;\\n address owner;\\n uint8 depth;\\n uint256 stake;\\n uint256 stakeDensity;\\n bytes32 hash;\\n }\\n\\n struct ChunkInclusionProof {\\n bytes32[] proofSegments;\\n bytes32 proveSegment;\\n // _RCspan is known for RC 32*32\\n\\n // Inclusion proof of transformed address\\n bytes32[] proofSegments2;\\n bytes32 proveSegment2;\\n // proveSegmentIndex2 known from deterministic random selection;\\n uint64 chunkSpan;\\n bytes32[] proofSegments3;\\n // _proveSegment3 known, is equal _proveSegment2\\n // proveSegmentIndex3 know, is equal _proveSegmentIndex2;\\n // chunkSpan2 is equal to chunkSpan (as the data is the same)\\n //\\n PostageProof postageProof;\\n SOCProof[] socProof;\\n }\\n\\n struct SOCProof {\\n address signer; // signer Ethereum address to check against\\n bytes signature;\\n bytes32 identifier; //\\n bytes32 chunkAddr; // wrapped chunk address\\n }\\n\\n struct PostageProof {\\n bytes signature;\\n bytes32 postageId;\\n uint64 index;\\n uint64 timeStamp;\\n // address signer; it is provided by the postage stamp contract\\n // bytes32 chunkAddr; it equals to the proveSegment argument\\n }\\n\\n // The address of the linked PostageStamp contract.\\n IPostageStamp public PostageContract;\\n // The address of the linked PriceOracle contract.\\n IPriceOracle public OracleContract;\\n // The address of the linked Staking contract.\\n IStakeRegistry public Stakes;\\n\\n // Commits for the current round.\\n Commit[] public currentCommits;\\n // Reveals for the current round.\\n Reveal[] public currentReveals;\\n\\n // The current anchor that being processed for the reveal and claim phases of the round.\\n bytes32 private currentRevealRoundAnchor;\\n\\n // The current random value from which we will random.\\n // inputs for selection of the truth teller and beneficiary.\\n bytes32 private seed;\\n\\n // The number of the currently active round phases.\\n uint64 public currentCommitRound;\\n uint64 public currentRevealRound;\\n uint64 public currentClaimRound;\\n\\n // Settings for slashing and freezing\\n uint8 private penaltyMultiplierDisagreement = 1;\\n uint8 private penaltyMultiplierNonRevealed = 2;\\n uint8 private penaltyRandomFactor = 100; // Use 100 as value to ignore random factor in freezing penalty\\n\\n // alpha=0.097612 beta=0.0716570 k=16\\n uint256 private sampleMaxValue = 1284401000000000000000000000000000000000000000000000000000000000000000000;\\n\\n // The reveal of the winner of the last round.\\n Reveal public winner;\\n\\n // The length of a round in blocks.\\n uint256 private constant ROUND_LENGTH = 152;\\n\\n // Maximum value of the keccack256 hash.\\n bytes32 private constant MAX_H = 0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff;\\n\\n // ----------------------------- Events ------------------------------\\n\\n /**\\n * @dev Emitted when the winner of a round is selected in the claim phase\\n */\\n event WinnerSelected(Reveal winner);\\n\\n /**\\n * @dev Emitted when the truth oracle of a round is selected in the claim phase.\\n */\\n event TruthSelected(bytes32 hash, uint8 depth);\\n\\n // Next two events to be removed after testing phase pending some other usefulness being found.\\n /**\\n * @dev Emits the number of commits being processed by the claim phase.\\n */\\n event CountCommits(uint256 _count);\\n\\n /**\\n * @dev Emits the number of reveals being processed by the claim phase.\\n */\\n event CountReveals(uint256 _count);\\n\\n /**\\n * @dev Logs that an overlay has committed\\n */\\n event Committed(uint256 roundNumber, bytes32 overlay);\\n /**\\n * @dev Emit from Postagestamp contract valid chunk count at the end of claim\\n */\\n event ChunkCount(uint256 validChunkCount);\\n\\n /**\\n * @dev Bytes32 anhor of current reveal round\\n */\\n event CurrentRevealAnchor(uint256 roundNumber, bytes32 anchor);\\n\\n /**\\n * @dev Logs that an overlay has revealed\\n */\\n event Revealed(\\n uint256 roundNumber,\\n bytes32 overlay,\\n uint256 stake,\\n uint256 stakeDensity,\\n bytes32 reserveCommitment,\\n uint8 depth\\n );\\n\\n /**\\n * @dev Logs for inclusion proof\\n */\\n event transformedChunkAddressFromInclusionProof(uint256 indexInRC, bytes32 chunkAddress);\\n\\n // ----------------------------- Errors ------------------------------\\n\\n error NotCommitPhase(); // Game is not in commit phase\\n error NoCommitsReceived(); // Round didn't receive any commits\\n error PhaseLastBlock(); // We don't permit commits in last block of the phase\\n error CommitRoundOver(); // Commit phase in this round is over\\n error CommitRoundNotStarted(); // Commit phase in this round has not started yet\\n error NotMatchingOwner(); // Sender of commit is not matching the overlay address\\n error MustStake2Rounds(); // Before entering the game node must stake 2 rounds prior\\n error NotStaked(); // Node didn't add any staking\\n error WrongPhase(); // Checking in wrong phase, need to check duing claim phase of current round for next round or commit in current round\\n error AlreadyCommitted(); // Node already committed in this round\\n error NotRevealPhase(); // Game is not in reveal phase\\n error OutOfDepthReveal(bytes32); // Anchor is out of reported depth in Reveal phase, anchor data available as argument\\n error OutOfDepthClaim(uint8); // Anchor is out of reported depth in Claim phase, entryProof index is argument\\n error OutOfDepth(); // Anchor is out of reported depth\\n error AlreadyRevealed(); // Node already revealed\\n error NoMatchingCommit(); // No matching commit and hash\\n error NotClaimPhase(); // Game is not in the claim phase\\n error NoReveals(); // Round did not receive any reveals\\n error FirstRevealDone(); // We don't want to return value after first reveal\\n error AlreadyClaimed(); // This round was already claimed\\n error NotAdmin(); // Caller of trx is not admin\\n error OnlyPauser(); // Only account with pauser role can call pause/unpause\\n error SocVerificationFailed(bytes32); // Soc verification failed for this element\\n error SocCalcNotMatching(bytes32); // Soc address calculation does not match with the witness\\n error IndexOutsideSet(bytes32); // Stamp available: index resides outside of the valid index set\\n error SigRecoveryFailed(bytes32); // Stamp authorized: signature recovery failed for element\\n error BatchDoesNotExist(bytes32); // Stamp alive: batch remaining balance validation failed for attached stamp\\n error BucketDiffers(bytes32); // Stamp aligned: postage bucket differs from address bucket\\n error InclusionProofFailed(uint8, bytes32);\\n // 1 = RC inclusion proof failed for element\\n // 2 = First sister segment in data must match,\\n // 3 = Inclusion proof failed for original address of element\\n // 4 = Inclusion proof failed for transformed address of element\\n error RandomElementCheckFailed(); // Random element order check failed\\n error LastElementCheckFailed(); // Last element order check failed\\n error ReserveCheckFailed(bytes32 trALast); // Reserve size estimation check failed\\n\\n // ----------------------------- CONSTRUCTOR ------------------------------\\n\\n /**\\n * @param staking the address of the linked Staking contract.\\n * @param postageContract the address of the linked PostageStamp contract.\\n * @param oracleContract the address of the linked PriceOracle contract.\\n */\\n constructor(address staking, address postageContract, address oracleContract) {\\n Stakes = IStakeRegistry(staking);\\n PostageContract = IPostageStamp(postageContract);\\n OracleContract = IPriceOracle(oracleContract);\\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\\n }\\n\\n ////////////////////////////////////////\\n // STATE CHANGING //\\n ////////////////////////////////////////\\n\\n /**\\n * @notice Begin application for a round if eligible. Commit a hashed value for which the pre-image will be\\n * subsequently revealed.\\n * @dev If a node's overlay is _inProximity_(_depth_) of the _currentRoundAnchor_, that node may compute an\\n * _obfuscatedHash_ by providing their _overlay_, reported storage _depth_, reserve commitment _hash_ and a\\n * randomly generated, and secret _revealNonce_ to the _wrapCommit_ method.\\n * @param _obfuscatedHash The calculated hash resultant of the required pre-image values.\\n * and be derived from the same key pair as the message sender.\\n * @param _roundNumber Node needs to provide round number for which commit is valid\\n */\\n function commit(bytes32 _obfuscatedHash, uint64 _roundNumber) external whenNotPaused {\\n uint64 cr = currentRound();\\n bytes32 _overlay = Stakes.overlayOfAddress(msg.sender);\\n uint256 _stake = Stakes.nodeEffectiveStake(msg.sender);\\n uint256 _lastUpdate = Stakes.lastUpdatedBlockNumberOfAddress(msg.sender);\\n\\n if (!currentPhaseCommit()) {\\n revert NotCommitPhase();\\n }\\n if (block.number % ROUND_LENGTH == (ROUND_LENGTH / 4) - 1) {\\n revert PhaseLastBlock();\\n }\\n\\n if (cr > _roundNumber) {\\n revert CommitRoundOver();\\n }\\n\\n if (cr < _roundNumber) {\\n revert CommitRoundNotStarted();\\n }\\n\\n if (_lastUpdate == 0) {\\n revert NotStaked();\\n }\\n\\n if (_lastUpdate >= block.number - 2 * ROUND_LENGTH) {\\n revert MustStake2Rounds();\\n }\\n\\n // if we are in a new commit phase, reset the array of commits and\\n // set the currentCommitRound to be the current one\\n if (cr != currentCommitRound) {\\n delete currentCommits;\\n currentCommitRound = cr;\\n }\\n\\n uint256 commitsArrayLength = currentCommits.length;\\n\\n for (uint256 i = 0; i < commitsArrayLength; ) {\\n if (currentCommits[i].overlay == _overlay) {\\n revert AlreadyCommitted();\\n }\\n\\n unchecked {\\n ++i;\\n }\\n }\\n\\n currentCommits.push(\\n Commit({\\n overlay: _overlay,\\n owner: msg.sender,\\n revealed: false,\\n stake: _stake,\\n obfuscatedHash: _obfuscatedHash,\\n revealIndex: 0\\n })\\n );\\n\\n emit Committed(_roundNumber, _overlay);\\n }\\n\\n /**\\n * @notice Reveal the pre-image values used to generate commit provided during this round's commit phase.\\n * @param _depth The reported depth.\\n * @param _hash The reserve commitment hash.\\n * @param _revealNonce The nonce used to generate the commit that is being revealed.\\n */\\n function reveal(uint8 _depth, bytes32 _hash, bytes32 _revealNonce) external whenNotPaused {\\n uint64 cr = currentRound();\\n bytes32 _overlay = Stakes.overlayOfAddress(msg.sender);\\n\\n if (_depth < currentMinimumDepth()) {\\n revert OutOfDepth();\\n }\\n\\n if (!currentPhaseReveal()) {\\n revert NotRevealPhase();\\n }\\n\\n if (cr != currentCommitRound) {\\n revert NoCommitsReceived();\\n }\\n\\n if (cr != currentRevealRound) {\\n currentRevealRoundAnchor = currentRoundAnchor();\\n delete currentReveals;\\n // We set currentRevealRound ONLY after we set current anchor\\n currentRevealRound = cr;\\n emit CurrentRevealAnchor(cr, currentRevealRoundAnchor);\\n updateRandomness();\\n }\\n\\n bytes32 obfuscatedHash = wrapCommit(_overlay, _depth, _hash, _revealNonce);\\n uint256 id = findCommit(_overlay, obfuscatedHash);\\n Commit memory revealedCommit = currentCommits[id];\\n\\n // Check that commit is in proximity of the current anchor\\n if (!inProximity(revealedCommit.overlay, currentRevealRoundAnchor, _depth)) {\\n revert OutOfDepthReveal(currentRevealRoundAnchor);\\n }\\n // Check that the commit has not already been revealed\\n if (revealedCommit.revealed) {\\n revert AlreadyRevealed();\\n }\\n\\n currentCommits[id].revealed = true;\\n currentCommits[id].revealIndex = currentReveals.length;\\n\\n currentReveals.push(\\n Reveal({\\n overlay: revealedCommit.overlay,\\n owner: revealedCommit.owner,\\n depth: _depth,\\n stake: revealedCommit.stake,\\n stakeDensity: revealedCommit.stake * uint256(2 ** _depth),\\n hash: _hash\\n })\\n );\\n\\n emit Revealed(\\n cr,\\n revealedCommit.overlay,\\n revealedCommit.stake,\\n revealedCommit.stake * uint256(2 ** _depth),\\n _hash,\\n _depth\\n );\\n }\\n\\n /**\\n * @notice Helper function to get this round truth\\n * @dev\\n */\\n function claim(\\n ChunkInclusionProof calldata entryProof1,\\n ChunkInclusionProof calldata entryProof2,\\n ChunkInclusionProof calldata entryProofLast\\n ) external whenNotPaused {\\n winnerSelection();\\n\\n Reveal memory winnerSelected = winner;\\n uint256 indexInRC1;\\n uint256 indexInRC2;\\n bytes32 _currentRevealRoundAnchor = currentRevealRoundAnchor;\\n bytes32 _seed = seed;\\n\\n // rand(14)\\n indexInRC1 = uint256(_seed) % 15;\\n // rand(13)\\n indexInRC2 = uint256(_seed) % 14;\\n if (indexInRC2 >= indexInRC1) {\\n indexInRC2++;\\n }\\n\\n if (!inProximity(entryProofLast.proveSegment, _currentRevealRoundAnchor, winnerSelected.depth)) {\\n revert OutOfDepthClaim(3);\\n }\\n\\n inclusionFunction(entryProofLast, 30);\\n stampFunction(entryProofLast);\\n socFunction(entryProofLast);\\n\\n if (!inProximity(entryProof1.proveSegment, _currentRevealRoundAnchor, winnerSelected.depth)) {\\n revert OutOfDepthClaim(2);\\n }\\n\\n inclusionFunction(entryProof1, indexInRC1 * 2);\\n stampFunction(entryProof1);\\n socFunction(entryProof1);\\n\\n if (!inProximity(entryProof2.proveSegment, _currentRevealRoundAnchor, winnerSelected.depth)) {\\n revert OutOfDepthClaim(1);\\n }\\n\\n inclusionFunction(entryProof2, indexInRC2 * 2);\\n stampFunction(entryProof2);\\n socFunction(entryProof2);\\n\\n checkOrder(\\n indexInRC1,\\n indexInRC2,\\n entryProof1.proofSegments[0],\\n entryProof2.proofSegments[0],\\n entryProofLast.proofSegments[0]\\n );\\n\\n estimateSize(entryProofLast.proofSegments[0]);\\n\\n PostageContract.withdraw(winnerSelected.owner);\\n emit WinnerSelected(winnerSelected);\\n emit ChunkCount(PostageContract.validChunkCount());\\n }\\n\\n function winnerSelection() internal {\\n uint64 cr = currentRound();\\n\\n if (!currentPhaseClaim()) {\\n revert NotClaimPhase();\\n }\\n\\n if (cr != currentRevealRound) {\\n revert NoReveals();\\n }\\n\\n if (cr <= currentClaimRound) {\\n revert AlreadyClaimed();\\n }\\n\\n uint256 currentWinnerSelectionSum = 0;\\n uint256 redundancyCount = 0;\\n bytes32 randomNumber;\\n uint256 randomNumberTrunc;\\n\\n bytes32 truthRevealedHash;\\n uint8 truthRevealedDepth;\\n uint256 currentCommitsLength = currentCommits.length;\\n\\n emit CountCommits(currentCommitsLength);\\n emit CountReveals(currentReveals.length);\\n\\n (truthRevealedHash, truthRevealedDepth) = getCurrentTruth();\\n emit TruthSelected(truthRevealedHash, truthRevealedDepth);\\n string memory winnerSelectionAnchor = currentWinnerSelectionAnchor();\\n\\n for (uint256 i = 0; i < currentCommitsLength; ) {\\n Commit memory currentCommit = currentCommits[i];\\n uint256 revIndex = currentCommit.revealIndex;\\n Reveal memory currentReveal = currentReveals[revIndex];\\n\\n // Select winner with valid truth\\n if (\\n currentCommit.revealed &&\\n truthRevealedHash == currentReveal.hash &&\\n truthRevealedDepth == currentReveal.depth\\n ) {\\n currentWinnerSelectionSum += currentReveal.stakeDensity;\\n randomNumber = keccak256(abi.encodePacked(winnerSelectionAnchor, redundancyCount));\\n randomNumberTrunc = uint256(randomNumber & MAX_H);\\n\\n if (randomNumberTrunc * currentWinnerSelectionSum < currentReveal.stakeDensity * (uint256(MAX_H) + 1)) {\\n winner = currentReveal;\\n }\\n\\n redundancyCount++;\\n }\\n\\n // Freeze deposit if any truth is false, make it a penaltyRandomFactor chance for this to happen\\n if (\\n currentCommit.revealed &&\\n (truthRevealedHash != currentReveal.hash || truthRevealedDepth != currentReveal.depth) &&\\n (block.prevrandao % 100 < penaltyRandomFactor)\\n ) {\\n Stakes.freezeDeposit(\\n currentReveal.owner,\\n penaltyMultiplierDisagreement * ROUND_LENGTH * uint256(2 ** truthRevealedDepth)\\n );\\n }\\n\\n // Slash deposits if revealed is false\\n if (!currentCommit.revealed) {\\n // slash in later phase (ph5)\\n // Stakes.slashDeposit(currentCommits[i].overlay, currentCommits[i].stake);\\n Stakes.freezeDeposit(\\n currentCommit.owner,\\n penaltyMultiplierNonRevealed * ROUND_LENGTH * uint256(2 ** truthRevealedDepth)\\n );\\n }\\n unchecked {\\n ++i;\\n }\\n }\\n\\n OracleContract.adjustPrice(uint16(redundancyCount));\\n currentClaimRound = cr;\\n }\\n\\n function inclusionFunction(ChunkInclusionProof calldata entryProof, uint256 indexInRC) internal {\\n uint256 randomChunkSegmentIndex = uint256(seed) % 128;\\n bytes32 calculatedTransformedAddr = TransformedBMTChunk.transformedChunkAddressFromInclusionProof(\\n entryProof.proofSegments3,\\n entryProof.proveSegment2,\\n randomChunkSegmentIndex,\\n entryProof.chunkSpan,\\n currentRevealRoundAnchor\\n );\\n\\n emit transformedChunkAddressFromInclusionProof(indexInRC, calculatedTransformedAddr);\\n\\n if (\\n winner.hash !=\\n BMTChunk.chunkAddressFromInclusionProof(\\n entryProof.proofSegments,\\n entryProof.proveSegment,\\n indexInRC,\\n 32 * 32\\n )\\n ) {\\n revert InclusionProofFailed(1, calculatedTransformedAddr);\\n }\\n\\n if (entryProof.proofSegments2[0] != entryProof.proofSegments3[0]) {\\n revert InclusionProofFailed(2, calculatedTransformedAddr);\\n }\\n\\n bytes32 originalAddress = entryProof.socProof.length > 0\\n ? entryProof.socProof[0].chunkAddr // soc attestation in socFunction\\n : entryProof.proveSegment;\\n\\n if (\\n originalAddress !=\\n BMTChunk.chunkAddressFromInclusionProof(\\n entryProof.proofSegments2,\\n entryProof.proveSegment2,\\n randomChunkSegmentIndex,\\n entryProof.chunkSpan\\n )\\n ) {\\n revert InclusionProofFailed(3, calculatedTransformedAddr);\\n }\\n\\n // In case of SOC, the transformed address is hashed together with its address in the sample\\n if (entryProof.socProof.length > 0) {\\n calculatedTransformedAddr = keccak256(\\n abi.encode(\\n entryProof.proveSegment, // SOC address\\n calculatedTransformedAddr\\n )\\n );\\n }\\n\\n if (entryProof.proofSegments[0] != calculatedTransformedAddr) {\\n revert InclusionProofFailed(4, calculatedTransformedAddr);\\n }\\n }\\n\\n /**\\n * @notice Set freezing parameters\\n */\\n function setFreezingParams(\\n uint8 _penaltyMultiplierDisagreement,\\n uint8 _penaltyMultiplierNonRevealed,\\n uint8 _penaltyRandomFactor\\n ) external {\\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\\n revert NotAdmin();\\n }\\n\\n penaltyMultiplierDisagreement = _penaltyMultiplierDisagreement;\\n penaltyMultiplierNonRevealed = _penaltyMultiplierNonRevealed;\\n penaltyRandomFactor = _penaltyRandomFactor;\\n }\\n\\n /**\\n * @notice changes the max sample value used for reserve estimation\\n */\\n function setSampleMaxValue(uint256 _sampleMaxValue) external {\\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\\n revert NotAdmin();\\n }\\n\\n sampleMaxValue = _sampleMaxValue;\\n }\\n\\n /**\\n * @notice Updates the source of randomness. Uses block.difficulty in pre-merge chains, this is substituted\\n * to block.prevrandao in post merge chains.\\n */\\n function updateRandomness() private {\\n seed = keccak256(abi.encode(seed, block.prevrandao));\\n }\\n\\n /**\\n * @dev Pause the contract. The contract is provably stopped by renouncing\\n the pauser role and the admin role after pausing, can only be called by the `PAUSER`\\n */\\n function pause() public {\\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\\n revert OnlyPauser();\\n }\\n\\n _pause();\\n }\\n\\n /**\\n * @dev Unpause the contract, can only be called by the pauser when paused\\n */\\n function unPause() public {\\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\\n revert OnlyPauser();\\n }\\n _unpause();\\n }\\n\\n ////////////////////////////////////////\\n // STATE READING //\\n ////////////////////////////////////////\\n\\n // ----------------------------- Anchor calculations ------------------------------\\n\\n /**\\n * @notice Returns the current random seed which is used to determine later utilised random numbers.\\n * If rounds have elapsed without reveals, hash the seed with an incremented nonce to produce a new\\n * random seed and hence a new round anchor.\\n */\\n function currentSeed() public view returns (bytes32) {\\n uint64 cr = currentRound();\\n bytes32 currentSeedValue = seed;\\n\\n if (cr > currentRevealRound + 1) {\\n uint256 difference = cr - currentRevealRound - 1;\\n currentSeedValue = keccak256(abi.encodePacked(currentSeedValue, difference));\\n }\\n\\n return currentSeedValue;\\n }\\n\\n /**\\n * @notice Returns the seed which will become current once the next commit phase begins.\\n * Used to determine what the next round's anchor will be.\\n */\\n function nextSeed() public view returns (bytes32) {\\n uint64 cr = currentRound() + 1;\\n bytes32 currentSeedValue = seed;\\n\\n if (cr > currentRevealRound + 1) {\\n uint256 difference = cr - currentRevealRound - 1;\\n currentSeedValue = keccak256(abi.encodePacked(currentSeedValue, difference));\\n }\\n\\n return currentSeedValue;\\n }\\n\\n /**\\n * @notice The random value used to choose the selected truth teller.\\n */\\n function currentTruthSelectionAnchor() private view returns (string memory) {\\n if (!currentPhaseClaim()) {\\n revert NotClaimPhase();\\n }\\n\\n uint64 cr = currentRound();\\n if (cr != currentRevealRound) {\\n revert NoReveals();\\n }\\n\\n return string(abi.encodePacked(seed, \\\"0\\\"));\\n }\\n\\n /**\\n * @notice The random value used to choose the selected beneficiary.\\n */\\n function currentWinnerSelectionAnchor() private view returns (string memory) {\\n if (!currentPhaseClaim()) {\\n revert NotClaimPhase();\\n }\\n uint64 cr = currentRound();\\n if (cr != currentRevealRound) {\\n revert NoReveals();\\n }\\n\\n return string(abi.encodePacked(seed, \\\"1\\\"));\\n }\\n\\n /**\\n * @notice The anchor used to determine eligibility for the current round.\\n * @dev A node must be within proximity order of less than or equal to the storage depth they intend to report.\\n */\\n function currentRoundAnchor() public view returns (bytes32 returnVal) {\\n // This will be called in reveal phase and set as currentRevealRoundAnchor or in\\n // commit phase when checking eligibility for next round by isParticipatingInUpcomingRound\\n if (currentPhaseCommit() || (currentRound() > currentRevealRound && !currentPhaseClaim())) {\\n return currentSeed();\\n }\\n\\n // This will be called by isParticipatingInUpcomingRound check in claim phase\\n if (currentPhaseClaim()) {\\n return nextSeed();\\n }\\n\\n // Without this, this function will output 0x0 after first reveal which is value and we prefere it reverts\\n if (currentPhaseReveal() && currentRound() == currentRevealRound) {\\n revert FirstRevealDone();\\n }\\n }\\n\\n /**\\n * @notice Returns true if an overlay address _A_ is within proximity order _minimum_ of _B_.\\n * @param A An overlay address to compare.\\n * @param B An overlay address to compare.\\n * @param minimum Minimum proximity order.\\n */\\n function inProximity(bytes32 A, bytes32 B, uint8 minimum) public pure returns (bool) {\\n if (minimum == 0) {\\n return true;\\n }\\n\\n return uint256(A ^ B) < uint256(2 ** (256 - minimum));\\n }\\n\\n // ----------------------------- Commit ------------------------------\\n\\n /**\\n * @notice The number of the current round.\\n */\\n function currentRound() public view returns (uint64) {\\n return uint64(block.number / ROUND_LENGTH);\\n }\\n\\n /**\\n * @notice Returns true if current block is during commit phase.\\n */\\n function currentPhaseCommit() public view returns (bool) {\\n if (block.number % ROUND_LENGTH < ROUND_LENGTH / 4) {\\n return true;\\n }\\n return false;\\n }\\n\\n /**\\n * @notice Determine if a the owner of a given overlay can participate in the upcoming round.\\n * @param _owner The address of the applicant from.\\n * @param _depth The storage depth the applicant intends to report.\\n */\\n function isParticipatingInUpcomingRound(address _owner, uint8 _depth) public view returns (bool) {\\n uint256 _lastUpdate = Stakes.lastUpdatedBlockNumberOfAddress(_owner);\\n\\n if (currentPhaseReveal()) {\\n revert WrongPhase();\\n }\\n\\n if (_lastUpdate == 0) {\\n revert NotStaked();\\n }\\n\\n if (_lastUpdate >= block.number - 2 * ROUND_LENGTH) {\\n revert MustStake2Rounds();\\n }\\n\\n return inProximity(Stakes.overlayOfAddress(_owner), currentRoundAnchor(), _depth);\\n }\\n\\n // ----------------------------- Reveal ------------------------------\\n\\n /**\\n * @notice Returns minimum depth reveal has to have to participate in this round\\n */\\n function currentMinimumDepth() public view returns (uint8) {\\n // We are checking value in reveal phase, as the currentCommitRound is set to the current round\\n // but the currentClaimRound is still set to the last time claim was made\\n // We add 1 to ensure that for the next round the minimum depth is the same as last winner depth\\n\\n uint256 difference = currentCommitRound - currentClaimRound;\\n uint8 skippedRounds = uint8(difference > 254 ? 254 : difference) + 1;\\n\\n uint8 lastWinnerDepth = winner.depth;\\n\\n // We ensure that skippedRounds is not bigger than lastWinnerDepth, because of overflow\\n return skippedRounds >= lastWinnerDepth ? 0 : lastWinnerDepth - skippedRounds;\\n }\\n\\n /**\\n * @notice Helper function to get this node reveal in commits\\n * @dev\\n */\\n function findCommit(bytes32 _overlay, bytes32 _obfuscatedHash) internal view returns (uint256) {\\n for (uint256 i = 0; i < currentCommits.length; ) {\\n if (currentCommits[i].overlay == _overlay && _obfuscatedHash == currentCommits[i].obfuscatedHash) {\\n return i;\\n }\\n unchecked {\\n ++i;\\n }\\n }\\n revert NoMatchingCommit();\\n }\\n\\n /**\\n * @notice Hash the pre-image values to the obsfucated hash.\\n * @dev _revealNonce_ must be randomly generated, used once and kept secret until the reveal phase.\\n * @param _overlay The overlay address of the applicant.\\n * @param _depth The reported depth.\\n * @param _hash The reserve commitment hash.\\n * @param revealNonce A random, single use, secret nonce.\\n */\\n function wrapCommit(\\n bytes32 _overlay,\\n uint8 _depth,\\n bytes32 _hash,\\n bytes32 revealNonce\\n ) public pure returns (bytes32) {\\n return keccak256(abi.encodePacked(_overlay, _depth, _hash, revealNonce));\\n }\\n\\n /**\\n * @notice Returns true if current block is during reveal phase.\\n */\\n function currentPhaseReveal() public view returns (bool) {\\n uint256 number = block.number % ROUND_LENGTH;\\n if (number >= ROUND_LENGTH / 4 && number < ROUND_LENGTH / 2) {\\n return true;\\n }\\n return false;\\n }\\n\\n /**\\n * @notice Returns true if current block is during reveal phase.\\n */\\n function currentRoundReveals() public view returns (Reveal[] memory) {\\n if (!currentPhaseClaim()) {\\n revert NotClaimPhase();\\n }\\n uint64 cr = currentRound();\\n if (cr != currentRevealRound) {\\n revert NoReveals();\\n }\\n\\n return currentReveals;\\n }\\n\\n // ----------------------------- Claim ------------------------------\\n\\n /**\\n * @notice Returns true if current block is during claim phase.\\n */\\n function currentPhaseClaim() public view returns (bool) {\\n if (block.number % ROUND_LENGTH >= ROUND_LENGTH / 2) {\\n return true;\\n }\\n return false;\\n }\\n\\n function getCurrentTruth() internal view returns (bytes32 Hash, uint8 Depth) {\\n uint256 currentSum;\\n bytes32 randomNumber;\\n uint256 randomNumberTrunc;\\n\\n bytes32 truthRevealedHash;\\n uint8 truthRevealedDepth;\\n uint256 revIndex;\\n string memory truthSelectionAnchor = currentTruthSelectionAnchor();\\n uint256 commitsArrayLength = currentCommits.length;\\n\\n for (uint256 i = 0; i < commitsArrayLength; ) {\\n if (currentCommits[i].revealed) {\\n revIndex = currentCommits[i].revealIndex;\\n currentSum += currentReveals[revIndex].stakeDensity;\\n randomNumber = keccak256(abi.encodePacked(truthSelectionAnchor, i));\\n randomNumberTrunc = uint256(randomNumber & MAX_H);\\n\\n // question is whether randomNumber / MAX_H < probability\\n // where probability is stakeDensity / currentSum\\n // to avoid resorting to floating points all divisions should be\\n // simplified with multiplying both sides (as long as divisor > 0)\\n // randomNumber / (MAX_H + 1) < stakeDensity / currentSum\\n // ( randomNumber / (MAX_H + 1) ) * currentSum < stakeDensity\\n // randomNumber * currentSum < stakeDensity * (MAX_H + 1)\\n if (randomNumberTrunc * currentSum < currentReveals[revIndex].stakeDensity * (uint256(MAX_H) + 1)) {\\n truthRevealedHash = currentReveals[revIndex].hash;\\n truthRevealedDepth = currentReveals[revIndex].depth;\\n }\\n }\\n unchecked {\\n ++i;\\n }\\n }\\n\\n return (truthRevealedHash, truthRevealedDepth);\\n }\\n\\n /**\\n * @notice Determine if a the owner of a given overlay will be the beneficiary of the claim phase.\\n * @param _overlay The overlay address of the applicant.\\n */\\n function isWinner(bytes32 _overlay) public view returns (bool) {\\n if (!currentPhaseClaim()) {\\n revert NotClaimPhase();\\n }\\n\\n uint64 cr = currentRound();\\n if (cr != currentRevealRound) {\\n revert NoReveals();\\n }\\n\\n if (cr <= currentClaimRound) {\\n revert AlreadyClaimed();\\n }\\n\\n uint256 currentWinnerSelectionSum;\\n bytes32 winnerIs;\\n bytes32 randomNumber;\\n uint256 randomNumberTrunc;\\n bytes32 truthRevealedHash;\\n uint8 truthRevealedDepth;\\n uint256 revIndex;\\n string memory winnerSelectionAnchor = currentWinnerSelectionAnchor();\\n uint256 redundancyCount = 0;\\n\\n // Get current truth\\n (truthRevealedHash, truthRevealedDepth) = getCurrentTruth();\\n uint256 commitsArrayLength = currentCommits.length;\\n\\n for (uint256 i = 0; i < commitsArrayLength; ) {\\n revIndex = currentCommits[i].revealIndex;\\n\\n // Deterministically read winner\\n if (\\n currentCommits[i].revealed &&\\n truthRevealedHash == currentReveals[revIndex].hash &&\\n truthRevealedDepth == currentReveals[revIndex].depth\\n ) {\\n currentWinnerSelectionSum += currentReveals[revIndex].stakeDensity;\\n randomNumber = keccak256(abi.encodePacked(winnerSelectionAnchor, redundancyCount));\\n randomNumberTrunc = uint256(randomNumber & MAX_H);\\n\\n if (\\n randomNumberTrunc * currentWinnerSelectionSum <\\n currentReveals[revIndex].stakeDensity * (uint256(MAX_H) + 1)\\n ) {\\n winnerIs = currentReveals[revIndex].overlay;\\n }\\n\\n redundancyCount++;\\n }\\n unchecked {\\n ++i;\\n }\\n }\\n\\n return (winnerIs == _overlay);\\n }\\n\\n // ----------------------------- Claim verifications ------------------------------\\n\\n function socFunction(ChunkInclusionProof calldata entryProof) internal pure {\\n if (entryProof.socProof.length == 0) return;\\n\\n if (\\n !Signatures.socVerify(\\n entryProof.socProof[0].signer, // signer Ethereum address to check against\\n entryProof.socProof[0].signature,\\n entryProof.socProof[0].identifier,\\n entryProof.socProof[0].chunkAddr\\n )\\n ) {\\n revert SocVerificationFailed(entryProof.socProof[0].chunkAddr);\\n }\\n\\n if (\\n calculateSocAddress(entryProof.socProof[0].identifier, entryProof.socProof[0].signer) !=\\n entryProof.proveSegment\\n ) {\\n revert SocCalcNotMatching(entryProof.socProof[0].chunkAddr);\\n }\\n }\\n\\n function stampFunction(ChunkInclusionProof calldata entryProof) internal view {\\n // authentic\\n (address batchOwner, uint8 batchDepth, uint8 bucketDepth, , , ) = PostageContract.batches(\\n entryProof.postageProof.postageId\\n );\\n\\n // alive\\n if (batchOwner == address(0)) {\\n revert BatchDoesNotExist(entryProof.postageProof.postageId); // Batch does not exist or expired\\n }\\n\\n uint32 postageIndex = getPostageIndex(entryProof.postageProof.index);\\n uint256 maxPostageIndex = postageStampIndexCount(batchDepth, bucketDepth);\\n // available\\n if (postageIndex >= maxPostageIndex) {\\n revert IndexOutsideSet(entryProof.postageProof.postageId);\\n }\\n\\n // aligned\\n uint64 postageBucket = getPostageBucket(entryProof.postageProof.index);\\n uint64 addressBucket = addressToBucket(entryProof.proveSegment, bucketDepth);\\n if (postageBucket != addressBucket) {\\n revert BucketDiffers(entryProof.postageProof.postageId);\\n }\\n\\n // authorized\\n if (\\n !Signatures.postageVerify(\\n batchOwner,\\n entryProof.postageProof.signature,\\n entryProof.proveSegment,\\n entryProof.postageProof.postageId,\\n entryProof.postageProof.index,\\n entryProof.postageProof.timeStamp\\n )\\n ) {\\n revert SigRecoveryFailed(entryProof.postageProof.postageId);\\n }\\n }\\n\\n function addressToBucket(bytes32 swarmAddress, uint8 bucketDepth) internal pure returns (uint32) {\\n uint32 prefix = uint32(uint256(swarmAddress) >> (256 - 32));\\n return prefix >> (32 - bucketDepth);\\n }\\n\\n function postageStampIndexCount(uint8 postageDepth, uint8 bucketDepth) internal pure returns (uint256) {\\n return 1 << (postageDepth - bucketDepth);\\n }\\n\\n function getPostageIndex(uint64 signedIndex) internal pure returns (uint32) {\\n return uint32(signedIndex);\\n }\\n\\n function getPostageBucket(uint64 signedIndex) internal pure returns (uint64) {\\n return uint32(signedIndex >> 32);\\n }\\n\\n function calculateSocAddress(bytes32 identifier, address signer) internal pure returns (bytes32) {\\n return keccak256(abi.encodePacked(identifier, signer));\\n }\\n\\n function checkOrder(uint256 a, uint256 b, bytes32 trA1, bytes32 trA2, bytes32 trALast) internal pure {\\n if (a < b) {\\n if (uint256(trA1) >= uint256(trA2)) {\\n revert RandomElementCheckFailed();\\n }\\n if (uint256(trA2) >= uint256(trALast)) {\\n revert LastElementCheckFailed();\\n }\\n } else {\\n if (uint256(trA2) >= uint256(trA1)) {\\n revert RandomElementCheckFailed();\\n }\\n if (uint256(trA1) >= uint256(trALast)) {\\n revert LastElementCheckFailed();\\n }\\n }\\n }\\n\\n function estimateSize(bytes32 trALast) internal view {\\n if (uint256(trALast) >= sampleMaxValue) {\\n revert ReserveCheckFailed(trALast);\\n }\\n }\\n}\\n\",\"keccak256\":\"0x6190a6c33847397660cf7315ade3acef9f8d79559be4e0f47d17b2514cdb13c9\",\"license\":\"BSD-3-Clause\"},\"src/Util/ChunkProof.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\npragma solidity ^0.8.19;\\n\\nlibrary BMTChunk {\\n // max chunk payload size\\n uint256 public constant MAX_CHUNK_PAYLOAD_SIZE = 4096;\\n // segment byte size\\n uint256 public constant SEGMENT_SIZE = 32;\\n\\n /**\\n * @notice Changes the endianness of a uint64.\\n * @dev https://graphics.stanford.edu/~seander/bithacks.html#ReverseParallel\\n * @param _b The unsigned integer to reverse\\n * @return v - The reversed value\\n */\\n function reverseUint64(uint64 _b) public pure returns (uint64) {\\n uint256 v = _b;\\n\\n // swap bytes\\n v =\\n ((v >> 8) & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) |\\n ((v & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) << 8);\\n // swap 2-byte long pairs\\n v =\\n ((v >> 16) & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) |\\n ((v & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) << 16);\\n // swap 4-byte long pairs\\n v =\\n ((v >> 32) & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) |\\n ((v & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) << 32);\\n\\n return uint64(v);\\n }\\n\\n /** Calculates the root hash from the provided inclusion proof segments and its corresponding segment index\\n * @param _proofSegments Proof segments.\\n * @param _proveSegment Segment to prove.\\n * @param _proveSegmentIndex Prove segment index\\n * @return _calculatedHash chunk hash\\n */\\n function rootHashFromInclusionProof(\\n bytes32[] memory _proofSegments,\\n bytes32 _proveSegment,\\n uint256 _proveSegmentIndex\\n ) internal pure returns (bytes32 _calculatedHash) {\\n _calculatedHash = _proveSegment;\\n for (uint256 i = 0; i < _proofSegments.length; i++) {\\n bool mergeFromRight = _proveSegmentIndex % 2 == 0;\\n _calculatedHash = mergeSegment(_calculatedHash, _proofSegments[i], mergeFromRight);\\n _proveSegmentIndex >>= 1;\\n }\\n return _calculatedHash;\\n }\\n\\n /**\\n * Calculate the chunk address from the Binary Merkle Tree of the chunk data\\n *\\n * The BMT chunk address is the hash of the 8 byte span and the root\\n * hash of a binary Merkle tree (BMT) built on the 32-byte segments\\n * of the underlying data.\\n * @param _proofSegments Proof segments.\\n * @param _proveSegment Segment to prove.\\n * @param _proveSegmentIndex Prove segment index\\n * @param _chunkSpan chunk bytes length\\n * @return _chunkHash chunk hash\\n */\\n function chunkAddressFromInclusionProof(\\n bytes32[] memory _proofSegments,\\n bytes32 _proveSegment,\\n uint256 _proveSegmentIndex,\\n uint64 _chunkSpan\\n ) internal pure returns (bytes32) {\\n bytes32 rootHash = rootHashFromInclusionProof(_proofSegments, _proveSegment, _proveSegmentIndex);\\n return keccak256(abi.encodePacked(reverseUint64(_chunkSpan), rootHash));\\n }\\n\\n function mergeSegment(\\n bytes32 _calculatedHash,\\n bytes32 _proofSegment,\\n bool mergeFromRight\\n ) internal pure returns (bytes32 res) {\\n if (mergeFromRight) {\\n res = keccak256(abi.encode(_calculatedHash, _proofSegment));\\n } else {\\n res = keccak256(abi.encode(_proofSegment, _calculatedHash));\\n }\\n return res;\\n }\\n}\\n\",\"keccak256\":\"0xe4a86f2002b8b8fc4c955537d6b80ba42fb04a816e783ddbd05f0484b013938a\",\"license\":\"MIT\"},\"src/Util/Signatures.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\npragma solidity ^0.8.19;\\n\\nlibrary Signatures {\\n error InvalidSignatureLength();\\n\\n /** Hash of the message to sign */\\n function getPostageMessageHash(\\n bytes32 _chunkAddr,\\n bytes32 _batchId,\\n uint64 _index,\\n uint64 _timeStamp\\n ) internal pure returns (bytes32) {\\n return keccak256(abi.encodePacked(_chunkAddr, _batchId, _index, _timeStamp));\\n }\\n\\n function postageVerify(\\n address _signer, // signer Ethereum address to check against\\n bytes memory _signature,\\n bytes32 _chunkAddr,\\n bytes32 _postageId,\\n uint64 _index,\\n uint64 _timeStamp\\n ) internal pure returns (bool) {\\n bytes32 messageHash = getPostageMessageHash(_chunkAddr, _postageId, _index, _timeStamp);\\n bytes32 ethMessageHash = getEthSignedMessageHash(messageHash);\\n\\n return recoverSigner(ethMessageHash, _signature) == _signer;\\n }\\n\\n function getEthSignedMessageHash(bytes32 _messageHash) internal pure returns (bytes32) {\\n /*\\n Signature is produced by signing a keccak256 hash with the following format:\\n \\\"\\\\x19Ethereum Signed Message\\\\n\\\" + len(msg) + msg\\n */\\n return keccak256(abi.encodePacked(\\\"\\\\x19Ethereum Signed Message:\\\\n32\\\", _messageHash));\\n }\\n\\n function recoverSigner(\\n bytes32 _ethSignedMessageHash, // it has to be prefixed message: https://ethereum.stackexchange.com/questions/19582/does-ecrecover-in-solidity-expects-the-x19ethereum-signed-message-n-prefix/21037\\n bytes memory _signature\\n ) internal pure returns (address) {\\n (bytes32 r, bytes32 s, uint8 v) = splitSignature(_signature);\\n\\n return ecrecover(_ethSignedMessageHash, v, r, s);\\n }\\n\\n function splitSignature(bytes memory sig) internal pure returns (bytes32 r_, bytes32 s_, uint8 v_) {\\n if (sig.length != 65) {\\n revert InvalidSignatureLength();\\n }\\n\\n assembly {\\n /*\\n verbose explanation: https://ethereum.stackexchange.com/questions/135591/split-signature-function-in-solidity-by-example-docs\\n First 32 bytes stores the length of the signature\\n add(sig, 32) = pointer of sig + 32\\n effectively, skips first 32 bytes of signature\\n mload(p) loads next 32 bytes starting at the memory address p into memory\\n */\\n\\n // first 32 bytes, after the length prefix\\n r_ := mload(add(sig, 32))\\n // second 32 bytes\\n s_ := mload(add(sig, 64))\\n // final byte (first byte of the next 32 bytes)\\n v_ := byte(0, mload(add(sig, 96)))\\n }\\n\\n // implicitly return (r, s, v)\\n }\\n\\n function getSocMessageHash(bytes32 _identifier, bytes32 _chunkAddr) internal pure returns (bytes32) {\\n return keccak256(abi.encodePacked(_identifier, _chunkAddr));\\n }\\n\\n function socVerify(\\n address _signer, // signer Ethereum address to check against\\n bytes memory _signature,\\n bytes32 _identifier,\\n bytes32 _chunkAddr\\n ) internal pure returns (bool) {\\n bytes32 messageHash = getSocMessageHash(_identifier, _chunkAddr);\\n bytes32 ethMessageHash = getEthSignedMessageHash(messageHash);\\n\\n return recoverSigner(ethMessageHash, _signature) == _signer;\\n }\\n}\\n\",\"keccak256\":\"0x11762639cfa5bd2ea21922f762254c776ce890ab9e4085b3e3d45dbe21867ac8\",\"license\":\"MIT\"},\"src/Util/TransformedChunkProof.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\npragma solidity ^0.8.19;\\n\\nlibrary TransformedBMTChunk {\\n // max chunk payload size\\n uint256 public constant MAX_CHUNK_PAYLOAD_SIZE = 4096;\\n // segment byte size\\n uint256 public constant SEGMENT_SIZE = 32;\\n\\n /** Calculates the root hash from the provided inclusion proof segments and its corresponding segment index\\n * @param _proofSegments Proof segments.\\n * @param _proveSegment Segment to prove.\\n * @param _proveSegmentIndex Prove segment index\\n * @return _calculatedHash chunk hash\\n */\\n function transformedRootHashFromInclusionProof(\\n bytes32[] memory _proofSegments,\\n bytes32 _proveSegment,\\n uint256 _proveSegmentIndex,\\n bytes32 key\\n ) internal pure returns (bytes32 _calculatedHash) {\\n _calculatedHash = _proveSegment;\\n for (uint256 i = 0; i < _proofSegments.length; i++) {\\n bool mergeFromRight = _proveSegmentIndex % 2 == 0 ? true : false;\\n _calculatedHash = transformedMergeSegment(_calculatedHash, _proofSegments[i], mergeFromRight, key);\\n _proveSegmentIndex >>= 1;\\n }\\n\\n return _calculatedHash;\\n }\\n\\n /**\\n * @notice Changes the endianness of a uint64.\\n * @dev https://graphics.stanford.edu/~seander/bithacks.html#ReverseParallel\\n * @param _b The unsigned integer to reverse\\n * @return v - The reversed value\\n */\\n function reverseUint64(uint64 _b) public pure returns (uint64) {\\n uint256 v = _b;\\n\\n // swap bytes\\n v =\\n ((v >> 8) & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) |\\n ((v & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) << 8);\\n // swap 2-byte long pairs\\n v =\\n ((v >> 16) & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) |\\n ((v & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) << 16);\\n // swap 4-byte long pairs\\n v =\\n ((v >> 32) & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) |\\n ((v & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) << 32);\\n\\n return uint64(v);\\n }\\n\\n /**\\n * Calculate the chunk address from the Binary Merkle Tree of the chunk data\\n *\\n * The BMT chunk address is the hash of the 8 byte span and the root\\n * hash of a binary Merkle tree (BMT) built on the 32-byte segments\\n * of the underlying data.\\n * @param _proofSegments Proof segments.\\n * @param _proveSegment Segment to prove.\\n * @param _proveSegmentIndex Prove segment index\\n * @param _chunkSpan chunk bytes length\\n * @return _chunkHash chunk hash\\n */\\n function transformedChunkAddressFromInclusionProof(\\n bytes32[] memory _proofSegments,\\n bytes32 _proveSegment,\\n uint256 _proveSegmentIndex,\\n uint64 _chunkSpan,\\n bytes32 key\\n ) internal pure returns (bytes32) {\\n bytes32 rootHash = transformedRootHashFromInclusionProof(\\n _proofSegments,\\n _proveSegment,\\n _proveSegmentIndex,\\n key\\n );\\n return keccak256(abi.encodePacked(key, reverseUint64(_chunkSpan), rootHash));\\n }\\n\\n function transformedMergeSegment(\\n bytes32 _calculatedHash,\\n bytes32 _proofSegment,\\n bool mergeFromRight,\\n bytes32 key\\n ) internal pure returns (bytes32 res) {\\n if (mergeFromRight) {\\n res = keccak256(abi.encode(key, _calculatedHash, _proofSegment));\\n } else {\\n res = keccak256(abi.encode(key, _proofSegment, _calculatedHash));\\n }\\n return res;\\n }\\n}\\n\",\"keccak256\":\"0xf36473af0bec0de80c769b139a09bc0329807cb5c3b6234473601081da14350c\",\"license\":\"MIT\"},\"src/interface/IPostageStamp.sol\":{\"content\":\"// SPDX-License-Identifier: BSD-3-Clause\\npragma solidity ^0.8.19;\\n\\ninterface IPostageStamp {\\n function withdraw(address beneficiary) external;\\n\\n function validChunkCount() external view returns (uint256);\\n\\n function batchOwner(bytes32 _batchId) external view returns (address);\\n\\n function batchDepth(bytes32 _batchId) external view returns (uint8);\\n\\n function batchBucketDepth(bytes32 _batchId) external view returns (uint8);\\n\\n function remainingBalance(bytes32 _batchId) external view returns (uint256);\\n\\n function minimumInitialBalancePerChunk() external view returns (uint256);\\n\\n function setPrice(uint256 _price) external;\\n\\n function batches(\\n bytes32\\n )\\n external\\n view\\n returns (\\n address owner,\\n uint8 depth,\\n uint8 bucketDepth,\\n bool immutableFlag,\\n uint256 normalisedBalance,\\n uint256 lastUpdatedBlockNumber\\n );\\n}\\n\",\"keccak256\":\"0xc018ff96e75e773e76e6245a930acc3679667250e345415a38196f1e2ad1de76\",\"license\":\"BSD-3-Clause\"}},\"version\":1}", - "bytecode": "0x60806040526008805462ffffff60c01b19166264020160c01b1790557dba1914b54e0348a1028d1a103a95ed55c4004b9d332400000000000000006009553480156200004a57600080fd5b5060405162004b0538038062004b058339810160408190526200006d916200019d565b60018054600380546001600160a01b03199081166001600160a01b03888116919091179092556001600160a81b0319909216610100868316021790925560028054909116918316919091179055620000c7600033620000d0565b505050620001e7565b620000dc8282620000e0565b5050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16620000dc576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556200013c3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b80516001600160a01b03811681146200019857600080fd5b919050565b600080600060608486031215620001b357600080fd5b620001be8462000180565b9250620001ce6020850162000180565b9150620001de6040850162000180565b90509250925092565b61490e80620001f76000396000f3fe608060405234801561001057600080fd5b50600436106102775760003560e01c806377c75d1011610160578063b6cd5822116100d8578063dfbf53ae1161008c578063f69ee1d111610071578063f69ee1d1146105d5578063f7b188a5146105e8578063fb00f2f3146105f057600080fd5b8063dfbf53ae14610592578063f4e6fcca146105c257600080fd5b8063ce987745116100bd578063ce98774514610564578063d1e8b63d14610577578063d547741f1461057f57600080fd5b8063b6cd582214610537578063c46b40291461054a57600080fd5b80638456cb591161012f5780638d8b6428116101145780638d8b6428146104f057806391d14854146104f8578063a217fddf1461052f57600080fd5b80638456cb59146104e05780638a19c8bc146104e857600080fd5b806377c75d101461045a5780637fe019c61461046d57806382b39b1b1461048857806383220626146104d857600080fd5b80635c975abb116101f357806364c34a85116101c257806369da9114116101a757806369da9114146103de5780636f94aaf2146103f157806372286cba1461040c57600080fd5b806364c34a85146103a957806369bfac01146103b157600080fd5b80635c975abb146103705780635d4844ea1461037b57806362fd29ae1461038e57806363f5cf7c1461039657600080fd5b80632a4e62491161024a5780632f3906da1161022f5780632f3906da1461034257806336568abe1461034a5780635838d6731461035d57600080fd5b80632a4e6249146103185780632f2ff15d1461032d57600080fd5b806301ffc9a71461027c5780631736d472146102a457806318350096146102b7578063248a9ca3146102e7575b600080fd5b61028f61028a36600461405f565b610603565b60405190151581526020015b60405180910390f35b61028f6102b23660046140ad565b61066c565b6001546102cf9061010090046001600160a01b031681565b6040516001600160a01b03909116815260200161029b565b61030a6102f53660046140e6565b60009081526020819052604090206001015490565b60405190815260200161029b565b6103206107fa565b60405161029b91906140ff565b61034061033b36600461418e565b610907565b005b61028f610931565b61034061035836600461418e565b61097b565b61034061036b3660046141d0565b610a0c565b60015460ff1661028f565b6003546102cf906001600160a01b031681565b61030a610f54565b6103406103a4366004614215565b611020565b61030a6113bb565b6008546103c59067ffffffffffffffff1681565b60405167ffffffffffffffff909116815260200161029b565b6002546102cf906001600160a01b031681565b6008546103c590600160801b900467ffffffffffffffff1681565b61041f61041a3660046140e6565b61149b565b604080519687526001600160a01b039095166020870152921515938501939093526060840152608083019190915260a082015260c00161029b565b61028f6104683660046140e6565b6114f2565b6008546103c590600160401b900467ffffffffffffffff1681565b61049b6104963660046140e6565b6117a2565b604080519687526001600160a01b03909516602087015260ff909316938501939093526060840152608083019190915260a082015260c00161029b565b61030a6117b2565b6103406117bd565b6103c5611816565b61028f611823565b61028f61050636600461418e565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b61030a600081565b61034061054536600461429d565b61184d565b610552611d8a565b60405160ff909116815260200161029b565b61030a6105723660046142d2565b611e0f565b61028f611e7d565b61034061058d36600461418e565b611ea2565b600a54600b54600c54600d54600e5461049b94936001600160a01b03811693600160a01b90910460ff1692909186565b6103406105d036600461430f565b611ec7565b6103406105e33660046140e6565b611fae565b610340612002565b61028f6105fe36600461435a565b612059565b60006001600160e01b031982167f7965db0b00000000000000000000000000000000000000000000000000000000148061066657507f01ffc9a7000000000000000000000000000000000000000000000000000000006001600160e01b03198316145b92915050565b60035460405163d1052d1f60e01b81526001600160a01b038481166004830152600092839291169063d1052d1f90602401602060405180830381865afa1580156106ba573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106de9190614388565b90506106e8610931565b1561071f576040517fe2586bcc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8060000361073f576040516273e5c360e31b815260040160405180910390fd5b61074b609860026143b7565b61075590436143ce565b811061077457604051630a0744c560e01b815260040160405180910390fd5b6003546040516397adedb560e01b81526001600160a01b0386811660048301526107f29216906397adedb590602401602060405180830381865afa1580156107c0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107e49190614388565b6107ec6113bb565b85612059565b949350505050565b6060610804611823565b61082157604051633788c6c160e11b815260040160405180910390fd5b600061082b611816565b60085490915067ffffffffffffffff808316600160401b909204161461086457604051636fbabc7760e01b815260040160405180910390fd5b6005805480602002602001604051908101604052809291908181526020016000905b828210156108fd5760008481526020908190206040805160c08101825260058602909201805483526001808201546001600160a01b03811685870152600160a01b900460ff169284019290925260028101546060840152600381015460808401526004015460a08301529083529092019101610886565b5050505091505090565b60008281526020819052604090206001015461092281612096565b61092c83836120a3565b505050565b60008061093f6098436143f7565b905061094d6004609861440b565b811015801561096657506109636002609861440b565b81105b1561097357600191505090565b600091505090565b6001600160a01b03811633146109fe5760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b610a088282612141565b5050565b610a146121c0565b6000610a1e611816565b6003546040516397adedb560e01b81523360048201529192506000916001600160a01b03909116906397adedb590602401602060405180830381865afa158015610a6c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a909190614388565b6003546040517f830a053e0000000000000000000000000000000000000000000000000000000081523360048201529192506000916001600160a01b039091169063830a053e90602401602060405180830381865afa158015610af7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b1b9190614388565b60035460405163d1052d1f60e01b81523360048201529192506000916001600160a01b039091169063d1052d1f90602401602060405180830381865afa158015610b69573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b8d9190614388565b9050610b97611e7d565b610bcd576040517fdc816a8700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001610bdb6004609861440b565b610be591906143ce565b610bf06098436143f7565b03610c27576040517f5baef6b600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8467ffffffffffffffff168467ffffffffffffffff161115610c75576040517f50ff7c0000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8467ffffffffffffffff168467ffffffffffffffff161015610cc3576040517f7a0c0fd600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b80600003610ce3576040516273e5c360e31b815260040160405180910390fd5b610cef609860026143b7565b610cf990436143ce565b8110610d1857604051630a0744c560e01b815260040160405180910390fd5b60085467ffffffffffffffff858116911614610d5857610d3a60046000613ff6565b6008805467ffffffffffffffff191667ffffffffffffffff86161790555b60045460005b81811015610dcb578460048281548110610d7a57610d7a61441f565b90600052602060002090600502016000015403610dc3576040517fbfec555800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600101610d5e565b506040805160c081018252858152336020808301918252600083850181815260608501898152608086018e815260a0870184815260048054600181018255955296517f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b60059095029485015594517f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19c8401805493516001600160a01b0390921674ffffffffffffffffffffffffffffffffffffffffff1990941693909317600160a01b9115159190910217909155517f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19d82015591517f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19e83015591517f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19f90910155815167ffffffffffffffff891681529081018690527f68e0867601a98978930107aee7f425665e61edd70ca594c68ca5da9e81f84c29910160405180910390a150505050505050565b600080610f5f611816565b610f6a906001614435565b60075460085491925090610f9090600160401b900467ffffffffffffffff166001614435565b67ffffffffffffffff168267ffffffffffffffff16111561066657600854600090600190610fcf90600160401b900467ffffffffffffffff168561445d565b610fd9919061445d565b67ffffffffffffffff1690508181604051602001611001929190918252602082015260400190565b6040516020818303038152906040528051906020012091505092915050565b6110286121c0565b611030612213565b6040805160c081018252600a548152600b546001600160a01b0381166020830152600160a01b900460ff1691810191909152600c546060820152600d546080820152600e5460a08201526006546007546000918291611090600f826143f7565b935061109d600e826143f7565b92508383106110b457826110b08161447e565b9350505b6110c78660200135838760400151612059565b6110e757604051633b5f43a360e01b8152600360048201526024016109f5565b6110f286601e61281f565b6110fb86612b31565b61110486612e3e565b6111178860200135838760400151612059565b61113757604051633b5f43a360e01b8152600260048201526024016109f5565b61114b886111468660026143b7565b61281f565b61115488612b31565b61115d88612e3e565b6111708760200135838760400151612059565b61119057604051633b5f43a360e01b8152600160048201526024016109f5565b61119f876111468560026143b7565b6111a887612b31565b6111b187612e3e565b61122784846111c08b80614497565b60008181106111d1576111d161441f565b602002919091013590506111e58b80614497565b60008181106111f6576111f661441f565b6020029190910135905061120a8b80614497565b600081811061121b5761121b61441f565b905060200201356130d2565b6112516112348780614497565b60008181106112455761124561441f565b9050602002013561315f565b60015460208601516040517f51cff8d90000000000000000000000000000000000000000000000000000000081526001600160a01b03918216600482015261010090920416906351cff8d990602401600060405180830381600087803b1580156112ba57600080fd5b505af11580156112ce573d6000803e3d6000fd5b505050507f788e77979e6e6a8a6a5d2c19c58b1ff9671298f54c85ac6f6aa30379aed5861a8560405161130191906144e8565b60405180910390a17fbee3fc8a3523c1a65fa9308ce1f2b8fd90c24975b141b754603194597846e4dd60018054906101000a90046001600160a01b03166001600160a01b0316638a5e8e326040518163ffffffff1660e01b8152600401602060405180830381865afa15801561137b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061139f9190614388565b6040519081526020015b60405180910390a15050505050505050565b60006113c5611e7d565b806114035750600854600160401b900467ffffffffffffffff166113e7611816565b67ffffffffffffffff161180156114035750611401611823565b155b15611415576114106117b2565b905090565b61141d611823565b1561142a57611410610f54565b611432610931565b80156114615750600854600160401b900467ffffffffffffffff16611455611816565b67ffffffffffffffff16145b15611498576040517f36b7884b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b90565b600481815481106114ab57600080fd5b6000918252602090912060059091020180546001820154600283015460038401546004909401549294506001600160a01b03821693600160a01b90920460ff169290919086565b60006114fc611823565b61151957604051633788c6c160e11b815260040160405180910390fd5b6000611523611816565b60085490915067ffffffffffffffff808316600160401b909204161461155c57604051636fbabc7760e01b815260040160405180910390fd5b60085467ffffffffffffffff600160801b90910481169082161161159357604051630c8d9eab60e31b815260040160405180910390fd5b6000806000806000806000806115a761319d565b905060006115b3613257565b600454919650945060005b8181101561178e57600481815481106115d9576115d961441f565b9060005260206000209060050201600401549450600481815481106116005761160061441f565b906000526020600020906005020160010160149054906101000a900460ff16801561164e5750600585815481106116395761163961441f565b90600052602060002090600502016004015487145b801561168c5750600585815481106116685761166861441f565b600091825260209091206001600590920201015460ff878116600160a01b90920416145b1561178657600585815481106116a4576116a461441f565b9060005260206000209060050201600301548b6116c19190614537565b9a5083836040516020016116d692919061456e565b60408051601f19818403018152919052805160209091012098506fffffffffffffffffffffffffffffffff808a169850611711906001614537565b600586815481106117245761172461441f565b90600052602060002090600502016003015461174091906143b7565b61174a8c8a6143b7565b101561177857600585815481106117635761176361441f565b90600052602060002090600502016000015499505b826117828161447e565b9350505b6001016115be565b505050959099149998505050505050505050565b600581815481106114ab57600080fd5b600080610f6a611816565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff1661180c57604051631d77d47760e21b815260040160405180910390fd5b611814613410565b565b600061141060984361440b565b60006118316002609861440b565b61183c6098436143f7565b106118475750600190565b50600090565b6118556121c0565b600061185f611816565b6003546040516397adedb560e01b81523360048201529192506000916001600160a01b03909116906397adedb590602401602060405180830381865afa1580156118ad573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118d19190614388565b90506118db611d8a565b60ff168560ff16101561191a576040517f83d9b7bd00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611922610931565b611958576040517fd1088db600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60085467ffffffffffffffff8381169116146119a0576040517f842a9e0a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60085467ffffffffffffffff838116600160401b9092041614611a88576119c56113bb565b6006556119d460056000613ff6565b600880547fffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff16600160401b67ffffffffffffffff8516908102919091179091556006546040805192835260208301919091527ff0ae472da9c8da86bda4991a549c03a3cb328b5f360ea11a5b8814f32bb85176910160405180910390a1611a88600754604080516020810192909252449082015260600160408051601f198184030181529190528051602090910120600755565b6000611a9682878787611e0f565b90506000611aa48383613464565b9050600060048281548110611abb57611abb61441f565b60009182526020918290206040805160c081018252600593909302909101805480845260018201546001600160a01b03811695850195909552600160a01b90940460ff1615159183019190915260028101546060830152600381015460808301526004015460a0820152600654909250611b3691908a612059565b611b72576006546040517f14ebbbe40000000000000000000000000000000000000000000000000000000081526004016109f591815260200190565b806040015115611bae576040517fa89ac15100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600160048381548110611bc357611bc361441f565b906000526020600020906005020160010160146101000a81548160ff02191690831515021790555060058054905060048381548110611c0457611c0461441f565b90600052602060002090600502016004018190555060056040518060c001604052808360000151815260200183602001516001600160a01b031681526020018a60ff168152602001836060015181526020018a6002611c639190614674565b8460600151611c7291906143b7565b815260209081018a90528254600181810185556000948552938290208351600590920201908155908201519281018054604084015160ff16600160a01b0274ffffffffffffffffffffffffffffffffffffffffff199091166001600160a01b0390951694909417939093179092556060808201516002808501919091556080830151600385015560a0909201516004909301929092558251918301517f13fc17fd71632266fe82092de6dd91a06b4fa68d8dc950492e5421cbed55a6a5928892909190611d40908d90614674565b8560600151611d4f91906143b7565b6040805167ffffffffffffffff909516855260208501939093529183015260608201526080810189905260ff8a1660a082015260c0016113a9565b6008546000908190611daf9067ffffffffffffffff600160801b82048116911661445d565b67ffffffffffffffff169050600060fe8211611dcb5781611dce565b60fe5b611dd9906001614683565b600b5490915060ff600160a01b9091048116908216811115611e0457611dff828261469c565b611e07565b60005b935050505090565b60408051602081018690527fff0000000000000000000000000000000000000000000000000000000000000060f886901b169181019190915260418101839052606181018290526000906081015b604051602081830303815290604052805190602001209050949350505050565b6000611e8b6004609861440b565b611e966098436143f7565b10156118475750600190565b600082815260208190526040902060010154611ebd81612096565b61092c8383612141565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff16611f1657604051637bfa4b9f60e01b815260040160405180910390fd5b600880547fffffffffffff0000ffffffffffffffffffffffffffffffffffffffffffffffff16600160c01b60ff958616027fffffffffffff00ffffffffffffffffffffffffffffffffffffffffffffffffff1617600160c81b93851693909302929092177fffffffffff00ffffffffffffffffffffffffffffffffffffffffffffffffffff16600160d01b9190931602919091179055565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff16611ffd57604051637bfa4b9f60e01b815260040160405180910390fd5b600955565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff1661205157604051631d77d47760e21b815260040160405180910390fd5b61181461350f565b60008160ff1660000361206e5750600161208f565b61207d60ff83166101006146b5565b6120889060026146d0565b8484181090505b9392505050565b6120a08133613548565b50565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610a08576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556120fd3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1615610a08576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b60015460ff16156118145760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a207061757365640000000000000000000000000000000060448201526064016109f5565b600061221d611816565b9050612227611823565b61224457604051633788c6c160e11b815260040160405180910390fd5b60085467ffffffffffffffff828116600160401b909204161461227a57604051636fbabc7760e01b815260040160405180910390fd5b60085467ffffffffffffffff600160801b9091048116908216116122b157604051630c8d9eab60e31b815260040160405180910390fd5b600454604051818152600091829182918291829182917f6752c5e71c95fb93bc7137adeb115a33fa4e54e2683e33d3f90c2bb1c4b6c2a59060200160405180910390a16005546040519081527f4c03de6a759749c0c9387b7014634dc5c6af610e1366023d90751c783a998f8d9060200160405180910390a1612332613257565b6040805183815260ff831660208201529295509093507f34e8eda4cd857cd2865becf58a47748f31415f4a382cbb2cc0c64b9a27c717be910160405180910390a1600061237d61319d565b905060005b828110156127595760006004828154811061239f5761239f61441f565b600091825260208083206040805160c08101825260059485029092018054835260018101546001600160a01b03811694840194909452600160a01b90930460ff16151590820152600282015460608201526003820154608082015260049091015460a0820181905282549194509291908390811061241f5761241f61441f565b60009182526020918290206040805160c0810182526005939093029091018054835260018101546001600160a01b03811694840194909452600160a01b90930460ff1682820152600283015460608301526003830154608083015260049092015460a082015290840151909150801561249b57508060a0015188145b80156124b05750806040015160ff168760ff16145b156125a55760808101516124c4908d614537565b9b50848b6040516020016124d992919061456e565b60408051601f19818403018152919052805160209091012099506fffffffffffffffffffffffffffffffff808b169950612514906001614537565b816080015161252391906143b7565b61252d8d8b6143b7565b1015612597578051600a556020810151600b8054604084015160ff16600160a01b0274ffffffffffffffffffffffffffffffffffffffffff199091166001600160a01b03909316929092179190911790556060810151600c556080810151600d5560a0810151600e555b8a6125a18161447e565b9b50505b826040015180156125ce57508060a00151881415806125ce5750806040015160ff168760ff1614155b80156125ef5750600854600160d01b900460ff166125ed6064446143f7565b105b1561269b5760035460208201516001600160a01b039091169063d009b2d6906126198a6002614674565b60085461263290609890600160c01b900460ff166143b7565b61263c91906143b7565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401600060405180830381600087803b15801561268257600080fd5b505af1158015612696573d6000803e3d6000fd5b505050505b826040015161274b5760035460208401516001600160a01b039091169063d009b2d6906126c98a6002614674565b6008546126e290609890600160c81b900460ff166143b7565b6126ec91906143b7565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401600060405180830381600087803b15801561273257600080fd5b505af1158015612746573d6000803e3d6000fd5b505050505b836001019350505050612382565b506002546040517fffb98fe300000000000000000000000000000000000000000000000000000000815261ffff891660048201526001600160a01b039091169063ffb98fe390602401600060405180830381600087803b1580156127bc57600080fd5b505af11580156127d0573d6000803e3d6000fd5b50506008805467ffffffffffffffff909c16600160801b027fffffffffffffffff0000000000000000ffffffffffffffffffffffffffffffff909c169b909b17909a5550505050505050505050565b600754600090612831906080906143f7565b9050600061289461284560a0860186614497565b8080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525050505060608601358461288c60a0890160808a016146e0565b6006546135bb565b60408051858152602081018390529192507f94e252069a85aa79db21f5bd8ca4e14dd3a3927aa492711017a2c8ddad95af00910160405180910390a161291c6128dd8580614497565b80806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250505050602086013585610400613733565b600e54146129475760405163755f0a2560e01b815260016004820152602481018290526044016109f5565b61295460a0850185614497565b60008181106129655761296561441f565b9050602002013584806040019061297c9190614497565b600081811061298d5761298d61441f565b90506020020135146129bc5760405163755f0a2560e01b815260026004820152602481018290526044016109f5565b6000806129cc60e0870187614497565b9050116129dd578460200135612a12565b6129ea60e0860186614497565b60008181106129fb576129fb61441f565b9050602002810190612a0d91906146fb565b606001355b9050612a70612a246040870187614497565b80806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250505050606087013585612a6b60a08a0160808b016146e0565b613733565b8114612a995760405163755f0a2560e01b815260036004820152602481018390526044016109f5565b6000612aa860e0870187614497565b90501115612ae05760408051602080880135908201529081018390526060016040516020818303038152906040528051906020012091505b81612aeb8680614497565b6000818110612afc57612afc61441f565b9050602002013514612b2a5760405163755f0a2560e01b8152600481810152602481018390526044016109f5565b5050505050565b6001546000908190819061010090046001600160a01b031663c81e25ab612b5b60c08701876146fb565b602001356040518263ffffffff1660e01b8152600401612b7d91815260200190565b60c060405180830381865afa158015612b9a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612bbe919061471b565b509396509194509250506001600160a01b0384169050612c1e57612be560c08501856146fb565b602001356040517f2396d34e0000000000000000000000000000000000000000000000000000000081526004016109f591815260200190565b6000612c41612c3060c08701876146fb565b6114989060608101906040016146e0565b90506000612c4f84846138a1565b9050808263ffffffff1610612ca457612c6b60c08701876146fb565b602001356040517f1362e4a00000000000000000000000000000000000000000000000000000000081526004016109f591815260200190565b6000612cd3612cb660c08901896146fb565b612cc79060608101906040016146e0565b60201c63ffffffff1690565b90506000612ce58860200135866138bc565b63ffffffff16905067ffffffffffffffff82168114612d4457612d0b60c08901896146fb565b602001356040517f6dd6a24f0000000000000000000000000000000000000000000000000000000081526004016109f591815260200190565b612dea87612d5560c08b018b6146fb565b612d5f9080614793565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050505060208b0135612da560c08d018d6146fb565b60200135612db660c08e018e6146fb565b612dc79060608101906040016146e0565b612dd460c08f018f6146fb565b612de59060808101906060016146e0565b6138e3565b612e3457612dfb60c08901896146fb565b602001356040517fdb12fb9d0000000000000000000000000000000000000000000000000000000081526004016109f591815260200190565b5050505050505050565b612e4b60e0820182614497565b9050600003612e575750565b612f78612e6760e0830183614497565b6000818110612e7857612e7861441f565b9050602002810190612e8a91906146fb565b612e989060208101906147da565b612ea560e0840184614497565b6000818110612eb657612eb661441f565b9050602002810190612ec891906146fb565b612ed6906020810190614793565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250612f189250505060e0850185614497565b6000818110612f2957612f2961441f565b9050602002810190612f3b91906146fb565b60400135612f4c60e0860186614497565b6000818110612f5d57612f5d61441f565b9050602002810190612f6f91906146fb565b6060013561397a565b612fe557612f8960e0820182614497565b6000818110612f9a57612f9a61441f565b9050602002810190612fac91906146fb565b606001356040517fd740df610000000000000000000000000000000000000000000000000000000081526004016109f591815260200190565b6020810135613064612ffa60e0840184614497565b600081811061300b5761300b61441f565b905060200281019061301d91906146fb565b6040013561302e60e0850185614497565b600081811061303f5761303f61441f565b905060200281019061305191906146fb565b61305f9060208101906147da565b613a0d565b146120a05761307660e0820182614497565b60008181106130875761308761441f565b905060200281019061309991906146fb565b606001356040517f82f2469d0000000000000000000000000000000000000000000000000000000081526004016109f591815260200190565b8385101561311f578183106130fa57604051633d386eb360e11b815260040160405180910390fd5b80821061311a57604051633588c6d360e11b815260040160405180910390fd5b612b2a565b82821061313f57604051633d386eb360e11b815260040160405180910390fd5b808310612b2a57604051633588c6d360e11b815260040160405180910390fd5b60095481106120a0576040517fb6052cdf000000000000000000000000000000000000000000000000000000008152600481018290526024016109f5565b60606131a7611823565b6131c457604051633788c6c160e11b815260040160405180910390fd5b60006131ce611816565b60085490915067ffffffffffffffff808316600160401b909204161461320757604051636fbabc7760e01b815260040160405180910390fd5b6007546040516020016132429181527f3100000000000000000000000000000000000000000000000000000000000000602082015260210190565b60405160208183030381529060405291505090565b600080600080600080600080600061326d613a5b565b60045490915060005b818110156133ff57600481815481106132915761329161441f565b906000526020600020906005020160010160149054906101000a900460ff16156133f757600481815481106132c8576132c861441f565b9060005260206000209060050201600401549350600584815481106132ef576132ef61441f565b9060005260206000209060050201600301548961330c9190614537565b9850828160405160200161332192919061456e565b60408051601f19818403018152919052805160209091012097506fffffffffffffffffffffffffffffffff808916975061335c906001614537565b6005858154811061336f5761336f61441f565b90600052602060002090600502016003015461338b91906143b7565b6133958a896143b7565b10156133f757600584815481106133ae576133ae61441f565b9060005260206000209060050201600401549550600584815481106133d5576133d561441f565b906000526020600020906005020160010160149054906101000a900460ff1694505b600101613276565b509399929850919650505050505050565b6134186121c0565b6001805460ff1916811790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258335b6040516001600160a01b03909116815260200160405180910390a1565b6000805b6004548110156134dc5783600482815481106134865761348661441f565b9060005260206000209060050201600001541480156134c85750600481815481106134b3576134b361441f565b90600052602060002090600502016003015483145b156134d4579050610666565b600101613468565b506040517fd950091500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b613517613ae4565b6001805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa33613447565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610a085761357981613b36565b613584836020613b48565b6040516020016135959291906147f7565b60408051601f198184030181529082905262461bcd60e51b82526109f591600401614878565b6000806135ca87878786613d0d565b9050826136cf856000808267ffffffffffffffff1690506008817eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff16901b600882901c7eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff161790506010817dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff16901b601082901c7dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff161790506020817bffffffff00000000ffffffff00000000ffffffff00000000ffffffff16901b602082901c7bffffffff00000000ffffffff00000000ffffffff00000000ffffffff1617905080915050919050565b826040516020016137119392919092835260c09190911b77ffffffffffffffffffffffffffffffffffffffffffffffff19166020830152602882015260480190565b6040516020818303038152906040528051906020012091505095945050505050565b600080613741868686613d83565b9050613845836000808267ffffffffffffffff1690506008817eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff16901b600882901c7eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff161790506010817dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff16901b601082901c7dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff161790506020817bffffffff00000000ffffffff00000000ffffffff00000000ffffffff16901b602082901c7bffffffff00000000ffffffff00000000ffffffff00000000ffffffff1617905080915050919050565b8160405160200161388092919060c09290921b77ffffffffffffffffffffffffffffffffffffffffffffffff19168252600882015260280190565b60405160208183030381529060405280519060200120915050949350505050565b60006138ad828461469c565b60ff166001901b905092915050565b600060e083901c6138ce83602061469c565b60ff168163ffffffff16901c91505092915050565b6000806138f286868686613deb565b9050600061394d826040517f19457468657265756d205369676e6564204d6573736167653a0a3332000000006020820152603c8101829052600090605c01604051602081830303815290604052805190602001209050919050565b9050886001600160a01b0316613963828a613e36565b6001600160a01b0316149998505050505050505050565b6000806139878484613eb5565b905060006139e2826040517f19457468657265756d205369676e6564204d6573736167653a0a3332000000006020820152603c8101829052600090605c01604051602081830303815290604052805190602001209050919050565b9050866001600160a01b03166139f88288613e36565b6001600160a01b031614979650505050505050565b60008282604051602001613a3d92919091825260601b6bffffffffffffffffffffffff1916602082015260340190565b60405160208183030381529060405280519060200120905092915050565b6060613a65611823565b613a8257604051633788c6c160e11b815260040160405180910390fd5b6000613a8c611816565b60085490915067ffffffffffffffff808316600160401b9092041614613ac557604051636fbabc7760e01b815260040160405180910390fd5b600754604051602001613242918152600360fc1b602082015260210190565b60015460ff166118145760405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f742070617573656400000000000000000000000060448201526064016109f5565b60606106666001600160a01b03831660145b60606000613b578360026143b7565b613b62906002614537565b67ffffffffffffffff811115613b7a57613b7a6148ab565b6040519080825280601f01601f191660200182016040528015613ba4576020820181803683370190505b509050600360fc1b81600081518110613bbf57613bbf61441f565b60200101906001600160f81b031916908160001a9053507f780000000000000000000000000000000000000000000000000000000000000081600181518110613c0a57613c0a61441f565b60200101906001600160f81b031916908160001a9053506000613c2e8460026143b7565b613c39906001614537565b90505b6001811115613cbe577f303132333435363738396162636465660000000000000000000000000000000085600f1660108110613c7a57613c7a61441f565b1a60f81b828281518110613c9057613c9061441f565b60200101906001600160f81b031916908160001a90535060049490941c93613cb7816148c1565b9050613c3c565b50831561208f5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e7460448201526064016109f5565b8260005b8551811015613d7a576000613d276002866143f7565b15613d33576000613d36565b60015b9050613d5d83888481518110613d4e57613d4e61441f565b60200260200101518387613ed1565b9250600185901c9450508080613d729061447e565b915050613d11565b50949350505050565b8160005b8451811015613de3576000613d9d6002856143f7565b6000149050613dc683878481518110613db857613db861441f565b602002602001015183613f31565b9250600184901c9350508080613ddb9061447e565b915050613d87565b509392505050565b604080516020810186905290810184905277ffffffffffffffffffffffffffffffffffffffffffffffff1960c084811b8216606084015283901b166068820152600090607001611e5d565b600080600080613e4585613f98565b6040805160008152602081018083528b905260ff8316918101919091526060810184905260808101839052929550909350915060019060a0016020604051602081039080840390855afa158015613ea0573d6000803e3d6000fd5b5050604051601f190151979650505050505050565b6040805160208101849052908101829052600090606001613a3d565b60008215613f11576040805160208101849052908101869052606081018590526080016040516020818303038152906040528051906020012090506107f2565b604080516020810184905290810185905260608101869052608001611e5d565b60008115613f6a57604080516020810186905290810184905260600160405160208183030381529060405280519060200120905061208f565b5050604080516020808201939093528082019390935280518084038201815260609093019052815191012090565b60008060008351604114613fd8576040517f4be6321b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50505060208101516040820151606090920151909260009190911a90565b50805460008255600502906000526020600020908101906120a091905b8082111561405b57600080825560018201805474ffffffffffffffffffffffffffffffffffffffffff1916905560028201819055600382018190556004820155600501614013565b5090565b60006020828403121561407157600080fd5b81356001600160e01b03198116811461208f57600080fd5b6001600160a01b03811681146120a057600080fd5b60ff811681146120a057600080fd5b600080604083850312156140c057600080fd5b82356140cb81614089565b915060208301356140db8161409e565b809150509250929050565b6000602082840312156140f857600080fd5b5035919050565b6020808252825182820181905260009190848201906040850190845b818110156141825761416f838551805182526001600160a01b03602082015116602083015260ff6040820151166040830152606081015160608301526080810151608083015260a081015160a08301525050565b9284019260c0929092019160010161411b565b50909695505050505050565b600080604083850312156141a157600080fd5b8235915060208301356140db81614089565b803567ffffffffffffffff811681146141cb57600080fd5b919050565b600080604083850312156141e357600080fd5b823591506141f3602084016141b3565b90509250929050565b6000610100828403121561420f57600080fd5b50919050565b60008060006060848603121561422a57600080fd5b833567ffffffffffffffff8082111561424257600080fd5b61424e878388016141fc565b9450602086013591508082111561426457600080fd5b614270878388016141fc565b9350604086013591508082111561428657600080fd5b50614293868287016141fc565b9150509250925092565b6000806000606084860312156142b257600080fd5b83356142bd8161409e565b95602085013595506040909401359392505050565b600080600080608085870312156142e857600080fd5b8435935060208501356142fa8161409e565b93969395505050506040820135916060013590565b60008060006060848603121561432457600080fd5b833561432f8161409e565b9250602084013561433f8161409e565b9150604084013561434f8161409e565b809150509250925092565b60008060006060848603121561436f57600080fd5b8335925060208401359150604084013561434f8161409e565b60006020828403121561439a57600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b8082028115828204841417610666576106666143a1565b81810381811115610666576106666143a1565b634e487b7160e01b600052601260045260246000fd5b600082614406576144066143e1565b500690565b60008261441a5761441a6143e1565b500490565b634e487b7160e01b600052603260045260246000fd5b67ffffffffffffffff818116838216019080821115614456576144566143a1565b5092915050565b67ffffffffffffffff828116828216039080821115614456576144566143a1565b600060018201614490576144906143a1565b5060010190565b6000808335601e198436030181126144ae57600080fd5b83018035915067ffffffffffffffff8211156144c957600080fd5b6020019150600581901b36038213156144e157600080fd5b9250929050565b60c081016106668284805182526001600160a01b03602082015116602083015260ff6040820151166040830152606081015160608301526080810151608083015260a081015160a08301525050565b80820180821115610666576106666143a1565b60005b8381101561456557818101518382015260200161454d565b50506000910152565b6000835161458081846020880161454a565b9190910191825250602001919050565b600181815b808511156145cb5781600019048211156145b1576145b16143a1565b808516156145be57918102915b93841c9390800290614595565b509250929050565b6000826145e257506001610666565b816145ef57506000610666565b8160018114614605576002811461460f5761462b565b6001915050610666565b60ff841115614620576146206143a1565b50506001821b610666565b5060208310610133831016604e8410600b841016171561464e575081810a610666565b6146588383614590565b806000190482111561466c5761466c6143a1565b029392505050565b600061208f60ff8416836145d3565b60ff8181168382160190811115610666576106666143a1565b60ff8281168282160390811115610666576106666143a1565b61ffff828116828216039080821115614456576144566143a1565b600061208f61ffff8416836145d3565b6000602082840312156146f257600080fd5b61208f826141b3565b60008235607e1983360301811261471157600080fd5b9190910192915050565b60008060008060008060c0878903121561473457600080fd5b865161473f81614089565b60208801519096506147508161409e565b60408801519095506147618161409e565b6060880151909450801515811461477757600080fd5b809350506080870151915060a087015190509295509295509295565b6000808335601e198436030181126147aa57600080fd5b83018035915067ffffffffffffffff8211156147c557600080fd5b6020019150368190038213156144e157600080fd5b6000602082840312156147ec57600080fd5b813561208f81614089565b7f416363657373436f6e74726f6c3a206163636f756e742000000000000000000081526000835161482f81601785016020880161454a565b7f206973206d697373696e6720726f6c6520000000000000000000000000000000601791840191820152835161486c81602884016020880161454a565b01602801949350505050565b602081526000825180602084015261489781604085016020870161454a565b601f01601f19169190910160400192915050565b634e487b7160e01b600052604160045260246000fd5b6000816148d0576148d06143a1565b50600019019056fea26469706673582212200f9f0a55ccd6f0cb7269fe52233ea174faebf4c052751953813f1866c96736b964736f6c63430008130033", - "deployedBytecode": "0x608060405234801561001057600080fd5b50600436106102775760003560e01c806377c75d1011610160578063b6cd5822116100d8578063dfbf53ae1161008c578063f69ee1d111610071578063f69ee1d1146105d5578063f7b188a5146105e8578063fb00f2f3146105f057600080fd5b8063dfbf53ae14610592578063f4e6fcca146105c257600080fd5b8063ce987745116100bd578063ce98774514610564578063d1e8b63d14610577578063d547741f1461057f57600080fd5b8063b6cd582214610537578063c46b40291461054a57600080fd5b80638456cb591161012f5780638d8b6428116101145780638d8b6428146104f057806391d14854146104f8578063a217fddf1461052f57600080fd5b80638456cb59146104e05780638a19c8bc146104e857600080fd5b806377c75d101461045a5780637fe019c61461046d57806382b39b1b1461048857806383220626146104d857600080fd5b80635c975abb116101f357806364c34a85116101c257806369da9114116101a757806369da9114146103de5780636f94aaf2146103f157806372286cba1461040c57600080fd5b806364c34a85146103a957806369bfac01146103b157600080fd5b80635c975abb146103705780635d4844ea1461037b57806362fd29ae1461038e57806363f5cf7c1461039657600080fd5b80632a4e62491161024a5780632f3906da1161022f5780632f3906da1461034257806336568abe1461034a5780635838d6731461035d57600080fd5b80632a4e6249146103185780632f2ff15d1461032d57600080fd5b806301ffc9a71461027c5780631736d472146102a457806318350096146102b7578063248a9ca3146102e7575b600080fd5b61028f61028a36600461405f565b610603565b60405190151581526020015b60405180910390f35b61028f6102b23660046140ad565b61066c565b6001546102cf9061010090046001600160a01b031681565b6040516001600160a01b03909116815260200161029b565b61030a6102f53660046140e6565b60009081526020819052604090206001015490565b60405190815260200161029b565b6103206107fa565b60405161029b91906140ff565b61034061033b36600461418e565b610907565b005b61028f610931565b61034061035836600461418e565b61097b565b61034061036b3660046141d0565b610a0c565b60015460ff1661028f565b6003546102cf906001600160a01b031681565b61030a610f54565b6103406103a4366004614215565b611020565b61030a6113bb565b6008546103c59067ffffffffffffffff1681565b60405167ffffffffffffffff909116815260200161029b565b6002546102cf906001600160a01b031681565b6008546103c590600160801b900467ffffffffffffffff1681565b61041f61041a3660046140e6565b61149b565b604080519687526001600160a01b039095166020870152921515938501939093526060840152608083019190915260a082015260c00161029b565b61028f6104683660046140e6565b6114f2565b6008546103c590600160401b900467ffffffffffffffff1681565b61049b6104963660046140e6565b6117a2565b604080519687526001600160a01b03909516602087015260ff909316938501939093526060840152608083019190915260a082015260c00161029b565b61030a6117b2565b6103406117bd565b6103c5611816565b61028f611823565b61028f61050636600461418e565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b61030a600081565b61034061054536600461429d565b61184d565b610552611d8a565b60405160ff909116815260200161029b565b61030a6105723660046142d2565b611e0f565b61028f611e7d565b61034061058d36600461418e565b611ea2565b600a54600b54600c54600d54600e5461049b94936001600160a01b03811693600160a01b90910460ff1692909186565b6103406105d036600461430f565b611ec7565b6103406105e33660046140e6565b611fae565b610340612002565b61028f6105fe36600461435a565b612059565b60006001600160e01b031982167f7965db0b00000000000000000000000000000000000000000000000000000000148061066657507f01ffc9a7000000000000000000000000000000000000000000000000000000006001600160e01b03198316145b92915050565b60035460405163d1052d1f60e01b81526001600160a01b038481166004830152600092839291169063d1052d1f90602401602060405180830381865afa1580156106ba573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106de9190614388565b90506106e8610931565b1561071f576040517fe2586bcc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8060000361073f576040516273e5c360e31b815260040160405180910390fd5b61074b609860026143b7565b61075590436143ce565b811061077457604051630a0744c560e01b815260040160405180910390fd5b6003546040516397adedb560e01b81526001600160a01b0386811660048301526107f29216906397adedb590602401602060405180830381865afa1580156107c0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107e49190614388565b6107ec6113bb565b85612059565b949350505050565b6060610804611823565b61082157604051633788c6c160e11b815260040160405180910390fd5b600061082b611816565b60085490915067ffffffffffffffff808316600160401b909204161461086457604051636fbabc7760e01b815260040160405180910390fd5b6005805480602002602001604051908101604052809291908181526020016000905b828210156108fd5760008481526020908190206040805160c08101825260058602909201805483526001808201546001600160a01b03811685870152600160a01b900460ff169284019290925260028101546060840152600381015460808401526004015460a08301529083529092019101610886565b5050505091505090565b60008281526020819052604090206001015461092281612096565b61092c83836120a3565b505050565b60008061093f6098436143f7565b905061094d6004609861440b565b811015801561096657506109636002609861440b565b81105b1561097357600191505090565b600091505090565b6001600160a01b03811633146109fe5760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b610a088282612141565b5050565b610a146121c0565b6000610a1e611816565b6003546040516397adedb560e01b81523360048201529192506000916001600160a01b03909116906397adedb590602401602060405180830381865afa158015610a6c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a909190614388565b6003546040517f830a053e0000000000000000000000000000000000000000000000000000000081523360048201529192506000916001600160a01b039091169063830a053e90602401602060405180830381865afa158015610af7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b1b9190614388565b60035460405163d1052d1f60e01b81523360048201529192506000916001600160a01b039091169063d1052d1f90602401602060405180830381865afa158015610b69573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b8d9190614388565b9050610b97611e7d565b610bcd576040517fdc816a8700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001610bdb6004609861440b565b610be591906143ce565b610bf06098436143f7565b03610c27576040517f5baef6b600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8467ffffffffffffffff168467ffffffffffffffff161115610c75576040517f50ff7c0000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8467ffffffffffffffff168467ffffffffffffffff161015610cc3576040517f7a0c0fd600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b80600003610ce3576040516273e5c360e31b815260040160405180910390fd5b610cef609860026143b7565b610cf990436143ce565b8110610d1857604051630a0744c560e01b815260040160405180910390fd5b60085467ffffffffffffffff858116911614610d5857610d3a60046000613ff6565b6008805467ffffffffffffffff191667ffffffffffffffff86161790555b60045460005b81811015610dcb578460048281548110610d7a57610d7a61441f565b90600052602060002090600502016000015403610dc3576040517fbfec555800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600101610d5e565b506040805160c081018252858152336020808301918252600083850181815260608501898152608086018e815260a0870184815260048054600181018255955296517f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b60059095029485015594517f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19c8401805493516001600160a01b0390921674ffffffffffffffffffffffffffffffffffffffffff1990941693909317600160a01b9115159190910217909155517f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19d82015591517f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19e83015591517f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19f90910155815167ffffffffffffffff891681529081018690527f68e0867601a98978930107aee7f425665e61edd70ca594c68ca5da9e81f84c29910160405180910390a150505050505050565b600080610f5f611816565b610f6a906001614435565b60075460085491925090610f9090600160401b900467ffffffffffffffff166001614435565b67ffffffffffffffff168267ffffffffffffffff16111561066657600854600090600190610fcf90600160401b900467ffffffffffffffff168561445d565b610fd9919061445d565b67ffffffffffffffff1690508181604051602001611001929190918252602082015260400190565b6040516020818303038152906040528051906020012091505092915050565b6110286121c0565b611030612213565b6040805160c081018252600a548152600b546001600160a01b0381166020830152600160a01b900460ff1691810191909152600c546060820152600d546080820152600e5460a08201526006546007546000918291611090600f826143f7565b935061109d600e826143f7565b92508383106110b457826110b08161447e565b9350505b6110c78660200135838760400151612059565b6110e757604051633b5f43a360e01b8152600360048201526024016109f5565b6110f286601e61281f565b6110fb86612b31565b61110486612e3e565b6111178860200135838760400151612059565b61113757604051633b5f43a360e01b8152600260048201526024016109f5565b61114b886111468660026143b7565b61281f565b61115488612b31565b61115d88612e3e565b6111708760200135838760400151612059565b61119057604051633b5f43a360e01b8152600160048201526024016109f5565b61119f876111468560026143b7565b6111a887612b31565b6111b187612e3e565b61122784846111c08b80614497565b60008181106111d1576111d161441f565b602002919091013590506111e58b80614497565b60008181106111f6576111f661441f565b6020029190910135905061120a8b80614497565b600081811061121b5761121b61441f565b905060200201356130d2565b6112516112348780614497565b60008181106112455761124561441f565b9050602002013561315f565b60015460208601516040517f51cff8d90000000000000000000000000000000000000000000000000000000081526001600160a01b03918216600482015261010090920416906351cff8d990602401600060405180830381600087803b1580156112ba57600080fd5b505af11580156112ce573d6000803e3d6000fd5b505050507f788e77979e6e6a8a6a5d2c19c58b1ff9671298f54c85ac6f6aa30379aed5861a8560405161130191906144e8565b60405180910390a17fbee3fc8a3523c1a65fa9308ce1f2b8fd90c24975b141b754603194597846e4dd60018054906101000a90046001600160a01b03166001600160a01b0316638a5e8e326040518163ffffffff1660e01b8152600401602060405180830381865afa15801561137b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061139f9190614388565b6040519081526020015b60405180910390a15050505050505050565b60006113c5611e7d565b806114035750600854600160401b900467ffffffffffffffff166113e7611816565b67ffffffffffffffff161180156114035750611401611823565b155b15611415576114106117b2565b905090565b61141d611823565b1561142a57611410610f54565b611432610931565b80156114615750600854600160401b900467ffffffffffffffff16611455611816565b67ffffffffffffffff16145b15611498576040517f36b7884b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b90565b600481815481106114ab57600080fd5b6000918252602090912060059091020180546001820154600283015460038401546004909401549294506001600160a01b03821693600160a01b90920460ff169290919086565b60006114fc611823565b61151957604051633788c6c160e11b815260040160405180910390fd5b6000611523611816565b60085490915067ffffffffffffffff808316600160401b909204161461155c57604051636fbabc7760e01b815260040160405180910390fd5b60085467ffffffffffffffff600160801b90910481169082161161159357604051630c8d9eab60e31b815260040160405180910390fd5b6000806000806000806000806115a761319d565b905060006115b3613257565b600454919650945060005b8181101561178e57600481815481106115d9576115d961441f565b9060005260206000209060050201600401549450600481815481106116005761160061441f565b906000526020600020906005020160010160149054906101000a900460ff16801561164e5750600585815481106116395761163961441f565b90600052602060002090600502016004015487145b801561168c5750600585815481106116685761166861441f565b600091825260209091206001600590920201015460ff878116600160a01b90920416145b1561178657600585815481106116a4576116a461441f565b9060005260206000209060050201600301548b6116c19190614537565b9a5083836040516020016116d692919061456e565b60408051601f19818403018152919052805160209091012098506fffffffffffffffffffffffffffffffff808a169850611711906001614537565b600586815481106117245761172461441f565b90600052602060002090600502016003015461174091906143b7565b61174a8c8a6143b7565b101561177857600585815481106117635761176361441f565b90600052602060002090600502016000015499505b826117828161447e565b9350505b6001016115be565b505050959099149998505050505050505050565b600581815481106114ab57600080fd5b600080610f6a611816565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff1661180c57604051631d77d47760e21b815260040160405180910390fd5b611814613410565b565b600061141060984361440b565b60006118316002609861440b565b61183c6098436143f7565b106118475750600190565b50600090565b6118556121c0565b600061185f611816565b6003546040516397adedb560e01b81523360048201529192506000916001600160a01b03909116906397adedb590602401602060405180830381865afa1580156118ad573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118d19190614388565b90506118db611d8a565b60ff168560ff16101561191a576040517f83d9b7bd00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611922610931565b611958576040517fd1088db600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60085467ffffffffffffffff8381169116146119a0576040517f842a9e0a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60085467ffffffffffffffff838116600160401b9092041614611a88576119c56113bb565b6006556119d460056000613ff6565b600880547fffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff16600160401b67ffffffffffffffff8516908102919091179091556006546040805192835260208301919091527ff0ae472da9c8da86bda4991a549c03a3cb328b5f360ea11a5b8814f32bb85176910160405180910390a1611a88600754604080516020810192909252449082015260600160408051601f198184030181529190528051602090910120600755565b6000611a9682878787611e0f565b90506000611aa48383613464565b9050600060048281548110611abb57611abb61441f565b60009182526020918290206040805160c081018252600593909302909101805480845260018201546001600160a01b03811695850195909552600160a01b90940460ff1615159183019190915260028101546060830152600381015460808301526004015460a0820152600654909250611b3691908a612059565b611b72576006546040517f14ebbbe40000000000000000000000000000000000000000000000000000000081526004016109f591815260200190565b806040015115611bae576040517fa89ac15100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600160048381548110611bc357611bc361441f565b906000526020600020906005020160010160146101000a81548160ff02191690831515021790555060058054905060048381548110611c0457611c0461441f565b90600052602060002090600502016004018190555060056040518060c001604052808360000151815260200183602001516001600160a01b031681526020018a60ff168152602001836060015181526020018a6002611c639190614674565b8460600151611c7291906143b7565b815260209081018a90528254600181810185556000948552938290208351600590920201908155908201519281018054604084015160ff16600160a01b0274ffffffffffffffffffffffffffffffffffffffffff199091166001600160a01b0390951694909417939093179092556060808201516002808501919091556080830151600385015560a0909201516004909301929092558251918301517f13fc17fd71632266fe82092de6dd91a06b4fa68d8dc950492e5421cbed55a6a5928892909190611d40908d90614674565b8560600151611d4f91906143b7565b6040805167ffffffffffffffff909516855260208501939093529183015260608201526080810189905260ff8a1660a082015260c0016113a9565b6008546000908190611daf9067ffffffffffffffff600160801b82048116911661445d565b67ffffffffffffffff169050600060fe8211611dcb5781611dce565b60fe5b611dd9906001614683565b600b5490915060ff600160a01b9091048116908216811115611e0457611dff828261469c565b611e07565b60005b935050505090565b60408051602081018690527fff0000000000000000000000000000000000000000000000000000000000000060f886901b169181019190915260418101839052606181018290526000906081015b604051602081830303815290604052805190602001209050949350505050565b6000611e8b6004609861440b565b611e966098436143f7565b10156118475750600190565b600082815260208190526040902060010154611ebd81612096565b61092c8383612141565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff16611f1657604051637bfa4b9f60e01b815260040160405180910390fd5b600880547fffffffffffff0000ffffffffffffffffffffffffffffffffffffffffffffffff16600160c01b60ff958616027fffffffffffff00ffffffffffffffffffffffffffffffffffffffffffffffffff1617600160c81b93851693909302929092177fffffffffff00ffffffffffffffffffffffffffffffffffffffffffffffffffff16600160d01b9190931602919091179055565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff16611ffd57604051637bfa4b9f60e01b815260040160405180910390fd5b600955565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff1661205157604051631d77d47760e21b815260040160405180910390fd5b61181461350f565b60008160ff1660000361206e5750600161208f565b61207d60ff83166101006146b5565b6120889060026146d0565b8484181090505b9392505050565b6120a08133613548565b50565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610a08576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556120fd3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1615610a08576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b60015460ff16156118145760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a207061757365640000000000000000000000000000000060448201526064016109f5565b600061221d611816565b9050612227611823565b61224457604051633788c6c160e11b815260040160405180910390fd5b60085467ffffffffffffffff828116600160401b909204161461227a57604051636fbabc7760e01b815260040160405180910390fd5b60085467ffffffffffffffff600160801b9091048116908216116122b157604051630c8d9eab60e31b815260040160405180910390fd5b600454604051818152600091829182918291829182917f6752c5e71c95fb93bc7137adeb115a33fa4e54e2683e33d3f90c2bb1c4b6c2a59060200160405180910390a16005546040519081527f4c03de6a759749c0c9387b7014634dc5c6af610e1366023d90751c783a998f8d9060200160405180910390a1612332613257565b6040805183815260ff831660208201529295509093507f34e8eda4cd857cd2865becf58a47748f31415f4a382cbb2cc0c64b9a27c717be910160405180910390a1600061237d61319d565b905060005b828110156127595760006004828154811061239f5761239f61441f565b600091825260208083206040805160c08101825260059485029092018054835260018101546001600160a01b03811694840194909452600160a01b90930460ff16151590820152600282015460608201526003820154608082015260049091015460a0820181905282549194509291908390811061241f5761241f61441f565b60009182526020918290206040805160c0810182526005939093029091018054835260018101546001600160a01b03811694840194909452600160a01b90930460ff1682820152600283015460608301526003830154608083015260049092015460a082015290840151909150801561249b57508060a0015188145b80156124b05750806040015160ff168760ff16145b156125a55760808101516124c4908d614537565b9b50848b6040516020016124d992919061456e565b60408051601f19818403018152919052805160209091012099506fffffffffffffffffffffffffffffffff808b169950612514906001614537565b816080015161252391906143b7565b61252d8d8b6143b7565b1015612597578051600a556020810151600b8054604084015160ff16600160a01b0274ffffffffffffffffffffffffffffffffffffffffff199091166001600160a01b03909316929092179190911790556060810151600c556080810151600d5560a0810151600e555b8a6125a18161447e565b9b50505b826040015180156125ce57508060a00151881415806125ce5750806040015160ff168760ff1614155b80156125ef5750600854600160d01b900460ff166125ed6064446143f7565b105b1561269b5760035460208201516001600160a01b039091169063d009b2d6906126198a6002614674565b60085461263290609890600160c01b900460ff166143b7565b61263c91906143b7565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401600060405180830381600087803b15801561268257600080fd5b505af1158015612696573d6000803e3d6000fd5b505050505b826040015161274b5760035460208401516001600160a01b039091169063d009b2d6906126c98a6002614674565b6008546126e290609890600160c81b900460ff166143b7565b6126ec91906143b7565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401600060405180830381600087803b15801561273257600080fd5b505af1158015612746573d6000803e3d6000fd5b505050505b836001019350505050612382565b506002546040517fffb98fe300000000000000000000000000000000000000000000000000000000815261ffff891660048201526001600160a01b039091169063ffb98fe390602401600060405180830381600087803b1580156127bc57600080fd5b505af11580156127d0573d6000803e3d6000fd5b50506008805467ffffffffffffffff909c16600160801b027fffffffffffffffff0000000000000000ffffffffffffffffffffffffffffffff909c169b909b17909a5550505050505050505050565b600754600090612831906080906143f7565b9050600061289461284560a0860186614497565b8080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525050505060608601358461288c60a0890160808a016146e0565b6006546135bb565b60408051858152602081018390529192507f94e252069a85aa79db21f5bd8ca4e14dd3a3927aa492711017a2c8ddad95af00910160405180910390a161291c6128dd8580614497565b80806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250505050602086013585610400613733565b600e54146129475760405163755f0a2560e01b815260016004820152602481018290526044016109f5565b61295460a0850185614497565b60008181106129655761296561441f565b9050602002013584806040019061297c9190614497565b600081811061298d5761298d61441f565b90506020020135146129bc5760405163755f0a2560e01b815260026004820152602481018290526044016109f5565b6000806129cc60e0870187614497565b9050116129dd578460200135612a12565b6129ea60e0860186614497565b60008181106129fb576129fb61441f565b9050602002810190612a0d91906146fb565b606001355b9050612a70612a246040870187614497565b80806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250505050606087013585612a6b60a08a0160808b016146e0565b613733565b8114612a995760405163755f0a2560e01b815260036004820152602481018390526044016109f5565b6000612aa860e0870187614497565b90501115612ae05760408051602080880135908201529081018390526060016040516020818303038152906040528051906020012091505b81612aeb8680614497565b6000818110612afc57612afc61441f565b9050602002013514612b2a5760405163755f0a2560e01b8152600481810152602481018390526044016109f5565b5050505050565b6001546000908190819061010090046001600160a01b031663c81e25ab612b5b60c08701876146fb565b602001356040518263ffffffff1660e01b8152600401612b7d91815260200190565b60c060405180830381865afa158015612b9a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612bbe919061471b565b509396509194509250506001600160a01b0384169050612c1e57612be560c08501856146fb565b602001356040517f2396d34e0000000000000000000000000000000000000000000000000000000081526004016109f591815260200190565b6000612c41612c3060c08701876146fb565b6114989060608101906040016146e0565b90506000612c4f84846138a1565b9050808263ffffffff1610612ca457612c6b60c08701876146fb565b602001356040517f1362e4a00000000000000000000000000000000000000000000000000000000081526004016109f591815260200190565b6000612cd3612cb660c08901896146fb565b612cc79060608101906040016146e0565b60201c63ffffffff1690565b90506000612ce58860200135866138bc565b63ffffffff16905067ffffffffffffffff82168114612d4457612d0b60c08901896146fb565b602001356040517f6dd6a24f0000000000000000000000000000000000000000000000000000000081526004016109f591815260200190565b612dea87612d5560c08b018b6146fb565b612d5f9080614793565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050505060208b0135612da560c08d018d6146fb565b60200135612db660c08e018e6146fb565b612dc79060608101906040016146e0565b612dd460c08f018f6146fb565b612de59060808101906060016146e0565b6138e3565b612e3457612dfb60c08901896146fb565b602001356040517fdb12fb9d0000000000000000000000000000000000000000000000000000000081526004016109f591815260200190565b5050505050505050565b612e4b60e0820182614497565b9050600003612e575750565b612f78612e6760e0830183614497565b6000818110612e7857612e7861441f565b9050602002810190612e8a91906146fb565b612e989060208101906147da565b612ea560e0840184614497565b6000818110612eb657612eb661441f565b9050602002810190612ec891906146fb565b612ed6906020810190614793565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250612f189250505060e0850185614497565b6000818110612f2957612f2961441f565b9050602002810190612f3b91906146fb565b60400135612f4c60e0860186614497565b6000818110612f5d57612f5d61441f565b9050602002810190612f6f91906146fb565b6060013561397a565b612fe557612f8960e0820182614497565b6000818110612f9a57612f9a61441f565b9050602002810190612fac91906146fb565b606001356040517fd740df610000000000000000000000000000000000000000000000000000000081526004016109f591815260200190565b6020810135613064612ffa60e0840184614497565b600081811061300b5761300b61441f565b905060200281019061301d91906146fb565b6040013561302e60e0850185614497565b600081811061303f5761303f61441f565b905060200281019061305191906146fb565b61305f9060208101906147da565b613a0d565b146120a05761307660e0820182614497565b60008181106130875761308761441f565b905060200281019061309991906146fb565b606001356040517f82f2469d0000000000000000000000000000000000000000000000000000000081526004016109f591815260200190565b8385101561311f578183106130fa57604051633d386eb360e11b815260040160405180910390fd5b80821061311a57604051633588c6d360e11b815260040160405180910390fd5b612b2a565b82821061313f57604051633d386eb360e11b815260040160405180910390fd5b808310612b2a57604051633588c6d360e11b815260040160405180910390fd5b60095481106120a0576040517fb6052cdf000000000000000000000000000000000000000000000000000000008152600481018290526024016109f5565b60606131a7611823565b6131c457604051633788c6c160e11b815260040160405180910390fd5b60006131ce611816565b60085490915067ffffffffffffffff808316600160401b909204161461320757604051636fbabc7760e01b815260040160405180910390fd5b6007546040516020016132429181527f3100000000000000000000000000000000000000000000000000000000000000602082015260210190565b60405160208183030381529060405291505090565b600080600080600080600080600061326d613a5b565b60045490915060005b818110156133ff57600481815481106132915761329161441f565b906000526020600020906005020160010160149054906101000a900460ff16156133f757600481815481106132c8576132c861441f565b9060005260206000209060050201600401549350600584815481106132ef576132ef61441f565b9060005260206000209060050201600301548961330c9190614537565b9850828160405160200161332192919061456e565b60408051601f19818403018152919052805160209091012097506fffffffffffffffffffffffffffffffff808916975061335c906001614537565b6005858154811061336f5761336f61441f565b90600052602060002090600502016003015461338b91906143b7565b6133958a896143b7565b10156133f757600584815481106133ae576133ae61441f565b9060005260206000209060050201600401549550600584815481106133d5576133d561441f565b906000526020600020906005020160010160149054906101000a900460ff1694505b600101613276565b509399929850919650505050505050565b6134186121c0565b6001805460ff1916811790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258335b6040516001600160a01b03909116815260200160405180910390a1565b6000805b6004548110156134dc5783600482815481106134865761348661441f565b9060005260206000209060050201600001541480156134c85750600481815481106134b3576134b361441f565b90600052602060002090600502016003015483145b156134d4579050610666565b600101613468565b506040517fd950091500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b613517613ae4565b6001805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa33613447565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610a085761357981613b36565b613584836020613b48565b6040516020016135959291906147f7565b60408051601f198184030181529082905262461bcd60e51b82526109f591600401614878565b6000806135ca87878786613d0d565b9050826136cf856000808267ffffffffffffffff1690506008817eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff16901b600882901c7eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff161790506010817dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff16901b601082901c7dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff161790506020817bffffffff00000000ffffffff00000000ffffffff00000000ffffffff16901b602082901c7bffffffff00000000ffffffff00000000ffffffff00000000ffffffff1617905080915050919050565b826040516020016137119392919092835260c09190911b77ffffffffffffffffffffffffffffffffffffffffffffffff19166020830152602882015260480190565b6040516020818303038152906040528051906020012091505095945050505050565b600080613741868686613d83565b9050613845836000808267ffffffffffffffff1690506008817eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff16901b600882901c7eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff161790506010817dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff16901b601082901c7dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff161790506020817bffffffff00000000ffffffff00000000ffffffff00000000ffffffff16901b602082901c7bffffffff00000000ffffffff00000000ffffffff00000000ffffffff1617905080915050919050565b8160405160200161388092919060c09290921b77ffffffffffffffffffffffffffffffffffffffffffffffff19168252600882015260280190565b60405160208183030381529060405280519060200120915050949350505050565b60006138ad828461469c565b60ff166001901b905092915050565b600060e083901c6138ce83602061469c565b60ff168163ffffffff16901c91505092915050565b6000806138f286868686613deb565b9050600061394d826040517f19457468657265756d205369676e6564204d6573736167653a0a3332000000006020820152603c8101829052600090605c01604051602081830303815290604052805190602001209050919050565b9050886001600160a01b0316613963828a613e36565b6001600160a01b0316149998505050505050505050565b6000806139878484613eb5565b905060006139e2826040517f19457468657265756d205369676e6564204d6573736167653a0a3332000000006020820152603c8101829052600090605c01604051602081830303815290604052805190602001209050919050565b9050866001600160a01b03166139f88288613e36565b6001600160a01b031614979650505050505050565b60008282604051602001613a3d92919091825260601b6bffffffffffffffffffffffff1916602082015260340190565b60405160208183030381529060405280519060200120905092915050565b6060613a65611823565b613a8257604051633788c6c160e11b815260040160405180910390fd5b6000613a8c611816565b60085490915067ffffffffffffffff808316600160401b9092041614613ac557604051636fbabc7760e01b815260040160405180910390fd5b600754604051602001613242918152600360fc1b602082015260210190565b60015460ff166118145760405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f742070617573656400000000000000000000000060448201526064016109f5565b60606106666001600160a01b03831660145b60606000613b578360026143b7565b613b62906002614537565b67ffffffffffffffff811115613b7a57613b7a6148ab565b6040519080825280601f01601f191660200182016040528015613ba4576020820181803683370190505b509050600360fc1b81600081518110613bbf57613bbf61441f565b60200101906001600160f81b031916908160001a9053507f780000000000000000000000000000000000000000000000000000000000000081600181518110613c0a57613c0a61441f565b60200101906001600160f81b031916908160001a9053506000613c2e8460026143b7565b613c39906001614537565b90505b6001811115613cbe577f303132333435363738396162636465660000000000000000000000000000000085600f1660108110613c7a57613c7a61441f565b1a60f81b828281518110613c9057613c9061441f565b60200101906001600160f81b031916908160001a90535060049490941c93613cb7816148c1565b9050613c3c565b50831561208f5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e7460448201526064016109f5565b8260005b8551811015613d7a576000613d276002866143f7565b15613d33576000613d36565b60015b9050613d5d83888481518110613d4e57613d4e61441f565b60200260200101518387613ed1565b9250600185901c9450508080613d729061447e565b915050613d11565b50949350505050565b8160005b8451811015613de3576000613d9d6002856143f7565b6000149050613dc683878481518110613db857613db861441f565b602002602001015183613f31565b9250600184901c9350508080613ddb9061447e565b915050613d87565b509392505050565b604080516020810186905290810184905277ffffffffffffffffffffffffffffffffffffffffffffffff1960c084811b8216606084015283901b166068820152600090607001611e5d565b600080600080613e4585613f98565b6040805160008152602081018083528b905260ff8316918101919091526060810184905260808101839052929550909350915060019060a0016020604051602081039080840390855afa158015613ea0573d6000803e3d6000fd5b5050604051601f190151979650505050505050565b6040805160208101849052908101829052600090606001613a3d565b60008215613f11576040805160208101849052908101869052606081018590526080016040516020818303038152906040528051906020012090506107f2565b604080516020810184905290810185905260608101869052608001611e5d565b60008115613f6a57604080516020810186905290810184905260600160405160208183030381529060405280519060200120905061208f565b5050604080516020808201939093528082019390935280518084038201815260609093019052815191012090565b60008060008351604114613fd8576040517f4be6321b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50505060208101516040820151606090920151909260009190911a90565b50805460008255600502906000526020600020908101906120a091905b8082111561405b57600080825560018201805474ffffffffffffffffffffffffffffffffffffffffff1916905560028201819055600382018190556004820155600501614013565b5090565b60006020828403121561407157600080fd5b81356001600160e01b03198116811461208f57600080fd5b6001600160a01b03811681146120a057600080fd5b60ff811681146120a057600080fd5b600080604083850312156140c057600080fd5b82356140cb81614089565b915060208301356140db8161409e565b809150509250929050565b6000602082840312156140f857600080fd5b5035919050565b6020808252825182820181905260009190848201906040850190845b818110156141825761416f838551805182526001600160a01b03602082015116602083015260ff6040820151166040830152606081015160608301526080810151608083015260a081015160a08301525050565b9284019260c0929092019160010161411b565b50909695505050505050565b600080604083850312156141a157600080fd5b8235915060208301356140db81614089565b803567ffffffffffffffff811681146141cb57600080fd5b919050565b600080604083850312156141e357600080fd5b823591506141f3602084016141b3565b90509250929050565b6000610100828403121561420f57600080fd5b50919050565b60008060006060848603121561422a57600080fd5b833567ffffffffffffffff8082111561424257600080fd5b61424e878388016141fc565b9450602086013591508082111561426457600080fd5b614270878388016141fc565b9350604086013591508082111561428657600080fd5b50614293868287016141fc565b9150509250925092565b6000806000606084860312156142b257600080fd5b83356142bd8161409e565b95602085013595506040909401359392505050565b600080600080608085870312156142e857600080fd5b8435935060208501356142fa8161409e565b93969395505050506040820135916060013590565b60008060006060848603121561432457600080fd5b833561432f8161409e565b9250602084013561433f8161409e565b9150604084013561434f8161409e565b809150509250925092565b60008060006060848603121561436f57600080fd5b8335925060208401359150604084013561434f8161409e565b60006020828403121561439a57600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b8082028115828204841417610666576106666143a1565b81810381811115610666576106666143a1565b634e487b7160e01b600052601260045260246000fd5b600082614406576144066143e1565b500690565b60008261441a5761441a6143e1565b500490565b634e487b7160e01b600052603260045260246000fd5b67ffffffffffffffff818116838216019080821115614456576144566143a1565b5092915050565b67ffffffffffffffff828116828216039080821115614456576144566143a1565b600060018201614490576144906143a1565b5060010190565b6000808335601e198436030181126144ae57600080fd5b83018035915067ffffffffffffffff8211156144c957600080fd5b6020019150600581901b36038213156144e157600080fd5b9250929050565b60c081016106668284805182526001600160a01b03602082015116602083015260ff6040820151166040830152606081015160608301526080810151608083015260a081015160a08301525050565b80820180821115610666576106666143a1565b60005b8381101561456557818101518382015260200161454d565b50506000910152565b6000835161458081846020880161454a565b9190910191825250602001919050565b600181815b808511156145cb5781600019048211156145b1576145b16143a1565b808516156145be57918102915b93841c9390800290614595565b509250929050565b6000826145e257506001610666565b816145ef57506000610666565b8160018114614605576002811461460f5761462b565b6001915050610666565b60ff841115614620576146206143a1565b50506001821b610666565b5060208310610133831016604e8410600b841016171561464e575081810a610666565b6146588383614590565b806000190482111561466c5761466c6143a1565b029392505050565b600061208f60ff8416836145d3565b60ff8181168382160190811115610666576106666143a1565b60ff8281168282160390811115610666576106666143a1565b61ffff828116828216039080821115614456576144566143a1565b600061208f61ffff8416836145d3565b6000602082840312156146f257600080fd5b61208f826141b3565b60008235607e1983360301811261471157600080fd5b9190910192915050565b60008060008060008060c0878903121561473457600080fd5b865161473f81614089565b60208801519096506147508161409e565b60408801519095506147618161409e565b6060880151909450801515811461477757600080fd5b809350506080870151915060a087015190509295509295509295565b6000808335601e198436030181126147aa57600080fd5b83018035915067ffffffffffffffff8211156147c557600080fd5b6020019150368190038213156144e157600080fd5b6000602082840312156147ec57600080fd5b813561208f81614089565b7f416363657373436f6e74726f6c3a206163636f756e742000000000000000000081526000835161482f81601785016020880161454a565b7f206973206d697373696e6720726f6c6520000000000000000000000000000000601791840191820152835161486c81602884016020880161454a565b01602801949350505050565b602081526000825180602084015261489781604085016020870161454a565b601f01601f19169190910160400192915050565b634e487b7160e01b600052604160045260246000fd5b6000816148d0576148d06143a1565b50600019019056fea26469706673582212200f9f0a55ccd6f0cb7269fe52233ea174faebf4c052751953813f1866c96736b964736f6c63430008130033", + "numDeployments": 11, + "solcInputHash": "294e4684ec82046939090fa9e468f317", + "metadata": "{\"compiler\":{\"version\":\"0.8.19+commit.7dd6d404\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"staking\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"postageContract\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"oracleContract\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[],\"name\":\"AlreadyClaimed\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"AlreadyCommitted\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"AlreadyRevealed\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"BatchDoesNotExist\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"BucketDiffers\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"CommitRoundNotStarted\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"CommitRoundOver\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"FirstRevealDone\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"uint8\",\"name\":\"\",\"type\":\"uint8\"},{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"InclusionProofFailed\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"IndexOutsideSet\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"InvalidSignatureLength\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"LastElementCheckFailed\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"MustStake2Rounds\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NoCommitsReceived\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NoMatchingCommit\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NoReveals\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NotAdmin\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NotClaimPhase\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NotCommitPhase\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NotMatchingOwner\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NotRevealPhase\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NotStaked\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"OnlyPauser\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"OutOfDepth\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"uint8\",\"name\":\"\",\"type\":\"uint8\"}],\"name\":\"OutOfDepthClaim\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"OutOfDepthReveal\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"PhaseLastBlock\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"RandomElementCheckFailed\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"trALast\",\"type\":\"bytes32\"}],\"name\":\"ReserveCheckFailed\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"SigRecoveryFailed\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"SocCalcNotMatching\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"SocVerificationFailed\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"WrongPhase\",\"type\":\"error\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"validChunkCount\",\"type\":\"uint256\"}],\"name\":\"ChunkCount\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"roundNumber\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint8\",\"name\":\"height\",\"type\":\"uint8\"}],\"name\":\"Committed\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"_count\",\"type\":\"uint256\"}],\"name\":\"CountCommits\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"_count\",\"type\":\"uint256\"}],\"name\":\"CountReveals\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"roundNumber\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"anchor\",\"type\":\"bytes32\"}],\"name\":\"CurrentRevealAnchor\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"Paused\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint16\",\"name\":\"redundancyCount\",\"type\":\"uint16\"}],\"name\":\"PriceAdjustmentSkipped\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"roundNumber\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"stake\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"stakeDensity\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"reserveCommitment\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint8\",\"name\":\"depth\",\"type\":\"uint8\"}],\"name\":\"Revealed\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"previousAdminRole\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"newAdminRole\",\"type\":\"bytes32\"}],\"name\":\"RoleAdminChanged\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"}],\"name\":\"RoleGranted\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"}],\"name\":\"RoleRevoked\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"hash\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint8\",\"name\":\"depth\",\"type\":\"uint8\"}],\"name\":\"TruthSelected\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"Unpaused\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"components\":[{\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"uint8\",\"name\":\"depth\",\"type\":\"uint8\"},{\"internalType\":\"uint256\",\"name\":\"stake\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"stakeDensity\",\"type\":\"uint256\"},{\"internalType\":\"bytes32\",\"name\":\"hash\",\"type\":\"bytes32\"}],\"indexed\":false,\"internalType\":\"struct Redistribution.Reveal\",\"name\":\"winner\",\"type\":\"tuple\"}],\"name\":\"WinnerSelected\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"}],\"name\":\"WithdrawFailed\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"indexInRC\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"chunkAddress\",\"type\":\"bytes32\"}],\"name\":\"transformedChunkAddressFromInclusionProof\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"DEFAULT_ADMIN_ROLE\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"OracleContract\",\"outputs\":[{\"internalType\":\"contract IPriceOracle\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"PostageContract\",\"outputs\":[{\"internalType\":\"contract IPostageStamp\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"Stakes\",\"outputs\":[{\"internalType\":\"contract IStakeRegistry\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"components\":[{\"internalType\":\"bytes32[]\",\"name\":\"proofSegments\",\"type\":\"bytes32[]\"},{\"internalType\":\"bytes32\",\"name\":\"proveSegment\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32[]\",\"name\":\"proofSegments2\",\"type\":\"bytes32[]\"},{\"internalType\":\"bytes32\",\"name\":\"proveSegment2\",\"type\":\"bytes32\"},{\"internalType\":\"uint64\",\"name\":\"chunkSpan\",\"type\":\"uint64\"},{\"internalType\":\"bytes32[]\",\"name\":\"proofSegments3\",\"type\":\"bytes32[]\"},{\"components\":[{\"internalType\":\"bytes\",\"name\":\"signature\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"postageId\",\"type\":\"bytes32\"},{\"internalType\":\"uint64\",\"name\":\"index\",\"type\":\"uint64\"},{\"internalType\":\"uint64\",\"name\":\"timeStamp\",\"type\":\"uint64\"}],\"internalType\":\"struct Redistribution.PostageProof\",\"name\":\"postageProof\",\"type\":\"tuple\"},{\"components\":[{\"internalType\":\"address\",\"name\":\"signer\",\"type\":\"address\"},{\"internalType\":\"bytes\",\"name\":\"signature\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"identifier\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"chunkAddr\",\"type\":\"bytes32\"}],\"internalType\":\"struct Redistribution.SOCProof[]\",\"name\":\"socProof\",\"type\":\"tuple[]\"}],\"internalType\":\"struct Redistribution.ChunkInclusionProof\",\"name\":\"entryProof1\",\"type\":\"tuple\"},{\"components\":[{\"internalType\":\"bytes32[]\",\"name\":\"proofSegments\",\"type\":\"bytes32[]\"},{\"internalType\":\"bytes32\",\"name\":\"proveSegment\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32[]\",\"name\":\"proofSegments2\",\"type\":\"bytes32[]\"},{\"internalType\":\"bytes32\",\"name\":\"proveSegment2\",\"type\":\"bytes32\"},{\"internalType\":\"uint64\",\"name\":\"chunkSpan\",\"type\":\"uint64\"},{\"internalType\":\"bytes32[]\",\"name\":\"proofSegments3\",\"type\":\"bytes32[]\"},{\"components\":[{\"internalType\":\"bytes\",\"name\":\"signature\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"postageId\",\"type\":\"bytes32\"},{\"internalType\":\"uint64\",\"name\":\"index\",\"type\":\"uint64\"},{\"internalType\":\"uint64\",\"name\":\"timeStamp\",\"type\":\"uint64\"}],\"internalType\":\"struct Redistribution.PostageProof\",\"name\":\"postageProof\",\"type\":\"tuple\"},{\"components\":[{\"internalType\":\"address\",\"name\":\"signer\",\"type\":\"address\"},{\"internalType\":\"bytes\",\"name\":\"signature\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"identifier\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"chunkAddr\",\"type\":\"bytes32\"}],\"internalType\":\"struct Redistribution.SOCProof[]\",\"name\":\"socProof\",\"type\":\"tuple[]\"}],\"internalType\":\"struct Redistribution.ChunkInclusionProof\",\"name\":\"entryProof2\",\"type\":\"tuple\"},{\"components\":[{\"internalType\":\"bytes32[]\",\"name\":\"proofSegments\",\"type\":\"bytes32[]\"},{\"internalType\":\"bytes32\",\"name\":\"proveSegment\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32[]\",\"name\":\"proofSegments2\",\"type\":\"bytes32[]\"},{\"internalType\":\"bytes32\",\"name\":\"proveSegment2\",\"type\":\"bytes32\"},{\"internalType\":\"uint64\",\"name\":\"chunkSpan\",\"type\":\"uint64\"},{\"internalType\":\"bytes32[]\",\"name\":\"proofSegments3\",\"type\":\"bytes32[]\"},{\"components\":[{\"internalType\":\"bytes\",\"name\":\"signature\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"postageId\",\"type\":\"bytes32\"},{\"internalType\":\"uint64\",\"name\":\"index\",\"type\":\"uint64\"},{\"internalType\":\"uint64\",\"name\":\"timeStamp\",\"type\":\"uint64\"}],\"internalType\":\"struct Redistribution.PostageProof\",\"name\":\"postageProof\",\"type\":\"tuple\"},{\"components\":[{\"internalType\":\"address\",\"name\":\"signer\",\"type\":\"address\"},{\"internalType\":\"bytes\",\"name\":\"signature\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"identifier\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"chunkAddr\",\"type\":\"bytes32\"}],\"internalType\":\"struct Redistribution.SOCProof[]\",\"name\":\"socProof\",\"type\":\"tuple[]\"}],\"internalType\":\"struct Redistribution.ChunkInclusionProof\",\"name\":\"entryProofLast\",\"type\":\"tuple\"}],\"name\":\"claim\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"_obfuscatedHash\",\"type\":\"bytes32\"},{\"internalType\":\"uint64\",\"name\":\"_roundNumber\",\"type\":\"uint64\"}],\"name\":\"commit\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentClaimRound\",\"outputs\":[{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentCommitRound\",\"outputs\":[{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"currentCommits\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"revealed\",\"type\":\"bool\"},{\"internalType\":\"uint8\",\"name\":\"height\",\"type\":\"uint8\"},{\"internalType\":\"uint256\",\"name\":\"stake\",\"type\":\"uint256\"},{\"internalType\":\"bytes32\",\"name\":\"obfuscatedHash\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"revealIndex\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentMinimumDepth\",\"outputs\":[{\"internalType\":\"uint8\",\"name\":\"\",\"type\":\"uint8\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentPhaseClaim\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentPhaseCommit\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentPhaseReveal\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentRevealRound\",\"outputs\":[{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"currentReveals\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"uint8\",\"name\":\"depth\",\"type\":\"uint8\"},{\"internalType\":\"uint256\",\"name\":\"stake\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"stakeDensity\",\"type\":\"uint256\"},{\"internalType\":\"bytes32\",\"name\":\"hash\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentRound\",\"outputs\":[{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentRoundAnchor\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"returnVal\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentRoundReveals\",\"outputs\":[{\"components\":[{\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"uint8\",\"name\":\"depth\",\"type\":\"uint8\"},{\"internalType\":\"uint256\",\"name\":\"stake\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"stakeDensity\",\"type\":\"uint256\"},{\"internalType\":\"bytes32\",\"name\":\"hash\",\"type\":\"bytes32\"}],\"internalType\":\"struct Redistribution.Reveal[]\",\"name\":\"\",\"type\":\"tuple[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentSeed\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"}],\"name\":\"getRoleAdmin\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"grantRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"hasRole\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"A\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"B\",\"type\":\"bytes32\"},{\"internalType\":\"uint8\",\"name\":\"minimum\",\"type\":\"uint8\"}],\"name\":\"inProximity\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"pure\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_owner\",\"type\":\"address\"},{\"internalType\":\"uint8\",\"name\":\"_depth\",\"type\":\"uint8\"}],\"name\":\"isParticipatingInUpcomingRound\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"_overlay\",\"type\":\"bytes32\"}],\"name\":\"isWinner\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"nextSeed\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"pause\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"paused\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"renounceRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint8\",\"name\":\"_depth\",\"type\":\"uint8\"},{\"internalType\":\"bytes32\",\"name\":\"_hash\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"_revealNonce\",\"type\":\"bytes32\"}],\"name\":\"reveal\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"revokeRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint8\",\"name\":\"_penaltyMultiplierDisagreement\",\"type\":\"uint8\"},{\"internalType\":\"uint8\",\"name\":\"_penaltyMultiplierNonRevealed\",\"type\":\"uint8\"},{\"internalType\":\"uint8\",\"name\":\"_penaltyRandomFactor\",\"type\":\"uint8\"}],\"name\":\"setFreezingParams\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_sampleMaxValue\",\"type\":\"uint256\"}],\"name\":\"setSampleMaxValue\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes4\",\"name\":\"interfaceId\",\"type\":\"bytes4\"}],\"name\":\"supportsInterface\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"unPause\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"winner\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"uint8\",\"name\":\"depth\",\"type\":\"uint8\"},{\"internalType\":\"uint256\",\"name\":\"stake\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"stakeDensity\",\"type\":\"uint256\"},{\"internalType\":\"bytes32\",\"name\":\"hash\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"_overlay\",\"type\":\"bytes32\"},{\"internalType\":\"uint8\",\"name\":\"_depth\",\"type\":\"uint8\"},{\"internalType\":\"bytes32\",\"name\":\"_hash\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"revealNonce\",\"type\":\"bytes32\"}],\"name\":\"wrapCommit\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"pure\",\"type\":\"function\"}],\"devdoc\":{\"author\":\"The Swarm Authors\",\"details\":\"Implements a Schelling Co-ordination game to form consensus around the Reserve Commitment hash. This takes place in three phases: _commit_, _reveal_ and _claim_. A node, upon establishing that it _isParticipatingInUpcomingRound_, i.e. it's overlay falls within proximity order of its reported depth with the _currentRoundAnchor_, prepares a \\\"reserve commitment hash\\\" using the chunks it currently stores in its reserve and calculates the \\\"storage depth\\\" (see Bee for details). These values, if calculated honestly, and with the right chunks stored, should be the same for every node in a neighbourhood. This is the Schelling point. Each eligible node can then use these values, together with a random, single use, secret _revealNonce_ and their _overlay_ as the pre-image values for the obsfucated _commit_, using the _wrapCommit_ method. Once the _commit_ round has elapsed, participating nodes must provide the values used to calculate their obsfucated _commit_ hash, which, once verified for correctness and proximity to the anchor are retained in the _currentReveals_. Nodes that have committed but do not reveal the correct values used to create the pre-image will have their stake \\\"frozen\\\" for a period of rounds proportional to their reported depth. During the _reveal_ round, randomness is updated after every successful reveal. Once the reveal round is concluded, the _currentRoundAnchor_ is updated and users can determine if they will be eligible their overlay will be eligible for the next commit phase using _isParticipatingInUpcomingRound_. When the _reveal_ phase has been concluded, the claim phase can begin. At this point, the truth teller and winner are already determined. By calling _isWinner_, an applicant node can run the relevant logic to determine if they have been selected as the beneficiary of this round. When calling _claim_, the current pot from the PostageStamp contract is withdrawn and transferred to that beneficiaries address. Nodes that have revealed values that differ from the truth, have their stakes \\\"frozen\\\" for a period of rounds proportional to their reported depth.\",\"events\":{\"ChunkCount(uint256)\":{\"details\":\"Emit from Postagestamp contract valid chunk count at the end of claim\"},\"Committed(uint256,bytes32,uint8)\":{\"details\":\"Logs that an overlay has committed\"},\"CountCommits(uint256)\":{\"details\":\"Emits the number of commits being processed by the claim phase.\"},\"CountReveals(uint256)\":{\"details\":\"Emits the number of reveals being processed by the claim phase.\"},\"CurrentRevealAnchor(uint256,bytes32)\":{\"details\":\"Bytes32 anhor of current reveal round\"},\"Paused(address)\":{\"details\":\"Emitted when the pause is triggered by `account`.\"},\"PriceAdjustmentSkipped(uint16)\":{\"details\":\"Output external call status\"},\"Revealed(uint256,bytes32,uint256,uint256,bytes32,uint8)\":{\"details\":\"Logs that an overlay has revealed\"},\"RoleAdminChanged(bytes32,bytes32,bytes32)\":{\"details\":\"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._\"},\"RoleGranted(bytes32,address,address)\":{\"details\":\"Emitted when `account` is granted `role`. `sender` is the account that originated the contract call, an admin role bearer except when using {AccessControl-_setupRole}.\"},\"RoleRevoked(bytes32,address,address)\":{\"details\":\"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`)\"},\"TruthSelected(bytes32,uint8)\":{\"details\":\"Emitted when the truth oracle of a round is selected in the claim phase.\"},\"Unpaused(address)\":{\"details\":\"Emitted when the pause is lifted by `account`.\"},\"WinnerSelected((bytes32,address,uint8,uint256,uint256,bytes32))\":{\"details\":\"Emitted when the winner of a round is selected in the claim phase\"},\"WithdrawFailed(address)\":{\"details\":\"Withdraw not successful in claim\"},\"transformedChunkAddressFromInclusionProof(uint256,bytes32)\":{\"details\":\"Logs for inclusion proof\"}},\"kind\":\"dev\",\"methods\":{\"commit(bytes32,uint64)\":{\"details\":\"If a node's overlay is _inProximity_(_depth_) of the _currentRoundAnchor_, that node may compute an _obfuscatedHash_ by providing their _overlay_, reported storage _depth_, reserve commitment _hash_ and a randomly generated, and secret _revealNonce_ to the _wrapCommit_ method.\",\"params\":{\"_obfuscatedHash\":\"The calculated hash resultant of the required pre-image values. and be derived from the same key pair as the message sender.\",\"_roundNumber\":\"Node needs to provide round number for which commit is valid\"}},\"constructor\":{\"params\":{\"oracleContract\":\"the address of the linked PriceOracle contract.\",\"postageContract\":\"the address of the linked PostageStamp contract.\",\"staking\":\"the address of the linked Staking contract.\"}},\"currentRoundAnchor()\":{\"details\":\"A node must be within proximity order of less than or equal to the storage depth they intend to report.\"},\"getRoleAdmin(bytes32)\":{\"details\":\"Returns the admin role that controls `role`. See {grantRole} and {revokeRole}. To change a role's admin, use {_setRoleAdmin}.\"},\"grantRole(bytes32,address)\":{\"details\":\"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.\"},\"hasRole(bytes32,address)\":{\"details\":\"Returns `true` if `account` has been granted `role`.\"},\"inProximity(bytes32,bytes32,uint8)\":{\"params\":{\"A\":\"An overlay address to compare.\",\"B\":\"An overlay address to compare.\",\"minimum\":\"Minimum proximity order.\"}},\"isParticipatingInUpcomingRound(address,uint8)\":{\"params\":{\"_depth\":\"The storage depth the applicant intends to report.\",\"_owner\":\"The address of the applicant from.\"}},\"isWinner(bytes32)\":{\"params\":{\"_overlay\":\"The overlay address of the applicant.\"}},\"pause()\":{\"details\":\"Pause the contract. The contract is provably stopped by renouncing the pauser role and the admin role after pausing, can only be called by the `PAUSER`\"},\"paused()\":{\"details\":\"Returns true if the contract is paused, and false otherwise.\"},\"renounceRole(bytes32,address)\":{\"details\":\"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.\"},\"reveal(uint8,bytes32,bytes32)\":{\"params\":{\"_depth\":\"The reported depth.\",\"_hash\":\"The reserve commitment hash.\",\"_revealNonce\":\"The nonce used to generate the commit that is being revealed.\"}},\"revokeRole(bytes32,address)\":{\"details\":\"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.\"},\"supportsInterface(bytes4)\":{\"details\":\"See {IERC165-supportsInterface}.\"},\"unPause()\":{\"details\":\"Unpause the contract, can only be called by the pauser when paused\"},\"wrapCommit(bytes32,uint8,bytes32,bytes32)\":{\"details\":\"_revealNonce_ must be randomly generated, used once and kept secret until the reveal phase.\",\"params\":{\"_depth\":\"The reported depth.\",\"_hash\":\"The reserve commitment hash.\",\"_overlay\":\"The overlay address of the applicant.\",\"revealNonce\":\"A random, single use, secret nonce.\"}}},\"title\":\"Redistribution contract\",\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{\"claim((bytes32[],bytes32,bytes32[],bytes32,uint64,bytes32[],(bytes,bytes32,uint64,uint64),(address,bytes,bytes32,bytes32)[]),(bytes32[],bytes32,bytes32[],bytes32,uint64,bytes32[],(bytes,bytes32,uint64,uint64),(address,bytes,bytes32,bytes32)[]),(bytes32[],bytes32,bytes32[],bytes32,uint64,bytes32[],(bytes,bytes32,uint64,uint64),(address,bytes,bytes32,bytes32)[]))\":{\"notice\":\"Helper function to get this round truth\"},\"commit(bytes32,uint64)\":{\"notice\":\"Begin application for a round if eligible. Commit a hashed value for which the pre-image will be subsequently revealed.\"},\"currentMinimumDepth()\":{\"notice\":\"Returns minimum depth reveal has to have to participate in this round\"},\"currentPhaseClaim()\":{\"notice\":\"Returns true if current block is during claim phase.\"},\"currentPhaseCommit()\":{\"notice\":\"Returns true if current block is during commit phase.\"},\"currentPhaseReveal()\":{\"notice\":\"Returns true if current block is during reveal phase.\"},\"currentRound()\":{\"notice\":\"The number of the current round.\"},\"currentRoundAnchor()\":{\"notice\":\"The anchor used to determine eligibility for the current round.\"},\"currentRoundReveals()\":{\"notice\":\"Returns true if current block is during reveal phase.\"},\"currentSeed()\":{\"notice\":\"Returns the current random seed which is used to determine later utilised random numbers. If rounds have elapsed without reveals, hash the seed with an incremented nonce to produce a new random seed and hence a new round anchor.\"},\"inProximity(bytes32,bytes32,uint8)\":{\"notice\":\"Returns true if an overlay address _A_ is within proximity order _minimum_ of _B_.\"},\"isParticipatingInUpcomingRound(address,uint8)\":{\"notice\":\"Determine if a the owner of a given overlay can participate in the upcoming round.\"},\"isWinner(bytes32)\":{\"notice\":\"Determine if a the owner of a given overlay will be the beneficiary of the claim phase.\"},\"nextSeed()\":{\"notice\":\"Returns the seed which will become current once the next commit phase begins. Used to determine what the next round's anchor will be.\"},\"reveal(uint8,bytes32,bytes32)\":{\"notice\":\"Reveal the pre-image values used to generate commit provided during this round's commit phase.\"},\"setFreezingParams(uint8,uint8,uint8)\":{\"notice\":\"Set freezing parameters\"},\"setSampleMaxValue(uint256)\":{\"notice\":\"changes the max sample value used for reserve estimation\"},\"wrapCommit(bytes32,uint8,bytes32,bytes32)\":{\"notice\":\"Hash the pre-image values to the obsfucated hash.\"}},\"version\":1}},\"settings\":{\"compilationTarget\":{\"src/Redistribution.sol\":\"Redistribution\"},\"evmVersion\":\"paris\",\"libraries\":{\":__CACHE_BREAKER__\":\"0x00000000d41867734bbee4c6863d9255b2b06ac1\"},\"metadata\":{\"bytecodeHash\":\"ipfs\",\"useLiteralContent\":true},\"optimizer\":{\"enabled\":true,\"runs\":1000},\"remappings\":[]},\"sources\":{\"@openzeppelin/contracts/access/AccessControl.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (access/AccessControl.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./IAccessControl.sol\\\";\\nimport \\\"../utils/Context.sol\\\";\\nimport \\\"../utils/Strings.sol\\\";\\nimport \\\"../utils/introspection/ERC165.sol\\\";\\n\\n/**\\n * @dev Contract module that allows children to implement role-based access\\n * control mechanisms. This is a lightweight version that doesn't allow enumerating role\\n * members except through off-chain means by accessing the contract event logs. Some\\n * applications may benefit from on-chain enumerability, for those cases see\\n * {AccessControlEnumerable}.\\n *\\n * Roles are referred to by their `bytes32` identifier. These should be exposed\\n * in the external API and be unique. The best way to achieve this is by\\n * using `public constant` hash digests:\\n *\\n * ```\\n * bytes32 public constant MY_ROLE = keccak256(\\\"MY_ROLE\\\");\\n * ```\\n *\\n * Roles can be used to represent a set of permissions. To restrict access to a\\n * function call, use {hasRole}:\\n *\\n * ```\\n * function foo() public {\\n * require(hasRole(MY_ROLE, msg.sender));\\n * ...\\n * }\\n * ```\\n *\\n * Roles can be granted and revoked dynamically via the {grantRole} and\\n * {revokeRole} functions. Each role has an associated admin role, and only\\n * accounts that have a role's admin role can call {grantRole} and {revokeRole}.\\n *\\n * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means\\n * that only accounts with this role will be able to grant or revoke other\\n * roles. More complex role relationships can be created by using\\n * {_setRoleAdmin}.\\n *\\n * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to\\n * grant and revoke this role. Extra precautions should be taken to secure\\n * accounts that have been granted it.\\n */\\nabstract contract AccessControl is Context, IAccessControl, ERC165 {\\n struct RoleData {\\n mapping(address => bool) members;\\n bytes32 adminRole;\\n }\\n\\n mapping(bytes32 => RoleData) private _roles;\\n\\n bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;\\n\\n /**\\n * @dev Modifier that checks that an account has a specific role. Reverts\\n * with a standardized message including the required role.\\n *\\n * The format of the revert reason is given by the following regular expression:\\n *\\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\\n *\\n * _Available since v4.1._\\n */\\n modifier onlyRole(bytes32 role) {\\n _checkRole(role);\\n _;\\n }\\n\\n /**\\n * @dev See {IERC165-supportsInterface}.\\n */\\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);\\n }\\n\\n /**\\n * @dev Returns `true` if `account` has been granted `role`.\\n */\\n function hasRole(bytes32 role, address account) public view virtual override returns (bool) {\\n return _roles[role].members[account];\\n }\\n\\n /**\\n * @dev Revert with a standard message if `_msgSender()` is missing `role`.\\n * Overriding this function changes the behavior of the {onlyRole} modifier.\\n *\\n * Format of the revert message is described in {_checkRole}.\\n *\\n * _Available since v4.6._\\n */\\n function _checkRole(bytes32 role) internal view virtual {\\n _checkRole(role, _msgSender());\\n }\\n\\n /**\\n * @dev Revert with a standard message if `account` is missing `role`.\\n *\\n * The format of the revert reason is given by the following regular expression:\\n *\\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\\n */\\n function _checkRole(bytes32 role, address account) internal view virtual {\\n if (!hasRole(role, account)) {\\n revert(\\n string(\\n abi.encodePacked(\\n \\\"AccessControl: account \\\",\\n Strings.toHexString(account),\\n \\\" is missing role \\\",\\n Strings.toHexString(uint256(role), 32)\\n )\\n )\\n );\\n }\\n }\\n\\n /**\\n * @dev Returns the admin role that controls `role`. See {grantRole} and\\n * {revokeRole}.\\n *\\n * To change a role's admin, use {_setRoleAdmin}.\\n */\\n function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {\\n return _roles[role].adminRole;\\n }\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * If `account` had not been already granted `role`, emits a {RoleGranted}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n *\\n * May emit a {RoleGranted} event.\\n */\\n function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\\n _grantRole(role, account);\\n }\\n\\n /**\\n * @dev Revokes `role` from `account`.\\n *\\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n *\\n * May emit a {RoleRevoked} event.\\n */\\n function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\\n _revokeRole(role, account);\\n }\\n\\n /**\\n * @dev Revokes `role` from the calling account.\\n *\\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\\n * purpose is to provide a mechanism for accounts to lose their privileges\\n * if they are compromised (such as when a trusted device is misplaced).\\n *\\n * If the calling account had been revoked `role`, emits a {RoleRevoked}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must be `account`.\\n *\\n * May emit a {RoleRevoked} event.\\n */\\n function renounceRole(bytes32 role, address account) public virtual override {\\n require(account == _msgSender(), \\\"AccessControl: can only renounce roles for self\\\");\\n\\n _revokeRole(role, account);\\n }\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * If `account` had not been already granted `role`, emits a {RoleGranted}\\n * event. Note that unlike {grantRole}, this function doesn't perform any\\n * checks on the calling account.\\n *\\n * May emit a {RoleGranted} event.\\n *\\n * [WARNING]\\n * ====\\n * This function should only be called from the constructor when setting\\n * up the initial roles for the system.\\n *\\n * Using this function in any other way is effectively circumventing the admin\\n * system imposed by {AccessControl}.\\n * ====\\n *\\n * NOTE: This function is deprecated in favor of {_grantRole}.\\n */\\n function _setupRole(bytes32 role, address account) internal virtual {\\n _grantRole(role, account);\\n }\\n\\n /**\\n * @dev Sets `adminRole` as ``role``'s admin role.\\n *\\n * Emits a {RoleAdminChanged} event.\\n */\\n function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {\\n bytes32 previousAdminRole = getRoleAdmin(role);\\n _roles[role].adminRole = adminRole;\\n emit RoleAdminChanged(role, previousAdminRole, adminRole);\\n }\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * Internal function without access restriction.\\n *\\n * May emit a {RoleGranted} event.\\n */\\n function _grantRole(bytes32 role, address account) internal virtual {\\n if (!hasRole(role, account)) {\\n _roles[role].members[account] = true;\\n emit RoleGranted(role, account, _msgSender());\\n }\\n }\\n\\n /**\\n * @dev Revokes `role` from `account`.\\n *\\n * Internal function without access restriction.\\n *\\n * May emit a {RoleRevoked} event.\\n */\\n function _revokeRole(bytes32 role, address account) internal virtual {\\n if (hasRole(role, account)) {\\n _roles[role].members[account] = false;\\n emit RoleRevoked(role, account, _msgSender());\\n }\\n }\\n}\\n\",\"keccak256\":\"0x67e3daf189111d6d5b0464ed09cf9f0605a22c4b965a7fcecd707101faff008a\",\"license\":\"MIT\"},\"@openzeppelin/contracts/access/IAccessControl.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev External interface of AccessControl declared to support ERC165 detection.\\n */\\ninterface IAccessControl {\\n /**\\n * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`\\n *\\n * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite\\n * {RoleAdminChanged} not being emitted signaling this.\\n *\\n * _Available since v3.1._\\n */\\n event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);\\n\\n /**\\n * @dev Emitted when `account` is granted `role`.\\n *\\n * `sender` is the account that originated the contract call, an admin role\\n * bearer except when using {AccessControl-_setupRole}.\\n */\\n event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);\\n\\n /**\\n * @dev Emitted when `account` is revoked `role`.\\n *\\n * `sender` is the account that originated the contract call:\\n * - if using `revokeRole`, it is the admin role bearer\\n * - if using `renounceRole`, it is the role bearer (i.e. `account`)\\n */\\n event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);\\n\\n /**\\n * @dev Returns `true` if `account` has been granted `role`.\\n */\\n function hasRole(bytes32 role, address account) external view returns (bool);\\n\\n /**\\n * @dev Returns the admin role that controls `role`. See {grantRole} and\\n * {revokeRole}.\\n *\\n * To change a role's admin, use {AccessControl-_setRoleAdmin}.\\n */\\n function getRoleAdmin(bytes32 role) external view returns (bytes32);\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * If `account` had not been already granted `role`, emits a {RoleGranted}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n */\\n function grantRole(bytes32 role, address account) external;\\n\\n /**\\n * @dev Revokes `role` from `account`.\\n *\\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n */\\n function revokeRole(bytes32 role, address account) external;\\n\\n /**\\n * @dev Revokes `role` from the calling account.\\n *\\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\\n * purpose is to provide a mechanism for accounts to lose their privileges\\n * if they are compromised (such as when a trusted device is misplaced).\\n *\\n * If the calling account had been granted `role`, emits a {RoleRevoked}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must be `account`.\\n */\\n function renounceRole(bytes32 role, address account) external;\\n}\\n\",\"keccak256\":\"0x59ce320a585d7e1f163cd70390a0ef2ff9cec832e2aa544293a00692465a7a57\",\"license\":\"MIT\"},\"@openzeppelin/contracts/security/Pausable.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"../utils/Context.sol\\\";\\n\\n/**\\n * @dev Contract module which allows children to implement an emergency stop\\n * mechanism that can be triggered by an authorized account.\\n *\\n * This module is used through inheritance. It will make available the\\n * modifiers `whenNotPaused` and `whenPaused`, which can be applied to\\n * the functions of your contract. Note that they will not be pausable by\\n * simply including this module, only once the modifiers are put in place.\\n */\\nabstract contract Pausable is Context {\\n /**\\n * @dev Emitted when the pause is triggered by `account`.\\n */\\n event Paused(address account);\\n\\n /**\\n * @dev Emitted when the pause is lifted by `account`.\\n */\\n event Unpaused(address account);\\n\\n bool private _paused;\\n\\n /**\\n * @dev Initializes the contract in unpaused state.\\n */\\n constructor() {\\n _paused = false;\\n }\\n\\n /**\\n * @dev Modifier to make a function callable only when the contract is not paused.\\n *\\n * Requirements:\\n *\\n * - The contract must not be paused.\\n */\\n modifier whenNotPaused() {\\n _requireNotPaused();\\n _;\\n }\\n\\n /**\\n * @dev Modifier to make a function callable only when the contract is paused.\\n *\\n * Requirements:\\n *\\n * - The contract must be paused.\\n */\\n modifier whenPaused() {\\n _requirePaused();\\n _;\\n }\\n\\n /**\\n * @dev Returns true if the contract is paused, and false otherwise.\\n */\\n function paused() public view virtual returns (bool) {\\n return _paused;\\n }\\n\\n /**\\n * @dev Throws if the contract is paused.\\n */\\n function _requireNotPaused() internal view virtual {\\n require(!paused(), \\\"Pausable: paused\\\");\\n }\\n\\n /**\\n * @dev Throws if the contract is not paused.\\n */\\n function _requirePaused() internal view virtual {\\n require(paused(), \\\"Pausable: not paused\\\");\\n }\\n\\n /**\\n * @dev Triggers stopped state.\\n *\\n * Requirements:\\n *\\n * - The contract must not be paused.\\n */\\n function _pause() internal virtual whenNotPaused {\\n _paused = true;\\n emit Paused(_msgSender());\\n }\\n\\n /**\\n * @dev Returns to normal state.\\n *\\n * Requirements:\\n *\\n * - The contract must be paused.\\n */\\n function _unpause() internal virtual whenPaused {\\n _paused = false;\\n emit Unpaused(_msgSender());\\n }\\n}\\n\",\"keccak256\":\"0x0849d93b16c9940beb286a7864ed02724b248b93e0d80ef6355af5ef15c64773\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/Context.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Provides information about the current execution context, including the\\n * sender of the transaction and its data. While these are generally available\\n * via msg.sender and msg.data, they should not be accessed in such a direct\\n * manner, since when dealing with meta-transactions the account sending and\\n * paying for execution may not be the actual sender (as far as an application\\n * is concerned).\\n *\\n * This contract is only required for intermediate, library-like contracts.\\n */\\nabstract contract Context {\\n function _msgSender() internal view virtual returns (address) {\\n return msg.sender;\\n }\\n\\n function _msgData() internal view virtual returns (bytes calldata) {\\n return msg.data;\\n }\\n}\\n\",\"keccak256\":\"0xe2e337e6dde9ef6b680e07338c493ebea1b5fd09b43424112868e9cc1706bca7\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/Strings.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./math/Math.sol\\\";\\n\\n/**\\n * @dev String operations.\\n */\\nlibrary Strings {\\n bytes16 private constant _SYMBOLS = \\\"0123456789abcdef\\\";\\n uint8 private constant _ADDRESS_LENGTH = 20;\\n\\n /**\\n * @dev Converts a `uint256` to its ASCII `string` decimal representation.\\n */\\n function toString(uint256 value) internal pure returns (string memory) {\\n unchecked {\\n uint256 length = Math.log10(value) + 1;\\n string memory buffer = new string(length);\\n uint256 ptr;\\n /// @solidity memory-safe-assembly\\n assembly {\\n ptr := add(buffer, add(32, length))\\n }\\n while (true) {\\n ptr--;\\n /// @solidity memory-safe-assembly\\n assembly {\\n mstore8(ptr, byte(mod(value, 10), _SYMBOLS))\\n }\\n value /= 10;\\n if (value == 0) break;\\n }\\n return buffer;\\n }\\n }\\n\\n /**\\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\\n */\\n function toHexString(uint256 value) internal pure returns (string memory) {\\n unchecked {\\n return toHexString(value, Math.log256(value) + 1);\\n }\\n }\\n\\n /**\\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\\n */\\n function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\\n bytes memory buffer = new bytes(2 * length + 2);\\n buffer[0] = \\\"0\\\";\\n buffer[1] = \\\"x\\\";\\n for (uint256 i = 2 * length + 1; i > 1; --i) {\\n buffer[i] = _SYMBOLS[value & 0xf];\\n value >>= 4;\\n }\\n require(value == 0, \\\"Strings: hex length insufficient\\\");\\n return string(buffer);\\n }\\n\\n /**\\n * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.\\n */\\n function toHexString(address addr) internal pure returns (string memory) {\\n return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);\\n }\\n}\\n\",\"keccak256\":\"0xa4d1d62251f8574deb032a35fc948386a9b4de74b812d4f545a1ac120486b48a\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/introspection/ERC165.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./IERC165.sol\\\";\\n\\n/**\\n * @dev Implementation of the {IERC165} interface.\\n *\\n * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check\\n * for the additional interface id that will be supported. For example:\\n *\\n * ```solidity\\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\\n * }\\n * ```\\n *\\n * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.\\n */\\nabstract contract ERC165 is IERC165 {\\n /**\\n * @dev See {IERC165-supportsInterface}.\\n */\\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n return interfaceId == type(IERC165).interfaceId;\\n }\\n}\\n\",\"keccak256\":\"0xd10975de010d89fd1c78dc5e8a9a7e7f496198085c151648f20cba166b32582b\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/introspection/IERC165.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Interface of the ERC165 standard, as defined in the\\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\\n *\\n * Implementers can declare support of contract interfaces, which can then be\\n * queried by others ({ERC165Checker}).\\n *\\n * For an implementation, see {ERC165}.\\n */\\ninterface IERC165 {\\n /**\\n * @dev Returns true if this contract implements the interface defined by\\n * `interfaceId`. See the corresponding\\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\\n * to learn more about how these ids are created.\\n *\\n * This function call must use less than 30 000 gas.\\n */\\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\\n}\\n\",\"keccak256\":\"0x447a5f3ddc18419d41ff92b3773fb86471b1db25773e07f877f548918a185bf1\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/math/Math.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Standard math utilities missing in the Solidity language.\\n */\\nlibrary Math {\\n enum Rounding {\\n Down, // Toward negative infinity\\n Up, // Toward infinity\\n Zero // Toward zero\\n }\\n\\n /**\\n * @dev Returns the largest of two numbers.\\n */\\n function max(uint256 a, uint256 b) internal pure returns (uint256) {\\n return a > b ? a : b;\\n }\\n\\n /**\\n * @dev Returns the smallest of two numbers.\\n */\\n function min(uint256 a, uint256 b) internal pure returns (uint256) {\\n return a < b ? a : b;\\n }\\n\\n /**\\n * @dev Returns the average of two numbers. The result is rounded towards\\n * zero.\\n */\\n function average(uint256 a, uint256 b) internal pure returns (uint256) {\\n // (a + b) / 2 can overflow.\\n return (a & b) + (a ^ b) / 2;\\n }\\n\\n /**\\n * @dev Returns the ceiling of the division of two numbers.\\n *\\n * This differs from standard division with `/` in that it rounds up instead\\n * of rounding down.\\n */\\n function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {\\n // (a + b - 1) / b can overflow on addition, so we distribute.\\n return a == 0 ? 0 : (a - 1) / b + 1;\\n }\\n\\n /**\\n * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0\\n * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)\\n * with further edits by Uniswap Labs also under MIT license.\\n */\\n function mulDiv(\\n uint256 x,\\n uint256 y,\\n uint256 denominator\\n ) internal pure returns (uint256 result) {\\n unchecked {\\n // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use\\n // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256\\n // variables such that product = prod1 * 2^256 + prod0.\\n uint256 prod0; // Least significant 256 bits of the product\\n uint256 prod1; // Most significant 256 bits of the product\\n assembly {\\n let mm := mulmod(x, y, not(0))\\n prod0 := mul(x, y)\\n prod1 := sub(sub(mm, prod0), lt(mm, prod0))\\n }\\n\\n // Handle non-overflow cases, 256 by 256 division.\\n if (prod1 == 0) {\\n return prod0 / denominator;\\n }\\n\\n // Make sure the result is less than 2^256. Also prevents denominator == 0.\\n require(denominator > prod1);\\n\\n ///////////////////////////////////////////////\\n // 512 by 256 division.\\n ///////////////////////////////////////////////\\n\\n // Make division exact by subtracting the remainder from [prod1 prod0].\\n uint256 remainder;\\n assembly {\\n // Compute remainder using mulmod.\\n remainder := mulmod(x, y, denominator)\\n\\n // Subtract 256 bit number from 512 bit number.\\n prod1 := sub(prod1, gt(remainder, prod0))\\n prod0 := sub(prod0, remainder)\\n }\\n\\n // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.\\n // See https://cs.stackexchange.com/q/138556/92363.\\n\\n // Does not overflow because the denominator cannot be zero at this stage in the function.\\n uint256 twos = denominator & (~denominator + 1);\\n assembly {\\n // Divide denominator by twos.\\n denominator := div(denominator, twos)\\n\\n // Divide [prod1 prod0] by twos.\\n prod0 := div(prod0, twos)\\n\\n // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.\\n twos := add(div(sub(0, twos), twos), 1)\\n }\\n\\n // Shift in bits from prod1 into prod0.\\n prod0 |= prod1 * twos;\\n\\n // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such\\n // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for\\n // four bits. That is, denominator * inv = 1 mod 2^4.\\n uint256 inverse = (3 * denominator) ^ 2;\\n\\n // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works\\n // in modular arithmetic, doubling the correct bits in each step.\\n inverse *= 2 - denominator * inverse; // inverse mod 2^8\\n inverse *= 2 - denominator * inverse; // inverse mod 2^16\\n inverse *= 2 - denominator * inverse; // inverse mod 2^32\\n inverse *= 2 - denominator * inverse; // inverse mod 2^64\\n inverse *= 2 - denominator * inverse; // inverse mod 2^128\\n inverse *= 2 - denominator * inverse; // inverse mod 2^256\\n\\n // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.\\n // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is\\n // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1\\n // is no longer required.\\n result = prod0 * inverse;\\n return result;\\n }\\n }\\n\\n /**\\n * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.\\n */\\n function mulDiv(\\n uint256 x,\\n uint256 y,\\n uint256 denominator,\\n Rounding rounding\\n ) internal pure returns (uint256) {\\n uint256 result = mulDiv(x, y, denominator);\\n if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {\\n result += 1;\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.\\n *\\n * Inspired by Henry S. Warren, Jr.'s \\\"Hacker's Delight\\\" (Chapter 11).\\n */\\n function sqrt(uint256 a) internal pure returns (uint256) {\\n if (a == 0) {\\n return 0;\\n }\\n\\n // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.\\n //\\n // We know that the \\\"msb\\\" (most significant bit) of our target number `a` is a power of 2 such that we have\\n // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.\\n //\\n // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`\\n // \\u2192 `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`\\n // \\u2192 `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`\\n //\\n // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.\\n uint256 result = 1 << (log2(a) >> 1);\\n\\n // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,\\n // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at\\n // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision\\n // into the expected uint128 result.\\n unchecked {\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n return min(result, a / result);\\n }\\n }\\n\\n /**\\n * @notice Calculates sqrt(a), following the selected rounding direction.\\n */\\n function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = sqrt(a);\\n return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);\\n }\\n }\\n\\n /**\\n * @dev Return the log in base 2, rounded down, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log2(uint256 value) internal pure returns (uint256) {\\n uint256 result = 0;\\n unchecked {\\n if (value >> 128 > 0) {\\n value >>= 128;\\n result += 128;\\n }\\n if (value >> 64 > 0) {\\n value >>= 64;\\n result += 64;\\n }\\n if (value >> 32 > 0) {\\n value >>= 32;\\n result += 32;\\n }\\n if (value >> 16 > 0) {\\n value >>= 16;\\n result += 16;\\n }\\n if (value >> 8 > 0) {\\n value >>= 8;\\n result += 8;\\n }\\n if (value >> 4 > 0) {\\n value >>= 4;\\n result += 4;\\n }\\n if (value >> 2 > 0) {\\n value >>= 2;\\n result += 2;\\n }\\n if (value >> 1 > 0) {\\n result += 1;\\n }\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Return the log in base 2, following the selected rounding direction, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = log2(value);\\n return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);\\n }\\n }\\n\\n /**\\n * @dev Return the log in base 10, rounded down, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log10(uint256 value) internal pure returns (uint256) {\\n uint256 result = 0;\\n unchecked {\\n if (value >= 10**64) {\\n value /= 10**64;\\n result += 64;\\n }\\n if (value >= 10**32) {\\n value /= 10**32;\\n result += 32;\\n }\\n if (value >= 10**16) {\\n value /= 10**16;\\n result += 16;\\n }\\n if (value >= 10**8) {\\n value /= 10**8;\\n result += 8;\\n }\\n if (value >= 10**4) {\\n value /= 10**4;\\n result += 4;\\n }\\n if (value >= 10**2) {\\n value /= 10**2;\\n result += 2;\\n }\\n if (value >= 10**1) {\\n result += 1;\\n }\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = log10(value);\\n return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);\\n }\\n }\\n\\n /**\\n * @dev Return the log in base 256, rounded down, of a positive value.\\n * Returns 0 if given 0.\\n *\\n * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.\\n */\\n function log256(uint256 value) internal pure returns (uint256) {\\n uint256 result = 0;\\n unchecked {\\n if (value >> 128 > 0) {\\n value >>= 128;\\n result += 16;\\n }\\n if (value >> 64 > 0) {\\n value >>= 64;\\n result += 8;\\n }\\n if (value >> 32 > 0) {\\n value >>= 32;\\n result += 4;\\n }\\n if (value >> 16 > 0) {\\n value >>= 16;\\n result += 2;\\n }\\n if (value >> 8 > 0) {\\n result += 1;\\n }\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = log256(value);\\n return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);\\n }\\n }\\n}\\n\",\"keccak256\":\"0xa1e8e83cd0087785df04ac79fb395d9f3684caeaf973d9e2c71caef723a3a5d6\",\"license\":\"MIT\"},\"src/Redistribution.sol\":{\"content\":\"// SPDX-License-Identifier: BSD-3-Clause\\npragma solidity ^0.8.19;\\nimport \\\"@openzeppelin/contracts/access/AccessControl.sol\\\";\\nimport \\\"@openzeppelin/contracts/security/Pausable.sol\\\";\\nimport \\\"./Util/TransformedChunkProof.sol\\\";\\nimport \\\"./Util/ChunkProof.sol\\\";\\nimport \\\"./Util/Signatures.sol\\\";\\nimport \\\"./interface/IPostageStamp.sol\\\";\\n\\ninterface IPriceOracle {\\n function adjustPrice(uint16 redundancy) external returns (bool);\\n}\\n\\ninterface IStakeRegistry {\\n struct Stake {\\n bytes32 overlay;\\n uint256 stakeAmount;\\n uint256 lastUpdatedBlockNumber;\\n }\\n\\n function freezeDeposit(address _owner, uint256 _time) external;\\n\\n function lastUpdatedBlockNumberOfAddress(address _owner) external view returns (uint256);\\n\\n function overlayOfAddress(address _owner) external view returns (bytes32);\\n\\n function heightOfAddress(address _owner) external view returns (uint8);\\n\\n function nodeEffectiveStake(address _owner) external view returns (uint256);\\n}\\n\\n/**\\n * @title Redistribution contract\\n * @author The Swarm Authors\\n * @dev Implements a Schelling Co-ordination game to form consensus around the Reserve Commitment hash. This takes\\n * place in three phases: _commit_, _reveal_ and _claim_.\\n *\\n * A node, upon establishing that it _isParticipatingInUpcomingRound_, i.e. it's overlay falls within proximity order\\n * of its reported depth with the _currentRoundAnchor_, prepares a \\\"reserve commitment hash\\\" using the chunks\\n * it currently stores in its reserve and calculates the \\\"storage depth\\\" (see Bee for details). These values, if calculated\\n * honestly, and with the right chunks stored, should be the same for every node in a neighbourhood. This is the Schelling point.\\n * Each eligible node can then use these values, together with a random, single use, secret _revealNonce_ and their\\n * _overlay_ as the pre-image values for the obsfucated _commit_, using the _wrapCommit_ method.\\n *\\n * Once the _commit_ round has elapsed, participating nodes must provide the values used to calculate their obsfucated\\n * _commit_ hash, which, once verified for correctness and proximity to the anchor are retained in the _currentReveals_.\\n * Nodes that have committed but do not reveal the correct values used to create the pre-image will have their stake\\n * \\\"frozen\\\" for a period of rounds proportional to their reported depth.\\n *\\n * During the _reveal_ round, randomness is updated after every successful reveal. Once the reveal round is concluded,\\n * the _currentRoundAnchor_ is updated and users can determine if they will be eligible their overlay will be eligible\\n * for the next commit phase using _isParticipatingInUpcomingRound_.\\n *\\n * When the _reveal_ phase has been concluded, the claim phase can begin. At this point, the truth teller and winner\\n * are already determined. By calling _isWinner_, an applicant node can run the relevant logic to determine if they have\\n * been selected as the beneficiary of this round. When calling _claim_, the current pot from the PostageStamp contract\\n * is withdrawn and transferred to that beneficiaries address. Nodes that have revealed values that differ from the truth,\\n * have their stakes \\\"frozen\\\" for a period of rounds proportional to their reported depth.\\n */\\n\\ncontract Redistribution is AccessControl, Pausable {\\n // ----------------------------- Type declarations ------------------------------\\n\\n // An eligible user may commit to an _obfuscatedHash_ during the commit phase...\\n struct Commit {\\n bytes32 overlay;\\n address owner;\\n bool revealed;\\n uint8 height;\\n uint256 stake;\\n bytes32 obfuscatedHash;\\n uint256 revealIndex;\\n }\\n // ...then provide the actual values that are the constituents of the pre-image of the _obfuscatedHash_\\n // during the reveal phase.\\n struct Reveal {\\n bytes32 overlay;\\n address owner;\\n uint8 depth;\\n uint256 stake;\\n uint256 stakeDensity;\\n bytes32 hash;\\n }\\n\\n struct ChunkInclusionProof {\\n bytes32[] proofSegments;\\n bytes32 proveSegment;\\n // _RCspan is known for RC 32*32\\n\\n // Inclusion proof of transformed address\\n bytes32[] proofSegments2;\\n bytes32 proveSegment2;\\n // proveSegmentIndex2 known from deterministic random selection;\\n uint64 chunkSpan;\\n bytes32[] proofSegments3;\\n // _proveSegment3 known, is equal _proveSegment2\\n // proveSegmentIndex3 know, is equal _proveSegmentIndex2;\\n // chunkSpan2 is equal to chunkSpan (as the data is the same)\\n //\\n PostageProof postageProof;\\n SOCProof[] socProof;\\n }\\n\\n struct SOCProof {\\n address signer; // signer Ethereum address to check against\\n bytes signature;\\n bytes32 identifier; //\\n bytes32 chunkAddr; // wrapped chunk address\\n }\\n\\n struct PostageProof {\\n bytes signature;\\n bytes32 postageId;\\n uint64 index;\\n uint64 timeStamp;\\n // address signer; it is provided by the postage stamp contract\\n // bytes32 chunkAddr; it equals to the proveSegment argument\\n }\\n\\n // The address of the linked PostageStamp contract.\\n IPostageStamp public PostageContract;\\n // The address of the linked PriceOracle contract.\\n IPriceOracle public OracleContract;\\n // The address of the linked Staking contract.\\n IStakeRegistry public Stakes;\\n\\n // Commits for the current round.\\n Commit[] public currentCommits;\\n // Reveals for the current round.\\n Reveal[] public currentReveals;\\n\\n // The current anchor that being processed for the reveal and claim phases of the round.\\n bytes32 private currentRevealRoundAnchor;\\n\\n // The current random value from which we will random.\\n // inputs for selection of the truth teller and beneficiary.\\n bytes32 private seed;\\n\\n // The number of the currently active round phases.\\n uint64 public currentCommitRound;\\n uint64 public currentRevealRound;\\n uint64 public currentClaimRound;\\n\\n // Settings for slashing and freezing\\n uint8 private penaltyMultiplierDisagreement = 1;\\n uint8 private penaltyMultiplierNonRevealed = 2;\\n uint8 private penaltyRandomFactor = 100; // Use 100 as value to ignore random factor in freezing penalty\\n\\n // alpha=0.097612 beta=0.0716570 k=16\\n uint256 private sampleMaxValue = 1284401000000000000000000000000000000000000000000000000000000000000000000;\\n\\n // The reveal of the winner of the last round.\\n Reveal public winner;\\n\\n // The length of a round in blocks.\\n uint256 private constant ROUND_LENGTH = 152;\\n\\n // Maximum value of the keccack256 hash.\\n bytes32 private constant MAX_H = 0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff;\\n\\n // ----------------------------- Events ------------------------------\\n\\n /**\\n * @dev Emitted when the winner of a round is selected in the claim phase\\n */\\n event WinnerSelected(Reveal winner);\\n\\n /**\\n * @dev Emitted when the truth oracle of a round is selected in the claim phase.\\n */\\n event TruthSelected(bytes32 hash, uint8 depth);\\n\\n // Next two events to be removed after testing phase pending some other usefulness being found.\\n /**\\n * @dev Emits the number of commits being processed by the claim phase.\\n */\\n event CountCommits(uint256 _count);\\n\\n /**\\n * @dev Emits the number of reveals being processed by the claim phase.\\n */\\n event CountReveals(uint256 _count);\\n\\n /**\\n * @dev Logs that an overlay has committed\\n */\\n event Committed(uint256 roundNumber, bytes32 overlay, uint8 height);\\n /**\\n * @dev Emit from Postagestamp contract valid chunk count at the end of claim\\n */\\n event ChunkCount(uint256 validChunkCount);\\n\\n /**\\n * @dev Bytes32 anhor of current reveal round\\n */\\n event CurrentRevealAnchor(uint256 roundNumber, bytes32 anchor);\\n\\n /**\\n * @dev Output external call status\\n */\\n event PriceAdjustmentSkipped(uint16 redundancyCount);\\n\\n /**\\n * @dev Withdraw not successful in claim\\n */\\n event WithdrawFailed(address owner);\\n\\n /**\\n * @dev Logs that an overlay has revealed\\n */\\n event Revealed(\\n uint256 roundNumber,\\n bytes32 overlay,\\n uint256 stake,\\n uint256 stakeDensity,\\n bytes32 reserveCommitment,\\n uint8 depth\\n );\\n\\n /**\\n * @dev Logs for inclusion proof\\n */\\n event transformedChunkAddressFromInclusionProof(uint256 indexInRC, bytes32 chunkAddress);\\n\\n // ----------------------------- Errors ------------------------------\\n\\n error NotCommitPhase(); // Game is not in commit phase\\n error NoCommitsReceived(); // Round didn't receive any commits\\n error PhaseLastBlock(); // We don't permit commits in last block of the phase\\n error CommitRoundOver(); // Commit phase in this round is over\\n error CommitRoundNotStarted(); // Commit phase in this round has not started yet\\n error NotMatchingOwner(); // Sender of commit is not matching the overlay address\\n error MustStake2Rounds(); // Before entering the game node must stake 2 rounds prior\\n error NotStaked(); // Node didn't add any staking\\n error WrongPhase(); // Checking in wrong phase, need to check duing claim phase of current round for next round or commit in current round\\n error AlreadyCommitted(); // Node already committed in this round\\n error NotRevealPhase(); // Game is not in reveal phase\\n error OutOfDepthReveal(bytes32); // Anchor is out of reported depth in Reveal phase, anchor data available as argument\\n error OutOfDepthClaim(uint8); // Anchor is out of reported depth in Claim phase, entryProof index is argument\\n error OutOfDepth(); // Anchor is out of reported depth\\n error AlreadyRevealed(); // Node already revealed\\n error NoMatchingCommit(); // No matching commit and hash\\n error NotClaimPhase(); // Game is not in the claim phase\\n error NoReveals(); // Round did not receive any reveals\\n error FirstRevealDone(); // We don't want to return value after first reveal\\n error AlreadyClaimed(); // This round was already claimed\\n error NotAdmin(); // Caller of trx is not admin\\n error OnlyPauser(); // Only account with pauser role can call pause/unpause\\n error SocVerificationFailed(bytes32); // Soc verification failed for this element\\n error SocCalcNotMatching(bytes32); // Soc address calculation does not match with the witness\\n error IndexOutsideSet(bytes32); // Stamp available: index resides outside of the valid index set\\n error SigRecoveryFailed(bytes32); // Stamp authorized: signature recovery failed for element\\n error BatchDoesNotExist(bytes32); // Stamp alive: batch remaining balance validation failed for attached stamp\\n error BucketDiffers(bytes32); // Stamp aligned: postage bucket differs from address bucket\\n error InclusionProofFailed(uint8, bytes32);\\n // 1 = RC inclusion proof failed for element\\n // 2 = First sister segment in data must match,\\n // 3 = Inclusion proof failed for original address of element\\n // 4 = Inclusion proof failed for transformed address of element\\n error RandomElementCheckFailed(); // Random element order check failed\\n error LastElementCheckFailed(); // Last element order check failed\\n error ReserveCheckFailed(bytes32 trALast); // Reserve size estimation check failed\\n\\n // ----------------------------- CONSTRUCTOR ------------------------------\\n\\n /**\\n * @param staking the address of the linked Staking contract.\\n * @param postageContract the address of the linked PostageStamp contract.\\n * @param oracleContract the address of the linked PriceOracle contract.\\n */\\n constructor(address staking, address postageContract, address oracleContract) {\\n Stakes = IStakeRegistry(staking);\\n PostageContract = IPostageStamp(postageContract);\\n OracleContract = IPriceOracle(oracleContract);\\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\\n }\\n\\n ////////////////////////////////////////\\n // STATE CHANGING //\\n ////////////////////////////////////////\\n\\n /**\\n * @notice Begin application for a round if eligible. Commit a hashed value for which the pre-image will be\\n * subsequently revealed.\\n * @dev If a node's overlay is _inProximity_(_depth_) of the _currentRoundAnchor_, that node may compute an\\n * _obfuscatedHash_ by providing their _overlay_, reported storage _depth_, reserve commitment _hash_ and a\\n * randomly generated, and secret _revealNonce_ to the _wrapCommit_ method.\\n * @param _obfuscatedHash The calculated hash resultant of the required pre-image values.\\n * and be derived from the same key pair as the message sender.\\n * @param _roundNumber Node needs to provide round number for which commit is valid\\n */\\n function commit(bytes32 _obfuscatedHash, uint64 _roundNumber) external whenNotPaused {\\n uint64 cr = currentRound();\\n bytes32 _overlay = Stakes.overlayOfAddress(msg.sender);\\n uint256 _stake = Stakes.nodeEffectiveStake(msg.sender);\\n uint256 _lastUpdate = Stakes.lastUpdatedBlockNumberOfAddress(msg.sender);\\n uint8 _height = Stakes.heightOfAddress(msg.sender);\\n\\n if (!currentPhaseCommit()) {\\n revert NotCommitPhase();\\n }\\n if (block.number % ROUND_LENGTH == (ROUND_LENGTH / 4) - 1) {\\n revert PhaseLastBlock();\\n }\\n\\n if (cr > _roundNumber) {\\n revert CommitRoundOver();\\n }\\n\\n if (cr < _roundNumber) {\\n revert CommitRoundNotStarted();\\n }\\n\\n if (_lastUpdate == 0) {\\n revert NotStaked();\\n }\\n\\n if (_lastUpdate >= block.number - 2 * ROUND_LENGTH) {\\n revert MustStake2Rounds();\\n }\\n\\n // if we are in a new commit phase, reset the array of commits and\\n // set the currentCommitRound to be the current one\\n if (cr != currentCommitRound) {\\n delete currentCommits;\\n currentCommitRound = cr;\\n }\\n\\n uint256 commitsArrayLength = currentCommits.length;\\n\\n for (uint256 i = 0; i < commitsArrayLength; ) {\\n if (currentCommits[i].overlay == _overlay) {\\n revert AlreadyCommitted();\\n }\\n\\n unchecked {\\n ++i;\\n }\\n }\\n\\n currentCommits.push(\\n Commit({\\n overlay: _overlay,\\n owner: msg.sender,\\n revealed: false,\\n height: _height,\\n stake: _stake,\\n obfuscatedHash: _obfuscatedHash,\\n revealIndex: 0\\n })\\n );\\n\\n emit Committed(_roundNumber, _overlay, _height);\\n }\\n\\n /**\\n * @notice Reveal the pre-image values used to generate commit provided during this round's commit phase.\\n * @param _depth The reported depth.\\n * @param _hash The reserve commitment hash.\\n * @param _revealNonce The nonce used to generate the commit that is being revealed.\\n */\\n function reveal(uint8 _depth, bytes32 _hash, bytes32 _revealNonce) external whenNotPaused {\\n uint64 cr = currentRound();\\n bytes32 _overlay = Stakes.overlayOfAddress(msg.sender);\\n\\n if (_depth < currentMinimumDepth()) {\\n revert OutOfDepth();\\n }\\n\\n if (!currentPhaseReveal()) {\\n revert NotRevealPhase();\\n }\\n\\n if (cr != currentCommitRound) {\\n revert NoCommitsReceived();\\n }\\n\\n if (cr != currentRevealRound) {\\n currentRevealRoundAnchor = currentRoundAnchor();\\n delete currentReveals;\\n // We set currentRevealRound ONLY after we set current anchor\\n currentRevealRound = cr;\\n emit CurrentRevealAnchor(cr, currentRevealRoundAnchor);\\n updateRandomness();\\n }\\n\\n bytes32 obfuscatedHash = wrapCommit(_overlay, _depth, _hash, _revealNonce);\\n uint256 id = findCommit(_overlay, obfuscatedHash);\\n Commit memory revealedCommit = currentCommits[id];\\n uint8 depthResponsibility = _depth - revealedCommit.height;\\n\\n // Check that commit is in proximity of the current anchor\\n if (!inProximity(revealedCommit.overlay, currentRevealRoundAnchor, depthResponsibility)) {\\n revert OutOfDepthReveal(currentRevealRoundAnchor);\\n }\\n // Check that the commit has not already been revealed\\n if (revealedCommit.revealed) {\\n revert AlreadyRevealed();\\n }\\n\\n currentCommits[id].revealed = true;\\n currentCommits[id].revealIndex = currentReveals.length;\\n\\n currentReveals.push(\\n Reveal({\\n overlay: revealedCommit.overlay,\\n owner: revealedCommit.owner,\\n depth: _depth,\\n stake: revealedCommit.stake,\\n stakeDensity: revealedCommit.stake * uint256(2 ** depthResponsibility),\\n hash: _hash\\n })\\n );\\n\\n emit Revealed(\\n cr,\\n revealedCommit.overlay,\\n revealedCommit.stake,\\n revealedCommit.stake * uint256(2 ** depthResponsibility),\\n _hash,\\n _depth\\n );\\n }\\n\\n /**\\n * @notice Helper function to get this round truth\\n * @dev\\n */\\n function claim(\\n ChunkInclusionProof calldata entryProof1,\\n ChunkInclusionProof calldata entryProof2,\\n ChunkInclusionProof calldata entryProofLast\\n ) external whenNotPaused {\\n winnerSelection();\\n\\n Reveal memory winnerSelected = winner;\\n uint256 indexInRC1;\\n uint256 indexInRC2;\\n bytes32 _currentRevealRoundAnchor = currentRevealRoundAnchor;\\n bytes32 _seed = seed;\\n\\n // rand(14)\\n indexInRC1 = uint256(_seed) % 15;\\n // rand(13)\\n indexInRC2 = uint256(_seed) % 14;\\n if (indexInRC2 >= indexInRC1) {\\n indexInRC2++;\\n }\\n\\n if (!inProximity(entryProofLast.proveSegment, _currentRevealRoundAnchor, winnerSelected.depth)) {\\n revert OutOfDepthClaim(3);\\n }\\n\\n inclusionFunction(entryProofLast, 30);\\n stampFunction(entryProofLast);\\n socFunction(entryProofLast);\\n\\n if (!inProximity(entryProof1.proveSegment, _currentRevealRoundAnchor, winnerSelected.depth)) {\\n revert OutOfDepthClaim(2);\\n }\\n\\n inclusionFunction(entryProof1, indexInRC1 * 2);\\n stampFunction(entryProof1);\\n socFunction(entryProof1);\\n\\n if (!inProximity(entryProof2.proveSegment, _currentRevealRoundAnchor, winnerSelected.depth)) {\\n revert OutOfDepthClaim(1);\\n }\\n\\n inclusionFunction(entryProof2, indexInRC2 * 2);\\n stampFunction(entryProof2);\\n socFunction(entryProof2);\\n\\n checkOrder(\\n indexInRC1,\\n indexInRC2,\\n entryProof1.proofSegments[0],\\n entryProof2.proofSegments[0],\\n entryProofLast.proofSegments[0]\\n );\\n\\n estimateSize(entryProofLast.proofSegments[0]);\\n\\n // Do the check if the withdraw was success\\n (bool success, ) = address(PostageContract).call(\\n abi.encodeWithSignature(\\\"withdraw(address)\\\", winnerSelected.owner)\\n );\\n if (!success) {\\n emit WithdrawFailed(winnerSelected.owner);\\n }\\n\\n emit WinnerSelected(winnerSelected);\\n emit ChunkCount(PostageContract.validChunkCount());\\n }\\n\\n function winnerSelection() internal {\\n uint64 cr = currentRound();\\n\\n if (!currentPhaseClaim()) {\\n revert NotClaimPhase();\\n }\\n\\n if (cr != currentRevealRound) {\\n revert NoReveals();\\n }\\n\\n if (cr <= currentClaimRound) {\\n revert AlreadyClaimed();\\n }\\n\\n uint256 currentWinnerSelectionSum = 0;\\n uint256 redundancyCount = 0;\\n bytes32 randomNumber;\\n uint256 randomNumberTrunc;\\n\\n bytes32 truthRevealedHash;\\n uint8 truthRevealedDepth;\\n uint256 currentCommitsLength = currentCommits.length;\\n\\n emit CountCommits(currentCommitsLength);\\n emit CountReveals(currentReveals.length);\\n\\n (truthRevealedHash, truthRevealedDepth) = getCurrentTruth();\\n emit TruthSelected(truthRevealedHash, truthRevealedDepth);\\n string memory winnerSelectionAnchor = currentWinnerSelectionAnchor();\\n\\n for (uint256 i = 0; i < currentCommitsLength; ) {\\n Commit memory currentCommit = currentCommits[i];\\n uint256 revIndex = currentCommit.revealIndex;\\n Reveal memory currentReveal = currentReveals[revIndex];\\n\\n // Select winner with valid truth\\n if (\\n currentCommit.revealed &&\\n truthRevealedHash == currentReveal.hash &&\\n truthRevealedDepth == currentReveal.depth\\n ) {\\n currentWinnerSelectionSum += currentReveal.stakeDensity;\\n randomNumber = keccak256(abi.encodePacked(winnerSelectionAnchor, redundancyCount));\\n randomNumberTrunc = uint256(randomNumber & MAX_H);\\n\\n if (randomNumberTrunc * currentWinnerSelectionSum < currentReveal.stakeDensity * (uint256(MAX_H) + 1)) {\\n winner = currentReveal;\\n }\\n\\n redundancyCount++;\\n }\\n\\n // Freeze deposit if any truth is false, make it a penaltyRandomFactor chance for this to happen\\n if (\\n currentCommit.revealed &&\\n (truthRevealedHash != currentReveal.hash || truthRevealedDepth != currentReveal.depth) &&\\n (block.prevrandao % 100 < penaltyRandomFactor)\\n ) {\\n Stakes.freezeDeposit(\\n currentReveal.owner,\\n penaltyMultiplierDisagreement * ROUND_LENGTH * uint256(2 ** truthRevealedDepth)\\n );\\n }\\n\\n // Slash deposits if revealed is false\\n if (!currentCommit.revealed) {\\n // slash in later phase (ph5)\\n // Stakes.slashDeposit(currentCommits[i].overlay, currentCommits[i].stake);\\n Stakes.freezeDeposit(\\n currentCommit.owner,\\n penaltyMultiplierNonRevealed * ROUND_LENGTH * uint256(2 ** truthRevealedDepth)\\n );\\n }\\n unchecked {\\n ++i;\\n }\\n }\\n\\n bool success = OracleContract.adjustPrice(uint16(redundancyCount));\\n if (!success) {\\n emit PriceAdjustmentSkipped(uint16(redundancyCount));\\n }\\n currentClaimRound = cr;\\n }\\n\\n function inclusionFunction(ChunkInclusionProof calldata entryProof, uint256 indexInRC) internal {\\n uint256 randomChunkSegmentIndex = uint256(seed) % 128;\\n bytes32 calculatedTransformedAddr = TransformedBMTChunk.transformedChunkAddressFromInclusionProof(\\n entryProof.proofSegments3,\\n entryProof.proveSegment2,\\n randomChunkSegmentIndex,\\n entryProof.chunkSpan,\\n currentRevealRoundAnchor\\n );\\n\\n emit transformedChunkAddressFromInclusionProof(indexInRC, calculatedTransformedAddr);\\n\\n if (\\n winner.hash !=\\n BMTChunk.chunkAddressFromInclusionProof(\\n entryProof.proofSegments,\\n entryProof.proveSegment,\\n indexInRC,\\n 32 * 32\\n )\\n ) {\\n revert InclusionProofFailed(1, calculatedTransformedAddr);\\n }\\n\\n if (entryProof.proofSegments2[0] != entryProof.proofSegments3[0]) {\\n revert InclusionProofFailed(2, calculatedTransformedAddr);\\n }\\n\\n bytes32 originalAddress = entryProof.socProof.length > 0\\n ? entryProof.socProof[0].chunkAddr // soc attestation in socFunction\\n : entryProof.proveSegment;\\n\\n if (\\n originalAddress !=\\n BMTChunk.chunkAddressFromInclusionProof(\\n entryProof.proofSegments2,\\n entryProof.proveSegment2,\\n randomChunkSegmentIndex,\\n entryProof.chunkSpan\\n )\\n ) {\\n revert InclusionProofFailed(3, calculatedTransformedAddr);\\n }\\n\\n // In case of SOC, the transformed address is hashed together with its address in the sample\\n if (entryProof.socProof.length > 0) {\\n calculatedTransformedAddr = keccak256(\\n abi.encode(\\n entryProof.proveSegment, // SOC address\\n calculatedTransformedAddr\\n )\\n );\\n }\\n\\n if (entryProof.proofSegments[0] != calculatedTransformedAddr) {\\n revert InclusionProofFailed(4, calculatedTransformedAddr);\\n }\\n }\\n\\n /**\\n * @notice Set freezing parameters\\n */\\n function setFreezingParams(\\n uint8 _penaltyMultiplierDisagreement,\\n uint8 _penaltyMultiplierNonRevealed,\\n uint8 _penaltyRandomFactor\\n ) external {\\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\\n revert NotAdmin();\\n }\\n\\n penaltyMultiplierDisagreement = _penaltyMultiplierDisagreement;\\n penaltyMultiplierNonRevealed = _penaltyMultiplierNonRevealed;\\n penaltyRandomFactor = _penaltyRandomFactor;\\n }\\n\\n /**\\n * @notice changes the max sample value used for reserve estimation\\n */\\n function setSampleMaxValue(uint256 _sampleMaxValue) external {\\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\\n revert NotAdmin();\\n }\\n\\n sampleMaxValue = _sampleMaxValue;\\n }\\n\\n /**\\n * @notice Updates the source of randomness. Uses block.difficulty in pre-merge chains, this is substituted\\n * to block.prevrandao in post merge chains.\\n */\\n function updateRandomness() private {\\n seed = keccak256(abi.encode(seed, block.prevrandao));\\n }\\n\\n /**\\n * @dev Pause the contract. The contract is provably stopped by renouncing\\n the pauser role and the admin role after pausing, can only be called by the `PAUSER`\\n */\\n function pause() public {\\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\\n revert OnlyPauser();\\n }\\n\\n _pause();\\n }\\n\\n /**\\n * @dev Unpause the contract, can only be called by the pauser when paused\\n */\\n function unPause() public {\\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\\n revert OnlyPauser();\\n }\\n _unpause();\\n }\\n\\n ////////////////////////////////////////\\n // STATE READING //\\n ////////////////////////////////////////\\n\\n // ----------------------------- Anchor calculations ------------------------------\\n\\n /**\\n * @notice Returns the current random seed which is used to determine later utilised random numbers.\\n * If rounds have elapsed without reveals, hash the seed with an incremented nonce to produce a new\\n * random seed and hence a new round anchor.\\n */\\n function currentSeed() public view returns (bytes32) {\\n uint64 cr = currentRound();\\n bytes32 currentSeedValue = seed;\\n\\n if (cr > currentRevealRound + 1) {\\n uint256 difference = cr - currentRevealRound - 1;\\n currentSeedValue = keccak256(abi.encodePacked(currentSeedValue, difference));\\n }\\n\\n return currentSeedValue;\\n }\\n\\n /**\\n * @notice Returns the seed which will become current once the next commit phase begins.\\n * Used to determine what the next round's anchor will be.\\n */\\n function nextSeed() public view returns (bytes32) {\\n uint64 cr = currentRound() + 1;\\n bytes32 currentSeedValue = seed;\\n\\n if (cr > currentRevealRound + 1) {\\n uint256 difference = cr - currentRevealRound - 1;\\n currentSeedValue = keccak256(abi.encodePacked(currentSeedValue, difference));\\n }\\n\\n return currentSeedValue;\\n }\\n\\n /**\\n * @notice The random value used to choose the selected truth teller.\\n */\\n function currentTruthSelectionAnchor() private view returns (string memory) {\\n if (!currentPhaseClaim()) {\\n revert NotClaimPhase();\\n }\\n\\n uint64 cr = currentRound();\\n if (cr != currentRevealRound) {\\n revert NoReveals();\\n }\\n\\n return string(abi.encodePacked(seed, \\\"0\\\"));\\n }\\n\\n /**\\n * @notice The random value used to choose the selected beneficiary.\\n */\\n function currentWinnerSelectionAnchor() private view returns (string memory) {\\n if (!currentPhaseClaim()) {\\n revert NotClaimPhase();\\n }\\n uint64 cr = currentRound();\\n if (cr != currentRevealRound) {\\n revert NoReveals();\\n }\\n\\n return string(abi.encodePacked(seed, \\\"1\\\"));\\n }\\n\\n /**\\n * @notice The anchor used to determine eligibility for the current round.\\n * @dev A node must be within proximity order of less than or equal to the storage depth they intend to report.\\n */\\n function currentRoundAnchor() public view returns (bytes32 returnVal) {\\n // This will be called in reveal phase and set as currentRevealRoundAnchor or in\\n // commit phase when checking eligibility for next round by isParticipatingInUpcomingRound\\n if (currentPhaseCommit() || (currentRound() > currentRevealRound && !currentPhaseClaim())) {\\n return currentSeed();\\n }\\n\\n // This will be called by isParticipatingInUpcomingRound check in claim phase\\n if (currentPhaseClaim()) {\\n return nextSeed();\\n }\\n\\n // Without this, this function will output 0x0 after first reveal which is value and we prefere it reverts\\n if (currentPhaseReveal() && currentRound() == currentRevealRound) {\\n revert FirstRevealDone();\\n }\\n }\\n\\n /**\\n * @notice Returns true if an overlay address _A_ is within proximity order _minimum_ of _B_.\\n * @param A An overlay address to compare.\\n * @param B An overlay address to compare.\\n * @param minimum Minimum proximity order.\\n */\\n function inProximity(bytes32 A, bytes32 B, uint8 minimum) public pure returns (bool) {\\n if (minimum == 0) {\\n return true;\\n }\\n\\n return uint256(A ^ B) < uint256(2 ** (256 - minimum));\\n }\\n\\n // ----------------------------- Commit ------------------------------\\n\\n /**\\n * @notice The number of the current round.\\n */\\n function currentRound() public view returns (uint64) {\\n return uint64(block.number / ROUND_LENGTH);\\n }\\n\\n /**\\n * @notice Returns true if current block is during commit phase.\\n */\\n function currentPhaseCommit() public view returns (bool) {\\n if (block.number % ROUND_LENGTH < ROUND_LENGTH / 4) {\\n return true;\\n }\\n return false;\\n }\\n\\n /**\\n * @notice Determine if a the owner of a given overlay can participate in the upcoming round.\\n * @param _owner The address of the applicant from.\\n * @param _depth The storage depth the applicant intends to report.\\n */\\n function isParticipatingInUpcomingRound(address _owner, uint8 _depth) public view returns (bool) {\\n uint256 _lastUpdate = Stakes.lastUpdatedBlockNumberOfAddress(_owner);\\n uint8 _depthResponsibility = _depth - Stakes.heightOfAddress(_owner);\\n\\n if (currentPhaseReveal()) {\\n revert WrongPhase();\\n }\\n\\n if (_lastUpdate == 0) {\\n revert NotStaked();\\n }\\n\\n if (_lastUpdate >= block.number - 2 * ROUND_LENGTH) {\\n revert MustStake2Rounds();\\n }\\n\\n return inProximity(Stakes.overlayOfAddress(_owner), currentRoundAnchor(), _depthResponsibility);\\n }\\n\\n // ----------------------------- Reveal ------------------------------\\n\\n /**\\n * @notice Returns minimum depth reveal has to have to participate in this round\\n */\\n function currentMinimumDepth() public view returns (uint8) {\\n // We are checking value in reveal phase, as the currentCommitRound is set to the current round\\n // but the currentClaimRound is still set to the last time claim was made\\n // We add 1 to ensure that for the next round the minimum depth is the same as last winner depth\\n\\n uint256 difference = currentCommitRound - currentClaimRound;\\n uint8 skippedRounds = uint8(difference > 254 ? 254 : difference) + 1;\\n\\n uint8 lastWinnerDepth = winner.depth;\\n\\n // We ensure that skippedRounds is not bigger than lastWinnerDepth, because of overflow\\n return skippedRounds >= lastWinnerDepth ? 0 : lastWinnerDepth - skippedRounds;\\n }\\n\\n /**\\n * @notice Helper function to get this node reveal in commits\\n * @dev\\n */\\n function findCommit(bytes32 _overlay, bytes32 _obfuscatedHash) internal view returns (uint256) {\\n for (uint256 i = 0; i < currentCommits.length; ) {\\n if (currentCommits[i].overlay == _overlay && _obfuscatedHash == currentCommits[i].obfuscatedHash) {\\n return i;\\n }\\n unchecked {\\n ++i;\\n }\\n }\\n revert NoMatchingCommit();\\n }\\n\\n /**\\n * @notice Hash the pre-image values to the obsfucated hash.\\n * @dev _revealNonce_ must be randomly generated, used once and kept secret until the reveal phase.\\n * @param _overlay The overlay address of the applicant.\\n * @param _depth The reported depth.\\n * @param _hash The reserve commitment hash.\\n * @param revealNonce A random, single use, secret nonce.\\n */\\n function wrapCommit(\\n bytes32 _overlay,\\n uint8 _depth,\\n bytes32 _hash,\\n bytes32 revealNonce\\n ) public pure returns (bytes32) {\\n return keccak256(abi.encodePacked(_overlay, _depth, _hash, revealNonce));\\n }\\n\\n /**\\n * @notice Returns true if current block is during reveal phase.\\n */\\n function currentPhaseReveal() public view returns (bool) {\\n uint256 number = block.number % ROUND_LENGTH;\\n if (number >= ROUND_LENGTH / 4 && number < ROUND_LENGTH / 2) {\\n return true;\\n }\\n return false;\\n }\\n\\n /**\\n * @notice Returns true if current block is during reveal phase.\\n */\\n function currentRoundReveals() public view returns (Reveal[] memory) {\\n if (!currentPhaseClaim()) {\\n revert NotClaimPhase();\\n }\\n uint64 cr = currentRound();\\n if (cr != currentRevealRound) {\\n revert NoReveals();\\n }\\n\\n return currentReveals;\\n }\\n\\n // ----------------------------- Claim ------------------------------\\n\\n /**\\n * @notice Returns true if current block is during claim phase.\\n */\\n function currentPhaseClaim() public view returns (bool) {\\n if (block.number % ROUND_LENGTH >= ROUND_LENGTH / 2) {\\n return true;\\n }\\n return false;\\n }\\n\\n function getCurrentTruth() internal view returns (bytes32 Hash, uint8 Depth) {\\n uint256 currentSum;\\n bytes32 randomNumber;\\n uint256 randomNumberTrunc;\\n\\n bytes32 truthRevealedHash;\\n uint8 truthRevealedDepth;\\n uint256 revIndex;\\n string memory truthSelectionAnchor = currentTruthSelectionAnchor();\\n uint256 commitsArrayLength = currentCommits.length;\\n\\n for (uint256 i = 0; i < commitsArrayLength; ) {\\n if (currentCommits[i].revealed) {\\n revIndex = currentCommits[i].revealIndex;\\n currentSum += currentReveals[revIndex].stakeDensity;\\n randomNumber = keccak256(abi.encodePacked(truthSelectionAnchor, i));\\n randomNumberTrunc = uint256(randomNumber & MAX_H);\\n\\n // question is whether randomNumber / MAX_H < probability\\n // where probability is stakeDensity / currentSum\\n // to avoid resorting to floating points all divisions should be\\n // simplified with multiplying both sides (as long as divisor > 0)\\n // randomNumber / (MAX_H + 1) < stakeDensity / currentSum\\n // ( randomNumber / (MAX_H + 1) ) * currentSum < stakeDensity\\n // randomNumber * currentSum < stakeDensity * (MAX_H + 1)\\n if (randomNumberTrunc * currentSum < currentReveals[revIndex].stakeDensity * (uint256(MAX_H) + 1)) {\\n truthRevealedHash = currentReveals[revIndex].hash;\\n truthRevealedDepth = currentReveals[revIndex].depth;\\n }\\n }\\n unchecked {\\n ++i;\\n }\\n }\\n\\n return (truthRevealedHash, truthRevealedDepth);\\n }\\n\\n /**\\n * @notice Determine if a the owner of a given overlay will be the beneficiary of the claim phase.\\n * @param _overlay The overlay address of the applicant.\\n */\\n function isWinner(bytes32 _overlay) public view returns (bool) {\\n if (!currentPhaseClaim()) {\\n revert NotClaimPhase();\\n }\\n\\n uint64 cr = currentRound();\\n if (cr != currentRevealRound) {\\n revert NoReveals();\\n }\\n\\n if (cr <= currentClaimRound) {\\n revert AlreadyClaimed();\\n }\\n\\n uint256 currentWinnerSelectionSum;\\n bytes32 winnerIs;\\n bytes32 randomNumber;\\n uint256 randomNumberTrunc;\\n bytes32 truthRevealedHash;\\n uint8 truthRevealedDepth;\\n uint256 revIndex;\\n string memory winnerSelectionAnchor = currentWinnerSelectionAnchor();\\n uint256 redundancyCount = 0;\\n\\n // Get current truth\\n (truthRevealedHash, truthRevealedDepth) = getCurrentTruth();\\n uint256 commitsArrayLength = currentCommits.length;\\n\\n for (uint256 i = 0; i < commitsArrayLength; ) {\\n revIndex = currentCommits[i].revealIndex;\\n\\n // Deterministically read winner\\n if (\\n currentCommits[i].revealed &&\\n truthRevealedHash == currentReveals[revIndex].hash &&\\n truthRevealedDepth == currentReveals[revIndex].depth\\n ) {\\n currentWinnerSelectionSum += currentReveals[revIndex].stakeDensity;\\n randomNumber = keccak256(abi.encodePacked(winnerSelectionAnchor, redundancyCount));\\n randomNumberTrunc = uint256(randomNumber & MAX_H);\\n\\n if (\\n randomNumberTrunc * currentWinnerSelectionSum <\\n currentReveals[revIndex].stakeDensity * (uint256(MAX_H) + 1)\\n ) {\\n winnerIs = currentReveals[revIndex].overlay;\\n }\\n\\n redundancyCount++;\\n }\\n unchecked {\\n ++i;\\n }\\n }\\n\\n return (winnerIs == _overlay);\\n }\\n\\n // ----------------------------- Claim verifications ------------------------------\\n\\n function socFunction(ChunkInclusionProof calldata entryProof) internal pure {\\n if (entryProof.socProof.length == 0) return;\\n\\n if (\\n !Signatures.socVerify(\\n entryProof.socProof[0].signer, // signer Ethereum address to check against\\n entryProof.socProof[0].signature,\\n entryProof.socProof[0].identifier,\\n entryProof.socProof[0].chunkAddr\\n )\\n ) {\\n revert SocVerificationFailed(entryProof.socProof[0].chunkAddr);\\n }\\n\\n if (\\n calculateSocAddress(entryProof.socProof[0].identifier, entryProof.socProof[0].signer) !=\\n entryProof.proveSegment\\n ) {\\n revert SocCalcNotMatching(entryProof.socProof[0].chunkAddr);\\n }\\n }\\n\\n function stampFunction(ChunkInclusionProof calldata entryProof) internal view {\\n // authentic\\n (address batchOwner, uint8 batchDepth, uint8 bucketDepth, , , ) = PostageContract.batches(\\n entryProof.postageProof.postageId\\n );\\n\\n // alive\\n if (batchOwner == address(0)) {\\n revert BatchDoesNotExist(entryProof.postageProof.postageId); // Batch does not exist or expired\\n }\\n\\n uint32 postageIndex = getPostageIndex(entryProof.postageProof.index);\\n uint256 maxPostageIndex = postageStampIndexCount(batchDepth, bucketDepth);\\n // available\\n if (postageIndex >= maxPostageIndex) {\\n revert IndexOutsideSet(entryProof.postageProof.postageId);\\n }\\n\\n // aligned\\n uint64 postageBucket = getPostageBucket(entryProof.postageProof.index);\\n uint64 addressBucket = addressToBucket(entryProof.proveSegment, bucketDepth);\\n if (postageBucket != addressBucket) {\\n revert BucketDiffers(entryProof.postageProof.postageId);\\n }\\n\\n // authorized\\n if (\\n !Signatures.postageVerify(\\n batchOwner,\\n entryProof.postageProof.signature,\\n entryProof.proveSegment,\\n entryProof.postageProof.postageId,\\n entryProof.postageProof.index,\\n entryProof.postageProof.timeStamp\\n )\\n ) {\\n revert SigRecoveryFailed(entryProof.postageProof.postageId);\\n }\\n }\\n\\n function addressToBucket(bytes32 swarmAddress, uint8 bucketDepth) internal pure returns (uint32) {\\n uint32 prefix = uint32(uint256(swarmAddress) >> (256 - 32));\\n return prefix >> (32 - bucketDepth);\\n }\\n\\n function postageStampIndexCount(uint8 postageDepth, uint8 bucketDepth) internal pure returns (uint256) {\\n return 1 << (postageDepth - bucketDepth);\\n }\\n\\n function getPostageIndex(uint64 signedIndex) internal pure returns (uint32) {\\n return uint32(signedIndex);\\n }\\n\\n function getPostageBucket(uint64 signedIndex) internal pure returns (uint64) {\\n return uint32(signedIndex >> 32);\\n }\\n\\n function calculateSocAddress(bytes32 identifier, address signer) internal pure returns (bytes32) {\\n return keccak256(abi.encodePacked(identifier, signer));\\n }\\n\\n function checkOrder(uint256 a, uint256 b, bytes32 trA1, bytes32 trA2, bytes32 trALast) internal pure {\\n if (a < b) {\\n if (uint256(trA1) >= uint256(trA2)) {\\n revert RandomElementCheckFailed();\\n }\\n if (uint256(trA2) >= uint256(trALast)) {\\n revert LastElementCheckFailed();\\n }\\n } else {\\n if (uint256(trA2) >= uint256(trA1)) {\\n revert RandomElementCheckFailed();\\n }\\n if (uint256(trA1) >= uint256(trALast)) {\\n revert LastElementCheckFailed();\\n }\\n }\\n }\\n\\n function estimateSize(bytes32 trALast) internal view {\\n if (uint256(trALast) >= sampleMaxValue) {\\n revert ReserveCheckFailed(trALast);\\n }\\n }\\n}\\n\",\"keccak256\":\"0xecc576245f09eba122643ca2fda047487c76cca36ebe50509ccc5eb99e7eb3a6\",\"license\":\"BSD-3-Clause\"},\"src/Util/ChunkProof.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\npragma solidity ^0.8.19;\\n\\nlibrary BMTChunk {\\n // max chunk payload size\\n uint256 public constant MAX_CHUNK_PAYLOAD_SIZE = 4096;\\n // segment byte size\\n uint256 public constant SEGMENT_SIZE = 32;\\n\\n /**\\n * @notice Changes the endianness of a uint64.\\n * @dev https://graphics.stanford.edu/~seander/bithacks.html#ReverseParallel\\n * @param _b The unsigned integer to reverse\\n * @return v - The reversed value\\n */\\n function reverseUint64(uint64 _b) public pure returns (uint64) {\\n uint256 v = _b;\\n\\n // swap bytes\\n v =\\n ((v >> 8) & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) |\\n ((v & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) << 8);\\n // swap 2-byte long pairs\\n v =\\n ((v >> 16) & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) |\\n ((v & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) << 16);\\n // swap 4-byte long pairs\\n v =\\n ((v >> 32) & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) |\\n ((v & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) << 32);\\n\\n return uint64(v);\\n }\\n\\n /** Calculates the root hash from the provided inclusion proof segments and its corresponding segment index\\n * @param _proofSegments Proof segments.\\n * @param _proveSegment Segment to prove.\\n * @param _proveSegmentIndex Prove segment index\\n * @return _calculatedHash chunk hash\\n */\\n function rootHashFromInclusionProof(\\n bytes32[] memory _proofSegments,\\n bytes32 _proveSegment,\\n uint256 _proveSegmentIndex\\n ) internal pure returns (bytes32 _calculatedHash) {\\n _calculatedHash = _proveSegment;\\n for (uint256 i = 0; i < _proofSegments.length; i++) {\\n bool mergeFromRight = _proveSegmentIndex % 2 == 0;\\n _calculatedHash = mergeSegment(_calculatedHash, _proofSegments[i], mergeFromRight);\\n _proveSegmentIndex >>= 1;\\n }\\n return _calculatedHash;\\n }\\n\\n /**\\n * Calculate the chunk address from the Binary Merkle Tree of the chunk data\\n *\\n * The BMT chunk address is the hash of the 8 byte span and the root\\n * hash of a binary Merkle tree (BMT) built on the 32-byte segments\\n * of the underlying data.\\n * @param _proofSegments Proof segments.\\n * @param _proveSegment Segment to prove.\\n * @param _proveSegmentIndex Prove segment index\\n * @param _chunkSpan chunk bytes length\\n * @return _chunkHash chunk hash\\n */\\n function chunkAddressFromInclusionProof(\\n bytes32[] memory _proofSegments,\\n bytes32 _proveSegment,\\n uint256 _proveSegmentIndex,\\n uint64 _chunkSpan\\n ) internal pure returns (bytes32) {\\n bytes32 rootHash = rootHashFromInclusionProof(_proofSegments, _proveSegment, _proveSegmentIndex);\\n return keccak256(abi.encodePacked(reverseUint64(_chunkSpan), rootHash));\\n }\\n\\n function mergeSegment(\\n bytes32 _calculatedHash,\\n bytes32 _proofSegment,\\n bool mergeFromRight\\n ) internal pure returns (bytes32 res) {\\n if (mergeFromRight) {\\n res = keccak256(abi.encode(_calculatedHash, _proofSegment));\\n } else {\\n res = keccak256(abi.encode(_proofSegment, _calculatedHash));\\n }\\n return res;\\n }\\n}\\n\",\"keccak256\":\"0xe4a86f2002b8b8fc4c955537d6b80ba42fb04a816e783ddbd05f0484b013938a\",\"license\":\"MIT\"},\"src/Util/Signatures.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\npragma solidity ^0.8.19;\\n\\nlibrary Signatures {\\n error InvalidSignatureLength();\\n\\n /** Hash of the message to sign */\\n function getPostageMessageHash(\\n bytes32 _chunkAddr,\\n bytes32 _batchId,\\n uint64 _index,\\n uint64 _timeStamp\\n ) internal pure returns (bytes32) {\\n return keccak256(abi.encodePacked(_chunkAddr, _batchId, _index, _timeStamp));\\n }\\n\\n function postageVerify(\\n address _signer, // signer Ethereum address to check against\\n bytes memory _signature,\\n bytes32 _chunkAddr,\\n bytes32 _postageId,\\n uint64 _index,\\n uint64 _timeStamp\\n ) internal pure returns (bool) {\\n bytes32 messageHash = getPostageMessageHash(_chunkAddr, _postageId, _index, _timeStamp);\\n bytes32 ethMessageHash = getEthSignedMessageHash(messageHash);\\n\\n return recoverSigner(ethMessageHash, _signature) == _signer;\\n }\\n\\n function getEthSignedMessageHash(bytes32 _messageHash) internal pure returns (bytes32) {\\n /*\\n Signature is produced by signing a keccak256 hash with the following format:\\n \\\"\\\\x19Ethereum Signed Message\\\\n\\\" + len(msg) + msg\\n */\\n return keccak256(abi.encodePacked(\\\"\\\\x19Ethereum Signed Message:\\\\n32\\\", _messageHash));\\n }\\n\\n function recoverSigner(\\n bytes32 _ethSignedMessageHash, // it has to be prefixed message: https://ethereum.stackexchange.com/questions/19582/does-ecrecover-in-solidity-expects-the-x19ethereum-signed-message-n-prefix/21037\\n bytes memory _signature\\n ) internal pure returns (address) {\\n (bytes32 r, bytes32 s, uint8 v) = splitSignature(_signature);\\n\\n return ecrecover(_ethSignedMessageHash, v, r, s);\\n }\\n\\n function splitSignature(bytes memory sig) internal pure returns (bytes32 r_, bytes32 s_, uint8 v_) {\\n if (sig.length != 65) {\\n revert InvalidSignatureLength();\\n }\\n\\n assembly {\\n /*\\n verbose explanation: https://ethereum.stackexchange.com/questions/135591/split-signature-function-in-solidity-by-example-docs\\n First 32 bytes stores the length of the signature\\n add(sig, 32) = pointer of sig + 32\\n effectively, skips first 32 bytes of signature\\n mload(p) loads next 32 bytes starting at the memory address p into memory\\n */\\n\\n // first 32 bytes, after the length prefix\\n r_ := mload(add(sig, 32))\\n // second 32 bytes\\n s_ := mload(add(sig, 64))\\n // final byte (first byte of the next 32 bytes)\\n v_ := byte(0, mload(add(sig, 96)))\\n }\\n\\n // implicitly return (r, s, v)\\n }\\n\\n function getSocMessageHash(bytes32 _identifier, bytes32 _chunkAddr) internal pure returns (bytes32) {\\n return keccak256(abi.encodePacked(_identifier, _chunkAddr));\\n }\\n\\n function socVerify(\\n address _signer, // signer Ethereum address to check against\\n bytes memory _signature,\\n bytes32 _identifier,\\n bytes32 _chunkAddr\\n ) internal pure returns (bool) {\\n bytes32 messageHash = getSocMessageHash(_identifier, _chunkAddr);\\n bytes32 ethMessageHash = getEthSignedMessageHash(messageHash);\\n\\n return recoverSigner(ethMessageHash, _signature) == _signer;\\n }\\n}\\n\",\"keccak256\":\"0x11762639cfa5bd2ea21922f762254c776ce890ab9e4085b3e3d45dbe21867ac8\",\"license\":\"MIT\"},\"src/Util/TransformedChunkProof.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\npragma solidity ^0.8.19;\\n\\nlibrary TransformedBMTChunk {\\n // max chunk payload size\\n uint256 public constant MAX_CHUNK_PAYLOAD_SIZE = 4096;\\n // segment byte size\\n uint256 public constant SEGMENT_SIZE = 32;\\n\\n /** Calculates the root hash from the provided inclusion proof segments and its corresponding segment index\\n * @param _proofSegments Proof segments.\\n * @param _proveSegment Segment to prove.\\n * @param _proveSegmentIndex Prove segment index\\n * @return _calculatedHash chunk hash\\n */\\n function transformedRootHashFromInclusionProof(\\n bytes32[] memory _proofSegments,\\n bytes32 _proveSegment,\\n uint256 _proveSegmentIndex,\\n bytes32 key\\n ) internal pure returns (bytes32 _calculatedHash) {\\n _calculatedHash = _proveSegment;\\n for (uint256 i = 0; i < _proofSegments.length; i++) {\\n bool mergeFromRight = _proveSegmentIndex % 2 == 0 ? true : false;\\n _calculatedHash = transformedMergeSegment(_calculatedHash, _proofSegments[i], mergeFromRight, key);\\n _proveSegmentIndex >>= 1;\\n }\\n\\n return _calculatedHash;\\n }\\n\\n /**\\n * @notice Changes the endianness of a uint64.\\n * @dev https://graphics.stanford.edu/~seander/bithacks.html#ReverseParallel\\n * @param _b The unsigned integer to reverse\\n * @return v - The reversed value\\n */\\n function reverseUint64(uint64 _b) public pure returns (uint64) {\\n uint256 v = _b;\\n\\n // swap bytes\\n v =\\n ((v >> 8) & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) |\\n ((v & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) << 8);\\n // swap 2-byte long pairs\\n v =\\n ((v >> 16) & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) |\\n ((v & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) << 16);\\n // swap 4-byte long pairs\\n v =\\n ((v >> 32) & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) |\\n ((v & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) << 32);\\n\\n return uint64(v);\\n }\\n\\n /**\\n * Calculate the chunk address from the Binary Merkle Tree of the chunk data\\n *\\n * The BMT chunk address is the hash of the 8 byte span and the root\\n * hash of a binary Merkle tree (BMT) built on the 32-byte segments\\n * of the underlying data.\\n * @param _proofSegments Proof segments.\\n * @param _proveSegment Segment to prove.\\n * @param _proveSegmentIndex Prove segment index\\n * @param _chunkSpan chunk bytes length\\n * @return _chunkHash chunk hash\\n */\\n function transformedChunkAddressFromInclusionProof(\\n bytes32[] memory _proofSegments,\\n bytes32 _proveSegment,\\n uint256 _proveSegmentIndex,\\n uint64 _chunkSpan,\\n bytes32 key\\n ) internal pure returns (bytes32) {\\n bytes32 rootHash = transformedRootHashFromInclusionProof(\\n _proofSegments,\\n _proveSegment,\\n _proveSegmentIndex,\\n key\\n );\\n return keccak256(abi.encodePacked(key, reverseUint64(_chunkSpan), rootHash));\\n }\\n\\n function transformedMergeSegment(\\n bytes32 _calculatedHash,\\n bytes32 _proofSegment,\\n bool mergeFromRight,\\n bytes32 key\\n ) internal pure returns (bytes32 res) {\\n if (mergeFromRight) {\\n res = keccak256(abi.encode(key, _calculatedHash, _proofSegment));\\n } else {\\n res = keccak256(abi.encode(key, _proofSegment, _calculatedHash));\\n }\\n return res;\\n }\\n}\\n\",\"keccak256\":\"0xf36473af0bec0de80c769b139a09bc0329807cb5c3b6234473601081da14350c\",\"license\":\"MIT\"},\"src/interface/IPostageStamp.sol\":{\"content\":\"// SPDX-License-Identifier: BSD-3-Clause\\npragma solidity ^0.8.19;\\n\\ninterface IPostageStamp {\\n function withdraw(address beneficiary) external;\\n\\n function setPrice(uint256 _price) external;\\n\\n function validChunkCount() external view returns (uint256);\\n\\n function batchOwner(bytes32 _batchId) external view returns (address);\\n\\n function batchDepth(bytes32 _batchId) external view returns (uint8);\\n\\n function batchBucketDepth(bytes32 _batchId) external view returns (uint8);\\n\\n function remainingBalance(bytes32 _batchId) external view returns (uint256);\\n\\n function minimumInitialBalancePerChunk() external view returns (uint256);\\n\\n function batches(\\n bytes32\\n )\\n external\\n view\\n returns (\\n address owner,\\n uint8 depth,\\n uint8 bucketDepth,\\n bool immutableFlag,\\n uint256 normalisedBalance,\\n uint256 lastUpdatedBlockNumber\\n );\\n}\\n\",\"keccak256\":\"0xb46f1043bf7fdc22d5f719ab97341211fa30fff499de3cf079be715079b965ad\",\"license\":\"BSD-3-Clause\"}},\"version\":1}", + "bytecode": "0x60806040526008805462ffffff60c01b19166264020160c01b1790557dba1914b54e0348a1028d1a103a95ed55c4004b9d332400000000000000006009553480156200004a57600080fd5b5060405162004e1538038062004e158339810160408190526200006d916200019d565b60018054600380546001600160a01b03199081166001600160a01b03888116919091179092556001600160a81b0319909216610100868316021790925560028054909116918316919091179055620000c7600033620000d0565b505050620001e7565b620000dc8282620000e0565b5050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16620000dc576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556200013c3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b80516001600160a01b03811681146200019857600080fd5b919050565b600080600060608486031215620001b357600080fd5b620001be8462000180565b9250620001ce6020850162000180565b9150620001de6040850162000180565b90509250925092565b614c1e80620001f76000396000f3fe608060405234801561001057600080fd5b50600436106102775760003560e01c806377c75d1011610160578063b6cd5822116100d8578063dfbf53ae1161008c578063f69ee1d111610071578063f69ee1d1146105df578063f7b188a5146105f2578063fb00f2f3146105fa57600080fd5b8063dfbf53ae1461059c578063f4e6fcca146105cc57600080fd5b8063ce987745116100bd578063ce9877451461056e578063d1e8b63d14610581578063d547741f1461058957600080fd5b8063b6cd582214610541578063c46b40291461055457600080fd5b80638456cb591161012f5780638d8b6428116101145780638d8b6428146104fa57806391d1485414610502578063a217fddf1461053957600080fd5b80638456cb59146104ea5780638a19c8bc146104f257600080fd5b806377c75d10146104645780637fe019c61461047757806382b39b1b1461049257806383220626146104e257600080fd5b80635c975abb116101f357806364c34a85116101c257806369da9114116101a757806369da9114146103de5780636f94aaf2146103f157806372286cba1461040c57600080fd5b806364c34a85146103a957806369bfac01146103b157600080fd5b80635c975abb146103705780635d4844ea1461037b57806362fd29ae1461038e57806363f5cf7c1461039657600080fd5b80632a4e62491161024a5780632f3906da1161022f5780632f3906da1461034257806336568abe1461034a5780635838d6731461035d57600080fd5b80632a4e6249146103185780632f2ff15d1461032d57600080fd5b806301ffc9a71461027c5780631736d472146102a457806318350096146102b7578063248a9ca3146102e7575b600080fd5b61028f61028a36600461431f565b61060d565b60405190151581526020015b60405180910390f35b61028f6102b236600461436d565b610676565b6001546102cf9061010090046001600160a01b031681565b6040516001600160a01b03909116815260200161029b565b61030a6102f53660046143a6565b60009081526020819052604090206001015490565b60405190815260200161029b565b610320610883565b60405161029b91906143bf565b61034061033b36600461444e565b610990565b005b61028f6109ba565b61034061035836600461444e565b610a04565b61034061036b366004614490565b610a95565b60015460ff1661028f565b6003546102cf906001600160a01b031681565b61030a611032565b6103406103a43660046144d5565b6110fe565b61030a611533565b6008546103c59067ffffffffffffffff1681565b60405167ffffffffffffffff909116815260200161029b565b6002546102cf906001600160a01b031681565b6008546103c590600160801b900467ffffffffffffffff1681565b61041f61041a3660046143a6565b611613565b604080519788526001600160a01b0390961660208801529315159486019490945260ff9091166060850152608084015260a083019190915260c082015260e00161029b565b61028f6104723660046143a6565b611671565b6008546103c590600160401b900467ffffffffffffffff1681565b6104a56104a03660046143a6565b611921565b604080519687526001600160a01b03909516602087015260ff909316938501939093526060840152608083019190915260a082015260c00161029b565b61030a611978565b610340611983565b6103c56119dc565b61028f6119e9565b61028f61051036600461444e565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b61030a600081565b61034061054f36600461455d565b611a13565b61055c611f6d565b60405160ff909116815260200161029b565b61030a61057c366004614592565b611ff2565b61028f612061565b61034061059736600461444e565b612086565b600a54600b54600c54600d54600e546104a594936001600160a01b03811693600160a01b90910460ff1692909186565b6103406105da3660046145cf565b6120ab565b6103406105ed3660046143a6565b612192565b6103406121e6565b61028f61060836600461461a565b61223d565b60006001600160e01b031982167f7965db0b00000000000000000000000000000000000000000000000000000000148061067057507f01ffc9a7000000000000000000000000000000000000000000000000000000006001600160e01b03198316145b92915050565b60035460405163d1052d1f60e01b81526001600160a01b038481166004830152600092839291169063d1052d1f90602401602060405180830381865afa1580156106c4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106e89190614648565b600354604051631d54805360e01b81526001600160a01b03878116600483015292935060009290911690631d54805390602401602060405180830381865afa158015610738573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061075c9190614661565b6107669085614694565b90506107706109ba565b156107a7576040517fe2586bcc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b816000036107c7576040516273e5c360e31b815260040160405180910390fd5b6107d3609860026146ad565b6107dd90436146c4565b82106107fc57604051630a0744c560e01b815260040160405180910390fd5b6003546040516397adedb560e01b81526001600160a01b03878116600483015261087a9216906397adedb590602401602060405180830381865afa158015610848573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061086c9190614648565b610874611533565b8361223d565b95945050505050565b606061088d6119e9565b6108aa57604051633788c6c160e11b815260040160405180910390fd5b60006108b46119dc565b60085490915067ffffffffffffffff808316600160401b90920416146108ed57604051636fbabc7760e01b815260040160405180910390fd5b6005805480602002602001604051908101604052809291908181526020016000905b828210156109865760008481526020908190206040805160c08101825260058602909201805483526001808201546001600160a01b03811685870152600160a01b900460ff169284019290925260028101546060840152600381015460808401526004015460a0830152908352909201910161090f565b5050505091505090565b6000828152602081905260409020600101546109ab8161227a565b6109b58383612287565b505050565b6000806109c86098436146ed565b90506109d660046098614701565b81101580156109ef57506109ec60026098614701565b81105b156109fc57600191505090565b600091505090565b6001600160a01b0381163314610a875760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b610a918282612325565b5050565b610a9d6123a4565b6000610aa76119dc565b6003546040516397adedb560e01b81523360048201529192506000916001600160a01b03909116906397adedb590602401602060405180830381865afa158015610af5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b199190614648565b6003546040517f830a053e0000000000000000000000000000000000000000000000000000000081523360048201529192506000916001600160a01b039091169063830a053e90602401602060405180830381865afa158015610b80573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ba49190614648565b60035460405163d1052d1f60e01b81523360048201529192506000916001600160a01b039091169063d1052d1f90602401602060405180830381865afa158015610bf2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c169190614648565b600354604051631d54805360e01b81523360048201529192506000916001600160a01b0390911690631d54805390602401602060405180830381865afa158015610c64573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c889190614661565b9050610c92612061565b610cc8576040517fdc816a8700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001610cd660046098614701565b610ce091906146c4565b610ceb6098436146ed565b03610d22576040517f5baef6b600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8567ffffffffffffffff168567ffffffffffffffff161115610d70576040517f50ff7c0000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8567ffffffffffffffff168567ffffffffffffffff161015610dbe576040517f7a0c0fd600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b81600003610dde576040516273e5c360e31b815260040160405180910390fd5b610dea609860026146ad565b610df490436146c4565b8210610e1357604051630a0744c560e01b815260040160405180910390fd5b60085467ffffffffffffffff868116911614610e5357610e356004600061423d565b6008805467ffffffffffffffff191667ffffffffffffffff87161790555b60045460005b81811015610ec6578560048281548110610e7557610e75614715565b90600052602060002090600502016000015403610ebe576040517fbfec555800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600101610e59565b5060046040518060e00160405280878152602001336001600160a01b031681526020016000151581526020018460ff1681526020018681526020018a8152602001600081525090806001815401808255809150506001900390600052602060002090600502016000909190919091506000820151816000015560208201518160010160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555060408201518160010160146101000a81548160ff02191690831515021790555060608201518160010160156101000a81548160ff021916908360ff1602179055506080820151816002015560a0820151816003015560c0820151816004015550507faadc88121471799d39ee2bbe1dd30a4ab57510e2a33bd6e537de5fafd2daa8868786846040516110209392919067ffffffffffffffff939093168352602083019190915260ff16604082015260600190565b60405180910390a15050505050505050565b60008061103d6119dc565b61104890600161472b565b6007546008549192509061106e90600160401b900467ffffffffffffffff16600161472b565b67ffffffffffffffff168267ffffffffffffffff161115610670576008546000906001906110ad90600160401b900467ffffffffffffffff1685614753565b6110b79190614753565b67ffffffffffffffff16905081816040516020016110df929190918252602082015260400190565b6040516020818303038152906040528051906020012091505092915050565b6111066123a4565b61110e6123f7565b6040805160c081018252600a548152600b546001600160a01b0381166020830152600160a01b900460ff1691810191909152600c546060820152600d546080820152600e5460a0820152600654600754600091829161116e600f826146ed565b935061117b600e826146ed565b9250838310611192578261118e81614774565b9350505b6111a5866020013583876040015161223d565b6111c557604051633b5f43a360e01b815260036004820152602401610a7e565b6111d086601e612a66565b6111d986612d78565b6111e286613085565b6111f5886020013583876040015161223d565b61121557604051633b5f43a360e01b815260026004820152602401610a7e565b611229886112248660026146ad565b612a66565b61123288612d78565b61123b88613085565b61124e876020013583876040015161223d565b61126e57604051633b5f43a360e01b815260016004820152602401610a7e565b61127d876112248560026146ad565b61128687612d78565b61128f87613085565b611305848461129e8b8061478d565b60008181106112af576112af614715565b602002919091013590506112c38b8061478d565b60008181106112d4576112d4614715565b602002919091013590506112e88b8061478d565b60008181106112f9576112f9614715565b90506020020135613319565b61132f611312878061478d565b600081811061132357611323614715565b905060200201356133a6565b60015460208601516040516001600160a01b03918216602482015260009261010090049091169060440160408051601f198184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f51cff8d900000000000000000000000000000000000000000000000000000000179052516113bc9190614802565b6000604051808303816000865af19150503d80600081146113f9576040519150601f19603f3d011682016040523d82523d6000602084013e6113fe565b606091505b5050905080611449576020808701516040516001600160a01b0390911681527f7ae187a0c04cf55b655ca83fa11d37854c882bf1fdcb588469b414731bb0e05a910160405180910390a15b7f788e77979e6e6a8a6a5d2c19c58b1ff9671298f54c85ac6f6aa30379aed5861a86604051611478919061481e565b60405180910390a17fbee3fc8a3523c1a65fa9308ce1f2b8fd90c24975b141b754603194597846e4dd60018054906101000a90046001600160a01b03166001600160a01b0316638a5e8e326040518163ffffffff1660e01b8152600401602060405180830381865afa1580156114f2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115169190614648565b6040519081526020015b60405180910390a1505050505050505050565b600061153d612061565b8061157b5750600854600160401b900467ffffffffffffffff1661155f6119dc565b67ffffffffffffffff1611801561157b57506115796119e9565b155b1561158d57611588611978565b905090565b6115956119e9565b156115a257611588611032565b6115aa6109ba565b80156115d95750600854600160401b900467ffffffffffffffff166115cd6119dc565b67ffffffffffffffff16145b15611610576040517f36b7884b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b90565b6004818154811061162357600080fd5b6000918252602090912060059091020180546001820154600283015460038401546004909401549294506001600160a01b0382169360ff600160a01b8404811694600160a81b909404169287565b600061167b6119e9565b61169857604051633788c6c160e11b815260040160405180910390fd5b60006116a26119dc565b60085490915067ffffffffffffffff808316600160401b90920416146116db57604051636fbabc7760e01b815260040160405180910390fd5b60085467ffffffffffffffff600160801b90910481169082161161171257604051630c8d9eab60e31b815260040160405180910390fd5b6000806000806000806000806117266133e4565b9050600061173261349e565b600454919650945060005b8181101561190d576004818154811061175857611758614715565b90600052602060002090600502016004015494506004818154811061177f5761177f614715565b906000526020600020906005020160010160149054906101000a900460ff1680156117cd5750600585815481106117b8576117b8614715565b90600052602060002090600502016004015487145b801561180b5750600585815481106117e7576117e7614715565b600091825260209091206001600590920201015460ff878116600160a01b90920416145b15611905576005858154811061182357611823614715565b9060005260206000209060050201600301548b611840919061486d565b9a508383604051602001611855929190614880565b60408051601f19818403018152919052805160209091012098506fffffffffffffffffffffffffffffffff808a16985061189090600161486d565b600586815481106118a3576118a3614715565b9060005260206000209060050201600301546118bf91906146ad565b6118c98c8a6146ad565b10156118f757600585815481106118e2576118e2614715565b90600052602060002090600502016000015499505b8261190181614774565b9350505b60010161173d565b505050959099149998505050505050505050565b6005818154811061193157600080fd5b6000918252602090912060059091020180546001820154600283015460038401546004909401549294506001600160a01b03821693600160a01b90920460ff169290919086565b6000806110486119dc565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff166119d257604051631d77d47760e21b815260040160405180910390fd5b6119da613657565b565b6000611588609843614701565b60006119f760026098614701565b611a026098436146ed565b10611a0d5750600190565b50600090565b611a1b6123a4565b6000611a256119dc565b6003546040516397adedb560e01b81523360048201529192506000916001600160a01b03909116906397adedb590602401602060405180830381865afa158015611a73573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a979190614648565b9050611aa1611f6d565b60ff168560ff161015611ae0576040517f83d9b7bd00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611ae86109ba565b611b1e576040517fd1088db600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60085467ffffffffffffffff838116911614611b66576040517f842a9e0a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60085467ffffffffffffffff838116600160401b9092041614611c4e57611b8b611533565b600655611b9a6005600061425e565b600880547fffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff16600160401b67ffffffffffffffff8516908102919091179091556006546040805192835260208301919091527ff0ae472da9c8da86bda4991a549c03a3cb328b5f360ea11a5b8814f32bb85176910160405180910390a1611c4e600754604080516020810192909252449082015260600160408051601f198184030181529190528051602090910120600755565b6000611c5c82878787611ff2565b90506000611c6a83836136ab565b9050600060048281548110611c8157611c81614715565b600091825260208083206040805160e08101825260059094029091018054845260018101546001600160a01b0381169385019390935260ff600160a01b84048116151592850192909252600160a81b909204166060830181905260028201546080840152600382015460a084015260049091015460c0830152909250611d07908a614694565b9050611d1a82600001516006548361223d565b611d56576006546040517f14ebbbe4000000000000000000000000000000000000000000000000000000008152600401610a7e91815260200190565b816040015115611d92576040517fa89ac15100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600160048481548110611da757611da7614715565b906000526020600020906005020160010160146101000a81548160ff02191690831515021790555060058054905060048481548110611de857611de8614715565b90600052602060002090600502016004018190555060056040518060c001604052808460000151815260200184602001516001600160a01b031681526020018b60ff16815260200184608001518152602001836002611e479190614986565b8560800151611e5691906146ad565b815260209081018b90528254600181810185556000948552938290208351600590920201908155908201519281018054604084015160ff16600160a01b0274ffffffffffffffffffffffffffffffffffffffffff199091166001600160a01b0390951694909417939093179092556060810151600280840191909155608080830151600385015560a0909201516004909301929092558351908401517f13fc17fd71632266fe82092de6dd91a06b4fa68d8dc950492e5421cbed55a6a59289929190611f23908690614986565b8660800151611f3291906146ad565b6040805167ffffffffffffffff90951685526020850193909352918301526060820152608081018a905260ff8b1660a082015260c001611520565b6008546000908190611f929067ffffffffffffffff600160801b820481169116614753565b67ffffffffffffffff169050600060fe8211611fae5781611fb1565b60fe5b611fbc906001614995565b600b5490915060ff600160a01b9091048116908216811115611fe757611fe28282614694565b611fea565b60005b935050505090565b60408051602081018690527fff0000000000000000000000000000000000000000000000000000000000000060f886901b169181019190915260418101839052606181018290526000906081015b6040516020818303038152906040528051906020012090505b949350505050565b600061206f60046098614701565b61207a6098436146ed565b1015611a0d5750600190565b6000828152602081905260409020600101546120a18161227a565b6109b58383612325565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff166120fa57604051637bfa4b9f60e01b815260040160405180910390fd5b600880547fffffffffffff0000ffffffffffffffffffffffffffffffffffffffffffffffff16600160c01b60ff958616027fffffffffffff00ffffffffffffffffffffffffffffffffffffffffffffffffff1617600160c81b93851693909302929092177fffffffffff00ffffffffffffffffffffffffffffffffffffffffffffffffffff16600160d01b9190931602919091179055565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff166121e157604051637bfa4b9f60e01b815260040160405180910390fd5b600955565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff1661223557604051631d77d47760e21b815260040160405180910390fd5b6119da613756565b60008160ff1660000361225257506001612273565b61226160ff83166101006149ae565b61226c9060026149c9565b8484181090505b9392505050565b612284813361378f565b50565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610a91576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556122e13390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1615610a91576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b60015460ff16156119da5760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a20706175736564000000000000000000000000000000006044820152606401610a7e565b60006124016119dc565b905061240b6119e9565b61242857604051633788c6c160e11b815260040160405180910390fd5b60085467ffffffffffffffff828116600160401b909204161461245e57604051636fbabc7760e01b815260040160405180910390fd5b60085467ffffffffffffffff600160801b90910481169082161161249557604051630c8d9eab60e31b815260040160405180910390fd5b600454604051818152600091829182918291829182917f6752c5e71c95fb93bc7137adeb115a33fa4e54e2683e33d3f90c2bb1c4b6c2a59060200160405180910390a16005546040519081527f4c03de6a759749c0c9387b7014634dc5c6af610e1366023d90751c783a998f8d9060200160405180910390a161251661349e565b6040805183815260ff831660208201529295509093507f34e8eda4cd857cd2865becf58a47748f31415f4a382cbb2cc0c64b9a27c717be910160405180910390a160006125616133e4565b905060005b8281101561294e5760006004828154811061258357612583614715565b600091825260208083206040805160e08101825260059485029092018054835260018101546001600160a01b0381169484019490945260ff600160a01b85048116151592840192909252600160a81b90930416606082015260028201546080820152600382015460a082015260049091015460c0820181905282549194509291908390811061261457612614614715565b60009182526020918290206040805160c0810182526005939093029091018054835260018101546001600160a01b03811694840194909452600160a01b90930460ff1682820152600283015460608301526003830154608083015260049092015460a082015290840151909150801561269057508060a0015188145b80156126a55750806040015160ff168760ff16145b1561279a5760808101516126b9908d61486d565b9b50848b6040516020016126ce929190614880565b60408051601f19818403018152919052805160209091012099506fffffffffffffffffffffffffffffffff808b16995061270990600161486d565b816080015161271891906146ad565b6127228d8b6146ad565b101561278c578051600a556020810151600b8054604084015160ff16600160a01b0274ffffffffffffffffffffffffffffffffffffffffff199091166001600160a01b03909316929092179190911790556060810151600c556080810151600d5560a0810151600e555b8a61279681614774565b9b50505b826040015180156127c357508060a00151881415806127c35750806040015160ff168760ff1614155b80156127e45750600854600160d01b900460ff166127e26064446146ed565b105b156128905760035460208201516001600160a01b039091169063d009b2d69061280e8a6002614986565b60085461282790609890600160c01b900460ff166146ad565b61283191906146ad565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401600060405180830381600087803b15801561287757600080fd5b505af115801561288b573d6000803e3d6000fd5b505050505b82604001516129405760035460208401516001600160a01b039091169063d009b2d6906128be8a6002614986565b6008546128d790609890600160c81b900460ff166146ad565b6128e191906146ad565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401600060405180830381600087803b15801561292757600080fd5b505af115801561293b573d6000803e3d6000fd5b505050505b836001019350505050612566565b506002546040517fffb98fe300000000000000000000000000000000000000000000000000000000815261ffff891660048201526000916001600160a01b03169063ffb98fe3906024016020604051808303816000875af11580156129b7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129db91906149e9565b905080612a1a5760405161ffff891681527f20378e5d379eabfa30444ecc5eb2b87d0d77bdbf5a58d80d008673b0ca6421419060200160405180910390a15b50506008805467ffffffffffffffff909916600160801b027fffffffffffffffff0000000000000000ffffffffffffffffffffffffffffffff9099169890981790975550505050505050565b600754600090612a78906080906146ed565b90506000612adb612a8c60a086018661478d565b80806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250505050606086013584612ad360a0890160808a01614a04565b600654613802565b60408051858152602081018390529192507f94e252069a85aa79db21f5bd8ca4e14dd3a3927aa492711017a2c8ddad95af00910160405180910390a1612b63612b24858061478d565b8080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525050505060208601358561040061397a565b600e5414612b8e5760405163755f0a2560e01b81526001600482015260248101829052604401610a7e565b612b9b60a085018561478d565b6000818110612bac57612bac614715565b90506020020135848060400190612bc3919061478d565b6000818110612bd457612bd4614715565b9050602002013514612c035760405163755f0a2560e01b81526002600482015260248101829052604401610a7e565b600080612c1360e087018761478d565b905011612c24578460200135612c59565b612c3160e086018661478d565b6000818110612c4257612c42614715565b9050602002810190612c549190614a1f565b606001355b9050612cb7612c6b604087018761478d565b80806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250505050606087013585612cb260a08a0160808b01614a04565b61397a565b8114612ce05760405163755f0a2560e01b81526003600482015260248101839052604401610a7e565b6000612cef60e087018761478d565b90501115612d275760408051602080880135908201529081018390526060016040516020818303038152906040528051906020012091505b81612d32868061478d565b6000818110612d4357612d43614715565b9050602002013514612d715760405163755f0a2560e01b815260048181015260248101839052604401610a7e565b5050505050565b6001546000908190819061010090046001600160a01b031663c81e25ab612da260c0870187614a1f565b602001356040518263ffffffff1660e01b8152600401612dc491815260200190565b60c060405180830381865afa158015612de1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e059190614a35565b509396509194509250506001600160a01b0384169050612e6557612e2c60c0850185614a1f565b602001356040517f2396d34e000000000000000000000000000000000000000000000000000000008152600401610a7e91815260200190565b6000612e88612e7760c0870187614a1f565b611610906060810190604001614a04565b90506000612e968484613ae8565b9050808263ffffffff1610612eeb57612eb260c0870187614a1f565b602001356040517f1362e4a0000000000000000000000000000000000000000000000000000000008152600401610a7e91815260200190565b6000612f1a612efd60c0890189614a1f565b612f0e906060810190604001614a04565b60201c63ffffffff1690565b90506000612f2c886020013586613b03565b63ffffffff16905067ffffffffffffffff82168114612f8b57612f5260c0890189614a1f565b602001356040517f6dd6a24f000000000000000000000000000000000000000000000000000000008152600401610a7e91815260200190565b61303187612f9c60c08b018b614a1f565b612fa69080614aa3565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050505060208b0135612fec60c08d018d614a1f565b60200135612ffd60c08e018e614a1f565b61300e906060810190604001614a04565b61301b60c08f018f614a1f565b61302c906080810190606001614a04565b613b2a565b61307b5761304260c0890189614a1f565b602001356040517fdb12fb9d000000000000000000000000000000000000000000000000000000008152600401610a7e91815260200190565b5050505050505050565b61309260e082018261478d565b905060000361309e5750565b6131bf6130ae60e083018361478d565b60008181106130bf576130bf614715565b90506020028101906130d19190614a1f565b6130df906020810190614aea565b6130ec60e084018461478d565b60008181106130fd576130fd614715565b905060200281019061310f9190614a1f565b61311d906020810190614aa3565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061315f9250505060e085018561478d565b600081811061317057613170614715565b90506020028101906131829190614a1f565b6040013561319360e086018661478d565b60008181106131a4576131a4614715565b90506020028101906131b69190614a1f565b60600135613bc1565b61322c576131d060e082018261478d565b60008181106131e1576131e1614715565b90506020028101906131f39190614a1f565b606001356040517fd740df61000000000000000000000000000000000000000000000000000000008152600401610a7e91815260200190565b60208101356132ab61324160e084018461478d565b600081811061325257613252614715565b90506020028101906132649190614a1f565b6040013561327560e085018561478d565b600081811061328657613286614715565b90506020028101906132989190614a1f565b6132a6906020810190614aea565b613c54565b14612284576132bd60e082018261478d565b60008181106132ce576132ce614715565b90506020028101906132e09190614a1f565b606001356040517f82f2469d000000000000000000000000000000000000000000000000000000008152600401610a7e91815260200190565b838510156133665781831061334157604051633d386eb360e11b815260040160405180910390fd5b80821061336157604051633588c6d360e11b815260040160405180910390fd5b612d71565b82821061338657604051633d386eb360e11b815260040160405180910390fd5b808310612d7157604051633588c6d360e11b815260040160405180910390fd5b6009548110612284576040517fb6052cdf00000000000000000000000000000000000000000000000000000000815260048101829052602401610a7e565b60606133ee6119e9565b61340b57604051633788c6c160e11b815260040160405180910390fd5b60006134156119dc565b60085490915067ffffffffffffffff808316600160401b909204161461344e57604051636fbabc7760e01b815260040160405180910390fd5b6007546040516020016134899181527f3100000000000000000000000000000000000000000000000000000000000000602082015260210190565b60405160208183030381529060405291505090565b60008060008060008060008060006134b4613ca2565b60045490915060005b8181101561364657600481815481106134d8576134d8614715565b906000526020600020906005020160010160149054906101000a900460ff161561363e576004818154811061350f5761350f614715565b90600052602060002090600502016004015493506005848154811061353657613536614715565b90600052602060002090600502016003015489613553919061486d565b98508281604051602001613568929190614880565b60408051601f19818403018152919052805160209091012097506fffffffffffffffffffffffffffffffff80891697506135a390600161486d565b600585815481106135b6576135b6614715565b9060005260206000209060050201600301546135d291906146ad565b6135dc8a896146ad565b101561363e57600584815481106135f5576135f5614715565b90600052602060002090600502016004015495506005848154811061361c5761361c614715565b906000526020600020906005020160010160149054906101000a900460ff1694505b6001016134bd565b509399929850919650505050505050565b61365f6123a4565b6001805460ff1916811790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258335b6040516001600160a01b03909116815260200160405180910390a1565b6000805b6004548110156137235783600482815481106136cd576136cd614715565b90600052602060002090600502016000015414801561370f5750600481815481106136fa576136fa614715565b90600052602060002090600502016003015483145b1561371b579050610670565b6001016136af565b506040517fd950091500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61375e613d2b565b6001805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa3361368e565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610a91576137c081613d7d565b6137cb836020613d8f565b6040516020016137dc929190614b07565b60408051601f198184030181529082905262461bcd60e51b8252610a7e91600401614b88565b60008061381187878786613f54565b905082613916856000808267ffffffffffffffff1690506008817eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff16901b600882901c7eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff161790506010817dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff16901b601082901c7dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff161790506020817bffffffff00000000ffffffff00000000ffffffff00000000ffffffff16901b602082901c7bffffffff00000000ffffffff00000000ffffffff00000000ffffffff1617905080915050919050565b826040516020016139589392919092835260c09190911b77ffffffffffffffffffffffffffffffffffffffffffffffff19166020830152602882015260480190565b6040516020818303038152906040528051906020012091505095945050505050565b600080613988868686613fca565b9050613a8c836000808267ffffffffffffffff1690506008817eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff16901b600882901c7eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff161790506010817dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff16901b601082901c7dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff161790506020817bffffffff00000000ffffffff00000000ffffffff00000000ffffffff16901b602082901c7bffffffff00000000ffffffff00000000ffffffff00000000ffffffff1617905080915050919050565b81604051602001613ac792919060c09290921b77ffffffffffffffffffffffffffffffffffffffffffffffff19168252600882015260280190565b60405160208183030381529060405280519060200120915050949350505050565b6000613af48284614694565b60ff166001901b905092915050565b600060e083901c613b15836020614694565b60ff168163ffffffff16901c91505092915050565b600080613b3986868686614032565b90506000613b94826040517f19457468657265756d205369676e6564204d6573736167653a0a3332000000006020820152603c8101829052600090605c01604051602081830303815290604052805190602001209050919050565b9050886001600160a01b0316613baa828a61407d565b6001600160a01b0316149998505050505050505050565b600080613bce84846140fc565b90506000613c29826040517f19457468657265756d205369676e6564204d6573736167653a0a3332000000006020820152603c8101829052600090605c01604051602081830303815290604052805190602001209050919050565b9050866001600160a01b0316613c3f828861407d565b6001600160a01b031614979650505050505050565b60008282604051602001613c8492919091825260601b6bffffffffffffffffffffffff1916602082015260340190565b60405160208183030381529060405280519060200120905092915050565b6060613cac6119e9565b613cc957604051633788c6c160e11b815260040160405180910390fd5b6000613cd36119dc565b60085490915067ffffffffffffffff808316600160401b9092041614613d0c57604051636fbabc7760e01b815260040160405180910390fd5b600754604051602001613489918152600360fc1b602082015260210190565b60015460ff166119da5760405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f74207061757365640000000000000000000000006044820152606401610a7e565b60606106706001600160a01b03831660145b60606000613d9e8360026146ad565b613da990600261486d565b67ffffffffffffffff811115613dc157613dc1614bbb565b6040519080825280601f01601f191660200182016040528015613deb576020820181803683370190505b509050600360fc1b81600081518110613e0657613e06614715565b60200101906001600160f81b031916908160001a9053507f780000000000000000000000000000000000000000000000000000000000000081600181518110613e5157613e51614715565b60200101906001600160f81b031916908160001a9053506000613e758460026146ad565b613e8090600161486d565b90505b6001811115613f05577f303132333435363738396162636465660000000000000000000000000000000085600f1660108110613ec157613ec1614715565b1a60f81b828281518110613ed757613ed7614715565b60200101906001600160f81b031916908160001a90535060049490941c93613efe81614bd1565b9050613e83565b5083156122735760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610a7e565b8260005b8551811015613fc1576000613f6e6002866146ed565b15613f7a576000613f7d565b60015b9050613fa483888481518110613f9557613f95614715565b60200260200101518387614118565b9250600185901c9450508080613fb990614774565b915050613f58565b50949350505050565b8160005b845181101561402a576000613fe46002856146ed565b600014905061400d83878481518110613fff57613fff614715565b602002602001015183614178565b9250600184901c935050808061402290614774565b915050613fce565b509392505050565b604080516020810186905290810184905277ffffffffffffffffffffffffffffffffffffffffffffffff1960c084811b8216606084015283901b166068820152600090607001612040565b60008060008061408c856141df565b6040805160008152602081018083528b905260ff8316918101919091526060810184905260808101839052929550909350915060019060a0016020604051602081039080840390855afa1580156140e7573d6000803e3d6000fd5b5050604051601f190151979650505050505050565b6040805160208101849052908101829052600090606001613c84565b6000821561415857604080516020810184905290810186905260608101859052608001604051602081830303815290604052805190602001209050612059565b604080516020810184905290810185905260608101869052608001612040565b600081156141b1576040805160208101869052908101849052606001604051602081830303815290604052805190602001209050612273565b5050604080516020808201939093528082019390935280518084038201815260609093019052815191012090565b6000806000835160411461421f576040517f4be6321b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50505060208101516040820151606090920151909260009190911a90565b5080546000825560050290600052602060002090810190612284919061427f565b508054600082556005029060005260206000209081019061228491906142d6565b5b808211156142d25760008082556001820180547fffffffffffffffffffff0000000000000000000000000000000000000000000016905560028201819055600382018190556004820155600501614280565b5090565b5b808211156142d257600080825560018201805474ffffffffffffffffffffffffffffffffffffffffff19169055600282018190556003820181905560048201556005016142d7565b60006020828403121561433157600080fd5b81356001600160e01b03198116811461227357600080fd5b6001600160a01b038116811461228457600080fd5b60ff8116811461228457600080fd5b6000806040838503121561438057600080fd5b823561438b81614349565b9150602083013561439b8161435e565b809150509250929050565b6000602082840312156143b857600080fd5b5035919050565b6020808252825182820181905260009190848201906040850190845b818110156144425761442f838551805182526001600160a01b03602082015116602083015260ff6040820151166040830152606081015160608301526080810151608083015260a081015160a08301525050565b9284019260c092909201916001016143db565b50909695505050505050565b6000806040838503121561446157600080fd5b82359150602083013561439b81614349565b803567ffffffffffffffff8116811461448b57600080fd5b919050565b600080604083850312156144a357600080fd5b823591506144b360208401614473565b90509250929050565b600061010082840312156144cf57600080fd5b50919050565b6000806000606084860312156144ea57600080fd5b833567ffffffffffffffff8082111561450257600080fd5b61450e878388016144bc565b9450602086013591508082111561452457600080fd5b614530878388016144bc565b9350604086013591508082111561454657600080fd5b50614553868287016144bc565b9150509250925092565b60008060006060848603121561457257600080fd5b833561457d8161435e565b95602085013595506040909401359392505050565b600080600080608085870312156145a857600080fd5b8435935060208501356145ba8161435e565b93969395505050506040820135916060013590565b6000806000606084860312156145e457600080fd5b83356145ef8161435e565b925060208401356145ff8161435e565b9150604084013561460f8161435e565b809150509250925092565b60008060006060848603121561462f57600080fd5b8335925060208401359150604084013561460f8161435e565b60006020828403121561465a57600080fd5b5051919050565b60006020828403121561467357600080fd5b81516122738161435e565b634e487b7160e01b600052601160045260246000fd5b60ff82811682821603908111156106705761067061467e565b80820281158282048414176106705761067061467e565b818103818111156106705761067061467e565b634e487b7160e01b600052601260045260246000fd5b6000826146fc576146fc6146d7565b500690565b600082614710576147106146d7565b500490565b634e487b7160e01b600052603260045260246000fd5b67ffffffffffffffff81811683821601908082111561474c5761474c61467e565b5092915050565b67ffffffffffffffff82811682821603908082111561474c5761474c61467e565b6000600182016147865761478661467e565b5060010190565b6000808335601e198436030181126147a457600080fd5b83018035915067ffffffffffffffff8211156147bf57600080fd5b6020019150600581901b36038213156147d757600080fd5b9250929050565b60005b838110156147f95781810151838201526020016147e1565b50506000910152565b600082516148148184602087016147de565b9190910192915050565b60c081016106708284805182526001600160a01b03602082015116602083015260ff6040820151166040830152606081015160608301526080810151608083015260a081015160a08301525050565b808201808211156106705761067061467e565b600083516148928184602088016147de565b9190910191825250602001919050565b600181815b808511156148dd5781600019048211156148c3576148c361467e565b808516156148d057918102915b93841c93908002906148a7565b509250929050565b6000826148f457506001610670565b8161490157506000610670565b816001811461491757600281146149215761493d565b6001915050610670565b60ff8411156149325761493261467e565b50506001821b610670565b5060208310610133831016604e8410600b8410161715614960575081810a610670565b61496a83836148a2565b806000190482111561497e5761497e61467e565b029392505050565b600061227360ff8416836148e5565b60ff81811683821601908111156106705761067061467e565b61ffff82811682821603908082111561474c5761474c61467e565b600061227361ffff8416836148e5565b8051801515811461448b57600080fd5b6000602082840312156149fb57600080fd5b612273826149d9565b600060208284031215614a1657600080fd5b61227382614473565b60008235607e1983360301811261481457600080fd5b60008060008060008060c08789031215614a4e57600080fd5b8651614a5981614349565b6020880151909650614a6a8161435e565b6040880151909550614a7b8161435e565b9350614a89606088016149d9565b92506080870151915060a087015190509295509295509295565b6000808335601e19843603018112614aba57600080fd5b83018035915067ffffffffffffffff821115614ad557600080fd5b6020019150368190038213156147d757600080fd5b600060208284031215614afc57600080fd5b813561227381614349565b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000815260008351614b3f8160178501602088016147de565b7f206973206d697373696e6720726f6c65200000000000000000000000000000006017918401918201528351614b7c8160288401602088016147de565b01602801949350505050565b6020815260008251806020840152614ba78160408501602087016147de565b601f01601f19169190910160400192915050565b634e487b7160e01b600052604160045260246000fd5b600081614be057614be061467e565b50600019019056fea2646970667358221220e6d529c753301d40b88db1b0768955eec9895788418077bb895e8f7739fb1b6964736f6c63430008130033", + "deployedBytecode": "0x608060405234801561001057600080fd5b50600436106102775760003560e01c806377c75d1011610160578063b6cd5822116100d8578063dfbf53ae1161008c578063f69ee1d111610071578063f69ee1d1146105df578063f7b188a5146105f2578063fb00f2f3146105fa57600080fd5b8063dfbf53ae1461059c578063f4e6fcca146105cc57600080fd5b8063ce987745116100bd578063ce9877451461056e578063d1e8b63d14610581578063d547741f1461058957600080fd5b8063b6cd582214610541578063c46b40291461055457600080fd5b80638456cb591161012f5780638d8b6428116101145780638d8b6428146104fa57806391d1485414610502578063a217fddf1461053957600080fd5b80638456cb59146104ea5780638a19c8bc146104f257600080fd5b806377c75d10146104645780637fe019c61461047757806382b39b1b1461049257806383220626146104e257600080fd5b80635c975abb116101f357806364c34a85116101c257806369da9114116101a757806369da9114146103de5780636f94aaf2146103f157806372286cba1461040c57600080fd5b806364c34a85146103a957806369bfac01146103b157600080fd5b80635c975abb146103705780635d4844ea1461037b57806362fd29ae1461038e57806363f5cf7c1461039657600080fd5b80632a4e62491161024a5780632f3906da1161022f5780632f3906da1461034257806336568abe1461034a5780635838d6731461035d57600080fd5b80632a4e6249146103185780632f2ff15d1461032d57600080fd5b806301ffc9a71461027c5780631736d472146102a457806318350096146102b7578063248a9ca3146102e7575b600080fd5b61028f61028a36600461431f565b61060d565b60405190151581526020015b60405180910390f35b61028f6102b236600461436d565b610676565b6001546102cf9061010090046001600160a01b031681565b6040516001600160a01b03909116815260200161029b565b61030a6102f53660046143a6565b60009081526020819052604090206001015490565b60405190815260200161029b565b610320610883565b60405161029b91906143bf565b61034061033b36600461444e565b610990565b005b61028f6109ba565b61034061035836600461444e565b610a04565b61034061036b366004614490565b610a95565b60015460ff1661028f565b6003546102cf906001600160a01b031681565b61030a611032565b6103406103a43660046144d5565b6110fe565b61030a611533565b6008546103c59067ffffffffffffffff1681565b60405167ffffffffffffffff909116815260200161029b565b6002546102cf906001600160a01b031681565b6008546103c590600160801b900467ffffffffffffffff1681565b61041f61041a3660046143a6565b611613565b604080519788526001600160a01b0390961660208801529315159486019490945260ff9091166060850152608084015260a083019190915260c082015260e00161029b565b61028f6104723660046143a6565b611671565b6008546103c590600160401b900467ffffffffffffffff1681565b6104a56104a03660046143a6565b611921565b604080519687526001600160a01b03909516602087015260ff909316938501939093526060840152608083019190915260a082015260c00161029b565b61030a611978565b610340611983565b6103c56119dc565b61028f6119e9565b61028f61051036600461444e565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b61030a600081565b61034061054f36600461455d565b611a13565b61055c611f6d565b60405160ff909116815260200161029b565b61030a61057c366004614592565b611ff2565b61028f612061565b61034061059736600461444e565b612086565b600a54600b54600c54600d54600e546104a594936001600160a01b03811693600160a01b90910460ff1692909186565b6103406105da3660046145cf565b6120ab565b6103406105ed3660046143a6565b612192565b6103406121e6565b61028f61060836600461461a565b61223d565b60006001600160e01b031982167f7965db0b00000000000000000000000000000000000000000000000000000000148061067057507f01ffc9a7000000000000000000000000000000000000000000000000000000006001600160e01b03198316145b92915050565b60035460405163d1052d1f60e01b81526001600160a01b038481166004830152600092839291169063d1052d1f90602401602060405180830381865afa1580156106c4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106e89190614648565b600354604051631d54805360e01b81526001600160a01b03878116600483015292935060009290911690631d54805390602401602060405180830381865afa158015610738573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061075c9190614661565b6107669085614694565b90506107706109ba565b156107a7576040517fe2586bcc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b816000036107c7576040516273e5c360e31b815260040160405180910390fd5b6107d3609860026146ad565b6107dd90436146c4565b82106107fc57604051630a0744c560e01b815260040160405180910390fd5b6003546040516397adedb560e01b81526001600160a01b03878116600483015261087a9216906397adedb590602401602060405180830381865afa158015610848573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061086c9190614648565b610874611533565b8361223d565b95945050505050565b606061088d6119e9565b6108aa57604051633788c6c160e11b815260040160405180910390fd5b60006108b46119dc565b60085490915067ffffffffffffffff808316600160401b90920416146108ed57604051636fbabc7760e01b815260040160405180910390fd5b6005805480602002602001604051908101604052809291908181526020016000905b828210156109865760008481526020908190206040805160c08101825260058602909201805483526001808201546001600160a01b03811685870152600160a01b900460ff169284019290925260028101546060840152600381015460808401526004015460a0830152908352909201910161090f565b5050505091505090565b6000828152602081905260409020600101546109ab8161227a565b6109b58383612287565b505050565b6000806109c86098436146ed565b90506109d660046098614701565b81101580156109ef57506109ec60026098614701565b81105b156109fc57600191505090565b600091505090565b6001600160a01b0381163314610a875760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b610a918282612325565b5050565b610a9d6123a4565b6000610aa76119dc565b6003546040516397adedb560e01b81523360048201529192506000916001600160a01b03909116906397adedb590602401602060405180830381865afa158015610af5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b199190614648565b6003546040517f830a053e0000000000000000000000000000000000000000000000000000000081523360048201529192506000916001600160a01b039091169063830a053e90602401602060405180830381865afa158015610b80573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ba49190614648565b60035460405163d1052d1f60e01b81523360048201529192506000916001600160a01b039091169063d1052d1f90602401602060405180830381865afa158015610bf2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c169190614648565b600354604051631d54805360e01b81523360048201529192506000916001600160a01b0390911690631d54805390602401602060405180830381865afa158015610c64573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c889190614661565b9050610c92612061565b610cc8576040517fdc816a8700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001610cd660046098614701565b610ce091906146c4565b610ceb6098436146ed565b03610d22576040517f5baef6b600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8567ffffffffffffffff168567ffffffffffffffff161115610d70576040517f50ff7c0000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8567ffffffffffffffff168567ffffffffffffffff161015610dbe576040517f7a0c0fd600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b81600003610dde576040516273e5c360e31b815260040160405180910390fd5b610dea609860026146ad565b610df490436146c4565b8210610e1357604051630a0744c560e01b815260040160405180910390fd5b60085467ffffffffffffffff868116911614610e5357610e356004600061423d565b6008805467ffffffffffffffff191667ffffffffffffffff87161790555b60045460005b81811015610ec6578560048281548110610e7557610e75614715565b90600052602060002090600502016000015403610ebe576040517fbfec555800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600101610e59565b5060046040518060e00160405280878152602001336001600160a01b031681526020016000151581526020018460ff1681526020018681526020018a8152602001600081525090806001815401808255809150506001900390600052602060002090600502016000909190919091506000820151816000015560208201518160010160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555060408201518160010160146101000a81548160ff02191690831515021790555060608201518160010160156101000a81548160ff021916908360ff1602179055506080820151816002015560a0820151816003015560c0820151816004015550507faadc88121471799d39ee2bbe1dd30a4ab57510e2a33bd6e537de5fafd2daa8868786846040516110209392919067ffffffffffffffff939093168352602083019190915260ff16604082015260600190565b60405180910390a15050505050505050565b60008061103d6119dc565b61104890600161472b565b6007546008549192509061106e90600160401b900467ffffffffffffffff16600161472b565b67ffffffffffffffff168267ffffffffffffffff161115610670576008546000906001906110ad90600160401b900467ffffffffffffffff1685614753565b6110b79190614753565b67ffffffffffffffff16905081816040516020016110df929190918252602082015260400190565b6040516020818303038152906040528051906020012091505092915050565b6111066123a4565b61110e6123f7565b6040805160c081018252600a548152600b546001600160a01b0381166020830152600160a01b900460ff1691810191909152600c546060820152600d546080820152600e5460a0820152600654600754600091829161116e600f826146ed565b935061117b600e826146ed565b9250838310611192578261118e81614774565b9350505b6111a5866020013583876040015161223d565b6111c557604051633b5f43a360e01b815260036004820152602401610a7e565b6111d086601e612a66565b6111d986612d78565b6111e286613085565b6111f5886020013583876040015161223d565b61121557604051633b5f43a360e01b815260026004820152602401610a7e565b611229886112248660026146ad565b612a66565b61123288612d78565b61123b88613085565b61124e876020013583876040015161223d565b61126e57604051633b5f43a360e01b815260016004820152602401610a7e565b61127d876112248560026146ad565b61128687612d78565b61128f87613085565b611305848461129e8b8061478d565b60008181106112af576112af614715565b602002919091013590506112c38b8061478d565b60008181106112d4576112d4614715565b602002919091013590506112e88b8061478d565b60008181106112f9576112f9614715565b90506020020135613319565b61132f611312878061478d565b600081811061132357611323614715565b905060200201356133a6565b60015460208601516040516001600160a01b03918216602482015260009261010090049091169060440160408051601f198184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f51cff8d900000000000000000000000000000000000000000000000000000000179052516113bc9190614802565b6000604051808303816000865af19150503d80600081146113f9576040519150601f19603f3d011682016040523d82523d6000602084013e6113fe565b606091505b5050905080611449576020808701516040516001600160a01b0390911681527f7ae187a0c04cf55b655ca83fa11d37854c882bf1fdcb588469b414731bb0e05a910160405180910390a15b7f788e77979e6e6a8a6a5d2c19c58b1ff9671298f54c85ac6f6aa30379aed5861a86604051611478919061481e565b60405180910390a17fbee3fc8a3523c1a65fa9308ce1f2b8fd90c24975b141b754603194597846e4dd60018054906101000a90046001600160a01b03166001600160a01b0316638a5e8e326040518163ffffffff1660e01b8152600401602060405180830381865afa1580156114f2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115169190614648565b6040519081526020015b60405180910390a1505050505050505050565b600061153d612061565b8061157b5750600854600160401b900467ffffffffffffffff1661155f6119dc565b67ffffffffffffffff1611801561157b57506115796119e9565b155b1561158d57611588611978565b905090565b6115956119e9565b156115a257611588611032565b6115aa6109ba565b80156115d95750600854600160401b900467ffffffffffffffff166115cd6119dc565b67ffffffffffffffff16145b15611610576040517f36b7884b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b90565b6004818154811061162357600080fd5b6000918252602090912060059091020180546001820154600283015460038401546004909401549294506001600160a01b0382169360ff600160a01b8404811694600160a81b909404169287565b600061167b6119e9565b61169857604051633788c6c160e11b815260040160405180910390fd5b60006116a26119dc565b60085490915067ffffffffffffffff808316600160401b90920416146116db57604051636fbabc7760e01b815260040160405180910390fd5b60085467ffffffffffffffff600160801b90910481169082161161171257604051630c8d9eab60e31b815260040160405180910390fd5b6000806000806000806000806117266133e4565b9050600061173261349e565b600454919650945060005b8181101561190d576004818154811061175857611758614715565b90600052602060002090600502016004015494506004818154811061177f5761177f614715565b906000526020600020906005020160010160149054906101000a900460ff1680156117cd5750600585815481106117b8576117b8614715565b90600052602060002090600502016004015487145b801561180b5750600585815481106117e7576117e7614715565b600091825260209091206001600590920201015460ff878116600160a01b90920416145b15611905576005858154811061182357611823614715565b9060005260206000209060050201600301548b611840919061486d565b9a508383604051602001611855929190614880565b60408051601f19818403018152919052805160209091012098506fffffffffffffffffffffffffffffffff808a16985061189090600161486d565b600586815481106118a3576118a3614715565b9060005260206000209060050201600301546118bf91906146ad565b6118c98c8a6146ad565b10156118f757600585815481106118e2576118e2614715565b90600052602060002090600502016000015499505b8261190181614774565b9350505b60010161173d565b505050959099149998505050505050505050565b6005818154811061193157600080fd5b6000918252602090912060059091020180546001820154600283015460038401546004909401549294506001600160a01b03821693600160a01b90920460ff169290919086565b6000806110486119dc565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff166119d257604051631d77d47760e21b815260040160405180910390fd5b6119da613657565b565b6000611588609843614701565b60006119f760026098614701565b611a026098436146ed565b10611a0d5750600190565b50600090565b611a1b6123a4565b6000611a256119dc565b6003546040516397adedb560e01b81523360048201529192506000916001600160a01b03909116906397adedb590602401602060405180830381865afa158015611a73573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a979190614648565b9050611aa1611f6d565b60ff168560ff161015611ae0576040517f83d9b7bd00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611ae86109ba565b611b1e576040517fd1088db600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60085467ffffffffffffffff838116911614611b66576040517f842a9e0a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60085467ffffffffffffffff838116600160401b9092041614611c4e57611b8b611533565b600655611b9a6005600061425e565b600880547fffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff16600160401b67ffffffffffffffff8516908102919091179091556006546040805192835260208301919091527ff0ae472da9c8da86bda4991a549c03a3cb328b5f360ea11a5b8814f32bb85176910160405180910390a1611c4e600754604080516020810192909252449082015260600160408051601f198184030181529190528051602090910120600755565b6000611c5c82878787611ff2565b90506000611c6a83836136ab565b9050600060048281548110611c8157611c81614715565b600091825260208083206040805160e08101825260059094029091018054845260018101546001600160a01b0381169385019390935260ff600160a01b84048116151592850192909252600160a81b909204166060830181905260028201546080840152600382015460a084015260049091015460c0830152909250611d07908a614694565b9050611d1a82600001516006548361223d565b611d56576006546040517f14ebbbe4000000000000000000000000000000000000000000000000000000008152600401610a7e91815260200190565b816040015115611d92576040517fa89ac15100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600160048481548110611da757611da7614715565b906000526020600020906005020160010160146101000a81548160ff02191690831515021790555060058054905060048481548110611de857611de8614715565b90600052602060002090600502016004018190555060056040518060c001604052808460000151815260200184602001516001600160a01b031681526020018b60ff16815260200184608001518152602001836002611e479190614986565b8560800151611e5691906146ad565b815260209081018b90528254600181810185556000948552938290208351600590920201908155908201519281018054604084015160ff16600160a01b0274ffffffffffffffffffffffffffffffffffffffffff199091166001600160a01b0390951694909417939093179092556060810151600280840191909155608080830151600385015560a0909201516004909301929092558351908401517f13fc17fd71632266fe82092de6dd91a06b4fa68d8dc950492e5421cbed55a6a59289929190611f23908690614986565b8660800151611f3291906146ad565b6040805167ffffffffffffffff90951685526020850193909352918301526060820152608081018a905260ff8b1660a082015260c001611520565b6008546000908190611f929067ffffffffffffffff600160801b820481169116614753565b67ffffffffffffffff169050600060fe8211611fae5781611fb1565b60fe5b611fbc906001614995565b600b5490915060ff600160a01b9091048116908216811115611fe757611fe28282614694565b611fea565b60005b935050505090565b60408051602081018690527fff0000000000000000000000000000000000000000000000000000000000000060f886901b169181019190915260418101839052606181018290526000906081015b6040516020818303038152906040528051906020012090505b949350505050565b600061206f60046098614701565b61207a6098436146ed565b1015611a0d5750600190565b6000828152602081905260409020600101546120a18161227a565b6109b58383612325565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff166120fa57604051637bfa4b9f60e01b815260040160405180910390fd5b600880547fffffffffffff0000ffffffffffffffffffffffffffffffffffffffffffffffff16600160c01b60ff958616027fffffffffffff00ffffffffffffffffffffffffffffffffffffffffffffffffff1617600160c81b93851693909302929092177fffffffffff00ffffffffffffffffffffffffffffffffffffffffffffffffffff16600160d01b9190931602919091179055565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff166121e157604051637bfa4b9f60e01b815260040160405180910390fd5b600955565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff1661223557604051631d77d47760e21b815260040160405180910390fd5b6119da613756565b60008160ff1660000361225257506001612273565b61226160ff83166101006149ae565b61226c9060026149c9565b8484181090505b9392505050565b612284813361378f565b50565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610a91576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556122e13390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1615610a91576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b60015460ff16156119da5760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a20706175736564000000000000000000000000000000006044820152606401610a7e565b60006124016119dc565b905061240b6119e9565b61242857604051633788c6c160e11b815260040160405180910390fd5b60085467ffffffffffffffff828116600160401b909204161461245e57604051636fbabc7760e01b815260040160405180910390fd5b60085467ffffffffffffffff600160801b90910481169082161161249557604051630c8d9eab60e31b815260040160405180910390fd5b600454604051818152600091829182918291829182917f6752c5e71c95fb93bc7137adeb115a33fa4e54e2683e33d3f90c2bb1c4b6c2a59060200160405180910390a16005546040519081527f4c03de6a759749c0c9387b7014634dc5c6af610e1366023d90751c783a998f8d9060200160405180910390a161251661349e565b6040805183815260ff831660208201529295509093507f34e8eda4cd857cd2865becf58a47748f31415f4a382cbb2cc0c64b9a27c717be910160405180910390a160006125616133e4565b905060005b8281101561294e5760006004828154811061258357612583614715565b600091825260208083206040805160e08101825260059485029092018054835260018101546001600160a01b0381169484019490945260ff600160a01b85048116151592840192909252600160a81b90930416606082015260028201546080820152600382015460a082015260049091015460c0820181905282549194509291908390811061261457612614614715565b60009182526020918290206040805160c0810182526005939093029091018054835260018101546001600160a01b03811694840194909452600160a01b90930460ff1682820152600283015460608301526003830154608083015260049092015460a082015290840151909150801561269057508060a0015188145b80156126a55750806040015160ff168760ff16145b1561279a5760808101516126b9908d61486d565b9b50848b6040516020016126ce929190614880565b60408051601f19818403018152919052805160209091012099506fffffffffffffffffffffffffffffffff808b16995061270990600161486d565b816080015161271891906146ad565b6127228d8b6146ad565b101561278c578051600a556020810151600b8054604084015160ff16600160a01b0274ffffffffffffffffffffffffffffffffffffffffff199091166001600160a01b03909316929092179190911790556060810151600c556080810151600d5560a0810151600e555b8a61279681614774565b9b50505b826040015180156127c357508060a00151881415806127c35750806040015160ff168760ff1614155b80156127e45750600854600160d01b900460ff166127e26064446146ed565b105b156128905760035460208201516001600160a01b039091169063d009b2d69061280e8a6002614986565b60085461282790609890600160c01b900460ff166146ad565b61283191906146ad565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401600060405180830381600087803b15801561287757600080fd5b505af115801561288b573d6000803e3d6000fd5b505050505b82604001516129405760035460208401516001600160a01b039091169063d009b2d6906128be8a6002614986565b6008546128d790609890600160c81b900460ff166146ad565b6128e191906146ad565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401600060405180830381600087803b15801561292757600080fd5b505af115801561293b573d6000803e3d6000fd5b505050505b836001019350505050612566565b506002546040517fffb98fe300000000000000000000000000000000000000000000000000000000815261ffff891660048201526000916001600160a01b03169063ffb98fe3906024016020604051808303816000875af11580156129b7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129db91906149e9565b905080612a1a5760405161ffff891681527f20378e5d379eabfa30444ecc5eb2b87d0d77bdbf5a58d80d008673b0ca6421419060200160405180910390a15b50506008805467ffffffffffffffff909916600160801b027fffffffffffffffff0000000000000000ffffffffffffffffffffffffffffffff9099169890981790975550505050505050565b600754600090612a78906080906146ed565b90506000612adb612a8c60a086018661478d565b80806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250505050606086013584612ad360a0890160808a01614a04565b600654613802565b60408051858152602081018390529192507f94e252069a85aa79db21f5bd8ca4e14dd3a3927aa492711017a2c8ddad95af00910160405180910390a1612b63612b24858061478d565b8080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525050505060208601358561040061397a565b600e5414612b8e5760405163755f0a2560e01b81526001600482015260248101829052604401610a7e565b612b9b60a085018561478d565b6000818110612bac57612bac614715565b90506020020135848060400190612bc3919061478d565b6000818110612bd457612bd4614715565b9050602002013514612c035760405163755f0a2560e01b81526002600482015260248101829052604401610a7e565b600080612c1360e087018761478d565b905011612c24578460200135612c59565b612c3160e086018661478d565b6000818110612c4257612c42614715565b9050602002810190612c549190614a1f565b606001355b9050612cb7612c6b604087018761478d565b80806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250505050606087013585612cb260a08a0160808b01614a04565b61397a565b8114612ce05760405163755f0a2560e01b81526003600482015260248101839052604401610a7e565b6000612cef60e087018761478d565b90501115612d275760408051602080880135908201529081018390526060016040516020818303038152906040528051906020012091505b81612d32868061478d565b6000818110612d4357612d43614715565b9050602002013514612d715760405163755f0a2560e01b815260048181015260248101839052604401610a7e565b5050505050565b6001546000908190819061010090046001600160a01b031663c81e25ab612da260c0870187614a1f565b602001356040518263ffffffff1660e01b8152600401612dc491815260200190565b60c060405180830381865afa158015612de1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e059190614a35565b509396509194509250506001600160a01b0384169050612e6557612e2c60c0850185614a1f565b602001356040517f2396d34e000000000000000000000000000000000000000000000000000000008152600401610a7e91815260200190565b6000612e88612e7760c0870187614a1f565b611610906060810190604001614a04565b90506000612e968484613ae8565b9050808263ffffffff1610612eeb57612eb260c0870187614a1f565b602001356040517f1362e4a0000000000000000000000000000000000000000000000000000000008152600401610a7e91815260200190565b6000612f1a612efd60c0890189614a1f565b612f0e906060810190604001614a04565b60201c63ffffffff1690565b90506000612f2c886020013586613b03565b63ffffffff16905067ffffffffffffffff82168114612f8b57612f5260c0890189614a1f565b602001356040517f6dd6a24f000000000000000000000000000000000000000000000000000000008152600401610a7e91815260200190565b61303187612f9c60c08b018b614a1f565b612fa69080614aa3565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050505060208b0135612fec60c08d018d614a1f565b60200135612ffd60c08e018e614a1f565b61300e906060810190604001614a04565b61301b60c08f018f614a1f565b61302c906080810190606001614a04565b613b2a565b61307b5761304260c0890189614a1f565b602001356040517fdb12fb9d000000000000000000000000000000000000000000000000000000008152600401610a7e91815260200190565b5050505050505050565b61309260e082018261478d565b905060000361309e5750565b6131bf6130ae60e083018361478d565b60008181106130bf576130bf614715565b90506020028101906130d19190614a1f565b6130df906020810190614aea565b6130ec60e084018461478d565b60008181106130fd576130fd614715565b905060200281019061310f9190614a1f565b61311d906020810190614aa3565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061315f9250505060e085018561478d565b600081811061317057613170614715565b90506020028101906131829190614a1f565b6040013561319360e086018661478d565b60008181106131a4576131a4614715565b90506020028101906131b69190614a1f565b60600135613bc1565b61322c576131d060e082018261478d565b60008181106131e1576131e1614715565b90506020028101906131f39190614a1f565b606001356040517fd740df61000000000000000000000000000000000000000000000000000000008152600401610a7e91815260200190565b60208101356132ab61324160e084018461478d565b600081811061325257613252614715565b90506020028101906132649190614a1f565b6040013561327560e085018561478d565b600081811061328657613286614715565b90506020028101906132989190614a1f565b6132a6906020810190614aea565b613c54565b14612284576132bd60e082018261478d565b60008181106132ce576132ce614715565b90506020028101906132e09190614a1f565b606001356040517f82f2469d000000000000000000000000000000000000000000000000000000008152600401610a7e91815260200190565b838510156133665781831061334157604051633d386eb360e11b815260040160405180910390fd5b80821061336157604051633588c6d360e11b815260040160405180910390fd5b612d71565b82821061338657604051633d386eb360e11b815260040160405180910390fd5b808310612d7157604051633588c6d360e11b815260040160405180910390fd5b6009548110612284576040517fb6052cdf00000000000000000000000000000000000000000000000000000000815260048101829052602401610a7e565b60606133ee6119e9565b61340b57604051633788c6c160e11b815260040160405180910390fd5b60006134156119dc565b60085490915067ffffffffffffffff808316600160401b909204161461344e57604051636fbabc7760e01b815260040160405180910390fd5b6007546040516020016134899181527f3100000000000000000000000000000000000000000000000000000000000000602082015260210190565b60405160208183030381529060405291505090565b60008060008060008060008060006134b4613ca2565b60045490915060005b8181101561364657600481815481106134d8576134d8614715565b906000526020600020906005020160010160149054906101000a900460ff161561363e576004818154811061350f5761350f614715565b90600052602060002090600502016004015493506005848154811061353657613536614715565b90600052602060002090600502016003015489613553919061486d565b98508281604051602001613568929190614880565b60408051601f19818403018152919052805160209091012097506fffffffffffffffffffffffffffffffff80891697506135a390600161486d565b600585815481106135b6576135b6614715565b9060005260206000209060050201600301546135d291906146ad565b6135dc8a896146ad565b101561363e57600584815481106135f5576135f5614715565b90600052602060002090600502016004015495506005848154811061361c5761361c614715565b906000526020600020906005020160010160149054906101000a900460ff1694505b6001016134bd565b509399929850919650505050505050565b61365f6123a4565b6001805460ff1916811790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258335b6040516001600160a01b03909116815260200160405180910390a1565b6000805b6004548110156137235783600482815481106136cd576136cd614715565b90600052602060002090600502016000015414801561370f5750600481815481106136fa576136fa614715565b90600052602060002090600502016003015483145b1561371b579050610670565b6001016136af565b506040517fd950091500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61375e613d2b565b6001805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa3361368e565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610a91576137c081613d7d565b6137cb836020613d8f565b6040516020016137dc929190614b07565b60408051601f198184030181529082905262461bcd60e51b8252610a7e91600401614b88565b60008061381187878786613f54565b905082613916856000808267ffffffffffffffff1690506008817eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff16901b600882901c7eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff161790506010817dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff16901b601082901c7dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff161790506020817bffffffff00000000ffffffff00000000ffffffff00000000ffffffff16901b602082901c7bffffffff00000000ffffffff00000000ffffffff00000000ffffffff1617905080915050919050565b826040516020016139589392919092835260c09190911b77ffffffffffffffffffffffffffffffffffffffffffffffff19166020830152602882015260480190565b6040516020818303038152906040528051906020012091505095945050505050565b600080613988868686613fca565b9050613a8c836000808267ffffffffffffffff1690506008817eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff16901b600882901c7eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff161790506010817dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff16901b601082901c7dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff161790506020817bffffffff00000000ffffffff00000000ffffffff00000000ffffffff16901b602082901c7bffffffff00000000ffffffff00000000ffffffff00000000ffffffff1617905080915050919050565b81604051602001613ac792919060c09290921b77ffffffffffffffffffffffffffffffffffffffffffffffff19168252600882015260280190565b60405160208183030381529060405280519060200120915050949350505050565b6000613af48284614694565b60ff166001901b905092915050565b600060e083901c613b15836020614694565b60ff168163ffffffff16901c91505092915050565b600080613b3986868686614032565b90506000613b94826040517f19457468657265756d205369676e6564204d6573736167653a0a3332000000006020820152603c8101829052600090605c01604051602081830303815290604052805190602001209050919050565b9050886001600160a01b0316613baa828a61407d565b6001600160a01b0316149998505050505050505050565b600080613bce84846140fc565b90506000613c29826040517f19457468657265756d205369676e6564204d6573736167653a0a3332000000006020820152603c8101829052600090605c01604051602081830303815290604052805190602001209050919050565b9050866001600160a01b0316613c3f828861407d565b6001600160a01b031614979650505050505050565b60008282604051602001613c8492919091825260601b6bffffffffffffffffffffffff1916602082015260340190565b60405160208183030381529060405280519060200120905092915050565b6060613cac6119e9565b613cc957604051633788c6c160e11b815260040160405180910390fd5b6000613cd36119dc565b60085490915067ffffffffffffffff808316600160401b9092041614613d0c57604051636fbabc7760e01b815260040160405180910390fd5b600754604051602001613489918152600360fc1b602082015260210190565b60015460ff166119da5760405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f74207061757365640000000000000000000000006044820152606401610a7e565b60606106706001600160a01b03831660145b60606000613d9e8360026146ad565b613da990600261486d565b67ffffffffffffffff811115613dc157613dc1614bbb565b6040519080825280601f01601f191660200182016040528015613deb576020820181803683370190505b509050600360fc1b81600081518110613e0657613e06614715565b60200101906001600160f81b031916908160001a9053507f780000000000000000000000000000000000000000000000000000000000000081600181518110613e5157613e51614715565b60200101906001600160f81b031916908160001a9053506000613e758460026146ad565b613e8090600161486d565b90505b6001811115613f05577f303132333435363738396162636465660000000000000000000000000000000085600f1660108110613ec157613ec1614715565b1a60f81b828281518110613ed757613ed7614715565b60200101906001600160f81b031916908160001a90535060049490941c93613efe81614bd1565b9050613e83565b5083156122735760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610a7e565b8260005b8551811015613fc1576000613f6e6002866146ed565b15613f7a576000613f7d565b60015b9050613fa483888481518110613f9557613f95614715565b60200260200101518387614118565b9250600185901c9450508080613fb990614774565b915050613f58565b50949350505050565b8160005b845181101561402a576000613fe46002856146ed565b600014905061400d83878481518110613fff57613fff614715565b602002602001015183614178565b9250600184901c935050808061402290614774565b915050613fce565b509392505050565b604080516020810186905290810184905277ffffffffffffffffffffffffffffffffffffffffffffffff1960c084811b8216606084015283901b166068820152600090607001612040565b60008060008061408c856141df565b6040805160008152602081018083528b905260ff8316918101919091526060810184905260808101839052929550909350915060019060a0016020604051602081039080840390855afa1580156140e7573d6000803e3d6000fd5b5050604051601f190151979650505050505050565b6040805160208101849052908101829052600090606001613c84565b6000821561415857604080516020810184905290810186905260608101859052608001604051602081830303815290604052805190602001209050612059565b604080516020810184905290810185905260608101869052608001612040565b600081156141b1576040805160208101869052908101849052606001604051602081830303815290604052805190602001209050612273565b5050604080516020808201939093528082019390935280518084038201815260609093019052815191012090565b6000806000835160411461421f576040517f4be6321b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50505060208101516040820151606090920151909260009190911a90565b5080546000825560050290600052602060002090810190612284919061427f565b508054600082556005029060005260206000209081019061228491906142d6565b5b808211156142d25760008082556001820180547fffffffffffffffffffff0000000000000000000000000000000000000000000016905560028201819055600382018190556004820155600501614280565b5090565b5b808211156142d257600080825560018201805474ffffffffffffffffffffffffffffffffffffffffff19169055600282018190556003820181905560048201556005016142d7565b60006020828403121561433157600080fd5b81356001600160e01b03198116811461227357600080fd5b6001600160a01b038116811461228457600080fd5b60ff8116811461228457600080fd5b6000806040838503121561438057600080fd5b823561438b81614349565b9150602083013561439b8161435e565b809150509250929050565b6000602082840312156143b857600080fd5b5035919050565b6020808252825182820181905260009190848201906040850190845b818110156144425761442f838551805182526001600160a01b03602082015116602083015260ff6040820151166040830152606081015160608301526080810151608083015260a081015160a08301525050565b9284019260c092909201916001016143db565b50909695505050505050565b6000806040838503121561446157600080fd5b82359150602083013561439b81614349565b803567ffffffffffffffff8116811461448b57600080fd5b919050565b600080604083850312156144a357600080fd5b823591506144b360208401614473565b90509250929050565b600061010082840312156144cf57600080fd5b50919050565b6000806000606084860312156144ea57600080fd5b833567ffffffffffffffff8082111561450257600080fd5b61450e878388016144bc565b9450602086013591508082111561452457600080fd5b614530878388016144bc565b9350604086013591508082111561454657600080fd5b50614553868287016144bc565b9150509250925092565b60008060006060848603121561457257600080fd5b833561457d8161435e565b95602085013595506040909401359392505050565b600080600080608085870312156145a857600080fd5b8435935060208501356145ba8161435e565b93969395505050506040820135916060013590565b6000806000606084860312156145e457600080fd5b83356145ef8161435e565b925060208401356145ff8161435e565b9150604084013561460f8161435e565b809150509250925092565b60008060006060848603121561462f57600080fd5b8335925060208401359150604084013561460f8161435e565b60006020828403121561465a57600080fd5b5051919050565b60006020828403121561467357600080fd5b81516122738161435e565b634e487b7160e01b600052601160045260246000fd5b60ff82811682821603908111156106705761067061467e565b80820281158282048414176106705761067061467e565b818103818111156106705761067061467e565b634e487b7160e01b600052601260045260246000fd5b6000826146fc576146fc6146d7565b500690565b600082614710576147106146d7565b500490565b634e487b7160e01b600052603260045260246000fd5b67ffffffffffffffff81811683821601908082111561474c5761474c61467e565b5092915050565b67ffffffffffffffff82811682821603908082111561474c5761474c61467e565b6000600182016147865761478661467e565b5060010190565b6000808335601e198436030181126147a457600080fd5b83018035915067ffffffffffffffff8211156147bf57600080fd5b6020019150600581901b36038213156147d757600080fd5b9250929050565b60005b838110156147f95781810151838201526020016147e1565b50506000910152565b600082516148148184602087016147de565b9190910192915050565b60c081016106708284805182526001600160a01b03602082015116602083015260ff6040820151166040830152606081015160608301526080810151608083015260a081015160a08301525050565b808201808211156106705761067061467e565b600083516148928184602088016147de565b9190910191825250602001919050565b600181815b808511156148dd5781600019048211156148c3576148c361467e565b808516156148d057918102915b93841c93908002906148a7565b509250929050565b6000826148f457506001610670565b8161490157506000610670565b816001811461491757600281146149215761493d565b6001915050610670565b60ff8411156149325761493261467e565b50506001821b610670565b5060208310610133831016604e8410600b8410161715614960575081810a610670565b61496a83836148a2565b806000190482111561497e5761497e61467e565b029392505050565b600061227360ff8416836148e5565b60ff81811683821601908111156106705761067061467e565b61ffff82811682821603908082111561474c5761474c61467e565b600061227361ffff8416836148e5565b8051801515811461448b57600080fd5b6000602082840312156149fb57600080fd5b612273826149d9565b600060208284031215614a1657600080fd5b61227382614473565b60008235607e1983360301811261481457600080fd5b60008060008060008060c08789031215614a4e57600080fd5b8651614a5981614349565b6020880151909650614a6a8161435e565b6040880151909550614a7b8161435e565b9350614a89606088016149d9565b92506080870151915060a087015190509295509295509295565b6000808335601e19843603018112614aba57600080fd5b83018035915067ffffffffffffffff821115614ad557600080fd5b6020019150368190038213156147d757600080fd5b600060208284031215614afc57600080fd5b813561227381614349565b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000815260008351614b3f8160178501602088016147de565b7f206973206d697373696e6720726f6c65200000000000000000000000000000006017918401918201528351614b7c8160288401602088016147de565b01602801949350505050565b6020815260008251806020840152614ba78160408501602087016147de565b601f01601f19169190910160400192915050565b634e487b7160e01b600052604160045260246000fd5b600081614be057614be061467e565b50600019019056fea2646970667358221220e6d529c753301d40b88db1b0768955eec9895788418077bb895e8f7739fb1b6964736f6c63430008130033", "devdoc": { "author": "The Swarm Authors", "details": "Implements a Schelling Co-ordination game to form consensus around the Reserve Commitment hash. This takes place in three phases: _commit_, _reveal_ and _claim_. A node, upon establishing that it _isParticipatingInUpcomingRound_, i.e. it's overlay falls within proximity order of its reported depth with the _currentRoundAnchor_, prepares a \"reserve commitment hash\" using the chunks it currently stores in its reserve and calculates the \"storage depth\" (see Bee for details). These values, if calculated honestly, and with the right chunks stored, should be the same for every node in a neighbourhood. This is the Schelling point. Each eligible node can then use these values, together with a random, single use, secret _revealNonce_ and their _overlay_ as the pre-image values for the obsfucated _commit_, using the _wrapCommit_ method. Once the _commit_ round has elapsed, participating nodes must provide the values used to calculate their obsfucated _commit_ hash, which, once verified for correctness and proximity to the anchor are retained in the _currentReveals_. Nodes that have committed but do not reveal the correct values used to create the pre-image will have their stake \"frozen\" for a period of rounds proportional to their reported depth. During the _reveal_ round, randomness is updated after every successful reveal. Once the reveal round is concluded, the _currentRoundAnchor_ is updated and users can determine if they will be eligible their overlay will be eligible for the next commit phase using _isParticipatingInUpcomingRound_. When the _reveal_ phase has been concluded, the claim phase can begin. At this point, the truth teller and winner are already determined. By calling _isWinner_, an applicant node can run the relevant logic to determine if they have been selected as the beneficiary of this round. When calling _claim_, the current pot from the PostageStamp contract is withdrawn and transferred to that beneficiaries address. Nodes that have revealed values that differ from the truth, have their stakes \"frozen\" for a period of rounds proportional to their reported depth.", @@ -1579,7 +1616,7 @@ "ChunkCount(uint256)": { "details": "Emit from Postagestamp contract valid chunk count at the end of claim" }, - "Committed(uint256,bytes32)": { + "Committed(uint256,bytes32,uint8)": { "details": "Logs that an overlay has committed" }, "CountCommits(uint256)": { @@ -1594,6 +1631,9 @@ "Paused(address)": { "details": "Emitted when the pause is triggered by `account`." }, + "PriceAdjustmentSkipped(uint16)": { + "details": "Output external call status" + }, "Revealed(uint256,bytes32,uint256,uint256,bytes32,uint8)": { "details": "Logs that an overlay has revealed" }, @@ -1615,6 +1655,9 @@ "WinnerSelected((bytes32,address,uint8,uint256,uint256,bytes32))": { "details": "Emitted when the winner of a round is selected in the claim phase" }, + "WithdrawFailed(address)": { + "details": "Withdraw not successful in claim" + }, "transformedChunkAddressFromInclusionProof(uint256,bytes32)": { "details": "Logs for inclusion proof" } @@ -1782,47 +1825,47 @@ "type": "t_bool" }, { - "astId": 7228, + "astId": 7296, "contract": "src/Redistribution.sol:Redistribution", "label": "PostageContract", "offset": 1, "slot": "1", - "type": "t_contract(IPostageStamp)11161" + "type": "t_contract(IPostageStamp)11359" }, { - "astId": 7231, + "astId": 7299, "contract": "src/Redistribution.sol:Redistribution", "label": "OracleContract", "offset": 0, "slot": "2", - "type": "t_contract(IPriceOracle)7117" + "type": "t_contract(IPriceOracle)7176" }, { - "astId": 7234, + "astId": 7302, "contract": "src/Redistribution.sol:Redistribution", "label": "Stakes", "offset": 0, "slot": "3", - "type": "t_contract(IStakeRegistry)7153" + "type": "t_contract(IStakeRegistry)7219" }, { - "astId": 7238, + "astId": 7306, "contract": "src/Redistribution.sol:Redistribution", "label": "currentCommits", "offset": 0, "slot": "4", - "type": "t_array(t_struct(Commit)7171_storage)dyn_storage" + "type": "t_array(t_struct(Commit)7239_storage)dyn_storage" }, { - "astId": 7242, + "astId": 7310, "contract": "src/Redistribution.sol:Redistribution", "label": "currentReveals", "offset": 0, "slot": "5", - "type": "t_array(t_struct(Reveal)7184_storage)dyn_storage" + "type": "t_array(t_struct(Reveal)7252_storage)dyn_storage" }, { - "astId": 7244, + "astId": 7312, "contract": "src/Redistribution.sol:Redistribution", "label": "currentRevealRoundAnchor", "offset": 0, @@ -1830,7 +1873,7 @@ "type": "t_bytes32" }, { - "astId": 7246, + "astId": 7314, "contract": "src/Redistribution.sol:Redistribution", "label": "seed", "offset": 0, @@ -1838,7 +1881,7 @@ "type": "t_bytes32" }, { - "astId": 7248, + "astId": 7316, "contract": "src/Redistribution.sol:Redistribution", "label": "currentCommitRound", "offset": 0, @@ -1846,7 +1889,7 @@ "type": "t_uint64" }, { - "astId": 7250, + "astId": 7318, "contract": "src/Redistribution.sol:Redistribution", "label": "currentRevealRound", "offset": 8, @@ -1854,7 +1897,7 @@ "type": "t_uint64" }, { - "astId": 7252, + "astId": 7320, "contract": "src/Redistribution.sol:Redistribution", "label": "currentClaimRound", "offset": 16, @@ -1862,7 +1905,7 @@ "type": "t_uint64" }, { - "astId": 7255, + "astId": 7323, "contract": "src/Redistribution.sol:Redistribution", "label": "penaltyMultiplierDisagreement", "offset": 24, @@ -1870,7 +1913,7 @@ "type": "t_uint8" }, { - "astId": 7258, + "astId": 7326, "contract": "src/Redistribution.sol:Redistribution", "label": "penaltyMultiplierNonRevealed", "offset": 25, @@ -1878,7 +1921,7 @@ "type": "t_uint8" }, { - "astId": 7261, + "astId": 7329, "contract": "src/Redistribution.sol:Redistribution", "label": "penaltyRandomFactor", "offset": 26, @@ -1886,7 +1929,7 @@ "type": "t_uint8" }, { - "astId": 7264, + "astId": 7332, "contract": "src/Redistribution.sol:Redistribution", "label": "sampleMaxValue", "offset": 0, @@ -1894,12 +1937,12 @@ "type": "t_uint256" }, { - "astId": 7267, + "astId": 7335, "contract": "src/Redistribution.sol:Redistribution", "label": "winner", "offset": 0, "slot": "10", - "type": "t_struct(Reveal)7184_storage" + "type": "t_struct(Reveal)7252_storage" } ], "types": { @@ -1908,14 +1951,14 @@ "label": "address", "numberOfBytes": "20" }, - "t_array(t_struct(Commit)7171_storage)dyn_storage": { - "base": "t_struct(Commit)7171_storage", + "t_array(t_struct(Commit)7239_storage)dyn_storage": { + "base": "t_struct(Commit)7239_storage", "encoding": "dynamic_array", "label": "struct Redistribution.Commit[]", "numberOfBytes": "32" }, - "t_array(t_struct(Reveal)7184_storage)dyn_storage": { - "base": "t_struct(Reveal)7184_storage", + "t_array(t_struct(Reveal)7252_storage)dyn_storage": { + "base": "t_struct(Reveal)7252_storage", "encoding": "dynamic_array", "label": "struct Redistribution.Reveal[]", "numberOfBytes": "32" @@ -1930,17 +1973,17 @@ "label": "bytes32", "numberOfBytes": "32" }, - "t_contract(IPostageStamp)11161": { + "t_contract(IPostageStamp)11359": { "encoding": "inplace", "label": "contract IPostageStamp", "numberOfBytes": "20" }, - "t_contract(IPriceOracle)7117": { + "t_contract(IPriceOracle)7176": { "encoding": "inplace", "label": "contract IPriceOracle", "numberOfBytes": "20" }, - "t_contract(IStakeRegistry)7153": { + "t_contract(IStakeRegistry)7219": { "encoding": "inplace", "label": "contract IStakeRegistry", "numberOfBytes": "20" @@ -1959,12 +2002,12 @@ "numberOfBytes": "32", "value": "t_struct(RoleData)19_storage" }, - "t_struct(Commit)7171_storage": { + "t_struct(Commit)7239_storage": { "encoding": "inplace", "label": "struct Redistribution.Commit", "members": [ { - "astId": 7160, + "astId": 7226, "contract": "src/Redistribution.sol:Redistribution", "label": "overlay", "offset": 0, @@ -1972,7 +2015,7 @@ "type": "t_bytes32" }, { - "astId": 7162, + "astId": 7228, "contract": "src/Redistribution.sol:Redistribution", "label": "owner", "offset": 0, @@ -1980,7 +2023,7 @@ "type": "t_address" }, { - "astId": 7164, + "astId": 7230, "contract": "src/Redistribution.sol:Redistribution", "label": "revealed", "offset": 20, @@ -1988,7 +2031,15 @@ "type": "t_bool" }, { - "astId": 7166, + "astId": 7232, + "contract": "src/Redistribution.sol:Redistribution", + "label": "height", + "offset": 21, + "slot": "1", + "type": "t_uint8" + }, + { + "astId": 7234, "contract": "src/Redistribution.sol:Redistribution", "label": "stake", "offset": 0, @@ -1996,7 +2047,7 @@ "type": "t_uint256" }, { - "astId": 7168, + "astId": 7236, "contract": "src/Redistribution.sol:Redistribution", "label": "obfuscatedHash", "offset": 0, @@ -2004,7 +2055,7 @@ "type": "t_bytes32" }, { - "astId": 7170, + "astId": 7238, "contract": "src/Redistribution.sol:Redistribution", "label": "revealIndex", "offset": 0, @@ -2014,12 +2065,12 @@ ], "numberOfBytes": "160" }, - "t_struct(Reveal)7184_storage": { + "t_struct(Reveal)7252_storage": { "encoding": "inplace", "label": "struct Redistribution.Reveal", "members": [ { - "astId": 7173, + "astId": 7241, "contract": "src/Redistribution.sol:Redistribution", "label": "overlay", "offset": 0, @@ -2027,7 +2078,7 @@ "type": "t_bytes32" }, { - "astId": 7175, + "astId": 7243, "contract": "src/Redistribution.sol:Redistribution", "label": "owner", "offset": 0, @@ -2035,7 +2086,7 @@ "type": "t_address" }, { - "astId": 7177, + "astId": 7245, "contract": "src/Redistribution.sol:Redistribution", "label": "depth", "offset": 20, @@ -2043,7 +2094,7 @@ "type": "t_uint8" }, { - "astId": 7179, + "astId": 7247, "contract": "src/Redistribution.sol:Redistribution", "label": "stake", "offset": 0, @@ -2051,7 +2102,7 @@ "type": "t_uint256" }, { - "astId": 7181, + "astId": 7249, "contract": "src/Redistribution.sol:Redistribution", "label": "stakeDensity", "offset": 0, @@ -2059,7 +2110,7 @@ "type": "t_uint256" }, { - "astId": 7183, + "astId": 7251, "contract": "src/Redistribution.sol:Redistribution", "label": "hash", "offset": 0, diff --git a/deployments/testnet/StakeRegistry.json b/deployments/testnet/StakeRegistry.json index e9414e40..5e0427b2 100644 --- a/deployments/testnet/StakeRegistry.json +++ b/deployments/testnet/StakeRegistry.json @@ -1,5 +1,5 @@ { - "address": "0x5CF39e699b601c2EBc3e25b19Fd4102d8366b56F", + "address": "0x4353A36f4376A273a65595Acd9bE6c63D90fC352", "abi": [ { "inputs": [ @@ -241,6 +241,12 @@ "internalType": "uint256", "name": "lastUpdatedBlock", "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint8", + "name": "height", + "type": "uint8" } ], "name": "StakeUpdated", @@ -422,6 +428,25 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "address", + "name": "_owner", + "type": "address" + } + ], + "name": "heightOfAddress", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -452,6 +477,11 @@ "internalType": "uint256", "name": "_addAmount", "type": "uint256" + }, + { + "internalType": "uint8", + "name": "_height", + "type": "uint8" } ], "name": "manageStake", @@ -607,6 +637,11 @@ "internalType": "uint256", "name": "lastUpdatedBlockNumber", "type": "uint256" + }, + { + "internalType": "uint8", + "name": "height", + "type": "uint8" } ], "stateMutability": "view", @@ -659,22 +694,22 @@ "type": "function" } ], - "transactionHash": "0xd33c67f32ff685129b9e3a34d295074f499557799ed66a7d8b7b0546cc568dfe", + "transactionHash": "0x5ba813333a676d5a87cbd349b982c73d1286307b4d1801b0fd7448977c0731ba", "receipt": { "to": null, "from": "0xb1C7F17Ed88189Abf269Bf68A3B2Ed83C5276aAe", - "contractAddress": "0x5CF39e699b601c2EBc3e25b19Fd4102d8366b56F", - "transactionIndex": 93, - "gasUsed": "1476021", - "logsBloom": "0x00000004000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000020000000000000000000800000000010000000000000000002000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000100000000000020000000000000000000000000000000002000000000000000000000000000000000", - "blockHash": "0xec533607e6bb9bbfb10c514f96241e6fef39ca771c6625f63994595a167098e9", - "transactionHash": "0xd33c67f32ff685129b9e3a34d295074f499557799ed66a7d8b7b0546cc568dfe", + "contractAddress": "0x4353A36f4376A273a65595Acd9bE6c63D90fC352", + "transactionIndex": 35, + "gasUsed": "1591431", + "logsBloom": "0x00000004000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000800000000010000000000000000002000000000040000000000000000000008000000008000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000100000000000020000000000000000000000000000000000000000000000000000000000000000000", + "blockHash": "0x038195e7b388c3d6130091ce64b0b4707898b52b17b5696066d2b63ffd05d227", + "transactionHash": "0x5ba813333a676d5a87cbd349b982c73d1286307b4d1801b0fd7448977c0731ba", "logs": [ { - "transactionIndex": 93, - "blockNumber": 6596291, - "transactionHash": "0xd33c67f32ff685129b9e3a34d295074f499557799ed66a7d8b7b0546cc568dfe", - "address": "0x5CF39e699b601c2EBc3e25b19Fd4102d8366b56F", + "transactionIndex": 35, + "blockNumber": 7036319, + "transactionHash": "0x5ba813333a676d5a87cbd349b982c73d1286307b4d1801b0fd7448977c0731ba", + "address": "0x4353A36f4376A273a65595Acd9bE6c63D90fC352", "topics": [ "0x2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d", "0x0000000000000000000000000000000000000000000000000000000000000000", @@ -682,25 +717,25 @@ "0x000000000000000000000000b1c7f17ed88189abf269bf68a3b2ed83c5276aae" ], "data": "0x", - "logIndex": 154, - "blockHash": "0xec533607e6bb9bbfb10c514f96241e6fef39ca771c6625f63994595a167098e9" + "logIndex": 74, + "blockHash": "0x038195e7b388c3d6130091ce64b0b4707898b52b17b5696066d2b63ffd05d227" } ], - "blockNumber": 6596291, - "cumulativeGasUsed": "18795861", + "blockNumber": 7036319, + "cumulativeGasUsed": "8452828", "status": 1, "byzantium": true }, "args": [ "0x543dDb01Ba47acB11de34891cD86B675F04840db", 10, - "0xf19F9d88e963A61c735C1716F8A689Dc2887F463" + "0xC5241172f010AB24ff3eeC61B4c684E1A9482D2b" ], - "numDeployments": 5, - "solcInputHash": "c39ceb5ddfc36744a77362b8ce122638", - "metadata": "{\"compiler\":{\"version\":\"0.8.19+commit.7dd6d404\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_bzzToken\",\"type\":\"address\"},{\"internalType\":\"uint64\",\"name\":\"_NetworkId\",\"type\":\"uint64\"},{\"internalType\":\"address\",\"name\":\"_oracleContract\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[],\"name\":\"BelowMinimumStake\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"Frozen\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"OnlyPauser\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"OnlyRedistributor\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"TransferFailed\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"Unauthorized\",\"type\":\"error\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"}],\"name\":\"OverlayChanged\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"Paused\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"previousAdminRole\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"newAdminRole\",\"type\":\"bytes32\"}],\"name\":\"RoleAdminChanged\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"}],\"name\":\"RoleGranted\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"}],\"name\":\"RoleRevoked\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"frozen\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"time\",\"type\":\"uint256\"}],\"name\":\"StakeFrozen\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"slashed\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"StakeSlashed\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"committedStake\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"potentialStake\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"lastUpdatedBlock\",\"type\":\"uint256\"}],\"name\":\"StakeUpdated\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"node\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"StakeWithdrawn\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"Unpaused\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"DEFAULT_ADMIN_ROLE\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"OracleContract\",\"outputs\":[{\"internalType\":\"contract IPriceOracle\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"REDISTRIBUTOR_ROLE\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"bzzToken\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint64\",\"name\":\"_NetworkId\",\"type\":\"uint64\"}],\"name\":\"changeNetworkId\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_owner\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"_time\",\"type\":\"uint256\"}],\"name\":\"freezeDeposit\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"}],\"name\":\"getRoleAdmin\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"grantRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"hasRole\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_owner\",\"type\":\"address\"}],\"name\":\"lastUpdatedBlockNumberOfAddress\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"_setNonce\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"_addAmount\",\"type\":\"uint256\"}],\"name\":\"manageStake\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"migrateStake\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_owner\",\"type\":\"address\"}],\"name\":\"nodeEffectiveStake\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_owner\",\"type\":\"address\"}],\"name\":\"overlayOfAddress\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"pause\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"paused\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"renounceRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"revokeRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_owner\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"_amount\",\"type\":\"uint256\"}],\"name\":\"slashDeposit\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"name\":\"stakes\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"committedStake\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"potentialStake\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"lastUpdatedBlockNumber\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes4\",\"name\":\"interfaceId\",\"type\":\"bytes4\"}],\"name\":\"supportsInterface\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"unPause\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"withdrawFromStake\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"withdrawableStake\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"}],\"devdoc\":{\"author\":\"The Swarm Authors\",\"details\":\"Allows users to stake tokens in order to be eligible for the Redistribution Schelling co-ordination game. Stakes are frozen or slashed by the Redistribution contract in response to violations of the protocol.\",\"events\":{\"OverlayChanged(address,bytes32)\":{\"details\":\"Emitted when a address changes overlay it uses\"},\"Paused(address)\":{\"details\":\"Emitted when the pause is triggered by `account`.\"},\"RoleAdminChanged(bytes32,bytes32,bytes32)\":{\"details\":\"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._\"},\"RoleGranted(bytes32,address,address)\":{\"details\":\"Emitted when `account` is granted `role`. `sender` is the account that originated the contract call, an admin role bearer except when using {AccessControl-_setupRole}.\"},\"RoleRevoked(bytes32,address,address)\":{\"details\":\"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`)\"},\"StakeFrozen(address,bytes32,uint256)\":{\"details\":\"Emitted when a stake for address `frozen` is frozen for `time` blocks.\"},\"StakeSlashed(address,bytes32,uint256)\":{\"details\":\"Emitted when a stake for address `slashed` is slashed by `amount`.\"},\"StakeUpdated(address,uint256,uint256,bytes32,uint256)\":{\"details\":\"Emitted when a stake is created or updated by `owner` of the `overlay` by `committedStake`, and `potentialStake` during `lastUpdatedBlock`.\"},\"StakeWithdrawn(address,uint256)\":{\"details\":\"Emitted when a stake for address is withdrawn\"},\"Unpaused(address)\":{\"details\":\"Emitted when the pause is lifted by `account`.\"}},\"kind\":\"dev\",\"methods\":{\"constructor\":{\"params\":{\"_NetworkId\":\"Swarm network ID\",\"_bzzToken\":\"Address of the staked ERC20 token\"}},\"freezeDeposit(address,uint256)\":{\"details\":\"Freeze an existing stake, can only be called by the redistributor\",\"params\":{\"_owner\":\"the addres selected\",\"_time\":\"penalty length in blocknumbers\"}},\"getRoleAdmin(bytes32)\":{\"details\":\"Returns the admin role that controls `role`. See {grantRole} and {revokeRole}. To change a role's admin, use {_setRoleAdmin}.\"},\"grantRole(bytes32,address)\":{\"details\":\"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.\"},\"hasRole(bytes32,address)\":{\"details\":\"Returns `true` if `account` has been granted `role`.\"},\"lastUpdatedBlockNumberOfAddress(address)\":{\"details\":\"Returns the `lastUpdatedBlockNumber` of `address`.\"},\"manageStake(bytes32,uint256)\":{\"details\":\"At least `_initialBalancePerChunk*2^depth` number of tokens need to be preapproved for this contract.\",\"params\":{\"_addAmount\":\"Deposited amount of ERC20 tokens, equals to added Potential stake value\",\"_setNonce\":\"Nonce that was used for overlay calculation.\"}},\"migrateStake()\":{\"details\":\"Migrate stake only when the staking contract is paused, can only be called by the owner of the stake\"},\"nodeEffectiveStake(address)\":{\"details\":\"Returns the current `effectiveStake` of `address`. previously usable stake\",\"params\":{\"_owner\":\"_owner of node\"}},\"overlayOfAddress(address)\":{\"details\":\"Returns the currently used overlay of the address.\",\"params\":{\"_owner\":\"address of node\"}},\"pause()\":{\"details\":\"Pause the contract. The contract is provably stopped by renouncing the pauser role and the admin role after pausing, can only be called by the `PAUSER`\"},\"paused()\":{\"details\":\"Returns true if the contract is paused, and false otherwise.\"},\"renounceRole(bytes32,address)\":{\"details\":\"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.\"},\"revokeRole(bytes32,address)\":{\"details\":\"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.\"},\"slashDeposit(address,uint256)\":{\"details\":\"Slash an existing stake, can only be called by the `redistributor`\",\"params\":{\"_amount\":\"the amount to be slashed\",\"_owner\":\"the _owner adress selected\"}},\"supportsInterface(bytes4)\":{\"details\":\"See {IERC165-supportsInterface}.\"},\"unPause()\":{\"details\":\"Unpause the contract, can only be called by the pauser when paused\"},\"withdrawFromStake()\":{\"details\":\"Withdraw node stake surplus\"},\"withdrawableStake()\":{\"details\":\"Check the amount that is possible to withdraw as surplus\"}},\"title\":\"Staking contract for the Swarm storage incentives\",\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{\"manageStake(bytes32,uint256)\":{\"notice\":\"Create a new stake or update an existing one, change overlay of node\"}},\"version\":1}},\"settings\":{\"compilationTarget\":{\"src/Staking.sol\":\"StakeRegistry\"},\"evmVersion\":\"paris\",\"libraries\":{\":__CACHE_BREAKER__\":\"0x00000000d41867734bbee4c6863d9255b2b06ac1\"},\"metadata\":{\"bytecodeHash\":\"ipfs\",\"useLiteralContent\":true},\"optimizer\":{\"enabled\":true,\"runs\":1000},\"remappings\":[]},\"sources\":{\"@openzeppelin/contracts/access/AccessControl.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (access/AccessControl.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./IAccessControl.sol\\\";\\nimport \\\"../utils/Context.sol\\\";\\nimport \\\"../utils/Strings.sol\\\";\\nimport \\\"../utils/introspection/ERC165.sol\\\";\\n\\n/**\\n * @dev Contract module that allows children to implement role-based access\\n * control mechanisms. This is a lightweight version that doesn't allow enumerating role\\n * members except through off-chain means by accessing the contract event logs. Some\\n * applications may benefit from on-chain enumerability, for those cases see\\n * {AccessControlEnumerable}.\\n *\\n * Roles are referred to by their `bytes32` identifier. These should be exposed\\n * in the external API and be unique. The best way to achieve this is by\\n * using `public constant` hash digests:\\n *\\n * ```\\n * bytes32 public constant MY_ROLE = keccak256(\\\"MY_ROLE\\\");\\n * ```\\n *\\n * Roles can be used to represent a set of permissions. To restrict access to a\\n * function call, use {hasRole}:\\n *\\n * ```\\n * function foo() public {\\n * require(hasRole(MY_ROLE, msg.sender));\\n * ...\\n * }\\n * ```\\n *\\n * Roles can be granted and revoked dynamically via the {grantRole} and\\n * {revokeRole} functions. Each role has an associated admin role, and only\\n * accounts that have a role's admin role can call {grantRole} and {revokeRole}.\\n *\\n * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means\\n * that only accounts with this role will be able to grant or revoke other\\n * roles. More complex role relationships can be created by using\\n * {_setRoleAdmin}.\\n *\\n * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to\\n * grant and revoke this role. Extra precautions should be taken to secure\\n * accounts that have been granted it.\\n */\\nabstract contract AccessControl is Context, IAccessControl, ERC165 {\\n struct RoleData {\\n mapping(address => bool) members;\\n bytes32 adminRole;\\n }\\n\\n mapping(bytes32 => RoleData) private _roles;\\n\\n bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;\\n\\n /**\\n * @dev Modifier that checks that an account has a specific role. Reverts\\n * with a standardized message including the required role.\\n *\\n * The format of the revert reason is given by the following regular expression:\\n *\\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\\n *\\n * _Available since v4.1._\\n */\\n modifier onlyRole(bytes32 role) {\\n _checkRole(role);\\n _;\\n }\\n\\n /**\\n * @dev See {IERC165-supportsInterface}.\\n */\\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);\\n }\\n\\n /**\\n * @dev Returns `true` if `account` has been granted `role`.\\n */\\n function hasRole(bytes32 role, address account) public view virtual override returns (bool) {\\n return _roles[role].members[account];\\n }\\n\\n /**\\n * @dev Revert with a standard message if `_msgSender()` is missing `role`.\\n * Overriding this function changes the behavior of the {onlyRole} modifier.\\n *\\n * Format of the revert message is described in {_checkRole}.\\n *\\n * _Available since v4.6._\\n */\\n function _checkRole(bytes32 role) internal view virtual {\\n _checkRole(role, _msgSender());\\n }\\n\\n /**\\n * @dev Revert with a standard message if `account` is missing `role`.\\n *\\n * The format of the revert reason is given by the following regular expression:\\n *\\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\\n */\\n function _checkRole(bytes32 role, address account) internal view virtual {\\n if (!hasRole(role, account)) {\\n revert(\\n string(\\n abi.encodePacked(\\n \\\"AccessControl: account \\\",\\n Strings.toHexString(account),\\n \\\" is missing role \\\",\\n Strings.toHexString(uint256(role), 32)\\n )\\n )\\n );\\n }\\n }\\n\\n /**\\n * @dev Returns the admin role that controls `role`. See {grantRole} and\\n * {revokeRole}.\\n *\\n * To change a role's admin, use {_setRoleAdmin}.\\n */\\n function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {\\n return _roles[role].adminRole;\\n }\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * If `account` had not been already granted `role`, emits a {RoleGranted}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n *\\n * May emit a {RoleGranted} event.\\n */\\n function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\\n _grantRole(role, account);\\n }\\n\\n /**\\n * @dev Revokes `role` from `account`.\\n *\\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n *\\n * May emit a {RoleRevoked} event.\\n */\\n function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\\n _revokeRole(role, account);\\n }\\n\\n /**\\n * @dev Revokes `role` from the calling account.\\n *\\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\\n * purpose is to provide a mechanism for accounts to lose their privileges\\n * if they are compromised (such as when a trusted device is misplaced).\\n *\\n * If the calling account had been revoked `role`, emits a {RoleRevoked}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must be `account`.\\n *\\n * May emit a {RoleRevoked} event.\\n */\\n function renounceRole(bytes32 role, address account) public virtual override {\\n require(account == _msgSender(), \\\"AccessControl: can only renounce roles for self\\\");\\n\\n _revokeRole(role, account);\\n }\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * If `account` had not been already granted `role`, emits a {RoleGranted}\\n * event. Note that unlike {grantRole}, this function doesn't perform any\\n * checks on the calling account.\\n *\\n * May emit a {RoleGranted} event.\\n *\\n * [WARNING]\\n * ====\\n * This function should only be called from the constructor when setting\\n * up the initial roles for the system.\\n *\\n * Using this function in any other way is effectively circumventing the admin\\n * system imposed by {AccessControl}.\\n * ====\\n *\\n * NOTE: This function is deprecated in favor of {_grantRole}.\\n */\\n function _setupRole(bytes32 role, address account) internal virtual {\\n _grantRole(role, account);\\n }\\n\\n /**\\n * @dev Sets `adminRole` as ``role``'s admin role.\\n *\\n * Emits a {RoleAdminChanged} event.\\n */\\n function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {\\n bytes32 previousAdminRole = getRoleAdmin(role);\\n _roles[role].adminRole = adminRole;\\n emit RoleAdminChanged(role, previousAdminRole, adminRole);\\n }\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * Internal function without access restriction.\\n *\\n * May emit a {RoleGranted} event.\\n */\\n function _grantRole(bytes32 role, address account) internal virtual {\\n if (!hasRole(role, account)) {\\n _roles[role].members[account] = true;\\n emit RoleGranted(role, account, _msgSender());\\n }\\n }\\n\\n /**\\n * @dev Revokes `role` from `account`.\\n *\\n * Internal function without access restriction.\\n *\\n * May emit a {RoleRevoked} event.\\n */\\n function _revokeRole(bytes32 role, address account) internal virtual {\\n if (hasRole(role, account)) {\\n _roles[role].members[account] = false;\\n emit RoleRevoked(role, account, _msgSender());\\n }\\n }\\n}\\n\",\"keccak256\":\"0x67e3daf189111d6d5b0464ed09cf9f0605a22c4b965a7fcecd707101faff008a\",\"license\":\"MIT\"},\"@openzeppelin/contracts/access/IAccessControl.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev External interface of AccessControl declared to support ERC165 detection.\\n */\\ninterface IAccessControl {\\n /**\\n * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`\\n *\\n * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite\\n * {RoleAdminChanged} not being emitted signaling this.\\n *\\n * _Available since v3.1._\\n */\\n event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);\\n\\n /**\\n * @dev Emitted when `account` is granted `role`.\\n *\\n * `sender` is the account that originated the contract call, an admin role\\n * bearer except when using {AccessControl-_setupRole}.\\n */\\n event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);\\n\\n /**\\n * @dev Emitted when `account` is revoked `role`.\\n *\\n * `sender` is the account that originated the contract call:\\n * - if using `revokeRole`, it is the admin role bearer\\n * - if using `renounceRole`, it is the role bearer (i.e. `account`)\\n */\\n event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);\\n\\n /**\\n * @dev Returns `true` if `account` has been granted `role`.\\n */\\n function hasRole(bytes32 role, address account) external view returns (bool);\\n\\n /**\\n * @dev Returns the admin role that controls `role`. See {grantRole} and\\n * {revokeRole}.\\n *\\n * To change a role's admin, use {AccessControl-_setRoleAdmin}.\\n */\\n function getRoleAdmin(bytes32 role) external view returns (bytes32);\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * If `account` had not been already granted `role`, emits a {RoleGranted}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n */\\n function grantRole(bytes32 role, address account) external;\\n\\n /**\\n * @dev Revokes `role` from `account`.\\n *\\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n */\\n function revokeRole(bytes32 role, address account) external;\\n\\n /**\\n * @dev Revokes `role` from the calling account.\\n *\\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\\n * purpose is to provide a mechanism for accounts to lose their privileges\\n * if they are compromised (such as when a trusted device is misplaced).\\n *\\n * If the calling account had been granted `role`, emits a {RoleRevoked}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must be `account`.\\n */\\n function renounceRole(bytes32 role, address account) external;\\n}\\n\",\"keccak256\":\"0x59ce320a585d7e1f163cd70390a0ef2ff9cec832e2aa544293a00692465a7a57\",\"license\":\"MIT\"},\"@openzeppelin/contracts/security/Pausable.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"../utils/Context.sol\\\";\\n\\n/**\\n * @dev Contract module which allows children to implement an emergency stop\\n * mechanism that can be triggered by an authorized account.\\n *\\n * This module is used through inheritance. It will make available the\\n * modifiers `whenNotPaused` and `whenPaused`, which can be applied to\\n * the functions of your contract. Note that they will not be pausable by\\n * simply including this module, only once the modifiers are put in place.\\n */\\nabstract contract Pausable is Context {\\n /**\\n * @dev Emitted when the pause is triggered by `account`.\\n */\\n event Paused(address account);\\n\\n /**\\n * @dev Emitted when the pause is lifted by `account`.\\n */\\n event Unpaused(address account);\\n\\n bool private _paused;\\n\\n /**\\n * @dev Initializes the contract in unpaused state.\\n */\\n constructor() {\\n _paused = false;\\n }\\n\\n /**\\n * @dev Modifier to make a function callable only when the contract is not paused.\\n *\\n * Requirements:\\n *\\n * - The contract must not be paused.\\n */\\n modifier whenNotPaused() {\\n _requireNotPaused();\\n _;\\n }\\n\\n /**\\n * @dev Modifier to make a function callable only when the contract is paused.\\n *\\n * Requirements:\\n *\\n * - The contract must be paused.\\n */\\n modifier whenPaused() {\\n _requirePaused();\\n _;\\n }\\n\\n /**\\n * @dev Returns true if the contract is paused, and false otherwise.\\n */\\n function paused() public view virtual returns (bool) {\\n return _paused;\\n }\\n\\n /**\\n * @dev Throws if the contract is paused.\\n */\\n function _requireNotPaused() internal view virtual {\\n require(!paused(), \\\"Pausable: paused\\\");\\n }\\n\\n /**\\n * @dev Throws if the contract is not paused.\\n */\\n function _requirePaused() internal view virtual {\\n require(paused(), \\\"Pausable: not paused\\\");\\n }\\n\\n /**\\n * @dev Triggers stopped state.\\n *\\n * Requirements:\\n *\\n * - The contract must not be paused.\\n */\\n function _pause() internal virtual whenNotPaused {\\n _paused = true;\\n emit Paused(_msgSender());\\n }\\n\\n /**\\n * @dev Returns to normal state.\\n *\\n * Requirements:\\n *\\n * - The contract must be paused.\\n */\\n function _unpause() internal virtual whenPaused {\\n _paused = false;\\n emit Unpaused(_msgSender());\\n }\\n}\\n\",\"keccak256\":\"0x0849d93b16c9940beb286a7864ed02724b248b93e0d80ef6355af5ef15c64773\",\"license\":\"MIT\"},\"@openzeppelin/contracts/token/ERC20/ERC20.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/ERC20.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./IERC20.sol\\\";\\nimport \\\"./extensions/IERC20Metadata.sol\\\";\\nimport \\\"../../utils/Context.sol\\\";\\n\\n/**\\n * @dev Implementation of the {IERC20} interface.\\n *\\n * This implementation is agnostic to the way tokens are created. This means\\n * that a supply mechanism has to be added in a derived contract using {_mint}.\\n * For a generic mechanism see {ERC20PresetMinterPauser}.\\n *\\n * TIP: For a detailed writeup see our guide\\n * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How\\n * to implement supply mechanisms].\\n *\\n * We have followed general OpenZeppelin Contracts guidelines: functions revert\\n * instead returning `false` on failure. This behavior is nonetheless\\n * conventional and does not conflict with the expectations of ERC20\\n * applications.\\n *\\n * Additionally, an {Approval} event is emitted on calls to {transferFrom}.\\n * This allows applications to reconstruct the allowance for all accounts just\\n * by listening to said events. Other implementations of the EIP may not emit\\n * these events, as it isn't required by the specification.\\n *\\n * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}\\n * functions have been added to mitigate the well-known issues around setting\\n * allowances. See {IERC20-approve}.\\n */\\ncontract ERC20 is Context, IERC20, IERC20Metadata {\\n mapping(address => uint256) private _balances;\\n\\n mapping(address => mapping(address => uint256)) private _allowances;\\n\\n uint256 private _totalSupply;\\n\\n string private _name;\\n string private _symbol;\\n\\n /**\\n * @dev Sets the values for {name} and {symbol}.\\n *\\n * The default value of {decimals} is 18. To select a different value for\\n * {decimals} you should overload it.\\n *\\n * All two of these values are immutable: they can only be set once during\\n * construction.\\n */\\n constructor(string memory name_, string memory symbol_) {\\n _name = name_;\\n _symbol = symbol_;\\n }\\n\\n /**\\n * @dev Returns the name of the token.\\n */\\n function name() public view virtual override returns (string memory) {\\n return _name;\\n }\\n\\n /**\\n * @dev Returns the symbol of the token, usually a shorter version of the\\n * name.\\n */\\n function symbol() public view virtual override returns (string memory) {\\n return _symbol;\\n }\\n\\n /**\\n * @dev Returns the number of decimals used to get its user representation.\\n * For example, if `decimals` equals `2`, a balance of `505` tokens should\\n * be displayed to a user as `5.05` (`505 / 10 ** 2`).\\n *\\n * Tokens usually opt for a value of 18, imitating the relationship between\\n * Ether and Wei. This is the value {ERC20} uses, unless this function is\\n * overridden;\\n *\\n * NOTE: This information is only used for _display_ purposes: it in\\n * no way affects any of the arithmetic of the contract, including\\n * {IERC20-balanceOf} and {IERC20-transfer}.\\n */\\n function decimals() public view virtual override returns (uint8) {\\n return 18;\\n }\\n\\n /**\\n * @dev See {IERC20-totalSupply}.\\n */\\n function totalSupply() public view virtual override returns (uint256) {\\n return _totalSupply;\\n }\\n\\n /**\\n * @dev See {IERC20-balanceOf}.\\n */\\n function balanceOf(address account) public view virtual override returns (uint256) {\\n return _balances[account];\\n }\\n\\n /**\\n * @dev See {IERC20-transfer}.\\n *\\n * Requirements:\\n *\\n * - `to` cannot be the zero address.\\n * - the caller must have a balance of at least `amount`.\\n */\\n function transfer(address to, uint256 amount) public virtual override returns (bool) {\\n address owner = _msgSender();\\n _transfer(owner, to, amount);\\n return true;\\n }\\n\\n /**\\n * @dev See {IERC20-allowance}.\\n */\\n function allowance(address owner, address spender) public view virtual override returns (uint256) {\\n return _allowances[owner][spender];\\n }\\n\\n /**\\n * @dev See {IERC20-approve}.\\n *\\n * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on\\n * `transferFrom`. This is semantically equivalent to an infinite approval.\\n *\\n * Requirements:\\n *\\n * - `spender` cannot be the zero address.\\n */\\n function approve(address spender, uint256 amount) public virtual override returns (bool) {\\n address owner = _msgSender();\\n _approve(owner, spender, amount);\\n return true;\\n }\\n\\n /**\\n * @dev See {IERC20-transferFrom}.\\n *\\n * Emits an {Approval} event indicating the updated allowance. This is not\\n * required by the EIP. See the note at the beginning of {ERC20}.\\n *\\n * NOTE: Does not update the allowance if the current allowance\\n * is the maximum `uint256`.\\n *\\n * Requirements:\\n *\\n * - `from` and `to` cannot be the zero address.\\n * - `from` must have a balance of at least `amount`.\\n * - the caller must have allowance for ``from``'s tokens of at least\\n * `amount`.\\n */\\n function transferFrom(\\n address from,\\n address to,\\n uint256 amount\\n ) public virtual override returns (bool) {\\n address spender = _msgSender();\\n _spendAllowance(from, spender, amount);\\n _transfer(from, to, amount);\\n return true;\\n }\\n\\n /**\\n * @dev Atomically increases the allowance granted to `spender` by the caller.\\n *\\n * This is an alternative to {approve} that can be used as a mitigation for\\n * problems described in {IERC20-approve}.\\n *\\n * Emits an {Approval} event indicating the updated allowance.\\n *\\n * Requirements:\\n *\\n * - `spender` cannot be the zero address.\\n */\\n function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {\\n address owner = _msgSender();\\n _approve(owner, spender, allowance(owner, spender) + addedValue);\\n return true;\\n }\\n\\n /**\\n * @dev Atomically decreases the allowance granted to `spender` by the caller.\\n *\\n * This is an alternative to {approve} that can be used as a mitigation for\\n * problems described in {IERC20-approve}.\\n *\\n * Emits an {Approval} event indicating the updated allowance.\\n *\\n * Requirements:\\n *\\n * - `spender` cannot be the zero address.\\n * - `spender` must have allowance for the caller of at least\\n * `subtractedValue`.\\n */\\n function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {\\n address owner = _msgSender();\\n uint256 currentAllowance = allowance(owner, spender);\\n require(currentAllowance >= subtractedValue, \\\"ERC20: decreased allowance below zero\\\");\\n unchecked {\\n _approve(owner, spender, currentAllowance - subtractedValue);\\n }\\n\\n return true;\\n }\\n\\n /**\\n * @dev Moves `amount` of tokens from `from` to `to`.\\n *\\n * This internal function is equivalent to {transfer}, and can be used to\\n * e.g. implement automatic token fees, slashing mechanisms, etc.\\n *\\n * Emits a {Transfer} event.\\n *\\n * Requirements:\\n *\\n * - `from` cannot be the zero address.\\n * - `to` cannot be the zero address.\\n * - `from` must have a balance of at least `amount`.\\n */\\n function _transfer(\\n address from,\\n address to,\\n uint256 amount\\n ) internal virtual {\\n require(from != address(0), \\\"ERC20: transfer from the zero address\\\");\\n require(to != address(0), \\\"ERC20: transfer to the zero address\\\");\\n\\n _beforeTokenTransfer(from, to, amount);\\n\\n uint256 fromBalance = _balances[from];\\n require(fromBalance >= amount, \\\"ERC20: transfer amount exceeds balance\\\");\\n unchecked {\\n _balances[from] = fromBalance - amount;\\n // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by\\n // decrementing then incrementing.\\n _balances[to] += amount;\\n }\\n\\n emit Transfer(from, to, amount);\\n\\n _afterTokenTransfer(from, to, amount);\\n }\\n\\n /** @dev Creates `amount` tokens and assigns them to `account`, increasing\\n * the total supply.\\n *\\n * Emits a {Transfer} event with `from` set to the zero address.\\n *\\n * Requirements:\\n *\\n * - `account` cannot be the zero address.\\n */\\n function _mint(address account, uint256 amount) internal virtual {\\n require(account != address(0), \\\"ERC20: mint to the zero address\\\");\\n\\n _beforeTokenTransfer(address(0), account, amount);\\n\\n _totalSupply += amount;\\n unchecked {\\n // Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.\\n _balances[account] += amount;\\n }\\n emit Transfer(address(0), account, amount);\\n\\n _afterTokenTransfer(address(0), account, amount);\\n }\\n\\n /**\\n * @dev Destroys `amount` tokens from `account`, reducing the\\n * total supply.\\n *\\n * Emits a {Transfer} event with `to` set to the zero address.\\n *\\n * Requirements:\\n *\\n * - `account` cannot be the zero address.\\n * - `account` must have at least `amount` tokens.\\n */\\n function _burn(address account, uint256 amount) internal virtual {\\n require(account != address(0), \\\"ERC20: burn from the zero address\\\");\\n\\n _beforeTokenTransfer(account, address(0), amount);\\n\\n uint256 accountBalance = _balances[account];\\n require(accountBalance >= amount, \\\"ERC20: burn amount exceeds balance\\\");\\n unchecked {\\n _balances[account] = accountBalance - amount;\\n // Overflow not possible: amount <= accountBalance <= totalSupply.\\n _totalSupply -= amount;\\n }\\n\\n emit Transfer(account, address(0), amount);\\n\\n _afterTokenTransfer(account, address(0), amount);\\n }\\n\\n /**\\n * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.\\n *\\n * This internal function is equivalent to `approve`, and can be used to\\n * e.g. set automatic allowances for certain subsystems, etc.\\n *\\n * Emits an {Approval} event.\\n *\\n * Requirements:\\n *\\n * - `owner` cannot be the zero address.\\n * - `spender` cannot be the zero address.\\n */\\n function _approve(\\n address owner,\\n address spender,\\n uint256 amount\\n ) internal virtual {\\n require(owner != address(0), \\\"ERC20: approve from the zero address\\\");\\n require(spender != address(0), \\\"ERC20: approve to the zero address\\\");\\n\\n _allowances[owner][spender] = amount;\\n emit Approval(owner, spender, amount);\\n }\\n\\n /**\\n * @dev Updates `owner` s allowance for `spender` based on spent `amount`.\\n *\\n * Does not update the allowance amount in case of infinite allowance.\\n * Revert if not enough allowance is available.\\n *\\n * Might emit an {Approval} event.\\n */\\n function _spendAllowance(\\n address owner,\\n address spender,\\n uint256 amount\\n ) internal virtual {\\n uint256 currentAllowance = allowance(owner, spender);\\n if (currentAllowance != type(uint256).max) {\\n require(currentAllowance >= amount, \\\"ERC20: insufficient allowance\\\");\\n unchecked {\\n _approve(owner, spender, currentAllowance - amount);\\n }\\n }\\n }\\n\\n /**\\n * @dev Hook that is called before any transfer of tokens. This includes\\n * minting and burning.\\n *\\n * Calling conditions:\\n *\\n * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\\n * will be transferred to `to`.\\n * - when `from` is zero, `amount` tokens will be minted for `to`.\\n * - when `to` is zero, `amount` of ``from``'s tokens will be burned.\\n * - `from` and `to` are never both zero.\\n *\\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\\n */\\n function _beforeTokenTransfer(\\n address from,\\n address to,\\n uint256 amount\\n ) internal virtual {}\\n\\n /**\\n * @dev Hook that is called after any transfer of tokens. This includes\\n * minting and burning.\\n *\\n * Calling conditions:\\n *\\n * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\\n * has been transferred to `to`.\\n * - when `from` is zero, `amount` tokens have been minted for `to`.\\n * - when `to` is zero, `amount` of ``from``'s tokens have been burned.\\n * - `from` and `to` are never both zero.\\n *\\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\\n */\\n function _afterTokenTransfer(\\n address from,\\n address to,\\n uint256 amount\\n ) internal virtual {}\\n}\\n\",\"keccak256\":\"0x4ffc0547c02ad22925310c585c0f166f8759e2648a09e9b489100c42f15dd98d\",\"license\":\"MIT\"},\"@openzeppelin/contracts/token/ERC20/IERC20.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Interface of the ERC20 standard as defined in the EIP.\\n */\\ninterface IERC20 {\\n /**\\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\\n * another (`to`).\\n *\\n * Note that `value` may be zero.\\n */\\n event Transfer(address indexed from, address indexed to, uint256 value);\\n\\n /**\\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\\n * a call to {approve}. `value` is the new allowance.\\n */\\n event Approval(address indexed owner, address indexed spender, uint256 value);\\n\\n /**\\n * @dev Returns the amount of tokens in existence.\\n */\\n function totalSupply() external view returns (uint256);\\n\\n /**\\n * @dev Returns the amount of tokens owned by `account`.\\n */\\n function balanceOf(address account) external view returns (uint256);\\n\\n /**\\n * @dev Moves `amount` tokens from the caller's account to `to`.\\n *\\n * Returns a boolean value indicating whether the operation succeeded.\\n *\\n * Emits a {Transfer} event.\\n */\\n function transfer(address to, uint256 amount) external returns (bool);\\n\\n /**\\n * @dev Returns the remaining number of tokens that `spender` will be\\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\\n * zero by default.\\n *\\n * This value changes when {approve} or {transferFrom} are called.\\n */\\n function allowance(address owner, address spender) external view returns (uint256);\\n\\n /**\\n * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\\n *\\n * Returns a boolean value indicating whether the operation succeeded.\\n *\\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\\n * that someone may use both the old and the new allowance by unfortunate\\n * transaction ordering. One possible solution to mitigate this race\\n * condition is to first reduce the spender's allowance to 0 and set the\\n * desired value afterwards:\\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\\n *\\n * Emits an {Approval} event.\\n */\\n function approve(address spender, uint256 amount) external returns (bool);\\n\\n /**\\n * @dev Moves `amount` tokens from `from` to `to` using the\\n * allowance mechanism. `amount` is then deducted from the caller's\\n * allowance.\\n *\\n * Returns a boolean value indicating whether the operation succeeded.\\n *\\n * Emits a {Transfer} event.\\n */\\n function transferFrom(\\n address from,\\n address to,\\n uint256 amount\\n ) external returns (bool);\\n}\\n\",\"keccak256\":\"0x9750c6b834f7b43000631af5cc30001c5f547b3ceb3635488f140f60e897ea6b\",\"license\":\"MIT\"},\"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"../IERC20.sol\\\";\\n\\n/**\\n * @dev Interface for the optional metadata functions from the ERC20 standard.\\n *\\n * _Available since v4.1._\\n */\\ninterface IERC20Metadata is IERC20 {\\n /**\\n * @dev Returns the name of the token.\\n */\\n function name() external view returns (string memory);\\n\\n /**\\n * @dev Returns the symbol of the token.\\n */\\n function symbol() external view returns (string memory);\\n\\n /**\\n * @dev Returns the decimals places of the token.\\n */\\n function decimals() external view returns (uint8);\\n}\\n\",\"keccak256\":\"0x8de418a5503946cabe331f35fe242d3201a73f67f77aaeb7110acb1f30423aca\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/Context.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Provides information about the current execution context, including the\\n * sender of the transaction and its data. While these are generally available\\n * via msg.sender and msg.data, they should not be accessed in such a direct\\n * manner, since when dealing with meta-transactions the account sending and\\n * paying for execution may not be the actual sender (as far as an application\\n * is concerned).\\n *\\n * This contract is only required for intermediate, library-like contracts.\\n */\\nabstract contract Context {\\n function _msgSender() internal view virtual returns (address) {\\n return msg.sender;\\n }\\n\\n function _msgData() internal view virtual returns (bytes calldata) {\\n return msg.data;\\n }\\n}\\n\",\"keccak256\":\"0xe2e337e6dde9ef6b680e07338c493ebea1b5fd09b43424112868e9cc1706bca7\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/Strings.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./math/Math.sol\\\";\\n\\n/**\\n * @dev String operations.\\n */\\nlibrary Strings {\\n bytes16 private constant _SYMBOLS = \\\"0123456789abcdef\\\";\\n uint8 private constant _ADDRESS_LENGTH = 20;\\n\\n /**\\n * @dev Converts a `uint256` to its ASCII `string` decimal representation.\\n */\\n function toString(uint256 value) internal pure returns (string memory) {\\n unchecked {\\n uint256 length = Math.log10(value) + 1;\\n string memory buffer = new string(length);\\n uint256 ptr;\\n /// @solidity memory-safe-assembly\\n assembly {\\n ptr := add(buffer, add(32, length))\\n }\\n while (true) {\\n ptr--;\\n /// @solidity memory-safe-assembly\\n assembly {\\n mstore8(ptr, byte(mod(value, 10), _SYMBOLS))\\n }\\n value /= 10;\\n if (value == 0) break;\\n }\\n return buffer;\\n }\\n }\\n\\n /**\\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\\n */\\n function toHexString(uint256 value) internal pure returns (string memory) {\\n unchecked {\\n return toHexString(value, Math.log256(value) + 1);\\n }\\n }\\n\\n /**\\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\\n */\\n function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\\n bytes memory buffer = new bytes(2 * length + 2);\\n buffer[0] = \\\"0\\\";\\n buffer[1] = \\\"x\\\";\\n for (uint256 i = 2 * length + 1; i > 1; --i) {\\n buffer[i] = _SYMBOLS[value & 0xf];\\n value >>= 4;\\n }\\n require(value == 0, \\\"Strings: hex length insufficient\\\");\\n return string(buffer);\\n }\\n\\n /**\\n * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.\\n */\\n function toHexString(address addr) internal pure returns (string memory) {\\n return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);\\n }\\n}\\n\",\"keccak256\":\"0xa4d1d62251f8574deb032a35fc948386a9b4de74b812d4f545a1ac120486b48a\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/introspection/ERC165.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./IERC165.sol\\\";\\n\\n/**\\n * @dev Implementation of the {IERC165} interface.\\n *\\n * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check\\n * for the additional interface id that will be supported. For example:\\n *\\n * ```solidity\\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\\n * }\\n * ```\\n *\\n * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.\\n */\\nabstract contract ERC165 is IERC165 {\\n /**\\n * @dev See {IERC165-supportsInterface}.\\n */\\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n return interfaceId == type(IERC165).interfaceId;\\n }\\n}\\n\",\"keccak256\":\"0xd10975de010d89fd1c78dc5e8a9a7e7f496198085c151648f20cba166b32582b\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/introspection/IERC165.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Interface of the ERC165 standard, as defined in the\\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\\n *\\n * Implementers can declare support of contract interfaces, which can then be\\n * queried by others ({ERC165Checker}).\\n *\\n * For an implementation, see {ERC165}.\\n */\\ninterface IERC165 {\\n /**\\n * @dev Returns true if this contract implements the interface defined by\\n * `interfaceId`. See the corresponding\\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\\n * to learn more about how these ids are created.\\n *\\n * This function call must use less than 30 000 gas.\\n */\\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\\n}\\n\",\"keccak256\":\"0x447a5f3ddc18419d41ff92b3773fb86471b1db25773e07f877f548918a185bf1\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/math/Math.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Standard math utilities missing in the Solidity language.\\n */\\nlibrary Math {\\n enum Rounding {\\n Down, // Toward negative infinity\\n Up, // Toward infinity\\n Zero // Toward zero\\n }\\n\\n /**\\n * @dev Returns the largest of two numbers.\\n */\\n function max(uint256 a, uint256 b) internal pure returns (uint256) {\\n return a > b ? a : b;\\n }\\n\\n /**\\n * @dev Returns the smallest of two numbers.\\n */\\n function min(uint256 a, uint256 b) internal pure returns (uint256) {\\n return a < b ? a : b;\\n }\\n\\n /**\\n * @dev Returns the average of two numbers. The result is rounded towards\\n * zero.\\n */\\n function average(uint256 a, uint256 b) internal pure returns (uint256) {\\n // (a + b) / 2 can overflow.\\n return (a & b) + (a ^ b) / 2;\\n }\\n\\n /**\\n * @dev Returns the ceiling of the division of two numbers.\\n *\\n * This differs from standard division with `/` in that it rounds up instead\\n * of rounding down.\\n */\\n function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {\\n // (a + b - 1) / b can overflow on addition, so we distribute.\\n return a == 0 ? 0 : (a - 1) / b + 1;\\n }\\n\\n /**\\n * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0\\n * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)\\n * with further edits by Uniswap Labs also under MIT license.\\n */\\n function mulDiv(\\n uint256 x,\\n uint256 y,\\n uint256 denominator\\n ) internal pure returns (uint256 result) {\\n unchecked {\\n // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use\\n // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256\\n // variables such that product = prod1 * 2^256 + prod0.\\n uint256 prod0; // Least significant 256 bits of the product\\n uint256 prod1; // Most significant 256 bits of the product\\n assembly {\\n let mm := mulmod(x, y, not(0))\\n prod0 := mul(x, y)\\n prod1 := sub(sub(mm, prod0), lt(mm, prod0))\\n }\\n\\n // Handle non-overflow cases, 256 by 256 division.\\n if (prod1 == 0) {\\n return prod0 / denominator;\\n }\\n\\n // Make sure the result is less than 2^256. Also prevents denominator == 0.\\n require(denominator > prod1);\\n\\n ///////////////////////////////////////////////\\n // 512 by 256 division.\\n ///////////////////////////////////////////////\\n\\n // Make division exact by subtracting the remainder from [prod1 prod0].\\n uint256 remainder;\\n assembly {\\n // Compute remainder using mulmod.\\n remainder := mulmod(x, y, denominator)\\n\\n // Subtract 256 bit number from 512 bit number.\\n prod1 := sub(prod1, gt(remainder, prod0))\\n prod0 := sub(prod0, remainder)\\n }\\n\\n // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.\\n // See https://cs.stackexchange.com/q/138556/92363.\\n\\n // Does not overflow because the denominator cannot be zero at this stage in the function.\\n uint256 twos = denominator & (~denominator + 1);\\n assembly {\\n // Divide denominator by twos.\\n denominator := div(denominator, twos)\\n\\n // Divide [prod1 prod0] by twos.\\n prod0 := div(prod0, twos)\\n\\n // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.\\n twos := add(div(sub(0, twos), twos), 1)\\n }\\n\\n // Shift in bits from prod1 into prod0.\\n prod0 |= prod1 * twos;\\n\\n // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such\\n // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for\\n // four bits. That is, denominator * inv = 1 mod 2^4.\\n uint256 inverse = (3 * denominator) ^ 2;\\n\\n // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works\\n // in modular arithmetic, doubling the correct bits in each step.\\n inverse *= 2 - denominator * inverse; // inverse mod 2^8\\n inverse *= 2 - denominator * inverse; // inverse mod 2^16\\n inverse *= 2 - denominator * inverse; // inverse mod 2^32\\n inverse *= 2 - denominator * inverse; // inverse mod 2^64\\n inverse *= 2 - denominator * inverse; // inverse mod 2^128\\n inverse *= 2 - denominator * inverse; // inverse mod 2^256\\n\\n // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.\\n // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is\\n // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1\\n // is no longer required.\\n result = prod0 * inverse;\\n return result;\\n }\\n }\\n\\n /**\\n * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.\\n */\\n function mulDiv(\\n uint256 x,\\n uint256 y,\\n uint256 denominator,\\n Rounding rounding\\n ) internal pure returns (uint256) {\\n uint256 result = mulDiv(x, y, denominator);\\n if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {\\n result += 1;\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.\\n *\\n * Inspired by Henry S. Warren, Jr.'s \\\"Hacker's Delight\\\" (Chapter 11).\\n */\\n function sqrt(uint256 a) internal pure returns (uint256) {\\n if (a == 0) {\\n return 0;\\n }\\n\\n // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.\\n //\\n // We know that the \\\"msb\\\" (most significant bit) of our target number `a` is a power of 2 such that we have\\n // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.\\n //\\n // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`\\n // \\u2192 `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`\\n // \\u2192 `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`\\n //\\n // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.\\n uint256 result = 1 << (log2(a) >> 1);\\n\\n // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,\\n // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at\\n // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision\\n // into the expected uint128 result.\\n unchecked {\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n return min(result, a / result);\\n }\\n }\\n\\n /**\\n * @notice Calculates sqrt(a), following the selected rounding direction.\\n */\\n function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = sqrt(a);\\n return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);\\n }\\n }\\n\\n /**\\n * @dev Return the log in base 2, rounded down, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log2(uint256 value) internal pure returns (uint256) {\\n uint256 result = 0;\\n unchecked {\\n if (value >> 128 > 0) {\\n value >>= 128;\\n result += 128;\\n }\\n if (value >> 64 > 0) {\\n value >>= 64;\\n result += 64;\\n }\\n if (value >> 32 > 0) {\\n value >>= 32;\\n result += 32;\\n }\\n if (value >> 16 > 0) {\\n value >>= 16;\\n result += 16;\\n }\\n if (value >> 8 > 0) {\\n value >>= 8;\\n result += 8;\\n }\\n if (value >> 4 > 0) {\\n value >>= 4;\\n result += 4;\\n }\\n if (value >> 2 > 0) {\\n value >>= 2;\\n result += 2;\\n }\\n if (value >> 1 > 0) {\\n result += 1;\\n }\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Return the log in base 2, following the selected rounding direction, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = log2(value);\\n return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);\\n }\\n }\\n\\n /**\\n * @dev Return the log in base 10, rounded down, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log10(uint256 value) internal pure returns (uint256) {\\n uint256 result = 0;\\n unchecked {\\n if (value >= 10**64) {\\n value /= 10**64;\\n result += 64;\\n }\\n if (value >= 10**32) {\\n value /= 10**32;\\n result += 32;\\n }\\n if (value >= 10**16) {\\n value /= 10**16;\\n result += 16;\\n }\\n if (value >= 10**8) {\\n value /= 10**8;\\n result += 8;\\n }\\n if (value >= 10**4) {\\n value /= 10**4;\\n result += 4;\\n }\\n if (value >= 10**2) {\\n value /= 10**2;\\n result += 2;\\n }\\n if (value >= 10**1) {\\n result += 1;\\n }\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = log10(value);\\n return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);\\n }\\n }\\n\\n /**\\n * @dev Return the log in base 256, rounded down, of a positive value.\\n * Returns 0 if given 0.\\n *\\n * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.\\n */\\n function log256(uint256 value) internal pure returns (uint256) {\\n uint256 result = 0;\\n unchecked {\\n if (value >> 128 > 0) {\\n value >>= 128;\\n result += 16;\\n }\\n if (value >> 64 > 0) {\\n value >>= 64;\\n result += 8;\\n }\\n if (value >> 32 > 0) {\\n value >>= 32;\\n result += 4;\\n }\\n if (value >> 16 > 0) {\\n value >>= 16;\\n result += 2;\\n }\\n if (value >> 8 > 0) {\\n result += 1;\\n }\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = log256(value);\\n return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);\\n }\\n }\\n}\\n\",\"keccak256\":\"0xa1e8e83cd0087785df04ac79fb395d9f3684caeaf973d9e2c71caef723a3a5d6\",\"license\":\"MIT\"},\"src/Staking.sol\":{\"content\":\"// SPDX-License-Identifier: BSD-3-Clause\\npragma solidity ^0.8.19;\\nimport \\\"@openzeppelin/contracts/token/ERC20/ERC20.sol\\\";\\nimport \\\"@openzeppelin/contracts/access/AccessControl.sol\\\";\\nimport \\\"@openzeppelin/contracts/security/Pausable.sol\\\";\\n\\ninterface IPriceOracle {\\n function currentPrice() external view returns (uint32);\\n}\\n\\n/**\\n * @title Staking contract for the Swarm storage incentives\\n * @author The Swarm Authors\\n * @dev Allows users to stake tokens in order to be eligible for the Redistribution Schelling co-ordination game.\\n * Stakes are frozen or slashed by the Redistribution contract in response to violations of the\\n * protocol.\\n */\\n\\ncontract StakeRegistry is AccessControl, Pausable {\\n // ----------------------------- State variables ------------------------------\\n\\n struct Stake {\\n // Overlay of the node that is being staked\\n bytes32 overlay;\\n // Stake balance expressed through price oracle\\n uint256 committedStake;\\n // Stake balance expressed in BZZ\\n uint256 potentialStake;\\n // Block height the stake was updated, also used as flag to check if the stake is set\\n uint256 lastUpdatedBlockNumber;\\n }\\n\\n // Associate every stake id with node address data.\\n mapping(address => Stake) public stakes;\\n\\n // Role allowed to freeze and slash entries\\n bytes32 public constant REDISTRIBUTOR_ROLE = keccak256(\\\"REDISTRIBUTOR_ROLE\\\");\\n\\n // Swarm network ID\\n uint64 NetworkId;\\n\\n // The miniumum stake allowed to be staked using the Staking contract.\\n uint64 private constant MIN_STAKE = 100000000000000000;\\n\\n // Address of the staked ERC20 token\\n address public immutable bzzToken;\\n\\n // The address of the linked PriceOracle contract.\\n IPriceOracle public OracleContract;\\n\\n // ----------------------------- Events ------------------------------\\n\\n /**\\n * @dev Emitted when a stake is created or updated by `owner` of the `overlay` by `committedStake`, and `potentialStake` during `lastUpdatedBlock`.\\n */\\n event StakeUpdated(\\n address indexed owner,\\n uint256 committedStake,\\n uint256 potentialStake,\\n bytes32 overlay,\\n uint256 lastUpdatedBlock\\n );\\n\\n /**\\n * @dev Emitted when a stake for address `slashed` is slashed by `amount`.\\n */\\n event StakeSlashed(address slashed, bytes32 overlay, uint256 amount);\\n\\n /**\\n * @dev Emitted when a stake for address `frozen` is frozen for `time` blocks.\\n */\\n event StakeFrozen(address frozen, bytes32 overlay, uint256 time);\\n\\n /**\\n * @dev Emitted when a address changes overlay it uses\\n */\\n event OverlayChanged(address owner, bytes32 overlay);\\n\\n /**\\n * @dev Emitted when a stake for address is withdrawn\\n */\\n event StakeWithdrawn(address node, uint256 amount);\\n\\n // ----------------------------- Errors ------------------------------\\n\\n error TransferFailed(); // Used when token transfers fail\\n error Frozen(); // Used when an action cannot proceed because the overlay is frozen\\n error Unauthorized(); // Used where only the owner can perform the action\\n error OnlyRedistributor(); // Used when only the redistributor role is allowed\\n error OnlyPauser(); // Used when only the pauser role is allowed\\n error BelowMinimumStake(); // Node participating in game has stake below minimum treshold\\n\\n // ----------------------------- CONSTRUCTOR ------------------------------\\n\\n /**\\n * @param _bzzToken Address of the staked ERC20 token\\n * @param _NetworkId Swarm network ID\\n */\\n constructor(address _bzzToken, uint64 _NetworkId, address _oracleContract) {\\n NetworkId = _NetworkId;\\n bzzToken = _bzzToken;\\n OracleContract = IPriceOracle(_oracleContract);\\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\\n }\\n\\n ////////////////////////////////////////\\n // STATE SETTING //\\n ////////////////////////////////////////\\n\\n /**\\n * @notice Create a new stake or update an existing one, change overlay of node\\n * @dev At least `_initialBalancePerChunk*2^depth` number of tokens need to be preapproved for this contract.\\n * @param _setNonce Nonce that was used for overlay calculation.\\n * @param _addAmount Deposited amount of ERC20 tokens, equals to added Potential stake value\\n */\\n function manageStake(bytes32 _setNonce, uint256 _addAmount) external whenNotPaused {\\n bytes32 _previousOverlay = stakes[msg.sender].overlay;\\n uint256 _stakingSet = stakes[msg.sender].lastUpdatedBlockNumber;\\n bytes32 _newOverlay = keccak256(abi.encodePacked(msg.sender, reverse(NetworkId), _setNonce));\\n uint256 _addCommittedStake = _addAmount / OracleContract.currentPrice(); // losing some decimals from start 10n16 becomes 99999999999984000\\n\\n // First time adding stake, check the minimum is added\\n if (_addAmount < MIN_STAKE && _stakingSet == 0) {\\n revert BelowMinimumStake();\\n }\\n\\n if (_stakingSet != 0 && !addressNotFrozen(msg.sender)) revert Frozen();\\n uint256 updatedCommittedStake = stakes[msg.sender].committedStake + _addCommittedStake;\\n uint256 updatedPotentialStake = stakes[msg.sender].potentialStake + _addAmount;\\n\\n stakes[msg.sender] = Stake({\\n overlay: _newOverlay,\\n committedStake: updatedCommittedStake,\\n potentialStake: updatedPotentialStake,\\n lastUpdatedBlockNumber: block.number\\n });\\n\\n // Transfer tokens and emit event that stake has been updated\\n if (_addAmount > 0) {\\n if (!ERC20(bzzToken).transferFrom(msg.sender, address(this), _addAmount)) revert TransferFailed();\\n emit StakeUpdated(msg.sender, updatedCommittedStake, updatedPotentialStake, _newOverlay, block.number);\\n }\\n\\n // Emit overlay change event\\n if (_previousOverlay != _newOverlay) {\\n emit OverlayChanged(msg.sender, _newOverlay);\\n }\\n }\\n\\n /**\\n * @dev Withdraw node stake surplus\\n */\\n function withdrawFromStake() external {\\n uint256 _potentialStake = stakes[msg.sender].potentialStake;\\n uint256 _surplusStake = _potentialStake -\\n calculateEffectiveStake(stakes[msg.sender].committedStake, _potentialStake);\\n\\n if (_surplusStake > 0) {\\n stakes[msg.sender].potentialStake -= _surplusStake;\\n if (!ERC20(bzzToken).transfer(msg.sender, _surplusStake)) revert TransferFailed();\\n emit StakeWithdrawn(msg.sender, _surplusStake);\\n }\\n }\\n\\n /**\\n * @dev Migrate stake only when the staking contract is paused,\\n * can only be called by the owner of the stake\\n */\\n function migrateStake() external whenPaused {\\n // We take out all the stake so user can migrate stake to other contract\\n if (lastUpdatedBlockNumberOfAddress(msg.sender) != 0) {\\n if (!ERC20(bzzToken).transfer(msg.sender, stakes[msg.sender].potentialStake)) revert TransferFailed();\\n delete stakes[msg.sender];\\n }\\n }\\n\\n /**\\n * @dev Freeze an existing stake, can only be called by the redistributor\\n * @param _owner the addres selected\\n * @param _time penalty length in blocknumbers\\n */\\n function freezeDeposit(address _owner, uint256 _time) external {\\n if (!hasRole(REDISTRIBUTOR_ROLE, msg.sender)) revert OnlyRedistributor();\\n\\n if (stakes[_owner].lastUpdatedBlockNumber != 0) {\\n stakes[_owner].lastUpdatedBlockNumber = block.number + _time;\\n emit StakeFrozen(_owner, stakes[_owner].overlay, _time);\\n }\\n }\\n\\n /**\\n * @dev Slash an existing stake, can only be called by the `redistributor`\\n * @param _owner the _owner adress selected\\n * @param _amount the amount to be slashed\\n */\\n function slashDeposit(address _owner, uint256 _amount) external {\\n if (!hasRole(REDISTRIBUTOR_ROLE, msg.sender)) revert OnlyRedistributor();\\n\\n if (stakes[_owner].lastUpdatedBlockNumber != 0) {\\n if (stakes[_owner].potentialStake > _amount) {\\n stakes[_owner].potentialStake -= _amount;\\n stakes[_owner].lastUpdatedBlockNumber = block.number;\\n } else {\\n delete stakes[_owner];\\n }\\n }\\n emit StakeSlashed(_owner, stakes[_owner].overlay, _amount);\\n }\\n\\n function changeNetworkId(uint64 _NetworkId) external {\\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) revert Unauthorized();\\n NetworkId = _NetworkId;\\n }\\n\\n /**\\n * @dev Pause the contract. The contract is provably stopped by renouncing\\n the pauser role and the admin role after pausing, can only be called by the `PAUSER`\\n */\\n function pause() public {\\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) revert OnlyPauser();\\n _pause();\\n }\\n\\n /**\\n * @dev Unpause the contract, can only be called by the pauser when paused\\n */\\n function unPause() public {\\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) revert OnlyPauser();\\n _unpause();\\n }\\n\\n ////////////////////////////////////////\\n // STATE READING //\\n ////////////////////////////////////////\\n\\n /**\\n * @dev Checks to see if `address` is frozen.\\n * @param _owner owner of staked address\\n *\\n * Returns a boolean value indicating whether the operation succeeded.\\n */\\n function addressNotFrozen(address _owner) internal view returns (bool) {\\n return stakes[_owner].lastUpdatedBlockNumber < block.number;\\n }\\n\\n /**\\n * @dev Returns the current `effectiveStake` of `address`. previously usable stake\\n * @param _owner _owner of node\\n */\\n function nodeEffectiveStake(address _owner) public view returns (uint256) {\\n return\\n addressNotFrozen(_owner)\\n ? calculateEffectiveStake(stakes[_owner].committedStake, stakes[_owner].potentialStake)\\n : 0;\\n }\\n\\n /**\\n * @dev Check the amount that is possible to withdraw as surplus\\n */\\n function withdrawableStake() public view returns (uint256) {\\n uint256 _potentialStake = stakes[msg.sender].potentialStake;\\n return _potentialStake - calculateEffectiveStake(stakes[msg.sender].committedStake, _potentialStake);\\n }\\n\\n /**\\n * @dev Returns the `lastUpdatedBlockNumber` of `address`.\\n */\\n function lastUpdatedBlockNumberOfAddress(address _owner) public view returns (uint256) {\\n return stakes[_owner].lastUpdatedBlockNumber;\\n }\\n\\n /**\\n * @dev Returns the currently used overlay of the address.\\n * @param _owner address of node\\n */\\n function overlayOfAddress(address _owner) public view returns (bytes32) {\\n return stakes[_owner].overlay;\\n }\\n\\n function calculateEffectiveStake(\\n uint256 committedStake,\\n uint256 potentialStakeBalance\\n ) internal view returns (uint256) {\\n // Calculate the product of committedStake and unitPrice to get price in BZZ\\n uint256 committedStakeBzz = committedStake * OracleContract.currentPrice();\\n\\n // Return the minimum value between committedStakeBzz and potentialStakeBalance\\n if (committedStakeBzz < potentialStakeBalance) {\\n return committedStakeBzz;\\n } else {\\n return potentialStakeBalance;\\n }\\n }\\n\\n /**\\n * @dev Please both Endians \\ud83e\\udd5a.\\n * @param input Eth address used for overlay calculation.\\n */\\n function reverse(uint64 input) internal pure returns (uint64 v) {\\n v = input;\\n\\n // swap bytes\\n v = ((v & 0xFF00FF00FF00FF00) >> 8) | ((v & 0x00FF00FF00FF00FF) << 8);\\n\\n // swap 2-byte long pairs\\n v = ((v & 0xFFFF0000FFFF0000) >> 16) | ((v & 0x0000FFFF0000FFFF) << 16);\\n\\n // swap 4-byte long pairs\\n v = (v >> 32) | (v << 32);\\n }\\n}\\n\",\"keccak256\":\"0xcb9e16e6deff7679d1a9fc2be41d3a26d78de40f2afb600b71d6c3fad7d5dbc8\",\"license\":\"BSD-3-Clause\"}},\"version\":1}", - "bytecode": "0x60a06040523480156200001157600080fd5b5060405162001ab438038062001ab483398101604081905262000034916200015a565b6001805460ff19169055600380546001600160a01b03808616608052831668010000000000000000026001600160e01b03199091166001600160401b03851617179055620000846000336200008d565b505050620001b2565b6200009982826200009d565b5050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1662000099576000828152602081815260408083206001600160a01b03851684529091529020805460ff19166001179055620000f93390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b80516001600160a01b03811681146200015557600080fd5b919050565b6000806000606084860312156200017057600080fd5b6200017b846200013d565b60208501519093506001600160401b03811681146200019957600080fd5b9150620001a9604085016200013d565b90509250925092565b6080516118d1620001e36000396000818161029d0152818161051c015281816108c40152610a6801526118d16000f3fe608060405234801561001057600080fd5b50600436106101985760003560e01c8063830a053e116100e3578063d009b2d61161008c578063d547741f11610066578063d547741f14610405578063e8e8d87e14610418578063f7b188a51461042b57600080fd5b8063d009b2d6146103b3578063d1052d1f146103c6578063d48bfaeb146103f257600080fd5b806397adedb5116100bd57806397adedb51461035b578063a217fddf14610384578063a6471a1d1461038c57600080fd5b8063830a053e146103095780638456cb591461031c57806391d148541461032457600080fd5b80632f2ff15d116101455780635c975abb1161011f5780635c975abb146102d757806369da9114146102e25780636f1c5de71461030157600080fd5b80632f2ff15d1461027257806336568abe14610285578063420fc4db1461029857600080fd5b806312236a771161017657806312236a77146101e257806316934fc4146101ea578063248a9ca31461024157600080fd5b806301ffc9a71461019d5780630aed7b0d146101c557806310ae2147146101cf575b600080fd5b6101b06101ab36600461158f565b610433565b60405190151581526020015b60405180910390f35b6101cd6104cc565b005b6101cd6101dd3660046115d1565b6105d6565b6101cd6109eb565b6102216101f836600461160f565b600260208190526000918252604090912080546001820154928201546003909201549092919084565b6040805194855260208501939093529183015260608201526080016101bc565b61026461024f36600461162a565b60009081526020819052604090206001015490565b6040519081526020016101bc565b6101cd610280366004611643565b610b39565b6101cd610293366004611643565b610b63565b6102bf7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b0390911681526020016101bc565b60015460ff166101b0565b6003546102bf906801000000000000000090046001600160a01b031681565b610264610bf0565b61026461031736600461160f565b610c25565b6101cd610c7b565b6101b0610332366004611643565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b61026461036936600461160f565b6001600160a01b031660009081526002602052604090205490565b610264600081565b6102647f3e35b14a9f4fef84b59f9bdcd3044fc28783144b7e42bfb2cd075e6a02cb082881565b6101cd6103c136600461166f565b610cd2565b6102646103d436600461160f565b6001600160a01b031660009081526002602052604090206003015490565b6101cd610400366004611699565b610dae565b6101cd610413366004611643565b610e3a565b6101cd61042636600461166f565b610e5f565b6101cd610fcb565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f7965db0b0000000000000000000000000000000000000000000000000000000014806104c657507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008316145b92915050565b6104d4611022565b33600090815260026020526040902060030154156105d457336000818152600260208190526040918290200154905163a9059cbb60e01b8152600481019290925260248201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063a9059cbb906044016020604051808303816000875af115801561056d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061059191906116c3565b6105ae576040516312171d8360e31b815260040160405180910390fd5b336000908152600260208190526040822082815560018101839055908101829055600301555b565b6105de611074565b336000818152600260209081526040822080546003918201549154909491939265ff000000ff00600883811b91821664ff000000ff9490911c93841617601090811b67ff000000ff0000009290921666ff000000ff0000949094169390931790921c9190911780821b6bffffffffffffffff0000000016911c63ffffffff161760405160609290921b6bffffffffffffffffffffffff1916602083015260c01b7fffffffffffffffff000000000000000000000000000000000000000000000000166034820152603c8101869052605c016040516020818303038152906040528051906020012090506000600360089054906101000a90046001600160a01b03166001600160a01b0316639d1b464a6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561071c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061074091906116e5565b6107509063ffffffff1686611721565b905067016345785d8a000085108015610767575082155b1561079e576040517f8ecf3d0300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b82158015906107bf5750336000908152600260205260409020600301544311155b156107f6576040517fa8cab3d100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b33600090815260026020526040812060010154610814908390611743565b3360009081526002602081905260408220015491925090610836908890611743565b604080516080810182528681526020808201868152828401858152436060850190815233600090815260029485905295909520935184559051600184015551908201559051600390910155905086156109a0576040517f23b872dd000000000000000000000000000000000000000000000000000000008152336004820152306024820152604481018890527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906323b872dd906064016020604051808303816000875af1158015610915573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061093991906116c3565b610956576040516312171d8360e31b815260040160405180910390fd5b604080518381526020810183905290810185905243606082015233907ff3fb57c8e9287d05c0b3c8612031896c43149edcf7ca6f1b287ac836b4b5d5699060800160405180910390a25b8386146109e15760408051338152602081018690527fe188baf4bcb1c4413d19ba0eaef908614d30e8df9570d6fc4d584b75f4a37a3a910160405180910390a15b5050505050505050565b336000908152600260208190526040822090810154600190910154909190610a1390836110c7565b610a1d9083611756565b90508015610b35573360009081526002602081905260408220018054839290610a47908490611756565b909155505060405163a9059cbb60e01b8152336004820152602481018290527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063a9059cbb906044016020604051808303816000875af1158015610ab9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610add91906116c3565b610afa576040516312171d8360e31b815260040160405180910390fd5b60408051338152602081018390527f8108595eb6bad3acefa9da467d90cc2217686d5c5ac85460f8b7849c840645fc91015b60405180910390a15b5050565b600082815260208190526040902060010154610b548161116b565b610b5e8383611178565b505050565b6001600160a01b0381163314610be65760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b610b358282611216565b336000908152600260208190526040822090810154600190910154610c1590826110c7565b610c1f9082611756565b91505090565b6001600160a01b0381166000908152600260205260408120600301544311610c4e5760006104c6565b6001600160a01b038216600090815260026020819052604090912060018101549101546104c691906110c7565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff16610cca57604051631d77d47760e21b815260040160405180910390fd5b6105d4611295565b3360009081527f10fa80d2e578284bf61a483a3da84fbdd683a7e7256a9895dc4461ac543f4a16602052604090205460ff16610d2157604051630490edbf60e31b815260040160405180910390fd5b6001600160a01b03821660009081526002602052604090206003015415610b3557610d4c8143611743565b6001600160a01b038316600081815260026020908152604091829020600381019490945592548151928352928201929092529081018290527fd7863535575e7de6678ea9d340a4bfe0b84d77323bfa2ef602c3c1df82aea78090606001610b2c565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff16610e16576040517f82b4290000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6003805467ffffffffffffffff191667ffffffffffffffff92909216919091179055565b600082815260208190526040902060010154610e558161116b565b610b5e8383611216565b3360009081527f10fa80d2e578284bf61a483a3da84fbdd683a7e7256a9895dc4461ac543f4a16602052604090205460ff16610eae57604051630490edbf60e31b815260040160405180910390fd5b6001600160a01b03821660009081526002602052604090206003015415610f76576001600160a01b03821660009081526002602081905260409091200154811015610f47576001600160a01b03821660009081526002602081905260408220018054839290610f1e908490611756565b90915550506001600160a01b038216600090815260026020526040902043600390910155610f76565b6001600160a01b0382166000908152600260208190526040822082815560018101839055908101829055600301555b6001600160a01b0382166000818152600260209081526040918290205482519384529083015281018290527f5f52ce031e6eba64e8a81288196b93a3e422096e80aea812f1f5a77866359b3a90606001610b2c565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff1661101a57604051631d77d47760e21b815260040160405180910390fd5b6105d46112e9565b60015460ff166105d45760405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f74207061757365640000000000000000000000006044820152606401610bdd565b60015460ff16156105d45760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a20706175736564000000000000000000000000000000006044820152606401610bdd565b600080600360089054906101000a90046001600160a01b03166001600160a01b0316639d1b464a6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561111d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061114191906116e5565b6111519063ffffffff1685611769565b9050828110156111625790506104c6565b829150506104c6565b6111758133611322565b50565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610b35576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556111d23390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1615610b35576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b61129d611074565b6001805460ff1916811790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258335b6040516001600160a01b03909116815260200160405180910390a1565b6112f1611022565b6001805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa336112cc565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610b355761135381611395565b61135e8360206113a7565b60405160200161136f9291906117a4565b60408051601f198184030181529082905262461bcd60e51b8252610bdd91600401611825565b60606104c66001600160a01b03831660145b606060006113b6836002611769565b6113c1906002611743565b67ffffffffffffffff8111156113d9576113d9611858565b6040519080825280601f01601f191660200182016040528015611403576020820181803683370190505b5090507f30000000000000000000000000000000000000000000000000000000000000008160008151811061143a5761143a61186e565b60200101906001600160f81b031916908160001a9053507f7800000000000000000000000000000000000000000000000000000000000000816001815181106114855761148561186e565b60200101906001600160f81b031916908160001a90535060006114a9846002611769565b6114b4906001611743565b90505b6001811115611539577f303132333435363738396162636465660000000000000000000000000000000085600f16601081106114f5576114f561186e565b1a60f81b82828151811061150b5761150b61186e565b60200101906001600160f81b031916908160001a90535060049490941c9361153281611884565b90506114b7565b5083156115885760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610bdd565b9392505050565b6000602082840312156115a157600080fd5b81357fffffffff000000000000000000000000000000000000000000000000000000008116811461158857600080fd5b600080604083850312156115e457600080fd5b50508035926020909101359150565b80356001600160a01b038116811461160a57600080fd5b919050565b60006020828403121561162157600080fd5b611588826115f3565b60006020828403121561163c57600080fd5b5035919050565b6000806040838503121561165657600080fd5b82359150611666602084016115f3565b90509250929050565b6000806040838503121561168257600080fd5b61168b836115f3565b946020939093013593505050565b6000602082840312156116ab57600080fd5b813567ffffffffffffffff8116811461158857600080fd5b6000602082840312156116d557600080fd5b8151801515811461158857600080fd5b6000602082840312156116f757600080fd5b815163ffffffff8116811461158857600080fd5b634e487b7160e01b600052601160045260246000fd5b60008261173e57634e487b7160e01b600052601260045260246000fd5b500490565b808201808211156104c6576104c661170b565b818103818111156104c6576104c661170b565b80820281158282048414176104c6576104c661170b565b60005b8381101561179b578181015183820152602001611783565b50506000910152565b7f416363657373436f6e74726f6c3a206163636f756e74200000000000000000008152600083516117dc816017850160208801611780565b7f206973206d697373696e6720726f6c65200000000000000000000000000000006017918401918201528351611819816028840160208801611780565b01602801949350505050565b6020815260008251806020840152611844816040850160208701611780565b601f01601f19169190910160400192915050565b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b6000816118935761189361170b565b50600019019056fea26469706673582212208bfe4c61da67ab0201caa241720a421db808c61d5820cfde14e7a06f558c7b1164736f6c63430008130033", - "deployedBytecode": "0x608060405234801561001057600080fd5b50600436106101985760003560e01c8063830a053e116100e3578063d009b2d61161008c578063d547741f11610066578063d547741f14610405578063e8e8d87e14610418578063f7b188a51461042b57600080fd5b8063d009b2d6146103b3578063d1052d1f146103c6578063d48bfaeb146103f257600080fd5b806397adedb5116100bd57806397adedb51461035b578063a217fddf14610384578063a6471a1d1461038c57600080fd5b8063830a053e146103095780638456cb591461031c57806391d148541461032457600080fd5b80632f2ff15d116101455780635c975abb1161011f5780635c975abb146102d757806369da9114146102e25780636f1c5de71461030157600080fd5b80632f2ff15d1461027257806336568abe14610285578063420fc4db1461029857600080fd5b806312236a771161017657806312236a77146101e257806316934fc4146101ea578063248a9ca31461024157600080fd5b806301ffc9a71461019d5780630aed7b0d146101c557806310ae2147146101cf575b600080fd5b6101b06101ab36600461158f565b610433565b60405190151581526020015b60405180910390f35b6101cd6104cc565b005b6101cd6101dd3660046115d1565b6105d6565b6101cd6109eb565b6102216101f836600461160f565b600260208190526000918252604090912080546001820154928201546003909201549092919084565b6040805194855260208501939093529183015260608201526080016101bc565b61026461024f36600461162a565b60009081526020819052604090206001015490565b6040519081526020016101bc565b6101cd610280366004611643565b610b39565b6101cd610293366004611643565b610b63565b6102bf7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b0390911681526020016101bc565b60015460ff166101b0565b6003546102bf906801000000000000000090046001600160a01b031681565b610264610bf0565b61026461031736600461160f565b610c25565b6101cd610c7b565b6101b0610332366004611643565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b61026461036936600461160f565b6001600160a01b031660009081526002602052604090205490565b610264600081565b6102647f3e35b14a9f4fef84b59f9bdcd3044fc28783144b7e42bfb2cd075e6a02cb082881565b6101cd6103c136600461166f565b610cd2565b6102646103d436600461160f565b6001600160a01b031660009081526002602052604090206003015490565b6101cd610400366004611699565b610dae565b6101cd610413366004611643565b610e3a565b6101cd61042636600461166f565b610e5f565b6101cd610fcb565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f7965db0b0000000000000000000000000000000000000000000000000000000014806104c657507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008316145b92915050565b6104d4611022565b33600090815260026020526040902060030154156105d457336000818152600260208190526040918290200154905163a9059cbb60e01b8152600481019290925260248201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063a9059cbb906044016020604051808303816000875af115801561056d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061059191906116c3565b6105ae576040516312171d8360e31b815260040160405180910390fd5b336000908152600260208190526040822082815560018101839055908101829055600301555b565b6105de611074565b336000818152600260209081526040822080546003918201549154909491939265ff000000ff00600883811b91821664ff000000ff9490911c93841617601090811b67ff000000ff0000009290921666ff000000ff0000949094169390931790921c9190911780821b6bffffffffffffffff0000000016911c63ffffffff161760405160609290921b6bffffffffffffffffffffffff1916602083015260c01b7fffffffffffffffff000000000000000000000000000000000000000000000000166034820152603c8101869052605c016040516020818303038152906040528051906020012090506000600360089054906101000a90046001600160a01b03166001600160a01b0316639d1b464a6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561071c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061074091906116e5565b6107509063ffffffff1686611721565b905067016345785d8a000085108015610767575082155b1561079e576040517f8ecf3d0300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b82158015906107bf5750336000908152600260205260409020600301544311155b156107f6576040517fa8cab3d100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b33600090815260026020526040812060010154610814908390611743565b3360009081526002602081905260408220015491925090610836908890611743565b604080516080810182528681526020808201868152828401858152436060850190815233600090815260029485905295909520935184559051600184015551908201559051600390910155905086156109a0576040517f23b872dd000000000000000000000000000000000000000000000000000000008152336004820152306024820152604481018890527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906323b872dd906064016020604051808303816000875af1158015610915573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061093991906116c3565b610956576040516312171d8360e31b815260040160405180910390fd5b604080518381526020810183905290810185905243606082015233907ff3fb57c8e9287d05c0b3c8612031896c43149edcf7ca6f1b287ac836b4b5d5699060800160405180910390a25b8386146109e15760408051338152602081018690527fe188baf4bcb1c4413d19ba0eaef908614d30e8df9570d6fc4d584b75f4a37a3a910160405180910390a15b5050505050505050565b336000908152600260208190526040822090810154600190910154909190610a1390836110c7565b610a1d9083611756565b90508015610b35573360009081526002602081905260408220018054839290610a47908490611756565b909155505060405163a9059cbb60e01b8152336004820152602481018290527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063a9059cbb906044016020604051808303816000875af1158015610ab9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610add91906116c3565b610afa576040516312171d8360e31b815260040160405180910390fd5b60408051338152602081018390527f8108595eb6bad3acefa9da467d90cc2217686d5c5ac85460f8b7849c840645fc91015b60405180910390a15b5050565b600082815260208190526040902060010154610b548161116b565b610b5e8383611178565b505050565b6001600160a01b0381163314610be65760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b610b358282611216565b336000908152600260208190526040822090810154600190910154610c1590826110c7565b610c1f9082611756565b91505090565b6001600160a01b0381166000908152600260205260408120600301544311610c4e5760006104c6565b6001600160a01b038216600090815260026020819052604090912060018101549101546104c691906110c7565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff16610cca57604051631d77d47760e21b815260040160405180910390fd5b6105d4611295565b3360009081527f10fa80d2e578284bf61a483a3da84fbdd683a7e7256a9895dc4461ac543f4a16602052604090205460ff16610d2157604051630490edbf60e31b815260040160405180910390fd5b6001600160a01b03821660009081526002602052604090206003015415610b3557610d4c8143611743565b6001600160a01b038316600081815260026020908152604091829020600381019490945592548151928352928201929092529081018290527fd7863535575e7de6678ea9d340a4bfe0b84d77323bfa2ef602c3c1df82aea78090606001610b2c565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff16610e16576040517f82b4290000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6003805467ffffffffffffffff191667ffffffffffffffff92909216919091179055565b600082815260208190526040902060010154610e558161116b565b610b5e8383611216565b3360009081527f10fa80d2e578284bf61a483a3da84fbdd683a7e7256a9895dc4461ac543f4a16602052604090205460ff16610eae57604051630490edbf60e31b815260040160405180910390fd5b6001600160a01b03821660009081526002602052604090206003015415610f76576001600160a01b03821660009081526002602081905260409091200154811015610f47576001600160a01b03821660009081526002602081905260408220018054839290610f1e908490611756565b90915550506001600160a01b038216600090815260026020526040902043600390910155610f76565b6001600160a01b0382166000908152600260208190526040822082815560018101839055908101829055600301555b6001600160a01b0382166000818152600260209081526040918290205482519384529083015281018290527f5f52ce031e6eba64e8a81288196b93a3e422096e80aea812f1f5a77866359b3a90606001610b2c565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff1661101a57604051631d77d47760e21b815260040160405180910390fd5b6105d46112e9565b60015460ff166105d45760405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f74207061757365640000000000000000000000006044820152606401610bdd565b60015460ff16156105d45760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a20706175736564000000000000000000000000000000006044820152606401610bdd565b600080600360089054906101000a90046001600160a01b03166001600160a01b0316639d1b464a6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561111d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061114191906116e5565b6111519063ffffffff1685611769565b9050828110156111625790506104c6565b829150506104c6565b6111758133611322565b50565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610b35576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556111d23390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1615610b35576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b61129d611074565b6001805460ff1916811790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258335b6040516001600160a01b03909116815260200160405180910390a1565b6112f1611022565b6001805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa336112cc565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610b355761135381611395565b61135e8360206113a7565b60405160200161136f9291906117a4565b60408051601f198184030181529082905262461bcd60e51b8252610bdd91600401611825565b60606104c66001600160a01b03831660145b606060006113b6836002611769565b6113c1906002611743565b67ffffffffffffffff8111156113d9576113d9611858565b6040519080825280601f01601f191660200182016040528015611403576020820181803683370190505b5090507f30000000000000000000000000000000000000000000000000000000000000008160008151811061143a5761143a61186e565b60200101906001600160f81b031916908160001a9053507f7800000000000000000000000000000000000000000000000000000000000000816001815181106114855761148561186e565b60200101906001600160f81b031916908160001a90535060006114a9846002611769565b6114b4906001611743565b90505b6001811115611539577f303132333435363738396162636465660000000000000000000000000000000085600f16601081106114f5576114f561186e565b1a60f81b82828151811061150b5761150b61186e565b60200101906001600160f81b031916908160001a90535060049490941c9361153281611884565b90506114b7565b5083156115885760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610bdd565b9392505050565b6000602082840312156115a157600080fd5b81357fffffffff000000000000000000000000000000000000000000000000000000008116811461158857600080fd5b600080604083850312156115e457600080fd5b50508035926020909101359150565b80356001600160a01b038116811461160a57600080fd5b919050565b60006020828403121561162157600080fd5b611588826115f3565b60006020828403121561163c57600080fd5b5035919050565b6000806040838503121561165657600080fd5b82359150611666602084016115f3565b90509250929050565b6000806040838503121561168257600080fd5b61168b836115f3565b946020939093013593505050565b6000602082840312156116ab57600080fd5b813567ffffffffffffffff8116811461158857600080fd5b6000602082840312156116d557600080fd5b8151801515811461158857600080fd5b6000602082840312156116f757600080fd5b815163ffffffff8116811461158857600080fd5b634e487b7160e01b600052601160045260246000fd5b60008261173e57634e487b7160e01b600052601260045260246000fd5b500490565b808201808211156104c6576104c661170b565b818103818111156104c6576104c661170b565b80820281158282048414176104c6576104c661170b565b60005b8381101561179b578181015183820152602001611783565b50506000910152565b7f416363657373436f6e74726f6c3a206163636f756e74200000000000000000008152600083516117dc816017850160208801611780565b7f206973206d697373696e6720726f6c65200000000000000000000000000000006017918401918201528351611819816028840160208801611780565b01602801949350505050565b6020815260008251806020840152611844816040850160208701611780565b601f01601f19169190910160400192915050565b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b6000816118935761189361170b565b50600019019056fea26469706673582212208bfe4c61da67ab0201caa241720a421db808c61d5820cfde14e7a06f558c7b1164736f6c63430008130033", + "numDeployments": 7, + "solcInputHash": "294e4684ec82046939090fa9e468f317", + "metadata": "{\"compiler\":{\"version\":\"0.8.19+commit.7dd6d404\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_bzzToken\",\"type\":\"address\"},{\"internalType\":\"uint64\",\"name\":\"_NetworkId\",\"type\":\"uint64\"},{\"internalType\":\"address\",\"name\":\"_oracleContract\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[],\"name\":\"BelowMinimumStake\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"Frozen\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"OnlyPauser\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"OnlyRedistributor\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"TransferFailed\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"Unauthorized\",\"type\":\"error\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"}],\"name\":\"OverlayChanged\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"Paused\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"previousAdminRole\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"newAdminRole\",\"type\":\"bytes32\"}],\"name\":\"RoleAdminChanged\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"}],\"name\":\"RoleGranted\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"}],\"name\":\"RoleRevoked\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"frozen\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"time\",\"type\":\"uint256\"}],\"name\":\"StakeFrozen\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"slashed\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"StakeSlashed\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"committedStake\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"potentialStake\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"lastUpdatedBlock\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint8\",\"name\":\"height\",\"type\":\"uint8\"}],\"name\":\"StakeUpdated\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"node\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"StakeWithdrawn\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"Unpaused\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"DEFAULT_ADMIN_ROLE\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"OracleContract\",\"outputs\":[{\"internalType\":\"contract IPriceOracle\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"REDISTRIBUTOR_ROLE\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"bzzToken\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint64\",\"name\":\"_NetworkId\",\"type\":\"uint64\"}],\"name\":\"changeNetworkId\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_owner\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"_time\",\"type\":\"uint256\"}],\"name\":\"freezeDeposit\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"}],\"name\":\"getRoleAdmin\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"grantRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"hasRole\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_owner\",\"type\":\"address\"}],\"name\":\"heightOfAddress\",\"outputs\":[{\"internalType\":\"uint8\",\"name\":\"\",\"type\":\"uint8\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_owner\",\"type\":\"address\"}],\"name\":\"lastUpdatedBlockNumberOfAddress\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"_setNonce\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"_addAmount\",\"type\":\"uint256\"},{\"internalType\":\"uint8\",\"name\":\"_height\",\"type\":\"uint8\"}],\"name\":\"manageStake\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"migrateStake\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_owner\",\"type\":\"address\"}],\"name\":\"nodeEffectiveStake\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_owner\",\"type\":\"address\"}],\"name\":\"overlayOfAddress\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"pause\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"paused\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"renounceRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"revokeRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_owner\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"_amount\",\"type\":\"uint256\"}],\"name\":\"slashDeposit\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"name\":\"stakes\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"committedStake\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"potentialStake\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"lastUpdatedBlockNumber\",\"type\":\"uint256\"},{\"internalType\":\"uint8\",\"name\":\"height\",\"type\":\"uint8\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes4\",\"name\":\"interfaceId\",\"type\":\"bytes4\"}],\"name\":\"supportsInterface\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"unPause\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"withdrawFromStake\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"withdrawableStake\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"}],\"devdoc\":{\"author\":\"The Swarm Authors\",\"details\":\"Allows users to stake tokens in order to be eligible for the Redistribution Schelling co-ordination game. Stakes are frozen or slashed by the Redistribution contract in response to violations of the protocol.\",\"events\":{\"OverlayChanged(address,bytes32)\":{\"details\":\"Emitted when a address changes overlay it uses\"},\"Paused(address)\":{\"details\":\"Emitted when the pause is triggered by `account`.\"},\"RoleAdminChanged(bytes32,bytes32,bytes32)\":{\"details\":\"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._\"},\"RoleGranted(bytes32,address,address)\":{\"details\":\"Emitted when `account` is granted `role`. `sender` is the account that originated the contract call, an admin role bearer except when using {AccessControl-_setupRole}.\"},\"RoleRevoked(bytes32,address,address)\":{\"details\":\"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`)\"},\"StakeFrozen(address,bytes32,uint256)\":{\"details\":\"Emitted when a stake for address `frozen` is frozen for `time` blocks.\"},\"StakeSlashed(address,bytes32,uint256)\":{\"details\":\"Emitted when a stake for address `slashed` is slashed by `amount`.\"},\"StakeUpdated(address,uint256,uint256,bytes32,uint256,uint8)\":{\"details\":\"Emitted when a stake is created or updated by `owner` of the `overlay`.\"},\"StakeWithdrawn(address,uint256)\":{\"details\":\"Emitted when a stake for address is withdrawn\"},\"Unpaused(address)\":{\"details\":\"Emitted when the pause is lifted by `account`.\"}},\"kind\":\"dev\",\"methods\":{\"constructor\":{\"params\":{\"_NetworkId\":\"Swarm network ID\",\"_bzzToken\":\"Address of the staked ERC20 token\"}},\"freezeDeposit(address,uint256)\":{\"details\":\"Freeze an existing stake, can only be called by the redistributor\",\"params\":{\"_owner\":\"the addres selected\",\"_time\":\"penalty length in blocknumbers\"}},\"getRoleAdmin(bytes32)\":{\"details\":\"Returns the admin role that controls `role`. See {grantRole} and {revokeRole}. To change a role's admin, use {_setRoleAdmin}.\"},\"grantRole(bytes32,address)\":{\"details\":\"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.\"},\"hasRole(bytes32,address)\":{\"details\":\"Returns `true` if `account` has been granted `role`.\"},\"heightOfAddress(address)\":{\"details\":\"Returns the currently height of the address.\",\"params\":{\"_owner\":\"address of node\"}},\"lastUpdatedBlockNumberOfAddress(address)\":{\"details\":\"Returns the `lastUpdatedBlockNumber` of `address`.\"},\"manageStake(bytes32,uint256,uint8)\":{\"details\":\"At least `_initialBalancePerChunk*2^depth` number of tokens need to be preapproved for this contract.\",\"params\":{\"_addAmount\":\"Deposited amount of ERC20 tokens, equals to added Potential stake value\",\"_height\":\"increased reserve by registering the number of doublings\",\"_setNonce\":\"Nonce that was used for overlay calculation.\"}},\"migrateStake()\":{\"details\":\"Migrate stake only when the staking contract is paused, can only be called by the owner of the stake\"},\"nodeEffectiveStake(address)\":{\"details\":\"Returns the current `effectiveStake` of `address`. previously usable stake\",\"params\":{\"_owner\":\"_owner of node\"}},\"overlayOfAddress(address)\":{\"details\":\"Returns the currently used overlay of the address.\",\"params\":{\"_owner\":\"address of node\"}},\"pause()\":{\"details\":\"Pause the contract. The contract is provably stopped by renouncing the pauser role and the admin role after pausing, can only be called by the `PAUSER`\"},\"paused()\":{\"details\":\"Returns true if the contract is paused, and false otherwise.\"},\"renounceRole(bytes32,address)\":{\"details\":\"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.\"},\"revokeRole(bytes32,address)\":{\"details\":\"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.\"},\"slashDeposit(address,uint256)\":{\"details\":\"Slash an existing stake, can only be called by the `redistributor`\",\"params\":{\"_amount\":\"the amount to be slashed\",\"_owner\":\"the _owner adress selected\"}},\"supportsInterface(bytes4)\":{\"details\":\"See {IERC165-supportsInterface}.\"},\"unPause()\":{\"details\":\"Unpause the contract, can only be called by the pauser when paused\"},\"withdrawFromStake()\":{\"details\":\"Withdraw node stake surplus\"},\"withdrawableStake()\":{\"details\":\"Check the amount that is possible to withdraw as surplus\"}},\"title\":\"Staking contract for the Swarm storage incentives\",\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{\"manageStake(bytes32,uint256,uint8)\":{\"notice\":\"Create a new stake or update an existing one, change overlay of node\"}},\"version\":1}},\"settings\":{\"compilationTarget\":{\"src/Staking.sol\":\"StakeRegistry\"},\"evmVersion\":\"paris\",\"libraries\":{\":__CACHE_BREAKER__\":\"0x00000000d41867734bbee4c6863d9255b2b06ac1\"},\"metadata\":{\"bytecodeHash\":\"ipfs\",\"useLiteralContent\":true},\"optimizer\":{\"enabled\":true,\"runs\":1000},\"remappings\":[]},\"sources\":{\"@openzeppelin/contracts/access/AccessControl.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (access/AccessControl.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./IAccessControl.sol\\\";\\nimport \\\"../utils/Context.sol\\\";\\nimport \\\"../utils/Strings.sol\\\";\\nimport \\\"../utils/introspection/ERC165.sol\\\";\\n\\n/**\\n * @dev Contract module that allows children to implement role-based access\\n * control mechanisms. This is a lightweight version that doesn't allow enumerating role\\n * members except through off-chain means by accessing the contract event logs. Some\\n * applications may benefit from on-chain enumerability, for those cases see\\n * {AccessControlEnumerable}.\\n *\\n * Roles are referred to by their `bytes32` identifier. These should be exposed\\n * in the external API and be unique. The best way to achieve this is by\\n * using `public constant` hash digests:\\n *\\n * ```\\n * bytes32 public constant MY_ROLE = keccak256(\\\"MY_ROLE\\\");\\n * ```\\n *\\n * Roles can be used to represent a set of permissions. To restrict access to a\\n * function call, use {hasRole}:\\n *\\n * ```\\n * function foo() public {\\n * require(hasRole(MY_ROLE, msg.sender));\\n * ...\\n * }\\n * ```\\n *\\n * Roles can be granted and revoked dynamically via the {grantRole} and\\n * {revokeRole} functions. Each role has an associated admin role, and only\\n * accounts that have a role's admin role can call {grantRole} and {revokeRole}.\\n *\\n * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means\\n * that only accounts with this role will be able to grant or revoke other\\n * roles. More complex role relationships can be created by using\\n * {_setRoleAdmin}.\\n *\\n * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to\\n * grant and revoke this role. Extra precautions should be taken to secure\\n * accounts that have been granted it.\\n */\\nabstract contract AccessControl is Context, IAccessControl, ERC165 {\\n struct RoleData {\\n mapping(address => bool) members;\\n bytes32 adminRole;\\n }\\n\\n mapping(bytes32 => RoleData) private _roles;\\n\\n bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;\\n\\n /**\\n * @dev Modifier that checks that an account has a specific role. Reverts\\n * with a standardized message including the required role.\\n *\\n * The format of the revert reason is given by the following regular expression:\\n *\\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\\n *\\n * _Available since v4.1._\\n */\\n modifier onlyRole(bytes32 role) {\\n _checkRole(role);\\n _;\\n }\\n\\n /**\\n * @dev See {IERC165-supportsInterface}.\\n */\\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);\\n }\\n\\n /**\\n * @dev Returns `true` if `account` has been granted `role`.\\n */\\n function hasRole(bytes32 role, address account) public view virtual override returns (bool) {\\n return _roles[role].members[account];\\n }\\n\\n /**\\n * @dev Revert with a standard message if `_msgSender()` is missing `role`.\\n * Overriding this function changes the behavior of the {onlyRole} modifier.\\n *\\n * Format of the revert message is described in {_checkRole}.\\n *\\n * _Available since v4.6._\\n */\\n function _checkRole(bytes32 role) internal view virtual {\\n _checkRole(role, _msgSender());\\n }\\n\\n /**\\n * @dev Revert with a standard message if `account` is missing `role`.\\n *\\n * The format of the revert reason is given by the following regular expression:\\n *\\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\\n */\\n function _checkRole(bytes32 role, address account) internal view virtual {\\n if (!hasRole(role, account)) {\\n revert(\\n string(\\n abi.encodePacked(\\n \\\"AccessControl: account \\\",\\n Strings.toHexString(account),\\n \\\" is missing role \\\",\\n Strings.toHexString(uint256(role), 32)\\n )\\n )\\n );\\n }\\n }\\n\\n /**\\n * @dev Returns the admin role that controls `role`. See {grantRole} and\\n * {revokeRole}.\\n *\\n * To change a role's admin, use {_setRoleAdmin}.\\n */\\n function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {\\n return _roles[role].adminRole;\\n }\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * If `account` had not been already granted `role`, emits a {RoleGranted}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n *\\n * May emit a {RoleGranted} event.\\n */\\n function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\\n _grantRole(role, account);\\n }\\n\\n /**\\n * @dev Revokes `role` from `account`.\\n *\\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n *\\n * May emit a {RoleRevoked} event.\\n */\\n function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\\n _revokeRole(role, account);\\n }\\n\\n /**\\n * @dev Revokes `role` from the calling account.\\n *\\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\\n * purpose is to provide a mechanism for accounts to lose their privileges\\n * if they are compromised (such as when a trusted device is misplaced).\\n *\\n * If the calling account had been revoked `role`, emits a {RoleRevoked}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must be `account`.\\n *\\n * May emit a {RoleRevoked} event.\\n */\\n function renounceRole(bytes32 role, address account) public virtual override {\\n require(account == _msgSender(), \\\"AccessControl: can only renounce roles for self\\\");\\n\\n _revokeRole(role, account);\\n }\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * If `account` had not been already granted `role`, emits a {RoleGranted}\\n * event. Note that unlike {grantRole}, this function doesn't perform any\\n * checks on the calling account.\\n *\\n * May emit a {RoleGranted} event.\\n *\\n * [WARNING]\\n * ====\\n * This function should only be called from the constructor when setting\\n * up the initial roles for the system.\\n *\\n * Using this function in any other way is effectively circumventing the admin\\n * system imposed by {AccessControl}.\\n * ====\\n *\\n * NOTE: This function is deprecated in favor of {_grantRole}.\\n */\\n function _setupRole(bytes32 role, address account) internal virtual {\\n _grantRole(role, account);\\n }\\n\\n /**\\n * @dev Sets `adminRole` as ``role``'s admin role.\\n *\\n * Emits a {RoleAdminChanged} event.\\n */\\n function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {\\n bytes32 previousAdminRole = getRoleAdmin(role);\\n _roles[role].adminRole = adminRole;\\n emit RoleAdminChanged(role, previousAdminRole, adminRole);\\n }\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * Internal function without access restriction.\\n *\\n * May emit a {RoleGranted} event.\\n */\\n function _grantRole(bytes32 role, address account) internal virtual {\\n if (!hasRole(role, account)) {\\n _roles[role].members[account] = true;\\n emit RoleGranted(role, account, _msgSender());\\n }\\n }\\n\\n /**\\n * @dev Revokes `role` from `account`.\\n *\\n * Internal function without access restriction.\\n *\\n * May emit a {RoleRevoked} event.\\n */\\n function _revokeRole(bytes32 role, address account) internal virtual {\\n if (hasRole(role, account)) {\\n _roles[role].members[account] = false;\\n emit RoleRevoked(role, account, _msgSender());\\n }\\n }\\n}\\n\",\"keccak256\":\"0x67e3daf189111d6d5b0464ed09cf9f0605a22c4b965a7fcecd707101faff008a\",\"license\":\"MIT\"},\"@openzeppelin/contracts/access/IAccessControl.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev External interface of AccessControl declared to support ERC165 detection.\\n */\\ninterface IAccessControl {\\n /**\\n * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`\\n *\\n * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite\\n * {RoleAdminChanged} not being emitted signaling this.\\n *\\n * _Available since v3.1._\\n */\\n event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);\\n\\n /**\\n * @dev Emitted when `account` is granted `role`.\\n *\\n * `sender` is the account that originated the contract call, an admin role\\n * bearer except when using {AccessControl-_setupRole}.\\n */\\n event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);\\n\\n /**\\n * @dev Emitted when `account` is revoked `role`.\\n *\\n * `sender` is the account that originated the contract call:\\n * - if using `revokeRole`, it is the admin role bearer\\n * - if using `renounceRole`, it is the role bearer (i.e. `account`)\\n */\\n event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);\\n\\n /**\\n * @dev Returns `true` if `account` has been granted `role`.\\n */\\n function hasRole(bytes32 role, address account) external view returns (bool);\\n\\n /**\\n * @dev Returns the admin role that controls `role`. See {grantRole} and\\n * {revokeRole}.\\n *\\n * To change a role's admin, use {AccessControl-_setRoleAdmin}.\\n */\\n function getRoleAdmin(bytes32 role) external view returns (bytes32);\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * If `account` had not been already granted `role`, emits a {RoleGranted}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n */\\n function grantRole(bytes32 role, address account) external;\\n\\n /**\\n * @dev Revokes `role` from `account`.\\n *\\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n */\\n function revokeRole(bytes32 role, address account) external;\\n\\n /**\\n * @dev Revokes `role` from the calling account.\\n *\\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\\n * purpose is to provide a mechanism for accounts to lose their privileges\\n * if they are compromised (such as when a trusted device is misplaced).\\n *\\n * If the calling account had been granted `role`, emits a {RoleRevoked}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must be `account`.\\n */\\n function renounceRole(bytes32 role, address account) external;\\n}\\n\",\"keccak256\":\"0x59ce320a585d7e1f163cd70390a0ef2ff9cec832e2aa544293a00692465a7a57\",\"license\":\"MIT\"},\"@openzeppelin/contracts/security/Pausable.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"../utils/Context.sol\\\";\\n\\n/**\\n * @dev Contract module which allows children to implement an emergency stop\\n * mechanism that can be triggered by an authorized account.\\n *\\n * This module is used through inheritance. It will make available the\\n * modifiers `whenNotPaused` and `whenPaused`, which can be applied to\\n * the functions of your contract. Note that they will not be pausable by\\n * simply including this module, only once the modifiers are put in place.\\n */\\nabstract contract Pausable is Context {\\n /**\\n * @dev Emitted when the pause is triggered by `account`.\\n */\\n event Paused(address account);\\n\\n /**\\n * @dev Emitted when the pause is lifted by `account`.\\n */\\n event Unpaused(address account);\\n\\n bool private _paused;\\n\\n /**\\n * @dev Initializes the contract in unpaused state.\\n */\\n constructor() {\\n _paused = false;\\n }\\n\\n /**\\n * @dev Modifier to make a function callable only when the contract is not paused.\\n *\\n * Requirements:\\n *\\n * - The contract must not be paused.\\n */\\n modifier whenNotPaused() {\\n _requireNotPaused();\\n _;\\n }\\n\\n /**\\n * @dev Modifier to make a function callable only when the contract is paused.\\n *\\n * Requirements:\\n *\\n * - The contract must be paused.\\n */\\n modifier whenPaused() {\\n _requirePaused();\\n _;\\n }\\n\\n /**\\n * @dev Returns true if the contract is paused, and false otherwise.\\n */\\n function paused() public view virtual returns (bool) {\\n return _paused;\\n }\\n\\n /**\\n * @dev Throws if the contract is paused.\\n */\\n function _requireNotPaused() internal view virtual {\\n require(!paused(), \\\"Pausable: paused\\\");\\n }\\n\\n /**\\n * @dev Throws if the contract is not paused.\\n */\\n function _requirePaused() internal view virtual {\\n require(paused(), \\\"Pausable: not paused\\\");\\n }\\n\\n /**\\n * @dev Triggers stopped state.\\n *\\n * Requirements:\\n *\\n * - The contract must not be paused.\\n */\\n function _pause() internal virtual whenNotPaused {\\n _paused = true;\\n emit Paused(_msgSender());\\n }\\n\\n /**\\n * @dev Returns to normal state.\\n *\\n * Requirements:\\n *\\n * - The contract must be paused.\\n */\\n function _unpause() internal virtual whenPaused {\\n _paused = false;\\n emit Unpaused(_msgSender());\\n }\\n}\\n\",\"keccak256\":\"0x0849d93b16c9940beb286a7864ed02724b248b93e0d80ef6355af5ef15c64773\",\"license\":\"MIT\"},\"@openzeppelin/contracts/token/ERC20/ERC20.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/ERC20.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./IERC20.sol\\\";\\nimport \\\"./extensions/IERC20Metadata.sol\\\";\\nimport \\\"../../utils/Context.sol\\\";\\n\\n/**\\n * @dev Implementation of the {IERC20} interface.\\n *\\n * This implementation is agnostic to the way tokens are created. This means\\n * that a supply mechanism has to be added in a derived contract using {_mint}.\\n * For a generic mechanism see {ERC20PresetMinterPauser}.\\n *\\n * TIP: For a detailed writeup see our guide\\n * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How\\n * to implement supply mechanisms].\\n *\\n * We have followed general OpenZeppelin Contracts guidelines: functions revert\\n * instead returning `false` on failure. This behavior is nonetheless\\n * conventional and does not conflict with the expectations of ERC20\\n * applications.\\n *\\n * Additionally, an {Approval} event is emitted on calls to {transferFrom}.\\n * This allows applications to reconstruct the allowance for all accounts just\\n * by listening to said events. Other implementations of the EIP may not emit\\n * these events, as it isn't required by the specification.\\n *\\n * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}\\n * functions have been added to mitigate the well-known issues around setting\\n * allowances. See {IERC20-approve}.\\n */\\ncontract ERC20 is Context, IERC20, IERC20Metadata {\\n mapping(address => uint256) private _balances;\\n\\n mapping(address => mapping(address => uint256)) private _allowances;\\n\\n uint256 private _totalSupply;\\n\\n string private _name;\\n string private _symbol;\\n\\n /**\\n * @dev Sets the values for {name} and {symbol}.\\n *\\n * The default value of {decimals} is 18. To select a different value for\\n * {decimals} you should overload it.\\n *\\n * All two of these values are immutable: they can only be set once during\\n * construction.\\n */\\n constructor(string memory name_, string memory symbol_) {\\n _name = name_;\\n _symbol = symbol_;\\n }\\n\\n /**\\n * @dev Returns the name of the token.\\n */\\n function name() public view virtual override returns (string memory) {\\n return _name;\\n }\\n\\n /**\\n * @dev Returns the symbol of the token, usually a shorter version of the\\n * name.\\n */\\n function symbol() public view virtual override returns (string memory) {\\n return _symbol;\\n }\\n\\n /**\\n * @dev Returns the number of decimals used to get its user representation.\\n * For example, if `decimals` equals `2`, a balance of `505` tokens should\\n * be displayed to a user as `5.05` (`505 / 10 ** 2`).\\n *\\n * Tokens usually opt for a value of 18, imitating the relationship between\\n * Ether and Wei. This is the value {ERC20} uses, unless this function is\\n * overridden;\\n *\\n * NOTE: This information is only used for _display_ purposes: it in\\n * no way affects any of the arithmetic of the contract, including\\n * {IERC20-balanceOf} and {IERC20-transfer}.\\n */\\n function decimals() public view virtual override returns (uint8) {\\n return 18;\\n }\\n\\n /**\\n * @dev See {IERC20-totalSupply}.\\n */\\n function totalSupply() public view virtual override returns (uint256) {\\n return _totalSupply;\\n }\\n\\n /**\\n * @dev See {IERC20-balanceOf}.\\n */\\n function balanceOf(address account) public view virtual override returns (uint256) {\\n return _balances[account];\\n }\\n\\n /**\\n * @dev See {IERC20-transfer}.\\n *\\n * Requirements:\\n *\\n * - `to` cannot be the zero address.\\n * - the caller must have a balance of at least `amount`.\\n */\\n function transfer(address to, uint256 amount) public virtual override returns (bool) {\\n address owner = _msgSender();\\n _transfer(owner, to, amount);\\n return true;\\n }\\n\\n /**\\n * @dev See {IERC20-allowance}.\\n */\\n function allowance(address owner, address spender) public view virtual override returns (uint256) {\\n return _allowances[owner][spender];\\n }\\n\\n /**\\n * @dev See {IERC20-approve}.\\n *\\n * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on\\n * `transferFrom`. This is semantically equivalent to an infinite approval.\\n *\\n * Requirements:\\n *\\n * - `spender` cannot be the zero address.\\n */\\n function approve(address spender, uint256 amount) public virtual override returns (bool) {\\n address owner = _msgSender();\\n _approve(owner, spender, amount);\\n return true;\\n }\\n\\n /**\\n * @dev See {IERC20-transferFrom}.\\n *\\n * Emits an {Approval} event indicating the updated allowance. This is not\\n * required by the EIP. See the note at the beginning of {ERC20}.\\n *\\n * NOTE: Does not update the allowance if the current allowance\\n * is the maximum `uint256`.\\n *\\n * Requirements:\\n *\\n * - `from` and `to` cannot be the zero address.\\n * - `from` must have a balance of at least `amount`.\\n * - the caller must have allowance for ``from``'s tokens of at least\\n * `amount`.\\n */\\n function transferFrom(\\n address from,\\n address to,\\n uint256 amount\\n ) public virtual override returns (bool) {\\n address spender = _msgSender();\\n _spendAllowance(from, spender, amount);\\n _transfer(from, to, amount);\\n return true;\\n }\\n\\n /**\\n * @dev Atomically increases the allowance granted to `spender` by the caller.\\n *\\n * This is an alternative to {approve} that can be used as a mitigation for\\n * problems described in {IERC20-approve}.\\n *\\n * Emits an {Approval} event indicating the updated allowance.\\n *\\n * Requirements:\\n *\\n * - `spender` cannot be the zero address.\\n */\\n function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {\\n address owner = _msgSender();\\n _approve(owner, spender, allowance(owner, spender) + addedValue);\\n return true;\\n }\\n\\n /**\\n * @dev Atomically decreases the allowance granted to `spender` by the caller.\\n *\\n * This is an alternative to {approve} that can be used as a mitigation for\\n * problems described in {IERC20-approve}.\\n *\\n * Emits an {Approval} event indicating the updated allowance.\\n *\\n * Requirements:\\n *\\n * - `spender` cannot be the zero address.\\n * - `spender` must have allowance for the caller of at least\\n * `subtractedValue`.\\n */\\n function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {\\n address owner = _msgSender();\\n uint256 currentAllowance = allowance(owner, spender);\\n require(currentAllowance >= subtractedValue, \\\"ERC20: decreased allowance below zero\\\");\\n unchecked {\\n _approve(owner, spender, currentAllowance - subtractedValue);\\n }\\n\\n return true;\\n }\\n\\n /**\\n * @dev Moves `amount` of tokens from `from` to `to`.\\n *\\n * This internal function is equivalent to {transfer}, and can be used to\\n * e.g. implement automatic token fees, slashing mechanisms, etc.\\n *\\n * Emits a {Transfer} event.\\n *\\n * Requirements:\\n *\\n * - `from` cannot be the zero address.\\n * - `to` cannot be the zero address.\\n * - `from` must have a balance of at least `amount`.\\n */\\n function _transfer(\\n address from,\\n address to,\\n uint256 amount\\n ) internal virtual {\\n require(from != address(0), \\\"ERC20: transfer from the zero address\\\");\\n require(to != address(0), \\\"ERC20: transfer to the zero address\\\");\\n\\n _beforeTokenTransfer(from, to, amount);\\n\\n uint256 fromBalance = _balances[from];\\n require(fromBalance >= amount, \\\"ERC20: transfer amount exceeds balance\\\");\\n unchecked {\\n _balances[from] = fromBalance - amount;\\n // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by\\n // decrementing then incrementing.\\n _balances[to] += amount;\\n }\\n\\n emit Transfer(from, to, amount);\\n\\n _afterTokenTransfer(from, to, amount);\\n }\\n\\n /** @dev Creates `amount` tokens and assigns them to `account`, increasing\\n * the total supply.\\n *\\n * Emits a {Transfer} event with `from` set to the zero address.\\n *\\n * Requirements:\\n *\\n * - `account` cannot be the zero address.\\n */\\n function _mint(address account, uint256 amount) internal virtual {\\n require(account != address(0), \\\"ERC20: mint to the zero address\\\");\\n\\n _beforeTokenTransfer(address(0), account, amount);\\n\\n _totalSupply += amount;\\n unchecked {\\n // Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.\\n _balances[account] += amount;\\n }\\n emit Transfer(address(0), account, amount);\\n\\n _afterTokenTransfer(address(0), account, amount);\\n }\\n\\n /**\\n * @dev Destroys `amount` tokens from `account`, reducing the\\n * total supply.\\n *\\n * Emits a {Transfer} event with `to` set to the zero address.\\n *\\n * Requirements:\\n *\\n * - `account` cannot be the zero address.\\n * - `account` must have at least `amount` tokens.\\n */\\n function _burn(address account, uint256 amount) internal virtual {\\n require(account != address(0), \\\"ERC20: burn from the zero address\\\");\\n\\n _beforeTokenTransfer(account, address(0), amount);\\n\\n uint256 accountBalance = _balances[account];\\n require(accountBalance >= amount, \\\"ERC20: burn amount exceeds balance\\\");\\n unchecked {\\n _balances[account] = accountBalance - amount;\\n // Overflow not possible: amount <= accountBalance <= totalSupply.\\n _totalSupply -= amount;\\n }\\n\\n emit Transfer(account, address(0), amount);\\n\\n _afterTokenTransfer(account, address(0), amount);\\n }\\n\\n /**\\n * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.\\n *\\n * This internal function is equivalent to `approve`, and can be used to\\n * e.g. set automatic allowances for certain subsystems, etc.\\n *\\n * Emits an {Approval} event.\\n *\\n * Requirements:\\n *\\n * - `owner` cannot be the zero address.\\n * - `spender` cannot be the zero address.\\n */\\n function _approve(\\n address owner,\\n address spender,\\n uint256 amount\\n ) internal virtual {\\n require(owner != address(0), \\\"ERC20: approve from the zero address\\\");\\n require(spender != address(0), \\\"ERC20: approve to the zero address\\\");\\n\\n _allowances[owner][spender] = amount;\\n emit Approval(owner, spender, amount);\\n }\\n\\n /**\\n * @dev Updates `owner` s allowance for `spender` based on spent `amount`.\\n *\\n * Does not update the allowance amount in case of infinite allowance.\\n * Revert if not enough allowance is available.\\n *\\n * Might emit an {Approval} event.\\n */\\n function _spendAllowance(\\n address owner,\\n address spender,\\n uint256 amount\\n ) internal virtual {\\n uint256 currentAllowance = allowance(owner, spender);\\n if (currentAllowance != type(uint256).max) {\\n require(currentAllowance >= amount, \\\"ERC20: insufficient allowance\\\");\\n unchecked {\\n _approve(owner, spender, currentAllowance - amount);\\n }\\n }\\n }\\n\\n /**\\n * @dev Hook that is called before any transfer of tokens. This includes\\n * minting and burning.\\n *\\n * Calling conditions:\\n *\\n * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\\n * will be transferred to `to`.\\n * - when `from` is zero, `amount` tokens will be minted for `to`.\\n * - when `to` is zero, `amount` of ``from``'s tokens will be burned.\\n * - `from` and `to` are never both zero.\\n *\\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\\n */\\n function _beforeTokenTransfer(\\n address from,\\n address to,\\n uint256 amount\\n ) internal virtual {}\\n\\n /**\\n * @dev Hook that is called after any transfer of tokens. This includes\\n * minting and burning.\\n *\\n * Calling conditions:\\n *\\n * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\\n * has been transferred to `to`.\\n * - when `from` is zero, `amount` tokens have been minted for `to`.\\n * - when `to` is zero, `amount` of ``from``'s tokens have been burned.\\n * - `from` and `to` are never both zero.\\n *\\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\\n */\\n function _afterTokenTransfer(\\n address from,\\n address to,\\n uint256 amount\\n ) internal virtual {}\\n}\\n\",\"keccak256\":\"0x4ffc0547c02ad22925310c585c0f166f8759e2648a09e9b489100c42f15dd98d\",\"license\":\"MIT\"},\"@openzeppelin/contracts/token/ERC20/IERC20.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Interface of the ERC20 standard as defined in the EIP.\\n */\\ninterface IERC20 {\\n /**\\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\\n * another (`to`).\\n *\\n * Note that `value` may be zero.\\n */\\n event Transfer(address indexed from, address indexed to, uint256 value);\\n\\n /**\\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\\n * a call to {approve}. `value` is the new allowance.\\n */\\n event Approval(address indexed owner, address indexed spender, uint256 value);\\n\\n /**\\n * @dev Returns the amount of tokens in existence.\\n */\\n function totalSupply() external view returns (uint256);\\n\\n /**\\n * @dev Returns the amount of tokens owned by `account`.\\n */\\n function balanceOf(address account) external view returns (uint256);\\n\\n /**\\n * @dev Moves `amount` tokens from the caller's account to `to`.\\n *\\n * Returns a boolean value indicating whether the operation succeeded.\\n *\\n * Emits a {Transfer} event.\\n */\\n function transfer(address to, uint256 amount) external returns (bool);\\n\\n /**\\n * @dev Returns the remaining number of tokens that `spender` will be\\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\\n * zero by default.\\n *\\n * This value changes when {approve} or {transferFrom} are called.\\n */\\n function allowance(address owner, address spender) external view returns (uint256);\\n\\n /**\\n * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\\n *\\n * Returns a boolean value indicating whether the operation succeeded.\\n *\\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\\n * that someone may use both the old and the new allowance by unfortunate\\n * transaction ordering. One possible solution to mitigate this race\\n * condition is to first reduce the spender's allowance to 0 and set the\\n * desired value afterwards:\\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\\n *\\n * Emits an {Approval} event.\\n */\\n function approve(address spender, uint256 amount) external returns (bool);\\n\\n /**\\n * @dev Moves `amount` tokens from `from` to `to` using the\\n * allowance mechanism. `amount` is then deducted from the caller's\\n * allowance.\\n *\\n * Returns a boolean value indicating whether the operation succeeded.\\n *\\n * Emits a {Transfer} event.\\n */\\n function transferFrom(\\n address from,\\n address to,\\n uint256 amount\\n ) external returns (bool);\\n}\\n\",\"keccak256\":\"0x9750c6b834f7b43000631af5cc30001c5f547b3ceb3635488f140f60e897ea6b\",\"license\":\"MIT\"},\"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"../IERC20.sol\\\";\\n\\n/**\\n * @dev Interface for the optional metadata functions from the ERC20 standard.\\n *\\n * _Available since v4.1._\\n */\\ninterface IERC20Metadata is IERC20 {\\n /**\\n * @dev Returns the name of the token.\\n */\\n function name() external view returns (string memory);\\n\\n /**\\n * @dev Returns the symbol of the token.\\n */\\n function symbol() external view returns (string memory);\\n\\n /**\\n * @dev Returns the decimals places of the token.\\n */\\n function decimals() external view returns (uint8);\\n}\\n\",\"keccak256\":\"0x8de418a5503946cabe331f35fe242d3201a73f67f77aaeb7110acb1f30423aca\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/Context.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Provides information about the current execution context, including the\\n * sender of the transaction and its data. While these are generally available\\n * via msg.sender and msg.data, they should not be accessed in such a direct\\n * manner, since when dealing with meta-transactions the account sending and\\n * paying for execution may not be the actual sender (as far as an application\\n * is concerned).\\n *\\n * This contract is only required for intermediate, library-like contracts.\\n */\\nabstract contract Context {\\n function _msgSender() internal view virtual returns (address) {\\n return msg.sender;\\n }\\n\\n function _msgData() internal view virtual returns (bytes calldata) {\\n return msg.data;\\n }\\n}\\n\",\"keccak256\":\"0xe2e337e6dde9ef6b680e07338c493ebea1b5fd09b43424112868e9cc1706bca7\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/Strings.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./math/Math.sol\\\";\\n\\n/**\\n * @dev String operations.\\n */\\nlibrary Strings {\\n bytes16 private constant _SYMBOLS = \\\"0123456789abcdef\\\";\\n uint8 private constant _ADDRESS_LENGTH = 20;\\n\\n /**\\n * @dev Converts a `uint256` to its ASCII `string` decimal representation.\\n */\\n function toString(uint256 value) internal pure returns (string memory) {\\n unchecked {\\n uint256 length = Math.log10(value) + 1;\\n string memory buffer = new string(length);\\n uint256 ptr;\\n /// @solidity memory-safe-assembly\\n assembly {\\n ptr := add(buffer, add(32, length))\\n }\\n while (true) {\\n ptr--;\\n /// @solidity memory-safe-assembly\\n assembly {\\n mstore8(ptr, byte(mod(value, 10), _SYMBOLS))\\n }\\n value /= 10;\\n if (value == 0) break;\\n }\\n return buffer;\\n }\\n }\\n\\n /**\\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\\n */\\n function toHexString(uint256 value) internal pure returns (string memory) {\\n unchecked {\\n return toHexString(value, Math.log256(value) + 1);\\n }\\n }\\n\\n /**\\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\\n */\\n function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\\n bytes memory buffer = new bytes(2 * length + 2);\\n buffer[0] = \\\"0\\\";\\n buffer[1] = \\\"x\\\";\\n for (uint256 i = 2 * length + 1; i > 1; --i) {\\n buffer[i] = _SYMBOLS[value & 0xf];\\n value >>= 4;\\n }\\n require(value == 0, \\\"Strings: hex length insufficient\\\");\\n return string(buffer);\\n }\\n\\n /**\\n * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.\\n */\\n function toHexString(address addr) internal pure returns (string memory) {\\n return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);\\n }\\n}\\n\",\"keccak256\":\"0xa4d1d62251f8574deb032a35fc948386a9b4de74b812d4f545a1ac120486b48a\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/introspection/ERC165.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./IERC165.sol\\\";\\n\\n/**\\n * @dev Implementation of the {IERC165} interface.\\n *\\n * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check\\n * for the additional interface id that will be supported. For example:\\n *\\n * ```solidity\\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\\n * }\\n * ```\\n *\\n * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.\\n */\\nabstract contract ERC165 is IERC165 {\\n /**\\n * @dev See {IERC165-supportsInterface}.\\n */\\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n return interfaceId == type(IERC165).interfaceId;\\n }\\n}\\n\",\"keccak256\":\"0xd10975de010d89fd1c78dc5e8a9a7e7f496198085c151648f20cba166b32582b\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/introspection/IERC165.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Interface of the ERC165 standard, as defined in the\\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\\n *\\n * Implementers can declare support of contract interfaces, which can then be\\n * queried by others ({ERC165Checker}).\\n *\\n * For an implementation, see {ERC165}.\\n */\\ninterface IERC165 {\\n /**\\n * @dev Returns true if this contract implements the interface defined by\\n * `interfaceId`. See the corresponding\\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\\n * to learn more about how these ids are created.\\n *\\n * This function call must use less than 30 000 gas.\\n */\\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\\n}\\n\",\"keccak256\":\"0x447a5f3ddc18419d41ff92b3773fb86471b1db25773e07f877f548918a185bf1\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/math/Math.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Standard math utilities missing in the Solidity language.\\n */\\nlibrary Math {\\n enum Rounding {\\n Down, // Toward negative infinity\\n Up, // Toward infinity\\n Zero // Toward zero\\n }\\n\\n /**\\n * @dev Returns the largest of two numbers.\\n */\\n function max(uint256 a, uint256 b) internal pure returns (uint256) {\\n return a > b ? a : b;\\n }\\n\\n /**\\n * @dev Returns the smallest of two numbers.\\n */\\n function min(uint256 a, uint256 b) internal pure returns (uint256) {\\n return a < b ? a : b;\\n }\\n\\n /**\\n * @dev Returns the average of two numbers. The result is rounded towards\\n * zero.\\n */\\n function average(uint256 a, uint256 b) internal pure returns (uint256) {\\n // (a + b) / 2 can overflow.\\n return (a & b) + (a ^ b) / 2;\\n }\\n\\n /**\\n * @dev Returns the ceiling of the division of two numbers.\\n *\\n * This differs from standard division with `/` in that it rounds up instead\\n * of rounding down.\\n */\\n function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {\\n // (a + b - 1) / b can overflow on addition, so we distribute.\\n return a == 0 ? 0 : (a - 1) / b + 1;\\n }\\n\\n /**\\n * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0\\n * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)\\n * with further edits by Uniswap Labs also under MIT license.\\n */\\n function mulDiv(\\n uint256 x,\\n uint256 y,\\n uint256 denominator\\n ) internal pure returns (uint256 result) {\\n unchecked {\\n // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use\\n // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256\\n // variables such that product = prod1 * 2^256 + prod0.\\n uint256 prod0; // Least significant 256 bits of the product\\n uint256 prod1; // Most significant 256 bits of the product\\n assembly {\\n let mm := mulmod(x, y, not(0))\\n prod0 := mul(x, y)\\n prod1 := sub(sub(mm, prod0), lt(mm, prod0))\\n }\\n\\n // Handle non-overflow cases, 256 by 256 division.\\n if (prod1 == 0) {\\n return prod0 / denominator;\\n }\\n\\n // Make sure the result is less than 2^256. Also prevents denominator == 0.\\n require(denominator > prod1);\\n\\n ///////////////////////////////////////////////\\n // 512 by 256 division.\\n ///////////////////////////////////////////////\\n\\n // Make division exact by subtracting the remainder from [prod1 prod0].\\n uint256 remainder;\\n assembly {\\n // Compute remainder using mulmod.\\n remainder := mulmod(x, y, denominator)\\n\\n // Subtract 256 bit number from 512 bit number.\\n prod1 := sub(prod1, gt(remainder, prod0))\\n prod0 := sub(prod0, remainder)\\n }\\n\\n // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.\\n // See https://cs.stackexchange.com/q/138556/92363.\\n\\n // Does not overflow because the denominator cannot be zero at this stage in the function.\\n uint256 twos = denominator & (~denominator + 1);\\n assembly {\\n // Divide denominator by twos.\\n denominator := div(denominator, twos)\\n\\n // Divide [prod1 prod0] by twos.\\n prod0 := div(prod0, twos)\\n\\n // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.\\n twos := add(div(sub(0, twos), twos), 1)\\n }\\n\\n // Shift in bits from prod1 into prod0.\\n prod0 |= prod1 * twos;\\n\\n // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such\\n // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for\\n // four bits. That is, denominator * inv = 1 mod 2^4.\\n uint256 inverse = (3 * denominator) ^ 2;\\n\\n // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works\\n // in modular arithmetic, doubling the correct bits in each step.\\n inverse *= 2 - denominator * inverse; // inverse mod 2^8\\n inverse *= 2 - denominator * inverse; // inverse mod 2^16\\n inverse *= 2 - denominator * inverse; // inverse mod 2^32\\n inverse *= 2 - denominator * inverse; // inverse mod 2^64\\n inverse *= 2 - denominator * inverse; // inverse mod 2^128\\n inverse *= 2 - denominator * inverse; // inverse mod 2^256\\n\\n // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.\\n // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is\\n // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1\\n // is no longer required.\\n result = prod0 * inverse;\\n return result;\\n }\\n }\\n\\n /**\\n * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.\\n */\\n function mulDiv(\\n uint256 x,\\n uint256 y,\\n uint256 denominator,\\n Rounding rounding\\n ) internal pure returns (uint256) {\\n uint256 result = mulDiv(x, y, denominator);\\n if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {\\n result += 1;\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.\\n *\\n * Inspired by Henry S. Warren, Jr.'s \\\"Hacker's Delight\\\" (Chapter 11).\\n */\\n function sqrt(uint256 a) internal pure returns (uint256) {\\n if (a == 0) {\\n return 0;\\n }\\n\\n // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.\\n //\\n // We know that the \\\"msb\\\" (most significant bit) of our target number `a` is a power of 2 such that we have\\n // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.\\n //\\n // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`\\n // \\u2192 `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`\\n // \\u2192 `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`\\n //\\n // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.\\n uint256 result = 1 << (log2(a) >> 1);\\n\\n // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,\\n // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at\\n // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision\\n // into the expected uint128 result.\\n unchecked {\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n return min(result, a / result);\\n }\\n }\\n\\n /**\\n * @notice Calculates sqrt(a), following the selected rounding direction.\\n */\\n function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = sqrt(a);\\n return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);\\n }\\n }\\n\\n /**\\n * @dev Return the log in base 2, rounded down, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log2(uint256 value) internal pure returns (uint256) {\\n uint256 result = 0;\\n unchecked {\\n if (value >> 128 > 0) {\\n value >>= 128;\\n result += 128;\\n }\\n if (value >> 64 > 0) {\\n value >>= 64;\\n result += 64;\\n }\\n if (value >> 32 > 0) {\\n value >>= 32;\\n result += 32;\\n }\\n if (value >> 16 > 0) {\\n value >>= 16;\\n result += 16;\\n }\\n if (value >> 8 > 0) {\\n value >>= 8;\\n result += 8;\\n }\\n if (value >> 4 > 0) {\\n value >>= 4;\\n result += 4;\\n }\\n if (value >> 2 > 0) {\\n value >>= 2;\\n result += 2;\\n }\\n if (value >> 1 > 0) {\\n result += 1;\\n }\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Return the log in base 2, following the selected rounding direction, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = log2(value);\\n return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);\\n }\\n }\\n\\n /**\\n * @dev Return the log in base 10, rounded down, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log10(uint256 value) internal pure returns (uint256) {\\n uint256 result = 0;\\n unchecked {\\n if (value >= 10**64) {\\n value /= 10**64;\\n result += 64;\\n }\\n if (value >= 10**32) {\\n value /= 10**32;\\n result += 32;\\n }\\n if (value >= 10**16) {\\n value /= 10**16;\\n result += 16;\\n }\\n if (value >= 10**8) {\\n value /= 10**8;\\n result += 8;\\n }\\n if (value >= 10**4) {\\n value /= 10**4;\\n result += 4;\\n }\\n if (value >= 10**2) {\\n value /= 10**2;\\n result += 2;\\n }\\n if (value >= 10**1) {\\n result += 1;\\n }\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = log10(value);\\n return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);\\n }\\n }\\n\\n /**\\n * @dev Return the log in base 256, rounded down, of a positive value.\\n * Returns 0 if given 0.\\n *\\n * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.\\n */\\n function log256(uint256 value) internal pure returns (uint256) {\\n uint256 result = 0;\\n unchecked {\\n if (value >> 128 > 0) {\\n value >>= 128;\\n result += 16;\\n }\\n if (value >> 64 > 0) {\\n value >>= 64;\\n result += 8;\\n }\\n if (value >> 32 > 0) {\\n value >>= 32;\\n result += 4;\\n }\\n if (value >> 16 > 0) {\\n value >>= 16;\\n result += 2;\\n }\\n if (value >> 8 > 0) {\\n result += 1;\\n }\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = log256(value);\\n return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);\\n }\\n }\\n}\\n\",\"keccak256\":\"0xa1e8e83cd0087785df04ac79fb395d9f3684caeaf973d9e2c71caef723a3a5d6\",\"license\":\"MIT\"},\"src/Staking.sol\":{\"content\":\"// SPDX-License-Identifier: BSD-3-Clause\\npragma solidity ^0.8.19;\\nimport \\\"@openzeppelin/contracts/token/ERC20/ERC20.sol\\\";\\nimport \\\"@openzeppelin/contracts/access/AccessControl.sol\\\";\\nimport \\\"@openzeppelin/contracts/security/Pausable.sol\\\";\\n\\ninterface IPriceOracle {\\n function currentPrice() external view returns (uint32);\\n}\\n\\n/**\\n * @title Staking contract for the Swarm storage incentives\\n * @author The Swarm Authors\\n * @dev Allows users to stake tokens in order to be eligible for the Redistribution Schelling co-ordination game.\\n * Stakes are frozen or slashed by the Redistribution contract in response to violations of the\\n * protocol.\\n */\\n\\ncontract StakeRegistry is AccessControl, Pausable {\\n // ----------------------------- State variables ------------------------------\\n\\n struct Stake {\\n // Overlay of the node that is being staked\\n bytes32 overlay;\\n // Stake balance expressed through price oracle\\n uint256 committedStake;\\n // Stake balance expressed in BZZ\\n uint256 potentialStake;\\n // Block height the stake was updated, also used as flag to check if the stake is set\\n uint256 lastUpdatedBlockNumber;\\n // Node indicating its increased reserve\\n uint8 height;\\n }\\n\\n // Associate every stake id with node address data.\\n mapping(address => Stake) public stakes;\\n\\n // Role allowed to freeze and slash entries\\n bytes32 public constant REDISTRIBUTOR_ROLE = keccak256(\\\"REDISTRIBUTOR_ROLE\\\");\\n\\n // Swarm network ID\\n uint64 NetworkId;\\n\\n // The miniumum stake allowed to be staked using the Staking contract.\\n uint64 private constant MIN_STAKE = 100000000000000000;\\n\\n // Address of the staked ERC20 token\\n address public immutable bzzToken;\\n\\n // The address of the linked PriceOracle contract.\\n IPriceOracle public OracleContract;\\n\\n // ----------------------------- Events ------------------------------\\n\\n /**\\n * @dev Emitted when a stake is created or updated by `owner` of the `overlay`.\\n */\\n event StakeUpdated(\\n address indexed owner,\\n uint256 committedStake,\\n uint256 potentialStake,\\n bytes32 overlay,\\n uint256 lastUpdatedBlock,\\n uint8 height\\n );\\n\\n /**\\n * @dev Emitted when a stake for address `slashed` is slashed by `amount`.\\n */\\n event StakeSlashed(address slashed, bytes32 overlay, uint256 amount);\\n\\n /**\\n * @dev Emitted when a stake for address `frozen` is frozen for `time` blocks.\\n */\\n event StakeFrozen(address frozen, bytes32 overlay, uint256 time);\\n\\n /**\\n * @dev Emitted when a address changes overlay it uses\\n */\\n event OverlayChanged(address owner, bytes32 overlay);\\n\\n /**\\n * @dev Emitted when a stake for address is withdrawn\\n */\\n event StakeWithdrawn(address node, uint256 amount);\\n\\n // ----------------------------- Errors ------------------------------\\n\\n error TransferFailed(); // Used when token transfers fail\\n error Frozen(); // Used when an action cannot proceed because the overlay is frozen\\n error Unauthorized(); // Used where only the owner can perform the action\\n error OnlyRedistributor(); // Used when only the redistributor role is allowed\\n error OnlyPauser(); // Used when only the pauser role is allowed\\n error BelowMinimumStake(); // Node participating in game has stake below minimum treshold\\n\\n // ----------------------------- CONSTRUCTOR ------------------------------\\n\\n /**\\n * @param _bzzToken Address of the staked ERC20 token\\n * @param _NetworkId Swarm network ID\\n */\\n constructor(address _bzzToken, uint64 _NetworkId, address _oracleContract) {\\n NetworkId = _NetworkId;\\n bzzToken = _bzzToken;\\n OracleContract = IPriceOracle(_oracleContract);\\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\\n }\\n\\n ////////////////////////////////////////\\n // STATE SETTING //\\n ////////////////////////////////////////\\n\\n /**\\n * @notice Create a new stake or update an existing one, change overlay of node\\n * @dev At least `_initialBalancePerChunk*2^depth` number of tokens need to be preapproved for this contract.\\n * @param _setNonce Nonce that was used for overlay calculation.\\n * @param _addAmount Deposited amount of ERC20 tokens, equals to added Potential stake value\\n * @param _height increased reserve by registering the number of doublings\\n */\\n function manageStake(bytes32 _setNonce, uint256 _addAmount, uint8 _height) external whenNotPaused {\\n bytes32 _previousOverlay = stakes[msg.sender].overlay;\\n uint256 _stakingSet = stakes[msg.sender].lastUpdatedBlockNumber;\\n bytes32 _newOverlay = keccak256(abi.encodePacked(msg.sender, reverse(NetworkId), _setNonce));\\n\\n // First time adding stake, check the minimum is added, take into account height\\n if (_addAmount < MIN_STAKE * 2 ** _height && _stakingSet == 0) {\\n revert BelowMinimumStake();\\n }\\n\\n if (_stakingSet != 0 && !addressNotFrozen(msg.sender)) revert Frozen();\\n\\n uint256 updatedPotentialStake = stakes[msg.sender].potentialStake;\\n uint256 updatedCommittedStake = stakes[msg.sender].committedStake;\\n\\n // Only update stake values if _addAmount is greater than 0\\n if (_addAmount > 0) {\\n updatedPotentialStake = stakes[msg.sender].potentialStake + _addAmount;\\n updatedCommittedStake = updatedPotentialStake / (OracleContract.currentPrice() * 2 ** _height);\\n }\\n\\n stakes[msg.sender] = Stake({\\n overlay: _newOverlay,\\n committedStake: updatedCommittedStake,\\n potentialStake: updatedPotentialStake,\\n lastUpdatedBlockNumber: block.number,\\n height: _height\\n });\\n\\n // Transfer tokens and emit event that stake has been updated\\n if (_addAmount > 0) {\\n if (!ERC20(bzzToken).transferFrom(msg.sender, address(this), _addAmount)) revert TransferFailed();\\n emit StakeUpdated(\\n msg.sender,\\n updatedCommittedStake,\\n updatedPotentialStake,\\n _newOverlay,\\n block.number,\\n _height\\n );\\n }\\n\\n // Emit overlay change event\\n if (_previousOverlay != _newOverlay) {\\n emit OverlayChanged(msg.sender, _newOverlay);\\n }\\n }\\n\\n /**\\n * @dev Withdraw node stake surplus\\n */\\n function withdrawFromStake() external {\\n uint256 _potentialStake = stakes[msg.sender].potentialStake;\\n uint256 _surplusStake = _potentialStake -\\n calculateEffectiveStake(stakes[msg.sender].committedStake, _potentialStake, stakes[msg.sender].height);\\n\\n if (_surplusStake > 0) {\\n stakes[msg.sender].potentialStake -= _surplusStake;\\n if (!ERC20(bzzToken).transfer(msg.sender, _surplusStake)) revert TransferFailed();\\n emit StakeWithdrawn(msg.sender, _surplusStake);\\n }\\n }\\n\\n /**\\n * @dev Migrate stake only when the staking contract is paused,\\n * can only be called by the owner of the stake\\n */\\n function migrateStake() external whenPaused {\\n // We take out all the stake so user can migrate stake to other contract\\n if (lastUpdatedBlockNumberOfAddress(msg.sender) != 0) {\\n if (!ERC20(bzzToken).transfer(msg.sender, stakes[msg.sender].potentialStake)) revert TransferFailed();\\n delete stakes[msg.sender];\\n }\\n }\\n\\n /**\\n * @dev Freeze an existing stake, can only be called by the redistributor\\n * @param _owner the addres selected\\n * @param _time penalty length in blocknumbers\\n */\\n function freezeDeposit(address _owner, uint256 _time) external {\\n if (!hasRole(REDISTRIBUTOR_ROLE, msg.sender)) revert OnlyRedistributor();\\n\\n if (stakes[_owner].lastUpdatedBlockNumber != 0) {\\n stakes[_owner].lastUpdatedBlockNumber = block.number + _time;\\n emit StakeFrozen(_owner, stakes[_owner].overlay, _time);\\n }\\n }\\n\\n /**\\n * @dev Slash an existing stake, can only be called by the `redistributor`\\n * @param _owner the _owner adress selected\\n * @param _amount the amount to be slashed\\n */\\n function slashDeposit(address _owner, uint256 _amount) external {\\n if (!hasRole(REDISTRIBUTOR_ROLE, msg.sender)) revert OnlyRedistributor();\\n\\n if (stakes[_owner].lastUpdatedBlockNumber != 0) {\\n if (stakes[_owner].potentialStake > _amount) {\\n stakes[_owner].potentialStake -= _amount;\\n stakes[_owner].lastUpdatedBlockNumber = block.number;\\n } else {\\n delete stakes[_owner];\\n }\\n }\\n emit StakeSlashed(_owner, stakes[_owner].overlay, _amount);\\n }\\n\\n function changeNetworkId(uint64 _NetworkId) external {\\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) revert Unauthorized();\\n NetworkId = _NetworkId;\\n }\\n\\n /**\\n * @dev Pause the contract. The contract is provably stopped by renouncing\\n the pauser role and the admin role after pausing, can only be called by the `PAUSER`\\n */\\n function pause() public {\\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) revert OnlyPauser();\\n _pause();\\n }\\n\\n /**\\n * @dev Unpause the contract, can only be called by the pauser when paused\\n */\\n function unPause() public {\\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) revert OnlyPauser();\\n _unpause();\\n }\\n\\n ////////////////////////////////////////\\n // STATE READING //\\n ////////////////////////////////////////\\n\\n /**\\n * @dev Checks to see if `address` is frozen.\\n * @param _owner owner of staked address\\n *\\n * Returns a boolean value indicating whether the operation succeeded.\\n */\\n function addressNotFrozen(address _owner) internal view returns (bool) {\\n return stakes[_owner].lastUpdatedBlockNumber < block.number;\\n }\\n\\n /**\\n * @dev Returns the current `effectiveStake` of `address`. previously usable stake\\n * @param _owner _owner of node\\n */\\n function nodeEffectiveStake(address _owner) public view returns (uint256) {\\n return\\n addressNotFrozen(_owner)\\n ? calculateEffectiveStake(\\n stakes[_owner].committedStake,\\n stakes[_owner].potentialStake,\\n stakes[_owner].height\\n )\\n : 0;\\n }\\n\\n /**\\n * @dev Check the amount that is possible to withdraw as surplus\\n */\\n function withdrawableStake() public view returns (uint256) {\\n uint256 _potentialStake = stakes[msg.sender].potentialStake;\\n return\\n _potentialStake -\\n calculateEffectiveStake(stakes[msg.sender].committedStake, _potentialStake, stakes[msg.sender].height);\\n }\\n\\n /**\\n * @dev Returns the `lastUpdatedBlockNumber` of `address`.\\n */\\n function lastUpdatedBlockNumberOfAddress(address _owner) public view returns (uint256) {\\n return stakes[_owner].lastUpdatedBlockNumber;\\n }\\n\\n /**\\n * @dev Returns the currently used overlay of the address.\\n * @param _owner address of node\\n */\\n function overlayOfAddress(address _owner) public view returns (bytes32) {\\n return stakes[_owner].overlay;\\n }\\n\\n /**\\n * @dev Returns the currently height of the address.\\n * @param _owner address of node\\n */\\n function heightOfAddress(address _owner) public view returns (uint8) {\\n return stakes[_owner].height;\\n }\\n\\n function calculateEffectiveStake(\\n uint256 committedStake,\\n uint256 potentialStakeBalance,\\n uint8 height\\n ) internal view returns (uint256) {\\n // Calculate the product of committedStake and unitPrice to get price in BZZ\\n uint256 committedStakeBzz = (2 ** height) * committedStake * OracleContract.currentPrice();\\n\\n // Return the minimum value between committedStakeBzz and potentialStakeBalance\\n if (committedStakeBzz < potentialStakeBalance) {\\n return committedStakeBzz;\\n } else {\\n return potentialStakeBalance;\\n }\\n }\\n\\n /**\\n * @dev Please both Endians \\ud83e\\udd5a.\\n * @param input Eth address used for overlay calculation.\\n */\\n function reverse(uint64 input) internal pure returns (uint64 v) {\\n v = input;\\n\\n // swap bytes\\n v = ((v & 0xFF00FF00FF00FF00) >> 8) | ((v & 0x00FF00FF00FF00FF) << 8);\\n\\n // swap 2-byte long pairs\\n v = ((v & 0xFFFF0000FFFF0000) >> 16) | ((v & 0x0000FFFF0000FFFF) << 16);\\n\\n // swap 4-byte long pairs\\n v = (v >> 32) | (v << 32);\\n }\\n}\\n\",\"keccak256\":\"0x958d6fccba5e0b9fa39b08de79ca8b29d15f89df75bc65b494d921d53b20f8ff\",\"license\":\"BSD-3-Clause\"}},\"version\":1}", + "bytecode": "0x60a06040523480156200001157600080fd5b5060405162001cca38038062001cca83398101604081905262000034916200015a565b6001805460ff19169055600380546001600160a01b03808616608052831668010000000000000000026001600160e01b03199091166001600160401b03851617179055620000846000336200008d565b505050620001b2565b6200009982826200009d565b5050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1662000099576000828152602081815260408083206001600160a01b03851684529091529020805460ff19166001179055620000f93390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b80516001600160a01b03811681146200015557600080fd5b919050565b6000806000606084860312156200017057600080fd5b6200017b846200013d565b60208501519093506001600160401b03811681146200019957600080fd5b9150620001a9604085016200013d565b90509250925092565b608051611ae7620001e3600039600081816102ea0152818161057c015281816106cb0152610b8f0152611ae76000f3fe608060405234801561001057600080fd5b50600436106101a35760003560e01c80636f1c5de7116100ee578063a6471a1d11610097578063d48bfaeb11610071578063d48bfaeb14610452578063d547741f14610465578063e8e8d87e14610478578063f7b188a51461048b57600080fd5b8063a6471a1d146103ec578063d009b2d614610413578063d1052d1f1461042657600080fd5b806391d14854116100c857806391d148541461038457806397adedb5146103bb578063a217fddf146103e457600080fd5b80636f1c5de714610361578063830a053e146103695780638456cb591461037c57600080fd5b80632f2ff15d116101505780635c975abb1161012a5780635c975abb14610324578063663e54f91461032f57806369da91141461034257600080fd5b80632f2ff15d146102bf57806336568abe146102d2578063420fc4db146102e557600080fd5b806316934fc41161018157806316934fc4146101e25780631d5480531461024d578063248a9ca31461028e57600080fd5b806301ffc9a7146101a85780630aed7b0d146101d057806312236a77146101da575b600080fd5b6101bb6101b6366004611695565b610493565b60405190151581526020015b60405180910390f35b6101d861052c565b005b6101d8610645565b6102226101f03660046116f3565b600260208190526000918252604090912080546001820154928201546003830154600490930154919392909160ff1685565b60408051958652602086019490945292840191909152606083015260ff16608082015260a0016101c7565b61027c61025b3660046116f3565b6001600160a01b031660009081526002602052604090206004015460ff1690565b60405160ff90911681526020016101c7565b6102b161029c36600461170e565b60009081526020819052604090206001015490565b6040519081526020016101c7565b6101d86102cd366004611727565b61079c565b6101d86102e0366004611727565b6107c6565b61030c7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b0390911681526020016101c7565b60015460ff166101bb565b6101d861033d366004611753565b610853565b60035461030c906801000000000000000090046001600160a01b031681565b6102b1610cbf565b6102b16103773660046116f3565b610cff565b6101d8610d60565b6101bb610392366004611727565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b6102b16103c93660046116f3565b6001600160a01b031660009081526002602052604090205490565b6102b1600081565b6102b17f3e35b14a9f4fef84b59f9bdcd3044fc28783144b7e42bfb2cd075e6a02cb082881565b6101d8610421366004611792565b610db7565b6102b16104343660046116f3565b6001600160a01b031660009081526002602052604090206003015490565b6101d86104603660046117bc565b610e93565b6101d8610473366004611727565b610f1f565b6101d8610486366004611792565b610f44565b6101d86110bf565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f7965db0b00000000000000000000000000000000000000000000000000000000148061052657507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008316145b92915050565b610534611116565b336000908152600260205260409020600301541561064357336000818152600260208190526040918290200154905163a9059cbb60e01b8152600481019290925260248201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063a9059cbb906044016020604051808303816000875af11580156105cd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105f191906117e6565b61060e576040516312171d8360e31b815260040160405180910390fd5b3360009081526002602081905260408220828155600181018390559081018290556003810191909155600401805460ff191690555b565b336000908152600260208190526040822090810154600182015460049092015490929161067691849060ff16611168565b610680908361181e565b905080156107985733600090815260026020819052604082200180548392906106aa90849061181e565b909155505060405163a9059cbb60e01b8152336004820152602481018290527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063a9059cbb906044016020604051808303816000875af115801561071c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061074091906117e6565b61075d576040516312171d8360e31b815260040160405180910390fd5b60408051338152602081018390527f8108595eb6bad3acefa9da467d90cc2217686d5c5ac85460f8b7849c840645fc91015b60405180910390a15b5050565b6000828152602081905260409020600101546107b781611225565b6107c18383611232565b505050565b6001600160a01b03811633146108495760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b61079882826112d0565b61085b61134f565b336000818152600260209081526040822080546003918201549154909491939265ff000000ff00600883811b91821664ff000000ff9490911c93841617601090811b67ff000000ff0000009290921666ff000000ff0000949094169390931790921c9190911780821b6bffffffffffffffff0000000016911c63ffffffff161760405160609290921b6bffffffffffffffffffffffff1916602083015260c01b7fffffffffffffffff000000000000000000000000000000000000000000000000166034820152603c8101879052605c016040516020818303038152906040528051906020012090508360026109519190611915565b6109639067016345785d8a0000611924565b8510801561096f575081155b156109a6576040517f8ecf3d0300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b81158015906109c75750336000908152600260205260409020600301544311155b156109fe576040517fa8cab3d100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b336000908152600260208190526040909120908101546001909101548615610ae0573360009081526002602081905260409091200154610a3f90889061193b565b9150610a4c866002611915565b600360089054906101000a90046001600160a01b03166001600160a01b0316639d1b464a6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610a9f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ac3919061194e565b63ffffffff16610ad39190611924565b610add9083611974565b90505b6040805160a0810182528481526020808201848152828401868152436060850190815260ff8c8116608087019081523360009081526002968790529790972095518655925160018601559051928401929092559051600383015591516004909101805460ff1916919092161790558615610c74576040517f23b872dd000000000000000000000000000000000000000000000000000000008152336004820152306024820152604481018890527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906323b872dd906064016020604051808303816000875af1158015610be0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c0491906117e6565b610c21576040516312171d8360e31b815260040160405180910390fd5b604080518281526020810184905290810184905243606082015260ff8716608082015233907f8fb3da6e133de1007392b10d429548e9c2565c791c52e1498b01b65d8797e74c9060a00160405180910390a25b828514610cb55760408051338152602081018590527fe188baf4bcb1c4413d19ba0eaef908614d30e8df9570d6fc4d584b75f4a37a3a910160405180910390a15b5050505050505050565b33600090815260026020819052604082209081015460018201546004909201549091610cef91839060ff16611168565b610cf9908261181e565b91505090565b6001600160a01b0381166000908152600260205260408120600301544311610d28576000610526565b6001600160a01b038216600090815260026020819052604090912060018101549181015460049091015461052692919060ff16611168565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff16610daf57604051631d77d47760e21b815260040160405180910390fd5b6106436113a2565b3360009081527f10fa80d2e578284bf61a483a3da84fbdd683a7e7256a9895dc4461ac543f4a16602052604090205460ff16610e0657604051630490edbf60e31b815260040160405180910390fd5b6001600160a01b0382166000908152600260205260409020600301541561079857610e31814361193b565b6001600160a01b038316600081815260026020908152604091829020600381019490945592548151928352928201929092529081018290527fd7863535575e7de6678ea9d340a4bfe0b84d77323bfa2ef602c3c1df82aea7809060600161078f565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff16610efb576040517f82b4290000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6003805467ffffffffffffffff191667ffffffffffffffff92909216919091179055565b600082815260208190526040902060010154610f3a81611225565b6107c183836112d0565b3360009081527f10fa80d2e578284bf61a483a3da84fbdd683a7e7256a9895dc4461ac543f4a16602052604090205460ff16610f9357604051630490edbf60e31b815260040160405180910390fd5b6001600160a01b0382166000908152600260205260409020600301541561106a576001600160a01b0382166000908152600260208190526040909120015481101561102c576001600160a01b0382166000908152600260208190526040822001805483929061100390849061181e565b90915550506001600160a01b03821660009081526002602052604090204360039091015561106a565b6001600160a01b03821660009081526002602081905260408220828155600181018390559081018290556003810191909155600401805460ff191690555b6001600160a01b0382166000818152600260209081526040918290205482519384529083015281018290527f5f52ce031e6eba64e8a81288196b93a3e422096e80aea812f1f5a77866359b3a9060600161078f565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff1661110e57604051631d77d47760e21b815260040160405180910390fd5b6106436113f6565b60015460ff166106435760405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f74207061757365640000000000000000000000006044820152606401610840565b600080600360089054906101000a90046001600160a01b03166001600160a01b0316639d1b464a6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156111be573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111e2919061194e565b63ffffffff16856111f4856002611915565b6111fe9190611924565b6112089190611924565b90508381101561121957905061121e565b839150505b9392505050565b61122f813361142f565b50565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610798576000828152602081815260408083206001600160a01b03851684529091529020805460ff1916600117905561128c3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1615610798576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b60015460ff16156106435760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a20706175736564000000000000000000000000000000006044820152606401610840565b6113aa61134f565b6001805460ff1916811790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258335b6040516001600160a01b03909116815260200160405180910390a1565b6113fe611116565b6001805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa336113d9565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1661079857611460816114a2565b61146b8360206114b4565b60405160200161147c9291906119ba565b60408051601f198184030181529082905262461bcd60e51b825261084091600401611a3b565b60606105266001600160a01b03831660145b606060006114c3836002611924565b6114ce90600261193b565b67ffffffffffffffff8111156114e6576114e6611a6e565b6040519080825280601f01601f191660200182016040528015611510576020820181803683370190505b5090507f30000000000000000000000000000000000000000000000000000000000000008160008151811061154757611547611a84565b60200101906001600160f81b031916908160001a9053507f78000000000000000000000000000000000000000000000000000000000000008160018151811061159257611592611a84565b60200101906001600160f81b031916908160001a90535060006115b6846002611924565b6115c190600161193b565b90505b6001811115611646577f303132333435363738396162636465660000000000000000000000000000000085600f166010811061160257611602611a84565b1a60f81b82828151811061161857611618611a84565b60200101906001600160f81b031916908160001a90535060049490941c9361163f81611a9a565b90506115c4565b50831561121e5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610840565b6000602082840312156116a757600080fd5b81357fffffffff000000000000000000000000000000000000000000000000000000008116811461121e57600080fd5b80356001600160a01b03811681146116ee57600080fd5b919050565b60006020828403121561170557600080fd5b61121e826116d7565b60006020828403121561172057600080fd5b5035919050565b6000806040838503121561173a57600080fd5b8235915061174a602084016116d7565b90509250929050565b60008060006060848603121561176857600080fd5b8335925060208401359150604084013560ff8116811461178757600080fd5b809150509250925092565b600080604083850312156117a557600080fd5b6117ae836116d7565b946020939093013593505050565b6000602082840312156117ce57600080fd5b813567ffffffffffffffff8116811461121e57600080fd5b6000602082840312156117f857600080fd5b8151801515811461121e57600080fd5b634e487b7160e01b600052601160045260246000fd5b8181038181111561052657610526611808565b600181815b8085111561186c57816000190482111561185257611852611808565b8085161561185f57918102915b93841c9390800290611836565b509250929050565b60008261188357506001610526565b8161189057506000610526565b81600181146118a657600281146118b0576118cc565b6001915050610526565b60ff8411156118c1576118c1611808565b50506001821b610526565b5060208310610133831016604e8410600b84101617156118ef575081810a610526565b6118f98383611831565b806000190482111561190d5761190d611808565b029392505050565b600061121e60ff841683611874565b808202811582820484141761052657610526611808565b8082018082111561052657610526611808565b60006020828403121561196057600080fd5b815163ffffffff8116811461121e57600080fd5b60008261199157634e487b7160e01b600052601260045260246000fd5b500490565b60005b838110156119b1578181015183820152602001611999565b50506000910152565b7f416363657373436f6e74726f6c3a206163636f756e74200000000000000000008152600083516119f2816017850160208801611996565b7f206973206d697373696e6720726f6c65200000000000000000000000000000006017918401918201528351611a2f816028840160208801611996565b01602801949350505050565b6020815260008251806020840152611a5a816040850160208701611996565b601f01601f19169190910160400192915050565b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b600081611aa957611aa9611808565b50600019019056fea2646970667358221220e15b5893be07329a6f2593445e71674f50d6bad57c5030abfefacec6cb27303464736f6c63430008130033", + "deployedBytecode": "0x608060405234801561001057600080fd5b50600436106101a35760003560e01c80636f1c5de7116100ee578063a6471a1d11610097578063d48bfaeb11610071578063d48bfaeb14610452578063d547741f14610465578063e8e8d87e14610478578063f7b188a51461048b57600080fd5b8063a6471a1d146103ec578063d009b2d614610413578063d1052d1f1461042657600080fd5b806391d14854116100c857806391d148541461038457806397adedb5146103bb578063a217fddf146103e457600080fd5b80636f1c5de714610361578063830a053e146103695780638456cb591461037c57600080fd5b80632f2ff15d116101505780635c975abb1161012a5780635c975abb14610324578063663e54f91461032f57806369da91141461034257600080fd5b80632f2ff15d146102bf57806336568abe146102d2578063420fc4db146102e557600080fd5b806316934fc41161018157806316934fc4146101e25780631d5480531461024d578063248a9ca31461028e57600080fd5b806301ffc9a7146101a85780630aed7b0d146101d057806312236a77146101da575b600080fd5b6101bb6101b6366004611695565b610493565b60405190151581526020015b60405180910390f35b6101d861052c565b005b6101d8610645565b6102226101f03660046116f3565b600260208190526000918252604090912080546001820154928201546003830154600490930154919392909160ff1685565b60408051958652602086019490945292840191909152606083015260ff16608082015260a0016101c7565b61027c61025b3660046116f3565b6001600160a01b031660009081526002602052604090206004015460ff1690565b60405160ff90911681526020016101c7565b6102b161029c36600461170e565b60009081526020819052604090206001015490565b6040519081526020016101c7565b6101d86102cd366004611727565b61079c565b6101d86102e0366004611727565b6107c6565b61030c7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b0390911681526020016101c7565b60015460ff166101bb565b6101d861033d366004611753565b610853565b60035461030c906801000000000000000090046001600160a01b031681565b6102b1610cbf565b6102b16103773660046116f3565b610cff565b6101d8610d60565b6101bb610392366004611727565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b6102b16103c93660046116f3565b6001600160a01b031660009081526002602052604090205490565b6102b1600081565b6102b17f3e35b14a9f4fef84b59f9bdcd3044fc28783144b7e42bfb2cd075e6a02cb082881565b6101d8610421366004611792565b610db7565b6102b16104343660046116f3565b6001600160a01b031660009081526002602052604090206003015490565b6101d86104603660046117bc565b610e93565b6101d8610473366004611727565b610f1f565b6101d8610486366004611792565b610f44565b6101d86110bf565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f7965db0b00000000000000000000000000000000000000000000000000000000148061052657507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008316145b92915050565b610534611116565b336000908152600260205260409020600301541561064357336000818152600260208190526040918290200154905163a9059cbb60e01b8152600481019290925260248201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063a9059cbb906044016020604051808303816000875af11580156105cd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105f191906117e6565b61060e576040516312171d8360e31b815260040160405180910390fd5b3360009081526002602081905260408220828155600181018390559081018290556003810191909155600401805460ff191690555b565b336000908152600260208190526040822090810154600182015460049092015490929161067691849060ff16611168565b610680908361181e565b905080156107985733600090815260026020819052604082200180548392906106aa90849061181e565b909155505060405163a9059cbb60e01b8152336004820152602481018290527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063a9059cbb906044016020604051808303816000875af115801561071c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061074091906117e6565b61075d576040516312171d8360e31b815260040160405180910390fd5b60408051338152602081018390527f8108595eb6bad3acefa9da467d90cc2217686d5c5ac85460f8b7849c840645fc91015b60405180910390a15b5050565b6000828152602081905260409020600101546107b781611225565b6107c18383611232565b505050565b6001600160a01b03811633146108495760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b61079882826112d0565b61085b61134f565b336000818152600260209081526040822080546003918201549154909491939265ff000000ff00600883811b91821664ff000000ff9490911c93841617601090811b67ff000000ff0000009290921666ff000000ff0000949094169390931790921c9190911780821b6bffffffffffffffff0000000016911c63ffffffff161760405160609290921b6bffffffffffffffffffffffff1916602083015260c01b7fffffffffffffffff000000000000000000000000000000000000000000000000166034820152603c8101879052605c016040516020818303038152906040528051906020012090508360026109519190611915565b6109639067016345785d8a0000611924565b8510801561096f575081155b156109a6576040517f8ecf3d0300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b81158015906109c75750336000908152600260205260409020600301544311155b156109fe576040517fa8cab3d100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b336000908152600260208190526040909120908101546001909101548615610ae0573360009081526002602081905260409091200154610a3f90889061193b565b9150610a4c866002611915565b600360089054906101000a90046001600160a01b03166001600160a01b0316639d1b464a6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610a9f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ac3919061194e565b63ffffffff16610ad39190611924565b610add9083611974565b90505b6040805160a0810182528481526020808201848152828401868152436060850190815260ff8c8116608087019081523360009081526002968790529790972095518655925160018601559051928401929092559051600383015591516004909101805460ff1916919092161790558615610c74576040517f23b872dd000000000000000000000000000000000000000000000000000000008152336004820152306024820152604481018890527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906323b872dd906064016020604051808303816000875af1158015610be0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c0491906117e6565b610c21576040516312171d8360e31b815260040160405180910390fd5b604080518281526020810184905290810184905243606082015260ff8716608082015233907f8fb3da6e133de1007392b10d429548e9c2565c791c52e1498b01b65d8797e74c9060a00160405180910390a25b828514610cb55760408051338152602081018590527fe188baf4bcb1c4413d19ba0eaef908614d30e8df9570d6fc4d584b75f4a37a3a910160405180910390a15b5050505050505050565b33600090815260026020819052604082209081015460018201546004909201549091610cef91839060ff16611168565b610cf9908261181e565b91505090565b6001600160a01b0381166000908152600260205260408120600301544311610d28576000610526565b6001600160a01b038216600090815260026020819052604090912060018101549181015460049091015461052692919060ff16611168565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff16610daf57604051631d77d47760e21b815260040160405180910390fd5b6106436113a2565b3360009081527f10fa80d2e578284bf61a483a3da84fbdd683a7e7256a9895dc4461ac543f4a16602052604090205460ff16610e0657604051630490edbf60e31b815260040160405180910390fd5b6001600160a01b0382166000908152600260205260409020600301541561079857610e31814361193b565b6001600160a01b038316600081815260026020908152604091829020600381019490945592548151928352928201929092529081018290527fd7863535575e7de6678ea9d340a4bfe0b84d77323bfa2ef602c3c1df82aea7809060600161078f565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff16610efb576040517f82b4290000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6003805467ffffffffffffffff191667ffffffffffffffff92909216919091179055565b600082815260208190526040902060010154610f3a81611225565b6107c183836112d0565b3360009081527f10fa80d2e578284bf61a483a3da84fbdd683a7e7256a9895dc4461ac543f4a16602052604090205460ff16610f9357604051630490edbf60e31b815260040160405180910390fd5b6001600160a01b0382166000908152600260205260409020600301541561106a576001600160a01b0382166000908152600260208190526040909120015481101561102c576001600160a01b0382166000908152600260208190526040822001805483929061100390849061181e565b90915550506001600160a01b03821660009081526002602052604090204360039091015561106a565b6001600160a01b03821660009081526002602081905260408220828155600181018390559081018290556003810191909155600401805460ff191690555b6001600160a01b0382166000818152600260209081526040918290205482519384529083015281018290527f5f52ce031e6eba64e8a81288196b93a3e422096e80aea812f1f5a77866359b3a9060600161078f565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff1661110e57604051631d77d47760e21b815260040160405180910390fd5b6106436113f6565b60015460ff166106435760405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f74207061757365640000000000000000000000006044820152606401610840565b600080600360089054906101000a90046001600160a01b03166001600160a01b0316639d1b464a6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156111be573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111e2919061194e565b63ffffffff16856111f4856002611915565b6111fe9190611924565b6112089190611924565b90508381101561121957905061121e565b839150505b9392505050565b61122f813361142f565b50565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610798576000828152602081815260408083206001600160a01b03851684529091529020805460ff1916600117905561128c3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1615610798576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b60015460ff16156106435760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a20706175736564000000000000000000000000000000006044820152606401610840565b6113aa61134f565b6001805460ff1916811790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258335b6040516001600160a01b03909116815260200160405180910390a1565b6113fe611116565b6001805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa336113d9565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1661079857611460816114a2565b61146b8360206114b4565b60405160200161147c9291906119ba565b60408051601f198184030181529082905262461bcd60e51b825261084091600401611a3b565b60606105266001600160a01b03831660145b606060006114c3836002611924565b6114ce90600261193b565b67ffffffffffffffff8111156114e6576114e6611a6e565b6040519080825280601f01601f191660200182016040528015611510576020820181803683370190505b5090507f30000000000000000000000000000000000000000000000000000000000000008160008151811061154757611547611a84565b60200101906001600160f81b031916908160001a9053507f78000000000000000000000000000000000000000000000000000000000000008160018151811061159257611592611a84565b60200101906001600160f81b031916908160001a90535060006115b6846002611924565b6115c190600161193b565b90505b6001811115611646577f303132333435363738396162636465660000000000000000000000000000000085600f166010811061160257611602611a84565b1a60f81b82828151811061161857611618611a84565b60200101906001600160f81b031916908160001a90535060049490941c9361163f81611a9a565b90506115c4565b50831561121e5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610840565b6000602082840312156116a757600080fd5b81357fffffffff000000000000000000000000000000000000000000000000000000008116811461121e57600080fd5b80356001600160a01b03811681146116ee57600080fd5b919050565b60006020828403121561170557600080fd5b61121e826116d7565b60006020828403121561172057600080fd5b5035919050565b6000806040838503121561173a57600080fd5b8235915061174a602084016116d7565b90509250929050565b60008060006060848603121561176857600080fd5b8335925060208401359150604084013560ff8116811461178757600080fd5b809150509250925092565b600080604083850312156117a557600080fd5b6117ae836116d7565b946020939093013593505050565b6000602082840312156117ce57600080fd5b813567ffffffffffffffff8116811461121e57600080fd5b6000602082840312156117f857600080fd5b8151801515811461121e57600080fd5b634e487b7160e01b600052601160045260246000fd5b8181038181111561052657610526611808565b600181815b8085111561186c57816000190482111561185257611852611808565b8085161561185f57918102915b93841c9390800290611836565b509250929050565b60008261188357506001610526565b8161189057506000610526565b81600181146118a657600281146118b0576118cc565b6001915050610526565b60ff8411156118c1576118c1611808565b50506001821b610526565b5060208310610133831016604e8410600b84101617156118ef575081810a610526565b6118f98383611831565b806000190482111561190d5761190d611808565b029392505050565b600061121e60ff841683611874565b808202811582820484141761052657610526611808565b8082018082111561052657610526611808565b60006020828403121561196057600080fd5b815163ffffffff8116811461121e57600080fd5b60008261199157634e487b7160e01b600052601260045260246000fd5b500490565b60005b838110156119b1578181015183820152602001611999565b50506000910152565b7f416363657373436f6e74726f6c3a206163636f756e74200000000000000000008152600083516119f2816017850160208801611996565b7f206973206d697373696e6720726f6c65200000000000000000000000000000006017918401918201528351611a2f816028840160208801611996565b01602801949350505050565b6020815260008251806020840152611a5a816040850160208701611996565b601f01601f19169190910160400192915050565b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b600081611aa957611aa9611808565b50600019019056fea2646970667358221220e15b5893be07329a6f2593445e71674f50d6bad57c5030abfefacec6cb27303464736f6c63430008130033", "devdoc": { "author": "The Swarm Authors", "details": "Allows users to stake tokens in order to be eligible for the Redistribution Schelling co-ordination game. Stakes are frozen or slashed by the Redistribution contract in response to violations of the protocol.", @@ -726,8 +761,8 @@ "StakeSlashed(address,bytes32,uint256)": { "details": "Emitted when a stake for address `slashed` is slashed by `amount`." }, - "StakeUpdated(address,uint256,uint256,bytes32,uint256)": { - "details": "Emitted when a stake is created or updated by `owner` of the `overlay` by `committedStake`, and `potentialStake` during `lastUpdatedBlock`." + "StakeUpdated(address,uint256,uint256,bytes32,uint256,uint8)": { + "details": "Emitted when a stake is created or updated by `owner` of the `overlay`." }, "StakeWithdrawn(address,uint256)": { "details": "Emitted when a stake for address is withdrawn" @@ -760,13 +795,20 @@ "hasRole(bytes32,address)": { "details": "Returns `true` if `account` has been granted `role`." }, + "heightOfAddress(address)": { + "details": "Returns the currently height of the address.", + "params": { + "_owner": "address of node" + } + }, "lastUpdatedBlockNumberOfAddress(address)": { "details": "Returns the `lastUpdatedBlockNumber` of `address`." }, - "manageStake(bytes32,uint256)": { + "manageStake(bytes32,uint256,uint8)": { "details": "At least `_initialBalancePerChunk*2^depth` number of tokens need to be preapproved for this contract.", "params": { "_addAmount": "Deposited amount of ERC20 tokens, equals to added Potential stake value", + "_height": "increased reserve by registering the number of doublings", "_setNonce": "Nonce that was used for overlay calculation." } }, @@ -823,7 +865,7 @@ "userdoc": { "kind": "user", "methods": { - "manageStake(bytes32,uint256)": { + "manageStake(bytes32,uint256,uint8)": { "notice": "Create a new stake or update an existing one, change overlay of node" } }, @@ -848,15 +890,15 @@ "type": "t_bool" }, { - "astId": 9715, + "astId": 9864, "contract": "src/Staking.sol:StakeRegistry", "label": "stakes", "offset": 0, "slot": "2", - "type": "t_mapping(t_address,t_struct(Stake)9710_storage)" + "type": "t_mapping(t_address,t_struct(Stake)9859_storage)" }, { - "astId": 9722, + "astId": 9871, "contract": "src/Staking.sol:StakeRegistry", "label": "NetworkId", "offset": 0, @@ -864,12 +906,12 @@ "type": "t_uint64" }, { - "astId": 9730, + "astId": 9879, "contract": "src/Staking.sol:StakeRegistry", "label": "OracleContract", "offset": 8, "slot": "3", - "type": "t_contract(IPriceOracle)9696" + "type": "t_contract(IPriceOracle)9843" } ], "types": { @@ -888,7 +930,7 @@ "label": "bytes32", "numberOfBytes": "32" }, - "t_contract(IPriceOracle)9696": { + "t_contract(IPriceOracle)9843": { "encoding": "inplace", "label": "contract IPriceOracle", "numberOfBytes": "20" @@ -900,12 +942,12 @@ "numberOfBytes": "32", "value": "t_bool" }, - "t_mapping(t_address,t_struct(Stake)9710_storage)": { + "t_mapping(t_address,t_struct(Stake)9859_storage)": { "encoding": "mapping", "key": "t_address", "label": "mapping(address => struct StakeRegistry.Stake)", "numberOfBytes": "32", - "value": "t_struct(Stake)9710_storage" + "value": "t_struct(Stake)9859_storage" }, "t_mapping(t_bytes32,t_struct(RoleData)19_storage)": { "encoding": "mapping", @@ -937,12 +979,12 @@ ], "numberOfBytes": "64" }, - "t_struct(Stake)9710_storage": { + "t_struct(Stake)9859_storage": { "encoding": "inplace", "label": "struct StakeRegistry.Stake", "members": [ { - "astId": 9703, + "astId": 9850, "contract": "src/Staking.sol:StakeRegistry", "label": "overlay", "offset": 0, @@ -950,7 +992,7 @@ "type": "t_bytes32" }, { - "astId": 9705, + "astId": 9852, "contract": "src/Staking.sol:StakeRegistry", "label": "committedStake", "offset": 0, @@ -958,7 +1000,7 @@ "type": "t_uint256" }, { - "astId": 9707, + "astId": 9854, "contract": "src/Staking.sol:StakeRegistry", "label": "potentialStake", "offset": 0, @@ -966,15 +1008,23 @@ "type": "t_uint256" }, { - "astId": 9709, + "astId": 9856, "contract": "src/Staking.sol:StakeRegistry", "label": "lastUpdatedBlockNumber", "offset": 0, "slot": "3", "type": "t_uint256" + }, + { + "astId": 9858, + "contract": "src/Staking.sol:StakeRegistry", + "label": "height", + "offset": 0, + "slot": "4", + "type": "t_uint8" } ], - "numberOfBytes": "128" + "numberOfBytes": "160" }, "t_uint256": { "encoding": "inplace", @@ -985,6 +1035,11 @@ "encoding": "inplace", "label": "uint64", "numberOfBytes": "8" + }, + "t_uint8": { + "encoding": "inplace", + "label": "uint8", + "numberOfBytes": "1" } } } diff --git a/deployments/testnet/solcInputs/294e4684ec82046939090fa9e468f317.json b/deployments/testnet/solcInputs/294e4684ec82046939090fa9e468f317.json new file mode 100644 index 00000000..f7502f37 --- /dev/null +++ b/deployments/testnet/solcInputs/294e4684ec82046939090fa9e468f317.json @@ -0,0 +1,118 @@ +{ + "language": "Solidity", + "sources": { + "@openzeppelin/contracts/access/AccessControl.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (access/AccessControl.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IAccessControl.sol\";\nimport \"../utils/Context.sol\";\nimport \"../utils/Strings.sol\";\nimport \"../utils/introspection/ERC165.sol\";\n\n/**\n * @dev Contract module that allows children to implement role-based access\n * control mechanisms. This is a lightweight version that doesn't allow enumerating role\n * members except through off-chain means by accessing the contract event logs. Some\n * applications may benefit from on-chain enumerability, for those cases see\n * {AccessControlEnumerable}.\n *\n * Roles are referred to by their `bytes32` identifier. These should be exposed\n * in the external API and be unique. The best way to achieve this is by\n * using `public constant` hash digests:\n *\n * ```\n * bytes32 public constant MY_ROLE = keccak256(\"MY_ROLE\");\n * ```\n *\n * Roles can be used to represent a set of permissions. To restrict access to a\n * function call, use {hasRole}:\n *\n * ```\n * function foo() public {\n * require(hasRole(MY_ROLE, msg.sender));\n * ...\n * }\n * ```\n *\n * Roles can be granted and revoked dynamically via the {grantRole} and\n * {revokeRole} functions. Each role has an associated admin role, and only\n * accounts that have a role's admin role can call {grantRole} and {revokeRole}.\n *\n * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means\n * that only accounts with this role will be able to grant or revoke other\n * roles. More complex role relationships can be created by using\n * {_setRoleAdmin}.\n *\n * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to\n * grant and revoke this role. Extra precautions should be taken to secure\n * accounts that have been granted it.\n */\nabstract contract AccessControl is Context, IAccessControl, ERC165 {\n struct RoleData {\n mapping(address => bool) members;\n bytes32 adminRole;\n }\n\n mapping(bytes32 => RoleData) private _roles;\n\n bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;\n\n /**\n * @dev Modifier that checks that an account has a specific role. Reverts\n * with a standardized message including the required role.\n *\n * The format of the revert reason is given by the following regular expression:\n *\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\n *\n * _Available since v4.1._\n */\n modifier onlyRole(bytes32 role) {\n _checkRole(role);\n _;\n }\n\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);\n }\n\n /**\n * @dev Returns `true` if `account` has been granted `role`.\n */\n function hasRole(bytes32 role, address account) public view virtual override returns (bool) {\n return _roles[role].members[account];\n }\n\n /**\n * @dev Revert with a standard message if `_msgSender()` is missing `role`.\n * Overriding this function changes the behavior of the {onlyRole} modifier.\n *\n * Format of the revert message is described in {_checkRole}.\n *\n * _Available since v4.6._\n */\n function _checkRole(bytes32 role) internal view virtual {\n _checkRole(role, _msgSender());\n }\n\n /**\n * @dev Revert with a standard message if `account` is missing `role`.\n *\n * The format of the revert reason is given by the following regular expression:\n *\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\n */\n function _checkRole(bytes32 role, address account) internal view virtual {\n if (!hasRole(role, account)) {\n revert(\n string(\n abi.encodePacked(\n \"AccessControl: account \",\n Strings.toHexString(account),\n \" is missing role \",\n Strings.toHexString(uint256(role), 32)\n )\n )\n );\n }\n }\n\n /**\n * @dev Returns the admin role that controls `role`. See {grantRole} and\n * {revokeRole}.\n *\n * To change a role's admin, use {_setRoleAdmin}.\n */\n function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {\n return _roles[role].adminRole;\n }\n\n /**\n * @dev Grants `role` to `account`.\n *\n * If `account` had not been already granted `role`, emits a {RoleGranted}\n * event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n *\n * May emit a {RoleGranted} event.\n */\n function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\n _grantRole(role, account);\n }\n\n /**\n * @dev Revokes `role` from `account`.\n *\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n *\n * May emit a {RoleRevoked} event.\n */\n function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\n _revokeRole(role, account);\n }\n\n /**\n * @dev Revokes `role` from the calling account.\n *\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\n * purpose is to provide a mechanism for accounts to lose their privileges\n * if they are compromised (such as when a trusted device is misplaced).\n *\n * If the calling account had been revoked `role`, emits a {RoleRevoked}\n * event.\n *\n * Requirements:\n *\n * - the caller must be `account`.\n *\n * May emit a {RoleRevoked} event.\n */\n function renounceRole(bytes32 role, address account) public virtual override {\n require(account == _msgSender(), \"AccessControl: can only renounce roles for self\");\n\n _revokeRole(role, account);\n }\n\n /**\n * @dev Grants `role` to `account`.\n *\n * If `account` had not been already granted `role`, emits a {RoleGranted}\n * event. Note that unlike {grantRole}, this function doesn't perform any\n * checks on the calling account.\n *\n * May emit a {RoleGranted} event.\n *\n * [WARNING]\n * ====\n * This function should only be called from the constructor when setting\n * up the initial roles for the system.\n *\n * Using this function in any other way is effectively circumventing the admin\n * system imposed by {AccessControl}.\n * ====\n *\n * NOTE: This function is deprecated in favor of {_grantRole}.\n */\n function _setupRole(bytes32 role, address account) internal virtual {\n _grantRole(role, account);\n }\n\n /**\n * @dev Sets `adminRole` as ``role``'s admin role.\n *\n * Emits a {RoleAdminChanged} event.\n */\n function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {\n bytes32 previousAdminRole = getRoleAdmin(role);\n _roles[role].adminRole = adminRole;\n emit RoleAdminChanged(role, previousAdminRole, adminRole);\n }\n\n /**\n * @dev Grants `role` to `account`.\n *\n * Internal function without access restriction.\n *\n * May emit a {RoleGranted} event.\n */\n function _grantRole(bytes32 role, address account) internal virtual {\n if (!hasRole(role, account)) {\n _roles[role].members[account] = true;\n emit RoleGranted(role, account, _msgSender());\n }\n }\n\n /**\n * @dev Revokes `role` from `account`.\n *\n * Internal function without access restriction.\n *\n * May emit a {RoleRevoked} event.\n */\n function _revokeRole(bytes32 role, address account) internal virtual {\n if (hasRole(role, account)) {\n _roles[role].members[account] = false;\n emit RoleRevoked(role, account, _msgSender());\n }\n }\n}\n" + }, + "@openzeppelin/contracts/access/AccessControlEnumerable.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (access/AccessControlEnumerable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IAccessControlEnumerable.sol\";\nimport \"./AccessControl.sol\";\nimport \"../utils/structs/EnumerableSet.sol\";\n\n/**\n * @dev Extension of {AccessControl} that allows enumerating the members of each role.\n */\nabstract contract AccessControlEnumerable is IAccessControlEnumerable, AccessControl {\n using EnumerableSet for EnumerableSet.AddressSet;\n\n mapping(bytes32 => EnumerableSet.AddressSet) private _roleMembers;\n\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n return interfaceId == type(IAccessControlEnumerable).interfaceId || super.supportsInterface(interfaceId);\n }\n\n /**\n * @dev Returns one of the accounts that have `role`. `index` must be a\n * value between 0 and {getRoleMemberCount}, non-inclusive.\n *\n * Role bearers are not sorted in any particular way, and their ordering may\n * change at any point.\n *\n * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure\n * you perform all queries on the same block. See the following\n * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]\n * for more information.\n */\n function getRoleMember(bytes32 role, uint256 index) public view virtual override returns (address) {\n return _roleMembers[role].at(index);\n }\n\n /**\n * @dev Returns the number of accounts that have `role`. Can be used\n * together with {getRoleMember} to enumerate all bearers of a role.\n */\n function getRoleMemberCount(bytes32 role) public view virtual override returns (uint256) {\n return _roleMembers[role].length();\n }\n\n /**\n * @dev Overload {_grantRole} to track enumerable memberships\n */\n function _grantRole(bytes32 role, address account) internal virtual override {\n super._grantRole(role, account);\n _roleMembers[role].add(account);\n }\n\n /**\n * @dev Overload {_revokeRole} to track enumerable memberships\n */\n function _revokeRole(bytes32 role, address account) internal virtual override {\n super._revokeRole(role, account);\n _roleMembers[role].remove(account);\n }\n}\n" + }, + "@openzeppelin/contracts/access/IAccessControl.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev External interface of AccessControl declared to support ERC165 detection.\n */\ninterface IAccessControl {\n /**\n * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`\n *\n * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite\n * {RoleAdminChanged} not being emitted signaling this.\n *\n * _Available since v3.1._\n */\n event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);\n\n /**\n * @dev Emitted when `account` is granted `role`.\n *\n * `sender` is the account that originated the contract call, an admin role\n * bearer except when using {AccessControl-_setupRole}.\n */\n event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);\n\n /**\n * @dev Emitted when `account` is revoked `role`.\n *\n * `sender` is the account that originated the contract call:\n * - if using `revokeRole`, it is the admin role bearer\n * - if using `renounceRole`, it is the role bearer (i.e. `account`)\n */\n event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);\n\n /**\n * @dev Returns `true` if `account` has been granted `role`.\n */\n function hasRole(bytes32 role, address account) external view returns (bool);\n\n /**\n * @dev Returns the admin role that controls `role`. See {grantRole} and\n * {revokeRole}.\n *\n * To change a role's admin, use {AccessControl-_setRoleAdmin}.\n */\n function getRoleAdmin(bytes32 role) external view returns (bytes32);\n\n /**\n * @dev Grants `role` to `account`.\n *\n * If `account` had not been already granted `role`, emits a {RoleGranted}\n * event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n */\n function grantRole(bytes32 role, address account) external;\n\n /**\n * @dev Revokes `role` from `account`.\n *\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n */\n function revokeRole(bytes32 role, address account) external;\n\n /**\n * @dev Revokes `role` from the calling account.\n *\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\n * purpose is to provide a mechanism for accounts to lose their privileges\n * if they are compromised (such as when a trusted device is misplaced).\n *\n * If the calling account had been granted `role`, emits a {RoleRevoked}\n * event.\n *\n * Requirements:\n *\n * - the caller must be `account`.\n */\n function renounceRole(bytes32 role, address account) external;\n}\n" + }, + "@openzeppelin/contracts/access/IAccessControlEnumerable.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (access/IAccessControlEnumerable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IAccessControl.sol\";\n\n/**\n * @dev External interface of AccessControlEnumerable declared to support ERC165 detection.\n */\ninterface IAccessControlEnumerable is IAccessControl {\n /**\n * @dev Returns one of the accounts that have `role`. `index` must be a\n * value between 0 and {getRoleMemberCount}, non-inclusive.\n *\n * Role bearers are not sorted in any particular way, and their ordering may\n * change at any point.\n *\n * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure\n * you perform all queries on the same block. See the following\n * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]\n * for more information.\n */\n function getRoleMember(bytes32 role, uint256 index) external view returns (address);\n\n /**\n * @dev Returns the number of accounts that have `role`. Can be used\n * together with {getRoleMember} to enumerate all bearers of a role.\n */\n function getRoleMemberCount(bytes32 role) external view returns (uint256);\n}\n" + }, + "@openzeppelin/contracts/security/Pausable.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which allows children to implement an emergency stop\n * mechanism that can be triggered by an authorized account.\n *\n * This module is used through inheritance. It will make available the\n * modifiers `whenNotPaused` and `whenPaused`, which can be applied to\n * the functions of your contract. Note that they will not be pausable by\n * simply including this module, only once the modifiers are put in place.\n */\nabstract contract Pausable is Context {\n /**\n * @dev Emitted when the pause is triggered by `account`.\n */\n event Paused(address account);\n\n /**\n * @dev Emitted when the pause is lifted by `account`.\n */\n event Unpaused(address account);\n\n bool private _paused;\n\n /**\n * @dev Initializes the contract in unpaused state.\n */\n constructor() {\n _paused = false;\n }\n\n /**\n * @dev Modifier to make a function callable only when the contract is not paused.\n *\n * Requirements:\n *\n * - The contract must not be paused.\n */\n modifier whenNotPaused() {\n _requireNotPaused();\n _;\n }\n\n /**\n * @dev Modifier to make a function callable only when the contract is paused.\n *\n * Requirements:\n *\n * - The contract must be paused.\n */\n modifier whenPaused() {\n _requirePaused();\n _;\n }\n\n /**\n * @dev Returns true if the contract is paused, and false otherwise.\n */\n function paused() public view virtual returns (bool) {\n return _paused;\n }\n\n /**\n * @dev Throws if the contract is paused.\n */\n function _requireNotPaused() internal view virtual {\n require(!paused(), \"Pausable: paused\");\n }\n\n /**\n * @dev Throws if the contract is not paused.\n */\n function _requirePaused() internal view virtual {\n require(paused(), \"Pausable: not paused\");\n }\n\n /**\n * @dev Triggers stopped state.\n *\n * Requirements:\n *\n * - The contract must not be paused.\n */\n function _pause() internal virtual whenNotPaused {\n _paused = true;\n emit Paused(_msgSender());\n }\n\n /**\n * @dev Returns to normal state.\n *\n * Requirements:\n *\n * - The contract must be paused.\n */\n function _unpause() internal virtual whenPaused {\n _paused = false;\n emit Unpaused(_msgSender());\n }\n}\n" + }, + "@openzeppelin/contracts/token/ERC20/ERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/ERC20.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC20.sol\";\nimport \"./extensions/IERC20Metadata.sol\";\nimport \"../../utils/Context.sol\";\n\n/**\n * @dev Implementation of the {IERC20} interface.\n *\n * This implementation is agnostic to the way tokens are created. This means\n * that a supply mechanism has to be added in a derived contract using {_mint}.\n * For a generic mechanism see {ERC20PresetMinterPauser}.\n *\n * TIP: For a detailed writeup see our guide\n * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How\n * to implement supply mechanisms].\n *\n * We have followed general OpenZeppelin Contracts guidelines: functions revert\n * instead returning `false` on failure. This behavior is nonetheless\n * conventional and does not conflict with the expectations of ERC20\n * applications.\n *\n * Additionally, an {Approval} event is emitted on calls to {transferFrom}.\n * This allows applications to reconstruct the allowance for all accounts just\n * by listening to said events. Other implementations of the EIP may not emit\n * these events, as it isn't required by the specification.\n *\n * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}\n * functions have been added to mitigate the well-known issues around setting\n * allowances. See {IERC20-approve}.\n */\ncontract ERC20 is Context, IERC20, IERC20Metadata {\n mapping(address => uint256) private _balances;\n\n mapping(address => mapping(address => uint256)) private _allowances;\n\n uint256 private _totalSupply;\n\n string private _name;\n string private _symbol;\n\n /**\n * @dev Sets the values for {name} and {symbol}.\n *\n * The default value of {decimals} is 18. To select a different value for\n * {decimals} you should overload it.\n *\n * All two of these values are immutable: they can only be set once during\n * construction.\n */\n constructor(string memory name_, string memory symbol_) {\n _name = name_;\n _symbol = symbol_;\n }\n\n /**\n * @dev Returns the name of the token.\n */\n function name() public view virtual override returns (string memory) {\n return _name;\n }\n\n /**\n * @dev Returns the symbol of the token, usually a shorter version of the\n * name.\n */\n function symbol() public view virtual override returns (string memory) {\n return _symbol;\n }\n\n /**\n * @dev Returns the number of decimals used to get its user representation.\n * For example, if `decimals` equals `2`, a balance of `505` tokens should\n * be displayed to a user as `5.05` (`505 / 10 ** 2`).\n *\n * Tokens usually opt for a value of 18, imitating the relationship between\n * Ether and Wei. This is the value {ERC20} uses, unless this function is\n * overridden;\n *\n * NOTE: This information is only used for _display_ purposes: it in\n * no way affects any of the arithmetic of the contract, including\n * {IERC20-balanceOf} and {IERC20-transfer}.\n */\n function decimals() public view virtual override returns (uint8) {\n return 18;\n }\n\n /**\n * @dev See {IERC20-totalSupply}.\n */\n function totalSupply() public view virtual override returns (uint256) {\n return _totalSupply;\n }\n\n /**\n * @dev See {IERC20-balanceOf}.\n */\n function balanceOf(address account) public view virtual override returns (uint256) {\n return _balances[account];\n }\n\n /**\n * @dev See {IERC20-transfer}.\n *\n * Requirements:\n *\n * - `to` cannot be the zero address.\n * - the caller must have a balance of at least `amount`.\n */\n function transfer(address to, uint256 amount) public virtual override returns (bool) {\n address owner = _msgSender();\n _transfer(owner, to, amount);\n return true;\n }\n\n /**\n * @dev See {IERC20-allowance}.\n */\n function allowance(address owner, address spender) public view virtual override returns (uint256) {\n return _allowances[owner][spender];\n }\n\n /**\n * @dev See {IERC20-approve}.\n *\n * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on\n * `transferFrom`. This is semantically equivalent to an infinite approval.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function approve(address spender, uint256 amount) public virtual override returns (bool) {\n address owner = _msgSender();\n _approve(owner, spender, amount);\n return true;\n }\n\n /**\n * @dev See {IERC20-transferFrom}.\n *\n * Emits an {Approval} event indicating the updated allowance. This is not\n * required by the EIP. See the note at the beginning of {ERC20}.\n *\n * NOTE: Does not update the allowance if the current allowance\n * is the maximum `uint256`.\n *\n * Requirements:\n *\n * - `from` and `to` cannot be the zero address.\n * - `from` must have a balance of at least `amount`.\n * - the caller must have allowance for ``from``'s tokens of at least\n * `amount`.\n */\n function transferFrom(\n address from,\n address to,\n uint256 amount\n ) public virtual override returns (bool) {\n address spender = _msgSender();\n _spendAllowance(from, spender, amount);\n _transfer(from, to, amount);\n return true;\n }\n\n /**\n * @dev Atomically increases the allowance granted to `spender` by the caller.\n *\n * This is an alternative to {approve} that can be used as a mitigation for\n * problems described in {IERC20-approve}.\n *\n * Emits an {Approval} event indicating the updated allowance.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {\n address owner = _msgSender();\n _approve(owner, spender, allowance(owner, spender) + addedValue);\n return true;\n }\n\n /**\n * @dev Atomically decreases the allowance granted to `spender` by the caller.\n *\n * This is an alternative to {approve} that can be used as a mitigation for\n * problems described in {IERC20-approve}.\n *\n * Emits an {Approval} event indicating the updated allowance.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n * - `spender` must have allowance for the caller of at least\n * `subtractedValue`.\n */\n function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {\n address owner = _msgSender();\n uint256 currentAllowance = allowance(owner, spender);\n require(currentAllowance >= subtractedValue, \"ERC20: decreased allowance below zero\");\n unchecked {\n _approve(owner, spender, currentAllowance - subtractedValue);\n }\n\n return true;\n }\n\n /**\n * @dev Moves `amount` of tokens from `from` to `to`.\n *\n * This internal function is equivalent to {transfer}, and can be used to\n * e.g. implement automatic token fees, slashing mechanisms, etc.\n *\n * Emits a {Transfer} event.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `from` must have a balance of at least `amount`.\n */\n function _transfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual {\n require(from != address(0), \"ERC20: transfer from the zero address\");\n require(to != address(0), \"ERC20: transfer to the zero address\");\n\n _beforeTokenTransfer(from, to, amount);\n\n uint256 fromBalance = _balances[from];\n require(fromBalance >= amount, \"ERC20: transfer amount exceeds balance\");\n unchecked {\n _balances[from] = fromBalance - amount;\n // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by\n // decrementing then incrementing.\n _balances[to] += amount;\n }\n\n emit Transfer(from, to, amount);\n\n _afterTokenTransfer(from, to, amount);\n }\n\n /** @dev Creates `amount` tokens and assigns them to `account`, increasing\n * the total supply.\n *\n * Emits a {Transfer} event with `from` set to the zero address.\n *\n * Requirements:\n *\n * - `account` cannot be the zero address.\n */\n function _mint(address account, uint256 amount) internal virtual {\n require(account != address(0), \"ERC20: mint to the zero address\");\n\n _beforeTokenTransfer(address(0), account, amount);\n\n _totalSupply += amount;\n unchecked {\n // Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.\n _balances[account] += amount;\n }\n emit Transfer(address(0), account, amount);\n\n _afterTokenTransfer(address(0), account, amount);\n }\n\n /**\n * @dev Destroys `amount` tokens from `account`, reducing the\n * total supply.\n *\n * Emits a {Transfer} event with `to` set to the zero address.\n *\n * Requirements:\n *\n * - `account` cannot be the zero address.\n * - `account` must have at least `amount` tokens.\n */\n function _burn(address account, uint256 amount) internal virtual {\n require(account != address(0), \"ERC20: burn from the zero address\");\n\n _beforeTokenTransfer(account, address(0), amount);\n\n uint256 accountBalance = _balances[account];\n require(accountBalance >= amount, \"ERC20: burn amount exceeds balance\");\n unchecked {\n _balances[account] = accountBalance - amount;\n // Overflow not possible: amount <= accountBalance <= totalSupply.\n _totalSupply -= amount;\n }\n\n emit Transfer(account, address(0), amount);\n\n _afterTokenTransfer(account, address(0), amount);\n }\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.\n *\n * This internal function is equivalent to `approve`, and can be used to\n * e.g. set automatic allowances for certain subsystems, etc.\n *\n * Emits an {Approval} event.\n *\n * Requirements:\n *\n * - `owner` cannot be the zero address.\n * - `spender` cannot be the zero address.\n */\n function _approve(\n address owner,\n address spender,\n uint256 amount\n ) internal virtual {\n require(owner != address(0), \"ERC20: approve from the zero address\");\n require(spender != address(0), \"ERC20: approve to the zero address\");\n\n _allowances[owner][spender] = amount;\n emit Approval(owner, spender, amount);\n }\n\n /**\n * @dev Updates `owner` s allowance for `spender` based on spent `amount`.\n *\n * Does not update the allowance amount in case of infinite allowance.\n * Revert if not enough allowance is available.\n *\n * Might emit an {Approval} event.\n */\n function _spendAllowance(\n address owner,\n address spender,\n uint256 amount\n ) internal virtual {\n uint256 currentAllowance = allowance(owner, spender);\n if (currentAllowance != type(uint256).max) {\n require(currentAllowance >= amount, \"ERC20: insufficient allowance\");\n unchecked {\n _approve(owner, spender, currentAllowance - amount);\n }\n }\n }\n\n /**\n * @dev Hook that is called before any transfer of tokens. This includes\n * minting and burning.\n *\n * Calling conditions:\n *\n * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n * will be transferred to `to`.\n * - when `from` is zero, `amount` tokens will be minted for `to`.\n * - when `to` is zero, `amount` of ``from``'s tokens will be burned.\n * - `from` and `to` are never both zero.\n *\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n */\n function _beforeTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual {}\n\n /**\n * @dev Hook that is called after any transfer of tokens. This includes\n * minting and burning.\n *\n * Calling conditions:\n *\n * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n * has been transferred to `to`.\n * - when `from` is zero, `amount` tokens have been minted for `to`.\n * - when `to` is zero, `amount` of ``from``'s tokens have been burned.\n * - `from` and `to` are never both zero.\n *\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n */\n function _afterTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual {}\n}\n" + }, + "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/extensions/ERC20Burnable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../ERC20.sol\";\nimport \"../../../utils/Context.sol\";\n\n/**\n * @dev Extension of {ERC20} that allows token holders to destroy both their own\n * tokens and those that they have an allowance for, in a way that can be\n * recognized off-chain (via event analysis).\n */\nabstract contract ERC20Burnable is Context, ERC20 {\n /**\n * @dev Destroys `amount` tokens from the caller.\n *\n * See {ERC20-_burn}.\n */\n function burn(uint256 amount) public virtual {\n _burn(_msgSender(), amount);\n }\n\n /**\n * @dev Destroys `amount` tokens from `account`, deducting from the caller's\n * allowance.\n *\n * See {ERC20-_burn} and {ERC20-allowance}.\n *\n * Requirements:\n *\n * - the caller must have allowance for ``accounts``'s tokens of at least\n * `amount`.\n */\n function burnFrom(address account, uint256 amount) public virtual {\n _spendAllowance(account, _msgSender(), amount);\n _burn(account, amount);\n }\n}\n" + }, + "@openzeppelin/contracts/token/ERC20/extensions/ERC20Pausable.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.2) (token/ERC20/extensions/ERC20Pausable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../ERC20.sol\";\nimport \"../../../security/Pausable.sol\";\n\n/**\n * @dev ERC20 token with pausable token transfers, minting and burning.\n *\n * Useful for scenarios such as preventing trades until the end of an evaluation\n * period, or having an emergency switch for freezing all token transfers in the\n * event of a large bug.\n *\n * IMPORTANT: This contract does not include public pause and unpause functions. In\n * addition to inheriting this contract, you must define both functions, invoking the\n * {Pausable-_pause} and {Pausable-_unpause} internal functions, with appropriate\n * access control, e.g. using {AccessControl} or {Ownable}. Not doing so will\n * make the contract unpausable.\n */\nabstract contract ERC20Pausable is ERC20, Pausable {\n /**\n * @dev See {ERC20-_beforeTokenTransfer}.\n *\n * Requirements:\n *\n * - the contract must not be paused.\n */\n function _beforeTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual override {\n super._beforeTokenTransfer(from, to, amount);\n\n require(!paused(), \"ERC20Pausable: token transfer while paused\");\n }\n}\n" + }, + "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20.sol\";\n\n/**\n * @dev Interface for the optional metadata functions from the ERC20 standard.\n *\n * _Available since v4.1._\n */\ninterface IERC20Metadata is IERC20 {\n /**\n * @dev Returns the name of the token.\n */\n function name() external view returns (string memory);\n\n /**\n * @dev Returns the symbol of the token.\n */\n function symbol() external view returns (string memory);\n\n /**\n * @dev Returns the decimals places of the token.\n */\n function decimals() external view returns (uint8);\n}\n" + }, + "@openzeppelin/contracts/token/ERC20/IERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n /**\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\n * another (`to`).\n *\n * Note that `value` may be zero.\n */\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n /**\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n * a call to {approve}. `value` is the new allowance.\n */\n event Approval(address indexed owner, address indexed spender, uint256 value);\n\n /**\n * @dev Returns the amount of tokens in existence.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns the amount of tokens owned by `account`.\n */\n function balanceOf(address account) external view returns (uint256);\n\n /**\n * @dev Moves `amount` tokens from the caller's account to `to`.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transfer(address to, uint256 amount) external returns (bool);\n\n /**\n * @dev Returns the remaining number of tokens that `spender` will be\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\n * zero by default.\n *\n * This value changes when {approve} or {transferFrom} are called.\n */\n function allowance(address owner, address spender) external view returns (uint256);\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\n * that someone may use both the old and the new allowance by unfortunate\n * transaction ordering. One possible solution to mitigate this race\n * condition is to first reduce the spender's allowance to 0 and set the\n * desired value afterwards:\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n *\n * Emits an {Approval} event.\n */\n function approve(address spender, uint256 amount) external returns (bool);\n\n /**\n * @dev Moves `amount` tokens from `from` to `to` using the\n * allowance mechanism. `amount` is then deducted from the caller's\n * allowance.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(\n address from,\n address to,\n uint256 amount\n ) external returns (bool);\n}\n" + }, + "@openzeppelin/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/presets/ERC20PresetMinterPauser.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../ERC20.sol\";\nimport \"../extensions/ERC20Burnable.sol\";\nimport \"../extensions/ERC20Pausable.sol\";\nimport \"../../../access/AccessControlEnumerable.sol\";\nimport \"../../../utils/Context.sol\";\n\n/**\n * @dev {ERC20} token, including:\n *\n * - ability for holders to burn (destroy) their tokens\n * - a minter role that allows for token minting (creation)\n * - a pauser role that allows to stop all token transfers\n *\n * This contract uses {AccessControl} to lock permissioned functions using the\n * different roles - head to its documentation for details.\n *\n * The account that deploys the contract will be granted the minter and pauser\n * roles, as well as the default admin role, which will let it grant both minter\n * and pauser roles to other accounts.\n *\n * _Deprecated in favor of https://wizard.openzeppelin.com/[Contracts Wizard]._\n */\ncontract ERC20PresetMinterPauser is Context, AccessControlEnumerable, ERC20Burnable, ERC20Pausable {\n bytes32 public constant MINTER_ROLE = keccak256(\"MINTER_ROLE\");\n bytes32 public constant PAUSER_ROLE = keccak256(\"PAUSER_ROLE\");\n\n /**\n * @dev Grants `DEFAULT_ADMIN_ROLE`, `MINTER_ROLE` and `PAUSER_ROLE` to the\n * account that deploys the contract.\n *\n * See {ERC20-constructor}.\n */\n constructor(string memory name, string memory symbol) ERC20(name, symbol) {\n _setupRole(DEFAULT_ADMIN_ROLE, _msgSender());\n\n _setupRole(MINTER_ROLE, _msgSender());\n _setupRole(PAUSER_ROLE, _msgSender());\n }\n\n /**\n * @dev Creates `amount` new tokens for `to`.\n *\n * See {ERC20-_mint}.\n *\n * Requirements:\n *\n * - the caller must have the `MINTER_ROLE`.\n */\n function mint(address to, uint256 amount) public virtual {\n require(hasRole(MINTER_ROLE, _msgSender()), \"ERC20PresetMinterPauser: must have minter role to mint\");\n _mint(to, amount);\n }\n\n /**\n * @dev Pauses all token transfers.\n *\n * See {ERC20Pausable} and {Pausable-_pause}.\n *\n * Requirements:\n *\n * - the caller must have the `PAUSER_ROLE`.\n */\n function pause() public virtual {\n require(hasRole(PAUSER_ROLE, _msgSender()), \"ERC20PresetMinterPauser: must have pauser role to pause\");\n _pause();\n }\n\n /**\n * @dev Unpauses all token transfers.\n *\n * See {ERC20Pausable} and {Pausable-_unpause}.\n *\n * Requirements:\n *\n * - the caller must have the `PAUSER_ROLE`.\n */\n function unpause() public virtual {\n require(hasRole(PAUSER_ROLE, _msgSender()), \"ERC20PresetMinterPauser: must have pauser role to unpause\");\n _unpause();\n }\n\n function _beforeTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual override(ERC20, ERC20Pausable) {\n super._beforeTokenTransfer(from, to, amount);\n }\n}\n" + }, + "@openzeppelin/contracts/utils/Context.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n}\n" + }, + "@openzeppelin/contracts/utils/introspection/ERC165.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC165.sol\";\n\n/**\n * @dev Implementation of the {IERC165} interface.\n *\n * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check\n * for the additional interface id that will be supported. For example:\n *\n * ```solidity\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\n * }\n * ```\n *\n * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.\n */\nabstract contract ERC165 is IERC165 {\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n return interfaceId == type(IERC165).interfaceId;\n }\n}\n" + }, + "@openzeppelin/contracts/utils/introspection/IERC165.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC165 standard, as defined in the\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\n *\n * Implementers can declare support of contract interfaces, which can then be\n * queried by others ({ERC165Checker}).\n *\n * For an implementation, see {ERC165}.\n */\ninterface IERC165 {\n /**\n * @dev Returns true if this contract implements the interface defined by\n * `interfaceId`. See the corresponding\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\n * to learn more about how these ids are created.\n *\n * This function call must use less than 30 000 gas.\n */\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n" + }, + "@openzeppelin/contracts/utils/math/Math.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Standard math utilities missing in the Solidity language.\n */\nlibrary Math {\n enum Rounding {\n Down, // Toward negative infinity\n Up, // Toward infinity\n Zero // Toward zero\n }\n\n /**\n * @dev Returns the largest of two numbers.\n */\n function max(uint256 a, uint256 b) internal pure returns (uint256) {\n return a > b ? a : b;\n }\n\n /**\n * @dev Returns the smallest of two numbers.\n */\n function min(uint256 a, uint256 b) internal pure returns (uint256) {\n return a < b ? a : b;\n }\n\n /**\n * @dev Returns the average of two numbers. The result is rounded towards\n * zero.\n */\n function average(uint256 a, uint256 b) internal pure returns (uint256) {\n // (a + b) / 2 can overflow.\n return (a & b) + (a ^ b) / 2;\n }\n\n /**\n * @dev Returns the ceiling of the division of two numbers.\n *\n * This differs from standard division with `/` in that it rounds up instead\n * of rounding down.\n */\n function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {\n // (a + b - 1) / b can overflow on addition, so we distribute.\n return a == 0 ? 0 : (a - 1) / b + 1;\n }\n\n /**\n * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0\n * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)\n * with further edits by Uniswap Labs also under MIT license.\n */\n function mulDiv(\n uint256 x,\n uint256 y,\n uint256 denominator\n ) internal pure returns (uint256 result) {\n unchecked {\n // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use\n // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256\n // variables such that product = prod1 * 2^256 + prod0.\n uint256 prod0; // Least significant 256 bits of the product\n uint256 prod1; // Most significant 256 bits of the product\n assembly {\n let mm := mulmod(x, y, not(0))\n prod0 := mul(x, y)\n prod1 := sub(sub(mm, prod0), lt(mm, prod0))\n }\n\n // Handle non-overflow cases, 256 by 256 division.\n if (prod1 == 0) {\n return prod0 / denominator;\n }\n\n // Make sure the result is less than 2^256. Also prevents denominator == 0.\n require(denominator > prod1);\n\n ///////////////////////////////////////////////\n // 512 by 256 division.\n ///////////////////////////////////////////////\n\n // Make division exact by subtracting the remainder from [prod1 prod0].\n uint256 remainder;\n assembly {\n // Compute remainder using mulmod.\n remainder := mulmod(x, y, denominator)\n\n // Subtract 256 bit number from 512 bit number.\n prod1 := sub(prod1, gt(remainder, prod0))\n prod0 := sub(prod0, remainder)\n }\n\n // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.\n // See https://cs.stackexchange.com/q/138556/92363.\n\n // Does not overflow because the denominator cannot be zero at this stage in the function.\n uint256 twos = denominator & (~denominator + 1);\n assembly {\n // Divide denominator by twos.\n denominator := div(denominator, twos)\n\n // Divide [prod1 prod0] by twos.\n prod0 := div(prod0, twos)\n\n // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.\n twos := add(div(sub(0, twos), twos), 1)\n }\n\n // Shift in bits from prod1 into prod0.\n prod0 |= prod1 * twos;\n\n // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such\n // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for\n // four bits. That is, denominator * inv = 1 mod 2^4.\n uint256 inverse = (3 * denominator) ^ 2;\n\n // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works\n // in modular arithmetic, doubling the correct bits in each step.\n inverse *= 2 - denominator * inverse; // inverse mod 2^8\n inverse *= 2 - denominator * inverse; // inverse mod 2^16\n inverse *= 2 - denominator * inverse; // inverse mod 2^32\n inverse *= 2 - denominator * inverse; // inverse mod 2^64\n inverse *= 2 - denominator * inverse; // inverse mod 2^128\n inverse *= 2 - denominator * inverse; // inverse mod 2^256\n\n // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.\n // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is\n // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1\n // is no longer required.\n result = prod0 * inverse;\n return result;\n }\n }\n\n /**\n * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.\n */\n function mulDiv(\n uint256 x,\n uint256 y,\n uint256 denominator,\n Rounding rounding\n ) internal pure returns (uint256) {\n uint256 result = mulDiv(x, y, denominator);\n if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {\n result += 1;\n }\n return result;\n }\n\n /**\n * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.\n *\n * Inspired by Henry S. Warren, Jr.'s \"Hacker's Delight\" (Chapter 11).\n */\n function sqrt(uint256 a) internal pure returns (uint256) {\n if (a == 0) {\n return 0;\n }\n\n // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.\n //\n // We know that the \"msb\" (most significant bit) of our target number `a` is a power of 2 such that we have\n // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.\n //\n // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`\n // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`\n // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`\n //\n // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.\n uint256 result = 1 << (log2(a) >> 1);\n\n // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,\n // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at\n // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision\n // into the expected uint128 result.\n unchecked {\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n return min(result, a / result);\n }\n }\n\n /**\n * @notice Calculates sqrt(a), following the selected rounding direction.\n */\n function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = sqrt(a);\n return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);\n }\n }\n\n /**\n * @dev Return the log in base 2, rounded down, of a positive value.\n * Returns 0 if given 0.\n */\n function log2(uint256 value) internal pure returns (uint256) {\n uint256 result = 0;\n unchecked {\n if (value >> 128 > 0) {\n value >>= 128;\n result += 128;\n }\n if (value >> 64 > 0) {\n value >>= 64;\n result += 64;\n }\n if (value >> 32 > 0) {\n value >>= 32;\n result += 32;\n }\n if (value >> 16 > 0) {\n value >>= 16;\n result += 16;\n }\n if (value >> 8 > 0) {\n value >>= 8;\n result += 8;\n }\n if (value >> 4 > 0) {\n value >>= 4;\n result += 4;\n }\n if (value >> 2 > 0) {\n value >>= 2;\n result += 2;\n }\n if (value >> 1 > 0) {\n result += 1;\n }\n }\n return result;\n }\n\n /**\n * @dev Return the log in base 2, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log2(value);\n return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);\n }\n }\n\n /**\n * @dev Return the log in base 10, rounded down, of a positive value.\n * Returns 0 if given 0.\n */\n function log10(uint256 value) internal pure returns (uint256) {\n uint256 result = 0;\n unchecked {\n if (value >= 10**64) {\n value /= 10**64;\n result += 64;\n }\n if (value >= 10**32) {\n value /= 10**32;\n result += 32;\n }\n if (value >= 10**16) {\n value /= 10**16;\n result += 16;\n }\n if (value >= 10**8) {\n value /= 10**8;\n result += 8;\n }\n if (value >= 10**4) {\n value /= 10**4;\n result += 4;\n }\n if (value >= 10**2) {\n value /= 10**2;\n result += 2;\n }\n if (value >= 10**1) {\n result += 1;\n }\n }\n return result;\n }\n\n /**\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log10(value);\n return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);\n }\n }\n\n /**\n * @dev Return the log in base 256, rounded down, of a positive value.\n * Returns 0 if given 0.\n *\n * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.\n */\n function log256(uint256 value) internal pure returns (uint256) {\n uint256 result = 0;\n unchecked {\n if (value >> 128 > 0) {\n value >>= 128;\n result += 16;\n }\n if (value >> 64 > 0) {\n value >>= 64;\n result += 8;\n }\n if (value >> 32 > 0) {\n value >>= 32;\n result += 4;\n }\n if (value >> 16 > 0) {\n value >>= 16;\n result += 2;\n }\n if (value >> 8 > 0) {\n result += 1;\n }\n }\n return result;\n }\n\n /**\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log256(value);\n return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);\n }\n }\n}\n" + }, + "@openzeppelin/contracts/utils/Strings.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./math/Math.sol\";\n\n/**\n * @dev String operations.\n */\nlibrary Strings {\n bytes16 private constant _SYMBOLS = \"0123456789abcdef\";\n uint8 private constant _ADDRESS_LENGTH = 20;\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` decimal representation.\n */\n function toString(uint256 value) internal pure returns (string memory) {\n unchecked {\n uint256 length = Math.log10(value) + 1;\n string memory buffer = new string(length);\n uint256 ptr;\n /// @solidity memory-safe-assembly\n assembly {\n ptr := add(buffer, add(32, length))\n }\n while (true) {\n ptr--;\n /// @solidity memory-safe-assembly\n assembly {\n mstore8(ptr, byte(mod(value, 10), _SYMBOLS))\n }\n value /= 10;\n if (value == 0) break;\n }\n return buffer;\n }\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\n */\n function toHexString(uint256 value) internal pure returns (string memory) {\n unchecked {\n return toHexString(value, Math.log256(value) + 1);\n }\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\n */\n function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\n bytes memory buffer = new bytes(2 * length + 2);\n buffer[0] = \"0\";\n buffer[1] = \"x\";\n for (uint256 i = 2 * length + 1; i > 1; --i) {\n buffer[i] = _SYMBOLS[value & 0xf];\n value >>= 4;\n }\n require(value == 0, \"Strings: hex length insufficient\");\n return string(buffer);\n }\n\n /**\n * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.\n */\n function toHexString(address addr) internal pure returns (string memory) {\n return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);\n }\n}\n" + }, + "@openzeppelin/contracts/utils/structs/EnumerableSet.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/structs/EnumerableSet.sol)\n// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Library for managing\n * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive\n * types.\n *\n * Sets have the following properties:\n *\n * - Elements are added, removed, and checked for existence in constant time\n * (O(1)).\n * - Elements are enumerated in O(n). No guarantees are made on the ordering.\n *\n * ```\n * contract Example {\n * // Add the library methods\n * using EnumerableSet for EnumerableSet.AddressSet;\n *\n * // Declare a set state variable\n * EnumerableSet.AddressSet private mySet;\n * }\n * ```\n *\n * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)\n * and `uint256` (`UintSet`) are supported.\n *\n * [WARNING]\n * ====\n * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure\n * unusable.\n * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.\n *\n * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an\n * array of EnumerableSet.\n * ====\n */\nlibrary EnumerableSet {\n // To implement this library for multiple types with as little code\n // repetition as possible, we write it in terms of a generic Set type with\n // bytes32 values.\n // The Set implementation uses private functions, and user-facing\n // implementations (such as AddressSet) are just wrappers around the\n // underlying Set.\n // This means that we can only create new EnumerableSets for types that fit\n // in bytes32.\n\n struct Set {\n // Storage of set values\n bytes32[] _values;\n // Position of the value in the `values` array, plus 1 because index 0\n // means a value is not in the set.\n mapping(bytes32 => uint256) _indexes;\n }\n\n /**\n * @dev Add a value to a set. O(1).\n *\n * Returns true if the value was added to the set, that is if it was not\n * already present.\n */\n function _add(Set storage set, bytes32 value) private returns (bool) {\n if (!_contains(set, value)) {\n set._values.push(value);\n // The value is stored at length-1, but we add 1 to all indexes\n // and use 0 as a sentinel value\n set._indexes[value] = set._values.length;\n return true;\n } else {\n return false;\n }\n }\n\n /**\n * @dev Removes a value from a set. O(1).\n *\n * Returns true if the value was removed from the set, that is if it was\n * present.\n */\n function _remove(Set storage set, bytes32 value) private returns (bool) {\n // We read and store the value's index to prevent multiple reads from the same storage slot\n uint256 valueIndex = set._indexes[value];\n\n if (valueIndex != 0) {\n // Equivalent to contains(set, value)\n // To delete an element from the _values array in O(1), we swap the element to delete with the last one in\n // the array, and then remove the last element (sometimes called as 'swap and pop').\n // This modifies the order of the array, as noted in {at}.\n\n uint256 toDeleteIndex = valueIndex - 1;\n uint256 lastIndex = set._values.length - 1;\n\n if (lastIndex != toDeleteIndex) {\n bytes32 lastValue = set._values[lastIndex];\n\n // Move the last value to the index where the value to delete is\n set._values[toDeleteIndex] = lastValue;\n // Update the index for the moved value\n set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex\n }\n\n // Delete the slot where the moved value was stored\n set._values.pop();\n\n // Delete the index for the deleted slot\n delete set._indexes[value];\n\n return true;\n } else {\n return false;\n }\n }\n\n /**\n * @dev Returns true if the value is in the set. O(1).\n */\n function _contains(Set storage set, bytes32 value) private view returns (bool) {\n return set._indexes[value] != 0;\n }\n\n /**\n * @dev Returns the number of values on the set. O(1).\n */\n function _length(Set storage set) private view returns (uint256) {\n return set._values.length;\n }\n\n /**\n * @dev Returns the value stored at position `index` in the set. O(1).\n *\n * Note that there are no guarantees on the ordering of values inside the\n * array, and it may change when more values are added or removed.\n *\n * Requirements:\n *\n * - `index` must be strictly less than {length}.\n */\n function _at(Set storage set, uint256 index) private view returns (bytes32) {\n return set._values[index];\n }\n\n /**\n * @dev Return the entire set in an array\n *\n * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n */\n function _values(Set storage set) private view returns (bytes32[] memory) {\n return set._values;\n }\n\n // Bytes32Set\n\n struct Bytes32Set {\n Set _inner;\n }\n\n /**\n * @dev Add a value to a set. O(1).\n *\n * Returns true if the value was added to the set, that is if it was not\n * already present.\n */\n function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {\n return _add(set._inner, value);\n }\n\n /**\n * @dev Removes a value from a set. O(1).\n *\n * Returns true if the value was removed from the set, that is if it was\n * present.\n */\n function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {\n return _remove(set._inner, value);\n }\n\n /**\n * @dev Returns true if the value is in the set. O(1).\n */\n function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {\n return _contains(set._inner, value);\n }\n\n /**\n * @dev Returns the number of values in the set. O(1).\n */\n function length(Bytes32Set storage set) internal view returns (uint256) {\n return _length(set._inner);\n }\n\n /**\n * @dev Returns the value stored at position `index` in the set. O(1).\n *\n * Note that there are no guarantees on the ordering of values inside the\n * array, and it may change when more values are added or removed.\n *\n * Requirements:\n *\n * - `index` must be strictly less than {length}.\n */\n function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {\n return _at(set._inner, index);\n }\n\n /**\n * @dev Return the entire set in an array\n *\n * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n */\n function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {\n bytes32[] memory store = _values(set._inner);\n bytes32[] memory result;\n\n /// @solidity memory-safe-assembly\n assembly {\n result := store\n }\n\n return result;\n }\n\n // AddressSet\n\n struct AddressSet {\n Set _inner;\n }\n\n /**\n * @dev Add a value to a set. O(1).\n *\n * Returns true if the value was added to the set, that is if it was not\n * already present.\n */\n function add(AddressSet storage set, address value) internal returns (bool) {\n return _add(set._inner, bytes32(uint256(uint160(value))));\n }\n\n /**\n * @dev Removes a value from a set. O(1).\n *\n * Returns true if the value was removed from the set, that is if it was\n * present.\n */\n function remove(AddressSet storage set, address value) internal returns (bool) {\n return _remove(set._inner, bytes32(uint256(uint160(value))));\n }\n\n /**\n * @dev Returns true if the value is in the set. O(1).\n */\n function contains(AddressSet storage set, address value) internal view returns (bool) {\n return _contains(set._inner, bytes32(uint256(uint160(value))));\n }\n\n /**\n * @dev Returns the number of values in the set. O(1).\n */\n function length(AddressSet storage set) internal view returns (uint256) {\n return _length(set._inner);\n }\n\n /**\n * @dev Returns the value stored at position `index` in the set. O(1).\n *\n * Note that there are no guarantees on the ordering of values inside the\n * array, and it may change when more values are added or removed.\n *\n * Requirements:\n *\n * - `index` must be strictly less than {length}.\n */\n function at(AddressSet storage set, uint256 index) internal view returns (address) {\n return address(uint160(uint256(_at(set._inner, index))));\n }\n\n /**\n * @dev Return the entire set in an array\n *\n * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n */\n function values(AddressSet storage set) internal view returns (address[] memory) {\n bytes32[] memory store = _values(set._inner);\n address[] memory result;\n\n /// @solidity memory-safe-assembly\n assembly {\n result := store\n }\n\n return result;\n }\n\n // UintSet\n\n struct UintSet {\n Set _inner;\n }\n\n /**\n * @dev Add a value to a set. O(1).\n *\n * Returns true if the value was added to the set, that is if it was not\n * already present.\n */\n function add(UintSet storage set, uint256 value) internal returns (bool) {\n return _add(set._inner, bytes32(value));\n }\n\n /**\n * @dev Removes a value from a set. O(1).\n *\n * Returns true if the value was removed from the set, that is if it was\n * present.\n */\n function remove(UintSet storage set, uint256 value) internal returns (bool) {\n return _remove(set._inner, bytes32(value));\n }\n\n /**\n * @dev Returns true if the value is in the set. O(1).\n */\n function contains(UintSet storage set, uint256 value) internal view returns (bool) {\n return _contains(set._inner, bytes32(value));\n }\n\n /**\n * @dev Returns the number of values in the set. O(1).\n */\n function length(UintSet storage set) internal view returns (uint256) {\n return _length(set._inner);\n }\n\n /**\n * @dev Returns the value stored at position `index` in the set. O(1).\n *\n * Note that there are no guarantees on the ordering of values inside the\n * array, and it may change when more values are added or removed.\n *\n * Requirements:\n *\n * - `index` must be strictly less than {length}.\n */\n function at(UintSet storage set, uint256 index) internal view returns (uint256) {\n return uint256(_at(set._inner, index));\n }\n\n /**\n * @dev Return the entire set in an array\n *\n * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n */\n function values(UintSet storage set) internal view returns (uint256[] memory) {\n bytes32[] memory store = _values(set._inner);\n uint256[] memory result;\n\n /// @solidity memory-safe-assembly\n assembly {\n result := store\n }\n\n return result;\n }\n}\n" + }, + "src/interface/IPostageStamp.sol": { + "content": "// SPDX-License-Identifier: BSD-3-Clause\npragma solidity ^0.8.19;\n\ninterface IPostageStamp {\n function withdraw(address beneficiary) external;\n\n function setPrice(uint256 _price) external;\n\n function validChunkCount() external view returns (uint256);\n\n function batchOwner(bytes32 _batchId) external view returns (address);\n\n function batchDepth(bytes32 _batchId) external view returns (uint8);\n\n function batchBucketDepth(bytes32 _batchId) external view returns (uint8);\n\n function remainingBalance(bytes32 _batchId) external view returns (uint256);\n\n function minimumInitialBalancePerChunk() external view returns (uint256);\n\n function batches(\n bytes32\n )\n external\n view\n returns (\n address owner,\n uint8 depth,\n uint8 bucketDepth,\n bool immutableFlag,\n uint256 normalisedBalance,\n uint256 lastUpdatedBlockNumber\n );\n}\n" + }, + "src/OrderStatisticsTree/HitchensOrderStatisticsTreeLib.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\n/*\nHitchens Order Statistics Tree v0.99\n\nA Solidity Red-Black Tree library to store and maintain a sorted data\nstructure in a Red-Black binary search tree, with O(log 2n) insert, remove\nand search time (and gas, approximately)\n\nhttps://github.com/rob-Hitchens/OrderStatisticsTree\n\nCopyright (c) Rob Hitchens. the MIT License\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\nSignificant portions from BokkyPooBahsRedBlackTreeLibrary,\nhttps://github.com/bokkypoobah/BokkyPooBahsRedBlackTreeLibrary\n\nTHIS SOFTWARE IS NOT TESTED OR AUDITED. DO NOT USE FOR PRODUCTION.\n*/\n\nlibrary HitchensOrderStatisticsTreeLib {\n uint private constant EMPTY = 0;\n struct Node {\n uint parent;\n uint left;\n uint right;\n bool red;\n bytes32[] keys;\n mapping(bytes32 => uint) keyMap;\n uint count;\n }\n struct Tree {\n uint root;\n mapping(uint => Node) nodes;\n }\n\n error ValueDoesNotExist(); // Provided value doesn't exist in the tree.\n error ValueCannotBeZero(); // Value to insert cannot be zero\n error ValueKeyPairExists(); // Value and Key pair exists. Cannot be inserted again.\n\n function first(Tree storage self) internal view returns (uint _value) {\n _value = self.root;\n if (_value == EMPTY) return 0;\n while (self.nodes[_value].left != EMPTY) {\n _value = self.nodes[_value].left;\n }\n }\n\n function exists(Tree storage self, uint value) internal view returns (bool _exists) {\n if (value == EMPTY) return false;\n if (value == self.root) return true;\n if (self.nodes[value].parent != EMPTY) return true;\n return false;\n }\n\n function keyExists(Tree storage self, bytes32 key, uint value) internal view returns (bool _exists) {\n if (!exists(self, value)) return false;\n return self.nodes[value].keys[self.nodes[value].keyMap[key]] == key;\n }\n\n function getNode(\n Tree storage self,\n uint value\n ) internal view returns (uint _parent, uint _left, uint _right, bool _red, uint keyCount, uint __count) {\n if (!exists(self, value)) {\n revert ValueDoesNotExist();\n }\n\n Node storage gn = self.nodes[value];\n return (gn.parent, gn.left, gn.right, gn.red, gn.keys.length, gn.keys.length + gn.count);\n }\n\n function getNodeCount(Tree storage self, uint value) internal view returns (uint __count) {\n Node storage gn = self.nodes[value];\n return gn.keys.length + gn.count;\n }\n\n function valueKeyAtIndex(Tree storage self, uint value, uint index) internal view returns (bytes32 _key) {\n if (!exists(self, value)) {\n revert ValueDoesNotExist();\n }\n return self.nodes[value].keys[index];\n }\n\n function count(Tree storage self) internal view returns (uint _count) {\n return getNodeCount(self, self.root);\n }\n\n /* We don't use this functionality, so it is commented out to make audit easier\n\n function percentile(Tree storage self, uint value) internal view returns(uint _percentile) {\n uint denominator = count(self);\n uint numerator = rank(self, value);\n _percentile = ((uint(1000) * numerator)/denominator+(uint(5)))/uint(10);\n }\n function permil(Tree storage self, uint value) internal view returns(uint _permil) {\n uint denominator = count(self);\n uint numerator = rank(self, value);\n _permil = ((uint(10000) * numerator)/denominator+(uint(5)))/uint(10);\n }\n function atPercentile(Tree storage self, uint _percentile) internal view returns(uint _value) {\n uint findRank = (((_percentile * count(self))/uint(10)) + uint(5)) / uint(10);\n return atRank(self,findRank);\n }\n function atPermil(Tree storage self, uint _permil) internal view returns(uint _value) {\n uint findRank = (((_permil * count(self))/uint(100)) + uint(5)) / uint(10);\n return atRank(self,findRank);\n }\n function median(Tree storage self) internal view returns(uint value) {\n return atPercentile(self,50);\n }\n function below(Tree storage self, uint value) public view returns(uint _below) {\n if(count(self) > 0 && value > 0) _below = rank(self,value)-uint(1);\n }\n function above(Tree storage self, uint value) public view returns(uint _above) {\n if(count(self) > 0) _above = count(self)-rank(self,value);\n }\n function valueBelowEstimate(Tree storage self, uint estimate) public view returns(uint _below) {\n if(count(self) > 0 && estimate > 0) {\n uint highestValue = last(self);\n uint lowestValue = first(self);\n if(estimate < lowestValue) {\n return 0;\n }\n if(estimate >= highestValue) {\n return highestValue;\n }\n uint rankOfValue = rank(self, estimate); // approximation\n _below = atRank(self, rankOfValue);\n if(_below > estimate) { // fix error in approximation\n rankOfValue--;\n _below = atRank(self, rankOfValue);\n }\n }\n }\n function valueAboveEstimate(Tree storage self, uint estimate) public view returns(uint _above) {\n if(count(self) > 0 && estimate > 0) {\n uint highestValue = last(self);\n uint lowestValue = first(self);\n if(estimate > highestValue) {\n return 0;\n }\n if(estimate <= lowestValue) {\n return lowestValue;\n }\n uint rankOfValue = rank(self, estimate); // approximation\n _above = atRank(self, rankOfValue);\n if(_above < estimate) { // fix error in approximation\n rankOfValue++;\n _above = atRank(self, rankOfValue);\n }\n }\n }\n function rank(Tree storage self, uint value) internal view returns(uint _rank) {\n if(count(self) > 0) {\n bool finished;\n uint cursor = self.root;\n Node storage c = self.nodes[cursor];\n uint smaller = getNodeCount(self,c.left);\n while (!finished) {\n uint keyCount = c.keys.length;\n if(cursor == value) {\n finished = true;\n } else {\n if(cursor < value) {\n cursor = c.right;\n c = self.nodes[cursor];\n smaller += keyCount + getNodeCount(self,c.left);\n } else {\n cursor = c.left;\n c = self.nodes[cursor];\n smaller -= (keyCount + getNodeCount(self,c.right));\n }\n }\n if (!exists(self,cursor)) {\n finished = true;\n }\n }\n return smaller + 1;\n }\n }\n function atRank(Tree storage self, uint _rank) internal view returns(uint _value) {\n bool finished;\n uint cursor = self.root;\n Node storage c = self.nodes[cursor];\n uint smaller = getNodeCount(self,c.left);\n while (!finished) {\n _value = cursor;\n c = self.nodes[cursor];\n uint keyCount = c.keys.length;\n if(smaller + 1 >= _rank && smaller + keyCount <= _rank) {\n _value = cursor;\n finished = true;\n } else {\n if(smaller + keyCount <= _rank) {\n cursor = c.right;\n c = self.nodes[cursor];\n smaller += keyCount + getNodeCount(self,c.left);\n } else {\n cursor = c.left;\n c = self.nodes[cursor];\n smaller -= (keyCount + getNodeCount(self,c.right));\n }\n }\n if (!exists(self,cursor)) {\n finished = true;\n }\n }\n }\n*/\n\n function insert(Tree storage self, bytes32 key, uint value) internal {\n if (value == EMPTY) {\n revert ValueCannotBeZero();\n }\n if (keyExists(self, key, value)) {\n revert ValueKeyPairExists();\n }\n uint cursor;\n uint probe = self.root;\n while (probe != EMPTY) {\n cursor = probe;\n if (value < probe) {\n probe = self.nodes[probe].left;\n } else if (value > probe) {\n probe = self.nodes[probe].right;\n } else if (value == probe) {\n self.nodes[probe].keys.push(key);\n self.nodes[probe].keyMap[key] = self.nodes[probe].keys.length - uint(1);\n return;\n }\n self.nodes[cursor].count++;\n }\n Node storage nValue = self.nodes[value];\n nValue.parent = cursor;\n nValue.left = EMPTY;\n nValue.right = EMPTY;\n nValue.red = true;\n nValue.keys.push(key);\n nValue.keyMap[key] = nValue.keys.length - uint(1);\n if (cursor == EMPTY) {\n self.root = value;\n } else if (value < cursor) {\n self.nodes[cursor].left = value;\n } else {\n self.nodes[cursor].right = value;\n }\n insertFixup(self, value);\n }\n\n function remove(Tree storage self, bytes32 key, uint value) internal {\n if (value == EMPTY) {\n revert ValueCannotBeZero();\n }\n if (!keyExists(self, key, value)) {\n revert ValueDoesNotExist();\n }\n\n Node storage nValue = self.nodes[value];\n uint rowToDelete = nValue.keyMap[key];\n bytes32 last = nValue.keys[nValue.keys.length - uint(1)];\n nValue.keys[rowToDelete] = last;\n nValue.keyMap[last] = rowToDelete;\n nValue.keys.pop();\n\n uint probe;\n uint cursor;\n\n if (nValue.keys.length == 0) {\n if (self.nodes[value].left == EMPTY || self.nodes[value].right == EMPTY) {\n cursor = value;\n } else {\n cursor = self.nodes[value].right;\n while (self.nodes[cursor].left != EMPTY) {\n cursor = self.nodes[cursor].left;\n }\n }\n\n if (self.nodes[cursor].left != EMPTY) {\n probe = self.nodes[cursor].left;\n } else {\n probe = self.nodes[cursor].right;\n }\n\n uint cursorParent = self.nodes[cursor].parent;\n self.nodes[probe].parent = cursorParent;\n\n if (cursorParent != EMPTY) {\n if (cursor == self.nodes[cursorParent].left) {\n self.nodes[cursorParent].left = probe;\n } else {\n self.nodes[cursorParent].right = probe;\n }\n } else {\n self.root = probe;\n }\n\n bool doFixup = !self.nodes[cursor].red;\n\n if (cursor != value) {\n replaceParent(self, cursor, value);\n self.nodes[cursor].left = self.nodes[value].left;\n self.nodes[self.nodes[cursor].left].parent = cursor;\n self.nodes[cursor].right = self.nodes[value].right;\n self.nodes[self.nodes[cursor].right].parent = cursor;\n self.nodes[cursor].red = self.nodes[value].red;\n (cursor, value) = (value, cursor);\n fixCountRecurse(self, value);\n }\n\n if (doFixup) {\n removeFixup(self, probe);\n }\n\n fixCountRecurse(self, cursorParent);\n delete self.nodes[cursor];\n }\n }\n\n function fixCountRecurse(Tree storage self, uint value) private {\n while (value != EMPTY) {\n self.nodes[value].count =\n getNodeCount(self, self.nodes[value].left) +\n getNodeCount(self, self.nodes[value].right);\n value = self.nodes[value].parent;\n }\n }\n\n function treeMinimum(Tree storage self, uint value) private view returns (uint) {\n while (self.nodes[value].left != EMPTY) {\n value = self.nodes[value].left;\n }\n return value;\n }\n\n function treeMaximum(Tree storage self, uint value) private view returns (uint) {\n while (self.nodes[value].right != EMPTY) {\n value = self.nodes[value].right;\n }\n return value;\n }\n\n function rotateLeft(Tree storage self, uint value) private {\n uint cursor = self.nodes[value].right;\n uint parent = self.nodes[value].parent;\n uint cursorLeft = self.nodes[cursor].left;\n self.nodes[value].right = cursorLeft;\n if (cursorLeft != EMPTY) {\n self.nodes[cursorLeft].parent = value;\n }\n self.nodes[cursor].parent = parent;\n if (parent == EMPTY) {\n self.root = cursor;\n } else if (value == self.nodes[parent].left) {\n self.nodes[parent].left = cursor;\n } else {\n self.nodes[parent].right = cursor;\n }\n self.nodes[cursor].left = value;\n self.nodes[value].parent = cursor;\n self.nodes[value].count =\n getNodeCount(self, self.nodes[value].left) +\n getNodeCount(self, self.nodes[value].right);\n self.nodes[cursor].count =\n getNodeCount(self, self.nodes[cursor].left) +\n getNodeCount(self, self.nodes[cursor].right);\n }\n\n function rotateRight(Tree storage self, uint value) private {\n uint cursor = self.nodes[value].left;\n uint parent = self.nodes[value].parent;\n uint cursorRight = self.nodes[cursor].right;\n self.nodes[value].left = cursorRight;\n if (cursorRight != EMPTY) {\n self.nodes[cursorRight].parent = value;\n }\n self.nodes[cursor].parent = parent;\n if (parent == EMPTY) {\n self.root = cursor;\n } else if (value == self.nodes[parent].right) {\n self.nodes[parent].right = cursor;\n } else {\n self.nodes[parent].left = cursor;\n }\n self.nodes[cursor].right = value;\n self.nodes[value].parent = cursor;\n self.nodes[value].count =\n getNodeCount(self, self.nodes[value].left) +\n getNodeCount(self, self.nodes[value].right);\n self.nodes[cursor].count =\n getNodeCount(self, self.nodes[cursor].left) +\n getNodeCount(self, self.nodes[cursor].right);\n }\n\n function insertFixup(Tree storage self, uint value) private {\n uint cursor;\n while (value != self.root && self.nodes[self.nodes[value].parent].red) {\n uint valueParent = self.nodes[value].parent;\n if (valueParent == self.nodes[self.nodes[valueParent].parent].left) {\n cursor = self.nodes[self.nodes[valueParent].parent].right;\n if (self.nodes[cursor].red) {\n self.nodes[valueParent].red = false;\n self.nodes[cursor].red = false;\n self.nodes[self.nodes[valueParent].parent].red = true;\n value = self.nodes[valueParent].parent;\n } else {\n if (value == self.nodes[valueParent].right) {\n value = valueParent;\n rotateLeft(self, value);\n }\n valueParent = self.nodes[value].parent;\n self.nodes[valueParent].red = false;\n self.nodes[self.nodes[valueParent].parent].red = true;\n rotateRight(self, self.nodes[valueParent].parent);\n }\n } else {\n cursor = self.nodes[self.nodes[valueParent].parent].left;\n if (self.nodes[cursor].red) {\n self.nodes[valueParent].red = false;\n self.nodes[cursor].red = false;\n self.nodes[self.nodes[valueParent].parent].red = true;\n value = self.nodes[valueParent].parent;\n } else {\n if (value == self.nodes[valueParent].left) {\n value = valueParent;\n rotateRight(self, value);\n }\n valueParent = self.nodes[value].parent;\n self.nodes[valueParent].red = false;\n self.nodes[self.nodes[valueParent].parent].red = true;\n rotateLeft(self, self.nodes[valueParent].parent);\n }\n }\n }\n self.nodes[self.root].red = false;\n }\n\n function replaceParent(Tree storage self, uint a, uint b) private {\n uint bParent = self.nodes[b].parent;\n self.nodes[a].parent = bParent;\n if (bParent == EMPTY) {\n self.root = a;\n } else {\n if (b == self.nodes[bParent].left) {\n self.nodes[bParent].left = a;\n } else {\n self.nodes[bParent].right = a;\n }\n }\n }\n\n function removeFixup(Tree storage self, uint value) private {\n uint cursor;\n while (value != self.root && !self.nodes[value].red) {\n uint valueParent = self.nodes[value].parent;\n if (value == self.nodes[valueParent].left) {\n cursor = self.nodes[valueParent].right;\n if (self.nodes[cursor].red) {\n self.nodes[cursor].red = false;\n self.nodes[valueParent].red = true;\n rotateLeft(self, valueParent);\n cursor = self.nodes[valueParent].right;\n }\n if (!self.nodes[self.nodes[cursor].left].red && !self.nodes[self.nodes[cursor].right].red) {\n self.nodes[cursor].red = true;\n value = valueParent;\n } else {\n if (!self.nodes[self.nodes[cursor].right].red) {\n self.nodes[self.nodes[cursor].left].red = false;\n self.nodes[cursor].red = true;\n rotateRight(self, cursor);\n cursor = self.nodes[valueParent].right;\n }\n self.nodes[cursor].red = self.nodes[valueParent].red;\n self.nodes[valueParent].red = false;\n self.nodes[self.nodes[cursor].right].red = false;\n rotateLeft(self, valueParent);\n value = self.root;\n }\n } else {\n cursor = self.nodes[valueParent].left;\n if (self.nodes[cursor].red) {\n self.nodes[cursor].red = false;\n self.nodes[valueParent].red = true;\n rotateRight(self, valueParent);\n cursor = self.nodes[valueParent].left;\n }\n if (!self.nodes[self.nodes[cursor].right].red && !self.nodes[self.nodes[cursor].left].red) {\n self.nodes[cursor].red = true;\n value = valueParent;\n } else {\n if (!self.nodes[self.nodes[cursor].left].red) {\n self.nodes[self.nodes[cursor].right].red = false;\n self.nodes[cursor].red = true;\n rotateLeft(self, cursor);\n cursor = self.nodes[valueParent].left;\n }\n self.nodes[cursor].red = self.nodes[valueParent].red;\n self.nodes[valueParent].red = false;\n self.nodes[self.nodes[cursor].left].red = false;\n rotateRight(self, valueParent);\n value = self.root;\n }\n }\n }\n self.nodes[value].red = false;\n }\n}\n" + }, + "src/PostageStamp.sol": { + "content": "// SPDX-License-Identifier: BSD-3-Clause\npragma solidity ^0.8.19;\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"@openzeppelin/contracts/security/Pausable.sol\";\nimport \"./OrderStatisticsTree/HitchensOrderStatisticsTreeLib.sol\";\n\n/**\n * @title PostageStamp contract\n * @author The Swarm Authors\n * @dev The postage stamp contracts allows users to create and manage postage stamp batches.\n * The current balance for each batch is stored ordered in descending order of normalised balance.\n * Balance is normalised to be per chunk and the total spend since the contract was deployed, i.e. when a batch\n * is bought, its per-chunk balance is supplemented with the current cost of storing one chunk since the beginning of time,\n * as if the batch had existed since the contract's inception. During the _expiry_ process, each of these balances is\n * checked against the _currentTotalOutPayment_, a similarly normalised figure that represents the current cost of\n * storing one chunk since the beginning of time. A batch with a normalised balance less than _currentTotalOutPayment_\n * is treated as expired.\n *\n * The _currentTotalOutPayment_ is calculated using _totalOutPayment_ which is updated during _setPrice_ events so\n * that the applicable per-chunk prices can be charged for the relevant periods of time. This can then be multiplied\n * by the amount of chunks which are allowed to be stamped by each batch to get the actual cost of storage.\n *\n * The amount of chunks a batch can stamp is determined by the _bucketDepth_. A batch may store a maximum of 2^depth chunks.\n * The global figure for the currently allowed chunks is tracked by _validChunkCount_ and updated during batch _expiry_ events.\n */\n\ncontract PostageStamp is AccessControl, Pausable {\n using HitchensOrderStatisticsTreeLib for HitchensOrderStatisticsTreeLib.Tree;\n\n // ----------------------------- State variables ------------------------------\n\n // Address of the ERC20 token this contract references.\n address public bzzToken;\n\n // Minimum allowed depth of bucket.\n uint8 public minimumBucketDepth;\n\n // Role allowed to increase totalOutPayment.\n bytes32 public immutable PRICE_ORACLE_ROLE;\n\n // Role allowed to pause\n bytes32 public immutable PAUSER_ROLE;\n // Role allowed to withdraw the pot.\n bytes32 public immutable REDISTRIBUTOR_ROLE;\n\n // Associate every batch id with batch data.\n mapping(bytes32 => Batch) public batches;\n // Store every batch id ordered by normalisedBalance.\n HitchensOrderStatisticsTreeLib.Tree tree;\n\n // Total out payment per chunk, at the blockheight of the last price change.\n uint256 private totalOutPayment;\n\n // Combined global chunk capacity of valid batches remaining at the blockheight expire() was last called.\n uint256 public validChunkCount;\n\n // Lottery pot at last update.\n uint256 public pot;\n\n // Normalised balance at the blockheight expire() was last called.\n uint256 public lastExpiryBalance;\n\n // Price from the last update.\n uint64 public lastPrice;\n\n // blocks in 24 hours ~ 24 * 60 * 60 / 5 = 17280\n uint64 public minimumValidityBlocks = 17280;\n\n // Block at which the last update occured.\n uint64 public lastUpdatedBlock;\n\n // ----------------------------- Type declarations ------------------------------\n\n struct Batch {\n // Owner of this batch (0 if not valid).\n address owner;\n // Current depth of this batch.\n uint8 depth;\n // Bucket depth defined in this batch\n uint8 bucketDepth;\n // Whether this batch is immutable.\n bool immutableFlag;\n // Normalised balance per chunk.\n uint256 normalisedBalance;\n // When was this batch last updated\n uint256 lastUpdatedBlockNumber;\n }\n\n struct ImportBatch {\n bytes32 batchId;\n address owner;\n uint8 depth;\n uint8 bucketDepth;\n bool immutableFlag;\n uint256 remainingBalance;\n }\n\n // ----------------------------- Events ------------------------------\n\n /**\n * @dev Emitted when a new batch is created.\n */\n event BatchCreated(\n bytes32 indexed batchId,\n uint256 totalAmount,\n uint256 normalisedBalance,\n address owner,\n uint8 depth,\n uint8 bucketDepth,\n bool immutableFlag\n );\n\n /**\n * @dev Emitted when an pot is Withdrawn.\n */\n event PotWithdrawn(address recipient, uint256 totalAmount);\n\n /**\n * @dev Emitted when an existing batch is topped up.\n */\n event BatchTopUp(bytes32 indexed batchId, uint256 topupAmount, uint256 normalisedBalance);\n\n /**\n * @dev Emitted when the depth of an existing batch increases.\n */\n event BatchDepthIncrease(bytes32 indexed batchId, uint8 newDepth, uint256 normalisedBalance);\n\n /**\n *@dev Emitted on every price update.\n */\n event PriceUpdate(uint256 price);\n\n /**\n *@dev Emitted on every batch failed in bulk batch creation\n */\n event CopyBatchFailed(uint index, bytes32 batchId);\n\n // ----------------------------- Errors ------------------------------\n\n error ZeroAddress(); // Owner cannot be the zero address\n error InvalidDepth(); // Invalid bucket depth\n error BatchExists(); // Batch already exists\n error InsufficientBalance(); // Insufficient initial balance for 24h minimum validity\n error TransferFailed(); // Failed transfer of BZZ tokens\n error ZeroBalance(); // NormalisedBalance cannot be zero\n error AdministratorOnly(); // Only administrator can use copy method\n error BatchDoesNotExist(); // Batch does not exist or has expired\n error BatchExpired(); // Batch already expired\n error BatchTooSmall(); // Batch too small to renew\n error NotBatchOwner(); // Not batch owner\n error DepthNotIncreasing(); // Depth not increasing\n error PriceOracleOnly(); // Only price oracle can set the price\n error InsufficienChunkCount(); // Insufficient valid chunk count\n error TotalOutpaymentDecreased(); // Current total outpayment should never decrease\n error NoBatchesExist(); // There are no batches\n error OnlyPauser(); // Only Pauser role can pause or unpause contracts\n error OnlyRedistributor(); // Only redistributor role can withdraw from the contract\n\n // ----------------------------- CONSTRUCTOR ------------------------------\n\n /**\n * @param _bzzToken The ERC20 token address to reference in this contract.\n * @param _minimumBucketDepth The minimum bucket depth of batches that can be purchased.\n */\n constructor(address _bzzToken, uint8 _minimumBucketDepth) {\n bzzToken = _bzzToken;\n minimumBucketDepth = _minimumBucketDepth;\n PRICE_ORACLE_ROLE = keccak256(\"PRICE_ORACLE_ROLE\");\n PAUSER_ROLE = keccak256(\"PAUSER_ROLE\");\n REDISTRIBUTOR_ROLE = keccak256(\"REDISTRIBUTOR_ROLE\");\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n _setupRole(PAUSER_ROLE, msg.sender);\n }\n\n ////////////////////////////////////////\n // STATE CHANGING //\n ////////////////////////////////////////\n\n /**\n * @notice Create a new batch.\n * @dev At least `_initialBalancePerChunk*2^depth` tokens must be approved in the ERC20 token contract.\n * @param _owner Owner of the new batch.\n * @param _initialBalancePerChunk Initial balance per chunk.\n * @param _depth Initial depth of the new batch.\n * @param _nonce A random value used in the batch id derivation to allow multiple batches per owner.\n * @param _immutable Whether the batch is mutable.\n */\n function createBatch(\n address _owner,\n uint256 _initialBalancePerChunk,\n uint8 _depth,\n uint8 _bucketDepth,\n bytes32 _nonce,\n bool _immutable\n ) external whenNotPaused returns (bytes32) {\n if (_owner == address(0)) {\n revert ZeroAddress();\n }\n\n if (_bucketDepth == 0 || _bucketDepth < minimumBucketDepth || _bucketDepth >= _depth) {\n revert InvalidDepth();\n }\n\n bytes32 batchId = keccak256(abi.encode(msg.sender, _nonce));\n if (batches[batchId].owner != address(0)) {\n revert BatchExists();\n }\n\n if (_initialBalancePerChunk < minimumInitialBalancePerChunk()) {\n revert InsufficientBalance();\n }\n\n uint256 totalAmount = _initialBalancePerChunk * (1 << _depth);\n if (!ERC20(bzzToken).transferFrom(msg.sender, address(this), totalAmount)) {\n revert TransferFailed();\n }\n\n uint256 normalisedBalance = currentTotalOutPayment() + (_initialBalancePerChunk);\n if (normalisedBalance == 0) {\n revert ZeroBalance();\n }\n\n expireLimited(type(uint256).max);\n validChunkCount += 1 << _depth;\n\n batches[batchId] = Batch({\n owner: _owner,\n depth: _depth,\n bucketDepth: _bucketDepth,\n immutableFlag: _immutable,\n normalisedBalance: normalisedBalance,\n lastUpdatedBlockNumber: block.number\n });\n\n tree.insert(batchId, normalisedBalance);\n\n emit BatchCreated(batchId, totalAmount, normalisedBalance, _owner, _depth, _bucketDepth, _immutable);\n\n return batchId;\n }\n\n /**\n * @notice Manually create a new batch when facilitating migration, can only be called by the Admin role.\n * @dev At least `_initialBalancePerChunk*2^depth` tokens must be approved in the ERC20 token contract.\n * @param _owner Owner of the new batch.\n * @param _initialBalancePerChunk Initial balance per chunk of the batch.\n * @param _depth Initial depth of the new batch.\n * @param _batchId BatchId being copied (from previous version contract data).\n * @param _immutable Whether the batch is mutable.\n */\n function copyBatch(\n address _owner,\n uint256 _initialBalancePerChunk,\n uint8 _depth,\n uint8 _bucketDepth,\n bytes32 _batchId,\n bool _immutable\n ) public whenNotPaused {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert AdministratorOnly();\n }\n\n if (_owner == address(0)) {\n revert ZeroAddress();\n }\n\n if (_bucketDepth == 0 || _bucketDepth >= _depth) {\n revert InvalidDepth();\n }\n\n if (batches[_batchId].owner != address(0)) {\n revert BatchExists();\n }\n\n uint256 totalAmount = _initialBalancePerChunk * (1 << _depth);\n uint256 normalisedBalance = currentTotalOutPayment() + (_initialBalancePerChunk);\n if (normalisedBalance == 0) {\n revert ZeroBalance();\n }\n\n //update validChunkCount to remove currently expired batches\n expireLimited(type(uint256).max);\n\n validChunkCount += 1 << _depth;\n\n batches[_batchId] = Batch({\n owner: _owner,\n depth: _depth,\n bucketDepth: _bucketDepth,\n immutableFlag: _immutable,\n normalisedBalance: normalisedBalance,\n lastUpdatedBlockNumber: block.number\n });\n\n tree.insert(_batchId, normalisedBalance);\n\n emit BatchCreated(_batchId, totalAmount, normalisedBalance, _owner, _depth, _bucketDepth, _immutable);\n }\n\n /**\n * @notice Import batches in bulk\n * @dev Import batches in bulk to lower the number of transactions needed,\n * @dev becase of block limitations 90 batches per trx is ceiling, 60 to 70 sweetspot\n * @param bulkBatches array of batches\n */\n function copyBatchBulk(ImportBatch[] calldata bulkBatches) external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert AdministratorOnly();\n }\n for (uint i = 0; i < bulkBatches.length; i++) {\n ImportBatch memory _batch = bulkBatches[i];\n try\n this.copyBatch(\n _batch.owner,\n _batch.remainingBalance,\n _batch.depth,\n _batch.bucketDepth,\n _batch.batchId,\n _batch.immutableFlag\n )\n {\n // Successful copyBatch call\n } catch {\n // copyBatch failed, handle error\n emit CopyBatchFailed(i, _batch.batchId);\n }\n }\n }\n\n /**\n * @notice Top up an existing batch.\n * @dev At least `_topupAmountPerChunk*2^depth` tokens must be approved in the ERC20 token contract.\n * @param _batchId The id of an existing batch.\n * @param _topupAmountPerChunk The amount of additional tokens to add per chunk.\n */\n function topUp(bytes32 _batchId, uint256 _topupAmountPerChunk) external whenNotPaused {\n Batch memory batch = batches[_batchId];\n\n if (batch.owner == address(0)) {\n revert BatchDoesNotExist();\n }\n\n if (batch.normalisedBalance <= currentTotalOutPayment()) {\n revert BatchExpired();\n }\n\n if (batch.depth <= minimumBucketDepth) {\n revert BatchTooSmall();\n }\n\n if (remainingBalance(_batchId) + (_topupAmountPerChunk) < minimumInitialBalancePerChunk()) {\n revert InsufficientBalance();\n }\n\n // per chunk balance multiplied by the batch size in chunks must be transferred from the sender\n uint256 totalAmount = _topupAmountPerChunk * (1 << batch.depth);\n if (!ERC20(bzzToken).transferFrom(msg.sender, address(this), totalAmount)) {\n revert TransferFailed();\n }\n\n // update by removing batch and then reinserting\n tree.remove(_batchId, batch.normalisedBalance);\n batch.normalisedBalance = batch.normalisedBalance + (_topupAmountPerChunk);\n tree.insert(_batchId, batch.normalisedBalance);\n\n batches[_batchId].normalisedBalance = batch.normalisedBalance;\n emit BatchTopUp(_batchId, totalAmount, batch.normalisedBalance);\n }\n\n /**\n * @notice Increase the depth of an existing batch.\n * @dev Can only be called by the owner of the batch.\n * @param _batchId the id of an existing batch.\n * @param _newDepth the new (larger than the previous one) depth for this batch.\n */\n function increaseDepth(bytes32 _batchId, uint8 _newDepth) external whenNotPaused {\n Batch memory batch = batches[_batchId];\n\n if (batch.owner != msg.sender) {\n revert NotBatchOwner();\n }\n\n if (!(minimumBucketDepth < _newDepth && batch.depth < _newDepth)) {\n revert DepthNotIncreasing();\n }\n\n if (batch.normalisedBalance <= currentTotalOutPayment()) {\n revert BatchExpired();\n }\n\n uint8 depthChange = _newDepth - batch.depth;\n uint256 newRemainingBalance = remainingBalance(_batchId) / (1 << depthChange);\n\n if (newRemainingBalance < minimumInitialBalancePerChunk()) {\n revert InsufficientBalance();\n }\n\n expireLimited(type(uint256).max);\n validChunkCount += (1 << _newDepth) - (1 << batch.depth);\n tree.remove(_batchId, batch.normalisedBalance);\n batches[_batchId].depth = _newDepth;\n batches[_batchId].lastUpdatedBlockNumber = block.number;\n\n batch.normalisedBalance = currentTotalOutPayment() + newRemainingBalance;\n batches[_batchId].normalisedBalance = batch.normalisedBalance;\n tree.insert(_batchId, batch.normalisedBalance);\n\n emit BatchDepthIncrease(_batchId, _newDepth, batch.normalisedBalance);\n }\n\n /**\n * @notice Set a new price.\n * @dev Can only be called by the price oracle role.\n * @param _price The new price.\n */\n function setPrice(uint256 _price) external {\n if (!hasRole(PRICE_ORACLE_ROLE, msg.sender)) {\n revert PriceOracleOnly();\n }\n\n if (lastPrice != 0) {\n totalOutPayment = currentTotalOutPayment();\n }\n\n lastPrice = uint64(_price);\n lastUpdatedBlock = uint64(block.number);\n\n emit PriceUpdate(_price);\n }\n\n function setMinimumValidityBlocks(uint64 _value) external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert AdministratorOnly();\n }\n\n minimumValidityBlocks = _value;\n }\n\n /**\n * @notice Reclaims a limited number of expired batches\n * @dev Can be used if reclaiming all expired batches would exceed the block gas limit, causing other\n * contract method calls to fail.\n * @param limit The maximum number of batches to expire.\n */\n function expireLimited(uint256 limit) public {\n // the lower bound of the normalised balance for which we will check if batches have expired\n uint256 _lastExpiryBalance = lastExpiryBalance;\n uint256 i;\n for (i; i < limit; ) {\n if (isBatchesTreeEmpty()) {\n lastExpiryBalance = currentTotalOutPayment();\n break;\n }\n // get the batch with the smallest normalised balance\n bytes32 fbi = firstBatchId();\n // if the batch with the smallest balance has not yet expired\n // we have already reached the end of the batches we need\n // to expire, so exit the loop\n if (remainingBalance(fbi) > 0) {\n // the upper bound of the normalised balance for which we will check if batches have expired\n // value is updated when there are no expired batches left\n lastExpiryBalance = currentTotalOutPayment();\n break;\n }\n // otherwise, the batch with the smallest balance has expired,\n // so we must remove the chunks this batch contributes to the global validChunkCount\n Batch memory batch = batches[fbi];\n uint256 batchSize = 1 << batch.depth;\n\n if (validChunkCount < batchSize) {\n revert InsufficienChunkCount();\n }\n validChunkCount -= batchSize;\n // since the batch expired _during_ the period we must add\n // remaining normalised payout for this batch only\n pot += batchSize * (batch.normalisedBalance - _lastExpiryBalance);\n tree.remove(fbi, batch.normalisedBalance);\n delete batches[fbi];\n\n unchecked {\n ++i;\n }\n }\n // then, for all batches that have _not_ expired during the period\n // add the total normalised payout of all batches\n // multiplied by the remaining total valid chunk count\n // to the pot for the period since the last expiry\n\n if (lastExpiryBalance < _lastExpiryBalance) {\n revert TotalOutpaymentDecreased();\n }\n\n // then, for all batches that have _not_ expired during the period\n // add the total normalised payout of all batches\n // multiplied by the remaining total valid chunk count\n // to the pot for the period since the last expiry\n pot += validChunkCount * (lastExpiryBalance - _lastExpiryBalance);\n }\n\n /**\n * @notice The current pot.\n */\n function totalPot() public returns (uint256) {\n expireLimited(type(uint256).max);\n uint256 balance = ERC20(bzzToken).balanceOf(address(this));\n return pot < balance ? pot : balance;\n }\n\n /**\n * @notice Withdraw the pot, authorised callers only.\n * @param beneficiary Recieves the current total pot.\n */\n\n function withdraw(address beneficiary) external {\n if (!hasRole(REDISTRIBUTOR_ROLE, msg.sender)) {\n revert OnlyRedistributor();\n }\n\n uint256 totalAmount = totalPot();\n if (!ERC20(bzzToken).transfer(beneficiary, totalAmount)) {\n revert TransferFailed();\n }\n\n emit PotWithdrawn(beneficiary, totalAmount);\n pot = 0;\n }\n\n /**\n * @notice Pause the contract.\n * @dev Can only be called by the pauser when not paused.\n * The contract can be provably stopped by renouncing the pauser role and the admin role once paused.\n */\n function pause() public {\n if (!hasRole(PAUSER_ROLE, msg.sender)) {\n revert OnlyPauser();\n }\n _pause();\n }\n\n /**\n * @notice Unpause the contract.\n * @dev Can only be called by the pauser role while paused.\n */\n function unPause() public {\n if (!hasRole(PAUSER_ROLE, msg.sender)) {\n revert OnlyPauser();\n }\n\n _unpause();\n }\n\n ////////////////////////////////////////\n // STATE READING //\n ////////////////////////////////////////\n\n /**\n * @notice Total per-chunk cost since the contract's deployment.\n * @dev Returns the total normalised all-time per chunk payout.\n * Only Batches with a normalised balance greater than this are valid.\n */\n function currentTotalOutPayment() public view returns (uint256) {\n uint256 blocks = block.number - lastUpdatedBlock;\n uint256 increaseSinceLastUpdate = lastPrice * (blocks);\n return totalOutPayment + (increaseSinceLastUpdate);\n }\n\n function minimumInitialBalancePerChunk() public view returns (uint256) {\n return minimumValidityBlocks * lastPrice;\n }\n\n /**\n * @notice Return the per chunk balance not yet used up.\n * @param _batchId The id of an existing batch.\n */\n function remainingBalance(bytes32 _batchId) public view returns (uint256) {\n Batch memory batch = batches[_batchId];\n\n if (batch.owner == address(0)) {\n revert BatchDoesNotExist(); // Batch does not exist or expired\n }\n\n if (batch.normalisedBalance <= currentTotalOutPayment()) {\n return 0;\n }\n\n return batch.normalisedBalance - currentTotalOutPayment();\n }\n\n /**\n * @notice Indicates whether expired batches exist.\n */\n function expiredBatchesExist() public view returns (bool) {\n if (isBatchesTreeEmpty()) {\n return false;\n }\n return (remainingBalance(firstBatchId()) <= 0);\n }\n\n /**\n * @notice Return true if no batches exist\n */\n function isBatchesTreeEmpty() public view returns (bool) {\n return tree.count() == 0;\n }\n\n /**\n * @notice Get the first batch id ordered by ascending normalised balance.\n * @dev If more than one batch id, return index at 0, if no batches, revert.\n */\n function firstBatchId() public view returns (bytes32) {\n uint256 val = tree.first();\n if (val == 0) {\n revert NoBatchesExist();\n }\n return tree.valueKeyAtIndex(val, 0);\n }\n\n function batchOwner(bytes32 _batchId) public view returns (address) {\n return batches[_batchId].owner;\n }\n\n function batchDepth(bytes32 _batchId) public view returns (uint8) {\n return batches[_batchId].depth;\n }\n\n function batchBucketDepth(bytes32 _batchId) public view returns (uint8) {\n return batches[_batchId].bucketDepth;\n }\n\n function batchImmutableFlag(bytes32 _batchId) public view returns (bool) {\n return batches[_batchId].immutableFlag;\n }\n\n function batchNormalisedBalance(bytes32 _batchId) public view returns (uint256) {\n return batches[_batchId].normalisedBalance;\n }\n\n function batchLastUpdatedBlockNumber(bytes32 _batchId) public view returns (uint256) {\n return batches[_batchId].lastUpdatedBlockNumber;\n }\n}\n" + }, + "src/PriceOracle.sol": { + "content": "// SPDX-License-Identifier: BSD-3-Clause\npragma solidity ^0.8.19;\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"./interface/IPostageStamp.sol\";\n\n/**\n * @title PriceOracle contract.\n * @author The Swarm Authors.\n * @dev The price oracle contract emits a price feed using events.\n */\n\ncontract PriceOracle is AccessControl {\n // ----------------------------- State variables ------------------------------\n\n // The address of the linked PostageStamp contract\n IPostageStamp public postageStamp;\n\n uint16 targetRedundancy = 4;\n uint16 maxConsideredExtraRedundancy = 4;\n\n // When the contract is paused, price changes are not effective\n bool public isPaused = false;\n\n // The number of the last round price adjusting happend\n uint64 public lastAdjustedRound;\n\n // The minimum price allowed\n uint32 public minimumPriceUpscaled = 24000 << 10; // we upscale it by 2^10\n\n // The priceBase to modulate the price\n uint32 public priceBase = 1048576;\n\n uint64 public currentPriceUpScaled = minimumPriceUpscaled;\n\n // Constants used to modulate the price, see below usage\n uint32[9] public changeRate = [1049417, 1049206, 1048996, 1048786, 1048576, 1048366, 1048156, 1047946, 1047736];\n\n // Role allowed to update price\n bytes32 public immutable PRICE_UPDATER_ROLE;\n\n // The length of a round in blocks.\n uint8 private constant ROUND_LENGTH = 152;\n\n // ----------------------------- Events ------------------------------\n\n /**\n *@dev Emitted on every price update.\n */\n event PriceUpdate(uint256 price);\n event StampPriceUpdateFailed(uint256 attemptedPrice);\n\n // ----------------------------- Custom Errors ------------------------------\n error CallerNotAdmin(); // Caller is not the admin\n error CallerNotPriceUpdater(); // Caller is not a price updater\n error PriceAlreadyAdjusted(); // Price already adjusted in this round\n error UnexpectedZero(); // Redundancy needs to be higher then 0\n\n // ----------------------------- CONSTRUCTOR ------------------------------\n\n constructor(address _postageStamp) {\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n postageStamp = IPostageStamp(_postageStamp);\n lastAdjustedRound = currentRound();\n PRICE_UPDATER_ROLE = keccak256(\"PRICE_UPDATER_ROLE\");\n emit PriceUpdate(currentPrice());\n }\n\n ////////////////////////////////////////\n // STATE SETTING //\n ////////////////////////////////////////\n\n /**\n * @notice Manually set the price.\n * @dev Can only be called by the admin role.\n * @param _price The new price.\n */ function setPrice(uint32 _price) external returns (bool) {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert CallerNotAdmin();\n }\n\n uint64 _currentPriceUpScaled = _price << 10;\n uint64 _minimumPriceUpscaled = minimumPriceUpscaled;\n\n // Enforce minimum price\n if (_currentPriceUpScaled < _minimumPriceUpscaled) {\n _currentPriceUpScaled = _minimumPriceUpscaled;\n }\n currentPriceUpScaled = _currentPriceUpScaled;\n\n // Check if the setting of price in postagestamp succeded\n (bool success, ) = address(postageStamp).call(\n abi.encodeWithSignature(\"setPrice(uint256)\", uint256(currentPrice()))\n );\n if (!success) {\n emit StampPriceUpdateFailed(currentPrice());\n return false;\n }\n emit PriceUpdate(currentPrice());\n return true;\n }\n\n function adjustPrice(uint16 redundancy) external returns (bool) {\n if (isPaused == false) {\n if (!hasRole(PRICE_UPDATER_ROLE, msg.sender)) {\n revert CallerNotPriceUpdater();\n }\n\n uint16 usedRedundancy = redundancy;\n uint64 currentRoundNumber = currentRound();\n\n // Price can only be adjusted once per round\n if (currentRoundNumber <= lastAdjustedRound) {\n revert PriceAlreadyAdjusted();\n }\n // Redundancy may not be zero\n if (redundancy == 0) {\n revert UnexpectedZero();\n }\n\n // Enforce maximum considered extra redundancy\n uint16 maxConsideredRedundancy = targetRedundancy + maxConsideredExtraRedundancy;\n if (redundancy > maxConsideredRedundancy) {\n usedRedundancy = maxConsideredRedundancy;\n }\n\n uint64 _currentPriceUpScaled = currentPriceUpScaled;\n uint64 _minimumPriceUpscaled = minimumPriceUpscaled;\n uint32 _priceBase = priceBase;\n\n // Set the number of rounds that were skipped, we substract 1 as lastAdjustedRound is set below and default results is 1\n uint64 skippedRounds = currentRoundNumber - lastAdjustedRound - 1;\n\n // We first apply the increase/decrease rate for the current round\n uint32 _changeRate = changeRate[usedRedundancy];\n _currentPriceUpScaled = (_changeRate * _currentPriceUpScaled) / _priceBase;\n\n // If previous rounds were skipped, use MAX price increase for the previous rounds\n if (skippedRounds > 0) {\n _changeRate = changeRate[0];\n for (uint64 i = 0; i < skippedRounds; i++) {\n _currentPriceUpScaled = (_changeRate * _currentPriceUpScaled) / _priceBase;\n }\n }\n\n // Enforce minimum price\n if (_currentPriceUpScaled < _minimumPriceUpscaled) {\n _currentPriceUpScaled = _minimumPriceUpscaled;\n }\n\n currentPriceUpScaled = _currentPriceUpScaled;\n lastAdjustedRound = currentRoundNumber;\n\n // Check if the price set in postagestamp succeded\n (bool success, ) = address(postageStamp).call(\n abi.encodeWithSignature(\"setPrice(uint256)\", uint256(currentPrice()))\n );\n if (!success) {\n emit StampPriceUpdateFailed(currentPrice());\n return false;\n }\n emit PriceUpdate(currentPrice());\n return true;\n }\n return false;\n }\n\n function pause() external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert CallerNotAdmin();\n }\n isPaused = true;\n }\n\n function unPause() external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert CallerNotAdmin();\n }\n isPaused = false;\n }\n\n ////////////////////////////////////////\n // STATE READING //\n ////////////////////////////////////////\n\n /**\n * @notice Return the number of the current round.\n */\n function currentRound() public view returns (uint64) {\n // We downcasted to uint64 as uint64 has 18,446,744,073,709,551,616 places\n // as each round is 152 x 5 = 760, each day has around 113 rounds which is 41245 in a year\n // it results 4.4724801e+14 years to run this game\n return uint64(block.number / uint256(ROUND_LENGTH));\n }\n\n /**\n * @notice Return the price downscaled\n */\n function currentPrice() public view returns (uint32) {\n // We downcasted to uint32 and bitshift it by 2^10\n return uint32((currentPriceUpScaled) >> 10);\n }\n\n /**\n * @notice Return the price downscaled\n */\n function minimumPrice() public view returns (uint32) {\n // We downcasted to uint32 and bitshift it by 2^10\n return uint32((minimumPriceUpscaled) >> 10);\n }\n}\n" + }, + "src/Redistribution.sol": { + "content": "// SPDX-License-Identifier: BSD-3-Clause\npragma solidity ^0.8.19;\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"@openzeppelin/contracts/security/Pausable.sol\";\nimport \"./Util/TransformedChunkProof.sol\";\nimport \"./Util/ChunkProof.sol\";\nimport \"./Util/Signatures.sol\";\nimport \"./interface/IPostageStamp.sol\";\n\ninterface IPriceOracle {\n function adjustPrice(uint16 redundancy) external returns (bool);\n}\n\ninterface IStakeRegistry {\n struct Stake {\n bytes32 overlay;\n uint256 stakeAmount;\n uint256 lastUpdatedBlockNumber;\n }\n\n function freezeDeposit(address _owner, uint256 _time) external;\n\n function lastUpdatedBlockNumberOfAddress(address _owner) external view returns (uint256);\n\n function overlayOfAddress(address _owner) external view returns (bytes32);\n\n function heightOfAddress(address _owner) external view returns (uint8);\n\n function nodeEffectiveStake(address _owner) external view returns (uint256);\n}\n\n/**\n * @title Redistribution contract\n * @author The Swarm Authors\n * @dev Implements a Schelling Co-ordination game to form consensus around the Reserve Commitment hash. This takes\n * place in three phases: _commit_, _reveal_ and _claim_.\n *\n * A node, upon establishing that it _isParticipatingInUpcomingRound_, i.e. it's overlay falls within proximity order\n * of its reported depth with the _currentRoundAnchor_, prepares a \"reserve commitment hash\" using the chunks\n * it currently stores in its reserve and calculates the \"storage depth\" (see Bee for details). These values, if calculated\n * honestly, and with the right chunks stored, should be the same for every node in a neighbourhood. This is the Schelling point.\n * Each eligible node can then use these values, together with a random, single use, secret _revealNonce_ and their\n * _overlay_ as the pre-image values for the obsfucated _commit_, using the _wrapCommit_ method.\n *\n * Once the _commit_ round has elapsed, participating nodes must provide the values used to calculate their obsfucated\n * _commit_ hash, which, once verified for correctness and proximity to the anchor are retained in the _currentReveals_.\n * Nodes that have committed but do not reveal the correct values used to create the pre-image will have their stake\n * \"frozen\" for a period of rounds proportional to their reported depth.\n *\n * During the _reveal_ round, randomness is updated after every successful reveal. Once the reveal round is concluded,\n * the _currentRoundAnchor_ is updated and users can determine if they will be eligible their overlay will be eligible\n * for the next commit phase using _isParticipatingInUpcomingRound_.\n *\n * When the _reveal_ phase has been concluded, the claim phase can begin. At this point, the truth teller and winner\n * are already determined. By calling _isWinner_, an applicant node can run the relevant logic to determine if they have\n * been selected as the beneficiary of this round. When calling _claim_, the current pot from the PostageStamp contract\n * is withdrawn and transferred to that beneficiaries address. Nodes that have revealed values that differ from the truth,\n * have their stakes \"frozen\" for a period of rounds proportional to their reported depth.\n */\n\ncontract Redistribution is AccessControl, Pausable {\n // ----------------------------- Type declarations ------------------------------\n\n // An eligible user may commit to an _obfuscatedHash_ during the commit phase...\n struct Commit {\n bytes32 overlay;\n address owner;\n bool revealed;\n uint8 height;\n uint256 stake;\n bytes32 obfuscatedHash;\n uint256 revealIndex;\n }\n // ...then provide the actual values that are the constituents of the pre-image of the _obfuscatedHash_\n // during the reveal phase.\n struct Reveal {\n bytes32 overlay;\n address owner;\n uint8 depth;\n uint256 stake;\n uint256 stakeDensity;\n bytes32 hash;\n }\n\n struct ChunkInclusionProof {\n bytes32[] proofSegments;\n bytes32 proveSegment;\n // _RCspan is known for RC 32*32\n\n // Inclusion proof of transformed address\n bytes32[] proofSegments2;\n bytes32 proveSegment2;\n // proveSegmentIndex2 known from deterministic random selection;\n uint64 chunkSpan;\n bytes32[] proofSegments3;\n // _proveSegment3 known, is equal _proveSegment2\n // proveSegmentIndex3 know, is equal _proveSegmentIndex2;\n // chunkSpan2 is equal to chunkSpan (as the data is the same)\n //\n PostageProof postageProof;\n SOCProof[] socProof;\n }\n\n struct SOCProof {\n address signer; // signer Ethereum address to check against\n bytes signature;\n bytes32 identifier; //\n bytes32 chunkAddr; // wrapped chunk address\n }\n\n struct PostageProof {\n bytes signature;\n bytes32 postageId;\n uint64 index;\n uint64 timeStamp;\n // address signer; it is provided by the postage stamp contract\n // bytes32 chunkAddr; it equals to the proveSegment argument\n }\n\n // The address of the linked PostageStamp contract.\n IPostageStamp public PostageContract;\n // The address of the linked PriceOracle contract.\n IPriceOracle public OracleContract;\n // The address of the linked Staking contract.\n IStakeRegistry public Stakes;\n\n // Commits for the current round.\n Commit[] public currentCommits;\n // Reveals for the current round.\n Reveal[] public currentReveals;\n\n // The current anchor that being processed for the reveal and claim phases of the round.\n bytes32 private currentRevealRoundAnchor;\n\n // The current random value from which we will random.\n // inputs for selection of the truth teller and beneficiary.\n bytes32 private seed;\n\n // The number of the currently active round phases.\n uint64 public currentCommitRound;\n uint64 public currentRevealRound;\n uint64 public currentClaimRound;\n\n // Settings for slashing and freezing\n uint8 private penaltyMultiplierDisagreement = 1;\n uint8 private penaltyMultiplierNonRevealed = 2;\n uint8 private penaltyRandomFactor = 100; // Use 100 as value to ignore random factor in freezing penalty\n\n // alpha=0.097612 beta=0.0716570 k=16\n uint256 private sampleMaxValue = 1284401000000000000000000000000000000000000000000000000000000000000000000;\n\n // The reveal of the winner of the last round.\n Reveal public winner;\n\n // The length of a round in blocks.\n uint256 private constant ROUND_LENGTH = 152;\n\n // Maximum value of the keccack256 hash.\n bytes32 private constant MAX_H = 0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff;\n\n // ----------------------------- Events ------------------------------\n\n /**\n * @dev Emitted when the winner of a round is selected in the claim phase\n */\n event WinnerSelected(Reveal winner);\n\n /**\n * @dev Emitted when the truth oracle of a round is selected in the claim phase.\n */\n event TruthSelected(bytes32 hash, uint8 depth);\n\n // Next two events to be removed after testing phase pending some other usefulness being found.\n /**\n * @dev Emits the number of commits being processed by the claim phase.\n */\n event CountCommits(uint256 _count);\n\n /**\n * @dev Emits the number of reveals being processed by the claim phase.\n */\n event CountReveals(uint256 _count);\n\n /**\n * @dev Logs that an overlay has committed\n */\n event Committed(uint256 roundNumber, bytes32 overlay, uint8 height);\n /**\n * @dev Emit from Postagestamp contract valid chunk count at the end of claim\n */\n event ChunkCount(uint256 validChunkCount);\n\n /**\n * @dev Bytes32 anhor of current reveal round\n */\n event CurrentRevealAnchor(uint256 roundNumber, bytes32 anchor);\n\n /**\n * @dev Output external call status\n */\n event PriceAdjustmentSkipped(uint16 redundancyCount);\n\n /**\n * @dev Withdraw not successful in claim\n */\n event WithdrawFailed(address owner);\n\n /**\n * @dev Logs that an overlay has revealed\n */\n event Revealed(\n uint256 roundNumber,\n bytes32 overlay,\n uint256 stake,\n uint256 stakeDensity,\n bytes32 reserveCommitment,\n uint8 depth\n );\n\n /**\n * @dev Logs for inclusion proof\n */\n event transformedChunkAddressFromInclusionProof(uint256 indexInRC, bytes32 chunkAddress);\n\n // ----------------------------- Errors ------------------------------\n\n error NotCommitPhase(); // Game is not in commit phase\n error NoCommitsReceived(); // Round didn't receive any commits\n error PhaseLastBlock(); // We don't permit commits in last block of the phase\n error CommitRoundOver(); // Commit phase in this round is over\n error CommitRoundNotStarted(); // Commit phase in this round has not started yet\n error NotMatchingOwner(); // Sender of commit is not matching the overlay address\n error MustStake2Rounds(); // Before entering the game node must stake 2 rounds prior\n error NotStaked(); // Node didn't add any staking\n error WrongPhase(); // Checking in wrong phase, need to check duing claim phase of current round for next round or commit in current round\n error AlreadyCommitted(); // Node already committed in this round\n error NotRevealPhase(); // Game is not in reveal phase\n error OutOfDepthReveal(bytes32); // Anchor is out of reported depth in Reveal phase, anchor data available as argument\n error OutOfDepthClaim(uint8); // Anchor is out of reported depth in Claim phase, entryProof index is argument\n error OutOfDepth(); // Anchor is out of reported depth\n error AlreadyRevealed(); // Node already revealed\n error NoMatchingCommit(); // No matching commit and hash\n error NotClaimPhase(); // Game is not in the claim phase\n error NoReveals(); // Round did not receive any reveals\n error FirstRevealDone(); // We don't want to return value after first reveal\n error AlreadyClaimed(); // This round was already claimed\n error NotAdmin(); // Caller of trx is not admin\n error OnlyPauser(); // Only account with pauser role can call pause/unpause\n error SocVerificationFailed(bytes32); // Soc verification failed for this element\n error SocCalcNotMatching(bytes32); // Soc address calculation does not match with the witness\n error IndexOutsideSet(bytes32); // Stamp available: index resides outside of the valid index set\n error SigRecoveryFailed(bytes32); // Stamp authorized: signature recovery failed for element\n error BatchDoesNotExist(bytes32); // Stamp alive: batch remaining balance validation failed for attached stamp\n error BucketDiffers(bytes32); // Stamp aligned: postage bucket differs from address bucket\n error InclusionProofFailed(uint8, bytes32);\n // 1 = RC inclusion proof failed for element\n // 2 = First sister segment in data must match,\n // 3 = Inclusion proof failed for original address of element\n // 4 = Inclusion proof failed for transformed address of element\n error RandomElementCheckFailed(); // Random element order check failed\n error LastElementCheckFailed(); // Last element order check failed\n error ReserveCheckFailed(bytes32 trALast); // Reserve size estimation check failed\n\n // ----------------------------- CONSTRUCTOR ------------------------------\n\n /**\n * @param staking the address of the linked Staking contract.\n * @param postageContract the address of the linked PostageStamp contract.\n * @param oracleContract the address of the linked PriceOracle contract.\n */\n constructor(address staking, address postageContract, address oracleContract) {\n Stakes = IStakeRegistry(staking);\n PostageContract = IPostageStamp(postageContract);\n OracleContract = IPriceOracle(oracleContract);\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n }\n\n ////////////////////////////////////////\n // STATE CHANGING //\n ////////////////////////////////////////\n\n /**\n * @notice Begin application for a round if eligible. Commit a hashed value for which the pre-image will be\n * subsequently revealed.\n * @dev If a node's overlay is _inProximity_(_depth_) of the _currentRoundAnchor_, that node may compute an\n * _obfuscatedHash_ by providing their _overlay_, reported storage _depth_, reserve commitment _hash_ and a\n * randomly generated, and secret _revealNonce_ to the _wrapCommit_ method.\n * @param _obfuscatedHash The calculated hash resultant of the required pre-image values.\n * and be derived from the same key pair as the message sender.\n * @param _roundNumber Node needs to provide round number for which commit is valid\n */\n function commit(bytes32 _obfuscatedHash, uint64 _roundNumber) external whenNotPaused {\n uint64 cr = currentRound();\n bytes32 _overlay = Stakes.overlayOfAddress(msg.sender);\n uint256 _stake = Stakes.nodeEffectiveStake(msg.sender);\n uint256 _lastUpdate = Stakes.lastUpdatedBlockNumberOfAddress(msg.sender);\n uint8 _height = Stakes.heightOfAddress(msg.sender);\n\n if (!currentPhaseCommit()) {\n revert NotCommitPhase();\n }\n if (block.number % ROUND_LENGTH == (ROUND_LENGTH / 4) - 1) {\n revert PhaseLastBlock();\n }\n\n if (cr > _roundNumber) {\n revert CommitRoundOver();\n }\n\n if (cr < _roundNumber) {\n revert CommitRoundNotStarted();\n }\n\n if (_lastUpdate == 0) {\n revert NotStaked();\n }\n\n if (_lastUpdate >= block.number - 2 * ROUND_LENGTH) {\n revert MustStake2Rounds();\n }\n\n // if we are in a new commit phase, reset the array of commits and\n // set the currentCommitRound to be the current one\n if (cr != currentCommitRound) {\n delete currentCommits;\n currentCommitRound = cr;\n }\n\n uint256 commitsArrayLength = currentCommits.length;\n\n for (uint256 i = 0; i < commitsArrayLength; ) {\n if (currentCommits[i].overlay == _overlay) {\n revert AlreadyCommitted();\n }\n\n unchecked {\n ++i;\n }\n }\n\n currentCommits.push(\n Commit({\n overlay: _overlay,\n owner: msg.sender,\n revealed: false,\n height: _height,\n stake: _stake,\n obfuscatedHash: _obfuscatedHash,\n revealIndex: 0\n })\n );\n\n emit Committed(_roundNumber, _overlay, _height);\n }\n\n /**\n * @notice Reveal the pre-image values used to generate commit provided during this round's commit phase.\n * @param _depth The reported depth.\n * @param _hash The reserve commitment hash.\n * @param _revealNonce The nonce used to generate the commit that is being revealed.\n */\n function reveal(uint8 _depth, bytes32 _hash, bytes32 _revealNonce) external whenNotPaused {\n uint64 cr = currentRound();\n bytes32 _overlay = Stakes.overlayOfAddress(msg.sender);\n\n if (_depth < currentMinimumDepth()) {\n revert OutOfDepth();\n }\n\n if (!currentPhaseReveal()) {\n revert NotRevealPhase();\n }\n\n if (cr != currentCommitRound) {\n revert NoCommitsReceived();\n }\n\n if (cr != currentRevealRound) {\n currentRevealRoundAnchor = currentRoundAnchor();\n delete currentReveals;\n // We set currentRevealRound ONLY after we set current anchor\n currentRevealRound = cr;\n emit CurrentRevealAnchor(cr, currentRevealRoundAnchor);\n updateRandomness();\n }\n\n bytes32 obfuscatedHash = wrapCommit(_overlay, _depth, _hash, _revealNonce);\n uint256 id = findCommit(_overlay, obfuscatedHash);\n Commit memory revealedCommit = currentCommits[id];\n uint8 depthResponsibility = _depth - revealedCommit.height;\n\n // Check that commit is in proximity of the current anchor\n if (!inProximity(revealedCommit.overlay, currentRevealRoundAnchor, depthResponsibility)) {\n revert OutOfDepthReveal(currentRevealRoundAnchor);\n }\n // Check that the commit has not already been revealed\n if (revealedCommit.revealed) {\n revert AlreadyRevealed();\n }\n\n currentCommits[id].revealed = true;\n currentCommits[id].revealIndex = currentReveals.length;\n\n currentReveals.push(\n Reveal({\n overlay: revealedCommit.overlay,\n owner: revealedCommit.owner,\n depth: _depth,\n stake: revealedCommit.stake,\n stakeDensity: revealedCommit.stake * uint256(2 ** depthResponsibility),\n hash: _hash\n })\n );\n\n emit Revealed(\n cr,\n revealedCommit.overlay,\n revealedCommit.stake,\n revealedCommit.stake * uint256(2 ** depthResponsibility),\n _hash,\n _depth\n );\n }\n\n /**\n * @notice Helper function to get this round truth\n * @dev\n */\n function claim(\n ChunkInclusionProof calldata entryProof1,\n ChunkInclusionProof calldata entryProof2,\n ChunkInclusionProof calldata entryProofLast\n ) external whenNotPaused {\n winnerSelection();\n\n Reveal memory winnerSelected = winner;\n uint256 indexInRC1;\n uint256 indexInRC2;\n bytes32 _currentRevealRoundAnchor = currentRevealRoundAnchor;\n bytes32 _seed = seed;\n\n // rand(14)\n indexInRC1 = uint256(_seed) % 15;\n // rand(13)\n indexInRC2 = uint256(_seed) % 14;\n if (indexInRC2 >= indexInRC1) {\n indexInRC2++;\n }\n\n if (!inProximity(entryProofLast.proveSegment, _currentRevealRoundAnchor, winnerSelected.depth)) {\n revert OutOfDepthClaim(3);\n }\n\n inclusionFunction(entryProofLast, 30);\n stampFunction(entryProofLast);\n socFunction(entryProofLast);\n\n if (!inProximity(entryProof1.proveSegment, _currentRevealRoundAnchor, winnerSelected.depth)) {\n revert OutOfDepthClaim(2);\n }\n\n inclusionFunction(entryProof1, indexInRC1 * 2);\n stampFunction(entryProof1);\n socFunction(entryProof1);\n\n if (!inProximity(entryProof2.proveSegment, _currentRevealRoundAnchor, winnerSelected.depth)) {\n revert OutOfDepthClaim(1);\n }\n\n inclusionFunction(entryProof2, indexInRC2 * 2);\n stampFunction(entryProof2);\n socFunction(entryProof2);\n\n checkOrder(\n indexInRC1,\n indexInRC2,\n entryProof1.proofSegments[0],\n entryProof2.proofSegments[0],\n entryProofLast.proofSegments[0]\n );\n\n estimateSize(entryProofLast.proofSegments[0]);\n\n // Do the check if the withdraw was success\n (bool success, ) = address(PostageContract).call(\n abi.encodeWithSignature(\"withdraw(address)\", winnerSelected.owner)\n );\n if (!success) {\n emit WithdrawFailed(winnerSelected.owner);\n }\n\n emit WinnerSelected(winnerSelected);\n emit ChunkCount(PostageContract.validChunkCount());\n }\n\n function winnerSelection() internal {\n uint64 cr = currentRound();\n\n if (!currentPhaseClaim()) {\n revert NotClaimPhase();\n }\n\n if (cr != currentRevealRound) {\n revert NoReveals();\n }\n\n if (cr <= currentClaimRound) {\n revert AlreadyClaimed();\n }\n\n uint256 currentWinnerSelectionSum = 0;\n uint256 redundancyCount = 0;\n bytes32 randomNumber;\n uint256 randomNumberTrunc;\n\n bytes32 truthRevealedHash;\n uint8 truthRevealedDepth;\n uint256 currentCommitsLength = currentCommits.length;\n\n emit CountCommits(currentCommitsLength);\n emit CountReveals(currentReveals.length);\n\n (truthRevealedHash, truthRevealedDepth) = getCurrentTruth();\n emit TruthSelected(truthRevealedHash, truthRevealedDepth);\n string memory winnerSelectionAnchor = currentWinnerSelectionAnchor();\n\n for (uint256 i = 0; i < currentCommitsLength; ) {\n Commit memory currentCommit = currentCommits[i];\n uint256 revIndex = currentCommit.revealIndex;\n Reveal memory currentReveal = currentReveals[revIndex];\n\n // Select winner with valid truth\n if (\n currentCommit.revealed &&\n truthRevealedHash == currentReveal.hash &&\n truthRevealedDepth == currentReveal.depth\n ) {\n currentWinnerSelectionSum += currentReveal.stakeDensity;\n randomNumber = keccak256(abi.encodePacked(winnerSelectionAnchor, redundancyCount));\n randomNumberTrunc = uint256(randomNumber & MAX_H);\n\n if (randomNumberTrunc * currentWinnerSelectionSum < currentReveal.stakeDensity * (uint256(MAX_H) + 1)) {\n winner = currentReveal;\n }\n\n redundancyCount++;\n }\n\n // Freeze deposit if any truth is false, make it a penaltyRandomFactor chance for this to happen\n if (\n currentCommit.revealed &&\n (truthRevealedHash != currentReveal.hash || truthRevealedDepth != currentReveal.depth) &&\n (block.prevrandao % 100 < penaltyRandomFactor)\n ) {\n Stakes.freezeDeposit(\n currentReveal.owner,\n penaltyMultiplierDisagreement * ROUND_LENGTH * uint256(2 ** truthRevealedDepth)\n );\n }\n\n // Slash deposits if revealed is false\n if (!currentCommit.revealed) {\n // slash in later phase (ph5)\n // Stakes.slashDeposit(currentCommits[i].overlay, currentCommits[i].stake);\n Stakes.freezeDeposit(\n currentCommit.owner,\n penaltyMultiplierNonRevealed * ROUND_LENGTH * uint256(2 ** truthRevealedDepth)\n );\n }\n unchecked {\n ++i;\n }\n }\n\n bool success = OracleContract.adjustPrice(uint16(redundancyCount));\n if (!success) {\n emit PriceAdjustmentSkipped(uint16(redundancyCount));\n }\n currentClaimRound = cr;\n }\n\n function inclusionFunction(ChunkInclusionProof calldata entryProof, uint256 indexInRC) internal {\n uint256 randomChunkSegmentIndex = uint256(seed) % 128;\n bytes32 calculatedTransformedAddr = TransformedBMTChunk.transformedChunkAddressFromInclusionProof(\n entryProof.proofSegments3,\n entryProof.proveSegment2,\n randomChunkSegmentIndex,\n entryProof.chunkSpan,\n currentRevealRoundAnchor\n );\n\n emit transformedChunkAddressFromInclusionProof(indexInRC, calculatedTransformedAddr);\n\n if (\n winner.hash !=\n BMTChunk.chunkAddressFromInclusionProof(\n entryProof.proofSegments,\n entryProof.proveSegment,\n indexInRC,\n 32 * 32\n )\n ) {\n revert InclusionProofFailed(1, calculatedTransformedAddr);\n }\n\n if (entryProof.proofSegments2[0] != entryProof.proofSegments3[0]) {\n revert InclusionProofFailed(2, calculatedTransformedAddr);\n }\n\n bytes32 originalAddress = entryProof.socProof.length > 0\n ? entryProof.socProof[0].chunkAddr // soc attestation in socFunction\n : entryProof.proveSegment;\n\n if (\n originalAddress !=\n BMTChunk.chunkAddressFromInclusionProof(\n entryProof.proofSegments2,\n entryProof.proveSegment2,\n randomChunkSegmentIndex,\n entryProof.chunkSpan\n )\n ) {\n revert InclusionProofFailed(3, calculatedTransformedAddr);\n }\n\n // In case of SOC, the transformed address is hashed together with its address in the sample\n if (entryProof.socProof.length > 0) {\n calculatedTransformedAddr = keccak256(\n abi.encode(\n entryProof.proveSegment, // SOC address\n calculatedTransformedAddr\n )\n );\n }\n\n if (entryProof.proofSegments[0] != calculatedTransformedAddr) {\n revert InclusionProofFailed(4, calculatedTransformedAddr);\n }\n }\n\n /**\n * @notice Set freezing parameters\n */\n function setFreezingParams(\n uint8 _penaltyMultiplierDisagreement,\n uint8 _penaltyMultiplierNonRevealed,\n uint8 _penaltyRandomFactor\n ) external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert NotAdmin();\n }\n\n penaltyMultiplierDisagreement = _penaltyMultiplierDisagreement;\n penaltyMultiplierNonRevealed = _penaltyMultiplierNonRevealed;\n penaltyRandomFactor = _penaltyRandomFactor;\n }\n\n /**\n * @notice changes the max sample value used for reserve estimation\n */\n function setSampleMaxValue(uint256 _sampleMaxValue) external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert NotAdmin();\n }\n\n sampleMaxValue = _sampleMaxValue;\n }\n\n /**\n * @notice Updates the source of randomness. Uses block.difficulty in pre-merge chains, this is substituted\n * to block.prevrandao in post merge chains.\n */\n function updateRandomness() private {\n seed = keccak256(abi.encode(seed, block.prevrandao));\n }\n\n /**\n * @dev Pause the contract. The contract is provably stopped by renouncing\n the pauser role and the admin role after pausing, can only be called by the `PAUSER`\n */\n function pause() public {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert OnlyPauser();\n }\n\n _pause();\n }\n\n /**\n * @dev Unpause the contract, can only be called by the pauser when paused\n */\n function unPause() public {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert OnlyPauser();\n }\n _unpause();\n }\n\n ////////////////////////////////////////\n // STATE READING //\n ////////////////////////////////////////\n\n // ----------------------------- Anchor calculations ------------------------------\n\n /**\n * @notice Returns the current random seed which is used to determine later utilised random numbers.\n * If rounds have elapsed without reveals, hash the seed with an incremented nonce to produce a new\n * random seed and hence a new round anchor.\n */\n function currentSeed() public view returns (bytes32) {\n uint64 cr = currentRound();\n bytes32 currentSeedValue = seed;\n\n if (cr > currentRevealRound + 1) {\n uint256 difference = cr - currentRevealRound - 1;\n currentSeedValue = keccak256(abi.encodePacked(currentSeedValue, difference));\n }\n\n return currentSeedValue;\n }\n\n /**\n * @notice Returns the seed which will become current once the next commit phase begins.\n * Used to determine what the next round's anchor will be.\n */\n function nextSeed() public view returns (bytes32) {\n uint64 cr = currentRound() + 1;\n bytes32 currentSeedValue = seed;\n\n if (cr > currentRevealRound + 1) {\n uint256 difference = cr - currentRevealRound - 1;\n currentSeedValue = keccak256(abi.encodePacked(currentSeedValue, difference));\n }\n\n return currentSeedValue;\n }\n\n /**\n * @notice The random value used to choose the selected truth teller.\n */\n function currentTruthSelectionAnchor() private view returns (string memory) {\n if (!currentPhaseClaim()) {\n revert NotClaimPhase();\n }\n\n uint64 cr = currentRound();\n if (cr != currentRevealRound) {\n revert NoReveals();\n }\n\n return string(abi.encodePacked(seed, \"0\"));\n }\n\n /**\n * @notice The random value used to choose the selected beneficiary.\n */\n function currentWinnerSelectionAnchor() private view returns (string memory) {\n if (!currentPhaseClaim()) {\n revert NotClaimPhase();\n }\n uint64 cr = currentRound();\n if (cr != currentRevealRound) {\n revert NoReveals();\n }\n\n return string(abi.encodePacked(seed, \"1\"));\n }\n\n /**\n * @notice The anchor used to determine eligibility for the current round.\n * @dev A node must be within proximity order of less than or equal to the storage depth they intend to report.\n */\n function currentRoundAnchor() public view returns (bytes32 returnVal) {\n // This will be called in reveal phase and set as currentRevealRoundAnchor or in\n // commit phase when checking eligibility for next round by isParticipatingInUpcomingRound\n if (currentPhaseCommit() || (currentRound() > currentRevealRound && !currentPhaseClaim())) {\n return currentSeed();\n }\n\n // This will be called by isParticipatingInUpcomingRound check in claim phase\n if (currentPhaseClaim()) {\n return nextSeed();\n }\n\n // Without this, this function will output 0x0 after first reveal which is value and we prefere it reverts\n if (currentPhaseReveal() && currentRound() == currentRevealRound) {\n revert FirstRevealDone();\n }\n }\n\n /**\n * @notice Returns true if an overlay address _A_ is within proximity order _minimum_ of _B_.\n * @param A An overlay address to compare.\n * @param B An overlay address to compare.\n * @param minimum Minimum proximity order.\n */\n function inProximity(bytes32 A, bytes32 B, uint8 minimum) public pure returns (bool) {\n if (minimum == 0) {\n return true;\n }\n\n return uint256(A ^ B) < uint256(2 ** (256 - minimum));\n }\n\n // ----------------------------- Commit ------------------------------\n\n /**\n * @notice The number of the current round.\n */\n function currentRound() public view returns (uint64) {\n return uint64(block.number / ROUND_LENGTH);\n }\n\n /**\n * @notice Returns true if current block is during commit phase.\n */\n function currentPhaseCommit() public view returns (bool) {\n if (block.number % ROUND_LENGTH < ROUND_LENGTH / 4) {\n return true;\n }\n return false;\n }\n\n /**\n * @notice Determine if a the owner of a given overlay can participate in the upcoming round.\n * @param _owner The address of the applicant from.\n * @param _depth The storage depth the applicant intends to report.\n */\n function isParticipatingInUpcomingRound(address _owner, uint8 _depth) public view returns (bool) {\n uint256 _lastUpdate = Stakes.lastUpdatedBlockNumberOfAddress(_owner);\n uint8 _depthResponsibility = _depth - Stakes.heightOfAddress(_owner);\n\n if (currentPhaseReveal()) {\n revert WrongPhase();\n }\n\n if (_lastUpdate == 0) {\n revert NotStaked();\n }\n\n if (_lastUpdate >= block.number - 2 * ROUND_LENGTH) {\n revert MustStake2Rounds();\n }\n\n return inProximity(Stakes.overlayOfAddress(_owner), currentRoundAnchor(), _depthResponsibility);\n }\n\n // ----------------------------- Reveal ------------------------------\n\n /**\n * @notice Returns minimum depth reveal has to have to participate in this round\n */\n function currentMinimumDepth() public view returns (uint8) {\n // We are checking value in reveal phase, as the currentCommitRound is set to the current round\n // but the currentClaimRound is still set to the last time claim was made\n // We add 1 to ensure that for the next round the minimum depth is the same as last winner depth\n\n uint256 difference = currentCommitRound - currentClaimRound;\n uint8 skippedRounds = uint8(difference > 254 ? 254 : difference) + 1;\n\n uint8 lastWinnerDepth = winner.depth;\n\n // We ensure that skippedRounds is not bigger than lastWinnerDepth, because of overflow\n return skippedRounds >= lastWinnerDepth ? 0 : lastWinnerDepth - skippedRounds;\n }\n\n /**\n * @notice Helper function to get this node reveal in commits\n * @dev\n */\n function findCommit(bytes32 _overlay, bytes32 _obfuscatedHash) internal view returns (uint256) {\n for (uint256 i = 0; i < currentCommits.length; ) {\n if (currentCommits[i].overlay == _overlay && _obfuscatedHash == currentCommits[i].obfuscatedHash) {\n return i;\n }\n unchecked {\n ++i;\n }\n }\n revert NoMatchingCommit();\n }\n\n /**\n * @notice Hash the pre-image values to the obsfucated hash.\n * @dev _revealNonce_ must be randomly generated, used once and kept secret until the reveal phase.\n * @param _overlay The overlay address of the applicant.\n * @param _depth The reported depth.\n * @param _hash The reserve commitment hash.\n * @param revealNonce A random, single use, secret nonce.\n */\n function wrapCommit(\n bytes32 _overlay,\n uint8 _depth,\n bytes32 _hash,\n bytes32 revealNonce\n ) public pure returns (bytes32) {\n return keccak256(abi.encodePacked(_overlay, _depth, _hash, revealNonce));\n }\n\n /**\n * @notice Returns true if current block is during reveal phase.\n */\n function currentPhaseReveal() public view returns (bool) {\n uint256 number = block.number % ROUND_LENGTH;\n if (number >= ROUND_LENGTH / 4 && number < ROUND_LENGTH / 2) {\n return true;\n }\n return false;\n }\n\n /**\n * @notice Returns true if current block is during reveal phase.\n */\n function currentRoundReveals() public view returns (Reveal[] memory) {\n if (!currentPhaseClaim()) {\n revert NotClaimPhase();\n }\n uint64 cr = currentRound();\n if (cr != currentRevealRound) {\n revert NoReveals();\n }\n\n return currentReveals;\n }\n\n // ----------------------------- Claim ------------------------------\n\n /**\n * @notice Returns true if current block is during claim phase.\n */\n function currentPhaseClaim() public view returns (bool) {\n if (block.number % ROUND_LENGTH >= ROUND_LENGTH / 2) {\n return true;\n }\n return false;\n }\n\n function getCurrentTruth() internal view returns (bytes32 Hash, uint8 Depth) {\n uint256 currentSum;\n bytes32 randomNumber;\n uint256 randomNumberTrunc;\n\n bytes32 truthRevealedHash;\n uint8 truthRevealedDepth;\n uint256 revIndex;\n string memory truthSelectionAnchor = currentTruthSelectionAnchor();\n uint256 commitsArrayLength = currentCommits.length;\n\n for (uint256 i = 0; i < commitsArrayLength; ) {\n if (currentCommits[i].revealed) {\n revIndex = currentCommits[i].revealIndex;\n currentSum += currentReveals[revIndex].stakeDensity;\n randomNumber = keccak256(abi.encodePacked(truthSelectionAnchor, i));\n randomNumberTrunc = uint256(randomNumber & MAX_H);\n\n // question is whether randomNumber / MAX_H < probability\n // where probability is stakeDensity / currentSum\n // to avoid resorting to floating points all divisions should be\n // simplified with multiplying both sides (as long as divisor > 0)\n // randomNumber / (MAX_H + 1) < stakeDensity / currentSum\n // ( randomNumber / (MAX_H + 1) ) * currentSum < stakeDensity\n // randomNumber * currentSum < stakeDensity * (MAX_H + 1)\n if (randomNumberTrunc * currentSum < currentReveals[revIndex].stakeDensity * (uint256(MAX_H) + 1)) {\n truthRevealedHash = currentReveals[revIndex].hash;\n truthRevealedDepth = currentReveals[revIndex].depth;\n }\n }\n unchecked {\n ++i;\n }\n }\n\n return (truthRevealedHash, truthRevealedDepth);\n }\n\n /**\n * @notice Determine if a the owner of a given overlay will be the beneficiary of the claim phase.\n * @param _overlay The overlay address of the applicant.\n */\n function isWinner(bytes32 _overlay) public view returns (bool) {\n if (!currentPhaseClaim()) {\n revert NotClaimPhase();\n }\n\n uint64 cr = currentRound();\n if (cr != currentRevealRound) {\n revert NoReveals();\n }\n\n if (cr <= currentClaimRound) {\n revert AlreadyClaimed();\n }\n\n uint256 currentWinnerSelectionSum;\n bytes32 winnerIs;\n bytes32 randomNumber;\n uint256 randomNumberTrunc;\n bytes32 truthRevealedHash;\n uint8 truthRevealedDepth;\n uint256 revIndex;\n string memory winnerSelectionAnchor = currentWinnerSelectionAnchor();\n uint256 redundancyCount = 0;\n\n // Get current truth\n (truthRevealedHash, truthRevealedDepth) = getCurrentTruth();\n uint256 commitsArrayLength = currentCommits.length;\n\n for (uint256 i = 0; i < commitsArrayLength; ) {\n revIndex = currentCommits[i].revealIndex;\n\n // Deterministically read winner\n if (\n currentCommits[i].revealed &&\n truthRevealedHash == currentReveals[revIndex].hash &&\n truthRevealedDepth == currentReveals[revIndex].depth\n ) {\n currentWinnerSelectionSum += currentReveals[revIndex].stakeDensity;\n randomNumber = keccak256(abi.encodePacked(winnerSelectionAnchor, redundancyCount));\n randomNumberTrunc = uint256(randomNumber & MAX_H);\n\n if (\n randomNumberTrunc * currentWinnerSelectionSum <\n currentReveals[revIndex].stakeDensity * (uint256(MAX_H) + 1)\n ) {\n winnerIs = currentReveals[revIndex].overlay;\n }\n\n redundancyCount++;\n }\n unchecked {\n ++i;\n }\n }\n\n return (winnerIs == _overlay);\n }\n\n // ----------------------------- Claim verifications ------------------------------\n\n function socFunction(ChunkInclusionProof calldata entryProof) internal pure {\n if (entryProof.socProof.length == 0) return;\n\n if (\n !Signatures.socVerify(\n entryProof.socProof[0].signer, // signer Ethereum address to check against\n entryProof.socProof[0].signature,\n entryProof.socProof[0].identifier,\n entryProof.socProof[0].chunkAddr\n )\n ) {\n revert SocVerificationFailed(entryProof.socProof[0].chunkAddr);\n }\n\n if (\n calculateSocAddress(entryProof.socProof[0].identifier, entryProof.socProof[0].signer) !=\n entryProof.proveSegment\n ) {\n revert SocCalcNotMatching(entryProof.socProof[0].chunkAddr);\n }\n }\n\n function stampFunction(ChunkInclusionProof calldata entryProof) internal view {\n // authentic\n (address batchOwner, uint8 batchDepth, uint8 bucketDepth, , , ) = PostageContract.batches(\n entryProof.postageProof.postageId\n );\n\n // alive\n if (batchOwner == address(0)) {\n revert BatchDoesNotExist(entryProof.postageProof.postageId); // Batch does not exist or expired\n }\n\n uint32 postageIndex = getPostageIndex(entryProof.postageProof.index);\n uint256 maxPostageIndex = postageStampIndexCount(batchDepth, bucketDepth);\n // available\n if (postageIndex >= maxPostageIndex) {\n revert IndexOutsideSet(entryProof.postageProof.postageId);\n }\n\n // aligned\n uint64 postageBucket = getPostageBucket(entryProof.postageProof.index);\n uint64 addressBucket = addressToBucket(entryProof.proveSegment, bucketDepth);\n if (postageBucket != addressBucket) {\n revert BucketDiffers(entryProof.postageProof.postageId);\n }\n\n // authorized\n if (\n !Signatures.postageVerify(\n batchOwner,\n entryProof.postageProof.signature,\n entryProof.proveSegment,\n entryProof.postageProof.postageId,\n entryProof.postageProof.index,\n entryProof.postageProof.timeStamp\n )\n ) {\n revert SigRecoveryFailed(entryProof.postageProof.postageId);\n }\n }\n\n function addressToBucket(bytes32 swarmAddress, uint8 bucketDepth) internal pure returns (uint32) {\n uint32 prefix = uint32(uint256(swarmAddress) >> (256 - 32));\n return prefix >> (32 - bucketDepth);\n }\n\n function postageStampIndexCount(uint8 postageDepth, uint8 bucketDepth) internal pure returns (uint256) {\n return 1 << (postageDepth - bucketDepth);\n }\n\n function getPostageIndex(uint64 signedIndex) internal pure returns (uint32) {\n return uint32(signedIndex);\n }\n\n function getPostageBucket(uint64 signedIndex) internal pure returns (uint64) {\n return uint32(signedIndex >> 32);\n }\n\n function calculateSocAddress(bytes32 identifier, address signer) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(identifier, signer));\n }\n\n function checkOrder(uint256 a, uint256 b, bytes32 trA1, bytes32 trA2, bytes32 trALast) internal pure {\n if (a < b) {\n if (uint256(trA1) >= uint256(trA2)) {\n revert RandomElementCheckFailed();\n }\n if (uint256(trA2) >= uint256(trALast)) {\n revert LastElementCheckFailed();\n }\n } else {\n if (uint256(trA2) >= uint256(trA1)) {\n revert RandomElementCheckFailed();\n }\n if (uint256(trA1) >= uint256(trALast)) {\n revert LastElementCheckFailed();\n }\n }\n }\n\n function estimateSize(bytes32 trALast) internal view {\n if (uint256(trALast) >= sampleMaxValue) {\n revert ReserveCheckFailed(trALast);\n }\n }\n}\n" + }, + "src/Staking.sol": { + "content": "// SPDX-License-Identifier: BSD-3-Clause\npragma solidity ^0.8.19;\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"@openzeppelin/contracts/security/Pausable.sol\";\n\ninterface IPriceOracle {\n function currentPrice() external view returns (uint32);\n}\n\n/**\n * @title Staking contract for the Swarm storage incentives\n * @author The Swarm Authors\n * @dev Allows users to stake tokens in order to be eligible for the Redistribution Schelling co-ordination game.\n * Stakes are frozen or slashed by the Redistribution contract in response to violations of the\n * protocol.\n */\n\ncontract StakeRegistry is AccessControl, Pausable {\n // ----------------------------- State variables ------------------------------\n\n struct Stake {\n // Overlay of the node that is being staked\n bytes32 overlay;\n // Stake balance expressed through price oracle\n uint256 committedStake;\n // Stake balance expressed in BZZ\n uint256 potentialStake;\n // Block height the stake was updated, also used as flag to check if the stake is set\n uint256 lastUpdatedBlockNumber;\n // Node indicating its increased reserve\n uint8 height;\n }\n\n // Associate every stake id with node address data.\n mapping(address => Stake) public stakes;\n\n // Role allowed to freeze and slash entries\n bytes32 public constant REDISTRIBUTOR_ROLE = keccak256(\"REDISTRIBUTOR_ROLE\");\n\n // Swarm network ID\n uint64 NetworkId;\n\n // The miniumum stake allowed to be staked using the Staking contract.\n uint64 private constant MIN_STAKE = 100000000000000000;\n\n // Address of the staked ERC20 token\n address public immutable bzzToken;\n\n // The address of the linked PriceOracle contract.\n IPriceOracle public OracleContract;\n\n // ----------------------------- Events ------------------------------\n\n /**\n * @dev Emitted when a stake is created or updated by `owner` of the `overlay`.\n */\n event StakeUpdated(\n address indexed owner,\n uint256 committedStake,\n uint256 potentialStake,\n bytes32 overlay,\n uint256 lastUpdatedBlock,\n uint8 height\n );\n\n /**\n * @dev Emitted when a stake for address `slashed` is slashed by `amount`.\n */\n event StakeSlashed(address slashed, bytes32 overlay, uint256 amount);\n\n /**\n * @dev Emitted when a stake for address `frozen` is frozen for `time` blocks.\n */\n event StakeFrozen(address frozen, bytes32 overlay, uint256 time);\n\n /**\n * @dev Emitted when a address changes overlay it uses\n */\n event OverlayChanged(address owner, bytes32 overlay);\n\n /**\n * @dev Emitted when a stake for address is withdrawn\n */\n event StakeWithdrawn(address node, uint256 amount);\n\n // ----------------------------- Errors ------------------------------\n\n error TransferFailed(); // Used when token transfers fail\n error Frozen(); // Used when an action cannot proceed because the overlay is frozen\n error Unauthorized(); // Used where only the owner can perform the action\n error OnlyRedistributor(); // Used when only the redistributor role is allowed\n error OnlyPauser(); // Used when only the pauser role is allowed\n error BelowMinimumStake(); // Node participating in game has stake below minimum treshold\n\n // ----------------------------- CONSTRUCTOR ------------------------------\n\n /**\n * @param _bzzToken Address of the staked ERC20 token\n * @param _NetworkId Swarm network ID\n */\n constructor(address _bzzToken, uint64 _NetworkId, address _oracleContract) {\n NetworkId = _NetworkId;\n bzzToken = _bzzToken;\n OracleContract = IPriceOracle(_oracleContract);\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n }\n\n ////////////////////////////////////////\n // STATE SETTING //\n ////////////////////////////////////////\n\n /**\n * @notice Create a new stake or update an existing one, change overlay of node\n * @dev At least `_initialBalancePerChunk*2^depth` number of tokens need to be preapproved for this contract.\n * @param _setNonce Nonce that was used for overlay calculation.\n * @param _addAmount Deposited amount of ERC20 tokens, equals to added Potential stake value\n * @param _height increased reserve by registering the number of doublings\n */\n function manageStake(bytes32 _setNonce, uint256 _addAmount, uint8 _height) external whenNotPaused {\n bytes32 _previousOverlay = stakes[msg.sender].overlay;\n uint256 _stakingSet = stakes[msg.sender].lastUpdatedBlockNumber;\n bytes32 _newOverlay = keccak256(abi.encodePacked(msg.sender, reverse(NetworkId), _setNonce));\n\n // First time adding stake, check the minimum is added, take into account height\n if (_addAmount < MIN_STAKE * 2 ** _height && _stakingSet == 0) {\n revert BelowMinimumStake();\n }\n\n if (_stakingSet != 0 && !addressNotFrozen(msg.sender)) revert Frozen();\n\n uint256 updatedPotentialStake = stakes[msg.sender].potentialStake;\n uint256 updatedCommittedStake = stakes[msg.sender].committedStake;\n\n // Only update stake values if _addAmount is greater than 0\n if (_addAmount > 0) {\n updatedPotentialStake = stakes[msg.sender].potentialStake + _addAmount;\n updatedCommittedStake = updatedPotentialStake / (OracleContract.currentPrice() * 2 ** _height);\n }\n\n stakes[msg.sender] = Stake({\n overlay: _newOverlay,\n committedStake: updatedCommittedStake,\n potentialStake: updatedPotentialStake,\n lastUpdatedBlockNumber: block.number,\n height: _height\n });\n\n // Transfer tokens and emit event that stake has been updated\n if (_addAmount > 0) {\n if (!ERC20(bzzToken).transferFrom(msg.sender, address(this), _addAmount)) revert TransferFailed();\n emit StakeUpdated(\n msg.sender,\n updatedCommittedStake,\n updatedPotentialStake,\n _newOverlay,\n block.number,\n _height\n );\n }\n\n // Emit overlay change event\n if (_previousOverlay != _newOverlay) {\n emit OverlayChanged(msg.sender, _newOverlay);\n }\n }\n\n /**\n * @dev Withdraw node stake surplus\n */\n function withdrawFromStake() external {\n uint256 _potentialStake = stakes[msg.sender].potentialStake;\n uint256 _surplusStake = _potentialStake -\n calculateEffectiveStake(stakes[msg.sender].committedStake, _potentialStake, stakes[msg.sender].height);\n\n if (_surplusStake > 0) {\n stakes[msg.sender].potentialStake -= _surplusStake;\n if (!ERC20(bzzToken).transfer(msg.sender, _surplusStake)) revert TransferFailed();\n emit StakeWithdrawn(msg.sender, _surplusStake);\n }\n }\n\n /**\n * @dev Migrate stake only when the staking contract is paused,\n * can only be called by the owner of the stake\n */\n function migrateStake() external whenPaused {\n // We take out all the stake so user can migrate stake to other contract\n if (lastUpdatedBlockNumberOfAddress(msg.sender) != 0) {\n if (!ERC20(bzzToken).transfer(msg.sender, stakes[msg.sender].potentialStake)) revert TransferFailed();\n delete stakes[msg.sender];\n }\n }\n\n /**\n * @dev Freeze an existing stake, can only be called by the redistributor\n * @param _owner the addres selected\n * @param _time penalty length in blocknumbers\n */\n function freezeDeposit(address _owner, uint256 _time) external {\n if (!hasRole(REDISTRIBUTOR_ROLE, msg.sender)) revert OnlyRedistributor();\n\n if (stakes[_owner].lastUpdatedBlockNumber != 0) {\n stakes[_owner].lastUpdatedBlockNumber = block.number + _time;\n emit StakeFrozen(_owner, stakes[_owner].overlay, _time);\n }\n }\n\n /**\n * @dev Slash an existing stake, can only be called by the `redistributor`\n * @param _owner the _owner adress selected\n * @param _amount the amount to be slashed\n */\n function slashDeposit(address _owner, uint256 _amount) external {\n if (!hasRole(REDISTRIBUTOR_ROLE, msg.sender)) revert OnlyRedistributor();\n\n if (stakes[_owner].lastUpdatedBlockNumber != 0) {\n if (stakes[_owner].potentialStake > _amount) {\n stakes[_owner].potentialStake -= _amount;\n stakes[_owner].lastUpdatedBlockNumber = block.number;\n } else {\n delete stakes[_owner];\n }\n }\n emit StakeSlashed(_owner, stakes[_owner].overlay, _amount);\n }\n\n function changeNetworkId(uint64 _NetworkId) external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) revert Unauthorized();\n NetworkId = _NetworkId;\n }\n\n /**\n * @dev Pause the contract. The contract is provably stopped by renouncing\n the pauser role and the admin role after pausing, can only be called by the `PAUSER`\n */\n function pause() public {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) revert OnlyPauser();\n _pause();\n }\n\n /**\n * @dev Unpause the contract, can only be called by the pauser when paused\n */\n function unPause() public {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) revert OnlyPauser();\n _unpause();\n }\n\n ////////////////////////////////////////\n // STATE READING //\n ////////////////////////////////////////\n\n /**\n * @dev Checks to see if `address` is frozen.\n * @param _owner owner of staked address\n *\n * Returns a boolean value indicating whether the operation succeeded.\n */\n function addressNotFrozen(address _owner) internal view returns (bool) {\n return stakes[_owner].lastUpdatedBlockNumber < block.number;\n }\n\n /**\n * @dev Returns the current `effectiveStake` of `address`. previously usable stake\n * @param _owner _owner of node\n */\n function nodeEffectiveStake(address _owner) public view returns (uint256) {\n return\n addressNotFrozen(_owner)\n ? calculateEffectiveStake(\n stakes[_owner].committedStake,\n stakes[_owner].potentialStake,\n stakes[_owner].height\n )\n : 0;\n }\n\n /**\n * @dev Check the amount that is possible to withdraw as surplus\n */\n function withdrawableStake() public view returns (uint256) {\n uint256 _potentialStake = stakes[msg.sender].potentialStake;\n return\n _potentialStake -\n calculateEffectiveStake(stakes[msg.sender].committedStake, _potentialStake, stakes[msg.sender].height);\n }\n\n /**\n * @dev Returns the `lastUpdatedBlockNumber` of `address`.\n */\n function lastUpdatedBlockNumberOfAddress(address _owner) public view returns (uint256) {\n return stakes[_owner].lastUpdatedBlockNumber;\n }\n\n /**\n * @dev Returns the currently used overlay of the address.\n * @param _owner address of node\n */\n function overlayOfAddress(address _owner) public view returns (bytes32) {\n return stakes[_owner].overlay;\n }\n\n /**\n * @dev Returns the currently height of the address.\n * @param _owner address of node\n */\n function heightOfAddress(address _owner) public view returns (uint8) {\n return stakes[_owner].height;\n }\n\n function calculateEffectiveStake(\n uint256 committedStake,\n uint256 potentialStakeBalance,\n uint8 height\n ) internal view returns (uint256) {\n // Calculate the product of committedStake and unitPrice to get price in BZZ\n uint256 committedStakeBzz = (2 ** height) * committedStake * OracleContract.currentPrice();\n\n // Return the minimum value between committedStakeBzz and potentialStakeBalance\n if (committedStakeBzz < potentialStakeBalance) {\n return committedStakeBzz;\n } else {\n return potentialStakeBalance;\n }\n }\n\n /**\n * @dev Please both Endians 🥚.\n * @param input Eth address used for overlay calculation.\n */\n function reverse(uint64 input) internal pure returns (uint64 v) {\n v = input;\n\n // swap bytes\n v = ((v & 0xFF00FF00FF00FF00) >> 8) | ((v & 0x00FF00FF00FF00FF) << 8);\n\n // swap 2-byte long pairs\n v = ((v & 0xFFFF0000FFFF0000) >> 16) | ((v & 0x0000FFFF0000FFFF) << 16);\n\n // swap 4-byte long pairs\n v = (v >> 32) | (v << 32);\n }\n}\n" + }, + "src/TestToken.sol": { + "content": "// SPDX-License-Identifier: BSD-3-Clause\npragma solidity ^0.8.19;\n\nimport \"@openzeppelin/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol\";\n\ncontract TestToken is ERC20PresetMinterPauser {\n uint256 private _initialSupply;\n\n constructor(string memory name, string memory symbol, uint256 initialSupply) ERC20PresetMinterPauser(name, symbol) {\n _initialSupply = initialSupply;\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n _mint(msg.sender, initialSupply);\n }\n\n // We use 16 decimals for BZZ/sBZZ token so we need to override it here\n function decimals() public view virtual override returns (uint8) {\n return 16;\n }\n}\n" + }, + "src/Util/ChunkProof.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\nlibrary BMTChunk {\n // max chunk payload size\n uint256 public constant MAX_CHUNK_PAYLOAD_SIZE = 4096;\n // segment byte size\n uint256 public constant SEGMENT_SIZE = 32;\n\n /**\n * @notice Changes the endianness of a uint64.\n * @dev https://graphics.stanford.edu/~seander/bithacks.html#ReverseParallel\n * @param _b The unsigned integer to reverse\n * @return v - The reversed value\n */\n function reverseUint64(uint64 _b) public pure returns (uint64) {\n uint256 v = _b;\n\n // swap bytes\n v =\n ((v >> 8) & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) |\n ((v & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) << 8);\n // swap 2-byte long pairs\n v =\n ((v >> 16) & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) |\n ((v & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) << 16);\n // swap 4-byte long pairs\n v =\n ((v >> 32) & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) |\n ((v & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) << 32);\n\n return uint64(v);\n }\n\n /** Calculates the root hash from the provided inclusion proof segments and its corresponding segment index\n * @param _proofSegments Proof segments.\n * @param _proveSegment Segment to prove.\n * @param _proveSegmentIndex Prove segment index\n * @return _calculatedHash chunk hash\n */\n function rootHashFromInclusionProof(\n bytes32[] memory _proofSegments,\n bytes32 _proveSegment,\n uint256 _proveSegmentIndex\n ) internal pure returns (bytes32 _calculatedHash) {\n _calculatedHash = _proveSegment;\n for (uint256 i = 0; i < _proofSegments.length; i++) {\n bool mergeFromRight = _proveSegmentIndex % 2 == 0;\n _calculatedHash = mergeSegment(_calculatedHash, _proofSegments[i], mergeFromRight);\n _proveSegmentIndex >>= 1;\n }\n return _calculatedHash;\n }\n\n /**\n * Calculate the chunk address from the Binary Merkle Tree of the chunk data\n *\n * The BMT chunk address is the hash of the 8 byte span and the root\n * hash of a binary Merkle tree (BMT) built on the 32-byte segments\n * of the underlying data.\n * @param _proofSegments Proof segments.\n * @param _proveSegment Segment to prove.\n * @param _proveSegmentIndex Prove segment index\n * @param _chunkSpan chunk bytes length\n * @return _chunkHash chunk hash\n */\n function chunkAddressFromInclusionProof(\n bytes32[] memory _proofSegments,\n bytes32 _proveSegment,\n uint256 _proveSegmentIndex,\n uint64 _chunkSpan\n ) internal pure returns (bytes32) {\n bytes32 rootHash = rootHashFromInclusionProof(_proofSegments, _proveSegment, _proveSegmentIndex);\n return keccak256(abi.encodePacked(reverseUint64(_chunkSpan), rootHash));\n }\n\n function mergeSegment(\n bytes32 _calculatedHash,\n bytes32 _proofSegment,\n bool mergeFromRight\n ) internal pure returns (bytes32 res) {\n if (mergeFromRight) {\n res = keccak256(abi.encode(_calculatedHash, _proofSegment));\n } else {\n res = keccak256(abi.encode(_proofSegment, _calculatedHash));\n }\n return res;\n }\n}\n" + }, + "src/Util/Signatures.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\nlibrary Signatures {\n error InvalidSignatureLength();\n\n /** Hash of the message to sign */\n function getPostageMessageHash(\n bytes32 _chunkAddr,\n bytes32 _batchId,\n uint64 _index,\n uint64 _timeStamp\n ) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(_chunkAddr, _batchId, _index, _timeStamp));\n }\n\n function postageVerify(\n address _signer, // signer Ethereum address to check against\n bytes memory _signature,\n bytes32 _chunkAddr,\n bytes32 _postageId,\n uint64 _index,\n uint64 _timeStamp\n ) internal pure returns (bool) {\n bytes32 messageHash = getPostageMessageHash(_chunkAddr, _postageId, _index, _timeStamp);\n bytes32 ethMessageHash = getEthSignedMessageHash(messageHash);\n\n return recoverSigner(ethMessageHash, _signature) == _signer;\n }\n\n function getEthSignedMessageHash(bytes32 _messageHash) internal pure returns (bytes32) {\n /*\n Signature is produced by signing a keccak256 hash with the following format:\n \"\\x19Ethereum Signed Message\\n\" + len(msg) + msg\n */\n return keccak256(abi.encodePacked(\"\\x19Ethereum Signed Message:\\n32\", _messageHash));\n }\n\n function recoverSigner(\n bytes32 _ethSignedMessageHash, // it has to be prefixed message: https://ethereum.stackexchange.com/questions/19582/does-ecrecover-in-solidity-expects-the-x19ethereum-signed-message-n-prefix/21037\n bytes memory _signature\n ) internal pure returns (address) {\n (bytes32 r, bytes32 s, uint8 v) = splitSignature(_signature);\n\n return ecrecover(_ethSignedMessageHash, v, r, s);\n }\n\n function splitSignature(bytes memory sig) internal pure returns (bytes32 r_, bytes32 s_, uint8 v_) {\n if (sig.length != 65) {\n revert InvalidSignatureLength();\n }\n\n assembly {\n /*\n verbose explanation: https://ethereum.stackexchange.com/questions/135591/split-signature-function-in-solidity-by-example-docs\n First 32 bytes stores the length of the signature\n add(sig, 32) = pointer of sig + 32\n effectively, skips first 32 bytes of signature\n mload(p) loads next 32 bytes starting at the memory address p into memory\n */\n\n // first 32 bytes, after the length prefix\n r_ := mload(add(sig, 32))\n // second 32 bytes\n s_ := mload(add(sig, 64))\n // final byte (first byte of the next 32 bytes)\n v_ := byte(0, mload(add(sig, 96)))\n }\n\n // implicitly return (r, s, v)\n }\n\n function getSocMessageHash(bytes32 _identifier, bytes32 _chunkAddr) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(_identifier, _chunkAddr));\n }\n\n function socVerify(\n address _signer, // signer Ethereum address to check against\n bytes memory _signature,\n bytes32 _identifier,\n bytes32 _chunkAddr\n ) internal pure returns (bool) {\n bytes32 messageHash = getSocMessageHash(_identifier, _chunkAddr);\n bytes32 ethMessageHash = getEthSignedMessageHash(messageHash);\n\n return recoverSigner(ethMessageHash, _signature) == _signer;\n }\n}\n" + }, + "src/Util/TransformedChunkProof.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\nlibrary TransformedBMTChunk {\n // max chunk payload size\n uint256 public constant MAX_CHUNK_PAYLOAD_SIZE = 4096;\n // segment byte size\n uint256 public constant SEGMENT_SIZE = 32;\n\n /** Calculates the root hash from the provided inclusion proof segments and its corresponding segment index\n * @param _proofSegments Proof segments.\n * @param _proveSegment Segment to prove.\n * @param _proveSegmentIndex Prove segment index\n * @return _calculatedHash chunk hash\n */\n function transformedRootHashFromInclusionProof(\n bytes32[] memory _proofSegments,\n bytes32 _proveSegment,\n uint256 _proveSegmentIndex,\n bytes32 key\n ) internal pure returns (bytes32 _calculatedHash) {\n _calculatedHash = _proveSegment;\n for (uint256 i = 0; i < _proofSegments.length; i++) {\n bool mergeFromRight = _proveSegmentIndex % 2 == 0 ? true : false;\n _calculatedHash = transformedMergeSegment(_calculatedHash, _proofSegments[i], mergeFromRight, key);\n _proveSegmentIndex >>= 1;\n }\n\n return _calculatedHash;\n }\n\n /**\n * @notice Changes the endianness of a uint64.\n * @dev https://graphics.stanford.edu/~seander/bithacks.html#ReverseParallel\n * @param _b The unsigned integer to reverse\n * @return v - The reversed value\n */\n function reverseUint64(uint64 _b) public pure returns (uint64) {\n uint256 v = _b;\n\n // swap bytes\n v =\n ((v >> 8) & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) |\n ((v & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) << 8);\n // swap 2-byte long pairs\n v =\n ((v >> 16) & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) |\n ((v & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) << 16);\n // swap 4-byte long pairs\n v =\n ((v >> 32) & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) |\n ((v & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) << 32);\n\n return uint64(v);\n }\n\n /**\n * Calculate the chunk address from the Binary Merkle Tree of the chunk data\n *\n * The BMT chunk address is the hash of the 8 byte span and the root\n * hash of a binary Merkle tree (BMT) built on the 32-byte segments\n * of the underlying data.\n * @param _proofSegments Proof segments.\n * @param _proveSegment Segment to prove.\n * @param _proveSegmentIndex Prove segment index\n * @param _chunkSpan chunk bytes length\n * @return _chunkHash chunk hash\n */\n function transformedChunkAddressFromInclusionProof(\n bytes32[] memory _proofSegments,\n bytes32 _proveSegment,\n uint256 _proveSegmentIndex,\n uint64 _chunkSpan,\n bytes32 key\n ) internal pure returns (bytes32) {\n bytes32 rootHash = transformedRootHashFromInclusionProof(\n _proofSegments,\n _proveSegment,\n _proveSegmentIndex,\n key\n );\n return keccak256(abi.encodePacked(key, reverseUint64(_chunkSpan), rootHash));\n }\n\n function transformedMergeSegment(\n bytes32 _calculatedHash,\n bytes32 _proofSegment,\n bool mergeFromRight,\n bytes32 key\n ) internal pure returns (bytes32 res) {\n if (mergeFromRight) {\n res = keccak256(abi.encode(key, _calculatedHash, _proofSegment));\n } else {\n res = keccak256(abi.encode(key, _proofSegment, _calculatedHash));\n }\n return res;\n }\n}\n" + } + }, + "settings": { + "optimizer": { + "enabled": true, + "runs": 1000 + }, + "outputSelection": { + "*": { + "*": [ + "abi", + "evm.bytecode", + "evm.deployedBytecode", + "evm.methodIdentifiers", + "metadata", + "devdoc", + "userdoc", + "storageLayout", + "evm.gasEstimates" + ], + "": [ + "ast" + ] + } + }, + "metadata": { + "useLiteralContent": true + }, + "libraries": { + "": { + "__CACHE_BREAKER__": "0x00000000d41867734bbee4c6863d9255b2b06ac1" + } + } + } +} \ No newline at end of file diff --git a/deployments/testnet/solcInputs/99c9ef5f7ef53ea99ef6c816b26b1e5c.json b/deployments/testnet/solcInputs/99c9ef5f7ef53ea99ef6c816b26b1e5c.json new file mode 100644 index 00000000..de0b639f --- /dev/null +++ b/deployments/testnet/solcInputs/99c9ef5f7ef53ea99ef6c816b26b1e5c.json @@ -0,0 +1,118 @@ +{ + "language": "Solidity", + "sources": { + "@openzeppelin/contracts/access/AccessControl.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (access/AccessControl.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IAccessControl.sol\";\nimport \"../utils/Context.sol\";\nimport \"../utils/Strings.sol\";\nimport \"../utils/introspection/ERC165.sol\";\n\n/**\n * @dev Contract module that allows children to implement role-based access\n * control mechanisms. This is a lightweight version that doesn't allow enumerating role\n * members except through off-chain means by accessing the contract event logs. Some\n * applications may benefit from on-chain enumerability, for those cases see\n * {AccessControlEnumerable}.\n *\n * Roles are referred to by their `bytes32` identifier. These should be exposed\n * in the external API and be unique. The best way to achieve this is by\n * using `public constant` hash digests:\n *\n * ```\n * bytes32 public constant MY_ROLE = keccak256(\"MY_ROLE\");\n * ```\n *\n * Roles can be used to represent a set of permissions. To restrict access to a\n * function call, use {hasRole}:\n *\n * ```\n * function foo() public {\n * require(hasRole(MY_ROLE, msg.sender));\n * ...\n * }\n * ```\n *\n * Roles can be granted and revoked dynamically via the {grantRole} and\n * {revokeRole} functions. Each role has an associated admin role, and only\n * accounts that have a role's admin role can call {grantRole} and {revokeRole}.\n *\n * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means\n * that only accounts with this role will be able to grant or revoke other\n * roles. More complex role relationships can be created by using\n * {_setRoleAdmin}.\n *\n * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to\n * grant and revoke this role. Extra precautions should be taken to secure\n * accounts that have been granted it.\n */\nabstract contract AccessControl is Context, IAccessControl, ERC165 {\n struct RoleData {\n mapping(address => bool) members;\n bytes32 adminRole;\n }\n\n mapping(bytes32 => RoleData) private _roles;\n\n bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;\n\n /**\n * @dev Modifier that checks that an account has a specific role. Reverts\n * with a standardized message including the required role.\n *\n * The format of the revert reason is given by the following regular expression:\n *\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\n *\n * _Available since v4.1._\n */\n modifier onlyRole(bytes32 role) {\n _checkRole(role);\n _;\n }\n\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);\n }\n\n /**\n * @dev Returns `true` if `account` has been granted `role`.\n */\n function hasRole(bytes32 role, address account) public view virtual override returns (bool) {\n return _roles[role].members[account];\n }\n\n /**\n * @dev Revert with a standard message if `_msgSender()` is missing `role`.\n * Overriding this function changes the behavior of the {onlyRole} modifier.\n *\n * Format of the revert message is described in {_checkRole}.\n *\n * _Available since v4.6._\n */\n function _checkRole(bytes32 role) internal view virtual {\n _checkRole(role, _msgSender());\n }\n\n /**\n * @dev Revert with a standard message if `account` is missing `role`.\n *\n * The format of the revert reason is given by the following regular expression:\n *\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\n */\n function _checkRole(bytes32 role, address account) internal view virtual {\n if (!hasRole(role, account)) {\n revert(\n string(\n abi.encodePacked(\n \"AccessControl: account \",\n Strings.toHexString(account),\n \" is missing role \",\n Strings.toHexString(uint256(role), 32)\n )\n )\n );\n }\n }\n\n /**\n * @dev Returns the admin role that controls `role`. See {grantRole} and\n * {revokeRole}.\n *\n * To change a role's admin, use {_setRoleAdmin}.\n */\n function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {\n return _roles[role].adminRole;\n }\n\n /**\n * @dev Grants `role` to `account`.\n *\n * If `account` had not been already granted `role`, emits a {RoleGranted}\n * event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n *\n * May emit a {RoleGranted} event.\n */\n function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\n _grantRole(role, account);\n }\n\n /**\n * @dev Revokes `role` from `account`.\n *\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n *\n * May emit a {RoleRevoked} event.\n */\n function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\n _revokeRole(role, account);\n }\n\n /**\n * @dev Revokes `role` from the calling account.\n *\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\n * purpose is to provide a mechanism for accounts to lose their privileges\n * if they are compromised (such as when a trusted device is misplaced).\n *\n * If the calling account had been revoked `role`, emits a {RoleRevoked}\n * event.\n *\n * Requirements:\n *\n * - the caller must be `account`.\n *\n * May emit a {RoleRevoked} event.\n */\n function renounceRole(bytes32 role, address account) public virtual override {\n require(account == _msgSender(), \"AccessControl: can only renounce roles for self\");\n\n _revokeRole(role, account);\n }\n\n /**\n * @dev Grants `role` to `account`.\n *\n * If `account` had not been already granted `role`, emits a {RoleGranted}\n * event. Note that unlike {grantRole}, this function doesn't perform any\n * checks on the calling account.\n *\n * May emit a {RoleGranted} event.\n *\n * [WARNING]\n * ====\n * This function should only be called from the constructor when setting\n * up the initial roles for the system.\n *\n * Using this function in any other way is effectively circumventing the admin\n * system imposed by {AccessControl}.\n * ====\n *\n * NOTE: This function is deprecated in favor of {_grantRole}.\n */\n function _setupRole(bytes32 role, address account) internal virtual {\n _grantRole(role, account);\n }\n\n /**\n * @dev Sets `adminRole` as ``role``'s admin role.\n *\n * Emits a {RoleAdminChanged} event.\n */\n function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {\n bytes32 previousAdminRole = getRoleAdmin(role);\n _roles[role].adminRole = adminRole;\n emit RoleAdminChanged(role, previousAdminRole, adminRole);\n }\n\n /**\n * @dev Grants `role` to `account`.\n *\n * Internal function without access restriction.\n *\n * May emit a {RoleGranted} event.\n */\n function _grantRole(bytes32 role, address account) internal virtual {\n if (!hasRole(role, account)) {\n _roles[role].members[account] = true;\n emit RoleGranted(role, account, _msgSender());\n }\n }\n\n /**\n * @dev Revokes `role` from `account`.\n *\n * Internal function without access restriction.\n *\n * May emit a {RoleRevoked} event.\n */\n function _revokeRole(bytes32 role, address account) internal virtual {\n if (hasRole(role, account)) {\n _roles[role].members[account] = false;\n emit RoleRevoked(role, account, _msgSender());\n }\n }\n}\n" + }, + "@openzeppelin/contracts/access/AccessControlEnumerable.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (access/AccessControlEnumerable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IAccessControlEnumerable.sol\";\nimport \"./AccessControl.sol\";\nimport \"../utils/structs/EnumerableSet.sol\";\n\n/**\n * @dev Extension of {AccessControl} that allows enumerating the members of each role.\n */\nabstract contract AccessControlEnumerable is IAccessControlEnumerable, AccessControl {\n using EnumerableSet for EnumerableSet.AddressSet;\n\n mapping(bytes32 => EnumerableSet.AddressSet) private _roleMembers;\n\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n return interfaceId == type(IAccessControlEnumerable).interfaceId || super.supportsInterface(interfaceId);\n }\n\n /**\n * @dev Returns one of the accounts that have `role`. `index` must be a\n * value between 0 and {getRoleMemberCount}, non-inclusive.\n *\n * Role bearers are not sorted in any particular way, and their ordering may\n * change at any point.\n *\n * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure\n * you perform all queries on the same block. See the following\n * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]\n * for more information.\n */\n function getRoleMember(bytes32 role, uint256 index) public view virtual override returns (address) {\n return _roleMembers[role].at(index);\n }\n\n /**\n * @dev Returns the number of accounts that have `role`. Can be used\n * together with {getRoleMember} to enumerate all bearers of a role.\n */\n function getRoleMemberCount(bytes32 role) public view virtual override returns (uint256) {\n return _roleMembers[role].length();\n }\n\n /**\n * @dev Overload {_grantRole} to track enumerable memberships\n */\n function _grantRole(bytes32 role, address account) internal virtual override {\n super._grantRole(role, account);\n _roleMembers[role].add(account);\n }\n\n /**\n * @dev Overload {_revokeRole} to track enumerable memberships\n */\n function _revokeRole(bytes32 role, address account) internal virtual override {\n super._revokeRole(role, account);\n _roleMembers[role].remove(account);\n }\n}\n" + }, + "@openzeppelin/contracts/access/IAccessControl.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev External interface of AccessControl declared to support ERC165 detection.\n */\ninterface IAccessControl {\n /**\n * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`\n *\n * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite\n * {RoleAdminChanged} not being emitted signaling this.\n *\n * _Available since v3.1._\n */\n event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);\n\n /**\n * @dev Emitted when `account` is granted `role`.\n *\n * `sender` is the account that originated the contract call, an admin role\n * bearer except when using {AccessControl-_setupRole}.\n */\n event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);\n\n /**\n * @dev Emitted when `account` is revoked `role`.\n *\n * `sender` is the account that originated the contract call:\n * - if using `revokeRole`, it is the admin role bearer\n * - if using `renounceRole`, it is the role bearer (i.e. `account`)\n */\n event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);\n\n /**\n * @dev Returns `true` if `account` has been granted `role`.\n */\n function hasRole(bytes32 role, address account) external view returns (bool);\n\n /**\n * @dev Returns the admin role that controls `role`. See {grantRole} and\n * {revokeRole}.\n *\n * To change a role's admin, use {AccessControl-_setRoleAdmin}.\n */\n function getRoleAdmin(bytes32 role) external view returns (bytes32);\n\n /**\n * @dev Grants `role` to `account`.\n *\n * If `account` had not been already granted `role`, emits a {RoleGranted}\n * event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n */\n function grantRole(bytes32 role, address account) external;\n\n /**\n * @dev Revokes `role` from `account`.\n *\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n */\n function revokeRole(bytes32 role, address account) external;\n\n /**\n * @dev Revokes `role` from the calling account.\n *\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\n * purpose is to provide a mechanism for accounts to lose their privileges\n * if they are compromised (such as when a trusted device is misplaced).\n *\n * If the calling account had been granted `role`, emits a {RoleRevoked}\n * event.\n *\n * Requirements:\n *\n * - the caller must be `account`.\n */\n function renounceRole(bytes32 role, address account) external;\n}\n" + }, + "@openzeppelin/contracts/access/IAccessControlEnumerable.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (access/IAccessControlEnumerable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IAccessControl.sol\";\n\n/**\n * @dev External interface of AccessControlEnumerable declared to support ERC165 detection.\n */\ninterface IAccessControlEnumerable is IAccessControl {\n /**\n * @dev Returns one of the accounts that have `role`. `index` must be a\n * value between 0 and {getRoleMemberCount}, non-inclusive.\n *\n * Role bearers are not sorted in any particular way, and their ordering may\n * change at any point.\n *\n * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure\n * you perform all queries on the same block. See the following\n * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]\n * for more information.\n */\n function getRoleMember(bytes32 role, uint256 index) external view returns (address);\n\n /**\n * @dev Returns the number of accounts that have `role`. Can be used\n * together with {getRoleMember} to enumerate all bearers of a role.\n */\n function getRoleMemberCount(bytes32 role) external view returns (uint256);\n}\n" + }, + "@openzeppelin/contracts/security/Pausable.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which allows children to implement an emergency stop\n * mechanism that can be triggered by an authorized account.\n *\n * This module is used through inheritance. It will make available the\n * modifiers `whenNotPaused` and `whenPaused`, which can be applied to\n * the functions of your contract. Note that they will not be pausable by\n * simply including this module, only once the modifiers are put in place.\n */\nabstract contract Pausable is Context {\n /**\n * @dev Emitted when the pause is triggered by `account`.\n */\n event Paused(address account);\n\n /**\n * @dev Emitted when the pause is lifted by `account`.\n */\n event Unpaused(address account);\n\n bool private _paused;\n\n /**\n * @dev Initializes the contract in unpaused state.\n */\n constructor() {\n _paused = false;\n }\n\n /**\n * @dev Modifier to make a function callable only when the contract is not paused.\n *\n * Requirements:\n *\n * - The contract must not be paused.\n */\n modifier whenNotPaused() {\n _requireNotPaused();\n _;\n }\n\n /**\n * @dev Modifier to make a function callable only when the contract is paused.\n *\n * Requirements:\n *\n * - The contract must be paused.\n */\n modifier whenPaused() {\n _requirePaused();\n _;\n }\n\n /**\n * @dev Returns true if the contract is paused, and false otherwise.\n */\n function paused() public view virtual returns (bool) {\n return _paused;\n }\n\n /**\n * @dev Throws if the contract is paused.\n */\n function _requireNotPaused() internal view virtual {\n require(!paused(), \"Pausable: paused\");\n }\n\n /**\n * @dev Throws if the contract is not paused.\n */\n function _requirePaused() internal view virtual {\n require(paused(), \"Pausable: not paused\");\n }\n\n /**\n * @dev Triggers stopped state.\n *\n * Requirements:\n *\n * - The contract must not be paused.\n */\n function _pause() internal virtual whenNotPaused {\n _paused = true;\n emit Paused(_msgSender());\n }\n\n /**\n * @dev Returns to normal state.\n *\n * Requirements:\n *\n * - The contract must be paused.\n */\n function _unpause() internal virtual whenPaused {\n _paused = false;\n emit Unpaused(_msgSender());\n }\n}\n" + }, + "@openzeppelin/contracts/token/ERC20/ERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/ERC20.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC20.sol\";\nimport \"./extensions/IERC20Metadata.sol\";\nimport \"../../utils/Context.sol\";\n\n/**\n * @dev Implementation of the {IERC20} interface.\n *\n * This implementation is agnostic to the way tokens are created. This means\n * that a supply mechanism has to be added in a derived contract using {_mint}.\n * For a generic mechanism see {ERC20PresetMinterPauser}.\n *\n * TIP: For a detailed writeup see our guide\n * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How\n * to implement supply mechanisms].\n *\n * We have followed general OpenZeppelin Contracts guidelines: functions revert\n * instead returning `false` on failure. This behavior is nonetheless\n * conventional and does not conflict with the expectations of ERC20\n * applications.\n *\n * Additionally, an {Approval} event is emitted on calls to {transferFrom}.\n * This allows applications to reconstruct the allowance for all accounts just\n * by listening to said events. Other implementations of the EIP may not emit\n * these events, as it isn't required by the specification.\n *\n * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}\n * functions have been added to mitigate the well-known issues around setting\n * allowances. See {IERC20-approve}.\n */\ncontract ERC20 is Context, IERC20, IERC20Metadata {\n mapping(address => uint256) private _balances;\n\n mapping(address => mapping(address => uint256)) private _allowances;\n\n uint256 private _totalSupply;\n\n string private _name;\n string private _symbol;\n\n /**\n * @dev Sets the values for {name} and {symbol}.\n *\n * The default value of {decimals} is 18. To select a different value for\n * {decimals} you should overload it.\n *\n * All two of these values are immutable: they can only be set once during\n * construction.\n */\n constructor(string memory name_, string memory symbol_) {\n _name = name_;\n _symbol = symbol_;\n }\n\n /**\n * @dev Returns the name of the token.\n */\n function name() public view virtual override returns (string memory) {\n return _name;\n }\n\n /**\n * @dev Returns the symbol of the token, usually a shorter version of the\n * name.\n */\n function symbol() public view virtual override returns (string memory) {\n return _symbol;\n }\n\n /**\n * @dev Returns the number of decimals used to get its user representation.\n * For example, if `decimals` equals `2`, a balance of `505` tokens should\n * be displayed to a user as `5.05` (`505 / 10 ** 2`).\n *\n * Tokens usually opt for a value of 18, imitating the relationship between\n * Ether and Wei. This is the value {ERC20} uses, unless this function is\n * overridden;\n *\n * NOTE: This information is only used for _display_ purposes: it in\n * no way affects any of the arithmetic of the contract, including\n * {IERC20-balanceOf} and {IERC20-transfer}.\n */\n function decimals() public view virtual override returns (uint8) {\n return 18;\n }\n\n /**\n * @dev See {IERC20-totalSupply}.\n */\n function totalSupply() public view virtual override returns (uint256) {\n return _totalSupply;\n }\n\n /**\n * @dev See {IERC20-balanceOf}.\n */\n function balanceOf(address account) public view virtual override returns (uint256) {\n return _balances[account];\n }\n\n /**\n * @dev See {IERC20-transfer}.\n *\n * Requirements:\n *\n * - `to` cannot be the zero address.\n * - the caller must have a balance of at least `amount`.\n */\n function transfer(address to, uint256 amount) public virtual override returns (bool) {\n address owner = _msgSender();\n _transfer(owner, to, amount);\n return true;\n }\n\n /**\n * @dev See {IERC20-allowance}.\n */\n function allowance(address owner, address spender) public view virtual override returns (uint256) {\n return _allowances[owner][spender];\n }\n\n /**\n * @dev See {IERC20-approve}.\n *\n * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on\n * `transferFrom`. This is semantically equivalent to an infinite approval.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function approve(address spender, uint256 amount) public virtual override returns (bool) {\n address owner = _msgSender();\n _approve(owner, spender, amount);\n return true;\n }\n\n /**\n * @dev See {IERC20-transferFrom}.\n *\n * Emits an {Approval} event indicating the updated allowance. This is not\n * required by the EIP. See the note at the beginning of {ERC20}.\n *\n * NOTE: Does not update the allowance if the current allowance\n * is the maximum `uint256`.\n *\n * Requirements:\n *\n * - `from` and `to` cannot be the zero address.\n * - `from` must have a balance of at least `amount`.\n * - the caller must have allowance for ``from``'s tokens of at least\n * `amount`.\n */\n function transferFrom(\n address from,\n address to,\n uint256 amount\n ) public virtual override returns (bool) {\n address spender = _msgSender();\n _spendAllowance(from, spender, amount);\n _transfer(from, to, amount);\n return true;\n }\n\n /**\n * @dev Atomically increases the allowance granted to `spender` by the caller.\n *\n * This is an alternative to {approve} that can be used as a mitigation for\n * problems described in {IERC20-approve}.\n *\n * Emits an {Approval} event indicating the updated allowance.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {\n address owner = _msgSender();\n _approve(owner, spender, allowance(owner, spender) + addedValue);\n return true;\n }\n\n /**\n * @dev Atomically decreases the allowance granted to `spender` by the caller.\n *\n * This is an alternative to {approve} that can be used as a mitigation for\n * problems described in {IERC20-approve}.\n *\n * Emits an {Approval} event indicating the updated allowance.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n * - `spender` must have allowance for the caller of at least\n * `subtractedValue`.\n */\n function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {\n address owner = _msgSender();\n uint256 currentAllowance = allowance(owner, spender);\n require(currentAllowance >= subtractedValue, \"ERC20: decreased allowance below zero\");\n unchecked {\n _approve(owner, spender, currentAllowance - subtractedValue);\n }\n\n return true;\n }\n\n /**\n * @dev Moves `amount` of tokens from `from` to `to`.\n *\n * This internal function is equivalent to {transfer}, and can be used to\n * e.g. implement automatic token fees, slashing mechanisms, etc.\n *\n * Emits a {Transfer} event.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `from` must have a balance of at least `amount`.\n */\n function _transfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual {\n require(from != address(0), \"ERC20: transfer from the zero address\");\n require(to != address(0), \"ERC20: transfer to the zero address\");\n\n _beforeTokenTransfer(from, to, amount);\n\n uint256 fromBalance = _balances[from];\n require(fromBalance >= amount, \"ERC20: transfer amount exceeds balance\");\n unchecked {\n _balances[from] = fromBalance - amount;\n // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by\n // decrementing then incrementing.\n _balances[to] += amount;\n }\n\n emit Transfer(from, to, amount);\n\n _afterTokenTransfer(from, to, amount);\n }\n\n /** @dev Creates `amount` tokens and assigns them to `account`, increasing\n * the total supply.\n *\n * Emits a {Transfer} event with `from` set to the zero address.\n *\n * Requirements:\n *\n * - `account` cannot be the zero address.\n */\n function _mint(address account, uint256 amount) internal virtual {\n require(account != address(0), \"ERC20: mint to the zero address\");\n\n _beforeTokenTransfer(address(0), account, amount);\n\n _totalSupply += amount;\n unchecked {\n // Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.\n _balances[account] += amount;\n }\n emit Transfer(address(0), account, amount);\n\n _afterTokenTransfer(address(0), account, amount);\n }\n\n /**\n * @dev Destroys `amount` tokens from `account`, reducing the\n * total supply.\n *\n * Emits a {Transfer} event with `to` set to the zero address.\n *\n * Requirements:\n *\n * - `account` cannot be the zero address.\n * - `account` must have at least `amount` tokens.\n */\n function _burn(address account, uint256 amount) internal virtual {\n require(account != address(0), \"ERC20: burn from the zero address\");\n\n _beforeTokenTransfer(account, address(0), amount);\n\n uint256 accountBalance = _balances[account];\n require(accountBalance >= amount, \"ERC20: burn amount exceeds balance\");\n unchecked {\n _balances[account] = accountBalance - amount;\n // Overflow not possible: amount <= accountBalance <= totalSupply.\n _totalSupply -= amount;\n }\n\n emit Transfer(account, address(0), amount);\n\n _afterTokenTransfer(account, address(0), amount);\n }\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.\n *\n * This internal function is equivalent to `approve`, and can be used to\n * e.g. set automatic allowances for certain subsystems, etc.\n *\n * Emits an {Approval} event.\n *\n * Requirements:\n *\n * - `owner` cannot be the zero address.\n * - `spender` cannot be the zero address.\n */\n function _approve(\n address owner,\n address spender,\n uint256 amount\n ) internal virtual {\n require(owner != address(0), \"ERC20: approve from the zero address\");\n require(spender != address(0), \"ERC20: approve to the zero address\");\n\n _allowances[owner][spender] = amount;\n emit Approval(owner, spender, amount);\n }\n\n /**\n * @dev Updates `owner` s allowance for `spender` based on spent `amount`.\n *\n * Does not update the allowance amount in case of infinite allowance.\n * Revert if not enough allowance is available.\n *\n * Might emit an {Approval} event.\n */\n function _spendAllowance(\n address owner,\n address spender,\n uint256 amount\n ) internal virtual {\n uint256 currentAllowance = allowance(owner, spender);\n if (currentAllowance != type(uint256).max) {\n require(currentAllowance >= amount, \"ERC20: insufficient allowance\");\n unchecked {\n _approve(owner, spender, currentAllowance - amount);\n }\n }\n }\n\n /**\n * @dev Hook that is called before any transfer of tokens. This includes\n * minting and burning.\n *\n * Calling conditions:\n *\n * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n * will be transferred to `to`.\n * - when `from` is zero, `amount` tokens will be minted for `to`.\n * - when `to` is zero, `amount` of ``from``'s tokens will be burned.\n * - `from` and `to` are never both zero.\n *\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n */\n function _beforeTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual {}\n\n /**\n * @dev Hook that is called after any transfer of tokens. This includes\n * minting and burning.\n *\n * Calling conditions:\n *\n * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n * has been transferred to `to`.\n * - when `from` is zero, `amount` tokens have been minted for `to`.\n * - when `to` is zero, `amount` of ``from``'s tokens have been burned.\n * - `from` and `to` are never both zero.\n *\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n */\n function _afterTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual {}\n}\n" + }, + "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/extensions/ERC20Burnable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../ERC20.sol\";\nimport \"../../../utils/Context.sol\";\n\n/**\n * @dev Extension of {ERC20} that allows token holders to destroy both their own\n * tokens and those that they have an allowance for, in a way that can be\n * recognized off-chain (via event analysis).\n */\nabstract contract ERC20Burnable is Context, ERC20 {\n /**\n * @dev Destroys `amount` tokens from the caller.\n *\n * See {ERC20-_burn}.\n */\n function burn(uint256 amount) public virtual {\n _burn(_msgSender(), amount);\n }\n\n /**\n * @dev Destroys `amount` tokens from `account`, deducting from the caller's\n * allowance.\n *\n * See {ERC20-_burn} and {ERC20-allowance}.\n *\n * Requirements:\n *\n * - the caller must have allowance for ``accounts``'s tokens of at least\n * `amount`.\n */\n function burnFrom(address account, uint256 amount) public virtual {\n _spendAllowance(account, _msgSender(), amount);\n _burn(account, amount);\n }\n}\n" + }, + "@openzeppelin/contracts/token/ERC20/extensions/ERC20Pausable.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.2) (token/ERC20/extensions/ERC20Pausable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../ERC20.sol\";\nimport \"../../../security/Pausable.sol\";\n\n/**\n * @dev ERC20 token with pausable token transfers, minting and burning.\n *\n * Useful for scenarios such as preventing trades until the end of an evaluation\n * period, or having an emergency switch for freezing all token transfers in the\n * event of a large bug.\n *\n * IMPORTANT: This contract does not include public pause and unpause functions. In\n * addition to inheriting this contract, you must define both functions, invoking the\n * {Pausable-_pause} and {Pausable-_unpause} internal functions, with appropriate\n * access control, e.g. using {AccessControl} or {Ownable}. Not doing so will\n * make the contract unpausable.\n */\nabstract contract ERC20Pausable is ERC20, Pausable {\n /**\n * @dev See {ERC20-_beforeTokenTransfer}.\n *\n * Requirements:\n *\n * - the contract must not be paused.\n */\n function _beforeTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual override {\n super._beforeTokenTransfer(from, to, amount);\n\n require(!paused(), \"ERC20Pausable: token transfer while paused\");\n }\n}\n" + }, + "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20.sol\";\n\n/**\n * @dev Interface for the optional metadata functions from the ERC20 standard.\n *\n * _Available since v4.1._\n */\ninterface IERC20Metadata is IERC20 {\n /**\n * @dev Returns the name of the token.\n */\n function name() external view returns (string memory);\n\n /**\n * @dev Returns the symbol of the token.\n */\n function symbol() external view returns (string memory);\n\n /**\n * @dev Returns the decimals places of the token.\n */\n function decimals() external view returns (uint8);\n}\n" + }, + "@openzeppelin/contracts/token/ERC20/IERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n /**\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\n * another (`to`).\n *\n * Note that `value` may be zero.\n */\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n /**\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n * a call to {approve}. `value` is the new allowance.\n */\n event Approval(address indexed owner, address indexed spender, uint256 value);\n\n /**\n * @dev Returns the amount of tokens in existence.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns the amount of tokens owned by `account`.\n */\n function balanceOf(address account) external view returns (uint256);\n\n /**\n * @dev Moves `amount` tokens from the caller's account to `to`.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transfer(address to, uint256 amount) external returns (bool);\n\n /**\n * @dev Returns the remaining number of tokens that `spender` will be\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\n * zero by default.\n *\n * This value changes when {approve} or {transferFrom} are called.\n */\n function allowance(address owner, address spender) external view returns (uint256);\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\n * that someone may use both the old and the new allowance by unfortunate\n * transaction ordering. One possible solution to mitigate this race\n * condition is to first reduce the spender's allowance to 0 and set the\n * desired value afterwards:\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n *\n * Emits an {Approval} event.\n */\n function approve(address spender, uint256 amount) external returns (bool);\n\n /**\n * @dev Moves `amount` tokens from `from` to `to` using the\n * allowance mechanism. `amount` is then deducted from the caller's\n * allowance.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(\n address from,\n address to,\n uint256 amount\n ) external returns (bool);\n}\n" + }, + "@openzeppelin/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/presets/ERC20PresetMinterPauser.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../ERC20.sol\";\nimport \"../extensions/ERC20Burnable.sol\";\nimport \"../extensions/ERC20Pausable.sol\";\nimport \"../../../access/AccessControlEnumerable.sol\";\nimport \"../../../utils/Context.sol\";\n\n/**\n * @dev {ERC20} token, including:\n *\n * - ability for holders to burn (destroy) their tokens\n * - a minter role that allows for token minting (creation)\n * - a pauser role that allows to stop all token transfers\n *\n * This contract uses {AccessControl} to lock permissioned functions using the\n * different roles - head to its documentation for details.\n *\n * The account that deploys the contract will be granted the minter and pauser\n * roles, as well as the default admin role, which will let it grant both minter\n * and pauser roles to other accounts.\n *\n * _Deprecated in favor of https://wizard.openzeppelin.com/[Contracts Wizard]._\n */\ncontract ERC20PresetMinterPauser is Context, AccessControlEnumerable, ERC20Burnable, ERC20Pausable {\n bytes32 public constant MINTER_ROLE = keccak256(\"MINTER_ROLE\");\n bytes32 public constant PAUSER_ROLE = keccak256(\"PAUSER_ROLE\");\n\n /**\n * @dev Grants `DEFAULT_ADMIN_ROLE`, `MINTER_ROLE` and `PAUSER_ROLE` to the\n * account that deploys the contract.\n *\n * See {ERC20-constructor}.\n */\n constructor(string memory name, string memory symbol) ERC20(name, symbol) {\n _setupRole(DEFAULT_ADMIN_ROLE, _msgSender());\n\n _setupRole(MINTER_ROLE, _msgSender());\n _setupRole(PAUSER_ROLE, _msgSender());\n }\n\n /**\n * @dev Creates `amount` new tokens for `to`.\n *\n * See {ERC20-_mint}.\n *\n * Requirements:\n *\n * - the caller must have the `MINTER_ROLE`.\n */\n function mint(address to, uint256 amount) public virtual {\n require(hasRole(MINTER_ROLE, _msgSender()), \"ERC20PresetMinterPauser: must have minter role to mint\");\n _mint(to, amount);\n }\n\n /**\n * @dev Pauses all token transfers.\n *\n * See {ERC20Pausable} and {Pausable-_pause}.\n *\n * Requirements:\n *\n * - the caller must have the `PAUSER_ROLE`.\n */\n function pause() public virtual {\n require(hasRole(PAUSER_ROLE, _msgSender()), \"ERC20PresetMinterPauser: must have pauser role to pause\");\n _pause();\n }\n\n /**\n * @dev Unpauses all token transfers.\n *\n * See {ERC20Pausable} and {Pausable-_unpause}.\n *\n * Requirements:\n *\n * - the caller must have the `PAUSER_ROLE`.\n */\n function unpause() public virtual {\n require(hasRole(PAUSER_ROLE, _msgSender()), \"ERC20PresetMinterPauser: must have pauser role to unpause\");\n _unpause();\n }\n\n function _beforeTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual override(ERC20, ERC20Pausable) {\n super._beforeTokenTransfer(from, to, amount);\n }\n}\n" + }, + "@openzeppelin/contracts/utils/Context.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n}\n" + }, + "@openzeppelin/contracts/utils/introspection/ERC165.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC165.sol\";\n\n/**\n * @dev Implementation of the {IERC165} interface.\n *\n * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check\n * for the additional interface id that will be supported. For example:\n *\n * ```solidity\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\n * }\n * ```\n *\n * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.\n */\nabstract contract ERC165 is IERC165 {\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n return interfaceId == type(IERC165).interfaceId;\n }\n}\n" + }, + "@openzeppelin/contracts/utils/introspection/IERC165.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC165 standard, as defined in the\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\n *\n * Implementers can declare support of contract interfaces, which can then be\n * queried by others ({ERC165Checker}).\n *\n * For an implementation, see {ERC165}.\n */\ninterface IERC165 {\n /**\n * @dev Returns true if this contract implements the interface defined by\n * `interfaceId`. See the corresponding\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\n * to learn more about how these ids are created.\n *\n * This function call must use less than 30 000 gas.\n */\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n" + }, + "@openzeppelin/contracts/utils/math/Math.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Standard math utilities missing in the Solidity language.\n */\nlibrary Math {\n enum Rounding {\n Down, // Toward negative infinity\n Up, // Toward infinity\n Zero // Toward zero\n }\n\n /**\n * @dev Returns the largest of two numbers.\n */\n function max(uint256 a, uint256 b) internal pure returns (uint256) {\n return a > b ? a : b;\n }\n\n /**\n * @dev Returns the smallest of two numbers.\n */\n function min(uint256 a, uint256 b) internal pure returns (uint256) {\n return a < b ? a : b;\n }\n\n /**\n * @dev Returns the average of two numbers. The result is rounded towards\n * zero.\n */\n function average(uint256 a, uint256 b) internal pure returns (uint256) {\n // (a + b) / 2 can overflow.\n return (a & b) + (a ^ b) / 2;\n }\n\n /**\n * @dev Returns the ceiling of the division of two numbers.\n *\n * This differs from standard division with `/` in that it rounds up instead\n * of rounding down.\n */\n function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {\n // (a + b - 1) / b can overflow on addition, so we distribute.\n return a == 0 ? 0 : (a - 1) / b + 1;\n }\n\n /**\n * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0\n * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)\n * with further edits by Uniswap Labs also under MIT license.\n */\n function mulDiv(\n uint256 x,\n uint256 y,\n uint256 denominator\n ) internal pure returns (uint256 result) {\n unchecked {\n // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use\n // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256\n // variables such that product = prod1 * 2^256 + prod0.\n uint256 prod0; // Least significant 256 bits of the product\n uint256 prod1; // Most significant 256 bits of the product\n assembly {\n let mm := mulmod(x, y, not(0))\n prod0 := mul(x, y)\n prod1 := sub(sub(mm, prod0), lt(mm, prod0))\n }\n\n // Handle non-overflow cases, 256 by 256 division.\n if (prod1 == 0) {\n return prod0 / denominator;\n }\n\n // Make sure the result is less than 2^256. Also prevents denominator == 0.\n require(denominator > prod1);\n\n ///////////////////////////////////////////////\n // 512 by 256 division.\n ///////////////////////////////////////////////\n\n // Make division exact by subtracting the remainder from [prod1 prod0].\n uint256 remainder;\n assembly {\n // Compute remainder using mulmod.\n remainder := mulmod(x, y, denominator)\n\n // Subtract 256 bit number from 512 bit number.\n prod1 := sub(prod1, gt(remainder, prod0))\n prod0 := sub(prod0, remainder)\n }\n\n // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.\n // See https://cs.stackexchange.com/q/138556/92363.\n\n // Does not overflow because the denominator cannot be zero at this stage in the function.\n uint256 twos = denominator & (~denominator + 1);\n assembly {\n // Divide denominator by twos.\n denominator := div(denominator, twos)\n\n // Divide [prod1 prod0] by twos.\n prod0 := div(prod0, twos)\n\n // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.\n twos := add(div(sub(0, twos), twos), 1)\n }\n\n // Shift in bits from prod1 into prod0.\n prod0 |= prod1 * twos;\n\n // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such\n // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for\n // four bits. That is, denominator * inv = 1 mod 2^4.\n uint256 inverse = (3 * denominator) ^ 2;\n\n // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works\n // in modular arithmetic, doubling the correct bits in each step.\n inverse *= 2 - denominator * inverse; // inverse mod 2^8\n inverse *= 2 - denominator * inverse; // inverse mod 2^16\n inverse *= 2 - denominator * inverse; // inverse mod 2^32\n inverse *= 2 - denominator * inverse; // inverse mod 2^64\n inverse *= 2 - denominator * inverse; // inverse mod 2^128\n inverse *= 2 - denominator * inverse; // inverse mod 2^256\n\n // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.\n // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is\n // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1\n // is no longer required.\n result = prod0 * inverse;\n return result;\n }\n }\n\n /**\n * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.\n */\n function mulDiv(\n uint256 x,\n uint256 y,\n uint256 denominator,\n Rounding rounding\n ) internal pure returns (uint256) {\n uint256 result = mulDiv(x, y, denominator);\n if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {\n result += 1;\n }\n return result;\n }\n\n /**\n * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.\n *\n * Inspired by Henry S. Warren, Jr.'s \"Hacker's Delight\" (Chapter 11).\n */\n function sqrt(uint256 a) internal pure returns (uint256) {\n if (a == 0) {\n return 0;\n }\n\n // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.\n //\n // We know that the \"msb\" (most significant bit) of our target number `a` is a power of 2 such that we have\n // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.\n //\n // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`\n // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`\n // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`\n //\n // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.\n uint256 result = 1 << (log2(a) >> 1);\n\n // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,\n // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at\n // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision\n // into the expected uint128 result.\n unchecked {\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n return min(result, a / result);\n }\n }\n\n /**\n * @notice Calculates sqrt(a), following the selected rounding direction.\n */\n function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = sqrt(a);\n return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);\n }\n }\n\n /**\n * @dev Return the log in base 2, rounded down, of a positive value.\n * Returns 0 if given 0.\n */\n function log2(uint256 value) internal pure returns (uint256) {\n uint256 result = 0;\n unchecked {\n if (value >> 128 > 0) {\n value >>= 128;\n result += 128;\n }\n if (value >> 64 > 0) {\n value >>= 64;\n result += 64;\n }\n if (value >> 32 > 0) {\n value >>= 32;\n result += 32;\n }\n if (value >> 16 > 0) {\n value >>= 16;\n result += 16;\n }\n if (value >> 8 > 0) {\n value >>= 8;\n result += 8;\n }\n if (value >> 4 > 0) {\n value >>= 4;\n result += 4;\n }\n if (value >> 2 > 0) {\n value >>= 2;\n result += 2;\n }\n if (value >> 1 > 0) {\n result += 1;\n }\n }\n return result;\n }\n\n /**\n * @dev Return the log in base 2, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log2(value);\n return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);\n }\n }\n\n /**\n * @dev Return the log in base 10, rounded down, of a positive value.\n * Returns 0 if given 0.\n */\n function log10(uint256 value) internal pure returns (uint256) {\n uint256 result = 0;\n unchecked {\n if (value >= 10**64) {\n value /= 10**64;\n result += 64;\n }\n if (value >= 10**32) {\n value /= 10**32;\n result += 32;\n }\n if (value >= 10**16) {\n value /= 10**16;\n result += 16;\n }\n if (value >= 10**8) {\n value /= 10**8;\n result += 8;\n }\n if (value >= 10**4) {\n value /= 10**4;\n result += 4;\n }\n if (value >= 10**2) {\n value /= 10**2;\n result += 2;\n }\n if (value >= 10**1) {\n result += 1;\n }\n }\n return result;\n }\n\n /**\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log10(value);\n return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);\n }\n }\n\n /**\n * @dev Return the log in base 256, rounded down, of a positive value.\n * Returns 0 if given 0.\n *\n * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.\n */\n function log256(uint256 value) internal pure returns (uint256) {\n uint256 result = 0;\n unchecked {\n if (value >> 128 > 0) {\n value >>= 128;\n result += 16;\n }\n if (value >> 64 > 0) {\n value >>= 64;\n result += 8;\n }\n if (value >> 32 > 0) {\n value >>= 32;\n result += 4;\n }\n if (value >> 16 > 0) {\n value >>= 16;\n result += 2;\n }\n if (value >> 8 > 0) {\n result += 1;\n }\n }\n return result;\n }\n\n /**\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log256(value);\n return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);\n }\n }\n}\n" + }, + "@openzeppelin/contracts/utils/Strings.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./math/Math.sol\";\n\n/**\n * @dev String operations.\n */\nlibrary Strings {\n bytes16 private constant _SYMBOLS = \"0123456789abcdef\";\n uint8 private constant _ADDRESS_LENGTH = 20;\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` decimal representation.\n */\n function toString(uint256 value) internal pure returns (string memory) {\n unchecked {\n uint256 length = Math.log10(value) + 1;\n string memory buffer = new string(length);\n uint256 ptr;\n /// @solidity memory-safe-assembly\n assembly {\n ptr := add(buffer, add(32, length))\n }\n while (true) {\n ptr--;\n /// @solidity memory-safe-assembly\n assembly {\n mstore8(ptr, byte(mod(value, 10), _SYMBOLS))\n }\n value /= 10;\n if (value == 0) break;\n }\n return buffer;\n }\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\n */\n function toHexString(uint256 value) internal pure returns (string memory) {\n unchecked {\n return toHexString(value, Math.log256(value) + 1);\n }\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\n */\n function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\n bytes memory buffer = new bytes(2 * length + 2);\n buffer[0] = \"0\";\n buffer[1] = \"x\";\n for (uint256 i = 2 * length + 1; i > 1; --i) {\n buffer[i] = _SYMBOLS[value & 0xf];\n value >>= 4;\n }\n require(value == 0, \"Strings: hex length insufficient\");\n return string(buffer);\n }\n\n /**\n * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.\n */\n function toHexString(address addr) internal pure returns (string memory) {\n return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);\n }\n}\n" + }, + "@openzeppelin/contracts/utils/structs/EnumerableSet.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/structs/EnumerableSet.sol)\n// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Library for managing\n * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive\n * types.\n *\n * Sets have the following properties:\n *\n * - Elements are added, removed, and checked for existence in constant time\n * (O(1)).\n * - Elements are enumerated in O(n). No guarantees are made on the ordering.\n *\n * ```\n * contract Example {\n * // Add the library methods\n * using EnumerableSet for EnumerableSet.AddressSet;\n *\n * // Declare a set state variable\n * EnumerableSet.AddressSet private mySet;\n * }\n * ```\n *\n * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)\n * and `uint256` (`UintSet`) are supported.\n *\n * [WARNING]\n * ====\n * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure\n * unusable.\n * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.\n *\n * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an\n * array of EnumerableSet.\n * ====\n */\nlibrary EnumerableSet {\n // To implement this library for multiple types with as little code\n // repetition as possible, we write it in terms of a generic Set type with\n // bytes32 values.\n // The Set implementation uses private functions, and user-facing\n // implementations (such as AddressSet) are just wrappers around the\n // underlying Set.\n // This means that we can only create new EnumerableSets for types that fit\n // in bytes32.\n\n struct Set {\n // Storage of set values\n bytes32[] _values;\n // Position of the value in the `values` array, plus 1 because index 0\n // means a value is not in the set.\n mapping(bytes32 => uint256) _indexes;\n }\n\n /**\n * @dev Add a value to a set. O(1).\n *\n * Returns true if the value was added to the set, that is if it was not\n * already present.\n */\n function _add(Set storage set, bytes32 value) private returns (bool) {\n if (!_contains(set, value)) {\n set._values.push(value);\n // The value is stored at length-1, but we add 1 to all indexes\n // and use 0 as a sentinel value\n set._indexes[value] = set._values.length;\n return true;\n } else {\n return false;\n }\n }\n\n /**\n * @dev Removes a value from a set. O(1).\n *\n * Returns true if the value was removed from the set, that is if it was\n * present.\n */\n function _remove(Set storage set, bytes32 value) private returns (bool) {\n // We read and store the value's index to prevent multiple reads from the same storage slot\n uint256 valueIndex = set._indexes[value];\n\n if (valueIndex != 0) {\n // Equivalent to contains(set, value)\n // To delete an element from the _values array in O(1), we swap the element to delete with the last one in\n // the array, and then remove the last element (sometimes called as 'swap and pop').\n // This modifies the order of the array, as noted in {at}.\n\n uint256 toDeleteIndex = valueIndex - 1;\n uint256 lastIndex = set._values.length - 1;\n\n if (lastIndex != toDeleteIndex) {\n bytes32 lastValue = set._values[lastIndex];\n\n // Move the last value to the index where the value to delete is\n set._values[toDeleteIndex] = lastValue;\n // Update the index for the moved value\n set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex\n }\n\n // Delete the slot where the moved value was stored\n set._values.pop();\n\n // Delete the index for the deleted slot\n delete set._indexes[value];\n\n return true;\n } else {\n return false;\n }\n }\n\n /**\n * @dev Returns true if the value is in the set. O(1).\n */\n function _contains(Set storage set, bytes32 value) private view returns (bool) {\n return set._indexes[value] != 0;\n }\n\n /**\n * @dev Returns the number of values on the set. O(1).\n */\n function _length(Set storage set) private view returns (uint256) {\n return set._values.length;\n }\n\n /**\n * @dev Returns the value stored at position `index` in the set. O(1).\n *\n * Note that there are no guarantees on the ordering of values inside the\n * array, and it may change when more values are added or removed.\n *\n * Requirements:\n *\n * - `index` must be strictly less than {length}.\n */\n function _at(Set storage set, uint256 index) private view returns (bytes32) {\n return set._values[index];\n }\n\n /**\n * @dev Return the entire set in an array\n *\n * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n */\n function _values(Set storage set) private view returns (bytes32[] memory) {\n return set._values;\n }\n\n // Bytes32Set\n\n struct Bytes32Set {\n Set _inner;\n }\n\n /**\n * @dev Add a value to a set. O(1).\n *\n * Returns true if the value was added to the set, that is if it was not\n * already present.\n */\n function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {\n return _add(set._inner, value);\n }\n\n /**\n * @dev Removes a value from a set. O(1).\n *\n * Returns true if the value was removed from the set, that is if it was\n * present.\n */\n function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {\n return _remove(set._inner, value);\n }\n\n /**\n * @dev Returns true if the value is in the set. O(1).\n */\n function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {\n return _contains(set._inner, value);\n }\n\n /**\n * @dev Returns the number of values in the set. O(1).\n */\n function length(Bytes32Set storage set) internal view returns (uint256) {\n return _length(set._inner);\n }\n\n /**\n * @dev Returns the value stored at position `index` in the set. O(1).\n *\n * Note that there are no guarantees on the ordering of values inside the\n * array, and it may change when more values are added or removed.\n *\n * Requirements:\n *\n * - `index` must be strictly less than {length}.\n */\n function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {\n return _at(set._inner, index);\n }\n\n /**\n * @dev Return the entire set in an array\n *\n * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n */\n function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {\n bytes32[] memory store = _values(set._inner);\n bytes32[] memory result;\n\n /// @solidity memory-safe-assembly\n assembly {\n result := store\n }\n\n return result;\n }\n\n // AddressSet\n\n struct AddressSet {\n Set _inner;\n }\n\n /**\n * @dev Add a value to a set. O(1).\n *\n * Returns true if the value was added to the set, that is if it was not\n * already present.\n */\n function add(AddressSet storage set, address value) internal returns (bool) {\n return _add(set._inner, bytes32(uint256(uint160(value))));\n }\n\n /**\n * @dev Removes a value from a set. O(1).\n *\n * Returns true if the value was removed from the set, that is if it was\n * present.\n */\n function remove(AddressSet storage set, address value) internal returns (bool) {\n return _remove(set._inner, bytes32(uint256(uint160(value))));\n }\n\n /**\n * @dev Returns true if the value is in the set. O(1).\n */\n function contains(AddressSet storage set, address value) internal view returns (bool) {\n return _contains(set._inner, bytes32(uint256(uint160(value))));\n }\n\n /**\n * @dev Returns the number of values in the set. O(1).\n */\n function length(AddressSet storage set) internal view returns (uint256) {\n return _length(set._inner);\n }\n\n /**\n * @dev Returns the value stored at position `index` in the set. O(1).\n *\n * Note that there are no guarantees on the ordering of values inside the\n * array, and it may change when more values are added or removed.\n *\n * Requirements:\n *\n * - `index` must be strictly less than {length}.\n */\n function at(AddressSet storage set, uint256 index) internal view returns (address) {\n return address(uint160(uint256(_at(set._inner, index))));\n }\n\n /**\n * @dev Return the entire set in an array\n *\n * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n */\n function values(AddressSet storage set) internal view returns (address[] memory) {\n bytes32[] memory store = _values(set._inner);\n address[] memory result;\n\n /// @solidity memory-safe-assembly\n assembly {\n result := store\n }\n\n return result;\n }\n\n // UintSet\n\n struct UintSet {\n Set _inner;\n }\n\n /**\n * @dev Add a value to a set. O(1).\n *\n * Returns true if the value was added to the set, that is if it was not\n * already present.\n */\n function add(UintSet storage set, uint256 value) internal returns (bool) {\n return _add(set._inner, bytes32(value));\n }\n\n /**\n * @dev Removes a value from a set. O(1).\n *\n * Returns true if the value was removed from the set, that is if it was\n * present.\n */\n function remove(UintSet storage set, uint256 value) internal returns (bool) {\n return _remove(set._inner, bytes32(value));\n }\n\n /**\n * @dev Returns true if the value is in the set. O(1).\n */\n function contains(UintSet storage set, uint256 value) internal view returns (bool) {\n return _contains(set._inner, bytes32(value));\n }\n\n /**\n * @dev Returns the number of values in the set. O(1).\n */\n function length(UintSet storage set) internal view returns (uint256) {\n return _length(set._inner);\n }\n\n /**\n * @dev Returns the value stored at position `index` in the set. O(1).\n *\n * Note that there are no guarantees on the ordering of values inside the\n * array, and it may change when more values are added or removed.\n *\n * Requirements:\n *\n * - `index` must be strictly less than {length}.\n */\n function at(UintSet storage set, uint256 index) internal view returns (uint256) {\n return uint256(_at(set._inner, index));\n }\n\n /**\n * @dev Return the entire set in an array\n *\n * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n */\n function values(UintSet storage set) internal view returns (uint256[] memory) {\n bytes32[] memory store = _values(set._inner);\n uint256[] memory result;\n\n /// @solidity memory-safe-assembly\n assembly {\n result := store\n }\n\n return result;\n }\n}\n" + }, + "src/interface/IPostageStamp.sol": { + "content": "// SPDX-License-Identifier: BSD-3-Clause\npragma solidity ^0.8.19;\n\ninterface IPostageStamp {\n function withdraw(address beneficiary) external;\n\n function setPrice(uint256 _price) external;\n\n function validChunkCount() external view returns (uint256);\n\n function batchOwner(bytes32 _batchId) external view returns (address);\n\n function batchDepth(bytes32 _batchId) external view returns (uint8);\n\n function batchBucketDepth(bytes32 _batchId) external view returns (uint8);\n\n function remainingBalance(bytes32 _batchId) external view returns (uint256);\n\n function minimumInitialBalancePerChunk() external view returns (uint256);\n\n function batches(\n bytes32\n )\n external\n view\n returns (\n address owner,\n uint8 depth,\n uint8 bucketDepth,\n bool immutableFlag,\n uint256 normalisedBalance,\n uint256 lastUpdatedBlockNumber\n );\n}\n" + }, + "src/OrderStatisticsTree/HitchensOrderStatisticsTreeLib.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\n/*\nHitchens Order Statistics Tree v0.99\n\nA Solidity Red-Black Tree library to store and maintain a sorted data\nstructure in a Red-Black binary search tree, with O(log 2n) insert, remove\nand search time (and gas, approximately)\n\nhttps://github.com/rob-Hitchens/OrderStatisticsTree\n\nCopyright (c) Rob Hitchens. the MIT License\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\nSignificant portions from BokkyPooBahsRedBlackTreeLibrary,\nhttps://github.com/bokkypoobah/BokkyPooBahsRedBlackTreeLibrary\n\nTHIS SOFTWARE IS NOT TESTED OR AUDITED. DO NOT USE FOR PRODUCTION.\n*/\n\nlibrary HitchensOrderStatisticsTreeLib {\n uint private constant EMPTY = 0;\n struct Node {\n uint parent;\n uint left;\n uint right;\n bool red;\n bytes32[] keys;\n mapping(bytes32 => uint) keyMap;\n uint count;\n }\n struct Tree {\n uint root;\n mapping(uint => Node) nodes;\n }\n\n error ValueDoesNotExist(); // Provided value doesn't exist in the tree.\n error ValueCannotBeZero(); // Value to insert cannot be zero\n error ValueKeyPairExists(); // Value and Key pair exists. Cannot be inserted again.\n\n function first(Tree storage self) internal view returns (uint _value) {\n _value = self.root;\n if (_value == EMPTY) return 0;\n while (self.nodes[_value].left != EMPTY) {\n _value = self.nodes[_value].left;\n }\n }\n\n function exists(Tree storage self, uint value) internal view returns (bool _exists) {\n if (value == EMPTY) return false;\n if (value == self.root) return true;\n if (self.nodes[value].parent != EMPTY) return true;\n return false;\n }\n\n function keyExists(Tree storage self, bytes32 key, uint value) internal view returns (bool _exists) {\n if (!exists(self, value)) return false;\n return self.nodes[value].keys[self.nodes[value].keyMap[key]] == key;\n }\n\n function getNode(\n Tree storage self,\n uint value\n ) internal view returns (uint _parent, uint _left, uint _right, bool _red, uint keyCount, uint __count) {\n if (!exists(self, value)) {\n revert ValueDoesNotExist();\n }\n\n Node storage gn = self.nodes[value];\n return (gn.parent, gn.left, gn.right, gn.red, gn.keys.length, gn.keys.length + gn.count);\n }\n\n function getNodeCount(Tree storage self, uint value) internal view returns (uint __count) {\n Node storage gn = self.nodes[value];\n return gn.keys.length + gn.count;\n }\n\n function valueKeyAtIndex(Tree storage self, uint value, uint index) internal view returns (bytes32 _key) {\n if (!exists(self, value)) {\n revert ValueDoesNotExist();\n }\n return self.nodes[value].keys[index];\n }\n\n function count(Tree storage self) internal view returns (uint _count) {\n return getNodeCount(self, self.root);\n }\n\n /* We don't use this functionality, so it is commented out to make audit easier\n\n function percentile(Tree storage self, uint value) internal view returns(uint _percentile) {\n uint denominator = count(self);\n uint numerator = rank(self, value);\n _percentile = ((uint(1000) * numerator)/denominator+(uint(5)))/uint(10);\n }\n function permil(Tree storage self, uint value) internal view returns(uint _permil) {\n uint denominator = count(self);\n uint numerator = rank(self, value);\n _permil = ((uint(10000) * numerator)/denominator+(uint(5)))/uint(10);\n }\n function atPercentile(Tree storage self, uint _percentile) internal view returns(uint _value) {\n uint findRank = (((_percentile * count(self))/uint(10)) + uint(5)) / uint(10);\n return atRank(self,findRank);\n }\n function atPermil(Tree storage self, uint _permil) internal view returns(uint _value) {\n uint findRank = (((_permil * count(self))/uint(100)) + uint(5)) / uint(10);\n return atRank(self,findRank);\n }\n function median(Tree storage self) internal view returns(uint value) {\n return atPercentile(self,50);\n }\n function below(Tree storage self, uint value) public view returns(uint _below) {\n if(count(self) > 0 && value > 0) _below = rank(self,value)-uint(1);\n }\n function above(Tree storage self, uint value) public view returns(uint _above) {\n if(count(self) > 0) _above = count(self)-rank(self,value);\n }\n function valueBelowEstimate(Tree storage self, uint estimate) public view returns(uint _below) {\n if(count(self) > 0 && estimate > 0) {\n uint highestValue = last(self);\n uint lowestValue = first(self);\n if(estimate < lowestValue) {\n return 0;\n }\n if(estimate >= highestValue) {\n return highestValue;\n }\n uint rankOfValue = rank(self, estimate); // approximation\n _below = atRank(self, rankOfValue);\n if(_below > estimate) { // fix error in approximation\n rankOfValue--;\n _below = atRank(self, rankOfValue);\n }\n }\n }\n function valueAboveEstimate(Tree storage self, uint estimate) public view returns(uint _above) {\n if(count(self) > 0 && estimate > 0) {\n uint highestValue = last(self);\n uint lowestValue = first(self);\n if(estimate > highestValue) {\n return 0;\n }\n if(estimate <= lowestValue) {\n return lowestValue;\n }\n uint rankOfValue = rank(self, estimate); // approximation\n _above = atRank(self, rankOfValue);\n if(_above < estimate) { // fix error in approximation\n rankOfValue++;\n _above = atRank(self, rankOfValue);\n }\n }\n }\n function rank(Tree storage self, uint value) internal view returns(uint _rank) {\n if(count(self) > 0) {\n bool finished;\n uint cursor = self.root;\n Node storage c = self.nodes[cursor];\n uint smaller = getNodeCount(self,c.left);\n while (!finished) {\n uint keyCount = c.keys.length;\n if(cursor == value) {\n finished = true;\n } else {\n if(cursor < value) {\n cursor = c.right;\n c = self.nodes[cursor];\n smaller += keyCount + getNodeCount(self,c.left);\n } else {\n cursor = c.left;\n c = self.nodes[cursor];\n smaller -= (keyCount + getNodeCount(self,c.right));\n }\n }\n if (!exists(self,cursor)) {\n finished = true;\n }\n }\n return smaller + 1;\n }\n }\n function atRank(Tree storage self, uint _rank) internal view returns(uint _value) {\n bool finished;\n uint cursor = self.root;\n Node storage c = self.nodes[cursor];\n uint smaller = getNodeCount(self,c.left);\n while (!finished) {\n _value = cursor;\n c = self.nodes[cursor];\n uint keyCount = c.keys.length;\n if(smaller + 1 >= _rank && smaller + keyCount <= _rank) {\n _value = cursor;\n finished = true;\n } else {\n if(smaller + keyCount <= _rank) {\n cursor = c.right;\n c = self.nodes[cursor];\n smaller += keyCount + getNodeCount(self,c.left);\n } else {\n cursor = c.left;\n c = self.nodes[cursor];\n smaller -= (keyCount + getNodeCount(self,c.right));\n }\n }\n if (!exists(self,cursor)) {\n finished = true;\n }\n }\n }\n*/\n\n function insert(Tree storage self, bytes32 key, uint value) internal {\n if (value == EMPTY) {\n revert ValueCannotBeZero();\n }\n if (keyExists(self, key, value)) {\n revert ValueKeyPairExists();\n }\n uint cursor;\n uint probe = self.root;\n while (probe != EMPTY) {\n cursor = probe;\n if (value < probe) {\n probe = self.nodes[probe].left;\n } else if (value > probe) {\n probe = self.nodes[probe].right;\n } else if (value == probe) {\n self.nodes[probe].keys.push(key);\n self.nodes[probe].keyMap[key] = self.nodes[probe].keys.length - uint(1);\n return;\n }\n self.nodes[cursor].count++;\n }\n Node storage nValue = self.nodes[value];\n nValue.parent = cursor;\n nValue.left = EMPTY;\n nValue.right = EMPTY;\n nValue.red = true;\n nValue.keys.push(key);\n nValue.keyMap[key] = nValue.keys.length - uint(1);\n if (cursor == EMPTY) {\n self.root = value;\n } else if (value < cursor) {\n self.nodes[cursor].left = value;\n } else {\n self.nodes[cursor].right = value;\n }\n insertFixup(self, value);\n }\n\n function remove(Tree storage self, bytes32 key, uint value) internal {\n if (value == EMPTY) {\n revert ValueCannotBeZero();\n }\n if (!keyExists(self, key, value)) {\n revert ValueDoesNotExist();\n }\n\n Node storage nValue = self.nodes[value];\n uint rowToDelete = nValue.keyMap[key];\n bytes32 last = nValue.keys[nValue.keys.length - uint(1)];\n nValue.keys[rowToDelete] = last;\n nValue.keyMap[last] = rowToDelete;\n nValue.keys.pop();\n\n uint probe;\n uint cursor;\n\n if (nValue.keys.length == 0) {\n if (self.nodes[value].left == EMPTY || self.nodes[value].right == EMPTY) {\n cursor = value;\n } else {\n cursor = self.nodes[value].right;\n while (self.nodes[cursor].left != EMPTY) {\n cursor = self.nodes[cursor].left;\n }\n }\n\n if (self.nodes[cursor].left != EMPTY) {\n probe = self.nodes[cursor].left;\n } else {\n probe = self.nodes[cursor].right;\n }\n\n uint cursorParent = self.nodes[cursor].parent;\n self.nodes[probe].parent = cursorParent;\n\n if (cursorParent != EMPTY) {\n if (cursor == self.nodes[cursorParent].left) {\n self.nodes[cursorParent].left = probe;\n } else {\n self.nodes[cursorParent].right = probe;\n }\n } else {\n self.root = probe;\n }\n\n bool doFixup = !self.nodes[cursor].red;\n\n if (cursor != value) {\n replaceParent(self, cursor, value);\n self.nodes[cursor].left = self.nodes[value].left;\n self.nodes[self.nodes[cursor].left].parent = cursor;\n self.nodes[cursor].right = self.nodes[value].right;\n self.nodes[self.nodes[cursor].right].parent = cursor;\n self.nodes[cursor].red = self.nodes[value].red;\n (cursor, value) = (value, cursor);\n fixCountRecurse(self, value);\n }\n\n if (doFixup) {\n removeFixup(self, probe);\n }\n\n fixCountRecurse(self, cursorParent);\n delete self.nodes[cursor];\n }\n }\n\n function fixCountRecurse(Tree storage self, uint value) private {\n while (value != EMPTY) {\n self.nodes[value].count =\n getNodeCount(self, self.nodes[value].left) +\n getNodeCount(self, self.nodes[value].right);\n value = self.nodes[value].parent;\n }\n }\n\n function treeMinimum(Tree storage self, uint value) private view returns (uint) {\n while (self.nodes[value].left != EMPTY) {\n value = self.nodes[value].left;\n }\n return value;\n }\n\n function treeMaximum(Tree storage self, uint value) private view returns (uint) {\n while (self.nodes[value].right != EMPTY) {\n value = self.nodes[value].right;\n }\n return value;\n }\n\n function rotateLeft(Tree storage self, uint value) private {\n uint cursor = self.nodes[value].right;\n uint parent = self.nodes[value].parent;\n uint cursorLeft = self.nodes[cursor].left;\n self.nodes[value].right = cursorLeft;\n if (cursorLeft != EMPTY) {\n self.nodes[cursorLeft].parent = value;\n }\n self.nodes[cursor].parent = parent;\n if (parent == EMPTY) {\n self.root = cursor;\n } else if (value == self.nodes[parent].left) {\n self.nodes[parent].left = cursor;\n } else {\n self.nodes[parent].right = cursor;\n }\n self.nodes[cursor].left = value;\n self.nodes[value].parent = cursor;\n self.nodes[value].count =\n getNodeCount(self, self.nodes[value].left) +\n getNodeCount(self, self.nodes[value].right);\n self.nodes[cursor].count =\n getNodeCount(self, self.nodes[cursor].left) +\n getNodeCount(self, self.nodes[cursor].right);\n }\n\n function rotateRight(Tree storage self, uint value) private {\n uint cursor = self.nodes[value].left;\n uint parent = self.nodes[value].parent;\n uint cursorRight = self.nodes[cursor].right;\n self.nodes[value].left = cursorRight;\n if (cursorRight != EMPTY) {\n self.nodes[cursorRight].parent = value;\n }\n self.nodes[cursor].parent = parent;\n if (parent == EMPTY) {\n self.root = cursor;\n } else if (value == self.nodes[parent].right) {\n self.nodes[parent].right = cursor;\n } else {\n self.nodes[parent].left = cursor;\n }\n self.nodes[cursor].right = value;\n self.nodes[value].parent = cursor;\n self.nodes[value].count =\n getNodeCount(self, self.nodes[value].left) +\n getNodeCount(self, self.nodes[value].right);\n self.nodes[cursor].count =\n getNodeCount(self, self.nodes[cursor].left) +\n getNodeCount(self, self.nodes[cursor].right);\n }\n\n function insertFixup(Tree storage self, uint value) private {\n uint cursor;\n while (value != self.root && self.nodes[self.nodes[value].parent].red) {\n uint valueParent = self.nodes[value].parent;\n if (valueParent == self.nodes[self.nodes[valueParent].parent].left) {\n cursor = self.nodes[self.nodes[valueParent].parent].right;\n if (self.nodes[cursor].red) {\n self.nodes[valueParent].red = false;\n self.nodes[cursor].red = false;\n self.nodes[self.nodes[valueParent].parent].red = true;\n value = self.nodes[valueParent].parent;\n } else {\n if (value == self.nodes[valueParent].right) {\n value = valueParent;\n rotateLeft(self, value);\n }\n valueParent = self.nodes[value].parent;\n self.nodes[valueParent].red = false;\n self.nodes[self.nodes[valueParent].parent].red = true;\n rotateRight(self, self.nodes[valueParent].parent);\n }\n } else {\n cursor = self.nodes[self.nodes[valueParent].parent].left;\n if (self.nodes[cursor].red) {\n self.nodes[valueParent].red = false;\n self.nodes[cursor].red = false;\n self.nodes[self.nodes[valueParent].parent].red = true;\n value = self.nodes[valueParent].parent;\n } else {\n if (value == self.nodes[valueParent].left) {\n value = valueParent;\n rotateRight(self, value);\n }\n valueParent = self.nodes[value].parent;\n self.nodes[valueParent].red = false;\n self.nodes[self.nodes[valueParent].parent].red = true;\n rotateLeft(self, self.nodes[valueParent].parent);\n }\n }\n }\n self.nodes[self.root].red = false;\n }\n\n function replaceParent(Tree storage self, uint a, uint b) private {\n uint bParent = self.nodes[b].parent;\n self.nodes[a].parent = bParent;\n if (bParent == EMPTY) {\n self.root = a;\n } else {\n if (b == self.nodes[bParent].left) {\n self.nodes[bParent].left = a;\n } else {\n self.nodes[bParent].right = a;\n }\n }\n }\n\n function removeFixup(Tree storage self, uint value) private {\n uint cursor;\n while (value != self.root && !self.nodes[value].red) {\n uint valueParent = self.nodes[value].parent;\n if (value == self.nodes[valueParent].left) {\n cursor = self.nodes[valueParent].right;\n if (self.nodes[cursor].red) {\n self.nodes[cursor].red = false;\n self.nodes[valueParent].red = true;\n rotateLeft(self, valueParent);\n cursor = self.nodes[valueParent].right;\n }\n if (!self.nodes[self.nodes[cursor].left].red && !self.nodes[self.nodes[cursor].right].red) {\n self.nodes[cursor].red = true;\n value = valueParent;\n } else {\n if (!self.nodes[self.nodes[cursor].right].red) {\n self.nodes[self.nodes[cursor].left].red = false;\n self.nodes[cursor].red = true;\n rotateRight(self, cursor);\n cursor = self.nodes[valueParent].right;\n }\n self.nodes[cursor].red = self.nodes[valueParent].red;\n self.nodes[valueParent].red = false;\n self.nodes[self.nodes[cursor].right].red = false;\n rotateLeft(self, valueParent);\n value = self.root;\n }\n } else {\n cursor = self.nodes[valueParent].left;\n if (self.nodes[cursor].red) {\n self.nodes[cursor].red = false;\n self.nodes[valueParent].red = true;\n rotateRight(self, valueParent);\n cursor = self.nodes[valueParent].left;\n }\n if (!self.nodes[self.nodes[cursor].right].red && !self.nodes[self.nodes[cursor].left].red) {\n self.nodes[cursor].red = true;\n value = valueParent;\n } else {\n if (!self.nodes[self.nodes[cursor].left].red) {\n self.nodes[self.nodes[cursor].right].red = false;\n self.nodes[cursor].red = true;\n rotateLeft(self, cursor);\n cursor = self.nodes[valueParent].left;\n }\n self.nodes[cursor].red = self.nodes[valueParent].red;\n self.nodes[valueParent].red = false;\n self.nodes[self.nodes[cursor].left].red = false;\n rotateRight(self, valueParent);\n value = self.root;\n }\n }\n }\n self.nodes[value].red = false;\n }\n}\n" + }, + "src/PostageStamp.sol": { + "content": "// SPDX-License-Identifier: BSD-3-Clause\npragma solidity ^0.8.19;\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"@openzeppelin/contracts/security/Pausable.sol\";\nimport \"./OrderStatisticsTree/HitchensOrderStatisticsTreeLib.sol\";\n\n/**\n * @title PostageStamp contract\n * @author The Swarm Authors\n * @dev The postage stamp contracts allows users to create and manage postage stamp batches.\n * The current balance for each batch is stored ordered in descending order of normalised balance.\n * Balance is normalised to be per chunk and the total spend since the contract was deployed, i.e. when a batch\n * is bought, its per-chunk balance is supplemented with the current cost of storing one chunk since the beginning of time,\n * as if the batch had existed since the contract's inception. During the _expiry_ process, each of these balances is\n * checked against the _currentTotalOutPayment_, a similarly normalised figure that represents the current cost of\n * storing one chunk since the beginning of time. A batch with a normalised balance less than _currentTotalOutPayment_\n * is treated as expired.\n *\n * The _currentTotalOutPayment_ is calculated using _totalOutPayment_ which is updated during _setPrice_ events so\n * that the applicable per-chunk prices can be charged for the relevant periods of time. This can then be multiplied\n * by the amount of chunks which are allowed to be stamped by each batch to get the actual cost of storage.\n *\n * The amount of chunks a batch can stamp is determined by the _bucketDepth_. A batch may store a maximum of 2^depth chunks.\n * The global figure for the currently allowed chunks is tracked by _validChunkCount_ and updated during batch _expiry_ events.\n */\n\ncontract PostageStamp is AccessControl, Pausable {\n using HitchensOrderStatisticsTreeLib for HitchensOrderStatisticsTreeLib.Tree;\n\n // ----------------------------- State variables ------------------------------\n\n // Address of the ERC20 token this contract references.\n address public bzzToken;\n\n // Minimum allowed depth of bucket.\n uint8 public minimumBucketDepth;\n\n // Role allowed to increase totalOutPayment.\n bytes32 public immutable PRICE_ORACLE_ROLE;\n\n // Role allowed to pause\n bytes32 public immutable PAUSER_ROLE;\n // Role allowed to withdraw the pot.\n bytes32 public immutable REDISTRIBUTOR_ROLE;\n\n // Associate every batch id with batch data.\n mapping(bytes32 => Batch) public batches;\n // Store every batch id ordered by normalisedBalance.\n HitchensOrderStatisticsTreeLib.Tree tree;\n\n // Total out payment per chunk, at the blockheight of the last price change.\n uint256 private totalOutPayment;\n\n // Combined global chunk capacity of valid batches remaining at the blockheight expire() was last called.\n uint256 public validChunkCount;\n\n // Lottery pot at last update.\n uint256 public pot;\n\n // Normalised balance at the blockheight expire() was last called.\n uint256 public lastExpiryBalance;\n\n // Price from the last update.\n uint64 public lastPrice;\n\n // blocks in 24 hours ~ 24 * 60 * 60 / 5 = 17280\n uint64 public minimumValidityBlocks = 17280;\n\n // Block at which the last update occured.\n uint64 public lastUpdatedBlock;\n\n // ----------------------------- Type declarations ------------------------------\n\n struct Batch {\n // Owner of this batch (0 if not valid).\n address owner;\n // Current depth of this batch.\n uint8 depth;\n // Bucket depth defined in this batch\n uint8 bucketDepth;\n // Whether this batch is immutable.\n bool immutableFlag;\n // Normalised balance per chunk.\n uint256 normalisedBalance;\n // When was this batch last updated\n uint256 lastUpdatedBlockNumber;\n }\n\n struct ImportBatch {\n bytes32 batchId;\n address owner;\n uint8 depth;\n uint8 bucketDepth;\n bool immutableFlag;\n uint256 remainingBalance;\n }\n\n // ----------------------------- Events ------------------------------\n\n /**\n * @dev Emitted when a new batch is created.\n */\n event BatchCreated(\n bytes32 indexed batchId,\n uint256 totalAmount,\n uint256 normalisedBalance,\n address owner,\n uint8 depth,\n uint8 bucketDepth,\n bool immutableFlag\n );\n\n /**\n * @dev Emitted when an pot is Withdrawn.\n */\n event PotWithdrawn(address recipient, uint256 totalAmount);\n\n /**\n * @dev Emitted when an existing batch is topped up.\n */\n event BatchTopUp(bytes32 indexed batchId, uint256 topupAmount, uint256 normalisedBalance);\n\n /**\n * @dev Emitted when the depth of an existing batch increases.\n */\n event BatchDepthIncrease(bytes32 indexed batchId, uint8 newDepth, uint256 normalisedBalance);\n\n /**\n *@dev Emitted on every price update.\n */\n event PriceUpdate(uint256 price);\n\n /**\n *@dev Emitted on every batch failed in bulk batch creation\n */\n event CopyBatchFailed(uint index, bytes32 batchId);\n\n // ----------------------------- Errors ------------------------------\n\n error ZeroAddress(); // Owner cannot be the zero address\n error InvalidDepth(); // Invalid bucket depth\n error BatchExists(); // Batch already exists\n error InsufficientBalance(); // Insufficient initial balance for 24h minimum validity\n error TransferFailed(); // Failed transfer of BZZ tokens\n error ZeroBalance(); // NormalisedBalance cannot be zero\n error AdministratorOnly(); // Only administrator can use copy method\n error BatchDoesNotExist(); // Batch does not exist or has expired\n error BatchExpired(); // Batch already expired\n error BatchTooSmall(); // Batch too small to renew\n error NotBatchOwner(); // Not batch owner\n error DepthNotIncreasing(); // Depth not increasing\n error PriceOracleOnly(); // Only price oracle can set the price\n error InsufficienChunkCount(); // Insufficient valid chunk count\n error TotalOutpaymentDecreased(); // Current total outpayment should never decrease\n error NoBatchesExist(); // There are no batches\n error OnlyPauser(); // Only Pauser role can pause or unpause contracts\n error OnlyRedistributor(); // Only redistributor role can withdraw from the contract\n\n // ----------------------------- CONSTRUCTOR ------------------------------\n\n /**\n * @param _bzzToken The ERC20 token address to reference in this contract.\n * @param _minimumBucketDepth The minimum bucket depth of batches that can be purchased.\n */\n constructor(address _bzzToken, uint8 _minimumBucketDepth) {\n bzzToken = _bzzToken;\n minimumBucketDepth = _minimumBucketDepth;\n PRICE_ORACLE_ROLE = keccak256(\"PRICE_ORACLE_ROLE\");\n PAUSER_ROLE = keccak256(\"PAUSER_ROLE\");\n REDISTRIBUTOR_ROLE = keccak256(\"REDISTRIBUTOR_ROLE\");\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n _setupRole(PAUSER_ROLE, msg.sender);\n }\n\n ////////////////////////////////////////\n // STATE CHANGING //\n ////////////////////////////////////////\n\n /**\n * @notice Create a new batch.\n * @dev At least `_initialBalancePerChunk*2^depth` tokens must be approved in the ERC20 token contract.\n * @param _owner Owner of the new batch.\n * @param _initialBalancePerChunk Initial balance per chunk.\n * @param _depth Initial depth of the new batch.\n * @param _nonce A random value used in the batch id derivation to allow multiple batches per owner.\n * @param _immutable Whether the batch is mutable.\n */\n function createBatch(\n address _owner,\n uint256 _initialBalancePerChunk,\n uint8 _depth,\n uint8 _bucketDepth,\n bytes32 _nonce,\n bool _immutable\n ) external whenNotPaused returns (bytes32) {\n if (_owner == address(0)) {\n revert ZeroAddress();\n }\n\n if (_bucketDepth == 0 || _bucketDepth < minimumBucketDepth || _bucketDepth >= _depth) {\n revert InvalidDepth();\n }\n\n bytes32 batchId = keccak256(abi.encode(msg.sender, _nonce));\n if (batches[batchId].owner != address(0)) {\n revert BatchExists();\n }\n\n if (_initialBalancePerChunk < minimumInitialBalancePerChunk()) {\n revert InsufficientBalance();\n }\n\n uint256 totalAmount = _initialBalancePerChunk * (1 << _depth);\n if (!ERC20(bzzToken).transferFrom(msg.sender, address(this), totalAmount)) {\n revert TransferFailed();\n }\n\n uint256 normalisedBalance = currentTotalOutPayment() + (_initialBalancePerChunk);\n if (normalisedBalance == 0) {\n revert ZeroBalance();\n }\n\n expireLimited(type(uint256).max);\n validChunkCount += 1 << _depth;\n\n batches[batchId] = Batch({\n owner: _owner,\n depth: _depth,\n bucketDepth: _bucketDepth,\n immutableFlag: _immutable,\n normalisedBalance: normalisedBalance,\n lastUpdatedBlockNumber: block.number\n });\n\n tree.insert(batchId, normalisedBalance);\n\n emit BatchCreated(batchId, totalAmount, normalisedBalance, _owner, _depth, _bucketDepth, _immutable);\n\n return batchId;\n }\n\n /**\n * @notice Manually create a new batch when facilitating migration, can only be called by the Admin role.\n * @dev At least `_initialBalancePerChunk*2^depth` tokens must be approved in the ERC20 token contract.\n * @param _owner Owner of the new batch.\n * @param _initialBalancePerChunk Initial balance per chunk of the batch.\n * @param _depth Initial depth of the new batch.\n * @param _batchId BatchId being copied (from previous version contract data).\n * @param _immutable Whether the batch is mutable.\n */\n function copyBatch(\n address _owner,\n uint256 _initialBalancePerChunk,\n uint8 _depth,\n uint8 _bucketDepth,\n bytes32 _batchId,\n bool _immutable\n ) public whenNotPaused {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert AdministratorOnly();\n }\n\n if (_owner == address(0)) {\n revert ZeroAddress();\n }\n\n if (_bucketDepth == 0 || _bucketDepth >= _depth) {\n revert InvalidDepth();\n }\n\n if (batches[_batchId].owner != address(0)) {\n revert BatchExists();\n }\n\n uint256 totalAmount = _initialBalancePerChunk * (1 << _depth);\n uint256 normalisedBalance = currentTotalOutPayment() + (_initialBalancePerChunk);\n if (normalisedBalance == 0) {\n revert ZeroBalance();\n }\n\n //update validChunkCount to remove currently expired batches\n expireLimited(type(uint256).max);\n\n validChunkCount += 1 << _depth;\n\n batches[_batchId] = Batch({\n owner: _owner,\n depth: _depth,\n bucketDepth: _bucketDepth,\n immutableFlag: _immutable,\n normalisedBalance: normalisedBalance,\n lastUpdatedBlockNumber: block.number\n });\n\n tree.insert(_batchId, normalisedBalance);\n\n emit BatchCreated(_batchId, totalAmount, normalisedBalance, _owner, _depth, _bucketDepth, _immutable);\n }\n\n /**\n * @notice Import batches in bulk\n * @dev Import batches in bulk to lower the number of transactions needed,\n * @dev becase of block limitations 90 batches per trx is ceiling, 60 to 70 sweetspot\n * @param bulkBatches array of batches\n */\n function copyBatchBulk(ImportBatch[] calldata bulkBatches) external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert AdministratorOnly();\n }\n for (uint i = 0; i < bulkBatches.length; i++) {\n ImportBatch memory _batch = bulkBatches[i];\n try\n this.copyBatch(\n _batch.owner,\n _batch.remainingBalance,\n _batch.depth,\n _batch.bucketDepth,\n _batch.batchId,\n _batch.immutableFlag\n )\n {\n // Successful copyBatch call\n } catch {\n // copyBatch failed, handle error\n emit CopyBatchFailed(i, _batch.batchId);\n }\n }\n }\n\n /**\n * @notice Top up an existing batch.\n * @dev At least `_topupAmountPerChunk*2^depth` tokens must be approved in the ERC20 token contract.\n * @param _batchId The id of an existing batch.\n * @param _topupAmountPerChunk The amount of additional tokens to add per chunk.\n */\n function topUp(bytes32 _batchId, uint256 _topupAmountPerChunk) external whenNotPaused {\n Batch memory batch = batches[_batchId];\n\n if (batch.owner == address(0)) {\n revert BatchDoesNotExist();\n }\n\n if (batch.normalisedBalance <= currentTotalOutPayment()) {\n revert BatchExpired();\n }\n\n if (batch.depth <= minimumBucketDepth) {\n revert BatchTooSmall();\n }\n\n if (remainingBalance(_batchId) + (_topupAmountPerChunk) < minimumInitialBalancePerChunk()) {\n revert InsufficientBalance();\n }\n\n // per chunk balance multiplied by the batch size in chunks must be transferred from the sender\n uint256 totalAmount = _topupAmountPerChunk * (1 << batch.depth);\n if (!ERC20(bzzToken).transferFrom(msg.sender, address(this), totalAmount)) {\n revert TransferFailed();\n }\n\n // update by removing batch and then reinserting\n tree.remove(_batchId, batch.normalisedBalance);\n batch.normalisedBalance = batch.normalisedBalance + (_topupAmountPerChunk);\n tree.insert(_batchId, batch.normalisedBalance);\n\n batches[_batchId].normalisedBalance = batch.normalisedBalance;\n emit BatchTopUp(_batchId, totalAmount, batch.normalisedBalance);\n }\n\n /**\n * @notice Increase the depth of an existing batch.\n * @dev Can only be called by the owner of the batch.\n * @param _batchId the id of an existing batch.\n * @param _newDepth the new (larger than the previous one) depth for this batch.\n */\n function increaseDepth(bytes32 _batchId, uint8 _newDepth) external whenNotPaused {\n Batch memory batch = batches[_batchId];\n\n if (batch.owner != msg.sender) {\n revert NotBatchOwner();\n }\n\n if (!(minimumBucketDepth < _newDepth && batch.depth < _newDepth)) {\n revert DepthNotIncreasing();\n }\n\n if (batch.normalisedBalance <= currentTotalOutPayment()) {\n revert BatchExpired();\n }\n\n uint8 depthChange = _newDepth - batch.depth;\n uint256 newRemainingBalance = remainingBalance(_batchId) / (1 << depthChange);\n\n if (newRemainingBalance < minimumInitialBalancePerChunk()) {\n revert InsufficientBalance();\n }\n\n expireLimited(type(uint256).max);\n validChunkCount += (1 << _newDepth) - (1 << batch.depth);\n tree.remove(_batchId, batch.normalisedBalance);\n batches[_batchId].depth = _newDepth;\n batches[_batchId].lastUpdatedBlockNumber = block.number;\n\n batch.normalisedBalance = currentTotalOutPayment() + newRemainingBalance;\n batches[_batchId].normalisedBalance = batch.normalisedBalance;\n tree.insert(_batchId, batch.normalisedBalance);\n\n emit BatchDepthIncrease(_batchId, _newDepth, batch.normalisedBalance);\n }\n\n /**\n * @notice Set a new price.\n * @dev Can only be called by the price oracle role.\n * @param _price The new price.\n */\n function setPrice(uint256 _price) external {\n if (!hasRole(PRICE_ORACLE_ROLE, msg.sender)) {\n revert PriceOracleOnly();\n }\n\n if (lastPrice != 0) {\n totalOutPayment = currentTotalOutPayment();\n }\n\n lastPrice = uint64(_price);\n lastUpdatedBlock = uint64(block.number);\n\n emit PriceUpdate(_price);\n }\n\n function setMinimumValidityBlocks(uint64 _value) external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert AdministratorOnly();\n }\n\n minimumValidityBlocks = _value;\n }\n\n /**\n * @notice Reclaims a limited number of expired batches\n * @dev Can be used if reclaiming all expired batches would exceed the block gas limit, causing other\n * contract method calls to fail.\n * @param limit The maximum number of batches to expire.\n */\n function expireLimited(uint256 limit) public {\n // the lower bound of the normalised balance for which we will check if batches have expired\n uint256 _lastExpiryBalance = lastExpiryBalance;\n uint256 i;\n for (i; i < limit; ) {\n if (isBatchesTreeEmpty()) {\n lastExpiryBalance = currentTotalOutPayment();\n break;\n }\n // get the batch with the smallest normalised balance\n bytes32 fbi = firstBatchId();\n // if the batch with the smallest balance has not yet expired\n // we have already reached the end of the batches we need\n // to expire, so exit the loop\n if (remainingBalance(fbi) > 0) {\n // the upper bound of the normalised balance for which we will check if batches have expired\n // value is updated when there are no expired batches left\n lastExpiryBalance = currentTotalOutPayment();\n break;\n }\n // otherwise, the batch with the smallest balance has expired,\n // so we must remove the chunks this batch contributes to the global validChunkCount\n Batch memory batch = batches[fbi];\n uint256 batchSize = 1 << batch.depth;\n\n if (validChunkCount < batchSize) {\n revert InsufficienChunkCount();\n }\n validChunkCount -= batchSize;\n // since the batch expired _during_ the period we must add\n // remaining normalised payout for this batch only\n pot += batchSize * (batch.normalisedBalance - _lastExpiryBalance);\n tree.remove(fbi, batch.normalisedBalance);\n delete batches[fbi];\n\n unchecked {\n ++i;\n }\n }\n // then, for all batches that have _not_ expired during the period\n // add the total normalised payout of all batches\n // multiplied by the remaining total valid chunk count\n // to the pot for the period since the last expiry\n\n if (lastExpiryBalance < _lastExpiryBalance) {\n revert TotalOutpaymentDecreased();\n }\n\n // then, for all batches that have _not_ expired during the period\n // add the total normalised payout of all batches\n // multiplied by the remaining total valid chunk count\n // to the pot for the period since the last expiry\n pot += validChunkCount * (lastExpiryBalance - _lastExpiryBalance);\n }\n\n /**\n * @notice The current pot.\n */\n function totalPot() public returns (uint256) {\n expireLimited(type(uint256).max);\n uint256 balance = ERC20(bzzToken).balanceOf(address(this));\n return pot < balance ? pot : balance;\n }\n\n /**\n * @notice Withdraw the pot, authorised callers only.\n * @param beneficiary Recieves the current total pot.\n */\n\n function withdraw(address beneficiary) external {\n if (!hasRole(REDISTRIBUTOR_ROLE, msg.sender)) {\n revert OnlyRedistributor();\n }\n\n uint256 totalAmount = totalPot();\n if (!ERC20(bzzToken).transfer(beneficiary, totalAmount)) {\n revert TransferFailed();\n }\n\n emit PotWithdrawn(beneficiary, totalAmount);\n pot = 0;\n }\n\n /**\n * @notice Pause the contract.\n * @dev Can only be called by the pauser when not paused.\n * The contract can be provably stopped by renouncing the pauser role and the admin role once paused.\n */\n function pause() public {\n if (!hasRole(PAUSER_ROLE, msg.sender)) {\n revert OnlyPauser();\n }\n _pause();\n }\n\n /**\n * @notice Unpause the contract.\n * @dev Can only be called by the pauser role while paused.\n */\n function unPause() public {\n if (!hasRole(PAUSER_ROLE, msg.sender)) {\n revert OnlyPauser();\n }\n\n _unpause();\n }\n\n ////////////////////////////////////////\n // STATE READING //\n ////////////////////////////////////////\n\n /**\n * @notice Total per-chunk cost since the contract's deployment.\n * @dev Returns the total normalised all-time per chunk payout.\n * Only Batches with a normalised balance greater than this are valid.\n */\n function currentTotalOutPayment() public view returns (uint256) {\n uint256 blocks = block.number - lastUpdatedBlock;\n uint256 increaseSinceLastUpdate = lastPrice * (blocks);\n return totalOutPayment + (increaseSinceLastUpdate);\n }\n\n function minimumInitialBalancePerChunk() public view returns (uint256) {\n return minimumValidityBlocks * lastPrice;\n }\n\n /**\n * @notice Return the per chunk balance not yet used up.\n * @param _batchId The id of an existing batch.\n */\n function remainingBalance(bytes32 _batchId) public view returns (uint256) {\n Batch memory batch = batches[_batchId];\n\n if (batch.owner == address(0)) {\n revert BatchDoesNotExist(); // Batch does not exist or expired\n }\n\n if (batch.normalisedBalance <= currentTotalOutPayment()) {\n return 0;\n }\n\n return batch.normalisedBalance - currentTotalOutPayment();\n }\n\n /**\n * @notice Indicates whether expired batches exist.\n */\n function expiredBatchesExist() public view returns (bool) {\n if (isBatchesTreeEmpty()) {\n return false;\n }\n return (remainingBalance(firstBatchId()) <= 0);\n }\n\n /**\n * @notice Return true if no batches exist\n */\n function isBatchesTreeEmpty() public view returns (bool) {\n return tree.count() == 0;\n }\n\n /**\n * @notice Get the first batch id ordered by ascending normalised balance.\n * @dev If more than one batch id, return index at 0, if no batches, revert.\n */\n function firstBatchId() public view returns (bytes32) {\n uint256 val = tree.first();\n if (val == 0) {\n revert NoBatchesExist();\n }\n return tree.valueKeyAtIndex(val, 0);\n }\n\n function batchOwner(bytes32 _batchId) public view returns (address) {\n return batches[_batchId].owner;\n }\n\n function batchDepth(bytes32 _batchId) public view returns (uint8) {\n return batches[_batchId].depth;\n }\n\n function batchBucketDepth(bytes32 _batchId) public view returns (uint8) {\n return batches[_batchId].bucketDepth;\n }\n\n function batchImmutableFlag(bytes32 _batchId) public view returns (bool) {\n return batches[_batchId].immutableFlag;\n }\n\n function batchNormalisedBalance(bytes32 _batchId) public view returns (uint256) {\n return batches[_batchId].normalisedBalance;\n }\n\n function batchLastUpdatedBlockNumber(bytes32 _batchId) public view returns (uint256) {\n return batches[_batchId].lastUpdatedBlockNumber;\n }\n}\n" + }, + "src/PriceOracle.sol": { + "content": "// SPDX-License-Identifier: BSD-3-Clause\npragma solidity ^0.8.19;\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"./interface/IPostageStamp.sol\";\n\n/**\n * @title PriceOracle contract.\n * @author The Swarm Authors.\n * @dev The price oracle contract emits a price feed using events.\n */\n\ncontract PriceOracle is AccessControl {\n // ----------------------------- State variables ------------------------------\n\n // The address of the linked PostageStamp contract\n IPostageStamp public postageStamp;\n\n uint16 targetRedundancy = 4;\n uint16 maxConsideredExtraRedundancy = 4;\n\n // When the contract is paused, price changes are not effective\n bool public isPaused = false;\n\n // The number of the last round price adjusting happend\n uint64 public lastAdjustedRound;\n\n // The minimum price allowed\n uint32 public minimumPriceUpscaled = 24000 << 10; // we upscale it by 2^10\n\n // The priceBase to modulate the price\n uint32 public priceBase = 1048576;\n\n uint64 public currentPriceUpScaled = minimumPriceUpscaled;\n\n // Constants used to modulate the price, see below usage\n uint32[9] public changeRate = [1049417, 1049206, 1048996, 1048786, 1048576, 1048366, 1048156, 1047946, 1047736];\n\n // Role allowed to update price\n bytes32 public immutable PRICE_UPDATER_ROLE;\n\n // The length of a round in blocks.\n uint8 private constant ROUND_LENGTH = 152;\n\n // ----------------------------- Events ------------------------------\n\n /**\n *@dev Emitted on every price update.\n */\n event PriceUpdate(uint256 price);\n event StampPriceUpdateFailed(uint256 attemptedPrice);\n\n // ----------------------------- Custom Errors ------------------------------\n error CallerNotAdmin(); // Caller is not the admin\n error CallerNotPriceUpdater(); // Caller is not a price updater\n error PriceAlreadyAdjusted(); // Price already adjusted in this round\n error UnexpectedZero(); // Redundancy needs to be higher then 0\n\n // ----------------------------- CONSTRUCTOR ------------------------------\n\n constructor(address _postageStamp) {\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n postageStamp = IPostageStamp(_postageStamp);\n lastAdjustedRound = currentRound();\n PRICE_UPDATER_ROLE = keccak256(\"PRICE_UPDATER_ROLE\");\n emit PriceUpdate(currentPrice());\n }\n\n ////////////////////////////////////////\n // STATE SETTING //\n ////////////////////////////////////////\n\n /**\n * @notice Manually set the price.\n * @dev Can only be called by the admin role.\n * @param _price The new price.\n */ function setPrice(uint32 _price) external returns (bool) {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert CallerNotAdmin();\n }\n\n uint64 _currentPriceUpScaled = _price << 10;\n uint64 _minimumPriceUpscaled = minimumPriceUpscaled;\n\n // Enforce minimum price\n if (_currentPriceUpScaled < _minimumPriceUpscaled) {\n _currentPriceUpScaled = _minimumPriceUpscaled;\n }\n currentPriceUpScaled = _currentPriceUpScaled;\n\n // Check if the setting of price in postagestamp succeded\n (bool success, ) = address(postageStamp).call(\n abi.encodeWithSignature(\"setPrice(uint256)\", uint256(currentPrice()))\n );\n if (!success) {\n emit StampPriceUpdateFailed(currentPrice());\n return false;\n }\n emit PriceUpdate(currentPrice());\n return true;\n }\n\n function adjustPrice(uint16 redundancy) external returns (bool) {\n if (isPaused == false) {\n if (!hasRole(PRICE_UPDATER_ROLE, msg.sender)) {\n revert CallerNotPriceUpdater();\n }\n\n uint16 usedRedundancy = redundancy;\n uint64 currentRoundNumber = currentRound();\n\n // Price can only be adjusted once per round\n if (currentRoundNumber <= lastAdjustedRound) {\n revert PriceAlreadyAdjusted();\n }\n // Redundancy may not be zero\n if (redundancy == 0) {\n revert UnexpectedZero();\n }\n\n // Enforce maximum considered extra redundancy\n uint16 maxConsideredRedundancy = targetRedundancy + maxConsideredExtraRedundancy;\n if (redundancy > maxConsideredRedundancy) {\n usedRedundancy = maxConsideredRedundancy;\n }\n\n uint64 _currentPriceUpScaled = currentPriceUpScaled;\n uint64 _minimumPriceUpscaled = minimumPriceUpscaled;\n uint32 _priceBase = priceBase;\n\n // Set the number of rounds that were skipped\n uint64 skippedRounds = currentRoundNumber - lastAdjustedRound - 1;\n\n // We first apply the increase/decrease rate for the current round\n uint32 _changeRate = changeRate[usedRedundancy];\n _currentPriceUpScaled = (_changeRate * _currentPriceUpScaled) / _priceBase;\n\n // If previous rounds were skipped, use MAX price increase for the previous rounds\n if (skippedRounds > 0) {\n _changeRate = changeRate[0];\n for (uint64 i = 0; i < skippedRounds; i++) {\n _currentPriceUpScaled = (_changeRate * _currentPriceUpScaled) / _priceBase;\n }\n }\n\n // Enforce minimum price\n if (_currentPriceUpScaled < _minimumPriceUpscaled) {\n _currentPriceUpScaled = _minimumPriceUpscaled;\n }\n\n currentPriceUpScaled = _currentPriceUpScaled;\n lastAdjustedRound = currentRoundNumber;\n\n // Check if the price set in postagestamp succeded\n (bool success, ) = address(postageStamp).call(\n abi.encodeWithSignature(\"setPrice(uint256)\", uint256(currentPrice()))\n );\n if (!success) {\n emit StampPriceUpdateFailed(currentPrice());\n return false;\n }\n emit PriceUpdate(currentPrice());\n return true;\n }\n return false;\n }\n\n function pause() external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert CallerNotAdmin();\n }\n isPaused = true;\n }\n\n function unPause() external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert CallerNotAdmin();\n }\n isPaused = false;\n }\n\n ////////////////////////////////////////\n // STATE READING //\n ////////////////////////////////////////\n\n /**\n * @notice Return the number of the current round.\n */\n function currentRound() public view returns (uint64) {\n // We downcasted to uint64 as uint64 has 18,446,744,073,709,551,616 places\n // as each round is 152 x 5 = 760, each day has around 113 rounds which is 41245 in a year\n // it results 4.4724801e+14 years to run this game\n return uint64(block.number / uint256(ROUND_LENGTH));\n }\n\n /**\n * @notice Return the price downscaled\n */\n function currentPrice() public view returns (uint32) {\n // We downcasted to uint32 and bitshift it by 2^10\n return uint32((currentPriceUpScaled) >> 10);\n }\n\n /**\n * @notice Return the price downscaled\n */\n function minimumPrice() public view returns (uint32) {\n // We downcasted to uint32 and bitshift it by 2^10\n return uint32((minimumPriceUpscaled) >> 10);\n }\n}\n" + }, + "src/Redistribution.sol": { + "content": "// SPDX-License-Identifier: BSD-3-Clause\npragma solidity ^0.8.19;\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"@openzeppelin/contracts/security/Pausable.sol\";\nimport \"./Util/TransformedChunkProof.sol\";\nimport \"./Util/ChunkProof.sol\";\nimport \"./Util/Signatures.sol\";\nimport \"./interface/IPostageStamp.sol\";\n\ninterface IPriceOracle {\n function adjustPrice(uint16 redundancy) external returns (bool);\n}\n\ninterface IStakeRegistry {\n struct Stake {\n bytes32 overlay;\n uint256 stakeAmount;\n uint256 lastUpdatedBlockNumber;\n }\n\n function freezeDeposit(address _owner, uint256 _time) external;\n\n function lastUpdatedBlockNumberOfAddress(address _owner) external view returns (uint256);\n\n function overlayOfAddress(address _owner) external view returns (bytes32);\n\n function heightOfAddress(address _owner) external view returns (uint8);\n\n function nodeEffectiveStake(address _owner) external view returns (uint256);\n}\n\n/**\n * @title Redistribution contract\n * @author The Swarm Authors\n * @dev Implements a Schelling Co-ordination game to form consensus around the Reserve Commitment hash. This takes\n * place in three phases: _commit_, _reveal_ and _claim_.\n *\n * A node, upon establishing that it _isParticipatingInUpcomingRound_, i.e. it's overlay falls within proximity order\n * of its reported depth with the _currentRoundAnchor_, prepares a \"reserve commitment hash\" using the chunks\n * it currently stores in its reserve and calculates the \"storage depth\" (see Bee for details). These values, if calculated\n * honestly, and with the right chunks stored, should be the same for every node in a neighbourhood. This is the Schelling point.\n * Each eligible node can then use these values, together with a random, single use, secret _revealNonce_ and their\n * _overlay_ as the pre-image values for the obsfucated _commit_, using the _wrapCommit_ method.\n *\n * Once the _commit_ round has elapsed, participating nodes must provide the values used to calculate their obsfucated\n * _commit_ hash, which, once verified for correctness and proximity to the anchor are retained in the _currentReveals_.\n * Nodes that have committed but do not reveal the correct values used to create the pre-image will have their stake\n * \"frozen\" for a period of rounds proportional to their reported depth.\n *\n * During the _reveal_ round, randomness is updated after every successful reveal. Once the reveal round is concluded,\n * the _currentRoundAnchor_ is updated and users can determine if they will be eligible their overlay will be eligible\n * for the next commit phase using _isParticipatingInUpcomingRound_.\n *\n * When the _reveal_ phase has been concluded, the claim phase can begin. At this point, the truth teller and winner\n * are already determined. By calling _isWinner_, an applicant node can run the relevant logic to determine if they have\n * been selected as the beneficiary of this round. When calling _claim_, the current pot from the PostageStamp contract\n * is withdrawn and transferred to that beneficiaries address. Nodes that have revealed values that differ from the truth,\n * have their stakes \"frozen\" for a period of rounds proportional to their reported depth.\n */\n\ncontract Redistribution is AccessControl, Pausable {\n // ----------------------------- Type declarations ------------------------------\n\n // An eligible user may commit to an _obfuscatedHash_ during the commit phase...\n struct Commit {\n bytes32 overlay;\n address owner;\n bool revealed;\n uint8 height;\n uint256 stake;\n bytes32 obfuscatedHash;\n uint256 revealIndex;\n }\n // ...then provide the actual values that are the constituents of the pre-image of the _obfuscatedHash_\n // during the reveal phase.\n struct Reveal {\n bytes32 overlay;\n address owner;\n uint8 depth;\n uint256 stake;\n uint256 stakeDensity;\n bytes32 hash;\n }\n\n struct ChunkInclusionProof {\n bytes32[] proofSegments;\n bytes32 proveSegment;\n // _RCspan is known for RC 32*32\n\n // Inclusion proof of transformed address\n bytes32[] proofSegments2;\n bytes32 proveSegment2;\n // proveSegmentIndex2 known from deterministic random selection;\n uint64 chunkSpan;\n bytes32[] proofSegments3;\n // _proveSegment3 known, is equal _proveSegment2\n // proveSegmentIndex3 know, is equal _proveSegmentIndex2;\n // chunkSpan2 is equal to chunkSpan (as the data is the same)\n //\n PostageProof postageProof;\n SOCProof[] socProof;\n }\n\n struct SOCProof {\n address signer; // signer Ethereum address to check against\n bytes signature;\n bytes32 identifier; //\n bytes32 chunkAddr; // wrapped chunk address\n }\n\n struct PostageProof {\n bytes signature;\n bytes32 postageId;\n uint64 index;\n uint64 timeStamp;\n // address signer; it is provided by the postage stamp contract\n // bytes32 chunkAddr; it equals to the proveSegment argument\n }\n\n // The address of the linked PostageStamp contract.\n IPostageStamp public PostageContract;\n // The address of the linked PriceOracle contract.\n IPriceOracle public OracleContract;\n // The address of the linked Staking contract.\n IStakeRegistry public Stakes;\n\n // Commits for the current round.\n Commit[] public currentCommits;\n // Reveals for the current round.\n Reveal[] public currentReveals;\n\n // The current anchor that being processed for the reveal and claim phases of the round.\n bytes32 private currentRevealRoundAnchor;\n\n // The current random value from which we will random.\n // inputs for selection of the truth teller and beneficiary.\n bytes32 private seed;\n\n // The number of the currently active round phases.\n uint64 public currentCommitRound;\n uint64 public currentRevealRound;\n uint64 public currentClaimRound;\n\n // Settings for slashing and freezing\n uint8 private penaltyMultiplierDisagreement = 1;\n uint8 private penaltyMultiplierNonRevealed = 2;\n uint8 private penaltyRandomFactor = 100; // Use 100 as value to ignore random factor in freezing penalty\n\n // alpha=0.097612 beta=0.0716570 k=16\n uint256 private sampleMaxValue = 1284401000000000000000000000000000000000000000000000000000000000000000000;\n\n // The reveal of the winner of the last round.\n Reveal public winner;\n\n // The length of a round in blocks.\n uint256 private constant ROUND_LENGTH = 152;\n\n // Maximum value of the keccack256 hash.\n bytes32 private constant MAX_H = 0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff;\n\n // ----------------------------- Events ------------------------------\n\n /**\n * @dev Emitted when the winner of a round is selected in the claim phase\n */\n event WinnerSelected(Reveal winner);\n\n /**\n * @dev Emitted when the truth oracle of a round is selected in the claim phase.\n */\n event TruthSelected(bytes32 hash, uint8 depth);\n\n // Next two events to be removed after testing phase pending some other usefulness being found.\n /**\n * @dev Emits the number of commits being processed by the claim phase.\n */\n event CountCommits(uint256 _count);\n\n /**\n * @dev Emits the number of reveals being processed by the claim phase.\n */\n event CountReveals(uint256 _count);\n\n /**\n * @dev Logs that an overlay has committed\n */\n event Committed(uint256 roundNumber, bytes32 overlay);\n /**\n * @dev Emit from Postagestamp contract valid chunk count at the end of claim\n */\n event ChunkCount(uint256 validChunkCount);\n\n /**\n * @dev Bytes32 anhor of current reveal round\n */\n event CurrentRevealAnchor(uint256 roundNumber, bytes32 anchor);\n\n /**\n * @dev Output external call status\n */\n event PriceAdjustmentSkipped(uint16 redundancyCount);\n\n /**\n * @dev Withdraw not successful in claim\n */\n event WithdrawFailed(address owner);\n\n /**\n * @dev Logs that an overlay has revealed\n */\n event Revealed(\n uint256 roundNumber,\n bytes32 overlay,\n uint256 stake,\n uint256 stakeDensity,\n bytes32 reserveCommitment,\n uint8 depth\n );\n\n /**\n * @dev Logs for inclusion proof\n */\n event transformedChunkAddressFromInclusionProof(uint256 indexInRC, bytes32 chunkAddress);\n\n // ----------------------------- Errors ------------------------------\n\n error NotCommitPhase(); // Game is not in commit phase\n error NoCommitsReceived(); // Round didn't receive any commits\n error PhaseLastBlock(); // We don't permit commits in last block of the phase\n error CommitRoundOver(); // Commit phase in this round is over\n error CommitRoundNotStarted(); // Commit phase in this round has not started yet\n error NotMatchingOwner(); // Sender of commit is not matching the overlay address\n error MustStake2Rounds(); // Before entering the game node must stake 2 rounds prior\n error NotStaked(); // Node didn't add any staking\n error WrongPhase(); // Checking in wrong phase, need to check duing claim phase of current round for next round or commit in current round\n error AlreadyCommitted(); // Node already committed in this round\n error NotRevealPhase(); // Game is not in reveal phase\n error OutOfDepthReveal(bytes32); // Anchor is out of reported depth in Reveal phase, anchor data available as argument\n error OutOfDepthClaim(uint8); // Anchor is out of reported depth in Claim phase, entryProof index is argument\n error OutOfDepth(); // Anchor is out of reported depth\n error AlreadyRevealed(); // Node already revealed\n error NoMatchingCommit(); // No matching commit and hash\n error NotClaimPhase(); // Game is not in the claim phase\n error NoReveals(); // Round did not receive any reveals\n error FirstRevealDone(); // We don't want to return value after first reveal\n error AlreadyClaimed(); // This round was already claimed\n error NotAdmin(); // Caller of trx is not admin\n error OnlyPauser(); // Only account with pauser role can call pause/unpause\n error SocVerificationFailed(bytes32); // Soc verification failed for this element\n error SocCalcNotMatching(bytes32); // Soc address calculation does not match with the witness\n error IndexOutsideSet(bytes32); // Stamp available: index resides outside of the valid index set\n error SigRecoveryFailed(bytes32); // Stamp authorized: signature recovery failed for element\n error BatchDoesNotExist(bytes32); // Stamp alive: batch remaining balance validation failed for attached stamp\n error BucketDiffers(bytes32); // Stamp aligned: postage bucket differs from address bucket\n error InclusionProofFailed(uint8, bytes32);\n // 1 = RC inclusion proof failed for element\n // 2 = First sister segment in data must match,\n // 3 = Inclusion proof failed for original address of element\n // 4 = Inclusion proof failed for transformed address of element\n error RandomElementCheckFailed(); // Random element order check failed\n error LastElementCheckFailed(); // Last element order check failed\n error ReserveCheckFailed(bytes32 trALast); // Reserve size estimation check failed\n\n // ----------------------------- CONSTRUCTOR ------------------------------\n\n /**\n * @param staking the address of the linked Staking contract.\n * @param postageContract the address of the linked PostageStamp contract.\n * @param oracleContract the address of the linked PriceOracle contract.\n */\n constructor(address staking, address postageContract, address oracleContract) {\n Stakes = IStakeRegistry(staking);\n PostageContract = IPostageStamp(postageContract);\n OracleContract = IPriceOracle(oracleContract);\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n }\n\n ////////////////////////////////////////\n // STATE CHANGING //\n ////////////////////////////////////////\n\n /**\n * @notice Begin application for a round if eligible. Commit a hashed value for which the pre-image will be\n * subsequently revealed.\n * @dev If a node's overlay is _inProximity_(_depth_) of the _currentRoundAnchor_, that node may compute an\n * _obfuscatedHash_ by providing their _overlay_, reported storage _depth_, reserve commitment _hash_ and a\n * randomly generated, and secret _revealNonce_ to the _wrapCommit_ method.\n * @param _obfuscatedHash The calculated hash resultant of the required pre-image values.\n * and be derived from the same key pair as the message sender.\n * @param _roundNumber Node needs to provide round number for which commit is valid\n */\n function commit(bytes32 _obfuscatedHash, uint64 _roundNumber) external whenNotPaused {\n uint64 cr = currentRound();\n bytes32 _overlay = Stakes.overlayOfAddress(msg.sender);\n uint256 _stake = Stakes.nodeEffectiveStake(msg.sender);\n uint256 _lastUpdate = Stakes.lastUpdatedBlockNumberOfAddress(msg.sender);\n uint8 _height = Stakes.heightOfAddress(msg.sender);\n\n if (!currentPhaseCommit()) {\n revert NotCommitPhase();\n }\n if (block.number % ROUND_LENGTH == (ROUND_LENGTH / 4) - 1) {\n revert PhaseLastBlock();\n }\n\n if (cr > _roundNumber) {\n revert CommitRoundOver();\n }\n\n if (cr < _roundNumber) {\n revert CommitRoundNotStarted();\n }\n\n if (_lastUpdate == 0) {\n revert NotStaked();\n }\n\n if (_lastUpdate >= block.number - 2 * ROUND_LENGTH) {\n revert MustStake2Rounds();\n }\n\n // if we are in a new commit phase, reset the array of commits and\n // set the currentCommitRound to be the current one\n if (cr != currentCommitRound) {\n delete currentCommits;\n currentCommitRound = cr;\n }\n\n uint256 commitsArrayLength = currentCommits.length;\n\n for (uint256 i = 0; i < commitsArrayLength; ) {\n if (currentCommits[i].overlay == _overlay) {\n revert AlreadyCommitted();\n }\n\n unchecked {\n ++i;\n }\n }\n\n currentCommits.push(\n Commit({\n overlay: _overlay,\n owner: msg.sender,\n revealed: false,\n height: _height,\n stake: _stake,\n obfuscatedHash: _obfuscatedHash,\n revealIndex: 0\n })\n );\n\n emit Committed(_roundNumber, _overlay);\n }\n\n /**\n * @notice Reveal the pre-image values used to generate commit provided during this round's commit phase.\n * @param _depth The reported depth.\n * @param _hash The reserve commitment hash.\n * @param _revealNonce The nonce used to generate the commit that is being revealed.\n */\n function reveal(uint8 _depth, bytes32 _hash, bytes32 _revealNonce) external whenNotPaused {\n uint64 cr = currentRound();\n bytes32 _overlay = Stakes.overlayOfAddress(msg.sender);\n\n if (_depth < currentMinimumDepth()) {\n revert OutOfDepth();\n }\n\n if (!currentPhaseReveal()) {\n revert NotRevealPhase();\n }\n\n if (cr != currentCommitRound) {\n revert NoCommitsReceived();\n }\n\n if (cr != currentRevealRound) {\n currentRevealRoundAnchor = currentRoundAnchor();\n delete currentReveals;\n // We set currentRevealRound ONLY after we set current anchor\n currentRevealRound = cr;\n emit CurrentRevealAnchor(cr, currentRevealRoundAnchor);\n updateRandomness();\n }\n\n bytes32 obfuscatedHash = wrapCommit(_overlay, _depth, _hash, _revealNonce);\n uint256 id = findCommit(_overlay, obfuscatedHash);\n Commit memory revealedCommit = currentCommits[id];\n uint8 depthResponsibility = _depth - revealedCommit.height;\n\n // Check that commit is in proximity of the current anchor\n if (!inProximity(revealedCommit.overlay, currentRevealRoundAnchor, depthResponsibility)) {\n revert OutOfDepthReveal(currentRevealRoundAnchor);\n }\n // Check that the commit has not already been revealed\n if (revealedCommit.revealed) {\n revert AlreadyRevealed();\n }\n\n currentCommits[id].revealed = true;\n currentCommits[id].revealIndex = currentReveals.length;\n\n currentReveals.push(\n Reveal({\n overlay: revealedCommit.overlay,\n owner: revealedCommit.owner,\n depth: _depth,\n stake: revealedCommit.stake,\n stakeDensity: revealedCommit.stake * uint256(2 ** depthResponsibility),\n hash: _hash\n })\n );\n\n emit Revealed(\n cr,\n revealedCommit.overlay,\n revealedCommit.stake,\n revealedCommit.stake * uint256(2 ** depthResponsibility),\n _hash,\n _depth\n );\n }\n\n /**\n * @notice Helper function to get this round truth\n * @dev\n */\n function claim(\n ChunkInclusionProof calldata entryProof1,\n ChunkInclusionProof calldata entryProof2,\n ChunkInclusionProof calldata entryProofLast\n ) external whenNotPaused {\n winnerSelection();\n\n Reveal memory winnerSelected = winner;\n uint256 indexInRC1;\n uint256 indexInRC2;\n bytes32 _currentRevealRoundAnchor = currentRevealRoundAnchor;\n bytes32 _seed = seed;\n\n // rand(14)\n indexInRC1 = uint256(_seed) % 15;\n // rand(13)\n indexInRC2 = uint256(_seed) % 14;\n if (indexInRC2 >= indexInRC1) {\n indexInRC2++;\n }\n\n if (!inProximity(entryProofLast.proveSegment, _currentRevealRoundAnchor, winnerSelected.depth)) {\n revert OutOfDepthClaim(3);\n }\n\n inclusionFunction(entryProofLast, 30);\n stampFunction(entryProofLast);\n socFunction(entryProofLast);\n\n if (!inProximity(entryProof1.proveSegment, _currentRevealRoundAnchor, winnerSelected.depth)) {\n revert OutOfDepthClaim(2);\n }\n\n inclusionFunction(entryProof1, indexInRC1 * 2);\n stampFunction(entryProof1);\n socFunction(entryProof1);\n\n if (!inProximity(entryProof2.proveSegment, _currentRevealRoundAnchor, winnerSelected.depth)) {\n revert OutOfDepthClaim(1);\n }\n\n inclusionFunction(entryProof2, indexInRC2 * 2);\n stampFunction(entryProof2);\n socFunction(entryProof2);\n\n checkOrder(\n indexInRC1,\n indexInRC2,\n entryProof1.proofSegments[0],\n entryProof2.proofSegments[0],\n entryProofLast.proofSegments[0]\n );\n\n estimateSize(entryProofLast.proofSegments[0]);\n\n // Do the check if the withdraw was success\n (bool success, ) = address(PostageContract).call(\n abi.encodeWithSignature(\"withdraw(address)\", winnerSelected.owner)\n );\n if (!success) {\n emit WithdrawFailed(winnerSelected.owner);\n }\n\n emit WinnerSelected(winnerSelected);\n emit ChunkCount(PostageContract.validChunkCount());\n }\n\n function winnerSelection() internal {\n uint64 cr = currentRound();\n\n if (!currentPhaseClaim()) {\n revert NotClaimPhase();\n }\n\n if (cr != currentRevealRound) {\n revert NoReveals();\n }\n\n if (cr <= currentClaimRound) {\n revert AlreadyClaimed();\n }\n\n uint256 currentWinnerSelectionSum = 0;\n uint256 redundancyCount = 0;\n bytes32 randomNumber;\n uint256 randomNumberTrunc;\n\n bytes32 truthRevealedHash;\n uint8 truthRevealedDepth;\n uint256 currentCommitsLength = currentCommits.length;\n\n emit CountCommits(currentCommitsLength);\n emit CountReveals(currentReveals.length);\n\n (truthRevealedHash, truthRevealedDepth) = getCurrentTruth();\n emit TruthSelected(truthRevealedHash, truthRevealedDepth);\n string memory winnerSelectionAnchor = currentWinnerSelectionAnchor();\n\n for (uint256 i = 0; i < currentCommitsLength; ) {\n Commit memory currentCommit = currentCommits[i];\n uint256 revIndex = currentCommit.revealIndex;\n Reveal memory currentReveal = currentReveals[revIndex];\n\n // Select winner with valid truth\n if (\n currentCommit.revealed &&\n truthRevealedHash == currentReveal.hash &&\n truthRevealedDepth == currentReveal.depth\n ) {\n currentWinnerSelectionSum += currentReveal.stakeDensity;\n randomNumber = keccak256(abi.encodePacked(winnerSelectionAnchor, redundancyCount));\n randomNumberTrunc = uint256(randomNumber & MAX_H);\n\n if (randomNumberTrunc * currentWinnerSelectionSum < currentReveal.stakeDensity * (uint256(MAX_H) + 1)) {\n winner = currentReveal;\n }\n\n redundancyCount++;\n }\n\n // Freeze deposit if any truth is false, make it a penaltyRandomFactor chance for this to happen\n if (\n currentCommit.revealed &&\n (truthRevealedHash != currentReveal.hash || truthRevealedDepth != currentReveal.depth) &&\n (block.prevrandao % 100 < penaltyRandomFactor)\n ) {\n Stakes.freezeDeposit(\n currentReveal.owner,\n penaltyMultiplierDisagreement * ROUND_LENGTH * uint256(2 ** truthRevealedDepth)\n );\n }\n\n // Slash deposits if revealed is false\n if (!currentCommit.revealed) {\n // slash in later phase (ph5)\n // Stakes.slashDeposit(currentCommits[i].overlay, currentCommits[i].stake);\n Stakes.freezeDeposit(\n currentCommit.owner,\n penaltyMultiplierNonRevealed * ROUND_LENGTH * uint256(2 ** truthRevealedDepth)\n );\n }\n unchecked {\n ++i;\n }\n }\n\n bool success = OracleContract.adjustPrice(uint16(redundancyCount));\n if (!success) {\n emit PriceAdjustmentSkipped(uint16(redundancyCount));\n }\n currentClaimRound = cr;\n }\n\n function inclusionFunction(ChunkInclusionProof calldata entryProof, uint256 indexInRC) internal {\n uint256 randomChunkSegmentIndex = uint256(seed) % 128;\n bytes32 calculatedTransformedAddr = TransformedBMTChunk.transformedChunkAddressFromInclusionProof(\n entryProof.proofSegments3,\n entryProof.proveSegment2,\n randomChunkSegmentIndex,\n entryProof.chunkSpan,\n currentRevealRoundAnchor\n );\n\n emit transformedChunkAddressFromInclusionProof(indexInRC, calculatedTransformedAddr);\n\n if (\n winner.hash !=\n BMTChunk.chunkAddressFromInclusionProof(\n entryProof.proofSegments,\n entryProof.proveSegment,\n indexInRC,\n 32 * 32\n )\n ) {\n revert InclusionProofFailed(1, calculatedTransformedAddr);\n }\n\n if (entryProof.proofSegments2[0] != entryProof.proofSegments3[0]) {\n revert InclusionProofFailed(2, calculatedTransformedAddr);\n }\n\n bytes32 originalAddress = entryProof.socProof.length > 0\n ? entryProof.socProof[0].chunkAddr // soc attestation in socFunction\n : entryProof.proveSegment;\n\n if (\n originalAddress !=\n BMTChunk.chunkAddressFromInclusionProof(\n entryProof.proofSegments2,\n entryProof.proveSegment2,\n randomChunkSegmentIndex,\n entryProof.chunkSpan\n )\n ) {\n revert InclusionProofFailed(3, calculatedTransformedAddr);\n }\n\n // In case of SOC, the transformed address is hashed together with its address in the sample\n if (entryProof.socProof.length > 0) {\n calculatedTransformedAddr = keccak256(\n abi.encode(\n entryProof.proveSegment, // SOC address\n calculatedTransformedAddr\n )\n );\n }\n\n if (entryProof.proofSegments[0] != calculatedTransformedAddr) {\n revert InclusionProofFailed(4, calculatedTransformedAddr);\n }\n }\n\n /**\n * @notice Set freezing parameters\n */\n function setFreezingParams(\n uint8 _penaltyMultiplierDisagreement,\n uint8 _penaltyMultiplierNonRevealed,\n uint8 _penaltyRandomFactor\n ) external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert NotAdmin();\n }\n\n penaltyMultiplierDisagreement = _penaltyMultiplierDisagreement;\n penaltyMultiplierNonRevealed = _penaltyMultiplierNonRevealed;\n penaltyRandomFactor = _penaltyRandomFactor;\n }\n\n /**\n * @notice changes the max sample value used for reserve estimation\n */\n function setSampleMaxValue(uint256 _sampleMaxValue) external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert NotAdmin();\n }\n\n sampleMaxValue = _sampleMaxValue;\n }\n\n /**\n * @notice Updates the source of randomness. Uses block.difficulty in pre-merge chains, this is substituted\n * to block.prevrandao in post merge chains.\n */\n function updateRandomness() private {\n seed = keccak256(abi.encode(seed, block.prevrandao));\n }\n\n /**\n * @dev Pause the contract. The contract is provably stopped by renouncing\n the pauser role and the admin role after pausing, can only be called by the `PAUSER`\n */\n function pause() public {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert OnlyPauser();\n }\n\n _pause();\n }\n\n /**\n * @dev Unpause the contract, can only be called by the pauser when paused\n */\n function unPause() public {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert OnlyPauser();\n }\n _unpause();\n }\n\n ////////////////////////////////////////\n // STATE READING //\n ////////////////////////////////////////\n\n // ----------------------------- Anchor calculations ------------------------------\n\n /**\n * @notice Returns the current random seed which is used to determine later utilised random numbers.\n * If rounds have elapsed without reveals, hash the seed with an incremented nonce to produce a new\n * random seed and hence a new round anchor.\n */\n function currentSeed() public view returns (bytes32) {\n uint64 cr = currentRound();\n bytes32 currentSeedValue = seed;\n\n if (cr > currentRevealRound + 1) {\n uint256 difference = cr - currentRevealRound - 1;\n currentSeedValue = keccak256(abi.encodePacked(currentSeedValue, difference));\n }\n\n return currentSeedValue;\n }\n\n /**\n * @notice Returns the seed which will become current once the next commit phase begins.\n * Used to determine what the next round's anchor will be.\n */\n function nextSeed() public view returns (bytes32) {\n uint64 cr = currentRound() + 1;\n bytes32 currentSeedValue = seed;\n\n if (cr > currentRevealRound + 1) {\n uint256 difference = cr - currentRevealRound - 1;\n currentSeedValue = keccak256(abi.encodePacked(currentSeedValue, difference));\n }\n\n return currentSeedValue;\n }\n\n /**\n * @notice The random value used to choose the selected truth teller.\n */\n function currentTruthSelectionAnchor() private view returns (string memory) {\n if (!currentPhaseClaim()) {\n revert NotClaimPhase();\n }\n\n uint64 cr = currentRound();\n if (cr != currentRevealRound) {\n revert NoReveals();\n }\n\n return string(abi.encodePacked(seed, \"0\"));\n }\n\n /**\n * @notice The random value used to choose the selected beneficiary.\n */\n function currentWinnerSelectionAnchor() private view returns (string memory) {\n if (!currentPhaseClaim()) {\n revert NotClaimPhase();\n }\n uint64 cr = currentRound();\n if (cr != currentRevealRound) {\n revert NoReveals();\n }\n\n return string(abi.encodePacked(seed, \"1\"));\n }\n\n /**\n * @notice The anchor used to determine eligibility for the current round.\n * @dev A node must be within proximity order of less than or equal to the storage depth they intend to report.\n */\n function currentRoundAnchor() public view returns (bytes32 returnVal) {\n // This will be called in reveal phase and set as currentRevealRoundAnchor or in\n // commit phase when checking eligibility for next round by isParticipatingInUpcomingRound\n if (currentPhaseCommit() || (currentRound() > currentRevealRound && !currentPhaseClaim())) {\n return currentSeed();\n }\n\n // This will be called by isParticipatingInUpcomingRound check in claim phase\n if (currentPhaseClaim()) {\n return nextSeed();\n }\n\n // Without this, this function will output 0x0 after first reveal which is value and we prefere it reverts\n if (currentPhaseReveal() && currentRound() == currentRevealRound) {\n revert FirstRevealDone();\n }\n }\n\n /**\n * @notice Returns true if an overlay address _A_ is within proximity order _minimum_ of _B_.\n * @param A An overlay address to compare.\n * @param B An overlay address to compare.\n * @param minimum Minimum proximity order.\n */\n function inProximity(bytes32 A, bytes32 B, uint8 minimum) public pure returns (bool) {\n if (minimum == 0) {\n return true;\n }\n\n return uint256(A ^ B) < uint256(2 ** (256 - minimum));\n }\n\n // ----------------------------- Commit ------------------------------\n\n /**\n * @notice The number of the current round.\n */\n function currentRound() public view returns (uint64) {\n return uint64(block.number / ROUND_LENGTH);\n }\n\n /**\n * @notice Returns true if current block is during commit phase.\n */\n function currentPhaseCommit() public view returns (bool) {\n if (block.number % ROUND_LENGTH < ROUND_LENGTH / 4) {\n return true;\n }\n return false;\n }\n\n /**\n * @notice Determine if a the owner of a given overlay can participate in the upcoming round.\n * @param _owner The address of the applicant from.\n * @param _depth The storage depth the applicant intends to report.\n */\n function isParticipatingInUpcomingRound(address _owner, uint8 _depth) public view returns (bool) {\n uint256 _lastUpdate = Stakes.lastUpdatedBlockNumberOfAddress(_owner);\n uint8 _depthResponsibility = _depth - Stakes.heightOfAddress(_owner);\n\n if (currentPhaseReveal()) {\n revert WrongPhase();\n }\n\n if (_lastUpdate == 0) {\n revert NotStaked();\n }\n\n if (_lastUpdate >= block.number - 2 * ROUND_LENGTH) {\n revert MustStake2Rounds();\n }\n\n return inProximity(Stakes.overlayOfAddress(_owner), currentRoundAnchor(), _depthResponsibility);\n }\n\n // ----------------------------- Reveal ------------------------------\n\n /**\n * @notice Returns minimum depth reveal has to have to participate in this round\n */\n function currentMinimumDepth() public view returns (uint8) {\n // We are checking value in reveal phase, as the currentCommitRound is set to the current round\n // but the currentClaimRound is still set to the last time claim was made\n // We add 1 to ensure that for the next round the minimum depth is the same as last winner depth\n\n uint256 difference = currentCommitRound - currentClaimRound;\n uint8 skippedRounds = uint8(difference > 254 ? 254 : difference) + 1;\n\n uint8 lastWinnerDepth = winner.depth;\n\n // We ensure that skippedRounds is not bigger than lastWinnerDepth, because of overflow\n return skippedRounds >= lastWinnerDepth ? 0 : lastWinnerDepth - skippedRounds;\n }\n\n /**\n * @notice Helper function to get this node reveal in commits\n * @dev\n */\n function findCommit(bytes32 _overlay, bytes32 _obfuscatedHash) internal view returns (uint256) {\n for (uint256 i = 0; i < currentCommits.length; ) {\n if (currentCommits[i].overlay == _overlay && _obfuscatedHash == currentCommits[i].obfuscatedHash) {\n return i;\n }\n unchecked {\n ++i;\n }\n }\n revert NoMatchingCommit();\n }\n\n /**\n * @notice Hash the pre-image values to the obsfucated hash.\n * @dev _revealNonce_ must be randomly generated, used once and kept secret until the reveal phase.\n * @param _overlay The overlay address of the applicant.\n * @param _depth The reported depth.\n * @param _hash The reserve commitment hash.\n * @param revealNonce A random, single use, secret nonce.\n */\n function wrapCommit(\n bytes32 _overlay,\n uint8 _depth,\n bytes32 _hash,\n bytes32 revealNonce\n ) public pure returns (bytes32) {\n return keccak256(abi.encodePacked(_overlay, _depth, _hash, revealNonce));\n }\n\n /**\n * @notice Returns true if current block is during reveal phase.\n */\n function currentPhaseReveal() public view returns (bool) {\n uint256 number = block.number % ROUND_LENGTH;\n if (number >= ROUND_LENGTH / 4 && number < ROUND_LENGTH / 2) {\n return true;\n }\n return false;\n }\n\n /**\n * @notice Returns true if current block is during reveal phase.\n */\n function currentRoundReveals() public view returns (Reveal[] memory) {\n if (!currentPhaseClaim()) {\n revert NotClaimPhase();\n }\n uint64 cr = currentRound();\n if (cr != currentRevealRound) {\n revert NoReveals();\n }\n\n return currentReveals;\n }\n\n // ----------------------------- Claim ------------------------------\n\n /**\n * @notice Returns true if current block is during claim phase.\n */\n function currentPhaseClaim() public view returns (bool) {\n if (block.number % ROUND_LENGTH >= ROUND_LENGTH / 2) {\n return true;\n }\n return false;\n }\n\n function getCurrentTruth() internal view returns (bytes32 Hash, uint8 Depth) {\n uint256 currentSum;\n bytes32 randomNumber;\n uint256 randomNumberTrunc;\n\n bytes32 truthRevealedHash;\n uint8 truthRevealedDepth;\n uint256 revIndex;\n string memory truthSelectionAnchor = currentTruthSelectionAnchor();\n uint256 commitsArrayLength = currentCommits.length;\n\n for (uint256 i = 0; i < commitsArrayLength; ) {\n if (currentCommits[i].revealed) {\n revIndex = currentCommits[i].revealIndex;\n currentSum += currentReveals[revIndex].stakeDensity;\n randomNumber = keccak256(abi.encodePacked(truthSelectionAnchor, i));\n randomNumberTrunc = uint256(randomNumber & MAX_H);\n\n // question is whether randomNumber / MAX_H < probability\n // where probability is stakeDensity / currentSum\n // to avoid resorting to floating points all divisions should be\n // simplified with multiplying both sides (as long as divisor > 0)\n // randomNumber / (MAX_H + 1) < stakeDensity / currentSum\n // ( randomNumber / (MAX_H + 1) ) * currentSum < stakeDensity\n // randomNumber * currentSum < stakeDensity * (MAX_H + 1)\n if (randomNumberTrunc * currentSum < currentReveals[revIndex].stakeDensity * (uint256(MAX_H) + 1)) {\n truthRevealedHash = currentReveals[revIndex].hash;\n truthRevealedDepth = currentReveals[revIndex].depth;\n }\n }\n unchecked {\n ++i;\n }\n }\n\n return (truthRevealedHash, truthRevealedDepth);\n }\n\n /**\n * @notice Determine if a the owner of a given overlay will be the beneficiary of the claim phase.\n * @param _overlay The overlay address of the applicant.\n */\n function isWinner(bytes32 _overlay) public view returns (bool) {\n if (!currentPhaseClaim()) {\n revert NotClaimPhase();\n }\n\n uint64 cr = currentRound();\n if (cr != currentRevealRound) {\n revert NoReveals();\n }\n\n if (cr <= currentClaimRound) {\n revert AlreadyClaimed();\n }\n\n uint256 currentWinnerSelectionSum;\n bytes32 winnerIs;\n bytes32 randomNumber;\n uint256 randomNumberTrunc;\n bytes32 truthRevealedHash;\n uint8 truthRevealedDepth;\n uint256 revIndex;\n string memory winnerSelectionAnchor = currentWinnerSelectionAnchor();\n uint256 redundancyCount = 0;\n\n // Get current truth\n (truthRevealedHash, truthRevealedDepth) = getCurrentTruth();\n uint256 commitsArrayLength = currentCommits.length;\n\n for (uint256 i = 0; i < commitsArrayLength; ) {\n revIndex = currentCommits[i].revealIndex;\n\n // Deterministically read winner\n if (\n currentCommits[i].revealed &&\n truthRevealedHash == currentReveals[revIndex].hash &&\n truthRevealedDepth == currentReveals[revIndex].depth\n ) {\n currentWinnerSelectionSum += currentReveals[revIndex].stakeDensity;\n randomNumber = keccak256(abi.encodePacked(winnerSelectionAnchor, redundancyCount));\n randomNumberTrunc = uint256(randomNumber & MAX_H);\n\n if (\n randomNumberTrunc * currentWinnerSelectionSum <\n currentReveals[revIndex].stakeDensity * (uint256(MAX_H) + 1)\n ) {\n winnerIs = currentReveals[revIndex].overlay;\n }\n\n redundancyCount++;\n }\n unchecked {\n ++i;\n }\n }\n\n return (winnerIs == _overlay);\n }\n\n // ----------------------------- Claim verifications ------------------------------\n\n function socFunction(ChunkInclusionProof calldata entryProof) internal pure {\n if (entryProof.socProof.length == 0) return;\n\n if (\n !Signatures.socVerify(\n entryProof.socProof[0].signer, // signer Ethereum address to check against\n entryProof.socProof[0].signature,\n entryProof.socProof[0].identifier,\n entryProof.socProof[0].chunkAddr\n )\n ) {\n revert SocVerificationFailed(entryProof.socProof[0].chunkAddr);\n }\n\n if (\n calculateSocAddress(entryProof.socProof[0].identifier, entryProof.socProof[0].signer) !=\n entryProof.proveSegment\n ) {\n revert SocCalcNotMatching(entryProof.socProof[0].chunkAddr);\n }\n }\n\n function stampFunction(ChunkInclusionProof calldata entryProof) internal view {\n // authentic\n (address batchOwner, uint8 batchDepth, uint8 bucketDepth, , , ) = PostageContract.batches(\n entryProof.postageProof.postageId\n );\n\n // alive\n if (batchOwner == address(0)) {\n revert BatchDoesNotExist(entryProof.postageProof.postageId); // Batch does not exist or expired\n }\n\n uint32 postageIndex = getPostageIndex(entryProof.postageProof.index);\n uint256 maxPostageIndex = postageStampIndexCount(batchDepth, bucketDepth);\n // available\n if (postageIndex >= maxPostageIndex) {\n revert IndexOutsideSet(entryProof.postageProof.postageId);\n }\n\n // aligned\n uint64 postageBucket = getPostageBucket(entryProof.postageProof.index);\n uint64 addressBucket = addressToBucket(entryProof.proveSegment, bucketDepth);\n if (postageBucket != addressBucket) {\n revert BucketDiffers(entryProof.postageProof.postageId);\n }\n\n // authorized\n if (\n !Signatures.postageVerify(\n batchOwner,\n entryProof.postageProof.signature,\n entryProof.proveSegment,\n entryProof.postageProof.postageId,\n entryProof.postageProof.index,\n entryProof.postageProof.timeStamp\n )\n ) {\n revert SigRecoveryFailed(entryProof.postageProof.postageId);\n }\n }\n\n function addressToBucket(bytes32 swarmAddress, uint8 bucketDepth) internal pure returns (uint32) {\n uint32 prefix = uint32(uint256(swarmAddress) >> (256 - 32));\n return prefix >> (32 - bucketDepth);\n }\n\n function postageStampIndexCount(uint8 postageDepth, uint8 bucketDepth) internal pure returns (uint256) {\n return 1 << (postageDepth - bucketDepth);\n }\n\n function getPostageIndex(uint64 signedIndex) internal pure returns (uint32) {\n return uint32(signedIndex);\n }\n\n function getPostageBucket(uint64 signedIndex) internal pure returns (uint64) {\n return uint32(signedIndex >> 32);\n }\n\n function calculateSocAddress(bytes32 identifier, address signer) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(identifier, signer));\n }\n\n function checkOrder(uint256 a, uint256 b, bytes32 trA1, bytes32 trA2, bytes32 trALast) internal pure {\n if (a < b) {\n if (uint256(trA1) >= uint256(trA2)) {\n revert RandomElementCheckFailed();\n }\n if (uint256(trA2) >= uint256(trALast)) {\n revert LastElementCheckFailed();\n }\n } else {\n if (uint256(trA2) >= uint256(trA1)) {\n revert RandomElementCheckFailed();\n }\n if (uint256(trA1) >= uint256(trALast)) {\n revert LastElementCheckFailed();\n }\n }\n }\n\n function estimateSize(bytes32 trALast) internal view {\n if (uint256(trALast) >= sampleMaxValue) {\n revert ReserveCheckFailed(trALast);\n }\n }\n}\n" + }, + "src/Staking.sol": { + "content": "// SPDX-License-Identifier: BSD-3-Clause\npragma solidity ^0.8.19;\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"@openzeppelin/contracts/security/Pausable.sol\";\n\ninterface IPriceOracle {\n function currentPrice() external view returns (uint32);\n}\n\n/**\n * @title Staking contract for the Swarm storage incentives\n * @author The Swarm Authors\n * @dev Allows users to stake tokens in order to be eligible for the Redistribution Schelling co-ordination game.\n * Stakes are frozen or slashed by the Redistribution contract in response to violations of the\n * protocol.\n */\n\ncontract StakeRegistry is AccessControl, Pausable {\n // ----------------------------- State variables ------------------------------\n\n struct Stake {\n // Overlay of the node that is being staked\n bytes32 overlay;\n // Stake balance expressed through price oracle\n uint256 committedStake;\n // Stake balance expressed in BZZ\n uint256 potentialStake;\n // Block height the stake was updated, also used as flag to check if the stake is set\n uint256 lastUpdatedBlockNumber;\n // Node indicating its increased reserve\n uint8 height;\n }\n\n // Associate every stake id with node address data.\n mapping(address => Stake) public stakes;\n\n // Role allowed to freeze and slash entries\n bytes32 public constant REDISTRIBUTOR_ROLE = keccak256(\"REDISTRIBUTOR_ROLE\");\n\n // Swarm network ID\n uint64 NetworkId;\n\n // The miniumum stake allowed to be staked using the Staking contract.\n uint64 private constant MIN_STAKE = 100000000000000000;\n\n // Address of the staked ERC20 token\n address public immutable bzzToken;\n\n // The address of the linked PriceOracle contract.\n IPriceOracle public OracleContract;\n\n // ----------------------------- Events ------------------------------\n\n /**\n * @dev Emitted when a stake is created or updated by `owner` of the `overlay`.\n */\n event StakeUpdated(\n address indexed owner,\n uint256 committedStake,\n uint256 potentialStake,\n bytes32 overlay,\n uint256 lastUpdatedBlock,\n uint8 height\n );\n\n /**\n * @dev Emitted when a stake for address `slashed` is slashed by `amount`.\n */\n event StakeSlashed(address slashed, bytes32 overlay, uint256 amount);\n\n /**\n * @dev Emitted when a stake for address `frozen` is frozen for `time` blocks.\n */\n event StakeFrozen(address frozen, bytes32 overlay, uint256 time);\n\n /**\n * @dev Emitted when a address changes overlay it uses\n */\n event OverlayChanged(address owner, bytes32 overlay);\n\n /**\n * @dev Emitted when a stake for address is withdrawn\n */\n event StakeWithdrawn(address node, uint256 amount);\n\n // ----------------------------- Errors ------------------------------\n\n error TransferFailed(); // Used when token transfers fail\n error Frozen(); // Used when an action cannot proceed because the overlay is frozen\n error Unauthorized(); // Used where only the owner can perform the action\n error OnlyRedistributor(); // Used when only the redistributor role is allowed\n error OnlyPauser(); // Used when only the pauser role is allowed\n error BelowMinimumStake(); // Node participating in game has stake below minimum treshold\n\n // ----------------------------- CONSTRUCTOR ------------------------------\n\n /**\n * @param _bzzToken Address of the staked ERC20 token\n * @param _NetworkId Swarm network ID\n */\n constructor(address _bzzToken, uint64 _NetworkId, address _oracleContract) {\n NetworkId = _NetworkId;\n bzzToken = _bzzToken;\n OracleContract = IPriceOracle(_oracleContract);\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n }\n\n ////////////////////////////////////////\n // STATE SETTING //\n ////////////////////////////////////////\n\n /**\n * @notice Create a new stake or update an existing one, change overlay of node\n * @dev At least `_initialBalancePerChunk*2^depth` number of tokens need to be preapproved for this contract.\n * @param _setNonce Nonce that was used for overlay calculation.\n * @param _addAmount Deposited amount of ERC20 tokens, equals to added Potential stake value\n * @param _height increased reserve by registering the number of doublings\n */\n function manageStake(bytes32 _setNonce, uint256 _addAmount, uint8 _height) external whenNotPaused {\n bytes32 _previousOverlay = stakes[msg.sender].overlay;\n uint256 _stakingSet = stakes[msg.sender].lastUpdatedBlockNumber;\n bytes32 _newOverlay = keccak256(abi.encodePacked(msg.sender, reverse(NetworkId), _setNonce));\n\n // First time adding stake, check the minimum is added, take into account height\n if (_addAmount < MIN_STAKE * 2 ** _height && _stakingSet == 0) {\n revert BelowMinimumStake();\n }\n\n if (_stakingSet != 0 && !addressNotFrozen(msg.sender)) revert Frozen();\n uint256 updatedPotentialStake = stakes[msg.sender].potentialStake + _addAmount;\n uint256 updatedCommittedStake = updatedPotentialStake / (OracleContract.currentPrice() * 2 ** _height);\n\n stakes[msg.sender] = Stake({\n overlay: _newOverlay,\n committedStake: updatedCommittedStake,\n potentialStake: updatedPotentialStake,\n lastUpdatedBlockNumber: block.number,\n height: _height\n });\n\n // Transfer tokens and emit event that stake has been updated\n if (_addAmount > 0) {\n if (!ERC20(bzzToken).transferFrom(msg.sender, address(this), _addAmount)) revert TransferFailed();\n emit StakeUpdated(\n msg.sender,\n updatedCommittedStake,\n updatedPotentialStake,\n _newOverlay,\n block.number,\n _height\n );\n }\n\n // Emit overlay change event\n if (_previousOverlay != _newOverlay) {\n emit OverlayChanged(msg.sender, _newOverlay);\n }\n }\n\n /**\n * @dev Withdraw node stake surplus\n */\n function withdrawFromStake() external {\n uint256 _potentialStake = stakes[msg.sender].potentialStake;\n uint256 _surplusStake = _potentialStake -\n calculateEffectiveStake(stakes[msg.sender].committedStake, _potentialStake, stakes[msg.sender].height);\n\n if (_surplusStake > 0) {\n stakes[msg.sender].potentialStake -= _surplusStake;\n if (!ERC20(bzzToken).transfer(msg.sender, _surplusStake)) revert TransferFailed();\n emit StakeWithdrawn(msg.sender, _surplusStake);\n }\n }\n\n /**\n * @dev Migrate stake only when the staking contract is paused,\n * can only be called by the owner of the stake\n */\n function migrateStake() external whenPaused {\n // We take out all the stake so user can migrate stake to other contract\n if (lastUpdatedBlockNumberOfAddress(msg.sender) != 0) {\n if (!ERC20(bzzToken).transfer(msg.sender, stakes[msg.sender].potentialStake)) revert TransferFailed();\n delete stakes[msg.sender];\n }\n }\n\n /**\n * @dev Freeze an existing stake, can only be called by the redistributor\n * @param _owner the addres selected\n * @param _time penalty length in blocknumbers\n */\n function freezeDeposit(address _owner, uint256 _time) external {\n if (!hasRole(REDISTRIBUTOR_ROLE, msg.sender)) revert OnlyRedistributor();\n\n if (stakes[_owner].lastUpdatedBlockNumber != 0) {\n stakes[_owner].lastUpdatedBlockNumber = block.number + _time;\n emit StakeFrozen(_owner, stakes[_owner].overlay, _time);\n }\n }\n\n /**\n * @dev Slash an existing stake, can only be called by the `redistributor`\n * @param _owner the _owner adress selected\n * @param _amount the amount to be slashed\n */\n function slashDeposit(address _owner, uint256 _amount) external {\n if (!hasRole(REDISTRIBUTOR_ROLE, msg.sender)) revert OnlyRedistributor();\n\n if (stakes[_owner].lastUpdatedBlockNumber != 0) {\n if (stakes[_owner].potentialStake > _amount) {\n stakes[_owner].potentialStake -= _amount;\n stakes[_owner].lastUpdatedBlockNumber = block.number;\n } else {\n delete stakes[_owner];\n }\n }\n emit StakeSlashed(_owner, stakes[_owner].overlay, _amount);\n }\n\n function changeNetworkId(uint64 _NetworkId) external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) revert Unauthorized();\n NetworkId = _NetworkId;\n }\n\n /**\n * @dev Pause the contract. The contract is provably stopped by renouncing\n the pauser role and the admin role after pausing, can only be called by the `PAUSER`\n */\n function pause() public {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) revert OnlyPauser();\n _pause();\n }\n\n /**\n * @dev Unpause the contract, can only be called by the pauser when paused\n */\n function unPause() public {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) revert OnlyPauser();\n _unpause();\n }\n\n ////////////////////////////////////////\n // STATE READING //\n ////////////////////////////////////////\n\n /**\n * @dev Checks to see if `address` is frozen.\n * @param _owner owner of staked address\n *\n * Returns a boolean value indicating whether the operation succeeded.\n */\n function addressNotFrozen(address _owner) internal view returns (bool) {\n return stakes[_owner].lastUpdatedBlockNumber < block.number;\n }\n\n /**\n * @dev Returns the current `effectiveStake` of `address`. previously usable stake\n * @param _owner _owner of node\n */\n function nodeEffectiveStake(address _owner) public view returns (uint256) {\n return\n addressNotFrozen(_owner)\n ? calculateEffectiveStake(\n stakes[_owner].committedStake,\n stakes[_owner].potentialStake,\n stakes[_owner].height\n )\n : 0;\n }\n\n /**\n * @dev Check the amount that is possible to withdraw as surplus\n */\n function withdrawableStake() public view returns (uint256) {\n uint256 _potentialStake = stakes[msg.sender].potentialStake;\n return\n _potentialStake -\n calculateEffectiveStake(stakes[msg.sender].committedStake, _potentialStake, stakes[msg.sender].height);\n }\n\n /**\n * @dev Returns the `lastUpdatedBlockNumber` of `address`.\n */\n function lastUpdatedBlockNumberOfAddress(address _owner) public view returns (uint256) {\n return stakes[_owner].lastUpdatedBlockNumber;\n }\n\n /**\n * @dev Returns the currently used overlay of the address.\n * @param _owner address of node\n */\n function overlayOfAddress(address _owner) public view returns (bytes32) {\n return stakes[_owner].overlay;\n }\n\n /**\n * @dev Returns the currently height of the address.\n * @param _owner address of node\n */\n function heightOfAddress(address _owner) public view returns (uint8) {\n return stakes[_owner].height;\n }\n\n function calculateEffectiveStake(\n uint256 committedStake,\n uint256 potentialStakeBalance,\n uint8 height\n ) internal view returns (uint256) {\n // Calculate the product of committedStake and unitPrice to get price in BZZ\n uint256 committedStakeBzz = (2 ** height) * committedStake * OracleContract.currentPrice();\n\n // Return the minimum value between committedStakeBzz and potentialStakeBalance\n if (committedStakeBzz < potentialStakeBalance) {\n return committedStakeBzz;\n } else {\n return potentialStakeBalance;\n }\n }\n\n /**\n * @dev Please both Endians 🥚.\n * @param input Eth address used for overlay calculation.\n */\n function reverse(uint64 input) internal pure returns (uint64 v) {\n v = input;\n\n // swap bytes\n v = ((v & 0xFF00FF00FF00FF00) >> 8) | ((v & 0x00FF00FF00FF00FF) << 8);\n\n // swap 2-byte long pairs\n v = ((v & 0xFFFF0000FFFF0000) >> 16) | ((v & 0x0000FFFF0000FFFF) << 16);\n\n // swap 4-byte long pairs\n v = (v >> 32) | (v << 32);\n }\n}\n" + }, + "src/TestToken.sol": { + "content": "// SPDX-License-Identifier: BSD-3-Clause\npragma solidity ^0.8.19;\n\nimport \"@openzeppelin/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol\";\n\ncontract TestToken is ERC20PresetMinterPauser {\n uint256 private _initialSupply;\n\n constructor(string memory name, string memory symbol, uint256 initialSupply) ERC20PresetMinterPauser(name, symbol) {\n _initialSupply = initialSupply;\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n _mint(msg.sender, initialSupply);\n }\n\n // We use 16 decimals for BZZ/sBZZ token so we need to override it here\n function decimals() public view virtual override returns (uint8) {\n return 16;\n }\n}\n" + }, + "src/Util/ChunkProof.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\nlibrary BMTChunk {\n // max chunk payload size\n uint256 public constant MAX_CHUNK_PAYLOAD_SIZE = 4096;\n // segment byte size\n uint256 public constant SEGMENT_SIZE = 32;\n\n /**\n * @notice Changes the endianness of a uint64.\n * @dev https://graphics.stanford.edu/~seander/bithacks.html#ReverseParallel\n * @param _b The unsigned integer to reverse\n * @return v - The reversed value\n */\n function reverseUint64(uint64 _b) public pure returns (uint64) {\n uint256 v = _b;\n\n // swap bytes\n v =\n ((v >> 8) & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) |\n ((v & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) << 8);\n // swap 2-byte long pairs\n v =\n ((v >> 16) & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) |\n ((v & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) << 16);\n // swap 4-byte long pairs\n v =\n ((v >> 32) & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) |\n ((v & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) << 32);\n\n return uint64(v);\n }\n\n /** Calculates the root hash from the provided inclusion proof segments and its corresponding segment index\n * @param _proofSegments Proof segments.\n * @param _proveSegment Segment to prove.\n * @param _proveSegmentIndex Prove segment index\n * @return _calculatedHash chunk hash\n */\n function rootHashFromInclusionProof(\n bytes32[] memory _proofSegments,\n bytes32 _proveSegment,\n uint256 _proveSegmentIndex\n ) internal pure returns (bytes32 _calculatedHash) {\n _calculatedHash = _proveSegment;\n for (uint256 i = 0; i < _proofSegments.length; i++) {\n bool mergeFromRight = _proveSegmentIndex % 2 == 0;\n _calculatedHash = mergeSegment(_calculatedHash, _proofSegments[i], mergeFromRight);\n _proveSegmentIndex >>= 1;\n }\n return _calculatedHash;\n }\n\n /**\n * Calculate the chunk address from the Binary Merkle Tree of the chunk data\n *\n * The BMT chunk address is the hash of the 8 byte span and the root\n * hash of a binary Merkle tree (BMT) built on the 32-byte segments\n * of the underlying data.\n * @param _proofSegments Proof segments.\n * @param _proveSegment Segment to prove.\n * @param _proveSegmentIndex Prove segment index\n * @param _chunkSpan chunk bytes length\n * @return _chunkHash chunk hash\n */\n function chunkAddressFromInclusionProof(\n bytes32[] memory _proofSegments,\n bytes32 _proveSegment,\n uint256 _proveSegmentIndex,\n uint64 _chunkSpan\n ) internal pure returns (bytes32) {\n bytes32 rootHash = rootHashFromInclusionProof(_proofSegments, _proveSegment, _proveSegmentIndex);\n return keccak256(abi.encodePacked(reverseUint64(_chunkSpan), rootHash));\n }\n\n function mergeSegment(\n bytes32 _calculatedHash,\n bytes32 _proofSegment,\n bool mergeFromRight\n ) internal pure returns (bytes32 res) {\n if (mergeFromRight) {\n res = keccak256(abi.encode(_calculatedHash, _proofSegment));\n } else {\n res = keccak256(abi.encode(_proofSegment, _calculatedHash));\n }\n return res;\n }\n}\n" + }, + "src/Util/Signatures.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\nlibrary Signatures {\n error InvalidSignatureLength();\n\n /** Hash of the message to sign */\n function getPostageMessageHash(\n bytes32 _chunkAddr,\n bytes32 _batchId,\n uint64 _index,\n uint64 _timeStamp\n ) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(_chunkAddr, _batchId, _index, _timeStamp));\n }\n\n function postageVerify(\n address _signer, // signer Ethereum address to check against\n bytes memory _signature,\n bytes32 _chunkAddr,\n bytes32 _postageId,\n uint64 _index,\n uint64 _timeStamp\n ) internal pure returns (bool) {\n bytes32 messageHash = getPostageMessageHash(_chunkAddr, _postageId, _index, _timeStamp);\n bytes32 ethMessageHash = getEthSignedMessageHash(messageHash);\n\n return recoverSigner(ethMessageHash, _signature) == _signer;\n }\n\n function getEthSignedMessageHash(bytes32 _messageHash) internal pure returns (bytes32) {\n /*\n Signature is produced by signing a keccak256 hash with the following format:\n \"\\x19Ethereum Signed Message\\n\" + len(msg) + msg\n */\n return keccak256(abi.encodePacked(\"\\x19Ethereum Signed Message:\\n32\", _messageHash));\n }\n\n function recoverSigner(\n bytes32 _ethSignedMessageHash, // it has to be prefixed message: https://ethereum.stackexchange.com/questions/19582/does-ecrecover-in-solidity-expects-the-x19ethereum-signed-message-n-prefix/21037\n bytes memory _signature\n ) internal pure returns (address) {\n (bytes32 r, bytes32 s, uint8 v) = splitSignature(_signature);\n\n return ecrecover(_ethSignedMessageHash, v, r, s);\n }\n\n function splitSignature(bytes memory sig) internal pure returns (bytes32 r_, bytes32 s_, uint8 v_) {\n if (sig.length != 65) {\n revert InvalidSignatureLength();\n }\n\n assembly {\n /*\n verbose explanation: https://ethereum.stackexchange.com/questions/135591/split-signature-function-in-solidity-by-example-docs\n First 32 bytes stores the length of the signature\n add(sig, 32) = pointer of sig + 32\n effectively, skips first 32 bytes of signature\n mload(p) loads next 32 bytes starting at the memory address p into memory\n */\n\n // first 32 bytes, after the length prefix\n r_ := mload(add(sig, 32))\n // second 32 bytes\n s_ := mload(add(sig, 64))\n // final byte (first byte of the next 32 bytes)\n v_ := byte(0, mload(add(sig, 96)))\n }\n\n // implicitly return (r, s, v)\n }\n\n function getSocMessageHash(bytes32 _identifier, bytes32 _chunkAddr) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(_identifier, _chunkAddr));\n }\n\n function socVerify(\n address _signer, // signer Ethereum address to check against\n bytes memory _signature,\n bytes32 _identifier,\n bytes32 _chunkAddr\n ) internal pure returns (bool) {\n bytes32 messageHash = getSocMessageHash(_identifier, _chunkAddr);\n bytes32 ethMessageHash = getEthSignedMessageHash(messageHash);\n\n return recoverSigner(ethMessageHash, _signature) == _signer;\n }\n}\n" + }, + "src/Util/TransformedChunkProof.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\nlibrary TransformedBMTChunk {\n // max chunk payload size\n uint256 public constant MAX_CHUNK_PAYLOAD_SIZE = 4096;\n // segment byte size\n uint256 public constant SEGMENT_SIZE = 32;\n\n /** Calculates the root hash from the provided inclusion proof segments and its corresponding segment index\n * @param _proofSegments Proof segments.\n * @param _proveSegment Segment to prove.\n * @param _proveSegmentIndex Prove segment index\n * @return _calculatedHash chunk hash\n */\n function transformedRootHashFromInclusionProof(\n bytes32[] memory _proofSegments,\n bytes32 _proveSegment,\n uint256 _proveSegmentIndex,\n bytes32 key\n ) internal pure returns (bytes32 _calculatedHash) {\n _calculatedHash = _proveSegment;\n for (uint256 i = 0; i < _proofSegments.length; i++) {\n bool mergeFromRight = _proveSegmentIndex % 2 == 0 ? true : false;\n _calculatedHash = transformedMergeSegment(_calculatedHash, _proofSegments[i], mergeFromRight, key);\n _proveSegmentIndex >>= 1;\n }\n\n return _calculatedHash;\n }\n\n /**\n * @notice Changes the endianness of a uint64.\n * @dev https://graphics.stanford.edu/~seander/bithacks.html#ReverseParallel\n * @param _b The unsigned integer to reverse\n * @return v - The reversed value\n */\n function reverseUint64(uint64 _b) public pure returns (uint64) {\n uint256 v = _b;\n\n // swap bytes\n v =\n ((v >> 8) & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) |\n ((v & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) << 8);\n // swap 2-byte long pairs\n v =\n ((v >> 16) & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) |\n ((v & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) << 16);\n // swap 4-byte long pairs\n v =\n ((v >> 32) & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) |\n ((v & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) << 32);\n\n return uint64(v);\n }\n\n /**\n * Calculate the chunk address from the Binary Merkle Tree of the chunk data\n *\n * The BMT chunk address is the hash of the 8 byte span and the root\n * hash of a binary Merkle tree (BMT) built on the 32-byte segments\n * of the underlying data.\n * @param _proofSegments Proof segments.\n * @param _proveSegment Segment to prove.\n * @param _proveSegmentIndex Prove segment index\n * @param _chunkSpan chunk bytes length\n * @return _chunkHash chunk hash\n */\n function transformedChunkAddressFromInclusionProof(\n bytes32[] memory _proofSegments,\n bytes32 _proveSegment,\n uint256 _proveSegmentIndex,\n uint64 _chunkSpan,\n bytes32 key\n ) internal pure returns (bytes32) {\n bytes32 rootHash = transformedRootHashFromInclusionProof(\n _proofSegments,\n _proveSegment,\n _proveSegmentIndex,\n key\n );\n return keccak256(abi.encodePacked(key, reverseUint64(_chunkSpan), rootHash));\n }\n\n function transformedMergeSegment(\n bytes32 _calculatedHash,\n bytes32 _proofSegment,\n bool mergeFromRight,\n bytes32 key\n ) internal pure returns (bytes32 res) {\n if (mergeFromRight) {\n res = keccak256(abi.encode(key, _calculatedHash, _proofSegment));\n } else {\n res = keccak256(abi.encode(key, _proofSegment, _calculatedHash));\n }\n return res;\n }\n}\n" + } + }, + "settings": { + "optimizer": { + "enabled": true, + "runs": 1000 + }, + "outputSelection": { + "*": { + "*": [ + "abi", + "evm.bytecode", + "evm.deployedBytecode", + "evm.methodIdentifiers", + "metadata", + "devdoc", + "userdoc", + "storageLayout", + "evm.gasEstimates" + ], + "": [ + "ast" + ] + } + }, + "metadata": { + "useLiteralContent": true + }, + "libraries": { + "": { + "__CACHE_BREAKER__": "0x00000000d41867734bbee4c6863d9255b2b06ac1" + } + } + } +} \ No newline at end of file diff --git a/deployments/testnet/solcInputs/be98d61f2910c0140b59702042017efa.json b/deployments/testnet/solcInputs/be98d61f2910c0140b59702042017efa.json new file mode 100644 index 00000000..08de023c --- /dev/null +++ b/deployments/testnet/solcInputs/be98d61f2910c0140b59702042017efa.json @@ -0,0 +1,118 @@ +{ + "language": "Solidity", + "sources": { + "@openzeppelin/contracts/access/AccessControl.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (access/AccessControl.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IAccessControl.sol\";\nimport \"../utils/Context.sol\";\nimport \"../utils/Strings.sol\";\nimport \"../utils/introspection/ERC165.sol\";\n\n/**\n * @dev Contract module that allows children to implement role-based access\n * control mechanisms. This is a lightweight version that doesn't allow enumerating role\n * members except through off-chain means by accessing the contract event logs. Some\n * applications may benefit from on-chain enumerability, for those cases see\n * {AccessControlEnumerable}.\n *\n * Roles are referred to by their `bytes32` identifier. These should be exposed\n * in the external API and be unique. The best way to achieve this is by\n * using `public constant` hash digests:\n *\n * ```\n * bytes32 public constant MY_ROLE = keccak256(\"MY_ROLE\");\n * ```\n *\n * Roles can be used to represent a set of permissions. To restrict access to a\n * function call, use {hasRole}:\n *\n * ```\n * function foo() public {\n * require(hasRole(MY_ROLE, msg.sender));\n * ...\n * }\n * ```\n *\n * Roles can be granted and revoked dynamically via the {grantRole} and\n * {revokeRole} functions. Each role has an associated admin role, and only\n * accounts that have a role's admin role can call {grantRole} and {revokeRole}.\n *\n * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means\n * that only accounts with this role will be able to grant or revoke other\n * roles. More complex role relationships can be created by using\n * {_setRoleAdmin}.\n *\n * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to\n * grant and revoke this role. Extra precautions should be taken to secure\n * accounts that have been granted it.\n */\nabstract contract AccessControl is Context, IAccessControl, ERC165 {\n struct RoleData {\n mapping(address => bool) members;\n bytes32 adminRole;\n }\n\n mapping(bytes32 => RoleData) private _roles;\n\n bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;\n\n /**\n * @dev Modifier that checks that an account has a specific role. Reverts\n * with a standardized message including the required role.\n *\n * The format of the revert reason is given by the following regular expression:\n *\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\n *\n * _Available since v4.1._\n */\n modifier onlyRole(bytes32 role) {\n _checkRole(role);\n _;\n }\n\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);\n }\n\n /**\n * @dev Returns `true` if `account` has been granted `role`.\n */\n function hasRole(bytes32 role, address account) public view virtual override returns (bool) {\n return _roles[role].members[account];\n }\n\n /**\n * @dev Revert with a standard message if `_msgSender()` is missing `role`.\n * Overriding this function changes the behavior of the {onlyRole} modifier.\n *\n * Format of the revert message is described in {_checkRole}.\n *\n * _Available since v4.6._\n */\n function _checkRole(bytes32 role) internal view virtual {\n _checkRole(role, _msgSender());\n }\n\n /**\n * @dev Revert with a standard message if `account` is missing `role`.\n *\n * The format of the revert reason is given by the following regular expression:\n *\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\n */\n function _checkRole(bytes32 role, address account) internal view virtual {\n if (!hasRole(role, account)) {\n revert(\n string(\n abi.encodePacked(\n \"AccessControl: account \",\n Strings.toHexString(account),\n \" is missing role \",\n Strings.toHexString(uint256(role), 32)\n )\n )\n );\n }\n }\n\n /**\n * @dev Returns the admin role that controls `role`. See {grantRole} and\n * {revokeRole}.\n *\n * To change a role's admin, use {_setRoleAdmin}.\n */\n function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {\n return _roles[role].adminRole;\n }\n\n /**\n * @dev Grants `role` to `account`.\n *\n * If `account` had not been already granted `role`, emits a {RoleGranted}\n * event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n *\n * May emit a {RoleGranted} event.\n */\n function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\n _grantRole(role, account);\n }\n\n /**\n * @dev Revokes `role` from `account`.\n *\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n *\n * May emit a {RoleRevoked} event.\n */\n function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\n _revokeRole(role, account);\n }\n\n /**\n * @dev Revokes `role` from the calling account.\n *\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\n * purpose is to provide a mechanism for accounts to lose their privileges\n * if they are compromised (such as when a trusted device is misplaced).\n *\n * If the calling account had been revoked `role`, emits a {RoleRevoked}\n * event.\n *\n * Requirements:\n *\n * - the caller must be `account`.\n *\n * May emit a {RoleRevoked} event.\n */\n function renounceRole(bytes32 role, address account) public virtual override {\n require(account == _msgSender(), \"AccessControl: can only renounce roles for self\");\n\n _revokeRole(role, account);\n }\n\n /**\n * @dev Grants `role` to `account`.\n *\n * If `account` had not been already granted `role`, emits a {RoleGranted}\n * event. Note that unlike {grantRole}, this function doesn't perform any\n * checks on the calling account.\n *\n * May emit a {RoleGranted} event.\n *\n * [WARNING]\n * ====\n * This function should only be called from the constructor when setting\n * up the initial roles for the system.\n *\n * Using this function in any other way is effectively circumventing the admin\n * system imposed by {AccessControl}.\n * ====\n *\n * NOTE: This function is deprecated in favor of {_grantRole}.\n */\n function _setupRole(bytes32 role, address account) internal virtual {\n _grantRole(role, account);\n }\n\n /**\n * @dev Sets `adminRole` as ``role``'s admin role.\n *\n * Emits a {RoleAdminChanged} event.\n */\n function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {\n bytes32 previousAdminRole = getRoleAdmin(role);\n _roles[role].adminRole = adminRole;\n emit RoleAdminChanged(role, previousAdminRole, adminRole);\n }\n\n /**\n * @dev Grants `role` to `account`.\n *\n * Internal function without access restriction.\n *\n * May emit a {RoleGranted} event.\n */\n function _grantRole(bytes32 role, address account) internal virtual {\n if (!hasRole(role, account)) {\n _roles[role].members[account] = true;\n emit RoleGranted(role, account, _msgSender());\n }\n }\n\n /**\n * @dev Revokes `role` from `account`.\n *\n * Internal function without access restriction.\n *\n * May emit a {RoleRevoked} event.\n */\n function _revokeRole(bytes32 role, address account) internal virtual {\n if (hasRole(role, account)) {\n _roles[role].members[account] = false;\n emit RoleRevoked(role, account, _msgSender());\n }\n }\n}\n" + }, + "@openzeppelin/contracts/access/AccessControlEnumerable.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (access/AccessControlEnumerable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IAccessControlEnumerable.sol\";\nimport \"./AccessControl.sol\";\nimport \"../utils/structs/EnumerableSet.sol\";\n\n/**\n * @dev Extension of {AccessControl} that allows enumerating the members of each role.\n */\nabstract contract AccessControlEnumerable is IAccessControlEnumerable, AccessControl {\n using EnumerableSet for EnumerableSet.AddressSet;\n\n mapping(bytes32 => EnumerableSet.AddressSet) private _roleMembers;\n\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n return interfaceId == type(IAccessControlEnumerable).interfaceId || super.supportsInterface(interfaceId);\n }\n\n /**\n * @dev Returns one of the accounts that have `role`. `index` must be a\n * value between 0 and {getRoleMemberCount}, non-inclusive.\n *\n * Role bearers are not sorted in any particular way, and their ordering may\n * change at any point.\n *\n * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure\n * you perform all queries on the same block. See the following\n * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]\n * for more information.\n */\n function getRoleMember(bytes32 role, uint256 index) public view virtual override returns (address) {\n return _roleMembers[role].at(index);\n }\n\n /**\n * @dev Returns the number of accounts that have `role`. Can be used\n * together with {getRoleMember} to enumerate all bearers of a role.\n */\n function getRoleMemberCount(bytes32 role) public view virtual override returns (uint256) {\n return _roleMembers[role].length();\n }\n\n /**\n * @dev Overload {_grantRole} to track enumerable memberships\n */\n function _grantRole(bytes32 role, address account) internal virtual override {\n super._grantRole(role, account);\n _roleMembers[role].add(account);\n }\n\n /**\n * @dev Overload {_revokeRole} to track enumerable memberships\n */\n function _revokeRole(bytes32 role, address account) internal virtual override {\n super._revokeRole(role, account);\n _roleMembers[role].remove(account);\n }\n}\n" + }, + "@openzeppelin/contracts/access/IAccessControl.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev External interface of AccessControl declared to support ERC165 detection.\n */\ninterface IAccessControl {\n /**\n * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`\n *\n * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite\n * {RoleAdminChanged} not being emitted signaling this.\n *\n * _Available since v3.1._\n */\n event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);\n\n /**\n * @dev Emitted when `account` is granted `role`.\n *\n * `sender` is the account that originated the contract call, an admin role\n * bearer except when using {AccessControl-_setupRole}.\n */\n event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);\n\n /**\n * @dev Emitted when `account` is revoked `role`.\n *\n * `sender` is the account that originated the contract call:\n * - if using `revokeRole`, it is the admin role bearer\n * - if using `renounceRole`, it is the role bearer (i.e. `account`)\n */\n event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);\n\n /**\n * @dev Returns `true` if `account` has been granted `role`.\n */\n function hasRole(bytes32 role, address account) external view returns (bool);\n\n /**\n * @dev Returns the admin role that controls `role`. See {grantRole} and\n * {revokeRole}.\n *\n * To change a role's admin, use {AccessControl-_setRoleAdmin}.\n */\n function getRoleAdmin(bytes32 role) external view returns (bytes32);\n\n /**\n * @dev Grants `role` to `account`.\n *\n * If `account` had not been already granted `role`, emits a {RoleGranted}\n * event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n */\n function grantRole(bytes32 role, address account) external;\n\n /**\n * @dev Revokes `role` from `account`.\n *\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n */\n function revokeRole(bytes32 role, address account) external;\n\n /**\n * @dev Revokes `role` from the calling account.\n *\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\n * purpose is to provide a mechanism for accounts to lose their privileges\n * if they are compromised (such as when a trusted device is misplaced).\n *\n * If the calling account had been granted `role`, emits a {RoleRevoked}\n * event.\n *\n * Requirements:\n *\n * - the caller must be `account`.\n */\n function renounceRole(bytes32 role, address account) external;\n}\n" + }, + "@openzeppelin/contracts/access/IAccessControlEnumerable.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (access/IAccessControlEnumerable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IAccessControl.sol\";\n\n/**\n * @dev External interface of AccessControlEnumerable declared to support ERC165 detection.\n */\ninterface IAccessControlEnumerable is IAccessControl {\n /**\n * @dev Returns one of the accounts that have `role`. `index` must be a\n * value between 0 and {getRoleMemberCount}, non-inclusive.\n *\n * Role bearers are not sorted in any particular way, and their ordering may\n * change at any point.\n *\n * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure\n * you perform all queries on the same block. See the following\n * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]\n * for more information.\n */\n function getRoleMember(bytes32 role, uint256 index) external view returns (address);\n\n /**\n * @dev Returns the number of accounts that have `role`. Can be used\n * together with {getRoleMember} to enumerate all bearers of a role.\n */\n function getRoleMemberCount(bytes32 role) external view returns (uint256);\n}\n" + }, + "@openzeppelin/contracts/security/Pausable.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which allows children to implement an emergency stop\n * mechanism that can be triggered by an authorized account.\n *\n * This module is used through inheritance. It will make available the\n * modifiers `whenNotPaused` and `whenPaused`, which can be applied to\n * the functions of your contract. Note that they will not be pausable by\n * simply including this module, only once the modifiers are put in place.\n */\nabstract contract Pausable is Context {\n /**\n * @dev Emitted when the pause is triggered by `account`.\n */\n event Paused(address account);\n\n /**\n * @dev Emitted when the pause is lifted by `account`.\n */\n event Unpaused(address account);\n\n bool private _paused;\n\n /**\n * @dev Initializes the contract in unpaused state.\n */\n constructor() {\n _paused = false;\n }\n\n /**\n * @dev Modifier to make a function callable only when the contract is not paused.\n *\n * Requirements:\n *\n * - The contract must not be paused.\n */\n modifier whenNotPaused() {\n _requireNotPaused();\n _;\n }\n\n /**\n * @dev Modifier to make a function callable only when the contract is paused.\n *\n * Requirements:\n *\n * - The contract must be paused.\n */\n modifier whenPaused() {\n _requirePaused();\n _;\n }\n\n /**\n * @dev Returns true if the contract is paused, and false otherwise.\n */\n function paused() public view virtual returns (bool) {\n return _paused;\n }\n\n /**\n * @dev Throws if the contract is paused.\n */\n function _requireNotPaused() internal view virtual {\n require(!paused(), \"Pausable: paused\");\n }\n\n /**\n * @dev Throws if the contract is not paused.\n */\n function _requirePaused() internal view virtual {\n require(paused(), \"Pausable: not paused\");\n }\n\n /**\n * @dev Triggers stopped state.\n *\n * Requirements:\n *\n * - The contract must not be paused.\n */\n function _pause() internal virtual whenNotPaused {\n _paused = true;\n emit Paused(_msgSender());\n }\n\n /**\n * @dev Returns to normal state.\n *\n * Requirements:\n *\n * - The contract must be paused.\n */\n function _unpause() internal virtual whenPaused {\n _paused = false;\n emit Unpaused(_msgSender());\n }\n}\n" + }, + "@openzeppelin/contracts/token/ERC20/ERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/ERC20.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC20.sol\";\nimport \"./extensions/IERC20Metadata.sol\";\nimport \"../../utils/Context.sol\";\n\n/**\n * @dev Implementation of the {IERC20} interface.\n *\n * This implementation is agnostic to the way tokens are created. This means\n * that a supply mechanism has to be added in a derived contract using {_mint}.\n * For a generic mechanism see {ERC20PresetMinterPauser}.\n *\n * TIP: For a detailed writeup see our guide\n * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How\n * to implement supply mechanisms].\n *\n * We have followed general OpenZeppelin Contracts guidelines: functions revert\n * instead returning `false` on failure. This behavior is nonetheless\n * conventional and does not conflict with the expectations of ERC20\n * applications.\n *\n * Additionally, an {Approval} event is emitted on calls to {transferFrom}.\n * This allows applications to reconstruct the allowance for all accounts just\n * by listening to said events. Other implementations of the EIP may not emit\n * these events, as it isn't required by the specification.\n *\n * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}\n * functions have been added to mitigate the well-known issues around setting\n * allowances. See {IERC20-approve}.\n */\ncontract ERC20 is Context, IERC20, IERC20Metadata {\n mapping(address => uint256) private _balances;\n\n mapping(address => mapping(address => uint256)) private _allowances;\n\n uint256 private _totalSupply;\n\n string private _name;\n string private _symbol;\n\n /**\n * @dev Sets the values for {name} and {symbol}.\n *\n * The default value of {decimals} is 18. To select a different value for\n * {decimals} you should overload it.\n *\n * All two of these values are immutable: they can only be set once during\n * construction.\n */\n constructor(string memory name_, string memory symbol_) {\n _name = name_;\n _symbol = symbol_;\n }\n\n /**\n * @dev Returns the name of the token.\n */\n function name() public view virtual override returns (string memory) {\n return _name;\n }\n\n /**\n * @dev Returns the symbol of the token, usually a shorter version of the\n * name.\n */\n function symbol() public view virtual override returns (string memory) {\n return _symbol;\n }\n\n /**\n * @dev Returns the number of decimals used to get its user representation.\n * For example, if `decimals` equals `2`, a balance of `505` tokens should\n * be displayed to a user as `5.05` (`505 / 10 ** 2`).\n *\n * Tokens usually opt for a value of 18, imitating the relationship between\n * Ether and Wei. This is the value {ERC20} uses, unless this function is\n * overridden;\n *\n * NOTE: This information is only used for _display_ purposes: it in\n * no way affects any of the arithmetic of the contract, including\n * {IERC20-balanceOf} and {IERC20-transfer}.\n */\n function decimals() public view virtual override returns (uint8) {\n return 18;\n }\n\n /**\n * @dev See {IERC20-totalSupply}.\n */\n function totalSupply() public view virtual override returns (uint256) {\n return _totalSupply;\n }\n\n /**\n * @dev See {IERC20-balanceOf}.\n */\n function balanceOf(address account) public view virtual override returns (uint256) {\n return _balances[account];\n }\n\n /**\n * @dev See {IERC20-transfer}.\n *\n * Requirements:\n *\n * - `to` cannot be the zero address.\n * - the caller must have a balance of at least `amount`.\n */\n function transfer(address to, uint256 amount) public virtual override returns (bool) {\n address owner = _msgSender();\n _transfer(owner, to, amount);\n return true;\n }\n\n /**\n * @dev See {IERC20-allowance}.\n */\n function allowance(address owner, address spender) public view virtual override returns (uint256) {\n return _allowances[owner][spender];\n }\n\n /**\n * @dev See {IERC20-approve}.\n *\n * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on\n * `transferFrom`. This is semantically equivalent to an infinite approval.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function approve(address spender, uint256 amount) public virtual override returns (bool) {\n address owner = _msgSender();\n _approve(owner, spender, amount);\n return true;\n }\n\n /**\n * @dev See {IERC20-transferFrom}.\n *\n * Emits an {Approval} event indicating the updated allowance. This is not\n * required by the EIP. See the note at the beginning of {ERC20}.\n *\n * NOTE: Does not update the allowance if the current allowance\n * is the maximum `uint256`.\n *\n * Requirements:\n *\n * - `from` and `to` cannot be the zero address.\n * - `from` must have a balance of at least `amount`.\n * - the caller must have allowance for ``from``'s tokens of at least\n * `amount`.\n */\n function transferFrom(\n address from,\n address to,\n uint256 amount\n ) public virtual override returns (bool) {\n address spender = _msgSender();\n _spendAllowance(from, spender, amount);\n _transfer(from, to, amount);\n return true;\n }\n\n /**\n * @dev Atomically increases the allowance granted to `spender` by the caller.\n *\n * This is an alternative to {approve} that can be used as a mitigation for\n * problems described in {IERC20-approve}.\n *\n * Emits an {Approval} event indicating the updated allowance.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {\n address owner = _msgSender();\n _approve(owner, spender, allowance(owner, spender) + addedValue);\n return true;\n }\n\n /**\n * @dev Atomically decreases the allowance granted to `spender` by the caller.\n *\n * This is an alternative to {approve} that can be used as a mitigation for\n * problems described in {IERC20-approve}.\n *\n * Emits an {Approval} event indicating the updated allowance.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n * - `spender` must have allowance for the caller of at least\n * `subtractedValue`.\n */\n function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {\n address owner = _msgSender();\n uint256 currentAllowance = allowance(owner, spender);\n require(currentAllowance >= subtractedValue, \"ERC20: decreased allowance below zero\");\n unchecked {\n _approve(owner, spender, currentAllowance - subtractedValue);\n }\n\n return true;\n }\n\n /**\n * @dev Moves `amount` of tokens from `from` to `to`.\n *\n * This internal function is equivalent to {transfer}, and can be used to\n * e.g. implement automatic token fees, slashing mechanisms, etc.\n *\n * Emits a {Transfer} event.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `from` must have a balance of at least `amount`.\n */\n function _transfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual {\n require(from != address(0), \"ERC20: transfer from the zero address\");\n require(to != address(0), \"ERC20: transfer to the zero address\");\n\n _beforeTokenTransfer(from, to, amount);\n\n uint256 fromBalance = _balances[from];\n require(fromBalance >= amount, \"ERC20: transfer amount exceeds balance\");\n unchecked {\n _balances[from] = fromBalance - amount;\n // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by\n // decrementing then incrementing.\n _balances[to] += amount;\n }\n\n emit Transfer(from, to, amount);\n\n _afterTokenTransfer(from, to, amount);\n }\n\n /** @dev Creates `amount` tokens and assigns them to `account`, increasing\n * the total supply.\n *\n * Emits a {Transfer} event with `from` set to the zero address.\n *\n * Requirements:\n *\n * - `account` cannot be the zero address.\n */\n function _mint(address account, uint256 amount) internal virtual {\n require(account != address(0), \"ERC20: mint to the zero address\");\n\n _beforeTokenTransfer(address(0), account, amount);\n\n _totalSupply += amount;\n unchecked {\n // Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.\n _balances[account] += amount;\n }\n emit Transfer(address(0), account, amount);\n\n _afterTokenTransfer(address(0), account, amount);\n }\n\n /**\n * @dev Destroys `amount` tokens from `account`, reducing the\n * total supply.\n *\n * Emits a {Transfer} event with `to` set to the zero address.\n *\n * Requirements:\n *\n * - `account` cannot be the zero address.\n * - `account` must have at least `amount` tokens.\n */\n function _burn(address account, uint256 amount) internal virtual {\n require(account != address(0), \"ERC20: burn from the zero address\");\n\n _beforeTokenTransfer(account, address(0), amount);\n\n uint256 accountBalance = _balances[account];\n require(accountBalance >= amount, \"ERC20: burn amount exceeds balance\");\n unchecked {\n _balances[account] = accountBalance - amount;\n // Overflow not possible: amount <= accountBalance <= totalSupply.\n _totalSupply -= amount;\n }\n\n emit Transfer(account, address(0), amount);\n\n _afterTokenTransfer(account, address(0), amount);\n }\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.\n *\n * This internal function is equivalent to `approve`, and can be used to\n * e.g. set automatic allowances for certain subsystems, etc.\n *\n * Emits an {Approval} event.\n *\n * Requirements:\n *\n * - `owner` cannot be the zero address.\n * - `spender` cannot be the zero address.\n */\n function _approve(\n address owner,\n address spender,\n uint256 amount\n ) internal virtual {\n require(owner != address(0), \"ERC20: approve from the zero address\");\n require(spender != address(0), \"ERC20: approve to the zero address\");\n\n _allowances[owner][spender] = amount;\n emit Approval(owner, spender, amount);\n }\n\n /**\n * @dev Updates `owner` s allowance for `spender` based on spent `amount`.\n *\n * Does not update the allowance amount in case of infinite allowance.\n * Revert if not enough allowance is available.\n *\n * Might emit an {Approval} event.\n */\n function _spendAllowance(\n address owner,\n address spender,\n uint256 amount\n ) internal virtual {\n uint256 currentAllowance = allowance(owner, spender);\n if (currentAllowance != type(uint256).max) {\n require(currentAllowance >= amount, \"ERC20: insufficient allowance\");\n unchecked {\n _approve(owner, spender, currentAllowance - amount);\n }\n }\n }\n\n /**\n * @dev Hook that is called before any transfer of tokens. This includes\n * minting and burning.\n *\n * Calling conditions:\n *\n * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n * will be transferred to `to`.\n * - when `from` is zero, `amount` tokens will be minted for `to`.\n * - when `to` is zero, `amount` of ``from``'s tokens will be burned.\n * - `from` and `to` are never both zero.\n *\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n */\n function _beforeTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual {}\n\n /**\n * @dev Hook that is called after any transfer of tokens. This includes\n * minting and burning.\n *\n * Calling conditions:\n *\n * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n * has been transferred to `to`.\n * - when `from` is zero, `amount` tokens have been minted for `to`.\n * - when `to` is zero, `amount` of ``from``'s tokens have been burned.\n * - `from` and `to` are never both zero.\n *\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n */\n function _afterTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual {}\n}\n" + }, + "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/extensions/ERC20Burnable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../ERC20.sol\";\nimport \"../../../utils/Context.sol\";\n\n/**\n * @dev Extension of {ERC20} that allows token holders to destroy both their own\n * tokens and those that they have an allowance for, in a way that can be\n * recognized off-chain (via event analysis).\n */\nabstract contract ERC20Burnable is Context, ERC20 {\n /**\n * @dev Destroys `amount` tokens from the caller.\n *\n * See {ERC20-_burn}.\n */\n function burn(uint256 amount) public virtual {\n _burn(_msgSender(), amount);\n }\n\n /**\n * @dev Destroys `amount` tokens from `account`, deducting from the caller's\n * allowance.\n *\n * See {ERC20-_burn} and {ERC20-allowance}.\n *\n * Requirements:\n *\n * - the caller must have allowance for ``accounts``'s tokens of at least\n * `amount`.\n */\n function burnFrom(address account, uint256 amount) public virtual {\n _spendAllowance(account, _msgSender(), amount);\n _burn(account, amount);\n }\n}\n" + }, + "@openzeppelin/contracts/token/ERC20/extensions/ERC20Pausable.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.2) (token/ERC20/extensions/ERC20Pausable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../ERC20.sol\";\nimport \"../../../security/Pausable.sol\";\n\n/**\n * @dev ERC20 token with pausable token transfers, minting and burning.\n *\n * Useful for scenarios such as preventing trades until the end of an evaluation\n * period, or having an emergency switch for freezing all token transfers in the\n * event of a large bug.\n *\n * IMPORTANT: This contract does not include public pause and unpause functions. In\n * addition to inheriting this contract, you must define both functions, invoking the\n * {Pausable-_pause} and {Pausable-_unpause} internal functions, with appropriate\n * access control, e.g. using {AccessControl} or {Ownable}. Not doing so will\n * make the contract unpausable.\n */\nabstract contract ERC20Pausable is ERC20, Pausable {\n /**\n * @dev See {ERC20-_beforeTokenTransfer}.\n *\n * Requirements:\n *\n * - the contract must not be paused.\n */\n function _beforeTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual override {\n super._beforeTokenTransfer(from, to, amount);\n\n require(!paused(), \"ERC20Pausable: token transfer while paused\");\n }\n}\n" + }, + "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20.sol\";\n\n/**\n * @dev Interface for the optional metadata functions from the ERC20 standard.\n *\n * _Available since v4.1._\n */\ninterface IERC20Metadata is IERC20 {\n /**\n * @dev Returns the name of the token.\n */\n function name() external view returns (string memory);\n\n /**\n * @dev Returns the symbol of the token.\n */\n function symbol() external view returns (string memory);\n\n /**\n * @dev Returns the decimals places of the token.\n */\n function decimals() external view returns (uint8);\n}\n" + }, + "@openzeppelin/contracts/token/ERC20/IERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n /**\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\n * another (`to`).\n *\n * Note that `value` may be zero.\n */\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n /**\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n * a call to {approve}. `value` is the new allowance.\n */\n event Approval(address indexed owner, address indexed spender, uint256 value);\n\n /**\n * @dev Returns the amount of tokens in existence.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns the amount of tokens owned by `account`.\n */\n function balanceOf(address account) external view returns (uint256);\n\n /**\n * @dev Moves `amount` tokens from the caller's account to `to`.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transfer(address to, uint256 amount) external returns (bool);\n\n /**\n * @dev Returns the remaining number of tokens that `spender` will be\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\n * zero by default.\n *\n * This value changes when {approve} or {transferFrom} are called.\n */\n function allowance(address owner, address spender) external view returns (uint256);\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\n * that someone may use both the old and the new allowance by unfortunate\n * transaction ordering. One possible solution to mitigate this race\n * condition is to first reduce the spender's allowance to 0 and set the\n * desired value afterwards:\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n *\n * Emits an {Approval} event.\n */\n function approve(address spender, uint256 amount) external returns (bool);\n\n /**\n * @dev Moves `amount` tokens from `from` to `to` using the\n * allowance mechanism. `amount` is then deducted from the caller's\n * allowance.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(\n address from,\n address to,\n uint256 amount\n ) external returns (bool);\n}\n" + }, + "@openzeppelin/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/presets/ERC20PresetMinterPauser.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../ERC20.sol\";\nimport \"../extensions/ERC20Burnable.sol\";\nimport \"../extensions/ERC20Pausable.sol\";\nimport \"../../../access/AccessControlEnumerable.sol\";\nimport \"../../../utils/Context.sol\";\n\n/**\n * @dev {ERC20} token, including:\n *\n * - ability for holders to burn (destroy) their tokens\n * - a minter role that allows for token minting (creation)\n * - a pauser role that allows to stop all token transfers\n *\n * This contract uses {AccessControl} to lock permissioned functions using the\n * different roles - head to its documentation for details.\n *\n * The account that deploys the contract will be granted the minter and pauser\n * roles, as well as the default admin role, which will let it grant both minter\n * and pauser roles to other accounts.\n *\n * _Deprecated in favor of https://wizard.openzeppelin.com/[Contracts Wizard]._\n */\ncontract ERC20PresetMinterPauser is Context, AccessControlEnumerable, ERC20Burnable, ERC20Pausable {\n bytes32 public constant MINTER_ROLE = keccak256(\"MINTER_ROLE\");\n bytes32 public constant PAUSER_ROLE = keccak256(\"PAUSER_ROLE\");\n\n /**\n * @dev Grants `DEFAULT_ADMIN_ROLE`, `MINTER_ROLE` and `PAUSER_ROLE` to the\n * account that deploys the contract.\n *\n * See {ERC20-constructor}.\n */\n constructor(string memory name, string memory symbol) ERC20(name, symbol) {\n _setupRole(DEFAULT_ADMIN_ROLE, _msgSender());\n\n _setupRole(MINTER_ROLE, _msgSender());\n _setupRole(PAUSER_ROLE, _msgSender());\n }\n\n /**\n * @dev Creates `amount` new tokens for `to`.\n *\n * See {ERC20-_mint}.\n *\n * Requirements:\n *\n * - the caller must have the `MINTER_ROLE`.\n */\n function mint(address to, uint256 amount) public virtual {\n require(hasRole(MINTER_ROLE, _msgSender()), \"ERC20PresetMinterPauser: must have minter role to mint\");\n _mint(to, amount);\n }\n\n /**\n * @dev Pauses all token transfers.\n *\n * See {ERC20Pausable} and {Pausable-_pause}.\n *\n * Requirements:\n *\n * - the caller must have the `PAUSER_ROLE`.\n */\n function pause() public virtual {\n require(hasRole(PAUSER_ROLE, _msgSender()), \"ERC20PresetMinterPauser: must have pauser role to pause\");\n _pause();\n }\n\n /**\n * @dev Unpauses all token transfers.\n *\n * See {ERC20Pausable} and {Pausable-_unpause}.\n *\n * Requirements:\n *\n * - the caller must have the `PAUSER_ROLE`.\n */\n function unpause() public virtual {\n require(hasRole(PAUSER_ROLE, _msgSender()), \"ERC20PresetMinterPauser: must have pauser role to unpause\");\n _unpause();\n }\n\n function _beforeTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual override(ERC20, ERC20Pausable) {\n super._beforeTokenTransfer(from, to, amount);\n }\n}\n" + }, + "@openzeppelin/contracts/utils/Context.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n}\n" + }, + "@openzeppelin/contracts/utils/introspection/ERC165.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC165.sol\";\n\n/**\n * @dev Implementation of the {IERC165} interface.\n *\n * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check\n * for the additional interface id that will be supported. For example:\n *\n * ```solidity\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\n * }\n * ```\n *\n * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.\n */\nabstract contract ERC165 is IERC165 {\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n return interfaceId == type(IERC165).interfaceId;\n }\n}\n" + }, + "@openzeppelin/contracts/utils/introspection/IERC165.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC165 standard, as defined in the\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\n *\n * Implementers can declare support of contract interfaces, which can then be\n * queried by others ({ERC165Checker}).\n *\n * For an implementation, see {ERC165}.\n */\ninterface IERC165 {\n /**\n * @dev Returns true if this contract implements the interface defined by\n * `interfaceId`. See the corresponding\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\n * to learn more about how these ids are created.\n *\n * This function call must use less than 30 000 gas.\n */\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n" + }, + "@openzeppelin/contracts/utils/math/Math.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Standard math utilities missing in the Solidity language.\n */\nlibrary Math {\n enum Rounding {\n Down, // Toward negative infinity\n Up, // Toward infinity\n Zero // Toward zero\n }\n\n /**\n * @dev Returns the largest of two numbers.\n */\n function max(uint256 a, uint256 b) internal pure returns (uint256) {\n return a > b ? a : b;\n }\n\n /**\n * @dev Returns the smallest of two numbers.\n */\n function min(uint256 a, uint256 b) internal pure returns (uint256) {\n return a < b ? a : b;\n }\n\n /**\n * @dev Returns the average of two numbers. The result is rounded towards\n * zero.\n */\n function average(uint256 a, uint256 b) internal pure returns (uint256) {\n // (a + b) / 2 can overflow.\n return (a & b) + (a ^ b) / 2;\n }\n\n /**\n * @dev Returns the ceiling of the division of two numbers.\n *\n * This differs from standard division with `/` in that it rounds up instead\n * of rounding down.\n */\n function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {\n // (a + b - 1) / b can overflow on addition, so we distribute.\n return a == 0 ? 0 : (a - 1) / b + 1;\n }\n\n /**\n * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0\n * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)\n * with further edits by Uniswap Labs also under MIT license.\n */\n function mulDiv(\n uint256 x,\n uint256 y,\n uint256 denominator\n ) internal pure returns (uint256 result) {\n unchecked {\n // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use\n // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256\n // variables such that product = prod1 * 2^256 + prod0.\n uint256 prod0; // Least significant 256 bits of the product\n uint256 prod1; // Most significant 256 bits of the product\n assembly {\n let mm := mulmod(x, y, not(0))\n prod0 := mul(x, y)\n prod1 := sub(sub(mm, prod0), lt(mm, prod0))\n }\n\n // Handle non-overflow cases, 256 by 256 division.\n if (prod1 == 0) {\n return prod0 / denominator;\n }\n\n // Make sure the result is less than 2^256. Also prevents denominator == 0.\n require(denominator > prod1);\n\n ///////////////////////////////////////////////\n // 512 by 256 division.\n ///////////////////////////////////////////////\n\n // Make division exact by subtracting the remainder from [prod1 prod0].\n uint256 remainder;\n assembly {\n // Compute remainder using mulmod.\n remainder := mulmod(x, y, denominator)\n\n // Subtract 256 bit number from 512 bit number.\n prod1 := sub(prod1, gt(remainder, prod0))\n prod0 := sub(prod0, remainder)\n }\n\n // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.\n // See https://cs.stackexchange.com/q/138556/92363.\n\n // Does not overflow because the denominator cannot be zero at this stage in the function.\n uint256 twos = denominator & (~denominator + 1);\n assembly {\n // Divide denominator by twos.\n denominator := div(denominator, twos)\n\n // Divide [prod1 prod0] by twos.\n prod0 := div(prod0, twos)\n\n // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.\n twos := add(div(sub(0, twos), twos), 1)\n }\n\n // Shift in bits from prod1 into prod0.\n prod0 |= prod1 * twos;\n\n // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such\n // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for\n // four bits. That is, denominator * inv = 1 mod 2^4.\n uint256 inverse = (3 * denominator) ^ 2;\n\n // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works\n // in modular arithmetic, doubling the correct bits in each step.\n inverse *= 2 - denominator * inverse; // inverse mod 2^8\n inverse *= 2 - denominator * inverse; // inverse mod 2^16\n inverse *= 2 - denominator * inverse; // inverse mod 2^32\n inverse *= 2 - denominator * inverse; // inverse mod 2^64\n inverse *= 2 - denominator * inverse; // inverse mod 2^128\n inverse *= 2 - denominator * inverse; // inverse mod 2^256\n\n // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.\n // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is\n // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1\n // is no longer required.\n result = prod0 * inverse;\n return result;\n }\n }\n\n /**\n * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.\n */\n function mulDiv(\n uint256 x,\n uint256 y,\n uint256 denominator,\n Rounding rounding\n ) internal pure returns (uint256) {\n uint256 result = mulDiv(x, y, denominator);\n if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {\n result += 1;\n }\n return result;\n }\n\n /**\n * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.\n *\n * Inspired by Henry S. Warren, Jr.'s \"Hacker's Delight\" (Chapter 11).\n */\n function sqrt(uint256 a) internal pure returns (uint256) {\n if (a == 0) {\n return 0;\n }\n\n // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.\n //\n // We know that the \"msb\" (most significant bit) of our target number `a` is a power of 2 such that we have\n // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.\n //\n // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`\n // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`\n // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`\n //\n // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.\n uint256 result = 1 << (log2(a) >> 1);\n\n // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,\n // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at\n // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision\n // into the expected uint128 result.\n unchecked {\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n return min(result, a / result);\n }\n }\n\n /**\n * @notice Calculates sqrt(a), following the selected rounding direction.\n */\n function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = sqrt(a);\n return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);\n }\n }\n\n /**\n * @dev Return the log in base 2, rounded down, of a positive value.\n * Returns 0 if given 0.\n */\n function log2(uint256 value) internal pure returns (uint256) {\n uint256 result = 0;\n unchecked {\n if (value >> 128 > 0) {\n value >>= 128;\n result += 128;\n }\n if (value >> 64 > 0) {\n value >>= 64;\n result += 64;\n }\n if (value >> 32 > 0) {\n value >>= 32;\n result += 32;\n }\n if (value >> 16 > 0) {\n value >>= 16;\n result += 16;\n }\n if (value >> 8 > 0) {\n value >>= 8;\n result += 8;\n }\n if (value >> 4 > 0) {\n value >>= 4;\n result += 4;\n }\n if (value >> 2 > 0) {\n value >>= 2;\n result += 2;\n }\n if (value >> 1 > 0) {\n result += 1;\n }\n }\n return result;\n }\n\n /**\n * @dev Return the log in base 2, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log2(value);\n return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);\n }\n }\n\n /**\n * @dev Return the log in base 10, rounded down, of a positive value.\n * Returns 0 if given 0.\n */\n function log10(uint256 value) internal pure returns (uint256) {\n uint256 result = 0;\n unchecked {\n if (value >= 10**64) {\n value /= 10**64;\n result += 64;\n }\n if (value >= 10**32) {\n value /= 10**32;\n result += 32;\n }\n if (value >= 10**16) {\n value /= 10**16;\n result += 16;\n }\n if (value >= 10**8) {\n value /= 10**8;\n result += 8;\n }\n if (value >= 10**4) {\n value /= 10**4;\n result += 4;\n }\n if (value >= 10**2) {\n value /= 10**2;\n result += 2;\n }\n if (value >= 10**1) {\n result += 1;\n }\n }\n return result;\n }\n\n /**\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log10(value);\n return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);\n }\n }\n\n /**\n * @dev Return the log in base 256, rounded down, of a positive value.\n * Returns 0 if given 0.\n *\n * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.\n */\n function log256(uint256 value) internal pure returns (uint256) {\n uint256 result = 0;\n unchecked {\n if (value >> 128 > 0) {\n value >>= 128;\n result += 16;\n }\n if (value >> 64 > 0) {\n value >>= 64;\n result += 8;\n }\n if (value >> 32 > 0) {\n value >>= 32;\n result += 4;\n }\n if (value >> 16 > 0) {\n value >>= 16;\n result += 2;\n }\n if (value >> 8 > 0) {\n result += 1;\n }\n }\n return result;\n }\n\n /**\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log256(value);\n return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);\n }\n }\n}\n" + }, + "@openzeppelin/contracts/utils/Strings.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./math/Math.sol\";\n\n/**\n * @dev String operations.\n */\nlibrary Strings {\n bytes16 private constant _SYMBOLS = \"0123456789abcdef\";\n uint8 private constant _ADDRESS_LENGTH = 20;\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` decimal representation.\n */\n function toString(uint256 value) internal pure returns (string memory) {\n unchecked {\n uint256 length = Math.log10(value) + 1;\n string memory buffer = new string(length);\n uint256 ptr;\n /// @solidity memory-safe-assembly\n assembly {\n ptr := add(buffer, add(32, length))\n }\n while (true) {\n ptr--;\n /// @solidity memory-safe-assembly\n assembly {\n mstore8(ptr, byte(mod(value, 10), _SYMBOLS))\n }\n value /= 10;\n if (value == 0) break;\n }\n return buffer;\n }\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\n */\n function toHexString(uint256 value) internal pure returns (string memory) {\n unchecked {\n return toHexString(value, Math.log256(value) + 1);\n }\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\n */\n function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\n bytes memory buffer = new bytes(2 * length + 2);\n buffer[0] = \"0\";\n buffer[1] = \"x\";\n for (uint256 i = 2 * length + 1; i > 1; --i) {\n buffer[i] = _SYMBOLS[value & 0xf];\n value >>= 4;\n }\n require(value == 0, \"Strings: hex length insufficient\");\n return string(buffer);\n }\n\n /**\n * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.\n */\n function toHexString(address addr) internal pure returns (string memory) {\n return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);\n }\n}\n" + }, + "@openzeppelin/contracts/utils/structs/EnumerableSet.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/structs/EnumerableSet.sol)\n// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Library for managing\n * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive\n * types.\n *\n * Sets have the following properties:\n *\n * - Elements are added, removed, and checked for existence in constant time\n * (O(1)).\n * - Elements are enumerated in O(n). No guarantees are made on the ordering.\n *\n * ```\n * contract Example {\n * // Add the library methods\n * using EnumerableSet for EnumerableSet.AddressSet;\n *\n * // Declare a set state variable\n * EnumerableSet.AddressSet private mySet;\n * }\n * ```\n *\n * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)\n * and `uint256` (`UintSet`) are supported.\n *\n * [WARNING]\n * ====\n * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure\n * unusable.\n * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.\n *\n * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an\n * array of EnumerableSet.\n * ====\n */\nlibrary EnumerableSet {\n // To implement this library for multiple types with as little code\n // repetition as possible, we write it in terms of a generic Set type with\n // bytes32 values.\n // The Set implementation uses private functions, and user-facing\n // implementations (such as AddressSet) are just wrappers around the\n // underlying Set.\n // This means that we can only create new EnumerableSets for types that fit\n // in bytes32.\n\n struct Set {\n // Storage of set values\n bytes32[] _values;\n // Position of the value in the `values` array, plus 1 because index 0\n // means a value is not in the set.\n mapping(bytes32 => uint256) _indexes;\n }\n\n /**\n * @dev Add a value to a set. O(1).\n *\n * Returns true if the value was added to the set, that is if it was not\n * already present.\n */\n function _add(Set storage set, bytes32 value) private returns (bool) {\n if (!_contains(set, value)) {\n set._values.push(value);\n // The value is stored at length-1, but we add 1 to all indexes\n // and use 0 as a sentinel value\n set._indexes[value] = set._values.length;\n return true;\n } else {\n return false;\n }\n }\n\n /**\n * @dev Removes a value from a set. O(1).\n *\n * Returns true if the value was removed from the set, that is if it was\n * present.\n */\n function _remove(Set storage set, bytes32 value) private returns (bool) {\n // We read and store the value's index to prevent multiple reads from the same storage slot\n uint256 valueIndex = set._indexes[value];\n\n if (valueIndex != 0) {\n // Equivalent to contains(set, value)\n // To delete an element from the _values array in O(1), we swap the element to delete with the last one in\n // the array, and then remove the last element (sometimes called as 'swap and pop').\n // This modifies the order of the array, as noted in {at}.\n\n uint256 toDeleteIndex = valueIndex - 1;\n uint256 lastIndex = set._values.length - 1;\n\n if (lastIndex != toDeleteIndex) {\n bytes32 lastValue = set._values[lastIndex];\n\n // Move the last value to the index where the value to delete is\n set._values[toDeleteIndex] = lastValue;\n // Update the index for the moved value\n set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex\n }\n\n // Delete the slot where the moved value was stored\n set._values.pop();\n\n // Delete the index for the deleted slot\n delete set._indexes[value];\n\n return true;\n } else {\n return false;\n }\n }\n\n /**\n * @dev Returns true if the value is in the set. O(1).\n */\n function _contains(Set storage set, bytes32 value) private view returns (bool) {\n return set._indexes[value] != 0;\n }\n\n /**\n * @dev Returns the number of values on the set. O(1).\n */\n function _length(Set storage set) private view returns (uint256) {\n return set._values.length;\n }\n\n /**\n * @dev Returns the value stored at position `index` in the set. O(1).\n *\n * Note that there are no guarantees on the ordering of values inside the\n * array, and it may change when more values are added or removed.\n *\n * Requirements:\n *\n * - `index` must be strictly less than {length}.\n */\n function _at(Set storage set, uint256 index) private view returns (bytes32) {\n return set._values[index];\n }\n\n /**\n * @dev Return the entire set in an array\n *\n * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n */\n function _values(Set storage set) private view returns (bytes32[] memory) {\n return set._values;\n }\n\n // Bytes32Set\n\n struct Bytes32Set {\n Set _inner;\n }\n\n /**\n * @dev Add a value to a set. O(1).\n *\n * Returns true if the value was added to the set, that is if it was not\n * already present.\n */\n function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {\n return _add(set._inner, value);\n }\n\n /**\n * @dev Removes a value from a set. O(1).\n *\n * Returns true if the value was removed from the set, that is if it was\n * present.\n */\n function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {\n return _remove(set._inner, value);\n }\n\n /**\n * @dev Returns true if the value is in the set. O(1).\n */\n function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {\n return _contains(set._inner, value);\n }\n\n /**\n * @dev Returns the number of values in the set. O(1).\n */\n function length(Bytes32Set storage set) internal view returns (uint256) {\n return _length(set._inner);\n }\n\n /**\n * @dev Returns the value stored at position `index` in the set. O(1).\n *\n * Note that there are no guarantees on the ordering of values inside the\n * array, and it may change when more values are added or removed.\n *\n * Requirements:\n *\n * - `index` must be strictly less than {length}.\n */\n function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {\n return _at(set._inner, index);\n }\n\n /**\n * @dev Return the entire set in an array\n *\n * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n */\n function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {\n bytes32[] memory store = _values(set._inner);\n bytes32[] memory result;\n\n /// @solidity memory-safe-assembly\n assembly {\n result := store\n }\n\n return result;\n }\n\n // AddressSet\n\n struct AddressSet {\n Set _inner;\n }\n\n /**\n * @dev Add a value to a set. O(1).\n *\n * Returns true if the value was added to the set, that is if it was not\n * already present.\n */\n function add(AddressSet storage set, address value) internal returns (bool) {\n return _add(set._inner, bytes32(uint256(uint160(value))));\n }\n\n /**\n * @dev Removes a value from a set. O(1).\n *\n * Returns true if the value was removed from the set, that is if it was\n * present.\n */\n function remove(AddressSet storage set, address value) internal returns (bool) {\n return _remove(set._inner, bytes32(uint256(uint160(value))));\n }\n\n /**\n * @dev Returns true if the value is in the set. O(1).\n */\n function contains(AddressSet storage set, address value) internal view returns (bool) {\n return _contains(set._inner, bytes32(uint256(uint160(value))));\n }\n\n /**\n * @dev Returns the number of values in the set. O(1).\n */\n function length(AddressSet storage set) internal view returns (uint256) {\n return _length(set._inner);\n }\n\n /**\n * @dev Returns the value stored at position `index` in the set. O(1).\n *\n * Note that there are no guarantees on the ordering of values inside the\n * array, and it may change when more values are added or removed.\n *\n * Requirements:\n *\n * - `index` must be strictly less than {length}.\n */\n function at(AddressSet storage set, uint256 index) internal view returns (address) {\n return address(uint160(uint256(_at(set._inner, index))));\n }\n\n /**\n * @dev Return the entire set in an array\n *\n * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n */\n function values(AddressSet storage set) internal view returns (address[] memory) {\n bytes32[] memory store = _values(set._inner);\n address[] memory result;\n\n /// @solidity memory-safe-assembly\n assembly {\n result := store\n }\n\n return result;\n }\n\n // UintSet\n\n struct UintSet {\n Set _inner;\n }\n\n /**\n * @dev Add a value to a set. O(1).\n *\n * Returns true if the value was added to the set, that is if it was not\n * already present.\n */\n function add(UintSet storage set, uint256 value) internal returns (bool) {\n return _add(set._inner, bytes32(value));\n }\n\n /**\n * @dev Removes a value from a set. O(1).\n *\n * Returns true if the value was removed from the set, that is if it was\n * present.\n */\n function remove(UintSet storage set, uint256 value) internal returns (bool) {\n return _remove(set._inner, bytes32(value));\n }\n\n /**\n * @dev Returns true if the value is in the set. O(1).\n */\n function contains(UintSet storage set, uint256 value) internal view returns (bool) {\n return _contains(set._inner, bytes32(value));\n }\n\n /**\n * @dev Returns the number of values in the set. O(1).\n */\n function length(UintSet storage set) internal view returns (uint256) {\n return _length(set._inner);\n }\n\n /**\n * @dev Returns the value stored at position `index` in the set. O(1).\n *\n * Note that there are no guarantees on the ordering of values inside the\n * array, and it may change when more values are added or removed.\n *\n * Requirements:\n *\n * - `index` must be strictly less than {length}.\n */\n function at(UintSet storage set, uint256 index) internal view returns (uint256) {\n return uint256(_at(set._inner, index));\n }\n\n /**\n * @dev Return the entire set in an array\n *\n * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n */\n function values(UintSet storage set) internal view returns (uint256[] memory) {\n bytes32[] memory store = _values(set._inner);\n uint256[] memory result;\n\n /// @solidity memory-safe-assembly\n assembly {\n result := store\n }\n\n return result;\n }\n}\n" + }, + "src/interface/IPostageStamp.sol": { + "content": "// SPDX-License-Identifier: BSD-3-Clause\npragma solidity ^0.8.19;\n\ninterface IPostageStamp {\n function withdraw(address beneficiary) external;\n\n function setPrice(uint256 _price) external;\n\n function validChunkCount() external view returns (uint256);\n\n function batchOwner(bytes32 _batchId) external view returns (address);\n\n function batchDepth(bytes32 _batchId) external view returns (uint8);\n\n function batchBucketDepth(bytes32 _batchId) external view returns (uint8);\n\n function remainingBalance(bytes32 _batchId) external view returns (uint256);\n\n function minimumInitialBalancePerChunk() external view returns (uint256);\n\n function batches(\n bytes32\n )\n external\n view\n returns (\n address owner,\n uint8 depth,\n uint8 bucketDepth,\n bool immutableFlag,\n uint256 normalisedBalance,\n uint256 lastUpdatedBlockNumber\n );\n}\n" + }, + "src/OrderStatisticsTree/HitchensOrderStatisticsTreeLib.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\n/*\nHitchens Order Statistics Tree v0.99\n\nA Solidity Red-Black Tree library to store and maintain a sorted data\nstructure in a Red-Black binary search tree, with O(log 2n) insert, remove\nand search time (and gas, approximately)\n\nhttps://github.com/rob-Hitchens/OrderStatisticsTree\n\nCopyright (c) Rob Hitchens. the MIT License\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\nSignificant portions from BokkyPooBahsRedBlackTreeLibrary,\nhttps://github.com/bokkypoobah/BokkyPooBahsRedBlackTreeLibrary\n\nTHIS SOFTWARE IS NOT TESTED OR AUDITED. DO NOT USE FOR PRODUCTION.\n*/\n\nlibrary HitchensOrderStatisticsTreeLib {\n uint private constant EMPTY = 0;\n struct Node {\n uint parent;\n uint left;\n uint right;\n bool red;\n bytes32[] keys;\n mapping(bytes32 => uint) keyMap;\n uint count;\n }\n struct Tree {\n uint root;\n mapping(uint => Node) nodes;\n }\n\n error ValueDoesNotExist(); // Provided value doesn't exist in the tree.\n error ValueCannotBeZero(); // Value to insert cannot be zero\n error ValueKeyPairExists(); // Value and Key pair exists. Cannot be inserted again.\n\n function first(Tree storage self) internal view returns (uint _value) {\n _value = self.root;\n if (_value == EMPTY) return 0;\n while (self.nodes[_value].left != EMPTY) {\n _value = self.nodes[_value].left;\n }\n }\n\n function exists(Tree storage self, uint value) internal view returns (bool _exists) {\n if (value == EMPTY) return false;\n if (value == self.root) return true;\n if (self.nodes[value].parent != EMPTY) return true;\n return false;\n }\n\n function keyExists(Tree storage self, bytes32 key, uint value) internal view returns (bool _exists) {\n if (!exists(self, value)) return false;\n return self.nodes[value].keys[self.nodes[value].keyMap[key]] == key;\n }\n\n function getNode(\n Tree storage self,\n uint value\n ) internal view returns (uint _parent, uint _left, uint _right, bool _red, uint keyCount, uint __count) {\n if (!exists(self, value)) {\n revert ValueDoesNotExist();\n }\n\n Node storage gn = self.nodes[value];\n return (gn.parent, gn.left, gn.right, gn.red, gn.keys.length, gn.keys.length + gn.count);\n }\n\n function getNodeCount(Tree storage self, uint value) internal view returns (uint __count) {\n Node storage gn = self.nodes[value];\n return gn.keys.length + gn.count;\n }\n\n function valueKeyAtIndex(Tree storage self, uint value, uint index) internal view returns (bytes32 _key) {\n if (!exists(self, value)) {\n revert ValueDoesNotExist();\n }\n return self.nodes[value].keys[index];\n }\n\n function count(Tree storage self) internal view returns (uint _count) {\n return getNodeCount(self, self.root);\n }\n\n /* We don't use this functionality, so it is commented out to make audit easier\n\n function percentile(Tree storage self, uint value) internal view returns(uint _percentile) {\n uint denominator = count(self);\n uint numerator = rank(self, value);\n _percentile = ((uint(1000) * numerator)/denominator+(uint(5)))/uint(10);\n }\n function permil(Tree storage self, uint value) internal view returns(uint _permil) {\n uint denominator = count(self);\n uint numerator = rank(self, value);\n _permil = ((uint(10000) * numerator)/denominator+(uint(5)))/uint(10);\n }\n function atPercentile(Tree storage self, uint _percentile) internal view returns(uint _value) {\n uint findRank = (((_percentile * count(self))/uint(10)) + uint(5)) / uint(10);\n return atRank(self,findRank);\n }\n function atPermil(Tree storage self, uint _permil) internal view returns(uint _value) {\n uint findRank = (((_permil * count(self))/uint(100)) + uint(5)) / uint(10);\n return atRank(self,findRank);\n }\n function median(Tree storage self) internal view returns(uint value) {\n return atPercentile(self,50);\n }\n function below(Tree storage self, uint value) public view returns(uint _below) {\n if(count(self) > 0 && value > 0) _below = rank(self,value)-uint(1);\n }\n function above(Tree storage self, uint value) public view returns(uint _above) {\n if(count(self) > 0) _above = count(self)-rank(self,value);\n }\n function valueBelowEstimate(Tree storage self, uint estimate) public view returns(uint _below) {\n if(count(self) > 0 && estimate > 0) {\n uint highestValue = last(self);\n uint lowestValue = first(self);\n if(estimate < lowestValue) {\n return 0;\n }\n if(estimate >= highestValue) {\n return highestValue;\n }\n uint rankOfValue = rank(self, estimate); // approximation\n _below = atRank(self, rankOfValue);\n if(_below > estimate) { // fix error in approximation\n rankOfValue--;\n _below = atRank(self, rankOfValue);\n }\n }\n }\n function valueAboveEstimate(Tree storage self, uint estimate) public view returns(uint _above) {\n if(count(self) > 0 && estimate > 0) {\n uint highestValue = last(self);\n uint lowestValue = first(self);\n if(estimate > highestValue) {\n return 0;\n }\n if(estimate <= lowestValue) {\n return lowestValue;\n }\n uint rankOfValue = rank(self, estimate); // approximation\n _above = atRank(self, rankOfValue);\n if(_above < estimate) { // fix error in approximation\n rankOfValue++;\n _above = atRank(self, rankOfValue);\n }\n }\n }\n function rank(Tree storage self, uint value) internal view returns(uint _rank) {\n if(count(self) > 0) {\n bool finished;\n uint cursor = self.root;\n Node storage c = self.nodes[cursor];\n uint smaller = getNodeCount(self,c.left);\n while (!finished) {\n uint keyCount = c.keys.length;\n if(cursor == value) {\n finished = true;\n } else {\n if(cursor < value) {\n cursor = c.right;\n c = self.nodes[cursor];\n smaller += keyCount + getNodeCount(self,c.left);\n } else {\n cursor = c.left;\n c = self.nodes[cursor];\n smaller -= (keyCount + getNodeCount(self,c.right));\n }\n }\n if (!exists(self,cursor)) {\n finished = true;\n }\n }\n return smaller + 1;\n }\n }\n function atRank(Tree storage self, uint _rank) internal view returns(uint _value) {\n bool finished;\n uint cursor = self.root;\n Node storage c = self.nodes[cursor];\n uint smaller = getNodeCount(self,c.left);\n while (!finished) {\n _value = cursor;\n c = self.nodes[cursor];\n uint keyCount = c.keys.length;\n if(smaller + 1 >= _rank && smaller + keyCount <= _rank) {\n _value = cursor;\n finished = true;\n } else {\n if(smaller + keyCount <= _rank) {\n cursor = c.right;\n c = self.nodes[cursor];\n smaller += keyCount + getNodeCount(self,c.left);\n } else {\n cursor = c.left;\n c = self.nodes[cursor];\n smaller -= (keyCount + getNodeCount(self,c.right));\n }\n }\n if (!exists(self,cursor)) {\n finished = true;\n }\n }\n }\n*/\n\n function insert(Tree storage self, bytes32 key, uint value) internal {\n if (value == EMPTY) {\n revert ValueCannotBeZero();\n }\n if (keyExists(self, key, value)) {\n revert ValueKeyPairExists();\n }\n uint cursor;\n uint probe = self.root;\n while (probe != EMPTY) {\n cursor = probe;\n if (value < probe) {\n probe = self.nodes[probe].left;\n } else if (value > probe) {\n probe = self.nodes[probe].right;\n } else if (value == probe) {\n self.nodes[probe].keys.push(key);\n self.nodes[probe].keyMap[key] = self.nodes[probe].keys.length - uint(1);\n return;\n }\n self.nodes[cursor].count++;\n }\n Node storage nValue = self.nodes[value];\n nValue.parent = cursor;\n nValue.left = EMPTY;\n nValue.right = EMPTY;\n nValue.red = true;\n nValue.keys.push(key);\n nValue.keyMap[key] = nValue.keys.length - uint(1);\n if (cursor == EMPTY) {\n self.root = value;\n } else if (value < cursor) {\n self.nodes[cursor].left = value;\n } else {\n self.nodes[cursor].right = value;\n }\n insertFixup(self, value);\n }\n\n function remove(Tree storage self, bytes32 key, uint value) internal {\n if (value == EMPTY) {\n revert ValueCannotBeZero();\n }\n if (!keyExists(self, key, value)) {\n revert ValueDoesNotExist();\n }\n\n Node storage nValue = self.nodes[value];\n uint rowToDelete = nValue.keyMap[key];\n bytes32 last = nValue.keys[nValue.keys.length - uint(1)];\n nValue.keys[rowToDelete] = last;\n nValue.keyMap[last] = rowToDelete;\n nValue.keys.pop();\n\n uint probe;\n uint cursor;\n\n if (nValue.keys.length == 0) {\n if (self.nodes[value].left == EMPTY || self.nodes[value].right == EMPTY) {\n cursor = value;\n } else {\n cursor = self.nodes[value].right;\n while (self.nodes[cursor].left != EMPTY) {\n cursor = self.nodes[cursor].left;\n }\n }\n\n if (self.nodes[cursor].left != EMPTY) {\n probe = self.nodes[cursor].left;\n } else {\n probe = self.nodes[cursor].right;\n }\n\n uint cursorParent = self.nodes[cursor].parent;\n self.nodes[probe].parent = cursorParent;\n\n if (cursorParent != EMPTY) {\n if (cursor == self.nodes[cursorParent].left) {\n self.nodes[cursorParent].left = probe;\n } else {\n self.nodes[cursorParent].right = probe;\n }\n } else {\n self.root = probe;\n }\n\n bool doFixup = !self.nodes[cursor].red;\n\n if (cursor != value) {\n replaceParent(self, cursor, value);\n self.nodes[cursor].left = self.nodes[value].left;\n self.nodes[self.nodes[cursor].left].parent = cursor;\n self.nodes[cursor].right = self.nodes[value].right;\n self.nodes[self.nodes[cursor].right].parent = cursor;\n self.nodes[cursor].red = self.nodes[value].red;\n (cursor, value) = (value, cursor);\n fixCountRecurse(self, value);\n }\n\n if (doFixup) {\n removeFixup(self, probe);\n }\n\n fixCountRecurse(self, cursorParent);\n delete self.nodes[cursor];\n }\n }\n\n function fixCountRecurse(Tree storage self, uint value) private {\n while (value != EMPTY) {\n self.nodes[value].count =\n getNodeCount(self, self.nodes[value].left) +\n getNodeCount(self, self.nodes[value].right);\n value = self.nodes[value].parent;\n }\n }\n\n function treeMinimum(Tree storage self, uint value) private view returns (uint) {\n while (self.nodes[value].left != EMPTY) {\n value = self.nodes[value].left;\n }\n return value;\n }\n\n function treeMaximum(Tree storage self, uint value) private view returns (uint) {\n while (self.nodes[value].right != EMPTY) {\n value = self.nodes[value].right;\n }\n return value;\n }\n\n function rotateLeft(Tree storage self, uint value) private {\n uint cursor = self.nodes[value].right;\n uint parent = self.nodes[value].parent;\n uint cursorLeft = self.nodes[cursor].left;\n self.nodes[value].right = cursorLeft;\n if (cursorLeft != EMPTY) {\n self.nodes[cursorLeft].parent = value;\n }\n self.nodes[cursor].parent = parent;\n if (parent == EMPTY) {\n self.root = cursor;\n } else if (value == self.nodes[parent].left) {\n self.nodes[parent].left = cursor;\n } else {\n self.nodes[parent].right = cursor;\n }\n self.nodes[cursor].left = value;\n self.nodes[value].parent = cursor;\n self.nodes[value].count =\n getNodeCount(self, self.nodes[value].left) +\n getNodeCount(self, self.nodes[value].right);\n self.nodes[cursor].count =\n getNodeCount(self, self.nodes[cursor].left) +\n getNodeCount(self, self.nodes[cursor].right);\n }\n\n function rotateRight(Tree storage self, uint value) private {\n uint cursor = self.nodes[value].left;\n uint parent = self.nodes[value].parent;\n uint cursorRight = self.nodes[cursor].right;\n self.nodes[value].left = cursorRight;\n if (cursorRight != EMPTY) {\n self.nodes[cursorRight].parent = value;\n }\n self.nodes[cursor].parent = parent;\n if (parent == EMPTY) {\n self.root = cursor;\n } else if (value == self.nodes[parent].right) {\n self.nodes[parent].right = cursor;\n } else {\n self.nodes[parent].left = cursor;\n }\n self.nodes[cursor].right = value;\n self.nodes[value].parent = cursor;\n self.nodes[value].count =\n getNodeCount(self, self.nodes[value].left) +\n getNodeCount(self, self.nodes[value].right);\n self.nodes[cursor].count =\n getNodeCount(self, self.nodes[cursor].left) +\n getNodeCount(self, self.nodes[cursor].right);\n }\n\n function insertFixup(Tree storage self, uint value) private {\n uint cursor;\n while (value != self.root && self.nodes[self.nodes[value].parent].red) {\n uint valueParent = self.nodes[value].parent;\n if (valueParent == self.nodes[self.nodes[valueParent].parent].left) {\n cursor = self.nodes[self.nodes[valueParent].parent].right;\n if (self.nodes[cursor].red) {\n self.nodes[valueParent].red = false;\n self.nodes[cursor].red = false;\n self.nodes[self.nodes[valueParent].parent].red = true;\n value = self.nodes[valueParent].parent;\n } else {\n if (value == self.nodes[valueParent].right) {\n value = valueParent;\n rotateLeft(self, value);\n }\n valueParent = self.nodes[value].parent;\n self.nodes[valueParent].red = false;\n self.nodes[self.nodes[valueParent].parent].red = true;\n rotateRight(self, self.nodes[valueParent].parent);\n }\n } else {\n cursor = self.nodes[self.nodes[valueParent].parent].left;\n if (self.nodes[cursor].red) {\n self.nodes[valueParent].red = false;\n self.nodes[cursor].red = false;\n self.nodes[self.nodes[valueParent].parent].red = true;\n value = self.nodes[valueParent].parent;\n } else {\n if (value == self.nodes[valueParent].left) {\n value = valueParent;\n rotateRight(self, value);\n }\n valueParent = self.nodes[value].parent;\n self.nodes[valueParent].red = false;\n self.nodes[self.nodes[valueParent].parent].red = true;\n rotateLeft(self, self.nodes[valueParent].parent);\n }\n }\n }\n self.nodes[self.root].red = false;\n }\n\n function replaceParent(Tree storage self, uint a, uint b) private {\n uint bParent = self.nodes[b].parent;\n self.nodes[a].parent = bParent;\n if (bParent == EMPTY) {\n self.root = a;\n } else {\n if (b == self.nodes[bParent].left) {\n self.nodes[bParent].left = a;\n } else {\n self.nodes[bParent].right = a;\n }\n }\n }\n\n function removeFixup(Tree storage self, uint value) private {\n uint cursor;\n while (value != self.root && !self.nodes[value].red) {\n uint valueParent = self.nodes[value].parent;\n if (value == self.nodes[valueParent].left) {\n cursor = self.nodes[valueParent].right;\n if (self.nodes[cursor].red) {\n self.nodes[cursor].red = false;\n self.nodes[valueParent].red = true;\n rotateLeft(self, valueParent);\n cursor = self.nodes[valueParent].right;\n }\n if (!self.nodes[self.nodes[cursor].left].red && !self.nodes[self.nodes[cursor].right].red) {\n self.nodes[cursor].red = true;\n value = valueParent;\n } else {\n if (!self.nodes[self.nodes[cursor].right].red) {\n self.nodes[self.nodes[cursor].left].red = false;\n self.nodes[cursor].red = true;\n rotateRight(self, cursor);\n cursor = self.nodes[valueParent].right;\n }\n self.nodes[cursor].red = self.nodes[valueParent].red;\n self.nodes[valueParent].red = false;\n self.nodes[self.nodes[cursor].right].red = false;\n rotateLeft(self, valueParent);\n value = self.root;\n }\n } else {\n cursor = self.nodes[valueParent].left;\n if (self.nodes[cursor].red) {\n self.nodes[cursor].red = false;\n self.nodes[valueParent].red = true;\n rotateRight(self, valueParent);\n cursor = self.nodes[valueParent].left;\n }\n if (!self.nodes[self.nodes[cursor].right].red && !self.nodes[self.nodes[cursor].left].red) {\n self.nodes[cursor].red = true;\n value = valueParent;\n } else {\n if (!self.nodes[self.nodes[cursor].left].red) {\n self.nodes[self.nodes[cursor].right].red = false;\n self.nodes[cursor].red = true;\n rotateLeft(self, cursor);\n cursor = self.nodes[valueParent].left;\n }\n self.nodes[cursor].red = self.nodes[valueParent].red;\n self.nodes[valueParent].red = false;\n self.nodes[self.nodes[cursor].left].red = false;\n rotateRight(self, valueParent);\n value = self.root;\n }\n }\n }\n self.nodes[value].red = false;\n }\n}\n" + }, + "src/PostageStamp.sol": { + "content": "// SPDX-License-Identifier: BSD-3-Clause\npragma solidity ^0.8.19;\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"@openzeppelin/contracts/security/Pausable.sol\";\nimport \"./OrderStatisticsTree/HitchensOrderStatisticsTreeLib.sol\";\n\n/**\n * @title PostageStamp contract\n * @author The Swarm Authors\n * @dev The postage stamp contracts allows users to create and manage postage stamp batches.\n * The current balance for each batch is stored ordered in descending order of normalised balance.\n * Balance is normalised to be per chunk and the total spend since the contract was deployed, i.e. when a batch\n * is bought, its per-chunk balance is supplemented with the current cost of storing one chunk since the beginning of time,\n * as if the batch had existed since the contract's inception. During the _expiry_ process, each of these balances is\n * checked against the _currentTotalOutPayment_, a similarly normalised figure that represents the current cost of\n * storing one chunk since the beginning of time. A batch with a normalised balance less than _currentTotalOutPayment_\n * is treated as expired.\n *\n * The _currentTotalOutPayment_ is calculated using _totalOutPayment_ which is updated during _setPrice_ events so\n * that the applicable per-chunk prices can be charged for the relevant periods of time. This can then be multiplied\n * by the amount of chunks which are allowed to be stamped by each batch to get the actual cost of storage.\n *\n * The amount of chunks a batch can stamp is determined by the _bucketDepth_. A batch may store a maximum of 2^depth chunks.\n * The global figure for the currently allowed chunks is tracked by _validChunkCount_ and updated during batch _expiry_ events.\n */\n\ncontract PostageStamp is AccessControl, Pausable {\n using HitchensOrderStatisticsTreeLib for HitchensOrderStatisticsTreeLib.Tree;\n\n // ----------------------------- State variables ------------------------------\n\n // Address of the ERC20 token this contract references.\n address public bzzToken;\n\n // Minimum allowed depth of bucket.\n uint8 public minimumBucketDepth;\n\n // Role allowed to increase totalOutPayment.\n bytes32 public immutable PRICE_ORACLE_ROLE;\n\n // Role allowed to pause\n bytes32 public immutable PAUSER_ROLE;\n // Role allowed to withdraw the pot.\n bytes32 public immutable REDISTRIBUTOR_ROLE;\n\n // Associate every batch id with batch data.\n mapping(bytes32 => Batch) public batches;\n // Store every batch id ordered by normalisedBalance.\n HitchensOrderStatisticsTreeLib.Tree tree;\n\n // Total out payment per chunk, at the blockheight of the last price change.\n uint256 private totalOutPayment;\n\n // Combined global chunk capacity of valid batches remaining at the blockheight expire() was last called.\n uint256 public validChunkCount;\n\n // Lottery pot at last update.\n uint256 public pot;\n\n // Normalised balance at the blockheight expire() was last called.\n uint256 public lastExpiryBalance;\n\n // Price from the last update.\n uint64 public lastPrice;\n\n // blocks in 24 hours ~ 24 * 60 * 60 / 5 = 17280\n uint64 public minimumValidityBlocks = 17280;\n\n // Block at which the last update occured.\n uint64 public lastUpdatedBlock;\n\n // ----------------------------- Type declarations ------------------------------\n\n struct Batch {\n // Owner of this batch (0 if not valid).\n address owner;\n // Current depth of this batch.\n uint8 depth;\n // Bucket depth defined in this batch\n uint8 bucketDepth;\n // Whether this batch is immutable.\n bool immutableFlag;\n // Normalised balance per chunk.\n uint256 normalisedBalance;\n // When was this batch last updated\n uint256 lastUpdatedBlockNumber;\n }\n\n struct ImportBatch {\n bytes32 batchId;\n address owner;\n uint8 depth;\n uint8 bucketDepth;\n bool immutableFlag;\n uint256 remainingBalance;\n }\n\n // ----------------------------- Events ------------------------------\n\n /**\n * @dev Emitted when a new batch is created.\n */\n event BatchCreated(\n bytes32 indexed batchId,\n uint256 totalAmount,\n uint256 normalisedBalance,\n address owner,\n uint8 depth,\n uint8 bucketDepth,\n bool immutableFlag\n );\n\n /**\n * @dev Emitted when an pot is Withdrawn.\n */\n event PotWithdrawn(address recipient, uint256 totalAmount);\n\n /**\n * @dev Emitted when an existing batch is topped up.\n */\n event BatchTopUp(bytes32 indexed batchId, uint256 topupAmount, uint256 normalisedBalance);\n\n /**\n * @dev Emitted when the depth of an existing batch increases.\n */\n event BatchDepthIncrease(bytes32 indexed batchId, uint8 newDepth, uint256 normalisedBalance);\n\n /**\n *@dev Emitted on every price update.\n */\n event PriceUpdate(uint256 price);\n\n /**\n *@dev Emitted on every batch failed in bulk batch creation\n */\n event CopyBatchFailed(uint index, bytes32 batchId);\n\n // ----------------------------- Errors ------------------------------\n\n error ZeroAddress(); // Owner cannot be the zero address\n error InvalidDepth(); // Invalid bucket depth\n error BatchExists(); // Batch already exists\n error InsufficientBalance(); // Insufficient initial balance for 24h minimum validity\n error TransferFailed(); // Failed transfer of BZZ tokens\n error ZeroBalance(); // NormalisedBalance cannot be zero\n error AdministratorOnly(); // Only administrator can use copy method\n error BatchDoesNotExist(); // Batch does not exist or has expired\n error BatchExpired(); // Batch already expired\n error BatchTooSmall(); // Batch too small to renew\n error NotBatchOwner(); // Not batch owner\n error DepthNotIncreasing(); // Depth not increasing\n error PriceOracleOnly(); // Only price oracle can set the price\n error InsufficienChunkCount(); // Insufficient valid chunk count\n error TotalOutpaymentDecreased(); // Current total outpayment should never decrease\n error NoBatchesExist(); // There are no batches\n error OnlyPauser(); // Only Pauser role can pause or unpause contracts\n error OnlyRedistributor(); // Only redistributor role can withdraw from the contract\n\n // ----------------------------- CONSTRUCTOR ------------------------------\n\n /**\n * @param _bzzToken The ERC20 token address to reference in this contract.\n * @param _minimumBucketDepth The minimum bucket depth of batches that can be purchased.\n */\n constructor(address _bzzToken, uint8 _minimumBucketDepth) {\n bzzToken = _bzzToken;\n minimumBucketDepth = _minimumBucketDepth;\n PRICE_ORACLE_ROLE = keccak256(\"PRICE_ORACLE_ROLE\");\n PAUSER_ROLE = keccak256(\"PAUSER_ROLE\");\n REDISTRIBUTOR_ROLE = keccak256(\"REDISTRIBUTOR_ROLE\");\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n _setupRole(PAUSER_ROLE, msg.sender);\n }\n\n ////////////////////////////////////////\n // STATE CHANGING //\n ////////////////////////////////////////\n\n /**\n * @notice Create a new batch.\n * @dev At least `_initialBalancePerChunk*2^depth` tokens must be approved in the ERC20 token contract.\n * @param _owner Owner of the new batch.\n * @param _initialBalancePerChunk Initial balance per chunk.\n * @param _depth Initial depth of the new batch.\n * @param _nonce A random value used in the batch id derivation to allow multiple batches per owner.\n * @param _immutable Whether the batch is mutable.\n */\n function createBatch(\n address _owner,\n uint256 _initialBalancePerChunk,\n uint8 _depth,\n uint8 _bucketDepth,\n bytes32 _nonce,\n bool _immutable\n ) external whenNotPaused returns (bytes32) {\n if (_owner == address(0)) {\n revert ZeroAddress();\n }\n\n if (_bucketDepth == 0 || _bucketDepth < minimumBucketDepth || _bucketDepth >= _depth) {\n revert InvalidDepth();\n }\n\n bytes32 batchId = keccak256(abi.encode(msg.sender, _nonce));\n if (batches[batchId].owner != address(0)) {\n revert BatchExists();\n }\n\n if (_initialBalancePerChunk < minimumInitialBalancePerChunk()) {\n revert InsufficientBalance();\n }\n\n uint256 totalAmount = _initialBalancePerChunk * (1 << _depth);\n if (!ERC20(bzzToken).transferFrom(msg.sender, address(this), totalAmount)) {\n revert TransferFailed();\n }\n\n uint256 normalisedBalance = currentTotalOutPayment() + (_initialBalancePerChunk);\n if (normalisedBalance == 0) {\n revert ZeroBalance();\n }\n\n expireLimited(type(uint256).max);\n validChunkCount += 1 << _depth;\n\n batches[batchId] = Batch({\n owner: _owner,\n depth: _depth,\n bucketDepth: _bucketDepth,\n immutableFlag: _immutable,\n normalisedBalance: normalisedBalance,\n lastUpdatedBlockNumber: block.number\n });\n\n tree.insert(batchId, normalisedBalance);\n\n emit BatchCreated(batchId, totalAmount, normalisedBalance, _owner, _depth, _bucketDepth, _immutable);\n\n return batchId;\n }\n\n /**\n * @notice Manually create a new batch when facilitating migration, can only be called by the Admin role.\n * @dev At least `_initialBalancePerChunk*2^depth` tokens must be approved in the ERC20 token contract.\n * @param _owner Owner of the new batch.\n * @param _initialBalancePerChunk Initial balance per chunk of the batch.\n * @param _depth Initial depth of the new batch.\n * @param _batchId BatchId being copied (from previous version contract data).\n * @param _immutable Whether the batch is mutable.\n */\n function copyBatch(\n address _owner,\n uint256 _initialBalancePerChunk,\n uint8 _depth,\n uint8 _bucketDepth,\n bytes32 _batchId,\n bool _immutable\n ) public whenNotPaused {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert AdministratorOnly();\n }\n\n if (_owner == address(0)) {\n revert ZeroAddress();\n }\n\n if (_bucketDepth == 0 || _bucketDepth >= _depth) {\n revert InvalidDepth();\n }\n\n if (batches[_batchId].owner != address(0)) {\n revert BatchExists();\n }\n\n uint256 totalAmount = _initialBalancePerChunk * (1 << _depth);\n uint256 normalisedBalance = currentTotalOutPayment() + (_initialBalancePerChunk);\n if (normalisedBalance == 0) {\n revert ZeroBalance();\n }\n\n //update validChunkCount to remove currently expired batches\n expireLimited(type(uint256).max);\n\n validChunkCount += 1 << _depth;\n\n batches[_batchId] = Batch({\n owner: _owner,\n depth: _depth,\n bucketDepth: _bucketDepth,\n immutableFlag: _immutable,\n normalisedBalance: normalisedBalance,\n lastUpdatedBlockNumber: block.number\n });\n\n tree.insert(_batchId, normalisedBalance);\n\n emit BatchCreated(_batchId, totalAmount, normalisedBalance, _owner, _depth, _bucketDepth, _immutable);\n }\n\n /**\n * @notice Import batches in bulk\n * @dev Import batches in bulk to lower the number of transactions needed,\n * @dev becase of block limitations 90 batches per trx is ceiling, 60 to 70 sweetspot\n * @param bulkBatches array of batches\n */\n function copyBatchBulk(ImportBatch[] calldata bulkBatches) external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert AdministratorOnly();\n }\n for (uint i = 0; i < bulkBatches.length; i++) {\n ImportBatch memory _batch = bulkBatches[i];\n try\n this.copyBatch(\n _batch.owner,\n _batch.remainingBalance,\n _batch.depth,\n _batch.bucketDepth,\n _batch.batchId,\n _batch.immutableFlag\n )\n {\n // Successful copyBatch call\n } catch {\n // copyBatch failed, handle error\n emit CopyBatchFailed(i, _batch.batchId);\n }\n }\n }\n\n /**\n * @notice Top up an existing batch.\n * @dev At least `_topupAmountPerChunk*2^depth` tokens must be approved in the ERC20 token contract.\n * @param _batchId The id of an existing batch.\n * @param _topupAmountPerChunk The amount of additional tokens to add per chunk.\n */\n function topUp(bytes32 _batchId, uint256 _topupAmountPerChunk) external whenNotPaused {\n Batch memory batch = batches[_batchId];\n\n if (batch.owner == address(0)) {\n revert BatchDoesNotExist();\n }\n\n if (batch.normalisedBalance <= currentTotalOutPayment()) {\n revert BatchExpired();\n }\n\n if (batch.depth <= minimumBucketDepth) {\n revert BatchTooSmall();\n }\n\n if (remainingBalance(_batchId) + (_topupAmountPerChunk) < minimumInitialBalancePerChunk()) {\n revert InsufficientBalance();\n }\n\n // per chunk balance multiplied by the batch size in chunks must be transferred from the sender\n uint256 totalAmount = _topupAmountPerChunk * (1 << batch.depth);\n if (!ERC20(bzzToken).transferFrom(msg.sender, address(this), totalAmount)) {\n revert TransferFailed();\n }\n\n // update by removing batch and then reinserting\n tree.remove(_batchId, batch.normalisedBalance);\n batch.normalisedBalance = batch.normalisedBalance + (_topupAmountPerChunk);\n tree.insert(_batchId, batch.normalisedBalance);\n\n batches[_batchId].normalisedBalance = batch.normalisedBalance;\n emit BatchTopUp(_batchId, totalAmount, batch.normalisedBalance);\n }\n\n /**\n * @notice Increase the depth of an existing batch.\n * @dev Can only be called by the owner of the batch.\n * @param _batchId the id of an existing batch.\n * @param _newDepth the new (larger than the previous one) depth for this batch.\n */\n function increaseDepth(bytes32 _batchId, uint8 _newDepth) external whenNotPaused {\n Batch memory batch = batches[_batchId];\n\n if (batch.owner != msg.sender) {\n revert NotBatchOwner();\n }\n\n if (!(minimumBucketDepth < _newDepth && batch.depth < _newDepth)) {\n revert DepthNotIncreasing();\n }\n\n if (batch.normalisedBalance <= currentTotalOutPayment()) {\n revert BatchExpired();\n }\n\n uint8 depthChange = _newDepth - batch.depth;\n uint256 newRemainingBalance = remainingBalance(_batchId) / (1 << depthChange);\n\n if (newRemainingBalance < minimumInitialBalancePerChunk()) {\n revert InsufficientBalance();\n }\n\n expireLimited(type(uint256).max);\n validChunkCount += (1 << _newDepth) - (1 << batch.depth);\n tree.remove(_batchId, batch.normalisedBalance);\n batches[_batchId].depth = _newDepth;\n batches[_batchId].lastUpdatedBlockNumber = block.number;\n\n batch.normalisedBalance = currentTotalOutPayment() + newRemainingBalance;\n batches[_batchId].normalisedBalance = batch.normalisedBalance;\n tree.insert(_batchId, batch.normalisedBalance);\n\n emit BatchDepthIncrease(_batchId, _newDepth, batch.normalisedBalance);\n }\n\n /**\n * @notice Set a new price.\n * @dev Can only be called by the price oracle role.\n * @param _price The new price.\n */\n function setPrice(uint256 _price) external {\n if (!hasRole(PRICE_ORACLE_ROLE, msg.sender)) {\n revert PriceOracleOnly();\n }\n\n if (lastPrice != 0) {\n totalOutPayment = currentTotalOutPayment();\n }\n\n lastPrice = uint64(_price);\n lastUpdatedBlock = uint64(block.number);\n\n emit PriceUpdate(_price);\n }\n\n function setMinimumValidityBlocks(uint64 _value) external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert AdministratorOnly();\n }\n\n minimumValidityBlocks = _value;\n }\n\n /**\n * @notice Reclaims a limited number of expired batches\n * @dev Can be used if reclaiming all expired batches would exceed the block gas limit, causing other\n * contract method calls to fail.\n * @param limit The maximum number of batches to expire.\n */\n function expireLimited(uint256 limit) public {\n // the lower bound of the normalised balance for which we will check if batches have expired\n uint256 _lastExpiryBalance = lastExpiryBalance;\n uint256 i;\n for (i; i < limit; ) {\n if (isBatchesTreeEmpty()) {\n lastExpiryBalance = currentTotalOutPayment();\n break;\n }\n // get the batch with the smallest normalised balance\n bytes32 fbi = firstBatchId();\n // if the batch with the smallest balance has not yet expired\n // we have already reached the end of the batches we need\n // to expire, so exit the loop\n if (remainingBalance(fbi) > 0) {\n // the upper bound of the normalised balance for which we will check if batches have expired\n // value is updated when there are no expired batches left\n lastExpiryBalance = currentTotalOutPayment();\n break;\n }\n // otherwise, the batch with the smallest balance has expired,\n // so we must remove the chunks this batch contributes to the global validChunkCount\n Batch memory batch = batches[fbi];\n uint256 batchSize = 1 << batch.depth;\n\n if (validChunkCount < batchSize) {\n revert InsufficienChunkCount();\n }\n validChunkCount -= batchSize;\n // since the batch expired _during_ the period we must add\n // remaining normalised payout for this batch only\n pot += batchSize * (batch.normalisedBalance - _lastExpiryBalance);\n tree.remove(fbi, batch.normalisedBalance);\n delete batches[fbi];\n\n unchecked {\n ++i;\n }\n }\n // then, for all batches that have _not_ expired during the period\n // add the total normalised payout of all batches\n // multiplied by the remaining total valid chunk count\n // to the pot for the period since the last expiry\n\n if (lastExpiryBalance < _lastExpiryBalance) {\n revert TotalOutpaymentDecreased();\n }\n\n // then, for all batches that have _not_ expired during the period\n // add the total normalised payout of all batches\n // multiplied by the remaining total valid chunk count\n // to the pot for the period since the last expiry\n pot += validChunkCount * (lastExpiryBalance - _lastExpiryBalance);\n }\n\n /**\n * @notice The current pot.\n */\n function totalPot() public returns (uint256) {\n expireLimited(type(uint256).max);\n uint256 balance = ERC20(bzzToken).balanceOf(address(this));\n return pot < balance ? pot : balance;\n }\n\n /**\n * @notice Withdraw the pot, authorised callers only.\n * @param beneficiary Recieves the current total pot.\n */\n\n function withdraw(address beneficiary) external {\n if (!hasRole(REDISTRIBUTOR_ROLE, msg.sender)) {\n revert OnlyRedistributor();\n }\n\n uint256 totalAmount = totalPot();\n if (!ERC20(bzzToken).transfer(beneficiary, totalAmount)) {\n revert TransferFailed();\n }\n\n emit PotWithdrawn(beneficiary, totalAmount);\n pot = 0;\n }\n\n /**\n * @notice Pause the contract.\n * @dev Can only be called by the pauser when not paused.\n * The contract can be provably stopped by renouncing the pauser role and the admin role once paused.\n */\n function pause() public {\n if (!hasRole(PAUSER_ROLE, msg.sender)) {\n revert OnlyPauser();\n }\n _pause();\n }\n\n /**\n * @notice Unpause the contract.\n * @dev Can only be called by the pauser role while paused.\n */\n function unPause() public {\n if (!hasRole(PAUSER_ROLE, msg.sender)) {\n revert OnlyPauser();\n }\n\n _unpause();\n }\n\n ////////////////////////////////////////\n // STATE READING //\n ////////////////////////////////////////\n\n /**\n * @notice Total per-chunk cost since the contract's deployment.\n * @dev Returns the total normalised all-time per chunk payout.\n * Only Batches with a normalised balance greater than this are valid.\n */\n function currentTotalOutPayment() public view returns (uint256) {\n uint256 blocks = block.number - lastUpdatedBlock;\n uint256 increaseSinceLastUpdate = lastPrice * (blocks);\n return totalOutPayment + (increaseSinceLastUpdate);\n }\n\n function minimumInitialBalancePerChunk() public view returns (uint256) {\n return minimumValidityBlocks * lastPrice;\n }\n\n /**\n * @notice Return the per chunk balance not yet used up.\n * @param _batchId The id of an existing batch.\n */\n function remainingBalance(bytes32 _batchId) public view returns (uint256) {\n Batch memory batch = batches[_batchId];\n\n if (batch.owner == address(0)) {\n revert BatchDoesNotExist(); // Batch does not exist or expired\n }\n\n if (batch.normalisedBalance <= currentTotalOutPayment()) {\n return 0;\n }\n\n return batch.normalisedBalance - currentTotalOutPayment();\n }\n\n /**\n * @notice Indicates whether expired batches exist.\n */\n function expiredBatchesExist() public view returns (bool) {\n if (isBatchesTreeEmpty()) {\n return false;\n }\n return (remainingBalance(firstBatchId()) <= 0);\n }\n\n /**\n * @notice Return true if no batches exist\n */\n function isBatchesTreeEmpty() public view returns (bool) {\n return tree.count() == 0;\n }\n\n /**\n * @notice Get the first batch id ordered by ascending normalised balance.\n * @dev If more than one batch id, return index at 0, if no batches, revert.\n */\n function firstBatchId() public view returns (bytes32) {\n uint256 val = tree.first();\n if (val == 0) {\n revert NoBatchesExist();\n }\n return tree.valueKeyAtIndex(val, 0);\n }\n\n function batchOwner(bytes32 _batchId) public view returns (address) {\n return batches[_batchId].owner;\n }\n\n function batchDepth(bytes32 _batchId) public view returns (uint8) {\n return batches[_batchId].depth;\n }\n\n function batchBucketDepth(bytes32 _batchId) public view returns (uint8) {\n return batches[_batchId].bucketDepth;\n }\n\n function batchImmutableFlag(bytes32 _batchId) public view returns (bool) {\n return batches[_batchId].immutableFlag;\n }\n\n function batchNormalisedBalance(bytes32 _batchId) public view returns (uint256) {\n return batches[_batchId].normalisedBalance;\n }\n\n function batchLastUpdatedBlockNumber(bytes32 _batchId) public view returns (uint256) {\n return batches[_batchId].lastUpdatedBlockNumber;\n }\n}\n" + }, + "src/PriceOracle.sol": { + "content": "// SPDX-License-Identifier: BSD-3-Clause\npragma solidity ^0.8.19;\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"./interface/IPostageStamp.sol\";\n\n/**\n * @title PriceOracle contract.\n * @author The Swarm Authors.\n * @dev The price oracle contract emits a price feed using events.\n */\n\ncontract PriceOracle is AccessControl {\n // ----------------------------- State variables ------------------------------\n\n // The address of the linked PostageStamp contract\n IPostageStamp public postageStamp;\n\n uint16 targetRedundancy = 4;\n uint16 maxConsideredExtraRedundancy = 4;\n\n // When the contract is paused, price changes are not effective\n bool public isPaused = false;\n\n // The number of the last round price adjusting happend\n uint64 public lastAdjustedRound;\n\n // The minimum price allowed\n uint32 public minimumPriceUpscaled = 24000 << 10; // we upscale it by 2^10\n\n // The priceBase to modulate the price\n uint32 public priceBase = 1048576;\n\n uint64 public currentPriceUpScaled = minimumPriceUpscaled;\n\n // Constants used to modulate the price, see below usage\n uint32[9] public changeRate = [1049417, 1049206, 1048996, 1048786, 1048576, 1048366, 1048156, 1047946, 1047736];\n\n // Role allowed to update price\n bytes32 public immutable PRICE_UPDATER_ROLE;\n\n // The length of a round in blocks.\n uint8 private constant ROUND_LENGTH = 152;\n\n // ----------------------------- Events ------------------------------\n\n /**\n *@dev Emitted on every price update.\n */\n event PriceUpdate(uint256 price);\n event StampPriceUpdateFailed(uint256 attemptedPrice);\n\n // ----------------------------- Custom Errors ------------------------------\n error CallerNotAdmin(); // Caller is not the admin\n error CallerNotPriceUpdater(); // Caller is not a price updater\n error PriceAlreadyAdjusted(); // Price already adjusted in this round\n error UnexpectedZero(); // Redundancy needs to be higher then 0\n\n // ----------------------------- CONSTRUCTOR ------------------------------\n\n constructor(address _postageStamp) {\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n postageStamp = IPostageStamp(_postageStamp);\n lastAdjustedRound = currentRound();\n PRICE_UPDATER_ROLE = keccak256(\"PRICE_UPDATER_ROLE\");\n emit PriceUpdate(currentPrice());\n }\n\n ////////////////////////////////////////\n // STATE SETTING //\n ////////////////////////////////////////\n\n /**\n * @notice Manually set the price.\n * @dev Can only be called by the admin role.\n * @param _price The new price.\n */ function setPrice(uint32 _price) external returns (bool) {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert CallerNotAdmin();\n }\n\n uint64 _currentPriceUpScaled = _price << 10;\n uint64 _minimumPriceUpscaled = minimumPriceUpscaled;\n\n // Enforce minimum price\n if (_currentPriceUpScaled < _minimumPriceUpscaled) {\n _currentPriceUpScaled = _minimumPriceUpscaled;\n }\n currentPriceUpScaled = _currentPriceUpScaled;\n\n // Check if the setting of price in postagestamp succeded\n (bool success, ) = address(postageStamp).call(\n abi.encodeWithSignature(\"setPrice(uint256)\", uint256(currentPrice()))\n );\n if (!success) {\n emit StampPriceUpdateFailed(currentPrice());\n return false;\n }\n emit PriceUpdate(currentPrice());\n return true;\n }\n\n function adjustPrice(uint16 redundancy) external returns (bool) {\n if (isPaused == false) {\n if (!hasRole(PRICE_UPDATER_ROLE, msg.sender)) {\n revert CallerNotPriceUpdater();\n }\n\n uint16 usedRedundancy = redundancy;\n uint64 currentRoundNumber = currentRound();\n\n // Price can only be adjusted once per round\n if (currentRoundNumber <= lastAdjustedRound) {\n revert PriceAlreadyAdjusted();\n }\n // Redundancy may not be zero\n if (redundancy == 0) {\n revert UnexpectedZero();\n }\n\n // Enforce maximum considered extra redundancy\n uint16 maxConsideredRedundancy = targetRedundancy + maxConsideredExtraRedundancy;\n if (redundancy > maxConsideredRedundancy) {\n usedRedundancy = maxConsideredRedundancy;\n }\n\n uint64 _currentPriceUpScaled = currentPriceUpScaled;\n uint64 _minimumPriceUpscaled = minimumPriceUpscaled;\n uint32 _priceBase = priceBase;\n\n // Set the number of rounds that were skipped\n uint64 skippedRounds = currentRoundNumber - lastAdjustedRound - 1;\n\n // We first apply the increase/decrease rate for the current round\n uint32 _changeRate = changeRate[usedRedundancy];\n _currentPriceUpScaled = (_changeRate * _currentPriceUpScaled) / _priceBase;\n\n // If previous rounds were skipped, use MAX price increase for the previous rounds\n if (skippedRounds > 0) {\n _changeRate = changeRate[0];\n for (uint64 i = 0; i < skippedRounds; i++) {\n _currentPriceUpScaled = (_changeRate * _currentPriceUpScaled) / _priceBase;\n }\n }\n\n // Enforce minimum price\n if (_currentPriceUpScaled < _minimumPriceUpscaled) {\n _currentPriceUpScaled = _minimumPriceUpscaled;\n }\n\n currentPriceUpScaled = _currentPriceUpScaled;\n lastAdjustedRound = currentRoundNumber;\n\n // Check if the price set in postagestamp succeded\n (bool success, ) = address(postageStamp).call(\n abi.encodeWithSignature(\"setPrice(uint256)\", uint256(currentPrice()))\n );\n if (!success) {\n emit StampPriceUpdateFailed(currentPrice());\n return false;\n }\n emit PriceUpdate(currentPrice());\n return true;\n }\n return false;\n }\n\n function pause() external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert CallerNotAdmin();\n }\n isPaused = true;\n }\n\n function unPause() external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert CallerNotAdmin();\n }\n isPaused = false;\n }\n\n ////////////////////////////////////////\n // STATE READING //\n ////////////////////////////////////////\n\n /**\n * @notice Return the number of the current round.\n */\n function currentRound() public view returns (uint64) {\n // We downcasted to uint64 as uint64 has 18,446,744,073,709,551,616 places\n // as each round is 152 x 5 = 760, each day has around 113 rounds which is 41245 in a year\n // it results 4.4724801e+14 years to run this game\n return uint64(block.number / uint256(ROUND_LENGTH));\n }\n\n /**\n * @notice Return the price downscaled\n */\n function currentPrice() public view returns (uint32) {\n // We downcasted to uint32 and bitshift it by 2^10\n return uint32((currentPriceUpScaled) >> 10);\n }\n\n /**\n * @notice Return the price downscaled\n */\n function minimumPrice() public view returns (uint32) {\n // We downcasted to uint32 and bitshift it by 2^10\n return uint32((minimumPriceUpscaled) >> 10);\n }\n}\n" + }, + "src/Redistribution.sol": { + "content": "// SPDX-License-Identifier: BSD-3-Clause\npragma solidity ^0.8.19;\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"@openzeppelin/contracts/security/Pausable.sol\";\nimport \"./Util/TransformedChunkProof.sol\";\nimport \"./Util/ChunkProof.sol\";\nimport \"./Util/Signatures.sol\";\nimport \"./interface/IPostageStamp.sol\";\n\ninterface IPriceOracle {\n function adjustPrice(uint16 redundancy) external returns (bool);\n}\n\ninterface IStakeRegistry {\n struct Stake {\n bytes32 overlay;\n uint256 stakeAmount;\n uint256 lastUpdatedBlockNumber;\n }\n\n function freezeDeposit(address _owner, uint256 _time) external;\n\n function lastUpdatedBlockNumberOfAddress(address _owner) external view returns (uint256);\n\n function overlayOfAddress(address _owner) external view returns (bytes32);\n\n function heightOfAddress(address _owner) external view returns (uint8);\n\n function nodeEffectiveStake(address _owner) external view returns (uint256);\n}\n\n/**\n * @title Redistribution contract\n * @author The Swarm Authors\n * @dev Implements a Schelling Co-ordination game to form consensus around the Reserve Commitment hash. This takes\n * place in three phases: _commit_, _reveal_ and _claim_.\n *\n * A node, upon establishing that it _isParticipatingInUpcomingRound_, i.e. it's overlay falls within proximity order\n * of its reported depth with the _currentRoundAnchor_, prepares a \"reserve commitment hash\" using the chunks\n * it currently stores in its reserve and calculates the \"storage depth\" (see Bee for details). These values, if calculated\n * honestly, and with the right chunks stored, should be the same for every node in a neighbourhood. This is the Schelling point.\n * Each eligible node can then use these values, together with a random, single use, secret _revealNonce_ and their\n * _overlay_ as the pre-image values for the obsfucated _commit_, using the _wrapCommit_ method.\n *\n * Once the _commit_ round has elapsed, participating nodes must provide the values used to calculate their obsfucated\n * _commit_ hash, which, once verified for correctness and proximity to the anchor are retained in the _currentReveals_.\n * Nodes that have committed but do not reveal the correct values used to create the pre-image will have their stake\n * \"frozen\" for a period of rounds proportional to their reported depth.\n *\n * During the _reveal_ round, randomness is updated after every successful reveal. Once the reveal round is concluded,\n * the _currentRoundAnchor_ is updated and users can determine if they will be eligible their overlay will be eligible\n * for the next commit phase using _isParticipatingInUpcomingRound_.\n *\n * When the _reveal_ phase has been concluded, the claim phase can begin. At this point, the truth teller and winner\n * are already determined. By calling _isWinner_, an applicant node can run the relevant logic to determine if they have\n * been selected as the beneficiary of this round. When calling _claim_, the current pot from the PostageStamp contract\n * is withdrawn and transferred to that beneficiaries address. Nodes that have revealed values that differ from the truth,\n * have their stakes \"frozen\" for a period of rounds proportional to their reported depth.\n */\n\ncontract Redistribution is AccessControl, Pausable {\n // ----------------------------- Type declarations ------------------------------\n\n // An eligible user may commit to an _obfuscatedHash_ during the commit phase...\n struct Commit {\n bytes32 overlay;\n address owner;\n bool revealed;\n uint8 height;\n uint256 stake;\n bytes32 obfuscatedHash;\n uint256 revealIndex;\n }\n // ...then provide the actual values that are the constituents of the pre-image of the _obfuscatedHash_\n // during the reveal phase.\n struct Reveal {\n bytes32 overlay;\n address owner;\n uint8 depth;\n uint256 stake;\n uint256 stakeDensity;\n bytes32 hash;\n }\n\n struct ChunkInclusionProof {\n bytes32[] proofSegments;\n bytes32 proveSegment;\n // _RCspan is known for RC 32*32\n\n // Inclusion proof of transformed address\n bytes32[] proofSegments2;\n bytes32 proveSegment2;\n // proveSegmentIndex2 known from deterministic random selection;\n uint64 chunkSpan;\n bytes32[] proofSegments3;\n // _proveSegment3 known, is equal _proveSegment2\n // proveSegmentIndex3 know, is equal _proveSegmentIndex2;\n // chunkSpan2 is equal to chunkSpan (as the data is the same)\n //\n PostageProof postageProof;\n SOCProof[] socProof;\n }\n\n struct SOCProof {\n address signer; // signer Ethereum address to check against\n bytes signature;\n bytes32 identifier; //\n bytes32 chunkAddr; // wrapped chunk address\n }\n\n struct PostageProof {\n bytes signature;\n bytes32 postageId;\n uint64 index;\n uint64 timeStamp;\n // address signer; it is provided by the postage stamp contract\n // bytes32 chunkAddr; it equals to the proveSegment argument\n }\n\n // The address of the linked PostageStamp contract.\n IPostageStamp public PostageContract;\n // The address of the linked PriceOracle contract.\n IPriceOracle public OracleContract;\n // The address of the linked Staking contract.\n IStakeRegistry public Stakes;\n\n // Commits for the current round.\n Commit[] public currentCommits;\n // Reveals for the current round.\n Reveal[] public currentReveals;\n\n // The current anchor that being processed for the reveal and claim phases of the round.\n bytes32 private currentRevealRoundAnchor;\n\n // The current random value from which we will random.\n // inputs for selection of the truth teller and beneficiary.\n bytes32 private seed;\n\n // The number of the currently active round phases.\n uint64 public currentCommitRound;\n uint64 public currentRevealRound;\n uint64 public currentClaimRound;\n\n // Settings for slashing and freezing\n uint8 private penaltyMultiplierDisagreement = 1;\n uint8 private penaltyMultiplierNonRevealed = 2;\n uint8 private penaltyRandomFactor = 100; // Use 100 as value to ignore random factor in freezing penalty\n\n // alpha=0.097612 beta=0.0716570 k=16\n uint256 private sampleMaxValue = 1284401000000000000000000000000000000000000000000000000000000000000000000;\n\n // The reveal of the winner of the last round.\n Reveal public winner;\n\n // The length of a round in blocks.\n uint256 private constant ROUND_LENGTH = 152;\n\n // Maximum value of the keccack256 hash.\n bytes32 private constant MAX_H = 0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff;\n\n // ----------------------------- Events ------------------------------\n\n /**\n * @dev Emitted when the winner of a round is selected in the claim phase\n */\n event WinnerSelected(Reveal winner);\n\n /**\n * @dev Emitted when the truth oracle of a round is selected in the claim phase.\n */\n event TruthSelected(bytes32 hash, uint8 depth);\n\n // Next two events to be removed after testing phase pending some other usefulness being found.\n /**\n * @dev Emits the number of commits being processed by the claim phase.\n */\n event CountCommits(uint256 _count);\n\n /**\n * @dev Emits the number of reveals being processed by the claim phase.\n */\n event CountReveals(uint256 _count);\n\n /**\n * @dev Logs that an overlay has committed\n */\n event Committed(uint256 roundNumber, bytes32 overlay, uint8 height);\n /**\n * @dev Emit from Postagestamp contract valid chunk count at the end of claim\n */\n event ChunkCount(uint256 validChunkCount);\n\n /**\n * @dev Bytes32 anhor of current reveal round\n */\n event CurrentRevealAnchor(uint256 roundNumber, bytes32 anchor);\n\n /**\n * @dev Output external call status\n */\n event PriceAdjustmentSkipped(uint16 redundancyCount);\n\n /**\n * @dev Withdraw not successful in claim\n */\n event WithdrawFailed(address owner);\n\n /**\n * @dev Logs that an overlay has revealed\n */\n event Revealed(\n uint256 roundNumber,\n bytes32 overlay,\n uint256 stake,\n uint256 stakeDensity,\n bytes32 reserveCommitment,\n uint8 depth\n );\n\n /**\n * @dev Logs for inclusion proof\n */\n event transformedChunkAddressFromInclusionProof(uint256 indexInRC, bytes32 chunkAddress);\n\n // ----------------------------- Errors ------------------------------\n\n error NotCommitPhase(); // Game is not in commit phase\n error NoCommitsReceived(); // Round didn't receive any commits\n error PhaseLastBlock(); // We don't permit commits in last block of the phase\n error CommitRoundOver(); // Commit phase in this round is over\n error CommitRoundNotStarted(); // Commit phase in this round has not started yet\n error NotMatchingOwner(); // Sender of commit is not matching the overlay address\n error MustStake2Rounds(); // Before entering the game node must stake 2 rounds prior\n error NotStaked(); // Node didn't add any staking\n error WrongPhase(); // Checking in wrong phase, need to check duing claim phase of current round for next round or commit in current round\n error AlreadyCommitted(); // Node already committed in this round\n error NotRevealPhase(); // Game is not in reveal phase\n error OutOfDepthReveal(bytes32); // Anchor is out of reported depth in Reveal phase, anchor data available as argument\n error OutOfDepthClaim(uint8); // Anchor is out of reported depth in Claim phase, entryProof index is argument\n error OutOfDepth(); // Anchor is out of reported depth\n error AlreadyRevealed(); // Node already revealed\n error NoMatchingCommit(); // No matching commit and hash\n error NotClaimPhase(); // Game is not in the claim phase\n error NoReveals(); // Round did not receive any reveals\n error FirstRevealDone(); // We don't want to return value after first reveal\n error AlreadyClaimed(); // This round was already claimed\n error NotAdmin(); // Caller of trx is not admin\n error OnlyPauser(); // Only account with pauser role can call pause/unpause\n error SocVerificationFailed(bytes32); // Soc verification failed for this element\n error SocCalcNotMatching(bytes32); // Soc address calculation does not match with the witness\n error IndexOutsideSet(bytes32); // Stamp available: index resides outside of the valid index set\n error SigRecoveryFailed(bytes32); // Stamp authorized: signature recovery failed for element\n error BatchDoesNotExist(bytes32); // Stamp alive: batch remaining balance validation failed for attached stamp\n error BucketDiffers(bytes32); // Stamp aligned: postage bucket differs from address bucket\n error InclusionProofFailed(uint8, bytes32);\n // 1 = RC inclusion proof failed for element\n // 2 = First sister segment in data must match,\n // 3 = Inclusion proof failed for original address of element\n // 4 = Inclusion proof failed for transformed address of element\n error RandomElementCheckFailed(); // Random element order check failed\n error LastElementCheckFailed(); // Last element order check failed\n error ReserveCheckFailed(bytes32 trALast); // Reserve size estimation check failed\n\n // ----------------------------- CONSTRUCTOR ------------------------------\n\n /**\n * @param staking the address of the linked Staking contract.\n * @param postageContract the address of the linked PostageStamp contract.\n * @param oracleContract the address of the linked PriceOracle contract.\n */\n constructor(address staking, address postageContract, address oracleContract) {\n Stakes = IStakeRegistry(staking);\n PostageContract = IPostageStamp(postageContract);\n OracleContract = IPriceOracle(oracleContract);\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n }\n\n ////////////////////////////////////////\n // STATE CHANGING //\n ////////////////////////////////////////\n\n /**\n * @notice Begin application for a round if eligible. Commit a hashed value for which the pre-image will be\n * subsequently revealed.\n * @dev If a node's overlay is _inProximity_(_depth_) of the _currentRoundAnchor_, that node may compute an\n * _obfuscatedHash_ by providing their _overlay_, reported storage _depth_, reserve commitment _hash_ and a\n * randomly generated, and secret _revealNonce_ to the _wrapCommit_ method.\n * @param _obfuscatedHash The calculated hash resultant of the required pre-image values.\n * and be derived from the same key pair as the message sender.\n * @param _roundNumber Node needs to provide round number for which commit is valid\n */\n function commit(bytes32 _obfuscatedHash, uint64 _roundNumber) external whenNotPaused {\n uint64 cr = currentRound();\n bytes32 _overlay = Stakes.overlayOfAddress(msg.sender);\n uint256 _stake = Stakes.nodeEffectiveStake(msg.sender);\n uint256 _lastUpdate = Stakes.lastUpdatedBlockNumberOfAddress(msg.sender);\n uint8 _height = Stakes.heightOfAddress(msg.sender);\n\n if (!currentPhaseCommit()) {\n revert NotCommitPhase();\n }\n if (block.number % ROUND_LENGTH == (ROUND_LENGTH / 4) - 1) {\n revert PhaseLastBlock();\n }\n\n if (cr > _roundNumber) {\n revert CommitRoundOver();\n }\n\n if (cr < _roundNumber) {\n revert CommitRoundNotStarted();\n }\n\n if (_lastUpdate == 0) {\n revert NotStaked();\n }\n\n if (_lastUpdate >= block.number - 2 * ROUND_LENGTH) {\n revert MustStake2Rounds();\n }\n\n // if we are in a new commit phase, reset the array of commits and\n // set the currentCommitRound to be the current one\n if (cr != currentCommitRound) {\n delete currentCommits;\n currentCommitRound = cr;\n }\n\n uint256 commitsArrayLength = currentCommits.length;\n\n for (uint256 i = 0; i < commitsArrayLength; ) {\n if (currentCommits[i].overlay == _overlay) {\n revert AlreadyCommitted();\n }\n\n unchecked {\n ++i;\n }\n }\n\n currentCommits.push(\n Commit({\n overlay: _overlay,\n owner: msg.sender,\n revealed: false,\n height: _height,\n stake: _stake,\n obfuscatedHash: _obfuscatedHash,\n revealIndex: 0\n })\n );\n\n emit Committed(_roundNumber, _overlay, _height);\n }\n\n /**\n * @notice Reveal the pre-image values used to generate commit provided during this round's commit phase.\n * @param _depth The reported depth.\n * @param _hash The reserve commitment hash.\n * @param _revealNonce The nonce used to generate the commit that is being revealed.\n */\n function reveal(uint8 _depth, bytes32 _hash, bytes32 _revealNonce) external whenNotPaused {\n uint64 cr = currentRound();\n bytes32 _overlay = Stakes.overlayOfAddress(msg.sender);\n\n if (_depth < currentMinimumDepth()) {\n revert OutOfDepth();\n }\n\n if (!currentPhaseReveal()) {\n revert NotRevealPhase();\n }\n\n if (cr != currentCommitRound) {\n revert NoCommitsReceived();\n }\n\n if (cr != currentRevealRound) {\n currentRevealRoundAnchor = currentRoundAnchor();\n delete currentReveals;\n // We set currentRevealRound ONLY after we set current anchor\n currentRevealRound = cr;\n emit CurrentRevealAnchor(cr, currentRevealRoundAnchor);\n updateRandomness();\n }\n\n bytes32 obfuscatedHash = wrapCommit(_overlay, _depth, _hash, _revealNonce);\n uint256 id = findCommit(_overlay, obfuscatedHash);\n Commit memory revealedCommit = currentCommits[id];\n uint8 depthResponsibility = _depth - revealedCommit.height;\n\n // Check that commit is in proximity of the current anchor\n if (!inProximity(revealedCommit.overlay, currentRevealRoundAnchor, depthResponsibility)) {\n revert OutOfDepthReveal(currentRevealRoundAnchor);\n }\n // Check that the commit has not already been revealed\n if (revealedCommit.revealed) {\n revert AlreadyRevealed();\n }\n\n currentCommits[id].revealed = true;\n currentCommits[id].revealIndex = currentReveals.length;\n\n currentReveals.push(\n Reveal({\n overlay: revealedCommit.overlay,\n owner: revealedCommit.owner,\n depth: _depth,\n stake: revealedCommit.stake,\n stakeDensity: revealedCommit.stake * uint256(2 ** depthResponsibility),\n hash: _hash\n })\n );\n\n emit Revealed(\n cr,\n revealedCommit.overlay,\n revealedCommit.stake,\n revealedCommit.stake * uint256(2 ** depthResponsibility),\n _hash,\n _depth\n );\n }\n\n /**\n * @notice Helper function to get this round truth\n * @dev\n */\n function claim(\n ChunkInclusionProof calldata entryProof1,\n ChunkInclusionProof calldata entryProof2,\n ChunkInclusionProof calldata entryProofLast\n ) external whenNotPaused {\n winnerSelection();\n\n Reveal memory winnerSelected = winner;\n uint256 indexInRC1;\n uint256 indexInRC2;\n bytes32 _currentRevealRoundAnchor = currentRevealRoundAnchor;\n bytes32 _seed = seed;\n\n // rand(14)\n indexInRC1 = uint256(_seed) % 15;\n // rand(13)\n indexInRC2 = uint256(_seed) % 14;\n if (indexInRC2 >= indexInRC1) {\n indexInRC2++;\n }\n\n if (!inProximity(entryProofLast.proveSegment, _currentRevealRoundAnchor, winnerSelected.depth)) {\n revert OutOfDepthClaim(3);\n }\n\n inclusionFunction(entryProofLast, 30);\n stampFunction(entryProofLast);\n socFunction(entryProofLast);\n\n if (!inProximity(entryProof1.proveSegment, _currentRevealRoundAnchor, winnerSelected.depth)) {\n revert OutOfDepthClaim(2);\n }\n\n inclusionFunction(entryProof1, indexInRC1 * 2);\n stampFunction(entryProof1);\n socFunction(entryProof1);\n\n if (!inProximity(entryProof2.proveSegment, _currentRevealRoundAnchor, winnerSelected.depth)) {\n revert OutOfDepthClaim(1);\n }\n\n inclusionFunction(entryProof2, indexInRC2 * 2);\n stampFunction(entryProof2);\n socFunction(entryProof2);\n\n checkOrder(\n indexInRC1,\n indexInRC2,\n entryProof1.proofSegments[0],\n entryProof2.proofSegments[0],\n entryProofLast.proofSegments[0]\n );\n\n estimateSize(entryProofLast.proofSegments[0]);\n\n // Do the check if the withdraw was success\n (bool success, ) = address(PostageContract).call(\n abi.encodeWithSignature(\"withdraw(address)\", winnerSelected.owner)\n );\n if (!success) {\n emit WithdrawFailed(winnerSelected.owner);\n }\n\n emit WinnerSelected(winnerSelected);\n emit ChunkCount(PostageContract.validChunkCount());\n }\n\n function winnerSelection() internal {\n uint64 cr = currentRound();\n\n if (!currentPhaseClaim()) {\n revert NotClaimPhase();\n }\n\n if (cr != currentRevealRound) {\n revert NoReveals();\n }\n\n if (cr <= currentClaimRound) {\n revert AlreadyClaimed();\n }\n\n uint256 currentWinnerSelectionSum = 0;\n uint256 redundancyCount = 0;\n bytes32 randomNumber;\n uint256 randomNumberTrunc;\n\n bytes32 truthRevealedHash;\n uint8 truthRevealedDepth;\n uint256 currentCommitsLength = currentCommits.length;\n\n emit CountCommits(currentCommitsLength);\n emit CountReveals(currentReveals.length);\n\n (truthRevealedHash, truthRevealedDepth) = getCurrentTruth();\n emit TruthSelected(truthRevealedHash, truthRevealedDepth);\n string memory winnerSelectionAnchor = currentWinnerSelectionAnchor();\n\n for (uint256 i = 0; i < currentCommitsLength; ) {\n Commit memory currentCommit = currentCommits[i];\n uint256 revIndex = currentCommit.revealIndex;\n Reveal memory currentReveal = currentReveals[revIndex];\n\n // Select winner with valid truth\n if (\n currentCommit.revealed &&\n truthRevealedHash == currentReveal.hash &&\n truthRevealedDepth == currentReveal.depth\n ) {\n currentWinnerSelectionSum += currentReveal.stakeDensity;\n randomNumber = keccak256(abi.encodePacked(winnerSelectionAnchor, redundancyCount));\n randomNumberTrunc = uint256(randomNumber & MAX_H);\n\n if (randomNumberTrunc * currentWinnerSelectionSum < currentReveal.stakeDensity * (uint256(MAX_H) + 1)) {\n winner = currentReveal;\n }\n\n redundancyCount++;\n }\n\n // Freeze deposit if any truth is false, make it a penaltyRandomFactor chance for this to happen\n if (\n currentCommit.revealed &&\n (truthRevealedHash != currentReveal.hash || truthRevealedDepth != currentReveal.depth) &&\n (block.prevrandao % 100 < penaltyRandomFactor)\n ) {\n Stakes.freezeDeposit(\n currentReveal.owner,\n penaltyMultiplierDisagreement * ROUND_LENGTH * uint256(2 ** truthRevealedDepth)\n );\n }\n\n // Slash deposits if revealed is false\n if (!currentCommit.revealed) {\n // slash in later phase (ph5)\n // Stakes.slashDeposit(currentCommits[i].overlay, currentCommits[i].stake);\n Stakes.freezeDeposit(\n currentCommit.owner,\n penaltyMultiplierNonRevealed * ROUND_LENGTH * uint256(2 ** truthRevealedDepth)\n );\n }\n unchecked {\n ++i;\n }\n }\n\n bool success = OracleContract.adjustPrice(uint16(redundancyCount));\n if (!success) {\n emit PriceAdjustmentSkipped(uint16(redundancyCount));\n }\n currentClaimRound = cr;\n }\n\n function inclusionFunction(ChunkInclusionProof calldata entryProof, uint256 indexInRC) internal {\n uint256 randomChunkSegmentIndex = uint256(seed) % 128;\n bytes32 calculatedTransformedAddr = TransformedBMTChunk.transformedChunkAddressFromInclusionProof(\n entryProof.proofSegments3,\n entryProof.proveSegment2,\n randomChunkSegmentIndex,\n entryProof.chunkSpan,\n currentRevealRoundAnchor\n );\n\n emit transformedChunkAddressFromInclusionProof(indexInRC, calculatedTransformedAddr);\n\n if (\n winner.hash !=\n BMTChunk.chunkAddressFromInclusionProof(\n entryProof.proofSegments,\n entryProof.proveSegment,\n indexInRC,\n 32 * 32\n )\n ) {\n revert InclusionProofFailed(1, calculatedTransformedAddr);\n }\n\n if (entryProof.proofSegments2[0] != entryProof.proofSegments3[0]) {\n revert InclusionProofFailed(2, calculatedTransformedAddr);\n }\n\n bytes32 originalAddress = entryProof.socProof.length > 0\n ? entryProof.socProof[0].chunkAddr // soc attestation in socFunction\n : entryProof.proveSegment;\n\n if (\n originalAddress !=\n BMTChunk.chunkAddressFromInclusionProof(\n entryProof.proofSegments2,\n entryProof.proveSegment2,\n randomChunkSegmentIndex,\n entryProof.chunkSpan\n )\n ) {\n revert InclusionProofFailed(3, calculatedTransformedAddr);\n }\n\n // In case of SOC, the transformed address is hashed together with its address in the sample\n if (entryProof.socProof.length > 0) {\n calculatedTransformedAddr = keccak256(\n abi.encode(\n entryProof.proveSegment, // SOC address\n calculatedTransformedAddr\n )\n );\n }\n\n if (entryProof.proofSegments[0] != calculatedTransformedAddr) {\n revert InclusionProofFailed(4, calculatedTransformedAddr);\n }\n }\n\n /**\n * @notice Set freezing parameters\n */\n function setFreezingParams(\n uint8 _penaltyMultiplierDisagreement,\n uint8 _penaltyMultiplierNonRevealed,\n uint8 _penaltyRandomFactor\n ) external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert NotAdmin();\n }\n\n penaltyMultiplierDisagreement = _penaltyMultiplierDisagreement;\n penaltyMultiplierNonRevealed = _penaltyMultiplierNonRevealed;\n penaltyRandomFactor = _penaltyRandomFactor;\n }\n\n /**\n * @notice changes the max sample value used for reserve estimation\n */\n function setSampleMaxValue(uint256 _sampleMaxValue) external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert NotAdmin();\n }\n\n sampleMaxValue = _sampleMaxValue;\n }\n\n /**\n * @notice Updates the source of randomness. Uses block.difficulty in pre-merge chains, this is substituted\n * to block.prevrandao in post merge chains.\n */\n function updateRandomness() private {\n seed = keccak256(abi.encode(seed, block.prevrandao));\n }\n\n /**\n * @dev Pause the contract. The contract is provably stopped by renouncing\n the pauser role and the admin role after pausing, can only be called by the `PAUSER`\n */\n function pause() public {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert OnlyPauser();\n }\n\n _pause();\n }\n\n /**\n * @dev Unpause the contract, can only be called by the pauser when paused\n */\n function unPause() public {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert OnlyPauser();\n }\n _unpause();\n }\n\n ////////////////////////////////////////\n // STATE READING //\n ////////////////////////////////////////\n\n // ----------------------------- Anchor calculations ------------------------------\n\n /**\n * @notice Returns the current random seed which is used to determine later utilised random numbers.\n * If rounds have elapsed without reveals, hash the seed with an incremented nonce to produce a new\n * random seed and hence a new round anchor.\n */\n function currentSeed() public view returns (bytes32) {\n uint64 cr = currentRound();\n bytes32 currentSeedValue = seed;\n\n if (cr > currentRevealRound + 1) {\n uint256 difference = cr - currentRevealRound - 1;\n currentSeedValue = keccak256(abi.encodePacked(currentSeedValue, difference));\n }\n\n return currentSeedValue;\n }\n\n /**\n * @notice Returns the seed which will become current once the next commit phase begins.\n * Used to determine what the next round's anchor will be.\n */\n function nextSeed() public view returns (bytes32) {\n uint64 cr = currentRound() + 1;\n bytes32 currentSeedValue = seed;\n\n if (cr > currentRevealRound + 1) {\n uint256 difference = cr - currentRevealRound - 1;\n currentSeedValue = keccak256(abi.encodePacked(currentSeedValue, difference));\n }\n\n return currentSeedValue;\n }\n\n /**\n * @notice The random value used to choose the selected truth teller.\n */\n function currentTruthSelectionAnchor() private view returns (string memory) {\n if (!currentPhaseClaim()) {\n revert NotClaimPhase();\n }\n\n uint64 cr = currentRound();\n if (cr != currentRevealRound) {\n revert NoReveals();\n }\n\n return string(abi.encodePacked(seed, \"0\"));\n }\n\n /**\n * @notice The random value used to choose the selected beneficiary.\n */\n function currentWinnerSelectionAnchor() private view returns (string memory) {\n if (!currentPhaseClaim()) {\n revert NotClaimPhase();\n }\n uint64 cr = currentRound();\n if (cr != currentRevealRound) {\n revert NoReveals();\n }\n\n return string(abi.encodePacked(seed, \"1\"));\n }\n\n /**\n * @notice The anchor used to determine eligibility for the current round.\n * @dev A node must be within proximity order of less than or equal to the storage depth they intend to report.\n */\n function currentRoundAnchor() public view returns (bytes32 returnVal) {\n // This will be called in reveal phase and set as currentRevealRoundAnchor or in\n // commit phase when checking eligibility for next round by isParticipatingInUpcomingRound\n if (currentPhaseCommit() || (currentRound() > currentRevealRound && !currentPhaseClaim())) {\n return currentSeed();\n }\n\n // This will be called by isParticipatingInUpcomingRound check in claim phase\n if (currentPhaseClaim()) {\n return nextSeed();\n }\n\n // Without this, this function will output 0x0 after first reveal which is value and we prefere it reverts\n if (currentPhaseReveal() && currentRound() == currentRevealRound) {\n revert FirstRevealDone();\n }\n }\n\n /**\n * @notice Returns true if an overlay address _A_ is within proximity order _minimum_ of _B_.\n * @param A An overlay address to compare.\n * @param B An overlay address to compare.\n * @param minimum Minimum proximity order.\n */\n function inProximity(bytes32 A, bytes32 B, uint8 minimum) public pure returns (bool) {\n if (minimum == 0) {\n return true;\n }\n\n return uint256(A ^ B) < uint256(2 ** (256 - minimum));\n }\n\n // ----------------------------- Commit ------------------------------\n\n /**\n * @notice The number of the current round.\n */\n function currentRound() public view returns (uint64) {\n return uint64(block.number / ROUND_LENGTH);\n }\n\n /**\n * @notice Returns true if current block is during commit phase.\n */\n function currentPhaseCommit() public view returns (bool) {\n if (block.number % ROUND_LENGTH < ROUND_LENGTH / 4) {\n return true;\n }\n return false;\n }\n\n /**\n * @notice Determine if a the owner of a given overlay can participate in the upcoming round.\n * @param _owner The address of the applicant from.\n * @param _depth The storage depth the applicant intends to report.\n */\n function isParticipatingInUpcomingRound(address _owner, uint8 _depth) public view returns (bool) {\n uint256 _lastUpdate = Stakes.lastUpdatedBlockNumberOfAddress(_owner);\n uint8 _depthResponsibility = _depth - Stakes.heightOfAddress(_owner);\n\n if (currentPhaseReveal()) {\n revert WrongPhase();\n }\n\n if (_lastUpdate == 0) {\n revert NotStaked();\n }\n\n if (_lastUpdate >= block.number - 2 * ROUND_LENGTH) {\n revert MustStake2Rounds();\n }\n\n return inProximity(Stakes.overlayOfAddress(_owner), currentRoundAnchor(), _depthResponsibility);\n }\n\n // ----------------------------- Reveal ------------------------------\n\n /**\n * @notice Returns minimum depth reveal has to have to participate in this round\n */\n function currentMinimumDepth() public view returns (uint8) {\n // We are checking value in reveal phase, as the currentCommitRound is set to the current round\n // but the currentClaimRound is still set to the last time claim was made\n // We add 1 to ensure that for the next round the minimum depth is the same as last winner depth\n\n uint256 difference = currentCommitRound - currentClaimRound;\n uint8 skippedRounds = uint8(difference > 254 ? 254 : difference) + 1;\n\n uint8 lastWinnerDepth = winner.depth;\n\n // We ensure that skippedRounds is not bigger than lastWinnerDepth, because of overflow\n return skippedRounds >= lastWinnerDepth ? 0 : lastWinnerDepth - skippedRounds;\n }\n\n /**\n * @notice Helper function to get this node reveal in commits\n * @dev\n */\n function findCommit(bytes32 _overlay, bytes32 _obfuscatedHash) internal view returns (uint256) {\n for (uint256 i = 0; i < currentCommits.length; ) {\n if (currentCommits[i].overlay == _overlay && _obfuscatedHash == currentCommits[i].obfuscatedHash) {\n return i;\n }\n unchecked {\n ++i;\n }\n }\n revert NoMatchingCommit();\n }\n\n /**\n * @notice Hash the pre-image values to the obsfucated hash.\n * @dev _revealNonce_ must be randomly generated, used once and kept secret until the reveal phase.\n * @param _overlay The overlay address of the applicant.\n * @param _depth The reported depth.\n * @param _hash The reserve commitment hash.\n * @param revealNonce A random, single use, secret nonce.\n */\n function wrapCommit(\n bytes32 _overlay,\n uint8 _depth,\n bytes32 _hash,\n bytes32 revealNonce\n ) public pure returns (bytes32) {\n return keccak256(abi.encodePacked(_overlay, _depth, _hash, revealNonce));\n }\n\n /**\n * @notice Returns true if current block is during reveal phase.\n */\n function currentPhaseReveal() public view returns (bool) {\n uint256 number = block.number % ROUND_LENGTH;\n if (number >= ROUND_LENGTH / 4 && number < ROUND_LENGTH / 2) {\n return true;\n }\n return false;\n }\n\n /**\n * @notice Returns true if current block is during reveal phase.\n */\n function currentRoundReveals() public view returns (Reveal[] memory) {\n if (!currentPhaseClaim()) {\n revert NotClaimPhase();\n }\n uint64 cr = currentRound();\n if (cr != currentRevealRound) {\n revert NoReveals();\n }\n\n return currentReveals;\n }\n\n // ----------------------------- Claim ------------------------------\n\n /**\n * @notice Returns true if current block is during claim phase.\n */\n function currentPhaseClaim() public view returns (bool) {\n if (block.number % ROUND_LENGTH >= ROUND_LENGTH / 2) {\n return true;\n }\n return false;\n }\n\n function getCurrentTruth() internal view returns (bytes32 Hash, uint8 Depth) {\n uint256 currentSum;\n bytes32 randomNumber;\n uint256 randomNumberTrunc;\n\n bytes32 truthRevealedHash;\n uint8 truthRevealedDepth;\n uint256 revIndex;\n string memory truthSelectionAnchor = currentTruthSelectionAnchor();\n uint256 commitsArrayLength = currentCommits.length;\n\n for (uint256 i = 0; i < commitsArrayLength; ) {\n if (currentCommits[i].revealed) {\n revIndex = currentCommits[i].revealIndex;\n currentSum += currentReveals[revIndex].stakeDensity;\n randomNumber = keccak256(abi.encodePacked(truthSelectionAnchor, i));\n randomNumberTrunc = uint256(randomNumber & MAX_H);\n\n // question is whether randomNumber / MAX_H < probability\n // where probability is stakeDensity / currentSum\n // to avoid resorting to floating points all divisions should be\n // simplified with multiplying both sides (as long as divisor > 0)\n // randomNumber / (MAX_H + 1) < stakeDensity / currentSum\n // ( randomNumber / (MAX_H + 1) ) * currentSum < stakeDensity\n // randomNumber * currentSum < stakeDensity * (MAX_H + 1)\n if (randomNumberTrunc * currentSum < currentReveals[revIndex].stakeDensity * (uint256(MAX_H) + 1)) {\n truthRevealedHash = currentReveals[revIndex].hash;\n truthRevealedDepth = currentReveals[revIndex].depth;\n }\n }\n unchecked {\n ++i;\n }\n }\n\n return (truthRevealedHash, truthRevealedDepth);\n }\n\n /**\n * @notice Determine if a the owner of a given overlay will be the beneficiary of the claim phase.\n * @param _overlay The overlay address of the applicant.\n */\n function isWinner(bytes32 _overlay) public view returns (bool) {\n if (!currentPhaseClaim()) {\n revert NotClaimPhase();\n }\n\n uint64 cr = currentRound();\n if (cr != currentRevealRound) {\n revert NoReveals();\n }\n\n if (cr <= currentClaimRound) {\n revert AlreadyClaimed();\n }\n\n uint256 currentWinnerSelectionSum;\n bytes32 winnerIs;\n bytes32 randomNumber;\n uint256 randomNumberTrunc;\n bytes32 truthRevealedHash;\n uint8 truthRevealedDepth;\n uint256 revIndex;\n string memory winnerSelectionAnchor = currentWinnerSelectionAnchor();\n uint256 redundancyCount = 0;\n\n // Get current truth\n (truthRevealedHash, truthRevealedDepth) = getCurrentTruth();\n uint256 commitsArrayLength = currentCommits.length;\n\n for (uint256 i = 0; i < commitsArrayLength; ) {\n revIndex = currentCommits[i].revealIndex;\n\n // Deterministically read winner\n if (\n currentCommits[i].revealed &&\n truthRevealedHash == currentReveals[revIndex].hash &&\n truthRevealedDepth == currentReveals[revIndex].depth\n ) {\n currentWinnerSelectionSum += currentReveals[revIndex].stakeDensity;\n randomNumber = keccak256(abi.encodePacked(winnerSelectionAnchor, redundancyCount));\n randomNumberTrunc = uint256(randomNumber & MAX_H);\n\n if (\n randomNumberTrunc * currentWinnerSelectionSum <\n currentReveals[revIndex].stakeDensity * (uint256(MAX_H) + 1)\n ) {\n winnerIs = currentReveals[revIndex].overlay;\n }\n\n redundancyCount++;\n }\n unchecked {\n ++i;\n }\n }\n\n return (winnerIs == _overlay);\n }\n\n // ----------------------------- Claim verifications ------------------------------\n\n function socFunction(ChunkInclusionProof calldata entryProof) internal pure {\n if (entryProof.socProof.length == 0) return;\n\n if (\n !Signatures.socVerify(\n entryProof.socProof[0].signer, // signer Ethereum address to check against\n entryProof.socProof[0].signature,\n entryProof.socProof[0].identifier,\n entryProof.socProof[0].chunkAddr\n )\n ) {\n revert SocVerificationFailed(entryProof.socProof[0].chunkAddr);\n }\n\n if (\n calculateSocAddress(entryProof.socProof[0].identifier, entryProof.socProof[0].signer) !=\n entryProof.proveSegment\n ) {\n revert SocCalcNotMatching(entryProof.socProof[0].chunkAddr);\n }\n }\n\n function stampFunction(ChunkInclusionProof calldata entryProof) internal view {\n // authentic\n (address batchOwner, uint8 batchDepth, uint8 bucketDepth, , , ) = PostageContract.batches(\n entryProof.postageProof.postageId\n );\n\n // alive\n if (batchOwner == address(0)) {\n revert BatchDoesNotExist(entryProof.postageProof.postageId); // Batch does not exist or expired\n }\n\n uint32 postageIndex = getPostageIndex(entryProof.postageProof.index);\n uint256 maxPostageIndex = postageStampIndexCount(batchDepth, bucketDepth);\n // available\n if (postageIndex >= maxPostageIndex) {\n revert IndexOutsideSet(entryProof.postageProof.postageId);\n }\n\n // aligned\n uint64 postageBucket = getPostageBucket(entryProof.postageProof.index);\n uint64 addressBucket = addressToBucket(entryProof.proveSegment, bucketDepth);\n if (postageBucket != addressBucket) {\n revert BucketDiffers(entryProof.postageProof.postageId);\n }\n\n // authorized\n if (\n !Signatures.postageVerify(\n batchOwner,\n entryProof.postageProof.signature,\n entryProof.proveSegment,\n entryProof.postageProof.postageId,\n entryProof.postageProof.index,\n entryProof.postageProof.timeStamp\n )\n ) {\n revert SigRecoveryFailed(entryProof.postageProof.postageId);\n }\n }\n\n function addressToBucket(bytes32 swarmAddress, uint8 bucketDepth) internal pure returns (uint32) {\n uint32 prefix = uint32(uint256(swarmAddress) >> (256 - 32));\n return prefix >> (32 - bucketDepth);\n }\n\n function postageStampIndexCount(uint8 postageDepth, uint8 bucketDepth) internal pure returns (uint256) {\n return 1 << (postageDepth - bucketDepth);\n }\n\n function getPostageIndex(uint64 signedIndex) internal pure returns (uint32) {\n return uint32(signedIndex);\n }\n\n function getPostageBucket(uint64 signedIndex) internal pure returns (uint64) {\n return uint32(signedIndex >> 32);\n }\n\n function calculateSocAddress(bytes32 identifier, address signer) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(identifier, signer));\n }\n\n function checkOrder(uint256 a, uint256 b, bytes32 trA1, bytes32 trA2, bytes32 trALast) internal pure {\n if (a < b) {\n if (uint256(trA1) >= uint256(trA2)) {\n revert RandomElementCheckFailed();\n }\n if (uint256(trA2) >= uint256(trALast)) {\n revert LastElementCheckFailed();\n }\n } else {\n if (uint256(trA2) >= uint256(trA1)) {\n revert RandomElementCheckFailed();\n }\n if (uint256(trA1) >= uint256(trALast)) {\n revert LastElementCheckFailed();\n }\n }\n }\n\n function estimateSize(bytes32 trALast) internal view {\n if (uint256(trALast) >= sampleMaxValue) {\n revert ReserveCheckFailed(trALast);\n }\n }\n}\n" + }, + "src/Staking.sol": { + "content": "// SPDX-License-Identifier: BSD-3-Clause\npragma solidity ^0.8.19;\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"@openzeppelin/contracts/security/Pausable.sol\";\n\ninterface IPriceOracle {\n function currentPrice() external view returns (uint32);\n}\n\n/**\n * @title Staking contract for the Swarm storage incentives\n * @author The Swarm Authors\n * @dev Allows users to stake tokens in order to be eligible for the Redistribution Schelling co-ordination game.\n * Stakes are frozen or slashed by the Redistribution contract in response to violations of the\n * protocol.\n */\n\ncontract StakeRegistry is AccessControl, Pausable {\n // ----------------------------- State variables ------------------------------\n\n struct Stake {\n // Overlay of the node that is being staked\n bytes32 overlay;\n // Stake balance expressed through price oracle\n uint256 committedStake;\n // Stake balance expressed in BZZ\n uint256 potentialStake;\n // Block height the stake was updated, also used as flag to check if the stake is set\n uint256 lastUpdatedBlockNumber;\n // Node indicating its increased reserve\n uint8 height;\n }\n\n // Associate every stake id with node address data.\n mapping(address => Stake) public stakes;\n\n // Role allowed to freeze and slash entries\n bytes32 public constant REDISTRIBUTOR_ROLE = keccak256(\"REDISTRIBUTOR_ROLE\");\n\n // Swarm network ID\n uint64 NetworkId;\n\n // The miniumum stake allowed to be staked using the Staking contract.\n uint64 private constant MIN_STAKE = 100000000000000000;\n\n // Address of the staked ERC20 token\n address public immutable bzzToken;\n\n // The address of the linked PriceOracle contract.\n IPriceOracle public OracleContract;\n\n // ----------------------------- Events ------------------------------\n\n /**\n * @dev Emitted when a stake is created or updated by `owner` of the `overlay`.\n */\n event StakeUpdated(\n address indexed owner,\n uint256 committedStake,\n uint256 potentialStake,\n bytes32 overlay,\n uint256 lastUpdatedBlock,\n uint8 height\n );\n\n /**\n * @dev Emitted when a stake for address `slashed` is slashed by `amount`.\n */\n event StakeSlashed(address slashed, bytes32 overlay, uint256 amount);\n\n /**\n * @dev Emitted when a stake for address `frozen` is frozen for `time` blocks.\n */\n event StakeFrozen(address frozen, bytes32 overlay, uint256 time);\n\n /**\n * @dev Emitted when a address changes overlay it uses\n */\n event OverlayChanged(address owner, bytes32 overlay);\n\n /**\n * @dev Emitted when a stake for address is withdrawn\n */\n event StakeWithdrawn(address node, uint256 amount);\n\n // ----------------------------- Errors ------------------------------\n\n error TransferFailed(); // Used when token transfers fail\n error Frozen(); // Used when an action cannot proceed because the overlay is frozen\n error Unauthorized(); // Used where only the owner can perform the action\n error OnlyRedistributor(); // Used when only the redistributor role is allowed\n error OnlyPauser(); // Used when only the pauser role is allowed\n error BelowMinimumStake(); // Node participating in game has stake below minimum treshold\n\n // ----------------------------- CONSTRUCTOR ------------------------------\n\n /**\n * @param _bzzToken Address of the staked ERC20 token\n * @param _NetworkId Swarm network ID\n */\n constructor(address _bzzToken, uint64 _NetworkId, address _oracleContract) {\n NetworkId = _NetworkId;\n bzzToken = _bzzToken;\n OracleContract = IPriceOracle(_oracleContract);\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n }\n\n ////////////////////////////////////////\n // STATE SETTING //\n ////////////////////////////////////////\n\n /**\n * @notice Create a new stake or update an existing one, change overlay of node\n * @dev At least `_initialBalancePerChunk*2^depth` number of tokens need to be preapproved for this contract.\n * @param _setNonce Nonce that was used for overlay calculation.\n * @param _addAmount Deposited amount of ERC20 tokens, equals to added Potential stake value\n * @param _height increased reserve by registering the number of doublings\n */\n function manageStake(bytes32 _setNonce, uint256 _addAmount, uint8 _height) external whenNotPaused {\n bytes32 _previousOverlay = stakes[msg.sender].overlay;\n uint256 _stakingSet = stakes[msg.sender].lastUpdatedBlockNumber;\n bytes32 _newOverlay = keccak256(abi.encodePacked(msg.sender, reverse(NetworkId), _setNonce));\n\n // First time adding stake, check the minimum is added, take into account height\n if (_addAmount < MIN_STAKE * 2 ** _height && _stakingSet == 0) {\n revert BelowMinimumStake();\n }\n\n if (_stakingSet != 0 && !addressNotFrozen(msg.sender)) revert Frozen();\n uint256 updatedPotentialStake = stakes[msg.sender].potentialStake + _addAmount;\n uint256 updatedCommittedStake = updatedPotentialStake / (OracleContract.currentPrice() * 2 ** _height);\n\n stakes[msg.sender] = Stake({\n overlay: _newOverlay,\n committedStake: updatedCommittedStake,\n potentialStake: updatedPotentialStake,\n lastUpdatedBlockNumber: block.number,\n height: _height\n });\n\n // Transfer tokens and emit event that stake has been updated\n if (_addAmount > 0) {\n if (!ERC20(bzzToken).transferFrom(msg.sender, address(this), _addAmount)) revert TransferFailed();\n emit StakeUpdated(\n msg.sender,\n updatedCommittedStake,\n updatedPotentialStake,\n _newOverlay,\n block.number,\n _height\n );\n }\n\n // Emit overlay change event\n if (_previousOverlay != _newOverlay) {\n emit OverlayChanged(msg.sender, _newOverlay);\n }\n }\n\n /**\n * @dev Withdraw node stake surplus\n */\n function withdrawFromStake() external {\n uint256 _potentialStake = stakes[msg.sender].potentialStake;\n uint256 _surplusStake = _potentialStake -\n calculateEffectiveStake(stakes[msg.sender].committedStake, _potentialStake, stakes[msg.sender].height);\n\n if (_surplusStake > 0) {\n stakes[msg.sender].potentialStake -= _surplusStake;\n if (!ERC20(bzzToken).transfer(msg.sender, _surplusStake)) revert TransferFailed();\n emit StakeWithdrawn(msg.sender, _surplusStake);\n }\n }\n\n /**\n * @dev Migrate stake only when the staking contract is paused,\n * can only be called by the owner of the stake\n */\n function migrateStake() external whenPaused {\n // We take out all the stake so user can migrate stake to other contract\n if (lastUpdatedBlockNumberOfAddress(msg.sender) != 0) {\n if (!ERC20(bzzToken).transfer(msg.sender, stakes[msg.sender].potentialStake)) revert TransferFailed();\n delete stakes[msg.sender];\n }\n }\n\n /**\n * @dev Freeze an existing stake, can only be called by the redistributor\n * @param _owner the addres selected\n * @param _time penalty length in blocknumbers\n */\n function freezeDeposit(address _owner, uint256 _time) external {\n if (!hasRole(REDISTRIBUTOR_ROLE, msg.sender)) revert OnlyRedistributor();\n\n if (stakes[_owner].lastUpdatedBlockNumber != 0) {\n stakes[_owner].lastUpdatedBlockNumber = block.number + _time;\n emit StakeFrozen(_owner, stakes[_owner].overlay, _time);\n }\n }\n\n /**\n * @dev Slash an existing stake, can only be called by the `redistributor`\n * @param _owner the _owner adress selected\n * @param _amount the amount to be slashed\n */\n function slashDeposit(address _owner, uint256 _amount) external {\n if (!hasRole(REDISTRIBUTOR_ROLE, msg.sender)) revert OnlyRedistributor();\n\n if (stakes[_owner].lastUpdatedBlockNumber != 0) {\n if (stakes[_owner].potentialStake > _amount) {\n stakes[_owner].potentialStake -= _amount;\n stakes[_owner].lastUpdatedBlockNumber = block.number;\n } else {\n delete stakes[_owner];\n }\n }\n emit StakeSlashed(_owner, stakes[_owner].overlay, _amount);\n }\n\n function changeNetworkId(uint64 _NetworkId) external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) revert Unauthorized();\n NetworkId = _NetworkId;\n }\n\n /**\n * @dev Pause the contract. The contract is provably stopped by renouncing\n the pauser role and the admin role after pausing, can only be called by the `PAUSER`\n */\n function pause() public {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) revert OnlyPauser();\n _pause();\n }\n\n /**\n * @dev Unpause the contract, can only be called by the pauser when paused\n */\n function unPause() public {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) revert OnlyPauser();\n _unpause();\n }\n\n ////////////////////////////////////////\n // STATE READING //\n ////////////////////////////////////////\n\n /**\n * @dev Checks to see if `address` is frozen.\n * @param _owner owner of staked address\n *\n * Returns a boolean value indicating whether the operation succeeded.\n */\n function addressNotFrozen(address _owner) internal view returns (bool) {\n return stakes[_owner].lastUpdatedBlockNumber < block.number;\n }\n\n /**\n * @dev Returns the current `effectiveStake` of `address`. previously usable stake\n * @param _owner _owner of node\n */\n function nodeEffectiveStake(address _owner) public view returns (uint256) {\n return\n addressNotFrozen(_owner)\n ? calculateEffectiveStake(\n stakes[_owner].committedStake,\n stakes[_owner].potentialStake,\n stakes[_owner].height\n )\n : 0;\n }\n\n /**\n * @dev Check the amount that is possible to withdraw as surplus\n */\n function withdrawableStake() public view returns (uint256) {\n uint256 _potentialStake = stakes[msg.sender].potentialStake;\n return\n _potentialStake -\n calculateEffectiveStake(stakes[msg.sender].committedStake, _potentialStake, stakes[msg.sender].height);\n }\n\n /**\n * @dev Returns the `lastUpdatedBlockNumber` of `address`.\n */\n function lastUpdatedBlockNumberOfAddress(address _owner) public view returns (uint256) {\n return stakes[_owner].lastUpdatedBlockNumber;\n }\n\n /**\n * @dev Returns the currently used overlay of the address.\n * @param _owner address of node\n */\n function overlayOfAddress(address _owner) public view returns (bytes32) {\n return stakes[_owner].overlay;\n }\n\n /**\n * @dev Returns the currently height of the address.\n * @param _owner address of node\n */\n function heightOfAddress(address _owner) public view returns (uint8) {\n return stakes[_owner].height;\n }\n\n function calculateEffectiveStake(\n uint256 committedStake,\n uint256 potentialStakeBalance,\n uint8 height\n ) internal view returns (uint256) {\n // Calculate the product of committedStake and unitPrice to get price in BZZ\n uint256 committedStakeBzz = (2 ** height) * committedStake * OracleContract.currentPrice();\n\n // Return the minimum value between committedStakeBzz and potentialStakeBalance\n if (committedStakeBzz < potentialStakeBalance) {\n return committedStakeBzz;\n } else {\n return potentialStakeBalance;\n }\n }\n\n /**\n * @dev Please both Endians 🥚.\n * @param input Eth address used for overlay calculation.\n */\n function reverse(uint64 input) internal pure returns (uint64 v) {\n v = input;\n\n // swap bytes\n v = ((v & 0xFF00FF00FF00FF00) >> 8) | ((v & 0x00FF00FF00FF00FF) << 8);\n\n // swap 2-byte long pairs\n v = ((v & 0xFFFF0000FFFF0000) >> 16) | ((v & 0x0000FFFF0000FFFF) << 16);\n\n // swap 4-byte long pairs\n v = (v >> 32) | (v << 32);\n }\n}\n" + }, + "src/TestToken.sol": { + "content": "// SPDX-License-Identifier: BSD-3-Clause\npragma solidity ^0.8.19;\n\nimport \"@openzeppelin/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol\";\n\ncontract TestToken is ERC20PresetMinterPauser {\n uint256 private _initialSupply;\n\n constructor(string memory name, string memory symbol, uint256 initialSupply) ERC20PresetMinterPauser(name, symbol) {\n _initialSupply = initialSupply;\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n _mint(msg.sender, initialSupply);\n }\n\n // We use 16 decimals for BZZ/sBZZ token so we need to override it here\n function decimals() public view virtual override returns (uint8) {\n return 16;\n }\n}\n" + }, + "src/Util/ChunkProof.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\nlibrary BMTChunk {\n // max chunk payload size\n uint256 public constant MAX_CHUNK_PAYLOAD_SIZE = 4096;\n // segment byte size\n uint256 public constant SEGMENT_SIZE = 32;\n\n /**\n * @notice Changes the endianness of a uint64.\n * @dev https://graphics.stanford.edu/~seander/bithacks.html#ReverseParallel\n * @param _b The unsigned integer to reverse\n * @return v - The reversed value\n */\n function reverseUint64(uint64 _b) public pure returns (uint64) {\n uint256 v = _b;\n\n // swap bytes\n v =\n ((v >> 8) & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) |\n ((v & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) << 8);\n // swap 2-byte long pairs\n v =\n ((v >> 16) & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) |\n ((v & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) << 16);\n // swap 4-byte long pairs\n v =\n ((v >> 32) & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) |\n ((v & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) << 32);\n\n return uint64(v);\n }\n\n /** Calculates the root hash from the provided inclusion proof segments and its corresponding segment index\n * @param _proofSegments Proof segments.\n * @param _proveSegment Segment to prove.\n * @param _proveSegmentIndex Prove segment index\n * @return _calculatedHash chunk hash\n */\n function rootHashFromInclusionProof(\n bytes32[] memory _proofSegments,\n bytes32 _proveSegment,\n uint256 _proveSegmentIndex\n ) internal pure returns (bytes32 _calculatedHash) {\n _calculatedHash = _proveSegment;\n for (uint256 i = 0; i < _proofSegments.length; i++) {\n bool mergeFromRight = _proveSegmentIndex % 2 == 0;\n _calculatedHash = mergeSegment(_calculatedHash, _proofSegments[i], mergeFromRight);\n _proveSegmentIndex >>= 1;\n }\n return _calculatedHash;\n }\n\n /**\n * Calculate the chunk address from the Binary Merkle Tree of the chunk data\n *\n * The BMT chunk address is the hash of the 8 byte span and the root\n * hash of a binary Merkle tree (BMT) built on the 32-byte segments\n * of the underlying data.\n * @param _proofSegments Proof segments.\n * @param _proveSegment Segment to prove.\n * @param _proveSegmentIndex Prove segment index\n * @param _chunkSpan chunk bytes length\n * @return _chunkHash chunk hash\n */\n function chunkAddressFromInclusionProof(\n bytes32[] memory _proofSegments,\n bytes32 _proveSegment,\n uint256 _proveSegmentIndex,\n uint64 _chunkSpan\n ) internal pure returns (bytes32) {\n bytes32 rootHash = rootHashFromInclusionProof(_proofSegments, _proveSegment, _proveSegmentIndex);\n return keccak256(abi.encodePacked(reverseUint64(_chunkSpan), rootHash));\n }\n\n function mergeSegment(\n bytes32 _calculatedHash,\n bytes32 _proofSegment,\n bool mergeFromRight\n ) internal pure returns (bytes32 res) {\n if (mergeFromRight) {\n res = keccak256(abi.encode(_calculatedHash, _proofSegment));\n } else {\n res = keccak256(abi.encode(_proofSegment, _calculatedHash));\n }\n return res;\n }\n}\n" + }, + "src/Util/Signatures.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\nlibrary Signatures {\n error InvalidSignatureLength();\n\n /** Hash of the message to sign */\n function getPostageMessageHash(\n bytes32 _chunkAddr,\n bytes32 _batchId,\n uint64 _index,\n uint64 _timeStamp\n ) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(_chunkAddr, _batchId, _index, _timeStamp));\n }\n\n function postageVerify(\n address _signer, // signer Ethereum address to check against\n bytes memory _signature,\n bytes32 _chunkAddr,\n bytes32 _postageId,\n uint64 _index,\n uint64 _timeStamp\n ) internal pure returns (bool) {\n bytes32 messageHash = getPostageMessageHash(_chunkAddr, _postageId, _index, _timeStamp);\n bytes32 ethMessageHash = getEthSignedMessageHash(messageHash);\n\n return recoverSigner(ethMessageHash, _signature) == _signer;\n }\n\n function getEthSignedMessageHash(bytes32 _messageHash) internal pure returns (bytes32) {\n /*\n Signature is produced by signing a keccak256 hash with the following format:\n \"\\x19Ethereum Signed Message\\n\" + len(msg) + msg\n */\n return keccak256(abi.encodePacked(\"\\x19Ethereum Signed Message:\\n32\", _messageHash));\n }\n\n function recoverSigner(\n bytes32 _ethSignedMessageHash, // it has to be prefixed message: https://ethereum.stackexchange.com/questions/19582/does-ecrecover-in-solidity-expects-the-x19ethereum-signed-message-n-prefix/21037\n bytes memory _signature\n ) internal pure returns (address) {\n (bytes32 r, bytes32 s, uint8 v) = splitSignature(_signature);\n\n return ecrecover(_ethSignedMessageHash, v, r, s);\n }\n\n function splitSignature(bytes memory sig) internal pure returns (bytes32 r_, bytes32 s_, uint8 v_) {\n if (sig.length != 65) {\n revert InvalidSignatureLength();\n }\n\n assembly {\n /*\n verbose explanation: https://ethereum.stackexchange.com/questions/135591/split-signature-function-in-solidity-by-example-docs\n First 32 bytes stores the length of the signature\n add(sig, 32) = pointer of sig + 32\n effectively, skips first 32 bytes of signature\n mload(p) loads next 32 bytes starting at the memory address p into memory\n */\n\n // first 32 bytes, after the length prefix\n r_ := mload(add(sig, 32))\n // second 32 bytes\n s_ := mload(add(sig, 64))\n // final byte (first byte of the next 32 bytes)\n v_ := byte(0, mload(add(sig, 96)))\n }\n\n // implicitly return (r, s, v)\n }\n\n function getSocMessageHash(bytes32 _identifier, bytes32 _chunkAddr) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(_identifier, _chunkAddr));\n }\n\n function socVerify(\n address _signer, // signer Ethereum address to check against\n bytes memory _signature,\n bytes32 _identifier,\n bytes32 _chunkAddr\n ) internal pure returns (bool) {\n bytes32 messageHash = getSocMessageHash(_identifier, _chunkAddr);\n bytes32 ethMessageHash = getEthSignedMessageHash(messageHash);\n\n return recoverSigner(ethMessageHash, _signature) == _signer;\n }\n}\n" + }, + "src/Util/TransformedChunkProof.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\nlibrary TransformedBMTChunk {\n // max chunk payload size\n uint256 public constant MAX_CHUNK_PAYLOAD_SIZE = 4096;\n // segment byte size\n uint256 public constant SEGMENT_SIZE = 32;\n\n /** Calculates the root hash from the provided inclusion proof segments and its corresponding segment index\n * @param _proofSegments Proof segments.\n * @param _proveSegment Segment to prove.\n * @param _proveSegmentIndex Prove segment index\n * @return _calculatedHash chunk hash\n */\n function transformedRootHashFromInclusionProof(\n bytes32[] memory _proofSegments,\n bytes32 _proveSegment,\n uint256 _proveSegmentIndex,\n bytes32 key\n ) internal pure returns (bytes32 _calculatedHash) {\n _calculatedHash = _proveSegment;\n for (uint256 i = 0; i < _proofSegments.length; i++) {\n bool mergeFromRight = _proveSegmentIndex % 2 == 0 ? true : false;\n _calculatedHash = transformedMergeSegment(_calculatedHash, _proofSegments[i], mergeFromRight, key);\n _proveSegmentIndex >>= 1;\n }\n\n return _calculatedHash;\n }\n\n /**\n * @notice Changes the endianness of a uint64.\n * @dev https://graphics.stanford.edu/~seander/bithacks.html#ReverseParallel\n * @param _b The unsigned integer to reverse\n * @return v - The reversed value\n */\n function reverseUint64(uint64 _b) public pure returns (uint64) {\n uint256 v = _b;\n\n // swap bytes\n v =\n ((v >> 8) & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) |\n ((v & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) << 8);\n // swap 2-byte long pairs\n v =\n ((v >> 16) & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) |\n ((v & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) << 16);\n // swap 4-byte long pairs\n v =\n ((v >> 32) & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) |\n ((v & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) << 32);\n\n return uint64(v);\n }\n\n /**\n * Calculate the chunk address from the Binary Merkle Tree of the chunk data\n *\n * The BMT chunk address is the hash of the 8 byte span and the root\n * hash of a binary Merkle tree (BMT) built on the 32-byte segments\n * of the underlying data.\n * @param _proofSegments Proof segments.\n * @param _proveSegment Segment to prove.\n * @param _proveSegmentIndex Prove segment index\n * @param _chunkSpan chunk bytes length\n * @return _chunkHash chunk hash\n */\n function transformedChunkAddressFromInclusionProof(\n bytes32[] memory _proofSegments,\n bytes32 _proveSegment,\n uint256 _proveSegmentIndex,\n uint64 _chunkSpan,\n bytes32 key\n ) internal pure returns (bytes32) {\n bytes32 rootHash = transformedRootHashFromInclusionProof(\n _proofSegments,\n _proveSegment,\n _proveSegmentIndex,\n key\n );\n return keccak256(abi.encodePacked(key, reverseUint64(_chunkSpan), rootHash));\n }\n\n function transformedMergeSegment(\n bytes32 _calculatedHash,\n bytes32 _proofSegment,\n bool mergeFromRight,\n bytes32 key\n ) internal pure returns (bytes32 res) {\n if (mergeFromRight) {\n res = keccak256(abi.encode(key, _calculatedHash, _proofSegment));\n } else {\n res = keccak256(abi.encode(key, _proofSegment, _calculatedHash));\n }\n return res;\n }\n}\n" + } + }, + "settings": { + "optimizer": { + "enabled": true, + "runs": 1000 + }, + "outputSelection": { + "*": { + "*": [ + "abi", + "evm.bytecode", + "evm.deployedBytecode", + "evm.methodIdentifiers", + "metadata", + "devdoc", + "userdoc", + "storageLayout", + "evm.gasEstimates" + ], + "": [ + "ast" + ] + } + }, + "metadata": { + "useLiteralContent": true + }, + "libraries": { + "": { + "__CACHE_BREAKER__": "0x00000000d41867734bbee4c6863d9255b2b06ac1" + } + } + } +} \ No newline at end of file diff --git a/deployments/testnetlight/PostageStamp.json b/deployments/testnetlight/PostageStamp.json index 2f9753cf..b9c8e9d7 100644 --- a/deployments/testnetlight/PostageStamp.json +++ b/deployments/testnetlight/PostageStamp.json @@ -1,5 +1,5 @@ { - "address": "0x38eC2DC60069b28439e4Fca4DF9a91b1d29217cF", + "address": "0x44598B43216eCe3C0eB0dd8e3006d23B40E0554c", "abi": [ { "inputs": [ @@ -1143,22 +1143,22 @@ "type": "function" } ], - "transactionHash": "0x6efb9bc6f637b808031cf157dba99d2b71fe08de180f51ed5f648cf139484a6d", + "transactionHash": "0x8c40d57a01af3af2b91e042d2ce728d1303fd911518efec408729d17d09913b5", "receipt": { "to": null, "from": "0xb1C7F17Ed88189Abf269Bf68A3B2Ed83C5276aAe", - "contractAddress": "0x38eC2DC60069b28439e4Fca4DF9a91b1d29217cF", - "transactionIndex": 57, + "contractAddress": "0x44598B43216eCe3C0eB0dd8e3006d23B40E0554c", + "transactionIndex": 48, "gasUsed": "3320836", - "logsBloom": "0x00000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000800000000010000000000000000102000000001040000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000100002000000020000000000000100000000000000000000000000400000000000000000000000000", - "blockHash": "0x5dfa112bed22e409cb6ec73d24a8b48d6bd9b50fbaf6ec6cf50c8d4d629a5e0d", - "transactionHash": "0x6efb9bc6f637b808031cf157dba99d2b71fe08de180f51ed5f648cf139484a6d", + "logsBloom": "0x00000004000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000020000000000000000000800000000010000000000000000002000000000040000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000100002000000020040000000000000000000000000000000000000400000000000000000000000000", + "blockHash": "0xffd6859f243f9ab9c1544b5c891b3c9460b30322049887e9aaeb494be32a226a", + "transactionHash": "0x8c40d57a01af3af2b91e042d2ce728d1303fd911518efec408729d17d09913b5", "logs": [ { - "transactionIndex": 57, - "blockNumber": 5855588, - "transactionHash": "0x6efb9bc6f637b808031cf157dba99d2b71fe08de180f51ed5f648cf139484a6d", - "address": "0x38eC2DC60069b28439e4Fca4DF9a91b1d29217cF", + "transactionIndex": 48, + "blockNumber": 6852192, + "transactionHash": "0x8c40d57a01af3af2b91e042d2ce728d1303fd911518efec408729d17d09913b5", + "address": "0x44598B43216eCe3C0eB0dd8e3006d23B40E0554c", "topics": [ "0x2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d", "0x0000000000000000000000000000000000000000000000000000000000000000", @@ -1166,14 +1166,14 @@ "0x000000000000000000000000b1c7f17ed88189abf269bf68a3b2ed83c5276aae" ], "data": "0x", - "logIndex": 140, - "blockHash": "0x5dfa112bed22e409cb6ec73d24a8b48d6bd9b50fbaf6ec6cf50c8d4d629a5e0d" + "logIndex": 63, + "blockHash": "0xffd6859f243f9ab9c1544b5c891b3c9460b30322049887e9aaeb494be32a226a" }, { - "transactionIndex": 57, - "blockNumber": 5855588, - "transactionHash": "0x6efb9bc6f637b808031cf157dba99d2b71fe08de180f51ed5f648cf139484a6d", - "address": "0x38eC2DC60069b28439e4Fca4DF9a91b1d29217cF", + "transactionIndex": 48, + "blockNumber": 6852192, + "transactionHash": "0x8c40d57a01af3af2b91e042d2ce728d1303fd911518efec408729d17d09913b5", + "address": "0x44598B43216eCe3C0eB0dd8e3006d23B40E0554c", "topics": [ "0x2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d", "0x65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a", @@ -1181,12 +1181,12 @@ "0x000000000000000000000000b1c7f17ed88189abf269bf68a3b2ed83c5276aae" ], "data": "0x", - "logIndex": 141, - "blockHash": "0x5dfa112bed22e409cb6ec73d24a8b48d6bd9b50fbaf6ec6cf50c8d4d629a5e0d" + "logIndex": 64, + "blockHash": "0xffd6859f243f9ab9c1544b5c891b3c9460b30322049887e9aaeb494be32a226a" } ], - "blockNumber": 5855588, - "cumulativeGasUsed": "12665824", + "blockNumber": 6852192, + "cumulativeGasUsed": "8428528", "status": 1, "byzantium": true }, @@ -1195,7 +1195,7 @@ 16 ], "numDeployments": 1, - "solcInputHash": "72863154353a753995d89fd6bb12e809", + "solcInputHash": "0713424b44e4d07fab3794bffaf90dbd", "metadata": "{\"compiler\":{\"version\":\"0.8.19+commit.7dd6d404\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_bzzToken\",\"type\":\"address\"},{\"internalType\":\"uint8\",\"name\":\"_minimumBucketDepth\",\"type\":\"uint8\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[],\"name\":\"AdministratorOnly\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"BatchDoesNotExist\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"BatchExists\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"BatchExpired\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"BatchTooSmall\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"DepthNotIncreasing\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"InsufficienChunkCount\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"InsufficientBalance\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"InvalidDepth\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NoBatchesExist\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NotBatchOwner\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"OnlyPauser\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"OnlyRedistributor\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"PriceOracleOnly\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"TotalOutpaymentDecreased\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"TransferFailed\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"ValueCannotBeZero\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"ValueDoesNotExist\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"ValueKeyPairExists\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"ZeroAddress\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"ZeroBalance\",\"type\":\"error\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"batchId\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"totalAmount\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"normalisedBalance\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint8\",\"name\":\"depth\",\"type\":\"uint8\"},{\"indexed\":false,\"internalType\":\"uint8\",\"name\":\"bucketDepth\",\"type\":\"uint8\"},{\"indexed\":false,\"internalType\":\"bool\",\"name\":\"immutableFlag\",\"type\":\"bool\"}],\"name\":\"BatchCreated\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"batchId\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint8\",\"name\":\"newDepth\",\"type\":\"uint8\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"normalisedBalance\",\"type\":\"uint256\"}],\"name\":\"BatchDepthIncrease\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"batchId\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"topupAmount\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"normalisedBalance\",\"type\":\"uint256\"}],\"name\":\"BatchTopUp\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"index\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"batchId\",\"type\":\"bytes32\"}],\"name\":\"CopyBatchFailed\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"Paused\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"recipient\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"totalAmount\",\"type\":\"uint256\"}],\"name\":\"PotWithdrawn\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"price\",\"type\":\"uint256\"}],\"name\":\"PriceUpdate\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"previousAdminRole\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"newAdminRole\",\"type\":\"bytes32\"}],\"name\":\"RoleAdminChanged\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"}],\"name\":\"RoleGranted\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"}],\"name\":\"RoleRevoked\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"Unpaused\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"DEFAULT_ADMIN_ROLE\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"PAUSER_ROLE\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"PRICE_ORACLE_ROLE\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"REDISTRIBUTOR_ROLE\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"_batchId\",\"type\":\"bytes32\"}],\"name\":\"batchBucketDepth\",\"outputs\":[{\"internalType\":\"uint8\",\"name\":\"\",\"type\":\"uint8\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"_batchId\",\"type\":\"bytes32\"}],\"name\":\"batchDepth\",\"outputs\":[{\"internalType\":\"uint8\",\"name\":\"\",\"type\":\"uint8\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"_batchId\",\"type\":\"bytes32\"}],\"name\":\"batchImmutableFlag\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"_batchId\",\"type\":\"bytes32\"}],\"name\":\"batchLastUpdatedBlockNumber\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"_batchId\",\"type\":\"bytes32\"}],\"name\":\"batchNormalisedBalance\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"_batchId\",\"type\":\"bytes32\"}],\"name\":\"batchOwner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"batches\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"uint8\",\"name\":\"depth\",\"type\":\"uint8\"},{\"internalType\":\"uint8\",\"name\":\"bucketDepth\",\"type\":\"uint8\"},{\"internalType\":\"bool\",\"name\":\"immutableFlag\",\"type\":\"bool\"},{\"internalType\":\"uint256\",\"name\":\"normalisedBalance\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"lastUpdatedBlockNumber\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"bzzToken\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_owner\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"_initialBalancePerChunk\",\"type\":\"uint256\"},{\"internalType\":\"uint8\",\"name\":\"_depth\",\"type\":\"uint8\"},{\"internalType\":\"uint8\",\"name\":\"_bucketDepth\",\"type\":\"uint8\"},{\"internalType\":\"bytes32\",\"name\":\"_batchId\",\"type\":\"bytes32\"},{\"internalType\":\"bool\",\"name\":\"_immutable\",\"type\":\"bool\"}],\"name\":\"copyBatch\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"components\":[{\"internalType\":\"bytes32\",\"name\":\"batchId\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"uint8\",\"name\":\"depth\",\"type\":\"uint8\"},{\"internalType\":\"uint8\",\"name\":\"bucketDepth\",\"type\":\"uint8\"},{\"internalType\":\"bool\",\"name\":\"immutableFlag\",\"type\":\"bool\"},{\"internalType\":\"uint256\",\"name\":\"remainingBalance\",\"type\":\"uint256\"}],\"internalType\":\"struct PostageStamp.ImportBatch[]\",\"name\":\"bulkBatches\",\"type\":\"tuple[]\"}],\"name\":\"copyBatchBulk\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_owner\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"_initialBalancePerChunk\",\"type\":\"uint256\"},{\"internalType\":\"uint8\",\"name\":\"_depth\",\"type\":\"uint8\"},{\"internalType\":\"uint8\",\"name\":\"_bucketDepth\",\"type\":\"uint8\"},{\"internalType\":\"bytes32\",\"name\":\"_nonce\",\"type\":\"bytes32\"},{\"internalType\":\"bool\",\"name\":\"_immutable\",\"type\":\"bool\"}],\"name\":\"createBatch\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentTotalOutPayment\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"limit\",\"type\":\"uint256\"}],\"name\":\"expireLimited\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"expiredBatchesExist\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"firstBatchId\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"}],\"name\":\"getRoleAdmin\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"grantRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"hasRole\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"_batchId\",\"type\":\"bytes32\"},{\"internalType\":\"uint8\",\"name\":\"_newDepth\",\"type\":\"uint8\"}],\"name\":\"increaseDepth\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"isBatchesTreeEmpty\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"lastExpiryBalance\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"lastPrice\",\"outputs\":[{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"lastUpdatedBlock\",\"outputs\":[{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"minimumBucketDepth\",\"outputs\":[{\"internalType\":\"uint8\",\"name\":\"\",\"type\":\"uint8\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"minimumInitialBalancePerChunk\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"minimumValidityBlocks\",\"outputs\":[{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"pause\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"paused\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"pot\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"_batchId\",\"type\":\"bytes32\"}],\"name\":\"remainingBalance\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"renounceRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"revokeRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint64\",\"name\":\"_value\",\"type\":\"uint64\"}],\"name\":\"setMinimumValidityBlocks\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_price\",\"type\":\"uint256\"}],\"name\":\"setPrice\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes4\",\"name\":\"interfaceId\",\"type\":\"bytes4\"}],\"name\":\"supportsInterface\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"_batchId\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"_topupAmountPerChunk\",\"type\":\"uint256\"}],\"name\":\"topUp\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"totalPot\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"unPause\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"validChunkCount\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"beneficiary\",\"type\":\"address\"}],\"name\":\"withdraw\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}],\"devdoc\":{\"author\":\"The Swarm Authors\",\"details\":\"The postage stamp contracts allows users to create and manage postage stamp batches. The current balance for each batch is stored ordered in descending order of normalised balance. Balance is normalised to be per chunk and the total spend since the contract was deployed, i.e. when a batch is bought, its per-chunk balance is supplemented with the current cost of storing one chunk since the beginning of time, as if the batch had existed since the contract's inception. During the _expiry_ process, each of these balances is checked against the _currentTotalOutPayment_, a similarly normalised figure that represents the current cost of storing one chunk since the beginning of time. A batch with a normalised balance less than _currentTotalOutPayment_ is treated as expired. The _currentTotalOutPayment_ is calculated using _totalOutPayment_ which is updated during _setPrice_ events so that the applicable per-chunk prices can be charged for the relevant periods of time. This can then be multiplied by the amount of chunks which are allowed to be stamped by each batch to get the actual cost of storage. The amount of chunks a batch can stamp is determined by the _bucketDepth_. A batch may store a maximum of 2^depth chunks. The global figure for the currently allowed chunks is tracked by _validChunkCount_ and updated during batch _expiry_ events.\",\"events\":{\"BatchCreated(bytes32,uint256,uint256,address,uint8,uint8,bool)\":{\"details\":\"Emitted when a new batch is created.\"},\"BatchDepthIncrease(bytes32,uint8,uint256)\":{\"details\":\"Emitted when the depth of an existing batch increases.\"},\"BatchTopUp(bytes32,uint256,uint256)\":{\"details\":\"Emitted when an existing batch is topped up.\"},\"CopyBatchFailed(uint256,bytes32)\":{\"details\":\"Emitted on every batch failed in bulk batch creation\"},\"Paused(address)\":{\"details\":\"Emitted when the pause is triggered by `account`.\"},\"PotWithdrawn(address,uint256)\":{\"details\":\"Emitted when an pot is Withdrawn.\"},\"PriceUpdate(uint256)\":{\"details\":\"Emitted on every price update.\"},\"RoleAdminChanged(bytes32,bytes32,bytes32)\":{\"details\":\"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._\"},\"RoleGranted(bytes32,address,address)\":{\"details\":\"Emitted when `account` is granted `role`. `sender` is the account that originated the contract call, an admin role bearer except when using {AccessControl-_setupRole}.\"},\"RoleRevoked(bytes32,address,address)\":{\"details\":\"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`)\"},\"Unpaused(address)\":{\"details\":\"Emitted when the pause is lifted by `account`.\"}},\"kind\":\"dev\",\"methods\":{\"constructor\":{\"params\":{\"_bzzToken\":\"The ERC20 token address to reference in this contract.\",\"_minimumBucketDepth\":\"The minimum bucket depth of batches that can be purchased.\"}},\"copyBatch(address,uint256,uint8,uint8,bytes32,bool)\":{\"details\":\"At least `_initialBalancePerChunk*2^depth` tokens must be approved in the ERC20 token contract.\",\"params\":{\"_batchId\":\"BatchId being copied (from previous version contract data).\",\"_depth\":\"Initial depth of the new batch.\",\"_immutable\":\"Whether the batch is mutable.\",\"_initialBalancePerChunk\":\"Initial balance per chunk of the batch.\",\"_owner\":\"Owner of the new batch.\"}},\"copyBatchBulk((bytes32,address,uint8,uint8,bool,uint256)[])\":{\"details\":\"Import batches in bulk to lower the number of transactions needed,becase of block limitations 90 batches per trx is ceiling, 60 to 70 sweetspot\",\"params\":{\"bulkBatches\":\"array of batches\"}},\"createBatch(address,uint256,uint8,uint8,bytes32,bool)\":{\"details\":\"At least `_initialBalancePerChunk*2^depth` tokens must be approved in the ERC20 token contract.\",\"params\":{\"_depth\":\"Initial depth of the new batch.\",\"_immutable\":\"Whether the batch is mutable.\",\"_initialBalancePerChunk\":\"Initial balance per chunk.\",\"_nonce\":\"A random value used in the batch id derivation to allow multiple batches per owner.\",\"_owner\":\"Owner of the new batch.\"}},\"currentTotalOutPayment()\":{\"details\":\"Returns the total normalised all-time per chunk payout. Only Batches with a normalised balance greater than this are valid.\"},\"expireLimited(uint256)\":{\"details\":\"Can be used if reclaiming all expired batches would exceed the block gas limit, causing other contract method calls to fail.\",\"params\":{\"limit\":\"The maximum number of batches to expire.\"}},\"firstBatchId()\":{\"details\":\"If more than one batch id, return index at 0, if no batches, revert.\"},\"getRoleAdmin(bytes32)\":{\"details\":\"Returns the admin role that controls `role`. See {grantRole} and {revokeRole}. To change a role's admin, use {_setRoleAdmin}.\"},\"grantRole(bytes32,address)\":{\"details\":\"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.\"},\"hasRole(bytes32,address)\":{\"details\":\"Returns `true` if `account` has been granted `role`.\"},\"increaseDepth(bytes32,uint8)\":{\"details\":\"Can only be called by the owner of the batch.\",\"params\":{\"_batchId\":\"the id of an existing batch.\",\"_newDepth\":\"the new (larger than the previous one) depth for this batch.\"}},\"pause()\":{\"details\":\"Can only be called by the pauser when not paused. The contract can be provably stopped by renouncing the pauser role and the admin role once paused.\"},\"paused()\":{\"details\":\"Returns true if the contract is paused, and false otherwise.\"},\"remainingBalance(bytes32)\":{\"params\":{\"_batchId\":\"The id of an existing batch.\"}},\"renounceRole(bytes32,address)\":{\"details\":\"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.\"},\"revokeRole(bytes32,address)\":{\"details\":\"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.\"},\"setPrice(uint256)\":{\"details\":\"Can only be called by the price oracle role.\",\"params\":{\"_price\":\"The new price.\"}},\"supportsInterface(bytes4)\":{\"details\":\"See {IERC165-supportsInterface}.\"},\"topUp(bytes32,uint256)\":{\"details\":\"At least `_topupAmountPerChunk*2^depth` tokens must be approved in the ERC20 token contract.\",\"params\":{\"_batchId\":\"The id of an existing batch.\",\"_topupAmountPerChunk\":\"The amount of additional tokens to add per chunk.\"}},\"unPause()\":{\"details\":\"Can only be called by the pauser role while paused.\"},\"withdraw(address)\":{\"params\":{\"beneficiary\":\"Recieves the current total pot.\"}}},\"title\":\"PostageStamp contract\",\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{\"copyBatch(address,uint256,uint8,uint8,bytes32,bool)\":{\"notice\":\"Manually create a new batch when facilitating migration, can only be called by the Admin role.\"},\"copyBatchBulk((bytes32,address,uint8,uint8,bool,uint256)[])\":{\"notice\":\"Import batches in bulk\"},\"createBatch(address,uint256,uint8,uint8,bytes32,bool)\":{\"notice\":\"Create a new batch.\"},\"currentTotalOutPayment()\":{\"notice\":\"Total per-chunk cost since the contract's deployment.\"},\"expireLimited(uint256)\":{\"notice\":\"Reclaims a limited number of expired batches\"},\"expiredBatchesExist()\":{\"notice\":\"Indicates whether expired batches exist.\"},\"firstBatchId()\":{\"notice\":\"Get the first batch id ordered by ascending normalised balance.\"},\"increaseDepth(bytes32,uint8)\":{\"notice\":\"Increase the depth of an existing batch.\"},\"isBatchesTreeEmpty()\":{\"notice\":\"Return true if no batches exist\"},\"pause()\":{\"notice\":\"Pause the contract.\"},\"remainingBalance(bytes32)\":{\"notice\":\"Return the per chunk balance not yet used up.\"},\"setPrice(uint256)\":{\"notice\":\"Set a new price.\"},\"topUp(bytes32,uint256)\":{\"notice\":\"Top up an existing batch.\"},\"totalPot()\":{\"notice\":\"The current pot.\"},\"unPause()\":{\"notice\":\"Unpause the contract.\"},\"withdraw(address)\":{\"notice\":\"Withdraw the pot, authorised callers only.\"}},\"version\":1}},\"settings\":{\"compilationTarget\":{\"src/PostageStamp.sol\":\"PostageStamp\"},\"evmVersion\":\"paris\",\"libraries\":{\":__CACHE_BREAKER__\":\"0x00000000d41867734bbee4c6863d9255b2b06ac1\"},\"metadata\":{\"bytecodeHash\":\"ipfs\",\"useLiteralContent\":true},\"optimizer\":{\"enabled\":true,\"runs\":1000},\"remappings\":[]},\"sources\":{\"@openzeppelin/contracts/access/AccessControl.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (access/AccessControl.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./IAccessControl.sol\\\";\\nimport \\\"../utils/Context.sol\\\";\\nimport \\\"../utils/Strings.sol\\\";\\nimport \\\"../utils/introspection/ERC165.sol\\\";\\n\\n/**\\n * @dev Contract module that allows children to implement role-based access\\n * control mechanisms. This is a lightweight version that doesn't allow enumerating role\\n * members except through off-chain means by accessing the contract event logs. Some\\n * applications may benefit from on-chain enumerability, for those cases see\\n * {AccessControlEnumerable}.\\n *\\n * Roles are referred to by their `bytes32` identifier. These should be exposed\\n * in the external API and be unique. The best way to achieve this is by\\n * using `public constant` hash digests:\\n *\\n * ```\\n * bytes32 public constant MY_ROLE = keccak256(\\\"MY_ROLE\\\");\\n * ```\\n *\\n * Roles can be used to represent a set of permissions. To restrict access to a\\n * function call, use {hasRole}:\\n *\\n * ```\\n * function foo() public {\\n * require(hasRole(MY_ROLE, msg.sender));\\n * ...\\n * }\\n * ```\\n *\\n * Roles can be granted and revoked dynamically via the {grantRole} and\\n * {revokeRole} functions. Each role has an associated admin role, and only\\n * accounts that have a role's admin role can call {grantRole} and {revokeRole}.\\n *\\n * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means\\n * that only accounts with this role will be able to grant or revoke other\\n * roles. More complex role relationships can be created by using\\n * {_setRoleAdmin}.\\n *\\n * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to\\n * grant and revoke this role. Extra precautions should be taken to secure\\n * accounts that have been granted it.\\n */\\nabstract contract AccessControl is Context, IAccessControl, ERC165 {\\n struct RoleData {\\n mapping(address => bool) members;\\n bytes32 adminRole;\\n }\\n\\n mapping(bytes32 => RoleData) private _roles;\\n\\n bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;\\n\\n /**\\n * @dev Modifier that checks that an account has a specific role. Reverts\\n * with a standardized message including the required role.\\n *\\n * The format of the revert reason is given by the following regular expression:\\n *\\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\\n *\\n * _Available since v4.1._\\n */\\n modifier onlyRole(bytes32 role) {\\n _checkRole(role);\\n _;\\n }\\n\\n /**\\n * @dev See {IERC165-supportsInterface}.\\n */\\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);\\n }\\n\\n /**\\n * @dev Returns `true` if `account` has been granted `role`.\\n */\\n function hasRole(bytes32 role, address account) public view virtual override returns (bool) {\\n return _roles[role].members[account];\\n }\\n\\n /**\\n * @dev Revert with a standard message if `_msgSender()` is missing `role`.\\n * Overriding this function changes the behavior of the {onlyRole} modifier.\\n *\\n * Format of the revert message is described in {_checkRole}.\\n *\\n * _Available since v4.6._\\n */\\n function _checkRole(bytes32 role) internal view virtual {\\n _checkRole(role, _msgSender());\\n }\\n\\n /**\\n * @dev Revert with a standard message if `account` is missing `role`.\\n *\\n * The format of the revert reason is given by the following regular expression:\\n *\\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\\n */\\n function _checkRole(bytes32 role, address account) internal view virtual {\\n if (!hasRole(role, account)) {\\n revert(\\n string(\\n abi.encodePacked(\\n \\\"AccessControl: account \\\",\\n Strings.toHexString(account),\\n \\\" is missing role \\\",\\n Strings.toHexString(uint256(role), 32)\\n )\\n )\\n );\\n }\\n }\\n\\n /**\\n * @dev Returns the admin role that controls `role`. See {grantRole} and\\n * {revokeRole}.\\n *\\n * To change a role's admin, use {_setRoleAdmin}.\\n */\\n function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {\\n return _roles[role].adminRole;\\n }\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * If `account` had not been already granted `role`, emits a {RoleGranted}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n *\\n * May emit a {RoleGranted} event.\\n */\\n function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\\n _grantRole(role, account);\\n }\\n\\n /**\\n * @dev Revokes `role` from `account`.\\n *\\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n *\\n * May emit a {RoleRevoked} event.\\n */\\n function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\\n _revokeRole(role, account);\\n }\\n\\n /**\\n * @dev Revokes `role` from the calling account.\\n *\\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\\n * purpose is to provide a mechanism for accounts to lose their privileges\\n * if they are compromised (such as when a trusted device is misplaced).\\n *\\n * If the calling account had been revoked `role`, emits a {RoleRevoked}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must be `account`.\\n *\\n * May emit a {RoleRevoked} event.\\n */\\n function renounceRole(bytes32 role, address account) public virtual override {\\n require(account == _msgSender(), \\\"AccessControl: can only renounce roles for self\\\");\\n\\n _revokeRole(role, account);\\n }\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * If `account` had not been already granted `role`, emits a {RoleGranted}\\n * event. Note that unlike {grantRole}, this function doesn't perform any\\n * checks on the calling account.\\n *\\n * May emit a {RoleGranted} event.\\n *\\n * [WARNING]\\n * ====\\n * This function should only be called from the constructor when setting\\n * up the initial roles for the system.\\n *\\n * Using this function in any other way is effectively circumventing the admin\\n * system imposed by {AccessControl}.\\n * ====\\n *\\n * NOTE: This function is deprecated in favor of {_grantRole}.\\n */\\n function _setupRole(bytes32 role, address account) internal virtual {\\n _grantRole(role, account);\\n }\\n\\n /**\\n * @dev Sets `adminRole` as ``role``'s admin role.\\n *\\n * Emits a {RoleAdminChanged} event.\\n */\\n function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {\\n bytes32 previousAdminRole = getRoleAdmin(role);\\n _roles[role].adminRole = adminRole;\\n emit RoleAdminChanged(role, previousAdminRole, adminRole);\\n }\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * Internal function without access restriction.\\n *\\n * May emit a {RoleGranted} event.\\n */\\n function _grantRole(bytes32 role, address account) internal virtual {\\n if (!hasRole(role, account)) {\\n _roles[role].members[account] = true;\\n emit RoleGranted(role, account, _msgSender());\\n }\\n }\\n\\n /**\\n * @dev Revokes `role` from `account`.\\n *\\n * Internal function without access restriction.\\n *\\n * May emit a {RoleRevoked} event.\\n */\\n function _revokeRole(bytes32 role, address account) internal virtual {\\n if (hasRole(role, account)) {\\n _roles[role].members[account] = false;\\n emit RoleRevoked(role, account, _msgSender());\\n }\\n }\\n}\\n\",\"keccak256\":\"0x67e3daf189111d6d5b0464ed09cf9f0605a22c4b965a7fcecd707101faff008a\",\"license\":\"MIT\"},\"@openzeppelin/contracts/access/IAccessControl.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev External interface of AccessControl declared to support ERC165 detection.\\n */\\ninterface IAccessControl {\\n /**\\n * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`\\n *\\n * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite\\n * {RoleAdminChanged} not being emitted signaling this.\\n *\\n * _Available since v3.1._\\n */\\n event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);\\n\\n /**\\n * @dev Emitted when `account` is granted `role`.\\n *\\n * `sender` is the account that originated the contract call, an admin role\\n * bearer except when using {AccessControl-_setupRole}.\\n */\\n event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);\\n\\n /**\\n * @dev Emitted when `account` is revoked `role`.\\n *\\n * `sender` is the account that originated the contract call:\\n * - if using `revokeRole`, it is the admin role bearer\\n * - if using `renounceRole`, it is the role bearer (i.e. `account`)\\n */\\n event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);\\n\\n /**\\n * @dev Returns `true` if `account` has been granted `role`.\\n */\\n function hasRole(bytes32 role, address account) external view returns (bool);\\n\\n /**\\n * @dev Returns the admin role that controls `role`. See {grantRole} and\\n * {revokeRole}.\\n *\\n * To change a role's admin, use {AccessControl-_setRoleAdmin}.\\n */\\n function getRoleAdmin(bytes32 role) external view returns (bytes32);\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * If `account` had not been already granted `role`, emits a {RoleGranted}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n */\\n function grantRole(bytes32 role, address account) external;\\n\\n /**\\n * @dev Revokes `role` from `account`.\\n *\\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n */\\n function revokeRole(bytes32 role, address account) external;\\n\\n /**\\n * @dev Revokes `role` from the calling account.\\n *\\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\\n * purpose is to provide a mechanism for accounts to lose their privileges\\n * if they are compromised (such as when a trusted device is misplaced).\\n *\\n * If the calling account had been granted `role`, emits a {RoleRevoked}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must be `account`.\\n */\\n function renounceRole(bytes32 role, address account) external;\\n}\\n\",\"keccak256\":\"0x59ce320a585d7e1f163cd70390a0ef2ff9cec832e2aa544293a00692465a7a57\",\"license\":\"MIT\"},\"@openzeppelin/contracts/security/Pausable.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"../utils/Context.sol\\\";\\n\\n/**\\n * @dev Contract module which allows children to implement an emergency stop\\n * mechanism that can be triggered by an authorized account.\\n *\\n * This module is used through inheritance. It will make available the\\n * modifiers `whenNotPaused` and `whenPaused`, which can be applied to\\n * the functions of your contract. Note that they will not be pausable by\\n * simply including this module, only once the modifiers are put in place.\\n */\\nabstract contract Pausable is Context {\\n /**\\n * @dev Emitted when the pause is triggered by `account`.\\n */\\n event Paused(address account);\\n\\n /**\\n * @dev Emitted when the pause is lifted by `account`.\\n */\\n event Unpaused(address account);\\n\\n bool private _paused;\\n\\n /**\\n * @dev Initializes the contract in unpaused state.\\n */\\n constructor() {\\n _paused = false;\\n }\\n\\n /**\\n * @dev Modifier to make a function callable only when the contract is not paused.\\n *\\n * Requirements:\\n *\\n * - The contract must not be paused.\\n */\\n modifier whenNotPaused() {\\n _requireNotPaused();\\n _;\\n }\\n\\n /**\\n * @dev Modifier to make a function callable only when the contract is paused.\\n *\\n * Requirements:\\n *\\n * - The contract must be paused.\\n */\\n modifier whenPaused() {\\n _requirePaused();\\n _;\\n }\\n\\n /**\\n * @dev Returns true if the contract is paused, and false otherwise.\\n */\\n function paused() public view virtual returns (bool) {\\n return _paused;\\n }\\n\\n /**\\n * @dev Throws if the contract is paused.\\n */\\n function _requireNotPaused() internal view virtual {\\n require(!paused(), \\\"Pausable: paused\\\");\\n }\\n\\n /**\\n * @dev Throws if the contract is not paused.\\n */\\n function _requirePaused() internal view virtual {\\n require(paused(), \\\"Pausable: not paused\\\");\\n }\\n\\n /**\\n * @dev Triggers stopped state.\\n *\\n * Requirements:\\n *\\n * - The contract must not be paused.\\n */\\n function _pause() internal virtual whenNotPaused {\\n _paused = true;\\n emit Paused(_msgSender());\\n }\\n\\n /**\\n * @dev Returns to normal state.\\n *\\n * Requirements:\\n *\\n * - The contract must be paused.\\n */\\n function _unpause() internal virtual whenPaused {\\n _paused = false;\\n emit Unpaused(_msgSender());\\n }\\n}\\n\",\"keccak256\":\"0x0849d93b16c9940beb286a7864ed02724b248b93e0d80ef6355af5ef15c64773\",\"license\":\"MIT\"},\"@openzeppelin/contracts/token/ERC20/ERC20.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/ERC20.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./IERC20.sol\\\";\\nimport \\\"./extensions/IERC20Metadata.sol\\\";\\nimport \\\"../../utils/Context.sol\\\";\\n\\n/**\\n * @dev Implementation of the {IERC20} interface.\\n *\\n * This implementation is agnostic to the way tokens are created. This means\\n * that a supply mechanism has to be added in a derived contract using {_mint}.\\n * For a generic mechanism see {ERC20PresetMinterPauser}.\\n *\\n * TIP: For a detailed writeup see our guide\\n * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How\\n * to implement supply mechanisms].\\n *\\n * We have followed general OpenZeppelin Contracts guidelines: functions revert\\n * instead returning `false` on failure. This behavior is nonetheless\\n * conventional and does not conflict with the expectations of ERC20\\n * applications.\\n *\\n * Additionally, an {Approval} event is emitted on calls to {transferFrom}.\\n * This allows applications to reconstruct the allowance for all accounts just\\n * by listening to said events. Other implementations of the EIP may not emit\\n * these events, as it isn't required by the specification.\\n *\\n * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}\\n * functions have been added to mitigate the well-known issues around setting\\n * allowances. See {IERC20-approve}.\\n */\\ncontract ERC20 is Context, IERC20, IERC20Metadata {\\n mapping(address => uint256) private _balances;\\n\\n mapping(address => mapping(address => uint256)) private _allowances;\\n\\n uint256 private _totalSupply;\\n\\n string private _name;\\n string private _symbol;\\n\\n /**\\n * @dev Sets the values for {name} and {symbol}.\\n *\\n * The default value of {decimals} is 18. To select a different value for\\n * {decimals} you should overload it.\\n *\\n * All two of these values are immutable: they can only be set once during\\n * construction.\\n */\\n constructor(string memory name_, string memory symbol_) {\\n _name = name_;\\n _symbol = symbol_;\\n }\\n\\n /**\\n * @dev Returns the name of the token.\\n */\\n function name() public view virtual override returns (string memory) {\\n return _name;\\n }\\n\\n /**\\n * @dev Returns the symbol of the token, usually a shorter version of the\\n * name.\\n */\\n function symbol() public view virtual override returns (string memory) {\\n return _symbol;\\n }\\n\\n /**\\n * @dev Returns the number of decimals used to get its user representation.\\n * For example, if `decimals` equals `2`, a balance of `505` tokens should\\n * be displayed to a user as `5.05` (`505 / 10 ** 2`).\\n *\\n * Tokens usually opt for a value of 18, imitating the relationship between\\n * Ether and Wei. This is the value {ERC20} uses, unless this function is\\n * overridden;\\n *\\n * NOTE: This information is only used for _display_ purposes: it in\\n * no way affects any of the arithmetic of the contract, including\\n * {IERC20-balanceOf} and {IERC20-transfer}.\\n */\\n function decimals() public view virtual override returns (uint8) {\\n return 18;\\n }\\n\\n /**\\n * @dev See {IERC20-totalSupply}.\\n */\\n function totalSupply() public view virtual override returns (uint256) {\\n return _totalSupply;\\n }\\n\\n /**\\n * @dev See {IERC20-balanceOf}.\\n */\\n function balanceOf(address account) public view virtual override returns (uint256) {\\n return _balances[account];\\n }\\n\\n /**\\n * @dev See {IERC20-transfer}.\\n *\\n * Requirements:\\n *\\n * - `to` cannot be the zero address.\\n * - the caller must have a balance of at least `amount`.\\n */\\n function transfer(address to, uint256 amount) public virtual override returns (bool) {\\n address owner = _msgSender();\\n _transfer(owner, to, amount);\\n return true;\\n }\\n\\n /**\\n * @dev See {IERC20-allowance}.\\n */\\n function allowance(address owner, address spender) public view virtual override returns (uint256) {\\n return _allowances[owner][spender];\\n }\\n\\n /**\\n * @dev See {IERC20-approve}.\\n *\\n * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on\\n * `transferFrom`. This is semantically equivalent to an infinite approval.\\n *\\n * Requirements:\\n *\\n * - `spender` cannot be the zero address.\\n */\\n function approve(address spender, uint256 amount) public virtual override returns (bool) {\\n address owner = _msgSender();\\n _approve(owner, spender, amount);\\n return true;\\n }\\n\\n /**\\n * @dev See {IERC20-transferFrom}.\\n *\\n * Emits an {Approval} event indicating the updated allowance. This is not\\n * required by the EIP. See the note at the beginning of {ERC20}.\\n *\\n * NOTE: Does not update the allowance if the current allowance\\n * is the maximum `uint256`.\\n *\\n * Requirements:\\n *\\n * - `from` and `to` cannot be the zero address.\\n * - `from` must have a balance of at least `amount`.\\n * - the caller must have allowance for ``from``'s tokens of at least\\n * `amount`.\\n */\\n function transferFrom(\\n address from,\\n address to,\\n uint256 amount\\n ) public virtual override returns (bool) {\\n address spender = _msgSender();\\n _spendAllowance(from, spender, amount);\\n _transfer(from, to, amount);\\n return true;\\n }\\n\\n /**\\n * @dev Atomically increases the allowance granted to `spender` by the caller.\\n *\\n * This is an alternative to {approve} that can be used as a mitigation for\\n * problems described in {IERC20-approve}.\\n *\\n * Emits an {Approval} event indicating the updated allowance.\\n *\\n * Requirements:\\n *\\n * - `spender` cannot be the zero address.\\n */\\n function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {\\n address owner = _msgSender();\\n _approve(owner, spender, allowance(owner, spender) + addedValue);\\n return true;\\n }\\n\\n /**\\n * @dev Atomically decreases the allowance granted to `spender` by the caller.\\n *\\n * This is an alternative to {approve} that can be used as a mitigation for\\n * problems described in {IERC20-approve}.\\n *\\n * Emits an {Approval} event indicating the updated allowance.\\n *\\n * Requirements:\\n *\\n * - `spender` cannot be the zero address.\\n * - `spender` must have allowance for the caller of at least\\n * `subtractedValue`.\\n */\\n function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {\\n address owner = _msgSender();\\n uint256 currentAllowance = allowance(owner, spender);\\n require(currentAllowance >= subtractedValue, \\\"ERC20: decreased allowance below zero\\\");\\n unchecked {\\n _approve(owner, spender, currentAllowance - subtractedValue);\\n }\\n\\n return true;\\n }\\n\\n /**\\n * @dev Moves `amount` of tokens from `from` to `to`.\\n *\\n * This internal function is equivalent to {transfer}, and can be used to\\n * e.g. implement automatic token fees, slashing mechanisms, etc.\\n *\\n * Emits a {Transfer} event.\\n *\\n * Requirements:\\n *\\n * - `from` cannot be the zero address.\\n * - `to` cannot be the zero address.\\n * - `from` must have a balance of at least `amount`.\\n */\\n function _transfer(\\n address from,\\n address to,\\n uint256 amount\\n ) internal virtual {\\n require(from != address(0), \\\"ERC20: transfer from the zero address\\\");\\n require(to != address(0), \\\"ERC20: transfer to the zero address\\\");\\n\\n _beforeTokenTransfer(from, to, amount);\\n\\n uint256 fromBalance = _balances[from];\\n require(fromBalance >= amount, \\\"ERC20: transfer amount exceeds balance\\\");\\n unchecked {\\n _balances[from] = fromBalance - amount;\\n // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by\\n // decrementing then incrementing.\\n _balances[to] += amount;\\n }\\n\\n emit Transfer(from, to, amount);\\n\\n _afterTokenTransfer(from, to, amount);\\n }\\n\\n /** @dev Creates `amount` tokens and assigns them to `account`, increasing\\n * the total supply.\\n *\\n * Emits a {Transfer} event with `from` set to the zero address.\\n *\\n * Requirements:\\n *\\n * - `account` cannot be the zero address.\\n */\\n function _mint(address account, uint256 amount) internal virtual {\\n require(account != address(0), \\\"ERC20: mint to the zero address\\\");\\n\\n _beforeTokenTransfer(address(0), account, amount);\\n\\n _totalSupply += amount;\\n unchecked {\\n // Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.\\n _balances[account] += amount;\\n }\\n emit Transfer(address(0), account, amount);\\n\\n _afterTokenTransfer(address(0), account, amount);\\n }\\n\\n /**\\n * @dev Destroys `amount` tokens from `account`, reducing the\\n * total supply.\\n *\\n * Emits a {Transfer} event with `to` set to the zero address.\\n *\\n * Requirements:\\n *\\n * - `account` cannot be the zero address.\\n * - `account` must have at least `amount` tokens.\\n */\\n function _burn(address account, uint256 amount) internal virtual {\\n require(account != address(0), \\\"ERC20: burn from the zero address\\\");\\n\\n _beforeTokenTransfer(account, address(0), amount);\\n\\n uint256 accountBalance = _balances[account];\\n require(accountBalance >= amount, \\\"ERC20: burn amount exceeds balance\\\");\\n unchecked {\\n _balances[account] = accountBalance - amount;\\n // Overflow not possible: amount <= accountBalance <= totalSupply.\\n _totalSupply -= amount;\\n }\\n\\n emit Transfer(account, address(0), amount);\\n\\n _afterTokenTransfer(account, address(0), amount);\\n }\\n\\n /**\\n * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.\\n *\\n * This internal function is equivalent to `approve`, and can be used to\\n * e.g. set automatic allowances for certain subsystems, etc.\\n *\\n * Emits an {Approval} event.\\n *\\n * Requirements:\\n *\\n * - `owner` cannot be the zero address.\\n * - `spender` cannot be the zero address.\\n */\\n function _approve(\\n address owner,\\n address spender,\\n uint256 amount\\n ) internal virtual {\\n require(owner != address(0), \\\"ERC20: approve from the zero address\\\");\\n require(spender != address(0), \\\"ERC20: approve to the zero address\\\");\\n\\n _allowances[owner][spender] = amount;\\n emit Approval(owner, spender, amount);\\n }\\n\\n /**\\n * @dev Updates `owner` s allowance for `spender` based on spent `amount`.\\n *\\n * Does not update the allowance amount in case of infinite allowance.\\n * Revert if not enough allowance is available.\\n *\\n * Might emit an {Approval} event.\\n */\\n function _spendAllowance(\\n address owner,\\n address spender,\\n uint256 amount\\n ) internal virtual {\\n uint256 currentAllowance = allowance(owner, spender);\\n if (currentAllowance != type(uint256).max) {\\n require(currentAllowance >= amount, \\\"ERC20: insufficient allowance\\\");\\n unchecked {\\n _approve(owner, spender, currentAllowance - amount);\\n }\\n }\\n }\\n\\n /**\\n * @dev Hook that is called before any transfer of tokens. This includes\\n * minting and burning.\\n *\\n * Calling conditions:\\n *\\n * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\\n * will be transferred to `to`.\\n * - when `from` is zero, `amount` tokens will be minted for `to`.\\n * - when `to` is zero, `amount` of ``from``'s tokens will be burned.\\n * - `from` and `to` are never both zero.\\n *\\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\\n */\\n function _beforeTokenTransfer(\\n address from,\\n address to,\\n uint256 amount\\n ) internal virtual {}\\n\\n /**\\n * @dev Hook that is called after any transfer of tokens. This includes\\n * minting and burning.\\n *\\n * Calling conditions:\\n *\\n * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\\n * has been transferred to `to`.\\n * - when `from` is zero, `amount` tokens have been minted for `to`.\\n * - when `to` is zero, `amount` of ``from``'s tokens have been burned.\\n * - `from` and `to` are never both zero.\\n *\\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\\n */\\n function _afterTokenTransfer(\\n address from,\\n address to,\\n uint256 amount\\n ) internal virtual {}\\n}\\n\",\"keccak256\":\"0x4ffc0547c02ad22925310c585c0f166f8759e2648a09e9b489100c42f15dd98d\",\"license\":\"MIT\"},\"@openzeppelin/contracts/token/ERC20/IERC20.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Interface of the ERC20 standard as defined in the EIP.\\n */\\ninterface IERC20 {\\n /**\\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\\n * another (`to`).\\n *\\n * Note that `value` may be zero.\\n */\\n event Transfer(address indexed from, address indexed to, uint256 value);\\n\\n /**\\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\\n * a call to {approve}. `value` is the new allowance.\\n */\\n event Approval(address indexed owner, address indexed spender, uint256 value);\\n\\n /**\\n * @dev Returns the amount of tokens in existence.\\n */\\n function totalSupply() external view returns (uint256);\\n\\n /**\\n * @dev Returns the amount of tokens owned by `account`.\\n */\\n function balanceOf(address account) external view returns (uint256);\\n\\n /**\\n * @dev Moves `amount` tokens from the caller's account to `to`.\\n *\\n * Returns a boolean value indicating whether the operation succeeded.\\n *\\n * Emits a {Transfer} event.\\n */\\n function transfer(address to, uint256 amount) external returns (bool);\\n\\n /**\\n * @dev Returns the remaining number of tokens that `spender` will be\\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\\n * zero by default.\\n *\\n * This value changes when {approve} or {transferFrom} are called.\\n */\\n function allowance(address owner, address spender) external view returns (uint256);\\n\\n /**\\n * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\\n *\\n * Returns a boolean value indicating whether the operation succeeded.\\n *\\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\\n * that someone may use both the old and the new allowance by unfortunate\\n * transaction ordering. One possible solution to mitigate this race\\n * condition is to first reduce the spender's allowance to 0 and set the\\n * desired value afterwards:\\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\\n *\\n * Emits an {Approval} event.\\n */\\n function approve(address spender, uint256 amount) external returns (bool);\\n\\n /**\\n * @dev Moves `amount` tokens from `from` to `to` using the\\n * allowance mechanism. `amount` is then deducted from the caller's\\n * allowance.\\n *\\n * Returns a boolean value indicating whether the operation succeeded.\\n *\\n * Emits a {Transfer} event.\\n */\\n function transferFrom(\\n address from,\\n address to,\\n uint256 amount\\n ) external returns (bool);\\n}\\n\",\"keccak256\":\"0x9750c6b834f7b43000631af5cc30001c5f547b3ceb3635488f140f60e897ea6b\",\"license\":\"MIT\"},\"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"../IERC20.sol\\\";\\n\\n/**\\n * @dev Interface for the optional metadata functions from the ERC20 standard.\\n *\\n * _Available since v4.1._\\n */\\ninterface IERC20Metadata is IERC20 {\\n /**\\n * @dev Returns the name of the token.\\n */\\n function name() external view returns (string memory);\\n\\n /**\\n * @dev Returns the symbol of the token.\\n */\\n function symbol() external view returns (string memory);\\n\\n /**\\n * @dev Returns the decimals places of the token.\\n */\\n function decimals() external view returns (uint8);\\n}\\n\",\"keccak256\":\"0x8de418a5503946cabe331f35fe242d3201a73f67f77aaeb7110acb1f30423aca\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/Context.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Provides information about the current execution context, including the\\n * sender of the transaction and its data. While these are generally available\\n * via msg.sender and msg.data, they should not be accessed in such a direct\\n * manner, since when dealing with meta-transactions the account sending and\\n * paying for execution may not be the actual sender (as far as an application\\n * is concerned).\\n *\\n * This contract is only required for intermediate, library-like contracts.\\n */\\nabstract contract Context {\\n function _msgSender() internal view virtual returns (address) {\\n return msg.sender;\\n }\\n\\n function _msgData() internal view virtual returns (bytes calldata) {\\n return msg.data;\\n }\\n}\\n\",\"keccak256\":\"0xe2e337e6dde9ef6b680e07338c493ebea1b5fd09b43424112868e9cc1706bca7\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/Strings.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./math/Math.sol\\\";\\n\\n/**\\n * @dev String operations.\\n */\\nlibrary Strings {\\n bytes16 private constant _SYMBOLS = \\\"0123456789abcdef\\\";\\n uint8 private constant _ADDRESS_LENGTH = 20;\\n\\n /**\\n * @dev Converts a `uint256` to its ASCII `string` decimal representation.\\n */\\n function toString(uint256 value) internal pure returns (string memory) {\\n unchecked {\\n uint256 length = Math.log10(value) + 1;\\n string memory buffer = new string(length);\\n uint256 ptr;\\n /// @solidity memory-safe-assembly\\n assembly {\\n ptr := add(buffer, add(32, length))\\n }\\n while (true) {\\n ptr--;\\n /// @solidity memory-safe-assembly\\n assembly {\\n mstore8(ptr, byte(mod(value, 10), _SYMBOLS))\\n }\\n value /= 10;\\n if (value == 0) break;\\n }\\n return buffer;\\n }\\n }\\n\\n /**\\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\\n */\\n function toHexString(uint256 value) internal pure returns (string memory) {\\n unchecked {\\n return toHexString(value, Math.log256(value) + 1);\\n }\\n }\\n\\n /**\\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\\n */\\n function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\\n bytes memory buffer = new bytes(2 * length + 2);\\n buffer[0] = \\\"0\\\";\\n buffer[1] = \\\"x\\\";\\n for (uint256 i = 2 * length + 1; i > 1; --i) {\\n buffer[i] = _SYMBOLS[value & 0xf];\\n value >>= 4;\\n }\\n require(value == 0, \\\"Strings: hex length insufficient\\\");\\n return string(buffer);\\n }\\n\\n /**\\n * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.\\n */\\n function toHexString(address addr) internal pure returns (string memory) {\\n return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);\\n }\\n}\\n\",\"keccak256\":\"0xa4d1d62251f8574deb032a35fc948386a9b4de74b812d4f545a1ac120486b48a\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/introspection/ERC165.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./IERC165.sol\\\";\\n\\n/**\\n * @dev Implementation of the {IERC165} interface.\\n *\\n * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check\\n * for the additional interface id that will be supported. For example:\\n *\\n * ```solidity\\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\\n * }\\n * ```\\n *\\n * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.\\n */\\nabstract contract ERC165 is IERC165 {\\n /**\\n * @dev See {IERC165-supportsInterface}.\\n */\\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n return interfaceId == type(IERC165).interfaceId;\\n }\\n}\\n\",\"keccak256\":\"0xd10975de010d89fd1c78dc5e8a9a7e7f496198085c151648f20cba166b32582b\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/introspection/IERC165.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Interface of the ERC165 standard, as defined in the\\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\\n *\\n * Implementers can declare support of contract interfaces, which can then be\\n * queried by others ({ERC165Checker}).\\n *\\n * For an implementation, see {ERC165}.\\n */\\ninterface IERC165 {\\n /**\\n * @dev Returns true if this contract implements the interface defined by\\n * `interfaceId`. See the corresponding\\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\\n * to learn more about how these ids are created.\\n *\\n * This function call must use less than 30 000 gas.\\n */\\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\\n}\\n\",\"keccak256\":\"0x447a5f3ddc18419d41ff92b3773fb86471b1db25773e07f877f548918a185bf1\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/math/Math.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Standard math utilities missing in the Solidity language.\\n */\\nlibrary Math {\\n enum Rounding {\\n Down, // Toward negative infinity\\n Up, // Toward infinity\\n Zero // Toward zero\\n }\\n\\n /**\\n * @dev Returns the largest of two numbers.\\n */\\n function max(uint256 a, uint256 b) internal pure returns (uint256) {\\n return a > b ? a : b;\\n }\\n\\n /**\\n * @dev Returns the smallest of two numbers.\\n */\\n function min(uint256 a, uint256 b) internal pure returns (uint256) {\\n return a < b ? a : b;\\n }\\n\\n /**\\n * @dev Returns the average of two numbers. The result is rounded towards\\n * zero.\\n */\\n function average(uint256 a, uint256 b) internal pure returns (uint256) {\\n // (a + b) / 2 can overflow.\\n return (a & b) + (a ^ b) / 2;\\n }\\n\\n /**\\n * @dev Returns the ceiling of the division of two numbers.\\n *\\n * This differs from standard division with `/` in that it rounds up instead\\n * of rounding down.\\n */\\n function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {\\n // (a + b - 1) / b can overflow on addition, so we distribute.\\n return a == 0 ? 0 : (a - 1) / b + 1;\\n }\\n\\n /**\\n * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0\\n * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)\\n * with further edits by Uniswap Labs also under MIT license.\\n */\\n function mulDiv(\\n uint256 x,\\n uint256 y,\\n uint256 denominator\\n ) internal pure returns (uint256 result) {\\n unchecked {\\n // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use\\n // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256\\n // variables such that product = prod1 * 2^256 + prod0.\\n uint256 prod0; // Least significant 256 bits of the product\\n uint256 prod1; // Most significant 256 bits of the product\\n assembly {\\n let mm := mulmod(x, y, not(0))\\n prod0 := mul(x, y)\\n prod1 := sub(sub(mm, prod0), lt(mm, prod0))\\n }\\n\\n // Handle non-overflow cases, 256 by 256 division.\\n if (prod1 == 0) {\\n return prod0 / denominator;\\n }\\n\\n // Make sure the result is less than 2^256. Also prevents denominator == 0.\\n require(denominator > prod1);\\n\\n ///////////////////////////////////////////////\\n // 512 by 256 division.\\n ///////////////////////////////////////////////\\n\\n // Make division exact by subtracting the remainder from [prod1 prod0].\\n uint256 remainder;\\n assembly {\\n // Compute remainder using mulmod.\\n remainder := mulmod(x, y, denominator)\\n\\n // Subtract 256 bit number from 512 bit number.\\n prod1 := sub(prod1, gt(remainder, prod0))\\n prod0 := sub(prod0, remainder)\\n }\\n\\n // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.\\n // See https://cs.stackexchange.com/q/138556/92363.\\n\\n // Does not overflow because the denominator cannot be zero at this stage in the function.\\n uint256 twos = denominator & (~denominator + 1);\\n assembly {\\n // Divide denominator by twos.\\n denominator := div(denominator, twos)\\n\\n // Divide [prod1 prod0] by twos.\\n prod0 := div(prod0, twos)\\n\\n // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.\\n twos := add(div(sub(0, twos), twos), 1)\\n }\\n\\n // Shift in bits from prod1 into prod0.\\n prod0 |= prod1 * twos;\\n\\n // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such\\n // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for\\n // four bits. That is, denominator * inv = 1 mod 2^4.\\n uint256 inverse = (3 * denominator) ^ 2;\\n\\n // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works\\n // in modular arithmetic, doubling the correct bits in each step.\\n inverse *= 2 - denominator * inverse; // inverse mod 2^8\\n inverse *= 2 - denominator * inverse; // inverse mod 2^16\\n inverse *= 2 - denominator * inverse; // inverse mod 2^32\\n inverse *= 2 - denominator * inverse; // inverse mod 2^64\\n inverse *= 2 - denominator * inverse; // inverse mod 2^128\\n inverse *= 2 - denominator * inverse; // inverse mod 2^256\\n\\n // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.\\n // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is\\n // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1\\n // is no longer required.\\n result = prod0 * inverse;\\n return result;\\n }\\n }\\n\\n /**\\n * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.\\n */\\n function mulDiv(\\n uint256 x,\\n uint256 y,\\n uint256 denominator,\\n Rounding rounding\\n ) internal pure returns (uint256) {\\n uint256 result = mulDiv(x, y, denominator);\\n if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {\\n result += 1;\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.\\n *\\n * Inspired by Henry S. Warren, Jr.'s \\\"Hacker's Delight\\\" (Chapter 11).\\n */\\n function sqrt(uint256 a) internal pure returns (uint256) {\\n if (a == 0) {\\n return 0;\\n }\\n\\n // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.\\n //\\n // We know that the \\\"msb\\\" (most significant bit) of our target number `a` is a power of 2 such that we have\\n // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.\\n //\\n // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`\\n // \\u2192 `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`\\n // \\u2192 `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`\\n //\\n // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.\\n uint256 result = 1 << (log2(a) >> 1);\\n\\n // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,\\n // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at\\n // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision\\n // into the expected uint128 result.\\n unchecked {\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n return min(result, a / result);\\n }\\n }\\n\\n /**\\n * @notice Calculates sqrt(a), following the selected rounding direction.\\n */\\n function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = sqrt(a);\\n return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);\\n }\\n }\\n\\n /**\\n * @dev Return the log in base 2, rounded down, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log2(uint256 value) internal pure returns (uint256) {\\n uint256 result = 0;\\n unchecked {\\n if (value >> 128 > 0) {\\n value >>= 128;\\n result += 128;\\n }\\n if (value >> 64 > 0) {\\n value >>= 64;\\n result += 64;\\n }\\n if (value >> 32 > 0) {\\n value >>= 32;\\n result += 32;\\n }\\n if (value >> 16 > 0) {\\n value >>= 16;\\n result += 16;\\n }\\n if (value >> 8 > 0) {\\n value >>= 8;\\n result += 8;\\n }\\n if (value >> 4 > 0) {\\n value >>= 4;\\n result += 4;\\n }\\n if (value >> 2 > 0) {\\n value >>= 2;\\n result += 2;\\n }\\n if (value >> 1 > 0) {\\n result += 1;\\n }\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Return the log in base 2, following the selected rounding direction, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = log2(value);\\n return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);\\n }\\n }\\n\\n /**\\n * @dev Return the log in base 10, rounded down, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log10(uint256 value) internal pure returns (uint256) {\\n uint256 result = 0;\\n unchecked {\\n if (value >= 10**64) {\\n value /= 10**64;\\n result += 64;\\n }\\n if (value >= 10**32) {\\n value /= 10**32;\\n result += 32;\\n }\\n if (value >= 10**16) {\\n value /= 10**16;\\n result += 16;\\n }\\n if (value >= 10**8) {\\n value /= 10**8;\\n result += 8;\\n }\\n if (value >= 10**4) {\\n value /= 10**4;\\n result += 4;\\n }\\n if (value >= 10**2) {\\n value /= 10**2;\\n result += 2;\\n }\\n if (value >= 10**1) {\\n result += 1;\\n }\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = log10(value);\\n return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);\\n }\\n }\\n\\n /**\\n * @dev Return the log in base 256, rounded down, of a positive value.\\n * Returns 0 if given 0.\\n *\\n * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.\\n */\\n function log256(uint256 value) internal pure returns (uint256) {\\n uint256 result = 0;\\n unchecked {\\n if (value >> 128 > 0) {\\n value >>= 128;\\n result += 16;\\n }\\n if (value >> 64 > 0) {\\n value >>= 64;\\n result += 8;\\n }\\n if (value >> 32 > 0) {\\n value >>= 32;\\n result += 4;\\n }\\n if (value >> 16 > 0) {\\n value >>= 16;\\n result += 2;\\n }\\n if (value >> 8 > 0) {\\n result += 1;\\n }\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = log256(value);\\n return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);\\n }\\n }\\n}\\n\",\"keccak256\":\"0xa1e8e83cd0087785df04ac79fb395d9f3684caeaf973d9e2c71caef723a3a5d6\",\"license\":\"MIT\"},\"src/OrderStatisticsTree/HitchensOrderStatisticsTreeLib.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\npragma solidity ^0.8.19;\\n\\n/*\\nHitchens Order Statistics Tree v0.99\\n\\nA Solidity Red-Black Tree library to store and maintain a sorted data\\nstructure in a Red-Black binary search tree, with O(log 2n) insert, remove\\nand search time (and gas, approximately)\\n\\nhttps://github.com/rob-Hitchens/OrderStatisticsTree\\n\\nCopyright (c) Rob Hitchens. the MIT License\\n\\nPermission is hereby granted, free of charge, to any person obtaining a copy\\nof this software and associated documentation files (the \\\"Software\\\"), to deal\\nin the Software without restriction, including without limitation the rights\\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\\ncopies of the Software, and to permit persons to whom the Software is\\nfurnished to do so, subject to the following conditions:\\n\\nThe above copyright notice and this permission notice shall be included in all\\ncopies or substantial portions of the Software.\\n\\nTHE SOFTWARE IS PROVIDED \\\"AS IS\\\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\\nSOFTWARE.\\n\\nSignificant portions from BokkyPooBahsRedBlackTreeLibrary,\\nhttps://github.com/bokkypoobah/BokkyPooBahsRedBlackTreeLibrary\\n\\nTHIS SOFTWARE IS NOT TESTED OR AUDITED. DO NOT USE FOR PRODUCTION.\\n*/\\n\\nlibrary HitchensOrderStatisticsTreeLib {\\n uint private constant EMPTY = 0;\\n struct Node {\\n uint parent;\\n uint left;\\n uint right;\\n bool red;\\n bytes32[] keys;\\n mapping(bytes32 => uint) keyMap;\\n uint count;\\n }\\n struct Tree {\\n uint root;\\n mapping(uint => Node) nodes;\\n }\\n\\n error ValueDoesNotExist(); // Provided value doesn't exist in the tree.\\n error ValueCannotBeZero(); // Value to insert cannot be zero\\n error ValueKeyPairExists(); // Value and Key pair exists. Cannot be inserted again.\\n\\n function first(Tree storage self) internal view returns (uint _value) {\\n _value = self.root;\\n if (_value == EMPTY) return 0;\\n while (self.nodes[_value].left != EMPTY) {\\n _value = self.nodes[_value].left;\\n }\\n }\\n\\n function exists(Tree storage self, uint value) internal view returns (bool _exists) {\\n if (value == EMPTY) return false;\\n if (value == self.root) return true;\\n if (self.nodes[value].parent != EMPTY) return true;\\n return false;\\n }\\n\\n function keyExists(Tree storage self, bytes32 key, uint value) internal view returns (bool _exists) {\\n if (!exists(self, value)) return false;\\n return self.nodes[value].keys[self.nodes[value].keyMap[key]] == key;\\n }\\n\\n function getNode(\\n Tree storage self,\\n uint value\\n ) internal view returns (uint _parent, uint _left, uint _right, bool _red, uint keyCount, uint __count) {\\n if (!exists(self, value)) {\\n revert ValueDoesNotExist();\\n }\\n\\n Node storage gn = self.nodes[value];\\n return (gn.parent, gn.left, gn.right, gn.red, gn.keys.length, gn.keys.length + gn.count);\\n }\\n\\n function getNodeCount(Tree storage self, uint value) internal view returns (uint __count) {\\n Node storage gn = self.nodes[value];\\n return gn.keys.length + gn.count;\\n }\\n\\n function valueKeyAtIndex(Tree storage self, uint value, uint index) internal view returns (bytes32 _key) {\\n if (!exists(self, value)) {\\n revert ValueDoesNotExist();\\n }\\n return self.nodes[value].keys[index];\\n }\\n\\n function count(Tree storage self) internal view returns (uint _count) {\\n return getNodeCount(self, self.root);\\n }\\n\\n /* We don't use this functionality, so it is commented out to make audit easier\\n\\n function percentile(Tree storage self, uint value) internal view returns(uint _percentile) {\\n uint denominator = count(self);\\n uint numerator = rank(self, value);\\n _percentile = ((uint(1000) * numerator)/denominator+(uint(5)))/uint(10);\\n }\\n function permil(Tree storage self, uint value) internal view returns(uint _permil) {\\n uint denominator = count(self);\\n uint numerator = rank(self, value);\\n _permil = ((uint(10000) * numerator)/denominator+(uint(5)))/uint(10);\\n }\\n function atPercentile(Tree storage self, uint _percentile) internal view returns(uint _value) {\\n uint findRank = (((_percentile * count(self))/uint(10)) + uint(5)) / uint(10);\\n return atRank(self,findRank);\\n }\\n function atPermil(Tree storage self, uint _permil) internal view returns(uint _value) {\\n uint findRank = (((_permil * count(self))/uint(100)) + uint(5)) / uint(10);\\n return atRank(self,findRank);\\n }\\n function median(Tree storage self) internal view returns(uint value) {\\n return atPercentile(self,50);\\n }\\n function below(Tree storage self, uint value) public view returns(uint _below) {\\n if(count(self) > 0 && value > 0) _below = rank(self,value)-uint(1);\\n }\\n function above(Tree storage self, uint value) public view returns(uint _above) {\\n if(count(self) > 0) _above = count(self)-rank(self,value);\\n }\\n function valueBelowEstimate(Tree storage self, uint estimate) public view returns(uint _below) {\\n if(count(self) > 0 && estimate > 0) {\\n uint highestValue = last(self);\\n uint lowestValue = first(self);\\n if(estimate < lowestValue) {\\n return 0;\\n }\\n if(estimate >= highestValue) {\\n return highestValue;\\n }\\n uint rankOfValue = rank(self, estimate); // approximation\\n _below = atRank(self, rankOfValue);\\n if(_below > estimate) { // fix error in approximation\\n rankOfValue--;\\n _below = atRank(self, rankOfValue);\\n }\\n }\\n }\\n function valueAboveEstimate(Tree storage self, uint estimate) public view returns(uint _above) {\\n if(count(self) > 0 && estimate > 0) {\\n uint highestValue = last(self);\\n uint lowestValue = first(self);\\n if(estimate > highestValue) {\\n return 0;\\n }\\n if(estimate <= lowestValue) {\\n return lowestValue;\\n }\\n uint rankOfValue = rank(self, estimate); // approximation\\n _above = atRank(self, rankOfValue);\\n if(_above < estimate) { // fix error in approximation\\n rankOfValue++;\\n _above = atRank(self, rankOfValue);\\n }\\n }\\n }\\n function rank(Tree storage self, uint value) internal view returns(uint _rank) {\\n if(count(self) > 0) {\\n bool finished;\\n uint cursor = self.root;\\n Node storage c = self.nodes[cursor];\\n uint smaller = getNodeCount(self,c.left);\\n while (!finished) {\\n uint keyCount = c.keys.length;\\n if(cursor == value) {\\n finished = true;\\n } else {\\n if(cursor < value) {\\n cursor = c.right;\\n c = self.nodes[cursor];\\n smaller += keyCount + getNodeCount(self,c.left);\\n } else {\\n cursor = c.left;\\n c = self.nodes[cursor];\\n smaller -= (keyCount + getNodeCount(self,c.right));\\n }\\n }\\n if (!exists(self,cursor)) {\\n finished = true;\\n }\\n }\\n return smaller + 1;\\n }\\n }\\n function atRank(Tree storage self, uint _rank) internal view returns(uint _value) {\\n bool finished;\\n uint cursor = self.root;\\n Node storage c = self.nodes[cursor];\\n uint smaller = getNodeCount(self,c.left);\\n while (!finished) {\\n _value = cursor;\\n c = self.nodes[cursor];\\n uint keyCount = c.keys.length;\\n if(smaller + 1 >= _rank && smaller + keyCount <= _rank) {\\n _value = cursor;\\n finished = true;\\n } else {\\n if(smaller + keyCount <= _rank) {\\n cursor = c.right;\\n c = self.nodes[cursor];\\n smaller += keyCount + getNodeCount(self,c.left);\\n } else {\\n cursor = c.left;\\n c = self.nodes[cursor];\\n smaller -= (keyCount + getNodeCount(self,c.right));\\n }\\n }\\n if (!exists(self,cursor)) {\\n finished = true;\\n }\\n }\\n }\\n*/\\n\\n function insert(Tree storage self, bytes32 key, uint value) internal {\\n if (value == EMPTY) {\\n revert ValueCannotBeZero();\\n }\\n if (keyExists(self, key, value)) {\\n revert ValueKeyPairExists();\\n }\\n uint cursor;\\n uint probe = self.root;\\n while (probe != EMPTY) {\\n cursor = probe;\\n if (value < probe) {\\n probe = self.nodes[probe].left;\\n } else if (value > probe) {\\n probe = self.nodes[probe].right;\\n } else if (value == probe) {\\n self.nodes[probe].keys.push(key);\\n self.nodes[probe].keyMap[key] = self.nodes[probe].keys.length - uint(1);\\n return;\\n }\\n self.nodes[cursor].count++;\\n }\\n Node storage nValue = self.nodes[value];\\n nValue.parent = cursor;\\n nValue.left = EMPTY;\\n nValue.right = EMPTY;\\n nValue.red = true;\\n nValue.keys.push(key);\\n nValue.keyMap[key] = nValue.keys.length - uint(1);\\n if (cursor == EMPTY) {\\n self.root = value;\\n } else if (value < cursor) {\\n self.nodes[cursor].left = value;\\n } else {\\n self.nodes[cursor].right = value;\\n }\\n insertFixup(self, value);\\n }\\n\\n function remove(Tree storage self, bytes32 key, uint value) internal {\\n if (value == EMPTY) {\\n revert ValueCannotBeZero();\\n }\\n if (!keyExists(self, key, value)) {\\n revert ValueDoesNotExist();\\n }\\n\\n Node storage nValue = self.nodes[value];\\n uint rowToDelete = nValue.keyMap[key];\\n bytes32 last = nValue.keys[nValue.keys.length - uint(1)];\\n nValue.keys[rowToDelete] = last;\\n nValue.keyMap[last] = rowToDelete;\\n nValue.keys.pop();\\n\\n uint probe;\\n uint cursor;\\n\\n if (nValue.keys.length == 0) {\\n if (self.nodes[value].left == EMPTY || self.nodes[value].right == EMPTY) {\\n cursor = value;\\n } else {\\n cursor = self.nodes[value].right;\\n while (self.nodes[cursor].left != EMPTY) {\\n cursor = self.nodes[cursor].left;\\n }\\n }\\n\\n if (self.nodes[cursor].left != EMPTY) {\\n probe = self.nodes[cursor].left;\\n } else {\\n probe = self.nodes[cursor].right;\\n }\\n\\n uint cursorParent = self.nodes[cursor].parent;\\n self.nodes[probe].parent = cursorParent;\\n\\n if (cursorParent != EMPTY) {\\n if (cursor == self.nodes[cursorParent].left) {\\n self.nodes[cursorParent].left = probe;\\n } else {\\n self.nodes[cursorParent].right = probe;\\n }\\n } else {\\n self.root = probe;\\n }\\n\\n bool doFixup = !self.nodes[cursor].red;\\n\\n if (cursor != value) {\\n replaceParent(self, cursor, value);\\n self.nodes[cursor].left = self.nodes[value].left;\\n self.nodes[self.nodes[cursor].left].parent = cursor;\\n self.nodes[cursor].right = self.nodes[value].right;\\n self.nodes[self.nodes[cursor].right].parent = cursor;\\n self.nodes[cursor].red = self.nodes[value].red;\\n (cursor, value) = (value, cursor);\\n fixCountRecurse(self, value);\\n }\\n\\n if (doFixup) {\\n removeFixup(self, probe);\\n }\\n\\n fixCountRecurse(self, cursorParent);\\n delete self.nodes[cursor];\\n }\\n }\\n\\n function fixCountRecurse(Tree storage self, uint value) private {\\n while (value != EMPTY) {\\n self.nodes[value].count =\\n getNodeCount(self, self.nodes[value].left) +\\n getNodeCount(self, self.nodes[value].right);\\n value = self.nodes[value].parent;\\n }\\n }\\n\\n function treeMinimum(Tree storage self, uint value) private view returns (uint) {\\n while (self.nodes[value].left != EMPTY) {\\n value = self.nodes[value].left;\\n }\\n return value;\\n }\\n\\n function treeMaximum(Tree storage self, uint value) private view returns (uint) {\\n while (self.nodes[value].right != EMPTY) {\\n value = self.nodes[value].right;\\n }\\n return value;\\n }\\n\\n function rotateLeft(Tree storage self, uint value) private {\\n uint cursor = self.nodes[value].right;\\n uint parent = self.nodes[value].parent;\\n uint cursorLeft = self.nodes[cursor].left;\\n self.nodes[value].right = cursorLeft;\\n if (cursorLeft != EMPTY) {\\n self.nodes[cursorLeft].parent = value;\\n }\\n self.nodes[cursor].parent = parent;\\n if (parent == EMPTY) {\\n self.root = cursor;\\n } else if (value == self.nodes[parent].left) {\\n self.nodes[parent].left = cursor;\\n } else {\\n self.nodes[parent].right = cursor;\\n }\\n self.nodes[cursor].left = value;\\n self.nodes[value].parent = cursor;\\n self.nodes[value].count =\\n getNodeCount(self, self.nodes[value].left) +\\n getNodeCount(self, self.nodes[value].right);\\n self.nodes[cursor].count =\\n getNodeCount(self, self.nodes[cursor].left) +\\n getNodeCount(self, self.nodes[cursor].right);\\n }\\n\\n function rotateRight(Tree storage self, uint value) private {\\n uint cursor = self.nodes[value].left;\\n uint parent = self.nodes[value].parent;\\n uint cursorRight = self.nodes[cursor].right;\\n self.nodes[value].left = cursorRight;\\n if (cursorRight != EMPTY) {\\n self.nodes[cursorRight].parent = value;\\n }\\n self.nodes[cursor].parent = parent;\\n if (parent == EMPTY) {\\n self.root = cursor;\\n } else if (value == self.nodes[parent].right) {\\n self.nodes[parent].right = cursor;\\n } else {\\n self.nodes[parent].left = cursor;\\n }\\n self.nodes[cursor].right = value;\\n self.nodes[value].parent = cursor;\\n self.nodes[value].count =\\n getNodeCount(self, self.nodes[value].left) +\\n getNodeCount(self, self.nodes[value].right);\\n self.nodes[cursor].count =\\n getNodeCount(self, self.nodes[cursor].left) +\\n getNodeCount(self, self.nodes[cursor].right);\\n }\\n\\n function insertFixup(Tree storage self, uint value) private {\\n uint cursor;\\n while (value != self.root && self.nodes[self.nodes[value].parent].red) {\\n uint valueParent = self.nodes[value].parent;\\n if (valueParent == self.nodes[self.nodes[valueParent].parent].left) {\\n cursor = self.nodes[self.nodes[valueParent].parent].right;\\n if (self.nodes[cursor].red) {\\n self.nodes[valueParent].red = false;\\n self.nodes[cursor].red = false;\\n self.nodes[self.nodes[valueParent].parent].red = true;\\n value = self.nodes[valueParent].parent;\\n } else {\\n if (value == self.nodes[valueParent].right) {\\n value = valueParent;\\n rotateLeft(self, value);\\n }\\n valueParent = self.nodes[value].parent;\\n self.nodes[valueParent].red = false;\\n self.nodes[self.nodes[valueParent].parent].red = true;\\n rotateRight(self, self.nodes[valueParent].parent);\\n }\\n } else {\\n cursor = self.nodes[self.nodes[valueParent].parent].left;\\n if (self.nodes[cursor].red) {\\n self.nodes[valueParent].red = false;\\n self.nodes[cursor].red = false;\\n self.nodes[self.nodes[valueParent].parent].red = true;\\n value = self.nodes[valueParent].parent;\\n } else {\\n if (value == self.nodes[valueParent].left) {\\n value = valueParent;\\n rotateRight(self, value);\\n }\\n valueParent = self.nodes[value].parent;\\n self.nodes[valueParent].red = false;\\n self.nodes[self.nodes[valueParent].parent].red = true;\\n rotateLeft(self, self.nodes[valueParent].parent);\\n }\\n }\\n }\\n self.nodes[self.root].red = false;\\n }\\n\\n function replaceParent(Tree storage self, uint a, uint b) private {\\n uint bParent = self.nodes[b].parent;\\n self.nodes[a].parent = bParent;\\n if (bParent == EMPTY) {\\n self.root = a;\\n } else {\\n if (b == self.nodes[bParent].left) {\\n self.nodes[bParent].left = a;\\n } else {\\n self.nodes[bParent].right = a;\\n }\\n }\\n }\\n\\n function removeFixup(Tree storage self, uint value) private {\\n uint cursor;\\n while (value != self.root && !self.nodes[value].red) {\\n uint valueParent = self.nodes[value].parent;\\n if (value == self.nodes[valueParent].left) {\\n cursor = self.nodes[valueParent].right;\\n if (self.nodes[cursor].red) {\\n self.nodes[cursor].red = false;\\n self.nodes[valueParent].red = true;\\n rotateLeft(self, valueParent);\\n cursor = self.nodes[valueParent].right;\\n }\\n if (!self.nodes[self.nodes[cursor].left].red && !self.nodes[self.nodes[cursor].right].red) {\\n self.nodes[cursor].red = true;\\n value = valueParent;\\n } else {\\n if (!self.nodes[self.nodes[cursor].right].red) {\\n self.nodes[self.nodes[cursor].left].red = false;\\n self.nodes[cursor].red = true;\\n rotateRight(self, cursor);\\n cursor = self.nodes[valueParent].right;\\n }\\n self.nodes[cursor].red = self.nodes[valueParent].red;\\n self.nodes[valueParent].red = false;\\n self.nodes[self.nodes[cursor].right].red = false;\\n rotateLeft(self, valueParent);\\n value = self.root;\\n }\\n } else {\\n cursor = self.nodes[valueParent].left;\\n if (self.nodes[cursor].red) {\\n self.nodes[cursor].red = false;\\n self.nodes[valueParent].red = true;\\n rotateRight(self, valueParent);\\n cursor = self.nodes[valueParent].left;\\n }\\n if (!self.nodes[self.nodes[cursor].right].red && !self.nodes[self.nodes[cursor].left].red) {\\n self.nodes[cursor].red = true;\\n value = valueParent;\\n } else {\\n if (!self.nodes[self.nodes[cursor].left].red) {\\n self.nodes[self.nodes[cursor].right].red = false;\\n self.nodes[cursor].red = true;\\n rotateLeft(self, cursor);\\n cursor = self.nodes[valueParent].left;\\n }\\n self.nodes[cursor].red = self.nodes[valueParent].red;\\n self.nodes[valueParent].red = false;\\n self.nodes[self.nodes[cursor].left].red = false;\\n rotateRight(self, valueParent);\\n value = self.root;\\n }\\n }\\n }\\n self.nodes[value].red = false;\\n }\\n}\\n\",\"keccak256\":\"0x3d13491ca535051ff9d923b284f6b633c660a4d110804e4a3e965dfaa59024b8\",\"license\":\"MIT\"},\"src/PostageStamp.sol\":{\"content\":\"// SPDX-License-Identifier: BSD-3-Clause\\npragma solidity ^0.8.19;\\nimport \\\"@openzeppelin/contracts/token/ERC20/ERC20.sol\\\";\\nimport \\\"@openzeppelin/contracts/access/AccessControl.sol\\\";\\nimport \\\"@openzeppelin/contracts/security/Pausable.sol\\\";\\nimport \\\"./OrderStatisticsTree/HitchensOrderStatisticsTreeLib.sol\\\";\\n\\n/**\\n * @title PostageStamp contract\\n * @author The Swarm Authors\\n * @dev The postage stamp contracts allows users to create and manage postage stamp batches.\\n * The current balance for each batch is stored ordered in descending order of normalised balance.\\n * Balance is normalised to be per chunk and the total spend since the contract was deployed, i.e. when a batch\\n * is bought, its per-chunk balance is supplemented with the current cost of storing one chunk since the beginning of time,\\n * as if the batch had existed since the contract's inception. During the _expiry_ process, each of these balances is\\n * checked against the _currentTotalOutPayment_, a similarly normalised figure that represents the current cost of\\n * storing one chunk since the beginning of time. A batch with a normalised balance less than _currentTotalOutPayment_\\n * is treated as expired.\\n *\\n * The _currentTotalOutPayment_ is calculated using _totalOutPayment_ which is updated during _setPrice_ events so\\n * that the applicable per-chunk prices can be charged for the relevant periods of time. This can then be multiplied\\n * by the amount of chunks which are allowed to be stamped by each batch to get the actual cost of storage.\\n *\\n * The amount of chunks a batch can stamp is determined by the _bucketDepth_. A batch may store a maximum of 2^depth chunks.\\n * The global figure for the currently allowed chunks is tracked by _validChunkCount_ and updated during batch _expiry_ events.\\n */\\n\\ncontract PostageStamp is AccessControl, Pausable {\\n using HitchensOrderStatisticsTreeLib for HitchensOrderStatisticsTreeLib.Tree;\\n\\n // ----------------------------- State variables ------------------------------\\n\\n // Address of the ERC20 token this contract references.\\n address public bzzToken;\\n\\n // Minimum allowed depth of bucket.\\n uint8 public minimumBucketDepth;\\n\\n // Role allowed to increase totalOutPayment.\\n bytes32 public immutable PRICE_ORACLE_ROLE;\\n\\n // Role allowed to pause\\n bytes32 public immutable PAUSER_ROLE;\\n // Role allowed to withdraw the pot.\\n bytes32 public immutable REDISTRIBUTOR_ROLE;\\n\\n // Associate every batch id with batch data.\\n mapping(bytes32 => Batch) public batches;\\n // Store every batch id ordered by normalisedBalance.\\n HitchensOrderStatisticsTreeLib.Tree tree;\\n\\n // Total out payment per chunk, at the blockheight of the last price change.\\n uint256 private totalOutPayment;\\n\\n // Combined global chunk capacity of valid batches remaining at the blockheight expire() was last called.\\n uint256 public validChunkCount;\\n\\n // Lottery pot at last update.\\n uint256 public pot;\\n\\n // Normalised balance at the blockheight expire() was last called.\\n uint256 public lastExpiryBalance;\\n\\n // Price from the last update.\\n uint64 public lastPrice;\\n\\n // blocks in 24 hours ~ 24 * 60 * 60 / 5 = 17280\\n uint64 public minimumValidityBlocks = 17280;\\n\\n // Block at which the last update occured.\\n uint64 public lastUpdatedBlock;\\n\\n // ----------------------------- Type declarations ------------------------------\\n\\n struct Batch {\\n // Owner of this batch (0 if not valid).\\n address owner;\\n // Current depth of this batch.\\n uint8 depth;\\n // Bucket depth defined in this batch\\n uint8 bucketDepth;\\n // Whether this batch is immutable.\\n bool immutableFlag;\\n // Normalised balance per chunk.\\n uint256 normalisedBalance;\\n // When was this batch last updated\\n uint256 lastUpdatedBlockNumber;\\n }\\n\\n struct ImportBatch {\\n bytes32 batchId;\\n address owner;\\n uint8 depth;\\n uint8 bucketDepth;\\n bool immutableFlag;\\n uint256 remainingBalance;\\n }\\n\\n // ----------------------------- Events ------------------------------\\n\\n /**\\n * @dev Emitted when a new batch is created.\\n */\\n event BatchCreated(\\n bytes32 indexed batchId,\\n uint256 totalAmount,\\n uint256 normalisedBalance,\\n address owner,\\n uint8 depth,\\n uint8 bucketDepth,\\n bool immutableFlag\\n );\\n\\n /**\\n * @dev Emitted when an pot is Withdrawn.\\n */\\n event PotWithdrawn(address recipient, uint256 totalAmount);\\n\\n /**\\n * @dev Emitted when an existing batch is topped up.\\n */\\n event BatchTopUp(bytes32 indexed batchId, uint256 topupAmount, uint256 normalisedBalance);\\n\\n /**\\n * @dev Emitted when the depth of an existing batch increases.\\n */\\n event BatchDepthIncrease(bytes32 indexed batchId, uint8 newDepth, uint256 normalisedBalance);\\n\\n /**\\n *@dev Emitted on every price update.\\n */\\n event PriceUpdate(uint256 price);\\n\\n /**\\n *@dev Emitted on every batch failed in bulk batch creation\\n */\\n event CopyBatchFailed(uint index, bytes32 batchId);\\n\\n // ----------------------------- Errors ------------------------------\\n\\n error ZeroAddress(); // Owner cannot be the zero address\\n error InvalidDepth(); // Invalid bucket depth\\n error BatchExists(); // Batch already exists\\n error InsufficientBalance(); // Insufficient initial balance for 24h minimum validity\\n error TransferFailed(); // Failed transfer of BZZ tokens\\n error ZeroBalance(); // NormalisedBalance cannot be zero\\n error AdministratorOnly(); // Only administrator can use copy method\\n error BatchDoesNotExist(); // Batch does not exist or has expired\\n error BatchExpired(); // Batch already expired\\n error BatchTooSmall(); // Batch too small to renew\\n error NotBatchOwner(); // Not batch owner\\n error DepthNotIncreasing(); // Depth not increasing\\n error PriceOracleOnly(); // Only price oracle can set the price\\n error InsufficienChunkCount(); // Insufficient valid chunk count\\n error TotalOutpaymentDecreased(); // Current total outpayment should never decrease\\n error NoBatchesExist(); // There are no batches\\n error OnlyPauser(); // Only Pauser role can pause or unpause contracts\\n error OnlyRedistributor(); // Only redistributor role can withdraw from the contract\\n\\n // ----------------------------- CONSTRUCTOR ------------------------------\\n\\n /**\\n * @param _bzzToken The ERC20 token address to reference in this contract.\\n * @param _minimumBucketDepth The minimum bucket depth of batches that can be purchased.\\n */\\n constructor(address _bzzToken, uint8 _minimumBucketDepth) {\\n bzzToken = _bzzToken;\\n minimumBucketDepth = _minimumBucketDepth;\\n PRICE_ORACLE_ROLE = keccak256(\\\"PRICE_ORACLE_ROLE\\\");\\n PAUSER_ROLE = keccak256(\\\"PAUSER_ROLE\\\");\\n REDISTRIBUTOR_ROLE = keccak256(\\\"REDISTRIBUTOR_ROLE\\\");\\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\\n _setupRole(PAUSER_ROLE, msg.sender);\\n }\\n\\n ////////////////////////////////////////\\n // STATE CHANGING //\\n ////////////////////////////////////////\\n\\n /**\\n * @notice Create a new batch.\\n * @dev At least `_initialBalancePerChunk*2^depth` tokens must be approved in the ERC20 token contract.\\n * @param _owner Owner of the new batch.\\n * @param _initialBalancePerChunk Initial balance per chunk.\\n * @param _depth Initial depth of the new batch.\\n * @param _nonce A random value used in the batch id derivation to allow multiple batches per owner.\\n * @param _immutable Whether the batch is mutable.\\n */\\n function createBatch(\\n address _owner,\\n uint256 _initialBalancePerChunk,\\n uint8 _depth,\\n uint8 _bucketDepth,\\n bytes32 _nonce,\\n bool _immutable\\n ) external whenNotPaused returns (bytes32) {\\n if (_owner == address(0)) {\\n revert ZeroAddress();\\n }\\n\\n if (_bucketDepth == 0 || _bucketDepth < minimumBucketDepth || _bucketDepth >= _depth) {\\n revert InvalidDepth();\\n }\\n\\n bytes32 batchId = keccak256(abi.encode(msg.sender, _nonce));\\n if (batches[batchId].owner != address(0)) {\\n revert BatchExists();\\n }\\n\\n if (_initialBalancePerChunk < minimumInitialBalancePerChunk()) {\\n revert InsufficientBalance();\\n }\\n\\n uint256 totalAmount = _initialBalancePerChunk * (1 << _depth);\\n if (!ERC20(bzzToken).transferFrom(msg.sender, address(this), totalAmount)) {\\n revert TransferFailed();\\n }\\n\\n uint256 normalisedBalance = currentTotalOutPayment() + (_initialBalancePerChunk);\\n if (normalisedBalance == 0) {\\n revert ZeroBalance();\\n }\\n\\n expireLimited(type(uint256).max);\\n validChunkCount += 1 << _depth;\\n\\n batches[batchId] = Batch({\\n owner: _owner,\\n depth: _depth,\\n bucketDepth: _bucketDepth,\\n immutableFlag: _immutable,\\n normalisedBalance: normalisedBalance,\\n lastUpdatedBlockNumber: block.number\\n });\\n\\n tree.insert(batchId, normalisedBalance);\\n\\n emit BatchCreated(batchId, totalAmount, normalisedBalance, _owner, _depth, _bucketDepth, _immutable);\\n\\n return batchId;\\n }\\n\\n /**\\n * @notice Manually create a new batch when facilitating migration, can only be called by the Admin role.\\n * @dev At least `_initialBalancePerChunk*2^depth` tokens must be approved in the ERC20 token contract.\\n * @param _owner Owner of the new batch.\\n * @param _initialBalancePerChunk Initial balance per chunk of the batch.\\n * @param _depth Initial depth of the new batch.\\n * @param _batchId BatchId being copied (from previous version contract data).\\n * @param _immutable Whether the batch is mutable.\\n */\\n function copyBatch(\\n address _owner,\\n uint256 _initialBalancePerChunk,\\n uint8 _depth,\\n uint8 _bucketDepth,\\n bytes32 _batchId,\\n bool _immutable\\n ) public whenNotPaused {\\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\\n revert AdministratorOnly();\\n }\\n\\n if (_owner == address(0)) {\\n revert ZeroAddress();\\n }\\n\\n if (_bucketDepth == 0 || _bucketDepth >= _depth) {\\n revert InvalidDepth();\\n }\\n\\n if (batches[_batchId].owner != address(0)) {\\n revert BatchExists();\\n }\\n\\n uint256 totalAmount = _initialBalancePerChunk * (1 << _depth);\\n uint256 normalisedBalance = currentTotalOutPayment() + (_initialBalancePerChunk);\\n if (normalisedBalance == 0) {\\n revert ZeroBalance();\\n }\\n\\n //update validChunkCount to remove currently expired batches\\n expireLimited(type(uint256).max);\\n\\n validChunkCount += 1 << _depth;\\n\\n batches[_batchId] = Batch({\\n owner: _owner,\\n depth: _depth,\\n bucketDepth: _bucketDepth,\\n immutableFlag: _immutable,\\n normalisedBalance: normalisedBalance,\\n lastUpdatedBlockNumber: block.number\\n });\\n\\n tree.insert(_batchId, normalisedBalance);\\n\\n emit BatchCreated(_batchId, totalAmount, normalisedBalance, _owner, _depth, _bucketDepth, _immutable);\\n }\\n\\n /**\\n * @notice Import batches in bulk\\n * @dev Import batches in bulk to lower the number of transactions needed,\\n * @dev becase of block limitations 90 batches per trx is ceiling, 60 to 70 sweetspot\\n * @param bulkBatches array of batches\\n */\\n function copyBatchBulk(ImportBatch[] calldata bulkBatches) external {\\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\\n revert AdministratorOnly();\\n }\\n for (uint i = 0; i < bulkBatches.length; i++) {\\n ImportBatch memory _batch = bulkBatches[i];\\n try\\n this.copyBatch(\\n _batch.owner,\\n _batch.remainingBalance,\\n _batch.depth,\\n _batch.bucketDepth,\\n _batch.batchId,\\n _batch.immutableFlag\\n )\\n {\\n // Successful copyBatch call\\n } catch {\\n // copyBatch failed, handle error\\n emit CopyBatchFailed(i, _batch.batchId);\\n }\\n }\\n }\\n\\n /**\\n * @notice Top up an existing batch.\\n * @dev At least `_topupAmountPerChunk*2^depth` tokens must be approved in the ERC20 token contract.\\n * @param _batchId The id of an existing batch.\\n * @param _topupAmountPerChunk The amount of additional tokens to add per chunk.\\n */\\n function topUp(bytes32 _batchId, uint256 _topupAmountPerChunk) external whenNotPaused {\\n Batch memory batch = batches[_batchId];\\n\\n if (batch.owner == address(0)) {\\n revert BatchDoesNotExist();\\n }\\n\\n if (batch.normalisedBalance <= currentTotalOutPayment()) {\\n revert BatchExpired();\\n }\\n\\n if (batch.depth <= minimumBucketDepth) {\\n revert BatchTooSmall();\\n }\\n\\n if (remainingBalance(_batchId) + (_topupAmountPerChunk) < minimumInitialBalancePerChunk()) {\\n revert InsufficientBalance();\\n }\\n\\n // per chunk balance multiplied by the batch size in chunks must be transferred from the sender\\n uint256 totalAmount = _topupAmountPerChunk * (1 << batch.depth);\\n if (!ERC20(bzzToken).transferFrom(msg.sender, address(this), totalAmount)) {\\n revert TransferFailed();\\n }\\n\\n // update by removing batch and then reinserting\\n tree.remove(_batchId, batch.normalisedBalance);\\n batch.normalisedBalance = batch.normalisedBalance + (_topupAmountPerChunk);\\n tree.insert(_batchId, batch.normalisedBalance);\\n\\n batches[_batchId].normalisedBalance = batch.normalisedBalance;\\n emit BatchTopUp(_batchId, totalAmount, batch.normalisedBalance);\\n }\\n\\n /**\\n * @notice Increase the depth of an existing batch.\\n * @dev Can only be called by the owner of the batch.\\n * @param _batchId the id of an existing batch.\\n * @param _newDepth the new (larger than the previous one) depth for this batch.\\n */\\n function increaseDepth(bytes32 _batchId, uint8 _newDepth) external whenNotPaused {\\n Batch memory batch = batches[_batchId];\\n\\n if (batch.owner != msg.sender) {\\n revert NotBatchOwner();\\n }\\n\\n if (!(minimumBucketDepth < _newDepth && batch.depth < _newDepth)) {\\n revert DepthNotIncreasing();\\n }\\n\\n if (batch.normalisedBalance <= currentTotalOutPayment()) {\\n revert BatchExpired();\\n }\\n\\n uint8 depthChange = _newDepth - batch.depth;\\n uint256 newRemainingBalance = remainingBalance(_batchId) / (1 << depthChange);\\n\\n if (newRemainingBalance < minimumInitialBalancePerChunk()) {\\n revert InsufficientBalance();\\n }\\n\\n expireLimited(type(uint256).max);\\n validChunkCount += (1 << _newDepth) - (1 << batch.depth);\\n tree.remove(_batchId, batch.normalisedBalance);\\n batches[_batchId].depth = _newDepth;\\n batches[_batchId].lastUpdatedBlockNumber = block.number;\\n\\n batch.normalisedBalance = currentTotalOutPayment() + newRemainingBalance;\\n batches[_batchId].normalisedBalance = batch.normalisedBalance;\\n tree.insert(_batchId, batch.normalisedBalance);\\n\\n emit BatchDepthIncrease(_batchId, _newDepth, batch.normalisedBalance);\\n }\\n\\n /**\\n * @notice Set a new price.\\n * @dev Can only be called by the price oracle role.\\n * @param _price The new price.\\n */\\n function setPrice(uint256 _price) external {\\n if (!hasRole(PRICE_ORACLE_ROLE, msg.sender)) {\\n revert PriceOracleOnly();\\n }\\n\\n if (lastPrice != 0) {\\n totalOutPayment = currentTotalOutPayment();\\n }\\n\\n lastPrice = uint64(_price);\\n lastUpdatedBlock = uint64(block.number);\\n\\n emit PriceUpdate(_price);\\n }\\n\\n function setMinimumValidityBlocks(uint64 _value) external {\\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\\n revert AdministratorOnly();\\n }\\n\\n minimumValidityBlocks = _value;\\n }\\n\\n /**\\n * @notice Reclaims a limited number of expired batches\\n * @dev Can be used if reclaiming all expired batches would exceed the block gas limit, causing other\\n * contract method calls to fail.\\n * @param limit The maximum number of batches to expire.\\n */\\n function expireLimited(uint256 limit) public {\\n // the lower bound of the normalised balance for which we will check if batches have expired\\n uint256 _lastExpiryBalance = lastExpiryBalance;\\n uint256 i;\\n for (i; i < limit; ) {\\n if (isBatchesTreeEmpty()) {\\n lastExpiryBalance = currentTotalOutPayment();\\n break;\\n }\\n // get the batch with the smallest normalised balance\\n bytes32 fbi = firstBatchId();\\n // if the batch with the smallest balance has not yet expired\\n // we have already reached the end of the batches we need\\n // to expire, so exit the loop\\n if (remainingBalance(fbi) > 0) {\\n // the upper bound of the normalised balance for which we will check if batches have expired\\n // value is updated when there are no expired batches left\\n lastExpiryBalance = currentTotalOutPayment();\\n break;\\n }\\n // otherwise, the batch with the smallest balance has expired,\\n // so we must remove the chunks this batch contributes to the global validChunkCount\\n Batch memory batch = batches[fbi];\\n uint256 batchSize = 1 << batch.depth;\\n\\n if (validChunkCount < batchSize) {\\n revert InsufficienChunkCount();\\n }\\n validChunkCount -= batchSize;\\n // since the batch expired _during_ the period we must add\\n // remaining normalised payout for this batch only\\n pot += batchSize * (batch.normalisedBalance - _lastExpiryBalance);\\n tree.remove(fbi, batch.normalisedBalance);\\n delete batches[fbi];\\n\\n unchecked {\\n ++i;\\n }\\n }\\n // then, for all batches that have _not_ expired during the period\\n // add the total normalised payout of all batches\\n // multiplied by the remaining total valid chunk count\\n // to the pot for the period since the last expiry\\n\\n if (lastExpiryBalance < _lastExpiryBalance) {\\n revert TotalOutpaymentDecreased();\\n }\\n\\n // then, for all batches that have _not_ expired during the period\\n // add the total normalised payout of all batches\\n // multiplied by the remaining total valid chunk count\\n // to the pot for the period since the last expiry\\n pot += validChunkCount * (lastExpiryBalance - _lastExpiryBalance);\\n }\\n\\n /**\\n * @notice The current pot.\\n */\\n function totalPot() public returns (uint256) {\\n expireLimited(type(uint256).max);\\n uint256 balance = ERC20(bzzToken).balanceOf(address(this));\\n return pot < balance ? pot : balance;\\n }\\n\\n /**\\n * @notice Withdraw the pot, authorised callers only.\\n * @param beneficiary Recieves the current total pot.\\n */\\n\\n function withdraw(address beneficiary) external {\\n if (!hasRole(REDISTRIBUTOR_ROLE, msg.sender)) {\\n revert OnlyRedistributor();\\n }\\n\\n uint256 totalAmount = totalPot();\\n if (!ERC20(bzzToken).transfer(beneficiary, totalAmount)) {\\n revert TransferFailed();\\n }\\n\\n emit PotWithdrawn(beneficiary, totalAmount);\\n pot = 0;\\n }\\n\\n /**\\n * @notice Pause the contract.\\n * @dev Can only be called by the pauser when not paused.\\n * The contract can be provably stopped by renouncing the pauser role and the admin role once paused.\\n */\\n function pause() public {\\n if (!hasRole(PAUSER_ROLE, msg.sender)) {\\n revert OnlyPauser();\\n }\\n _pause();\\n }\\n\\n /**\\n * @notice Unpause the contract.\\n * @dev Can only be called by the pauser role while paused.\\n */\\n function unPause() public {\\n if (!hasRole(PAUSER_ROLE, msg.sender)) {\\n revert OnlyPauser();\\n }\\n\\n _unpause();\\n }\\n\\n ////////////////////////////////////////\\n // STATE READING //\\n ////////////////////////////////////////\\n\\n /**\\n * @notice Total per-chunk cost since the contract's deployment.\\n * @dev Returns the total normalised all-time per chunk payout.\\n * Only Batches with a normalised balance greater than this are valid.\\n */\\n function currentTotalOutPayment() public view returns (uint256) {\\n uint256 blocks = block.number - lastUpdatedBlock;\\n uint256 increaseSinceLastUpdate = lastPrice * (blocks);\\n return totalOutPayment + (increaseSinceLastUpdate);\\n }\\n\\n function minimumInitialBalancePerChunk() public view returns (uint256) {\\n return minimumValidityBlocks * lastPrice;\\n }\\n\\n /**\\n * @notice Return the per chunk balance not yet used up.\\n * @param _batchId The id of an existing batch.\\n */\\n function remainingBalance(bytes32 _batchId) public view returns (uint256) {\\n Batch memory batch = batches[_batchId];\\n\\n if (batch.owner == address(0)) {\\n revert BatchDoesNotExist(); // Batch does not exist or expired\\n }\\n\\n if (batch.normalisedBalance <= currentTotalOutPayment()) {\\n return 0;\\n }\\n\\n return batch.normalisedBalance - currentTotalOutPayment();\\n }\\n\\n /**\\n * @notice Indicates whether expired batches exist.\\n */\\n function expiredBatchesExist() public view returns (bool) {\\n if (isBatchesTreeEmpty()) {\\n return false;\\n }\\n return (remainingBalance(firstBatchId()) <= 0);\\n }\\n\\n /**\\n * @notice Return true if no batches exist\\n */\\n function isBatchesTreeEmpty() public view returns (bool) {\\n return tree.count() == 0;\\n }\\n\\n /**\\n * @notice Get the first batch id ordered by ascending normalised balance.\\n * @dev If more than one batch id, return index at 0, if no batches, revert.\\n */\\n function firstBatchId() public view returns (bytes32) {\\n uint256 val = tree.first();\\n if (val == 0) {\\n revert NoBatchesExist();\\n }\\n return tree.valueKeyAtIndex(val, 0);\\n }\\n\\n function batchOwner(bytes32 _batchId) public view returns (address) {\\n return batches[_batchId].owner;\\n }\\n\\n function batchDepth(bytes32 _batchId) public view returns (uint8) {\\n return batches[_batchId].depth;\\n }\\n\\n function batchBucketDepth(bytes32 _batchId) public view returns (uint8) {\\n return batches[_batchId].bucketDepth;\\n }\\n\\n function batchImmutableFlag(bytes32 _batchId) public view returns (bool) {\\n return batches[_batchId].immutableFlag;\\n }\\n\\n function batchNormalisedBalance(bytes32 _batchId) public view returns (uint256) {\\n return batches[_batchId].normalisedBalance;\\n }\\n\\n function batchLastUpdatedBlockNumber(bytes32 _batchId) public view returns (uint256) {\\n return batches[_batchId].lastUpdatedBlockNumber;\\n }\\n}\\n\",\"keccak256\":\"0x7d4fb7df6e72f3feb06c17dfa56f21213b6a2f2911814c495d65444b7ea2f256\",\"license\":\"BSD-3-Clause\"}},\"version\":1}", "bytecode": "0x60e060405260098054600160401b600160801b03191669438000000000000000001790553480156200003057600080fd5b5060405162003bc938038062003bc98339810160408190526200005391620001c4565b600180546001600160b01b0319166101006001600160a01b0385160260ff60a81b191617600160a81b60ff8416021790557f1337d7d57528a8879766fdf2d0456253114c66c4fc263c97168bfdb007c64c666080527f65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a60a0527f3e35b14a9f4fef84b59f9bdcd3044fc28783144b7e42bfb2cd075e6a02cb082860c052620000fd60003362000114565b60a0516200010c903362000114565b505062000213565b62000120828262000124565b5050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1662000120576000828152602081815260408083206001600160a01b03851684529091529020805460ff19166001179055620001803390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b60008060408385031215620001d857600080fd5b82516001600160a01b0381168114620001f057600080fd5b602084015190925060ff811681146200020857600080fd5b809150509250929050565b60805160a05160c05161396a6200025f600039600081816105bb015261118b01526000818161075e015281816118ad0152611e2b015260008181610609015261199e015261396a6000f3fe608060405234801561001057600080fd5b50600436106102f45760003560e01c806381e508b911610191578063b998902f116100e3578063dd483cfb11610097578063ea612e1f11610071578063ea612e1f14610780578063f7b188a514610789578063f90ce5ba1461079157600080fd5b8063dd483cfb14610716578063df67438514610736578063e63ab1e91461075957600080fd5b8063d547741f116100c8578063d547741f146106c6578063d71ba7c4146106d9578063d968f44b146106ec57600080fd5b8063b998902f14610604578063c81e25ab1461062b57600080fd5b806391b7f5ed11610145578063a6471a1d1161011f578063a6471a1d146105b6578063a81064ee146105dd578063b67644b9146105f157600080fd5b806391b7f5ed1461056457806391d1485414610577578063a217fddf146105ae57600080fd5b80638a5e8e32116101765780638a5e8e321461054b5780638b82547f14610554578063906978421461055c57600080fd5b806381e508b91461051f5780638456cb591461054357600080fd5b8063420fc4db1161024a57806351b17cd0116101fe5780635c975abb116101d85780635c975abb146104f9578063628de87714610504578063711bfa2b1461051757600080fd5b806351b17cd0146104cb57806351cff8d9146104d35780635239af71146104e657600080fd5b806347aab79b1161022f57806347aab79b1461049c5780634ba2363a146104af5780634bb13e34146104b857600080fd5b8063420fc4db1461045a57806344beae8e1461047257600080fd5b80632182ddb1116102ac5780632f2ff15d116102865780632f2ff15d146103f857806332ac57dd1461040b57806336568abe1461044757600080fd5b80632182ddb11461037e578063248a9ca3146103bf57806324b570a9146103f057600080fd5b80631889b99b116102dd5780631889b99b1461034e57806318c8572f146103565780631a37b4851461036b57600080fd5b806301ffc9a7146102f9578063053f14da14610321575b600080fd5b61030c610307366004613427565b6107ac565b60405190151581526020015b60405180910390f35b6009546103359067ffffffffffffffff1681565b60405167ffffffffffffffff9091168152602001610318565b61030c610845565b6103696103643660046134aa565b610857565b005b610369610379366004613514565b610af1565b6103a761038c36600461353e565b6000908152600260205260409020546001600160a01b031690565b6040516001600160a01b039091168152602001610318565b6103e26103cd36600461353e565b60009081526020819052604090206001015490565b604051908152602001610318565b6103e2610b87565b610369610406366004613557565b610c3a565b61043561041936600461353e565b600090815260026020526040902054600160a81b900460ff1690565b60405160ff9091168152602001610318565b610369610455366004613557565b610c64565b6001546103a79061010090046001600160a01b031681565b61043561048036600461353e565b600090815260026020526040902054600160a01b900460ff1690565b6103696104aa366004613583565b610cf5565b6103e260075481565b6103696104c63660046135a6565b610fa8565b6103e2611131565b6103696104e136600461361b565b611189565b6103e26104f43660046134aa565b611306565b60015460ff1661030c565b61036961051236600461353e565b611664565b61030c611882565b6103e261052d36600461353e565b6000908152600260208190526040909120015490565b6103696118ab565b6103e260065481565b6103e261190e565b6103e2611964565b61036961057236600461353e565b61199c565b61030c610585366004613557565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b6103e2600081565b6103e27f000000000000000000000000000000000000000000000000000000000000000081565b60015461043590600160a81b900460ff1681565b6103696105ff366004613636565b611aab565b6103e27f000000000000000000000000000000000000000000000000000000000000000081565b61068661063936600461353e565b60026020819052600091825260409091208054600182015491909201546001600160a01b0383169260ff600160a01b8204811693600160a81b8304821693600160b01b9093049091169186565b604080516001600160a01b0397909716875260ff9586166020880152939094169285019290925215156060840152608083015260a082015260c001610318565b6103696106d4366004613557565b611d3f565b6103e26106e736600461353e565b611d64565b61030c6106fa36600461353e565b600090815260026020526040902054600160b01b900460ff1690565b6009546103359068010000000000000000900467ffffffffffffffff1681565b6103e261074436600461353e565b60009081526002602052604090206001015490565b6103e27f000000000000000000000000000000000000000000000000000000000000000081565b6103e260085481565b610369611e29565b60095461033590600160801b900467ffffffffffffffff1681565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f7965db0b00000000000000000000000000000000000000000000000000000000148061083f57507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008316145b92915050565b60006108516003611e8a565b15919050565b61085f611e9a565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff166108ae57604051635844c9e760e11b815260040160405180910390fd5b6001600160a01b0386166108d55760405163d92e233d60e01b815260040160405180910390fd5b60ff831615806108eb57508360ff168360ff1610155b1561090957604051630a0b2c3560e41b815260040160405180910390fd5b6000828152600260205260409020546001600160a01b03161561093f576040516311ab459f60e21b815260040160405180910390fd5b6000610951600160ff87161b8761366e565b905060008661095e611131565b6109689190613685565b90508060000361098b5760405163334ab3f560e11b815260040160405180910390fd5b610996600019611664565b8560ff166001901b600660008282546109af9190613685565b90915550506040805160c0810182526001600160a01b03808b16825260ff808a1660208085019182528a831685870190815289151560608701908152608087018981524360a0890190815260008e815260029586905299909920975188549551935192511515600160b01b0260ff60b01b19938816600160a81b029390931661ffff60a81b1994909716600160a01b0274ffffffffffffffffffffffffffffffffffffffffff19909616971696909617939093171692909217178355905160018301559151910155610a8360038583611eed565b60408051838152602081018390526001600160a01b038a168183015260ff88811660608301528716608082015284151560a0820152905185917f9b088e2c89b322a3c1d81515e1c88db3d386d022926f0e2d0b9b5813b7413d58919081900360c00190a25050505050505050565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff16610b4057604051635844c9e760e11b815260040160405180910390fd5b6009805467ffffffffffffffff90921668010000000000000000027fffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff909216919091179055565b6000610b94600019611664565b6001546040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015260009161010090046001600160a01b0316906370a0823190602401602060405180830381865afa158015610bfb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c1f9190613698565b90508060075410610c305780610c34565b6007545b91505090565b600082815260208190526040902060010154610c55816120f0565b610c5f83836120fd565b505050565b6001600160a01b0381163314610ce75760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b610cf1828261219b565b5050565b610cfd611e9a565b600082815260026020818152604092839020835160c08101855281546001600160a01b03811680835260ff600160a01b8304811695840195909552600160a81b8204851696830196909652600160b01b900490921615156060830152600181015460808301529091015460a0820152903314610da5576040517fb72bcb2f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60015460ff808416600160a81b90920416108015610dcc57508160ff16816020015160ff16105b610e02576040517fd5fd03fc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610e0a611131565b816080015111610e2d576040516368aebbc560e01b815260040160405180910390fd5b6000816020015183610e3f91906136b1565b90506000600160ff83161b610e5386611d64565b610e5d91906136ca565b9050610e67611964565b811015610e8757604051631e9acf1760e31b815260040160405180910390fd5b610e92600019611664565b826020015160ff166001901b8460ff166001901b610eb091906136ec565b60066000828254610ec19190613685565b90915550506080830151610ed990600390879061221a565b600085815260026020819052604090912080547fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff16600160a01b60ff8816021781554391015580610f28611131565b610f329190613685565b6080840181815260008781526002602052604090206001019190915551610f5d906003908790611eed565b60808301516040805160ff87168152602081019290925286917faf27998ec15e9d3809edad41aec1b5551d8412e71bd07c91611a0237ead1dc8e910160405180910390a25050505050565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff16610ff757604051635844c9e760e11b815260040160405180910390fd5b60005b81811015610c5f576000838383818110611016576110166136ff565b905060c0020180360381019061102c919061372b565b602081015160a082015160408084015160608501518551608087015193517f18c8572f0000000000000000000000000000000000000000000000000000000081526001600160a01b039096166004870152602486019490945260ff91821660448601521660648401526084830191909152151560a482015290915030906318c8572f9060c401600060405180830381600087803b1580156110cc57600080fd5b505af19250505080156110dd575060015b61111e5780516040805184815260208101929092527f7ded044f9ef68a0ffb6bdb48c80387f300787e7492659224ad140db77893950d910160405180910390a15b5080611129816137cd565b915050610ffa565b600954600090819061115490600160801b900467ffffffffffffffff16436136ec565b60095490915060009061117290839067ffffffffffffffff1661366e565b9050806005546111829190613685565b9250505090565b7f000000000000000000000000000000000000000000000000000000000000000060009081526020818152604080832033845290915290205460ff166111fb576040517f24876df800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000611205610b87565b6001546040517fa9059cbb0000000000000000000000000000000000000000000000000000000081526001600160a01b038581166004830152602482018490529293506101009091049091169063a9059cbb906044016020604051808303816000875af115801561127a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061129e91906137e6565b6112bb576040516312171d8360e31b815260040160405180910390fd5b604080516001600160a01b0384168152602081018390527ff5d8f9b1e7af440e1e7915f4693ccc004d1461a7dafd17ea7347d03decf298e1910160405180910390a150506000600755565b6000611310611e9a565b6001600160a01b0387166113375760405163d92e233d60e01b815260040160405180910390fd5b60ff84161580611356575060015460ff600160a81b9091048116908516105b8061136757508460ff168460ff1610155b1561138557604051630a0b2c3560e41b815260040160405180910390fd5b6040805133602082015290810184905260009060600160408051601f198184030181529181528151602092830120600081815260029093529120549091506001600160a01b0316156113ea576040516311ab459f60e21b815260040160405180910390fd5b6113f2611964565b87101561141257604051631e9acf1760e31b815260040160405180910390fd5b6000611424600160ff89161b8961366e565b6001546040516323b872dd60e01b81523360048201523060248201526044810183905291925061010090046001600160a01b0316906323b872dd906064016020604051808303816000875af1158015611481573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114a591906137e6565b6114c2576040516312171d8360e31b815260040160405180910390fd5b6000886114cd611131565b6114d79190613685565b9050806000036114fa5760405163334ab3f560e11b815260040160405180910390fd5b611505600019611664565b8760ff166001901b6006600082825461151e9190613685565b90915550506040805160c0810182526001600160a01b03808d16825260ff808c1660208085019182528c83168587019081528b151560608701908152608087018981524360a0890190815260008d815260029586905299909920975188549551935192511515600160b01b0260ff60b01b19938816600160a81b029390931661ffff60a81b1994909716600160a01b0274ffffffffffffffffffffffffffffffffffffffffff199096169716969096179390931716929092171783559051600183015591519101556115f260038483611eed565b60408051838152602081018390526001600160a01b038c168183015260ff8a811660608301528916608082015286151560a0820152905184917f9b088e2c89b322a3c1d81515e1c88db3d386d022926f0e2d0b9b5813b7413d58919081900360c00190a2509098975050505050505050565b60085460005b828110156118105761167a610845565b1561168f57611687611131565b600855611810565b600061169961190e565b905060006116a682611d64565b11156116bd576116b4611131565b60085550611810565b600081815260026020818152604092839020835160c08101855281546001600160a01b038116825260ff600160a01b82048116948301859052600160a81b8204811696830196909652600160b01b900490941615156060850152600180820154608086015292015460a084015260065491901b9081111561176a576040517f9b02220b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b806006600082825461177c91906136ec565b909155505060808201516117919086906136ec565b61179b908261366e565b600760008282546117ac9190613685565b909155505060808201516117c490600390859061221a565b50506000908152600260208190526040822080547fffffffffffffffffff000000000000000000000000000000000000000000000016815560018082018490559101919091550161166a565b81600854101561184c576040517f530da97a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8160085461185a91906136ec565b600654611867919061366e565b600760008282546118789190613685565b9091555050505050565b600061188c610845565b156118975750600090565b60006118a46106e761190e565b1115905090565b7f000000000000000000000000000000000000000000000000000000000000000060009081526020818152604080832033845290915290205460ff1661190457604051631d77d47760e21b815260040160405180910390fd5b61190c61256b565b565b60008061191b60036125bf565b905080600003611957576040517f46c83ec800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610c346003826000612606565b60095460009061198d9067ffffffffffffffff8082169168010000000000000000900416613803565b67ffffffffffffffff16905090565b7f000000000000000000000000000000000000000000000000000000000000000060009081526020818152604080832033845290915290205460ff16611a0e576040517fea0f601b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60095467ffffffffffffffff1615611a2c57611a28611131565b6005555b600980544367ffffffffffffffff908116600160801b027fffffffffffffffff0000000000000000ffffffffffffffff0000000000000000909216908416171790556040517fae46785019700e30375a5d7b4f91e32f8060ef085111f896ebf889450aa2ab5a90611aa09083815260200190565b60405180910390a150565b611ab3611e9a565b600082815260026020818152604092839020835160c08101855281546001600160a01b03811680835260ff600160a01b8304811695840195909552600160a81b8204851696830196909652600160b01b900490921615156060830152600181015460808301529091015460a082015290611b4057604051634ee9bc0f60e01b815260040160405180910390fd5b611b48611131565b816080015111611b6b576040516368aebbc560e01b815260040160405180910390fd5b600154602082015160ff600160a81b9092048216911611611bb8576040517f7103b80500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611bc0611964565b82611bca85611d64565b611bd49190613685565b1015611bf357604051631e9acf1760e31b815260040160405180910390fd5b6000816020015160ff166001901b83611c0c919061366e565b6001546040516323b872dd60e01b81523360048201523060248201526044810183905291925061010090046001600160a01b0316906323b872dd906064016020604051808303816000875af1158015611c69573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c8d91906137e6565b611caa576040516312171d8360e31b815260040160405180910390fd5b6080820151611cbd90600390869061221a565b828260800151611ccd9190613685565b60808301819052611ce2906003908690611eed565b60808201805160008681526002602090815260409182902060010192909255915182518481529182015285917faf5756c62d6c0722ef9be1f82bef97ab06ea5aea7f3eb8ad348422079f01d88d910160405180910390a250505050565b600082815260208190526040902060010154611d5a816120f0565b610c5f838361219b565b6000818152600260208181526040808420815160c08101835281546001600160a01b03811680835260ff600160a01b8304811696840196909652600160a81b8204861694830194909452600160b01b900490931615156060840152600181015460808401529092015460a082015290611df057604051634ee9bc0f60e01b815260040160405180910390fd5b611df8611131565b816080015111611e0b5750600092915050565b611e13611131565b8160800151611e2291906136ec565b9392505050565b7f000000000000000000000000000000000000000000000000000000000000000060009081526020818152604080832033845290915290205460ff16611e8257604051631d77d47760e21b815260040160405180910390fd5b61190c612668565b600061083f8283600001546126a1565b60015460ff161561190c5760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a20706175736564000000000000000000000000000000006044820152606401610cde565b80611f0b576040516363868c5560e11b815260040160405180910390fd5b611f168383836126cd565b15611f4d576040517f6082d5c100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b82546000905b80156120315780915080831015611f7d576000908152600180860160205260409091200154612008565b80831115611f9e576000908152600185016020526040902060020154612008565b808303612008576000818152600180870160209081526040832060040180548084018255818552918420909101879055918390529054611fde91906136ec565b60009182526001909501602090815260408083209583526005909501905292909220929092555050565b60008281526001860160205260408120600601805491612027836137cd565b9190505550611f53565b600083815260018087016020908152604083208581558083018490556002810184905560038101805460ff191684179055600481018054808501825581865292909420909101879055915461208691906136ec565b6000868152600583016020526040902055826120a4578386556120de565b828410156120c757600083815260018088016020526040909120018490556120de565b600083815260018701602052604090206002018490555b6120e88685612733565b505050505050565b6120fa813361299b565b50565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610cf1576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556121573390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1615610cf1576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b80612238576040516363868c5560e11b815260040160405180910390fd5b6122438383836126cd565b61226057604051635889b1c560e11b815260040160405180910390fd5b6000818152600180850160209081526040808420868552600581019092528320546004820180549294919391929091612298916136ec565b815481106122a8576122a86136ff565b90600052602060002001549050808360040183815481106122cb576122cb6136ff565b60009182526020808320909101929092558281526005850190915260409020829055600483018054806123005761230061382f565b6001900381819060005260206000200160009055905560008084600401805490506000036125615760008681526001808a0160205260409091200154158061235957506000868152600189016020526040902060020154155b156123655750846123ad565b5060008581526001880160205260409020600201545b60008181526001808a0160205260409091200154156123ad57600090815260018089016020526040909120015461237b565b60008181526001808a0160205260409091200154156123e15760008181526001808a016020526040909120015491506123f8565b600081815260018901602052604090206002015491505b600081815260018901602052604080822054848352912081905580156124685760008181526001808b0160205260409091200154820361244d5760008181526001808b0160205260409091200183905561246c565b600081815260018a016020526040902060020183905561246c565b8289555b600082815260018a01602052604090206003015460ff16158783146124ff576124968a848a612a0e565b600088815260018b8101602052604080832080830154878552828520938401819055845281842087905560028082015490840181905584529083208690556003908101549286905201805460ff191660ff90921615159190911790559196916124ff8a89612a87565b801561250f5761250f8a85612af4565b6125198a83612a87565b60008381526001808c01602052604082208281559081018290556002810182905560038101805460ff191690559061255460048301826133f5565b6006820160009055505050505b5050505050505050565b612573611e9a565b6001805460ff1916811790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258335b6040516001600160a01b03909116815260200160405180910390a1565b8054806125ce57506000919050565b5b6000818152600180840160205260409091200154156126015760009081526001808301602052604090912001546125cf565b919050565b60006126128484612f0d565b61262f57604051635889b1c560e11b815260040160405180910390fd5b60008381526001850160205260409020600401805483908110612654576126546136ff565b906000526020600020015490509392505050565b612670612f53565b6001805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa336125a2565b60008181526001830160205260408120600681015460048201546126c59190613685565b949350505050565b60006126d98483612f0d565b6126e557506000611e22565b60008281526001850160209081526040808320868452600581019092529091205460049091018054859290811061271e5761271e6136ff565b90600052602060002001541490509392505050565b60005b825482148015906127605750600082815260018401602052604080822054825290206003015460ff165b1561297957600082815260018085016020526040808320548084528184205484529220015481036128815760008181526001850160205260408082205482528082206002015480835291206003015490925060ff1615612808576000818152600180860160205260408083206003808201805460ff19908116909155878652838620820180548216905582548652928520018054909216909217905590829052549250612973565b6000818152600185016020526040902060020154830361282f5780925061282f8484612fa5565b50600082815260018085016020526040808320548084528184206003808201805460ff1990811690915582548752938620018054909316909317909155918290525461287c908590613122565b612973565b6000818152600180860160205260408083205483528083209091015480835291206003015490925060ff16156128ff576000818152600180860160205260408083206003808201805460ff19908116909155878652838620820180548216905582548652928520018054909216909217905590829052549250612973565b60008181526001808601602052604090912001548303612926578092506129268484613122565b50600082815260018085016020526040808320548084528184206003808201805460ff19908116909155825487529386200180549093169093179091559182905254612973908590612fa5565b50612736565b505080546000908152600190910160205260409020600301805460ff19169055565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610cf1576129cc81613202565b6129d7836020613214565b6040516020016129e8929190613869565b60408051601f198184030181529082905262461bcd60e51b8252610cde916004016138ea565b600081815260018401602052604080822054848352912081905580612a3557828455612a81565b60008181526001808601602052604090912001548203612a6a5760008181526001808601602052604090912001839055612a81565b600081815260018501602052604090206002018390555b50505050565b8015610cf1576000818152600183016020526040902060020154612aac9083906126a1565b6000828152600180850160205260409091200154612acb9084906126a1565b612ad59190613685565b6000918252600183016020526040909120600681019190915554612a87565b60005b82548214801590612b1c5750600082815260018401602052604090206003015460ff16155b15612eee5760008281526001808501602052604080832054808452922001548303612d175760008181526001850160205260408082206002015480835291206003015490925060ff1615612bbf576000828152600180860160205260408083206003908101805460ff19908116909155858552919093209092018054909216179055612ba88482612fa5565b600081815260018501602052604090206002015491505b60008281526001808601602052604080832090910154825290206003015460ff16158015612c0a5750600082815260018501602052604080822060020154825290206003015460ff16155b15612c3757600082815260018581016020526040909120600301805460ff19169091179055915081612ee8565b600082815260018501602052604080822060020154825290206003015460ff16612cb4576000828152600180860160205260408083208083015484529083206003908101805460ff1990811690915593869052018054909216179055612c9d8483613122565b600081815260018501602052604090206002015491505b600081815260018501602052604080822060039081018054868552838520808401805460ff909316151560ff199384161790558254821690925560029091015484529190922090910180549091169055612d0e8482612fa5565b83549250612ee8565b6000818152600180860160205260408083209091015480835291206003015490925060ff1615612d96576000828152600180860160205260408083206003908101805460ff19908116909155858552919093209092018054909216179055612d7f8482613122565b600081815260018086016020526040909120015491505b600082815260018501602052604080822060020154825290206003015460ff16158015612de1575060008281526001808601602052604080832090910154825290206003015460ff16155b15612e0e57600082815260018581016020526040909120600301805460ff19169091179055915081612ee8565b60008281526001808601602052604080832090910154825290206003015460ff16612e8d57600082815260018086016020526040808320600281015484529083206003908101805460ff1990811690915593869052018054909216179055612e768483612fa5565b600081815260018086016020526040909120015491505b60008181526001808601602052604080832060039081018054878652838620808401805460ff909316151560ff19938416179055825482169092559301548452922090910180549091169055612ee38482613122565b835492505b50612af7565b506000908152600190910160205260409020600301805460ff19169055565b600081612f1c5750600061083f565b82548203612f2c5750600161083f565b600082815260018401602052604090205415612f4a5750600161083f565b50600092915050565b60015460ff1661190c5760405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f74207061757365640000000000000000000000006044820152606401610cde565b600081815260018084016020526040808320600281018054915482865292852090930154938590529183905590918015612fed57600081815260018601602052604090208490555b600083815260018601602052604090208290558161300d57828555613059565b600082815260018087016020526040909120015484036130425760008281526001808701602052604090912001839055613059565b600082815260018601602052604090206002018390555b6000838152600180870160205260408083209091018690558582529020838155600201546130889086906126a1565b60008581526001808801602052604090912001546130a79087906126a1565b6130b19190613685565b60008581526001870160205260408082206006019290925584815220600201546130dc9086906126a1565b60008481526001808801602052604090912001546130fb9087906126a1565b6131059190613685565b600093845260019095016020525050604090206006019190915550565b6000818152600180840160205260408083209182018054925483855291842060020154938590528390559091801561316857600081815260018601602052604090208490555b6000838152600186016020526040902082905581613188578285556131d4565b600082815260018601602052604090206002015484036131bd57600082815260018601602052604090206002018390556131d4565b600082815260018087016020526040909120018390555b60008381526001860160205260408082206002908101879055868352912084815501546130889086906126a1565b606061083f6001600160a01b03831660145b6060600061322383600261366e565b61322e906002613685565b67ffffffffffffffff81111561324657613246613715565b6040519080825280601f01601f191660200182016040528015613270576020820181803683370190505b5090507f3000000000000000000000000000000000000000000000000000000000000000816000815181106132a7576132a76136ff565b60200101906001600160f81b031916908160001a9053507f7800000000000000000000000000000000000000000000000000000000000000816001815181106132f2576132f26136ff565b60200101906001600160f81b031916908160001a905350600061331684600261366e565b613321906001613685565b90505b60018111156133a6577f303132333435363738396162636465660000000000000000000000000000000085600f1660108110613362576133626136ff565b1a60f81b828281518110613378576133786136ff565b60200101906001600160f81b031916908160001a90535060049490941c9361339f8161391d565b9050613324565b508315611e225760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610cde565b50805460008255906000526020600020908101906120fa91905b80821115613423576000815560010161340f565b5090565b60006020828403121561343957600080fd5b81357fffffffff0000000000000000000000000000000000000000000000000000000081168114611e2257600080fd5b80356001600160a01b038116811461260157600080fd5b803560ff8116811461260157600080fd5b80151581146120fa57600080fd5b803561260181613491565b60008060008060008060c087890312156134c357600080fd5b6134cc87613469565b9550602087013594506134e160408801613480565b93506134ef60608801613480565b92506080870135915060a087013561350681613491565b809150509295509295509295565b60006020828403121561352657600080fd5b813567ffffffffffffffff81168114611e2257600080fd5b60006020828403121561355057600080fd5b5035919050565b6000806040838503121561356a57600080fd5b8235915061357a60208401613469565b90509250929050565b6000806040838503121561359657600080fd5b8235915061357a60208401613480565b600080602083850312156135b957600080fd5b823567ffffffffffffffff808211156135d157600080fd5b818501915085601f8301126135e557600080fd5b8135818111156135f457600080fd5b86602060c08302850101111561360957600080fd5b60209290920196919550909350505050565b60006020828403121561362d57600080fd5b611e2282613469565b6000806040838503121561364957600080fd5b50508035926020909101359150565b634e487b7160e01b600052601160045260246000fd5b808202811582820484141761083f5761083f613658565b8082018082111561083f5761083f613658565b6000602082840312156136aa57600080fd5b5051919050565b60ff828116828216039081111561083f5761083f613658565b6000826136e757634e487b7160e01b600052601260045260246000fd5b500490565b8181038181111561083f5761083f613658565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b600060c0828403121561373d57600080fd5b60405160c0810181811067ffffffffffffffff8211171561376e57634e487b7160e01b600052604160045260246000fd5b6040528235815261378160208401613469565b602082015261379260408401613480565b60408201526137a360608401613480565b60608201526137b46080840161349f565b608082015260a083013560a08201528091505092915050565b6000600182016137df576137df613658565b5060010190565b6000602082840312156137f857600080fd5b8151611e2281613491565b67ffffffffffffffff81811683821602808216919082811461382757613827613658565b505092915050565b634e487b7160e01b600052603160045260246000fd5b60005b83811015613860578181015183820152602001613848565b50506000910152565b7f416363657373436f6e74726f6c3a206163636f756e74200000000000000000008152600083516138a1816017850160208801613845565b7f206973206d697373696e6720726f6c652000000000000000000000000000000060179184019182015283516138de816028840160208801613845565b01602801949350505050565b6020815260008251806020840152613909816040850160208701613845565b601f01601f19169190910160400192915050565b60008161392c5761392c613658565b50600019019056fea2646970667358221220b8e989571a98a41404ede9329461cf1ff50f79df9ca172c5ded6755573d871c364736f6c63430008130033", "deployedBytecode": "0x608060405234801561001057600080fd5b50600436106102f45760003560e01c806381e508b911610191578063b998902f116100e3578063dd483cfb11610097578063ea612e1f11610071578063ea612e1f14610780578063f7b188a514610789578063f90ce5ba1461079157600080fd5b8063dd483cfb14610716578063df67438514610736578063e63ab1e91461075957600080fd5b8063d547741f116100c8578063d547741f146106c6578063d71ba7c4146106d9578063d968f44b146106ec57600080fd5b8063b998902f14610604578063c81e25ab1461062b57600080fd5b806391b7f5ed11610145578063a6471a1d1161011f578063a6471a1d146105b6578063a81064ee146105dd578063b67644b9146105f157600080fd5b806391b7f5ed1461056457806391d1485414610577578063a217fddf146105ae57600080fd5b80638a5e8e32116101765780638a5e8e321461054b5780638b82547f14610554578063906978421461055c57600080fd5b806381e508b91461051f5780638456cb591461054357600080fd5b8063420fc4db1161024a57806351b17cd0116101fe5780635c975abb116101d85780635c975abb146104f9578063628de87714610504578063711bfa2b1461051757600080fd5b806351b17cd0146104cb57806351cff8d9146104d35780635239af71146104e657600080fd5b806347aab79b1161022f57806347aab79b1461049c5780634ba2363a146104af5780634bb13e34146104b857600080fd5b8063420fc4db1461045a57806344beae8e1461047257600080fd5b80632182ddb1116102ac5780632f2ff15d116102865780632f2ff15d146103f857806332ac57dd1461040b57806336568abe1461044757600080fd5b80632182ddb11461037e578063248a9ca3146103bf57806324b570a9146103f057600080fd5b80631889b99b116102dd5780631889b99b1461034e57806318c8572f146103565780631a37b4851461036b57600080fd5b806301ffc9a7146102f9578063053f14da14610321575b600080fd5b61030c610307366004613427565b6107ac565b60405190151581526020015b60405180910390f35b6009546103359067ffffffffffffffff1681565b60405167ffffffffffffffff9091168152602001610318565b61030c610845565b6103696103643660046134aa565b610857565b005b610369610379366004613514565b610af1565b6103a761038c36600461353e565b6000908152600260205260409020546001600160a01b031690565b6040516001600160a01b039091168152602001610318565b6103e26103cd36600461353e565b60009081526020819052604090206001015490565b604051908152602001610318565b6103e2610b87565b610369610406366004613557565b610c3a565b61043561041936600461353e565b600090815260026020526040902054600160a81b900460ff1690565b60405160ff9091168152602001610318565b610369610455366004613557565b610c64565b6001546103a79061010090046001600160a01b031681565b61043561048036600461353e565b600090815260026020526040902054600160a01b900460ff1690565b6103696104aa366004613583565b610cf5565b6103e260075481565b6103696104c63660046135a6565b610fa8565b6103e2611131565b6103696104e136600461361b565b611189565b6103e26104f43660046134aa565b611306565b60015460ff1661030c565b61036961051236600461353e565b611664565b61030c611882565b6103e261052d36600461353e565b6000908152600260208190526040909120015490565b6103696118ab565b6103e260065481565b6103e261190e565b6103e2611964565b61036961057236600461353e565b61199c565b61030c610585366004613557565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b6103e2600081565b6103e27f000000000000000000000000000000000000000000000000000000000000000081565b60015461043590600160a81b900460ff1681565b6103696105ff366004613636565b611aab565b6103e27f000000000000000000000000000000000000000000000000000000000000000081565b61068661063936600461353e565b60026020819052600091825260409091208054600182015491909201546001600160a01b0383169260ff600160a01b8204811693600160a81b8304821693600160b01b9093049091169186565b604080516001600160a01b0397909716875260ff9586166020880152939094169285019290925215156060840152608083015260a082015260c001610318565b6103696106d4366004613557565b611d3f565b6103e26106e736600461353e565b611d64565b61030c6106fa36600461353e565b600090815260026020526040902054600160b01b900460ff1690565b6009546103359068010000000000000000900467ffffffffffffffff1681565b6103e261074436600461353e565b60009081526002602052604090206001015490565b6103e27f000000000000000000000000000000000000000000000000000000000000000081565b6103e260085481565b610369611e29565b60095461033590600160801b900467ffffffffffffffff1681565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f7965db0b00000000000000000000000000000000000000000000000000000000148061083f57507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008316145b92915050565b60006108516003611e8a565b15919050565b61085f611e9a565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff166108ae57604051635844c9e760e11b815260040160405180910390fd5b6001600160a01b0386166108d55760405163d92e233d60e01b815260040160405180910390fd5b60ff831615806108eb57508360ff168360ff1610155b1561090957604051630a0b2c3560e41b815260040160405180910390fd5b6000828152600260205260409020546001600160a01b03161561093f576040516311ab459f60e21b815260040160405180910390fd5b6000610951600160ff87161b8761366e565b905060008661095e611131565b6109689190613685565b90508060000361098b5760405163334ab3f560e11b815260040160405180910390fd5b610996600019611664565b8560ff166001901b600660008282546109af9190613685565b90915550506040805160c0810182526001600160a01b03808b16825260ff808a1660208085019182528a831685870190815289151560608701908152608087018981524360a0890190815260008e815260029586905299909920975188549551935192511515600160b01b0260ff60b01b19938816600160a81b029390931661ffff60a81b1994909716600160a01b0274ffffffffffffffffffffffffffffffffffffffffff19909616971696909617939093171692909217178355905160018301559151910155610a8360038583611eed565b60408051838152602081018390526001600160a01b038a168183015260ff88811660608301528716608082015284151560a0820152905185917f9b088e2c89b322a3c1d81515e1c88db3d386d022926f0e2d0b9b5813b7413d58919081900360c00190a25050505050505050565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff16610b4057604051635844c9e760e11b815260040160405180910390fd5b6009805467ffffffffffffffff90921668010000000000000000027fffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff909216919091179055565b6000610b94600019611664565b6001546040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015260009161010090046001600160a01b0316906370a0823190602401602060405180830381865afa158015610bfb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c1f9190613698565b90508060075410610c305780610c34565b6007545b91505090565b600082815260208190526040902060010154610c55816120f0565b610c5f83836120fd565b505050565b6001600160a01b0381163314610ce75760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b610cf1828261219b565b5050565b610cfd611e9a565b600082815260026020818152604092839020835160c08101855281546001600160a01b03811680835260ff600160a01b8304811695840195909552600160a81b8204851696830196909652600160b01b900490921615156060830152600181015460808301529091015460a0820152903314610da5576040517fb72bcb2f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60015460ff808416600160a81b90920416108015610dcc57508160ff16816020015160ff16105b610e02576040517fd5fd03fc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610e0a611131565b816080015111610e2d576040516368aebbc560e01b815260040160405180910390fd5b6000816020015183610e3f91906136b1565b90506000600160ff83161b610e5386611d64565b610e5d91906136ca565b9050610e67611964565b811015610e8757604051631e9acf1760e31b815260040160405180910390fd5b610e92600019611664565b826020015160ff166001901b8460ff166001901b610eb091906136ec565b60066000828254610ec19190613685565b90915550506080830151610ed990600390879061221a565b600085815260026020819052604090912080547fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff16600160a01b60ff8816021781554391015580610f28611131565b610f329190613685565b6080840181815260008781526002602052604090206001019190915551610f5d906003908790611eed565b60808301516040805160ff87168152602081019290925286917faf27998ec15e9d3809edad41aec1b5551d8412e71bd07c91611a0237ead1dc8e910160405180910390a25050505050565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff16610ff757604051635844c9e760e11b815260040160405180910390fd5b60005b81811015610c5f576000838383818110611016576110166136ff565b905060c0020180360381019061102c919061372b565b602081015160a082015160408084015160608501518551608087015193517f18c8572f0000000000000000000000000000000000000000000000000000000081526001600160a01b039096166004870152602486019490945260ff91821660448601521660648401526084830191909152151560a482015290915030906318c8572f9060c401600060405180830381600087803b1580156110cc57600080fd5b505af19250505080156110dd575060015b61111e5780516040805184815260208101929092527f7ded044f9ef68a0ffb6bdb48c80387f300787e7492659224ad140db77893950d910160405180910390a15b5080611129816137cd565b915050610ffa565b600954600090819061115490600160801b900467ffffffffffffffff16436136ec565b60095490915060009061117290839067ffffffffffffffff1661366e565b9050806005546111829190613685565b9250505090565b7f000000000000000000000000000000000000000000000000000000000000000060009081526020818152604080832033845290915290205460ff166111fb576040517f24876df800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000611205610b87565b6001546040517fa9059cbb0000000000000000000000000000000000000000000000000000000081526001600160a01b038581166004830152602482018490529293506101009091049091169063a9059cbb906044016020604051808303816000875af115801561127a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061129e91906137e6565b6112bb576040516312171d8360e31b815260040160405180910390fd5b604080516001600160a01b0384168152602081018390527ff5d8f9b1e7af440e1e7915f4693ccc004d1461a7dafd17ea7347d03decf298e1910160405180910390a150506000600755565b6000611310611e9a565b6001600160a01b0387166113375760405163d92e233d60e01b815260040160405180910390fd5b60ff84161580611356575060015460ff600160a81b9091048116908516105b8061136757508460ff168460ff1610155b1561138557604051630a0b2c3560e41b815260040160405180910390fd5b6040805133602082015290810184905260009060600160408051601f198184030181529181528151602092830120600081815260029093529120549091506001600160a01b0316156113ea576040516311ab459f60e21b815260040160405180910390fd5b6113f2611964565b87101561141257604051631e9acf1760e31b815260040160405180910390fd5b6000611424600160ff89161b8961366e565b6001546040516323b872dd60e01b81523360048201523060248201526044810183905291925061010090046001600160a01b0316906323b872dd906064016020604051808303816000875af1158015611481573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114a591906137e6565b6114c2576040516312171d8360e31b815260040160405180910390fd5b6000886114cd611131565b6114d79190613685565b9050806000036114fa5760405163334ab3f560e11b815260040160405180910390fd5b611505600019611664565b8760ff166001901b6006600082825461151e9190613685565b90915550506040805160c0810182526001600160a01b03808d16825260ff808c1660208085019182528c83168587019081528b151560608701908152608087018981524360a0890190815260008d815260029586905299909920975188549551935192511515600160b01b0260ff60b01b19938816600160a81b029390931661ffff60a81b1994909716600160a01b0274ffffffffffffffffffffffffffffffffffffffffff199096169716969096179390931716929092171783559051600183015591519101556115f260038483611eed565b60408051838152602081018390526001600160a01b038c168183015260ff8a811660608301528916608082015286151560a0820152905184917f9b088e2c89b322a3c1d81515e1c88db3d386d022926f0e2d0b9b5813b7413d58919081900360c00190a2509098975050505050505050565b60085460005b828110156118105761167a610845565b1561168f57611687611131565b600855611810565b600061169961190e565b905060006116a682611d64565b11156116bd576116b4611131565b60085550611810565b600081815260026020818152604092839020835160c08101855281546001600160a01b038116825260ff600160a01b82048116948301859052600160a81b8204811696830196909652600160b01b900490941615156060850152600180820154608086015292015460a084015260065491901b9081111561176a576040517f9b02220b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b806006600082825461177c91906136ec565b909155505060808201516117919086906136ec565b61179b908261366e565b600760008282546117ac9190613685565b909155505060808201516117c490600390859061221a565b50506000908152600260208190526040822080547fffffffffffffffffff000000000000000000000000000000000000000000000016815560018082018490559101919091550161166a565b81600854101561184c576040517f530da97a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8160085461185a91906136ec565b600654611867919061366e565b600760008282546118789190613685565b9091555050505050565b600061188c610845565b156118975750600090565b60006118a46106e761190e565b1115905090565b7f000000000000000000000000000000000000000000000000000000000000000060009081526020818152604080832033845290915290205460ff1661190457604051631d77d47760e21b815260040160405180910390fd5b61190c61256b565b565b60008061191b60036125bf565b905080600003611957576040517f46c83ec800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610c346003826000612606565b60095460009061198d9067ffffffffffffffff8082169168010000000000000000900416613803565b67ffffffffffffffff16905090565b7f000000000000000000000000000000000000000000000000000000000000000060009081526020818152604080832033845290915290205460ff16611a0e576040517fea0f601b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60095467ffffffffffffffff1615611a2c57611a28611131565b6005555b600980544367ffffffffffffffff908116600160801b027fffffffffffffffff0000000000000000ffffffffffffffff0000000000000000909216908416171790556040517fae46785019700e30375a5d7b4f91e32f8060ef085111f896ebf889450aa2ab5a90611aa09083815260200190565b60405180910390a150565b611ab3611e9a565b600082815260026020818152604092839020835160c08101855281546001600160a01b03811680835260ff600160a01b8304811695840195909552600160a81b8204851696830196909652600160b01b900490921615156060830152600181015460808301529091015460a082015290611b4057604051634ee9bc0f60e01b815260040160405180910390fd5b611b48611131565b816080015111611b6b576040516368aebbc560e01b815260040160405180910390fd5b600154602082015160ff600160a81b9092048216911611611bb8576040517f7103b80500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611bc0611964565b82611bca85611d64565b611bd49190613685565b1015611bf357604051631e9acf1760e31b815260040160405180910390fd5b6000816020015160ff166001901b83611c0c919061366e565b6001546040516323b872dd60e01b81523360048201523060248201526044810183905291925061010090046001600160a01b0316906323b872dd906064016020604051808303816000875af1158015611c69573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c8d91906137e6565b611caa576040516312171d8360e31b815260040160405180910390fd5b6080820151611cbd90600390869061221a565b828260800151611ccd9190613685565b60808301819052611ce2906003908690611eed565b60808201805160008681526002602090815260409182902060010192909255915182518481529182015285917faf5756c62d6c0722ef9be1f82bef97ab06ea5aea7f3eb8ad348422079f01d88d910160405180910390a250505050565b600082815260208190526040902060010154611d5a816120f0565b610c5f838361219b565b6000818152600260208181526040808420815160c08101835281546001600160a01b03811680835260ff600160a01b8304811696840196909652600160a81b8204861694830194909452600160b01b900490931615156060840152600181015460808401529092015460a082015290611df057604051634ee9bc0f60e01b815260040160405180910390fd5b611df8611131565b816080015111611e0b5750600092915050565b611e13611131565b8160800151611e2291906136ec565b9392505050565b7f000000000000000000000000000000000000000000000000000000000000000060009081526020818152604080832033845290915290205460ff16611e8257604051631d77d47760e21b815260040160405180910390fd5b61190c612668565b600061083f8283600001546126a1565b60015460ff161561190c5760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a20706175736564000000000000000000000000000000006044820152606401610cde565b80611f0b576040516363868c5560e11b815260040160405180910390fd5b611f168383836126cd565b15611f4d576040517f6082d5c100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b82546000905b80156120315780915080831015611f7d576000908152600180860160205260409091200154612008565b80831115611f9e576000908152600185016020526040902060020154612008565b808303612008576000818152600180870160209081526040832060040180548084018255818552918420909101879055918390529054611fde91906136ec565b60009182526001909501602090815260408083209583526005909501905292909220929092555050565b60008281526001860160205260408120600601805491612027836137cd565b9190505550611f53565b600083815260018087016020908152604083208581558083018490556002810184905560038101805460ff191684179055600481018054808501825581865292909420909101879055915461208691906136ec565b6000868152600583016020526040902055826120a4578386556120de565b828410156120c757600083815260018088016020526040909120018490556120de565b600083815260018701602052604090206002018490555b6120e88685612733565b505050505050565b6120fa813361299b565b50565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610cf1576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556121573390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1615610cf1576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b80612238576040516363868c5560e11b815260040160405180910390fd5b6122438383836126cd565b61226057604051635889b1c560e11b815260040160405180910390fd5b6000818152600180850160209081526040808420868552600581019092528320546004820180549294919391929091612298916136ec565b815481106122a8576122a86136ff565b90600052602060002001549050808360040183815481106122cb576122cb6136ff565b60009182526020808320909101929092558281526005850190915260409020829055600483018054806123005761230061382f565b6001900381819060005260206000200160009055905560008084600401805490506000036125615760008681526001808a0160205260409091200154158061235957506000868152600189016020526040902060020154155b156123655750846123ad565b5060008581526001880160205260409020600201545b60008181526001808a0160205260409091200154156123ad57600090815260018089016020526040909120015461237b565b60008181526001808a0160205260409091200154156123e15760008181526001808a016020526040909120015491506123f8565b600081815260018901602052604090206002015491505b600081815260018901602052604080822054848352912081905580156124685760008181526001808b0160205260409091200154820361244d5760008181526001808b0160205260409091200183905561246c565b600081815260018a016020526040902060020183905561246c565b8289555b600082815260018a01602052604090206003015460ff16158783146124ff576124968a848a612a0e565b600088815260018b8101602052604080832080830154878552828520938401819055845281842087905560028082015490840181905584529083208690556003908101549286905201805460ff191660ff90921615159190911790559196916124ff8a89612a87565b801561250f5761250f8a85612af4565b6125198a83612a87565b60008381526001808c01602052604082208281559081018290556002810182905560038101805460ff191690559061255460048301826133f5565b6006820160009055505050505b5050505050505050565b612573611e9a565b6001805460ff1916811790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258335b6040516001600160a01b03909116815260200160405180910390a1565b8054806125ce57506000919050565b5b6000818152600180840160205260409091200154156126015760009081526001808301602052604090912001546125cf565b919050565b60006126128484612f0d565b61262f57604051635889b1c560e11b815260040160405180910390fd5b60008381526001850160205260409020600401805483908110612654576126546136ff565b906000526020600020015490509392505050565b612670612f53565b6001805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa336125a2565b60008181526001830160205260408120600681015460048201546126c59190613685565b949350505050565b60006126d98483612f0d565b6126e557506000611e22565b60008281526001850160209081526040808320868452600581019092529091205460049091018054859290811061271e5761271e6136ff565b90600052602060002001541490509392505050565b60005b825482148015906127605750600082815260018401602052604080822054825290206003015460ff165b1561297957600082815260018085016020526040808320548084528184205484529220015481036128815760008181526001850160205260408082205482528082206002015480835291206003015490925060ff1615612808576000818152600180860160205260408083206003808201805460ff19908116909155878652838620820180548216905582548652928520018054909216909217905590829052549250612973565b6000818152600185016020526040902060020154830361282f5780925061282f8484612fa5565b50600082815260018085016020526040808320548084528184206003808201805460ff1990811690915582548752938620018054909316909317909155918290525461287c908590613122565b612973565b6000818152600180860160205260408083205483528083209091015480835291206003015490925060ff16156128ff576000818152600180860160205260408083206003808201805460ff19908116909155878652838620820180548216905582548652928520018054909216909217905590829052549250612973565b60008181526001808601602052604090912001548303612926578092506129268484613122565b50600082815260018085016020526040808320548084528184206003808201805460ff19908116909155825487529386200180549093169093179091559182905254612973908590612fa5565b50612736565b505080546000908152600190910160205260409020600301805460ff19169055565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610cf1576129cc81613202565b6129d7836020613214565b6040516020016129e8929190613869565b60408051601f198184030181529082905262461bcd60e51b8252610cde916004016138ea565b600081815260018401602052604080822054848352912081905580612a3557828455612a81565b60008181526001808601602052604090912001548203612a6a5760008181526001808601602052604090912001839055612a81565b600081815260018501602052604090206002018390555b50505050565b8015610cf1576000818152600183016020526040902060020154612aac9083906126a1565b6000828152600180850160205260409091200154612acb9084906126a1565b612ad59190613685565b6000918252600183016020526040909120600681019190915554612a87565b60005b82548214801590612b1c5750600082815260018401602052604090206003015460ff16155b15612eee5760008281526001808501602052604080832054808452922001548303612d175760008181526001850160205260408082206002015480835291206003015490925060ff1615612bbf576000828152600180860160205260408083206003908101805460ff19908116909155858552919093209092018054909216179055612ba88482612fa5565b600081815260018501602052604090206002015491505b60008281526001808601602052604080832090910154825290206003015460ff16158015612c0a5750600082815260018501602052604080822060020154825290206003015460ff16155b15612c3757600082815260018581016020526040909120600301805460ff19169091179055915081612ee8565b600082815260018501602052604080822060020154825290206003015460ff16612cb4576000828152600180860160205260408083208083015484529083206003908101805460ff1990811690915593869052018054909216179055612c9d8483613122565b600081815260018501602052604090206002015491505b600081815260018501602052604080822060039081018054868552838520808401805460ff909316151560ff199384161790558254821690925560029091015484529190922090910180549091169055612d0e8482612fa5565b83549250612ee8565b6000818152600180860160205260408083209091015480835291206003015490925060ff1615612d96576000828152600180860160205260408083206003908101805460ff19908116909155858552919093209092018054909216179055612d7f8482613122565b600081815260018086016020526040909120015491505b600082815260018501602052604080822060020154825290206003015460ff16158015612de1575060008281526001808601602052604080832090910154825290206003015460ff16155b15612e0e57600082815260018581016020526040909120600301805460ff19169091179055915081612ee8565b60008281526001808601602052604080832090910154825290206003015460ff16612e8d57600082815260018086016020526040808320600281015484529083206003908101805460ff1990811690915593869052018054909216179055612e768483612fa5565b600081815260018086016020526040909120015491505b60008181526001808601602052604080832060039081018054878652838620808401805460ff909316151560ff19938416179055825482169092559301548452922090910180549091169055612ee38482613122565b835492505b50612af7565b506000908152600190910160205260409020600301805460ff19169055565b600081612f1c5750600061083f565b82548203612f2c5750600161083f565b600082815260018401602052604090205415612f4a5750600161083f565b50600092915050565b60015460ff1661190c5760405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f74207061757365640000000000000000000000006044820152606401610cde565b600081815260018084016020526040808320600281018054915482865292852090930154938590529183905590918015612fed57600081815260018601602052604090208490555b600083815260018601602052604090208290558161300d57828555613059565b600082815260018087016020526040909120015484036130425760008281526001808701602052604090912001839055613059565b600082815260018601602052604090206002018390555b6000838152600180870160205260408083209091018690558582529020838155600201546130889086906126a1565b60008581526001808801602052604090912001546130a79087906126a1565b6130b19190613685565b60008581526001870160205260408082206006019290925584815220600201546130dc9086906126a1565b60008481526001808801602052604090912001546130fb9087906126a1565b6131059190613685565b600093845260019095016020525050604090206006019190915550565b6000818152600180840160205260408083209182018054925483855291842060020154938590528390559091801561316857600081815260018601602052604090208490555b6000838152600186016020526040902082905581613188578285556131d4565b600082815260018601602052604090206002015484036131bd57600082815260018601602052604090206002018390556131d4565b600082815260018087016020526040909120018390555b60008381526001860160205260408082206002908101879055868352912084815501546130889086906126a1565b606061083f6001600160a01b03831660145b6060600061322383600261366e565b61322e906002613685565b67ffffffffffffffff81111561324657613246613715565b6040519080825280601f01601f191660200182016040528015613270576020820181803683370190505b5090507f3000000000000000000000000000000000000000000000000000000000000000816000815181106132a7576132a76136ff565b60200101906001600160f81b031916908160001a9053507f7800000000000000000000000000000000000000000000000000000000000000816001815181106132f2576132f26136ff565b60200101906001600160f81b031916908160001a905350600061331684600261366e565b613321906001613685565b90505b60018111156133a6577f303132333435363738396162636465660000000000000000000000000000000085600f1660108110613362576133626136ff565b1a60f81b828281518110613378576133786136ff565b60200101906001600160f81b031916908160001a90535060049490941c9361339f8161391d565b9050613324565b508315611e225760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610cde565b50805460008255906000526020600020908101906120fa91905b80821115613423576000815560010161340f565b5090565b60006020828403121561343957600080fd5b81357fffffffff0000000000000000000000000000000000000000000000000000000081168114611e2257600080fd5b80356001600160a01b038116811461260157600080fd5b803560ff8116811461260157600080fd5b80151581146120fa57600080fd5b803561260181613491565b60008060008060008060c087890312156134c357600080fd5b6134cc87613469565b9550602087013594506134e160408801613480565b93506134ef60608801613480565b92506080870135915060a087013561350681613491565b809150509295509295509295565b60006020828403121561352657600080fd5b813567ffffffffffffffff81168114611e2257600080fd5b60006020828403121561355057600080fd5b5035919050565b6000806040838503121561356a57600080fd5b8235915061357a60208401613469565b90509250929050565b6000806040838503121561359657600080fd5b8235915061357a60208401613480565b600080602083850312156135b957600080fd5b823567ffffffffffffffff808211156135d157600080fd5b818501915085601f8301126135e557600080fd5b8135818111156135f457600080fd5b86602060c08302850101111561360957600080fd5b60209290920196919550909350505050565b60006020828403121561362d57600080fd5b611e2282613469565b6000806040838503121561364957600080fd5b50508035926020909101359150565b634e487b7160e01b600052601160045260246000fd5b808202811582820484141761083f5761083f613658565b8082018082111561083f5761083f613658565b6000602082840312156136aa57600080fd5b5051919050565b60ff828116828216039081111561083f5761083f613658565b6000826136e757634e487b7160e01b600052601260045260246000fd5b500490565b8181038181111561083f5761083f613658565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b600060c0828403121561373d57600080fd5b60405160c0810181811067ffffffffffffffff8211171561376e57634e487b7160e01b600052604160045260246000fd5b6040528235815261378160208401613469565b602082015261379260408401613480565b60408201526137a360608401613480565b60608201526137b46080840161349f565b608082015260a083013560a08201528091505092915050565b6000600182016137df576137df613658565b5060010190565b6000602082840312156137f857600080fd5b8151611e2281613491565b67ffffffffffffffff81811683821602808216919082811461382757613827613658565b505092915050565b634e487b7160e01b600052603160045260246000fd5b60005b83811015613860578181015183820152602001613848565b50506000910152565b7f416363657373436f6e74726f6c3a206163636f756e74200000000000000000008152600083516138a1816017850160208801613845565b7f206973206d697373696e6720726f6c652000000000000000000000000000000060179184019182015283516138de816028840160208801613845565b01602801949350505050565b6020815260008251806020840152613909816040850160208701613845565b601f01601f19169190910160400192915050565b60008161392c5761392c613658565b50600019019056fea2646970667358221220b8e989571a98a41404ede9329461cf1ff50f79df9ca172c5ded6755573d871c364736f6c63430008130033", diff --git a/deployments/testnetlight/PriceOracle.json b/deployments/testnetlight/PriceOracle.json index d5abac3a..3b10344d 100644 --- a/deployments/testnetlight/PriceOracle.json +++ b/deployments/testnetlight/PriceOracle.json @@ -1,5 +1,5 @@ { - "address": "0xcA1E073042438a40A7BC0e558e2B9bd1fe2647F8", + "address": "0x01709567dfF91A387eB2d1Ca60255f80e7633EC2", "abi": [ { "inputs": [ @@ -120,6 +120,19 @@ "name": "RoleRevoked", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "attemptedPrice", + "type": "uint256" + } + ], + "name": "StampPriceUpdateFailed", + "type": "event" + }, { "inputs": [], "name": "DEFAULT_ADMIN_ROLE", @@ -155,7 +168,13 @@ } ], "name": "adjustPrice", - "outputs": [], + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], "stateMutability": "nonpayable", "type": "function" }, @@ -408,7 +427,13 @@ } ], "name": "setPrice", - "outputs": [], + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], "stateMutability": "nonpayable", "type": "function" }, @@ -439,22 +464,22 @@ "type": "function" } ], - "transactionHash": "0xce7fcd6374fa68c11bf50510e1cb557090c9e1a26bb9f5546d206931f33a8b93", + "transactionHash": "0xd61dfa362212d7b1db233fe38d2bcadc9bf99bc858f8cc2c7344ce7fe6d39909", "receipt": { "to": null, "from": "0xb1C7F17Ed88189Abf269Bf68A3B2Ed83C5276aAe", - "contractAddress": "0xcA1E073042438a40A7BC0e558e2B9bd1fe2647F8", - "transactionIndex": 50, - "gasUsed": "1218946", - "logsBloom": "0x00000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000020000000000000000000800000000010000000000000000002000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000001000000000000000000000000000000000000000000000000000000000200100000000000020000000000000000000000000000000000000000000000000000000000000000000", - "blockHash": "0x1185eac5ce7d8477749237fecd9e397e99da2f34bbb66d51fb726bbb3c252a06", - "transactionHash": "0xce7fcd6374fa68c11bf50510e1cb557090c9e1a26bb9f5546d206931f33a8b93", + "contractAddress": "0x01709567dfF91A387eB2d1Ca60255f80e7633EC2", + "transactionIndex": 117, + "gasUsed": "1307783", + "logsBloom": "0x00000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000800000000010000000000000000002000000000040000020000000000000000008000000000000000000000000800000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000002000000000000000000000000100000000000020000000000000000000000000000000000000000000000000000000000000000000", + "blockHash": "0x3cc8492e3385d5fbbf52da7c4879e41ca6a810da2677aded22e38a02e1ca060b", + "transactionHash": "0xd61dfa362212d7b1db233fe38d2bcadc9bf99bc858f8cc2c7344ce7fe6d39909", "logs": [ { - "transactionIndex": 50, - "blockNumber": 5855594, - "transactionHash": "0xce7fcd6374fa68c11bf50510e1cb557090c9e1a26bb9f5546d206931f33a8b93", - "address": "0xcA1E073042438a40A7BC0e558e2B9bd1fe2647F8", + "transactionIndex": 117, + "blockNumber": 6964089, + "transactionHash": "0xd61dfa362212d7b1db233fe38d2bcadc9bf99bc858f8cc2c7344ce7fe6d39909", + "address": "0x01709567dfF91A387eB2d1Ca60255f80e7633EC2", "topics": [ "0x2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d", "0x0000000000000000000000000000000000000000000000000000000000000000", @@ -462,23 +487,35 @@ "0x000000000000000000000000b1c7f17ed88189abf269bf68a3b2ed83c5276aae" ], "data": "0x", - "logIndex": 129, - "blockHash": "0x1185eac5ce7d8477749237fecd9e397e99da2f34bbb66d51fb726bbb3c252a06" + "logIndex": 205, + "blockHash": "0x3cc8492e3385d5fbbf52da7c4879e41ca6a810da2677aded22e38a02e1ca060b" + }, + { + "transactionIndex": 117, + "blockNumber": 6964089, + "transactionHash": "0xd61dfa362212d7b1db233fe38d2bcadc9bf99bc858f8cc2c7344ce7fe6d39909", + "address": "0x01709567dfF91A387eB2d1Ca60255f80e7633EC2", + "topics": [ + "0xae46785019700e30375a5d7b4f91e32f8060ef085111f896ebf889450aa2ab5a" + ], + "data": "0x0000000000000000000000000000000000000000000000000000000000005dc0", + "logIndex": 206, + "blockHash": "0x3cc8492e3385d5fbbf52da7c4879e41ca6a810da2677aded22e38a02e1ca060b" } ], - "blockNumber": 5855594, - "cumulativeGasUsed": "7447939", + "blockNumber": 6964089, + "cumulativeGasUsed": "18491444", "status": 1, "byzantium": true }, "args": [ - "0x38eC2DC60069b28439e4Fca4DF9a91b1d29217cF" + "0x44598B43216eCe3C0eB0dd8e3006d23B40E0554c" ], - "numDeployments": 1, - "solcInputHash": "72863154353a753995d89fd6bb12e809", - "metadata": "{\"compiler\":{\"version\":\"0.8.19+commit.7dd6d404\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_postageStamp\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[],\"name\":\"CallerNotAdmin\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"CallerNotPriceUpdater\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"PriceAlreadyAdjusted\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"UnexpectedZero\",\"type\":\"error\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"price\",\"type\":\"uint256\"}],\"name\":\"PriceUpdate\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"previousAdminRole\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"newAdminRole\",\"type\":\"bytes32\"}],\"name\":\"RoleAdminChanged\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"}],\"name\":\"RoleGranted\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"}],\"name\":\"RoleRevoked\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"DEFAULT_ADMIN_ROLE\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"PRICE_UPDATER_ROLE\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"redundancy\",\"type\":\"uint16\"}],\"name\":\"adjustPrice\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"changeRate\",\"outputs\":[{\"internalType\":\"uint32\",\"name\":\"\",\"type\":\"uint32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentPrice\",\"outputs\":[{\"internalType\":\"uint32\",\"name\":\"\",\"type\":\"uint32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentPriceUpScaled\",\"outputs\":[{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentRound\",\"outputs\":[{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"}],\"name\":\"getRoleAdmin\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"grantRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"hasRole\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"isPaused\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"lastAdjustedRound\",\"outputs\":[{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"minimumPrice\",\"outputs\":[{\"internalType\":\"uint32\",\"name\":\"\",\"type\":\"uint32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"minimumPriceUpscaled\",\"outputs\":[{\"internalType\":\"uint32\",\"name\":\"\",\"type\":\"uint32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"pause\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"postageStamp\",\"outputs\":[{\"internalType\":\"contract IPostageStamp\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"priceBase\",\"outputs\":[{\"internalType\":\"uint32\",\"name\":\"\",\"type\":\"uint32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"renounceRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"revokeRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"_price\",\"type\":\"uint32\"}],\"name\":\"setPrice\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes4\",\"name\":\"interfaceId\",\"type\":\"bytes4\"}],\"name\":\"supportsInterface\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"unPause\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}],\"devdoc\":{\"author\":\"The Swarm Authors.\",\"details\":\"The price oracle contract emits a price feed using events.\",\"events\":{\"PriceUpdate(uint256)\":{\"details\":\"Emitted on every price update.\"},\"RoleAdminChanged(bytes32,bytes32,bytes32)\":{\"details\":\"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._\"},\"RoleGranted(bytes32,address,address)\":{\"details\":\"Emitted when `account` is granted `role`. `sender` is the account that originated the contract call, an admin role bearer except when using {AccessControl-_setupRole}.\"},\"RoleRevoked(bytes32,address,address)\":{\"details\":\"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`)\"}},\"kind\":\"dev\",\"methods\":{\"getRoleAdmin(bytes32)\":{\"details\":\"Returns the admin role that controls `role`. See {grantRole} and {revokeRole}. To change a role's admin, use {_setRoleAdmin}.\"},\"grantRole(bytes32,address)\":{\"details\":\"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.\"},\"hasRole(bytes32,address)\":{\"details\":\"Returns `true` if `account` has been granted `role`.\"},\"renounceRole(bytes32,address)\":{\"details\":\"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.\"},\"revokeRole(bytes32,address)\":{\"details\":\"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.\"},\"setPrice(uint32)\":{\"details\":\"Can only be called by the admin role.\",\"params\":{\"_price\":\"The new price.\"}},\"supportsInterface(bytes4)\":{\"details\":\"See {IERC165-supportsInterface}.\"}},\"title\":\"PriceOracle contract.\",\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{\"currentPrice()\":{\"notice\":\"Return the price downscaled\"},\"currentRound()\":{\"notice\":\"Return the number of the current round.\"},\"minimumPrice()\":{\"notice\":\"Return the price downscaled\"},\"setPrice(uint32)\":{\"notice\":\"Manually set the price.\"}},\"version\":1}},\"settings\":{\"compilationTarget\":{\"src/PriceOracle.sol\":\"PriceOracle\"},\"evmVersion\":\"paris\",\"libraries\":{\":__CACHE_BREAKER__\":\"0x00000000d41867734bbee4c6863d9255b2b06ac1\"},\"metadata\":{\"bytecodeHash\":\"ipfs\",\"useLiteralContent\":true},\"optimizer\":{\"enabled\":true,\"runs\":1000},\"remappings\":[]},\"sources\":{\"@openzeppelin/contracts/access/AccessControl.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (access/AccessControl.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./IAccessControl.sol\\\";\\nimport \\\"../utils/Context.sol\\\";\\nimport \\\"../utils/Strings.sol\\\";\\nimport \\\"../utils/introspection/ERC165.sol\\\";\\n\\n/**\\n * @dev Contract module that allows children to implement role-based access\\n * control mechanisms. This is a lightweight version that doesn't allow enumerating role\\n * members except through off-chain means by accessing the contract event logs. Some\\n * applications may benefit from on-chain enumerability, for those cases see\\n * {AccessControlEnumerable}.\\n *\\n * Roles are referred to by their `bytes32` identifier. These should be exposed\\n * in the external API and be unique. The best way to achieve this is by\\n * using `public constant` hash digests:\\n *\\n * ```\\n * bytes32 public constant MY_ROLE = keccak256(\\\"MY_ROLE\\\");\\n * ```\\n *\\n * Roles can be used to represent a set of permissions. To restrict access to a\\n * function call, use {hasRole}:\\n *\\n * ```\\n * function foo() public {\\n * require(hasRole(MY_ROLE, msg.sender));\\n * ...\\n * }\\n * ```\\n *\\n * Roles can be granted and revoked dynamically via the {grantRole} and\\n * {revokeRole} functions. Each role has an associated admin role, and only\\n * accounts that have a role's admin role can call {grantRole} and {revokeRole}.\\n *\\n * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means\\n * that only accounts with this role will be able to grant or revoke other\\n * roles. More complex role relationships can be created by using\\n * {_setRoleAdmin}.\\n *\\n * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to\\n * grant and revoke this role. Extra precautions should be taken to secure\\n * accounts that have been granted it.\\n */\\nabstract contract AccessControl is Context, IAccessControl, ERC165 {\\n struct RoleData {\\n mapping(address => bool) members;\\n bytes32 adminRole;\\n }\\n\\n mapping(bytes32 => RoleData) private _roles;\\n\\n bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;\\n\\n /**\\n * @dev Modifier that checks that an account has a specific role. Reverts\\n * with a standardized message including the required role.\\n *\\n * The format of the revert reason is given by the following regular expression:\\n *\\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\\n *\\n * _Available since v4.1._\\n */\\n modifier onlyRole(bytes32 role) {\\n _checkRole(role);\\n _;\\n }\\n\\n /**\\n * @dev See {IERC165-supportsInterface}.\\n */\\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);\\n }\\n\\n /**\\n * @dev Returns `true` if `account` has been granted `role`.\\n */\\n function hasRole(bytes32 role, address account) public view virtual override returns (bool) {\\n return _roles[role].members[account];\\n }\\n\\n /**\\n * @dev Revert with a standard message if `_msgSender()` is missing `role`.\\n * Overriding this function changes the behavior of the {onlyRole} modifier.\\n *\\n * Format of the revert message is described in {_checkRole}.\\n *\\n * _Available since v4.6._\\n */\\n function _checkRole(bytes32 role) internal view virtual {\\n _checkRole(role, _msgSender());\\n }\\n\\n /**\\n * @dev Revert with a standard message if `account` is missing `role`.\\n *\\n * The format of the revert reason is given by the following regular expression:\\n *\\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\\n */\\n function _checkRole(bytes32 role, address account) internal view virtual {\\n if (!hasRole(role, account)) {\\n revert(\\n string(\\n abi.encodePacked(\\n \\\"AccessControl: account \\\",\\n Strings.toHexString(account),\\n \\\" is missing role \\\",\\n Strings.toHexString(uint256(role), 32)\\n )\\n )\\n );\\n }\\n }\\n\\n /**\\n * @dev Returns the admin role that controls `role`. See {grantRole} and\\n * {revokeRole}.\\n *\\n * To change a role's admin, use {_setRoleAdmin}.\\n */\\n function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {\\n return _roles[role].adminRole;\\n }\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * If `account` had not been already granted `role`, emits a {RoleGranted}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n *\\n * May emit a {RoleGranted} event.\\n */\\n function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\\n _grantRole(role, account);\\n }\\n\\n /**\\n * @dev Revokes `role` from `account`.\\n *\\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n *\\n * May emit a {RoleRevoked} event.\\n */\\n function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\\n _revokeRole(role, account);\\n }\\n\\n /**\\n * @dev Revokes `role` from the calling account.\\n *\\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\\n * purpose is to provide a mechanism for accounts to lose their privileges\\n * if they are compromised (such as when a trusted device is misplaced).\\n *\\n * If the calling account had been revoked `role`, emits a {RoleRevoked}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must be `account`.\\n *\\n * May emit a {RoleRevoked} event.\\n */\\n function renounceRole(bytes32 role, address account) public virtual override {\\n require(account == _msgSender(), \\\"AccessControl: can only renounce roles for self\\\");\\n\\n _revokeRole(role, account);\\n }\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * If `account` had not been already granted `role`, emits a {RoleGranted}\\n * event. Note that unlike {grantRole}, this function doesn't perform any\\n * checks on the calling account.\\n *\\n * May emit a {RoleGranted} event.\\n *\\n * [WARNING]\\n * ====\\n * This function should only be called from the constructor when setting\\n * up the initial roles for the system.\\n *\\n * Using this function in any other way is effectively circumventing the admin\\n * system imposed by {AccessControl}.\\n * ====\\n *\\n * NOTE: This function is deprecated in favor of {_grantRole}.\\n */\\n function _setupRole(bytes32 role, address account) internal virtual {\\n _grantRole(role, account);\\n }\\n\\n /**\\n * @dev Sets `adminRole` as ``role``'s admin role.\\n *\\n * Emits a {RoleAdminChanged} event.\\n */\\n function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {\\n bytes32 previousAdminRole = getRoleAdmin(role);\\n _roles[role].adminRole = adminRole;\\n emit RoleAdminChanged(role, previousAdminRole, adminRole);\\n }\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * Internal function without access restriction.\\n *\\n * May emit a {RoleGranted} event.\\n */\\n function _grantRole(bytes32 role, address account) internal virtual {\\n if (!hasRole(role, account)) {\\n _roles[role].members[account] = true;\\n emit RoleGranted(role, account, _msgSender());\\n }\\n }\\n\\n /**\\n * @dev Revokes `role` from `account`.\\n *\\n * Internal function without access restriction.\\n *\\n * May emit a {RoleRevoked} event.\\n */\\n function _revokeRole(bytes32 role, address account) internal virtual {\\n if (hasRole(role, account)) {\\n _roles[role].members[account] = false;\\n emit RoleRevoked(role, account, _msgSender());\\n }\\n }\\n}\\n\",\"keccak256\":\"0x67e3daf189111d6d5b0464ed09cf9f0605a22c4b965a7fcecd707101faff008a\",\"license\":\"MIT\"},\"@openzeppelin/contracts/access/IAccessControl.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev External interface of AccessControl declared to support ERC165 detection.\\n */\\ninterface IAccessControl {\\n /**\\n * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`\\n *\\n * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite\\n * {RoleAdminChanged} not being emitted signaling this.\\n *\\n * _Available since v3.1._\\n */\\n event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);\\n\\n /**\\n * @dev Emitted when `account` is granted `role`.\\n *\\n * `sender` is the account that originated the contract call, an admin role\\n * bearer except when using {AccessControl-_setupRole}.\\n */\\n event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);\\n\\n /**\\n * @dev Emitted when `account` is revoked `role`.\\n *\\n * `sender` is the account that originated the contract call:\\n * - if using `revokeRole`, it is the admin role bearer\\n * - if using `renounceRole`, it is the role bearer (i.e. `account`)\\n */\\n event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);\\n\\n /**\\n * @dev Returns `true` if `account` has been granted `role`.\\n */\\n function hasRole(bytes32 role, address account) external view returns (bool);\\n\\n /**\\n * @dev Returns the admin role that controls `role`. See {grantRole} and\\n * {revokeRole}.\\n *\\n * To change a role's admin, use {AccessControl-_setRoleAdmin}.\\n */\\n function getRoleAdmin(bytes32 role) external view returns (bytes32);\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * If `account` had not been already granted `role`, emits a {RoleGranted}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n */\\n function grantRole(bytes32 role, address account) external;\\n\\n /**\\n * @dev Revokes `role` from `account`.\\n *\\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n */\\n function revokeRole(bytes32 role, address account) external;\\n\\n /**\\n * @dev Revokes `role` from the calling account.\\n *\\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\\n * purpose is to provide a mechanism for accounts to lose their privileges\\n * if they are compromised (such as when a trusted device is misplaced).\\n *\\n * If the calling account had been granted `role`, emits a {RoleRevoked}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must be `account`.\\n */\\n function renounceRole(bytes32 role, address account) external;\\n}\\n\",\"keccak256\":\"0x59ce320a585d7e1f163cd70390a0ef2ff9cec832e2aa544293a00692465a7a57\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/Context.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Provides information about the current execution context, including the\\n * sender of the transaction and its data. While these are generally available\\n * via msg.sender and msg.data, they should not be accessed in such a direct\\n * manner, since when dealing with meta-transactions the account sending and\\n * paying for execution may not be the actual sender (as far as an application\\n * is concerned).\\n *\\n * This contract is only required for intermediate, library-like contracts.\\n */\\nabstract contract Context {\\n function _msgSender() internal view virtual returns (address) {\\n return msg.sender;\\n }\\n\\n function _msgData() internal view virtual returns (bytes calldata) {\\n return msg.data;\\n }\\n}\\n\",\"keccak256\":\"0xe2e337e6dde9ef6b680e07338c493ebea1b5fd09b43424112868e9cc1706bca7\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/Strings.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./math/Math.sol\\\";\\n\\n/**\\n * @dev String operations.\\n */\\nlibrary Strings {\\n bytes16 private constant _SYMBOLS = \\\"0123456789abcdef\\\";\\n uint8 private constant _ADDRESS_LENGTH = 20;\\n\\n /**\\n * @dev Converts a `uint256` to its ASCII `string` decimal representation.\\n */\\n function toString(uint256 value) internal pure returns (string memory) {\\n unchecked {\\n uint256 length = Math.log10(value) + 1;\\n string memory buffer = new string(length);\\n uint256 ptr;\\n /// @solidity memory-safe-assembly\\n assembly {\\n ptr := add(buffer, add(32, length))\\n }\\n while (true) {\\n ptr--;\\n /// @solidity memory-safe-assembly\\n assembly {\\n mstore8(ptr, byte(mod(value, 10), _SYMBOLS))\\n }\\n value /= 10;\\n if (value == 0) break;\\n }\\n return buffer;\\n }\\n }\\n\\n /**\\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\\n */\\n function toHexString(uint256 value) internal pure returns (string memory) {\\n unchecked {\\n return toHexString(value, Math.log256(value) + 1);\\n }\\n }\\n\\n /**\\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\\n */\\n function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\\n bytes memory buffer = new bytes(2 * length + 2);\\n buffer[0] = \\\"0\\\";\\n buffer[1] = \\\"x\\\";\\n for (uint256 i = 2 * length + 1; i > 1; --i) {\\n buffer[i] = _SYMBOLS[value & 0xf];\\n value >>= 4;\\n }\\n require(value == 0, \\\"Strings: hex length insufficient\\\");\\n return string(buffer);\\n }\\n\\n /**\\n * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.\\n */\\n function toHexString(address addr) internal pure returns (string memory) {\\n return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);\\n }\\n}\\n\",\"keccak256\":\"0xa4d1d62251f8574deb032a35fc948386a9b4de74b812d4f545a1ac120486b48a\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/introspection/ERC165.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./IERC165.sol\\\";\\n\\n/**\\n * @dev Implementation of the {IERC165} interface.\\n *\\n * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check\\n * for the additional interface id that will be supported. For example:\\n *\\n * ```solidity\\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\\n * }\\n * ```\\n *\\n * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.\\n */\\nabstract contract ERC165 is IERC165 {\\n /**\\n * @dev See {IERC165-supportsInterface}.\\n */\\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n return interfaceId == type(IERC165).interfaceId;\\n }\\n}\\n\",\"keccak256\":\"0xd10975de010d89fd1c78dc5e8a9a7e7f496198085c151648f20cba166b32582b\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/introspection/IERC165.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Interface of the ERC165 standard, as defined in the\\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\\n *\\n * Implementers can declare support of contract interfaces, which can then be\\n * queried by others ({ERC165Checker}).\\n *\\n * For an implementation, see {ERC165}.\\n */\\ninterface IERC165 {\\n /**\\n * @dev Returns true if this contract implements the interface defined by\\n * `interfaceId`. See the corresponding\\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\\n * to learn more about how these ids are created.\\n *\\n * This function call must use less than 30 000 gas.\\n */\\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\\n}\\n\",\"keccak256\":\"0x447a5f3ddc18419d41ff92b3773fb86471b1db25773e07f877f548918a185bf1\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/math/Math.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Standard math utilities missing in the Solidity language.\\n */\\nlibrary Math {\\n enum Rounding {\\n Down, // Toward negative infinity\\n Up, // Toward infinity\\n Zero // Toward zero\\n }\\n\\n /**\\n * @dev Returns the largest of two numbers.\\n */\\n function max(uint256 a, uint256 b) internal pure returns (uint256) {\\n return a > b ? a : b;\\n }\\n\\n /**\\n * @dev Returns the smallest of two numbers.\\n */\\n function min(uint256 a, uint256 b) internal pure returns (uint256) {\\n return a < b ? a : b;\\n }\\n\\n /**\\n * @dev Returns the average of two numbers. The result is rounded towards\\n * zero.\\n */\\n function average(uint256 a, uint256 b) internal pure returns (uint256) {\\n // (a + b) / 2 can overflow.\\n return (a & b) + (a ^ b) / 2;\\n }\\n\\n /**\\n * @dev Returns the ceiling of the division of two numbers.\\n *\\n * This differs from standard division with `/` in that it rounds up instead\\n * of rounding down.\\n */\\n function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {\\n // (a + b - 1) / b can overflow on addition, so we distribute.\\n return a == 0 ? 0 : (a - 1) / b + 1;\\n }\\n\\n /**\\n * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0\\n * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)\\n * with further edits by Uniswap Labs also under MIT license.\\n */\\n function mulDiv(\\n uint256 x,\\n uint256 y,\\n uint256 denominator\\n ) internal pure returns (uint256 result) {\\n unchecked {\\n // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use\\n // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256\\n // variables such that product = prod1 * 2^256 + prod0.\\n uint256 prod0; // Least significant 256 bits of the product\\n uint256 prod1; // Most significant 256 bits of the product\\n assembly {\\n let mm := mulmod(x, y, not(0))\\n prod0 := mul(x, y)\\n prod1 := sub(sub(mm, prod0), lt(mm, prod0))\\n }\\n\\n // Handle non-overflow cases, 256 by 256 division.\\n if (prod1 == 0) {\\n return prod0 / denominator;\\n }\\n\\n // Make sure the result is less than 2^256. Also prevents denominator == 0.\\n require(denominator > prod1);\\n\\n ///////////////////////////////////////////////\\n // 512 by 256 division.\\n ///////////////////////////////////////////////\\n\\n // Make division exact by subtracting the remainder from [prod1 prod0].\\n uint256 remainder;\\n assembly {\\n // Compute remainder using mulmod.\\n remainder := mulmod(x, y, denominator)\\n\\n // Subtract 256 bit number from 512 bit number.\\n prod1 := sub(prod1, gt(remainder, prod0))\\n prod0 := sub(prod0, remainder)\\n }\\n\\n // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.\\n // See https://cs.stackexchange.com/q/138556/92363.\\n\\n // Does not overflow because the denominator cannot be zero at this stage in the function.\\n uint256 twos = denominator & (~denominator + 1);\\n assembly {\\n // Divide denominator by twos.\\n denominator := div(denominator, twos)\\n\\n // Divide [prod1 prod0] by twos.\\n prod0 := div(prod0, twos)\\n\\n // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.\\n twos := add(div(sub(0, twos), twos), 1)\\n }\\n\\n // Shift in bits from prod1 into prod0.\\n prod0 |= prod1 * twos;\\n\\n // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such\\n // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for\\n // four bits. That is, denominator * inv = 1 mod 2^4.\\n uint256 inverse = (3 * denominator) ^ 2;\\n\\n // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works\\n // in modular arithmetic, doubling the correct bits in each step.\\n inverse *= 2 - denominator * inverse; // inverse mod 2^8\\n inverse *= 2 - denominator * inverse; // inverse mod 2^16\\n inverse *= 2 - denominator * inverse; // inverse mod 2^32\\n inverse *= 2 - denominator * inverse; // inverse mod 2^64\\n inverse *= 2 - denominator * inverse; // inverse mod 2^128\\n inverse *= 2 - denominator * inverse; // inverse mod 2^256\\n\\n // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.\\n // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is\\n // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1\\n // is no longer required.\\n result = prod0 * inverse;\\n return result;\\n }\\n }\\n\\n /**\\n * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.\\n */\\n function mulDiv(\\n uint256 x,\\n uint256 y,\\n uint256 denominator,\\n Rounding rounding\\n ) internal pure returns (uint256) {\\n uint256 result = mulDiv(x, y, denominator);\\n if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {\\n result += 1;\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.\\n *\\n * Inspired by Henry S. Warren, Jr.'s \\\"Hacker's Delight\\\" (Chapter 11).\\n */\\n function sqrt(uint256 a) internal pure returns (uint256) {\\n if (a == 0) {\\n return 0;\\n }\\n\\n // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.\\n //\\n // We know that the \\\"msb\\\" (most significant bit) of our target number `a` is a power of 2 such that we have\\n // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.\\n //\\n // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`\\n // \\u2192 `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`\\n // \\u2192 `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`\\n //\\n // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.\\n uint256 result = 1 << (log2(a) >> 1);\\n\\n // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,\\n // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at\\n // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision\\n // into the expected uint128 result.\\n unchecked {\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n return min(result, a / result);\\n }\\n }\\n\\n /**\\n * @notice Calculates sqrt(a), following the selected rounding direction.\\n */\\n function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = sqrt(a);\\n return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);\\n }\\n }\\n\\n /**\\n * @dev Return the log in base 2, rounded down, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log2(uint256 value) internal pure returns (uint256) {\\n uint256 result = 0;\\n unchecked {\\n if (value >> 128 > 0) {\\n value >>= 128;\\n result += 128;\\n }\\n if (value >> 64 > 0) {\\n value >>= 64;\\n result += 64;\\n }\\n if (value >> 32 > 0) {\\n value >>= 32;\\n result += 32;\\n }\\n if (value >> 16 > 0) {\\n value >>= 16;\\n result += 16;\\n }\\n if (value >> 8 > 0) {\\n value >>= 8;\\n result += 8;\\n }\\n if (value >> 4 > 0) {\\n value >>= 4;\\n result += 4;\\n }\\n if (value >> 2 > 0) {\\n value >>= 2;\\n result += 2;\\n }\\n if (value >> 1 > 0) {\\n result += 1;\\n }\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Return the log in base 2, following the selected rounding direction, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = log2(value);\\n return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);\\n }\\n }\\n\\n /**\\n * @dev Return the log in base 10, rounded down, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log10(uint256 value) internal pure returns (uint256) {\\n uint256 result = 0;\\n unchecked {\\n if (value >= 10**64) {\\n value /= 10**64;\\n result += 64;\\n }\\n if (value >= 10**32) {\\n value /= 10**32;\\n result += 32;\\n }\\n if (value >= 10**16) {\\n value /= 10**16;\\n result += 16;\\n }\\n if (value >= 10**8) {\\n value /= 10**8;\\n result += 8;\\n }\\n if (value >= 10**4) {\\n value /= 10**4;\\n result += 4;\\n }\\n if (value >= 10**2) {\\n value /= 10**2;\\n result += 2;\\n }\\n if (value >= 10**1) {\\n result += 1;\\n }\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = log10(value);\\n return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);\\n }\\n }\\n\\n /**\\n * @dev Return the log in base 256, rounded down, of a positive value.\\n * Returns 0 if given 0.\\n *\\n * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.\\n */\\n function log256(uint256 value) internal pure returns (uint256) {\\n uint256 result = 0;\\n unchecked {\\n if (value >> 128 > 0) {\\n value >>= 128;\\n result += 16;\\n }\\n if (value >> 64 > 0) {\\n value >>= 64;\\n result += 8;\\n }\\n if (value >> 32 > 0) {\\n value >>= 32;\\n result += 4;\\n }\\n if (value >> 16 > 0) {\\n value >>= 16;\\n result += 2;\\n }\\n if (value >> 8 > 0) {\\n result += 1;\\n }\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = log256(value);\\n return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);\\n }\\n }\\n}\\n\",\"keccak256\":\"0xa1e8e83cd0087785df04ac79fb395d9f3684caeaf973d9e2c71caef723a3a5d6\",\"license\":\"MIT\"},\"src/PriceOracle.sol\":{\"content\":\"// SPDX-License-Identifier: BSD-3-Clause\\npragma solidity ^0.8.19;\\nimport \\\"@openzeppelin/contracts/access/AccessControl.sol\\\";\\nimport \\\"./interface/IPostageStamp.sol\\\";\\n\\n/**\\n * @title PriceOracle contract.\\n * @author The Swarm Authors.\\n * @dev The price oracle contract emits a price feed using events.\\n */\\n\\ncontract PriceOracle is AccessControl {\\n // ----------------------------- State variables ------------------------------\\n\\n // The address of the linked PostageStamp contract\\n IPostageStamp public postageStamp;\\n\\n uint16 targetRedundancy = 4;\\n uint16 maxConsideredExtraRedundancy = 4;\\n\\n // When the contract is paused, price changes are not effective\\n bool public isPaused = false;\\n\\n // The number of the last round price adjusting happend\\n uint64 public lastAdjustedRound;\\n\\n // The minimum price allowed\\n uint32 public minimumPriceUpscaled = 24000 << 10; // we upscale it by 2^10\\n\\n // The priceBase to modulate the price\\n uint32 public priceBase = 524288;\\n\\n uint64 public currentPriceUpScaled = minimumPriceUpscaled;\\n\\n // Constants used to modulate the price, see below usage\\n uint32[9] public changeRate = [524324, 524315, 524306, 524297, 524288, 524279, 524270, 524261, 524252];\\n\\n // Role allowed to update price\\n bytes32 public immutable PRICE_UPDATER_ROLE;\\n\\n // The length of a round in blocks.\\n uint8 private constant ROUND_LENGTH = 152;\\n\\n // ----------------------------- Events ------------------------------\\n\\n /**\\n *@dev Emitted on every price update.\\n */\\n event PriceUpdate(uint256 price);\\n\\n // ----------------------------- Custom Errors ------------------------------\\n error CallerNotAdmin(); // Caller is not the admin\\n error CallerNotPriceUpdater(); // Caller is not a price updater\\n error PriceAlreadyAdjusted(); // Price already adjusted in this round\\n error UnexpectedZero(); // Redundancy needs to be higher then 0\\n\\n // ----------------------------- CONSTRUCTOR ------------------------------\\n\\n constructor(address _postageStamp) {\\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\\n postageStamp = IPostageStamp(_postageStamp);\\n lastAdjustedRound = currentRound();\\n PRICE_UPDATER_ROLE = keccak256(\\\"PRICE_UPDATER_ROLE\\\");\\n }\\n\\n ////////////////////////////////////////\\n // STATE SETTING //\\n ////////////////////////////////////////\\n\\n /**\\n * @notice Manually set the price.\\n * @dev Can only be called by the admin role.\\n * @param _price The new price.\\n */ function setPrice(uint32 _price) external {\\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\\n revert CallerNotAdmin();\\n }\\n\\n uint64 _currentPriceUpScaled = _price << 10;\\n uint64 _minimumPriceUpscaled = minimumPriceUpscaled;\\n\\n // Enforce minimum price\\n if (_currentPriceUpScaled < _minimumPriceUpscaled) {\\n _currentPriceUpScaled = _minimumPriceUpscaled;\\n }\\n currentPriceUpScaled = _currentPriceUpScaled;\\n\\n // Price in postagestamp is set at 256 so we need to upcast it\\n postageStamp.setPrice(uint256(currentPrice()));\\n emit PriceUpdate(currentPrice());\\n }\\n\\n function adjustPrice(uint16 redundancy) external {\\n if (isPaused == false) {\\n if (!hasRole(PRICE_UPDATER_ROLE, msg.sender)) {\\n revert CallerNotPriceUpdater();\\n }\\n\\n uint16 usedRedundancy = redundancy;\\n uint64 currentRoundNumber = currentRound();\\n\\n // Price can only be adjusted once per round\\n if (currentRoundNumber <= lastAdjustedRound) {\\n revert PriceAlreadyAdjusted();\\n }\\n // Redundancy may not be zero\\n if (redundancy == 0) {\\n revert UnexpectedZero();\\n }\\n\\n // Enforce maximum considered extra redundancy\\n uint16 maxConsideredRedundancy = targetRedundancy + maxConsideredExtraRedundancy;\\n if (redundancy > maxConsideredRedundancy) {\\n usedRedundancy = maxConsideredRedundancy;\\n }\\n\\n uint64 _currentPriceUpScaled = currentPriceUpScaled;\\n uint64 _minimumPriceUpscaled = minimumPriceUpscaled;\\n uint32 _priceBase = priceBase;\\n\\n // Set the number of rounds that were skipped\\n uint64 skippedRounds = currentRoundNumber - lastAdjustedRound - 1;\\n\\n // We first apply the increase/decrease rate for the current round\\n uint32 _changeRate = changeRate[usedRedundancy];\\n _currentPriceUpScaled = (_changeRate * _currentPriceUpScaled) / _priceBase;\\n\\n // If previous rounds were skipped, use MAX price increase for the previous rounds\\n if (skippedRounds > 0) {\\n _changeRate = changeRate[0];\\n for (uint64 i = 0; i < skippedRounds; i++) {\\n _currentPriceUpScaled = (_changeRate * _currentPriceUpScaled) / _priceBase;\\n }\\n }\\n\\n // Enforce minimum price\\n if (_currentPriceUpScaled < _minimumPriceUpscaled) {\\n _currentPriceUpScaled = _minimumPriceUpscaled;\\n }\\n\\n currentPriceUpScaled = _currentPriceUpScaled;\\n lastAdjustedRound = currentRoundNumber;\\n postageStamp.setPrice(uint256(currentPrice()));\\n emit PriceUpdate(currentPrice());\\n }\\n }\\n\\n function pause() external {\\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\\n revert CallerNotAdmin();\\n }\\n isPaused = true;\\n }\\n\\n function unPause() external {\\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\\n revert CallerNotAdmin();\\n }\\n isPaused = false;\\n }\\n\\n ////////////////////////////////////////\\n // STATE READING //\\n ////////////////////////////////////////\\n\\n /**\\n * @notice Return the number of the current round.\\n */\\n function currentRound() public view returns (uint64) {\\n // We downcasted to uint64 as uint64 has 18,446,744,073,709,551,616 places\\n // as each round is 152 x 5 = 760, each day has around 113 rounds which is 41245 in a year\\n // it results 4.4724801e+14 years to run this game\\n return uint64(block.number / uint256(ROUND_LENGTH));\\n }\\n\\n /**\\n * @notice Return the price downscaled\\n */\\n function currentPrice() public view returns (uint32) {\\n // We downcasted to uint32 and bitshift it by 2^10\\n return uint32((currentPriceUpScaled) >> 10);\\n }\\n\\n /**\\n * @notice Return the price downscaled\\n */\\n function minimumPrice() public view returns (uint32) {\\n // We downcasted to uint32 and bitshift it by 2^10\\n return uint32((minimumPriceUpscaled) >> 10);\\n }\\n}\\n\",\"keccak256\":\"0x46220a921dcbac1f300a12aa0c441bbebf340485e9bbd9514163ac600fc1d64d\",\"license\":\"BSD-3-Clause\"},\"src/interface/IPostageStamp.sol\":{\"content\":\"// SPDX-License-Identifier: BSD-3-Clause\\npragma solidity ^0.8.19;\\n\\ninterface IPostageStamp {\\n function withdraw(address beneficiary) external;\\n\\n function validChunkCount() external view returns (uint256);\\n\\n function batchOwner(bytes32 _batchId) external view returns (address);\\n\\n function batchDepth(bytes32 _batchId) external view returns (uint8);\\n\\n function batchBucketDepth(bytes32 _batchId) external view returns (uint8);\\n\\n function remainingBalance(bytes32 _batchId) external view returns (uint256);\\n\\n function minimumInitialBalancePerChunk() external view returns (uint256);\\n\\n function setPrice(uint256 _price) external;\\n\\n function batches(\\n bytes32\\n )\\n external\\n view\\n returns (\\n address owner,\\n uint8 depth,\\n uint8 bucketDepth,\\n bool immutableFlag,\\n uint256 normalisedBalance,\\n uint256 lastUpdatedBlockNumber\\n );\\n}\\n\",\"keccak256\":\"0xc018ff96e75e773e76e6245a930acc3679667250e345415a38196f1e2ad1de76\",\"license\":\"BSD-3-Clause\"}},\"version\":1}", - "bytecode": "0x600180546201000160a21b64ffffffffff60a01b1990911617905560028054600160401b600160c01b0319811663ffffffff68010000000000000000600160401b600160801b03199093166e0800000177000000000000000000009081179390930416600160801b02171790556101c06040526208002460a09081526208001b60c0526208001260e052620800096101005262080000610120526207fff7610140526207ffee610160526207ffe5610180526207ffdc6101a052620000c99060039060096200023b565b50348015620000d757600080fd5b506040516200163438038062001634833981016040819052620000fa91620002f4565b6200010760003362000177565b600180546001600160a01b0319166001600160a01b0383161790556200012c62000187565b600280546001600160401b0319166001600160401b0392909216919091179055507fd96ba01d6560c2ab35f2940dd8d70c5f5fe06236c72674237120515918198fb060805262000349565b6200018382826200019b565b5050565b60006200019660984362000326565b905090565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1662000183576000828152602081815260408083206001600160a01b03851684529091529020805460ff19166001179055620001f73390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b600283019183908215620002cb5791602002820160005b838211156200029757835183826101000a81548163ffffffff021916908362ffffff160217905550926020019260040160208160030104928301926001030262000252565b8015620002c95782816101000a81549063ffffffff021916905560040160208160030104928301926001030262000297565b505b50620002d9929150620002dd565b5090565b5b80821115620002d95760008155600101620002de565b6000602082840312156200030757600080fd5b81516001600160a01b03811681146200031f57600080fd5b9392505050565b6000826200034457634e487b7160e01b600052601260045260246000fd5b500490565b6080516112c86200036c600039600081816103ac015261080d01526112c86000f3fe608060405234801561001057600080fd5b50600436106101825760003560e01c806391d14854116100d8578063daafe0a51161008c578063f7b188a511610066578063f7b188a51461039f578063fb8d8101146103a7578063ffb98fe3146103ce57600080fd5b8063daafe0a514610346578063dcd8ffb814610359578063e0632c641461037457600080fd5b8063a217fddf116100bd578063a217fddf14610317578063b187bd261461031f578063d547741f1461033357600080fd5b806391d14854146102c55780639d1b464a146102fc57600080fd5b80637310561b1161013a5780637f386b6c116101145780637f386b6c146102995780638456cb59146102b55780638a19c8bc146102bd57600080fd5b80637310561b1461023557806374e7493b1461026a5780637e8effdd1461027d57600080fd5b80632f2ff15d1161016b5780632f2ff15d146101e057806336568abe146101f557806355bdcd231461020857600080fd5b806301ffc9a714610187578063248a9ca3146101af575b600080fd5b61019a610195366004610f6f565b6103e1565b60405190151581526020015b60405180910390f35b6101d26101bd366004610fb1565b60009081526020819052604090206001015490565b6040519081526020016101a6565b6101f36101ee366004610fca565b61047a565b005b6101f3610203366004610fca565b6104a4565b60025461021c9067ffffffffffffffff1681565b60405167ffffffffffffffff90911681526020016101a6565b600254610255906c01000000000000000000000000900463ffffffff1681565b60405163ffffffff90911681526020016101a6565b610255610278366004610fb1565b610535565b6002546102559068010000000000000000900463ffffffff1681565b600254680100000000000000009004600a1c623fffff16610255565b6101f3610565565b61021c6105c9565b61019a6102d3366004610fca565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b600254600160801b9004600a1c663fffffffffffff16610255565b6101d2600081565b60015461019a90600160c01b900460ff1681565b6101f3610341366004610fca565b6105db565b6101f3610354366004611006565b610600565b60025461021c90600160801b900467ffffffffffffffff1681565b600154610387906001600160a01b031681565b6040516001600160a01b0390911681526020016101a6565b6101f3610797565b6101d27f000000000000000000000000000000000000000000000000000000000000000081565b6101f36103dc36600461102c565b6107f5565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f7965db0b00000000000000000000000000000000000000000000000000000000148061047457507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008316145b92915050565b60008281526020819052604090206001015461049581610bdb565b61049f8383610be5565b505050565b6001600160a01b03811633146105275760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b6105318282610c83565b5050565b6003816009811061054557600080fd5b60089182820401919006600402915054906101000a900463ffffffff1681565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff166105b45760405163036c8cf960e11b815260040160405180910390fd5b6001805460ff60c01b1916600160c01b179055565b60006105d660984361107c565b905090565b6000828152602081905260409020600101546105f681610bdb565b61049f8383610c83565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff1661064f5760405163036c8cf960e11b815260040160405180910390fd5b60025463fffffc00600a83901b169068010000000000000000900463ffffffff168082101561067c578091505b6002805467ffffffffffffffff8416600160801b027fffffffffffffffff0000000000000000ffffffffffffffffffffffffffffffff9091161790556001546001600160a01b03166391b7f5ed6106e6600254663fffffffffffff600160801b909104600a1c1690565b63ffffffff166040518263ffffffff1660e01b815260040161070a91815260200190565b600060405180830381600087803b15801561072457600080fd5b505af1158015610738573d6000803e3d6000fd5b505050507fae46785019700e30375a5d7b4f91e32f8060ef085111f896ebf889450aa2ab5a61077a600254663fffffffffffff600160801b909104600a1c1690565b60405163ffffffff909116815260200160405180910390a1505050565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff166107e65760405163036c8cf960e11b815260040160405180910390fd5b6001805460ff60c01b19169055565b600154600160c01b900460ff161515600003610bd8577f000000000000000000000000000000000000000000000000000000000000000060009081526020818152604080832033845290915290205460ff1661087d576040517f262791ec00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8060006108886105c9565b60025490915067ffffffffffffffff908116908216116108d4576040517f08a5cb4c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8261ffff16600003610912576040517fb5ca2d7100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60015460009061095a9061ffff760100000000000000000000000000000000000000000000820481169174010000000000000000000000000000000000000000900416611090565b90508061ffff168461ffff161115610970578092505b60025467ffffffffffffffff600160801b820481169163ffffffff6801000000000000000082048116926c010000000000000000000000008304909116916000916001916109bf9116886110b2565b6109c991906110b2565b9050600060038861ffff16600981106109e4576109e46110d3565b60088104919091015460079091166004026101000a900463ffffffff90811691508316610a1186836110e9565b610a1b9190611115565b945067ffffffffffffffff821615610a8f575060035463ffffffff1660005b8267ffffffffffffffff168167ffffffffffffffff161015610a8d578363ffffffff16868363ffffffff16610a6f91906110e9565b610a799190611115565b955080610a858161113c565b915050610a3a565b505b8367ffffffffffffffff168567ffffffffffffffff161015610aaf578394505b600280547fffffffffffffffff0000000000000000ffffffffffffffff000000000000000016600160801b67ffffffffffffffff888116820267ffffffffffffffff191692909217918a1691909117918290556001546001600160a01b0316916391b7f5ed919004600a1c663fffffffffffff1663ffffffff166040518263ffffffff1660e01b8152600401610b4791815260200190565b600060405180830381600087803b158015610b6157600080fd5b505af1158015610b75573d6000803e3d6000fd5b505050507fae46785019700e30375a5d7b4f91e32f8060ef085111f896ebf889450aa2ab5a610bb7600254663fffffffffffff600160801b909104600a1c1690565b60405163ffffffff909116815260200160405180910390a150505050505050505b50565b610bd88133610d02565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610531576000828152602081815260408083206001600160a01b03851684529091529020805460ff19166001179055610c3f3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1615610531576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1661053157610d3381610d75565b610d3e836020610d87565b604051602001610d4f929190611187565b60408051601f198184030181529082905262461bcd60e51b825261051e91600401611208565b60606104746001600160a01b03831660145b60606000610d9683600261123b565b610da1906002611252565b67ffffffffffffffff811115610db957610db9611265565b6040519080825280601f01601f191660200182016040528015610de3576020820181803683370190505b5090507f300000000000000000000000000000000000000000000000000000000000000081600081518110610e1a57610e1a6110d3565b60200101906001600160f81b031916908160001a9053507f780000000000000000000000000000000000000000000000000000000000000081600181518110610e6557610e656110d3565b60200101906001600160f81b031916908160001a9053506000610e8984600261123b565b610e94906001611252565b90505b6001811115610f19577f303132333435363738396162636465660000000000000000000000000000000085600f1660108110610ed557610ed56110d3565b1a60f81b828281518110610eeb57610eeb6110d3565b60200101906001600160f81b031916908160001a90535060049490941c93610f128161127b565b9050610e97565b508315610f685760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e74604482015260640161051e565b9392505050565b600060208284031215610f8157600080fd5b81357fffffffff0000000000000000000000000000000000000000000000000000000081168114610f6857600080fd5b600060208284031215610fc357600080fd5b5035919050565b60008060408385031215610fdd57600080fd5b8235915060208301356001600160a01b0381168114610ffb57600080fd5b809150509250929050565b60006020828403121561101857600080fd5b813563ffffffff81168114610f6857600080fd5b60006020828403121561103e57600080fd5b813561ffff81168114610f6857600080fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b60008261108b5761108b611050565b500490565b61ffff8181168382160190808211156110ab576110ab611066565b5092915050565b67ffffffffffffffff8281168282160390808211156110ab576110ab611066565b634e487b7160e01b600052603260045260246000fd5b67ffffffffffffffff81811683821602808216919082811461110d5761110d611066565b505092915050565b600067ffffffffffffffff8084168061113057611130611050565b92169190910492915050565b600067ffffffffffffffff80831681810361115957611159611066565b6001019392505050565b60005b8381101561117e578181015183820152602001611166565b50506000910152565b7f416363657373436f6e74726f6c3a206163636f756e74200000000000000000008152600083516111bf816017850160208801611163565b7f206973206d697373696e6720726f6c652000000000000000000000000000000060179184019182015283516111fc816028840160208801611163565b01602801949350505050565b6020815260008251806020840152611227816040850160208701611163565b601f01601f19169190910160400192915050565b808202811582820484141761047457610474611066565b8082018082111561047457610474611066565b634e487b7160e01b600052604160045260246000fd5b60008161128a5761128a611066565b50600019019056fea2646970667358221220ae138e65b6afda072afc2642ba44cd4f0dba23acc91686a94131453ad482fce464736f6c63430008130033", - "deployedBytecode": "0x608060405234801561001057600080fd5b50600436106101825760003560e01c806391d14854116100d8578063daafe0a51161008c578063f7b188a511610066578063f7b188a51461039f578063fb8d8101146103a7578063ffb98fe3146103ce57600080fd5b8063daafe0a514610346578063dcd8ffb814610359578063e0632c641461037457600080fd5b8063a217fddf116100bd578063a217fddf14610317578063b187bd261461031f578063d547741f1461033357600080fd5b806391d14854146102c55780639d1b464a146102fc57600080fd5b80637310561b1161013a5780637f386b6c116101145780637f386b6c146102995780638456cb59146102b55780638a19c8bc146102bd57600080fd5b80637310561b1461023557806374e7493b1461026a5780637e8effdd1461027d57600080fd5b80632f2ff15d1161016b5780632f2ff15d146101e057806336568abe146101f557806355bdcd231461020857600080fd5b806301ffc9a714610187578063248a9ca3146101af575b600080fd5b61019a610195366004610f6f565b6103e1565b60405190151581526020015b60405180910390f35b6101d26101bd366004610fb1565b60009081526020819052604090206001015490565b6040519081526020016101a6565b6101f36101ee366004610fca565b61047a565b005b6101f3610203366004610fca565b6104a4565b60025461021c9067ffffffffffffffff1681565b60405167ffffffffffffffff90911681526020016101a6565b600254610255906c01000000000000000000000000900463ffffffff1681565b60405163ffffffff90911681526020016101a6565b610255610278366004610fb1565b610535565b6002546102559068010000000000000000900463ffffffff1681565b600254680100000000000000009004600a1c623fffff16610255565b6101f3610565565b61021c6105c9565b61019a6102d3366004610fca565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b600254600160801b9004600a1c663fffffffffffff16610255565b6101d2600081565b60015461019a90600160c01b900460ff1681565b6101f3610341366004610fca565b6105db565b6101f3610354366004611006565b610600565b60025461021c90600160801b900467ffffffffffffffff1681565b600154610387906001600160a01b031681565b6040516001600160a01b0390911681526020016101a6565b6101f3610797565b6101d27f000000000000000000000000000000000000000000000000000000000000000081565b6101f36103dc36600461102c565b6107f5565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f7965db0b00000000000000000000000000000000000000000000000000000000148061047457507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008316145b92915050565b60008281526020819052604090206001015461049581610bdb565b61049f8383610be5565b505050565b6001600160a01b03811633146105275760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b6105318282610c83565b5050565b6003816009811061054557600080fd5b60089182820401919006600402915054906101000a900463ffffffff1681565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff166105b45760405163036c8cf960e11b815260040160405180910390fd5b6001805460ff60c01b1916600160c01b179055565b60006105d660984361107c565b905090565b6000828152602081905260409020600101546105f681610bdb565b61049f8383610c83565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff1661064f5760405163036c8cf960e11b815260040160405180910390fd5b60025463fffffc00600a83901b169068010000000000000000900463ffffffff168082101561067c578091505b6002805467ffffffffffffffff8416600160801b027fffffffffffffffff0000000000000000ffffffffffffffffffffffffffffffff9091161790556001546001600160a01b03166391b7f5ed6106e6600254663fffffffffffff600160801b909104600a1c1690565b63ffffffff166040518263ffffffff1660e01b815260040161070a91815260200190565b600060405180830381600087803b15801561072457600080fd5b505af1158015610738573d6000803e3d6000fd5b505050507fae46785019700e30375a5d7b4f91e32f8060ef085111f896ebf889450aa2ab5a61077a600254663fffffffffffff600160801b909104600a1c1690565b60405163ffffffff909116815260200160405180910390a1505050565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff166107e65760405163036c8cf960e11b815260040160405180910390fd5b6001805460ff60c01b19169055565b600154600160c01b900460ff161515600003610bd8577f000000000000000000000000000000000000000000000000000000000000000060009081526020818152604080832033845290915290205460ff1661087d576040517f262791ec00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8060006108886105c9565b60025490915067ffffffffffffffff908116908216116108d4576040517f08a5cb4c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8261ffff16600003610912576040517fb5ca2d7100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60015460009061095a9061ffff760100000000000000000000000000000000000000000000820481169174010000000000000000000000000000000000000000900416611090565b90508061ffff168461ffff161115610970578092505b60025467ffffffffffffffff600160801b820481169163ffffffff6801000000000000000082048116926c010000000000000000000000008304909116916000916001916109bf9116886110b2565b6109c991906110b2565b9050600060038861ffff16600981106109e4576109e46110d3565b60088104919091015460079091166004026101000a900463ffffffff90811691508316610a1186836110e9565b610a1b9190611115565b945067ffffffffffffffff821615610a8f575060035463ffffffff1660005b8267ffffffffffffffff168167ffffffffffffffff161015610a8d578363ffffffff16868363ffffffff16610a6f91906110e9565b610a799190611115565b955080610a858161113c565b915050610a3a565b505b8367ffffffffffffffff168567ffffffffffffffff161015610aaf578394505b600280547fffffffffffffffff0000000000000000ffffffffffffffff000000000000000016600160801b67ffffffffffffffff888116820267ffffffffffffffff191692909217918a1691909117918290556001546001600160a01b0316916391b7f5ed919004600a1c663fffffffffffff1663ffffffff166040518263ffffffff1660e01b8152600401610b4791815260200190565b600060405180830381600087803b158015610b6157600080fd5b505af1158015610b75573d6000803e3d6000fd5b505050507fae46785019700e30375a5d7b4f91e32f8060ef085111f896ebf889450aa2ab5a610bb7600254663fffffffffffff600160801b909104600a1c1690565b60405163ffffffff909116815260200160405180910390a150505050505050505b50565b610bd88133610d02565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610531576000828152602081815260408083206001600160a01b03851684529091529020805460ff19166001179055610c3f3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1615610531576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1661053157610d3381610d75565b610d3e836020610d87565b604051602001610d4f929190611187565b60408051601f198184030181529082905262461bcd60e51b825261051e91600401611208565b60606104746001600160a01b03831660145b60606000610d9683600261123b565b610da1906002611252565b67ffffffffffffffff811115610db957610db9611265565b6040519080825280601f01601f191660200182016040528015610de3576020820181803683370190505b5090507f300000000000000000000000000000000000000000000000000000000000000081600081518110610e1a57610e1a6110d3565b60200101906001600160f81b031916908160001a9053507f780000000000000000000000000000000000000000000000000000000000000081600181518110610e6557610e656110d3565b60200101906001600160f81b031916908160001a9053506000610e8984600261123b565b610e94906001611252565b90505b6001811115610f19577f303132333435363738396162636465660000000000000000000000000000000085600f1660108110610ed557610ed56110d3565b1a60f81b828281518110610eeb57610eeb6110d3565b60200101906001600160f81b031916908160001a90535060049490941c93610f128161127b565b9050610e97565b508315610f685760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e74604482015260640161051e565b9392505050565b600060208284031215610f8157600080fd5b81357fffffffff0000000000000000000000000000000000000000000000000000000081168114610f6857600080fd5b600060208284031215610fc357600080fd5b5035919050565b60008060408385031215610fdd57600080fd5b8235915060208301356001600160a01b0381168114610ffb57600080fd5b809150509250929050565b60006020828403121561101857600080fd5b813563ffffffff81168114610f6857600080fd5b60006020828403121561103e57600080fd5b813561ffff81168114610f6857600080fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b60008261108b5761108b611050565b500490565b61ffff8181168382160190808211156110ab576110ab611066565b5092915050565b67ffffffffffffffff8281168282160390808211156110ab576110ab611066565b634e487b7160e01b600052603260045260246000fd5b67ffffffffffffffff81811683821602808216919082811461110d5761110d611066565b505092915050565b600067ffffffffffffffff8084168061113057611130611050565b92169190910492915050565b600067ffffffffffffffff80831681810361115957611159611066565b6001019392505050565b60005b8381101561117e578181015183820152602001611166565b50506000910152565b7f416363657373436f6e74726f6c3a206163636f756e74200000000000000000008152600083516111bf816017850160208801611163565b7f206973206d697373696e6720726f6c652000000000000000000000000000000060179184019182015283516111fc816028840160208801611163565b01602801949350505050565b6020815260008251806020840152611227816040850160208701611163565b601f01601f19169190910160400192915050565b808202811582820484141761047457610474611066565b8082018082111561047457610474611066565b634e487b7160e01b600052604160045260246000fd5b60008161128a5761128a611066565b50600019019056fea2646970667358221220ae138e65b6afda072afc2642ba44cd4f0dba23acc91686a94131453ad482fce464736f6c63430008130033", + "numDeployments": 3, + "solcInputHash": "99c9ef5f7ef53ea99ef6c816b26b1e5c", + "metadata": "{\"compiler\":{\"version\":\"0.8.19+commit.7dd6d404\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_postageStamp\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[],\"name\":\"CallerNotAdmin\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"CallerNotPriceUpdater\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"PriceAlreadyAdjusted\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"UnexpectedZero\",\"type\":\"error\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"price\",\"type\":\"uint256\"}],\"name\":\"PriceUpdate\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"previousAdminRole\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"newAdminRole\",\"type\":\"bytes32\"}],\"name\":\"RoleAdminChanged\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"}],\"name\":\"RoleGranted\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"}],\"name\":\"RoleRevoked\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"attemptedPrice\",\"type\":\"uint256\"}],\"name\":\"StampPriceUpdateFailed\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"DEFAULT_ADMIN_ROLE\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"PRICE_UPDATER_ROLE\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"redundancy\",\"type\":\"uint16\"}],\"name\":\"adjustPrice\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"changeRate\",\"outputs\":[{\"internalType\":\"uint32\",\"name\":\"\",\"type\":\"uint32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentPrice\",\"outputs\":[{\"internalType\":\"uint32\",\"name\":\"\",\"type\":\"uint32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentPriceUpScaled\",\"outputs\":[{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentRound\",\"outputs\":[{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"}],\"name\":\"getRoleAdmin\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"grantRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"hasRole\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"isPaused\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"lastAdjustedRound\",\"outputs\":[{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"minimumPrice\",\"outputs\":[{\"internalType\":\"uint32\",\"name\":\"\",\"type\":\"uint32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"minimumPriceUpscaled\",\"outputs\":[{\"internalType\":\"uint32\",\"name\":\"\",\"type\":\"uint32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"pause\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"postageStamp\",\"outputs\":[{\"internalType\":\"contract IPostageStamp\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"priceBase\",\"outputs\":[{\"internalType\":\"uint32\",\"name\":\"\",\"type\":\"uint32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"renounceRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"revokeRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"_price\",\"type\":\"uint32\"}],\"name\":\"setPrice\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes4\",\"name\":\"interfaceId\",\"type\":\"bytes4\"}],\"name\":\"supportsInterface\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"unPause\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}],\"devdoc\":{\"author\":\"The Swarm Authors.\",\"details\":\"The price oracle contract emits a price feed using events.\",\"events\":{\"PriceUpdate(uint256)\":{\"details\":\"Emitted on every price update.\"},\"RoleAdminChanged(bytes32,bytes32,bytes32)\":{\"details\":\"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._\"},\"RoleGranted(bytes32,address,address)\":{\"details\":\"Emitted when `account` is granted `role`. `sender` is the account that originated the contract call, an admin role bearer except when using {AccessControl-_setupRole}.\"},\"RoleRevoked(bytes32,address,address)\":{\"details\":\"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`)\"}},\"kind\":\"dev\",\"methods\":{\"getRoleAdmin(bytes32)\":{\"details\":\"Returns the admin role that controls `role`. See {grantRole} and {revokeRole}. To change a role's admin, use {_setRoleAdmin}.\"},\"grantRole(bytes32,address)\":{\"details\":\"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.\"},\"hasRole(bytes32,address)\":{\"details\":\"Returns `true` if `account` has been granted `role`.\"},\"renounceRole(bytes32,address)\":{\"details\":\"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.\"},\"revokeRole(bytes32,address)\":{\"details\":\"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.\"},\"setPrice(uint32)\":{\"details\":\"Can only be called by the admin role.\",\"params\":{\"_price\":\"The new price.\"}},\"supportsInterface(bytes4)\":{\"details\":\"See {IERC165-supportsInterface}.\"}},\"title\":\"PriceOracle contract.\",\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{\"currentPrice()\":{\"notice\":\"Return the price downscaled\"},\"currentRound()\":{\"notice\":\"Return the number of the current round.\"},\"minimumPrice()\":{\"notice\":\"Return the price downscaled\"},\"setPrice(uint32)\":{\"notice\":\"Manually set the price.\"}},\"version\":1}},\"settings\":{\"compilationTarget\":{\"src/PriceOracle.sol\":\"PriceOracle\"},\"evmVersion\":\"paris\",\"libraries\":{\":__CACHE_BREAKER__\":\"0x00000000d41867734bbee4c6863d9255b2b06ac1\"},\"metadata\":{\"bytecodeHash\":\"ipfs\",\"useLiteralContent\":true},\"optimizer\":{\"enabled\":true,\"runs\":1000},\"remappings\":[]},\"sources\":{\"@openzeppelin/contracts/access/AccessControl.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (access/AccessControl.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./IAccessControl.sol\\\";\\nimport \\\"../utils/Context.sol\\\";\\nimport \\\"../utils/Strings.sol\\\";\\nimport \\\"../utils/introspection/ERC165.sol\\\";\\n\\n/**\\n * @dev Contract module that allows children to implement role-based access\\n * control mechanisms. This is a lightweight version that doesn't allow enumerating role\\n * members except through off-chain means by accessing the contract event logs. Some\\n * applications may benefit from on-chain enumerability, for those cases see\\n * {AccessControlEnumerable}.\\n *\\n * Roles are referred to by their `bytes32` identifier. These should be exposed\\n * in the external API and be unique. The best way to achieve this is by\\n * using `public constant` hash digests:\\n *\\n * ```\\n * bytes32 public constant MY_ROLE = keccak256(\\\"MY_ROLE\\\");\\n * ```\\n *\\n * Roles can be used to represent a set of permissions. To restrict access to a\\n * function call, use {hasRole}:\\n *\\n * ```\\n * function foo() public {\\n * require(hasRole(MY_ROLE, msg.sender));\\n * ...\\n * }\\n * ```\\n *\\n * Roles can be granted and revoked dynamically via the {grantRole} and\\n * {revokeRole} functions. Each role has an associated admin role, and only\\n * accounts that have a role's admin role can call {grantRole} and {revokeRole}.\\n *\\n * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means\\n * that only accounts with this role will be able to grant or revoke other\\n * roles. More complex role relationships can be created by using\\n * {_setRoleAdmin}.\\n *\\n * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to\\n * grant and revoke this role. Extra precautions should be taken to secure\\n * accounts that have been granted it.\\n */\\nabstract contract AccessControl is Context, IAccessControl, ERC165 {\\n struct RoleData {\\n mapping(address => bool) members;\\n bytes32 adminRole;\\n }\\n\\n mapping(bytes32 => RoleData) private _roles;\\n\\n bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;\\n\\n /**\\n * @dev Modifier that checks that an account has a specific role. Reverts\\n * with a standardized message including the required role.\\n *\\n * The format of the revert reason is given by the following regular expression:\\n *\\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\\n *\\n * _Available since v4.1._\\n */\\n modifier onlyRole(bytes32 role) {\\n _checkRole(role);\\n _;\\n }\\n\\n /**\\n * @dev See {IERC165-supportsInterface}.\\n */\\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);\\n }\\n\\n /**\\n * @dev Returns `true` if `account` has been granted `role`.\\n */\\n function hasRole(bytes32 role, address account) public view virtual override returns (bool) {\\n return _roles[role].members[account];\\n }\\n\\n /**\\n * @dev Revert with a standard message if `_msgSender()` is missing `role`.\\n * Overriding this function changes the behavior of the {onlyRole} modifier.\\n *\\n * Format of the revert message is described in {_checkRole}.\\n *\\n * _Available since v4.6._\\n */\\n function _checkRole(bytes32 role) internal view virtual {\\n _checkRole(role, _msgSender());\\n }\\n\\n /**\\n * @dev Revert with a standard message if `account` is missing `role`.\\n *\\n * The format of the revert reason is given by the following regular expression:\\n *\\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\\n */\\n function _checkRole(bytes32 role, address account) internal view virtual {\\n if (!hasRole(role, account)) {\\n revert(\\n string(\\n abi.encodePacked(\\n \\\"AccessControl: account \\\",\\n Strings.toHexString(account),\\n \\\" is missing role \\\",\\n Strings.toHexString(uint256(role), 32)\\n )\\n )\\n );\\n }\\n }\\n\\n /**\\n * @dev Returns the admin role that controls `role`. See {grantRole} and\\n * {revokeRole}.\\n *\\n * To change a role's admin, use {_setRoleAdmin}.\\n */\\n function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {\\n return _roles[role].adminRole;\\n }\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * If `account` had not been already granted `role`, emits a {RoleGranted}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n *\\n * May emit a {RoleGranted} event.\\n */\\n function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\\n _grantRole(role, account);\\n }\\n\\n /**\\n * @dev Revokes `role` from `account`.\\n *\\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n *\\n * May emit a {RoleRevoked} event.\\n */\\n function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\\n _revokeRole(role, account);\\n }\\n\\n /**\\n * @dev Revokes `role` from the calling account.\\n *\\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\\n * purpose is to provide a mechanism for accounts to lose their privileges\\n * if they are compromised (such as when a trusted device is misplaced).\\n *\\n * If the calling account had been revoked `role`, emits a {RoleRevoked}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must be `account`.\\n *\\n * May emit a {RoleRevoked} event.\\n */\\n function renounceRole(bytes32 role, address account) public virtual override {\\n require(account == _msgSender(), \\\"AccessControl: can only renounce roles for self\\\");\\n\\n _revokeRole(role, account);\\n }\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * If `account` had not been already granted `role`, emits a {RoleGranted}\\n * event. Note that unlike {grantRole}, this function doesn't perform any\\n * checks on the calling account.\\n *\\n * May emit a {RoleGranted} event.\\n *\\n * [WARNING]\\n * ====\\n * This function should only be called from the constructor when setting\\n * up the initial roles for the system.\\n *\\n * Using this function in any other way is effectively circumventing the admin\\n * system imposed by {AccessControl}.\\n * ====\\n *\\n * NOTE: This function is deprecated in favor of {_grantRole}.\\n */\\n function _setupRole(bytes32 role, address account) internal virtual {\\n _grantRole(role, account);\\n }\\n\\n /**\\n * @dev Sets `adminRole` as ``role``'s admin role.\\n *\\n * Emits a {RoleAdminChanged} event.\\n */\\n function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {\\n bytes32 previousAdminRole = getRoleAdmin(role);\\n _roles[role].adminRole = adminRole;\\n emit RoleAdminChanged(role, previousAdminRole, adminRole);\\n }\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * Internal function without access restriction.\\n *\\n * May emit a {RoleGranted} event.\\n */\\n function _grantRole(bytes32 role, address account) internal virtual {\\n if (!hasRole(role, account)) {\\n _roles[role].members[account] = true;\\n emit RoleGranted(role, account, _msgSender());\\n }\\n }\\n\\n /**\\n * @dev Revokes `role` from `account`.\\n *\\n * Internal function without access restriction.\\n *\\n * May emit a {RoleRevoked} event.\\n */\\n function _revokeRole(bytes32 role, address account) internal virtual {\\n if (hasRole(role, account)) {\\n _roles[role].members[account] = false;\\n emit RoleRevoked(role, account, _msgSender());\\n }\\n }\\n}\\n\",\"keccak256\":\"0x67e3daf189111d6d5b0464ed09cf9f0605a22c4b965a7fcecd707101faff008a\",\"license\":\"MIT\"},\"@openzeppelin/contracts/access/IAccessControl.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev External interface of AccessControl declared to support ERC165 detection.\\n */\\ninterface IAccessControl {\\n /**\\n * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`\\n *\\n * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite\\n * {RoleAdminChanged} not being emitted signaling this.\\n *\\n * _Available since v3.1._\\n */\\n event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);\\n\\n /**\\n * @dev Emitted when `account` is granted `role`.\\n *\\n * `sender` is the account that originated the contract call, an admin role\\n * bearer except when using {AccessControl-_setupRole}.\\n */\\n event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);\\n\\n /**\\n * @dev Emitted when `account` is revoked `role`.\\n *\\n * `sender` is the account that originated the contract call:\\n * - if using `revokeRole`, it is the admin role bearer\\n * - if using `renounceRole`, it is the role bearer (i.e. `account`)\\n */\\n event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);\\n\\n /**\\n * @dev Returns `true` if `account` has been granted `role`.\\n */\\n function hasRole(bytes32 role, address account) external view returns (bool);\\n\\n /**\\n * @dev Returns the admin role that controls `role`. See {grantRole} and\\n * {revokeRole}.\\n *\\n * To change a role's admin, use {AccessControl-_setRoleAdmin}.\\n */\\n function getRoleAdmin(bytes32 role) external view returns (bytes32);\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * If `account` had not been already granted `role`, emits a {RoleGranted}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n */\\n function grantRole(bytes32 role, address account) external;\\n\\n /**\\n * @dev Revokes `role` from `account`.\\n *\\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n */\\n function revokeRole(bytes32 role, address account) external;\\n\\n /**\\n * @dev Revokes `role` from the calling account.\\n *\\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\\n * purpose is to provide a mechanism for accounts to lose their privileges\\n * if they are compromised (such as when a trusted device is misplaced).\\n *\\n * If the calling account had been granted `role`, emits a {RoleRevoked}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must be `account`.\\n */\\n function renounceRole(bytes32 role, address account) external;\\n}\\n\",\"keccak256\":\"0x59ce320a585d7e1f163cd70390a0ef2ff9cec832e2aa544293a00692465a7a57\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/Context.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Provides information about the current execution context, including the\\n * sender of the transaction and its data. While these are generally available\\n * via msg.sender and msg.data, they should not be accessed in such a direct\\n * manner, since when dealing with meta-transactions the account sending and\\n * paying for execution may not be the actual sender (as far as an application\\n * is concerned).\\n *\\n * This contract is only required for intermediate, library-like contracts.\\n */\\nabstract contract Context {\\n function _msgSender() internal view virtual returns (address) {\\n return msg.sender;\\n }\\n\\n function _msgData() internal view virtual returns (bytes calldata) {\\n return msg.data;\\n }\\n}\\n\",\"keccak256\":\"0xe2e337e6dde9ef6b680e07338c493ebea1b5fd09b43424112868e9cc1706bca7\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/Strings.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./math/Math.sol\\\";\\n\\n/**\\n * @dev String operations.\\n */\\nlibrary Strings {\\n bytes16 private constant _SYMBOLS = \\\"0123456789abcdef\\\";\\n uint8 private constant _ADDRESS_LENGTH = 20;\\n\\n /**\\n * @dev Converts a `uint256` to its ASCII `string` decimal representation.\\n */\\n function toString(uint256 value) internal pure returns (string memory) {\\n unchecked {\\n uint256 length = Math.log10(value) + 1;\\n string memory buffer = new string(length);\\n uint256 ptr;\\n /// @solidity memory-safe-assembly\\n assembly {\\n ptr := add(buffer, add(32, length))\\n }\\n while (true) {\\n ptr--;\\n /// @solidity memory-safe-assembly\\n assembly {\\n mstore8(ptr, byte(mod(value, 10), _SYMBOLS))\\n }\\n value /= 10;\\n if (value == 0) break;\\n }\\n return buffer;\\n }\\n }\\n\\n /**\\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\\n */\\n function toHexString(uint256 value) internal pure returns (string memory) {\\n unchecked {\\n return toHexString(value, Math.log256(value) + 1);\\n }\\n }\\n\\n /**\\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\\n */\\n function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\\n bytes memory buffer = new bytes(2 * length + 2);\\n buffer[0] = \\\"0\\\";\\n buffer[1] = \\\"x\\\";\\n for (uint256 i = 2 * length + 1; i > 1; --i) {\\n buffer[i] = _SYMBOLS[value & 0xf];\\n value >>= 4;\\n }\\n require(value == 0, \\\"Strings: hex length insufficient\\\");\\n return string(buffer);\\n }\\n\\n /**\\n * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.\\n */\\n function toHexString(address addr) internal pure returns (string memory) {\\n return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);\\n }\\n}\\n\",\"keccak256\":\"0xa4d1d62251f8574deb032a35fc948386a9b4de74b812d4f545a1ac120486b48a\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/introspection/ERC165.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./IERC165.sol\\\";\\n\\n/**\\n * @dev Implementation of the {IERC165} interface.\\n *\\n * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check\\n * for the additional interface id that will be supported. For example:\\n *\\n * ```solidity\\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\\n * }\\n * ```\\n *\\n * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.\\n */\\nabstract contract ERC165 is IERC165 {\\n /**\\n * @dev See {IERC165-supportsInterface}.\\n */\\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n return interfaceId == type(IERC165).interfaceId;\\n }\\n}\\n\",\"keccak256\":\"0xd10975de010d89fd1c78dc5e8a9a7e7f496198085c151648f20cba166b32582b\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/introspection/IERC165.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Interface of the ERC165 standard, as defined in the\\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\\n *\\n * Implementers can declare support of contract interfaces, which can then be\\n * queried by others ({ERC165Checker}).\\n *\\n * For an implementation, see {ERC165}.\\n */\\ninterface IERC165 {\\n /**\\n * @dev Returns true if this contract implements the interface defined by\\n * `interfaceId`. See the corresponding\\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\\n * to learn more about how these ids are created.\\n *\\n * This function call must use less than 30 000 gas.\\n */\\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\\n}\\n\",\"keccak256\":\"0x447a5f3ddc18419d41ff92b3773fb86471b1db25773e07f877f548918a185bf1\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/math/Math.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Standard math utilities missing in the Solidity language.\\n */\\nlibrary Math {\\n enum Rounding {\\n Down, // Toward negative infinity\\n Up, // Toward infinity\\n Zero // Toward zero\\n }\\n\\n /**\\n * @dev Returns the largest of two numbers.\\n */\\n function max(uint256 a, uint256 b) internal pure returns (uint256) {\\n return a > b ? a : b;\\n }\\n\\n /**\\n * @dev Returns the smallest of two numbers.\\n */\\n function min(uint256 a, uint256 b) internal pure returns (uint256) {\\n return a < b ? a : b;\\n }\\n\\n /**\\n * @dev Returns the average of two numbers. The result is rounded towards\\n * zero.\\n */\\n function average(uint256 a, uint256 b) internal pure returns (uint256) {\\n // (a + b) / 2 can overflow.\\n return (a & b) + (a ^ b) / 2;\\n }\\n\\n /**\\n * @dev Returns the ceiling of the division of two numbers.\\n *\\n * This differs from standard division with `/` in that it rounds up instead\\n * of rounding down.\\n */\\n function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {\\n // (a + b - 1) / b can overflow on addition, so we distribute.\\n return a == 0 ? 0 : (a - 1) / b + 1;\\n }\\n\\n /**\\n * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0\\n * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)\\n * with further edits by Uniswap Labs also under MIT license.\\n */\\n function mulDiv(\\n uint256 x,\\n uint256 y,\\n uint256 denominator\\n ) internal pure returns (uint256 result) {\\n unchecked {\\n // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use\\n // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256\\n // variables such that product = prod1 * 2^256 + prod0.\\n uint256 prod0; // Least significant 256 bits of the product\\n uint256 prod1; // Most significant 256 bits of the product\\n assembly {\\n let mm := mulmod(x, y, not(0))\\n prod0 := mul(x, y)\\n prod1 := sub(sub(mm, prod0), lt(mm, prod0))\\n }\\n\\n // Handle non-overflow cases, 256 by 256 division.\\n if (prod1 == 0) {\\n return prod0 / denominator;\\n }\\n\\n // Make sure the result is less than 2^256. Also prevents denominator == 0.\\n require(denominator > prod1);\\n\\n ///////////////////////////////////////////////\\n // 512 by 256 division.\\n ///////////////////////////////////////////////\\n\\n // Make division exact by subtracting the remainder from [prod1 prod0].\\n uint256 remainder;\\n assembly {\\n // Compute remainder using mulmod.\\n remainder := mulmod(x, y, denominator)\\n\\n // Subtract 256 bit number from 512 bit number.\\n prod1 := sub(prod1, gt(remainder, prod0))\\n prod0 := sub(prod0, remainder)\\n }\\n\\n // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.\\n // See https://cs.stackexchange.com/q/138556/92363.\\n\\n // Does not overflow because the denominator cannot be zero at this stage in the function.\\n uint256 twos = denominator & (~denominator + 1);\\n assembly {\\n // Divide denominator by twos.\\n denominator := div(denominator, twos)\\n\\n // Divide [prod1 prod0] by twos.\\n prod0 := div(prod0, twos)\\n\\n // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.\\n twos := add(div(sub(0, twos), twos), 1)\\n }\\n\\n // Shift in bits from prod1 into prod0.\\n prod0 |= prod1 * twos;\\n\\n // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such\\n // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for\\n // four bits. That is, denominator * inv = 1 mod 2^4.\\n uint256 inverse = (3 * denominator) ^ 2;\\n\\n // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works\\n // in modular arithmetic, doubling the correct bits in each step.\\n inverse *= 2 - denominator * inverse; // inverse mod 2^8\\n inverse *= 2 - denominator * inverse; // inverse mod 2^16\\n inverse *= 2 - denominator * inverse; // inverse mod 2^32\\n inverse *= 2 - denominator * inverse; // inverse mod 2^64\\n inverse *= 2 - denominator * inverse; // inverse mod 2^128\\n inverse *= 2 - denominator * inverse; // inverse mod 2^256\\n\\n // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.\\n // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is\\n // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1\\n // is no longer required.\\n result = prod0 * inverse;\\n return result;\\n }\\n }\\n\\n /**\\n * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.\\n */\\n function mulDiv(\\n uint256 x,\\n uint256 y,\\n uint256 denominator,\\n Rounding rounding\\n ) internal pure returns (uint256) {\\n uint256 result = mulDiv(x, y, denominator);\\n if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {\\n result += 1;\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.\\n *\\n * Inspired by Henry S. Warren, Jr.'s \\\"Hacker's Delight\\\" (Chapter 11).\\n */\\n function sqrt(uint256 a) internal pure returns (uint256) {\\n if (a == 0) {\\n return 0;\\n }\\n\\n // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.\\n //\\n // We know that the \\\"msb\\\" (most significant bit) of our target number `a` is a power of 2 such that we have\\n // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.\\n //\\n // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`\\n // \\u2192 `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`\\n // \\u2192 `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`\\n //\\n // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.\\n uint256 result = 1 << (log2(a) >> 1);\\n\\n // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,\\n // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at\\n // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision\\n // into the expected uint128 result.\\n unchecked {\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n return min(result, a / result);\\n }\\n }\\n\\n /**\\n * @notice Calculates sqrt(a), following the selected rounding direction.\\n */\\n function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = sqrt(a);\\n return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);\\n }\\n }\\n\\n /**\\n * @dev Return the log in base 2, rounded down, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log2(uint256 value) internal pure returns (uint256) {\\n uint256 result = 0;\\n unchecked {\\n if (value >> 128 > 0) {\\n value >>= 128;\\n result += 128;\\n }\\n if (value >> 64 > 0) {\\n value >>= 64;\\n result += 64;\\n }\\n if (value >> 32 > 0) {\\n value >>= 32;\\n result += 32;\\n }\\n if (value >> 16 > 0) {\\n value >>= 16;\\n result += 16;\\n }\\n if (value >> 8 > 0) {\\n value >>= 8;\\n result += 8;\\n }\\n if (value >> 4 > 0) {\\n value >>= 4;\\n result += 4;\\n }\\n if (value >> 2 > 0) {\\n value >>= 2;\\n result += 2;\\n }\\n if (value >> 1 > 0) {\\n result += 1;\\n }\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Return the log in base 2, following the selected rounding direction, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = log2(value);\\n return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);\\n }\\n }\\n\\n /**\\n * @dev Return the log in base 10, rounded down, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log10(uint256 value) internal pure returns (uint256) {\\n uint256 result = 0;\\n unchecked {\\n if (value >= 10**64) {\\n value /= 10**64;\\n result += 64;\\n }\\n if (value >= 10**32) {\\n value /= 10**32;\\n result += 32;\\n }\\n if (value >= 10**16) {\\n value /= 10**16;\\n result += 16;\\n }\\n if (value >= 10**8) {\\n value /= 10**8;\\n result += 8;\\n }\\n if (value >= 10**4) {\\n value /= 10**4;\\n result += 4;\\n }\\n if (value >= 10**2) {\\n value /= 10**2;\\n result += 2;\\n }\\n if (value >= 10**1) {\\n result += 1;\\n }\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = log10(value);\\n return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);\\n }\\n }\\n\\n /**\\n * @dev Return the log in base 256, rounded down, of a positive value.\\n * Returns 0 if given 0.\\n *\\n * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.\\n */\\n function log256(uint256 value) internal pure returns (uint256) {\\n uint256 result = 0;\\n unchecked {\\n if (value >> 128 > 0) {\\n value >>= 128;\\n result += 16;\\n }\\n if (value >> 64 > 0) {\\n value >>= 64;\\n result += 8;\\n }\\n if (value >> 32 > 0) {\\n value >>= 32;\\n result += 4;\\n }\\n if (value >> 16 > 0) {\\n value >>= 16;\\n result += 2;\\n }\\n if (value >> 8 > 0) {\\n result += 1;\\n }\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = log256(value);\\n return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);\\n }\\n }\\n}\\n\",\"keccak256\":\"0xa1e8e83cd0087785df04ac79fb395d9f3684caeaf973d9e2c71caef723a3a5d6\",\"license\":\"MIT\"},\"src/PriceOracle.sol\":{\"content\":\"// SPDX-License-Identifier: BSD-3-Clause\\npragma solidity ^0.8.19;\\nimport \\\"@openzeppelin/contracts/access/AccessControl.sol\\\";\\nimport \\\"./interface/IPostageStamp.sol\\\";\\n\\n/**\\n * @title PriceOracle contract.\\n * @author The Swarm Authors.\\n * @dev The price oracle contract emits a price feed using events.\\n */\\n\\ncontract PriceOracle is AccessControl {\\n // ----------------------------- State variables ------------------------------\\n\\n // The address of the linked PostageStamp contract\\n IPostageStamp public postageStamp;\\n\\n uint16 targetRedundancy = 4;\\n uint16 maxConsideredExtraRedundancy = 4;\\n\\n // When the contract is paused, price changes are not effective\\n bool public isPaused = false;\\n\\n // The number of the last round price adjusting happend\\n uint64 public lastAdjustedRound;\\n\\n // The minimum price allowed\\n uint32 public minimumPriceUpscaled = 24000 << 10; // we upscale it by 2^10\\n\\n // The priceBase to modulate the price\\n uint32 public priceBase = 1048576;\\n\\n uint64 public currentPriceUpScaled = minimumPriceUpscaled;\\n\\n // Constants used to modulate the price, see below usage\\n uint32[9] public changeRate = [1049417, 1049206, 1048996, 1048786, 1048576, 1048366, 1048156, 1047946, 1047736];\\n\\n // Role allowed to update price\\n bytes32 public immutable PRICE_UPDATER_ROLE;\\n\\n // The length of a round in blocks.\\n uint8 private constant ROUND_LENGTH = 152;\\n\\n // ----------------------------- Events ------------------------------\\n\\n /**\\n *@dev Emitted on every price update.\\n */\\n event PriceUpdate(uint256 price);\\n event StampPriceUpdateFailed(uint256 attemptedPrice);\\n\\n // ----------------------------- Custom Errors ------------------------------\\n error CallerNotAdmin(); // Caller is not the admin\\n error CallerNotPriceUpdater(); // Caller is not a price updater\\n error PriceAlreadyAdjusted(); // Price already adjusted in this round\\n error UnexpectedZero(); // Redundancy needs to be higher then 0\\n\\n // ----------------------------- CONSTRUCTOR ------------------------------\\n\\n constructor(address _postageStamp) {\\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\\n postageStamp = IPostageStamp(_postageStamp);\\n lastAdjustedRound = currentRound();\\n PRICE_UPDATER_ROLE = keccak256(\\\"PRICE_UPDATER_ROLE\\\");\\n emit PriceUpdate(currentPrice());\\n }\\n\\n ////////////////////////////////////////\\n // STATE SETTING //\\n ////////////////////////////////////////\\n\\n /**\\n * @notice Manually set the price.\\n * @dev Can only be called by the admin role.\\n * @param _price The new price.\\n */ function setPrice(uint32 _price) external returns (bool) {\\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\\n revert CallerNotAdmin();\\n }\\n\\n uint64 _currentPriceUpScaled = _price << 10;\\n uint64 _minimumPriceUpscaled = minimumPriceUpscaled;\\n\\n // Enforce minimum price\\n if (_currentPriceUpScaled < _minimumPriceUpscaled) {\\n _currentPriceUpScaled = _minimumPriceUpscaled;\\n }\\n currentPriceUpScaled = _currentPriceUpScaled;\\n\\n // Check if the setting of price in postagestamp succeded\\n (bool success, ) = address(postageStamp).call(\\n abi.encodeWithSignature(\\\"setPrice(uint256)\\\", uint256(currentPrice()))\\n );\\n if (!success) {\\n emit StampPriceUpdateFailed(currentPrice());\\n return false;\\n }\\n emit PriceUpdate(currentPrice());\\n return true;\\n }\\n\\n function adjustPrice(uint16 redundancy) external returns (bool) {\\n if (isPaused == false) {\\n if (!hasRole(PRICE_UPDATER_ROLE, msg.sender)) {\\n revert CallerNotPriceUpdater();\\n }\\n\\n uint16 usedRedundancy = redundancy;\\n uint64 currentRoundNumber = currentRound();\\n\\n // Price can only be adjusted once per round\\n if (currentRoundNumber <= lastAdjustedRound) {\\n revert PriceAlreadyAdjusted();\\n }\\n // Redundancy may not be zero\\n if (redundancy == 0) {\\n revert UnexpectedZero();\\n }\\n\\n // Enforce maximum considered extra redundancy\\n uint16 maxConsideredRedundancy = targetRedundancy + maxConsideredExtraRedundancy;\\n if (redundancy > maxConsideredRedundancy) {\\n usedRedundancy = maxConsideredRedundancy;\\n }\\n\\n uint64 _currentPriceUpScaled = currentPriceUpScaled;\\n uint64 _minimumPriceUpscaled = minimumPriceUpscaled;\\n uint32 _priceBase = priceBase;\\n\\n // Set the number of rounds that were skipped\\n uint64 skippedRounds = currentRoundNumber - lastAdjustedRound - 1;\\n\\n // We first apply the increase/decrease rate for the current round\\n uint32 _changeRate = changeRate[usedRedundancy];\\n _currentPriceUpScaled = (_changeRate * _currentPriceUpScaled) / _priceBase;\\n\\n // If previous rounds were skipped, use MAX price increase for the previous rounds\\n if (skippedRounds > 0) {\\n _changeRate = changeRate[0];\\n for (uint64 i = 0; i < skippedRounds; i++) {\\n _currentPriceUpScaled = (_changeRate * _currentPriceUpScaled) / _priceBase;\\n }\\n }\\n\\n // Enforce minimum price\\n if (_currentPriceUpScaled < _minimumPriceUpscaled) {\\n _currentPriceUpScaled = _minimumPriceUpscaled;\\n }\\n\\n currentPriceUpScaled = _currentPriceUpScaled;\\n lastAdjustedRound = currentRoundNumber;\\n\\n // Check if the price set in postagestamp succeded\\n (bool success, ) = address(postageStamp).call(\\n abi.encodeWithSignature(\\\"setPrice(uint256)\\\", uint256(currentPrice()))\\n );\\n if (!success) {\\n emit StampPriceUpdateFailed(currentPrice());\\n return false;\\n }\\n emit PriceUpdate(currentPrice());\\n return true;\\n }\\n return false;\\n }\\n\\n function pause() external {\\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\\n revert CallerNotAdmin();\\n }\\n isPaused = true;\\n }\\n\\n function unPause() external {\\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\\n revert CallerNotAdmin();\\n }\\n isPaused = false;\\n }\\n\\n ////////////////////////////////////////\\n // STATE READING //\\n ////////////////////////////////////////\\n\\n /**\\n * @notice Return the number of the current round.\\n */\\n function currentRound() public view returns (uint64) {\\n // We downcasted to uint64 as uint64 has 18,446,744,073,709,551,616 places\\n // as each round is 152 x 5 = 760, each day has around 113 rounds which is 41245 in a year\\n // it results 4.4724801e+14 years to run this game\\n return uint64(block.number / uint256(ROUND_LENGTH));\\n }\\n\\n /**\\n * @notice Return the price downscaled\\n */\\n function currentPrice() public view returns (uint32) {\\n // We downcasted to uint32 and bitshift it by 2^10\\n return uint32((currentPriceUpScaled) >> 10);\\n }\\n\\n /**\\n * @notice Return the price downscaled\\n */\\n function minimumPrice() public view returns (uint32) {\\n // We downcasted to uint32 and bitshift it by 2^10\\n return uint32((minimumPriceUpscaled) >> 10);\\n }\\n}\\n\",\"keccak256\":\"0xd20bafc89a159228f118b31cdec5bc6a1a14c1979eeb6271f0c6ed0e47f1a617\",\"license\":\"BSD-3-Clause\"},\"src/interface/IPostageStamp.sol\":{\"content\":\"// SPDX-License-Identifier: BSD-3-Clause\\npragma solidity ^0.8.19;\\n\\ninterface IPostageStamp {\\n function withdraw(address beneficiary) external;\\n\\n function setPrice(uint256 _price) external;\\n\\n function validChunkCount() external view returns (uint256);\\n\\n function batchOwner(bytes32 _batchId) external view returns (address);\\n\\n function batchDepth(bytes32 _batchId) external view returns (uint8);\\n\\n function batchBucketDepth(bytes32 _batchId) external view returns (uint8);\\n\\n function remainingBalance(bytes32 _batchId) external view returns (uint256);\\n\\n function minimumInitialBalancePerChunk() external view returns (uint256);\\n\\n function batches(\\n bytes32\\n )\\n external\\n view\\n returns (\\n address owner,\\n uint8 depth,\\n uint8 bucketDepth,\\n bool immutableFlag,\\n uint256 normalisedBalance,\\n uint256 lastUpdatedBlockNumber\\n );\\n}\\n\",\"keccak256\":\"0xb46f1043bf7fdc22d5f719ab97341211fa30fff499de3cf079be715079b965ad\",\"license\":\"BSD-3-Clause\"}},\"version\":1}", + "bytecode": "0x600180546201000160a21b64ffffffffff60a01b1990911617905560028054600160401b600160c01b0319811663ffffffff68010000000000000000600160401b600160801b03199093166e1000000177000000000000000000009081179390930416600160801b02171790556101c06040526210034960a09081526210027660c052621001a460e052621000d2610100526210000061012052620fff2e61014052620ffe5c61016052620ffd8a61018052620ffcb86101a052620000c990600390600962000291565b50348015620000d757600080fd5b506040516200181938038062001819833981016040819052620000fa916200034a565b62000107600033620001cd565b600180546001600160a01b0319166001600160a01b0383161790556200012c620001dd565b600280546001600160401b0319166001600160401b03929092169190911790557fd96ba01d6560c2ab35f2940dd8d70c5f5fe06236c72674237120515918198fb06080527fae46785019700e30375a5d7b4f91e32f8060ef085111f896ebf889450aa2ab5a620001ae600254600160801b9004600a1c663fffffffffffff1690565b60405163ffffffff909116815260200160405180910390a1506200039f565b620001d98282620001f1565b5050565b6000620001ec6098436200037c565b905090565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16620001d9576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556200024d3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b600283019183908215620003215791602002820160005b83821115620002ed57835183826101000a81548163ffffffff021916908362ffffff1602179055509260200192600401602081600301049283019260010302620002a8565b80156200031f5782816101000a81549063ffffffff0219169055600401602081600301049283019260010302620002ed565b505b506200032f92915062000333565b5090565b5b808211156200032f576000815560010162000334565b6000602082840312156200035d57600080fd5b81516001600160a01b03811681146200037557600080fd5b9392505050565b6000826200039a57634e487b7160e01b600052601260045260246000fd5b500490565b608051611457620003c2600039600081816103ac01526108bf01526114576000f3fe608060405234801561001057600080fd5b50600436106101825760003560e01c806391d14854116100d8578063daafe0a51161008c578063f7b188a511610066578063f7b188a51461039f578063fb8d8101146103a7578063ffb98fe3146103ce57600080fd5b8063daafe0a514610346578063dcd8ffb814610359578063e0632c641461037457600080fd5b8063a217fddf116100bd578063a217fddf14610317578063b187bd261461031f578063d547741f1461033357600080fd5b806391d14854146102c55780639d1b464a146102fc57600080fd5b80637310561b1161013a5780637f386b6c116101145780637f386b6c146102995780638456cb59146102b55780638a19c8bc146102bd57600080fd5b80637310561b1461023557806374e7493b1461026a5780637e8effdd1461027d57600080fd5b80632f2ff15d1161016b5780632f2ff15d146101e057806336568abe146101f557806355bdcd231461020857600080fd5b806301ffc9a714610187578063248a9ca3146101af575b600080fd5b61019a6101953660046110e2565b6103e1565b60405190151581526020015b60405180910390f35b6101d26101bd366004611124565b60009081526020819052604090206001015490565b6040519081526020016101a6565b6101f36101ee36600461113d565b61047a565b005b6101f361020336600461113d565b6104a4565b60025461021c9067ffffffffffffffff1681565b60405167ffffffffffffffff90911681526020016101a6565b600254610255906c01000000000000000000000000900463ffffffff1681565b60405163ffffffff90911681526020016101a6565b610255610278366004611124565b610535565b6002546102559068010000000000000000900463ffffffff1681565b600254680100000000000000009004600a1c623fffff16610255565b6101f3610565565b61021c6105c9565b61019a6102d336600461113d565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b600254600160801b9004600a1c663fffffffffffff16610255565b6101d2600081565b60015461019a90600160c01b900460ff1681565b6101f361034136600461113d565b6105db565b61019a610354366004611179565b610600565b60025461021c90600160801b900467ffffffffffffffff1681565b600154610387906001600160a01b031681565b6040516001600160a01b0390911681526020016101a6565b6101f3610847565b6101d27f000000000000000000000000000000000000000000000000000000000000000081565b61019a6103dc36600461119f565b6108a5565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f7965db0b00000000000000000000000000000000000000000000000000000000148061047457507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008316145b92915050565b60008281526020819052604090206001015461049581610d4b565b61049f8383610d58565b505050565b6001600160a01b03811633146105275760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b6105318282610df6565b5050565b6003816009811061054557600080fd5b60089182820401919006600402915054906101000a900463ffffffff1681565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff166105b45760405163036c8cf960e11b815260040160405180910390fd5b6001805460ff60c01b1916600160c01b179055565b60006105d66098436111ef565b905090565b6000828152602081905260409020600101546105f681610d4b565b61049f8383610df6565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604081205460ff1661064f5760405163036c8cf960e11b815260040160405180910390fd5b60025463fffffc00600a84901b169068010000000000000000900463ffffffff168082101561067c578091505b6002805467ffffffffffffffff8416600160801b027fffffffffffffffff0000000000000000ffffffffffffffffffffffffffffffff9091161790556001546000906001600160a01b03166106e4600254663fffffffffffff600160801b909104600a1c1690565b63ffffffff166040516024016106fc91815260200190565b60408051601f198184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff166391b7f5ed60e01b179052516107469190611227565b6000604051808303816000865af19150503d8060008114610783576040519150601f19603f3d011682016040523d82523d6000602084013e610788565b606091505b50509050806107ec576002547fd2821f4adadf1d64076091cc92984c0f001a300541dd58cff8e8e29d6290c33d90600160801b9004600a1c663fffffffffffff1660405163ffffffff909116815260200160405180910390a1506000949350505050565b6002547fae46785019700e30375a5d7b4f91e32f8060ef085111f896ebf889450aa2ab5a90600160801b9004600a1c663fffffffffffff1660405163ffffffff909116815260200160405180910390a1506001949350505050565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff166108965760405163036c8cf960e11b815260040160405180910390fd5b6001805460ff60c01b19169055565b600154600090600160c01b900460ff1615158103610d43577f000000000000000000000000000000000000000000000000000000000000000060009081526020818152604080832033845290915290205460ff1661092f576040517f262791ec00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b81600061093a6105c9565b60025490915067ffffffffffffffff90811690821611610986576040517f08a5cb4c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8361ffff166000036109c4576040517fb5ca2d7100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600154600090610a0c9061ffff760100000000000000000000000000000000000000000000820481169174010000000000000000000000000000000000000000900416611243565b90508061ffff168561ffff161115610a22578092505b60025467ffffffffffffffff600160801b820481169163ffffffff6801000000000000000082048116926c01000000000000000000000000830490911691600091600191610a71911688611265565b610a7b9190611265565b9050600060038861ffff1660098110610a9657610a96611286565b60088104919091015460079091166004026101000a900463ffffffff90811691508316610ac3868361129c565b610acd91906112c8565b945067ffffffffffffffff821615610b41575060035463ffffffff1660005b8267ffffffffffffffff168167ffffffffffffffff161015610b3f578363ffffffff16868363ffffffff16610b21919061129c565b610b2b91906112c8565b955080610b37816112ef565b915050610aec565b505b8367ffffffffffffffff168567ffffffffffffffff161015610b61578394505b600280547fffffffffffffffff0000000000000000ffffffffffffffff000000000000000016600160801b67ffffffffffffffff888116820267ffffffffffffffff191692909217918a1691909117918290556001546000926001600160a01b03909116919004600a1c663fffffffffffff1663ffffffff16604051602401610bec91815260200190565b60408051601f198184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff166391b7f5ed60e01b17905251610c369190611227565b6000604051808303816000865af19150503d8060008114610c73576040519150601f19603f3d011682016040523d82523d6000602084013e610c78565b606091505b5050905080610ce2576002547fd2821f4adadf1d64076091cc92984c0f001a300541dd58cff8e8e29d6290c33d90600160801b9004600a1c663fffffffffffff1660405163ffffffff909116815260200160405180910390a15060009a9950505050505050505050565b6002547fae46785019700e30375a5d7b4f91e32f8060ef085111f896ebf889450aa2ab5a90600160801b9004600a1c663fffffffffffff1660405163ffffffff909116815260200160405180910390a15060019a9950505050505050505050565b506000919050565b610d558133610e75565b50565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610531576000828152602081815260408083206001600160a01b03851684529091529020805460ff19166001179055610db23390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1615610531576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1661053157610ea681610ee8565b610eb1836020610efa565b604051602001610ec2929190611316565b60408051601f198184030181529082905262461bcd60e51b825261051e91600401611397565b60606104746001600160a01b03831660145b60606000610f098360026113ca565b610f149060026113e1565b67ffffffffffffffff811115610f2c57610f2c6113f4565b6040519080825280601f01601f191660200182016040528015610f56576020820181803683370190505b5090507f300000000000000000000000000000000000000000000000000000000000000081600081518110610f8d57610f8d611286565b60200101906001600160f81b031916908160001a9053507f780000000000000000000000000000000000000000000000000000000000000081600181518110610fd857610fd8611286565b60200101906001600160f81b031916908160001a9053506000610ffc8460026113ca565b6110079060016113e1565b90505b600181111561108c577f303132333435363738396162636465660000000000000000000000000000000085600f166010811061104857611048611286565b1a60f81b82828151811061105e5761105e611286565b60200101906001600160f81b031916908160001a90535060049490941c936110858161140a565b905061100a565b5083156110db5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e74604482015260640161051e565b9392505050565b6000602082840312156110f457600080fd5b81357fffffffff00000000000000000000000000000000000000000000000000000000811681146110db57600080fd5b60006020828403121561113657600080fd5b5035919050565b6000806040838503121561115057600080fd5b8235915060208301356001600160a01b038116811461116e57600080fd5b809150509250929050565b60006020828403121561118b57600080fd5b813563ffffffff811681146110db57600080fd5b6000602082840312156111b157600080fd5b813561ffff811681146110db57600080fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b6000826111fe576111fe6111c3565b500490565b60005b8381101561121e578181015183820152602001611206565b50506000910152565b60008251611239818460208701611203565b9190910192915050565b61ffff81811683821601908082111561125e5761125e6111d9565b5092915050565b67ffffffffffffffff82811682821603908082111561125e5761125e6111d9565b634e487b7160e01b600052603260045260246000fd5b67ffffffffffffffff8181168382160280821691908281146112c0576112c06111d9565b505092915050565b600067ffffffffffffffff808416806112e3576112e36111c3565b92169190910492915050565b600067ffffffffffffffff80831681810361130c5761130c6111d9565b6001019392505050565b7f416363657373436f6e74726f6c3a206163636f756e742000000000000000000081526000835161134e816017850160208801611203565b7f206973206d697373696e6720726f6c6520000000000000000000000000000000601791840191820152835161138b816028840160208801611203565b01602801949350505050565b60208152600082518060208401526113b6816040850160208701611203565b601f01601f19169190910160400192915050565b8082028115828204841417610474576104746111d9565b80820180821115610474576104746111d9565b634e487b7160e01b600052604160045260246000fd5b600081611419576114196111d9565b50600019019056fea2646970667358221220fe4d5e770c549445a1c04db94a469cb1f4118d505fa93712dfcd199d4742f1ae64736f6c63430008130033", + "deployedBytecode": "0x608060405234801561001057600080fd5b50600436106101825760003560e01c806391d14854116100d8578063daafe0a51161008c578063f7b188a511610066578063f7b188a51461039f578063fb8d8101146103a7578063ffb98fe3146103ce57600080fd5b8063daafe0a514610346578063dcd8ffb814610359578063e0632c641461037457600080fd5b8063a217fddf116100bd578063a217fddf14610317578063b187bd261461031f578063d547741f1461033357600080fd5b806391d14854146102c55780639d1b464a146102fc57600080fd5b80637310561b1161013a5780637f386b6c116101145780637f386b6c146102995780638456cb59146102b55780638a19c8bc146102bd57600080fd5b80637310561b1461023557806374e7493b1461026a5780637e8effdd1461027d57600080fd5b80632f2ff15d1161016b5780632f2ff15d146101e057806336568abe146101f557806355bdcd231461020857600080fd5b806301ffc9a714610187578063248a9ca3146101af575b600080fd5b61019a6101953660046110e2565b6103e1565b60405190151581526020015b60405180910390f35b6101d26101bd366004611124565b60009081526020819052604090206001015490565b6040519081526020016101a6565b6101f36101ee36600461113d565b61047a565b005b6101f361020336600461113d565b6104a4565b60025461021c9067ffffffffffffffff1681565b60405167ffffffffffffffff90911681526020016101a6565b600254610255906c01000000000000000000000000900463ffffffff1681565b60405163ffffffff90911681526020016101a6565b610255610278366004611124565b610535565b6002546102559068010000000000000000900463ffffffff1681565b600254680100000000000000009004600a1c623fffff16610255565b6101f3610565565b61021c6105c9565b61019a6102d336600461113d565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b600254600160801b9004600a1c663fffffffffffff16610255565b6101d2600081565b60015461019a90600160c01b900460ff1681565b6101f361034136600461113d565b6105db565b61019a610354366004611179565b610600565b60025461021c90600160801b900467ffffffffffffffff1681565b600154610387906001600160a01b031681565b6040516001600160a01b0390911681526020016101a6565b6101f3610847565b6101d27f000000000000000000000000000000000000000000000000000000000000000081565b61019a6103dc36600461119f565b6108a5565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f7965db0b00000000000000000000000000000000000000000000000000000000148061047457507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008316145b92915050565b60008281526020819052604090206001015461049581610d4b565b61049f8383610d58565b505050565b6001600160a01b03811633146105275760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b6105318282610df6565b5050565b6003816009811061054557600080fd5b60089182820401919006600402915054906101000a900463ffffffff1681565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff166105b45760405163036c8cf960e11b815260040160405180910390fd5b6001805460ff60c01b1916600160c01b179055565b60006105d66098436111ef565b905090565b6000828152602081905260409020600101546105f681610d4b565b61049f8383610df6565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604081205460ff1661064f5760405163036c8cf960e11b815260040160405180910390fd5b60025463fffffc00600a84901b169068010000000000000000900463ffffffff168082101561067c578091505b6002805467ffffffffffffffff8416600160801b027fffffffffffffffff0000000000000000ffffffffffffffffffffffffffffffff9091161790556001546000906001600160a01b03166106e4600254663fffffffffffff600160801b909104600a1c1690565b63ffffffff166040516024016106fc91815260200190565b60408051601f198184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff166391b7f5ed60e01b179052516107469190611227565b6000604051808303816000865af19150503d8060008114610783576040519150601f19603f3d011682016040523d82523d6000602084013e610788565b606091505b50509050806107ec576002547fd2821f4adadf1d64076091cc92984c0f001a300541dd58cff8e8e29d6290c33d90600160801b9004600a1c663fffffffffffff1660405163ffffffff909116815260200160405180910390a1506000949350505050565b6002547fae46785019700e30375a5d7b4f91e32f8060ef085111f896ebf889450aa2ab5a90600160801b9004600a1c663fffffffffffff1660405163ffffffff909116815260200160405180910390a1506001949350505050565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff166108965760405163036c8cf960e11b815260040160405180910390fd5b6001805460ff60c01b19169055565b600154600090600160c01b900460ff1615158103610d43577f000000000000000000000000000000000000000000000000000000000000000060009081526020818152604080832033845290915290205460ff1661092f576040517f262791ec00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b81600061093a6105c9565b60025490915067ffffffffffffffff90811690821611610986576040517f08a5cb4c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8361ffff166000036109c4576040517fb5ca2d7100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600154600090610a0c9061ffff760100000000000000000000000000000000000000000000820481169174010000000000000000000000000000000000000000900416611243565b90508061ffff168561ffff161115610a22578092505b60025467ffffffffffffffff600160801b820481169163ffffffff6801000000000000000082048116926c01000000000000000000000000830490911691600091600191610a71911688611265565b610a7b9190611265565b9050600060038861ffff1660098110610a9657610a96611286565b60088104919091015460079091166004026101000a900463ffffffff90811691508316610ac3868361129c565b610acd91906112c8565b945067ffffffffffffffff821615610b41575060035463ffffffff1660005b8267ffffffffffffffff168167ffffffffffffffff161015610b3f578363ffffffff16868363ffffffff16610b21919061129c565b610b2b91906112c8565b955080610b37816112ef565b915050610aec565b505b8367ffffffffffffffff168567ffffffffffffffff161015610b61578394505b600280547fffffffffffffffff0000000000000000ffffffffffffffff000000000000000016600160801b67ffffffffffffffff888116820267ffffffffffffffff191692909217918a1691909117918290556001546000926001600160a01b03909116919004600a1c663fffffffffffff1663ffffffff16604051602401610bec91815260200190565b60408051601f198184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff166391b7f5ed60e01b17905251610c369190611227565b6000604051808303816000865af19150503d8060008114610c73576040519150601f19603f3d011682016040523d82523d6000602084013e610c78565b606091505b5050905080610ce2576002547fd2821f4adadf1d64076091cc92984c0f001a300541dd58cff8e8e29d6290c33d90600160801b9004600a1c663fffffffffffff1660405163ffffffff909116815260200160405180910390a15060009a9950505050505050505050565b6002547fae46785019700e30375a5d7b4f91e32f8060ef085111f896ebf889450aa2ab5a90600160801b9004600a1c663fffffffffffff1660405163ffffffff909116815260200160405180910390a15060019a9950505050505050505050565b506000919050565b610d558133610e75565b50565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610531576000828152602081815260408083206001600160a01b03851684529091529020805460ff19166001179055610db23390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1615610531576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1661053157610ea681610ee8565b610eb1836020610efa565b604051602001610ec2929190611316565b60408051601f198184030181529082905262461bcd60e51b825261051e91600401611397565b60606104746001600160a01b03831660145b60606000610f098360026113ca565b610f149060026113e1565b67ffffffffffffffff811115610f2c57610f2c6113f4565b6040519080825280601f01601f191660200182016040528015610f56576020820181803683370190505b5090507f300000000000000000000000000000000000000000000000000000000000000081600081518110610f8d57610f8d611286565b60200101906001600160f81b031916908160001a9053507f780000000000000000000000000000000000000000000000000000000000000081600181518110610fd857610fd8611286565b60200101906001600160f81b031916908160001a9053506000610ffc8460026113ca565b6110079060016113e1565b90505b600181111561108c577f303132333435363738396162636465660000000000000000000000000000000085600f166010811061104857611048611286565b1a60f81b82828151811061105e5761105e611286565b60200101906001600160f81b031916908160001a90535060049490941c936110858161140a565b905061100a565b5083156110db5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e74604482015260640161051e565b9392505050565b6000602082840312156110f457600080fd5b81357fffffffff00000000000000000000000000000000000000000000000000000000811681146110db57600080fd5b60006020828403121561113657600080fd5b5035919050565b6000806040838503121561115057600080fd5b8235915060208301356001600160a01b038116811461116e57600080fd5b809150509250929050565b60006020828403121561118b57600080fd5b813563ffffffff811681146110db57600080fd5b6000602082840312156111b157600080fd5b813561ffff811681146110db57600080fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b6000826111fe576111fe6111c3565b500490565b60005b8381101561121e578181015183820152602001611206565b50506000910152565b60008251611239818460208701611203565b9190910192915050565b61ffff81811683821601908082111561125e5761125e6111d9565b5092915050565b67ffffffffffffffff82811682821603908082111561125e5761125e6111d9565b634e487b7160e01b600052603260045260246000fd5b67ffffffffffffffff8181168382160280821691908281146112c0576112c06111d9565b505092915050565b600067ffffffffffffffff808416806112e3576112e36111c3565b92169190910492915050565b600067ffffffffffffffff80831681810361130c5761130c6111d9565b6001019392505050565b7f416363657373436f6e74726f6c3a206163636f756e742000000000000000000081526000835161134e816017850160208801611203565b7f206973206d697373696e6720726f6c6520000000000000000000000000000000601791840191820152835161138b816028840160208801611203565b01602801949350505050565b60208152600082518060208401526113b6816040850160208701611203565b601f01601f19169190910160400192915050565b8082028115828204841417610474576104746111d9565b80820180821115610474576104746111d9565b634e487b7160e01b600052604160045260246000fd5b600081611419576114196111d9565b50600019019056fea2646970667358221220fe4d5e770c549445a1c04db94a469cb1f4118d505fa93712dfcd199d4742f1ae64736f6c63430008130033", "devdoc": { "author": "The Swarm Authors.", "details": "The price oracle contract emits a price feed using events.", @@ -560,7 +597,7 @@ "label": "postageStamp", "offset": 0, "slot": "1", - "type": "t_contract(IPostageStamp)11004" + "type": "t_contract(IPostageStamp)11335" }, { "astId": 6719, @@ -649,7 +686,7 @@ "label": "bytes32", "numberOfBytes": "32" }, - "t_contract(IPostageStamp)11004": { + "t_contract(IPostageStamp)11335": { "encoding": "inplace", "label": "contract IPostageStamp", "numberOfBytes": "20" diff --git a/deployments/testnetlight/Redistribution.json b/deployments/testnetlight/Redistribution.json index 0a8565eb..4e90794c 100644 --- a/deployments/testnetlight/Redistribution.json +++ b/deployments/testnetlight/Redistribution.json @@ -1,5 +1,5 @@ { - "address": "0x136Ce406e2339973DC6159fF72b7E598b7B39160", + "address": "0xD3Bb610E7ABcaEF1de07b79Cd2fFdEC2c9F51FBC", "abi": [ { "inputs": [ @@ -342,6 +342,19 @@ "name": "Paused", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint16", + "name": "redundancyCount", + "type": "uint16" + } + ], + "name": "PriceAdjustmentSkipped", + "type": "event" + }, { "anonymous": false, "inputs": [ @@ -537,6 +550,19 @@ "name": "WinnerSelected", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "owner", + "type": "address" + } + ], + "name": "WithdrawFailed", + "type": "event" + }, { "anonymous": false, "inputs": [ @@ -958,6 +984,11 @@ "name": "revealed", "type": "bool" }, + { + "internalType": "uint8", + "name": "height", + "type": "uint8" + }, { "internalType": "uint256", "name": "stake", @@ -1530,22 +1561,22 @@ "type": "function" } ], - "transactionHash": "0x348deb8b394dfd0453fb59d194353da8c44483b12e928bc627b53a8469c32ca5", + "transactionHash": "0x44bfb521348261b044e0156e456cef699c710448fb46cc397f1acbc63a5b9ed4", "receipt": { "to": null, "from": "0xb1C7F17Ed88189Abf269Bf68A3B2Ed83C5276aAe", - "contractAddress": "0x136Ce406e2339973DC6159fF72b7E598b7B39160", - "transactionIndex": 43, - "gasUsed": "4251329", - "logsBloom": "0x00000004000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000020000000000000000000800000000010000000000000000002000000000040000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000100002040000020000000000000000000000000000000000000000400000000000000000000000000", - "blockHash": "0x079edbb1deaf94c3d197dad1cac2b75c234e72e8d8405dbc35a5b49cf68cfa22", - "transactionHash": "0x348deb8b394dfd0453fb59d194353da8c44483b12e928bc627b53a8469c32ca5", + "contractAddress": "0xD3Bb610E7ABcaEF1de07b79Cd2fFdEC2c9F51FBC", + "transactionIndex": 61, + "gasUsed": "4391185", + "logsBloom": "0x00000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000800000000010000000000000000002000000000040000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000400000000000000000040100000000000020000000000000000000000000000000000000000000000000000000000000000000", + "blockHash": "0x0b0c3112ab25edc0850d03dcbd5abd7da69ffb324275d277b0e23c5416faa127", + "transactionHash": "0x44bfb521348261b044e0156e456cef699c710448fb46cc397f1acbc63a5b9ed4", "logs": [ { - "transactionIndex": 43, - "blockNumber": 6321448, - "transactionHash": "0x348deb8b394dfd0453fb59d194353da8c44483b12e928bc627b53a8469c32ca5", - "address": "0x136Ce406e2339973DC6159fF72b7E598b7B39160", + "transactionIndex": 61, + "blockNumber": 6964103, + "transactionHash": "0x44bfb521348261b044e0156e456cef699c710448fb46cc397f1acbc63a5b9ed4", + "address": "0xD3Bb610E7ABcaEF1de07b79Cd2fFdEC2c9F51FBC", "topics": [ "0x2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d", "0x0000000000000000000000000000000000000000000000000000000000000000", @@ -1553,40 +1584,25 @@ "0x000000000000000000000000b1c7f17ed88189abf269bf68a3b2ed83c5276aae" ], "data": "0x", - "logIndex": 130, - "blockHash": "0x079edbb1deaf94c3d197dad1cac2b75c234e72e8d8405dbc35a5b49cf68cfa22" - }, - { - "transactionIndex": 43, - "blockNumber": 6321448, - "transactionHash": "0x348deb8b394dfd0453fb59d194353da8c44483b12e928bc627b53a8469c32ca5", - "address": "0x136Ce406e2339973DC6159fF72b7E598b7B39160", - "topics": [ - "0x2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d", - "0x65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a", - "0x000000000000000000000000b1c7f17ed88189abf269bf68a3b2ed83c5276aae", - "0x000000000000000000000000b1c7f17ed88189abf269bf68a3b2ed83c5276aae" - ], - "data": "0x", - "logIndex": 131, - "blockHash": "0x079edbb1deaf94c3d197dad1cac2b75c234e72e8d8405dbc35a5b49cf68cfa22" + "logIndex": 60, + "blockHash": "0x0b0c3112ab25edc0850d03dcbd5abd7da69ffb324275d277b0e23c5416faa127" } ], - "blockNumber": 6321448, - "cumulativeGasUsed": "12826828", + "blockNumber": 6964103, + "cumulativeGasUsed": "9621015", "status": 1, "byzantium": true }, "args": [ - "0x5922F26A68021C9edf53d9CFbEFc3181f0d16E93", - "0x38eC2DC60069b28439e4Fca4DF9a91b1d29217cF", - "0xcA1E073042438a40A7BC0e558e2B9bd1fe2647F8" + "0x554D880D39f1072D147aaf5b8BB2589A882617F8", + "0x44598B43216eCe3C0eB0dd8e3006d23B40E0554c", + "0x01709567dfF91A387eB2d1Ca60255f80e7633EC2" ], "numDeployments": 3, - "solcInputHash": "823850fc9cd5102bcd2f6d2624ab2024", - "metadata": "{\"compiler\":{\"version\":\"0.8.19+commit.7dd6d404\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"staking\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"postageContract\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"oracleContract\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[],\"name\":\"AlreadyClaimed\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"AlreadyCommitted\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"AlreadyRevealed\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"BatchDoesNotExist\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"BucketDiffers\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"CommitRoundNotStarted\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"CommitRoundOver\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"FirstRevealDone\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"uint8\",\"name\":\"\",\"type\":\"uint8\"},{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"InclusionProofFailed\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"IndexOutsideSet\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"InvalidSignatureLength\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"LastElementCheckFailed\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"MustStake2Rounds\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NoCommitsReceived\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NoMatchingCommit\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NoReveals\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NotAdmin\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NotClaimPhase\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NotCommitPhase\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NotMatchingOwner\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NotRevealPhase\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NotStaked\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"OnlyPauser\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"OutOfDepth\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"uint8\",\"name\":\"\",\"type\":\"uint8\"}],\"name\":\"OutOfDepthClaim\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"OutOfDepthReveal\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"PhaseLastBlock\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"RandomElementCheckFailed\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"trALast\",\"type\":\"bytes32\"}],\"name\":\"ReserveCheckFailed\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"SigRecoveryFailed\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"SocCalcNotMatching\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"SocVerificationFailed\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"WrongPhase\",\"type\":\"error\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"validChunkCount\",\"type\":\"uint256\"}],\"name\":\"ChunkCount\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"roundNumber\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"}],\"name\":\"Committed\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"_count\",\"type\":\"uint256\"}],\"name\":\"CountCommits\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"_count\",\"type\":\"uint256\"}],\"name\":\"CountReveals\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"roundNumber\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"anchor\",\"type\":\"bytes32\"}],\"name\":\"CurrentRevealAnchor\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"Paused\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"roundNumber\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"stake\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"stakeDensity\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"reserveCommitment\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint8\",\"name\":\"depth\",\"type\":\"uint8\"}],\"name\":\"Revealed\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"previousAdminRole\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"newAdminRole\",\"type\":\"bytes32\"}],\"name\":\"RoleAdminChanged\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"}],\"name\":\"RoleGranted\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"}],\"name\":\"RoleRevoked\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"hash\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint8\",\"name\":\"depth\",\"type\":\"uint8\"}],\"name\":\"TruthSelected\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"Unpaused\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"components\":[{\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"uint8\",\"name\":\"depth\",\"type\":\"uint8\"},{\"internalType\":\"uint256\",\"name\":\"stake\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"stakeDensity\",\"type\":\"uint256\"},{\"internalType\":\"bytes32\",\"name\":\"hash\",\"type\":\"bytes32\"}],\"indexed\":false,\"internalType\":\"struct Redistribution.Reveal\",\"name\":\"winner\",\"type\":\"tuple\"}],\"name\":\"WinnerSelected\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"indexInRC\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"chunkAddress\",\"type\":\"bytes32\"}],\"name\":\"transformedChunkAddressFromInclusionProof\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"DEFAULT_ADMIN_ROLE\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"OracleContract\",\"outputs\":[{\"internalType\":\"contract IPriceOracle\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"PostageContract\",\"outputs\":[{\"internalType\":\"contract IPostageStamp\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"Stakes\",\"outputs\":[{\"internalType\":\"contract IStakeRegistry\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"components\":[{\"internalType\":\"bytes32[]\",\"name\":\"proofSegments\",\"type\":\"bytes32[]\"},{\"internalType\":\"bytes32\",\"name\":\"proveSegment\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32[]\",\"name\":\"proofSegments2\",\"type\":\"bytes32[]\"},{\"internalType\":\"bytes32\",\"name\":\"proveSegment2\",\"type\":\"bytes32\"},{\"internalType\":\"uint64\",\"name\":\"chunkSpan\",\"type\":\"uint64\"},{\"internalType\":\"bytes32[]\",\"name\":\"proofSegments3\",\"type\":\"bytes32[]\"},{\"components\":[{\"internalType\":\"bytes\",\"name\":\"signature\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"postageId\",\"type\":\"bytes32\"},{\"internalType\":\"uint64\",\"name\":\"index\",\"type\":\"uint64\"},{\"internalType\":\"uint64\",\"name\":\"timeStamp\",\"type\":\"uint64\"}],\"internalType\":\"struct Redistribution.PostageProof\",\"name\":\"postageProof\",\"type\":\"tuple\"},{\"components\":[{\"internalType\":\"address\",\"name\":\"signer\",\"type\":\"address\"},{\"internalType\":\"bytes\",\"name\":\"signature\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"identifier\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"chunkAddr\",\"type\":\"bytes32\"}],\"internalType\":\"struct Redistribution.SOCProof[]\",\"name\":\"socProof\",\"type\":\"tuple[]\"}],\"internalType\":\"struct Redistribution.ChunkInclusionProof\",\"name\":\"entryProof1\",\"type\":\"tuple\"},{\"components\":[{\"internalType\":\"bytes32[]\",\"name\":\"proofSegments\",\"type\":\"bytes32[]\"},{\"internalType\":\"bytes32\",\"name\":\"proveSegment\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32[]\",\"name\":\"proofSegments2\",\"type\":\"bytes32[]\"},{\"internalType\":\"bytes32\",\"name\":\"proveSegment2\",\"type\":\"bytes32\"},{\"internalType\":\"uint64\",\"name\":\"chunkSpan\",\"type\":\"uint64\"},{\"internalType\":\"bytes32[]\",\"name\":\"proofSegments3\",\"type\":\"bytes32[]\"},{\"components\":[{\"internalType\":\"bytes\",\"name\":\"signature\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"postageId\",\"type\":\"bytes32\"},{\"internalType\":\"uint64\",\"name\":\"index\",\"type\":\"uint64\"},{\"internalType\":\"uint64\",\"name\":\"timeStamp\",\"type\":\"uint64\"}],\"internalType\":\"struct Redistribution.PostageProof\",\"name\":\"postageProof\",\"type\":\"tuple\"},{\"components\":[{\"internalType\":\"address\",\"name\":\"signer\",\"type\":\"address\"},{\"internalType\":\"bytes\",\"name\":\"signature\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"identifier\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"chunkAddr\",\"type\":\"bytes32\"}],\"internalType\":\"struct Redistribution.SOCProof[]\",\"name\":\"socProof\",\"type\":\"tuple[]\"}],\"internalType\":\"struct Redistribution.ChunkInclusionProof\",\"name\":\"entryProof2\",\"type\":\"tuple\"},{\"components\":[{\"internalType\":\"bytes32[]\",\"name\":\"proofSegments\",\"type\":\"bytes32[]\"},{\"internalType\":\"bytes32\",\"name\":\"proveSegment\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32[]\",\"name\":\"proofSegments2\",\"type\":\"bytes32[]\"},{\"internalType\":\"bytes32\",\"name\":\"proveSegment2\",\"type\":\"bytes32\"},{\"internalType\":\"uint64\",\"name\":\"chunkSpan\",\"type\":\"uint64\"},{\"internalType\":\"bytes32[]\",\"name\":\"proofSegments3\",\"type\":\"bytes32[]\"},{\"components\":[{\"internalType\":\"bytes\",\"name\":\"signature\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"postageId\",\"type\":\"bytes32\"},{\"internalType\":\"uint64\",\"name\":\"index\",\"type\":\"uint64\"},{\"internalType\":\"uint64\",\"name\":\"timeStamp\",\"type\":\"uint64\"}],\"internalType\":\"struct Redistribution.PostageProof\",\"name\":\"postageProof\",\"type\":\"tuple\"},{\"components\":[{\"internalType\":\"address\",\"name\":\"signer\",\"type\":\"address\"},{\"internalType\":\"bytes\",\"name\":\"signature\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"identifier\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"chunkAddr\",\"type\":\"bytes32\"}],\"internalType\":\"struct Redistribution.SOCProof[]\",\"name\":\"socProof\",\"type\":\"tuple[]\"}],\"internalType\":\"struct Redistribution.ChunkInclusionProof\",\"name\":\"entryProofLast\",\"type\":\"tuple\"}],\"name\":\"claim\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"_obfuscatedHash\",\"type\":\"bytes32\"},{\"internalType\":\"uint64\",\"name\":\"_roundNumber\",\"type\":\"uint64\"}],\"name\":\"commit\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentClaimRound\",\"outputs\":[{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentCommitRound\",\"outputs\":[{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"currentCommits\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"revealed\",\"type\":\"bool\"},{\"internalType\":\"uint256\",\"name\":\"stake\",\"type\":\"uint256\"},{\"internalType\":\"bytes32\",\"name\":\"obfuscatedHash\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"revealIndex\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentMinimumDepth\",\"outputs\":[{\"internalType\":\"uint8\",\"name\":\"\",\"type\":\"uint8\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentPhaseClaim\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentPhaseCommit\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentPhaseReveal\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentRevealRound\",\"outputs\":[{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"currentReveals\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"uint8\",\"name\":\"depth\",\"type\":\"uint8\"},{\"internalType\":\"uint256\",\"name\":\"stake\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"stakeDensity\",\"type\":\"uint256\"},{\"internalType\":\"bytes32\",\"name\":\"hash\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentRound\",\"outputs\":[{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentRoundAnchor\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"returnVal\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentRoundReveals\",\"outputs\":[{\"components\":[{\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"uint8\",\"name\":\"depth\",\"type\":\"uint8\"},{\"internalType\":\"uint256\",\"name\":\"stake\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"stakeDensity\",\"type\":\"uint256\"},{\"internalType\":\"bytes32\",\"name\":\"hash\",\"type\":\"bytes32\"}],\"internalType\":\"struct Redistribution.Reveal[]\",\"name\":\"\",\"type\":\"tuple[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentSeed\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"}],\"name\":\"getRoleAdmin\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"grantRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"hasRole\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"A\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"B\",\"type\":\"bytes32\"},{\"internalType\":\"uint8\",\"name\":\"minimum\",\"type\":\"uint8\"}],\"name\":\"inProximity\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"pure\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_owner\",\"type\":\"address\"},{\"internalType\":\"uint8\",\"name\":\"_depth\",\"type\":\"uint8\"}],\"name\":\"isParticipatingInUpcomingRound\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"_overlay\",\"type\":\"bytes32\"}],\"name\":\"isWinner\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"nextSeed\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"pause\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"paused\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"renounceRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint8\",\"name\":\"_depth\",\"type\":\"uint8\"},{\"internalType\":\"bytes32\",\"name\":\"_hash\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"_revealNonce\",\"type\":\"bytes32\"}],\"name\":\"reveal\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"revokeRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint8\",\"name\":\"_penaltyMultiplierDisagreement\",\"type\":\"uint8\"},{\"internalType\":\"uint8\",\"name\":\"_penaltyMultiplierNonRevealed\",\"type\":\"uint8\"},{\"internalType\":\"uint8\",\"name\":\"_penaltyRandomFactor\",\"type\":\"uint8\"}],\"name\":\"setFreezingParams\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_sampleMaxValue\",\"type\":\"uint256\"}],\"name\":\"setSampleMaxValue\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes4\",\"name\":\"interfaceId\",\"type\":\"bytes4\"}],\"name\":\"supportsInterface\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"unPause\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"winner\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"uint8\",\"name\":\"depth\",\"type\":\"uint8\"},{\"internalType\":\"uint256\",\"name\":\"stake\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"stakeDensity\",\"type\":\"uint256\"},{\"internalType\":\"bytes32\",\"name\":\"hash\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"_overlay\",\"type\":\"bytes32\"},{\"internalType\":\"uint8\",\"name\":\"_depth\",\"type\":\"uint8\"},{\"internalType\":\"bytes32\",\"name\":\"_hash\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"revealNonce\",\"type\":\"bytes32\"}],\"name\":\"wrapCommit\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"pure\",\"type\":\"function\"}],\"devdoc\":{\"author\":\"The Swarm Authors\",\"details\":\"Implements a Schelling Co-ordination game to form consensus around the Reserve Commitment hash. This takes place in three phases: _commit_, _reveal_ and _claim_. A node, upon establishing that it _isParticipatingInUpcomingRound_, i.e. it's overlay falls within proximity order of its reported depth with the _currentRoundAnchor_, prepares a \\\"reserve commitment hash\\\" using the chunks it currently stores in its reserve and calculates the \\\"storage depth\\\" (see Bee for details). These values, if calculated honestly, and with the right chunks stored, should be the same for every node in a neighbourhood. This is the Schelling point. Each eligible node can then use these values, together with a random, single use, secret _revealNonce_ and their _overlay_ as the pre-image values for the obsfucated _commit_, using the _wrapCommit_ method. Once the _commit_ round has elapsed, participating nodes must provide the values used to calculate their obsfucated _commit_ hash, which, once verified for correctness and proximity to the anchor are retained in the _currentReveals_. Nodes that have committed but do not reveal the correct values used to create the pre-image will have their stake \\\"frozen\\\" for a period of rounds proportional to their reported depth. During the _reveal_ round, randomness is updated after every successful reveal. Once the reveal round is concluded, the _currentRoundAnchor_ is updated and users can determine if they will be eligible their overlay will be eligible for the next commit phase using _isParticipatingInUpcomingRound_. When the _reveal_ phase has been concluded, the claim phase can begin. At this point, the truth teller and winner are already determined. By calling _isWinner_, an applicant node can run the relevant logic to determine if they have been selected as the beneficiary of this round. When calling _claim_, the current pot from the PostageStamp contract is withdrawn and transferred to that beneficiaries address. Nodes that have revealed values that differ from the truth, have their stakes \\\"frozen\\\" for a period of rounds proportional to their reported depth.\",\"events\":{\"ChunkCount(uint256)\":{\"details\":\"Emit from Postagestamp contract valid chunk count at the end of claim\"},\"Committed(uint256,bytes32)\":{\"details\":\"Logs that an overlay has committed\"},\"CountCommits(uint256)\":{\"details\":\"Emits the number of commits being processed by the claim phase.\"},\"CountReveals(uint256)\":{\"details\":\"Emits the number of reveals being processed by the claim phase.\"},\"CurrentRevealAnchor(uint256,bytes32)\":{\"details\":\"Bytes32 anhor of current reveal round\"},\"Paused(address)\":{\"details\":\"Emitted when the pause is triggered by `account`.\"},\"Revealed(uint256,bytes32,uint256,uint256,bytes32,uint8)\":{\"details\":\"Logs that an overlay has revealed\"},\"RoleAdminChanged(bytes32,bytes32,bytes32)\":{\"details\":\"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._\"},\"RoleGranted(bytes32,address,address)\":{\"details\":\"Emitted when `account` is granted `role`. `sender` is the account that originated the contract call, an admin role bearer except when using {AccessControl-_setupRole}.\"},\"RoleRevoked(bytes32,address,address)\":{\"details\":\"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`)\"},\"TruthSelected(bytes32,uint8)\":{\"details\":\"Emitted when the truth oracle of a round is selected in the claim phase.\"},\"Unpaused(address)\":{\"details\":\"Emitted when the pause is lifted by `account`.\"},\"WinnerSelected((bytes32,address,uint8,uint256,uint256,bytes32))\":{\"details\":\"Emitted when the winner of a round is selected in the claim phase\"},\"transformedChunkAddressFromInclusionProof(uint256,bytes32)\":{\"details\":\"Logs for inclusion proof\"}},\"kind\":\"dev\",\"methods\":{\"commit(bytes32,uint64)\":{\"details\":\"If a node's overlay is _inProximity_(_depth_) of the _currentRoundAnchor_, that node may compute an _obfuscatedHash_ by providing their _overlay_, reported storage _depth_, reserve commitment _hash_ and a randomly generated, and secret _revealNonce_ to the _wrapCommit_ method.\",\"params\":{\"_obfuscatedHash\":\"The calculated hash resultant of the required pre-image values. and be derived from the same key pair as the message sender.\",\"_roundNumber\":\"Node needs to provide round number for which commit is valid\"}},\"constructor\":{\"params\":{\"oracleContract\":\"the address of the linked PriceOracle contract.\",\"postageContract\":\"the address of the linked PostageStamp contract.\",\"staking\":\"the address of the linked Staking contract.\"}},\"currentRoundAnchor()\":{\"details\":\"A node must be within proximity order of less than or equal to the storage depth they intend to report.\"},\"getRoleAdmin(bytes32)\":{\"details\":\"Returns the admin role that controls `role`. See {grantRole} and {revokeRole}. To change a role's admin, use {_setRoleAdmin}.\"},\"grantRole(bytes32,address)\":{\"details\":\"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.\"},\"hasRole(bytes32,address)\":{\"details\":\"Returns `true` if `account` has been granted `role`.\"},\"inProximity(bytes32,bytes32,uint8)\":{\"params\":{\"A\":\"An overlay address to compare.\",\"B\":\"An overlay address to compare.\",\"minimum\":\"Minimum proximity order.\"}},\"isParticipatingInUpcomingRound(address,uint8)\":{\"params\":{\"_depth\":\"The storage depth the applicant intends to report.\",\"_owner\":\"The address of the applicant from.\"}},\"isWinner(bytes32)\":{\"params\":{\"_overlay\":\"The overlay address of the applicant.\"}},\"pause()\":{\"details\":\"Pause the contract. The contract is provably stopped by renouncing the pauser role and the admin role after pausing, can only be called by the `PAUSER`\"},\"paused()\":{\"details\":\"Returns true if the contract is paused, and false otherwise.\"},\"renounceRole(bytes32,address)\":{\"details\":\"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.\"},\"reveal(uint8,bytes32,bytes32)\":{\"params\":{\"_depth\":\"The reported depth.\",\"_hash\":\"The reserve commitment hash.\",\"_revealNonce\":\"The nonce used to generate the commit that is being revealed.\"}},\"revokeRole(bytes32,address)\":{\"details\":\"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.\"},\"supportsInterface(bytes4)\":{\"details\":\"See {IERC165-supportsInterface}.\"},\"unPause()\":{\"details\":\"Unpause the contract, can only be called by the pauser when paused\"},\"wrapCommit(bytes32,uint8,bytes32,bytes32)\":{\"details\":\"_revealNonce_ must be randomly generated, used once and kept secret until the reveal phase.\",\"params\":{\"_depth\":\"The reported depth.\",\"_hash\":\"The reserve commitment hash.\",\"_overlay\":\"The overlay address of the applicant.\",\"revealNonce\":\"A random, single use, secret nonce.\"}}},\"title\":\"Redistribution contract\",\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{\"claim((bytes32[],bytes32,bytes32[],bytes32,uint64,bytes32[],(bytes,bytes32,uint64,uint64),(address,bytes,bytes32,bytes32)[]),(bytes32[],bytes32,bytes32[],bytes32,uint64,bytes32[],(bytes,bytes32,uint64,uint64),(address,bytes,bytes32,bytes32)[]),(bytes32[],bytes32,bytes32[],bytes32,uint64,bytes32[],(bytes,bytes32,uint64,uint64),(address,bytes,bytes32,bytes32)[]))\":{\"notice\":\"Helper function to get this round truth\"},\"commit(bytes32,uint64)\":{\"notice\":\"Begin application for a round if eligible. Commit a hashed value for which the pre-image will be subsequently revealed.\"},\"currentMinimumDepth()\":{\"notice\":\"Returns minimum depth reveal has to have to participate in this round\"},\"currentPhaseClaim()\":{\"notice\":\"Returns true if current block is during claim phase.\"},\"currentPhaseCommit()\":{\"notice\":\"Returns true if current block is during commit phase.\"},\"currentPhaseReveal()\":{\"notice\":\"Returns true if current block is during reveal phase.\"},\"currentRound()\":{\"notice\":\"The number of the current round.\"},\"currentRoundAnchor()\":{\"notice\":\"The anchor used to determine eligibility for the current round.\"},\"currentRoundReveals()\":{\"notice\":\"Returns true if current block is during reveal phase.\"},\"currentSeed()\":{\"notice\":\"Returns the current random seed which is used to determine later utilised random numbers. If rounds have elapsed without reveals, hash the seed with an incremented nonce to produce a new random seed and hence a new round anchor.\"},\"inProximity(bytes32,bytes32,uint8)\":{\"notice\":\"Returns true if an overlay address _A_ is within proximity order _minimum_ of _B_.\"},\"isParticipatingInUpcomingRound(address,uint8)\":{\"notice\":\"Determine if a the owner of a given overlay can participate in the upcoming round.\"},\"isWinner(bytes32)\":{\"notice\":\"Determine if a the owner of a given overlay will be the beneficiary of the claim phase.\"},\"nextSeed()\":{\"notice\":\"Returns the seed which will become current once the next commit phase begins. Used to determine what the next round's anchor will be.\"},\"reveal(uint8,bytes32,bytes32)\":{\"notice\":\"Reveal the pre-image values used to generate commit provided during this round's commit phase.\"},\"setFreezingParams(uint8,uint8,uint8)\":{\"notice\":\"Set freezing parameters\"},\"setSampleMaxValue(uint256)\":{\"notice\":\"changes the max sample value used for reserve estimation\"},\"wrapCommit(bytes32,uint8,bytes32,bytes32)\":{\"notice\":\"Hash the pre-image values to the obsfucated hash.\"}},\"version\":1}},\"settings\":{\"compilationTarget\":{\"src/Redistribution.sol\":\"Redistribution\"},\"evmVersion\":\"paris\",\"libraries\":{\":__CACHE_BREAKER__\":\"0x00000000d41867734bbee4c6863d9255b2b06ac1\"},\"metadata\":{\"bytecodeHash\":\"ipfs\",\"useLiteralContent\":true},\"optimizer\":{\"enabled\":true,\"runs\":1000},\"remappings\":[]},\"sources\":{\"@openzeppelin/contracts/access/AccessControl.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (access/AccessControl.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./IAccessControl.sol\\\";\\nimport \\\"../utils/Context.sol\\\";\\nimport \\\"../utils/Strings.sol\\\";\\nimport \\\"../utils/introspection/ERC165.sol\\\";\\n\\n/**\\n * @dev Contract module that allows children to implement role-based access\\n * control mechanisms. This is a lightweight version that doesn't allow enumerating role\\n * members except through off-chain means by accessing the contract event logs. Some\\n * applications may benefit from on-chain enumerability, for those cases see\\n * {AccessControlEnumerable}.\\n *\\n * Roles are referred to by their `bytes32` identifier. These should be exposed\\n * in the external API and be unique. The best way to achieve this is by\\n * using `public constant` hash digests:\\n *\\n * ```\\n * bytes32 public constant MY_ROLE = keccak256(\\\"MY_ROLE\\\");\\n * ```\\n *\\n * Roles can be used to represent a set of permissions. To restrict access to a\\n * function call, use {hasRole}:\\n *\\n * ```\\n * function foo() public {\\n * require(hasRole(MY_ROLE, msg.sender));\\n * ...\\n * }\\n * ```\\n *\\n * Roles can be granted and revoked dynamically via the {grantRole} and\\n * {revokeRole} functions. Each role has an associated admin role, and only\\n * accounts that have a role's admin role can call {grantRole} and {revokeRole}.\\n *\\n * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means\\n * that only accounts with this role will be able to grant or revoke other\\n * roles. More complex role relationships can be created by using\\n * {_setRoleAdmin}.\\n *\\n * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to\\n * grant and revoke this role. Extra precautions should be taken to secure\\n * accounts that have been granted it.\\n */\\nabstract contract AccessControl is Context, IAccessControl, ERC165 {\\n struct RoleData {\\n mapping(address => bool) members;\\n bytes32 adminRole;\\n }\\n\\n mapping(bytes32 => RoleData) private _roles;\\n\\n bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;\\n\\n /**\\n * @dev Modifier that checks that an account has a specific role. Reverts\\n * with a standardized message including the required role.\\n *\\n * The format of the revert reason is given by the following regular expression:\\n *\\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\\n *\\n * _Available since v4.1._\\n */\\n modifier onlyRole(bytes32 role) {\\n _checkRole(role);\\n _;\\n }\\n\\n /**\\n * @dev See {IERC165-supportsInterface}.\\n */\\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);\\n }\\n\\n /**\\n * @dev Returns `true` if `account` has been granted `role`.\\n */\\n function hasRole(bytes32 role, address account) public view virtual override returns (bool) {\\n return _roles[role].members[account];\\n }\\n\\n /**\\n * @dev Revert with a standard message if `_msgSender()` is missing `role`.\\n * Overriding this function changes the behavior of the {onlyRole} modifier.\\n *\\n * Format of the revert message is described in {_checkRole}.\\n *\\n * _Available since v4.6._\\n */\\n function _checkRole(bytes32 role) internal view virtual {\\n _checkRole(role, _msgSender());\\n }\\n\\n /**\\n * @dev Revert with a standard message if `account` is missing `role`.\\n *\\n * The format of the revert reason is given by the following regular expression:\\n *\\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\\n */\\n function _checkRole(bytes32 role, address account) internal view virtual {\\n if (!hasRole(role, account)) {\\n revert(\\n string(\\n abi.encodePacked(\\n \\\"AccessControl: account \\\",\\n Strings.toHexString(account),\\n \\\" is missing role \\\",\\n Strings.toHexString(uint256(role), 32)\\n )\\n )\\n );\\n }\\n }\\n\\n /**\\n * @dev Returns the admin role that controls `role`. See {grantRole} and\\n * {revokeRole}.\\n *\\n * To change a role's admin, use {_setRoleAdmin}.\\n */\\n function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {\\n return _roles[role].adminRole;\\n }\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * If `account` had not been already granted `role`, emits a {RoleGranted}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n *\\n * May emit a {RoleGranted} event.\\n */\\n function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\\n _grantRole(role, account);\\n }\\n\\n /**\\n * @dev Revokes `role` from `account`.\\n *\\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n *\\n * May emit a {RoleRevoked} event.\\n */\\n function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\\n _revokeRole(role, account);\\n }\\n\\n /**\\n * @dev Revokes `role` from the calling account.\\n *\\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\\n * purpose is to provide a mechanism for accounts to lose their privileges\\n * if they are compromised (such as when a trusted device is misplaced).\\n *\\n * If the calling account had been revoked `role`, emits a {RoleRevoked}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must be `account`.\\n *\\n * May emit a {RoleRevoked} event.\\n */\\n function renounceRole(bytes32 role, address account) public virtual override {\\n require(account == _msgSender(), \\\"AccessControl: can only renounce roles for self\\\");\\n\\n _revokeRole(role, account);\\n }\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * If `account` had not been already granted `role`, emits a {RoleGranted}\\n * event. Note that unlike {grantRole}, this function doesn't perform any\\n * checks on the calling account.\\n *\\n * May emit a {RoleGranted} event.\\n *\\n * [WARNING]\\n * ====\\n * This function should only be called from the constructor when setting\\n * up the initial roles for the system.\\n *\\n * Using this function in any other way is effectively circumventing the admin\\n * system imposed by {AccessControl}.\\n * ====\\n *\\n * NOTE: This function is deprecated in favor of {_grantRole}.\\n */\\n function _setupRole(bytes32 role, address account) internal virtual {\\n _grantRole(role, account);\\n }\\n\\n /**\\n * @dev Sets `adminRole` as ``role``'s admin role.\\n *\\n * Emits a {RoleAdminChanged} event.\\n */\\n function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {\\n bytes32 previousAdminRole = getRoleAdmin(role);\\n _roles[role].adminRole = adminRole;\\n emit RoleAdminChanged(role, previousAdminRole, adminRole);\\n }\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * Internal function without access restriction.\\n *\\n * May emit a {RoleGranted} event.\\n */\\n function _grantRole(bytes32 role, address account) internal virtual {\\n if (!hasRole(role, account)) {\\n _roles[role].members[account] = true;\\n emit RoleGranted(role, account, _msgSender());\\n }\\n }\\n\\n /**\\n * @dev Revokes `role` from `account`.\\n *\\n * Internal function without access restriction.\\n *\\n * May emit a {RoleRevoked} event.\\n */\\n function _revokeRole(bytes32 role, address account) internal virtual {\\n if (hasRole(role, account)) {\\n _roles[role].members[account] = false;\\n emit RoleRevoked(role, account, _msgSender());\\n }\\n }\\n}\\n\",\"keccak256\":\"0x67e3daf189111d6d5b0464ed09cf9f0605a22c4b965a7fcecd707101faff008a\",\"license\":\"MIT\"},\"@openzeppelin/contracts/access/IAccessControl.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev External interface of AccessControl declared to support ERC165 detection.\\n */\\ninterface IAccessControl {\\n /**\\n * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`\\n *\\n * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite\\n * {RoleAdminChanged} not being emitted signaling this.\\n *\\n * _Available since v3.1._\\n */\\n event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);\\n\\n /**\\n * @dev Emitted when `account` is granted `role`.\\n *\\n * `sender` is the account that originated the contract call, an admin role\\n * bearer except when using {AccessControl-_setupRole}.\\n */\\n event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);\\n\\n /**\\n * @dev Emitted when `account` is revoked `role`.\\n *\\n * `sender` is the account that originated the contract call:\\n * - if using `revokeRole`, it is the admin role bearer\\n * - if using `renounceRole`, it is the role bearer (i.e. `account`)\\n */\\n event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);\\n\\n /**\\n * @dev Returns `true` if `account` has been granted `role`.\\n */\\n function hasRole(bytes32 role, address account) external view returns (bool);\\n\\n /**\\n * @dev Returns the admin role that controls `role`. See {grantRole} and\\n * {revokeRole}.\\n *\\n * To change a role's admin, use {AccessControl-_setRoleAdmin}.\\n */\\n function getRoleAdmin(bytes32 role) external view returns (bytes32);\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * If `account` had not been already granted `role`, emits a {RoleGranted}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n */\\n function grantRole(bytes32 role, address account) external;\\n\\n /**\\n * @dev Revokes `role` from `account`.\\n *\\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n */\\n function revokeRole(bytes32 role, address account) external;\\n\\n /**\\n * @dev Revokes `role` from the calling account.\\n *\\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\\n * purpose is to provide a mechanism for accounts to lose their privileges\\n * if they are compromised (such as when a trusted device is misplaced).\\n *\\n * If the calling account had been granted `role`, emits a {RoleRevoked}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must be `account`.\\n */\\n function renounceRole(bytes32 role, address account) external;\\n}\\n\",\"keccak256\":\"0x59ce320a585d7e1f163cd70390a0ef2ff9cec832e2aa544293a00692465a7a57\",\"license\":\"MIT\"},\"@openzeppelin/contracts/security/Pausable.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"../utils/Context.sol\\\";\\n\\n/**\\n * @dev Contract module which allows children to implement an emergency stop\\n * mechanism that can be triggered by an authorized account.\\n *\\n * This module is used through inheritance. It will make available the\\n * modifiers `whenNotPaused` and `whenPaused`, which can be applied to\\n * the functions of your contract. Note that they will not be pausable by\\n * simply including this module, only once the modifiers are put in place.\\n */\\nabstract contract Pausable is Context {\\n /**\\n * @dev Emitted when the pause is triggered by `account`.\\n */\\n event Paused(address account);\\n\\n /**\\n * @dev Emitted when the pause is lifted by `account`.\\n */\\n event Unpaused(address account);\\n\\n bool private _paused;\\n\\n /**\\n * @dev Initializes the contract in unpaused state.\\n */\\n constructor() {\\n _paused = false;\\n }\\n\\n /**\\n * @dev Modifier to make a function callable only when the contract is not paused.\\n *\\n * Requirements:\\n *\\n * - The contract must not be paused.\\n */\\n modifier whenNotPaused() {\\n _requireNotPaused();\\n _;\\n }\\n\\n /**\\n * @dev Modifier to make a function callable only when the contract is paused.\\n *\\n * Requirements:\\n *\\n * - The contract must be paused.\\n */\\n modifier whenPaused() {\\n _requirePaused();\\n _;\\n }\\n\\n /**\\n * @dev Returns true if the contract is paused, and false otherwise.\\n */\\n function paused() public view virtual returns (bool) {\\n return _paused;\\n }\\n\\n /**\\n * @dev Throws if the contract is paused.\\n */\\n function _requireNotPaused() internal view virtual {\\n require(!paused(), \\\"Pausable: paused\\\");\\n }\\n\\n /**\\n * @dev Throws if the contract is not paused.\\n */\\n function _requirePaused() internal view virtual {\\n require(paused(), \\\"Pausable: not paused\\\");\\n }\\n\\n /**\\n * @dev Triggers stopped state.\\n *\\n * Requirements:\\n *\\n * - The contract must not be paused.\\n */\\n function _pause() internal virtual whenNotPaused {\\n _paused = true;\\n emit Paused(_msgSender());\\n }\\n\\n /**\\n * @dev Returns to normal state.\\n *\\n * Requirements:\\n *\\n * - The contract must be paused.\\n */\\n function _unpause() internal virtual whenPaused {\\n _paused = false;\\n emit Unpaused(_msgSender());\\n }\\n}\\n\",\"keccak256\":\"0x0849d93b16c9940beb286a7864ed02724b248b93e0d80ef6355af5ef15c64773\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/Context.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Provides information about the current execution context, including the\\n * sender of the transaction and its data. While these are generally available\\n * via msg.sender and msg.data, they should not be accessed in such a direct\\n * manner, since when dealing with meta-transactions the account sending and\\n * paying for execution may not be the actual sender (as far as an application\\n * is concerned).\\n *\\n * This contract is only required for intermediate, library-like contracts.\\n */\\nabstract contract Context {\\n function _msgSender() internal view virtual returns (address) {\\n return msg.sender;\\n }\\n\\n function _msgData() internal view virtual returns (bytes calldata) {\\n return msg.data;\\n }\\n}\\n\",\"keccak256\":\"0xe2e337e6dde9ef6b680e07338c493ebea1b5fd09b43424112868e9cc1706bca7\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/Strings.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./math/Math.sol\\\";\\n\\n/**\\n * @dev String operations.\\n */\\nlibrary Strings {\\n bytes16 private constant _SYMBOLS = \\\"0123456789abcdef\\\";\\n uint8 private constant _ADDRESS_LENGTH = 20;\\n\\n /**\\n * @dev Converts a `uint256` to its ASCII `string` decimal representation.\\n */\\n function toString(uint256 value) internal pure returns (string memory) {\\n unchecked {\\n uint256 length = Math.log10(value) + 1;\\n string memory buffer = new string(length);\\n uint256 ptr;\\n /// @solidity memory-safe-assembly\\n assembly {\\n ptr := add(buffer, add(32, length))\\n }\\n while (true) {\\n ptr--;\\n /// @solidity memory-safe-assembly\\n assembly {\\n mstore8(ptr, byte(mod(value, 10), _SYMBOLS))\\n }\\n value /= 10;\\n if (value == 0) break;\\n }\\n return buffer;\\n }\\n }\\n\\n /**\\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\\n */\\n function toHexString(uint256 value) internal pure returns (string memory) {\\n unchecked {\\n return toHexString(value, Math.log256(value) + 1);\\n }\\n }\\n\\n /**\\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\\n */\\n function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\\n bytes memory buffer = new bytes(2 * length + 2);\\n buffer[0] = \\\"0\\\";\\n buffer[1] = \\\"x\\\";\\n for (uint256 i = 2 * length + 1; i > 1; --i) {\\n buffer[i] = _SYMBOLS[value & 0xf];\\n value >>= 4;\\n }\\n require(value == 0, \\\"Strings: hex length insufficient\\\");\\n return string(buffer);\\n }\\n\\n /**\\n * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.\\n */\\n function toHexString(address addr) internal pure returns (string memory) {\\n return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);\\n }\\n}\\n\",\"keccak256\":\"0xa4d1d62251f8574deb032a35fc948386a9b4de74b812d4f545a1ac120486b48a\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/introspection/ERC165.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./IERC165.sol\\\";\\n\\n/**\\n * @dev Implementation of the {IERC165} interface.\\n *\\n * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check\\n * for the additional interface id that will be supported. For example:\\n *\\n * ```solidity\\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\\n * }\\n * ```\\n *\\n * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.\\n */\\nabstract contract ERC165 is IERC165 {\\n /**\\n * @dev See {IERC165-supportsInterface}.\\n */\\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n return interfaceId == type(IERC165).interfaceId;\\n }\\n}\\n\",\"keccak256\":\"0xd10975de010d89fd1c78dc5e8a9a7e7f496198085c151648f20cba166b32582b\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/introspection/IERC165.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Interface of the ERC165 standard, as defined in the\\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\\n *\\n * Implementers can declare support of contract interfaces, which can then be\\n * queried by others ({ERC165Checker}).\\n *\\n * For an implementation, see {ERC165}.\\n */\\ninterface IERC165 {\\n /**\\n * @dev Returns true if this contract implements the interface defined by\\n * `interfaceId`. See the corresponding\\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\\n * to learn more about how these ids are created.\\n *\\n * This function call must use less than 30 000 gas.\\n */\\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\\n}\\n\",\"keccak256\":\"0x447a5f3ddc18419d41ff92b3773fb86471b1db25773e07f877f548918a185bf1\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/math/Math.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Standard math utilities missing in the Solidity language.\\n */\\nlibrary Math {\\n enum Rounding {\\n Down, // Toward negative infinity\\n Up, // Toward infinity\\n Zero // Toward zero\\n }\\n\\n /**\\n * @dev Returns the largest of two numbers.\\n */\\n function max(uint256 a, uint256 b) internal pure returns (uint256) {\\n return a > b ? a : b;\\n }\\n\\n /**\\n * @dev Returns the smallest of two numbers.\\n */\\n function min(uint256 a, uint256 b) internal pure returns (uint256) {\\n return a < b ? a : b;\\n }\\n\\n /**\\n * @dev Returns the average of two numbers. The result is rounded towards\\n * zero.\\n */\\n function average(uint256 a, uint256 b) internal pure returns (uint256) {\\n // (a + b) / 2 can overflow.\\n return (a & b) + (a ^ b) / 2;\\n }\\n\\n /**\\n * @dev Returns the ceiling of the division of two numbers.\\n *\\n * This differs from standard division with `/` in that it rounds up instead\\n * of rounding down.\\n */\\n function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {\\n // (a + b - 1) / b can overflow on addition, so we distribute.\\n return a == 0 ? 0 : (a - 1) / b + 1;\\n }\\n\\n /**\\n * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0\\n * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)\\n * with further edits by Uniswap Labs also under MIT license.\\n */\\n function mulDiv(\\n uint256 x,\\n uint256 y,\\n uint256 denominator\\n ) internal pure returns (uint256 result) {\\n unchecked {\\n // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use\\n // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256\\n // variables such that product = prod1 * 2^256 + prod0.\\n uint256 prod0; // Least significant 256 bits of the product\\n uint256 prod1; // Most significant 256 bits of the product\\n assembly {\\n let mm := mulmod(x, y, not(0))\\n prod0 := mul(x, y)\\n prod1 := sub(sub(mm, prod0), lt(mm, prod0))\\n }\\n\\n // Handle non-overflow cases, 256 by 256 division.\\n if (prod1 == 0) {\\n return prod0 / denominator;\\n }\\n\\n // Make sure the result is less than 2^256. Also prevents denominator == 0.\\n require(denominator > prod1);\\n\\n ///////////////////////////////////////////////\\n // 512 by 256 division.\\n ///////////////////////////////////////////////\\n\\n // Make division exact by subtracting the remainder from [prod1 prod0].\\n uint256 remainder;\\n assembly {\\n // Compute remainder using mulmod.\\n remainder := mulmod(x, y, denominator)\\n\\n // Subtract 256 bit number from 512 bit number.\\n prod1 := sub(prod1, gt(remainder, prod0))\\n prod0 := sub(prod0, remainder)\\n }\\n\\n // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.\\n // See https://cs.stackexchange.com/q/138556/92363.\\n\\n // Does not overflow because the denominator cannot be zero at this stage in the function.\\n uint256 twos = denominator & (~denominator + 1);\\n assembly {\\n // Divide denominator by twos.\\n denominator := div(denominator, twos)\\n\\n // Divide [prod1 prod0] by twos.\\n prod0 := div(prod0, twos)\\n\\n // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.\\n twos := add(div(sub(0, twos), twos), 1)\\n }\\n\\n // Shift in bits from prod1 into prod0.\\n prod0 |= prod1 * twos;\\n\\n // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such\\n // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for\\n // four bits. That is, denominator * inv = 1 mod 2^4.\\n uint256 inverse = (3 * denominator) ^ 2;\\n\\n // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works\\n // in modular arithmetic, doubling the correct bits in each step.\\n inverse *= 2 - denominator * inverse; // inverse mod 2^8\\n inverse *= 2 - denominator * inverse; // inverse mod 2^16\\n inverse *= 2 - denominator * inverse; // inverse mod 2^32\\n inverse *= 2 - denominator * inverse; // inverse mod 2^64\\n inverse *= 2 - denominator * inverse; // inverse mod 2^128\\n inverse *= 2 - denominator * inverse; // inverse mod 2^256\\n\\n // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.\\n // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is\\n // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1\\n // is no longer required.\\n result = prod0 * inverse;\\n return result;\\n }\\n }\\n\\n /**\\n * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.\\n */\\n function mulDiv(\\n uint256 x,\\n uint256 y,\\n uint256 denominator,\\n Rounding rounding\\n ) internal pure returns (uint256) {\\n uint256 result = mulDiv(x, y, denominator);\\n if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {\\n result += 1;\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.\\n *\\n * Inspired by Henry S. Warren, Jr.'s \\\"Hacker's Delight\\\" (Chapter 11).\\n */\\n function sqrt(uint256 a) internal pure returns (uint256) {\\n if (a == 0) {\\n return 0;\\n }\\n\\n // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.\\n //\\n // We know that the \\\"msb\\\" (most significant bit) of our target number `a` is a power of 2 such that we have\\n // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.\\n //\\n // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`\\n // \\u2192 `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`\\n // \\u2192 `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`\\n //\\n // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.\\n uint256 result = 1 << (log2(a) >> 1);\\n\\n // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,\\n // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at\\n // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision\\n // into the expected uint128 result.\\n unchecked {\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n return min(result, a / result);\\n }\\n }\\n\\n /**\\n * @notice Calculates sqrt(a), following the selected rounding direction.\\n */\\n function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = sqrt(a);\\n return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);\\n }\\n }\\n\\n /**\\n * @dev Return the log in base 2, rounded down, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log2(uint256 value) internal pure returns (uint256) {\\n uint256 result = 0;\\n unchecked {\\n if (value >> 128 > 0) {\\n value >>= 128;\\n result += 128;\\n }\\n if (value >> 64 > 0) {\\n value >>= 64;\\n result += 64;\\n }\\n if (value >> 32 > 0) {\\n value >>= 32;\\n result += 32;\\n }\\n if (value >> 16 > 0) {\\n value >>= 16;\\n result += 16;\\n }\\n if (value >> 8 > 0) {\\n value >>= 8;\\n result += 8;\\n }\\n if (value >> 4 > 0) {\\n value >>= 4;\\n result += 4;\\n }\\n if (value >> 2 > 0) {\\n value >>= 2;\\n result += 2;\\n }\\n if (value >> 1 > 0) {\\n result += 1;\\n }\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Return the log in base 2, following the selected rounding direction, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = log2(value);\\n return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);\\n }\\n }\\n\\n /**\\n * @dev Return the log in base 10, rounded down, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log10(uint256 value) internal pure returns (uint256) {\\n uint256 result = 0;\\n unchecked {\\n if (value >= 10**64) {\\n value /= 10**64;\\n result += 64;\\n }\\n if (value >= 10**32) {\\n value /= 10**32;\\n result += 32;\\n }\\n if (value >= 10**16) {\\n value /= 10**16;\\n result += 16;\\n }\\n if (value >= 10**8) {\\n value /= 10**8;\\n result += 8;\\n }\\n if (value >= 10**4) {\\n value /= 10**4;\\n result += 4;\\n }\\n if (value >= 10**2) {\\n value /= 10**2;\\n result += 2;\\n }\\n if (value >= 10**1) {\\n result += 1;\\n }\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = log10(value);\\n return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);\\n }\\n }\\n\\n /**\\n * @dev Return the log in base 256, rounded down, of a positive value.\\n * Returns 0 if given 0.\\n *\\n * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.\\n */\\n function log256(uint256 value) internal pure returns (uint256) {\\n uint256 result = 0;\\n unchecked {\\n if (value >> 128 > 0) {\\n value >>= 128;\\n result += 16;\\n }\\n if (value >> 64 > 0) {\\n value >>= 64;\\n result += 8;\\n }\\n if (value >> 32 > 0) {\\n value >>= 32;\\n result += 4;\\n }\\n if (value >> 16 > 0) {\\n value >>= 16;\\n result += 2;\\n }\\n if (value >> 8 > 0) {\\n result += 1;\\n }\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = log256(value);\\n return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);\\n }\\n }\\n}\\n\",\"keccak256\":\"0xa1e8e83cd0087785df04ac79fb395d9f3684caeaf973d9e2c71caef723a3a5d6\",\"license\":\"MIT\"},\"src/Redistribution.sol\":{\"content\":\"// SPDX-License-Identifier: BSD-3-Clause\\npragma solidity ^0.8.19;\\nimport \\\"@openzeppelin/contracts/access/AccessControl.sol\\\";\\nimport \\\"@openzeppelin/contracts/security/Pausable.sol\\\";\\nimport \\\"./Util/TransformedChunkProof.sol\\\";\\nimport \\\"./Util/ChunkProof.sol\\\";\\nimport \\\"./Util/Signatures.sol\\\";\\nimport \\\"./interface/IPostageStamp.sol\\\";\\n\\ninterface IPriceOracle {\\n function adjustPrice(uint16 redundancy) external;\\n}\\n\\ninterface IStakeRegistry {\\n struct Stake {\\n bytes32 overlay;\\n uint256 stakeAmount;\\n uint256 lastUpdatedBlockNumber;\\n bool isValue;\\n }\\n\\n function freezeDeposit(address _owner, uint256 _time) external;\\n\\n function lastUpdatedBlockNumberOfAddress(address _owner) external view returns (uint256);\\n\\n function overlayOfAddress(address _owner) external view returns (bytes32);\\n\\n function nodeEffectiveStake(address _owner) external view returns (uint256);\\n\\n function getStakeStruct(address _owner) external view returns (Stake memory);\\n}\\n\\n/**\\n * @title Redistribution contract\\n * @author The Swarm Authors\\n * @dev Implements a Schelling Co-ordination game to form consensus around the Reserve Commitment hash. This takes\\n * place in three phases: _commit_, _reveal_ and _claim_.\\n *\\n * A node, upon establishing that it _isParticipatingInUpcomingRound_, i.e. it's overlay falls within proximity order\\n * of its reported depth with the _currentRoundAnchor_, prepares a \\\"reserve commitment hash\\\" using the chunks\\n * it currently stores in its reserve and calculates the \\\"storage depth\\\" (see Bee for details). These values, if calculated\\n * honestly, and with the right chunks stored, should be the same for every node in a neighbourhood. This is the Schelling point.\\n * Each eligible node can then use these values, together with a random, single use, secret _revealNonce_ and their\\n * _overlay_ as the pre-image values for the obsfucated _commit_, using the _wrapCommit_ method.\\n *\\n * Once the _commit_ round has elapsed, participating nodes must provide the values used to calculate their obsfucated\\n * _commit_ hash, which, once verified for correctness and proximity to the anchor are retained in the _currentReveals_.\\n * Nodes that have committed but do not reveal the correct values used to create the pre-image will have their stake\\n * \\\"frozen\\\" for a period of rounds proportional to their reported depth.\\n *\\n * During the _reveal_ round, randomness is updated after every successful reveal. Once the reveal round is concluded,\\n * the _currentRoundAnchor_ is updated and users can determine if they will be eligible their overlay will be eligible\\n * for the next commit phase using _isParticipatingInUpcomingRound_.\\n *\\n * When the _reveal_ phase has been concluded, the claim phase can begin. At this point, the truth teller and winner\\n * are already determined. By calling _isWinner_, an applicant node can run the relevant logic to determine if they have\\n * been selected as the beneficiary of this round. When calling _claim_, the current pot from the PostageStamp contract\\n * is withdrawn and transferred to that beneficiaries address. Nodes that have revealed values that differ from the truth,\\n * have their stakes \\\"frozen\\\" for a period of rounds proportional to their reported depth.\\n */\\n\\ncontract Redistribution is AccessControl, Pausable {\\n // ----------------------------- Type declarations ------------------------------\\n\\n // An eligible user may commit to an _obfuscatedHash_ during the commit phase...\\n struct Commit {\\n bytes32 overlay;\\n address owner;\\n bool revealed;\\n uint256 stake;\\n bytes32 obfuscatedHash;\\n uint256 revealIndex;\\n }\\n // ...then provide the actual values that are the constituents of the pre-image of the _obfuscatedHash_\\n // during the reveal phase.\\n struct Reveal {\\n bytes32 overlay;\\n address owner;\\n uint8 depth;\\n uint256 stake;\\n uint256 stakeDensity;\\n bytes32 hash;\\n }\\n\\n struct ChunkInclusionProof {\\n bytes32[] proofSegments;\\n bytes32 proveSegment;\\n // _RCspan is known for RC 32*32\\n\\n // Inclusion proof of transformed address\\n bytes32[] proofSegments2;\\n bytes32 proveSegment2;\\n // proveSegmentIndex2 known from deterministic random selection;\\n uint64 chunkSpan;\\n bytes32[] proofSegments3;\\n // _proveSegment3 known, is equal _proveSegment2\\n // proveSegmentIndex3 know, is equal _proveSegmentIndex2;\\n // chunkSpan2 is equal to chunkSpan (as the data is the same)\\n //\\n PostageProof postageProof;\\n SOCProof[] socProof;\\n }\\n\\n struct SOCProof {\\n address signer; // signer Ethereum address to check against\\n bytes signature;\\n bytes32 identifier; //\\n bytes32 chunkAddr; // wrapped chunk address\\n }\\n\\n struct PostageProof {\\n bytes signature;\\n bytes32 postageId;\\n uint64 index;\\n uint64 timeStamp;\\n // address signer; it is provided by the postage stamp contract\\n // bytes32 chunkAddr; it equals to the proveSegment argument\\n }\\n\\n // The address of the linked PostageStamp contract.\\n IPostageStamp public PostageContract;\\n // The address of the linked PriceOracle contract.\\n IPriceOracle public OracleContract;\\n // The address of the linked Staking contract.\\n IStakeRegistry public Stakes;\\n\\n // Commits for the current round.\\n Commit[] public currentCommits;\\n // Reveals for the current round.\\n Reveal[] public currentReveals;\\n\\n // The current anchor that being processed for the reveal and claim phases of the round.\\n bytes32 private currentRevealRoundAnchor;\\n\\n // The current random value from which we will random.\\n // inputs for selection of the truth teller and beneficiary.\\n bytes32 private seed;\\n\\n // The number of the currently active round phases.\\n uint64 public currentCommitRound;\\n uint64 public currentRevealRound;\\n uint64 public currentClaimRound;\\n\\n // Settings for slashing and freezing\\n uint8 private penaltyMultiplierDisagreement = 1;\\n uint8 private penaltyMultiplierNonRevealed = 2;\\n uint8 private penaltyRandomFactor = 100; // Use 100 as value to ignore random factor in freezing penalty\\n\\n // alpha=0.097612 beta=0.0716570 k=16\\n uint256 private sampleMaxValue = 1284401000000000000000000000000000000000000000000000000000000000000000000;\\n\\n // The reveal of the winner of the last round.\\n Reveal public winner;\\n\\n // The length of a round in blocks.\\n uint256 private constant ROUND_LENGTH = 152;\\n\\n // Maximum value of the keccack256 hash.\\n bytes32 private constant MAX_H = 0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff;\\n\\n // Role allowed to pause.\\n bytes32 private immutable PAUSER_ROLE;\\n\\n // ----------------------------- Events ------------------------------\\n\\n /**\\n * @dev Emitted when the winner of a round is selected in the claim phase\\n */\\n event WinnerSelected(Reveal winner);\\n\\n /**\\n * @dev Emitted when the truth oracle of a round is selected in the claim phase.\\n */\\n event TruthSelected(bytes32 hash, uint8 depth);\\n\\n // Next two events to be removed after testing phase pending some other usefulness being found.\\n /**\\n * @dev Emits the number of commits being processed by the claim phase.\\n */\\n event CountCommits(uint256 _count);\\n\\n /**\\n * @dev Emits the number of reveals being processed by the claim phase.\\n */\\n event CountReveals(uint256 _count);\\n\\n /**\\n * @dev Logs that an overlay has committed\\n */\\n event Committed(uint256 roundNumber, bytes32 overlay);\\n /**\\n * @dev Emit from Postagestamp contract valid chunk count at the end of claim\\n */\\n event ChunkCount(uint256 validChunkCount);\\n\\n /**\\n * @dev Bytes32 anhor of current reveal round\\n */\\n event CurrentRevealAnchor(uint256 roundNumber, bytes32 anchor);\\n\\n /**\\n * @dev Logs that an overlay has revealed\\n */\\n event Revealed(\\n uint256 roundNumber,\\n bytes32 overlay,\\n uint256 stake,\\n uint256 stakeDensity,\\n bytes32 reserveCommitment,\\n uint8 depth\\n );\\n\\n /**\\n * @dev Logs for inclusion proof\\n */\\n event transformedChunkAddressFromInclusionProof(uint256 indexInRC, bytes32 chunkAddress);\\n\\n // ----------------------------- Errors ------------------------------\\n\\n error NotCommitPhase(); // Game is not in commit phase\\n error NoCommitsReceived(); // Round didn't receive any commits\\n error PhaseLastBlock(); // We don't permit commits in last block of the phase\\n error CommitRoundOver(); // Commit phase in this round is over\\n error CommitRoundNotStarted(); // Commit phase in this round has not started yet\\n error NotMatchingOwner(); // Sender of commit is not matching the overlay address\\n error MustStake2Rounds(); // Before entering the game node must stake 2 rounds prior\\n error NotStaked(); // Node didn't add any staking\\n error WrongPhase(); // Checking in wrong phase, need to check duing claim phase of current round for next round or commit in current round\\n error AlreadyCommitted(); // Node already committed in this round\\n error NotRevealPhase(); // Game is not in reveal phase\\n error OutOfDepthReveal(bytes32); // Anchor is out of reported depth in Reveal phase, anchor data available as argument\\n error OutOfDepthClaim(uint8); // Anchor is out of reported depth in Claim phase, entryProof index is argument\\n error OutOfDepth(); // Anchor is out of reported depth\\n error AlreadyRevealed(); // Node already revealed\\n error NoMatchingCommit(); // No matching commit and hash\\n error NotClaimPhase(); // Game is not in the claim phase\\n error NoReveals(); // Round did not receive any reveals\\n error FirstRevealDone(); // We don't want to return value after first reveal\\n error AlreadyClaimed(); // This round was already claimed\\n error NotAdmin(); // Caller of trx is not admin\\n error OnlyPauser(); // Only account with pauser role can call pause/unpause\\n error SocVerificationFailed(bytes32); // Soc verification failed for this element\\n error SocCalcNotMatching(bytes32); // Soc address calculation does not match with the witness\\n error IndexOutsideSet(bytes32); // Stamp available: index resides outside of the valid index set\\n error SigRecoveryFailed(bytes32); // Stamp authorized: signature recovery failed for element\\n error BatchDoesNotExist(bytes32); // Stamp alive: batch remaining balance validation failed for attached stamp\\n error BucketDiffers(bytes32); // Stamp aligned: postage bucket differs from address bucket\\n error InclusionProofFailed(uint8, bytes32);\\n // 1 = RC inclusion proof failed for element\\n // 2 = First sister segment in data must match,\\n // 3 = Inclusion proof failed for original address of element\\n // 4 = Inclusion proof failed for transformed address of element\\n error RandomElementCheckFailed(); // Random element order check failed\\n error LastElementCheckFailed(); // Last element order check failed\\n error ReserveCheckFailed(bytes32 trALast); // Reserve size estimation check failed\\n\\n // ----------------------------- CONSTRUCTOR ------------------------------\\n\\n /**\\n * @param staking the address of the linked Staking contract.\\n * @param postageContract the address of the linked PostageStamp contract.\\n * @param oracleContract the address of the linked PriceOracle contract.\\n */\\n constructor(address staking, address postageContract, address oracleContract) {\\n Stakes = IStakeRegistry(staking);\\n PostageContract = IPostageStamp(postageContract);\\n OracleContract = IPriceOracle(oracleContract);\\n PAUSER_ROLE = keccak256(\\\"PAUSER_ROLE\\\");\\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\\n _setupRole(PAUSER_ROLE, msg.sender);\\n }\\n\\n ////////////////////////////////////////\\n // STATE CHANGING //\\n ////////////////////////////////////////\\n\\n /**\\n * @notice Begin application for a round if eligible. Commit a hashed value for which the pre-image will be\\n * subsequently revealed.\\n * @dev If a node's overlay is _inProximity_(_depth_) of the _currentRoundAnchor_, that node may compute an\\n * _obfuscatedHash_ by providing their _overlay_, reported storage _depth_, reserve commitment _hash_ and a\\n * randomly generated, and secret _revealNonce_ to the _wrapCommit_ method.\\n * @param _obfuscatedHash The calculated hash resultant of the required pre-image values.\\n * and be derived from the same key pair as the message sender.\\n * @param _roundNumber Node needs to provide round number for which commit is valid\\n */\\n function commit(bytes32 _obfuscatedHash, uint64 _roundNumber) external whenNotPaused {\\n uint64 cr = currentRound();\\n bytes32 _overlay = Stakes.overlayOfAddress(msg.sender);\\n uint256 _stake = Stakes.nodeEffectiveStake(msg.sender);\\n uint256 _lastUpdate = Stakes.lastUpdatedBlockNumberOfAddress(msg.sender);\\n\\n if (!currentPhaseCommit()) {\\n revert NotCommitPhase();\\n }\\n if (block.number % ROUND_LENGTH == (ROUND_LENGTH / 4) - 1) {\\n revert PhaseLastBlock();\\n }\\n\\n if (cr > _roundNumber) {\\n revert CommitRoundOver();\\n }\\n\\n if (cr < _roundNumber) {\\n revert CommitRoundNotStarted();\\n }\\n\\n if (_lastUpdate == 0) {\\n revert NotStaked();\\n }\\n\\n if (_lastUpdate >= block.number - 2 * ROUND_LENGTH) {\\n revert MustStake2Rounds();\\n }\\n\\n // if we are in a new commit phase, reset the array of commits and\\n // set the currentCommitRound to be the current one\\n if (cr != currentCommitRound) {\\n delete currentCommits;\\n currentCommitRound = cr;\\n }\\n\\n uint256 commitsArrayLength = currentCommits.length;\\n\\n for (uint256 i = 0; i < commitsArrayLength; ) {\\n if (currentCommits[i].overlay == _overlay) {\\n revert AlreadyCommitted();\\n }\\n\\n unchecked {\\n ++i;\\n }\\n }\\n\\n currentCommits.push(\\n Commit({\\n overlay: _overlay,\\n owner: msg.sender,\\n revealed: false,\\n stake: _stake,\\n obfuscatedHash: _obfuscatedHash,\\n revealIndex: 0\\n })\\n );\\n\\n emit Committed(_roundNumber, _overlay);\\n }\\n\\n /**\\n * @notice Reveal the pre-image values used to generate commit provided during this round's commit phase.\\n * @param _depth The reported depth.\\n * @param _hash The reserve commitment hash.\\n * @param _revealNonce The nonce used to generate the commit that is being revealed.\\n */\\n function reveal(uint8 _depth, bytes32 _hash, bytes32 _revealNonce) external whenNotPaused {\\n uint64 cr = currentRound();\\n bytes32 _overlay = Stakes.overlayOfAddress(msg.sender);\\n\\n if (_depth < currentMinimumDepth()) {\\n revert OutOfDepth();\\n }\\n\\n if (!currentPhaseReveal()) {\\n revert NotRevealPhase();\\n }\\n\\n if (cr != currentCommitRound) {\\n revert NoCommitsReceived();\\n }\\n\\n if (cr != currentRevealRound) {\\n currentRevealRoundAnchor = currentRoundAnchor();\\n delete currentReveals;\\n // We set currentRevealRound ONLY after we set current anchor\\n currentRevealRound = cr;\\n emit CurrentRevealAnchor(cr, currentRevealRoundAnchor);\\n updateRandomness();\\n }\\n\\n bytes32 obfuscatedHash = wrapCommit(_overlay, _depth, _hash, _revealNonce);\\n uint256 id = findCommit(_overlay, obfuscatedHash);\\n Commit memory revealedCommit = currentCommits[id];\\n\\n // Check that commit is in proximity of the current anchor\\n if (!inProximity(revealedCommit.overlay, currentRevealRoundAnchor, _depth)) {\\n revert OutOfDepthReveal(currentRevealRoundAnchor);\\n }\\n // Check that the commit has not already been revealed\\n if (revealedCommit.revealed) {\\n revert AlreadyRevealed();\\n }\\n\\n currentCommits[id].revealed = true;\\n currentCommits[id].revealIndex = currentReveals.length;\\n\\n currentReveals.push(\\n Reveal({\\n overlay: revealedCommit.overlay,\\n owner: revealedCommit.owner,\\n depth: _depth,\\n stake: revealedCommit.stake,\\n stakeDensity: revealedCommit.stake * uint256(2 ** _depth),\\n hash: _hash\\n })\\n );\\n\\n emit Revealed(\\n cr,\\n revealedCommit.overlay,\\n revealedCommit.stake,\\n revealedCommit.stake * uint256(2 ** _depth),\\n _hash,\\n _depth\\n );\\n }\\n\\n /**\\n * @notice Helper function to get this round truth\\n * @dev\\n */\\n function claim(\\n ChunkInclusionProof calldata entryProof1,\\n ChunkInclusionProof calldata entryProof2,\\n ChunkInclusionProof calldata entryProofLast\\n ) external whenNotPaused {\\n winnerSelection();\\n\\n Reveal memory winnerSelected = winner;\\n uint256 indexInRC1;\\n uint256 indexInRC2;\\n bytes32 _currentRevealRoundAnchor = currentRevealRoundAnchor;\\n bytes32 _seed = seed;\\n\\n // rand(14)\\n indexInRC1 = uint256(_seed) % 15;\\n // rand(13)\\n indexInRC2 = uint256(_seed) % 14;\\n if (indexInRC2 >= indexInRC1) {\\n indexInRC2++;\\n }\\n\\n if (!inProximity(entryProofLast.proveSegment, _currentRevealRoundAnchor, winnerSelected.depth)) {\\n revert OutOfDepthClaim(3);\\n }\\n\\n inclusionFunction(entryProofLast, 30);\\n stampFunction(entryProofLast);\\n socFunction(entryProofLast);\\n\\n if (!inProximity(entryProof1.proveSegment, _currentRevealRoundAnchor, winnerSelected.depth)) {\\n revert OutOfDepthClaim(2);\\n }\\n\\n inclusionFunction(entryProof1, indexInRC1 * 2);\\n stampFunction(entryProof1);\\n socFunction(entryProof1);\\n\\n if (!inProximity(entryProof2.proveSegment, _currentRevealRoundAnchor, winnerSelected.depth)) {\\n revert OutOfDepthClaim(1);\\n }\\n\\n inclusionFunction(entryProof2, indexInRC2 * 2);\\n stampFunction(entryProof2);\\n socFunction(entryProof2);\\n\\n checkOrder(\\n indexInRC1,\\n indexInRC2,\\n entryProof1.proofSegments[0],\\n entryProof2.proofSegments[0],\\n entryProofLast.proofSegments[0]\\n );\\n\\n estimateSize(entryProofLast.proofSegments[0]);\\n\\n PostageContract.withdraw(winnerSelected.owner);\\n emit WinnerSelected(winnerSelected);\\n emit ChunkCount(PostageContract.validChunkCount());\\n }\\n\\n function winnerSelection() internal {\\n uint64 cr = currentRound();\\n\\n if (!currentPhaseClaim()) {\\n revert NotClaimPhase();\\n }\\n\\n if (cr != currentRevealRound) {\\n revert NoReveals();\\n }\\n\\n if (cr <= currentClaimRound) {\\n revert AlreadyClaimed();\\n }\\n\\n uint256 currentWinnerSelectionSum = 0;\\n uint256 redundancyCount = 0;\\n bytes32 randomNumber;\\n uint256 randomNumberTrunc;\\n\\n bytes32 truthRevealedHash;\\n uint8 truthRevealedDepth;\\n uint256 currentCommitsLength = currentCommits.length;\\n\\n emit CountCommits(currentCommitsLength);\\n emit CountReveals(currentReveals.length);\\n\\n (truthRevealedHash, truthRevealedDepth) = getCurrentTruth();\\n emit TruthSelected(truthRevealedHash, truthRevealedDepth);\\n string memory winnerSelectionAnchor = currentWinnerSelectionAnchor();\\n\\n for (uint256 i = 0; i < currentCommitsLength; ) {\\n Commit memory currentCommit = currentCommits[i];\\n uint256 revIndex = currentCommit.revealIndex;\\n Reveal memory currentReveal = currentReveals[revIndex];\\n\\n // Select winner with valid truth\\n if (\\n currentCommit.revealed &&\\n truthRevealedHash == currentReveal.hash &&\\n truthRevealedDepth == currentReveal.depth\\n ) {\\n currentWinnerSelectionSum += currentReveal.stakeDensity;\\n randomNumber = keccak256(abi.encodePacked(winnerSelectionAnchor, redundancyCount));\\n randomNumberTrunc = uint256(randomNumber & MAX_H);\\n\\n if (randomNumberTrunc * currentWinnerSelectionSum < currentReveal.stakeDensity * (uint256(MAX_H) + 1)) {\\n winner = currentReveal;\\n }\\n\\n redundancyCount++;\\n }\\n\\n // Freeze deposit if any truth is false, make it a penaltyRandomFactor chance for this to happen\\n if (\\n currentCommit.revealed &&\\n (truthRevealedHash != currentReveal.hash || truthRevealedDepth != currentReveal.depth) &&\\n (block.prevrandao % 100 < penaltyRandomFactor)\\n ) {\\n Stakes.freezeDeposit(\\n currentReveal.owner,\\n penaltyMultiplierDisagreement * ROUND_LENGTH * uint256(2 ** truthRevealedDepth)\\n );\\n }\\n\\n // Slash deposits if revealed is false\\n if (!currentCommit.revealed) {\\n // slash in later phase (ph5)\\n // Stakes.slashDeposit(currentCommits[i].overlay, currentCommits[i].stake);\\n Stakes.freezeDeposit(\\n currentCommit.owner,\\n penaltyMultiplierNonRevealed * ROUND_LENGTH * uint256(2 ** truthRevealedDepth)\\n );\\n }\\n unchecked {\\n ++i;\\n }\\n }\\n\\n OracleContract.adjustPrice(uint16(redundancyCount));\\n currentClaimRound = cr;\\n }\\n\\n function inclusionFunction(ChunkInclusionProof calldata entryProof, uint256 indexInRC) internal {\\n uint256 randomChunkSegmentIndex = uint256(seed) % 128;\\n bytes32 calculatedTransformedAddr = TransformedBMTChunk.transformedChunkAddressFromInclusionProof(\\n entryProof.proofSegments3,\\n entryProof.proveSegment2,\\n randomChunkSegmentIndex,\\n entryProof.chunkSpan,\\n currentRevealRoundAnchor\\n );\\n\\n emit transformedChunkAddressFromInclusionProof(indexInRC, calculatedTransformedAddr);\\n\\n if (\\n winner.hash !=\\n BMTChunk.chunkAddressFromInclusionProof(\\n entryProof.proofSegments,\\n entryProof.proveSegment,\\n indexInRC,\\n 32 * 32\\n )\\n ) {\\n revert InclusionProofFailed(1, calculatedTransformedAddr);\\n }\\n\\n if (entryProof.proofSegments2[0] != entryProof.proofSegments3[0]) {\\n revert InclusionProofFailed(2, calculatedTransformedAddr);\\n }\\n\\n bytes32 originalAddress = entryProof.socProof.length > 0\\n ? entryProof.socProof[0].chunkAddr // soc attestation in socFunction\\n : entryProof.proveSegment;\\n\\n if (\\n originalAddress !=\\n BMTChunk.chunkAddressFromInclusionProof(\\n entryProof.proofSegments2,\\n entryProof.proveSegment2,\\n randomChunkSegmentIndex,\\n entryProof.chunkSpan\\n )\\n ) {\\n revert InclusionProofFailed(3, calculatedTransformedAddr);\\n }\\n\\n // In case of SOC, the transformed address is hashed together with its address in the sample\\n if (entryProof.socProof.length > 0) {\\n calculatedTransformedAddr = keccak256(\\n abi.encode(\\n entryProof.proveSegment, // SOC address\\n calculatedTransformedAddr\\n )\\n );\\n }\\n\\n if (entryProof.proofSegments[0] != calculatedTransformedAddr) {\\n revert InclusionProofFailed(4, calculatedTransformedAddr);\\n }\\n }\\n\\n /**\\n * @notice Set freezing parameters\\n */\\n function setFreezingParams(\\n uint8 _penaltyMultiplierDisagreement,\\n uint8 _penaltyMultiplierNonRevealed,\\n uint8 _penaltyRandomFactor\\n ) external {\\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\\n revert NotAdmin();\\n }\\n\\n penaltyMultiplierDisagreement = _penaltyMultiplierDisagreement;\\n penaltyMultiplierNonRevealed = _penaltyMultiplierNonRevealed;\\n penaltyRandomFactor = _penaltyRandomFactor;\\n }\\n\\n /**\\n * @notice changes the max sample value used for reserve estimation\\n */\\n function setSampleMaxValue(uint256 _sampleMaxValue) external {\\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\\n revert NotAdmin();\\n }\\n\\n sampleMaxValue = _sampleMaxValue;\\n }\\n\\n /**\\n * @notice Updates the source of randomness. Uses block.difficulty in pre-merge chains, this is substituted\\n * to block.prevrandao in post merge chains.\\n */\\n function updateRandomness() private {\\n seed = keccak256(abi.encode(seed, block.prevrandao));\\n }\\n\\n /**\\n * @dev Pause the contract. The contract is provably stopped by renouncing\\n the pauser role and the admin role after pausing, can only be called by the `PAUSER`\\n */\\n function pause() public {\\n if (!hasRole(PAUSER_ROLE, msg.sender)) {\\n revert OnlyPauser();\\n }\\n\\n _pause();\\n }\\n\\n /**\\n * @dev Unpause the contract, can only be called by the pauser when paused\\n */\\n function unPause() public {\\n if (!hasRole(PAUSER_ROLE, msg.sender)) {\\n revert OnlyPauser();\\n }\\n _unpause();\\n }\\n\\n ////////////////////////////////////////\\n // STATE READING //\\n ////////////////////////////////////////\\n\\n // ----------------------------- Anchor calculations ------------------------------\\n\\n /**\\n * @notice Returns the current random seed which is used to determine later utilised random numbers.\\n * If rounds have elapsed without reveals, hash the seed with an incremented nonce to produce a new\\n * random seed and hence a new round anchor.\\n */\\n function currentSeed() public view returns (bytes32) {\\n uint64 cr = currentRound();\\n bytes32 currentSeedValue = seed;\\n\\n if (cr > currentRevealRound + 1) {\\n uint256 difference = cr - currentRevealRound - 1;\\n currentSeedValue = keccak256(abi.encodePacked(currentSeedValue, difference));\\n }\\n\\n return currentSeedValue;\\n }\\n\\n /**\\n * @notice Returns the seed which will become current once the next commit phase begins.\\n * Used to determine what the next round's anchor will be.\\n */\\n function nextSeed() public view returns (bytes32) {\\n uint64 cr = currentRound() + 1;\\n bytes32 currentSeedValue = seed;\\n\\n if (cr > currentRevealRound + 1) {\\n uint256 difference = cr - currentRevealRound - 1;\\n currentSeedValue = keccak256(abi.encodePacked(currentSeedValue, difference));\\n }\\n\\n return currentSeedValue;\\n }\\n\\n /**\\n * @notice The random value used to choose the selected truth teller.\\n */\\n function currentTruthSelectionAnchor() private view returns (string memory) {\\n if (!currentPhaseClaim()) {\\n revert NotClaimPhase();\\n }\\n\\n uint64 cr = currentRound();\\n if (cr != currentRevealRound) {\\n revert NoReveals();\\n }\\n\\n return string(abi.encodePacked(seed, \\\"0\\\"));\\n }\\n\\n /**\\n * @notice The random value used to choose the selected beneficiary.\\n */\\n function currentWinnerSelectionAnchor() private view returns (string memory) {\\n if (!currentPhaseClaim()) {\\n revert NotClaimPhase();\\n }\\n uint64 cr = currentRound();\\n if (cr != currentRevealRound) {\\n revert NoReveals();\\n }\\n\\n return string(abi.encodePacked(seed, \\\"1\\\"));\\n }\\n\\n /**\\n * @notice The anchor used to determine eligibility for the current round.\\n * @dev A node must be within proximity order of less than or equal to the storage depth they intend to report.\\n */\\n function currentRoundAnchor() public view returns (bytes32 returnVal) {\\n // This will be called in reveal phase and set as currentRevealRoundAnchor or in\\n // commit phase when checking eligibility for next round by isParticipatingInUpcomingRound\\n if (currentPhaseCommit() || (currentRound() > currentRevealRound && !currentPhaseClaim())) {\\n return currentSeed();\\n }\\n\\n // This will be called by isParticipatingInUpcomingRound check in claim phase\\n if (currentPhaseClaim()) {\\n return nextSeed();\\n }\\n\\n // Without this, this function will output 0x0 after first reveal which is value and we prefere it reverts\\n if (currentPhaseReveal() && currentRound() == currentRevealRound) {\\n revert FirstRevealDone();\\n }\\n }\\n\\n /**\\n * @notice Returns true if an overlay address _A_ is within proximity order _minimum_ of _B_.\\n * @param A An overlay address to compare.\\n * @param B An overlay address to compare.\\n * @param minimum Minimum proximity order.\\n */\\n function inProximity(bytes32 A, bytes32 B, uint8 minimum) public pure returns (bool) {\\n if (minimum == 0) {\\n return true;\\n }\\n\\n return uint256(A ^ B) < uint256(2 ** (256 - minimum));\\n }\\n\\n // ----------------------------- Commit ------------------------------\\n\\n /**\\n * @notice The number of the current round.\\n */\\n function currentRound() public view returns (uint64) {\\n return uint64(block.number / ROUND_LENGTH);\\n }\\n\\n /**\\n * @notice Returns true if current block is during commit phase.\\n */\\n function currentPhaseCommit() public view returns (bool) {\\n if (block.number % ROUND_LENGTH < ROUND_LENGTH / 4) {\\n return true;\\n }\\n return false;\\n }\\n\\n /**\\n * @notice Determine if a the owner of a given overlay can participate in the upcoming round.\\n * @param _owner The address of the applicant from.\\n * @param _depth The storage depth the applicant intends to report.\\n */\\n function isParticipatingInUpcomingRound(address _owner, uint8 _depth) public view returns (bool) {\\n if (currentPhaseReveal()) {\\n revert WrongPhase();\\n }\\n\\n if (Stakes.lastUpdatedBlockNumberOfAddress(_owner) >= block.number - 2 * ROUND_LENGTH) {\\n revert MustStake2Rounds();\\n }\\n\\n return inProximity(Stakes.overlayOfAddress(_owner), currentRoundAnchor(), _depth);\\n }\\n\\n // ----------------------------- Reveal ------------------------------\\n\\n /**\\n * @notice Returns minimum depth reveal has to have to participate in this round\\n */\\n function currentMinimumDepth() public view returns (uint8) {\\n // We are checking value in reveal phase, as the currentCommitRound is set to the current round\\n // but the currentClaimRound is still set to the last time claim was made\\n // We add 1 to ensure that for the next round the minimum depth is the same as last winner depth\\n\\n uint256 difference = currentCommitRound - currentClaimRound;\\n uint8 skippedRounds = uint8(difference > 254 ? 254 : difference) + 1;\\n\\n uint8 lastWinnerDepth = winner.depth;\\n\\n // We ensure that skippedRounds is not bigger than lastWinnerDepth, because of overflow\\n return skippedRounds >= lastWinnerDepth ? 0 : lastWinnerDepth - skippedRounds;\\n }\\n\\n /**\\n * @notice Helper function to get this node reveal in commits\\n * @dev\\n */\\n function findCommit(bytes32 _overlay, bytes32 _obfuscatedHash) internal view returns (uint256) {\\n for (uint256 i = 0; i < currentCommits.length; ) {\\n if (currentCommits[i].overlay == _overlay && _obfuscatedHash == currentCommits[i].obfuscatedHash) {\\n return i;\\n }\\n unchecked {\\n ++i;\\n }\\n }\\n revert NoMatchingCommit();\\n }\\n\\n /**\\n * @notice Hash the pre-image values to the obsfucated hash.\\n * @dev _revealNonce_ must be randomly generated, used once and kept secret until the reveal phase.\\n * @param _overlay The overlay address of the applicant.\\n * @param _depth The reported depth.\\n * @param _hash The reserve commitment hash.\\n * @param revealNonce A random, single use, secret nonce.\\n */\\n function wrapCommit(\\n bytes32 _overlay,\\n uint8 _depth,\\n bytes32 _hash,\\n bytes32 revealNonce\\n ) public pure returns (bytes32) {\\n return keccak256(abi.encodePacked(_overlay, _depth, _hash, revealNonce));\\n }\\n\\n /**\\n * @notice Returns true if current block is during reveal phase.\\n */\\n function currentPhaseReveal() public view returns (bool) {\\n uint256 number = block.number % ROUND_LENGTH;\\n if (number >= ROUND_LENGTH / 4 && number < ROUND_LENGTH / 2) {\\n return true;\\n }\\n return false;\\n }\\n\\n /**\\n * @notice Returns true if current block is during reveal phase.\\n */\\n function currentRoundReveals() public view returns (Reveal[] memory) {\\n if (!currentPhaseClaim()) {\\n revert NotClaimPhase();\\n }\\n uint64 cr = currentRound();\\n if (cr != currentRevealRound) {\\n revert NoReveals();\\n }\\n\\n return currentReveals;\\n }\\n\\n // ----------------------------- Claim ------------------------------\\n\\n /**\\n * @notice Returns true if current block is during claim phase.\\n */\\n function currentPhaseClaim() public view returns (bool) {\\n if (block.number % ROUND_LENGTH >= ROUND_LENGTH / 2) {\\n return true;\\n }\\n return false;\\n }\\n\\n function getCurrentTruth() internal view returns (bytes32 Hash, uint8 Depth) {\\n uint256 currentSum;\\n bytes32 randomNumber;\\n uint256 randomNumberTrunc;\\n\\n bytes32 truthRevealedHash;\\n uint8 truthRevealedDepth;\\n uint256 revIndex;\\n string memory truthSelectionAnchor = currentTruthSelectionAnchor();\\n uint256 commitsArrayLength = currentCommits.length;\\n\\n for (uint256 i = 0; i < commitsArrayLength; ) {\\n if (currentCommits[i].revealed) {\\n revIndex = currentCommits[i].revealIndex;\\n currentSum += currentReveals[revIndex].stakeDensity;\\n randomNumber = keccak256(abi.encodePacked(truthSelectionAnchor, i));\\n randomNumberTrunc = uint256(randomNumber & MAX_H);\\n\\n // question is whether randomNumber / MAX_H < probability\\n // where probability is stakeDensity / currentSum\\n // to avoid resorting to floating points all divisions should be\\n // simplified with multiplying both sides (as long as divisor > 0)\\n // randomNumber / (MAX_H + 1) < stakeDensity / currentSum\\n // ( randomNumber / (MAX_H + 1) ) * currentSum < stakeDensity\\n // randomNumber * currentSum < stakeDensity * (MAX_H + 1)\\n if (randomNumberTrunc * currentSum < currentReveals[revIndex].stakeDensity * (uint256(MAX_H) + 1)) {\\n truthRevealedHash = currentReveals[revIndex].hash;\\n truthRevealedDepth = currentReveals[revIndex].depth;\\n }\\n }\\n unchecked {\\n ++i;\\n }\\n }\\n\\n return (truthRevealedHash, truthRevealedDepth);\\n }\\n\\n /**\\n * @notice Determine if a the owner of a given overlay will be the beneficiary of the claim phase.\\n * @param _overlay The overlay address of the applicant.\\n */\\n function isWinner(bytes32 _overlay) public view returns (bool) {\\n if (!currentPhaseClaim()) {\\n revert NotClaimPhase();\\n }\\n\\n uint64 cr = currentRound();\\n if (cr != currentRevealRound) {\\n revert NoReveals();\\n }\\n\\n if (cr <= currentClaimRound) {\\n revert AlreadyClaimed();\\n }\\n\\n uint256 currentWinnerSelectionSum;\\n bytes32 winnerIs;\\n bytes32 randomNumber;\\n uint256 randomNumberTrunc;\\n bytes32 truthRevealedHash;\\n uint8 truthRevealedDepth;\\n uint256 revIndex;\\n string memory winnerSelectionAnchor = currentWinnerSelectionAnchor();\\n uint256 redundancyCount = 0;\\n\\n // Get current truth\\n (truthRevealedHash, truthRevealedDepth) = getCurrentTruth();\\n uint256 commitsArrayLength = currentCommits.length;\\n\\n for (uint256 i = 0; i < commitsArrayLength; ) {\\n revIndex = currentCommits[i].revealIndex;\\n\\n // Deterministically read winner\\n if (\\n currentCommits[i].revealed &&\\n truthRevealedHash == currentReveals[revIndex].hash &&\\n truthRevealedDepth == currentReveals[revIndex].depth\\n ) {\\n currentWinnerSelectionSum += currentReveals[revIndex].stakeDensity;\\n randomNumber = keccak256(abi.encodePacked(winnerSelectionAnchor, redundancyCount));\\n randomNumberTrunc = uint256(randomNumber & MAX_H);\\n\\n if (\\n randomNumberTrunc * currentWinnerSelectionSum <\\n currentReveals[revIndex].stakeDensity * (uint256(MAX_H) + 1)\\n ) {\\n winnerIs = currentReveals[revIndex].overlay;\\n }\\n\\n redundancyCount++;\\n }\\n unchecked {\\n ++i;\\n }\\n }\\n\\n return (winnerIs == _overlay);\\n }\\n\\n // ----------------------------- Claim verifications ------------------------------\\n\\n function socFunction(ChunkInclusionProof calldata entryProof) internal pure {\\n if (entryProof.socProof.length == 0) return;\\n\\n if (\\n !Signatures.socVerify(\\n entryProof.socProof[0].signer, // signer Ethereum address to check against\\n entryProof.socProof[0].signature,\\n entryProof.socProof[0].identifier,\\n entryProof.socProof[0].chunkAddr\\n )\\n ) {\\n revert SocVerificationFailed(entryProof.socProof[0].chunkAddr);\\n }\\n\\n if (\\n calculateSocAddress(entryProof.socProof[0].identifier, entryProof.socProof[0].signer) !=\\n entryProof.proveSegment\\n ) {\\n revert SocCalcNotMatching(entryProof.socProof[0].chunkAddr);\\n }\\n }\\n\\n function stampFunction(ChunkInclusionProof calldata entryProof) internal view {\\n // authentic\\n (address batchOwner, uint8 batchDepth, uint8 bucketDepth, , , ) = PostageContract.batches(\\n entryProof.postageProof.postageId\\n );\\n\\n // alive\\n if (batchOwner == address(0)) {\\n revert BatchDoesNotExist(entryProof.postageProof.postageId); // Batch does not exist or expired\\n }\\n\\n uint32 postageIndex = getPostageIndex(entryProof.postageProof.index);\\n uint256 maxPostageIndex = postageStampIndexCount(batchDepth, bucketDepth);\\n // available\\n if (postageIndex >= maxPostageIndex) {\\n revert IndexOutsideSet(entryProof.postageProof.postageId);\\n }\\n\\n // aligned\\n uint64 postageBucket = getPostageBucket(entryProof.postageProof.index);\\n uint64 addressBucket = addressToBucket(entryProof.proveSegment, bucketDepth);\\n if (postageBucket != addressBucket) {\\n revert BucketDiffers(entryProof.postageProof.postageId);\\n }\\n\\n // authorized\\n if (\\n !Signatures.postageVerify(\\n batchOwner,\\n entryProof.postageProof.signature,\\n entryProof.proveSegment,\\n entryProof.postageProof.postageId,\\n entryProof.postageProof.index,\\n entryProof.postageProof.timeStamp\\n )\\n ) {\\n revert SigRecoveryFailed(entryProof.postageProof.postageId);\\n }\\n }\\n\\n function addressToBucket(bytes32 swarmAddress, uint8 bucketDepth) internal pure returns (uint32) {\\n uint32 prefix = uint32(uint256(swarmAddress) >> (256 - 32));\\n return prefix >> (32 - bucketDepth);\\n }\\n\\n function postageStampIndexCount(uint8 postageDepth, uint8 bucketDepth) internal pure returns (uint256) {\\n return 1 << (postageDepth - bucketDepth);\\n }\\n\\n function getPostageIndex(uint64 signedIndex) internal pure returns (uint32) {\\n return uint32(signedIndex);\\n }\\n\\n function getPostageBucket(uint64 signedIndex) internal pure returns (uint64) {\\n return uint32(signedIndex >> 32);\\n }\\n\\n function calculateSocAddress(bytes32 identifier, address signer) internal pure returns (bytes32) {\\n return keccak256(abi.encodePacked(identifier, signer));\\n }\\n\\n function checkOrder(uint256 a, uint256 b, bytes32 trA1, bytes32 trA2, bytes32 trALast) internal pure {\\n if (a < b) {\\n if (uint256(trA1) >= uint256(trA2)) {\\n revert RandomElementCheckFailed();\\n }\\n if (uint256(trA2) >= uint256(trALast)) {\\n revert LastElementCheckFailed();\\n }\\n } else {\\n if (uint256(trA2) >= uint256(trA1)) {\\n revert RandomElementCheckFailed();\\n }\\n if (uint256(trA1) >= uint256(trALast)) {\\n revert LastElementCheckFailed();\\n }\\n }\\n }\\n\\n function estimateSize(bytes32 trALast) internal view {\\n if (uint256(trALast) >= sampleMaxValue) {\\n revert ReserveCheckFailed(trALast);\\n }\\n }\\n}\\n\",\"keccak256\":\"0x9e9eea17eeafb783aa8e8c0c97e66a9c58571cb6683f73565c28b6b5e99c505d\",\"license\":\"BSD-3-Clause\"},\"src/Util/ChunkProof.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\npragma solidity ^0.8.19;\\n\\nlibrary BMTChunk {\\n // max chunk payload size\\n uint256 public constant MAX_CHUNK_PAYLOAD_SIZE = 4096;\\n // segment byte size\\n uint256 public constant SEGMENT_SIZE = 32;\\n\\n /**\\n * @notice Changes the endianness of a uint64.\\n * @dev https://graphics.stanford.edu/~seander/bithacks.html#ReverseParallel\\n * @param _b The unsigned integer to reverse\\n * @return v - The reversed value\\n */\\n function reverseUint64(uint64 _b) public pure returns (uint64) {\\n uint256 v = _b;\\n\\n // swap bytes\\n v =\\n ((v >> 8) & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) |\\n ((v & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) << 8);\\n // swap 2-byte long pairs\\n v =\\n ((v >> 16) & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) |\\n ((v & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) << 16);\\n // swap 4-byte long pairs\\n v =\\n ((v >> 32) & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) |\\n ((v & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) << 32);\\n\\n return uint64(v);\\n }\\n\\n /** Calculates the root hash from the provided inclusion proof segments and its corresponding segment index\\n * @param _proofSegments Proof segments.\\n * @param _proveSegment Segment to prove.\\n * @param _proveSegmentIndex Prove segment index\\n * @return _calculatedHash chunk hash\\n */\\n function rootHashFromInclusionProof(\\n bytes32[] memory _proofSegments,\\n bytes32 _proveSegment,\\n uint256 _proveSegmentIndex\\n ) internal pure returns (bytes32 _calculatedHash) {\\n _calculatedHash = _proveSegment;\\n for (uint256 i = 0; i < _proofSegments.length; i++) {\\n bool mergeFromRight = _proveSegmentIndex % 2 == 0;\\n _calculatedHash = mergeSegment(_calculatedHash, _proofSegments[i], mergeFromRight);\\n _proveSegmentIndex >>= 1;\\n }\\n return _calculatedHash;\\n }\\n\\n /**\\n * Calculate the chunk address from the Binary Merkle Tree of the chunk data\\n *\\n * The BMT chunk address is the hash of the 8 byte span and the root\\n * hash of a binary Merkle tree (BMT) built on the 32-byte segments\\n * of the underlying data.\\n * @param _proofSegments Proof segments.\\n * @param _proveSegment Segment to prove.\\n * @param _proveSegmentIndex Prove segment index\\n * @param _chunkSpan chunk bytes length\\n * @return _chunkHash chunk hash\\n */\\n function chunkAddressFromInclusionProof(\\n bytes32[] memory _proofSegments,\\n bytes32 _proveSegment,\\n uint256 _proveSegmentIndex,\\n uint64 _chunkSpan\\n ) internal pure returns (bytes32) {\\n bytes32 rootHash = rootHashFromInclusionProof(_proofSegments, _proveSegment, _proveSegmentIndex);\\n return keccak256(abi.encodePacked(reverseUint64(_chunkSpan), rootHash));\\n }\\n\\n function mergeSegment(\\n bytes32 _calculatedHash,\\n bytes32 _proofSegment,\\n bool mergeFromRight\\n ) internal pure returns (bytes32 res) {\\n if (mergeFromRight) {\\n res = keccak256(abi.encode(_calculatedHash, _proofSegment));\\n } else {\\n res = keccak256(abi.encode(_proofSegment, _calculatedHash));\\n }\\n return res;\\n }\\n}\\n\",\"keccak256\":\"0xe4a86f2002b8b8fc4c955537d6b80ba42fb04a816e783ddbd05f0484b013938a\",\"license\":\"MIT\"},\"src/Util/Signatures.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\npragma solidity ^0.8.19;\\n\\nlibrary Signatures {\\n error InvalidSignatureLength();\\n\\n /** Hash of the message to sign */\\n function getPostageMessageHash(\\n bytes32 _chunkAddr,\\n bytes32 _batchId,\\n uint64 _index,\\n uint64 _timeStamp\\n ) internal pure returns (bytes32) {\\n return keccak256(abi.encodePacked(_chunkAddr, _batchId, _index, _timeStamp));\\n }\\n\\n function postageVerify(\\n address _signer, // signer Ethereum address to check against\\n bytes memory _signature,\\n bytes32 _chunkAddr,\\n bytes32 _postageId,\\n uint64 _index,\\n uint64 _timeStamp\\n ) internal pure returns (bool) {\\n bytes32 messageHash = getPostageMessageHash(_chunkAddr, _postageId, _index, _timeStamp);\\n bytes32 ethMessageHash = getEthSignedMessageHash(messageHash);\\n\\n return recoverSigner(ethMessageHash, _signature) == _signer;\\n }\\n\\n function getEthSignedMessageHash(bytes32 _messageHash) internal pure returns (bytes32) {\\n /*\\n Signature is produced by signing a keccak256 hash with the following format:\\n \\\"\\\\x19Ethereum Signed Message\\\\n\\\" + len(msg) + msg\\n */\\n return keccak256(abi.encodePacked(\\\"\\\\x19Ethereum Signed Message:\\\\n32\\\", _messageHash));\\n }\\n\\n function recoverSigner(\\n bytes32 _ethSignedMessageHash, // it has to be prefixed message: https://ethereum.stackexchange.com/questions/19582/does-ecrecover-in-solidity-expects-the-x19ethereum-signed-message-n-prefix/21037\\n bytes memory _signature\\n ) internal pure returns (address) {\\n (bytes32 r, bytes32 s, uint8 v) = splitSignature(_signature);\\n\\n return ecrecover(_ethSignedMessageHash, v, r, s);\\n }\\n\\n function splitSignature(bytes memory sig) internal pure returns (bytes32 r_, bytes32 s_, uint8 v_) {\\n if (sig.length != 65) {\\n revert InvalidSignatureLength();\\n }\\n\\n assembly {\\n /*\\n verbose explanation: https://ethereum.stackexchange.com/questions/135591/split-signature-function-in-solidity-by-example-docs\\n First 32 bytes stores the length of the signature\\n add(sig, 32) = pointer of sig + 32\\n effectively, skips first 32 bytes of signature\\n mload(p) loads next 32 bytes starting at the memory address p into memory\\n */\\n\\n // first 32 bytes, after the length prefix\\n r_ := mload(add(sig, 32))\\n // second 32 bytes\\n s_ := mload(add(sig, 64))\\n // final byte (first byte of the next 32 bytes)\\n v_ := byte(0, mload(add(sig, 96)))\\n }\\n\\n // implicitly return (r, s, v)\\n }\\n\\n function getSocMessageHash(bytes32 _identifier, bytes32 _chunkAddr) internal pure returns (bytes32) {\\n return keccak256(abi.encodePacked(_identifier, _chunkAddr));\\n }\\n\\n function socVerify(\\n address _signer, // signer Ethereum address to check against\\n bytes memory _signature,\\n bytes32 _identifier,\\n bytes32 _chunkAddr\\n ) internal pure returns (bool) {\\n bytes32 messageHash = getSocMessageHash(_identifier, _chunkAddr);\\n bytes32 ethMessageHash = getEthSignedMessageHash(messageHash);\\n\\n return recoverSigner(ethMessageHash, _signature) == _signer;\\n }\\n}\\n\",\"keccak256\":\"0x11762639cfa5bd2ea21922f762254c776ce890ab9e4085b3e3d45dbe21867ac8\",\"license\":\"MIT\"},\"src/Util/TransformedChunkProof.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\npragma solidity ^0.8.19;\\n\\nlibrary TransformedBMTChunk {\\n // max chunk payload size\\n uint256 public constant MAX_CHUNK_PAYLOAD_SIZE = 4096;\\n // segment byte size\\n uint256 public constant SEGMENT_SIZE = 32;\\n\\n /** Calculates the root hash from the provided inclusion proof segments and its corresponding segment index\\n * @param _proofSegments Proof segments.\\n * @param _proveSegment Segment to prove.\\n * @param _proveSegmentIndex Prove segment index\\n * @return _calculatedHash chunk hash\\n */\\n function transformedRootHashFromInclusionProof(\\n bytes32[] memory _proofSegments,\\n bytes32 _proveSegment,\\n uint256 _proveSegmentIndex,\\n bytes32 key\\n ) internal pure returns (bytes32 _calculatedHash) {\\n _calculatedHash = _proveSegment;\\n for (uint256 i = 0; i < _proofSegments.length; i++) {\\n bool mergeFromRight = _proveSegmentIndex % 2 == 0 ? true : false;\\n _calculatedHash = transformedMergeSegment(_calculatedHash, _proofSegments[i], mergeFromRight, key);\\n _proveSegmentIndex >>= 1;\\n }\\n\\n return _calculatedHash;\\n }\\n\\n /**\\n * @notice Changes the endianness of a uint64.\\n * @dev https://graphics.stanford.edu/~seander/bithacks.html#ReverseParallel\\n * @param _b The unsigned integer to reverse\\n * @return v - The reversed value\\n */\\n function reverseUint64(uint64 _b) public pure returns (uint64) {\\n uint256 v = _b;\\n\\n // swap bytes\\n v =\\n ((v >> 8) & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) |\\n ((v & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) << 8);\\n // swap 2-byte long pairs\\n v =\\n ((v >> 16) & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) |\\n ((v & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) << 16);\\n // swap 4-byte long pairs\\n v =\\n ((v >> 32) & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) |\\n ((v & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) << 32);\\n\\n return uint64(v);\\n }\\n\\n /**\\n * Calculate the chunk address from the Binary Merkle Tree of the chunk data\\n *\\n * The BMT chunk address is the hash of the 8 byte span and the root\\n * hash of a binary Merkle tree (BMT) built on the 32-byte segments\\n * of the underlying data.\\n * @param _proofSegments Proof segments.\\n * @param _proveSegment Segment to prove.\\n * @param _proveSegmentIndex Prove segment index\\n * @param _chunkSpan chunk bytes length\\n * @return _chunkHash chunk hash\\n */\\n function transformedChunkAddressFromInclusionProof(\\n bytes32[] memory _proofSegments,\\n bytes32 _proveSegment,\\n uint256 _proveSegmentIndex,\\n uint64 _chunkSpan,\\n bytes32 key\\n ) internal pure returns (bytes32) {\\n bytes32 rootHash = transformedRootHashFromInclusionProof(\\n _proofSegments,\\n _proveSegment,\\n _proveSegmentIndex,\\n key\\n );\\n return keccak256(abi.encodePacked(key, reverseUint64(_chunkSpan), rootHash));\\n }\\n\\n function transformedMergeSegment(\\n bytes32 _calculatedHash,\\n bytes32 _proofSegment,\\n bool mergeFromRight,\\n bytes32 key\\n ) internal pure returns (bytes32 res) {\\n if (mergeFromRight) {\\n res = keccak256(abi.encode(key, _calculatedHash, _proofSegment));\\n } else {\\n res = keccak256(abi.encode(key, _proofSegment, _calculatedHash));\\n }\\n return res;\\n }\\n}\\n\",\"keccak256\":\"0xf36473af0bec0de80c769b139a09bc0329807cb5c3b6234473601081da14350c\",\"license\":\"MIT\"},\"src/interface/IPostageStamp.sol\":{\"content\":\"// SPDX-License-Identifier: BSD-3-Clause\\npragma solidity ^0.8.19;\\n\\ninterface IPostageStamp {\\n function withdraw(address beneficiary) external;\\n\\n function validChunkCount() external view returns (uint256);\\n\\n function batchOwner(bytes32 _batchId) external view returns (address);\\n\\n function batchDepth(bytes32 _batchId) external view returns (uint8);\\n\\n function batchBucketDepth(bytes32 _batchId) external view returns (uint8);\\n\\n function remainingBalance(bytes32 _batchId) external view returns (uint256);\\n\\n function minimumInitialBalancePerChunk() external view returns (uint256);\\n\\n function setPrice(uint256 _price) external;\\n\\n function batches(\\n bytes32\\n )\\n external\\n view\\n returns (\\n address owner,\\n uint8 depth,\\n uint8 bucketDepth,\\n bool immutableFlag,\\n uint256 normalisedBalance,\\n uint256 lastUpdatedBlockNumber\\n );\\n}\\n\",\"keccak256\":\"0xc018ff96e75e773e76e6245a930acc3679667250e345415a38196f1e2ad1de76\",\"license\":\"BSD-3-Clause\"}},\"version\":1}", - "bytecode": "0x60a06040526008805462ffffff60c01b19166264020160c01b1790557dba1914b54e0348a1028d1a103a95ed55c4004b9d332400000000000000006009553480156200004a57600080fd5b5060405162004b5338038062004b538339810160408190526200006d91620001d0565b60018054600380546001600160a01b03199081166001600160a01b03888116919091179092556001600160a81b03199092166101008683160217909255600280549091169183169190911790557f65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a608052620000eb60003362000103565b608051620000fa903362000103565b5050506200021a565b6200010f828262000113565b5050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff166200010f576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556200016f3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b80516001600160a01b0381168114620001cb57600080fd5b919050565b600080600060608486031215620001e657600080fd5b620001f184620001b3565b92506200020160208501620001b3565b91506200021160408501620001b3565b90509250925092565b6080516149166200023d600039600081816117b3015261200301526149166000f3fe608060405234801561001057600080fd5b50600436106102775760003560e01c806377c75d1011610160578063b6cd5822116100d8578063dfbf53ae1161008c578063f69ee1d111610071578063f69ee1d1146105d5578063f7b188a5146105e8578063fb00f2f3146105f057600080fd5b8063dfbf53ae14610592578063f4e6fcca146105c257600080fd5b8063ce987745116100bd578063ce98774514610564578063d1e8b63d14610577578063d547741f1461057f57600080fd5b8063b6cd582214610537578063c46b40291461054a57600080fd5b80638456cb591161012f5780638d8b6428116101145780638d8b6428146104f057806391d14854146104f8578063a217fddf1461052f57600080fd5b80638456cb59146104e05780638a19c8bc146104e857600080fd5b806377c75d101461045a5780637fe019c61461046d57806382b39b1b1461048857806383220626146104d857600080fd5b80635c975abb116101f357806364c34a85116101c257806369da9114116101a757806369da9114146103de5780636f94aaf2146103f157806372286cba1461040c57600080fd5b806364c34a85146103a957806369bfac01146103b157600080fd5b80635c975abb146103705780635d4844ea1461037b57806362fd29ae1461038e57806363f5cf7c1461039657600080fd5b80632a4e62491161024a5780632f3906da1161022f5780632f3906da1461034257806336568abe1461034a5780635838d6731461035d57600080fd5b80632a4e6249146103185780632f2ff15d1461032d57600080fd5b806301ffc9a71461027c5780631736d472146102a457806318350096146102b7578063248a9ca3146102e7575b600080fd5b61028f61028a366004614067565b610603565b60405190151581526020015b60405180910390f35b61028f6102b23660046140b5565b61066c565b6001546102cf9061010090046001600160a01b031681565b6040516001600160a01b03909116815260200161029b565b61030a6102f53660046140ee565b60009081526020819052604090206001015490565b60405190815260200161029b565b6103206107d4565b60405161029b9190614107565b61034061033b366004614196565b6108e1565b005b61028f61090b565b610340610358366004614196565b610955565b61034061036b3660046141d8565b6109e6565b60015460ff1661028f565b6003546102cf906001600160a01b031681565b61030a610f48565b6103406103a436600461421d565b611014565b61030a6113af565b6008546103c59067ffffffffffffffff1681565b60405167ffffffffffffffff909116815260200161029b565b6002546102cf906001600160a01b031681565b6008546103c590600160801b900467ffffffffffffffff1681565b61041f61041a3660046140ee565b61148f565b604080519687526001600160a01b039095166020870152921515938501939093526060840152608083019190915260a082015260c00161029b565b61028f6104683660046140ee565b6114e6565b6008546103c590600160401b900467ffffffffffffffff1681565b61049b6104963660046140ee565b611796565b604080519687526001600160a01b03909516602087015260ff909316938501939093526060840152608083019190915260a082015260c00161029b565b61030a6117a6565b6103406117b1565b6103c5611814565b61028f611821565b61028f610506366004614196565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b61030a600081565b6103406105453660046142a5565b61184b565b610552611d88565b60405160ff909116815260200161029b565b61030a6105723660046142da565b611e0d565b61028f611e7c565b61034061058d366004614196565b611ea1565b600a54600b54600c54600d54600e5461049b94936001600160a01b03811693600160a01b90910460ff1692909186565b6103406105d0366004614317565b611ec6565b6103406105e33660046140ee565b611fad565b610340612001565b61028f6105fe366004614362565b612062565b60006001600160e01b031982167f7965db0b00000000000000000000000000000000000000000000000000000000148061066657507f01ffc9a7000000000000000000000000000000000000000000000000000000006001600160e01b03198316145b92915050565b600061067661090b565b156106ad576040517fe2586bcc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6106b9609860026143a6565b6106c390436143bd565b60035460405163d1052d1f60e01b81526001600160a01b0386811660048301529091169063d1052d1f90602401602060405180830381865afa15801561070d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061073191906143d0565b1061074f57604051630a0744c560e01b815260040160405180910390fd5b6003546040516397adedb560e01b81526001600160a01b0385811660048301526107cd9216906397adedb590602401602060405180830381865afa15801561079b573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107bf91906143d0565b6107c76113af565b84612062565b9392505050565b60606107de611821565b6107fb57604051633788c6c160e11b815260040160405180910390fd5b6000610805611814565b60085490915067ffffffffffffffff808316600160401b909204161461083e57604051636fbabc7760e01b815260040160405180910390fd5b6005805480602002602001604051908101604052809291908181526020016000905b828210156108d75760008481526020908190206040805160c08101825260058602909201805483526001808201546001600160a01b03811685870152600160a01b900460ff169284019290925260028101546060840152600381015460808401526004015460a08301529083529092019101610860565b5050505091505090565b6000828152602081905260409020600101546108fc8161209e565b61090683836120ab565b505050565b6000806109196098436143ff565b905061092760046098614413565b8110158015610940575061093d60026098614413565b81105b1561094d57600191505090565b600091505090565b6001600160a01b03811633146109d85760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b6109e28282612149565b5050565b6109ee6121c8565b60006109f8611814565b6003546040516397adedb560e01b81523360048201529192506000916001600160a01b03909116906397adedb590602401602060405180830381865afa158015610a46573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a6a91906143d0565b6003546040517f830a053e0000000000000000000000000000000000000000000000000000000081523360048201529192506000916001600160a01b039091169063830a053e90602401602060405180830381865afa158015610ad1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610af591906143d0565b60035460405163d1052d1f60e01b81523360048201529192506000916001600160a01b039091169063d1052d1f90602401602060405180830381865afa158015610b43573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b6791906143d0565b9050610b71611e7c565b610ba7576040517fdc816a8700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001610bb560046098614413565b610bbf91906143bd565b610bca6098436143ff565b03610c01576040517f5baef6b600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8467ffffffffffffffff168467ffffffffffffffff161115610c4f576040517f50ff7c0000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8467ffffffffffffffff168467ffffffffffffffff161015610c9d576040517f7a0c0fd600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b80600003610cd7576040517f039f2e1800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610ce3609860026143a6565b610ced90436143bd565b8110610d0c57604051630a0744c560e01b815260040160405180910390fd5b60085467ffffffffffffffff858116911614610d4c57610d2e60046000613ffe565b6008805467ffffffffffffffff191667ffffffffffffffff86161790555b60045460005b81811015610dbf578460048281548110610d6e57610d6e614427565b90600052602060002090600502016000015403610db7576040517fbfec555800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600101610d52565b506040805160c081018252858152336020808301918252600083850181815260608501898152608086018e815260a0870184815260048054600181018255955296517f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b60059095029485015594517f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19c8401805493516001600160a01b0390921674ffffffffffffffffffffffffffffffffffffffffff1990941693909317600160a01b9115159190910217909155517f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19d82015591517f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19e83015591517f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19f90910155815167ffffffffffffffff891681529081018690527f68e0867601a98978930107aee7f425665e61edd70ca594c68ca5da9e81f84c29910160405180910390a150505050505050565b600080610f53611814565b610f5e90600161443d565b60075460085491925090610f8490600160401b900467ffffffffffffffff16600161443d565b67ffffffffffffffff168267ffffffffffffffff16111561066657600854600090600190610fc390600160401b900467ffffffffffffffff1685614465565b610fcd9190614465565b67ffffffffffffffff1690508181604051602001610ff5929190918252602082015260400190565b6040516020818303038152906040528051906020012091505092915050565b61101c6121c8565b61102461221b565b6040805160c081018252600a548152600b546001600160a01b0381166020830152600160a01b900460ff1691810191909152600c546060820152600d546080820152600e5460a08201526006546007546000918291611084600f826143ff565b9350611091600e826143ff565b92508383106110a857826110a481614486565b9350505b6110bb8660200135838760400151612062565b6110db57604051633b5f43a360e01b8152600360048201526024016109cf565b6110e686601e612827565b6110ef86612b39565b6110f886612e46565b61110b8860200135838760400151612062565b61112b57604051633b5f43a360e01b8152600260048201526024016109cf565b61113f8861113a8660026143a6565b612827565b61114888612b39565b61115188612e46565b6111648760200135838760400151612062565b61118457604051633b5f43a360e01b8152600160048201526024016109cf565b6111938761113a8560026143a6565b61119c87612b39565b6111a587612e46565b61121b84846111b48b8061449f565b60008181106111c5576111c5614427565b602002919091013590506111d98b8061449f565b60008181106111ea576111ea614427565b602002919091013590506111fe8b8061449f565b600081811061120f5761120f614427565b905060200201356130da565b611245611228878061449f565b600081811061123957611239614427565b90506020020135613167565b60015460208601516040517f51cff8d90000000000000000000000000000000000000000000000000000000081526001600160a01b03918216600482015261010090920416906351cff8d990602401600060405180830381600087803b1580156112ae57600080fd5b505af11580156112c2573d6000803e3d6000fd5b505050507f788e77979e6e6a8a6a5d2c19c58b1ff9671298f54c85ac6f6aa30379aed5861a856040516112f591906144f0565b60405180910390a17fbee3fc8a3523c1a65fa9308ce1f2b8fd90c24975b141b754603194597846e4dd60018054906101000a90046001600160a01b03166001600160a01b0316638a5e8e326040518163ffffffff1660e01b8152600401602060405180830381865afa15801561136f573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061139391906143d0565b6040519081526020015b60405180910390a15050505050505050565b60006113b9611e7c565b806113f75750600854600160401b900467ffffffffffffffff166113db611814565b67ffffffffffffffff161180156113f757506113f5611821565b155b15611409576114046117a6565b905090565b611411611821565b1561141e57611404610f48565b61142661090b565b80156114555750600854600160401b900467ffffffffffffffff16611449611814565b67ffffffffffffffff16145b1561148c576040517f36b7884b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b90565b6004818154811061149f57600080fd5b6000918252602090912060059091020180546001820154600283015460038401546004909401549294506001600160a01b03821693600160a01b90920460ff169290919086565b60006114f0611821565b61150d57604051633788c6c160e11b815260040160405180910390fd5b6000611517611814565b60085490915067ffffffffffffffff808316600160401b909204161461155057604051636fbabc7760e01b815260040160405180910390fd5b60085467ffffffffffffffff600160801b90910481169082161161158757604051630c8d9eab60e31b815260040160405180910390fd5b60008060008060008060008061159b6131a5565b905060006115a761325f565b600454919650945060005b8181101561178257600481815481106115cd576115cd614427565b9060005260206000209060050201600401549450600481815481106115f4576115f4614427565b906000526020600020906005020160010160149054906101000a900460ff16801561164257506005858154811061162d5761162d614427565b90600052602060002090600502016004015487145b801561168057506005858154811061165c5761165c614427565b600091825260209091206001600590920201015460ff878116600160a01b90920416145b1561177a576005858154811061169857611698614427565b9060005260206000209060050201600301548b6116b5919061453f565b9a5083836040516020016116ca929190614576565b60408051601f19818403018152919052805160209091012098506fffffffffffffffffffffffffffffffff808a16985061170590600161453f565b6005868154811061171857611718614427565b90600052602060002090600502016003015461173491906143a6565b61173e8c8a6143a6565b101561176c576005858154811061175757611757614427565b90600052602060002090600502016000015499505b8261177681614486565b9350505b6001016115b2565b505050959099149998505050505050505050565b6005818154811061149f57600080fd5b600080610f5e611814565b7f000000000000000000000000000000000000000000000000000000000000000060009081526020818152604080832033845290915290205460ff1661180a57604051631d77d47760e21b815260040160405180910390fd5b611812613418565b565b6000611404609843614413565b600061182f60026098614413565b61183a6098436143ff565b106118455750600190565b50600090565b6118536121c8565b600061185d611814565b6003546040516397adedb560e01b81523360048201529192506000916001600160a01b03909116906397adedb590602401602060405180830381865afa1580156118ab573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118cf91906143d0565b90506118d9611d88565b60ff168560ff161015611918576040517f83d9b7bd00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61192061090b565b611956576040517fd1088db600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60085467ffffffffffffffff83811691161461199e576040517f842a9e0a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60085467ffffffffffffffff838116600160401b9092041614611a86576119c36113af565b6006556119d260056000613ffe565b600880547fffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff16600160401b67ffffffffffffffff8516908102919091179091556006546040805192835260208301919091527ff0ae472da9c8da86bda4991a549c03a3cb328b5f360ea11a5b8814f32bb85176910160405180910390a1611a86600754604080516020810192909252449082015260600160408051601f198184030181529190528051602090910120600755565b6000611a9482878787611e0d565b90506000611aa2838361346c565b9050600060048281548110611ab957611ab9614427565b60009182526020918290206040805160c081018252600593909302909101805480845260018201546001600160a01b03811695850195909552600160a01b90940460ff1615159183019190915260028101546060830152600381015460808301526004015460a0820152600654909250611b3491908a612062565b611b70576006546040517f14ebbbe40000000000000000000000000000000000000000000000000000000081526004016109cf91815260200190565b806040015115611bac576040517fa89ac15100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600160048381548110611bc157611bc1614427565b906000526020600020906005020160010160146101000a81548160ff02191690831515021790555060058054905060048381548110611c0257611c02614427565b90600052602060002090600502016004018190555060056040518060c001604052808360000151815260200183602001516001600160a01b031681526020018a60ff168152602001836060015181526020018a6002611c61919061467c565b8460600151611c7091906143a6565b815260209081018a90528254600181810185556000948552938290208351600590920201908155908201519281018054604084015160ff16600160a01b0274ffffffffffffffffffffffffffffffffffffffffff199091166001600160a01b0390951694909417939093179092556060808201516002808501919091556080830151600385015560a0909201516004909301929092558251918301517f13fc17fd71632266fe82092de6dd91a06b4fa68d8dc950492e5421cbed55a6a5928892909190611d3e908d9061467c565b8560600151611d4d91906143a6565b6040805167ffffffffffffffff909516855260208501939093529183015260608201526080810189905260ff8a1660a082015260c00161139d565b6008546000908190611dad9067ffffffffffffffff600160801b820481169116614465565b67ffffffffffffffff169050600060fe8211611dc95781611dcc565b60fe5b611dd790600161468b565b600b5490915060ff600160a01b9091048116908216811115611e0257611dfd82826146a4565b611e05565b60005b935050505090565b60408051602081018690527fff0000000000000000000000000000000000000000000000000000000000000060f886901b169181019190915260418101839052606181018290526000906081015b6040516020818303038152906040528051906020012090505b949350505050565b6000611e8a60046098614413565b611e956098436143ff565b10156118455750600190565b600082815260208190526040902060010154611ebc8161209e565b6109068383612149565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff16611f1557604051637bfa4b9f60e01b815260040160405180910390fd5b600880547fffffffffffff0000ffffffffffffffffffffffffffffffffffffffffffffffff16600160c01b60ff958616027fffffffffffff00ffffffffffffffffffffffffffffffffffffffffffffffffff1617600160c81b93851693909302929092177fffffffffff00ffffffffffffffffffffffffffffffffffffffffffffffffffff16600160d01b9190931602919091179055565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff16611ffc57604051637bfa4b9f60e01b815260040160405180910390fd5b600955565b7f000000000000000000000000000000000000000000000000000000000000000060009081526020818152604080832033845290915290205460ff1661205a57604051631d77d47760e21b815260040160405180910390fd5b611812613517565b60008160ff16600003612077575060016107cd565b61208660ff83166101006146bd565b6120919060026146d8565b8484181090509392505050565b6120a88133613550565b50565b6000828152602081815260408083206001600160a01b038516845290915290205460ff166109e2576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556121053390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16156109e2576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b60015460ff16156118125760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a207061757365640000000000000000000000000000000060448201526064016109cf565b6000612225611814565b905061222f611821565b61224c57604051633788c6c160e11b815260040160405180910390fd5b60085467ffffffffffffffff828116600160401b909204161461228257604051636fbabc7760e01b815260040160405180910390fd5b60085467ffffffffffffffff600160801b9091048116908216116122b957604051630c8d9eab60e31b815260040160405180910390fd5b600454604051818152600091829182918291829182917f6752c5e71c95fb93bc7137adeb115a33fa4e54e2683e33d3f90c2bb1c4b6c2a59060200160405180910390a16005546040519081527f4c03de6a759749c0c9387b7014634dc5c6af610e1366023d90751c783a998f8d9060200160405180910390a161233a61325f565b6040805183815260ff831660208201529295509093507f34e8eda4cd857cd2865becf58a47748f31415f4a382cbb2cc0c64b9a27c717be910160405180910390a160006123856131a5565b905060005b82811015612761576000600482815481106123a7576123a7614427565b600091825260208083206040805160c08101825260059485029092018054835260018101546001600160a01b03811694840194909452600160a01b90930460ff16151590820152600282015460608201526003820154608082015260049091015460a0820181905282549194509291908390811061242757612427614427565b60009182526020918290206040805160c0810182526005939093029091018054835260018101546001600160a01b03811694840194909452600160a01b90930460ff1682820152600283015460608301526003830154608083015260049092015460a08201529084015190915080156124a357508060a0015188145b80156124b85750806040015160ff168760ff16145b156125ad5760808101516124cc908d61453f565b9b50848b6040516020016124e1929190614576565b60408051601f19818403018152919052805160209091012099506fffffffffffffffffffffffffffffffff808b16995061251c90600161453f565b816080015161252b91906143a6565b6125358d8b6143a6565b101561259f578051600a556020810151600b8054604084015160ff16600160a01b0274ffffffffffffffffffffffffffffffffffffffffff199091166001600160a01b03909316929092179190911790556060810151600c556080810151600d5560a0810151600e555b8a6125a981614486565b9b50505b826040015180156125d657508060a00151881415806125d65750806040015160ff168760ff1614155b80156125f75750600854600160d01b900460ff166125f56064446143ff565b105b156126a35760035460208201516001600160a01b039091169063d009b2d6906126218a600261467c565b60085461263a90609890600160c01b900460ff166143a6565b61264491906143a6565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401600060405180830381600087803b15801561268a57600080fd5b505af115801561269e573d6000803e3d6000fd5b505050505b82604001516127535760035460208401516001600160a01b039091169063d009b2d6906126d18a600261467c565b6008546126ea90609890600160c81b900460ff166143a6565b6126f491906143a6565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401600060405180830381600087803b15801561273a57600080fd5b505af115801561274e573d6000803e3d6000fd5b505050505b83600101935050505061238a565b506002546040517fffb98fe300000000000000000000000000000000000000000000000000000000815261ffff891660048201526001600160a01b039091169063ffb98fe390602401600060405180830381600087803b1580156127c457600080fd5b505af11580156127d8573d6000803e3d6000fd5b50506008805467ffffffffffffffff909c16600160801b027fffffffffffffffff0000000000000000ffffffffffffffffffffffffffffffff909c169b909b17909a5550505050505050505050565b600754600090612839906080906143ff565b9050600061289c61284d60a086018661449f565b8080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525050505060608601358461289460a0890160808a016146e8565b6006546135c3565b60408051858152602081018390529192507f94e252069a85aa79db21f5bd8ca4e14dd3a3927aa492711017a2c8ddad95af00910160405180910390a16129246128e5858061449f565b8080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525050505060208601358561040061373b565b600e541461294f5760405163755f0a2560e01b815260016004820152602481018290526044016109cf565b61295c60a085018561449f565b600081811061296d5761296d614427565b90506020020135848060400190612984919061449f565b600081811061299557612995614427565b90506020020135146129c45760405163755f0a2560e01b815260026004820152602481018290526044016109cf565b6000806129d460e087018761449f565b9050116129e5578460200135612a1a565b6129f260e086018661449f565b6000818110612a0357612a03614427565b9050602002810190612a159190614703565b606001355b9050612a78612a2c604087018761449f565b80806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250505050606087013585612a7360a08a0160808b016146e8565b61373b565b8114612aa15760405163755f0a2560e01b815260036004820152602481018390526044016109cf565b6000612ab060e087018761449f565b90501115612ae85760408051602080880135908201529081018390526060016040516020818303038152906040528051906020012091505b81612af3868061449f565b6000818110612b0457612b04614427565b9050602002013514612b325760405163755f0a2560e01b8152600481810152602481018390526044016109cf565b5050505050565b6001546000908190819061010090046001600160a01b031663c81e25ab612b6360c0870187614703565b602001356040518263ffffffff1660e01b8152600401612b8591815260200190565b60c060405180830381865afa158015612ba2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612bc69190614723565b509396509194509250506001600160a01b0384169050612c2657612bed60c0850185614703565b602001356040517f2396d34e0000000000000000000000000000000000000000000000000000000081526004016109cf91815260200190565b6000612c49612c3860c0870187614703565b61148c9060608101906040016146e8565b90506000612c5784846138a9565b9050808263ffffffff1610612cac57612c7360c0870187614703565b602001356040517f1362e4a00000000000000000000000000000000000000000000000000000000081526004016109cf91815260200190565b6000612cdb612cbe60c0890189614703565b612ccf9060608101906040016146e8565b60201c63ffffffff1690565b90506000612ced8860200135866138c4565b63ffffffff16905067ffffffffffffffff82168114612d4c57612d1360c0890189614703565b602001356040517f6dd6a24f0000000000000000000000000000000000000000000000000000000081526004016109cf91815260200190565b612df287612d5d60c08b018b614703565b612d67908061479b565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050505060208b0135612dad60c08d018d614703565b60200135612dbe60c08e018e614703565b612dcf9060608101906040016146e8565b612ddc60c08f018f614703565b612ded9060808101906060016146e8565b6138eb565b612e3c57612e0360c0890189614703565b602001356040517fdb12fb9d0000000000000000000000000000000000000000000000000000000081526004016109cf91815260200190565b5050505050505050565b612e5360e082018261449f565b9050600003612e5f5750565b612f80612e6f60e083018361449f565b6000818110612e8057612e80614427565b9050602002810190612e929190614703565b612ea09060208101906147e2565b612ead60e084018461449f565b6000818110612ebe57612ebe614427565b9050602002810190612ed09190614703565b612ede90602081019061479b565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250612f209250505060e085018561449f565b6000818110612f3157612f31614427565b9050602002810190612f439190614703565b60400135612f5460e086018661449f565b6000818110612f6557612f65614427565b9050602002810190612f779190614703565b60600135613982565b612fed57612f9160e082018261449f565b6000818110612fa257612fa2614427565b9050602002810190612fb49190614703565b606001356040517fd740df610000000000000000000000000000000000000000000000000000000081526004016109cf91815260200190565b602081013561306c61300260e084018461449f565b600081811061301357613013614427565b90506020028101906130259190614703565b6040013561303660e085018561449f565b600081811061304757613047614427565b90506020028101906130599190614703565b6130679060208101906147e2565b613a15565b146120a85761307e60e082018261449f565b600081811061308f5761308f614427565b90506020028101906130a19190614703565b606001356040517f82f2469d0000000000000000000000000000000000000000000000000000000081526004016109cf91815260200190565b838510156131275781831061310257604051633d386eb360e11b815260040160405180910390fd5b80821061312257604051633588c6d360e11b815260040160405180910390fd5b612b32565b82821061314757604051633d386eb360e11b815260040160405180910390fd5b808310612b3257604051633588c6d360e11b815260040160405180910390fd5b60095481106120a8576040517fb6052cdf000000000000000000000000000000000000000000000000000000008152600481018290526024016109cf565b60606131af611821565b6131cc57604051633788c6c160e11b815260040160405180910390fd5b60006131d6611814565b60085490915067ffffffffffffffff808316600160401b909204161461320f57604051636fbabc7760e01b815260040160405180910390fd5b60075460405160200161324a9181527f3100000000000000000000000000000000000000000000000000000000000000602082015260210190565b60405160208183030381529060405291505090565b6000806000806000806000806000613275613a63565b60045490915060005b81811015613407576004818154811061329957613299614427565b906000526020600020906005020160010160149054906101000a900460ff16156133ff57600481815481106132d0576132d0614427565b9060005260206000209060050201600401549350600584815481106132f7576132f7614427565b90600052602060002090600502016003015489613314919061453f565b98508281604051602001613329929190614576565b60408051601f19818403018152919052805160209091012097506fffffffffffffffffffffffffffffffff808916975061336490600161453f565b6005858154811061337757613377614427565b90600052602060002090600502016003015461339391906143a6565b61339d8a896143a6565b10156133ff57600584815481106133b6576133b6614427565b9060005260206000209060050201600401549550600584815481106133dd576133dd614427565b906000526020600020906005020160010160149054906101000a900460ff1694505b60010161327e565b509399929850919650505050505050565b6134206121c8565b6001805460ff1916811790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258335b6040516001600160a01b03909116815260200160405180910390a1565b6000805b6004548110156134e457836004828154811061348e5761348e614427565b9060005260206000209060050201600001541480156134d05750600481815481106134bb576134bb614427565b90600052602060002090600502016003015483145b156134dc579050610666565b600101613470565b506040517fd950091500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61351f613aec565b6001805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa3361344f565b6000828152602081815260408083206001600160a01b038516845290915290205460ff166109e25761358181613b3e565b61358c836020613b50565b60405160200161359d9291906147ff565b60408051601f198184030181529082905262461bcd60e51b82526109cf91600401614880565b6000806135d287878786613d15565b9050826136d7856000808267ffffffffffffffff1690506008817eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff16901b600882901c7eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff161790506010817dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff16901b601082901c7dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff161790506020817bffffffff00000000ffffffff00000000ffffffff00000000ffffffff16901b602082901c7bffffffff00000000ffffffff00000000ffffffff00000000ffffffff1617905080915050919050565b826040516020016137199392919092835260c09190911b77ffffffffffffffffffffffffffffffffffffffffffffffff19166020830152602882015260480190565b6040516020818303038152906040528051906020012091505095945050505050565b600080613749868686613d8b565b905061384d836000808267ffffffffffffffff1690506008817eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff16901b600882901c7eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff161790506010817dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff16901b601082901c7dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff161790506020817bffffffff00000000ffffffff00000000ffffffff00000000ffffffff16901b602082901c7bffffffff00000000ffffffff00000000ffffffff00000000ffffffff1617905080915050919050565b8160405160200161388892919060c09290921b77ffffffffffffffffffffffffffffffffffffffffffffffff19168252600882015260280190565b60405160208183030381529060405280519060200120915050949350505050565b60006138b582846146a4565b60ff166001901b905092915050565b600060e083901c6138d68360206146a4565b60ff168163ffffffff16901c91505092915050565b6000806138fa86868686613df3565b90506000613955826040517f19457468657265756d205369676e6564204d6573736167653a0a3332000000006020820152603c8101829052600090605c01604051602081830303815290604052805190602001209050919050565b9050886001600160a01b031661396b828a613e3e565b6001600160a01b0316149998505050505050505050565b60008061398f8484613ebd565b905060006139ea826040517f19457468657265756d205369676e6564204d6573736167653a0a3332000000006020820152603c8101829052600090605c01604051602081830303815290604052805190602001209050919050565b9050866001600160a01b0316613a008288613e3e565b6001600160a01b031614979650505050505050565b60008282604051602001613a4592919091825260601b6bffffffffffffffffffffffff1916602082015260340190565b60405160208183030381529060405280519060200120905092915050565b6060613a6d611821565b613a8a57604051633788c6c160e11b815260040160405180910390fd5b6000613a94611814565b60085490915067ffffffffffffffff808316600160401b9092041614613acd57604051636fbabc7760e01b815260040160405180910390fd5b60075460405160200161324a918152600360fc1b602082015260210190565b60015460ff166118125760405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f742070617573656400000000000000000000000060448201526064016109cf565b60606106666001600160a01b03831660145b60606000613b5f8360026143a6565b613b6a90600261453f565b67ffffffffffffffff811115613b8257613b826148b3565b6040519080825280601f01601f191660200182016040528015613bac576020820181803683370190505b509050600360fc1b81600081518110613bc757613bc7614427565b60200101906001600160f81b031916908160001a9053507f780000000000000000000000000000000000000000000000000000000000000081600181518110613c1257613c12614427565b60200101906001600160f81b031916908160001a9053506000613c368460026143a6565b613c4190600161453f565b90505b6001811115613cc6577f303132333435363738396162636465660000000000000000000000000000000085600f1660108110613c8257613c82614427565b1a60f81b828281518110613c9857613c98614427565b60200101906001600160f81b031916908160001a90535060049490941c93613cbf816148c9565b9050613c44565b5083156107cd5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e7460448201526064016109cf565b8260005b8551811015613d82576000613d2f6002866143ff565b15613d3b576000613d3e565b60015b9050613d6583888481518110613d5657613d56614427565b60200260200101518387613ed9565b9250600185901c9450508080613d7a90614486565b915050613d19565b50949350505050565b8160005b8451811015613deb576000613da56002856143ff565b6000149050613dce83878481518110613dc057613dc0614427565b602002602001015183613f39565b9250600184901c9350508080613de390614486565b915050613d8f565b509392505050565b604080516020810186905290810184905277ffffffffffffffffffffffffffffffffffffffffffffffff1960c084811b8216606084015283901b166068820152600090607001611e5b565b600080600080613e4d85613fa0565b6040805160008152602081018083528b905260ff8316918101919091526060810184905260808101839052929550909350915060019060a0016020604051602081039080840390855afa158015613ea8573d6000803e3d6000fd5b5050604051601f190151979650505050505050565b6040805160208101849052908101829052600090606001613a45565b60008215613f1957604080516020810184905290810186905260608101859052608001604051602081830303815290604052805190602001209050611e74565b604080516020810184905290810185905260608101869052608001611e5b565b60008115613f725760408051602081018690529081018490526060016040516020818303038152906040528051906020012090506107cd565b5050604080516020808201939093528082019390935280518084038201815260609093019052815191012090565b60008060008351604114613fe0576040517f4be6321b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50505060208101516040820151606090920151909260009190911a90565b50805460008255600502906000526020600020908101906120a891905b8082111561406357600080825560018201805474ffffffffffffffffffffffffffffffffffffffffff191690556002820181905560038201819055600482015560050161401b565b5090565b60006020828403121561407957600080fd5b81356001600160e01b0319811681146107cd57600080fd5b6001600160a01b03811681146120a857600080fd5b60ff811681146120a857600080fd5b600080604083850312156140c857600080fd5b82356140d381614091565b915060208301356140e3816140a6565b809150509250929050565b60006020828403121561410057600080fd5b5035919050565b6020808252825182820181905260009190848201906040850190845b8181101561418a57614177838551805182526001600160a01b03602082015116602083015260ff6040820151166040830152606081015160608301526080810151608083015260a081015160a08301525050565b9284019260c09290920191600101614123565b50909695505050505050565b600080604083850312156141a957600080fd5b8235915060208301356140e381614091565b803567ffffffffffffffff811681146141d357600080fd5b919050565b600080604083850312156141eb57600080fd5b823591506141fb602084016141bb565b90509250929050565b6000610100828403121561421757600080fd5b50919050565b60008060006060848603121561423257600080fd5b833567ffffffffffffffff8082111561424a57600080fd5b61425687838801614204565b9450602086013591508082111561426c57600080fd5b61427887838801614204565b9350604086013591508082111561428e57600080fd5b5061429b86828701614204565b9150509250925092565b6000806000606084860312156142ba57600080fd5b83356142c5816140a6565b95602085013595506040909401359392505050565b600080600080608085870312156142f057600080fd5b843593506020850135614302816140a6565b93969395505050506040820135916060013590565b60008060006060848603121561432c57600080fd5b8335614337816140a6565b92506020840135614347816140a6565b91506040840135614357816140a6565b809150509250925092565b60008060006060848603121561437757600080fd5b83359250602084013591506040840135614357816140a6565b634e487b7160e01b600052601160045260246000fd5b808202811582820484141761066657610666614390565b8181038181111561066657610666614390565b6000602082840312156143e257600080fd5b5051919050565b634e487b7160e01b600052601260045260246000fd5b60008261440e5761440e6143e9565b500690565b600082614422576144226143e9565b500490565b634e487b7160e01b600052603260045260246000fd5b67ffffffffffffffff81811683821601908082111561445e5761445e614390565b5092915050565b67ffffffffffffffff82811682821603908082111561445e5761445e614390565b60006001820161449857614498614390565b5060010190565b6000808335601e198436030181126144b657600080fd5b83018035915067ffffffffffffffff8211156144d157600080fd5b6020019150600581901b36038213156144e957600080fd5b9250929050565b60c081016106668284805182526001600160a01b03602082015116602083015260ff6040820151166040830152606081015160608301526080810151608083015260a081015160a08301525050565b8082018082111561066657610666614390565b60005b8381101561456d578181015183820152602001614555565b50506000910152565b60008351614588818460208801614552565b9190910191825250602001919050565b600181815b808511156145d35781600019048211156145b9576145b9614390565b808516156145c657918102915b93841c939080029061459d565b509250929050565b6000826145ea57506001610666565b816145f757506000610666565b816001811461460d576002811461461757614633565b6001915050610666565b60ff84111561462857614628614390565b50506001821b610666565b5060208310610133831016604e8410600b8410161715614656575081810a610666565b6146608383614598565b806000190482111561467457614674614390565b029392505050565b60006107cd60ff8416836145db565b60ff818116838216019081111561066657610666614390565b60ff828116828216039081111561066657610666614390565b61ffff82811682821603908082111561445e5761445e614390565b60006107cd61ffff8416836145db565b6000602082840312156146fa57600080fd5b6107cd826141bb565b60008235607e1983360301811261471957600080fd5b9190910192915050565b60008060008060008060c0878903121561473c57600080fd5b865161474781614091565b6020880151909650614758816140a6565b6040880151909550614769816140a6565b6060880151909450801515811461477f57600080fd5b809350506080870151915060a087015190509295509295509295565b6000808335601e198436030181126147b257600080fd5b83018035915067ffffffffffffffff8211156147cd57600080fd5b6020019150368190038213156144e957600080fd5b6000602082840312156147f457600080fd5b81356107cd81614091565b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000815260008351614837816017850160208801614552565b7f206973206d697373696e6720726f6c65200000000000000000000000000000006017918401918201528351614874816028840160208801614552565b01602801949350505050565b602081526000825180602084015261489f816040850160208701614552565b601f01601f19169190910160400192915050565b634e487b7160e01b600052604160045260246000fd5b6000816148d8576148d8614390565b50600019019056fea2646970667358221220bf9437374f3c2964ae746fad5e40f62176f0244d2f63eb0765e85a08bf2885f664736f6c63430008130033", - "deployedBytecode": "0x608060405234801561001057600080fd5b50600436106102775760003560e01c806377c75d1011610160578063b6cd5822116100d8578063dfbf53ae1161008c578063f69ee1d111610071578063f69ee1d1146105d5578063f7b188a5146105e8578063fb00f2f3146105f057600080fd5b8063dfbf53ae14610592578063f4e6fcca146105c257600080fd5b8063ce987745116100bd578063ce98774514610564578063d1e8b63d14610577578063d547741f1461057f57600080fd5b8063b6cd582214610537578063c46b40291461054a57600080fd5b80638456cb591161012f5780638d8b6428116101145780638d8b6428146104f057806391d14854146104f8578063a217fddf1461052f57600080fd5b80638456cb59146104e05780638a19c8bc146104e857600080fd5b806377c75d101461045a5780637fe019c61461046d57806382b39b1b1461048857806383220626146104d857600080fd5b80635c975abb116101f357806364c34a85116101c257806369da9114116101a757806369da9114146103de5780636f94aaf2146103f157806372286cba1461040c57600080fd5b806364c34a85146103a957806369bfac01146103b157600080fd5b80635c975abb146103705780635d4844ea1461037b57806362fd29ae1461038e57806363f5cf7c1461039657600080fd5b80632a4e62491161024a5780632f3906da1161022f5780632f3906da1461034257806336568abe1461034a5780635838d6731461035d57600080fd5b80632a4e6249146103185780632f2ff15d1461032d57600080fd5b806301ffc9a71461027c5780631736d472146102a457806318350096146102b7578063248a9ca3146102e7575b600080fd5b61028f61028a366004614067565b610603565b60405190151581526020015b60405180910390f35b61028f6102b23660046140b5565b61066c565b6001546102cf9061010090046001600160a01b031681565b6040516001600160a01b03909116815260200161029b565b61030a6102f53660046140ee565b60009081526020819052604090206001015490565b60405190815260200161029b565b6103206107d4565b60405161029b9190614107565b61034061033b366004614196565b6108e1565b005b61028f61090b565b610340610358366004614196565b610955565b61034061036b3660046141d8565b6109e6565b60015460ff1661028f565b6003546102cf906001600160a01b031681565b61030a610f48565b6103406103a436600461421d565b611014565b61030a6113af565b6008546103c59067ffffffffffffffff1681565b60405167ffffffffffffffff909116815260200161029b565b6002546102cf906001600160a01b031681565b6008546103c590600160801b900467ffffffffffffffff1681565b61041f61041a3660046140ee565b61148f565b604080519687526001600160a01b039095166020870152921515938501939093526060840152608083019190915260a082015260c00161029b565b61028f6104683660046140ee565b6114e6565b6008546103c590600160401b900467ffffffffffffffff1681565b61049b6104963660046140ee565b611796565b604080519687526001600160a01b03909516602087015260ff909316938501939093526060840152608083019190915260a082015260c00161029b565b61030a6117a6565b6103406117b1565b6103c5611814565b61028f611821565b61028f610506366004614196565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b61030a600081565b6103406105453660046142a5565b61184b565b610552611d88565b60405160ff909116815260200161029b565b61030a6105723660046142da565b611e0d565b61028f611e7c565b61034061058d366004614196565b611ea1565b600a54600b54600c54600d54600e5461049b94936001600160a01b03811693600160a01b90910460ff1692909186565b6103406105d0366004614317565b611ec6565b6103406105e33660046140ee565b611fad565b610340612001565b61028f6105fe366004614362565b612062565b60006001600160e01b031982167f7965db0b00000000000000000000000000000000000000000000000000000000148061066657507f01ffc9a7000000000000000000000000000000000000000000000000000000006001600160e01b03198316145b92915050565b600061067661090b565b156106ad576040517fe2586bcc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6106b9609860026143a6565b6106c390436143bd565b60035460405163d1052d1f60e01b81526001600160a01b0386811660048301529091169063d1052d1f90602401602060405180830381865afa15801561070d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061073191906143d0565b1061074f57604051630a0744c560e01b815260040160405180910390fd5b6003546040516397adedb560e01b81526001600160a01b0385811660048301526107cd9216906397adedb590602401602060405180830381865afa15801561079b573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107bf91906143d0565b6107c76113af565b84612062565b9392505050565b60606107de611821565b6107fb57604051633788c6c160e11b815260040160405180910390fd5b6000610805611814565b60085490915067ffffffffffffffff808316600160401b909204161461083e57604051636fbabc7760e01b815260040160405180910390fd5b6005805480602002602001604051908101604052809291908181526020016000905b828210156108d75760008481526020908190206040805160c08101825260058602909201805483526001808201546001600160a01b03811685870152600160a01b900460ff169284019290925260028101546060840152600381015460808401526004015460a08301529083529092019101610860565b5050505091505090565b6000828152602081905260409020600101546108fc8161209e565b61090683836120ab565b505050565b6000806109196098436143ff565b905061092760046098614413565b8110158015610940575061093d60026098614413565b81105b1561094d57600191505090565b600091505090565b6001600160a01b03811633146109d85760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b6109e28282612149565b5050565b6109ee6121c8565b60006109f8611814565b6003546040516397adedb560e01b81523360048201529192506000916001600160a01b03909116906397adedb590602401602060405180830381865afa158015610a46573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a6a91906143d0565b6003546040517f830a053e0000000000000000000000000000000000000000000000000000000081523360048201529192506000916001600160a01b039091169063830a053e90602401602060405180830381865afa158015610ad1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610af591906143d0565b60035460405163d1052d1f60e01b81523360048201529192506000916001600160a01b039091169063d1052d1f90602401602060405180830381865afa158015610b43573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b6791906143d0565b9050610b71611e7c565b610ba7576040517fdc816a8700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001610bb560046098614413565b610bbf91906143bd565b610bca6098436143ff565b03610c01576040517f5baef6b600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8467ffffffffffffffff168467ffffffffffffffff161115610c4f576040517f50ff7c0000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8467ffffffffffffffff168467ffffffffffffffff161015610c9d576040517f7a0c0fd600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b80600003610cd7576040517f039f2e1800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610ce3609860026143a6565b610ced90436143bd565b8110610d0c57604051630a0744c560e01b815260040160405180910390fd5b60085467ffffffffffffffff858116911614610d4c57610d2e60046000613ffe565b6008805467ffffffffffffffff191667ffffffffffffffff86161790555b60045460005b81811015610dbf578460048281548110610d6e57610d6e614427565b90600052602060002090600502016000015403610db7576040517fbfec555800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600101610d52565b506040805160c081018252858152336020808301918252600083850181815260608501898152608086018e815260a0870184815260048054600181018255955296517f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b60059095029485015594517f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19c8401805493516001600160a01b0390921674ffffffffffffffffffffffffffffffffffffffffff1990941693909317600160a01b9115159190910217909155517f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19d82015591517f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19e83015591517f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19f90910155815167ffffffffffffffff891681529081018690527f68e0867601a98978930107aee7f425665e61edd70ca594c68ca5da9e81f84c29910160405180910390a150505050505050565b600080610f53611814565b610f5e90600161443d565b60075460085491925090610f8490600160401b900467ffffffffffffffff16600161443d565b67ffffffffffffffff168267ffffffffffffffff16111561066657600854600090600190610fc390600160401b900467ffffffffffffffff1685614465565b610fcd9190614465565b67ffffffffffffffff1690508181604051602001610ff5929190918252602082015260400190565b6040516020818303038152906040528051906020012091505092915050565b61101c6121c8565b61102461221b565b6040805160c081018252600a548152600b546001600160a01b0381166020830152600160a01b900460ff1691810191909152600c546060820152600d546080820152600e5460a08201526006546007546000918291611084600f826143ff565b9350611091600e826143ff565b92508383106110a857826110a481614486565b9350505b6110bb8660200135838760400151612062565b6110db57604051633b5f43a360e01b8152600360048201526024016109cf565b6110e686601e612827565b6110ef86612b39565b6110f886612e46565b61110b8860200135838760400151612062565b61112b57604051633b5f43a360e01b8152600260048201526024016109cf565b61113f8861113a8660026143a6565b612827565b61114888612b39565b61115188612e46565b6111648760200135838760400151612062565b61118457604051633b5f43a360e01b8152600160048201526024016109cf565b6111938761113a8560026143a6565b61119c87612b39565b6111a587612e46565b61121b84846111b48b8061449f565b60008181106111c5576111c5614427565b602002919091013590506111d98b8061449f565b60008181106111ea576111ea614427565b602002919091013590506111fe8b8061449f565b600081811061120f5761120f614427565b905060200201356130da565b611245611228878061449f565b600081811061123957611239614427565b90506020020135613167565b60015460208601516040517f51cff8d90000000000000000000000000000000000000000000000000000000081526001600160a01b03918216600482015261010090920416906351cff8d990602401600060405180830381600087803b1580156112ae57600080fd5b505af11580156112c2573d6000803e3d6000fd5b505050507f788e77979e6e6a8a6a5d2c19c58b1ff9671298f54c85ac6f6aa30379aed5861a856040516112f591906144f0565b60405180910390a17fbee3fc8a3523c1a65fa9308ce1f2b8fd90c24975b141b754603194597846e4dd60018054906101000a90046001600160a01b03166001600160a01b0316638a5e8e326040518163ffffffff1660e01b8152600401602060405180830381865afa15801561136f573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061139391906143d0565b6040519081526020015b60405180910390a15050505050505050565b60006113b9611e7c565b806113f75750600854600160401b900467ffffffffffffffff166113db611814565b67ffffffffffffffff161180156113f757506113f5611821565b155b15611409576114046117a6565b905090565b611411611821565b1561141e57611404610f48565b61142661090b565b80156114555750600854600160401b900467ffffffffffffffff16611449611814565b67ffffffffffffffff16145b1561148c576040517f36b7884b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b90565b6004818154811061149f57600080fd5b6000918252602090912060059091020180546001820154600283015460038401546004909401549294506001600160a01b03821693600160a01b90920460ff169290919086565b60006114f0611821565b61150d57604051633788c6c160e11b815260040160405180910390fd5b6000611517611814565b60085490915067ffffffffffffffff808316600160401b909204161461155057604051636fbabc7760e01b815260040160405180910390fd5b60085467ffffffffffffffff600160801b90910481169082161161158757604051630c8d9eab60e31b815260040160405180910390fd5b60008060008060008060008061159b6131a5565b905060006115a761325f565b600454919650945060005b8181101561178257600481815481106115cd576115cd614427565b9060005260206000209060050201600401549450600481815481106115f4576115f4614427565b906000526020600020906005020160010160149054906101000a900460ff16801561164257506005858154811061162d5761162d614427565b90600052602060002090600502016004015487145b801561168057506005858154811061165c5761165c614427565b600091825260209091206001600590920201015460ff878116600160a01b90920416145b1561177a576005858154811061169857611698614427565b9060005260206000209060050201600301548b6116b5919061453f565b9a5083836040516020016116ca929190614576565b60408051601f19818403018152919052805160209091012098506fffffffffffffffffffffffffffffffff808a16985061170590600161453f565b6005868154811061171857611718614427565b90600052602060002090600502016003015461173491906143a6565b61173e8c8a6143a6565b101561176c576005858154811061175757611757614427565b90600052602060002090600502016000015499505b8261177681614486565b9350505b6001016115b2565b505050959099149998505050505050505050565b6005818154811061149f57600080fd5b600080610f5e611814565b7f000000000000000000000000000000000000000000000000000000000000000060009081526020818152604080832033845290915290205460ff1661180a57604051631d77d47760e21b815260040160405180910390fd5b611812613418565b565b6000611404609843614413565b600061182f60026098614413565b61183a6098436143ff565b106118455750600190565b50600090565b6118536121c8565b600061185d611814565b6003546040516397adedb560e01b81523360048201529192506000916001600160a01b03909116906397adedb590602401602060405180830381865afa1580156118ab573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118cf91906143d0565b90506118d9611d88565b60ff168560ff161015611918576040517f83d9b7bd00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61192061090b565b611956576040517fd1088db600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60085467ffffffffffffffff83811691161461199e576040517f842a9e0a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60085467ffffffffffffffff838116600160401b9092041614611a86576119c36113af565b6006556119d260056000613ffe565b600880547fffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff16600160401b67ffffffffffffffff8516908102919091179091556006546040805192835260208301919091527ff0ae472da9c8da86bda4991a549c03a3cb328b5f360ea11a5b8814f32bb85176910160405180910390a1611a86600754604080516020810192909252449082015260600160408051601f198184030181529190528051602090910120600755565b6000611a9482878787611e0d565b90506000611aa2838361346c565b9050600060048281548110611ab957611ab9614427565b60009182526020918290206040805160c081018252600593909302909101805480845260018201546001600160a01b03811695850195909552600160a01b90940460ff1615159183019190915260028101546060830152600381015460808301526004015460a0820152600654909250611b3491908a612062565b611b70576006546040517f14ebbbe40000000000000000000000000000000000000000000000000000000081526004016109cf91815260200190565b806040015115611bac576040517fa89ac15100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600160048381548110611bc157611bc1614427565b906000526020600020906005020160010160146101000a81548160ff02191690831515021790555060058054905060048381548110611c0257611c02614427565b90600052602060002090600502016004018190555060056040518060c001604052808360000151815260200183602001516001600160a01b031681526020018a60ff168152602001836060015181526020018a6002611c61919061467c565b8460600151611c7091906143a6565b815260209081018a90528254600181810185556000948552938290208351600590920201908155908201519281018054604084015160ff16600160a01b0274ffffffffffffffffffffffffffffffffffffffffff199091166001600160a01b0390951694909417939093179092556060808201516002808501919091556080830151600385015560a0909201516004909301929092558251918301517f13fc17fd71632266fe82092de6dd91a06b4fa68d8dc950492e5421cbed55a6a5928892909190611d3e908d9061467c565b8560600151611d4d91906143a6565b6040805167ffffffffffffffff909516855260208501939093529183015260608201526080810189905260ff8a1660a082015260c00161139d565b6008546000908190611dad9067ffffffffffffffff600160801b820481169116614465565b67ffffffffffffffff169050600060fe8211611dc95781611dcc565b60fe5b611dd790600161468b565b600b5490915060ff600160a01b9091048116908216811115611e0257611dfd82826146a4565b611e05565b60005b935050505090565b60408051602081018690527fff0000000000000000000000000000000000000000000000000000000000000060f886901b169181019190915260418101839052606181018290526000906081015b6040516020818303038152906040528051906020012090505b949350505050565b6000611e8a60046098614413565b611e956098436143ff565b10156118455750600190565b600082815260208190526040902060010154611ebc8161209e565b6109068383612149565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff16611f1557604051637bfa4b9f60e01b815260040160405180910390fd5b600880547fffffffffffff0000ffffffffffffffffffffffffffffffffffffffffffffffff16600160c01b60ff958616027fffffffffffff00ffffffffffffffffffffffffffffffffffffffffffffffffff1617600160c81b93851693909302929092177fffffffffff00ffffffffffffffffffffffffffffffffffffffffffffffffffff16600160d01b9190931602919091179055565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff16611ffc57604051637bfa4b9f60e01b815260040160405180910390fd5b600955565b7f000000000000000000000000000000000000000000000000000000000000000060009081526020818152604080832033845290915290205460ff1661205a57604051631d77d47760e21b815260040160405180910390fd5b611812613517565b60008160ff16600003612077575060016107cd565b61208660ff83166101006146bd565b6120919060026146d8565b8484181090509392505050565b6120a88133613550565b50565b6000828152602081815260408083206001600160a01b038516845290915290205460ff166109e2576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556121053390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16156109e2576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b60015460ff16156118125760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a207061757365640000000000000000000000000000000060448201526064016109cf565b6000612225611814565b905061222f611821565b61224c57604051633788c6c160e11b815260040160405180910390fd5b60085467ffffffffffffffff828116600160401b909204161461228257604051636fbabc7760e01b815260040160405180910390fd5b60085467ffffffffffffffff600160801b9091048116908216116122b957604051630c8d9eab60e31b815260040160405180910390fd5b600454604051818152600091829182918291829182917f6752c5e71c95fb93bc7137adeb115a33fa4e54e2683e33d3f90c2bb1c4b6c2a59060200160405180910390a16005546040519081527f4c03de6a759749c0c9387b7014634dc5c6af610e1366023d90751c783a998f8d9060200160405180910390a161233a61325f565b6040805183815260ff831660208201529295509093507f34e8eda4cd857cd2865becf58a47748f31415f4a382cbb2cc0c64b9a27c717be910160405180910390a160006123856131a5565b905060005b82811015612761576000600482815481106123a7576123a7614427565b600091825260208083206040805160c08101825260059485029092018054835260018101546001600160a01b03811694840194909452600160a01b90930460ff16151590820152600282015460608201526003820154608082015260049091015460a0820181905282549194509291908390811061242757612427614427565b60009182526020918290206040805160c0810182526005939093029091018054835260018101546001600160a01b03811694840194909452600160a01b90930460ff1682820152600283015460608301526003830154608083015260049092015460a08201529084015190915080156124a357508060a0015188145b80156124b85750806040015160ff168760ff16145b156125ad5760808101516124cc908d61453f565b9b50848b6040516020016124e1929190614576565b60408051601f19818403018152919052805160209091012099506fffffffffffffffffffffffffffffffff808b16995061251c90600161453f565b816080015161252b91906143a6565b6125358d8b6143a6565b101561259f578051600a556020810151600b8054604084015160ff16600160a01b0274ffffffffffffffffffffffffffffffffffffffffff199091166001600160a01b03909316929092179190911790556060810151600c556080810151600d5560a0810151600e555b8a6125a981614486565b9b50505b826040015180156125d657508060a00151881415806125d65750806040015160ff168760ff1614155b80156125f75750600854600160d01b900460ff166125f56064446143ff565b105b156126a35760035460208201516001600160a01b039091169063d009b2d6906126218a600261467c565b60085461263a90609890600160c01b900460ff166143a6565b61264491906143a6565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401600060405180830381600087803b15801561268a57600080fd5b505af115801561269e573d6000803e3d6000fd5b505050505b82604001516127535760035460208401516001600160a01b039091169063d009b2d6906126d18a600261467c565b6008546126ea90609890600160c81b900460ff166143a6565b6126f491906143a6565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401600060405180830381600087803b15801561273a57600080fd5b505af115801561274e573d6000803e3d6000fd5b505050505b83600101935050505061238a565b506002546040517fffb98fe300000000000000000000000000000000000000000000000000000000815261ffff891660048201526001600160a01b039091169063ffb98fe390602401600060405180830381600087803b1580156127c457600080fd5b505af11580156127d8573d6000803e3d6000fd5b50506008805467ffffffffffffffff909c16600160801b027fffffffffffffffff0000000000000000ffffffffffffffffffffffffffffffff909c169b909b17909a5550505050505050505050565b600754600090612839906080906143ff565b9050600061289c61284d60a086018661449f565b8080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525050505060608601358461289460a0890160808a016146e8565b6006546135c3565b60408051858152602081018390529192507f94e252069a85aa79db21f5bd8ca4e14dd3a3927aa492711017a2c8ddad95af00910160405180910390a16129246128e5858061449f565b8080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525050505060208601358561040061373b565b600e541461294f5760405163755f0a2560e01b815260016004820152602481018290526044016109cf565b61295c60a085018561449f565b600081811061296d5761296d614427565b90506020020135848060400190612984919061449f565b600081811061299557612995614427565b90506020020135146129c45760405163755f0a2560e01b815260026004820152602481018290526044016109cf565b6000806129d460e087018761449f565b9050116129e5578460200135612a1a565b6129f260e086018661449f565b6000818110612a0357612a03614427565b9050602002810190612a159190614703565b606001355b9050612a78612a2c604087018761449f565b80806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250505050606087013585612a7360a08a0160808b016146e8565b61373b565b8114612aa15760405163755f0a2560e01b815260036004820152602481018390526044016109cf565b6000612ab060e087018761449f565b90501115612ae85760408051602080880135908201529081018390526060016040516020818303038152906040528051906020012091505b81612af3868061449f565b6000818110612b0457612b04614427565b9050602002013514612b325760405163755f0a2560e01b8152600481810152602481018390526044016109cf565b5050505050565b6001546000908190819061010090046001600160a01b031663c81e25ab612b6360c0870187614703565b602001356040518263ffffffff1660e01b8152600401612b8591815260200190565b60c060405180830381865afa158015612ba2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612bc69190614723565b509396509194509250506001600160a01b0384169050612c2657612bed60c0850185614703565b602001356040517f2396d34e0000000000000000000000000000000000000000000000000000000081526004016109cf91815260200190565b6000612c49612c3860c0870187614703565b61148c9060608101906040016146e8565b90506000612c5784846138a9565b9050808263ffffffff1610612cac57612c7360c0870187614703565b602001356040517f1362e4a00000000000000000000000000000000000000000000000000000000081526004016109cf91815260200190565b6000612cdb612cbe60c0890189614703565b612ccf9060608101906040016146e8565b60201c63ffffffff1690565b90506000612ced8860200135866138c4565b63ffffffff16905067ffffffffffffffff82168114612d4c57612d1360c0890189614703565b602001356040517f6dd6a24f0000000000000000000000000000000000000000000000000000000081526004016109cf91815260200190565b612df287612d5d60c08b018b614703565b612d67908061479b565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050505060208b0135612dad60c08d018d614703565b60200135612dbe60c08e018e614703565b612dcf9060608101906040016146e8565b612ddc60c08f018f614703565b612ded9060808101906060016146e8565b6138eb565b612e3c57612e0360c0890189614703565b602001356040517fdb12fb9d0000000000000000000000000000000000000000000000000000000081526004016109cf91815260200190565b5050505050505050565b612e5360e082018261449f565b9050600003612e5f5750565b612f80612e6f60e083018361449f565b6000818110612e8057612e80614427565b9050602002810190612e929190614703565b612ea09060208101906147e2565b612ead60e084018461449f565b6000818110612ebe57612ebe614427565b9050602002810190612ed09190614703565b612ede90602081019061479b565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250612f209250505060e085018561449f565b6000818110612f3157612f31614427565b9050602002810190612f439190614703565b60400135612f5460e086018661449f565b6000818110612f6557612f65614427565b9050602002810190612f779190614703565b60600135613982565b612fed57612f9160e082018261449f565b6000818110612fa257612fa2614427565b9050602002810190612fb49190614703565b606001356040517fd740df610000000000000000000000000000000000000000000000000000000081526004016109cf91815260200190565b602081013561306c61300260e084018461449f565b600081811061301357613013614427565b90506020028101906130259190614703565b6040013561303660e085018561449f565b600081811061304757613047614427565b90506020028101906130599190614703565b6130679060208101906147e2565b613a15565b146120a85761307e60e082018261449f565b600081811061308f5761308f614427565b90506020028101906130a19190614703565b606001356040517f82f2469d0000000000000000000000000000000000000000000000000000000081526004016109cf91815260200190565b838510156131275781831061310257604051633d386eb360e11b815260040160405180910390fd5b80821061312257604051633588c6d360e11b815260040160405180910390fd5b612b32565b82821061314757604051633d386eb360e11b815260040160405180910390fd5b808310612b3257604051633588c6d360e11b815260040160405180910390fd5b60095481106120a8576040517fb6052cdf000000000000000000000000000000000000000000000000000000008152600481018290526024016109cf565b60606131af611821565b6131cc57604051633788c6c160e11b815260040160405180910390fd5b60006131d6611814565b60085490915067ffffffffffffffff808316600160401b909204161461320f57604051636fbabc7760e01b815260040160405180910390fd5b60075460405160200161324a9181527f3100000000000000000000000000000000000000000000000000000000000000602082015260210190565b60405160208183030381529060405291505090565b6000806000806000806000806000613275613a63565b60045490915060005b81811015613407576004818154811061329957613299614427565b906000526020600020906005020160010160149054906101000a900460ff16156133ff57600481815481106132d0576132d0614427565b9060005260206000209060050201600401549350600584815481106132f7576132f7614427565b90600052602060002090600502016003015489613314919061453f565b98508281604051602001613329929190614576565b60408051601f19818403018152919052805160209091012097506fffffffffffffffffffffffffffffffff808916975061336490600161453f565b6005858154811061337757613377614427565b90600052602060002090600502016003015461339391906143a6565b61339d8a896143a6565b10156133ff57600584815481106133b6576133b6614427565b9060005260206000209060050201600401549550600584815481106133dd576133dd614427565b906000526020600020906005020160010160149054906101000a900460ff1694505b60010161327e565b509399929850919650505050505050565b6134206121c8565b6001805460ff1916811790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258335b6040516001600160a01b03909116815260200160405180910390a1565b6000805b6004548110156134e457836004828154811061348e5761348e614427565b9060005260206000209060050201600001541480156134d05750600481815481106134bb576134bb614427565b90600052602060002090600502016003015483145b156134dc579050610666565b600101613470565b506040517fd950091500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61351f613aec565b6001805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa3361344f565b6000828152602081815260408083206001600160a01b038516845290915290205460ff166109e25761358181613b3e565b61358c836020613b50565b60405160200161359d9291906147ff565b60408051601f198184030181529082905262461bcd60e51b82526109cf91600401614880565b6000806135d287878786613d15565b9050826136d7856000808267ffffffffffffffff1690506008817eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff16901b600882901c7eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff161790506010817dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff16901b601082901c7dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff161790506020817bffffffff00000000ffffffff00000000ffffffff00000000ffffffff16901b602082901c7bffffffff00000000ffffffff00000000ffffffff00000000ffffffff1617905080915050919050565b826040516020016137199392919092835260c09190911b77ffffffffffffffffffffffffffffffffffffffffffffffff19166020830152602882015260480190565b6040516020818303038152906040528051906020012091505095945050505050565b600080613749868686613d8b565b905061384d836000808267ffffffffffffffff1690506008817eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff16901b600882901c7eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff161790506010817dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff16901b601082901c7dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff161790506020817bffffffff00000000ffffffff00000000ffffffff00000000ffffffff16901b602082901c7bffffffff00000000ffffffff00000000ffffffff00000000ffffffff1617905080915050919050565b8160405160200161388892919060c09290921b77ffffffffffffffffffffffffffffffffffffffffffffffff19168252600882015260280190565b60405160208183030381529060405280519060200120915050949350505050565b60006138b582846146a4565b60ff166001901b905092915050565b600060e083901c6138d68360206146a4565b60ff168163ffffffff16901c91505092915050565b6000806138fa86868686613df3565b90506000613955826040517f19457468657265756d205369676e6564204d6573736167653a0a3332000000006020820152603c8101829052600090605c01604051602081830303815290604052805190602001209050919050565b9050886001600160a01b031661396b828a613e3e565b6001600160a01b0316149998505050505050505050565b60008061398f8484613ebd565b905060006139ea826040517f19457468657265756d205369676e6564204d6573736167653a0a3332000000006020820152603c8101829052600090605c01604051602081830303815290604052805190602001209050919050565b9050866001600160a01b0316613a008288613e3e565b6001600160a01b031614979650505050505050565b60008282604051602001613a4592919091825260601b6bffffffffffffffffffffffff1916602082015260340190565b60405160208183030381529060405280519060200120905092915050565b6060613a6d611821565b613a8a57604051633788c6c160e11b815260040160405180910390fd5b6000613a94611814565b60085490915067ffffffffffffffff808316600160401b9092041614613acd57604051636fbabc7760e01b815260040160405180910390fd5b60075460405160200161324a918152600360fc1b602082015260210190565b60015460ff166118125760405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f742070617573656400000000000000000000000060448201526064016109cf565b60606106666001600160a01b03831660145b60606000613b5f8360026143a6565b613b6a90600261453f565b67ffffffffffffffff811115613b8257613b826148b3565b6040519080825280601f01601f191660200182016040528015613bac576020820181803683370190505b509050600360fc1b81600081518110613bc757613bc7614427565b60200101906001600160f81b031916908160001a9053507f780000000000000000000000000000000000000000000000000000000000000081600181518110613c1257613c12614427565b60200101906001600160f81b031916908160001a9053506000613c368460026143a6565b613c4190600161453f565b90505b6001811115613cc6577f303132333435363738396162636465660000000000000000000000000000000085600f1660108110613c8257613c82614427565b1a60f81b828281518110613c9857613c98614427565b60200101906001600160f81b031916908160001a90535060049490941c93613cbf816148c9565b9050613c44565b5083156107cd5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e7460448201526064016109cf565b8260005b8551811015613d82576000613d2f6002866143ff565b15613d3b576000613d3e565b60015b9050613d6583888481518110613d5657613d56614427565b60200260200101518387613ed9565b9250600185901c9450508080613d7a90614486565b915050613d19565b50949350505050565b8160005b8451811015613deb576000613da56002856143ff565b6000149050613dce83878481518110613dc057613dc0614427565b602002602001015183613f39565b9250600184901c9350508080613de390614486565b915050613d8f565b509392505050565b604080516020810186905290810184905277ffffffffffffffffffffffffffffffffffffffffffffffff1960c084811b8216606084015283901b166068820152600090607001611e5b565b600080600080613e4d85613fa0565b6040805160008152602081018083528b905260ff8316918101919091526060810184905260808101839052929550909350915060019060a0016020604051602081039080840390855afa158015613ea8573d6000803e3d6000fd5b5050604051601f190151979650505050505050565b6040805160208101849052908101829052600090606001613a45565b60008215613f1957604080516020810184905290810186905260608101859052608001604051602081830303815290604052805190602001209050611e74565b604080516020810184905290810185905260608101869052608001611e5b565b60008115613f725760408051602081018690529081018490526060016040516020818303038152906040528051906020012090506107cd565b5050604080516020808201939093528082019390935280518084038201815260609093019052815191012090565b60008060008351604114613fe0576040517f4be6321b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50505060208101516040820151606090920151909260009190911a90565b50805460008255600502906000526020600020908101906120a891905b8082111561406357600080825560018201805474ffffffffffffffffffffffffffffffffffffffffff191690556002820181905560038201819055600482015560050161401b565b5090565b60006020828403121561407957600080fd5b81356001600160e01b0319811681146107cd57600080fd5b6001600160a01b03811681146120a857600080fd5b60ff811681146120a857600080fd5b600080604083850312156140c857600080fd5b82356140d381614091565b915060208301356140e3816140a6565b809150509250929050565b60006020828403121561410057600080fd5b5035919050565b6020808252825182820181905260009190848201906040850190845b8181101561418a57614177838551805182526001600160a01b03602082015116602083015260ff6040820151166040830152606081015160608301526080810151608083015260a081015160a08301525050565b9284019260c09290920191600101614123565b50909695505050505050565b600080604083850312156141a957600080fd5b8235915060208301356140e381614091565b803567ffffffffffffffff811681146141d357600080fd5b919050565b600080604083850312156141eb57600080fd5b823591506141fb602084016141bb565b90509250929050565b6000610100828403121561421757600080fd5b50919050565b60008060006060848603121561423257600080fd5b833567ffffffffffffffff8082111561424a57600080fd5b61425687838801614204565b9450602086013591508082111561426c57600080fd5b61427887838801614204565b9350604086013591508082111561428e57600080fd5b5061429b86828701614204565b9150509250925092565b6000806000606084860312156142ba57600080fd5b83356142c5816140a6565b95602085013595506040909401359392505050565b600080600080608085870312156142f057600080fd5b843593506020850135614302816140a6565b93969395505050506040820135916060013590565b60008060006060848603121561432c57600080fd5b8335614337816140a6565b92506020840135614347816140a6565b91506040840135614357816140a6565b809150509250925092565b60008060006060848603121561437757600080fd5b83359250602084013591506040840135614357816140a6565b634e487b7160e01b600052601160045260246000fd5b808202811582820484141761066657610666614390565b8181038181111561066657610666614390565b6000602082840312156143e257600080fd5b5051919050565b634e487b7160e01b600052601260045260246000fd5b60008261440e5761440e6143e9565b500690565b600082614422576144226143e9565b500490565b634e487b7160e01b600052603260045260246000fd5b67ffffffffffffffff81811683821601908082111561445e5761445e614390565b5092915050565b67ffffffffffffffff82811682821603908082111561445e5761445e614390565b60006001820161449857614498614390565b5060010190565b6000808335601e198436030181126144b657600080fd5b83018035915067ffffffffffffffff8211156144d157600080fd5b6020019150600581901b36038213156144e957600080fd5b9250929050565b60c081016106668284805182526001600160a01b03602082015116602083015260ff6040820151166040830152606081015160608301526080810151608083015260a081015160a08301525050565b8082018082111561066657610666614390565b60005b8381101561456d578181015183820152602001614555565b50506000910152565b60008351614588818460208801614552565b9190910191825250602001919050565b600181815b808511156145d35781600019048211156145b9576145b9614390565b808516156145c657918102915b93841c939080029061459d565b509250929050565b6000826145ea57506001610666565b816145f757506000610666565b816001811461460d576002811461461757614633565b6001915050610666565b60ff84111561462857614628614390565b50506001821b610666565b5060208310610133831016604e8410600b8410161715614656575081810a610666565b6146608383614598565b806000190482111561467457614674614390565b029392505050565b60006107cd60ff8416836145db565b60ff818116838216019081111561066657610666614390565b60ff828116828216039081111561066657610666614390565b61ffff82811682821603908082111561445e5761445e614390565b60006107cd61ffff8416836145db565b6000602082840312156146fa57600080fd5b6107cd826141bb565b60008235607e1983360301811261471957600080fd5b9190910192915050565b60008060008060008060c0878903121561473c57600080fd5b865161474781614091565b6020880151909650614758816140a6565b6040880151909550614769816140a6565b6060880151909450801515811461477f57600080fd5b809350506080870151915060a087015190509295509295509295565b6000808335601e198436030181126147b257600080fd5b83018035915067ffffffffffffffff8211156147cd57600080fd5b6020019150368190038213156144e957600080fd5b6000602082840312156147f457600080fd5b81356107cd81614091565b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000815260008351614837816017850160208801614552565b7f206973206d697373696e6720726f6c65200000000000000000000000000000006017918401918201528351614874816028840160208801614552565b01602801949350505050565b602081526000825180602084015261489f816040850160208701614552565b601f01601f19169190910160400192915050565b634e487b7160e01b600052604160045260246000fd5b6000816148d8576148d8614390565b50600019019056fea2646970667358221220bf9437374f3c2964ae746fad5e40f62176f0244d2f63eb0765e85a08bf2885f664736f6c63430008130033", + "solcInputHash": "99c9ef5f7ef53ea99ef6c816b26b1e5c", + "metadata": "{\"compiler\":{\"version\":\"0.8.19+commit.7dd6d404\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"staking\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"postageContract\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"oracleContract\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[],\"name\":\"AlreadyClaimed\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"AlreadyCommitted\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"AlreadyRevealed\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"BatchDoesNotExist\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"BucketDiffers\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"CommitRoundNotStarted\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"CommitRoundOver\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"FirstRevealDone\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"uint8\",\"name\":\"\",\"type\":\"uint8\"},{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"InclusionProofFailed\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"IndexOutsideSet\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"InvalidSignatureLength\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"LastElementCheckFailed\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"MustStake2Rounds\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NoCommitsReceived\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NoMatchingCommit\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NoReveals\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NotAdmin\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NotClaimPhase\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NotCommitPhase\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NotMatchingOwner\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NotRevealPhase\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NotStaked\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"OnlyPauser\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"OutOfDepth\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"uint8\",\"name\":\"\",\"type\":\"uint8\"}],\"name\":\"OutOfDepthClaim\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"OutOfDepthReveal\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"PhaseLastBlock\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"RandomElementCheckFailed\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"trALast\",\"type\":\"bytes32\"}],\"name\":\"ReserveCheckFailed\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"SigRecoveryFailed\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"SocCalcNotMatching\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"SocVerificationFailed\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"WrongPhase\",\"type\":\"error\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"validChunkCount\",\"type\":\"uint256\"}],\"name\":\"ChunkCount\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"roundNumber\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"}],\"name\":\"Committed\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"_count\",\"type\":\"uint256\"}],\"name\":\"CountCommits\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"_count\",\"type\":\"uint256\"}],\"name\":\"CountReveals\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"roundNumber\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"anchor\",\"type\":\"bytes32\"}],\"name\":\"CurrentRevealAnchor\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"Paused\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint16\",\"name\":\"redundancyCount\",\"type\":\"uint16\"}],\"name\":\"PriceAdjustmentSkipped\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"roundNumber\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"stake\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"stakeDensity\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"reserveCommitment\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint8\",\"name\":\"depth\",\"type\":\"uint8\"}],\"name\":\"Revealed\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"previousAdminRole\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"newAdminRole\",\"type\":\"bytes32\"}],\"name\":\"RoleAdminChanged\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"}],\"name\":\"RoleGranted\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"}],\"name\":\"RoleRevoked\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"hash\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint8\",\"name\":\"depth\",\"type\":\"uint8\"}],\"name\":\"TruthSelected\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"Unpaused\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"components\":[{\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"uint8\",\"name\":\"depth\",\"type\":\"uint8\"},{\"internalType\":\"uint256\",\"name\":\"stake\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"stakeDensity\",\"type\":\"uint256\"},{\"internalType\":\"bytes32\",\"name\":\"hash\",\"type\":\"bytes32\"}],\"indexed\":false,\"internalType\":\"struct Redistribution.Reveal\",\"name\":\"winner\",\"type\":\"tuple\"}],\"name\":\"WinnerSelected\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"}],\"name\":\"WithdrawFailed\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"indexInRC\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"chunkAddress\",\"type\":\"bytes32\"}],\"name\":\"transformedChunkAddressFromInclusionProof\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"DEFAULT_ADMIN_ROLE\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"OracleContract\",\"outputs\":[{\"internalType\":\"contract IPriceOracle\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"PostageContract\",\"outputs\":[{\"internalType\":\"contract IPostageStamp\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"Stakes\",\"outputs\":[{\"internalType\":\"contract IStakeRegistry\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"components\":[{\"internalType\":\"bytes32[]\",\"name\":\"proofSegments\",\"type\":\"bytes32[]\"},{\"internalType\":\"bytes32\",\"name\":\"proveSegment\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32[]\",\"name\":\"proofSegments2\",\"type\":\"bytes32[]\"},{\"internalType\":\"bytes32\",\"name\":\"proveSegment2\",\"type\":\"bytes32\"},{\"internalType\":\"uint64\",\"name\":\"chunkSpan\",\"type\":\"uint64\"},{\"internalType\":\"bytes32[]\",\"name\":\"proofSegments3\",\"type\":\"bytes32[]\"},{\"components\":[{\"internalType\":\"bytes\",\"name\":\"signature\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"postageId\",\"type\":\"bytes32\"},{\"internalType\":\"uint64\",\"name\":\"index\",\"type\":\"uint64\"},{\"internalType\":\"uint64\",\"name\":\"timeStamp\",\"type\":\"uint64\"}],\"internalType\":\"struct Redistribution.PostageProof\",\"name\":\"postageProof\",\"type\":\"tuple\"},{\"components\":[{\"internalType\":\"address\",\"name\":\"signer\",\"type\":\"address\"},{\"internalType\":\"bytes\",\"name\":\"signature\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"identifier\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"chunkAddr\",\"type\":\"bytes32\"}],\"internalType\":\"struct Redistribution.SOCProof[]\",\"name\":\"socProof\",\"type\":\"tuple[]\"}],\"internalType\":\"struct Redistribution.ChunkInclusionProof\",\"name\":\"entryProof1\",\"type\":\"tuple\"},{\"components\":[{\"internalType\":\"bytes32[]\",\"name\":\"proofSegments\",\"type\":\"bytes32[]\"},{\"internalType\":\"bytes32\",\"name\":\"proveSegment\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32[]\",\"name\":\"proofSegments2\",\"type\":\"bytes32[]\"},{\"internalType\":\"bytes32\",\"name\":\"proveSegment2\",\"type\":\"bytes32\"},{\"internalType\":\"uint64\",\"name\":\"chunkSpan\",\"type\":\"uint64\"},{\"internalType\":\"bytes32[]\",\"name\":\"proofSegments3\",\"type\":\"bytes32[]\"},{\"components\":[{\"internalType\":\"bytes\",\"name\":\"signature\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"postageId\",\"type\":\"bytes32\"},{\"internalType\":\"uint64\",\"name\":\"index\",\"type\":\"uint64\"},{\"internalType\":\"uint64\",\"name\":\"timeStamp\",\"type\":\"uint64\"}],\"internalType\":\"struct Redistribution.PostageProof\",\"name\":\"postageProof\",\"type\":\"tuple\"},{\"components\":[{\"internalType\":\"address\",\"name\":\"signer\",\"type\":\"address\"},{\"internalType\":\"bytes\",\"name\":\"signature\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"identifier\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"chunkAddr\",\"type\":\"bytes32\"}],\"internalType\":\"struct Redistribution.SOCProof[]\",\"name\":\"socProof\",\"type\":\"tuple[]\"}],\"internalType\":\"struct Redistribution.ChunkInclusionProof\",\"name\":\"entryProof2\",\"type\":\"tuple\"},{\"components\":[{\"internalType\":\"bytes32[]\",\"name\":\"proofSegments\",\"type\":\"bytes32[]\"},{\"internalType\":\"bytes32\",\"name\":\"proveSegment\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32[]\",\"name\":\"proofSegments2\",\"type\":\"bytes32[]\"},{\"internalType\":\"bytes32\",\"name\":\"proveSegment2\",\"type\":\"bytes32\"},{\"internalType\":\"uint64\",\"name\":\"chunkSpan\",\"type\":\"uint64\"},{\"internalType\":\"bytes32[]\",\"name\":\"proofSegments3\",\"type\":\"bytes32[]\"},{\"components\":[{\"internalType\":\"bytes\",\"name\":\"signature\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"postageId\",\"type\":\"bytes32\"},{\"internalType\":\"uint64\",\"name\":\"index\",\"type\":\"uint64\"},{\"internalType\":\"uint64\",\"name\":\"timeStamp\",\"type\":\"uint64\"}],\"internalType\":\"struct Redistribution.PostageProof\",\"name\":\"postageProof\",\"type\":\"tuple\"},{\"components\":[{\"internalType\":\"address\",\"name\":\"signer\",\"type\":\"address\"},{\"internalType\":\"bytes\",\"name\":\"signature\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"identifier\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"chunkAddr\",\"type\":\"bytes32\"}],\"internalType\":\"struct Redistribution.SOCProof[]\",\"name\":\"socProof\",\"type\":\"tuple[]\"}],\"internalType\":\"struct Redistribution.ChunkInclusionProof\",\"name\":\"entryProofLast\",\"type\":\"tuple\"}],\"name\":\"claim\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"_obfuscatedHash\",\"type\":\"bytes32\"},{\"internalType\":\"uint64\",\"name\":\"_roundNumber\",\"type\":\"uint64\"}],\"name\":\"commit\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentClaimRound\",\"outputs\":[{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentCommitRound\",\"outputs\":[{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"currentCommits\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"revealed\",\"type\":\"bool\"},{\"internalType\":\"uint8\",\"name\":\"height\",\"type\":\"uint8\"},{\"internalType\":\"uint256\",\"name\":\"stake\",\"type\":\"uint256\"},{\"internalType\":\"bytes32\",\"name\":\"obfuscatedHash\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"revealIndex\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentMinimumDepth\",\"outputs\":[{\"internalType\":\"uint8\",\"name\":\"\",\"type\":\"uint8\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentPhaseClaim\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentPhaseCommit\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentPhaseReveal\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentRevealRound\",\"outputs\":[{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"currentReveals\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"uint8\",\"name\":\"depth\",\"type\":\"uint8\"},{\"internalType\":\"uint256\",\"name\":\"stake\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"stakeDensity\",\"type\":\"uint256\"},{\"internalType\":\"bytes32\",\"name\":\"hash\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentRound\",\"outputs\":[{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentRoundAnchor\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"returnVal\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentRoundReveals\",\"outputs\":[{\"components\":[{\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"uint8\",\"name\":\"depth\",\"type\":\"uint8\"},{\"internalType\":\"uint256\",\"name\":\"stake\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"stakeDensity\",\"type\":\"uint256\"},{\"internalType\":\"bytes32\",\"name\":\"hash\",\"type\":\"bytes32\"}],\"internalType\":\"struct Redistribution.Reveal[]\",\"name\":\"\",\"type\":\"tuple[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"currentSeed\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"}],\"name\":\"getRoleAdmin\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"grantRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"hasRole\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"A\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"B\",\"type\":\"bytes32\"},{\"internalType\":\"uint8\",\"name\":\"minimum\",\"type\":\"uint8\"}],\"name\":\"inProximity\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"pure\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_owner\",\"type\":\"address\"},{\"internalType\":\"uint8\",\"name\":\"_depth\",\"type\":\"uint8\"}],\"name\":\"isParticipatingInUpcomingRound\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"_overlay\",\"type\":\"bytes32\"}],\"name\":\"isWinner\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"nextSeed\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"pause\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"paused\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"renounceRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint8\",\"name\":\"_depth\",\"type\":\"uint8\"},{\"internalType\":\"bytes32\",\"name\":\"_hash\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"_revealNonce\",\"type\":\"bytes32\"}],\"name\":\"reveal\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"revokeRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint8\",\"name\":\"_penaltyMultiplierDisagreement\",\"type\":\"uint8\"},{\"internalType\":\"uint8\",\"name\":\"_penaltyMultiplierNonRevealed\",\"type\":\"uint8\"},{\"internalType\":\"uint8\",\"name\":\"_penaltyRandomFactor\",\"type\":\"uint8\"}],\"name\":\"setFreezingParams\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_sampleMaxValue\",\"type\":\"uint256\"}],\"name\":\"setSampleMaxValue\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes4\",\"name\":\"interfaceId\",\"type\":\"bytes4\"}],\"name\":\"supportsInterface\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"unPause\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"winner\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"uint8\",\"name\":\"depth\",\"type\":\"uint8\"},{\"internalType\":\"uint256\",\"name\":\"stake\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"stakeDensity\",\"type\":\"uint256\"},{\"internalType\":\"bytes32\",\"name\":\"hash\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"_overlay\",\"type\":\"bytes32\"},{\"internalType\":\"uint8\",\"name\":\"_depth\",\"type\":\"uint8\"},{\"internalType\":\"bytes32\",\"name\":\"_hash\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"revealNonce\",\"type\":\"bytes32\"}],\"name\":\"wrapCommit\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"pure\",\"type\":\"function\"}],\"devdoc\":{\"author\":\"The Swarm Authors\",\"details\":\"Implements a Schelling Co-ordination game to form consensus around the Reserve Commitment hash. This takes place in three phases: _commit_, _reveal_ and _claim_. A node, upon establishing that it _isParticipatingInUpcomingRound_, i.e. it's overlay falls within proximity order of its reported depth with the _currentRoundAnchor_, prepares a \\\"reserve commitment hash\\\" using the chunks it currently stores in its reserve and calculates the \\\"storage depth\\\" (see Bee for details). These values, if calculated honestly, and with the right chunks stored, should be the same for every node in a neighbourhood. This is the Schelling point. Each eligible node can then use these values, together with a random, single use, secret _revealNonce_ and their _overlay_ as the pre-image values for the obsfucated _commit_, using the _wrapCommit_ method. Once the _commit_ round has elapsed, participating nodes must provide the values used to calculate their obsfucated _commit_ hash, which, once verified for correctness and proximity to the anchor are retained in the _currentReveals_. Nodes that have committed but do not reveal the correct values used to create the pre-image will have their stake \\\"frozen\\\" for a period of rounds proportional to their reported depth. During the _reveal_ round, randomness is updated after every successful reveal. Once the reveal round is concluded, the _currentRoundAnchor_ is updated and users can determine if they will be eligible their overlay will be eligible for the next commit phase using _isParticipatingInUpcomingRound_. When the _reveal_ phase has been concluded, the claim phase can begin. At this point, the truth teller and winner are already determined. By calling _isWinner_, an applicant node can run the relevant logic to determine if they have been selected as the beneficiary of this round. When calling _claim_, the current pot from the PostageStamp contract is withdrawn and transferred to that beneficiaries address. Nodes that have revealed values that differ from the truth, have their stakes \\\"frozen\\\" for a period of rounds proportional to their reported depth.\",\"events\":{\"ChunkCount(uint256)\":{\"details\":\"Emit from Postagestamp contract valid chunk count at the end of claim\"},\"Committed(uint256,bytes32)\":{\"details\":\"Logs that an overlay has committed\"},\"CountCommits(uint256)\":{\"details\":\"Emits the number of commits being processed by the claim phase.\"},\"CountReveals(uint256)\":{\"details\":\"Emits the number of reveals being processed by the claim phase.\"},\"CurrentRevealAnchor(uint256,bytes32)\":{\"details\":\"Bytes32 anhor of current reveal round\"},\"Paused(address)\":{\"details\":\"Emitted when the pause is triggered by `account`.\"},\"PriceAdjustmentSkipped(uint16)\":{\"details\":\"Output external call status\"},\"Revealed(uint256,bytes32,uint256,uint256,bytes32,uint8)\":{\"details\":\"Logs that an overlay has revealed\"},\"RoleAdminChanged(bytes32,bytes32,bytes32)\":{\"details\":\"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._\"},\"RoleGranted(bytes32,address,address)\":{\"details\":\"Emitted when `account` is granted `role`. `sender` is the account that originated the contract call, an admin role bearer except when using {AccessControl-_setupRole}.\"},\"RoleRevoked(bytes32,address,address)\":{\"details\":\"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`)\"},\"TruthSelected(bytes32,uint8)\":{\"details\":\"Emitted when the truth oracle of a round is selected in the claim phase.\"},\"Unpaused(address)\":{\"details\":\"Emitted when the pause is lifted by `account`.\"},\"WinnerSelected((bytes32,address,uint8,uint256,uint256,bytes32))\":{\"details\":\"Emitted when the winner of a round is selected in the claim phase\"},\"WithdrawFailed(address)\":{\"details\":\"Withdraw not successful in claim\"},\"transformedChunkAddressFromInclusionProof(uint256,bytes32)\":{\"details\":\"Logs for inclusion proof\"}},\"kind\":\"dev\",\"methods\":{\"commit(bytes32,uint64)\":{\"details\":\"If a node's overlay is _inProximity_(_depth_) of the _currentRoundAnchor_, that node may compute an _obfuscatedHash_ by providing their _overlay_, reported storage _depth_, reserve commitment _hash_ and a randomly generated, and secret _revealNonce_ to the _wrapCommit_ method.\",\"params\":{\"_obfuscatedHash\":\"The calculated hash resultant of the required pre-image values. and be derived from the same key pair as the message sender.\",\"_roundNumber\":\"Node needs to provide round number for which commit is valid\"}},\"constructor\":{\"params\":{\"oracleContract\":\"the address of the linked PriceOracle contract.\",\"postageContract\":\"the address of the linked PostageStamp contract.\",\"staking\":\"the address of the linked Staking contract.\"}},\"currentRoundAnchor()\":{\"details\":\"A node must be within proximity order of less than or equal to the storage depth they intend to report.\"},\"getRoleAdmin(bytes32)\":{\"details\":\"Returns the admin role that controls `role`. See {grantRole} and {revokeRole}. To change a role's admin, use {_setRoleAdmin}.\"},\"grantRole(bytes32,address)\":{\"details\":\"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.\"},\"hasRole(bytes32,address)\":{\"details\":\"Returns `true` if `account` has been granted `role`.\"},\"inProximity(bytes32,bytes32,uint8)\":{\"params\":{\"A\":\"An overlay address to compare.\",\"B\":\"An overlay address to compare.\",\"minimum\":\"Minimum proximity order.\"}},\"isParticipatingInUpcomingRound(address,uint8)\":{\"params\":{\"_depth\":\"The storage depth the applicant intends to report.\",\"_owner\":\"The address of the applicant from.\"}},\"isWinner(bytes32)\":{\"params\":{\"_overlay\":\"The overlay address of the applicant.\"}},\"pause()\":{\"details\":\"Pause the contract. The contract is provably stopped by renouncing the pauser role and the admin role after pausing, can only be called by the `PAUSER`\"},\"paused()\":{\"details\":\"Returns true if the contract is paused, and false otherwise.\"},\"renounceRole(bytes32,address)\":{\"details\":\"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.\"},\"reveal(uint8,bytes32,bytes32)\":{\"params\":{\"_depth\":\"The reported depth.\",\"_hash\":\"The reserve commitment hash.\",\"_revealNonce\":\"The nonce used to generate the commit that is being revealed.\"}},\"revokeRole(bytes32,address)\":{\"details\":\"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.\"},\"supportsInterface(bytes4)\":{\"details\":\"See {IERC165-supportsInterface}.\"},\"unPause()\":{\"details\":\"Unpause the contract, can only be called by the pauser when paused\"},\"wrapCommit(bytes32,uint8,bytes32,bytes32)\":{\"details\":\"_revealNonce_ must be randomly generated, used once and kept secret until the reveal phase.\",\"params\":{\"_depth\":\"The reported depth.\",\"_hash\":\"The reserve commitment hash.\",\"_overlay\":\"The overlay address of the applicant.\",\"revealNonce\":\"A random, single use, secret nonce.\"}}},\"title\":\"Redistribution contract\",\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{\"claim((bytes32[],bytes32,bytes32[],bytes32,uint64,bytes32[],(bytes,bytes32,uint64,uint64),(address,bytes,bytes32,bytes32)[]),(bytes32[],bytes32,bytes32[],bytes32,uint64,bytes32[],(bytes,bytes32,uint64,uint64),(address,bytes,bytes32,bytes32)[]),(bytes32[],bytes32,bytes32[],bytes32,uint64,bytes32[],(bytes,bytes32,uint64,uint64),(address,bytes,bytes32,bytes32)[]))\":{\"notice\":\"Helper function to get this round truth\"},\"commit(bytes32,uint64)\":{\"notice\":\"Begin application for a round if eligible. Commit a hashed value for which the pre-image will be subsequently revealed.\"},\"currentMinimumDepth()\":{\"notice\":\"Returns minimum depth reveal has to have to participate in this round\"},\"currentPhaseClaim()\":{\"notice\":\"Returns true if current block is during claim phase.\"},\"currentPhaseCommit()\":{\"notice\":\"Returns true if current block is during commit phase.\"},\"currentPhaseReveal()\":{\"notice\":\"Returns true if current block is during reveal phase.\"},\"currentRound()\":{\"notice\":\"The number of the current round.\"},\"currentRoundAnchor()\":{\"notice\":\"The anchor used to determine eligibility for the current round.\"},\"currentRoundReveals()\":{\"notice\":\"Returns true if current block is during reveal phase.\"},\"currentSeed()\":{\"notice\":\"Returns the current random seed which is used to determine later utilised random numbers. If rounds have elapsed without reveals, hash the seed with an incremented nonce to produce a new random seed and hence a new round anchor.\"},\"inProximity(bytes32,bytes32,uint8)\":{\"notice\":\"Returns true if an overlay address _A_ is within proximity order _minimum_ of _B_.\"},\"isParticipatingInUpcomingRound(address,uint8)\":{\"notice\":\"Determine if a the owner of a given overlay can participate in the upcoming round.\"},\"isWinner(bytes32)\":{\"notice\":\"Determine if a the owner of a given overlay will be the beneficiary of the claim phase.\"},\"nextSeed()\":{\"notice\":\"Returns the seed which will become current once the next commit phase begins. Used to determine what the next round's anchor will be.\"},\"reveal(uint8,bytes32,bytes32)\":{\"notice\":\"Reveal the pre-image values used to generate commit provided during this round's commit phase.\"},\"setFreezingParams(uint8,uint8,uint8)\":{\"notice\":\"Set freezing parameters\"},\"setSampleMaxValue(uint256)\":{\"notice\":\"changes the max sample value used for reserve estimation\"},\"wrapCommit(bytes32,uint8,bytes32,bytes32)\":{\"notice\":\"Hash the pre-image values to the obsfucated hash.\"}},\"version\":1}},\"settings\":{\"compilationTarget\":{\"src/Redistribution.sol\":\"Redistribution\"},\"evmVersion\":\"paris\",\"libraries\":{\":__CACHE_BREAKER__\":\"0x00000000d41867734bbee4c6863d9255b2b06ac1\"},\"metadata\":{\"bytecodeHash\":\"ipfs\",\"useLiteralContent\":true},\"optimizer\":{\"enabled\":true,\"runs\":1000},\"remappings\":[]},\"sources\":{\"@openzeppelin/contracts/access/AccessControl.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (access/AccessControl.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./IAccessControl.sol\\\";\\nimport \\\"../utils/Context.sol\\\";\\nimport \\\"../utils/Strings.sol\\\";\\nimport \\\"../utils/introspection/ERC165.sol\\\";\\n\\n/**\\n * @dev Contract module that allows children to implement role-based access\\n * control mechanisms. This is a lightweight version that doesn't allow enumerating role\\n * members except through off-chain means by accessing the contract event logs. Some\\n * applications may benefit from on-chain enumerability, for those cases see\\n * {AccessControlEnumerable}.\\n *\\n * Roles are referred to by their `bytes32` identifier. These should be exposed\\n * in the external API and be unique. The best way to achieve this is by\\n * using `public constant` hash digests:\\n *\\n * ```\\n * bytes32 public constant MY_ROLE = keccak256(\\\"MY_ROLE\\\");\\n * ```\\n *\\n * Roles can be used to represent a set of permissions. To restrict access to a\\n * function call, use {hasRole}:\\n *\\n * ```\\n * function foo() public {\\n * require(hasRole(MY_ROLE, msg.sender));\\n * ...\\n * }\\n * ```\\n *\\n * Roles can be granted and revoked dynamically via the {grantRole} and\\n * {revokeRole} functions. Each role has an associated admin role, and only\\n * accounts that have a role's admin role can call {grantRole} and {revokeRole}.\\n *\\n * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means\\n * that only accounts with this role will be able to grant or revoke other\\n * roles. More complex role relationships can be created by using\\n * {_setRoleAdmin}.\\n *\\n * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to\\n * grant and revoke this role. Extra precautions should be taken to secure\\n * accounts that have been granted it.\\n */\\nabstract contract AccessControl is Context, IAccessControl, ERC165 {\\n struct RoleData {\\n mapping(address => bool) members;\\n bytes32 adminRole;\\n }\\n\\n mapping(bytes32 => RoleData) private _roles;\\n\\n bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;\\n\\n /**\\n * @dev Modifier that checks that an account has a specific role. Reverts\\n * with a standardized message including the required role.\\n *\\n * The format of the revert reason is given by the following regular expression:\\n *\\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\\n *\\n * _Available since v4.1._\\n */\\n modifier onlyRole(bytes32 role) {\\n _checkRole(role);\\n _;\\n }\\n\\n /**\\n * @dev See {IERC165-supportsInterface}.\\n */\\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);\\n }\\n\\n /**\\n * @dev Returns `true` if `account` has been granted `role`.\\n */\\n function hasRole(bytes32 role, address account) public view virtual override returns (bool) {\\n return _roles[role].members[account];\\n }\\n\\n /**\\n * @dev Revert with a standard message if `_msgSender()` is missing `role`.\\n * Overriding this function changes the behavior of the {onlyRole} modifier.\\n *\\n * Format of the revert message is described in {_checkRole}.\\n *\\n * _Available since v4.6._\\n */\\n function _checkRole(bytes32 role) internal view virtual {\\n _checkRole(role, _msgSender());\\n }\\n\\n /**\\n * @dev Revert with a standard message if `account` is missing `role`.\\n *\\n * The format of the revert reason is given by the following regular expression:\\n *\\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\\n */\\n function _checkRole(bytes32 role, address account) internal view virtual {\\n if (!hasRole(role, account)) {\\n revert(\\n string(\\n abi.encodePacked(\\n \\\"AccessControl: account \\\",\\n Strings.toHexString(account),\\n \\\" is missing role \\\",\\n Strings.toHexString(uint256(role), 32)\\n )\\n )\\n );\\n }\\n }\\n\\n /**\\n * @dev Returns the admin role that controls `role`. See {grantRole} and\\n * {revokeRole}.\\n *\\n * To change a role's admin, use {_setRoleAdmin}.\\n */\\n function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {\\n return _roles[role].adminRole;\\n }\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * If `account` had not been already granted `role`, emits a {RoleGranted}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n *\\n * May emit a {RoleGranted} event.\\n */\\n function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\\n _grantRole(role, account);\\n }\\n\\n /**\\n * @dev Revokes `role` from `account`.\\n *\\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n *\\n * May emit a {RoleRevoked} event.\\n */\\n function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\\n _revokeRole(role, account);\\n }\\n\\n /**\\n * @dev Revokes `role` from the calling account.\\n *\\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\\n * purpose is to provide a mechanism for accounts to lose their privileges\\n * if they are compromised (such as when a trusted device is misplaced).\\n *\\n * If the calling account had been revoked `role`, emits a {RoleRevoked}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must be `account`.\\n *\\n * May emit a {RoleRevoked} event.\\n */\\n function renounceRole(bytes32 role, address account) public virtual override {\\n require(account == _msgSender(), \\\"AccessControl: can only renounce roles for self\\\");\\n\\n _revokeRole(role, account);\\n }\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * If `account` had not been already granted `role`, emits a {RoleGranted}\\n * event. Note that unlike {grantRole}, this function doesn't perform any\\n * checks on the calling account.\\n *\\n * May emit a {RoleGranted} event.\\n *\\n * [WARNING]\\n * ====\\n * This function should only be called from the constructor when setting\\n * up the initial roles for the system.\\n *\\n * Using this function in any other way is effectively circumventing the admin\\n * system imposed by {AccessControl}.\\n * ====\\n *\\n * NOTE: This function is deprecated in favor of {_grantRole}.\\n */\\n function _setupRole(bytes32 role, address account) internal virtual {\\n _grantRole(role, account);\\n }\\n\\n /**\\n * @dev Sets `adminRole` as ``role``'s admin role.\\n *\\n * Emits a {RoleAdminChanged} event.\\n */\\n function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {\\n bytes32 previousAdminRole = getRoleAdmin(role);\\n _roles[role].adminRole = adminRole;\\n emit RoleAdminChanged(role, previousAdminRole, adminRole);\\n }\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * Internal function without access restriction.\\n *\\n * May emit a {RoleGranted} event.\\n */\\n function _grantRole(bytes32 role, address account) internal virtual {\\n if (!hasRole(role, account)) {\\n _roles[role].members[account] = true;\\n emit RoleGranted(role, account, _msgSender());\\n }\\n }\\n\\n /**\\n * @dev Revokes `role` from `account`.\\n *\\n * Internal function without access restriction.\\n *\\n * May emit a {RoleRevoked} event.\\n */\\n function _revokeRole(bytes32 role, address account) internal virtual {\\n if (hasRole(role, account)) {\\n _roles[role].members[account] = false;\\n emit RoleRevoked(role, account, _msgSender());\\n }\\n }\\n}\\n\",\"keccak256\":\"0x67e3daf189111d6d5b0464ed09cf9f0605a22c4b965a7fcecd707101faff008a\",\"license\":\"MIT\"},\"@openzeppelin/contracts/access/IAccessControl.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev External interface of AccessControl declared to support ERC165 detection.\\n */\\ninterface IAccessControl {\\n /**\\n * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`\\n *\\n * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite\\n * {RoleAdminChanged} not being emitted signaling this.\\n *\\n * _Available since v3.1._\\n */\\n event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);\\n\\n /**\\n * @dev Emitted when `account` is granted `role`.\\n *\\n * `sender` is the account that originated the contract call, an admin role\\n * bearer except when using {AccessControl-_setupRole}.\\n */\\n event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);\\n\\n /**\\n * @dev Emitted when `account` is revoked `role`.\\n *\\n * `sender` is the account that originated the contract call:\\n * - if using `revokeRole`, it is the admin role bearer\\n * - if using `renounceRole`, it is the role bearer (i.e. `account`)\\n */\\n event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);\\n\\n /**\\n * @dev Returns `true` if `account` has been granted `role`.\\n */\\n function hasRole(bytes32 role, address account) external view returns (bool);\\n\\n /**\\n * @dev Returns the admin role that controls `role`. See {grantRole} and\\n * {revokeRole}.\\n *\\n * To change a role's admin, use {AccessControl-_setRoleAdmin}.\\n */\\n function getRoleAdmin(bytes32 role) external view returns (bytes32);\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * If `account` had not been already granted `role`, emits a {RoleGranted}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n */\\n function grantRole(bytes32 role, address account) external;\\n\\n /**\\n * @dev Revokes `role` from `account`.\\n *\\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n */\\n function revokeRole(bytes32 role, address account) external;\\n\\n /**\\n * @dev Revokes `role` from the calling account.\\n *\\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\\n * purpose is to provide a mechanism for accounts to lose their privileges\\n * if they are compromised (such as when a trusted device is misplaced).\\n *\\n * If the calling account had been granted `role`, emits a {RoleRevoked}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must be `account`.\\n */\\n function renounceRole(bytes32 role, address account) external;\\n}\\n\",\"keccak256\":\"0x59ce320a585d7e1f163cd70390a0ef2ff9cec832e2aa544293a00692465a7a57\",\"license\":\"MIT\"},\"@openzeppelin/contracts/security/Pausable.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"../utils/Context.sol\\\";\\n\\n/**\\n * @dev Contract module which allows children to implement an emergency stop\\n * mechanism that can be triggered by an authorized account.\\n *\\n * This module is used through inheritance. It will make available the\\n * modifiers `whenNotPaused` and `whenPaused`, which can be applied to\\n * the functions of your contract. Note that they will not be pausable by\\n * simply including this module, only once the modifiers are put in place.\\n */\\nabstract contract Pausable is Context {\\n /**\\n * @dev Emitted when the pause is triggered by `account`.\\n */\\n event Paused(address account);\\n\\n /**\\n * @dev Emitted when the pause is lifted by `account`.\\n */\\n event Unpaused(address account);\\n\\n bool private _paused;\\n\\n /**\\n * @dev Initializes the contract in unpaused state.\\n */\\n constructor() {\\n _paused = false;\\n }\\n\\n /**\\n * @dev Modifier to make a function callable only when the contract is not paused.\\n *\\n * Requirements:\\n *\\n * - The contract must not be paused.\\n */\\n modifier whenNotPaused() {\\n _requireNotPaused();\\n _;\\n }\\n\\n /**\\n * @dev Modifier to make a function callable only when the contract is paused.\\n *\\n * Requirements:\\n *\\n * - The contract must be paused.\\n */\\n modifier whenPaused() {\\n _requirePaused();\\n _;\\n }\\n\\n /**\\n * @dev Returns true if the contract is paused, and false otherwise.\\n */\\n function paused() public view virtual returns (bool) {\\n return _paused;\\n }\\n\\n /**\\n * @dev Throws if the contract is paused.\\n */\\n function _requireNotPaused() internal view virtual {\\n require(!paused(), \\\"Pausable: paused\\\");\\n }\\n\\n /**\\n * @dev Throws if the contract is not paused.\\n */\\n function _requirePaused() internal view virtual {\\n require(paused(), \\\"Pausable: not paused\\\");\\n }\\n\\n /**\\n * @dev Triggers stopped state.\\n *\\n * Requirements:\\n *\\n * - The contract must not be paused.\\n */\\n function _pause() internal virtual whenNotPaused {\\n _paused = true;\\n emit Paused(_msgSender());\\n }\\n\\n /**\\n * @dev Returns to normal state.\\n *\\n * Requirements:\\n *\\n * - The contract must be paused.\\n */\\n function _unpause() internal virtual whenPaused {\\n _paused = false;\\n emit Unpaused(_msgSender());\\n }\\n}\\n\",\"keccak256\":\"0x0849d93b16c9940beb286a7864ed02724b248b93e0d80ef6355af5ef15c64773\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/Context.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Provides information about the current execution context, including the\\n * sender of the transaction and its data. While these are generally available\\n * via msg.sender and msg.data, they should not be accessed in such a direct\\n * manner, since when dealing with meta-transactions the account sending and\\n * paying for execution may not be the actual sender (as far as an application\\n * is concerned).\\n *\\n * This contract is only required for intermediate, library-like contracts.\\n */\\nabstract contract Context {\\n function _msgSender() internal view virtual returns (address) {\\n return msg.sender;\\n }\\n\\n function _msgData() internal view virtual returns (bytes calldata) {\\n return msg.data;\\n }\\n}\\n\",\"keccak256\":\"0xe2e337e6dde9ef6b680e07338c493ebea1b5fd09b43424112868e9cc1706bca7\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/Strings.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./math/Math.sol\\\";\\n\\n/**\\n * @dev String operations.\\n */\\nlibrary Strings {\\n bytes16 private constant _SYMBOLS = \\\"0123456789abcdef\\\";\\n uint8 private constant _ADDRESS_LENGTH = 20;\\n\\n /**\\n * @dev Converts a `uint256` to its ASCII `string` decimal representation.\\n */\\n function toString(uint256 value) internal pure returns (string memory) {\\n unchecked {\\n uint256 length = Math.log10(value) + 1;\\n string memory buffer = new string(length);\\n uint256 ptr;\\n /// @solidity memory-safe-assembly\\n assembly {\\n ptr := add(buffer, add(32, length))\\n }\\n while (true) {\\n ptr--;\\n /// @solidity memory-safe-assembly\\n assembly {\\n mstore8(ptr, byte(mod(value, 10), _SYMBOLS))\\n }\\n value /= 10;\\n if (value == 0) break;\\n }\\n return buffer;\\n }\\n }\\n\\n /**\\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\\n */\\n function toHexString(uint256 value) internal pure returns (string memory) {\\n unchecked {\\n return toHexString(value, Math.log256(value) + 1);\\n }\\n }\\n\\n /**\\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\\n */\\n function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\\n bytes memory buffer = new bytes(2 * length + 2);\\n buffer[0] = \\\"0\\\";\\n buffer[1] = \\\"x\\\";\\n for (uint256 i = 2 * length + 1; i > 1; --i) {\\n buffer[i] = _SYMBOLS[value & 0xf];\\n value >>= 4;\\n }\\n require(value == 0, \\\"Strings: hex length insufficient\\\");\\n return string(buffer);\\n }\\n\\n /**\\n * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.\\n */\\n function toHexString(address addr) internal pure returns (string memory) {\\n return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);\\n }\\n}\\n\",\"keccak256\":\"0xa4d1d62251f8574deb032a35fc948386a9b4de74b812d4f545a1ac120486b48a\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/introspection/ERC165.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./IERC165.sol\\\";\\n\\n/**\\n * @dev Implementation of the {IERC165} interface.\\n *\\n * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check\\n * for the additional interface id that will be supported. For example:\\n *\\n * ```solidity\\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\\n * }\\n * ```\\n *\\n * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.\\n */\\nabstract contract ERC165 is IERC165 {\\n /**\\n * @dev See {IERC165-supportsInterface}.\\n */\\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n return interfaceId == type(IERC165).interfaceId;\\n }\\n}\\n\",\"keccak256\":\"0xd10975de010d89fd1c78dc5e8a9a7e7f496198085c151648f20cba166b32582b\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/introspection/IERC165.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Interface of the ERC165 standard, as defined in the\\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\\n *\\n * Implementers can declare support of contract interfaces, which can then be\\n * queried by others ({ERC165Checker}).\\n *\\n * For an implementation, see {ERC165}.\\n */\\ninterface IERC165 {\\n /**\\n * @dev Returns true if this contract implements the interface defined by\\n * `interfaceId`. See the corresponding\\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\\n * to learn more about how these ids are created.\\n *\\n * This function call must use less than 30 000 gas.\\n */\\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\\n}\\n\",\"keccak256\":\"0x447a5f3ddc18419d41ff92b3773fb86471b1db25773e07f877f548918a185bf1\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/math/Math.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Standard math utilities missing in the Solidity language.\\n */\\nlibrary Math {\\n enum Rounding {\\n Down, // Toward negative infinity\\n Up, // Toward infinity\\n Zero // Toward zero\\n }\\n\\n /**\\n * @dev Returns the largest of two numbers.\\n */\\n function max(uint256 a, uint256 b) internal pure returns (uint256) {\\n return a > b ? a : b;\\n }\\n\\n /**\\n * @dev Returns the smallest of two numbers.\\n */\\n function min(uint256 a, uint256 b) internal pure returns (uint256) {\\n return a < b ? a : b;\\n }\\n\\n /**\\n * @dev Returns the average of two numbers. The result is rounded towards\\n * zero.\\n */\\n function average(uint256 a, uint256 b) internal pure returns (uint256) {\\n // (a + b) / 2 can overflow.\\n return (a & b) + (a ^ b) / 2;\\n }\\n\\n /**\\n * @dev Returns the ceiling of the division of two numbers.\\n *\\n * This differs from standard division with `/` in that it rounds up instead\\n * of rounding down.\\n */\\n function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {\\n // (a + b - 1) / b can overflow on addition, so we distribute.\\n return a == 0 ? 0 : (a - 1) / b + 1;\\n }\\n\\n /**\\n * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0\\n * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)\\n * with further edits by Uniswap Labs also under MIT license.\\n */\\n function mulDiv(\\n uint256 x,\\n uint256 y,\\n uint256 denominator\\n ) internal pure returns (uint256 result) {\\n unchecked {\\n // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use\\n // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256\\n // variables such that product = prod1 * 2^256 + prod0.\\n uint256 prod0; // Least significant 256 bits of the product\\n uint256 prod1; // Most significant 256 bits of the product\\n assembly {\\n let mm := mulmod(x, y, not(0))\\n prod0 := mul(x, y)\\n prod1 := sub(sub(mm, prod0), lt(mm, prod0))\\n }\\n\\n // Handle non-overflow cases, 256 by 256 division.\\n if (prod1 == 0) {\\n return prod0 / denominator;\\n }\\n\\n // Make sure the result is less than 2^256. Also prevents denominator == 0.\\n require(denominator > prod1);\\n\\n ///////////////////////////////////////////////\\n // 512 by 256 division.\\n ///////////////////////////////////////////////\\n\\n // Make division exact by subtracting the remainder from [prod1 prod0].\\n uint256 remainder;\\n assembly {\\n // Compute remainder using mulmod.\\n remainder := mulmod(x, y, denominator)\\n\\n // Subtract 256 bit number from 512 bit number.\\n prod1 := sub(prod1, gt(remainder, prod0))\\n prod0 := sub(prod0, remainder)\\n }\\n\\n // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.\\n // See https://cs.stackexchange.com/q/138556/92363.\\n\\n // Does not overflow because the denominator cannot be zero at this stage in the function.\\n uint256 twos = denominator & (~denominator + 1);\\n assembly {\\n // Divide denominator by twos.\\n denominator := div(denominator, twos)\\n\\n // Divide [prod1 prod0] by twos.\\n prod0 := div(prod0, twos)\\n\\n // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.\\n twos := add(div(sub(0, twos), twos), 1)\\n }\\n\\n // Shift in bits from prod1 into prod0.\\n prod0 |= prod1 * twos;\\n\\n // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such\\n // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for\\n // four bits. That is, denominator * inv = 1 mod 2^4.\\n uint256 inverse = (3 * denominator) ^ 2;\\n\\n // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works\\n // in modular arithmetic, doubling the correct bits in each step.\\n inverse *= 2 - denominator * inverse; // inverse mod 2^8\\n inverse *= 2 - denominator * inverse; // inverse mod 2^16\\n inverse *= 2 - denominator * inverse; // inverse mod 2^32\\n inverse *= 2 - denominator * inverse; // inverse mod 2^64\\n inverse *= 2 - denominator * inverse; // inverse mod 2^128\\n inverse *= 2 - denominator * inverse; // inverse mod 2^256\\n\\n // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.\\n // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is\\n // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1\\n // is no longer required.\\n result = prod0 * inverse;\\n return result;\\n }\\n }\\n\\n /**\\n * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.\\n */\\n function mulDiv(\\n uint256 x,\\n uint256 y,\\n uint256 denominator,\\n Rounding rounding\\n ) internal pure returns (uint256) {\\n uint256 result = mulDiv(x, y, denominator);\\n if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {\\n result += 1;\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.\\n *\\n * Inspired by Henry S. Warren, Jr.'s \\\"Hacker's Delight\\\" (Chapter 11).\\n */\\n function sqrt(uint256 a) internal pure returns (uint256) {\\n if (a == 0) {\\n return 0;\\n }\\n\\n // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.\\n //\\n // We know that the \\\"msb\\\" (most significant bit) of our target number `a` is a power of 2 such that we have\\n // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.\\n //\\n // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`\\n // \\u2192 `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`\\n // \\u2192 `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`\\n //\\n // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.\\n uint256 result = 1 << (log2(a) >> 1);\\n\\n // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,\\n // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at\\n // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision\\n // into the expected uint128 result.\\n unchecked {\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n return min(result, a / result);\\n }\\n }\\n\\n /**\\n * @notice Calculates sqrt(a), following the selected rounding direction.\\n */\\n function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = sqrt(a);\\n return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);\\n }\\n }\\n\\n /**\\n * @dev Return the log in base 2, rounded down, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log2(uint256 value) internal pure returns (uint256) {\\n uint256 result = 0;\\n unchecked {\\n if (value >> 128 > 0) {\\n value >>= 128;\\n result += 128;\\n }\\n if (value >> 64 > 0) {\\n value >>= 64;\\n result += 64;\\n }\\n if (value >> 32 > 0) {\\n value >>= 32;\\n result += 32;\\n }\\n if (value >> 16 > 0) {\\n value >>= 16;\\n result += 16;\\n }\\n if (value >> 8 > 0) {\\n value >>= 8;\\n result += 8;\\n }\\n if (value >> 4 > 0) {\\n value >>= 4;\\n result += 4;\\n }\\n if (value >> 2 > 0) {\\n value >>= 2;\\n result += 2;\\n }\\n if (value >> 1 > 0) {\\n result += 1;\\n }\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Return the log in base 2, following the selected rounding direction, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = log2(value);\\n return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);\\n }\\n }\\n\\n /**\\n * @dev Return the log in base 10, rounded down, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log10(uint256 value) internal pure returns (uint256) {\\n uint256 result = 0;\\n unchecked {\\n if (value >= 10**64) {\\n value /= 10**64;\\n result += 64;\\n }\\n if (value >= 10**32) {\\n value /= 10**32;\\n result += 32;\\n }\\n if (value >= 10**16) {\\n value /= 10**16;\\n result += 16;\\n }\\n if (value >= 10**8) {\\n value /= 10**8;\\n result += 8;\\n }\\n if (value >= 10**4) {\\n value /= 10**4;\\n result += 4;\\n }\\n if (value >= 10**2) {\\n value /= 10**2;\\n result += 2;\\n }\\n if (value >= 10**1) {\\n result += 1;\\n }\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = log10(value);\\n return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);\\n }\\n }\\n\\n /**\\n * @dev Return the log in base 256, rounded down, of a positive value.\\n * Returns 0 if given 0.\\n *\\n * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.\\n */\\n function log256(uint256 value) internal pure returns (uint256) {\\n uint256 result = 0;\\n unchecked {\\n if (value >> 128 > 0) {\\n value >>= 128;\\n result += 16;\\n }\\n if (value >> 64 > 0) {\\n value >>= 64;\\n result += 8;\\n }\\n if (value >> 32 > 0) {\\n value >>= 32;\\n result += 4;\\n }\\n if (value >> 16 > 0) {\\n value >>= 16;\\n result += 2;\\n }\\n if (value >> 8 > 0) {\\n result += 1;\\n }\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = log256(value);\\n return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);\\n }\\n }\\n}\\n\",\"keccak256\":\"0xa1e8e83cd0087785df04ac79fb395d9f3684caeaf973d9e2c71caef723a3a5d6\",\"license\":\"MIT\"},\"src/Redistribution.sol\":{\"content\":\"// SPDX-License-Identifier: BSD-3-Clause\\npragma solidity ^0.8.19;\\nimport \\\"@openzeppelin/contracts/access/AccessControl.sol\\\";\\nimport \\\"@openzeppelin/contracts/security/Pausable.sol\\\";\\nimport \\\"./Util/TransformedChunkProof.sol\\\";\\nimport \\\"./Util/ChunkProof.sol\\\";\\nimport \\\"./Util/Signatures.sol\\\";\\nimport \\\"./interface/IPostageStamp.sol\\\";\\n\\ninterface IPriceOracle {\\n function adjustPrice(uint16 redundancy) external returns (bool);\\n}\\n\\ninterface IStakeRegistry {\\n struct Stake {\\n bytes32 overlay;\\n uint256 stakeAmount;\\n uint256 lastUpdatedBlockNumber;\\n }\\n\\n function freezeDeposit(address _owner, uint256 _time) external;\\n\\n function lastUpdatedBlockNumberOfAddress(address _owner) external view returns (uint256);\\n\\n function overlayOfAddress(address _owner) external view returns (bytes32);\\n\\n function heightOfAddress(address _owner) external view returns (uint8);\\n\\n function nodeEffectiveStake(address _owner) external view returns (uint256);\\n}\\n\\n/**\\n * @title Redistribution contract\\n * @author The Swarm Authors\\n * @dev Implements a Schelling Co-ordination game to form consensus around the Reserve Commitment hash. This takes\\n * place in three phases: _commit_, _reveal_ and _claim_.\\n *\\n * A node, upon establishing that it _isParticipatingInUpcomingRound_, i.e. it's overlay falls within proximity order\\n * of its reported depth with the _currentRoundAnchor_, prepares a \\\"reserve commitment hash\\\" using the chunks\\n * it currently stores in its reserve and calculates the \\\"storage depth\\\" (see Bee for details). These values, if calculated\\n * honestly, and with the right chunks stored, should be the same for every node in a neighbourhood. This is the Schelling point.\\n * Each eligible node can then use these values, together with a random, single use, secret _revealNonce_ and their\\n * _overlay_ as the pre-image values for the obsfucated _commit_, using the _wrapCommit_ method.\\n *\\n * Once the _commit_ round has elapsed, participating nodes must provide the values used to calculate their obsfucated\\n * _commit_ hash, which, once verified for correctness and proximity to the anchor are retained in the _currentReveals_.\\n * Nodes that have committed but do not reveal the correct values used to create the pre-image will have their stake\\n * \\\"frozen\\\" for a period of rounds proportional to their reported depth.\\n *\\n * During the _reveal_ round, randomness is updated after every successful reveal. Once the reveal round is concluded,\\n * the _currentRoundAnchor_ is updated and users can determine if they will be eligible their overlay will be eligible\\n * for the next commit phase using _isParticipatingInUpcomingRound_.\\n *\\n * When the _reveal_ phase has been concluded, the claim phase can begin. At this point, the truth teller and winner\\n * are already determined. By calling _isWinner_, an applicant node can run the relevant logic to determine if they have\\n * been selected as the beneficiary of this round. When calling _claim_, the current pot from the PostageStamp contract\\n * is withdrawn and transferred to that beneficiaries address. Nodes that have revealed values that differ from the truth,\\n * have their stakes \\\"frozen\\\" for a period of rounds proportional to their reported depth.\\n */\\n\\ncontract Redistribution is AccessControl, Pausable {\\n // ----------------------------- Type declarations ------------------------------\\n\\n // An eligible user may commit to an _obfuscatedHash_ during the commit phase...\\n struct Commit {\\n bytes32 overlay;\\n address owner;\\n bool revealed;\\n uint8 height;\\n uint256 stake;\\n bytes32 obfuscatedHash;\\n uint256 revealIndex;\\n }\\n // ...then provide the actual values that are the constituents of the pre-image of the _obfuscatedHash_\\n // during the reveal phase.\\n struct Reveal {\\n bytes32 overlay;\\n address owner;\\n uint8 depth;\\n uint256 stake;\\n uint256 stakeDensity;\\n bytes32 hash;\\n }\\n\\n struct ChunkInclusionProof {\\n bytes32[] proofSegments;\\n bytes32 proveSegment;\\n // _RCspan is known for RC 32*32\\n\\n // Inclusion proof of transformed address\\n bytes32[] proofSegments2;\\n bytes32 proveSegment2;\\n // proveSegmentIndex2 known from deterministic random selection;\\n uint64 chunkSpan;\\n bytes32[] proofSegments3;\\n // _proveSegment3 known, is equal _proveSegment2\\n // proveSegmentIndex3 know, is equal _proveSegmentIndex2;\\n // chunkSpan2 is equal to chunkSpan (as the data is the same)\\n //\\n PostageProof postageProof;\\n SOCProof[] socProof;\\n }\\n\\n struct SOCProof {\\n address signer; // signer Ethereum address to check against\\n bytes signature;\\n bytes32 identifier; //\\n bytes32 chunkAddr; // wrapped chunk address\\n }\\n\\n struct PostageProof {\\n bytes signature;\\n bytes32 postageId;\\n uint64 index;\\n uint64 timeStamp;\\n // address signer; it is provided by the postage stamp contract\\n // bytes32 chunkAddr; it equals to the proveSegment argument\\n }\\n\\n // The address of the linked PostageStamp contract.\\n IPostageStamp public PostageContract;\\n // The address of the linked PriceOracle contract.\\n IPriceOracle public OracleContract;\\n // The address of the linked Staking contract.\\n IStakeRegistry public Stakes;\\n\\n // Commits for the current round.\\n Commit[] public currentCommits;\\n // Reveals for the current round.\\n Reveal[] public currentReveals;\\n\\n // The current anchor that being processed for the reveal and claim phases of the round.\\n bytes32 private currentRevealRoundAnchor;\\n\\n // The current random value from which we will random.\\n // inputs for selection of the truth teller and beneficiary.\\n bytes32 private seed;\\n\\n // The number of the currently active round phases.\\n uint64 public currentCommitRound;\\n uint64 public currentRevealRound;\\n uint64 public currentClaimRound;\\n\\n // Settings for slashing and freezing\\n uint8 private penaltyMultiplierDisagreement = 1;\\n uint8 private penaltyMultiplierNonRevealed = 2;\\n uint8 private penaltyRandomFactor = 100; // Use 100 as value to ignore random factor in freezing penalty\\n\\n // alpha=0.097612 beta=0.0716570 k=16\\n uint256 private sampleMaxValue = 1284401000000000000000000000000000000000000000000000000000000000000000000;\\n\\n // The reveal of the winner of the last round.\\n Reveal public winner;\\n\\n // The length of a round in blocks.\\n uint256 private constant ROUND_LENGTH = 152;\\n\\n // Maximum value of the keccack256 hash.\\n bytes32 private constant MAX_H = 0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff;\\n\\n // ----------------------------- Events ------------------------------\\n\\n /**\\n * @dev Emitted when the winner of a round is selected in the claim phase\\n */\\n event WinnerSelected(Reveal winner);\\n\\n /**\\n * @dev Emitted when the truth oracle of a round is selected in the claim phase.\\n */\\n event TruthSelected(bytes32 hash, uint8 depth);\\n\\n // Next two events to be removed after testing phase pending some other usefulness being found.\\n /**\\n * @dev Emits the number of commits being processed by the claim phase.\\n */\\n event CountCommits(uint256 _count);\\n\\n /**\\n * @dev Emits the number of reveals being processed by the claim phase.\\n */\\n event CountReveals(uint256 _count);\\n\\n /**\\n * @dev Logs that an overlay has committed\\n */\\n event Committed(uint256 roundNumber, bytes32 overlay);\\n /**\\n * @dev Emit from Postagestamp contract valid chunk count at the end of claim\\n */\\n event ChunkCount(uint256 validChunkCount);\\n\\n /**\\n * @dev Bytes32 anhor of current reveal round\\n */\\n event CurrentRevealAnchor(uint256 roundNumber, bytes32 anchor);\\n\\n /**\\n * @dev Output external call status\\n */\\n event PriceAdjustmentSkipped(uint16 redundancyCount);\\n\\n /**\\n * @dev Withdraw not successful in claim\\n */\\n event WithdrawFailed(address owner);\\n\\n /**\\n * @dev Logs that an overlay has revealed\\n */\\n event Revealed(\\n uint256 roundNumber,\\n bytes32 overlay,\\n uint256 stake,\\n uint256 stakeDensity,\\n bytes32 reserveCommitment,\\n uint8 depth\\n );\\n\\n /**\\n * @dev Logs for inclusion proof\\n */\\n event transformedChunkAddressFromInclusionProof(uint256 indexInRC, bytes32 chunkAddress);\\n\\n // ----------------------------- Errors ------------------------------\\n\\n error NotCommitPhase(); // Game is not in commit phase\\n error NoCommitsReceived(); // Round didn't receive any commits\\n error PhaseLastBlock(); // We don't permit commits in last block of the phase\\n error CommitRoundOver(); // Commit phase in this round is over\\n error CommitRoundNotStarted(); // Commit phase in this round has not started yet\\n error NotMatchingOwner(); // Sender of commit is not matching the overlay address\\n error MustStake2Rounds(); // Before entering the game node must stake 2 rounds prior\\n error NotStaked(); // Node didn't add any staking\\n error WrongPhase(); // Checking in wrong phase, need to check duing claim phase of current round for next round or commit in current round\\n error AlreadyCommitted(); // Node already committed in this round\\n error NotRevealPhase(); // Game is not in reveal phase\\n error OutOfDepthReveal(bytes32); // Anchor is out of reported depth in Reveal phase, anchor data available as argument\\n error OutOfDepthClaim(uint8); // Anchor is out of reported depth in Claim phase, entryProof index is argument\\n error OutOfDepth(); // Anchor is out of reported depth\\n error AlreadyRevealed(); // Node already revealed\\n error NoMatchingCommit(); // No matching commit and hash\\n error NotClaimPhase(); // Game is not in the claim phase\\n error NoReveals(); // Round did not receive any reveals\\n error FirstRevealDone(); // We don't want to return value after first reveal\\n error AlreadyClaimed(); // This round was already claimed\\n error NotAdmin(); // Caller of trx is not admin\\n error OnlyPauser(); // Only account with pauser role can call pause/unpause\\n error SocVerificationFailed(bytes32); // Soc verification failed for this element\\n error SocCalcNotMatching(bytes32); // Soc address calculation does not match with the witness\\n error IndexOutsideSet(bytes32); // Stamp available: index resides outside of the valid index set\\n error SigRecoveryFailed(bytes32); // Stamp authorized: signature recovery failed for element\\n error BatchDoesNotExist(bytes32); // Stamp alive: batch remaining balance validation failed for attached stamp\\n error BucketDiffers(bytes32); // Stamp aligned: postage bucket differs from address bucket\\n error InclusionProofFailed(uint8, bytes32);\\n // 1 = RC inclusion proof failed for element\\n // 2 = First sister segment in data must match,\\n // 3 = Inclusion proof failed for original address of element\\n // 4 = Inclusion proof failed for transformed address of element\\n error RandomElementCheckFailed(); // Random element order check failed\\n error LastElementCheckFailed(); // Last element order check failed\\n error ReserveCheckFailed(bytes32 trALast); // Reserve size estimation check failed\\n\\n // ----------------------------- CONSTRUCTOR ------------------------------\\n\\n /**\\n * @param staking the address of the linked Staking contract.\\n * @param postageContract the address of the linked PostageStamp contract.\\n * @param oracleContract the address of the linked PriceOracle contract.\\n */\\n constructor(address staking, address postageContract, address oracleContract) {\\n Stakes = IStakeRegistry(staking);\\n PostageContract = IPostageStamp(postageContract);\\n OracleContract = IPriceOracle(oracleContract);\\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\\n }\\n\\n ////////////////////////////////////////\\n // STATE CHANGING //\\n ////////////////////////////////////////\\n\\n /**\\n * @notice Begin application for a round if eligible. Commit a hashed value for which the pre-image will be\\n * subsequently revealed.\\n * @dev If a node's overlay is _inProximity_(_depth_) of the _currentRoundAnchor_, that node may compute an\\n * _obfuscatedHash_ by providing their _overlay_, reported storage _depth_, reserve commitment _hash_ and a\\n * randomly generated, and secret _revealNonce_ to the _wrapCommit_ method.\\n * @param _obfuscatedHash The calculated hash resultant of the required pre-image values.\\n * and be derived from the same key pair as the message sender.\\n * @param _roundNumber Node needs to provide round number for which commit is valid\\n */\\n function commit(bytes32 _obfuscatedHash, uint64 _roundNumber) external whenNotPaused {\\n uint64 cr = currentRound();\\n bytes32 _overlay = Stakes.overlayOfAddress(msg.sender);\\n uint256 _stake = Stakes.nodeEffectiveStake(msg.sender);\\n uint256 _lastUpdate = Stakes.lastUpdatedBlockNumberOfAddress(msg.sender);\\n uint8 _height = Stakes.heightOfAddress(msg.sender);\\n\\n if (!currentPhaseCommit()) {\\n revert NotCommitPhase();\\n }\\n if (block.number % ROUND_LENGTH == (ROUND_LENGTH / 4) - 1) {\\n revert PhaseLastBlock();\\n }\\n\\n if (cr > _roundNumber) {\\n revert CommitRoundOver();\\n }\\n\\n if (cr < _roundNumber) {\\n revert CommitRoundNotStarted();\\n }\\n\\n if (_lastUpdate == 0) {\\n revert NotStaked();\\n }\\n\\n if (_lastUpdate >= block.number - 2 * ROUND_LENGTH) {\\n revert MustStake2Rounds();\\n }\\n\\n // if we are in a new commit phase, reset the array of commits and\\n // set the currentCommitRound to be the current one\\n if (cr != currentCommitRound) {\\n delete currentCommits;\\n currentCommitRound = cr;\\n }\\n\\n uint256 commitsArrayLength = currentCommits.length;\\n\\n for (uint256 i = 0; i < commitsArrayLength; ) {\\n if (currentCommits[i].overlay == _overlay) {\\n revert AlreadyCommitted();\\n }\\n\\n unchecked {\\n ++i;\\n }\\n }\\n\\n currentCommits.push(\\n Commit({\\n overlay: _overlay,\\n owner: msg.sender,\\n revealed: false,\\n height: _height,\\n stake: _stake,\\n obfuscatedHash: _obfuscatedHash,\\n revealIndex: 0\\n })\\n );\\n\\n emit Committed(_roundNumber, _overlay);\\n }\\n\\n /**\\n * @notice Reveal the pre-image values used to generate commit provided during this round's commit phase.\\n * @param _depth The reported depth.\\n * @param _hash The reserve commitment hash.\\n * @param _revealNonce The nonce used to generate the commit that is being revealed.\\n */\\n function reveal(uint8 _depth, bytes32 _hash, bytes32 _revealNonce) external whenNotPaused {\\n uint64 cr = currentRound();\\n bytes32 _overlay = Stakes.overlayOfAddress(msg.sender);\\n\\n if (_depth < currentMinimumDepth()) {\\n revert OutOfDepth();\\n }\\n\\n if (!currentPhaseReveal()) {\\n revert NotRevealPhase();\\n }\\n\\n if (cr != currentCommitRound) {\\n revert NoCommitsReceived();\\n }\\n\\n if (cr != currentRevealRound) {\\n currentRevealRoundAnchor = currentRoundAnchor();\\n delete currentReveals;\\n // We set currentRevealRound ONLY after we set current anchor\\n currentRevealRound = cr;\\n emit CurrentRevealAnchor(cr, currentRevealRoundAnchor);\\n updateRandomness();\\n }\\n\\n bytes32 obfuscatedHash = wrapCommit(_overlay, _depth, _hash, _revealNonce);\\n uint256 id = findCommit(_overlay, obfuscatedHash);\\n Commit memory revealedCommit = currentCommits[id];\\n uint8 depthResponsibility = _depth - revealedCommit.height;\\n\\n // Check that commit is in proximity of the current anchor\\n if (!inProximity(revealedCommit.overlay, currentRevealRoundAnchor, depthResponsibility)) {\\n revert OutOfDepthReveal(currentRevealRoundAnchor);\\n }\\n // Check that the commit has not already been revealed\\n if (revealedCommit.revealed) {\\n revert AlreadyRevealed();\\n }\\n\\n currentCommits[id].revealed = true;\\n currentCommits[id].revealIndex = currentReveals.length;\\n\\n currentReveals.push(\\n Reveal({\\n overlay: revealedCommit.overlay,\\n owner: revealedCommit.owner,\\n depth: _depth,\\n stake: revealedCommit.stake,\\n stakeDensity: revealedCommit.stake * uint256(2 ** depthResponsibility),\\n hash: _hash\\n })\\n );\\n\\n emit Revealed(\\n cr,\\n revealedCommit.overlay,\\n revealedCommit.stake,\\n revealedCommit.stake * uint256(2 ** depthResponsibility),\\n _hash,\\n _depth\\n );\\n }\\n\\n /**\\n * @notice Helper function to get this round truth\\n * @dev\\n */\\n function claim(\\n ChunkInclusionProof calldata entryProof1,\\n ChunkInclusionProof calldata entryProof2,\\n ChunkInclusionProof calldata entryProofLast\\n ) external whenNotPaused {\\n winnerSelection();\\n\\n Reveal memory winnerSelected = winner;\\n uint256 indexInRC1;\\n uint256 indexInRC2;\\n bytes32 _currentRevealRoundAnchor = currentRevealRoundAnchor;\\n bytes32 _seed = seed;\\n\\n // rand(14)\\n indexInRC1 = uint256(_seed) % 15;\\n // rand(13)\\n indexInRC2 = uint256(_seed) % 14;\\n if (indexInRC2 >= indexInRC1) {\\n indexInRC2++;\\n }\\n\\n if (!inProximity(entryProofLast.proveSegment, _currentRevealRoundAnchor, winnerSelected.depth)) {\\n revert OutOfDepthClaim(3);\\n }\\n\\n inclusionFunction(entryProofLast, 30);\\n stampFunction(entryProofLast);\\n socFunction(entryProofLast);\\n\\n if (!inProximity(entryProof1.proveSegment, _currentRevealRoundAnchor, winnerSelected.depth)) {\\n revert OutOfDepthClaim(2);\\n }\\n\\n inclusionFunction(entryProof1, indexInRC1 * 2);\\n stampFunction(entryProof1);\\n socFunction(entryProof1);\\n\\n if (!inProximity(entryProof2.proveSegment, _currentRevealRoundAnchor, winnerSelected.depth)) {\\n revert OutOfDepthClaim(1);\\n }\\n\\n inclusionFunction(entryProof2, indexInRC2 * 2);\\n stampFunction(entryProof2);\\n socFunction(entryProof2);\\n\\n checkOrder(\\n indexInRC1,\\n indexInRC2,\\n entryProof1.proofSegments[0],\\n entryProof2.proofSegments[0],\\n entryProofLast.proofSegments[0]\\n );\\n\\n estimateSize(entryProofLast.proofSegments[0]);\\n\\n // Do the check if the withdraw was success\\n (bool success, ) = address(PostageContract).call(\\n abi.encodeWithSignature(\\\"withdraw(address)\\\", winnerSelected.owner)\\n );\\n if (!success) {\\n emit WithdrawFailed(winnerSelected.owner);\\n }\\n\\n emit WinnerSelected(winnerSelected);\\n emit ChunkCount(PostageContract.validChunkCount());\\n }\\n\\n function winnerSelection() internal {\\n uint64 cr = currentRound();\\n\\n if (!currentPhaseClaim()) {\\n revert NotClaimPhase();\\n }\\n\\n if (cr != currentRevealRound) {\\n revert NoReveals();\\n }\\n\\n if (cr <= currentClaimRound) {\\n revert AlreadyClaimed();\\n }\\n\\n uint256 currentWinnerSelectionSum = 0;\\n uint256 redundancyCount = 0;\\n bytes32 randomNumber;\\n uint256 randomNumberTrunc;\\n\\n bytes32 truthRevealedHash;\\n uint8 truthRevealedDepth;\\n uint256 currentCommitsLength = currentCommits.length;\\n\\n emit CountCommits(currentCommitsLength);\\n emit CountReveals(currentReveals.length);\\n\\n (truthRevealedHash, truthRevealedDepth) = getCurrentTruth();\\n emit TruthSelected(truthRevealedHash, truthRevealedDepth);\\n string memory winnerSelectionAnchor = currentWinnerSelectionAnchor();\\n\\n for (uint256 i = 0; i < currentCommitsLength; ) {\\n Commit memory currentCommit = currentCommits[i];\\n uint256 revIndex = currentCommit.revealIndex;\\n Reveal memory currentReveal = currentReveals[revIndex];\\n\\n // Select winner with valid truth\\n if (\\n currentCommit.revealed &&\\n truthRevealedHash == currentReveal.hash &&\\n truthRevealedDepth == currentReveal.depth\\n ) {\\n currentWinnerSelectionSum += currentReveal.stakeDensity;\\n randomNumber = keccak256(abi.encodePacked(winnerSelectionAnchor, redundancyCount));\\n randomNumberTrunc = uint256(randomNumber & MAX_H);\\n\\n if (randomNumberTrunc * currentWinnerSelectionSum < currentReveal.stakeDensity * (uint256(MAX_H) + 1)) {\\n winner = currentReveal;\\n }\\n\\n redundancyCount++;\\n }\\n\\n // Freeze deposit if any truth is false, make it a penaltyRandomFactor chance for this to happen\\n if (\\n currentCommit.revealed &&\\n (truthRevealedHash != currentReveal.hash || truthRevealedDepth != currentReveal.depth) &&\\n (block.prevrandao % 100 < penaltyRandomFactor)\\n ) {\\n Stakes.freezeDeposit(\\n currentReveal.owner,\\n penaltyMultiplierDisagreement * ROUND_LENGTH * uint256(2 ** truthRevealedDepth)\\n );\\n }\\n\\n // Slash deposits if revealed is false\\n if (!currentCommit.revealed) {\\n // slash in later phase (ph5)\\n // Stakes.slashDeposit(currentCommits[i].overlay, currentCommits[i].stake);\\n Stakes.freezeDeposit(\\n currentCommit.owner,\\n penaltyMultiplierNonRevealed * ROUND_LENGTH * uint256(2 ** truthRevealedDepth)\\n );\\n }\\n unchecked {\\n ++i;\\n }\\n }\\n\\n bool success = OracleContract.adjustPrice(uint16(redundancyCount));\\n if (!success) {\\n emit PriceAdjustmentSkipped(uint16(redundancyCount));\\n }\\n currentClaimRound = cr;\\n }\\n\\n function inclusionFunction(ChunkInclusionProof calldata entryProof, uint256 indexInRC) internal {\\n uint256 randomChunkSegmentIndex = uint256(seed) % 128;\\n bytes32 calculatedTransformedAddr = TransformedBMTChunk.transformedChunkAddressFromInclusionProof(\\n entryProof.proofSegments3,\\n entryProof.proveSegment2,\\n randomChunkSegmentIndex,\\n entryProof.chunkSpan,\\n currentRevealRoundAnchor\\n );\\n\\n emit transformedChunkAddressFromInclusionProof(indexInRC, calculatedTransformedAddr);\\n\\n if (\\n winner.hash !=\\n BMTChunk.chunkAddressFromInclusionProof(\\n entryProof.proofSegments,\\n entryProof.proveSegment,\\n indexInRC,\\n 32 * 32\\n )\\n ) {\\n revert InclusionProofFailed(1, calculatedTransformedAddr);\\n }\\n\\n if (entryProof.proofSegments2[0] != entryProof.proofSegments3[0]) {\\n revert InclusionProofFailed(2, calculatedTransformedAddr);\\n }\\n\\n bytes32 originalAddress = entryProof.socProof.length > 0\\n ? entryProof.socProof[0].chunkAddr // soc attestation in socFunction\\n : entryProof.proveSegment;\\n\\n if (\\n originalAddress !=\\n BMTChunk.chunkAddressFromInclusionProof(\\n entryProof.proofSegments2,\\n entryProof.proveSegment2,\\n randomChunkSegmentIndex,\\n entryProof.chunkSpan\\n )\\n ) {\\n revert InclusionProofFailed(3, calculatedTransformedAddr);\\n }\\n\\n // In case of SOC, the transformed address is hashed together with its address in the sample\\n if (entryProof.socProof.length > 0) {\\n calculatedTransformedAddr = keccak256(\\n abi.encode(\\n entryProof.proveSegment, // SOC address\\n calculatedTransformedAddr\\n )\\n );\\n }\\n\\n if (entryProof.proofSegments[0] != calculatedTransformedAddr) {\\n revert InclusionProofFailed(4, calculatedTransformedAddr);\\n }\\n }\\n\\n /**\\n * @notice Set freezing parameters\\n */\\n function setFreezingParams(\\n uint8 _penaltyMultiplierDisagreement,\\n uint8 _penaltyMultiplierNonRevealed,\\n uint8 _penaltyRandomFactor\\n ) external {\\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\\n revert NotAdmin();\\n }\\n\\n penaltyMultiplierDisagreement = _penaltyMultiplierDisagreement;\\n penaltyMultiplierNonRevealed = _penaltyMultiplierNonRevealed;\\n penaltyRandomFactor = _penaltyRandomFactor;\\n }\\n\\n /**\\n * @notice changes the max sample value used for reserve estimation\\n */\\n function setSampleMaxValue(uint256 _sampleMaxValue) external {\\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\\n revert NotAdmin();\\n }\\n\\n sampleMaxValue = _sampleMaxValue;\\n }\\n\\n /**\\n * @notice Updates the source of randomness. Uses block.difficulty in pre-merge chains, this is substituted\\n * to block.prevrandao in post merge chains.\\n */\\n function updateRandomness() private {\\n seed = keccak256(abi.encode(seed, block.prevrandao));\\n }\\n\\n /**\\n * @dev Pause the contract. The contract is provably stopped by renouncing\\n the pauser role and the admin role after pausing, can only be called by the `PAUSER`\\n */\\n function pause() public {\\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\\n revert OnlyPauser();\\n }\\n\\n _pause();\\n }\\n\\n /**\\n * @dev Unpause the contract, can only be called by the pauser when paused\\n */\\n function unPause() public {\\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\\n revert OnlyPauser();\\n }\\n _unpause();\\n }\\n\\n ////////////////////////////////////////\\n // STATE READING //\\n ////////////////////////////////////////\\n\\n // ----------------------------- Anchor calculations ------------------------------\\n\\n /**\\n * @notice Returns the current random seed which is used to determine later utilised random numbers.\\n * If rounds have elapsed without reveals, hash the seed with an incremented nonce to produce a new\\n * random seed and hence a new round anchor.\\n */\\n function currentSeed() public view returns (bytes32) {\\n uint64 cr = currentRound();\\n bytes32 currentSeedValue = seed;\\n\\n if (cr > currentRevealRound + 1) {\\n uint256 difference = cr - currentRevealRound - 1;\\n currentSeedValue = keccak256(abi.encodePacked(currentSeedValue, difference));\\n }\\n\\n return currentSeedValue;\\n }\\n\\n /**\\n * @notice Returns the seed which will become current once the next commit phase begins.\\n * Used to determine what the next round's anchor will be.\\n */\\n function nextSeed() public view returns (bytes32) {\\n uint64 cr = currentRound() + 1;\\n bytes32 currentSeedValue = seed;\\n\\n if (cr > currentRevealRound + 1) {\\n uint256 difference = cr - currentRevealRound - 1;\\n currentSeedValue = keccak256(abi.encodePacked(currentSeedValue, difference));\\n }\\n\\n return currentSeedValue;\\n }\\n\\n /**\\n * @notice The random value used to choose the selected truth teller.\\n */\\n function currentTruthSelectionAnchor() private view returns (string memory) {\\n if (!currentPhaseClaim()) {\\n revert NotClaimPhase();\\n }\\n\\n uint64 cr = currentRound();\\n if (cr != currentRevealRound) {\\n revert NoReveals();\\n }\\n\\n return string(abi.encodePacked(seed, \\\"0\\\"));\\n }\\n\\n /**\\n * @notice The random value used to choose the selected beneficiary.\\n */\\n function currentWinnerSelectionAnchor() private view returns (string memory) {\\n if (!currentPhaseClaim()) {\\n revert NotClaimPhase();\\n }\\n uint64 cr = currentRound();\\n if (cr != currentRevealRound) {\\n revert NoReveals();\\n }\\n\\n return string(abi.encodePacked(seed, \\\"1\\\"));\\n }\\n\\n /**\\n * @notice The anchor used to determine eligibility for the current round.\\n * @dev A node must be within proximity order of less than or equal to the storage depth they intend to report.\\n */\\n function currentRoundAnchor() public view returns (bytes32 returnVal) {\\n // This will be called in reveal phase and set as currentRevealRoundAnchor or in\\n // commit phase when checking eligibility for next round by isParticipatingInUpcomingRound\\n if (currentPhaseCommit() || (currentRound() > currentRevealRound && !currentPhaseClaim())) {\\n return currentSeed();\\n }\\n\\n // This will be called by isParticipatingInUpcomingRound check in claim phase\\n if (currentPhaseClaim()) {\\n return nextSeed();\\n }\\n\\n // Without this, this function will output 0x0 after first reveal which is value and we prefere it reverts\\n if (currentPhaseReveal() && currentRound() == currentRevealRound) {\\n revert FirstRevealDone();\\n }\\n }\\n\\n /**\\n * @notice Returns true if an overlay address _A_ is within proximity order _minimum_ of _B_.\\n * @param A An overlay address to compare.\\n * @param B An overlay address to compare.\\n * @param minimum Minimum proximity order.\\n */\\n function inProximity(bytes32 A, bytes32 B, uint8 minimum) public pure returns (bool) {\\n if (minimum == 0) {\\n return true;\\n }\\n\\n return uint256(A ^ B) < uint256(2 ** (256 - minimum));\\n }\\n\\n // ----------------------------- Commit ------------------------------\\n\\n /**\\n * @notice The number of the current round.\\n */\\n function currentRound() public view returns (uint64) {\\n return uint64(block.number / ROUND_LENGTH);\\n }\\n\\n /**\\n * @notice Returns true if current block is during commit phase.\\n */\\n function currentPhaseCommit() public view returns (bool) {\\n if (block.number % ROUND_LENGTH < ROUND_LENGTH / 4) {\\n return true;\\n }\\n return false;\\n }\\n\\n /**\\n * @notice Determine if a the owner of a given overlay can participate in the upcoming round.\\n * @param _owner The address of the applicant from.\\n * @param _depth The storage depth the applicant intends to report.\\n */\\n function isParticipatingInUpcomingRound(address _owner, uint8 _depth) public view returns (bool) {\\n uint256 _lastUpdate = Stakes.lastUpdatedBlockNumberOfAddress(_owner);\\n uint8 _depthResponsibility = _depth - Stakes.heightOfAddress(_owner);\\n\\n if (currentPhaseReveal()) {\\n revert WrongPhase();\\n }\\n\\n if (_lastUpdate == 0) {\\n revert NotStaked();\\n }\\n\\n if (_lastUpdate >= block.number - 2 * ROUND_LENGTH) {\\n revert MustStake2Rounds();\\n }\\n\\n return inProximity(Stakes.overlayOfAddress(_owner), currentRoundAnchor(), _depthResponsibility);\\n }\\n\\n // ----------------------------- Reveal ------------------------------\\n\\n /**\\n * @notice Returns minimum depth reveal has to have to participate in this round\\n */\\n function currentMinimumDepth() public view returns (uint8) {\\n // We are checking value in reveal phase, as the currentCommitRound is set to the current round\\n // but the currentClaimRound is still set to the last time claim was made\\n // We add 1 to ensure that for the next round the minimum depth is the same as last winner depth\\n\\n uint256 difference = currentCommitRound - currentClaimRound;\\n uint8 skippedRounds = uint8(difference > 254 ? 254 : difference) + 1;\\n\\n uint8 lastWinnerDepth = winner.depth;\\n\\n // We ensure that skippedRounds is not bigger than lastWinnerDepth, because of overflow\\n return skippedRounds >= lastWinnerDepth ? 0 : lastWinnerDepth - skippedRounds;\\n }\\n\\n /**\\n * @notice Helper function to get this node reveal in commits\\n * @dev\\n */\\n function findCommit(bytes32 _overlay, bytes32 _obfuscatedHash) internal view returns (uint256) {\\n for (uint256 i = 0; i < currentCommits.length; ) {\\n if (currentCommits[i].overlay == _overlay && _obfuscatedHash == currentCommits[i].obfuscatedHash) {\\n return i;\\n }\\n unchecked {\\n ++i;\\n }\\n }\\n revert NoMatchingCommit();\\n }\\n\\n /**\\n * @notice Hash the pre-image values to the obsfucated hash.\\n * @dev _revealNonce_ must be randomly generated, used once and kept secret until the reveal phase.\\n * @param _overlay The overlay address of the applicant.\\n * @param _depth The reported depth.\\n * @param _hash The reserve commitment hash.\\n * @param revealNonce A random, single use, secret nonce.\\n */\\n function wrapCommit(\\n bytes32 _overlay,\\n uint8 _depth,\\n bytes32 _hash,\\n bytes32 revealNonce\\n ) public pure returns (bytes32) {\\n return keccak256(abi.encodePacked(_overlay, _depth, _hash, revealNonce));\\n }\\n\\n /**\\n * @notice Returns true if current block is during reveal phase.\\n */\\n function currentPhaseReveal() public view returns (bool) {\\n uint256 number = block.number % ROUND_LENGTH;\\n if (number >= ROUND_LENGTH / 4 && number < ROUND_LENGTH / 2) {\\n return true;\\n }\\n return false;\\n }\\n\\n /**\\n * @notice Returns true if current block is during reveal phase.\\n */\\n function currentRoundReveals() public view returns (Reveal[] memory) {\\n if (!currentPhaseClaim()) {\\n revert NotClaimPhase();\\n }\\n uint64 cr = currentRound();\\n if (cr != currentRevealRound) {\\n revert NoReveals();\\n }\\n\\n return currentReveals;\\n }\\n\\n // ----------------------------- Claim ------------------------------\\n\\n /**\\n * @notice Returns true if current block is during claim phase.\\n */\\n function currentPhaseClaim() public view returns (bool) {\\n if (block.number % ROUND_LENGTH >= ROUND_LENGTH / 2) {\\n return true;\\n }\\n return false;\\n }\\n\\n function getCurrentTruth() internal view returns (bytes32 Hash, uint8 Depth) {\\n uint256 currentSum;\\n bytes32 randomNumber;\\n uint256 randomNumberTrunc;\\n\\n bytes32 truthRevealedHash;\\n uint8 truthRevealedDepth;\\n uint256 revIndex;\\n string memory truthSelectionAnchor = currentTruthSelectionAnchor();\\n uint256 commitsArrayLength = currentCommits.length;\\n\\n for (uint256 i = 0; i < commitsArrayLength; ) {\\n if (currentCommits[i].revealed) {\\n revIndex = currentCommits[i].revealIndex;\\n currentSum += currentReveals[revIndex].stakeDensity;\\n randomNumber = keccak256(abi.encodePacked(truthSelectionAnchor, i));\\n randomNumberTrunc = uint256(randomNumber & MAX_H);\\n\\n // question is whether randomNumber / MAX_H < probability\\n // where probability is stakeDensity / currentSum\\n // to avoid resorting to floating points all divisions should be\\n // simplified with multiplying both sides (as long as divisor > 0)\\n // randomNumber / (MAX_H + 1) < stakeDensity / currentSum\\n // ( randomNumber / (MAX_H + 1) ) * currentSum < stakeDensity\\n // randomNumber * currentSum < stakeDensity * (MAX_H + 1)\\n if (randomNumberTrunc * currentSum < currentReveals[revIndex].stakeDensity * (uint256(MAX_H) + 1)) {\\n truthRevealedHash = currentReveals[revIndex].hash;\\n truthRevealedDepth = currentReveals[revIndex].depth;\\n }\\n }\\n unchecked {\\n ++i;\\n }\\n }\\n\\n return (truthRevealedHash, truthRevealedDepth);\\n }\\n\\n /**\\n * @notice Determine if a the owner of a given overlay will be the beneficiary of the claim phase.\\n * @param _overlay The overlay address of the applicant.\\n */\\n function isWinner(bytes32 _overlay) public view returns (bool) {\\n if (!currentPhaseClaim()) {\\n revert NotClaimPhase();\\n }\\n\\n uint64 cr = currentRound();\\n if (cr != currentRevealRound) {\\n revert NoReveals();\\n }\\n\\n if (cr <= currentClaimRound) {\\n revert AlreadyClaimed();\\n }\\n\\n uint256 currentWinnerSelectionSum;\\n bytes32 winnerIs;\\n bytes32 randomNumber;\\n uint256 randomNumberTrunc;\\n bytes32 truthRevealedHash;\\n uint8 truthRevealedDepth;\\n uint256 revIndex;\\n string memory winnerSelectionAnchor = currentWinnerSelectionAnchor();\\n uint256 redundancyCount = 0;\\n\\n // Get current truth\\n (truthRevealedHash, truthRevealedDepth) = getCurrentTruth();\\n uint256 commitsArrayLength = currentCommits.length;\\n\\n for (uint256 i = 0; i < commitsArrayLength; ) {\\n revIndex = currentCommits[i].revealIndex;\\n\\n // Deterministically read winner\\n if (\\n currentCommits[i].revealed &&\\n truthRevealedHash == currentReveals[revIndex].hash &&\\n truthRevealedDepth == currentReveals[revIndex].depth\\n ) {\\n currentWinnerSelectionSum += currentReveals[revIndex].stakeDensity;\\n randomNumber = keccak256(abi.encodePacked(winnerSelectionAnchor, redundancyCount));\\n randomNumberTrunc = uint256(randomNumber & MAX_H);\\n\\n if (\\n randomNumberTrunc * currentWinnerSelectionSum <\\n currentReveals[revIndex].stakeDensity * (uint256(MAX_H) + 1)\\n ) {\\n winnerIs = currentReveals[revIndex].overlay;\\n }\\n\\n redundancyCount++;\\n }\\n unchecked {\\n ++i;\\n }\\n }\\n\\n return (winnerIs == _overlay);\\n }\\n\\n // ----------------------------- Claim verifications ------------------------------\\n\\n function socFunction(ChunkInclusionProof calldata entryProof) internal pure {\\n if (entryProof.socProof.length == 0) return;\\n\\n if (\\n !Signatures.socVerify(\\n entryProof.socProof[0].signer, // signer Ethereum address to check against\\n entryProof.socProof[0].signature,\\n entryProof.socProof[0].identifier,\\n entryProof.socProof[0].chunkAddr\\n )\\n ) {\\n revert SocVerificationFailed(entryProof.socProof[0].chunkAddr);\\n }\\n\\n if (\\n calculateSocAddress(entryProof.socProof[0].identifier, entryProof.socProof[0].signer) !=\\n entryProof.proveSegment\\n ) {\\n revert SocCalcNotMatching(entryProof.socProof[0].chunkAddr);\\n }\\n }\\n\\n function stampFunction(ChunkInclusionProof calldata entryProof) internal view {\\n // authentic\\n (address batchOwner, uint8 batchDepth, uint8 bucketDepth, , , ) = PostageContract.batches(\\n entryProof.postageProof.postageId\\n );\\n\\n // alive\\n if (batchOwner == address(0)) {\\n revert BatchDoesNotExist(entryProof.postageProof.postageId); // Batch does not exist or expired\\n }\\n\\n uint32 postageIndex = getPostageIndex(entryProof.postageProof.index);\\n uint256 maxPostageIndex = postageStampIndexCount(batchDepth, bucketDepth);\\n // available\\n if (postageIndex >= maxPostageIndex) {\\n revert IndexOutsideSet(entryProof.postageProof.postageId);\\n }\\n\\n // aligned\\n uint64 postageBucket = getPostageBucket(entryProof.postageProof.index);\\n uint64 addressBucket = addressToBucket(entryProof.proveSegment, bucketDepth);\\n if (postageBucket != addressBucket) {\\n revert BucketDiffers(entryProof.postageProof.postageId);\\n }\\n\\n // authorized\\n if (\\n !Signatures.postageVerify(\\n batchOwner,\\n entryProof.postageProof.signature,\\n entryProof.proveSegment,\\n entryProof.postageProof.postageId,\\n entryProof.postageProof.index,\\n entryProof.postageProof.timeStamp\\n )\\n ) {\\n revert SigRecoveryFailed(entryProof.postageProof.postageId);\\n }\\n }\\n\\n function addressToBucket(bytes32 swarmAddress, uint8 bucketDepth) internal pure returns (uint32) {\\n uint32 prefix = uint32(uint256(swarmAddress) >> (256 - 32));\\n return prefix >> (32 - bucketDepth);\\n }\\n\\n function postageStampIndexCount(uint8 postageDepth, uint8 bucketDepth) internal pure returns (uint256) {\\n return 1 << (postageDepth - bucketDepth);\\n }\\n\\n function getPostageIndex(uint64 signedIndex) internal pure returns (uint32) {\\n return uint32(signedIndex);\\n }\\n\\n function getPostageBucket(uint64 signedIndex) internal pure returns (uint64) {\\n return uint32(signedIndex >> 32);\\n }\\n\\n function calculateSocAddress(bytes32 identifier, address signer) internal pure returns (bytes32) {\\n return keccak256(abi.encodePacked(identifier, signer));\\n }\\n\\n function checkOrder(uint256 a, uint256 b, bytes32 trA1, bytes32 trA2, bytes32 trALast) internal pure {\\n if (a < b) {\\n if (uint256(trA1) >= uint256(trA2)) {\\n revert RandomElementCheckFailed();\\n }\\n if (uint256(trA2) >= uint256(trALast)) {\\n revert LastElementCheckFailed();\\n }\\n } else {\\n if (uint256(trA2) >= uint256(trA1)) {\\n revert RandomElementCheckFailed();\\n }\\n if (uint256(trA1) >= uint256(trALast)) {\\n revert LastElementCheckFailed();\\n }\\n }\\n }\\n\\n function estimateSize(bytes32 trALast) internal view {\\n if (uint256(trALast) >= sampleMaxValue) {\\n revert ReserveCheckFailed(trALast);\\n }\\n }\\n}\\n\",\"keccak256\":\"0xe81060e24baf7ad67b4e26841635070f7b68cc54ed49b0983b0b87947ea2d7d1\",\"license\":\"BSD-3-Clause\"},\"src/Util/ChunkProof.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\npragma solidity ^0.8.19;\\n\\nlibrary BMTChunk {\\n // max chunk payload size\\n uint256 public constant MAX_CHUNK_PAYLOAD_SIZE = 4096;\\n // segment byte size\\n uint256 public constant SEGMENT_SIZE = 32;\\n\\n /**\\n * @notice Changes the endianness of a uint64.\\n * @dev https://graphics.stanford.edu/~seander/bithacks.html#ReverseParallel\\n * @param _b The unsigned integer to reverse\\n * @return v - The reversed value\\n */\\n function reverseUint64(uint64 _b) public pure returns (uint64) {\\n uint256 v = _b;\\n\\n // swap bytes\\n v =\\n ((v >> 8) & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) |\\n ((v & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) << 8);\\n // swap 2-byte long pairs\\n v =\\n ((v >> 16) & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) |\\n ((v & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) << 16);\\n // swap 4-byte long pairs\\n v =\\n ((v >> 32) & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) |\\n ((v & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) << 32);\\n\\n return uint64(v);\\n }\\n\\n /** Calculates the root hash from the provided inclusion proof segments and its corresponding segment index\\n * @param _proofSegments Proof segments.\\n * @param _proveSegment Segment to prove.\\n * @param _proveSegmentIndex Prove segment index\\n * @return _calculatedHash chunk hash\\n */\\n function rootHashFromInclusionProof(\\n bytes32[] memory _proofSegments,\\n bytes32 _proveSegment,\\n uint256 _proveSegmentIndex\\n ) internal pure returns (bytes32 _calculatedHash) {\\n _calculatedHash = _proveSegment;\\n for (uint256 i = 0; i < _proofSegments.length; i++) {\\n bool mergeFromRight = _proveSegmentIndex % 2 == 0;\\n _calculatedHash = mergeSegment(_calculatedHash, _proofSegments[i], mergeFromRight);\\n _proveSegmentIndex >>= 1;\\n }\\n return _calculatedHash;\\n }\\n\\n /**\\n * Calculate the chunk address from the Binary Merkle Tree of the chunk data\\n *\\n * The BMT chunk address is the hash of the 8 byte span and the root\\n * hash of a binary Merkle tree (BMT) built on the 32-byte segments\\n * of the underlying data.\\n * @param _proofSegments Proof segments.\\n * @param _proveSegment Segment to prove.\\n * @param _proveSegmentIndex Prove segment index\\n * @param _chunkSpan chunk bytes length\\n * @return _chunkHash chunk hash\\n */\\n function chunkAddressFromInclusionProof(\\n bytes32[] memory _proofSegments,\\n bytes32 _proveSegment,\\n uint256 _proveSegmentIndex,\\n uint64 _chunkSpan\\n ) internal pure returns (bytes32) {\\n bytes32 rootHash = rootHashFromInclusionProof(_proofSegments, _proveSegment, _proveSegmentIndex);\\n return keccak256(abi.encodePacked(reverseUint64(_chunkSpan), rootHash));\\n }\\n\\n function mergeSegment(\\n bytes32 _calculatedHash,\\n bytes32 _proofSegment,\\n bool mergeFromRight\\n ) internal pure returns (bytes32 res) {\\n if (mergeFromRight) {\\n res = keccak256(abi.encode(_calculatedHash, _proofSegment));\\n } else {\\n res = keccak256(abi.encode(_proofSegment, _calculatedHash));\\n }\\n return res;\\n }\\n}\\n\",\"keccak256\":\"0xe4a86f2002b8b8fc4c955537d6b80ba42fb04a816e783ddbd05f0484b013938a\",\"license\":\"MIT\"},\"src/Util/Signatures.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\npragma solidity ^0.8.19;\\n\\nlibrary Signatures {\\n error InvalidSignatureLength();\\n\\n /** Hash of the message to sign */\\n function getPostageMessageHash(\\n bytes32 _chunkAddr,\\n bytes32 _batchId,\\n uint64 _index,\\n uint64 _timeStamp\\n ) internal pure returns (bytes32) {\\n return keccak256(abi.encodePacked(_chunkAddr, _batchId, _index, _timeStamp));\\n }\\n\\n function postageVerify(\\n address _signer, // signer Ethereum address to check against\\n bytes memory _signature,\\n bytes32 _chunkAddr,\\n bytes32 _postageId,\\n uint64 _index,\\n uint64 _timeStamp\\n ) internal pure returns (bool) {\\n bytes32 messageHash = getPostageMessageHash(_chunkAddr, _postageId, _index, _timeStamp);\\n bytes32 ethMessageHash = getEthSignedMessageHash(messageHash);\\n\\n return recoverSigner(ethMessageHash, _signature) == _signer;\\n }\\n\\n function getEthSignedMessageHash(bytes32 _messageHash) internal pure returns (bytes32) {\\n /*\\n Signature is produced by signing a keccak256 hash with the following format:\\n \\\"\\\\x19Ethereum Signed Message\\\\n\\\" + len(msg) + msg\\n */\\n return keccak256(abi.encodePacked(\\\"\\\\x19Ethereum Signed Message:\\\\n32\\\", _messageHash));\\n }\\n\\n function recoverSigner(\\n bytes32 _ethSignedMessageHash, // it has to be prefixed message: https://ethereum.stackexchange.com/questions/19582/does-ecrecover-in-solidity-expects-the-x19ethereum-signed-message-n-prefix/21037\\n bytes memory _signature\\n ) internal pure returns (address) {\\n (bytes32 r, bytes32 s, uint8 v) = splitSignature(_signature);\\n\\n return ecrecover(_ethSignedMessageHash, v, r, s);\\n }\\n\\n function splitSignature(bytes memory sig) internal pure returns (bytes32 r_, bytes32 s_, uint8 v_) {\\n if (sig.length != 65) {\\n revert InvalidSignatureLength();\\n }\\n\\n assembly {\\n /*\\n verbose explanation: https://ethereum.stackexchange.com/questions/135591/split-signature-function-in-solidity-by-example-docs\\n First 32 bytes stores the length of the signature\\n add(sig, 32) = pointer of sig + 32\\n effectively, skips first 32 bytes of signature\\n mload(p) loads next 32 bytes starting at the memory address p into memory\\n */\\n\\n // first 32 bytes, after the length prefix\\n r_ := mload(add(sig, 32))\\n // second 32 bytes\\n s_ := mload(add(sig, 64))\\n // final byte (first byte of the next 32 bytes)\\n v_ := byte(0, mload(add(sig, 96)))\\n }\\n\\n // implicitly return (r, s, v)\\n }\\n\\n function getSocMessageHash(bytes32 _identifier, bytes32 _chunkAddr) internal pure returns (bytes32) {\\n return keccak256(abi.encodePacked(_identifier, _chunkAddr));\\n }\\n\\n function socVerify(\\n address _signer, // signer Ethereum address to check against\\n bytes memory _signature,\\n bytes32 _identifier,\\n bytes32 _chunkAddr\\n ) internal pure returns (bool) {\\n bytes32 messageHash = getSocMessageHash(_identifier, _chunkAddr);\\n bytes32 ethMessageHash = getEthSignedMessageHash(messageHash);\\n\\n return recoverSigner(ethMessageHash, _signature) == _signer;\\n }\\n}\\n\",\"keccak256\":\"0x11762639cfa5bd2ea21922f762254c776ce890ab9e4085b3e3d45dbe21867ac8\",\"license\":\"MIT\"},\"src/Util/TransformedChunkProof.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\npragma solidity ^0.8.19;\\n\\nlibrary TransformedBMTChunk {\\n // max chunk payload size\\n uint256 public constant MAX_CHUNK_PAYLOAD_SIZE = 4096;\\n // segment byte size\\n uint256 public constant SEGMENT_SIZE = 32;\\n\\n /** Calculates the root hash from the provided inclusion proof segments and its corresponding segment index\\n * @param _proofSegments Proof segments.\\n * @param _proveSegment Segment to prove.\\n * @param _proveSegmentIndex Prove segment index\\n * @return _calculatedHash chunk hash\\n */\\n function transformedRootHashFromInclusionProof(\\n bytes32[] memory _proofSegments,\\n bytes32 _proveSegment,\\n uint256 _proveSegmentIndex,\\n bytes32 key\\n ) internal pure returns (bytes32 _calculatedHash) {\\n _calculatedHash = _proveSegment;\\n for (uint256 i = 0; i < _proofSegments.length; i++) {\\n bool mergeFromRight = _proveSegmentIndex % 2 == 0 ? true : false;\\n _calculatedHash = transformedMergeSegment(_calculatedHash, _proofSegments[i], mergeFromRight, key);\\n _proveSegmentIndex >>= 1;\\n }\\n\\n return _calculatedHash;\\n }\\n\\n /**\\n * @notice Changes the endianness of a uint64.\\n * @dev https://graphics.stanford.edu/~seander/bithacks.html#ReverseParallel\\n * @param _b The unsigned integer to reverse\\n * @return v - The reversed value\\n */\\n function reverseUint64(uint64 _b) public pure returns (uint64) {\\n uint256 v = _b;\\n\\n // swap bytes\\n v =\\n ((v >> 8) & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) |\\n ((v & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) << 8);\\n // swap 2-byte long pairs\\n v =\\n ((v >> 16) & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) |\\n ((v & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) << 16);\\n // swap 4-byte long pairs\\n v =\\n ((v >> 32) & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) |\\n ((v & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) << 32);\\n\\n return uint64(v);\\n }\\n\\n /**\\n * Calculate the chunk address from the Binary Merkle Tree of the chunk data\\n *\\n * The BMT chunk address is the hash of the 8 byte span and the root\\n * hash of a binary Merkle tree (BMT) built on the 32-byte segments\\n * of the underlying data.\\n * @param _proofSegments Proof segments.\\n * @param _proveSegment Segment to prove.\\n * @param _proveSegmentIndex Prove segment index\\n * @param _chunkSpan chunk bytes length\\n * @return _chunkHash chunk hash\\n */\\n function transformedChunkAddressFromInclusionProof(\\n bytes32[] memory _proofSegments,\\n bytes32 _proveSegment,\\n uint256 _proveSegmentIndex,\\n uint64 _chunkSpan,\\n bytes32 key\\n ) internal pure returns (bytes32) {\\n bytes32 rootHash = transformedRootHashFromInclusionProof(\\n _proofSegments,\\n _proveSegment,\\n _proveSegmentIndex,\\n key\\n );\\n return keccak256(abi.encodePacked(key, reverseUint64(_chunkSpan), rootHash));\\n }\\n\\n function transformedMergeSegment(\\n bytes32 _calculatedHash,\\n bytes32 _proofSegment,\\n bool mergeFromRight,\\n bytes32 key\\n ) internal pure returns (bytes32 res) {\\n if (mergeFromRight) {\\n res = keccak256(abi.encode(key, _calculatedHash, _proofSegment));\\n } else {\\n res = keccak256(abi.encode(key, _proofSegment, _calculatedHash));\\n }\\n return res;\\n }\\n}\\n\",\"keccak256\":\"0xf36473af0bec0de80c769b139a09bc0329807cb5c3b6234473601081da14350c\",\"license\":\"MIT\"},\"src/interface/IPostageStamp.sol\":{\"content\":\"// SPDX-License-Identifier: BSD-3-Clause\\npragma solidity ^0.8.19;\\n\\ninterface IPostageStamp {\\n function withdraw(address beneficiary) external;\\n\\n function setPrice(uint256 _price) external;\\n\\n function validChunkCount() external view returns (uint256);\\n\\n function batchOwner(bytes32 _batchId) external view returns (address);\\n\\n function batchDepth(bytes32 _batchId) external view returns (uint8);\\n\\n function batchBucketDepth(bytes32 _batchId) external view returns (uint8);\\n\\n function remainingBalance(bytes32 _batchId) external view returns (uint256);\\n\\n function minimumInitialBalancePerChunk() external view returns (uint256);\\n\\n function batches(\\n bytes32\\n )\\n external\\n view\\n returns (\\n address owner,\\n uint8 depth,\\n uint8 bucketDepth,\\n bool immutableFlag,\\n uint256 normalisedBalance,\\n uint256 lastUpdatedBlockNumber\\n );\\n}\\n\",\"keccak256\":\"0xb46f1043bf7fdc22d5f719ab97341211fa30fff499de3cf079be715079b965ad\",\"license\":\"BSD-3-Clause\"}},\"version\":1}", + "bytecode": "0x60806040526008805462ffffff60c01b19166264020160c01b1790557dba1914b54e0348a1028d1a103a95ed55c4004b9d332400000000000000006009553480156200004a57600080fd5b5060405162004e0838038062004e088339810160408190526200006d916200019d565b60018054600380546001600160a01b03199081166001600160a01b03888116919091179092556001600160a81b0319909216610100868316021790925560028054909116918316919091179055620000c7600033620000d0565b505050620001e7565b620000dc8282620000e0565b5050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16620000dc576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556200013c3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b80516001600160a01b03811681146200019857600080fd5b919050565b600080600060608486031215620001b357600080fd5b620001be8462000180565b9250620001ce6020850162000180565b9150620001de6040850162000180565b90509250925092565b614c1180620001f76000396000f3fe608060405234801561001057600080fd5b50600436106102775760003560e01c806377c75d1011610160578063b6cd5822116100d8578063dfbf53ae1161008c578063f69ee1d111610071578063f69ee1d1146105df578063f7b188a5146105f2578063fb00f2f3146105fa57600080fd5b8063dfbf53ae1461059c578063f4e6fcca146105cc57600080fd5b8063ce987745116100bd578063ce9877451461056e578063d1e8b63d14610581578063d547741f1461058957600080fd5b8063b6cd582214610541578063c46b40291461055457600080fd5b80638456cb591161012f5780638d8b6428116101145780638d8b6428146104fa57806391d1485414610502578063a217fddf1461053957600080fd5b80638456cb59146104ea5780638a19c8bc146104f257600080fd5b806377c75d10146104645780637fe019c61461047757806382b39b1b1461049257806383220626146104e257600080fd5b80635c975abb116101f357806364c34a85116101c257806369da9114116101a757806369da9114146103de5780636f94aaf2146103f157806372286cba1461040c57600080fd5b806364c34a85146103a957806369bfac01146103b157600080fd5b80635c975abb146103705780635d4844ea1461037b57806362fd29ae1461038e57806363f5cf7c1461039657600080fd5b80632a4e62491161024a5780632f3906da1161022f5780632f3906da1461034257806336568abe1461034a5780635838d6731461035d57600080fd5b80632a4e6249146103185780632f2ff15d1461032d57600080fd5b806301ffc9a71461027c5780631736d472146102a457806318350096146102b7578063248a9ca3146102e7575b600080fd5b61028f61028a366004614312565b61060d565b60405190151581526020015b60405180910390f35b61028f6102b2366004614360565b610676565b6001546102cf9061010090046001600160a01b031681565b6040516001600160a01b03909116815260200161029b565b61030a6102f5366004614399565b60009081526020819052604090206001015490565b60405190815260200161029b565b610320610883565b60405161029b91906143b2565b61034061033b366004614441565b610990565b005b61028f6109ba565b610340610358366004614441565b610a04565b61034061036b366004614483565b610a95565b60015460ff1661028f565b6003546102cf906001600160a01b031681565b61030a611025565b6103406103a43660046144c8565b6110f1565b61030a611526565b6008546103c59067ffffffffffffffff1681565b60405167ffffffffffffffff909116815260200161029b565b6002546102cf906001600160a01b031681565b6008546103c590600160801b900467ffffffffffffffff1681565b61041f61041a366004614399565b611606565b604080519788526001600160a01b0390961660208801529315159486019490945260ff9091166060850152608084015260a083019190915260c082015260e00161029b565b61028f610472366004614399565b611664565b6008546103c590600160401b900467ffffffffffffffff1681565b6104a56104a0366004614399565b611914565b604080519687526001600160a01b03909516602087015260ff909316938501939093526060840152608083019190915260a082015260c00161029b565b61030a61196b565b610340611976565b6103c56119cf565b61028f6119dc565b61028f610510366004614441565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b61030a600081565b61034061054f366004614550565b611a06565b61055c611f60565b60405160ff909116815260200161029b565b61030a61057c366004614585565b611fe5565b61028f612054565b610340610597366004614441565b612079565b600a54600b54600c54600d54600e546104a594936001600160a01b03811693600160a01b90910460ff1692909186565b6103406105da3660046145c2565b61209e565b6103406105ed366004614399565b612185565b6103406121d9565b61028f61060836600461460d565b612230565b60006001600160e01b031982167f7965db0b00000000000000000000000000000000000000000000000000000000148061067057507f01ffc9a7000000000000000000000000000000000000000000000000000000006001600160e01b03198316145b92915050565b60035460405163d1052d1f60e01b81526001600160a01b038481166004830152600092839291169063d1052d1f90602401602060405180830381865afa1580156106c4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106e8919061463b565b600354604051631d54805360e01b81526001600160a01b03878116600483015292935060009290911690631d54805390602401602060405180830381865afa158015610738573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061075c9190614654565b6107669085614687565b90506107706109ba565b156107a7576040517fe2586bcc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b816000036107c7576040516273e5c360e31b815260040160405180910390fd5b6107d3609860026146a0565b6107dd90436146b7565b82106107fc57604051630a0744c560e01b815260040160405180910390fd5b6003546040516397adedb560e01b81526001600160a01b03878116600483015261087a9216906397adedb590602401602060405180830381865afa158015610848573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061086c919061463b565b610874611526565b83612230565b95945050505050565b606061088d6119dc565b6108aa57604051633788c6c160e11b815260040160405180910390fd5b60006108b46119cf565b60085490915067ffffffffffffffff808316600160401b90920416146108ed57604051636fbabc7760e01b815260040160405180910390fd5b6005805480602002602001604051908101604052809291908181526020016000905b828210156109865760008481526020908190206040805160c08101825260058602909201805483526001808201546001600160a01b03811685870152600160a01b900460ff169284019290925260028101546060840152600381015460808401526004015460a0830152908352909201910161090f565b5050505091505090565b6000828152602081905260409020600101546109ab8161226d565b6109b5838361227a565b505050565b6000806109c86098436146e0565b90506109d6600460986146f4565b81101580156109ef57506109ec600260986146f4565b81105b156109fc57600191505090565b600091505090565b6001600160a01b0381163314610a875760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b610a918282612318565b5050565b610a9d612397565b6000610aa76119cf565b6003546040516397adedb560e01b81523360048201529192506000916001600160a01b03909116906397adedb590602401602060405180830381865afa158015610af5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b19919061463b565b6003546040517f830a053e0000000000000000000000000000000000000000000000000000000081523360048201529192506000916001600160a01b039091169063830a053e90602401602060405180830381865afa158015610b80573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ba4919061463b565b60035460405163d1052d1f60e01b81523360048201529192506000916001600160a01b039091169063d1052d1f90602401602060405180830381865afa158015610bf2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c16919061463b565b600354604051631d54805360e01b81523360048201529192506000916001600160a01b0390911690631d54805390602401602060405180830381865afa158015610c64573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c889190614654565b9050610c92612054565b610cc8576040517fdc816a8700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001610cd6600460986146f4565b610ce091906146b7565b610ceb6098436146e0565b03610d22576040517f5baef6b600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8567ffffffffffffffff168567ffffffffffffffff161115610d70576040517f50ff7c0000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8567ffffffffffffffff168567ffffffffffffffff161015610dbe576040517f7a0c0fd600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b81600003610dde576040516273e5c360e31b815260040160405180910390fd5b610dea609860026146a0565b610df490436146b7565b8210610e1357604051630a0744c560e01b815260040160405180910390fd5b60085467ffffffffffffffff868116911614610e5357610e3560046000614230565b6008805467ffffffffffffffff191667ffffffffffffffff87161790555b60045460005b81811015610ec6578560048281548110610e7557610e75614708565b90600052602060002090600502016000015403610ebe576040517fbfec555800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600101610e59565b5060046040518060e00160405280878152602001336001600160a01b031681526020016000151581526020018460ff1681526020018681526020018a8152602001600081525090806001815401808255809150506001900390600052602060002090600502016000909190919091506000820151816000015560208201518160010160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555060408201518160010160146101000a81548160ff02191690831515021790555060608201518160010160156101000a81548160ff021916908360ff1602179055506080820151816002015560a0820151816003015560c0820151816004015550507f68e0867601a98978930107aee7f425665e61edd70ca594c68ca5da9e81f84c29878660405161101392919067ffffffffffffffff929092168252602082015260400190565b60405180910390a15050505050505050565b6000806110306119cf565b61103b90600161471e565b6007546008549192509061106190600160401b900467ffffffffffffffff16600161471e565b67ffffffffffffffff168267ffffffffffffffff161115610670576008546000906001906110a090600160401b900467ffffffffffffffff1685614746565b6110aa9190614746565b67ffffffffffffffff16905081816040516020016110d2929190918252602082015260400190565b6040516020818303038152906040528051906020012091505092915050565b6110f9612397565b6111016123ea565b6040805160c081018252600a548152600b546001600160a01b0381166020830152600160a01b900460ff1691810191909152600c546060820152600d546080820152600e5460a08201526006546007546000918291611161600f826146e0565b935061116e600e826146e0565b9250838310611185578261118181614767565b9350505b6111988660200135838760400151612230565b6111b857604051633b5f43a360e01b815260036004820152602401610a7e565b6111c386601e612a59565b6111cc86612d6b565b6111d586613078565b6111e88860200135838760400151612230565b61120857604051633b5f43a360e01b815260026004820152602401610a7e565b61121c886112178660026146a0565b612a59565b61122588612d6b565b61122e88613078565b6112418760200135838760400151612230565b61126157604051633b5f43a360e01b815260016004820152602401610a7e565b611270876112178560026146a0565b61127987612d6b565b61128287613078565b6112f884846112918b80614780565b60008181106112a2576112a2614708565b602002919091013590506112b68b80614780565b60008181106112c7576112c7614708565b602002919091013590506112db8b80614780565b60008181106112ec576112ec614708565b9050602002013561330c565b6113226113058780614780565b600081811061131657611316614708565b90506020020135613399565b60015460208601516040516001600160a01b03918216602482015260009261010090049091169060440160408051601f198184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f51cff8d900000000000000000000000000000000000000000000000000000000179052516113af91906147f5565b6000604051808303816000865af19150503d80600081146113ec576040519150601f19603f3d011682016040523d82523d6000602084013e6113f1565b606091505b505090508061143c576020808701516040516001600160a01b0390911681527f7ae187a0c04cf55b655ca83fa11d37854c882bf1fdcb588469b414731bb0e05a910160405180910390a15b7f788e77979e6e6a8a6a5d2c19c58b1ff9671298f54c85ac6f6aa30379aed5861a8660405161146b9190614811565b60405180910390a17fbee3fc8a3523c1a65fa9308ce1f2b8fd90c24975b141b754603194597846e4dd60018054906101000a90046001600160a01b03166001600160a01b0316638a5e8e326040518163ffffffff1660e01b8152600401602060405180830381865afa1580156114e5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611509919061463b565b6040519081526020015b60405180910390a1505050505050505050565b6000611530612054565b8061156e5750600854600160401b900467ffffffffffffffff166115526119cf565b67ffffffffffffffff1611801561156e575061156c6119dc565b155b156115805761157b61196b565b905090565b6115886119dc565b156115955761157b611025565b61159d6109ba565b80156115cc5750600854600160401b900467ffffffffffffffff166115c06119cf565b67ffffffffffffffff16145b15611603576040517f36b7884b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b90565b6004818154811061161657600080fd5b6000918252602090912060059091020180546001820154600283015460038401546004909401549294506001600160a01b0382169360ff600160a01b8404811694600160a81b909404169287565b600061166e6119dc565b61168b57604051633788c6c160e11b815260040160405180910390fd5b60006116956119cf565b60085490915067ffffffffffffffff808316600160401b90920416146116ce57604051636fbabc7760e01b815260040160405180910390fd5b60085467ffffffffffffffff600160801b90910481169082161161170557604051630c8d9eab60e31b815260040160405180910390fd5b6000806000806000806000806117196133d7565b90506000611725613491565b600454919650945060005b81811015611900576004818154811061174b5761174b614708565b90600052602060002090600502016004015494506004818154811061177257611772614708565b906000526020600020906005020160010160149054906101000a900460ff1680156117c05750600585815481106117ab576117ab614708565b90600052602060002090600502016004015487145b80156117fe5750600585815481106117da576117da614708565b600091825260209091206001600590920201015460ff878116600160a01b90920416145b156118f8576005858154811061181657611816614708565b9060005260206000209060050201600301548b6118339190614860565b9a508383604051602001611848929190614873565b60408051601f19818403018152919052805160209091012098506fffffffffffffffffffffffffffffffff808a169850611883906001614860565b6005868154811061189657611896614708565b9060005260206000209060050201600301546118b291906146a0565b6118bc8c8a6146a0565b10156118ea57600585815481106118d5576118d5614708565b90600052602060002090600502016000015499505b826118f481614767565b9350505b600101611730565b505050959099149998505050505050505050565b6005818154811061192457600080fd5b6000918252602090912060059091020180546001820154600283015460038401546004909401549294506001600160a01b03821693600160a01b90920460ff169290919086565b60008061103b6119cf565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff166119c557604051631d77d47760e21b815260040160405180910390fd5b6119cd61364a565b565b600061157b6098436146f4565b60006119ea600260986146f4565b6119f56098436146e0565b10611a005750600190565b50600090565b611a0e612397565b6000611a186119cf565b6003546040516397adedb560e01b81523360048201529192506000916001600160a01b03909116906397adedb590602401602060405180830381865afa158015611a66573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a8a919061463b565b9050611a94611f60565b60ff168560ff161015611ad3576040517f83d9b7bd00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611adb6109ba565b611b11576040517fd1088db600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60085467ffffffffffffffff838116911614611b59576040517f842a9e0a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60085467ffffffffffffffff838116600160401b9092041614611c4157611b7e611526565b600655611b8d60056000614251565b600880547fffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff16600160401b67ffffffffffffffff8516908102919091179091556006546040805192835260208301919091527ff0ae472da9c8da86bda4991a549c03a3cb328b5f360ea11a5b8814f32bb85176910160405180910390a1611c41600754604080516020810192909252449082015260600160408051601f198184030181529190528051602090910120600755565b6000611c4f82878787611fe5565b90506000611c5d838361369e565b9050600060048281548110611c7457611c74614708565b600091825260208083206040805160e08101825260059094029091018054845260018101546001600160a01b0381169385019390935260ff600160a01b84048116151592850192909252600160a81b909204166060830181905260028201546080840152600382015460a084015260049091015460c0830152909250611cfa908a614687565b9050611d0d826000015160065483612230565b611d49576006546040517f14ebbbe4000000000000000000000000000000000000000000000000000000008152600401610a7e91815260200190565b816040015115611d85576040517fa89ac15100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600160048481548110611d9a57611d9a614708565b906000526020600020906005020160010160146101000a81548160ff02191690831515021790555060058054905060048481548110611ddb57611ddb614708565b90600052602060002090600502016004018190555060056040518060c001604052808460000151815260200184602001516001600160a01b031681526020018b60ff16815260200184608001518152602001836002611e3a9190614979565b8560800151611e4991906146a0565b815260209081018b90528254600181810185556000948552938290208351600590920201908155908201519281018054604084015160ff16600160a01b0274ffffffffffffffffffffffffffffffffffffffffff199091166001600160a01b0390951694909417939093179092556060810151600280840191909155608080830151600385015560a0909201516004909301929092558351908401517f13fc17fd71632266fe82092de6dd91a06b4fa68d8dc950492e5421cbed55a6a59289929190611f16908690614979565b8660800151611f2591906146a0565b6040805167ffffffffffffffff90951685526020850193909352918301526060820152608081018a905260ff8b1660a082015260c001611513565b6008546000908190611f859067ffffffffffffffff600160801b820481169116614746565b67ffffffffffffffff169050600060fe8211611fa15781611fa4565b60fe5b611faf906001614988565b600b5490915060ff600160a01b9091048116908216811115611fda57611fd58282614687565b611fdd565b60005b935050505090565b60408051602081018690527fff0000000000000000000000000000000000000000000000000000000000000060f886901b169181019190915260418101839052606181018290526000906081015b6040516020818303038152906040528051906020012090505b949350505050565b6000612062600460986146f4565b61206d6098436146e0565b1015611a005750600190565b6000828152602081905260409020600101546120948161226d565b6109b58383612318565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff166120ed57604051637bfa4b9f60e01b815260040160405180910390fd5b600880547fffffffffffff0000ffffffffffffffffffffffffffffffffffffffffffffffff16600160c01b60ff958616027fffffffffffff00ffffffffffffffffffffffffffffffffffffffffffffffffff1617600160c81b93851693909302929092177fffffffffff00ffffffffffffffffffffffffffffffffffffffffffffffffffff16600160d01b9190931602919091179055565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff166121d457604051637bfa4b9f60e01b815260040160405180910390fd5b600955565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff1661222857604051631d77d47760e21b815260040160405180910390fd5b6119cd613749565b60008160ff1660000361224557506001612266565b61225460ff83166101006149a1565b61225f9060026149bc565b8484181090505b9392505050565b6122778133613782565b50565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610a91576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556122d43390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1615610a91576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b60015460ff16156119cd5760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a20706175736564000000000000000000000000000000006044820152606401610a7e565b60006123f46119cf565b90506123fe6119dc565b61241b57604051633788c6c160e11b815260040160405180910390fd5b60085467ffffffffffffffff828116600160401b909204161461245157604051636fbabc7760e01b815260040160405180910390fd5b60085467ffffffffffffffff600160801b90910481169082161161248857604051630c8d9eab60e31b815260040160405180910390fd5b600454604051818152600091829182918291829182917f6752c5e71c95fb93bc7137adeb115a33fa4e54e2683e33d3f90c2bb1c4b6c2a59060200160405180910390a16005546040519081527f4c03de6a759749c0c9387b7014634dc5c6af610e1366023d90751c783a998f8d9060200160405180910390a1612509613491565b6040805183815260ff831660208201529295509093507f34e8eda4cd857cd2865becf58a47748f31415f4a382cbb2cc0c64b9a27c717be910160405180910390a160006125546133d7565b905060005b828110156129415760006004828154811061257657612576614708565b600091825260208083206040805160e08101825260059485029092018054835260018101546001600160a01b0381169484019490945260ff600160a01b85048116151592840192909252600160a81b90930416606082015260028201546080820152600382015460a082015260049091015460c0820181905282549194509291908390811061260757612607614708565b60009182526020918290206040805160c0810182526005939093029091018054835260018101546001600160a01b03811694840194909452600160a01b90930460ff1682820152600283015460608301526003830154608083015260049092015460a082015290840151909150801561268357508060a0015188145b80156126985750806040015160ff168760ff16145b1561278d5760808101516126ac908d614860565b9b50848b6040516020016126c1929190614873565b60408051601f19818403018152919052805160209091012099506fffffffffffffffffffffffffffffffff808b1699506126fc906001614860565b816080015161270b91906146a0565b6127158d8b6146a0565b101561277f578051600a556020810151600b8054604084015160ff16600160a01b0274ffffffffffffffffffffffffffffffffffffffffff199091166001600160a01b03909316929092179190911790556060810151600c556080810151600d5560a0810151600e555b8a61278981614767565b9b50505b826040015180156127b657508060a00151881415806127b65750806040015160ff168760ff1614155b80156127d75750600854600160d01b900460ff166127d56064446146e0565b105b156128835760035460208201516001600160a01b039091169063d009b2d6906128018a6002614979565b60085461281a90609890600160c01b900460ff166146a0565b61282491906146a0565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401600060405180830381600087803b15801561286a57600080fd5b505af115801561287e573d6000803e3d6000fd5b505050505b82604001516129335760035460208401516001600160a01b039091169063d009b2d6906128b18a6002614979565b6008546128ca90609890600160c81b900460ff166146a0565b6128d491906146a0565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401600060405180830381600087803b15801561291a57600080fd5b505af115801561292e573d6000803e3d6000fd5b505050505b836001019350505050612559565b506002546040517fffb98fe300000000000000000000000000000000000000000000000000000000815261ffff891660048201526000916001600160a01b03169063ffb98fe3906024016020604051808303816000875af11580156129aa573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129ce91906149dc565b905080612a0d5760405161ffff891681527f20378e5d379eabfa30444ecc5eb2b87d0d77bdbf5a58d80d008673b0ca6421419060200160405180910390a15b50506008805467ffffffffffffffff909916600160801b027fffffffffffffffff0000000000000000ffffffffffffffffffffffffffffffff9099169890981790975550505050505050565b600754600090612a6b906080906146e0565b90506000612ace612a7f60a0860186614780565b80806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250505050606086013584612ac660a0890160808a016149f7565b6006546137f5565b60408051858152602081018390529192507f94e252069a85aa79db21f5bd8ca4e14dd3a3927aa492711017a2c8ddad95af00910160405180910390a1612b56612b178580614780565b8080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525050505060208601358561040061396d565b600e5414612b815760405163755f0a2560e01b81526001600482015260248101829052604401610a7e565b612b8e60a0850185614780565b6000818110612b9f57612b9f614708565b90506020020135848060400190612bb69190614780565b6000818110612bc757612bc7614708565b9050602002013514612bf65760405163755f0a2560e01b81526002600482015260248101829052604401610a7e565b600080612c0660e0870187614780565b905011612c17578460200135612c4c565b612c2460e0860186614780565b6000818110612c3557612c35614708565b9050602002810190612c479190614a12565b606001355b9050612caa612c5e6040870187614780565b80806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250505050606087013585612ca560a08a0160808b016149f7565b61396d565b8114612cd35760405163755f0a2560e01b81526003600482015260248101839052604401610a7e565b6000612ce260e0870187614780565b90501115612d1a5760408051602080880135908201529081018390526060016040516020818303038152906040528051906020012091505b81612d258680614780565b6000818110612d3657612d36614708565b9050602002013514612d645760405163755f0a2560e01b815260048181015260248101839052604401610a7e565b5050505050565b6001546000908190819061010090046001600160a01b031663c81e25ab612d9560c0870187614a12565b602001356040518263ffffffff1660e01b8152600401612db791815260200190565b60c060405180830381865afa158015612dd4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612df89190614a28565b509396509194509250506001600160a01b0384169050612e5857612e1f60c0850185614a12565b602001356040517f2396d34e000000000000000000000000000000000000000000000000000000008152600401610a7e91815260200190565b6000612e7b612e6a60c0870187614a12565b6116039060608101906040016149f7565b90506000612e898484613adb565b9050808263ffffffff1610612ede57612ea560c0870187614a12565b602001356040517f1362e4a0000000000000000000000000000000000000000000000000000000008152600401610a7e91815260200190565b6000612f0d612ef060c0890189614a12565b612f019060608101906040016149f7565b60201c63ffffffff1690565b90506000612f1f886020013586613af6565b63ffffffff16905067ffffffffffffffff82168114612f7e57612f4560c0890189614a12565b602001356040517f6dd6a24f000000000000000000000000000000000000000000000000000000008152600401610a7e91815260200190565b61302487612f8f60c08b018b614a12565b612f999080614a96565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050505060208b0135612fdf60c08d018d614a12565b60200135612ff060c08e018e614a12565b6130019060608101906040016149f7565b61300e60c08f018f614a12565b61301f9060808101906060016149f7565b613b1d565b61306e5761303560c0890189614a12565b602001356040517fdb12fb9d000000000000000000000000000000000000000000000000000000008152600401610a7e91815260200190565b5050505050505050565b61308560e0820182614780565b90506000036130915750565b6131b26130a160e0830183614780565b60008181106130b2576130b2614708565b90506020028101906130c49190614a12565b6130d2906020810190614add565b6130df60e0840184614780565b60008181106130f0576130f0614708565b90506020028101906131029190614a12565b613110906020810190614a96565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152506131529250505060e0850185614780565b600081811061316357613163614708565b90506020028101906131759190614a12565b6040013561318660e0860186614780565b600081811061319757613197614708565b90506020028101906131a99190614a12565b60600135613bb4565b61321f576131c360e0820182614780565b60008181106131d4576131d4614708565b90506020028101906131e69190614a12565b606001356040517fd740df61000000000000000000000000000000000000000000000000000000008152600401610a7e91815260200190565b602081013561329e61323460e0840184614780565b600081811061324557613245614708565b90506020028101906132579190614a12565b6040013561326860e0850185614780565b600081811061327957613279614708565b905060200281019061328b9190614a12565b613299906020810190614add565b613c47565b14612277576132b060e0820182614780565b60008181106132c1576132c1614708565b90506020028101906132d39190614a12565b606001356040517f82f2469d000000000000000000000000000000000000000000000000000000008152600401610a7e91815260200190565b838510156133595781831061333457604051633d386eb360e11b815260040160405180910390fd5b80821061335457604051633588c6d360e11b815260040160405180910390fd5b612d64565b82821061337957604051633d386eb360e11b815260040160405180910390fd5b808310612d6457604051633588c6d360e11b815260040160405180910390fd5b6009548110612277576040517fb6052cdf00000000000000000000000000000000000000000000000000000000815260048101829052602401610a7e565b60606133e16119dc565b6133fe57604051633788c6c160e11b815260040160405180910390fd5b60006134086119cf565b60085490915067ffffffffffffffff808316600160401b909204161461344157604051636fbabc7760e01b815260040160405180910390fd5b60075460405160200161347c9181527f3100000000000000000000000000000000000000000000000000000000000000602082015260210190565b60405160208183030381529060405291505090565b60008060008060008060008060006134a7613c95565b60045490915060005b8181101561363957600481815481106134cb576134cb614708565b906000526020600020906005020160010160149054906101000a900460ff1615613631576004818154811061350257613502614708565b90600052602060002090600502016004015493506005848154811061352957613529614708565b906000526020600020906005020160030154896135469190614860565b9850828160405160200161355b929190614873565b60408051601f19818403018152919052805160209091012097506fffffffffffffffffffffffffffffffff8089169750613596906001614860565b600585815481106135a9576135a9614708565b9060005260206000209060050201600301546135c591906146a0565b6135cf8a896146a0565b101561363157600584815481106135e8576135e8614708565b90600052602060002090600502016004015495506005848154811061360f5761360f614708565b906000526020600020906005020160010160149054906101000a900460ff1694505b6001016134b0565b509399929850919650505050505050565b613652612397565b6001805460ff1916811790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258335b6040516001600160a01b03909116815260200160405180910390a1565b6000805b6004548110156137165783600482815481106136c0576136c0614708565b9060005260206000209060050201600001541480156137025750600481815481106136ed576136ed614708565b90600052602060002090600502016003015483145b1561370e579050610670565b6001016136a2565b506040517fd950091500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b613751613d1e565b6001805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa33613681565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610a91576137b381613d70565b6137be836020613d82565b6040516020016137cf929190614afa565b60408051601f198184030181529082905262461bcd60e51b8252610a7e91600401614b7b565b60008061380487878786613f47565b905082613909856000808267ffffffffffffffff1690506008817eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff16901b600882901c7eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff161790506010817dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff16901b601082901c7dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff161790506020817bffffffff00000000ffffffff00000000ffffffff00000000ffffffff16901b602082901c7bffffffff00000000ffffffff00000000ffffffff00000000ffffffff1617905080915050919050565b8260405160200161394b9392919092835260c09190911b77ffffffffffffffffffffffffffffffffffffffffffffffff19166020830152602882015260480190565b6040516020818303038152906040528051906020012091505095945050505050565b60008061397b868686613fbd565b9050613a7f836000808267ffffffffffffffff1690506008817eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff16901b600882901c7eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff161790506010817dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff16901b601082901c7dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff161790506020817bffffffff00000000ffffffff00000000ffffffff00000000ffffffff16901b602082901c7bffffffff00000000ffffffff00000000ffffffff00000000ffffffff1617905080915050919050565b81604051602001613aba92919060c09290921b77ffffffffffffffffffffffffffffffffffffffffffffffff19168252600882015260280190565b60405160208183030381529060405280519060200120915050949350505050565b6000613ae78284614687565b60ff166001901b905092915050565b600060e083901c613b08836020614687565b60ff168163ffffffff16901c91505092915050565b600080613b2c86868686614025565b90506000613b87826040517f19457468657265756d205369676e6564204d6573736167653a0a3332000000006020820152603c8101829052600090605c01604051602081830303815290604052805190602001209050919050565b9050886001600160a01b0316613b9d828a614070565b6001600160a01b0316149998505050505050505050565b600080613bc184846140ef565b90506000613c1c826040517f19457468657265756d205369676e6564204d6573736167653a0a3332000000006020820152603c8101829052600090605c01604051602081830303815290604052805190602001209050919050565b9050866001600160a01b0316613c328288614070565b6001600160a01b031614979650505050505050565b60008282604051602001613c7792919091825260601b6bffffffffffffffffffffffff1916602082015260340190565b60405160208183030381529060405280519060200120905092915050565b6060613c9f6119dc565b613cbc57604051633788c6c160e11b815260040160405180910390fd5b6000613cc66119cf565b60085490915067ffffffffffffffff808316600160401b9092041614613cff57604051636fbabc7760e01b815260040160405180910390fd5b60075460405160200161347c918152600360fc1b602082015260210190565b60015460ff166119cd5760405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f74207061757365640000000000000000000000006044820152606401610a7e565b60606106706001600160a01b03831660145b60606000613d918360026146a0565b613d9c906002614860565b67ffffffffffffffff811115613db457613db4614bae565b6040519080825280601f01601f191660200182016040528015613dde576020820181803683370190505b509050600360fc1b81600081518110613df957613df9614708565b60200101906001600160f81b031916908160001a9053507f780000000000000000000000000000000000000000000000000000000000000081600181518110613e4457613e44614708565b60200101906001600160f81b031916908160001a9053506000613e688460026146a0565b613e73906001614860565b90505b6001811115613ef8577f303132333435363738396162636465660000000000000000000000000000000085600f1660108110613eb457613eb4614708565b1a60f81b828281518110613eca57613eca614708565b60200101906001600160f81b031916908160001a90535060049490941c93613ef181614bc4565b9050613e76565b5083156122665760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610a7e565b8260005b8551811015613fb4576000613f616002866146e0565b15613f6d576000613f70565b60015b9050613f9783888481518110613f8857613f88614708565b6020026020010151838761410b565b9250600185901c9450508080613fac90614767565b915050613f4b565b50949350505050565b8160005b845181101561401d576000613fd76002856146e0565b600014905061400083878481518110613ff257613ff2614708565b60200260200101518361416b565b9250600184901c935050808061401590614767565b915050613fc1565b509392505050565b604080516020810186905290810184905277ffffffffffffffffffffffffffffffffffffffffffffffff1960c084811b8216606084015283901b166068820152600090607001612033565b60008060008061407f856141d2565b6040805160008152602081018083528b905260ff8316918101919091526060810184905260808101839052929550909350915060019060a0016020604051602081039080840390855afa1580156140da573d6000803e3d6000fd5b5050604051601f190151979650505050505050565b6040805160208101849052908101829052600090606001613c77565b6000821561414b5760408051602081018490529081018690526060810185905260800160405160208183030381529060405280519060200120905061204c565b604080516020810184905290810185905260608101869052608001612033565b600081156141a4576040805160208101869052908101849052606001604051602081830303815290604052805190602001209050612266565b5050604080516020808201939093528082019390935280518084038201815260609093019052815191012090565b60008060008351604114614212576040517f4be6321b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50505060208101516040820151606090920151909260009190911a90565b50805460008255600502906000526020600020908101906122779190614272565b508054600082556005029060005260206000209081019061227791906142c9565b5b808211156142c55760008082556001820180547fffffffffffffffffffff0000000000000000000000000000000000000000000016905560028201819055600382018190556004820155600501614273565b5090565b5b808211156142c557600080825560018201805474ffffffffffffffffffffffffffffffffffffffffff19169055600282018190556003820181905560048201556005016142ca565b60006020828403121561432457600080fd5b81356001600160e01b03198116811461226657600080fd5b6001600160a01b038116811461227757600080fd5b60ff8116811461227757600080fd5b6000806040838503121561437357600080fd5b823561437e8161433c565b9150602083013561438e81614351565b809150509250929050565b6000602082840312156143ab57600080fd5b5035919050565b6020808252825182820181905260009190848201906040850190845b8181101561443557614422838551805182526001600160a01b03602082015116602083015260ff6040820151166040830152606081015160608301526080810151608083015260a081015160a08301525050565b9284019260c092909201916001016143ce565b50909695505050505050565b6000806040838503121561445457600080fd5b82359150602083013561438e8161433c565b803567ffffffffffffffff8116811461447e57600080fd5b919050565b6000806040838503121561449657600080fd5b823591506144a660208401614466565b90509250929050565b600061010082840312156144c257600080fd5b50919050565b6000806000606084860312156144dd57600080fd5b833567ffffffffffffffff808211156144f557600080fd5b614501878388016144af565b9450602086013591508082111561451757600080fd5b614523878388016144af565b9350604086013591508082111561453957600080fd5b50614546868287016144af565b9150509250925092565b60008060006060848603121561456557600080fd5b833561457081614351565b95602085013595506040909401359392505050565b6000806000806080858703121561459b57600080fd5b8435935060208501356145ad81614351565b93969395505050506040820135916060013590565b6000806000606084860312156145d757600080fd5b83356145e281614351565b925060208401356145f281614351565b9150604084013561460281614351565b809150509250925092565b60008060006060848603121561462257600080fd5b8335925060208401359150604084013561460281614351565b60006020828403121561464d57600080fd5b5051919050565b60006020828403121561466657600080fd5b815161226681614351565b634e487b7160e01b600052601160045260246000fd5b60ff828116828216039081111561067057610670614671565b808202811582820484141761067057610670614671565b8181038181111561067057610670614671565b634e487b7160e01b600052601260045260246000fd5b6000826146ef576146ef6146ca565b500690565b600082614703576147036146ca565b500490565b634e487b7160e01b600052603260045260246000fd5b67ffffffffffffffff81811683821601908082111561473f5761473f614671565b5092915050565b67ffffffffffffffff82811682821603908082111561473f5761473f614671565b60006001820161477957614779614671565b5060010190565b6000808335601e1984360301811261479757600080fd5b83018035915067ffffffffffffffff8211156147b257600080fd5b6020019150600581901b36038213156147ca57600080fd5b9250929050565b60005b838110156147ec5781810151838201526020016147d4565b50506000910152565b600082516148078184602087016147d1565b9190910192915050565b60c081016106708284805182526001600160a01b03602082015116602083015260ff6040820151166040830152606081015160608301526080810151608083015260a081015160a08301525050565b8082018082111561067057610670614671565b600083516148858184602088016147d1565b9190910191825250602001919050565b600181815b808511156148d05781600019048211156148b6576148b6614671565b808516156148c357918102915b93841c939080029061489a565b509250929050565b6000826148e757506001610670565b816148f457506000610670565b816001811461490a576002811461491457614930565b6001915050610670565b60ff84111561492557614925614671565b50506001821b610670565b5060208310610133831016604e8410600b8410161715614953575081810a610670565b61495d8383614895565b806000190482111561497157614971614671565b029392505050565b600061226660ff8416836148d8565b60ff818116838216019081111561067057610670614671565b61ffff82811682821603908082111561473f5761473f614671565b600061226661ffff8416836148d8565b8051801515811461447e57600080fd5b6000602082840312156149ee57600080fd5b612266826149cc565b600060208284031215614a0957600080fd5b61226682614466565b60008235607e1983360301811261480757600080fd5b60008060008060008060c08789031215614a4157600080fd5b8651614a4c8161433c565b6020880151909650614a5d81614351565b6040880151909550614a6e81614351565b9350614a7c606088016149cc565b92506080870151915060a087015190509295509295509295565b6000808335601e19843603018112614aad57600080fd5b83018035915067ffffffffffffffff821115614ac857600080fd5b6020019150368190038213156147ca57600080fd5b600060208284031215614aef57600080fd5b81356122668161433c565b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000815260008351614b328160178501602088016147d1565b7f206973206d697373696e6720726f6c65200000000000000000000000000000006017918401918201528351614b6f8160288401602088016147d1565b01602801949350505050565b6020815260008251806020840152614b9a8160408501602087016147d1565b601f01601f19169190910160400192915050565b634e487b7160e01b600052604160045260246000fd5b600081614bd357614bd3614671565b50600019019056fea2646970667358221220bfb91c91c1b7acac1e1e0c04feef5d4b5547a65013c587ca7b8653505ea7ffe564736f6c63430008130033", + "deployedBytecode": "0x608060405234801561001057600080fd5b50600436106102775760003560e01c806377c75d1011610160578063b6cd5822116100d8578063dfbf53ae1161008c578063f69ee1d111610071578063f69ee1d1146105df578063f7b188a5146105f2578063fb00f2f3146105fa57600080fd5b8063dfbf53ae1461059c578063f4e6fcca146105cc57600080fd5b8063ce987745116100bd578063ce9877451461056e578063d1e8b63d14610581578063d547741f1461058957600080fd5b8063b6cd582214610541578063c46b40291461055457600080fd5b80638456cb591161012f5780638d8b6428116101145780638d8b6428146104fa57806391d1485414610502578063a217fddf1461053957600080fd5b80638456cb59146104ea5780638a19c8bc146104f257600080fd5b806377c75d10146104645780637fe019c61461047757806382b39b1b1461049257806383220626146104e257600080fd5b80635c975abb116101f357806364c34a85116101c257806369da9114116101a757806369da9114146103de5780636f94aaf2146103f157806372286cba1461040c57600080fd5b806364c34a85146103a957806369bfac01146103b157600080fd5b80635c975abb146103705780635d4844ea1461037b57806362fd29ae1461038e57806363f5cf7c1461039657600080fd5b80632a4e62491161024a5780632f3906da1161022f5780632f3906da1461034257806336568abe1461034a5780635838d6731461035d57600080fd5b80632a4e6249146103185780632f2ff15d1461032d57600080fd5b806301ffc9a71461027c5780631736d472146102a457806318350096146102b7578063248a9ca3146102e7575b600080fd5b61028f61028a366004614312565b61060d565b60405190151581526020015b60405180910390f35b61028f6102b2366004614360565b610676565b6001546102cf9061010090046001600160a01b031681565b6040516001600160a01b03909116815260200161029b565b61030a6102f5366004614399565b60009081526020819052604090206001015490565b60405190815260200161029b565b610320610883565b60405161029b91906143b2565b61034061033b366004614441565b610990565b005b61028f6109ba565b610340610358366004614441565b610a04565b61034061036b366004614483565b610a95565b60015460ff1661028f565b6003546102cf906001600160a01b031681565b61030a611025565b6103406103a43660046144c8565b6110f1565b61030a611526565b6008546103c59067ffffffffffffffff1681565b60405167ffffffffffffffff909116815260200161029b565b6002546102cf906001600160a01b031681565b6008546103c590600160801b900467ffffffffffffffff1681565b61041f61041a366004614399565b611606565b604080519788526001600160a01b0390961660208801529315159486019490945260ff9091166060850152608084015260a083019190915260c082015260e00161029b565b61028f610472366004614399565b611664565b6008546103c590600160401b900467ffffffffffffffff1681565b6104a56104a0366004614399565b611914565b604080519687526001600160a01b03909516602087015260ff909316938501939093526060840152608083019190915260a082015260c00161029b565b61030a61196b565b610340611976565b6103c56119cf565b61028f6119dc565b61028f610510366004614441565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b61030a600081565b61034061054f366004614550565b611a06565b61055c611f60565b60405160ff909116815260200161029b565b61030a61057c366004614585565b611fe5565b61028f612054565b610340610597366004614441565b612079565b600a54600b54600c54600d54600e546104a594936001600160a01b03811693600160a01b90910460ff1692909186565b6103406105da3660046145c2565b61209e565b6103406105ed366004614399565b612185565b6103406121d9565b61028f61060836600461460d565b612230565b60006001600160e01b031982167f7965db0b00000000000000000000000000000000000000000000000000000000148061067057507f01ffc9a7000000000000000000000000000000000000000000000000000000006001600160e01b03198316145b92915050565b60035460405163d1052d1f60e01b81526001600160a01b038481166004830152600092839291169063d1052d1f90602401602060405180830381865afa1580156106c4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106e8919061463b565b600354604051631d54805360e01b81526001600160a01b03878116600483015292935060009290911690631d54805390602401602060405180830381865afa158015610738573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061075c9190614654565b6107669085614687565b90506107706109ba565b156107a7576040517fe2586bcc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b816000036107c7576040516273e5c360e31b815260040160405180910390fd5b6107d3609860026146a0565b6107dd90436146b7565b82106107fc57604051630a0744c560e01b815260040160405180910390fd5b6003546040516397adedb560e01b81526001600160a01b03878116600483015261087a9216906397adedb590602401602060405180830381865afa158015610848573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061086c919061463b565b610874611526565b83612230565b95945050505050565b606061088d6119dc565b6108aa57604051633788c6c160e11b815260040160405180910390fd5b60006108b46119cf565b60085490915067ffffffffffffffff808316600160401b90920416146108ed57604051636fbabc7760e01b815260040160405180910390fd5b6005805480602002602001604051908101604052809291908181526020016000905b828210156109865760008481526020908190206040805160c08101825260058602909201805483526001808201546001600160a01b03811685870152600160a01b900460ff169284019290925260028101546060840152600381015460808401526004015460a0830152908352909201910161090f565b5050505091505090565b6000828152602081905260409020600101546109ab8161226d565b6109b5838361227a565b505050565b6000806109c86098436146e0565b90506109d6600460986146f4565b81101580156109ef57506109ec600260986146f4565b81105b156109fc57600191505090565b600091505090565b6001600160a01b0381163314610a875760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b610a918282612318565b5050565b610a9d612397565b6000610aa76119cf565b6003546040516397adedb560e01b81523360048201529192506000916001600160a01b03909116906397adedb590602401602060405180830381865afa158015610af5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b19919061463b565b6003546040517f830a053e0000000000000000000000000000000000000000000000000000000081523360048201529192506000916001600160a01b039091169063830a053e90602401602060405180830381865afa158015610b80573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ba4919061463b565b60035460405163d1052d1f60e01b81523360048201529192506000916001600160a01b039091169063d1052d1f90602401602060405180830381865afa158015610bf2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c16919061463b565b600354604051631d54805360e01b81523360048201529192506000916001600160a01b0390911690631d54805390602401602060405180830381865afa158015610c64573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c889190614654565b9050610c92612054565b610cc8576040517fdc816a8700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001610cd6600460986146f4565b610ce091906146b7565b610ceb6098436146e0565b03610d22576040517f5baef6b600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8567ffffffffffffffff168567ffffffffffffffff161115610d70576040517f50ff7c0000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8567ffffffffffffffff168567ffffffffffffffff161015610dbe576040517f7a0c0fd600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b81600003610dde576040516273e5c360e31b815260040160405180910390fd5b610dea609860026146a0565b610df490436146b7565b8210610e1357604051630a0744c560e01b815260040160405180910390fd5b60085467ffffffffffffffff868116911614610e5357610e3560046000614230565b6008805467ffffffffffffffff191667ffffffffffffffff87161790555b60045460005b81811015610ec6578560048281548110610e7557610e75614708565b90600052602060002090600502016000015403610ebe576040517fbfec555800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600101610e59565b5060046040518060e00160405280878152602001336001600160a01b031681526020016000151581526020018460ff1681526020018681526020018a8152602001600081525090806001815401808255809150506001900390600052602060002090600502016000909190919091506000820151816000015560208201518160010160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555060408201518160010160146101000a81548160ff02191690831515021790555060608201518160010160156101000a81548160ff021916908360ff1602179055506080820151816002015560a0820151816003015560c0820151816004015550507f68e0867601a98978930107aee7f425665e61edd70ca594c68ca5da9e81f84c29878660405161101392919067ffffffffffffffff929092168252602082015260400190565b60405180910390a15050505050505050565b6000806110306119cf565b61103b90600161471e565b6007546008549192509061106190600160401b900467ffffffffffffffff16600161471e565b67ffffffffffffffff168267ffffffffffffffff161115610670576008546000906001906110a090600160401b900467ffffffffffffffff1685614746565b6110aa9190614746565b67ffffffffffffffff16905081816040516020016110d2929190918252602082015260400190565b6040516020818303038152906040528051906020012091505092915050565b6110f9612397565b6111016123ea565b6040805160c081018252600a548152600b546001600160a01b0381166020830152600160a01b900460ff1691810191909152600c546060820152600d546080820152600e5460a08201526006546007546000918291611161600f826146e0565b935061116e600e826146e0565b9250838310611185578261118181614767565b9350505b6111988660200135838760400151612230565b6111b857604051633b5f43a360e01b815260036004820152602401610a7e565b6111c386601e612a59565b6111cc86612d6b565b6111d586613078565b6111e88860200135838760400151612230565b61120857604051633b5f43a360e01b815260026004820152602401610a7e565b61121c886112178660026146a0565b612a59565b61122588612d6b565b61122e88613078565b6112418760200135838760400151612230565b61126157604051633b5f43a360e01b815260016004820152602401610a7e565b611270876112178560026146a0565b61127987612d6b565b61128287613078565b6112f884846112918b80614780565b60008181106112a2576112a2614708565b602002919091013590506112b68b80614780565b60008181106112c7576112c7614708565b602002919091013590506112db8b80614780565b60008181106112ec576112ec614708565b9050602002013561330c565b6113226113058780614780565b600081811061131657611316614708565b90506020020135613399565b60015460208601516040516001600160a01b03918216602482015260009261010090049091169060440160408051601f198184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f51cff8d900000000000000000000000000000000000000000000000000000000179052516113af91906147f5565b6000604051808303816000865af19150503d80600081146113ec576040519150601f19603f3d011682016040523d82523d6000602084013e6113f1565b606091505b505090508061143c576020808701516040516001600160a01b0390911681527f7ae187a0c04cf55b655ca83fa11d37854c882bf1fdcb588469b414731bb0e05a910160405180910390a15b7f788e77979e6e6a8a6a5d2c19c58b1ff9671298f54c85ac6f6aa30379aed5861a8660405161146b9190614811565b60405180910390a17fbee3fc8a3523c1a65fa9308ce1f2b8fd90c24975b141b754603194597846e4dd60018054906101000a90046001600160a01b03166001600160a01b0316638a5e8e326040518163ffffffff1660e01b8152600401602060405180830381865afa1580156114e5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611509919061463b565b6040519081526020015b60405180910390a1505050505050505050565b6000611530612054565b8061156e5750600854600160401b900467ffffffffffffffff166115526119cf565b67ffffffffffffffff1611801561156e575061156c6119dc565b155b156115805761157b61196b565b905090565b6115886119dc565b156115955761157b611025565b61159d6109ba565b80156115cc5750600854600160401b900467ffffffffffffffff166115c06119cf565b67ffffffffffffffff16145b15611603576040517f36b7884b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b90565b6004818154811061161657600080fd5b6000918252602090912060059091020180546001820154600283015460038401546004909401549294506001600160a01b0382169360ff600160a01b8404811694600160a81b909404169287565b600061166e6119dc565b61168b57604051633788c6c160e11b815260040160405180910390fd5b60006116956119cf565b60085490915067ffffffffffffffff808316600160401b90920416146116ce57604051636fbabc7760e01b815260040160405180910390fd5b60085467ffffffffffffffff600160801b90910481169082161161170557604051630c8d9eab60e31b815260040160405180910390fd5b6000806000806000806000806117196133d7565b90506000611725613491565b600454919650945060005b81811015611900576004818154811061174b5761174b614708565b90600052602060002090600502016004015494506004818154811061177257611772614708565b906000526020600020906005020160010160149054906101000a900460ff1680156117c05750600585815481106117ab576117ab614708565b90600052602060002090600502016004015487145b80156117fe5750600585815481106117da576117da614708565b600091825260209091206001600590920201015460ff878116600160a01b90920416145b156118f8576005858154811061181657611816614708565b9060005260206000209060050201600301548b6118339190614860565b9a508383604051602001611848929190614873565b60408051601f19818403018152919052805160209091012098506fffffffffffffffffffffffffffffffff808a169850611883906001614860565b6005868154811061189657611896614708565b9060005260206000209060050201600301546118b291906146a0565b6118bc8c8a6146a0565b10156118ea57600585815481106118d5576118d5614708565b90600052602060002090600502016000015499505b826118f481614767565b9350505b600101611730565b505050959099149998505050505050505050565b6005818154811061192457600080fd5b6000918252602090912060059091020180546001820154600283015460038401546004909401549294506001600160a01b03821693600160a01b90920460ff169290919086565b60008061103b6119cf565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff166119c557604051631d77d47760e21b815260040160405180910390fd5b6119cd61364a565b565b600061157b6098436146f4565b60006119ea600260986146f4565b6119f56098436146e0565b10611a005750600190565b50600090565b611a0e612397565b6000611a186119cf565b6003546040516397adedb560e01b81523360048201529192506000916001600160a01b03909116906397adedb590602401602060405180830381865afa158015611a66573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a8a919061463b565b9050611a94611f60565b60ff168560ff161015611ad3576040517f83d9b7bd00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611adb6109ba565b611b11576040517fd1088db600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60085467ffffffffffffffff838116911614611b59576040517f842a9e0a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60085467ffffffffffffffff838116600160401b9092041614611c4157611b7e611526565b600655611b8d60056000614251565b600880547fffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff16600160401b67ffffffffffffffff8516908102919091179091556006546040805192835260208301919091527ff0ae472da9c8da86bda4991a549c03a3cb328b5f360ea11a5b8814f32bb85176910160405180910390a1611c41600754604080516020810192909252449082015260600160408051601f198184030181529190528051602090910120600755565b6000611c4f82878787611fe5565b90506000611c5d838361369e565b9050600060048281548110611c7457611c74614708565b600091825260208083206040805160e08101825260059094029091018054845260018101546001600160a01b0381169385019390935260ff600160a01b84048116151592850192909252600160a81b909204166060830181905260028201546080840152600382015460a084015260049091015460c0830152909250611cfa908a614687565b9050611d0d826000015160065483612230565b611d49576006546040517f14ebbbe4000000000000000000000000000000000000000000000000000000008152600401610a7e91815260200190565b816040015115611d85576040517fa89ac15100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600160048481548110611d9a57611d9a614708565b906000526020600020906005020160010160146101000a81548160ff02191690831515021790555060058054905060048481548110611ddb57611ddb614708565b90600052602060002090600502016004018190555060056040518060c001604052808460000151815260200184602001516001600160a01b031681526020018b60ff16815260200184608001518152602001836002611e3a9190614979565b8560800151611e4991906146a0565b815260209081018b90528254600181810185556000948552938290208351600590920201908155908201519281018054604084015160ff16600160a01b0274ffffffffffffffffffffffffffffffffffffffffff199091166001600160a01b0390951694909417939093179092556060810151600280840191909155608080830151600385015560a0909201516004909301929092558351908401517f13fc17fd71632266fe82092de6dd91a06b4fa68d8dc950492e5421cbed55a6a59289929190611f16908690614979565b8660800151611f2591906146a0565b6040805167ffffffffffffffff90951685526020850193909352918301526060820152608081018a905260ff8b1660a082015260c001611513565b6008546000908190611f859067ffffffffffffffff600160801b820481169116614746565b67ffffffffffffffff169050600060fe8211611fa15781611fa4565b60fe5b611faf906001614988565b600b5490915060ff600160a01b9091048116908216811115611fda57611fd58282614687565b611fdd565b60005b935050505090565b60408051602081018690527fff0000000000000000000000000000000000000000000000000000000000000060f886901b169181019190915260418101839052606181018290526000906081015b6040516020818303038152906040528051906020012090505b949350505050565b6000612062600460986146f4565b61206d6098436146e0565b1015611a005750600190565b6000828152602081905260409020600101546120948161226d565b6109b58383612318565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff166120ed57604051637bfa4b9f60e01b815260040160405180910390fd5b600880547fffffffffffff0000ffffffffffffffffffffffffffffffffffffffffffffffff16600160c01b60ff958616027fffffffffffff00ffffffffffffffffffffffffffffffffffffffffffffffffff1617600160c81b93851693909302929092177fffffffffff00ffffffffffffffffffffffffffffffffffffffffffffffffffff16600160d01b9190931602919091179055565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff166121d457604051637bfa4b9f60e01b815260040160405180910390fd5b600955565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff1661222857604051631d77d47760e21b815260040160405180910390fd5b6119cd613749565b60008160ff1660000361224557506001612266565b61225460ff83166101006149a1565b61225f9060026149bc565b8484181090505b9392505050565b6122778133613782565b50565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610a91576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556122d43390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1615610a91576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b60015460ff16156119cd5760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a20706175736564000000000000000000000000000000006044820152606401610a7e565b60006123f46119cf565b90506123fe6119dc565b61241b57604051633788c6c160e11b815260040160405180910390fd5b60085467ffffffffffffffff828116600160401b909204161461245157604051636fbabc7760e01b815260040160405180910390fd5b60085467ffffffffffffffff600160801b90910481169082161161248857604051630c8d9eab60e31b815260040160405180910390fd5b600454604051818152600091829182918291829182917f6752c5e71c95fb93bc7137adeb115a33fa4e54e2683e33d3f90c2bb1c4b6c2a59060200160405180910390a16005546040519081527f4c03de6a759749c0c9387b7014634dc5c6af610e1366023d90751c783a998f8d9060200160405180910390a1612509613491565b6040805183815260ff831660208201529295509093507f34e8eda4cd857cd2865becf58a47748f31415f4a382cbb2cc0c64b9a27c717be910160405180910390a160006125546133d7565b905060005b828110156129415760006004828154811061257657612576614708565b600091825260208083206040805160e08101825260059485029092018054835260018101546001600160a01b0381169484019490945260ff600160a01b85048116151592840192909252600160a81b90930416606082015260028201546080820152600382015460a082015260049091015460c0820181905282549194509291908390811061260757612607614708565b60009182526020918290206040805160c0810182526005939093029091018054835260018101546001600160a01b03811694840194909452600160a01b90930460ff1682820152600283015460608301526003830154608083015260049092015460a082015290840151909150801561268357508060a0015188145b80156126985750806040015160ff168760ff16145b1561278d5760808101516126ac908d614860565b9b50848b6040516020016126c1929190614873565b60408051601f19818403018152919052805160209091012099506fffffffffffffffffffffffffffffffff808b1699506126fc906001614860565b816080015161270b91906146a0565b6127158d8b6146a0565b101561277f578051600a556020810151600b8054604084015160ff16600160a01b0274ffffffffffffffffffffffffffffffffffffffffff199091166001600160a01b03909316929092179190911790556060810151600c556080810151600d5560a0810151600e555b8a61278981614767565b9b50505b826040015180156127b657508060a00151881415806127b65750806040015160ff168760ff1614155b80156127d75750600854600160d01b900460ff166127d56064446146e0565b105b156128835760035460208201516001600160a01b039091169063d009b2d6906128018a6002614979565b60085461281a90609890600160c01b900460ff166146a0565b61282491906146a0565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401600060405180830381600087803b15801561286a57600080fd5b505af115801561287e573d6000803e3d6000fd5b505050505b82604001516129335760035460208401516001600160a01b039091169063d009b2d6906128b18a6002614979565b6008546128ca90609890600160c81b900460ff166146a0565b6128d491906146a0565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401600060405180830381600087803b15801561291a57600080fd5b505af115801561292e573d6000803e3d6000fd5b505050505b836001019350505050612559565b506002546040517fffb98fe300000000000000000000000000000000000000000000000000000000815261ffff891660048201526000916001600160a01b03169063ffb98fe3906024016020604051808303816000875af11580156129aa573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129ce91906149dc565b905080612a0d5760405161ffff891681527f20378e5d379eabfa30444ecc5eb2b87d0d77bdbf5a58d80d008673b0ca6421419060200160405180910390a15b50506008805467ffffffffffffffff909916600160801b027fffffffffffffffff0000000000000000ffffffffffffffffffffffffffffffff9099169890981790975550505050505050565b600754600090612a6b906080906146e0565b90506000612ace612a7f60a0860186614780565b80806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250505050606086013584612ac660a0890160808a016149f7565b6006546137f5565b60408051858152602081018390529192507f94e252069a85aa79db21f5bd8ca4e14dd3a3927aa492711017a2c8ddad95af00910160405180910390a1612b56612b178580614780565b8080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525050505060208601358561040061396d565b600e5414612b815760405163755f0a2560e01b81526001600482015260248101829052604401610a7e565b612b8e60a0850185614780565b6000818110612b9f57612b9f614708565b90506020020135848060400190612bb69190614780565b6000818110612bc757612bc7614708565b9050602002013514612bf65760405163755f0a2560e01b81526002600482015260248101829052604401610a7e565b600080612c0660e0870187614780565b905011612c17578460200135612c4c565b612c2460e0860186614780565b6000818110612c3557612c35614708565b9050602002810190612c479190614a12565b606001355b9050612caa612c5e6040870187614780565b80806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250505050606087013585612ca560a08a0160808b016149f7565b61396d565b8114612cd35760405163755f0a2560e01b81526003600482015260248101839052604401610a7e565b6000612ce260e0870187614780565b90501115612d1a5760408051602080880135908201529081018390526060016040516020818303038152906040528051906020012091505b81612d258680614780565b6000818110612d3657612d36614708565b9050602002013514612d645760405163755f0a2560e01b815260048181015260248101839052604401610a7e565b5050505050565b6001546000908190819061010090046001600160a01b031663c81e25ab612d9560c0870187614a12565b602001356040518263ffffffff1660e01b8152600401612db791815260200190565b60c060405180830381865afa158015612dd4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612df89190614a28565b509396509194509250506001600160a01b0384169050612e5857612e1f60c0850185614a12565b602001356040517f2396d34e000000000000000000000000000000000000000000000000000000008152600401610a7e91815260200190565b6000612e7b612e6a60c0870187614a12565b6116039060608101906040016149f7565b90506000612e898484613adb565b9050808263ffffffff1610612ede57612ea560c0870187614a12565b602001356040517f1362e4a0000000000000000000000000000000000000000000000000000000008152600401610a7e91815260200190565b6000612f0d612ef060c0890189614a12565b612f019060608101906040016149f7565b60201c63ffffffff1690565b90506000612f1f886020013586613af6565b63ffffffff16905067ffffffffffffffff82168114612f7e57612f4560c0890189614a12565b602001356040517f6dd6a24f000000000000000000000000000000000000000000000000000000008152600401610a7e91815260200190565b61302487612f8f60c08b018b614a12565b612f999080614a96565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050505060208b0135612fdf60c08d018d614a12565b60200135612ff060c08e018e614a12565b6130019060608101906040016149f7565b61300e60c08f018f614a12565b61301f9060808101906060016149f7565b613b1d565b61306e5761303560c0890189614a12565b602001356040517fdb12fb9d000000000000000000000000000000000000000000000000000000008152600401610a7e91815260200190565b5050505050505050565b61308560e0820182614780565b90506000036130915750565b6131b26130a160e0830183614780565b60008181106130b2576130b2614708565b90506020028101906130c49190614a12565b6130d2906020810190614add565b6130df60e0840184614780565b60008181106130f0576130f0614708565b90506020028101906131029190614a12565b613110906020810190614a96565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152506131529250505060e0850185614780565b600081811061316357613163614708565b90506020028101906131759190614a12565b6040013561318660e0860186614780565b600081811061319757613197614708565b90506020028101906131a99190614a12565b60600135613bb4565b61321f576131c360e0820182614780565b60008181106131d4576131d4614708565b90506020028101906131e69190614a12565b606001356040517fd740df61000000000000000000000000000000000000000000000000000000008152600401610a7e91815260200190565b602081013561329e61323460e0840184614780565b600081811061324557613245614708565b90506020028101906132579190614a12565b6040013561326860e0850185614780565b600081811061327957613279614708565b905060200281019061328b9190614a12565b613299906020810190614add565b613c47565b14612277576132b060e0820182614780565b60008181106132c1576132c1614708565b90506020028101906132d39190614a12565b606001356040517f82f2469d000000000000000000000000000000000000000000000000000000008152600401610a7e91815260200190565b838510156133595781831061333457604051633d386eb360e11b815260040160405180910390fd5b80821061335457604051633588c6d360e11b815260040160405180910390fd5b612d64565b82821061337957604051633d386eb360e11b815260040160405180910390fd5b808310612d6457604051633588c6d360e11b815260040160405180910390fd5b6009548110612277576040517fb6052cdf00000000000000000000000000000000000000000000000000000000815260048101829052602401610a7e565b60606133e16119dc565b6133fe57604051633788c6c160e11b815260040160405180910390fd5b60006134086119cf565b60085490915067ffffffffffffffff808316600160401b909204161461344157604051636fbabc7760e01b815260040160405180910390fd5b60075460405160200161347c9181527f3100000000000000000000000000000000000000000000000000000000000000602082015260210190565b60405160208183030381529060405291505090565b60008060008060008060008060006134a7613c95565b60045490915060005b8181101561363957600481815481106134cb576134cb614708565b906000526020600020906005020160010160149054906101000a900460ff1615613631576004818154811061350257613502614708565b90600052602060002090600502016004015493506005848154811061352957613529614708565b906000526020600020906005020160030154896135469190614860565b9850828160405160200161355b929190614873565b60408051601f19818403018152919052805160209091012097506fffffffffffffffffffffffffffffffff8089169750613596906001614860565b600585815481106135a9576135a9614708565b9060005260206000209060050201600301546135c591906146a0565b6135cf8a896146a0565b101561363157600584815481106135e8576135e8614708565b90600052602060002090600502016004015495506005848154811061360f5761360f614708565b906000526020600020906005020160010160149054906101000a900460ff1694505b6001016134b0565b509399929850919650505050505050565b613652612397565b6001805460ff1916811790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258335b6040516001600160a01b03909116815260200160405180910390a1565b6000805b6004548110156137165783600482815481106136c0576136c0614708565b9060005260206000209060050201600001541480156137025750600481815481106136ed576136ed614708565b90600052602060002090600502016003015483145b1561370e579050610670565b6001016136a2565b506040517fd950091500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b613751613d1e565b6001805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa33613681565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610a91576137b381613d70565b6137be836020613d82565b6040516020016137cf929190614afa565b60408051601f198184030181529082905262461bcd60e51b8252610a7e91600401614b7b565b60008061380487878786613f47565b905082613909856000808267ffffffffffffffff1690506008817eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff16901b600882901c7eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff161790506010817dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff16901b601082901c7dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff161790506020817bffffffff00000000ffffffff00000000ffffffff00000000ffffffff16901b602082901c7bffffffff00000000ffffffff00000000ffffffff00000000ffffffff1617905080915050919050565b8260405160200161394b9392919092835260c09190911b77ffffffffffffffffffffffffffffffffffffffffffffffff19166020830152602882015260480190565b6040516020818303038152906040528051906020012091505095945050505050565b60008061397b868686613fbd565b9050613a7f836000808267ffffffffffffffff1690506008817eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff16901b600882901c7eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff161790506010817dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff16901b601082901c7dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff161790506020817bffffffff00000000ffffffff00000000ffffffff00000000ffffffff16901b602082901c7bffffffff00000000ffffffff00000000ffffffff00000000ffffffff1617905080915050919050565b81604051602001613aba92919060c09290921b77ffffffffffffffffffffffffffffffffffffffffffffffff19168252600882015260280190565b60405160208183030381529060405280519060200120915050949350505050565b6000613ae78284614687565b60ff166001901b905092915050565b600060e083901c613b08836020614687565b60ff168163ffffffff16901c91505092915050565b600080613b2c86868686614025565b90506000613b87826040517f19457468657265756d205369676e6564204d6573736167653a0a3332000000006020820152603c8101829052600090605c01604051602081830303815290604052805190602001209050919050565b9050886001600160a01b0316613b9d828a614070565b6001600160a01b0316149998505050505050505050565b600080613bc184846140ef565b90506000613c1c826040517f19457468657265756d205369676e6564204d6573736167653a0a3332000000006020820152603c8101829052600090605c01604051602081830303815290604052805190602001209050919050565b9050866001600160a01b0316613c328288614070565b6001600160a01b031614979650505050505050565b60008282604051602001613c7792919091825260601b6bffffffffffffffffffffffff1916602082015260340190565b60405160208183030381529060405280519060200120905092915050565b6060613c9f6119dc565b613cbc57604051633788c6c160e11b815260040160405180910390fd5b6000613cc66119cf565b60085490915067ffffffffffffffff808316600160401b9092041614613cff57604051636fbabc7760e01b815260040160405180910390fd5b60075460405160200161347c918152600360fc1b602082015260210190565b60015460ff166119cd5760405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f74207061757365640000000000000000000000006044820152606401610a7e565b60606106706001600160a01b03831660145b60606000613d918360026146a0565b613d9c906002614860565b67ffffffffffffffff811115613db457613db4614bae565b6040519080825280601f01601f191660200182016040528015613dde576020820181803683370190505b509050600360fc1b81600081518110613df957613df9614708565b60200101906001600160f81b031916908160001a9053507f780000000000000000000000000000000000000000000000000000000000000081600181518110613e4457613e44614708565b60200101906001600160f81b031916908160001a9053506000613e688460026146a0565b613e73906001614860565b90505b6001811115613ef8577f303132333435363738396162636465660000000000000000000000000000000085600f1660108110613eb457613eb4614708565b1a60f81b828281518110613eca57613eca614708565b60200101906001600160f81b031916908160001a90535060049490941c93613ef181614bc4565b9050613e76565b5083156122665760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610a7e565b8260005b8551811015613fb4576000613f616002866146e0565b15613f6d576000613f70565b60015b9050613f9783888481518110613f8857613f88614708565b6020026020010151838761410b565b9250600185901c9450508080613fac90614767565b915050613f4b565b50949350505050565b8160005b845181101561401d576000613fd76002856146e0565b600014905061400083878481518110613ff257613ff2614708565b60200260200101518361416b565b9250600184901c935050808061401590614767565b915050613fc1565b509392505050565b604080516020810186905290810184905277ffffffffffffffffffffffffffffffffffffffffffffffff1960c084811b8216606084015283901b166068820152600090607001612033565b60008060008061407f856141d2565b6040805160008152602081018083528b905260ff8316918101919091526060810184905260808101839052929550909350915060019060a0016020604051602081039080840390855afa1580156140da573d6000803e3d6000fd5b5050604051601f190151979650505050505050565b6040805160208101849052908101829052600090606001613c77565b6000821561414b5760408051602081018490529081018690526060810185905260800160405160208183030381529060405280519060200120905061204c565b604080516020810184905290810185905260608101869052608001612033565b600081156141a4576040805160208101869052908101849052606001604051602081830303815290604052805190602001209050612266565b5050604080516020808201939093528082019390935280518084038201815260609093019052815191012090565b60008060008351604114614212576040517f4be6321b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50505060208101516040820151606090920151909260009190911a90565b50805460008255600502906000526020600020908101906122779190614272565b508054600082556005029060005260206000209081019061227791906142c9565b5b808211156142c55760008082556001820180547fffffffffffffffffffff0000000000000000000000000000000000000000000016905560028201819055600382018190556004820155600501614273565b5090565b5b808211156142c557600080825560018201805474ffffffffffffffffffffffffffffffffffffffffff19169055600282018190556003820181905560048201556005016142ca565b60006020828403121561432457600080fd5b81356001600160e01b03198116811461226657600080fd5b6001600160a01b038116811461227757600080fd5b60ff8116811461227757600080fd5b6000806040838503121561437357600080fd5b823561437e8161433c565b9150602083013561438e81614351565b809150509250929050565b6000602082840312156143ab57600080fd5b5035919050565b6020808252825182820181905260009190848201906040850190845b8181101561443557614422838551805182526001600160a01b03602082015116602083015260ff6040820151166040830152606081015160608301526080810151608083015260a081015160a08301525050565b9284019260c092909201916001016143ce565b50909695505050505050565b6000806040838503121561445457600080fd5b82359150602083013561438e8161433c565b803567ffffffffffffffff8116811461447e57600080fd5b919050565b6000806040838503121561449657600080fd5b823591506144a660208401614466565b90509250929050565b600061010082840312156144c257600080fd5b50919050565b6000806000606084860312156144dd57600080fd5b833567ffffffffffffffff808211156144f557600080fd5b614501878388016144af565b9450602086013591508082111561451757600080fd5b614523878388016144af565b9350604086013591508082111561453957600080fd5b50614546868287016144af565b9150509250925092565b60008060006060848603121561456557600080fd5b833561457081614351565b95602085013595506040909401359392505050565b6000806000806080858703121561459b57600080fd5b8435935060208501356145ad81614351565b93969395505050506040820135916060013590565b6000806000606084860312156145d757600080fd5b83356145e281614351565b925060208401356145f281614351565b9150604084013561460281614351565b809150509250925092565b60008060006060848603121561462257600080fd5b8335925060208401359150604084013561460281614351565b60006020828403121561464d57600080fd5b5051919050565b60006020828403121561466657600080fd5b815161226681614351565b634e487b7160e01b600052601160045260246000fd5b60ff828116828216039081111561067057610670614671565b808202811582820484141761067057610670614671565b8181038181111561067057610670614671565b634e487b7160e01b600052601260045260246000fd5b6000826146ef576146ef6146ca565b500690565b600082614703576147036146ca565b500490565b634e487b7160e01b600052603260045260246000fd5b67ffffffffffffffff81811683821601908082111561473f5761473f614671565b5092915050565b67ffffffffffffffff82811682821603908082111561473f5761473f614671565b60006001820161477957614779614671565b5060010190565b6000808335601e1984360301811261479757600080fd5b83018035915067ffffffffffffffff8211156147b257600080fd5b6020019150600581901b36038213156147ca57600080fd5b9250929050565b60005b838110156147ec5781810151838201526020016147d4565b50506000910152565b600082516148078184602087016147d1565b9190910192915050565b60c081016106708284805182526001600160a01b03602082015116602083015260ff6040820151166040830152606081015160608301526080810151608083015260a081015160a08301525050565b8082018082111561067057610670614671565b600083516148858184602088016147d1565b9190910191825250602001919050565b600181815b808511156148d05781600019048211156148b6576148b6614671565b808516156148c357918102915b93841c939080029061489a565b509250929050565b6000826148e757506001610670565b816148f457506000610670565b816001811461490a576002811461491457614930565b6001915050610670565b60ff84111561492557614925614671565b50506001821b610670565b5060208310610133831016604e8410600b8410161715614953575081810a610670565b61495d8383614895565b806000190482111561497157614971614671565b029392505050565b600061226660ff8416836148d8565b60ff818116838216019081111561067057610670614671565b61ffff82811682821603908082111561473f5761473f614671565b600061226661ffff8416836148d8565b8051801515811461447e57600080fd5b6000602082840312156149ee57600080fd5b612266826149cc565b600060208284031215614a0957600080fd5b61226682614466565b60008235607e1983360301811261480757600080fd5b60008060008060008060c08789031215614a4157600080fd5b8651614a4c8161433c565b6020880151909650614a5d81614351565b6040880151909550614a6e81614351565b9350614a7c606088016149cc565b92506080870151915060a087015190509295509295509295565b6000808335601e19843603018112614aad57600080fd5b83018035915067ffffffffffffffff821115614ac857600080fd5b6020019150368190038213156147ca57600080fd5b600060208284031215614aef57600080fd5b81356122668161433c565b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000815260008351614b328160178501602088016147d1565b7f206973206d697373696e6720726f6c65200000000000000000000000000000006017918401918201528351614b6f8160288401602088016147d1565b01602801949350505050565b6020815260008251806020840152614b9a8160408501602087016147d1565b601f01601f19169190910160400192915050565b634e487b7160e01b600052604160045260246000fd5b600081614bd357614bd3614671565b50600019019056fea2646970667358221220bfb91c91c1b7acac1e1e0c04feef5d4b5547a65013c587ca7b8653505ea7ffe564736f6c63430008130033", "devdoc": { "author": "The Swarm Authors", "details": "Implements a Schelling Co-ordination game to form consensus around the Reserve Commitment hash. This takes place in three phases: _commit_, _reveal_ and _claim_. A node, upon establishing that it _isParticipatingInUpcomingRound_, i.e. it's overlay falls within proximity order of its reported depth with the _currentRoundAnchor_, prepares a \"reserve commitment hash\" using the chunks it currently stores in its reserve and calculates the \"storage depth\" (see Bee for details). These values, if calculated honestly, and with the right chunks stored, should be the same for every node in a neighbourhood. This is the Schelling point. Each eligible node can then use these values, together with a random, single use, secret _revealNonce_ and their _overlay_ as the pre-image values for the obsfucated _commit_, using the _wrapCommit_ method. Once the _commit_ round has elapsed, participating nodes must provide the values used to calculate their obsfucated _commit_ hash, which, once verified for correctness and proximity to the anchor are retained in the _currentReveals_. Nodes that have committed but do not reveal the correct values used to create the pre-image will have their stake \"frozen\" for a period of rounds proportional to their reported depth. During the _reveal_ round, randomness is updated after every successful reveal. Once the reveal round is concluded, the _currentRoundAnchor_ is updated and users can determine if they will be eligible their overlay will be eligible for the next commit phase using _isParticipatingInUpcomingRound_. When the _reveal_ phase has been concluded, the claim phase can begin. At this point, the truth teller and winner are already determined. By calling _isWinner_, an applicant node can run the relevant logic to determine if they have been selected as the beneficiary of this round. When calling _claim_, the current pot from the PostageStamp contract is withdrawn and transferred to that beneficiaries address. Nodes that have revealed values that differ from the truth, have their stakes \"frozen\" for a period of rounds proportional to their reported depth.", @@ -1609,6 +1625,9 @@ "Paused(address)": { "details": "Emitted when the pause is triggered by `account`." }, + "PriceAdjustmentSkipped(uint16)": { + "details": "Output external call status" + }, "Revealed(uint256,bytes32,uint256,uint256,bytes32,uint8)": { "details": "Logs that an overlay has revealed" }, @@ -1630,6 +1649,9 @@ "WinnerSelected((bytes32,address,uint8,uint256,uint256,bytes32))": { "details": "Emitted when the winner of a round is selected in the claim phase" }, + "WithdrawFailed(address)": { + "details": "Withdraw not successful in claim" + }, "transformedChunkAddressFromInclusionProof(uint256,bytes32)": { "details": "Logs for inclusion proof" } @@ -1797,47 +1819,47 @@ "type": "t_bool" }, { - "astId": 7238, + "astId": 7296, "contract": "src/Redistribution.sol:Redistribution", "label": "PostageContract", "offset": 1, "slot": "1", - "type": "t_contract(IPostageStamp)11180" + "type": "t_contract(IPostageStamp)11335" }, { - "astId": 7241, + "astId": 7299, "contract": "src/Redistribution.sol:Redistribution", "label": "OracleContract", "offset": 0, "slot": "2", - "type": "t_contract(IPriceOracle)7117" + "type": "t_contract(IPriceOracle)7176" }, { - "astId": 7244, + "astId": 7302, "contract": "src/Redistribution.sol:Redistribution", "label": "Stakes", "offset": 0, "slot": "3", - "type": "t_contract(IStakeRegistry)7163" + "type": "t_contract(IStakeRegistry)7219" }, { - "astId": 7248, + "astId": 7306, "contract": "src/Redistribution.sol:Redistribution", "label": "currentCommits", "offset": 0, "slot": "4", - "type": "t_array(t_struct(Commit)7181_storage)dyn_storage" + "type": "t_array(t_struct(Commit)7239_storage)dyn_storage" }, { - "astId": 7252, + "astId": 7310, "contract": "src/Redistribution.sol:Redistribution", "label": "currentReveals", "offset": 0, "slot": "5", - "type": "t_array(t_struct(Reveal)7194_storage)dyn_storage" + "type": "t_array(t_struct(Reveal)7252_storage)dyn_storage" }, { - "astId": 7254, + "astId": 7312, "contract": "src/Redistribution.sol:Redistribution", "label": "currentRevealRoundAnchor", "offset": 0, @@ -1845,7 +1867,7 @@ "type": "t_bytes32" }, { - "astId": 7256, + "astId": 7314, "contract": "src/Redistribution.sol:Redistribution", "label": "seed", "offset": 0, @@ -1853,7 +1875,7 @@ "type": "t_bytes32" }, { - "astId": 7258, + "astId": 7316, "contract": "src/Redistribution.sol:Redistribution", "label": "currentCommitRound", "offset": 0, @@ -1861,7 +1883,7 @@ "type": "t_uint64" }, { - "astId": 7260, + "astId": 7318, "contract": "src/Redistribution.sol:Redistribution", "label": "currentRevealRound", "offset": 8, @@ -1869,7 +1891,7 @@ "type": "t_uint64" }, { - "astId": 7262, + "astId": 7320, "contract": "src/Redistribution.sol:Redistribution", "label": "currentClaimRound", "offset": 16, @@ -1877,7 +1899,7 @@ "type": "t_uint64" }, { - "astId": 7265, + "astId": 7323, "contract": "src/Redistribution.sol:Redistribution", "label": "penaltyMultiplierDisagreement", "offset": 24, @@ -1885,7 +1907,7 @@ "type": "t_uint8" }, { - "astId": 7268, + "astId": 7326, "contract": "src/Redistribution.sol:Redistribution", "label": "penaltyMultiplierNonRevealed", "offset": 25, @@ -1893,7 +1915,7 @@ "type": "t_uint8" }, { - "astId": 7271, + "astId": 7329, "contract": "src/Redistribution.sol:Redistribution", "label": "penaltyRandomFactor", "offset": 26, @@ -1901,7 +1923,7 @@ "type": "t_uint8" }, { - "astId": 7274, + "astId": 7332, "contract": "src/Redistribution.sol:Redistribution", "label": "sampleMaxValue", "offset": 0, @@ -1909,12 +1931,12 @@ "type": "t_uint256" }, { - "astId": 7277, + "astId": 7335, "contract": "src/Redistribution.sol:Redistribution", "label": "winner", "offset": 0, "slot": "10", - "type": "t_struct(Reveal)7194_storage" + "type": "t_struct(Reveal)7252_storage" } ], "types": { @@ -1923,14 +1945,14 @@ "label": "address", "numberOfBytes": "20" }, - "t_array(t_struct(Commit)7181_storage)dyn_storage": { - "base": "t_struct(Commit)7181_storage", + "t_array(t_struct(Commit)7239_storage)dyn_storage": { + "base": "t_struct(Commit)7239_storage", "encoding": "dynamic_array", "label": "struct Redistribution.Commit[]", "numberOfBytes": "32" }, - "t_array(t_struct(Reveal)7194_storage)dyn_storage": { - "base": "t_struct(Reveal)7194_storage", + "t_array(t_struct(Reveal)7252_storage)dyn_storage": { + "base": "t_struct(Reveal)7252_storage", "encoding": "dynamic_array", "label": "struct Redistribution.Reveal[]", "numberOfBytes": "32" @@ -1945,17 +1967,17 @@ "label": "bytes32", "numberOfBytes": "32" }, - "t_contract(IPostageStamp)11180": { + "t_contract(IPostageStamp)11335": { "encoding": "inplace", "label": "contract IPostageStamp", "numberOfBytes": "20" }, - "t_contract(IPriceOracle)7117": { + "t_contract(IPriceOracle)7176": { "encoding": "inplace", "label": "contract IPriceOracle", "numberOfBytes": "20" }, - "t_contract(IStakeRegistry)7163": { + "t_contract(IStakeRegistry)7219": { "encoding": "inplace", "label": "contract IStakeRegistry", "numberOfBytes": "20" @@ -1974,12 +1996,12 @@ "numberOfBytes": "32", "value": "t_struct(RoleData)19_storage" }, - "t_struct(Commit)7181_storage": { + "t_struct(Commit)7239_storage": { "encoding": "inplace", "label": "struct Redistribution.Commit", "members": [ { - "astId": 7170, + "astId": 7226, "contract": "src/Redistribution.sol:Redistribution", "label": "overlay", "offset": 0, @@ -1987,7 +2009,7 @@ "type": "t_bytes32" }, { - "astId": 7172, + "astId": 7228, "contract": "src/Redistribution.sol:Redistribution", "label": "owner", "offset": 0, @@ -1995,7 +2017,7 @@ "type": "t_address" }, { - "astId": 7174, + "astId": 7230, "contract": "src/Redistribution.sol:Redistribution", "label": "revealed", "offset": 20, @@ -2003,7 +2025,15 @@ "type": "t_bool" }, { - "astId": 7176, + "astId": 7232, + "contract": "src/Redistribution.sol:Redistribution", + "label": "height", + "offset": 21, + "slot": "1", + "type": "t_uint8" + }, + { + "astId": 7234, "contract": "src/Redistribution.sol:Redistribution", "label": "stake", "offset": 0, @@ -2011,7 +2041,7 @@ "type": "t_uint256" }, { - "astId": 7178, + "astId": 7236, "contract": "src/Redistribution.sol:Redistribution", "label": "obfuscatedHash", "offset": 0, @@ -2019,7 +2049,7 @@ "type": "t_bytes32" }, { - "astId": 7180, + "astId": 7238, "contract": "src/Redistribution.sol:Redistribution", "label": "revealIndex", "offset": 0, @@ -2029,12 +2059,12 @@ ], "numberOfBytes": "160" }, - "t_struct(Reveal)7194_storage": { + "t_struct(Reveal)7252_storage": { "encoding": "inplace", "label": "struct Redistribution.Reveal", "members": [ { - "astId": 7183, + "astId": 7241, "contract": "src/Redistribution.sol:Redistribution", "label": "overlay", "offset": 0, @@ -2042,7 +2072,7 @@ "type": "t_bytes32" }, { - "astId": 7185, + "astId": 7243, "contract": "src/Redistribution.sol:Redistribution", "label": "owner", "offset": 0, @@ -2050,7 +2080,7 @@ "type": "t_address" }, { - "astId": 7187, + "astId": 7245, "contract": "src/Redistribution.sol:Redistribution", "label": "depth", "offset": 20, @@ -2058,7 +2088,7 @@ "type": "t_uint8" }, { - "astId": 7189, + "astId": 7247, "contract": "src/Redistribution.sol:Redistribution", "label": "stake", "offset": 0, @@ -2066,7 +2096,7 @@ "type": "t_uint256" }, { - "astId": 7191, + "astId": 7249, "contract": "src/Redistribution.sol:Redistribution", "label": "stakeDensity", "offset": 0, @@ -2074,7 +2104,7 @@ "type": "t_uint256" }, { - "astId": 7193, + "astId": 7251, "contract": "src/Redistribution.sol:Redistribution", "label": "hash", "offset": 0, diff --git a/deployments/testnetlight/StakeRegistry.json b/deployments/testnetlight/StakeRegistry.json index e5da470c..88ec7aa0 100644 --- a/deployments/testnetlight/StakeRegistry.json +++ b/deployments/testnetlight/StakeRegistry.json @@ -1,5 +1,5 @@ { - "address": "0x5922F26A68021C9edf53d9CFbEFc3181f0d16E93", + "address": "0x554D880D39f1072D147aaf5b8BB2589A882617F8", "abi": [ { "inputs": [ @@ -241,6 +241,12 @@ "internalType": "uint256", "name": "lastUpdatedBlock", "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint8", + "name": "height", + "type": "uint8" } ], "name": "StakeUpdated", @@ -304,19 +310,6 @@ "stateMutability": "view", "type": "function" }, - { - "inputs": [], - "name": "PAUSER_ROLE", - "outputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "stateMutability": "view", - "type": "function" - }, { "inputs": [], "name": "REDISTRIBUTOR_ROLE", @@ -435,6 +428,25 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "address", + "name": "_owner", + "type": "address" + } + ], + "name": "heightOfAddress", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -465,6 +477,11 @@ "internalType": "uint256", "name": "_addAmount", "type": "uint256" + }, + { + "internalType": "uint8", + "name": "_height", + "type": "uint8" } ], "name": "manageStake", @@ -622,9 +639,9 @@ "type": "uint256" }, { - "internalType": "bool", - "name": "isValue", - "type": "bool" + "internalType": "uint8", + "name": "height", + "type": "uint8" } ], "stateMutability": "view", @@ -677,22 +694,22 @@ "type": "function" } ], - "transactionHash": "0x4950a8f5e1a2b7cecef0a1844a014ff19ea25f81e1938b21883747c4a6494bc5", + "transactionHash": "0x87e589d18784f32d151ba039880244434c98cf1e482e9d646423770927a2b855", "receipt": { "to": null, "from": "0xb1C7F17Ed88189Abf269Bf68A3B2Ed83C5276aAe", - "contractAddress": "0x5922F26A68021C9edf53d9CFbEFc3181f0d16E93", - "transactionIndex": 99, - "gasUsed": "1531776", - "logsBloom": "0x00000004000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000800000000010000000000000000002004000000040000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000001002000000000000000000000000000000000000000000000000000000000100002000000020000000000000000000000000000000000000000400000000000000000000000000", - "blockHash": "0xad94780a1ac88e76197fb0f1500db0a1ad4c5219c10ae6f54b8faf4ea98ae2d5", - "transactionHash": "0x4950a8f5e1a2b7cecef0a1844a014ff19ea25f81e1938b21883747c4a6494bc5", + "contractAddress": "0x554D880D39f1072D147aaf5b8BB2589A882617F8", + "transactionIndex": 55, + "gasUsed": "1584090", + "logsBloom": "0x00000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000020000000000000000000800000000010000000000000000006000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000001000000000000000000000000000000000000000000000000000000000000100000000000020000000000000000000000000000000000000000000000000000000000000000000", + "blockHash": "0x6f8de981f481588e750737ded0d2d5b4f657fc3e9461be5fe25f1b2182807419", + "transactionHash": "0x87e589d18784f32d151ba039880244434c98cf1e482e9d646423770927a2b855", "logs": [ { - "transactionIndex": 99, - "blockNumber": 6321442, - "transactionHash": "0x4950a8f5e1a2b7cecef0a1844a014ff19ea25f81e1938b21883747c4a6494bc5", - "address": "0x5922F26A68021C9edf53d9CFbEFc3181f0d16E93", + "transactionIndex": 55, + "blockNumber": 6964096, + "transactionHash": "0x87e589d18784f32d151ba039880244434c98cf1e482e9d646423770927a2b855", + "address": "0x554D880D39f1072D147aaf5b8BB2589A882617F8", "topics": [ "0x2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d", "0x0000000000000000000000000000000000000000000000000000000000000000", @@ -700,40 +717,25 @@ "0x000000000000000000000000b1c7f17ed88189abf269bf68a3b2ed83c5276aae" ], "data": "0x", - "logIndex": 193, - "blockHash": "0xad94780a1ac88e76197fb0f1500db0a1ad4c5219c10ae6f54b8faf4ea98ae2d5" - }, - { - "transactionIndex": 99, - "blockNumber": 6321442, - "transactionHash": "0x4950a8f5e1a2b7cecef0a1844a014ff19ea25f81e1938b21883747c4a6494bc5", - "address": "0x5922F26A68021C9edf53d9CFbEFc3181f0d16E93", - "topics": [ - "0x2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d", - "0x65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a", - "0x000000000000000000000000b1c7f17ed88189abf269bf68a3b2ed83c5276aae", - "0x000000000000000000000000b1c7f17ed88189abf269bf68a3b2ed83c5276aae" - ], - "data": "0x", - "logIndex": 194, - "blockHash": "0xad94780a1ac88e76197fb0f1500db0a1ad4c5219c10ae6f54b8faf4ea98ae2d5" + "logIndex": 58, + "blockHash": "0x6f8de981f481588e750737ded0d2d5b4f657fc3e9461be5fe25f1b2182807419" } ], - "blockNumber": 6321442, - "cumulativeGasUsed": "13319167", + "blockNumber": 6964096, + "cumulativeGasUsed": "9726306", "status": 1, "byzantium": true }, "args": [ "0x543dDb01Ba47acB11de34891cD86B675F04840db", 333, - "0xcA1E073042438a40A7BC0e558e2B9bd1fe2647F8" + "0x01709567dfF91A387eB2d1Ca60255f80e7633EC2" ], "numDeployments": 3, - "solcInputHash": "823850fc9cd5102bcd2f6d2624ab2024", - "metadata": "{\"compiler\":{\"version\":\"0.8.19+commit.7dd6d404\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_bzzToken\",\"type\":\"address\"},{\"internalType\":\"uint64\",\"name\":\"_NetworkId\",\"type\":\"uint64\"},{\"internalType\":\"address\",\"name\":\"_oracleContract\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[],\"name\":\"BelowMinimumStake\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"Frozen\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"OnlyPauser\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"OnlyRedistributor\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"TransferFailed\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"Unauthorized\",\"type\":\"error\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"}],\"name\":\"OverlayChanged\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"Paused\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"previousAdminRole\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"newAdminRole\",\"type\":\"bytes32\"}],\"name\":\"RoleAdminChanged\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"}],\"name\":\"RoleGranted\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"}],\"name\":\"RoleRevoked\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"frozen\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"time\",\"type\":\"uint256\"}],\"name\":\"StakeFrozen\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"slashed\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"StakeSlashed\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"committedStake\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"potentialStake\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"lastUpdatedBlock\",\"type\":\"uint256\"}],\"name\":\"StakeUpdated\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"node\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"StakeWithdrawn\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"Unpaused\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"DEFAULT_ADMIN_ROLE\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"OracleContract\",\"outputs\":[{\"internalType\":\"contract IPriceOracle\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"PAUSER_ROLE\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"REDISTRIBUTOR_ROLE\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"bzzToken\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint64\",\"name\":\"_NetworkId\",\"type\":\"uint64\"}],\"name\":\"changeNetworkId\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_owner\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"_time\",\"type\":\"uint256\"}],\"name\":\"freezeDeposit\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"}],\"name\":\"getRoleAdmin\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"grantRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"hasRole\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_owner\",\"type\":\"address\"}],\"name\":\"lastUpdatedBlockNumberOfAddress\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"_setNonce\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"_addAmount\",\"type\":\"uint256\"}],\"name\":\"manageStake\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"migrateStake\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_owner\",\"type\":\"address\"}],\"name\":\"nodeEffectiveStake\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_owner\",\"type\":\"address\"}],\"name\":\"overlayOfAddress\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"pause\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"paused\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"renounceRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"revokeRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_owner\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"_amount\",\"type\":\"uint256\"}],\"name\":\"slashDeposit\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"name\":\"stakes\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"committedStake\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"potentialStake\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"lastUpdatedBlockNumber\",\"type\":\"uint256\"},{\"internalType\":\"bool\",\"name\":\"isValue\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes4\",\"name\":\"interfaceId\",\"type\":\"bytes4\"}],\"name\":\"supportsInterface\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"unPause\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"withdrawFromStake\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"withdrawableStake\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"}],\"devdoc\":{\"author\":\"The Swarm Authors\",\"details\":\"Allows users to stake tokens in order to be eligible for the Redistribution Schelling co-ordination game. Stakes are frozen or slashed by the Redistribution contract in response to violations of the protocol.\",\"events\":{\"OverlayChanged(address,bytes32)\":{\"details\":\"Emitted when a address changes overlay it uses\"},\"Paused(address)\":{\"details\":\"Emitted when the pause is triggered by `account`.\"},\"RoleAdminChanged(bytes32,bytes32,bytes32)\":{\"details\":\"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._\"},\"RoleGranted(bytes32,address,address)\":{\"details\":\"Emitted when `account` is granted `role`. `sender` is the account that originated the contract call, an admin role bearer except when using {AccessControl-_setupRole}.\"},\"RoleRevoked(bytes32,address,address)\":{\"details\":\"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`)\"},\"StakeFrozen(address,bytes32,uint256)\":{\"details\":\"Emitted when a stake for address `frozen` is frozen for `time` blocks.\"},\"StakeSlashed(address,bytes32,uint256)\":{\"details\":\"Emitted when a stake for address `slashed` is slashed by `amount`.\"},\"StakeUpdated(address,uint256,uint256,bytes32,uint256)\":{\"details\":\"Emitted when a stake is created or updated by `owner` of the `overlay` by `committedStake`, and `potentialStake` during `lastUpdatedBlock`.\"},\"StakeWithdrawn(address,uint256)\":{\"details\":\"Emitted when a stake for address is withdrawn\"},\"Unpaused(address)\":{\"details\":\"Emitted when the pause is lifted by `account`.\"}},\"kind\":\"dev\",\"methods\":{\"constructor\":{\"params\":{\"_NetworkId\":\"Swarm network ID\",\"_bzzToken\":\"Address of the staked ERC20 token\"}},\"freezeDeposit(address,uint256)\":{\"details\":\"Freeze an existing stake, can only be called by the redistributor\",\"params\":{\"_owner\":\"the addres selected\",\"_time\":\"penalty length in blocknumbers\"}},\"getRoleAdmin(bytes32)\":{\"details\":\"Returns the admin role that controls `role`. See {grantRole} and {revokeRole}. To change a role's admin, use {_setRoleAdmin}.\"},\"grantRole(bytes32,address)\":{\"details\":\"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.\"},\"hasRole(bytes32,address)\":{\"details\":\"Returns `true` if `account` has been granted `role`.\"},\"lastUpdatedBlockNumberOfAddress(address)\":{\"details\":\"Returns the `lastUpdatedBlockNumber` of `address`.\"},\"manageStake(bytes32,uint256)\":{\"details\":\"At least `_initialBalancePerChunk*2^depth` number of tokens need to be preapproved for this contract.\",\"params\":{\"_addAmount\":\"Deposited amount of ERC20 tokens, equals to added Potential stake value\",\"_setNonce\":\"Nonce that was used for overlay calculation.\"}},\"migrateStake()\":{\"details\":\"Migrate stake only when the staking contract is paused, can only be called by the owner of the stake\"},\"nodeEffectiveStake(address)\":{\"details\":\"Returns the current `effectiveStake` of `address`. previously usable stake\",\"params\":{\"_owner\":\"_owner of node\"}},\"overlayOfAddress(address)\":{\"details\":\"Returns the currently used overlay of the address.\",\"params\":{\"_owner\":\"address of node\"}},\"pause()\":{\"details\":\"Pause the contract. The contract is provably stopped by renouncing the pauser role and the admin role after pausing, can only be called by the `PAUSER`\"},\"paused()\":{\"details\":\"Returns true if the contract is paused, and false otherwise.\"},\"renounceRole(bytes32,address)\":{\"details\":\"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.\"},\"revokeRole(bytes32,address)\":{\"details\":\"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.\"},\"slashDeposit(address,uint256)\":{\"details\":\"Slash an existing stake, can only be called by the `redistributor`\",\"params\":{\"_amount\":\"the amount to be slashed\",\"_owner\":\"the _owner adress selected\"}},\"supportsInterface(bytes4)\":{\"details\":\"See {IERC165-supportsInterface}.\"},\"unPause()\":{\"details\":\"Unpause the contract, can only be called by the pauser when paused\"},\"withdrawFromStake()\":{\"details\":\"Withdraw node stake surplus\"},\"withdrawableStake()\":{\"details\":\"Check the amount that is possible to withdraw as surplus\"}},\"title\":\"Staking contract for the Swarm storage incentives\",\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{\"manageStake(bytes32,uint256)\":{\"notice\":\"Create a new stake or update an existing one, change overlay of node\"}},\"version\":1}},\"settings\":{\"compilationTarget\":{\"src/Staking.sol\":\"StakeRegistry\"},\"evmVersion\":\"paris\",\"libraries\":{\":__CACHE_BREAKER__\":\"0x00000000d41867734bbee4c6863d9255b2b06ac1\"},\"metadata\":{\"bytecodeHash\":\"ipfs\",\"useLiteralContent\":true},\"optimizer\":{\"enabled\":true,\"runs\":1000},\"remappings\":[]},\"sources\":{\"@openzeppelin/contracts/access/AccessControl.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (access/AccessControl.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./IAccessControl.sol\\\";\\nimport \\\"../utils/Context.sol\\\";\\nimport \\\"../utils/Strings.sol\\\";\\nimport \\\"../utils/introspection/ERC165.sol\\\";\\n\\n/**\\n * @dev Contract module that allows children to implement role-based access\\n * control mechanisms. This is a lightweight version that doesn't allow enumerating role\\n * members except through off-chain means by accessing the contract event logs. Some\\n * applications may benefit from on-chain enumerability, for those cases see\\n * {AccessControlEnumerable}.\\n *\\n * Roles are referred to by their `bytes32` identifier. These should be exposed\\n * in the external API and be unique. The best way to achieve this is by\\n * using `public constant` hash digests:\\n *\\n * ```\\n * bytes32 public constant MY_ROLE = keccak256(\\\"MY_ROLE\\\");\\n * ```\\n *\\n * Roles can be used to represent a set of permissions. To restrict access to a\\n * function call, use {hasRole}:\\n *\\n * ```\\n * function foo() public {\\n * require(hasRole(MY_ROLE, msg.sender));\\n * ...\\n * }\\n * ```\\n *\\n * Roles can be granted and revoked dynamically via the {grantRole} and\\n * {revokeRole} functions. Each role has an associated admin role, and only\\n * accounts that have a role's admin role can call {grantRole} and {revokeRole}.\\n *\\n * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means\\n * that only accounts with this role will be able to grant or revoke other\\n * roles. More complex role relationships can be created by using\\n * {_setRoleAdmin}.\\n *\\n * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to\\n * grant and revoke this role. Extra precautions should be taken to secure\\n * accounts that have been granted it.\\n */\\nabstract contract AccessControl is Context, IAccessControl, ERC165 {\\n struct RoleData {\\n mapping(address => bool) members;\\n bytes32 adminRole;\\n }\\n\\n mapping(bytes32 => RoleData) private _roles;\\n\\n bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;\\n\\n /**\\n * @dev Modifier that checks that an account has a specific role. Reverts\\n * with a standardized message including the required role.\\n *\\n * The format of the revert reason is given by the following regular expression:\\n *\\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\\n *\\n * _Available since v4.1._\\n */\\n modifier onlyRole(bytes32 role) {\\n _checkRole(role);\\n _;\\n }\\n\\n /**\\n * @dev See {IERC165-supportsInterface}.\\n */\\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);\\n }\\n\\n /**\\n * @dev Returns `true` if `account` has been granted `role`.\\n */\\n function hasRole(bytes32 role, address account) public view virtual override returns (bool) {\\n return _roles[role].members[account];\\n }\\n\\n /**\\n * @dev Revert with a standard message if `_msgSender()` is missing `role`.\\n * Overriding this function changes the behavior of the {onlyRole} modifier.\\n *\\n * Format of the revert message is described in {_checkRole}.\\n *\\n * _Available since v4.6._\\n */\\n function _checkRole(bytes32 role) internal view virtual {\\n _checkRole(role, _msgSender());\\n }\\n\\n /**\\n * @dev Revert with a standard message if `account` is missing `role`.\\n *\\n * The format of the revert reason is given by the following regular expression:\\n *\\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\\n */\\n function _checkRole(bytes32 role, address account) internal view virtual {\\n if (!hasRole(role, account)) {\\n revert(\\n string(\\n abi.encodePacked(\\n \\\"AccessControl: account \\\",\\n Strings.toHexString(account),\\n \\\" is missing role \\\",\\n Strings.toHexString(uint256(role), 32)\\n )\\n )\\n );\\n }\\n }\\n\\n /**\\n * @dev Returns the admin role that controls `role`. See {grantRole} and\\n * {revokeRole}.\\n *\\n * To change a role's admin, use {_setRoleAdmin}.\\n */\\n function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {\\n return _roles[role].adminRole;\\n }\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * If `account` had not been already granted `role`, emits a {RoleGranted}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n *\\n * May emit a {RoleGranted} event.\\n */\\n function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\\n _grantRole(role, account);\\n }\\n\\n /**\\n * @dev Revokes `role` from `account`.\\n *\\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n *\\n * May emit a {RoleRevoked} event.\\n */\\n function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\\n _revokeRole(role, account);\\n }\\n\\n /**\\n * @dev Revokes `role` from the calling account.\\n *\\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\\n * purpose is to provide a mechanism for accounts to lose their privileges\\n * if they are compromised (such as when a trusted device is misplaced).\\n *\\n * If the calling account had been revoked `role`, emits a {RoleRevoked}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must be `account`.\\n *\\n * May emit a {RoleRevoked} event.\\n */\\n function renounceRole(bytes32 role, address account) public virtual override {\\n require(account == _msgSender(), \\\"AccessControl: can only renounce roles for self\\\");\\n\\n _revokeRole(role, account);\\n }\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * If `account` had not been already granted `role`, emits a {RoleGranted}\\n * event. Note that unlike {grantRole}, this function doesn't perform any\\n * checks on the calling account.\\n *\\n * May emit a {RoleGranted} event.\\n *\\n * [WARNING]\\n * ====\\n * This function should only be called from the constructor when setting\\n * up the initial roles for the system.\\n *\\n * Using this function in any other way is effectively circumventing the admin\\n * system imposed by {AccessControl}.\\n * ====\\n *\\n * NOTE: This function is deprecated in favor of {_grantRole}.\\n */\\n function _setupRole(bytes32 role, address account) internal virtual {\\n _grantRole(role, account);\\n }\\n\\n /**\\n * @dev Sets `adminRole` as ``role``'s admin role.\\n *\\n * Emits a {RoleAdminChanged} event.\\n */\\n function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {\\n bytes32 previousAdminRole = getRoleAdmin(role);\\n _roles[role].adminRole = adminRole;\\n emit RoleAdminChanged(role, previousAdminRole, adminRole);\\n }\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * Internal function without access restriction.\\n *\\n * May emit a {RoleGranted} event.\\n */\\n function _grantRole(bytes32 role, address account) internal virtual {\\n if (!hasRole(role, account)) {\\n _roles[role].members[account] = true;\\n emit RoleGranted(role, account, _msgSender());\\n }\\n }\\n\\n /**\\n * @dev Revokes `role` from `account`.\\n *\\n * Internal function without access restriction.\\n *\\n * May emit a {RoleRevoked} event.\\n */\\n function _revokeRole(bytes32 role, address account) internal virtual {\\n if (hasRole(role, account)) {\\n _roles[role].members[account] = false;\\n emit RoleRevoked(role, account, _msgSender());\\n }\\n }\\n}\\n\",\"keccak256\":\"0x67e3daf189111d6d5b0464ed09cf9f0605a22c4b965a7fcecd707101faff008a\",\"license\":\"MIT\"},\"@openzeppelin/contracts/access/IAccessControl.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev External interface of AccessControl declared to support ERC165 detection.\\n */\\ninterface IAccessControl {\\n /**\\n * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`\\n *\\n * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite\\n * {RoleAdminChanged} not being emitted signaling this.\\n *\\n * _Available since v3.1._\\n */\\n event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);\\n\\n /**\\n * @dev Emitted when `account` is granted `role`.\\n *\\n * `sender` is the account that originated the contract call, an admin role\\n * bearer except when using {AccessControl-_setupRole}.\\n */\\n event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);\\n\\n /**\\n * @dev Emitted when `account` is revoked `role`.\\n *\\n * `sender` is the account that originated the contract call:\\n * - if using `revokeRole`, it is the admin role bearer\\n * - if using `renounceRole`, it is the role bearer (i.e. `account`)\\n */\\n event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);\\n\\n /**\\n * @dev Returns `true` if `account` has been granted `role`.\\n */\\n function hasRole(bytes32 role, address account) external view returns (bool);\\n\\n /**\\n * @dev Returns the admin role that controls `role`. See {grantRole} and\\n * {revokeRole}.\\n *\\n * To change a role's admin, use {AccessControl-_setRoleAdmin}.\\n */\\n function getRoleAdmin(bytes32 role) external view returns (bytes32);\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * If `account` had not been already granted `role`, emits a {RoleGranted}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n */\\n function grantRole(bytes32 role, address account) external;\\n\\n /**\\n * @dev Revokes `role` from `account`.\\n *\\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n */\\n function revokeRole(bytes32 role, address account) external;\\n\\n /**\\n * @dev Revokes `role` from the calling account.\\n *\\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\\n * purpose is to provide a mechanism for accounts to lose their privileges\\n * if they are compromised (such as when a trusted device is misplaced).\\n *\\n * If the calling account had been granted `role`, emits a {RoleRevoked}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must be `account`.\\n */\\n function renounceRole(bytes32 role, address account) external;\\n}\\n\",\"keccak256\":\"0x59ce320a585d7e1f163cd70390a0ef2ff9cec832e2aa544293a00692465a7a57\",\"license\":\"MIT\"},\"@openzeppelin/contracts/security/Pausable.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"../utils/Context.sol\\\";\\n\\n/**\\n * @dev Contract module which allows children to implement an emergency stop\\n * mechanism that can be triggered by an authorized account.\\n *\\n * This module is used through inheritance. It will make available the\\n * modifiers `whenNotPaused` and `whenPaused`, which can be applied to\\n * the functions of your contract. Note that they will not be pausable by\\n * simply including this module, only once the modifiers are put in place.\\n */\\nabstract contract Pausable is Context {\\n /**\\n * @dev Emitted when the pause is triggered by `account`.\\n */\\n event Paused(address account);\\n\\n /**\\n * @dev Emitted when the pause is lifted by `account`.\\n */\\n event Unpaused(address account);\\n\\n bool private _paused;\\n\\n /**\\n * @dev Initializes the contract in unpaused state.\\n */\\n constructor() {\\n _paused = false;\\n }\\n\\n /**\\n * @dev Modifier to make a function callable only when the contract is not paused.\\n *\\n * Requirements:\\n *\\n * - The contract must not be paused.\\n */\\n modifier whenNotPaused() {\\n _requireNotPaused();\\n _;\\n }\\n\\n /**\\n * @dev Modifier to make a function callable only when the contract is paused.\\n *\\n * Requirements:\\n *\\n * - The contract must be paused.\\n */\\n modifier whenPaused() {\\n _requirePaused();\\n _;\\n }\\n\\n /**\\n * @dev Returns true if the contract is paused, and false otherwise.\\n */\\n function paused() public view virtual returns (bool) {\\n return _paused;\\n }\\n\\n /**\\n * @dev Throws if the contract is paused.\\n */\\n function _requireNotPaused() internal view virtual {\\n require(!paused(), \\\"Pausable: paused\\\");\\n }\\n\\n /**\\n * @dev Throws if the contract is not paused.\\n */\\n function _requirePaused() internal view virtual {\\n require(paused(), \\\"Pausable: not paused\\\");\\n }\\n\\n /**\\n * @dev Triggers stopped state.\\n *\\n * Requirements:\\n *\\n * - The contract must not be paused.\\n */\\n function _pause() internal virtual whenNotPaused {\\n _paused = true;\\n emit Paused(_msgSender());\\n }\\n\\n /**\\n * @dev Returns to normal state.\\n *\\n * Requirements:\\n *\\n * - The contract must be paused.\\n */\\n function _unpause() internal virtual whenPaused {\\n _paused = false;\\n emit Unpaused(_msgSender());\\n }\\n}\\n\",\"keccak256\":\"0x0849d93b16c9940beb286a7864ed02724b248b93e0d80ef6355af5ef15c64773\",\"license\":\"MIT\"},\"@openzeppelin/contracts/token/ERC20/ERC20.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/ERC20.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./IERC20.sol\\\";\\nimport \\\"./extensions/IERC20Metadata.sol\\\";\\nimport \\\"../../utils/Context.sol\\\";\\n\\n/**\\n * @dev Implementation of the {IERC20} interface.\\n *\\n * This implementation is agnostic to the way tokens are created. This means\\n * that a supply mechanism has to be added in a derived contract using {_mint}.\\n * For a generic mechanism see {ERC20PresetMinterPauser}.\\n *\\n * TIP: For a detailed writeup see our guide\\n * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How\\n * to implement supply mechanisms].\\n *\\n * We have followed general OpenZeppelin Contracts guidelines: functions revert\\n * instead returning `false` on failure. This behavior is nonetheless\\n * conventional and does not conflict with the expectations of ERC20\\n * applications.\\n *\\n * Additionally, an {Approval} event is emitted on calls to {transferFrom}.\\n * This allows applications to reconstruct the allowance for all accounts just\\n * by listening to said events. Other implementations of the EIP may not emit\\n * these events, as it isn't required by the specification.\\n *\\n * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}\\n * functions have been added to mitigate the well-known issues around setting\\n * allowances. See {IERC20-approve}.\\n */\\ncontract ERC20 is Context, IERC20, IERC20Metadata {\\n mapping(address => uint256) private _balances;\\n\\n mapping(address => mapping(address => uint256)) private _allowances;\\n\\n uint256 private _totalSupply;\\n\\n string private _name;\\n string private _symbol;\\n\\n /**\\n * @dev Sets the values for {name} and {symbol}.\\n *\\n * The default value of {decimals} is 18. To select a different value for\\n * {decimals} you should overload it.\\n *\\n * All two of these values are immutable: they can only be set once during\\n * construction.\\n */\\n constructor(string memory name_, string memory symbol_) {\\n _name = name_;\\n _symbol = symbol_;\\n }\\n\\n /**\\n * @dev Returns the name of the token.\\n */\\n function name() public view virtual override returns (string memory) {\\n return _name;\\n }\\n\\n /**\\n * @dev Returns the symbol of the token, usually a shorter version of the\\n * name.\\n */\\n function symbol() public view virtual override returns (string memory) {\\n return _symbol;\\n }\\n\\n /**\\n * @dev Returns the number of decimals used to get its user representation.\\n * For example, if `decimals` equals `2`, a balance of `505` tokens should\\n * be displayed to a user as `5.05` (`505 / 10 ** 2`).\\n *\\n * Tokens usually opt for a value of 18, imitating the relationship between\\n * Ether and Wei. This is the value {ERC20} uses, unless this function is\\n * overridden;\\n *\\n * NOTE: This information is only used for _display_ purposes: it in\\n * no way affects any of the arithmetic of the contract, including\\n * {IERC20-balanceOf} and {IERC20-transfer}.\\n */\\n function decimals() public view virtual override returns (uint8) {\\n return 18;\\n }\\n\\n /**\\n * @dev See {IERC20-totalSupply}.\\n */\\n function totalSupply() public view virtual override returns (uint256) {\\n return _totalSupply;\\n }\\n\\n /**\\n * @dev See {IERC20-balanceOf}.\\n */\\n function balanceOf(address account) public view virtual override returns (uint256) {\\n return _balances[account];\\n }\\n\\n /**\\n * @dev See {IERC20-transfer}.\\n *\\n * Requirements:\\n *\\n * - `to` cannot be the zero address.\\n * - the caller must have a balance of at least `amount`.\\n */\\n function transfer(address to, uint256 amount) public virtual override returns (bool) {\\n address owner = _msgSender();\\n _transfer(owner, to, amount);\\n return true;\\n }\\n\\n /**\\n * @dev See {IERC20-allowance}.\\n */\\n function allowance(address owner, address spender) public view virtual override returns (uint256) {\\n return _allowances[owner][spender];\\n }\\n\\n /**\\n * @dev See {IERC20-approve}.\\n *\\n * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on\\n * `transferFrom`. This is semantically equivalent to an infinite approval.\\n *\\n * Requirements:\\n *\\n * - `spender` cannot be the zero address.\\n */\\n function approve(address spender, uint256 amount) public virtual override returns (bool) {\\n address owner = _msgSender();\\n _approve(owner, spender, amount);\\n return true;\\n }\\n\\n /**\\n * @dev See {IERC20-transferFrom}.\\n *\\n * Emits an {Approval} event indicating the updated allowance. This is not\\n * required by the EIP. See the note at the beginning of {ERC20}.\\n *\\n * NOTE: Does not update the allowance if the current allowance\\n * is the maximum `uint256`.\\n *\\n * Requirements:\\n *\\n * - `from` and `to` cannot be the zero address.\\n * - `from` must have a balance of at least `amount`.\\n * - the caller must have allowance for ``from``'s tokens of at least\\n * `amount`.\\n */\\n function transferFrom(\\n address from,\\n address to,\\n uint256 amount\\n ) public virtual override returns (bool) {\\n address spender = _msgSender();\\n _spendAllowance(from, spender, amount);\\n _transfer(from, to, amount);\\n return true;\\n }\\n\\n /**\\n * @dev Atomically increases the allowance granted to `spender` by the caller.\\n *\\n * This is an alternative to {approve} that can be used as a mitigation for\\n * problems described in {IERC20-approve}.\\n *\\n * Emits an {Approval} event indicating the updated allowance.\\n *\\n * Requirements:\\n *\\n * - `spender` cannot be the zero address.\\n */\\n function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {\\n address owner = _msgSender();\\n _approve(owner, spender, allowance(owner, spender) + addedValue);\\n return true;\\n }\\n\\n /**\\n * @dev Atomically decreases the allowance granted to `spender` by the caller.\\n *\\n * This is an alternative to {approve} that can be used as a mitigation for\\n * problems described in {IERC20-approve}.\\n *\\n * Emits an {Approval} event indicating the updated allowance.\\n *\\n * Requirements:\\n *\\n * - `spender` cannot be the zero address.\\n * - `spender` must have allowance for the caller of at least\\n * `subtractedValue`.\\n */\\n function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {\\n address owner = _msgSender();\\n uint256 currentAllowance = allowance(owner, spender);\\n require(currentAllowance >= subtractedValue, \\\"ERC20: decreased allowance below zero\\\");\\n unchecked {\\n _approve(owner, spender, currentAllowance - subtractedValue);\\n }\\n\\n return true;\\n }\\n\\n /**\\n * @dev Moves `amount` of tokens from `from` to `to`.\\n *\\n * This internal function is equivalent to {transfer}, and can be used to\\n * e.g. implement automatic token fees, slashing mechanisms, etc.\\n *\\n * Emits a {Transfer} event.\\n *\\n * Requirements:\\n *\\n * - `from` cannot be the zero address.\\n * - `to` cannot be the zero address.\\n * - `from` must have a balance of at least `amount`.\\n */\\n function _transfer(\\n address from,\\n address to,\\n uint256 amount\\n ) internal virtual {\\n require(from != address(0), \\\"ERC20: transfer from the zero address\\\");\\n require(to != address(0), \\\"ERC20: transfer to the zero address\\\");\\n\\n _beforeTokenTransfer(from, to, amount);\\n\\n uint256 fromBalance = _balances[from];\\n require(fromBalance >= amount, \\\"ERC20: transfer amount exceeds balance\\\");\\n unchecked {\\n _balances[from] = fromBalance - amount;\\n // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by\\n // decrementing then incrementing.\\n _balances[to] += amount;\\n }\\n\\n emit Transfer(from, to, amount);\\n\\n _afterTokenTransfer(from, to, amount);\\n }\\n\\n /** @dev Creates `amount` tokens and assigns them to `account`, increasing\\n * the total supply.\\n *\\n * Emits a {Transfer} event with `from` set to the zero address.\\n *\\n * Requirements:\\n *\\n * - `account` cannot be the zero address.\\n */\\n function _mint(address account, uint256 amount) internal virtual {\\n require(account != address(0), \\\"ERC20: mint to the zero address\\\");\\n\\n _beforeTokenTransfer(address(0), account, amount);\\n\\n _totalSupply += amount;\\n unchecked {\\n // Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.\\n _balances[account] += amount;\\n }\\n emit Transfer(address(0), account, amount);\\n\\n _afterTokenTransfer(address(0), account, amount);\\n }\\n\\n /**\\n * @dev Destroys `amount` tokens from `account`, reducing the\\n * total supply.\\n *\\n * Emits a {Transfer} event with `to` set to the zero address.\\n *\\n * Requirements:\\n *\\n * - `account` cannot be the zero address.\\n * - `account` must have at least `amount` tokens.\\n */\\n function _burn(address account, uint256 amount) internal virtual {\\n require(account != address(0), \\\"ERC20: burn from the zero address\\\");\\n\\n _beforeTokenTransfer(account, address(0), amount);\\n\\n uint256 accountBalance = _balances[account];\\n require(accountBalance >= amount, \\\"ERC20: burn amount exceeds balance\\\");\\n unchecked {\\n _balances[account] = accountBalance - amount;\\n // Overflow not possible: amount <= accountBalance <= totalSupply.\\n _totalSupply -= amount;\\n }\\n\\n emit Transfer(account, address(0), amount);\\n\\n _afterTokenTransfer(account, address(0), amount);\\n }\\n\\n /**\\n * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.\\n *\\n * This internal function is equivalent to `approve`, and can be used to\\n * e.g. set automatic allowances for certain subsystems, etc.\\n *\\n * Emits an {Approval} event.\\n *\\n * Requirements:\\n *\\n * - `owner` cannot be the zero address.\\n * - `spender` cannot be the zero address.\\n */\\n function _approve(\\n address owner,\\n address spender,\\n uint256 amount\\n ) internal virtual {\\n require(owner != address(0), \\\"ERC20: approve from the zero address\\\");\\n require(spender != address(0), \\\"ERC20: approve to the zero address\\\");\\n\\n _allowances[owner][spender] = amount;\\n emit Approval(owner, spender, amount);\\n }\\n\\n /**\\n * @dev Updates `owner` s allowance for `spender` based on spent `amount`.\\n *\\n * Does not update the allowance amount in case of infinite allowance.\\n * Revert if not enough allowance is available.\\n *\\n * Might emit an {Approval} event.\\n */\\n function _spendAllowance(\\n address owner,\\n address spender,\\n uint256 amount\\n ) internal virtual {\\n uint256 currentAllowance = allowance(owner, spender);\\n if (currentAllowance != type(uint256).max) {\\n require(currentAllowance >= amount, \\\"ERC20: insufficient allowance\\\");\\n unchecked {\\n _approve(owner, spender, currentAllowance - amount);\\n }\\n }\\n }\\n\\n /**\\n * @dev Hook that is called before any transfer of tokens. This includes\\n * minting and burning.\\n *\\n * Calling conditions:\\n *\\n * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\\n * will be transferred to `to`.\\n * - when `from` is zero, `amount` tokens will be minted for `to`.\\n * - when `to` is zero, `amount` of ``from``'s tokens will be burned.\\n * - `from` and `to` are never both zero.\\n *\\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\\n */\\n function _beforeTokenTransfer(\\n address from,\\n address to,\\n uint256 amount\\n ) internal virtual {}\\n\\n /**\\n * @dev Hook that is called after any transfer of tokens. This includes\\n * minting and burning.\\n *\\n * Calling conditions:\\n *\\n * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\\n * has been transferred to `to`.\\n * - when `from` is zero, `amount` tokens have been minted for `to`.\\n * - when `to` is zero, `amount` of ``from``'s tokens have been burned.\\n * - `from` and `to` are never both zero.\\n *\\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\\n */\\n function _afterTokenTransfer(\\n address from,\\n address to,\\n uint256 amount\\n ) internal virtual {}\\n}\\n\",\"keccak256\":\"0x4ffc0547c02ad22925310c585c0f166f8759e2648a09e9b489100c42f15dd98d\",\"license\":\"MIT\"},\"@openzeppelin/contracts/token/ERC20/IERC20.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Interface of the ERC20 standard as defined in the EIP.\\n */\\ninterface IERC20 {\\n /**\\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\\n * another (`to`).\\n *\\n * Note that `value` may be zero.\\n */\\n event Transfer(address indexed from, address indexed to, uint256 value);\\n\\n /**\\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\\n * a call to {approve}. `value` is the new allowance.\\n */\\n event Approval(address indexed owner, address indexed spender, uint256 value);\\n\\n /**\\n * @dev Returns the amount of tokens in existence.\\n */\\n function totalSupply() external view returns (uint256);\\n\\n /**\\n * @dev Returns the amount of tokens owned by `account`.\\n */\\n function balanceOf(address account) external view returns (uint256);\\n\\n /**\\n * @dev Moves `amount` tokens from the caller's account to `to`.\\n *\\n * Returns a boolean value indicating whether the operation succeeded.\\n *\\n * Emits a {Transfer} event.\\n */\\n function transfer(address to, uint256 amount) external returns (bool);\\n\\n /**\\n * @dev Returns the remaining number of tokens that `spender` will be\\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\\n * zero by default.\\n *\\n * This value changes when {approve} or {transferFrom} are called.\\n */\\n function allowance(address owner, address spender) external view returns (uint256);\\n\\n /**\\n * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\\n *\\n * Returns a boolean value indicating whether the operation succeeded.\\n *\\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\\n * that someone may use both the old and the new allowance by unfortunate\\n * transaction ordering. One possible solution to mitigate this race\\n * condition is to first reduce the spender's allowance to 0 and set the\\n * desired value afterwards:\\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\\n *\\n * Emits an {Approval} event.\\n */\\n function approve(address spender, uint256 amount) external returns (bool);\\n\\n /**\\n * @dev Moves `amount` tokens from `from` to `to` using the\\n * allowance mechanism. `amount` is then deducted from the caller's\\n * allowance.\\n *\\n * Returns a boolean value indicating whether the operation succeeded.\\n *\\n * Emits a {Transfer} event.\\n */\\n function transferFrom(\\n address from,\\n address to,\\n uint256 amount\\n ) external returns (bool);\\n}\\n\",\"keccak256\":\"0x9750c6b834f7b43000631af5cc30001c5f547b3ceb3635488f140f60e897ea6b\",\"license\":\"MIT\"},\"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"../IERC20.sol\\\";\\n\\n/**\\n * @dev Interface for the optional metadata functions from the ERC20 standard.\\n *\\n * _Available since v4.1._\\n */\\ninterface IERC20Metadata is IERC20 {\\n /**\\n * @dev Returns the name of the token.\\n */\\n function name() external view returns (string memory);\\n\\n /**\\n * @dev Returns the symbol of the token.\\n */\\n function symbol() external view returns (string memory);\\n\\n /**\\n * @dev Returns the decimals places of the token.\\n */\\n function decimals() external view returns (uint8);\\n}\\n\",\"keccak256\":\"0x8de418a5503946cabe331f35fe242d3201a73f67f77aaeb7110acb1f30423aca\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/Context.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Provides information about the current execution context, including the\\n * sender of the transaction and its data. While these are generally available\\n * via msg.sender and msg.data, they should not be accessed in such a direct\\n * manner, since when dealing with meta-transactions the account sending and\\n * paying for execution may not be the actual sender (as far as an application\\n * is concerned).\\n *\\n * This contract is only required for intermediate, library-like contracts.\\n */\\nabstract contract Context {\\n function _msgSender() internal view virtual returns (address) {\\n return msg.sender;\\n }\\n\\n function _msgData() internal view virtual returns (bytes calldata) {\\n return msg.data;\\n }\\n}\\n\",\"keccak256\":\"0xe2e337e6dde9ef6b680e07338c493ebea1b5fd09b43424112868e9cc1706bca7\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/Strings.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./math/Math.sol\\\";\\n\\n/**\\n * @dev String operations.\\n */\\nlibrary Strings {\\n bytes16 private constant _SYMBOLS = \\\"0123456789abcdef\\\";\\n uint8 private constant _ADDRESS_LENGTH = 20;\\n\\n /**\\n * @dev Converts a `uint256` to its ASCII `string` decimal representation.\\n */\\n function toString(uint256 value) internal pure returns (string memory) {\\n unchecked {\\n uint256 length = Math.log10(value) + 1;\\n string memory buffer = new string(length);\\n uint256 ptr;\\n /// @solidity memory-safe-assembly\\n assembly {\\n ptr := add(buffer, add(32, length))\\n }\\n while (true) {\\n ptr--;\\n /// @solidity memory-safe-assembly\\n assembly {\\n mstore8(ptr, byte(mod(value, 10), _SYMBOLS))\\n }\\n value /= 10;\\n if (value == 0) break;\\n }\\n return buffer;\\n }\\n }\\n\\n /**\\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\\n */\\n function toHexString(uint256 value) internal pure returns (string memory) {\\n unchecked {\\n return toHexString(value, Math.log256(value) + 1);\\n }\\n }\\n\\n /**\\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\\n */\\n function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\\n bytes memory buffer = new bytes(2 * length + 2);\\n buffer[0] = \\\"0\\\";\\n buffer[1] = \\\"x\\\";\\n for (uint256 i = 2 * length + 1; i > 1; --i) {\\n buffer[i] = _SYMBOLS[value & 0xf];\\n value >>= 4;\\n }\\n require(value == 0, \\\"Strings: hex length insufficient\\\");\\n return string(buffer);\\n }\\n\\n /**\\n * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.\\n */\\n function toHexString(address addr) internal pure returns (string memory) {\\n return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);\\n }\\n}\\n\",\"keccak256\":\"0xa4d1d62251f8574deb032a35fc948386a9b4de74b812d4f545a1ac120486b48a\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/introspection/ERC165.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./IERC165.sol\\\";\\n\\n/**\\n * @dev Implementation of the {IERC165} interface.\\n *\\n * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check\\n * for the additional interface id that will be supported. For example:\\n *\\n * ```solidity\\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\\n * }\\n * ```\\n *\\n * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.\\n */\\nabstract contract ERC165 is IERC165 {\\n /**\\n * @dev See {IERC165-supportsInterface}.\\n */\\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n return interfaceId == type(IERC165).interfaceId;\\n }\\n}\\n\",\"keccak256\":\"0xd10975de010d89fd1c78dc5e8a9a7e7f496198085c151648f20cba166b32582b\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/introspection/IERC165.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Interface of the ERC165 standard, as defined in the\\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\\n *\\n * Implementers can declare support of contract interfaces, which can then be\\n * queried by others ({ERC165Checker}).\\n *\\n * For an implementation, see {ERC165}.\\n */\\ninterface IERC165 {\\n /**\\n * @dev Returns true if this contract implements the interface defined by\\n * `interfaceId`. See the corresponding\\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\\n * to learn more about how these ids are created.\\n *\\n * This function call must use less than 30 000 gas.\\n */\\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\\n}\\n\",\"keccak256\":\"0x447a5f3ddc18419d41ff92b3773fb86471b1db25773e07f877f548918a185bf1\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/math/Math.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Standard math utilities missing in the Solidity language.\\n */\\nlibrary Math {\\n enum Rounding {\\n Down, // Toward negative infinity\\n Up, // Toward infinity\\n Zero // Toward zero\\n }\\n\\n /**\\n * @dev Returns the largest of two numbers.\\n */\\n function max(uint256 a, uint256 b) internal pure returns (uint256) {\\n return a > b ? a : b;\\n }\\n\\n /**\\n * @dev Returns the smallest of two numbers.\\n */\\n function min(uint256 a, uint256 b) internal pure returns (uint256) {\\n return a < b ? a : b;\\n }\\n\\n /**\\n * @dev Returns the average of two numbers. The result is rounded towards\\n * zero.\\n */\\n function average(uint256 a, uint256 b) internal pure returns (uint256) {\\n // (a + b) / 2 can overflow.\\n return (a & b) + (a ^ b) / 2;\\n }\\n\\n /**\\n * @dev Returns the ceiling of the division of two numbers.\\n *\\n * This differs from standard division with `/` in that it rounds up instead\\n * of rounding down.\\n */\\n function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {\\n // (a + b - 1) / b can overflow on addition, so we distribute.\\n return a == 0 ? 0 : (a - 1) / b + 1;\\n }\\n\\n /**\\n * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0\\n * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)\\n * with further edits by Uniswap Labs also under MIT license.\\n */\\n function mulDiv(\\n uint256 x,\\n uint256 y,\\n uint256 denominator\\n ) internal pure returns (uint256 result) {\\n unchecked {\\n // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use\\n // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256\\n // variables such that product = prod1 * 2^256 + prod0.\\n uint256 prod0; // Least significant 256 bits of the product\\n uint256 prod1; // Most significant 256 bits of the product\\n assembly {\\n let mm := mulmod(x, y, not(0))\\n prod0 := mul(x, y)\\n prod1 := sub(sub(mm, prod0), lt(mm, prod0))\\n }\\n\\n // Handle non-overflow cases, 256 by 256 division.\\n if (prod1 == 0) {\\n return prod0 / denominator;\\n }\\n\\n // Make sure the result is less than 2^256. Also prevents denominator == 0.\\n require(denominator > prod1);\\n\\n ///////////////////////////////////////////////\\n // 512 by 256 division.\\n ///////////////////////////////////////////////\\n\\n // Make division exact by subtracting the remainder from [prod1 prod0].\\n uint256 remainder;\\n assembly {\\n // Compute remainder using mulmod.\\n remainder := mulmod(x, y, denominator)\\n\\n // Subtract 256 bit number from 512 bit number.\\n prod1 := sub(prod1, gt(remainder, prod0))\\n prod0 := sub(prod0, remainder)\\n }\\n\\n // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.\\n // See https://cs.stackexchange.com/q/138556/92363.\\n\\n // Does not overflow because the denominator cannot be zero at this stage in the function.\\n uint256 twos = denominator & (~denominator + 1);\\n assembly {\\n // Divide denominator by twos.\\n denominator := div(denominator, twos)\\n\\n // Divide [prod1 prod0] by twos.\\n prod0 := div(prod0, twos)\\n\\n // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.\\n twos := add(div(sub(0, twos), twos), 1)\\n }\\n\\n // Shift in bits from prod1 into prod0.\\n prod0 |= prod1 * twos;\\n\\n // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such\\n // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for\\n // four bits. That is, denominator * inv = 1 mod 2^4.\\n uint256 inverse = (3 * denominator) ^ 2;\\n\\n // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works\\n // in modular arithmetic, doubling the correct bits in each step.\\n inverse *= 2 - denominator * inverse; // inverse mod 2^8\\n inverse *= 2 - denominator * inverse; // inverse mod 2^16\\n inverse *= 2 - denominator * inverse; // inverse mod 2^32\\n inverse *= 2 - denominator * inverse; // inverse mod 2^64\\n inverse *= 2 - denominator * inverse; // inverse mod 2^128\\n inverse *= 2 - denominator * inverse; // inverse mod 2^256\\n\\n // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.\\n // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is\\n // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1\\n // is no longer required.\\n result = prod0 * inverse;\\n return result;\\n }\\n }\\n\\n /**\\n * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.\\n */\\n function mulDiv(\\n uint256 x,\\n uint256 y,\\n uint256 denominator,\\n Rounding rounding\\n ) internal pure returns (uint256) {\\n uint256 result = mulDiv(x, y, denominator);\\n if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {\\n result += 1;\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.\\n *\\n * Inspired by Henry S. Warren, Jr.'s \\\"Hacker's Delight\\\" (Chapter 11).\\n */\\n function sqrt(uint256 a) internal pure returns (uint256) {\\n if (a == 0) {\\n return 0;\\n }\\n\\n // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.\\n //\\n // We know that the \\\"msb\\\" (most significant bit) of our target number `a` is a power of 2 such that we have\\n // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.\\n //\\n // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`\\n // \\u2192 `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`\\n // \\u2192 `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`\\n //\\n // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.\\n uint256 result = 1 << (log2(a) >> 1);\\n\\n // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,\\n // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at\\n // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision\\n // into the expected uint128 result.\\n unchecked {\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n return min(result, a / result);\\n }\\n }\\n\\n /**\\n * @notice Calculates sqrt(a), following the selected rounding direction.\\n */\\n function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = sqrt(a);\\n return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);\\n }\\n }\\n\\n /**\\n * @dev Return the log in base 2, rounded down, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log2(uint256 value) internal pure returns (uint256) {\\n uint256 result = 0;\\n unchecked {\\n if (value >> 128 > 0) {\\n value >>= 128;\\n result += 128;\\n }\\n if (value >> 64 > 0) {\\n value >>= 64;\\n result += 64;\\n }\\n if (value >> 32 > 0) {\\n value >>= 32;\\n result += 32;\\n }\\n if (value >> 16 > 0) {\\n value >>= 16;\\n result += 16;\\n }\\n if (value >> 8 > 0) {\\n value >>= 8;\\n result += 8;\\n }\\n if (value >> 4 > 0) {\\n value >>= 4;\\n result += 4;\\n }\\n if (value >> 2 > 0) {\\n value >>= 2;\\n result += 2;\\n }\\n if (value >> 1 > 0) {\\n result += 1;\\n }\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Return the log in base 2, following the selected rounding direction, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = log2(value);\\n return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);\\n }\\n }\\n\\n /**\\n * @dev Return the log in base 10, rounded down, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log10(uint256 value) internal pure returns (uint256) {\\n uint256 result = 0;\\n unchecked {\\n if (value >= 10**64) {\\n value /= 10**64;\\n result += 64;\\n }\\n if (value >= 10**32) {\\n value /= 10**32;\\n result += 32;\\n }\\n if (value >= 10**16) {\\n value /= 10**16;\\n result += 16;\\n }\\n if (value >= 10**8) {\\n value /= 10**8;\\n result += 8;\\n }\\n if (value >= 10**4) {\\n value /= 10**4;\\n result += 4;\\n }\\n if (value >= 10**2) {\\n value /= 10**2;\\n result += 2;\\n }\\n if (value >= 10**1) {\\n result += 1;\\n }\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = log10(value);\\n return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);\\n }\\n }\\n\\n /**\\n * @dev Return the log in base 256, rounded down, of a positive value.\\n * Returns 0 if given 0.\\n *\\n * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.\\n */\\n function log256(uint256 value) internal pure returns (uint256) {\\n uint256 result = 0;\\n unchecked {\\n if (value >> 128 > 0) {\\n value >>= 128;\\n result += 16;\\n }\\n if (value >> 64 > 0) {\\n value >>= 64;\\n result += 8;\\n }\\n if (value >> 32 > 0) {\\n value >>= 32;\\n result += 4;\\n }\\n if (value >> 16 > 0) {\\n value >>= 16;\\n result += 2;\\n }\\n if (value >> 8 > 0) {\\n result += 1;\\n }\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = log256(value);\\n return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);\\n }\\n }\\n}\\n\",\"keccak256\":\"0xa1e8e83cd0087785df04ac79fb395d9f3684caeaf973d9e2c71caef723a3a5d6\",\"license\":\"MIT\"},\"src/Staking.sol\":{\"content\":\"// SPDX-License-Identifier: BSD-3-Clause\\npragma solidity ^0.8.19;\\nimport \\\"@openzeppelin/contracts/token/ERC20/ERC20.sol\\\";\\nimport \\\"@openzeppelin/contracts/access/AccessControl.sol\\\";\\nimport \\\"@openzeppelin/contracts/security/Pausable.sol\\\";\\n\\ninterface IPriceOracle {\\n function currentPrice() external view returns (uint32);\\n}\\n\\n/**\\n * @title Staking contract for the Swarm storage incentives\\n * @author The Swarm Authors\\n * @dev Allows users to stake tokens in order to be eligible for the Redistribution Schelling co-ordination game.\\n * Stakes are frozen or slashed by the Redistribution contract in response to violations of the\\n * protocol.\\n */\\n\\ncontract StakeRegistry is AccessControl, Pausable {\\n // ----------------------------- State variables ------------------------------\\n\\n struct Stake {\\n // Overlay of the node that is being staked\\n bytes32 overlay;\\n // Stake balance expressed through price oracle\\n uint256 committedStake;\\n // Stake balance expressed in BZZ\\n uint256 potentialStake;\\n // Block height the stake was updated\\n uint256 lastUpdatedBlockNumber;\\n // Used to indicate presents in stakes struct\\n bool isValue;\\n }\\n\\n // Associate every stake id with node address data.\\n mapping(address => Stake) public stakes;\\n\\n // Role allowed to pause\\n bytes32 public constant PAUSER_ROLE = keccak256(\\\"PAUSER_ROLE\\\");\\n // Role allowed to freeze and slash entries\\n bytes32 public constant REDISTRIBUTOR_ROLE = keccak256(\\\"REDISTRIBUTOR_ROLE\\\");\\n\\n // Swarm network ID\\n uint64 NetworkId;\\n\\n // The miniumum stake allowed to be staked using the Staking contract.\\n uint64 private constant MIN_STAKE = 100000000000000000;\\n\\n // Address of the staked ERC20 token\\n address public immutable bzzToken;\\n\\n // The address of the linked PriceOracle contract.\\n IPriceOracle public OracleContract;\\n\\n // ----------------------------- Events ------------------------------\\n\\n /**\\n * @dev Emitted when a stake is created or updated by `owner` of the `overlay` by `committedStake`, and `potentialStake` during `lastUpdatedBlock`.\\n */\\n event StakeUpdated(\\n address indexed owner,\\n uint256 committedStake,\\n uint256 potentialStake,\\n bytes32 overlay,\\n uint256 lastUpdatedBlock\\n );\\n\\n /**\\n * @dev Emitted when a stake for address `slashed` is slashed by `amount`.\\n */\\n event StakeSlashed(address slashed, bytes32 overlay, uint256 amount);\\n\\n /**\\n * @dev Emitted when a stake for address `frozen` is frozen for `time` blocks.\\n */\\n event StakeFrozen(address frozen, bytes32 overlay, uint256 time);\\n\\n /**\\n * @dev Emitted when a address changes overlay it uses\\n */\\n event OverlayChanged(address owner, bytes32 overlay);\\n\\n /**\\n * @dev Emitted when a stake for address is withdrawn\\n */\\n event StakeWithdrawn(address node, uint256 amount);\\n\\n // ----------------------------- Errors ------------------------------\\n\\n error TransferFailed(); // Used when token transfers fail\\n error Frozen(); // Used when an action cannot proceed because the overlay is frozen\\n error Unauthorized(); // Used where only the owner can perform the action\\n error OnlyRedistributor(); // Used when only the redistributor role is allowed\\n error OnlyPauser(); // Used when only the pauser role is allowed\\n error BelowMinimumStake(); // Node participating in game has stake below minimum treshold\\n\\n // ----------------------------- CONSTRUCTOR ------------------------------\\n\\n /**\\n * @param _bzzToken Address of the staked ERC20 token\\n * @param _NetworkId Swarm network ID\\n */\\n constructor(address _bzzToken, uint64 _NetworkId, address _oracleContract) {\\n NetworkId = _NetworkId;\\n bzzToken = _bzzToken;\\n OracleContract = IPriceOracle(_oracleContract);\\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\\n _setupRole(PAUSER_ROLE, msg.sender);\\n }\\n\\n ////////////////////////////////////////\\n // STATE SETTING //\\n ////////////////////////////////////////\\n\\n /**\\n * @notice Create a new stake or update an existing one, change overlay of node\\n * @dev At least `_initialBalancePerChunk*2^depth` number of tokens need to be preapproved for this contract.\\n * @param _setNonce Nonce that was used for overlay calculation.\\n * @param _addAmount Deposited amount of ERC20 tokens, equals to added Potential stake value\\n */\\n function manageStake(bytes32 _setNonce, uint256 _addAmount) external whenNotPaused {\\n bytes32 _previousOverlay = stakes[msg.sender].overlay;\\n bool _stakingSet = stakes[msg.sender].isValue;\\n bytes32 _newOverlay = keccak256(abi.encodePacked(msg.sender, reverse(NetworkId), _setNonce));\\n uint256 _addCommittedStake = _addAmount / OracleContract.currentPrice(); // losing some decimals from start 10n16 becomes 99999999999984000\\n\\n // First time adding stake, check the minimum is added\\n if (_addAmount < MIN_STAKE && !_stakingSet) {\\n revert BelowMinimumStake();\\n }\\n\\n if (_stakingSet && !addressNotFrozen(msg.sender)) revert Frozen();\\n uint256 updatedCommittedStake = stakes[msg.sender].committedStake + _addCommittedStake;\\n uint256 updatedPotentialStake = stakes[msg.sender].potentialStake + _addAmount;\\n\\n stakes[msg.sender] = Stake({\\n overlay: _newOverlay,\\n committedStake: updatedCommittedStake,\\n potentialStake: updatedPotentialStake,\\n lastUpdatedBlockNumber: block.number,\\n isValue: true\\n });\\n\\n // Transfer tokens and emit event that stake has been updated\\n if (_addAmount > 0) {\\n if (!ERC20(bzzToken).transferFrom(msg.sender, address(this), _addAmount)) revert TransferFailed();\\n emit StakeUpdated(msg.sender, updatedCommittedStake, updatedPotentialStake, _newOverlay, block.number);\\n }\\n\\n // Emit overlay change event\\n if (_previousOverlay != _newOverlay) {\\n emit OverlayChanged(msg.sender, _newOverlay);\\n }\\n }\\n\\n /**\\n * @dev Withdraw node stake surplus\\n */\\n function withdrawFromStake() external {\\n uint256 _potentialStake = stakes[msg.sender].potentialStake;\\n uint256 _surplusStake = _potentialStake -\\n calculateEffectiveStake(stakes[msg.sender].committedStake, _potentialStake);\\n\\n if (_surplusStake > 0) {\\n stakes[msg.sender].potentialStake -= _surplusStake;\\n if (!ERC20(bzzToken).transfer(msg.sender, _surplusStake)) revert TransferFailed();\\n emit StakeWithdrawn(msg.sender, _surplusStake);\\n }\\n }\\n\\n /**\\n * @dev Migrate stake only when the staking contract is paused,\\n * can only be called by the owner of the stake\\n */\\n function migrateStake() external whenPaused {\\n // We take out all the stake so user can migrate stake to other contract\\n if (lastUpdatedBlockNumberOfAddress(msg.sender) != 0) {\\n if (!ERC20(bzzToken).transfer(msg.sender, stakes[msg.sender].potentialStake)) revert TransferFailed();\\n delete stakes[msg.sender];\\n }\\n }\\n\\n /**\\n * @dev Freeze an existing stake, can only be called by the redistributor\\n * @param _owner the addres selected\\n * @param _time penalty length in blocknumbers\\n */\\n function freezeDeposit(address _owner, uint256 _time) external {\\n if (!hasRole(REDISTRIBUTOR_ROLE, msg.sender)) revert OnlyRedistributor();\\n\\n if (stakes[_owner].isValue) {\\n stakes[_owner].lastUpdatedBlockNumber = block.number + _time;\\n emit StakeFrozen(_owner, stakes[_owner].overlay, _time);\\n }\\n }\\n\\n /**\\n * @dev Slash an existing stake, can only be called by the `redistributor`\\n * @param _owner the _owner adress selected\\n * @param _amount the amount to be slashed\\n */\\n function slashDeposit(address _owner, uint256 _amount) external {\\n if (!hasRole(REDISTRIBUTOR_ROLE, msg.sender)) revert OnlyRedistributor();\\n\\n if (stakes[_owner].isValue) {\\n if (stakes[_owner].potentialStake > _amount) {\\n stakes[_owner].potentialStake -= _amount;\\n stakes[_owner].lastUpdatedBlockNumber = block.number;\\n } else {\\n delete stakes[_owner];\\n }\\n }\\n emit StakeSlashed(_owner, stakes[_owner].overlay, _amount);\\n }\\n\\n function changeNetworkId(uint64 _NetworkId) external {\\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) revert Unauthorized();\\n NetworkId = _NetworkId;\\n }\\n\\n /**\\n * @dev Pause the contract. The contract is provably stopped by renouncing\\n the pauser role and the admin role after pausing, can only be called by the `PAUSER`\\n */\\n function pause() public {\\n if (!hasRole(PAUSER_ROLE, msg.sender)) revert OnlyPauser();\\n _pause();\\n }\\n\\n /**\\n * @dev Unpause the contract, can only be called by the pauser when paused\\n */\\n function unPause() public {\\n if (!hasRole(PAUSER_ROLE, msg.sender)) revert OnlyPauser();\\n _unpause();\\n }\\n\\n ////////////////////////////////////////\\n // STATE READING //\\n ////////////////////////////////////////\\n\\n /**\\n * @dev Checks to see if `address` is frozen.\\n * @param _owner owner of staked address\\n *\\n * Returns a boolean value indicating whether the operation succeeded.\\n */\\n function addressNotFrozen(address _owner) internal view returns (bool) {\\n return stakes[_owner].lastUpdatedBlockNumber < block.number;\\n }\\n\\n /**\\n * @dev Returns the current `effectiveStake` of `address`. previously usable stake\\n * @param _owner _owner of node\\n */\\n function nodeEffectiveStake(address _owner) public view returns (uint256) {\\n return\\n addressNotFrozen(_owner)\\n ? calculateEffectiveStake(stakes[_owner].committedStake, stakes[_owner].potentialStake)\\n : 0;\\n }\\n\\n /**\\n * @dev Check the amount that is possible to withdraw as surplus\\n */\\n function withdrawableStake() public view returns (uint256) {\\n uint256 _potentialStake = stakes[msg.sender].potentialStake;\\n return _potentialStake - calculateEffectiveStake(stakes[msg.sender].committedStake, _potentialStake);\\n }\\n\\n /**\\n * @dev Returns the `lastUpdatedBlockNumber` of `address`.\\n */\\n function lastUpdatedBlockNumberOfAddress(address _owner) public view returns (uint256) {\\n return stakes[_owner].lastUpdatedBlockNumber;\\n }\\n\\n /**\\n * @dev Returns the currently used overlay of the address.\\n * @param _owner address of node\\n */\\n function overlayOfAddress(address _owner) public view returns (bytes32) {\\n return stakes[_owner].overlay;\\n }\\n\\n function calculateEffectiveStake(\\n uint256 committedStake,\\n uint256 potentialStakeBalance\\n ) internal view returns (uint256) {\\n // Calculate the product of committedStake and unitPrice to get price in BZZ\\n uint256 committedStakeBzz = committedStake * OracleContract.currentPrice();\\n\\n // Return the minimum value between committedStakeBzz and potentialStakeBalance\\n if (committedStakeBzz < potentialStakeBalance) {\\n return committedStakeBzz;\\n } else {\\n return potentialStakeBalance;\\n }\\n }\\n\\n /**\\n * @dev Please both Endians \\ud83e\\udd5a.\\n * @param input Eth address used for overlay calculation.\\n */\\n function reverse(uint64 input) internal pure returns (uint64 v) {\\n v = input;\\n\\n // swap bytes\\n v = ((v & 0xFF00FF00FF00FF00) >> 8) | ((v & 0x00FF00FF00FF00FF) << 8);\\n\\n // swap 2-byte long pairs\\n v = ((v & 0xFFFF0000FFFF0000) >> 16) | ((v & 0x0000FFFF0000FFFF) << 16);\\n\\n // swap 4-byte long pairs\\n v = (v >> 32) | (v << 32);\\n }\\n}\\n\",\"keccak256\":\"0xd803f0304eb3b22e7691103cec8503b9aa24ad27b7812c498f7be1e709e32944\",\"license\":\"BSD-3-Clause\"}},\"version\":1}", - "bytecode": "0x60a06040523480156200001157600080fd5b5060405162001b6d38038062001b6d833981016040819052620000349162000186565b6001805460ff19169055600380546001600160a01b03808616608052831668010000000000000000026001600160e01b03199091166001600160401b0385161717905562000084600033620000b9565b620000b07f65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a33620000b9565b505050620001de565b620000c58282620000c9565b5050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16620000c5576000828152602081815260408083206001600160a01b03851684529091529020805460ff19166001179055620001253390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b80516001600160a01b03811681146200018157600080fd5b919050565b6000806000606084860312156200019c57600080fd5b620001a78462000169565b60208501519093506001600160401b0381168114620001c557600080fd5b9150620001d56040850162000169565b90509250925092565b60805161195e6200020f600039600081816102bb015281816105610152818161093c0152610ae0015261195e6000f3fe608060405234801561001057600080fd5b50600436106101a35760003560e01c8063830a053e116100ee578063d009b2d611610097578063d547741f11610071578063d547741f14610423578063e63ab1e914610436578063e8e8d87e1461045d578063f7b188a51461047057600080fd5b8063d009b2d6146103d1578063d1052d1f146103e4578063d48bfaeb1461041057600080fd5b806397adedb5116100c857806397adedb514610379578063a217fddf146103a2578063a6471a1d146103aa57600080fd5b8063830a053e146103275780638456cb591461033a57806391d148541461034257600080fd5b80632f2ff15d116101505780635c975abb1161012a5780635c975abb146102f557806369da9114146103005780636f1c5de71461031f57600080fd5b80632f2ff15d1461029057806336568abe146102a3578063420fc4db146102b657600080fd5b806312236a771161018157806312236a77146101ed57806316934fc4146101f5578063248a9ca31461025f57600080fd5b806301ffc9a7146101a85780630aed7b0d146101d057806310ae2147146101da575b600080fd5b6101bb6101b636600461161c565b610478565b60405190151581526020015b60405180910390f35b6101d8610511565b005b6101d86101e836600461165e565b61062a565b6101d8610a63565b61023561020336600461169c565b600260208190526000918252604090912080546001820154928201546003830154600490930154919392909160ff1685565b6040805195865260208601949094529284019190915260608301521515608082015260a0016101c7565b61028261026d3660046116b7565b60009081526020819052604090206001015490565b6040519081526020016101c7565b6101d861029e3660046116d0565b610bb1565b6101d86102b13660046116d0565b610bdb565b6102dd7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b0390911681526020016101c7565b60015460ff166101bb565b6003546102dd906801000000000000000090046001600160a01b031681565b610282610c68565b61028261033536600461169c565b610c9d565b6101d8610cf3565b6101bb6103503660046116d0565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b61028261038736600461169c565b6001600160a01b031660009081526002602052604090205490565b610282600081565b6102827f3e35b14a9f4fef84b59f9bdcd3044fc28783144b7e42bfb2cd075e6a02cb082881565b6101d86103df3660046116fc565b610d4a565b6102826103f236600461169c565b6001600160a01b031660009081526002602052604090206003015490565b6101d861041e366004611726565b610e29565b6101d86104313660046116d0565b610eb5565b6102827f65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a81565b6101d861046b3660046116fc565b610eda565b6101d8611058565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f7965db0b00000000000000000000000000000000000000000000000000000000148061050b57507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008316145b92915050565b6105196110af565b336000908152600260205260409020600301541561062857336000818152600260208190526040918290200154905163a9059cbb60e01b8152600481019290925260248201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063a9059cbb906044016020604051808303816000875af11580156105b2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105d69190611750565b6105f3576040516312171d8360e31b815260040160405180910390fd5b3360009081526002602081905260408220828155600181018390559081018290556003810191909155600401805460ff191690555b565b610632611101565b33600081815260026020908152604082208054600490910154600354919460ff9091169392909165ff000000ff00600882811b91821664ff000000ff9390911c92831617601090811b67ff000000ff0000009290921666ff000000ff0000939093169290921790911c1780821b6bffffffffffffffff0000000016911c63ffffffff161760405160609290921b6bffffffffffffffffffffffff1916602083015260c01b7fffffffffffffffff000000000000000000000000000000000000000000000000166034820152603c8101869052605c016040516020818303038152906040528051906020012090506000600360089054906101000a90046001600160a01b03166001600160a01b0316639d1b464a6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610774573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107989190611772565b6107a89063ffffffff16866117ae565b905067016345785d8a0000851080156107bf575082155b156107f6576040517f8ecf3d0300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8280156108155750336000908152600260205260409020600301544311155b1561084c576040517fa8cab3d100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b3360009081526002602052604081206001015461086a9083906117d0565b336000908152600260208190526040822001549192509061088c9088906117d0565b6040805160a081018252868152602080820186815282840185815243606085019081526001608086018181523360009081526002968790529790972095518655925192850192909255519183019190915551600382015590516004909101805460ff191691151591909117905590508615610a18576040517f23b872dd000000000000000000000000000000000000000000000000000000008152336004820152306024820152604481018890527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906323b872dd906064016020604051808303816000875af115801561098d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109b19190611750565b6109ce576040516312171d8360e31b815260040160405180910390fd5b604080518381526020810183905290810185905243606082015233907ff3fb57c8e9287d05c0b3c8612031896c43149edcf7ca6f1b287ac836b4b5d5699060800160405180910390a25b838614610a595760408051338152602081018690527fe188baf4bcb1c4413d19ba0eaef908614d30e8df9570d6fc4d584b75f4a37a3a910160405180910390a15b5050505050505050565b336000908152600260208190526040822090810154600190910154909190610a8b9083611154565b610a9590836117e3565b90508015610bad573360009081526002602081905260408220018054839290610abf9084906117e3565b909155505060405163a9059cbb60e01b8152336004820152602481018290527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063a9059cbb906044016020604051808303816000875af1158015610b31573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b559190611750565b610b72576040516312171d8360e31b815260040160405180910390fd5b60408051338152602081018390527f8108595eb6bad3acefa9da467d90cc2217686d5c5ac85460f8b7849c840645fc91015b60405180910390a15b5050565b600082815260208190526040902060010154610bcc816111f8565b610bd68383611205565b505050565b6001600160a01b0381163314610c5e5760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b610bad82826112a3565b336000908152600260208190526040822090810154600190910154610c8d9082611154565b610c9790826117e3565b91505090565b6001600160a01b0381166000908152600260205260408120600301544311610cc657600061050b565b6001600160a01b0382166000908152600260208190526040909120600181015491015461050b9190611154565b3360009081527ff7c9542c591017a21c74b6f3fab6263c7952fc0aaf9db4c22a2a04ddc7f8674f602052604090205460ff16610d4257604051631d77d47760e21b815260040160405180910390fd5b610628611322565b3360009081527f10fa80d2e578284bf61a483a3da84fbdd683a7e7256a9895dc4461ac543f4a16602052604090205460ff16610d9957604051630490edbf60e31b815260040160405180910390fd5b6001600160a01b03821660009081526002602052604090206004015460ff1615610bad57610dc781436117d0565b6001600160a01b038316600081815260026020908152604091829020600381019490945592548151928352928201929092529081018290527fd7863535575e7de6678ea9d340a4bfe0b84d77323bfa2ef602c3c1df82aea78090606001610ba4565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff16610e91576040517f82b4290000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6003805467ffffffffffffffff191667ffffffffffffffff92909216919091179055565b600082815260208190526040902060010154610ed0816111f8565b610bd683836112a3565b3360009081527f10fa80d2e578284bf61a483a3da84fbdd683a7e7256a9895dc4461ac543f4a16602052604090205460ff16610f2957604051630490edbf60e31b815260040160405180910390fd5b6001600160a01b03821660009081526002602052604090206004015460ff1615611003576001600160a01b03821660009081526002602081905260409091200154811015610fc5576001600160a01b03821660009081526002602081905260408220018054839290610f9c9084906117e3565b90915550506001600160a01b038216600090815260026020526040902043600390910155611003565b6001600160a01b03821660009081526002602081905260408220828155600181018390559081018290556003810191909155600401805460ff191690555b6001600160a01b0382166000818152600260209081526040918290205482519384529083015281018290527f5f52ce031e6eba64e8a81288196b93a3e422096e80aea812f1f5a77866359b3a90606001610ba4565b3360009081527ff7c9542c591017a21c74b6f3fab6263c7952fc0aaf9db4c22a2a04ddc7f8674f602052604090205460ff166110a757604051631d77d47760e21b815260040160405180910390fd5b610628611376565b60015460ff166106285760405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f74207061757365640000000000000000000000006044820152606401610c55565b60015460ff16156106285760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a20706175736564000000000000000000000000000000006044820152606401610c55565b600080600360089054906101000a90046001600160a01b03166001600160a01b0316639d1b464a6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156111aa573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111ce9190611772565b6111de9063ffffffff16856117f6565b9050828110156111ef57905061050b565b8291505061050b565b61120281336113af565b50565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610bad576000828152602081815260408083206001600160a01b03851684529091529020805460ff1916600117905561125f3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1615610bad576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b61132a611101565b6001805460ff1916811790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258335b6040516001600160a01b03909116815260200160405180910390a1565b61137e6110af565b6001805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa33611359565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610bad576113e081611422565b6113eb836020611434565b6040516020016113fc929190611831565b60408051601f198184030181529082905262461bcd60e51b8252610c55916004016118b2565b606061050b6001600160a01b03831660145b606060006114438360026117f6565b61144e9060026117d0565b67ffffffffffffffff811115611466576114666118e5565b6040519080825280601f01601f191660200182016040528015611490576020820181803683370190505b5090507f3000000000000000000000000000000000000000000000000000000000000000816000815181106114c7576114c76118fb565b60200101906001600160f81b031916908160001a9053507f780000000000000000000000000000000000000000000000000000000000000081600181518110611512576115126118fb565b60200101906001600160f81b031916908160001a90535060006115368460026117f6565b6115419060016117d0565b90505b60018111156115c6577f303132333435363738396162636465660000000000000000000000000000000085600f1660108110611582576115826118fb565b1a60f81b828281518110611598576115986118fb565b60200101906001600160f81b031916908160001a90535060049490941c936115bf81611911565b9050611544565b5083156116155760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610c55565b9392505050565b60006020828403121561162e57600080fd5b81357fffffffff000000000000000000000000000000000000000000000000000000008116811461161557600080fd5b6000806040838503121561167157600080fd5b50508035926020909101359150565b80356001600160a01b038116811461169757600080fd5b919050565b6000602082840312156116ae57600080fd5b61161582611680565b6000602082840312156116c957600080fd5b5035919050565b600080604083850312156116e357600080fd5b823591506116f360208401611680565b90509250929050565b6000806040838503121561170f57600080fd5b61171883611680565b946020939093013593505050565b60006020828403121561173857600080fd5b813567ffffffffffffffff8116811461161557600080fd5b60006020828403121561176257600080fd5b8151801515811461161557600080fd5b60006020828403121561178457600080fd5b815163ffffffff8116811461161557600080fd5b634e487b7160e01b600052601160045260246000fd5b6000826117cb57634e487b7160e01b600052601260045260246000fd5b500490565b8082018082111561050b5761050b611798565b8181038181111561050b5761050b611798565b808202811582820484141761050b5761050b611798565b60005b83811015611828578181015183820152602001611810565b50506000910152565b7f416363657373436f6e74726f6c3a206163636f756e742000000000000000000081526000835161186981601785016020880161180d565b7f206973206d697373696e6720726f6c652000000000000000000000000000000060179184019182015283516118a681602884016020880161180d565b01602801949350505050565b60208152600082518060208401526118d181604085016020870161180d565b601f01601f19169190910160400192915050565b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b60008161192057611920611798565b50600019019056fea2646970667358221220b26cc4a0fea0a6d176083cf5678c5082e9b1853c692f2d07ad8366c8e50c52fa64736f6c63430008130033", - "deployedBytecode": "0x608060405234801561001057600080fd5b50600436106101a35760003560e01c8063830a053e116100ee578063d009b2d611610097578063d547741f11610071578063d547741f14610423578063e63ab1e914610436578063e8e8d87e1461045d578063f7b188a51461047057600080fd5b8063d009b2d6146103d1578063d1052d1f146103e4578063d48bfaeb1461041057600080fd5b806397adedb5116100c857806397adedb514610379578063a217fddf146103a2578063a6471a1d146103aa57600080fd5b8063830a053e146103275780638456cb591461033a57806391d148541461034257600080fd5b80632f2ff15d116101505780635c975abb1161012a5780635c975abb146102f557806369da9114146103005780636f1c5de71461031f57600080fd5b80632f2ff15d1461029057806336568abe146102a3578063420fc4db146102b657600080fd5b806312236a771161018157806312236a77146101ed57806316934fc4146101f5578063248a9ca31461025f57600080fd5b806301ffc9a7146101a85780630aed7b0d146101d057806310ae2147146101da575b600080fd5b6101bb6101b636600461161c565b610478565b60405190151581526020015b60405180910390f35b6101d8610511565b005b6101d86101e836600461165e565b61062a565b6101d8610a63565b61023561020336600461169c565b600260208190526000918252604090912080546001820154928201546003830154600490930154919392909160ff1685565b6040805195865260208601949094529284019190915260608301521515608082015260a0016101c7565b61028261026d3660046116b7565b60009081526020819052604090206001015490565b6040519081526020016101c7565b6101d861029e3660046116d0565b610bb1565b6101d86102b13660046116d0565b610bdb565b6102dd7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b0390911681526020016101c7565b60015460ff166101bb565b6003546102dd906801000000000000000090046001600160a01b031681565b610282610c68565b61028261033536600461169c565b610c9d565b6101d8610cf3565b6101bb6103503660046116d0565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b61028261038736600461169c565b6001600160a01b031660009081526002602052604090205490565b610282600081565b6102827f3e35b14a9f4fef84b59f9bdcd3044fc28783144b7e42bfb2cd075e6a02cb082881565b6101d86103df3660046116fc565b610d4a565b6102826103f236600461169c565b6001600160a01b031660009081526002602052604090206003015490565b6101d861041e366004611726565b610e29565b6101d86104313660046116d0565b610eb5565b6102827f65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a81565b6101d861046b3660046116fc565b610eda565b6101d8611058565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f7965db0b00000000000000000000000000000000000000000000000000000000148061050b57507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008316145b92915050565b6105196110af565b336000908152600260205260409020600301541561062857336000818152600260208190526040918290200154905163a9059cbb60e01b8152600481019290925260248201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063a9059cbb906044016020604051808303816000875af11580156105b2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105d69190611750565b6105f3576040516312171d8360e31b815260040160405180910390fd5b3360009081526002602081905260408220828155600181018390559081018290556003810191909155600401805460ff191690555b565b610632611101565b33600081815260026020908152604082208054600490910154600354919460ff9091169392909165ff000000ff00600882811b91821664ff000000ff9390911c92831617601090811b67ff000000ff0000009290921666ff000000ff0000939093169290921790911c1780821b6bffffffffffffffff0000000016911c63ffffffff161760405160609290921b6bffffffffffffffffffffffff1916602083015260c01b7fffffffffffffffff000000000000000000000000000000000000000000000000166034820152603c8101869052605c016040516020818303038152906040528051906020012090506000600360089054906101000a90046001600160a01b03166001600160a01b0316639d1b464a6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610774573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107989190611772565b6107a89063ffffffff16866117ae565b905067016345785d8a0000851080156107bf575082155b156107f6576040517f8ecf3d0300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8280156108155750336000908152600260205260409020600301544311155b1561084c576040517fa8cab3d100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b3360009081526002602052604081206001015461086a9083906117d0565b336000908152600260208190526040822001549192509061088c9088906117d0565b6040805160a081018252868152602080820186815282840185815243606085019081526001608086018181523360009081526002968790529790972095518655925192850192909255519183019190915551600382015590516004909101805460ff191691151591909117905590508615610a18576040517f23b872dd000000000000000000000000000000000000000000000000000000008152336004820152306024820152604481018890527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906323b872dd906064016020604051808303816000875af115801561098d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109b19190611750565b6109ce576040516312171d8360e31b815260040160405180910390fd5b604080518381526020810183905290810185905243606082015233907ff3fb57c8e9287d05c0b3c8612031896c43149edcf7ca6f1b287ac836b4b5d5699060800160405180910390a25b838614610a595760408051338152602081018690527fe188baf4bcb1c4413d19ba0eaef908614d30e8df9570d6fc4d584b75f4a37a3a910160405180910390a15b5050505050505050565b336000908152600260208190526040822090810154600190910154909190610a8b9083611154565b610a9590836117e3565b90508015610bad573360009081526002602081905260408220018054839290610abf9084906117e3565b909155505060405163a9059cbb60e01b8152336004820152602481018290527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063a9059cbb906044016020604051808303816000875af1158015610b31573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b559190611750565b610b72576040516312171d8360e31b815260040160405180910390fd5b60408051338152602081018390527f8108595eb6bad3acefa9da467d90cc2217686d5c5ac85460f8b7849c840645fc91015b60405180910390a15b5050565b600082815260208190526040902060010154610bcc816111f8565b610bd68383611205565b505050565b6001600160a01b0381163314610c5e5760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b610bad82826112a3565b336000908152600260208190526040822090810154600190910154610c8d9082611154565b610c9790826117e3565b91505090565b6001600160a01b0381166000908152600260205260408120600301544311610cc657600061050b565b6001600160a01b0382166000908152600260208190526040909120600181015491015461050b9190611154565b3360009081527ff7c9542c591017a21c74b6f3fab6263c7952fc0aaf9db4c22a2a04ddc7f8674f602052604090205460ff16610d4257604051631d77d47760e21b815260040160405180910390fd5b610628611322565b3360009081527f10fa80d2e578284bf61a483a3da84fbdd683a7e7256a9895dc4461ac543f4a16602052604090205460ff16610d9957604051630490edbf60e31b815260040160405180910390fd5b6001600160a01b03821660009081526002602052604090206004015460ff1615610bad57610dc781436117d0565b6001600160a01b038316600081815260026020908152604091829020600381019490945592548151928352928201929092529081018290527fd7863535575e7de6678ea9d340a4bfe0b84d77323bfa2ef602c3c1df82aea78090606001610ba4565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff16610e91576040517f82b4290000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6003805467ffffffffffffffff191667ffffffffffffffff92909216919091179055565b600082815260208190526040902060010154610ed0816111f8565b610bd683836112a3565b3360009081527f10fa80d2e578284bf61a483a3da84fbdd683a7e7256a9895dc4461ac543f4a16602052604090205460ff16610f2957604051630490edbf60e31b815260040160405180910390fd5b6001600160a01b03821660009081526002602052604090206004015460ff1615611003576001600160a01b03821660009081526002602081905260409091200154811015610fc5576001600160a01b03821660009081526002602081905260408220018054839290610f9c9084906117e3565b90915550506001600160a01b038216600090815260026020526040902043600390910155611003565b6001600160a01b03821660009081526002602081905260408220828155600181018390559081018290556003810191909155600401805460ff191690555b6001600160a01b0382166000818152600260209081526040918290205482519384529083015281018290527f5f52ce031e6eba64e8a81288196b93a3e422096e80aea812f1f5a77866359b3a90606001610ba4565b3360009081527ff7c9542c591017a21c74b6f3fab6263c7952fc0aaf9db4c22a2a04ddc7f8674f602052604090205460ff166110a757604051631d77d47760e21b815260040160405180910390fd5b610628611376565b60015460ff166106285760405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f74207061757365640000000000000000000000006044820152606401610c55565b60015460ff16156106285760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a20706175736564000000000000000000000000000000006044820152606401610c55565b600080600360089054906101000a90046001600160a01b03166001600160a01b0316639d1b464a6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156111aa573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111ce9190611772565b6111de9063ffffffff16856117f6565b9050828110156111ef57905061050b565b8291505061050b565b61120281336113af565b50565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610bad576000828152602081815260408083206001600160a01b03851684529091529020805460ff1916600117905561125f3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1615610bad576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b61132a611101565b6001805460ff1916811790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258335b6040516001600160a01b03909116815260200160405180910390a1565b61137e6110af565b6001805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa33611359565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610bad576113e081611422565b6113eb836020611434565b6040516020016113fc929190611831565b60408051601f198184030181529082905262461bcd60e51b8252610c55916004016118b2565b606061050b6001600160a01b03831660145b606060006114438360026117f6565b61144e9060026117d0565b67ffffffffffffffff811115611466576114666118e5565b6040519080825280601f01601f191660200182016040528015611490576020820181803683370190505b5090507f3000000000000000000000000000000000000000000000000000000000000000816000815181106114c7576114c76118fb565b60200101906001600160f81b031916908160001a9053507f780000000000000000000000000000000000000000000000000000000000000081600181518110611512576115126118fb565b60200101906001600160f81b031916908160001a90535060006115368460026117f6565b6115419060016117d0565b90505b60018111156115c6577f303132333435363738396162636465660000000000000000000000000000000085600f1660108110611582576115826118fb565b1a60f81b828281518110611598576115986118fb565b60200101906001600160f81b031916908160001a90535060049490941c936115bf81611911565b9050611544565b5083156116155760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610c55565b9392505050565b60006020828403121561162e57600080fd5b81357fffffffff000000000000000000000000000000000000000000000000000000008116811461161557600080fd5b6000806040838503121561167157600080fd5b50508035926020909101359150565b80356001600160a01b038116811461169757600080fd5b919050565b6000602082840312156116ae57600080fd5b61161582611680565b6000602082840312156116c957600080fd5b5035919050565b600080604083850312156116e357600080fd5b823591506116f360208401611680565b90509250929050565b6000806040838503121561170f57600080fd5b61171883611680565b946020939093013593505050565b60006020828403121561173857600080fd5b813567ffffffffffffffff8116811461161557600080fd5b60006020828403121561176257600080fd5b8151801515811461161557600080fd5b60006020828403121561178457600080fd5b815163ffffffff8116811461161557600080fd5b634e487b7160e01b600052601160045260246000fd5b6000826117cb57634e487b7160e01b600052601260045260246000fd5b500490565b8082018082111561050b5761050b611798565b8181038181111561050b5761050b611798565b808202811582820484141761050b5761050b611798565b60005b83811015611828578181015183820152602001611810565b50506000910152565b7f416363657373436f6e74726f6c3a206163636f756e742000000000000000000081526000835161186981601785016020880161180d565b7f206973206d697373696e6720726f6c652000000000000000000000000000000060179184019182015283516118a681602884016020880161180d565b01602801949350505050565b60208152600082518060208401526118d181604085016020870161180d565b601f01601f19169190910160400192915050565b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b60008161192057611920611798565b50600019019056fea2646970667358221220b26cc4a0fea0a6d176083cf5678c5082e9b1853c692f2d07ad8366c8e50c52fa64736f6c63430008130033", + "solcInputHash": "99c9ef5f7ef53ea99ef6c816b26b1e5c", + "metadata": "{\"compiler\":{\"version\":\"0.8.19+commit.7dd6d404\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_bzzToken\",\"type\":\"address\"},{\"internalType\":\"uint64\",\"name\":\"_NetworkId\",\"type\":\"uint64\"},{\"internalType\":\"address\",\"name\":\"_oracleContract\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[],\"name\":\"BelowMinimumStake\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"Frozen\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"OnlyPauser\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"OnlyRedistributor\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"TransferFailed\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"Unauthorized\",\"type\":\"error\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"}],\"name\":\"OverlayChanged\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"Paused\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"previousAdminRole\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"newAdminRole\",\"type\":\"bytes32\"}],\"name\":\"RoleAdminChanged\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"}],\"name\":\"RoleGranted\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"}],\"name\":\"RoleRevoked\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"frozen\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"time\",\"type\":\"uint256\"}],\"name\":\"StakeFrozen\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"slashed\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"StakeSlashed\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"committedStake\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"potentialStake\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"lastUpdatedBlock\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint8\",\"name\":\"height\",\"type\":\"uint8\"}],\"name\":\"StakeUpdated\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"node\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"StakeWithdrawn\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"Unpaused\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"DEFAULT_ADMIN_ROLE\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"OracleContract\",\"outputs\":[{\"internalType\":\"contract IPriceOracle\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"REDISTRIBUTOR_ROLE\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"bzzToken\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint64\",\"name\":\"_NetworkId\",\"type\":\"uint64\"}],\"name\":\"changeNetworkId\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_owner\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"_time\",\"type\":\"uint256\"}],\"name\":\"freezeDeposit\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"}],\"name\":\"getRoleAdmin\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"grantRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"hasRole\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_owner\",\"type\":\"address\"}],\"name\":\"heightOfAddress\",\"outputs\":[{\"internalType\":\"uint8\",\"name\":\"\",\"type\":\"uint8\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_owner\",\"type\":\"address\"}],\"name\":\"lastUpdatedBlockNumberOfAddress\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"_setNonce\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"_addAmount\",\"type\":\"uint256\"},{\"internalType\":\"uint8\",\"name\":\"_height\",\"type\":\"uint8\"}],\"name\":\"manageStake\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"migrateStake\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_owner\",\"type\":\"address\"}],\"name\":\"nodeEffectiveStake\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_owner\",\"type\":\"address\"}],\"name\":\"overlayOfAddress\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"pause\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"paused\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"renounceRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"revokeRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_owner\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"_amount\",\"type\":\"uint256\"}],\"name\":\"slashDeposit\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"name\":\"stakes\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"overlay\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"committedStake\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"potentialStake\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"lastUpdatedBlockNumber\",\"type\":\"uint256\"},{\"internalType\":\"uint8\",\"name\":\"height\",\"type\":\"uint8\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes4\",\"name\":\"interfaceId\",\"type\":\"bytes4\"}],\"name\":\"supportsInterface\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"unPause\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"withdrawFromStake\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"withdrawableStake\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"}],\"devdoc\":{\"author\":\"The Swarm Authors\",\"details\":\"Allows users to stake tokens in order to be eligible for the Redistribution Schelling co-ordination game. Stakes are frozen or slashed by the Redistribution contract in response to violations of the protocol.\",\"events\":{\"OverlayChanged(address,bytes32)\":{\"details\":\"Emitted when a address changes overlay it uses\"},\"Paused(address)\":{\"details\":\"Emitted when the pause is triggered by `account`.\"},\"RoleAdminChanged(bytes32,bytes32,bytes32)\":{\"details\":\"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._\"},\"RoleGranted(bytes32,address,address)\":{\"details\":\"Emitted when `account` is granted `role`. `sender` is the account that originated the contract call, an admin role bearer except when using {AccessControl-_setupRole}.\"},\"RoleRevoked(bytes32,address,address)\":{\"details\":\"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`)\"},\"StakeFrozen(address,bytes32,uint256)\":{\"details\":\"Emitted when a stake for address `frozen` is frozen for `time` blocks.\"},\"StakeSlashed(address,bytes32,uint256)\":{\"details\":\"Emitted when a stake for address `slashed` is slashed by `amount`.\"},\"StakeUpdated(address,uint256,uint256,bytes32,uint256,uint8)\":{\"details\":\"Emitted when a stake is created or updated by `owner` of the `overlay`.\"},\"StakeWithdrawn(address,uint256)\":{\"details\":\"Emitted when a stake for address is withdrawn\"},\"Unpaused(address)\":{\"details\":\"Emitted when the pause is lifted by `account`.\"}},\"kind\":\"dev\",\"methods\":{\"constructor\":{\"params\":{\"_NetworkId\":\"Swarm network ID\",\"_bzzToken\":\"Address of the staked ERC20 token\"}},\"freezeDeposit(address,uint256)\":{\"details\":\"Freeze an existing stake, can only be called by the redistributor\",\"params\":{\"_owner\":\"the addres selected\",\"_time\":\"penalty length in blocknumbers\"}},\"getRoleAdmin(bytes32)\":{\"details\":\"Returns the admin role that controls `role`. See {grantRole} and {revokeRole}. To change a role's admin, use {_setRoleAdmin}.\"},\"grantRole(bytes32,address)\":{\"details\":\"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.\"},\"hasRole(bytes32,address)\":{\"details\":\"Returns `true` if `account` has been granted `role`.\"},\"heightOfAddress(address)\":{\"details\":\"Returns the currently height of the address.\",\"params\":{\"_owner\":\"address of node\"}},\"lastUpdatedBlockNumberOfAddress(address)\":{\"details\":\"Returns the `lastUpdatedBlockNumber` of `address`.\"},\"manageStake(bytes32,uint256,uint8)\":{\"details\":\"At least `_initialBalancePerChunk*2^depth` number of tokens need to be preapproved for this contract.\",\"params\":{\"_addAmount\":\"Deposited amount of ERC20 tokens, equals to added Potential stake value\",\"_height\":\"increased reserve by registering the number of doublings\",\"_setNonce\":\"Nonce that was used for overlay calculation.\"}},\"migrateStake()\":{\"details\":\"Migrate stake only when the staking contract is paused, can only be called by the owner of the stake\"},\"nodeEffectiveStake(address)\":{\"details\":\"Returns the current `effectiveStake` of `address`. previously usable stake\",\"params\":{\"_owner\":\"_owner of node\"}},\"overlayOfAddress(address)\":{\"details\":\"Returns the currently used overlay of the address.\",\"params\":{\"_owner\":\"address of node\"}},\"pause()\":{\"details\":\"Pause the contract. The contract is provably stopped by renouncing the pauser role and the admin role after pausing, can only be called by the `PAUSER`\"},\"paused()\":{\"details\":\"Returns true if the contract is paused, and false otherwise.\"},\"renounceRole(bytes32,address)\":{\"details\":\"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.\"},\"revokeRole(bytes32,address)\":{\"details\":\"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.\"},\"slashDeposit(address,uint256)\":{\"details\":\"Slash an existing stake, can only be called by the `redistributor`\",\"params\":{\"_amount\":\"the amount to be slashed\",\"_owner\":\"the _owner adress selected\"}},\"supportsInterface(bytes4)\":{\"details\":\"See {IERC165-supportsInterface}.\"},\"unPause()\":{\"details\":\"Unpause the contract, can only be called by the pauser when paused\"},\"withdrawFromStake()\":{\"details\":\"Withdraw node stake surplus\"},\"withdrawableStake()\":{\"details\":\"Check the amount that is possible to withdraw as surplus\"}},\"title\":\"Staking contract for the Swarm storage incentives\",\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{\"manageStake(bytes32,uint256,uint8)\":{\"notice\":\"Create a new stake or update an existing one, change overlay of node\"}},\"version\":1}},\"settings\":{\"compilationTarget\":{\"src/Staking.sol\":\"StakeRegistry\"},\"evmVersion\":\"paris\",\"libraries\":{\":__CACHE_BREAKER__\":\"0x00000000d41867734bbee4c6863d9255b2b06ac1\"},\"metadata\":{\"bytecodeHash\":\"ipfs\",\"useLiteralContent\":true},\"optimizer\":{\"enabled\":true,\"runs\":1000},\"remappings\":[]},\"sources\":{\"@openzeppelin/contracts/access/AccessControl.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (access/AccessControl.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./IAccessControl.sol\\\";\\nimport \\\"../utils/Context.sol\\\";\\nimport \\\"../utils/Strings.sol\\\";\\nimport \\\"../utils/introspection/ERC165.sol\\\";\\n\\n/**\\n * @dev Contract module that allows children to implement role-based access\\n * control mechanisms. This is a lightweight version that doesn't allow enumerating role\\n * members except through off-chain means by accessing the contract event logs. Some\\n * applications may benefit from on-chain enumerability, for those cases see\\n * {AccessControlEnumerable}.\\n *\\n * Roles are referred to by their `bytes32` identifier. These should be exposed\\n * in the external API and be unique. The best way to achieve this is by\\n * using `public constant` hash digests:\\n *\\n * ```\\n * bytes32 public constant MY_ROLE = keccak256(\\\"MY_ROLE\\\");\\n * ```\\n *\\n * Roles can be used to represent a set of permissions. To restrict access to a\\n * function call, use {hasRole}:\\n *\\n * ```\\n * function foo() public {\\n * require(hasRole(MY_ROLE, msg.sender));\\n * ...\\n * }\\n * ```\\n *\\n * Roles can be granted and revoked dynamically via the {grantRole} and\\n * {revokeRole} functions. Each role has an associated admin role, and only\\n * accounts that have a role's admin role can call {grantRole} and {revokeRole}.\\n *\\n * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means\\n * that only accounts with this role will be able to grant or revoke other\\n * roles. More complex role relationships can be created by using\\n * {_setRoleAdmin}.\\n *\\n * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to\\n * grant and revoke this role. Extra precautions should be taken to secure\\n * accounts that have been granted it.\\n */\\nabstract contract AccessControl is Context, IAccessControl, ERC165 {\\n struct RoleData {\\n mapping(address => bool) members;\\n bytes32 adminRole;\\n }\\n\\n mapping(bytes32 => RoleData) private _roles;\\n\\n bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;\\n\\n /**\\n * @dev Modifier that checks that an account has a specific role. Reverts\\n * with a standardized message including the required role.\\n *\\n * The format of the revert reason is given by the following regular expression:\\n *\\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\\n *\\n * _Available since v4.1._\\n */\\n modifier onlyRole(bytes32 role) {\\n _checkRole(role);\\n _;\\n }\\n\\n /**\\n * @dev See {IERC165-supportsInterface}.\\n */\\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);\\n }\\n\\n /**\\n * @dev Returns `true` if `account` has been granted `role`.\\n */\\n function hasRole(bytes32 role, address account) public view virtual override returns (bool) {\\n return _roles[role].members[account];\\n }\\n\\n /**\\n * @dev Revert with a standard message if `_msgSender()` is missing `role`.\\n * Overriding this function changes the behavior of the {onlyRole} modifier.\\n *\\n * Format of the revert message is described in {_checkRole}.\\n *\\n * _Available since v4.6._\\n */\\n function _checkRole(bytes32 role) internal view virtual {\\n _checkRole(role, _msgSender());\\n }\\n\\n /**\\n * @dev Revert with a standard message if `account` is missing `role`.\\n *\\n * The format of the revert reason is given by the following regular expression:\\n *\\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\\n */\\n function _checkRole(bytes32 role, address account) internal view virtual {\\n if (!hasRole(role, account)) {\\n revert(\\n string(\\n abi.encodePacked(\\n \\\"AccessControl: account \\\",\\n Strings.toHexString(account),\\n \\\" is missing role \\\",\\n Strings.toHexString(uint256(role), 32)\\n )\\n )\\n );\\n }\\n }\\n\\n /**\\n * @dev Returns the admin role that controls `role`. See {grantRole} and\\n * {revokeRole}.\\n *\\n * To change a role's admin, use {_setRoleAdmin}.\\n */\\n function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {\\n return _roles[role].adminRole;\\n }\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * If `account` had not been already granted `role`, emits a {RoleGranted}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n *\\n * May emit a {RoleGranted} event.\\n */\\n function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\\n _grantRole(role, account);\\n }\\n\\n /**\\n * @dev Revokes `role` from `account`.\\n *\\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n *\\n * May emit a {RoleRevoked} event.\\n */\\n function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\\n _revokeRole(role, account);\\n }\\n\\n /**\\n * @dev Revokes `role` from the calling account.\\n *\\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\\n * purpose is to provide a mechanism for accounts to lose their privileges\\n * if they are compromised (such as when a trusted device is misplaced).\\n *\\n * If the calling account had been revoked `role`, emits a {RoleRevoked}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must be `account`.\\n *\\n * May emit a {RoleRevoked} event.\\n */\\n function renounceRole(bytes32 role, address account) public virtual override {\\n require(account == _msgSender(), \\\"AccessControl: can only renounce roles for self\\\");\\n\\n _revokeRole(role, account);\\n }\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * If `account` had not been already granted `role`, emits a {RoleGranted}\\n * event. Note that unlike {grantRole}, this function doesn't perform any\\n * checks on the calling account.\\n *\\n * May emit a {RoleGranted} event.\\n *\\n * [WARNING]\\n * ====\\n * This function should only be called from the constructor when setting\\n * up the initial roles for the system.\\n *\\n * Using this function in any other way is effectively circumventing the admin\\n * system imposed by {AccessControl}.\\n * ====\\n *\\n * NOTE: This function is deprecated in favor of {_grantRole}.\\n */\\n function _setupRole(bytes32 role, address account) internal virtual {\\n _grantRole(role, account);\\n }\\n\\n /**\\n * @dev Sets `adminRole` as ``role``'s admin role.\\n *\\n * Emits a {RoleAdminChanged} event.\\n */\\n function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {\\n bytes32 previousAdminRole = getRoleAdmin(role);\\n _roles[role].adminRole = adminRole;\\n emit RoleAdminChanged(role, previousAdminRole, adminRole);\\n }\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * Internal function without access restriction.\\n *\\n * May emit a {RoleGranted} event.\\n */\\n function _grantRole(bytes32 role, address account) internal virtual {\\n if (!hasRole(role, account)) {\\n _roles[role].members[account] = true;\\n emit RoleGranted(role, account, _msgSender());\\n }\\n }\\n\\n /**\\n * @dev Revokes `role` from `account`.\\n *\\n * Internal function without access restriction.\\n *\\n * May emit a {RoleRevoked} event.\\n */\\n function _revokeRole(bytes32 role, address account) internal virtual {\\n if (hasRole(role, account)) {\\n _roles[role].members[account] = false;\\n emit RoleRevoked(role, account, _msgSender());\\n }\\n }\\n}\\n\",\"keccak256\":\"0x67e3daf189111d6d5b0464ed09cf9f0605a22c4b965a7fcecd707101faff008a\",\"license\":\"MIT\"},\"@openzeppelin/contracts/access/IAccessControl.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev External interface of AccessControl declared to support ERC165 detection.\\n */\\ninterface IAccessControl {\\n /**\\n * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`\\n *\\n * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite\\n * {RoleAdminChanged} not being emitted signaling this.\\n *\\n * _Available since v3.1._\\n */\\n event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);\\n\\n /**\\n * @dev Emitted when `account` is granted `role`.\\n *\\n * `sender` is the account that originated the contract call, an admin role\\n * bearer except when using {AccessControl-_setupRole}.\\n */\\n event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);\\n\\n /**\\n * @dev Emitted when `account` is revoked `role`.\\n *\\n * `sender` is the account that originated the contract call:\\n * - if using `revokeRole`, it is the admin role bearer\\n * - if using `renounceRole`, it is the role bearer (i.e. `account`)\\n */\\n event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);\\n\\n /**\\n * @dev Returns `true` if `account` has been granted `role`.\\n */\\n function hasRole(bytes32 role, address account) external view returns (bool);\\n\\n /**\\n * @dev Returns the admin role that controls `role`. See {grantRole} and\\n * {revokeRole}.\\n *\\n * To change a role's admin, use {AccessControl-_setRoleAdmin}.\\n */\\n function getRoleAdmin(bytes32 role) external view returns (bytes32);\\n\\n /**\\n * @dev Grants `role` to `account`.\\n *\\n * If `account` had not been already granted `role`, emits a {RoleGranted}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n */\\n function grantRole(bytes32 role, address account) external;\\n\\n /**\\n * @dev Revokes `role` from `account`.\\n *\\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\\n *\\n * Requirements:\\n *\\n * - the caller must have ``role``'s admin role.\\n */\\n function revokeRole(bytes32 role, address account) external;\\n\\n /**\\n * @dev Revokes `role` from the calling account.\\n *\\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\\n * purpose is to provide a mechanism for accounts to lose their privileges\\n * if they are compromised (such as when a trusted device is misplaced).\\n *\\n * If the calling account had been granted `role`, emits a {RoleRevoked}\\n * event.\\n *\\n * Requirements:\\n *\\n * - the caller must be `account`.\\n */\\n function renounceRole(bytes32 role, address account) external;\\n}\\n\",\"keccak256\":\"0x59ce320a585d7e1f163cd70390a0ef2ff9cec832e2aa544293a00692465a7a57\",\"license\":\"MIT\"},\"@openzeppelin/contracts/security/Pausable.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"../utils/Context.sol\\\";\\n\\n/**\\n * @dev Contract module which allows children to implement an emergency stop\\n * mechanism that can be triggered by an authorized account.\\n *\\n * This module is used through inheritance. It will make available the\\n * modifiers `whenNotPaused` and `whenPaused`, which can be applied to\\n * the functions of your contract. Note that they will not be pausable by\\n * simply including this module, only once the modifiers are put in place.\\n */\\nabstract contract Pausable is Context {\\n /**\\n * @dev Emitted when the pause is triggered by `account`.\\n */\\n event Paused(address account);\\n\\n /**\\n * @dev Emitted when the pause is lifted by `account`.\\n */\\n event Unpaused(address account);\\n\\n bool private _paused;\\n\\n /**\\n * @dev Initializes the contract in unpaused state.\\n */\\n constructor() {\\n _paused = false;\\n }\\n\\n /**\\n * @dev Modifier to make a function callable only when the contract is not paused.\\n *\\n * Requirements:\\n *\\n * - The contract must not be paused.\\n */\\n modifier whenNotPaused() {\\n _requireNotPaused();\\n _;\\n }\\n\\n /**\\n * @dev Modifier to make a function callable only when the contract is paused.\\n *\\n * Requirements:\\n *\\n * - The contract must be paused.\\n */\\n modifier whenPaused() {\\n _requirePaused();\\n _;\\n }\\n\\n /**\\n * @dev Returns true if the contract is paused, and false otherwise.\\n */\\n function paused() public view virtual returns (bool) {\\n return _paused;\\n }\\n\\n /**\\n * @dev Throws if the contract is paused.\\n */\\n function _requireNotPaused() internal view virtual {\\n require(!paused(), \\\"Pausable: paused\\\");\\n }\\n\\n /**\\n * @dev Throws if the contract is not paused.\\n */\\n function _requirePaused() internal view virtual {\\n require(paused(), \\\"Pausable: not paused\\\");\\n }\\n\\n /**\\n * @dev Triggers stopped state.\\n *\\n * Requirements:\\n *\\n * - The contract must not be paused.\\n */\\n function _pause() internal virtual whenNotPaused {\\n _paused = true;\\n emit Paused(_msgSender());\\n }\\n\\n /**\\n * @dev Returns to normal state.\\n *\\n * Requirements:\\n *\\n * - The contract must be paused.\\n */\\n function _unpause() internal virtual whenPaused {\\n _paused = false;\\n emit Unpaused(_msgSender());\\n }\\n}\\n\",\"keccak256\":\"0x0849d93b16c9940beb286a7864ed02724b248b93e0d80ef6355af5ef15c64773\",\"license\":\"MIT\"},\"@openzeppelin/contracts/token/ERC20/ERC20.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/ERC20.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./IERC20.sol\\\";\\nimport \\\"./extensions/IERC20Metadata.sol\\\";\\nimport \\\"../../utils/Context.sol\\\";\\n\\n/**\\n * @dev Implementation of the {IERC20} interface.\\n *\\n * This implementation is agnostic to the way tokens are created. This means\\n * that a supply mechanism has to be added in a derived contract using {_mint}.\\n * For a generic mechanism see {ERC20PresetMinterPauser}.\\n *\\n * TIP: For a detailed writeup see our guide\\n * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How\\n * to implement supply mechanisms].\\n *\\n * We have followed general OpenZeppelin Contracts guidelines: functions revert\\n * instead returning `false` on failure. This behavior is nonetheless\\n * conventional and does not conflict with the expectations of ERC20\\n * applications.\\n *\\n * Additionally, an {Approval} event is emitted on calls to {transferFrom}.\\n * This allows applications to reconstruct the allowance for all accounts just\\n * by listening to said events. Other implementations of the EIP may not emit\\n * these events, as it isn't required by the specification.\\n *\\n * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}\\n * functions have been added to mitigate the well-known issues around setting\\n * allowances. See {IERC20-approve}.\\n */\\ncontract ERC20 is Context, IERC20, IERC20Metadata {\\n mapping(address => uint256) private _balances;\\n\\n mapping(address => mapping(address => uint256)) private _allowances;\\n\\n uint256 private _totalSupply;\\n\\n string private _name;\\n string private _symbol;\\n\\n /**\\n * @dev Sets the values for {name} and {symbol}.\\n *\\n * The default value of {decimals} is 18. To select a different value for\\n * {decimals} you should overload it.\\n *\\n * All two of these values are immutable: they can only be set once during\\n * construction.\\n */\\n constructor(string memory name_, string memory symbol_) {\\n _name = name_;\\n _symbol = symbol_;\\n }\\n\\n /**\\n * @dev Returns the name of the token.\\n */\\n function name() public view virtual override returns (string memory) {\\n return _name;\\n }\\n\\n /**\\n * @dev Returns the symbol of the token, usually a shorter version of the\\n * name.\\n */\\n function symbol() public view virtual override returns (string memory) {\\n return _symbol;\\n }\\n\\n /**\\n * @dev Returns the number of decimals used to get its user representation.\\n * For example, if `decimals` equals `2`, a balance of `505` tokens should\\n * be displayed to a user as `5.05` (`505 / 10 ** 2`).\\n *\\n * Tokens usually opt for a value of 18, imitating the relationship between\\n * Ether and Wei. This is the value {ERC20} uses, unless this function is\\n * overridden;\\n *\\n * NOTE: This information is only used for _display_ purposes: it in\\n * no way affects any of the arithmetic of the contract, including\\n * {IERC20-balanceOf} and {IERC20-transfer}.\\n */\\n function decimals() public view virtual override returns (uint8) {\\n return 18;\\n }\\n\\n /**\\n * @dev See {IERC20-totalSupply}.\\n */\\n function totalSupply() public view virtual override returns (uint256) {\\n return _totalSupply;\\n }\\n\\n /**\\n * @dev See {IERC20-balanceOf}.\\n */\\n function balanceOf(address account) public view virtual override returns (uint256) {\\n return _balances[account];\\n }\\n\\n /**\\n * @dev See {IERC20-transfer}.\\n *\\n * Requirements:\\n *\\n * - `to` cannot be the zero address.\\n * - the caller must have a balance of at least `amount`.\\n */\\n function transfer(address to, uint256 amount) public virtual override returns (bool) {\\n address owner = _msgSender();\\n _transfer(owner, to, amount);\\n return true;\\n }\\n\\n /**\\n * @dev See {IERC20-allowance}.\\n */\\n function allowance(address owner, address spender) public view virtual override returns (uint256) {\\n return _allowances[owner][spender];\\n }\\n\\n /**\\n * @dev See {IERC20-approve}.\\n *\\n * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on\\n * `transferFrom`. This is semantically equivalent to an infinite approval.\\n *\\n * Requirements:\\n *\\n * - `spender` cannot be the zero address.\\n */\\n function approve(address spender, uint256 amount) public virtual override returns (bool) {\\n address owner = _msgSender();\\n _approve(owner, spender, amount);\\n return true;\\n }\\n\\n /**\\n * @dev See {IERC20-transferFrom}.\\n *\\n * Emits an {Approval} event indicating the updated allowance. This is not\\n * required by the EIP. See the note at the beginning of {ERC20}.\\n *\\n * NOTE: Does not update the allowance if the current allowance\\n * is the maximum `uint256`.\\n *\\n * Requirements:\\n *\\n * - `from` and `to` cannot be the zero address.\\n * - `from` must have a balance of at least `amount`.\\n * - the caller must have allowance for ``from``'s tokens of at least\\n * `amount`.\\n */\\n function transferFrom(\\n address from,\\n address to,\\n uint256 amount\\n ) public virtual override returns (bool) {\\n address spender = _msgSender();\\n _spendAllowance(from, spender, amount);\\n _transfer(from, to, amount);\\n return true;\\n }\\n\\n /**\\n * @dev Atomically increases the allowance granted to `spender` by the caller.\\n *\\n * This is an alternative to {approve} that can be used as a mitigation for\\n * problems described in {IERC20-approve}.\\n *\\n * Emits an {Approval} event indicating the updated allowance.\\n *\\n * Requirements:\\n *\\n * - `spender` cannot be the zero address.\\n */\\n function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {\\n address owner = _msgSender();\\n _approve(owner, spender, allowance(owner, spender) + addedValue);\\n return true;\\n }\\n\\n /**\\n * @dev Atomically decreases the allowance granted to `spender` by the caller.\\n *\\n * This is an alternative to {approve} that can be used as a mitigation for\\n * problems described in {IERC20-approve}.\\n *\\n * Emits an {Approval} event indicating the updated allowance.\\n *\\n * Requirements:\\n *\\n * - `spender` cannot be the zero address.\\n * - `spender` must have allowance for the caller of at least\\n * `subtractedValue`.\\n */\\n function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {\\n address owner = _msgSender();\\n uint256 currentAllowance = allowance(owner, spender);\\n require(currentAllowance >= subtractedValue, \\\"ERC20: decreased allowance below zero\\\");\\n unchecked {\\n _approve(owner, spender, currentAllowance - subtractedValue);\\n }\\n\\n return true;\\n }\\n\\n /**\\n * @dev Moves `amount` of tokens from `from` to `to`.\\n *\\n * This internal function is equivalent to {transfer}, and can be used to\\n * e.g. implement automatic token fees, slashing mechanisms, etc.\\n *\\n * Emits a {Transfer} event.\\n *\\n * Requirements:\\n *\\n * - `from` cannot be the zero address.\\n * - `to` cannot be the zero address.\\n * - `from` must have a balance of at least `amount`.\\n */\\n function _transfer(\\n address from,\\n address to,\\n uint256 amount\\n ) internal virtual {\\n require(from != address(0), \\\"ERC20: transfer from the zero address\\\");\\n require(to != address(0), \\\"ERC20: transfer to the zero address\\\");\\n\\n _beforeTokenTransfer(from, to, amount);\\n\\n uint256 fromBalance = _balances[from];\\n require(fromBalance >= amount, \\\"ERC20: transfer amount exceeds balance\\\");\\n unchecked {\\n _balances[from] = fromBalance - amount;\\n // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by\\n // decrementing then incrementing.\\n _balances[to] += amount;\\n }\\n\\n emit Transfer(from, to, amount);\\n\\n _afterTokenTransfer(from, to, amount);\\n }\\n\\n /** @dev Creates `amount` tokens and assigns them to `account`, increasing\\n * the total supply.\\n *\\n * Emits a {Transfer} event with `from` set to the zero address.\\n *\\n * Requirements:\\n *\\n * - `account` cannot be the zero address.\\n */\\n function _mint(address account, uint256 amount) internal virtual {\\n require(account != address(0), \\\"ERC20: mint to the zero address\\\");\\n\\n _beforeTokenTransfer(address(0), account, amount);\\n\\n _totalSupply += amount;\\n unchecked {\\n // Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.\\n _balances[account] += amount;\\n }\\n emit Transfer(address(0), account, amount);\\n\\n _afterTokenTransfer(address(0), account, amount);\\n }\\n\\n /**\\n * @dev Destroys `amount` tokens from `account`, reducing the\\n * total supply.\\n *\\n * Emits a {Transfer} event with `to` set to the zero address.\\n *\\n * Requirements:\\n *\\n * - `account` cannot be the zero address.\\n * - `account` must have at least `amount` tokens.\\n */\\n function _burn(address account, uint256 amount) internal virtual {\\n require(account != address(0), \\\"ERC20: burn from the zero address\\\");\\n\\n _beforeTokenTransfer(account, address(0), amount);\\n\\n uint256 accountBalance = _balances[account];\\n require(accountBalance >= amount, \\\"ERC20: burn amount exceeds balance\\\");\\n unchecked {\\n _balances[account] = accountBalance - amount;\\n // Overflow not possible: amount <= accountBalance <= totalSupply.\\n _totalSupply -= amount;\\n }\\n\\n emit Transfer(account, address(0), amount);\\n\\n _afterTokenTransfer(account, address(0), amount);\\n }\\n\\n /**\\n * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.\\n *\\n * This internal function is equivalent to `approve`, and can be used to\\n * e.g. set automatic allowances for certain subsystems, etc.\\n *\\n * Emits an {Approval} event.\\n *\\n * Requirements:\\n *\\n * - `owner` cannot be the zero address.\\n * - `spender` cannot be the zero address.\\n */\\n function _approve(\\n address owner,\\n address spender,\\n uint256 amount\\n ) internal virtual {\\n require(owner != address(0), \\\"ERC20: approve from the zero address\\\");\\n require(spender != address(0), \\\"ERC20: approve to the zero address\\\");\\n\\n _allowances[owner][spender] = amount;\\n emit Approval(owner, spender, amount);\\n }\\n\\n /**\\n * @dev Updates `owner` s allowance for `spender` based on spent `amount`.\\n *\\n * Does not update the allowance amount in case of infinite allowance.\\n * Revert if not enough allowance is available.\\n *\\n * Might emit an {Approval} event.\\n */\\n function _spendAllowance(\\n address owner,\\n address spender,\\n uint256 amount\\n ) internal virtual {\\n uint256 currentAllowance = allowance(owner, spender);\\n if (currentAllowance != type(uint256).max) {\\n require(currentAllowance >= amount, \\\"ERC20: insufficient allowance\\\");\\n unchecked {\\n _approve(owner, spender, currentAllowance - amount);\\n }\\n }\\n }\\n\\n /**\\n * @dev Hook that is called before any transfer of tokens. This includes\\n * minting and burning.\\n *\\n * Calling conditions:\\n *\\n * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\\n * will be transferred to `to`.\\n * - when `from` is zero, `amount` tokens will be minted for `to`.\\n * - when `to` is zero, `amount` of ``from``'s tokens will be burned.\\n * - `from` and `to` are never both zero.\\n *\\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\\n */\\n function _beforeTokenTransfer(\\n address from,\\n address to,\\n uint256 amount\\n ) internal virtual {}\\n\\n /**\\n * @dev Hook that is called after any transfer of tokens. This includes\\n * minting and burning.\\n *\\n * Calling conditions:\\n *\\n * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\\n * has been transferred to `to`.\\n * - when `from` is zero, `amount` tokens have been minted for `to`.\\n * - when `to` is zero, `amount` of ``from``'s tokens have been burned.\\n * - `from` and `to` are never both zero.\\n *\\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\\n */\\n function _afterTokenTransfer(\\n address from,\\n address to,\\n uint256 amount\\n ) internal virtual {}\\n}\\n\",\"keccak256\":\"0x4ffc0547c02ad22925310c585c0f166f8759e2648a09e9b489100c42f15dd98d\",\"license\":\"MIT\"},\"@openzeppelin/contracts/token/ERC20/IERC20.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Interface of the ERC20 standard as defined in the EIP.\\n */\\ninterface IERC20 {\\n /**\\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\\n * another (`to`).\\n *\\n * Note that `value` may be zero.\\n */\\n event Transfer(address indexed from, address indexed to, uint256 value);\\n\\n /**\\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\\n * a call to {approve}. `value` is the new allowance.\\n */\\n event Approval(address indexed owner, address indexed spender, uint256 value);\\n\\n /**\\n * @dev Returns the amount of tokens in existence.\\n */\\n function totalSupply() external view returns (uint256);\\n\\n /**\\n * @dev Returns the amount of tokens owned by `account`.\\n */\\n function balanceOf(address account) external view returns (uint256);\\n\\n /**\\n * @dev Moves `amount` tokens from the caller's account to `to`.\\n *\\n * Returns a boolean value indicating whether the operation succeeded.\\n *\\n * Emits a {Transfer} event.\\n */\\n function transfer(address to, uint256 amount) external returns (bool);\\n\\n /**\\n * @dev Returns the remaining number of tokens that `spender` will be\\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\\n * zero by default.\\n *\\n * This value changes when {approve} or {transferFrom} are called.\\n */\\n function allowance(address owner, address spender) external view returns (uint256);\\n\\n /**\\n * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\\n *\\n * Returns a boolean value indicating whether the operation succeeded.\\n *\\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\\n * that someone may use both the old and the new allowance by unfortunate\\n * transaction ordering. One possible solution to mitigate this race\\n * condition is to first reduce the spender's allowance to 0 and set the\\n * desired value afterwards:\\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\\n *\\n * Emits an {Approval} event.\\n */\\n function approve(address spender, uint256 amount) external returns (bool);\\n\\n /**\\n * @dev Moves `amount` tokens from `from` to `to` using the\\n * allowance mechanism. `amount` is then deducted from the caller's\\n * allowance.\\n *\\n * Returns a boolean value indicating whether the operation succeeded.\\n *\\n * Emits a {Transfer} event.\\n */\\n function transferFrom(\\n address from,\\n address to,\\n uint256 amount\\n ) external returns (bool);\\n}\\n\",\"keccak256\":\"0x9750c6b834f7b43000631af5cc30001c5f547b3ceb3635488f140f60e897ea6b\",\"license\":\"MIT\"},\"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"../IERC20.sol\\\";\\n\\n/**\\n * @dev Interface for the optional metadata functions from the ERC20 standard.\\n *\\n * _Available since v4.1._\\n */\\ninterface IERC20Metadata is IERC20 {\\n /**\\n * @dev Returns the name of the token.\\n */\\n function name() external view returns (string memory);\\n\\n /**\\n * @dev Returns the symbol of the token.\\n */\\n function symbol() external view returns (string memory);\\n\\n /**\\n * @dev Returns the decimals places of the token.\\n */\\n function decimals() external view returns (uint8);\\n}\\n\",\"keccak256\":\"0x8de418a5503946cabe331f35fe242d3201a73f67f77aaeb7110acb1f30423aca\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/Context.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Provides information about the current execution context, including the\\n * sender of the transaction and its data. While these are generally available\\n * via msg.sender and msg.data, they should not be accessed in such a direct\\n * manner, since when dealing with meta-transactions the account sending and\\n * paying for execution may not be the actual sender (as far as an application\\n * is concerned).\\n *\\n * This contract is only required for intermediate, library-like contracts.\\n */\\nabstract contract Context {\\n function _msgSender() internal view virtual returns (address) {\\n return msg.sender;\\n }\\n\\n function _msgData() internal view virtual returns (bytes calldata) {\\n return msg.data;\\n }\\n}\\n\",\"keccak256\":\"0xe2e337e6dde9ef6b680e07338c493ebea1b5fd09b43424112868e9cc1706bca7\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/Strings.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./math/Math.sol\\\";\\n\\n/**\\n * @dev String operations.\\n */\\nlibrary Strings {\\n bytes16 private constant _SYMBOLS = \\\"0123456789abcdef\\\";\\n uint8 private constant _ADDRESS_LENGTH = 20;\\n\\n /**\\n * @dev Converts a `uint256` to its ASCII `string` decimal representation.\\n */\\n function toString(uint256 value) internal pure returns (string memory) {\\n unchecked {\\n uint256 length = Math.log10(value) + 1;\\n string memory buffer = new string(length);\\n uint256 ptr;\\n /// @solidity memory-safe-assembly\\n assembly {\\n ptr := add(buffer, add(32, length))\\n }\\n while (true) {\\n ptr--;\\n /// @solidity memory-safe-assembly\\n assembly {\\n mstore8(ptr, byte(mod(value, 10), _SYMBOLS))\\n }\\n value /= 10;\\n if (value == 0) break;\\n }\\n return buffer;\\n }\\n }\\n\\n /**\\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\\n */\\n function toHexString(uint256 value) internal pure returns (string memory) {\\n unchecked {\\n return toHexString(value, Math.log256(value) + 1);\\n }\\n }\\n\\n /**\\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\\n */\\n function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\\n bytes memory buffer = new bytes(2 * length + 2);\\n buffer[0] = \\\"0\\\";\\n buffer[1] = \\\"x\\\";\\n for (uint256 i = 2 * length + 1; i > 1; --i) {\\n buffer[i] = _SYMBOLS[value & 0xf];\\n value >>= 4;\\n }\\n require(value == 0, \\\"Strings: hex length insufficient\\\");\\n return string(buffer);\\n }\\n\\n /**\\n * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.\\n */\\n function toHexString(address addr) internal pure returns (string memory) {\\n return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);\\n }\\n}\\n\",\"keccak256\":\"0xa4d1d62251f8574deb032a35fc948386a9b4de74b812d4f545a1ac120486b48a\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/introspection/ERC165.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./IERC165.sol\\\";\\n\\n/**\\n * @dev Implementation of the {IERC165} interface.\\n *\\n * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check\\n * for the additional interface id that will be supported. For example:\\n *\\n * ```solidity\\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\\n * }\\n * ```\\n *\\n * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.\\n */\\nabstract contract ERC165 is IERC165 {\\n /**\\n * @dev See {IERC165-supportsInterface}.\\n */\\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n return interfaceId == type(IERC165).interfaceId;\\n }\\n}\\n\",\"keccak256\":\"0xd10975de010d89fd1c78dc5e8a9a7e7f496198085c151648f20cba166b32582b\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/introspection/IERC165.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Interface of the ERC165 standard, as defined in the\\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\\n *\\n * Implementers can declare support of contract interfaces, which can then be\\n * queried by others ({ERC165Checker}).\\n *\\n * For an implementation, see {ERC165}.\\n */\\ninterface IERC165 {\\n /**\\n * @dev Returns true if this contract implements the interface defined by\\n * `interfaceId`. See the corresponding\\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\\n * to learn more about how these ids are created.\\n *\\n * This function call must use less than 30 000 gas.\\n */\\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\\n}\\n\",\"keccak256\":\"0x447a5f3ddc18419d41ff92b3773fb86471b1db25773e07f877f548918a185bf1\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/math/Math.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Standard math utilities missing in the Solidity language.\\n */\\nlibrary Math {\\n enum Rounding {\\n Down, // Toward negative infinity\\n Up, // Toward infinity\\n Zero // Toward zero\\n }\\n\\n /**\\n * @dev Returns the largest of two numbers.\\n */\\n function max(uint256 a, uint256 b) internal pure returns (uint256) {\\n return a > b ? a : b;\\n }\\n\\n /**\\n * @dev Returns the smallest of two numbers.\\n */\\n function min(uint256 a, uint256 b) internal pure returns (uint256) {\\n return a < b ? a : b;\\n }\\n\\n /**\\n * @dev Returns the average of two numbers. The result is rounded towards\\n * zero.\\n */\\n function average(uint256 a, uint256 b) internal pure returns (uint256) {\\n // (a + b) / 2 can overflow.\\n return (a & b) + (a ^ b) / 2;\\n }\\n\\n /**\\n * @dev Returns the ceiling of the division of two numbers.\\n *\\n * This differs from standard division with `/` in that it rounds up instead\\n * of rounding down.\\n */\\n function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {\\n // (a + b - 1) / b can overflow on addition, so we distribute.\\n return a == 0 ? 0 : (a - 1) / b + 1;\\n }\\n\\n /**\\n * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0\\n * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)\\n * with further edits by Uniswap Labs also under MIT license.\\n */\\n function mulDiv(\\n uint256 x,\\n uint256 y,\\n uint256 denominator\\n ) internal pure returns (uint256 result) {\\n unchecked {\\n // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use\\n // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256\\n // variables such that product = prod1 * 2^256 + prod0.\\n uint256 prod0; // Least significant 256 bits of the product\\n uint256 prod1; // Most significant 256 bits of the product\\n assembly {\\n let mm := mulmod(x, y, not(0))\\n prod0 := mul(x, y)\\n prod1 := sub(sub(mm, prod0), lt(mm, prod0))\\n }\\n\\n // Handle non-overflow cases, 256 by 256 division.\\n if (prod1 == 0) {\\n return prod0 / denominator;\\n }\\n\\n // Make sure the result is less than 2^256. Also prevents denominator == 0.\\n require(denominator > prod1);\\n\\n ///////////////////////////////////////////////\\n // 512 by 256 division.\\n ///////////////////////////////////////////////\\n\\n // Make division exact by subtracting the remainder from [prod1 prod0].\\n uint256 remainder;\\n assembly {\\n // Compute remainder using mulmod.\\n remainder := mulmod(x, y, denominator)\\n\\n // Subtract 256 bit number from 512 bit number.\\n prod1 := sub(prod1, gt(remainder, prod0))\\n prod0 := sub(prod0, remainder)\\n }\\n\\n // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.\\n // See https://cs.stackexchange.com/q/138556/92363.\\n\\n // Does not overflow because the denominator cannot be zero at this stage in the function.\\n uint256 twos = denominator & (~denominator + 1);\\n assembly {\\n // Divide denominator by twos.\\n denominator := div(denominator, twos)\\n\\n // Divide [prod1 prod0] by twos.\\n prod0 := div(prod0, twos)\\n\\n // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.\\n twos := add(div(sub(0, twos), twos), 1)\\n }\\n\\n // Shift in bits from prod1 into prod0.\\n prod0 |= prod1 * twos;\\n\\n // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such\\n // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for\\n // four bits. That is, denominator * inv = 1 mod 2^4.\\n uint256 inverse = (3 * denominator) ^ 2;\\n\\n // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works\\n // in modular arithmetic, doubling the correct bits in each step.\\n inverse *= 2 - denominator * inverse; // inverse mod 2^8\\n inverse *= 2 - denominator * inverse; // inverse mod 2^16\\n inverse *= 2 - denominator * inverse; // inverse mod 2^32\\n inverse *= 2 - denominator * inverse; // inverse mod 2^64\\n inverse *= 2 - denominator * inverse; // inverse mod 2^128\\n inverse *= 2 - denominator * inverse; // inverse mod 2^256\\n\\n // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.\\n // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is\\n // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1\\n // is no longer required.\\n result = prod0 * inverse;\\n return result;\\n }\\n }\\n\\n /**\\n * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.\\n */\\n function mulDiv(\\n uint256 x,\\n uint256 y,\\n uint256 denominator,\\n Rounding rounding\\n ) internal pure returns (uint256) {\\n uint256 result = mulDiv(x, y, denominator);\\n if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {\\n result += 1;\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.\\n *\\n * Inspired by Henry S. Warren, Jr.'s \\\"Hacker's Delight\\\" (Chapter 11).\\n */\\n function sqrt(uint256 a) internal pure returns (uint256) {\\n if (a == 0) {\\n return 0;\\n }\\n\\n // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.\\n //\\n // We know that the \\\"msb\\\" (most significant bit) of our target number `a` is a power of 2 such that we have\\n // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.\\n //\\n // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`\\n // \\u2192 `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`\\n // \\u2192 `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`\\n //\\n // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.\\n uint256 result = 1 << (log2(a) >> 1);\\n\\n // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,\\n // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at\\n // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision\\n // into the expected uint128 result.\\n unchecked {\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n result = (result + a / result) >> 1;\\n return min(result, a / result);\\n }\\n }\\n\\n /**\\n * @notice Calculates sqrt(a), following the selected rounding direction.\\n */\\n function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = sqrt(a);\\n return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);\\n }\\n }\\n\\n /**\\n * @dev Return the log in base 2, rounded down, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log2(uint256 value) internal pure returns (uint256) {\\n uint256 result = 0;\\n unchecked {\\n if (value >> 128 > 0) {\\n value >>= 128;\\n result += 128;\\n }\\n if (value >> 64 > 0) {\\n value >>= 64;\\n result += 64;\\n }\\n if (value >> 32 > 0) {\\n value >>= 32;\\n result += 32;\\n }\\n if (value >> 16 > 0) {\\n value >>= 16;\\n result += 16;\\n }\\n if (value >> 8 > 0) {\\n value >>= 8;\\n result += 8;\\n }\\n if (value >> 4 > 0) {\\n value >>= 4;\\n result += 4;\\n }\\n if (value >> 2 > 0) {\\n value >>= 2;\\n result += 2;\\n }\\n if (value >> 1 > 0) {\\n result += 1;\\n }\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Return the log in base 2, following the selected rounding direction, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = log2(value);\\n return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);\\n }\\n }\\n\\n /**\\n * @dev Return the log in base 10, rounded down, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log10(uint256 value) internal pure returns (uint256) {\\n uint256 result = 0;\\n unchecked {\\n if (value >= 10**64) {\\n value /= 10**64;\\n result += 64;\\n }\\n if (value >= 10**32) {\\n value /= 10**32;\\n result += 32;\\n }\\n if (value >= 10**16) {\\n value /= 10**16;\\n result += 16;\\n }\\n if (value >= 10**8) {\\n value /= 10**8;\\n result += 8;\\n }\\n if (value >= 10**4) {\\n value /= 10**4;\\n result += 4;\\n }\\n if (value >= 10**2) {\\n value /= 10**2;\\n result += 2;\\n }\\n if (value >= 10**1) {\\n result += 1;\\n }\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = log10(value);\\n return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);\\n }\\n }\\n\\n /**\\n * @dev Return the log in base 256, rounded down, of a positive value.\\n * Returns 0 if given 0.\\n *\\n * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.\\n */\\n function log256(uint256 value) internal pure returns (uint256) {\\n uint256 result = 0;\\n unchecked {\\n if (value >> 128 > 0) {\\n value >>= 128;\\n result += 16;\\n }\\n if (value >> 64 > 0) {\\n value >>= 64;\\n result += 8;\\n }\\n if (value >> 32 > 0) {\\n value >>= 32;\\n result += 4;\\n }\\n if (value >> 16 > 0) {\\n value >>= 16;\\n result += 2;\\n }\\n if (value >> 8 > 0) {\\n result += 1;\\n }\\n }\\n return result;\\n }\\n\\n /**\\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\\n * Returns 0 if given 0.\\n */\\n function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {\\n unchecked {\\n uint256 result = log256(value);\\n return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);\\n }\\n }\\n}\\n\",\"keccak256\":\"0xa1e8e83cd0087785df04ac79fb395d9f3684caeaf973d9e2c71caef723a3a5d6\",\"license\":\"MIT\"},\"src/Staking.sol\":{\"content\":\"// SPDX-License-Identifier: BSD-3-Clause\\npragma solidity ^0.8.19;\\nimport \\\"@openzeppelin/contracts/token/ERC20/ERC20.sol\\\";\\nimport \\\"@openzeppelin/contracts/access/AccessControl.sol\\\";\\nimport \\\"@openzeppelin/contracts/security/Pausable.sol\\\";\\n\\ninterface IPriceOracle {\\n function currentPrice() external view returns (uint32);\\n}\\n\\n/**\\n * @title Staking contract for the Swarm storage incentives\\n * @author The Swarm Authors\\n * @dev Allows users to stake tokens in order to be eligible for the Redistribution Schelling co-ordination game.\\n * Stakes are frozen or slashed by the Redistribution contract in response to violations of the\\n * protocol.\\n */\\n\\ncontract StakeRegistry is AccessControl, Pausable {\\n // ----------------------------- State variables ------------------------------\\n\\n struct Stake {\\n // Overlay of the node that is being staked\\n bytes32 overlay;\\n // Stake balance expressed through price oracle\\n uint256 committedStake;\\n // Stake balance expressed in BZZ\\n uint256 potentialStake;\\n // Block height the stake was updated, also used as flag to check if the stake is set\\n uint256 lastUpdatedBlockNumber;\\n // Node indicating its increased reserve\\n uint8 height;\\n }\\n\\n // Associate every stake id with node address data.\\n mapping(address => Stake) public stakes;\\n\\n // Role allowed to freeze and slash entries\\n bytes32 public constant REDISTRIBUTOR_ROLE = keccak256(\\\"REDISTRIBUTOR_ROLE\\\");\\n\\n // Swarm network ID\\n uint64 NetworkId;\\n\\n // The miniumum stake allowed to be staked using the Staking contract.\\n uint64 private constant MIN_STAKE = 100000000000000000;\\n\\n // Address of the staked ERC20 token\\n address public immutable bzzToken;\\n\\n // The address of the linked PriceOracle contract.\\n IPriceOracle public OracleContract;\\n\\n // ----------------------------- Events ------------------------------\\n\\n /**\\n * @dev Emitted when a stake is created or updated by `owner` of the `overlay`.\\n */\\n event StakeUpdated(\\n address indexed owner,\\n uint256 committedStake,\\n uint256 potentialStake,\\n bytes32 overlay,\\n uint256 lastUpdatedBlock,\\n uint8 height\\n );\\n\\n /**\\n * @dev Emitted when a stake for address `slashed` is slashed by `amount`.\\n */\\n event StakeSlashed(address slashed, bytes32 overlay, uint256 amount);\\n\\n /**\\n * @dev Emitted when a stake for address `frozen` is frozen for `time` blocks.\\n */\\n event StakeFrozen(address frozen, bytes32 overlay, uint256 time);\\n\\n /**\\n * @dev Emitted when a address changes overlay it uses\\n */\\n event OverlayChanged(address owner, bytes32 overlay);\\n\\n /**\\n * @dev Emitted when a stake for address is withdrawn\\n */\\n event StakeWithdrawn(address node, uint256 amount);\\n\\n // ----------------------------- Errors ------------------------------\\n\\n error TransferFailed(); // Used when token transfers fail\\n error Frozen(); // Used when an action cannot proceed because the overlay is frozen\\n error Unauthorized(); // Used where only the owner can perform the action\\n error OnlyRedistributor(); // Used when only the redistributor role is allowed\\n error OnlyPauser(); // Used when only the pauser role is allowed\\n error BelowMinimumStake(); // Node participating in game has stake below minimum treshold\\n\\n // ----------------------------- CONSTRUCTOR ------------------------------\\n\\n /**\\n * @param _bzzToken Address of the staked ERC20 token\\n * @param _NetworkId Swarm network ID\\n */\\n constructor(address _bzzToken, uint64 _NetworkId, address _oracleContract) {\\n NetworkId = _NetworkId;\\n bzzToken = _bzzToken;\\n OracleContract = IPriceOracle(_oracleContract);\\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\\n }\\n\\n ////////////////////////////////////////\\n // STATE SETTING //\\n ////////////////////////////////////////\\n\\n /**\\n * @notice Create a new stake or update an existing one, change overlay of node\\n * @dev At least `_initialBalancePerChunk*2^depth` number of tokens need to be preapproved for this contract.\\n * @param _setNonce Nonce that was used for overlay calculation.\\n * @param _addAmount Deposited amount of ERC20 tokens, equals to added Potential stake value\\n * @param _height increased reserve by registering the number of doublings\\n */\\n function manageStake(bytes32 _setNonce, uint256 _addAmount, uint8 _height) external whenNotPaused {\\n bytes32 _previousOverlay = stakes[msg.sender].overlay;\\n uint256 _stakingSet = stakes[msg.sender].lastUpdatedBlockNumber;\\n bytes32 _newOverlay = keccak256(abi.encodePacked(msg.sender, reverse(NetworkId), _setNonce));\\n\\n // First time adding stake, check the minimum is added, take into account height\\n if (_addAmount < MIN_STAKE * 2 ** _height && _stakingSet == 0) {\\n revert BelowMinimumStake();\\n }\\n\\n if (_stakingSet != 0 && !addressNotFrozen(msg.sender)) revert Frozen();\\n uint256 updatedPotentialStake = stakes[msg.sender].potentialStake + _addAmount;\\n uint256 updatedCommittedStake = updatedPotentialStake / (OracleContract.currentPrice() * 2 ** _height);\\n\\n stakes[msg.sender] = Stake({\\n overlay: _newOverlay,\\n committedStake: updatedCommittedStake,\\n potentialStake: updatedPotentialStake,\\n lastUpdatedBlockNumber: block.number,\\n height: _height\\n });\\n\\n // Transfer tokens and emit event that stake has been updated\\n if (_addAmount > 0) {\\n if (!ERC20(bzzToken).transferFrom(msg.sender, address(this), _addAmount)) revert TransferFailed();\\n emit StakeUpdated(\\n msg.sender,\\n updatedCommittedStake,\\n updatedPotentialStake,\\n _newOverlay,\\n block.number,\\n _height\\n );\\n }\\n\\n // Emit overlay change event\\n if (_previousOverlay != _newOverlay) {\\n emit OverlayChanged(msg.sender, _newOverlay);\\n }\\n }\\n\\n /**\\n * @dev Withdraw node stake surplus\\n */\\n function withdrawFromStake() external {\\n uint256 _potentialStake = stakes[msg.sender].potentialStake;\\n uint256 _surplusStake = _potentialStake -\\n calculateEffectiveStake(stakes[msg.sender].committedStake, _potentialStake, stakes[msg.sender].height);\\n\\n if (_surplusStake > 0) {\\n stakes[msg.sender].potentialStake -= _surplusStake;\\n if (!ERC20(bzzToken).transfer(msg.sender, _surplusStake)) revert TransferFailed();\\n emit StakeWithdrawn(msg.sender, _surplusStake);\\n }\\n }\\n\\n /**\\n * @dev Migrate stake only when the staking contract is paused,\\n * can only be called by the owner of the stake\\n */\\n function migrateStake() external whenPaused {\\n // We take out all the stake so user can migrate stake to other contract\\n if (lastUpdatedBlockNumberOfAddress(msg.sender) != 0) {\\n if (!ERC20(bzzToken).transfer(msg.sender, stakes[msg.sender].potentialStake)) revert TransferFailed();\\n delete stakes[msg.sender];\\n }\\n }\\n\\n /**\\n * @dev Freeze an existing stake, can only be called by the redistributor\\n * @param _owner the addres selected\\n * @param _time penalty length in blocknumbers\\n */\\n function freezeDeposit(address _owner, uint256 _time) external {\\n if (!hasRole(REDISTRIBUTOR_ROLE, msg.sender)) revert OnlyRedistributor();\\n\\n if (stakes[_owner].lastUpdatedBlockNumber != 0) {\\n stakes[_owner].lastUpdatedBlockNumber = block.number + _time;\\n emit StakeFrozen(_owner, stakes[_owner].overlay, _time);\\n }\\n }\\n\\n /**\\n * @dev Slash an existing stake, can only be called by the `redistributor`\\n * @param _owner the _owner adress selected\\n * @param _amount the amount to be slashed\\n */\\n function slashDeposit(address _owner, uint256 _amount) external {\\n if (!hasRole(REDISTRIBUTOR_ROLE, msg.sender)) revert OnlyRedistributor();\\n\\n if (stakes[_owner].lastUpdatedBlockNumber != 0) {\\n if (stakes[_owner].potentialStake > _amount) {\\n stakes[_owner].potentialStake -= _amount;\\n stakes[_owner].lastUpdatedBlockNumber = block.number;\\n } else {\\n delete stakes[_owner];\\n }\\n }\\n emit StakeSlashed(_owner, stakes[_owner].overlay, _amount);\\n }\\n\\n function changeNetworkId(uint64 _NetworkId) external {\\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) revert Unauthorized();\\n NetworkId = _NetworkId;\\n }\\n\\n /**\\n * @dev Pause the contract. The contract is provably stopped by renouncing\\n the pauser role and the admin role after pausing, can only be called by the `PAUSER`\\n */\\n function pause() public {\\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) revert OnlyPauser();\\n _pause();\\n }\\n\\n /**\\n * @dev Unpause the contract, can only be called by the pauser when paused\\n */\\n function unPause() public {\\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) revert OnlyPauser();\\n _unpause();\\n }\\n\\n ////////////////////////////////////////\\n // STATE READING //\\n ////////////////////////////////////////\\n\\n /**\\n * @dev Checks to see if `address` is frozen.\\n * @param _owner owner of staked address\\n *\\n * Returns a boolean value indicating whether the operation succeeded.\\n */\\n function addressNotFrozen(address _owner) internal view returns (bool) {\\n return stakes[_owner].lastUpdatedBlockNumber < block.number;\\n }\\n\\n /**\\n * @dev Returns the current `effectiveStake` of `address`. previously usable stake\\n * @param _owner _owner of node\\n */\\n function nodeEffectiveStake(address _owner) public view returns (uint256) {\\n return\\n addressNotFrozen(_owner)\\n ? calculateEffectiveStake(\\n stakes[_owner].committedStake,\\n stakes[_owner].potentialStake,\\n stakes[_owner].height\\n )\\n : 0;\\n }\\n\\n /**\\n * @dev Check the amount that is possible to withdraw as surplus\\n */\\n function withdrawableStake() public view returns (uint256) {\\n uint256 _potentialStake = stakes[msg.sender].potentialStake;\\n return\\n _potentialStake -\\n calculateEffectiveStake(stakes[msg.sender].committedStake, _potentialStake, stakes[msg.sender].height);\\n }\\n\\n /**\\n * @dev Returns the `lastUpdatedBlockNumber` of `address`.\\n */\\n function lastUpdatedBlockNumberOfAddress(address _owner) public view returns (uint256) {\\n return stakes[_owner].lastUpdatedBlockNumber;\\n }\\n\\n /**\\n * @dev Returns the currently used overlay of the address.\\n * @param _owner address of node\\n */\\n function overlayOfAddress(address _owner) public view returns (bytes32) {\\n return stakes[_owner].overlay;\\n }\\n\\n /**\\n * @dev Returns the currently height of the address.\\n * @param _owner address of node\\n */\\n function heightOfAddress(address _owner) public view returns (uint8) {\\n return stakes[_owner].height;\\n }\\n\\n function calculateEffectiveStake(\\n uint256 committedStake,\\n uint256 potentialStakeBalance,\\n uint8 height\\n ) internal view returns (uint256) {\\n // Calculate the product of committedStake and unitPrice to get price in BZZ\\n uint256 committedStakeBzz = (2 ** height) * committedStake * OracleContract.currentPrice();\\n\\n // Return the minimum value between committedStakeBzz and potentialStakeBalance\\n if (committedStakeBzz < potentialStakeBalance) {\\n return committedStakeBzz;\\n } else {\\n return potentialStakeBalance;\\n }\\n }\\n\\n /**\\n * @dev Please both Endians \\ud83e\\udd5a.\\n * @param input Eth address used for overlay calculation.\\n */\\n function reverse(uint64 input) internal pure returns (uint64 v) {\\n v = input;\\n\\n // swap bytes\\n v = ((v & 0xFF00FF00FF00FF00) >> 8) | ((v & 0x00FF00FF00FF00FF) << 8);\\n\\n // swap 2-byte long pairs\\n v = ((v & 0xFFFF0000FFFF0000) >> 16) | ((v & 0x0000FFFF0000FFFF) << 16);\\n\\n // swap 4-byte long pairs\\n v = (v >> 32) | (v << 32);\\n }\\n}\\n\",\"keccak256\":\"0xaa3bc2607ff345d2853b5b8f790d72f216ca5be1cee681805196b3985c830fc5\",\"license\":\"BSD-3-Clause\"}},\"version\":1}", + "bytecode": "0x60a06040523480156200001157600080fd5b5060405162001ca838038062001ca883398101604081905262000034916200015a565b6001805460ff19169055600380546001600160a01b03808616608052831668010000000000000000026001600160e01b03199091166001600160401b03851617179055620000846000336200008d565b505050620001b2565b6200009982826200009d565b5050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1662000099576000828152602081815260408083206001600160a01b03851684529091529020805460ff19166001179055620000f93390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b80516001600160a01b03811681146200015557600080fd5b919050565b6000806000606084860312156200017057600080fd5b6200017b846200013d565b60208501519093506001600160401b03811681146200019957600080fd5b9150620001a9604085016200013d565b90509250925092565b608051611ac5620001e3600039600081816102ea0152818161057c015281816106cb0152610b6d0152611ac56000f3fe608060405234801561001057600080fd5b50600436106101a35760003560e01c80636f1c5de7116100ee578063a6471a1d11610097578063d48bfaeb11610071578063d48bfaeb14610452578063d547741f14610465578063e8e8d87e14610478578063f7b188a51461048b57600080fd5b8063a6471a1d146103ec578063d009b2d614610413578063d1052d1f1461042657600080fd5b806391d14854116100c857806391d148541461038457806397adedb5146103bb578063a217fddf146103e457600080fd5b80636f1c5de714610361578063830a053e146103695780638456cb591461037c57600080fd5b80632f2ff15d116101505780635c975abb1161012a5780635c975abb14610324578063663e54f91461032f57806369da91141461034257600080fd5b80632f2ff15d146102bf57806336568abe146102d2578063420fc4db146102e557600080fd5b806316934fc41161018157806316934fc4146101e25780631d5480531461024d578063248a9ca31461028e57600080fd5b806301ffc9a7146101a85780630aed7b0d146101d057806312236a77146101da575b600080fd5b6101bb6101b6366004611673565b610493565b60405190151581526020015b60405180910390f35b6101d861052c565b005b6101d8610645565b6102226101f03660046116d1565b600260208190526000918252604090912080546001820154928201546003830154600490930154919392909160ff1685565b60408051958652602086019490945292840191909152606083015260ff16608082015260a0016101c7565b61027c61025b3660046116d1565b6001600160a01b031660009081526002602052604090206004015460ff1690565b60405160ff90911681526020016101c7565b6102b161029c3660046116ec565b60009081526020819052604090206001015490565b6040519081526020016101c7565b6101d86102cd366004611705565b61079c565b6101d86102e0366004611705565b6107c6565b61030c7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b0390911681526020016101c7565b60015460ff166101bb565b6101d861033d366004611731565b610853565b60035461030c906801000000000000000090046001600160a01b031681565b6102b1610c9d565b6102b16103773660046116d1565b610cdd565b6101d8610d3e565b6101bb610392366004611705565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b6102b16103c93660046116d1565b6001600160a01b031660009081526002602052604090205490565b6102b1600081565b6102b17f3e35b14a9f4fef84b59f9bdcd3044fc28783144b7e42bfb2cd075e6a02cb082881565b6101d8610421366004611770565b610d95565b6102b16104343660046116d1565b6001600160a01b031660009081526002602052604090206003015490565b6101d861046036600461179a565b610e71565b6101d8610473366004611705565b610efd565b6101d8610486366004611770565b610f22565b6101d861109d565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f7965db0b00000000000000000000000000000000000000000000000000000000148061052657507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008316145b92915050565b6105346110f4565b336000908152600260205260409020600301541561064357336000818152600260208190526040918290200154905163a9059cbb60e01b8152600481019290925260248201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063a9059cbb906044016020604051808303816000875af11580156105cd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105f191906117c4565b61060e576040516312171d8360e31b815260040160405180910390fd5b3360009081526002602081905260408220828155600181018390559081018290556003810191909155600401805460ff191690555b565b336000908152600260208190526040822090810154600182015460049092015490929161067691849060ff16611146565b61068090836117fc565b905080156107985733600090815260026020819052604082200180548392906106aa9084906117fc565b909155505060405163a9059cbb60e01b8152336004820152602481018290527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063a9059cbb906044016020604051808303816000875af115801561071c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061074091906117c4565b61075d576040516312171d8360e31b815260040160405180910390fd5b60408051338152602081018390527f8108595eb6bad3acefa9da467d90cc2217686d5c5ac85460f8b7849c840645fc91015b60405180910390a15b5050565b6000828152602081905260409020600101546107b781611203565b6107c18383611210565b505050565b6001600160a01b03811633146108495760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b61079882826112ae565b61085b61132d565b336000818152600260209081526040822080546003918201549154909491939265ff000000ff00600883811b91821664ff000000ff9490911c93841617601090811b67ff000000ff0000009290921666ff000000ff0000949094169390931790921c9190911780821b6bffffffffffffffff0000000016911c63ffffffff161760405160609290921b6bffffffffffffffffffffffff1916602083015260c01b7fffffffffffffffff000000000000000000000000000000000000000000000000166034820152603c8101879052605c0160405160208183030381529060405280519060200120905083600261095191906118f3565b6109639067016345785d8a0000611902565b8510801561096f575081155b156109a6576040517f8ecf3d0300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b81158015906109c75750336000908152600260205260409020600301544311155b156109fe576040517fa8cab3d100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b33600090815260026020819052604082200154610a1c908790611919565b90506000610a2b8660026118f3565b600360089054906101000a90046001600160a01b03166001600160a01b0316639d1b464a6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610a7e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610aa2919061192c565b63ffffffff16610ab29190611902565b610abc9083611952565b6040805160a0810182528581526020808201848152828401878152436060850190815260ff8d8116608087019081523360009081526002968790529790972095518655925160018601559051928401929092559051600383015591516004909101805460ff19169190921617905590508615610c52576040517f23b872dd000000000000000000000000000000000000000000000000000000008152336004820152306024820152604481018890527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906323b872dd906064016020604051808303816000875af1158015610bbe573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610be291906117c4565b610bff576040516312171d8360e31b815260040160405180910390fd5b604080518281526020810184905290810184905243606082015260ff8716608082015233907f8fb3da6e133de1007392b10d429548e9c2565c791c52e1498b01b65d8797e74c9060a00160405180910390a25b828514610c935760408051338152602081018590527fe188baf4bcb1c4413d19ba0eaef908614d30e8df9570d6fc4d584b75f4a37a3a910160405180910390a15b5050505050505050565b33600090815260026020819052604082209081015460018201546004909201549091610ccd91839060ff16611146565b610cd790826117fc565b91505090565b6001600160a01b0381166000908152600260205260408120600301544311610d06576000610526565b6001600160a01b038216600090815260026020819052604090912060018101549181015460049091015461052692919060ff16611146565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff16610d8d57604051631d77d47760e21b815260040160405180910390fd5b610643611380565b3360009081527f10fa80d2e578284bf61a483a3da84fbdd683a7e7256a9895dc4461ac543f4a16602052604090205460ff16610de457604051630490edbf60e31b815260040160405180910390fd5b6001600160a01b0382166000908152600260205260409020600301541561079857610e0f8143611919565b6001600160a01b038316600081815260026020908152604091829020600381019490945592548151928352928201929092529081018290527fd7863535575e7de6678ea9d340a4bfe0b84d77323bfa2ef602c3c1df82aea7809060600161078f565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff16610ed9576040517f82b4290000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6003805467ffffffffffffffff191667ffffffffffffffff92909216919091179055565b600082815260208190526040902060010154610f1881611203565b6107c183836112ae565b3360009081527f10fa80d2e578284bf61a483a3da84fbdd683a7e7256a9895dc4461ac543f4a16602052604090205460ff16610f7157604051630490edbf60e31b815260040160405180910390fd5b6001600160a01b03821660009081526002602052604090206003015415611048576001600160a01b0382166000908152600260208190526040909120015481101561100a576001600160a01b03821660009081526002602081905260408220018054839290610fe19084906117fc565b90915550506001600160a01b038216600090815260026020526040902043600390910155611048565b6001600160a01b03821660009081526002602081905260408220828155600181018390559081018290556003810191909155600401805460ff191690555b6001600160a01b0382166000818152600260209081526040918290205482519384529083015281018290527f5f52ce031e6eba64e8a81288196b93a3e422096e80aea812f1f5a77866359b3a9060600161078f565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff166110ec57604051631d77d47760e21b815260040160405180910390fd5b6106436113d4565b60015460ff166106435760405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f74207061757365640000000000000000000000006044820152606401610840565b600080600360089054906101000a90046001600160a01b03166001600160a01b0316639d1b464a6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561119c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111c0919061192c565b63ffffffff16856111d28560026118f3565b6111dc9190611902565b6111e69190611902565b9050838110156111f75790506111fc565b839150505b9392505050565b61120d813361140d565b50565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610798576000828152602081815260408083206001600160a01b03851684529091529020805460ff1916600117905561126a3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1615610798576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b60015460ff16156106435760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a20706175736564000000000000000000000000000000006044820152606401610840565b61138861132d565b6001805460ff1916811790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258335b6040516001600160a01b03909116815260200160405180910390a1565b6113dc6110f4565b6001805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa336113b7565b6000828152602081815260408083206001600160a01b038516845290915290205460ff166107985761143e81611480565b611449836020611492565b60405160200161145a929190611998565b60408051601f198184030181529082905262461bcd60e51b825261084091600401611a19565b60606105266001600160a01b03831660145b606060006114a1836002611902565b6114ac906002611919565b67ffffffffffffffff8111156114c4576114c4611a4c565b6040519080825280601f01601f1916602001820160405280156114ee576020820181803683370190505b5090507f30000000000000000000000000000000000000000000000000000000000000008160008151811061152557611525611a62565b60200101906001600160f81b031916908160001a9053507f78000000000000000000000000000000000000000000000000000000000000008160018151811061157057611570611a62565b60200101906001600160f81b031916908160001a9053506000611594846002611902565b61159f906001611919565b90505b6001811115611624577f303132333435363738396162636465660000000000000000000000000000000085600f16601081106115e0576115e0611a62565b1a60f81b8282815181106115f6576115f6611a62565b60200101906001600160f81b031916908160001a90535060049490941c9361161d81611a78565b90506115a2565b5083156111fc5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610840565b60006020828403121561168557600080fd5b81357fffffffff00000000000000000000000000000000000000000000000000000000811681146111fc57600080fd5b80356001600160a01b03811681146116cc57600080fd5b919050565b6000602082840312156116e357600080fd5b6111fc826116b5565b6000602082840312156116fe57600080fd5b5035919050565b6000806040838503121561171857600080fd5b82359150611728602084016116b5565b90509250929050565b60008060006060848603121561174657600080fd5b8335925060208401359150604084013560ff8116811461176557600080fd5b809150509250925092565b6000806040838503121561178357600080fd5b61178c836116b5565b946020939093013593505050565b6000602082840312156117ac57600080fd5b813567ffffffffffffffff811681146111fc57600080fd5b6000602082840312156117d657600080fd5b815180151581146111fc57600080fd5b634e487b7160e01b600052601160045260246000fd5b81810381811115610526576105266117e6565b600181815b8085111561184a578160001904821115611830576118306117e6565b8085161561183d57918102915b93841c9390800290611814565b509250929050565b60008261186157506001610526565b8161186e57506000610526565b8160018114611884576002811461188e576118aa565b6001915050610526565b60ff84111561189f5761189f6117e6565b50506001821b610526565b5060208310610133831016604e8410600b84101617156118cd575081810a610526565b6118d7838361180f565b80600019048211156118eb576118eb6117e6565b029392505050565b60006111fc60ff841683611852565b8082028115828204841417610526576105266117e6565b80820180821115610526576105266117e6565b60006020828403121561193e57600080fd5b815163ffffffff811681146111fc57600080fd5b60008261196f57634e487b7160e01b600052601260045260246000fd5b500490565b60005b8381101561198f578181015183820152602001611977565b50506000910152565b7f416363657373436f6e74726f6c3a206163636f756e74200000000000000000008152600083516119d0816017850160208801611974565b7f206973206d697373696e6720726f6c65200000000000000000000000000000006017918401918201528351611a0d816028840160208801611974565b01602801949350505050565b6020815260008251806020840152611a38816040850160208701611974565b601f01601f19169190910160400192915050565b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b600081611a8757611a876117e6565b50600019019056fea2646970667358221220ff91de3fa40e277999ea9df6f0ac0b44544ec6c733dc037c85cb8464053c758e64736f6c63430008130033", + "deployedBytecode": "0x608060405234801561001057600080fd5b50600436106101a35760003560e01c80636f1c5de7116100ee578063a6471a1d11610097578063d48bfaeb11610071578063d48bfaeb14610452578063d547741f14610465578063e8e8d87e14610478578063f7b188a51461048b57600080fd5b8063a6471a1d146103ec578063d009b2d614610413578063d1052d1f1461042657600080fd5b806391d14854116100c857806391d148541461038457806397adedb5146103bb578063a217fddf146103e457600080fd5b80636f1c5de714610361578063830a053e146103695780638456cb591461037c57600080fd5b80632f2ff15d116101505780635c975abb1161012a5780635c975abb14610324578063663e54f91461032f57806369da91141461034257600080fd5b80632f2ff15d146102bf57806336568abe146102d2578063420fc4db146102e557600080fd5b806316934fc41161018157806316934fc4146101e25780631d5480531461024d578063248a9ca31461028e57600080fd5b806301ffc9a7146101a85780630aed7b0d146101d057806312236a77146101da575b600080fd5b6101bb6101b6366004611673565b610493565b60405190151581526020015b60405180910390f35b6101d861052c565b005b6101d8610645565b6102226101f03660046116d1565b600260208190526000918252604090912080546001820154928201546003830154600490930154919392909160ff1685565b60408051958652602086019490945292840191909152606083015260ff16608082015260a0016101c7565b61027c61025b3660046116d1565b6001600160a01b031660009081526002602052604090206004015460ff1690565b60405160ff90911681526020016101c7565b6102b161029c3660046116ec565b60009081526020819052604090206001015490565b6040519081526020016101c7565b6101d86102cd366004611705565b61079c565b6101d86102e0366004611705565b6107c6565b61030c7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b0390911681526020016101c7565b60015460ff166101bb565b6101d861033d366004611731565b610853565b60035461030c906801000000000000000090046001600160a01b031681565b6102b1610c9d565b6102b16103773660046116d1565b610cdd565b6101d8610d3e565b6101bb610392366004611705565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b6102b16103c93660046116d1565b6001600160a01b031660009081526002602052604090205490565b6102b1600081565b6102b17f3e35b14a9f4fef84b59f9bdcd3044fc28783144b7e42bfb2cd075e6a02cb082881565b6101d8610421366004611770565b610d95565b6102b16104343660046116d1565b6001600160a01b031660009081526002602052604090206003015490565b6101d861046036600461179a565b610e71565b6101d8610473366004611705565b610efd565b6101d8610486366004611770565b610f22565b6101d861109d565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f7965db0b00000000000000000000000000000000000000000000000000000000148061052657507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008316145b92915050565b6105346110f4565b336000908152600260205260409020600301541561064357336000818152600260208190526040918290200154905163a9059cbb60e01b8152600481019290925260248201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063a9059cbb906044016020604051808303816000875af11580156105cd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105f191906117c4565b61060e576040516312171d8360e31b815260040160405180910390fd5b3360009081526002602081905260408220828155600181018390559081018290556003810191909155600401805460ff191690555b565b336000908152600260208190526040822090810154600182015460049092015490929161067691849060ff16611146565b61068090836117fc565b905080156107985733600090815260026020819052604082200180548392906106aa9084906117fc565b909155505060405163a9059cbb60e01b8152336004820152602481018290527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063a9059cbb906044016020604051808303816000875af115801561071c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061074091906117c4565b61075d576040516312171d8360e31b815260040160405180910390fd5b60408051338152602081018390527f8108595eb6bad3acefa9da467d90cc2217686d5c5ac85460f8b7849c840645fc91015b60405180910390a15b5050565b6000828152602081905260409020600101546107b781611203565b6107c18383611210565b505050565b6001600160a01b03811633146108495760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b61079882826112ae565b61085b61132d565b336000818152600260209081526040822080546003918201549154909491939265ff000000ff00600883811b91821664ff000000ff9490911c93841617601090811b67ff000000ff0000009290921666ff000000ff0000949094169390931790921c9190911780821b6bffffffffffffffff0000000016911c63ffffffff161760405160609290921b6bffffffffffffffffffffffff1916602083015260c01b7fffffffffffffffff000000000000000000000000000000000000000000000000166034820152603c8101879052605c0160405160208183030381529060405280519060200120905083600261095191906118f3565b6109639067016345785d8a0000611902565b8510801561096f575081155b156109a6576040517f8ecf3d0300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b81158015906109c75750336000908152600260205260409020600301544311155b156109fe576040517fa8cab3d100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b33600090815260026020819052604082200154610a1c908790611919565b90506000610a2b8660026118f3565b600360089054906101000a90046001600160a01b03166001600160a01b0316639d1b464a6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610a7e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610aa2919061192c565b63ffffffff16610ab29190611902565b610abc9083611952565b6040805160a0810182528581526020808201848152828401878152436060850190815260ff8d8116608087019081523360009081526002968790529790972095518655925160018601559051928401929092559051600383015591516004909101805460ff19169190921617905590508615610c52576040517f23b872dd000000000000000000000000000000000000000000000000000000008152336004820152306024820152604481018890527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906323b872dd906064016020604051808303816000875af1158015610bbe573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610be291906117c4565b610bff576040516312171d8360e31b815260040160405180910390fd5b604080518281526020810184905290810184905243606082015260ff8716608082015233907f8fb3da6e133de1007392b10d429548e9c2565c791c52e1498b01b65d8797e74c9060a00160405180910390a25b828514610c935760408051338152602081018590527fe188baf4bcb1c4413d19ba0eaef908614d30e8df9570d6fc4d584b75f4a37a3a910160405180910390a15b5050505050505050565b33600090815260026020819052604082209081015460018201546004909201549091610ccd91839060ff16611146565b610cd790826117fc565b91505090565b6001600160a01b0381166000908152600260205260408120600301544311610d06576000610526565b6001600160a01b038216600090815260026020819052604090912060018101549181015460049091015461052692919060ff16611146565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff16610d8d57604051631d77d47760e21b815260040160405180910390fd5b610643611380565b3360009081527f10fa80d2e578284bf61a483a3da84fbdd683a7e7256a9895dc4461ac543f4a16602052604090205460ff16610de457604051630490edbf60e31b815260040160405180910390fd5b6001600160a01b0382166000908152600260205260409020600301541561079857610e0f8143611919565b6001600160a01b038316600081815260026020908152604091829020600381019490945592548151928352928201929092529081018290527fd7863535575e7de6678ea9d340a4bfe0b84d77323bfa2ef602c3c1df82aea7809060600161078f565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff16610ed9576040517f82b4290000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6003805467ffffffffffffffff191667ffffffffffffffff92909216919091179055565b600082815260208190526040902060010154610f1881611203565b6107c183836112ae565b3360009081527f10fa80d2e578284bf61a483a3da84fbdd683a7e7256a9895dc4461ac543f4a16602052604090205460ff16610f7157604051630490edbf60e31b815260040160405180910390fd5b6001600160a01b03821660009081526002602052604090206003015415611048576001600160a01b0382166000908152600260208190526040909120015481101561100a576001600160a01b03821660009081526002602081905260408220018054839290610fe19084906117fc565b90915550506001600160a01b038216600090815260026020526040902043600390910155611048565b6001600160a01b03821660009081526002602081905260408220828155600181018390559081018290556003810191909155600401805460ff191690555b6001600160a01b0382166000818152600260209081526040918290205482519384529083015281018290527f5f52ce031e6eba64e8a81288196b93a3e422096e80aea812f1f5a77866359b3a9060600161078f565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff166110ec57604051631d77d47760e21b815260040160405180910390fd5b6106436113d4565b60015460ff166106435760405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f74207061757365640000000000000000000000006044820152606401610840565b600080600360089054906101000a90046001600160a01b03166001600160a01b0316639d1b464a6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561119c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111c0919061192c565b63ffffffff16856111d28560026118f3565b6111dc9190611902565b6111e69190611902565b9050838110156111f75790506111fc565b839150505b9392505050565b61120d813361140d565b50565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610798576000828152602081815260408083206001600160a01b03851684529091529020805460ff1916600117905561126a3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1615610798576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b60015460ff16156106435760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a20706175736564000000000000000000000000000000006044820152606401610840565b61138861132d565b6001805460ff1916811790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258335b6040516001600160a01b03909116815260200160405180910390a1565b6113dc6110f4565b6001805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa336113b7565b6000828152602081815260408083206001600160a01b038516845290915290205460ff166107985761143e81611480565b611449836020611492565b60405160200161145a929190611998565b60408051601f198184030181529082905262461bcd60e51b825261084091600401611a19565b60606105266001600160a01b03831660145b606060006114a1836002611902565b6114ac906002611919565b67ffffffffffffffff8111156114c4576114c4611a4c565b6040519080825280601f01601f1916602001820160405280156114ee576020820181803683370190505b5090507f30000000000000000000000000000000000000000000000000000000000000008160008151811061152557611525611a62565b60200101906001600160f81b031916908160001a9053507f78000000000000000000000000000000000000000000000000000000000000008160018151811061157057611570611a62565b60200101906001600160f81b031916908160001a9053506000611594846002611902565b61159f906001611919565b90505b6001811115611624577f303132333435363738396162636465660000000000000000000000000000000085600f16601081106115e0576115e0611a62565b1a60f81b8282815181106115f6576115f6611a62565b60200101906001600160f81b031916908160001a90535060049490941c9361161d81611a78565b90506115a2565b5083156111fc5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610840565b60006020828403121561168557600080fd5b81357fffffffff00000000000000000000000000000000000000000000000000000000811681146111fc57600080fd5b80356001600160a01b03811681146116cc57600080fd5b919050565b6000602082840312156116e357600080fd5b6111fc826116b5565b6000602082840312156116fe57600080fd5b5035919050565b6000806040838503121561171857600080fd5b82359150611728602084016116b5565b90509250929050565b60008060006060848603121561174657600080fd5b8335925060208401359150604084013560ff8116811461176557600080fd5b809150509250925092565b6000806040838503121561178357600080fd5b61178c836116b5565b946020939093013593505050565b6000602082840312156117ac57600080fd5b813567ffffffffffffffff811681146111fc57600080fd5b6000602082840312156117d657600080fd5b815180151581146111fc57600080fd5b634e487b7160e01b600052601160045260246000fd5b81810381811115610526576105266117e6565b600181815b8085111561184a578160001904821115611830576118306117e6565b8085161561183d57918102915b93841c9390800290611814565b509250929050565b60008261186157506001610526565b8161186e57506000610526565b8160018114611884576002811461188e576118aa565b6001915050610526565b60ff84111561189f5761189f6117e6565b50506001821b610526565b5060208310610133831016604e8410600b84101617156118cd575081810a610526565b6118d7838361180f565b80600019048211156118eb576118eb6117e6565b029392505050565b60006111fc60ff841683611852565b8082028115828204841417610526576105266117e6565b80820180821115610526576105266117e6565b60006020828403121561193e57600080fd5b815163ffffffff811681146111fc57600080fd5b60008261196f57634e487b7160e01b600052601260045260246000fd5b500490565b60005b8381101561198f578181015183820152602001611977565b50506000910152565b7f416363657373436f6e74726f6c3a206163636f756e74200000000000000000008152600083516119d0816017850160208801611974565b7f206973206d697373696e6720726f6c65200000000000000000000000000000006017918401918201528351611a0d816028840160208801611974565b01602801949350505050565b6020815260008251806020840152611a38816040850160208701611974565b601f01601f19169190910160400192915050565b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b600081611a8757611a876117e6565b50600019019056fea2646970667358221220ff91de3fa40e277999ea9df6f0ac0b44544ec6c733dc037c85cb8464053c758e64736f6c63430008130033", "devdoc": { "author": "The Swarm Authors", "details": "Allows users to stake tokens in order to be eligible for the Redistribution Schelling co-ordination game. Stakes are frozen or slashed by the Redistribution contract in response to violations of the protocol.", @@ -759,8 +761,8 @@ "StakeSlashed(address,bytes32,uint256)": { "details": "Emitted when a stake for address `slashed` is slashed by `amount`." }, - "StakeUpdated(address,uint256,uint256,bytes32,uint256)": { - "details": "Emitted when a stake is created or updated by `owner` of the `overlay` by `committedStake`, and `potentialStake` during `lastUpdatedBlock`." + "StakeUpdated(address,uint256,uint256,bytes32,uint256,uint8)": { + "details": "Emitted when a stake is created or updated by `owner` of the `overlay`." }, "StakeWithdrawn(address,uint256)": { "details": "Emitted when a stake for address is withdrawn" @@ -793,13 +795,20 @@ "hasRole(bytes32,address)": { "details": "Returns `true` if `account` has been granted `role`." }, + "heightOfAddress(address)": { + "details": "Returns the currently height of the address.", + "params": { + "_owner": "address of node" + } + }, "lastUpdatedBlockNumberOfAddress(address)": { "details": "Returns the `lastUpdatedBlockNumber` of `address`." }, - "manageStake(bytes32,uint256)": { + "manageStake(bytes32,uint256,uint8)": { "details": "At least `_initialBalancePerChunk*2^depth` number of tokens need to be preapproved for this contract.", "params": { "_addAmount": "Deposited amount of ERC20 tokens, equals to added Potential stake value", + "_height": "increased reserve by registering the number of doublings", "_setNonce": "Nonce that was used for overlay calculation." } }, @@ -856,7 +865,7 @@ "userdoc": { "kind": "user", "methods": { - "manageStake(bytes32,uint256)": { + "manageStake(bytes32,uint256,uint8)": { "notice": "Create a new stake or update an existing one, change overlay of node" } }, @@ -881,15 +890,15 @@ "type": "t_bool" }, { - "astId": 9741, + "astId": 9861, "contract": "src/Staking.sol:StakeRegistry", "label": "stakes", "offset": 0, "slot": "2", - "type": "t_mapping(t_address,t_struct(Stake)9736_storage)" + "type": "t_mapping(t_address,t_struct(Stake)9856_storage)" }, { - "astId": 9753, + "astId": 9868, "contract": "src/Staking.sol:StakeRegistry", "label": "NetworkId", "offset": 0, @@ -897,12 +906,12 @@ "type": "t_uint64" }, { - "astId": 9761, + "astId": 9876, "contract": "src/Staking.sol:StakeRegistry", "label": "OracleContract", "offset": 8, "slot": "3", - "type": "t_contract(IPriceOracle)9720" + "type": "t_contract(IPriceOracle)9840" } ], "types": { @@ -921,7 +930,7 @@ "label": "bytes32", "numberOfBytes": "32" }, - "t_contract(IPriceOracle)9720": { + "t_contract(IPriceOracle)9840": { "encoding": "inplace", "label": "contract IPriceOracle", "numberOfBytes": "20" @@ -933,12 +942,12 @@ "numberOfBytes": "32", "value": "t_bool" }, - "t_mapping(t_address,t_struct(Stake)9736_storage)": { + "t_mapping(t_address,t_struct(Stake)9856_storage)": { "encoding": "mapping", "key": "t_address", "label": "mapping(address => struct StakeRegistry.Stake)", "numberOfBytes": "32", - "value": "t_struct(Stake)9736_storage" + "value": "t_struct(Stake)9856_storage" }, "t_mapping(t_bytes32,t_struct(RoleData)19_storage)": { "encoding": "mapping", @@ -970,12 +979,12 @@ ], "numberOfBytes": "64" }, - "t_struct(Stake)9736_storage": { + "t_struct(Stake)9856_storage": { "encoding": "inplace", "label": "struct StakeRegistry.Stake", "members": [ { - "astId": 9727, + "astId": 9847, "contract": "src/Staking.sol:StakeRegistry", "label": "overlay", "offset": 0, @@ -983,7 +992,7 @@ "type": "t_bytes32" }, { - "astId": 9729, + "astId": 9849, "contract": "src/Staking.sol:StakeRegistry", "label": "committedStake", "offset": 0, @@ -991,7 +1000,7 @@ "type": "t_uint256" }, { - "astId": 9731, + "astId": 9851, "contract": "src/Staking.sol:StakeRegistry", "label": "potentialStake", "offset": 0, @@ -999,7 +1008,7 @@ "type": "t_uint256" }, { - "astId": 9733, + "astId": 9853, "contract": "src/Staking.sol:StakeRegistry", "label": "lastUpdatedBlockNumber", "offset": 0, @@ -1007,12 +1016,12 @@ "type": "t_uint256" }, { - "astId": 9735, + "astId": 9855, "contract": "src/Staking.sol:StakeRegistry", - "label": "isValue", + "label": "height", "offset": 0, "slot": "4", - "type": "t_bool" + "type": "t_uint8" } ], "numberOfBytes": "160" @@ -1026,6 +1035,11 @@ "encoding": "inplace", "label": "uint64", "numberOfBytes": "8" + }, + "t_uint8": { + "encoding": "inplace", + "label": "uint8", + "numberOfBytes": "1" } } } diff --git a/deployments/testnetlight/solcInputs/0832aa87b3772da802f21b970bba5942.json b/deployments/testnetlight/solcInputs/0713424b44e4d07fab3794bffaf90dbd.json similarity index 69% rename from deployments/testnetlight/solcInputs/0832aa87b3772da802f21b970bba5942.json rename to deployments/testnetlight/solcInputs/0713424b44e4d07fab3794bffaf90dbd.json index 8bb8d0e2..cec2e32e 100644 --- a/deployments/testnetlight/solcInputs/0832aa87b3772da802f21b970bba5942.json +++ b/deployments/testnetlight/solcInputs/0713424b44e4d07fab3794bffaf90dbd.json @@ -62,13 +62,13 @@ "content": "// SPDX-License-Identifier: BSD-3-Clause\npragma solidity ^0.8.19;\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"@openzeppelin/contracts/security/Pausable.sol\";\nimport \"./OrderStatisticsTree/HitchensOrderStatisticsTreeLib.sol\";\n\n/**\n * @title PostageStamp contract\n * @author The Swarm Authors\n * @dev The postage stamp contracts allows users to create and manage postage stamp batches.\n * The current balance for each batch is stored ordered in descending order of normalised balance.\n * Balance is normalised to be per chunk and the total spend since the contract was deployed, i.e. when a batch\n * is bought, its per-chunk balance is supplemented with the current cost of storing one chunk since the beginning of time,\n * as if the batch had existed since the contract's inception. During the _expiry_ process, each of these balances is\n * checked against the _currentTotalOutPayment_, a similarly normalised figure that represents the current cost of\n * storing one chunk since the beginning of time. A batch with a normalised balance less than _currentTotalOutPayment_\n * is treated as expired.\n *\n * The _currentTotalOutPayment_ is calculated using _totalOutPayment_ which is updated during _setPrice_ events so\n * that the applicable per-chunk prices can be charged for the relevant periods of time. This can then be multiplied\n * by the amount of chunks which are allowed to be stamped by each batch to get the actual cost of storage.\n *\n * The amount of chunks a batch can stamp is determined by the _bucketDepth_. A batch may store a maximum of 2^depth chunks.\n * The global figure for the currently allowed chunks is tracked by _validChunkCount_ and updated during batch _expiry_ events.\n */\n\ncontract PostageStamp is AccessControl, Pausable {\n using HitchensOrderStatisticsTreeLib for HitchensOrderStatisticsTreeLib.Tree;\n\n // ----------------------------- State variables ------------------------------\n\n // Address of the ERC20 token this contract references.\n address public bzzToken;\n\n // Minimum allowed depth of bucket.\n uint8 public minimumBucketDepth;\n\n // Role allowed to increase totalOutPayment.\n bytes32 public immutable PRICE_ORACLE_ROLE;\n\n // Role allowed to pause\n bytes32 public immutable PAUSER_ROLE;\n // Role allowed to withdraw the pot.\n bytes32 public immutable REDISTRIBUTOR_ROLE;\n\n // Associate every batch id with batch data.\n mapping(bytes32 => Batch) public batches;\n // Store every batch id ordered by normalisedBalance.\n HitchensOrderStatisticsTreeLib.Tree tree;\n\n // Total out payment per chunk, at the blockheight of the last price change.\n uint256 private totalOutPayment;\n\n // Combined global chunk capacity of valid batches remaining at the blockheight expire() was last called.\n uint256 public validChunkCount;\n\n // Lottery pot at last update.\n uint256 public pot;\n\n // Normalised balance at the blockheight expire() was last called.\n uint256 public lastExpiryBalance;\n\n // Price from the last update.\n uint64 public lastPrice;\n\n // blocks in 24 hours ~ 24 * 60 * 60 / 5 = 17280\n uint64 public minimumValidityBlocks = 17280;\n\n // Block at which the last update occured.\n uint64 public lastUpdatedBlock;\n\n // ----------------------------- Type declarations ------------------------------\n\n struct Batch {\n // Owner of this batch (0 if not valid).\n address owner;\n // Current depth of this batch.\n uint8 depth;\n // Bucket depth defined in this batch\n uint8 bucketDepth;\n // Whether this batch is immutable.\n bool immutableFlag;\n // Normalised balance per chunk.\n uint256 normalisedBalance;\n // When was this batch last updated\n uint256 lastUpdatedBlockNumber;\n }\n\n struct ImportBatch {\n bytes32 batchId;\n address owner;\n uint8 depth;\n uint8 bucketDepth;\n bool immutableFlag;\n uint256 remainingBalance;\n }\n\n // ----------------------------- Events ------------------------------\n\n /**\n * @dev Emitted when a new batch is created.\n */\n event BatchCreated(\n bytes32 indexed batchId,\n uint256 totalAmount,\n uint256 normalisedBalance,\n address owner,\n uint8 depth,\n uint8 bucketDepth,\n bool immutableFlag\n );\n\n /**\n * @dev Emitted when an pot is Withdrawn.\n */\n event PotWithdrawn(address recipient, uint256 totalAmount);\n\n /**\n * @dev Emitted when an existing batch is topped up.\n */\n event BatchTopUp(bytes32 indexed batchId, uint256 topupAmount, uint256 normalisedBalance);\n\n /**\n * @dev Emitted when the depth of an existing batch increases.\n */\n event BatchDepthIncrease(bytes32 indexed batchId, uint8 newDepth, uint256 normalisedBalance);\n\n /**\n *@dev Emitted on every price update.\n */\n event PriceUpdate(uint256 price);\n\n /**\n *@dev Emitted on every batch failed in bulk batch creation\n */\n event CopyBatchFailed(uint index, bytes32 batchId);\n\n // ----------------------------- Errors ------------------------------\n\n error ZeroAddress(); // Owner cannot be the zero address\n error InvalidDepth(); // Invalid bucket depth\n error BatchExists(); // Batch already exists\n error InsufficientBalance(); // Insufficient initial balance for 24h minimum validity\n error TransferFailed(); // Failed transfer of BZZ tokens\n error ZeroBalance(); // NormalisedBalance cannot be zero\n error AdministratorOnly(); // Only administrator can use copy method\n error BatchDoesNotExist(); // Batch does not exist or has expired\n error BatchExpired(); // Batch already expired\n error BatchTooSmall(); // Batch too small to renew\n error NotBatchOwner(); // Not batch owner\n error DepthNotIncreasing(); // Depth not increasing\n error PriceOracleOnly(); // Only price oracle can set the price\n error InsufficienChunkCount(); // Insufficient valid chunk count\n error TotalOutpaymentDecreased(); // Current total outpayment should never decrease\n error NoBatchesExist(); // There are no batches\n error OnlyPauser(); // Only Pauser role can pause or unpause contracts\n error OnlyRedistributor(); // Only redistributor role can withdraw from the contract\n\n // ----------------------------- CONSTRUCTOR ------------------------------\n\n /**\n * @param _bzzToken The ERC20 token address to reference in this contract.\n * @param _minimumBucketDepth The minimum bucket depth of batches that can be purchased.\n */\n constructor(address _bzzToken, uint8 _minimumBucketDepth) {\n bzzToken = _bzzToken;\n minimumBucketDepth = _minimumBucketDepth;\n PRICE_ORACLE_ROLE = keccak256(\"PRICE_ORACLE_ROLE\");\n PAUSER_ROLE = keccak256(\"PAUSER_ROLE\");\n REDISTRIBUTOR_ROLE = keccak256(\"REDISTRIBUTOR_ROLE\");\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n _setupRole(PAUSER_ROLE, msg.sender);\n }\n\n ////////////////////////////////////////\n // STATE CHANGING //\n ////////////////////////////////////////\n\n /**\n * @notice Create a new batch.\n * @dev At least `_initialBalancePerChunk*2^depth` tokens must be approved in the ERC20 token contract.\n * @param _owner Owner of the new batch.\n * @param _initialBalancePerChunk Initial balance per chunk.\n * @param _depth Initial depth of the new batch.\n * @param _nonce A random value used in the batch id derivation to allow multiple batches per owner.\n * @param _immutable Whether the batch is mutable.\n */\n function createBatch(\n address _owner,\n uint256 _initialBalancePerChunk,\n uint8 _depth,\n uint8 _bucketDepth,\n bytes32 _nonce,\n bool _immutable\n ) external whenNotPaused returns (bytes32) {\n if (_owner == address(0)) {\n revert ZeroAddress();\n }\n\n if (_bucketDepth == 0 || _bucketDepth < minimumBucketDepth || _bucketDepth >= _depth) {\n revert InvalidDepth();\n }\n\n bytes32 batchId = keccak256(abi.encode(msg.sender, _nonce));\n if (batches[batchId].owner != address(0)) {\n revert BatchExists();\n }\n\n if (_initialBalancePerChunk < minimumInitialBalancePerChunk()) {\n revert InsufficientBalance();\n }\n\n uint256 totalAmount = _initialBalancePerChunk * (1 << _depth);\n if (!ERC20(bzzToken).transferFrom(msg.sender, address(this), totalAmount)) {\n revert TransferFailed();\n }\n\n uint256 normalisedBalance = currentTotalOutPayment() + (_initialBalancePerChunk);\n if (normalisedBalance == 0) {\n revert ZeroBalance();\n }\n\n expireLimited(type(uint256).max);\n validChunkCount += 1 << _depth;\n\n batches[batchId] = Batch({\n owner: _owner,\n depth: _depth,\n bucketDepth: _bucketDepth,\n immutableFlag: _immutable,\n normalisedBalance: normalisedBalance,\n lastUpdatedBlockNumber: block.number\n });\n\n tree.insert(batchId, normalisedBalance);\n\n emit BatchCreated(batchId, totalAmount, normalisedBalance, _owner, _depth, _bucketDepth, _immutable);\n\n return batchId;\n }\n\n /**\n * @notice Manually create a new batch when facilitating migration, can only be called by the Admin role.\n * @dev At least `_initialBalancePerChunk*2^depth` tokens must be approved in the ERC20 token contract.\n * @param _owner Owner of the new batch.\n * @param _initialBalancePerChunk Initial balance per chunk of the batch.\n * @param _depth Initial depth of the new batch.\n * @param _batchId BatchId being copied (from previous version contract data).\n * @param _immutable Whether the batch is mutable.\n */\n function copyBatch(\n address _owner,\n uint256 _initialBalancePerChunk,\n uint8 _depth,\n uint8 _bucketDepth,\n bytes32 _batchId,\n bool _immutable\n ) public whenNotPaused {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert AdministratorOnly();\n }\n\n if (_owner == address(0)) {\n revert ZeroAddress();\n }\n\n if (_bucketDepth == 0 || _bucketDepth >= _depth) {\n revert InvalidDepth();\n }\n\n if (batches[_batchId].owner != address(0)) {\n revert BatchExists();\n }\n\n uint256 totalAmount = _initialBalancePerChunk * (1 << _depth);\n uint256 normalisedBalance = currentTotalOutPayment() + (_initialBalancePerChunk);\n if (normalisedBalance == 0) {\n revert ZeroBalance();\n }\n\n //update validChunkCount to remove currently expired batches\n expireLimited(type(uint256).max);\n\n validChunkCount += 1 << _depth;\n\n batches[_batchId] = Batch({\n owner: _owner,\n depth: _depth,\n bucketDepth: _bucketDepth,\n immutableFlag: _immutable,\n normalisedBalance: normalisedBalance,\n lastUpdatedBlockNumber: block.number\n });\n\n tree.insert(_batchId, normalisedBalance);\n\n emit BatchCreated(_batchId, totalAmount, normalisedBalance, _owner, _depth, _bucketDepth, _immutable);\n }\n\n /**\n * @notice Import batches in bulk\n * @dev Import batches in bulk to lower the number of transactions needed,\n * @dev becase of block limitations 90 batches per trx is ceiling, 60 to 70 sweetspot\n * @param bulkBatches array of batches\n */\n function copyBatchBulk(ImportBatch[] calldata bulkBatches) external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert AdministratorOnly();\n }\n for (uint i = 0; i < bulkBatches.length; i++) {\n ImportBatch memory _batch = bulkBatches[i];\n try\n this.copyBatch(\n _batch.owner,\n _batch.remainingBalance,\n _batch.depth,\n _batch.bucketDepth,\n _batch.batchId,\n _batch.immutableFlag\n )\n {\n // Successful copyBatch call\n } catch {\n // copyBatch failed, handle error\n emit CopyBatchFailed(i, _batch.batchId);\n }\n }\n }\n\n /**\n * @notice Top up an existing batch.\n * @dev At least `_topupAmountPerChunk*2^depth` tokens must be approved in the ERC20 token contract.\n * @param _batchId The id of an existing batch.\n * @param _topupAmountPerChunk The amount of additional tokens to add per chunk.\n */\n function topUp(bytes32 _batchId, uint256 _topupAmountPerChunk) external whenNotPaused {\n Batch memory batch = batches[_batchId];\n\n if (batch.owner == address(0)) {\n revert BatchDoesNotExist();\n }\n\n if (batch.normalisedBalance <= currentTotalOutPayment()) {\n revert BatchExpired();\n }\n\n if (batch.depth <= minimumBucketDepth) {\n revert BatchTooSmall();\n }\n\n if (remainingBalance(_batchId) + (_topupAmountPerChunk) < minimumInitialBalancePerChunk()) {\n revert InsufficientBalance();\n }\n\n // per chunk balance multiplied by the batch size in chunks must be transferred from the sender\n uint256 totalAmount = _topupAmountPerChunk * (1 << batch.depth);\n if (!ERC20(bzzToken).transferFrom(msg.sender, address(this), totalAmount)) {\n revert TransferFailed();\n }\n\n // update by removing batch and then reinserting\n tree.remove(_batchId, batch.normalisedBalance);\n batch.normalisedBalance = batch.normalisedBalance + (_topupAmountPerChunk);\n tree.insert(_batchId, batch.normalisedBalance);\n\n batches[_batchId].normalisedBalance = batch.normalisedBalance;\n emit BatchTopUp(_batchId, totalAmount, batch.normalisedBalance);\n }\n\n /**\n * @notice Increase the depth of an existing batch.\n * @dev Can only be called by the owner of the batch.\n * @param _batchId the id of an existing batch.\n * @param _newDepth the new (larger than the previous one) depth for this batch.\n */\n function increaseDepth(bytes32 _batchId, uint8 _newDepth) external whenNotPaused {\n Batch memory batch = batches[_batchId];\n\n if (batch.owner != msg.sender) {\n revert NotBatchOwner();\n }\n\n if (!(minimumBucketDepth < _newDepth && batch.depth < _newDepth)) {\n revert DepthNotIncreasing();\n }\n\n if (batch.normalisedBalance <= currentTotalOutPayment()) {\n revert BatchExpired();\n }\n\n uint8 depthChange = _newDepth - batch.depth;\n uint256 newRemainingBalance = remainingBalance(_batchId) / (1 << depthChange);\n\n if (newRemainingBalance < minimumInitialBalancePerChunk()) {\n revert InsufficientBalance();\n }\n\n expireLimited(type(uint256).max);\n validChunkCount += (1 << _newDepth) - (1 << batch.depth);\n tree.remove(_batchId, batch.normalisedBalance);\n batches[_batchId].depth = _newDepth;\n batches[_batchId].lastUpdatedBlockNumber = block.number;\n\n batch.normalisedBalance = currentTotalOutPayment() + newRemainingBalance;\n batches[_batchId].normalisedBalance = batch.normalisedBalance;\n tree.insert(_batchId, batch.normalisedBalance);\n\n emit BatchDepthIncrease(_batchId, _newDepth, batch.normalisedBalance);\n }\n\n /**\n * @notice Set a new price.\n * @dev Can only be called by the price oracle role.\n * @param _price The new price.\n */\n function setPrice(uint256 _price) external {\n if (!hasRole(PRICE_ORACLE_ROLE, msg.sender)) {\n revert PriceOracleOnly();\n }\n\n if (lastPrice != 0) {\n totalOutPayment = currentTotalOutPayment();\n }\n\n lastPrice = uint64(_price);\n lastUpdatedBlock = uint64(block.number);\n\n emit PriceUpdate(_price);\n }\n\n function setMinimumValidityBlocks(uint64 _value) external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert AdministratorOnly();\n }\n\n minimumValidityBlocks = _value;\n }\n\n /**\n * @notice Reclaims a limited number of expired batches\n * @dev Can be used if reclaiming all expired batches would exceed the block gas limit, causing other\n * contract method calls to fail.\n * @param limit The maximum number of batches to expire.\n */\n function expireLimited(uint256 limit) public {\n // the lower bound of the normalised balance for which we will check if batches have expired\n uint256 _lastExpiryBalance = lastExpiryBalance;\n uint256 i;\n for (i; i < limit; ) {\n if (isBatchesTreeEmpty()) {\n lastExpiryBalance = currentTotalOutPayment();\n break;\n }\n // get the batch with the smallest normalised balance\n bytes32 fbi = firstBatchId();\n // if the batch with the smallest balance has not yet expired\n // we have already reached the end of the batches we need\n // to expire, so exit the loop\n if (remainingBalance(fbi) > 0) {\n // the upper bound of the normalised balance for which we will check if batches have expired\n // value is updated when there are no expired batches left\n lastExpiryBalance = currentTotalOutPayment();\n break;\n }\n // otherwise, the batch with the smallest balance has expired,\n // so we must remove the chunks this batch contributes to the global validChunkCount\n Batch memory batch = batches[fbi];\n uint256 batchSize = 1 << batch.depth;\n\n if (validChunkCount < batchSize) {\n revert InsufficienChunkCount();\n }\n validChunkCount -= batchSize;\n // since the batch expired _during_ the period we must add\n // remaining normalised payout for this batch only\n pot += batchSize * (batch.normalisedBalance - _lastExpiryBalance);\n tree.remove(fbi, batch.normalisedBalance);\n delete batches[fbi];\n\n unchecked {\n ++i;\n }\n }\n // then, for all batches that have _not_ expired during the period\n // add the total normalised payout of all batches\n // multiplied by the remaining total valid chunk count\n // to the pot for the period since the last expiry\n\n if (lastExpiryBalance < _lastExpiryBalance) {\n revert TotalOutpaymentDecreased();\n }\n\n // then, for all batches that have _not_ expired during the period\n // add the total normalised payout of all batches\n // multiplied by the remaining total valid chunk count\n // to the pot for the period since the last expiry\n pot += validChunkCount * (lastExpiryBalance - _lastExpiryBalance);\n }\n\n /**\n * @notice The current pot.\n */\n function totalPot() public returns (uint256) {\n expireLimited(type(uint256).max);\n uint256 balance = ERC20(bzzToken).balanceOf(address(this));\n return pot < balance ? pot : balance;\n }\n\n /**\n * @notice Withdraw the pot, authorised callers only.\n * @param beneficiary Recieves the current total pot.\n */\n\n function withdraw(address beneficiary) external {\n if (!hasRole(REDISTRIBUTOR_ROLE, msg.sender)) {\n revert OnlyRedistributor();\n }\n\n uint256 totalAmount = totalPot();\n if (!ERC20(bzzToken).transfer(beneficiary, totalAmount)) {\n revert TransferFailed();\n }\n\n emit PotWithdrawn(beneficiary, totalAmount);\n pot = 0;\n }\n\n /**\n * @notice Pause the contract.\n * @dev Can only be called by the pauser when not paused.\n * The contract can be provably stopped by renouncing the pauser role and the admin role once paused.\n */\n function pause() public {\n if (!hasRole(PAUSER_ROLE, msg.sender)) {\n revert OnlyPauser();\n }\n _pause();\n }\n\n /**\n * @notice Unpause the contract.\n * @dev Can only be called by the pauser role while paused.\n */\n function unPause() public {\n if (!hasRole(PAUSER_ROLE, msg.sender)) {\n revert OnlyPauser();\n }\n\n _unpause();\n }\n\n ////////////////////////////////////////\n // STATE READING //\n ////////////////////////////////////////\n\n /**\n * @notice Total per-chunk cost since the contract's deployment.\n * @dev Returns the total normalised all-time per chunk payout.\n * Only Batches with a normalised balance greater than this are valid.\n */\n function currentTotalOutPayment() public view returns (uint256) {\n uint256 blocks = block.number - lastUpdatedBlock;\n uint256 increaseSinceLastUpdate = lastPrice * (blocks);\n return totalOutPayment + (increaseSinceLastUpdate);\n }\n\n function minimumInitialBalancePerChunk() public view returns (uint256) {\n return minimumValidityBlocks * lastPrice;\n }\n\n /**\n * @notice Return the per chunk balance not yet used up.\n * @param _batchId The id of an existing batch.\n */\n function remainingBalance(bytes32 _batchId) public view returns (uint256) {\n Batch memory batch = batches[_batchId];\n\n if (batch.owner == address(0)) {\n revert BatchDoesNotExist(); // Batch does not exist or expired\n }\n\n if (batch.normalisedBalance <= currentTotalOutPayment()) {\n return 0;\n }\n\n return batch.normalisedBalance - currentTotalOutPayment();\n }\n\n /**\n * @notice Indicates whether expired batches exist.\n */\n function expiredBatchesExist() public view returns (bool) {\n if (isBatchesTreeEmpty()) {\n return false;\n }\n return (remainingBalance(firstBatchId()) <= 0);\n }\n\n /**\n * @notice Return true if no batches exist\n */\n function isBatchesTreeEmpty() public view returns (bool) {\n return tree.count() == 0;\n }\n\n /**\n * @notice Get the first batch id ordered by ascending normalised balance.\n * @dev If more than one batch id, return index at 0, if no batches, revert.\n */\n function firstBatchId() public view returns (bytes32) {\n uint256 val = tree.first();\n if (val == 0) {\n revert NoBatchesExist();\n }\n return tree.valueKeyAtIndex(val, 0);\n }\n\n function batchOwner(bytes32 _batchId) public view returns (address) {\n return batches[_batchId].owner;\n }\n\n function batchDepth(bytes32 _batchId) public view returns (uint8) {\n return batches[_batchId].depth;\n }\n\n function batchBucketDepth(bytes32 _batchId) public view returns (uint8) {\n return batches[_batchId].bucketDepth;\n }\n\n function batchImmutableFlag(bytes32 _batchId) public view returns (bool) {\n return batches[_batchId].immutableFlag;\n }\n\n function batchNormalisedBalance(bytes32 _batchId) public view returns (uint256) {\n return batches[_batchId].normalisedBalance;\n }\n\n function batchLastUpdatedBlockNumber(bytes32 _batchId) public view returns (uint256) {\n return batches[_batchId].lastUpdatedBlockNumber;\n }\n}\n" }, "src/PriceOracle.sol": { - "content": "// SPDX-License-Identifier: BSD-3-Clause\npragma solidity ^0.8.19;\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"./interface/IPostageStamp.sol\";\n\n/**\n * @title PriceOracle contract.\n * @author The Swarm Authors.\n * @dev The price oracle contract emits a price feed using events.\n */\n\ncontract PriceOracle is AccessControl {\n // ----------------------------- State variables ------------------------------\n\n // The address of the linked PostageStamp contract\n IPostageStamp public postageStamp;\n\n uint16 targetRedundancy = 4;\n uint16 maxConsideredExtraRedundancy = 4;\n\n // When the contract is paused, price changes are not effective\n bool public isPaused = false;\n\n // The number of the last round price adjusting happend\n uint64 public lastAdjustedRound;\n\n // The minimum price allowed\n uint32 public minimumPriceUpscaled = 24000 << 10; // we upscale it by 2^10\n\n // The priceBase to modulate the price\n uint32 public priceBase = 524288;\n\n uint64 public currentPriceUpScaled = minimumPriceUpscaled;\n\n // Constants used to modulate the price, see below usage\n uint32[9] public changeRate = [524324, 524315, 524306, 524297, 524288, 524279, 524270, 524261, 524252];\n\n // Role allowed to update price\n bytes32 public immutable PRICE_UPDATER_ROLE;\n\n // The length of a round in blocks.\n uint8 private constant ROUND_LENGTH = 152;\n\n // ----------------------------- Events ------------------------------\n\n /**\n *@dev Emitted on every price update.\n */\n event PriceUpdate(uint256 price);\n\n // ----------------------------- Custom Errors ------------------------------\n error CallerNotAdmin(); // Caller is not the admin\n error CallerNotPriceUpdater(); // Caller is not a price updater\n error PriceAlreadyAdjusted(); // Price already adjusted in this round\n error UnexpectedZero(); // Redundancy needs to be higher then 0\n\n // ----------------------------- CONSTRUCTOR ------------------------------\n\n constructor(address _postageStamp) {\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n postageStamp = IPostageStamp(_postageStamp);\n lastAdjustedRound = currentRound();\n PRICE_UPDATER_ROLE = keccak256(\"PRICE_UPDATER_ROLE\");\n }\n\n ////////////////////////////////////////\n // STATE SETTING //\n ////////////////////////////////////////\n\n /**\n * @notice Manually set the price.\n * @dev Can only be called by the admin role.\n * @param _price The new price.\n */ function setPrice(uint32 _price) external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert CallerNotAdmin();\n }\n\n uint64 _currentPriceUpScaled = _price << 10;\n uint64 _minimumPriceUpscaled = minimumPriceUpscaled;\n\n // Enforce minimum price\n if (_currentPriceUpScaled < _minimumPriceUpscaled) {\n _currentPriceUpScaled = _minimumPriceUpscaled;\n }\n currentPriceUpScaled = _currentPriceUpScaled;\n\n // Price in postagestamp is set at 256 so we need to upcast it\n postageStamp.setPrice(uint256(currentPrice()));\n emit PriceUpdate(currentPrice());\n }\n\n function adjustPrice(uint16 redundancy) external {\n if (isPaused == false) {\n if (!hasRole(PRICE_UPDATER_ROLE, msg.sender)) {\n revert CallerNotPriceUpdater();\n }\n\n uint16 usedRedundancy = redundancy;\n uint64 currentRoundNumber = currentRound();\n\n // Price can only be adjusted once per round\n if (currentRoundNumber <= lastAdjustedRound) {\n revert PriceAlreadyAdjusted();\n }\n // Redundancy may not be zero\n if (redundancy == 0) {\n revert UnexpectedZero();\n }\n\n // Enforce maximum considered extra redundancy\n uint16 maxConsideredRedundancy = targetRedundancy + maxConsideredExtraRedundancy;\n if (redundancy > maxConsideredRedundancy) {\n usedRedundancy = maxConsideredRedundancy;\n }\n\n uint64 _currentPriceUpScaled = currentPriceUpScaled;\n uint64 _minimumPriceUpscaled = minimumPriceUpscaled;\n uint32 _priceBase = priceBase;\n\n // Set the number of rounds that were skipped\n uint64 skippedRounds = currentRoundNumber - lastAdjustedRound - 1;\n\n // We first apply the increase/decrease rate for the current round\n uint32 _changeRate = changeRate[usedRedundancy];\n _currentPriceUpScaled = (_changeRate * _currentPriceUpScaled) / _priceBase;\n\n // If previous rounds were skipped, use MAX price increase for the previous rounds\n if (skippedRounds > 0) {\n _changeRate = changeRate[0];\n for (uint64 i = 0; i < skippedRounds; i++) {\n _currentPriceUpScaled = (_changeRate * _currentPriceUpScaled) / _priceBase;\n }\n }\n\n // Enforce minimum price\n if (_currentPriceUpScaled < _minimumPriceUpscaled) {\n _currentPriceUpScaled = _minimumPriceUpscaled;\n }\n\n currentPriceUpScaled = _currentPriceUpScaled;\n lastAdjustedRound = currentRoundNumber;\n postageStamp.setPrice(uint256(currentPrice()));\n emit PriceUpdate(currentPrice());\n }\n }\n\n function pause() external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert CallerNotAdmin();\n }\n isPaused = true;\n }\n\n function unPause() external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert CallerNotAdmin();\n }\n isPaused = false;\n }\n\n ////////////////////////////////////////\n // STATE READING //\n ////////////////////////////////////////\n\n /**\n * @notice Return the number of the current round.\n */\n function currentRound() public view returns (uint64) {\n // We downcasted to uint64 as uint64 has 18,446,744,073,709,551,616 places\n // as each round is 152 x 5 = 760, each day has around 113 rounds which is 41245 in a year\n // it results 4.4724801e+14 years to run this game\n return uint64(block.number / uint256(ROUND_LENGTH));\n }\n\n /**\n * @notice Return the price downscaled\n */\n function currentPrice() public view returns (uint32) {\n // We downcasted to uint32 and bitshift it by 2^10\n return uint32((currentPriceUpScaled) >> 10);\n }\n\n /**\n * @notice Return the price downscaled\n */\n function minimumPrice() public view returns (uint32) {\n // We downcasted to uint32 and bitshift it by 2^10\n return uint32((minimumPriceUpscaled) >> 10);\n }\n}\n" + "content": "// SPDX-License-Identifier: BSD-3-Clause\npragma solidity ^0.8.19;\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"./interface/IPostageStamp.sol\";\n\n/**\n * @title PriceOracle contract.\n * @author The Swarm Authors.\n * @dev The price oracle contract emits a price feed using events.\n */\n\ncontract PriceOracle is AccessControl {\n // ----------------------------- State variables ------------------------------\n\n // The address of the linked PostageStamp contract\n IPostageStamp public postageStamp;\n\n uint16 targetRedundancy = 4;\n uint16 maxConsideredExtraRedundancy = 4;\n\n // When the contract is paused, price changes are not effective\n bool public isPaused = false;\n\n // The number of the last round price adjusting happend\n uint64 public lastAdjustedRound;\n\n // The minimum price allowed\n uint32 public minimumPriceUpscaled = 24000 << 10; // we upscale it by 2^10\n\n // The priceBase to modulate the price\n uint32 public priceBase = 524288;\n\n uint64 public currentPriceUpScaled = minimumPriceUpscaled;\n\n // Constants used to modulate the price, see below usage\n uint32[9] public changeRate = [524324, 524315, 524306, 524297, 524288, 524279, 524270, 524261, 524252];\n\n // Role allowed to update price\n bytes32 public immutable PRICE_UPDATER_ROLE;\n\n // The length of a round in blocks.\n uint8 private constant ROUND_LENGTH = 152;\n\n // ----------------------------- Events ------------------------------\n\n /**\n *@dev Emitted on every price update.\n */\n event PriceUpdate(uint256 price);\n\n // ----------------------------- Custom Errors ------------------------------\n error CallerNotAdmin(); // Caller is not the admin\n error CallerNotPriceUpdater(); // Caller is not a price updater\n error PriceAlreadyAdjusted(); // Price already adjusted in this round\n error UnexpectedZero(); // Redundancy needs to be higher then 0\n\n // ----------------------------- CONSTRUCTOR ------------------------------\n\n constructor(address _postageStamp) {\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n postageStamp = IPostageStamp(_postageStamp);\n lastAdjustedRound = currentRound();\n PRICE_UPDATER_ROLE = keccak256(\"PRICE_UPDATER_ROLE\");\n emit PriceUpdate(currentPrice());\n }\n\n ////////////////////////////////////////\n // STATE SETTING //\n ////////////////////////////////////////\n\n /**\n * @notice Manually set the price.\n * @dev Can only be called by the admin role.\n * @param _price The new price.\n */ function setPrice(uint32 _price) external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert CallerNotAdmin();\n }\n\n uint64 _currentPriceUpScaled = _price << 10;\n uint64 _minimumPriceUpscaled = minimumPriceUpscaled;\n\n // Enforce minimum price\n if (_currentPriceUpScaled < _minimumPriceUpscaled) {\n _currentPriceUpScaled = _minimumPriceUpscaled;\n }\n currentPriceUpScaled = _currentPriceUpScaled;\n\n // Price in postagestamp is set at 256 so we need to upcast it\n postageStamp.setPrice(uint256(currentPrice()));\n emit PriceUpdate(currentPrice());\n }\n\n function adjustPrice(uint16 redundancy) external {\n if (isPaused == false) {\n if (!hasRole(PRICE_UPDATER_ROLE, msg.sender)) {\n revert CallerNotPriceUpdater();\n }\n\n uint16 usedRedundancy = redundancy;\n uint64 currentRoundNumber = currentRound();\n\n // Price can only be adjusted once per round\n if (currentRoundNumber <= lastAdjustedRound) {\n revert PriceAlreadyAdjusted();\n }\n // Redundancy may not be zero\n if (redundancy == 0) {\n revert UnexpectedZero();\n }\n\n // Enforce maximum considered extra redundancy\n uint16 maxConsideredRedundancy = targetRedundancy + maxConsideredExtraRedundancy;\n if (redundancy > maxConsideredRedundancy) {\n usedRedundancy = maxConsideredRedundancy;\n }\n\n uint64 _currentPriceUpScaled = currentPriceUpScaled;\n uint64 _minimumPriceUpscaled = minimumPriceUpscaled;\n uint32 _priceBase = priceBase;\n\n // Set the number of rounds that were skipped\n uint64 skippedRounds = currentRoundNumber - lastAdjustedRound - 1;\n\n // We first apply the increase/decrease rate for the current round\n uint32 _changeRate = changeRate[usedRedundancy];\n _currentPriceUpScaled = (_changeRate * _currentPriceUpScaled) / _priceBase;\n\n // If previous rounds were skipped, use MAX price increase for the previous rounds\n if (skippedRounds > 0) {\n _changeRate = changeRate[0];\n for (uint64 i = 0; i < skippedRounds; i++) {\n _currentPriceUpScaled = (_changeRate * _currentPriceUpScaled) / _priceBase;\n }\n }\n\n // Enforce minimum price\n if (_currentPriceUpScaled < _minimumPriceUpscaled) {\n _currentPriceUpScaled = _minimumPriceUpscaled;\n }\n\n currentPriceUpScaled = _currentPriceUpScaled;\n lastAdjustedRound = currentRoundNumber;\n postageStamp.setPrice(uint256(currentPrice()));\n emit PriceUpdate(currentPrice());\n }\n }\n\n function pause() external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert CallerNotAdmin();\n }\n isPaused = true;\n }\n\n function unPause() external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert CallerNotAdmin();\n }\n isPaused = false;\n }\n\n ////////////////////////////////////////\n // STATE READING //\n ////////////////////////////////////////\n\n /**\n * @notice Return the number of the current round.\n */\n function currentRound() public view returns (uint64) {\n // We downcasted to uint64 as uint64 has 18,446,744,073,709,551,616 places\n // as each round is 152 x 5 = 760, each day has around 113 rounds which is 41245 in a year\n // it results 4.4724801e+14 years to run this game\n return uint64(block.number / uint256(ROUND_LENGTH));\n }\n\n /**\n * @notice Return the price downscaled\n */\n function currentPrice() public view returns (uint32) {\n // We downcasted to uint32 and bitshift it by 2^10\n return uint32((currentPriceUpScaled) >> 10);\n }\n\n /**\n * @notice Return the price downscaled\n */\n function minimumPrice() public view returns (uint32) {\n // We downcasted to uint32 and bitshift it by 2^10\n return uint32((minimumPriceUpscaled) >> 10);\n }\n}\n" }, "src/Redistribution.sol": { - "content": "// SPDX-License-Identifier: BSD-3-Clause\npragma solidity ^0.8.19;\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"@openzeppelin/contracts/security/Pausable.sol\";\nimport \"./Util/TransformedChunkProof.sol\";\nimport \"./Util/ChunkProof.sol\";\nimport \"./Util/Signatures.sol\";\nimport \"./interface/IPostageStamp.sol\";\n\ninterface IPriceOracle {\n function adjustPrice(uint16 redundancy) external;\n}\n\ninterface IStakeRegistry {\n struct Stake {\n bytes32 overlay;\n uint256 stakeAmount;\n uint256 lastUpdatedBlockNumber;\n bool isValue;\n }\n\n function freezeDeposit(address _owner, uint256 _time) external;\n\n function lastUpdatedBlockNumberOfAddress(address _owner) external view returns (uint256);\n\n function overlayOfAddress(address _owner) external view returns (bytes32);\n\n function stakeOfAddress(address _owner) external view returns (uint256);\n\n function getStakeStruct(address _owner) external view returns (Stake memory);\n}\n\n/**\n * @title Redistribution contract\n * @author The Swarm Authors\n * @dev Implements a Schelling Co-ordination game to form consensus around the Reserve Commitment hash. This takes\n * place in three phases: _commit_, _reveal_ and _claim_.\n *\n * A node, upon establishing that it _isParticipatingInUpcomingRound_, i.e. it's overlay falls within proximity order\n * of its reported depth with the _currentRoundAnchor_, prepares a \"reserve commitment hash\" using the chunks\n * it currently stores in its reserve and calculates the \"storage depth\" (see Bee for details). These values, if calculated\n * honestly, and with the right chunks stored, should be the same for every node in a neighbourhood. This is the Schelling point.\n * Each eligible node can then use these values, together with a random, single use, secret _revealNonce_ and their\n * _overlay_ as the pre-image values for the obsfucated _commit_, using the _wrapCommit_ method.\n *\n * Once the _commit_ round has elapsed, participating nodes must provide the values used to calculate their obsfucated\n * _commit_ hash, which, once verified for correctness and proximity to the anchor are retained in the _currentReveals_.\n * Nodes that have commited but do not reveal the correct values used to create the pre-image will have their stake\n * \"frozen\" for a period of rounds proportional to their reported depth.\n *\n * During the _reveal_ round, randomness is updated after every successful reveal. Once the reveal round is concluded,\n * the _currentRoundAnchor_ is updated and users can determine if they will be eligible their overlay will be eligible\n * for the next commit phase using _isParticipatingInUpcomingRound_.\n *\n * When the _reveal_ phase has been concluded, the claim phase can begin. At this point, the truth teller and winner\n * are already determined. By calling _isWinner_, an applicant node can run the relevant logic to determine if they have\n * been selected as the beneficiary of this round. When calling _claim_, the current pot from the PostageStamp contract\n * is withdrawn and transferred to that beneficiaries address. Nodes that have revealed values that differ from the truth,\n * have their stakes \"frozen\" for a period of rounds proportional to their reported depth.\n */\n\ncontract Redistribution is AccessControl, Pausable {\n // ----------------------------- Type declarations ------------------------------\n\n // An eligible user may commit to an _obfuscatedHash_ during the commit phase...\n struct Commit {\n bytes32 overlay;\n address owner;\n bool revealed;\n uint256 stake;\n bytes32 obfuscatedHash;\n uint256 revealIndex;\n }\n // ...then provide the actual values that are the constituents of the pre-image of the _obfuscatedHash_\n // during the reveal phase.\n struct Reveal {\n bytes32 overlay;\n address owner;\n uint8 depth;\n uint256 stake;\n uint256 stakeDensity;\n bytes32 hash;\n }\n\n struct ChunkInclusionProof {\n bytes32[] proofSegments;\n bytes32 proveSegment;\n // _RCspan is known for RC 32*32\n\n // Inclusion proof of transformed address\n bytes32[] proofSegments2;\n bytes32 proveSegment2;\n // proveSegmentIndex2 known from deterministic random selection;\n uint64 chunkSpan;\n bytes32[] proofSegments3;\n // _proveSegment3 known, is equal _proveSegment2\n // proveSegmentIndex3 know, is equal _proveSegmentIndex2;\n // chunkSpan2 is equal to chunkSpan (as the data is the same)\n //\n PostageProof postageProof;\n SOCProof[] socProof;\n }\n\n struct SOCProof {\n address signer; // signer Ethereum address to check against\n bytes signature;\n bytes32 identifier; //\n bytes32 chunkAddr; // wrapped chunk address\n }\n\n struct PostageProof {\n bytes signature;\n bytes32 postageId;\n uint64 index;\n uint64 timeStamp;\n // address signer; it is provided by the postage stamp contract\n // bytes32 chunkAddr; it equals to the proveSegment argument\n }\n\n // The address of the linked PostageStamp contract.\n IPostageStamp public PostageContract;\n // The address of the linked PriceOracle contract.\n IPriceOracle public OracleContract;\n // The address of the linked Staking contract.\n IStakeRegistry public Stakes;\n\n // Commits for the current round.\n Commit[] public currentCommits;\n // Reveals for the current round.\n Reveal[] public currentReveals;\n\n // The current anchor that being processed for the reveal and claim phases of the round.\n bytes32 private currentRevealRoundAnchor;\n\n // The current random value from which we will random.\n // inputs for selection of the truth teller and beneficiary.\n bytes32 private seed;\n\n // The number of the currently active round phases.\n uint64 public currentCommitRound;\n uint64 public currentRevealRound;\n uint64 public currentClaimRound;\n\n // Settings for slashing and freezing\n uint8 private penaltyMultiplierDisagreement = 1;\n uint8 private penaltyMultiplierNonRevealed = 2;\n uint8 private penaltyRandomFactor = 100; // Use 100 as value to ignore random factor in freezing penalty\n\n // alpha=0.097612 beta=0.0716570 k=16\n uint256 private sampleMaxValue = 1284401000000000000000000000000000000000000000000000000000000000000000000;\n\n // The reveal of the winner of the last round.\n Reveal public winner;\n\n // The length of a round in blocks.\n uint256 private constant ROUND_LENGTH = 152;\n\n // The miniumum stake allowed to be staked using the Staking contract.\n uint64 private constant MIN_STAKE = 100000000000000000;\n\n // Maximum value of the keccack256 hash.\n bytes32 private constant MAX_H = 0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff;\n\n // Role allowed to pause.\n bytes32 private immutable PAUSER_ROLE;\n\n // ----------------------------- Events ------------------------------\n\n /**\n * @dev Emitted when the winner of a round is selected in the claim phase\n */\n event WinnerSelected(Reveal winner);\n\n /**\n * @dev Emitted when the truth oracle of a round is selected in the claim phase.\n */\n event TruthSelected(bytes32 hash, uint8 depth);\n\n // Next two events to be removed after testing phase pending some other usefulness being found.\n /**\n * @dev Emits the number of commits being processed by the claim phase.\n */\n event CountCommits(uint256 _count);\n\n /**\n * @dev Emits the number of reveals being processed by the claim phase.\n */\n event CountReveals(uint256 _count);\n\n /**\n * @dev Logs that an overlay has committed\n */\n event Committed(uint256 roundNumber, bytes32 overlay);\n /**\n * @dev Emit from Postagestamp contract valid chunk count at the end of claim\n */\n event ChunkCount(uint256 validChunkCount);\n\n /**\n * @dev Bytes32 anhor of current reveal round\n */\n event CurrentRevealAnchor(uint256 roundNumber, bytes32 anchor);\n\n /**\n * @dev Logs that an overlay has revealed\n */\n event Revealed(\n uint256 roundNumber,\n bytes32 overlay,\n uint256 stake,\n uint256 stakeDensity,\n bytes32 reserveCommitment,\n uint8 depth\n );\n\n /**\n * @dev Logs for inclusion proof\n */\n event transformedChunkAddressFromInclusionProof(uint256 indexInRC, bytes32 chunkAddress);\n\n // ----------------------------- Errors ------------------------------\n\n error NotCommitPhase(); // Game is not in commit phase\n error NoCommitsReceived(); // Round didn't receive any commits\n error PhaseLastBlock(); // We don't permit commits in last block of the phase\n error BelowMinimumStake(); // Node participating in game has stake below minimum treshold\n error CommitRoundOver(); // Commit phase in this round is over\n error CommitRoundNotStarted(); // Commit phase in this round has not started yet\n error NotMatchingOwner(); // Sender of commit is not matching the overlay address\n error MustStake2Rounds(); // Before entering the game node must stake 2 rounds prior\n error WrongPhase(); // Checking in wrong phase, need to check duing claim phase of current round for next round or commit in current round\n error AlreadyCommited(); // Node already commited in this round\n error NotRevealPhase(); // Game is not in reveal phase\n error OutOfDepthReveal(bytes32); // Anchor is out of reported depth in Reveal phase, anchor data available as argument\n error OutOfDepthClaim(uint8); // Anchor is out of reported depth in Claim phase, entryProof index is argument\n error OutOfDepth(); // Anchor is out of reported depth\n error AlreadyRevealed(); // Node already revealed\n error NoMatchingCommit(); // No matching commit and hash\n error NotClaimPhase(); // Game is not in the claim phase\n error NoReveals(); // Round did not receive any reveals\n error FirstRevealDone(); // We don't want to return value after first reveal\n error AlreadyClaimed(); // This round was already claimed\n error NotAdmin(); // Caller of trx is not admin\n error OnlyPauser(); // Only account with pauser role can call pause/unpause\n error SocVerificationFailed(bytes32); // Soc verification failed for this element\n error SocCalcNotMatching(bytes32); // Soc address calculation does not match with the witness\n error IndexOutsideSet(bytes32); // Stamp available: index resides outside of the valid index set\n error SigRecoveryFailed(bytes32); // Stamp authorized: signature recovery failed for element\n error BatchDoesNotExist(bytes32); // Stamp alive: batch remaining balance validation failed for attached stamp\n error BucketDiffers(bytes32); // Stamp aligned: postage bucket differs from address bucket\n error InclusionProofFailed(uint8, bytes32);\n // 1 = RC inclusion proof failed for element\n // 2 = First sister segment in data must match,\n // 3 = Inclusion proof failed for original address of element\n // 4 = Inclusion proof failed for transformed address of element\n error RandomElementCheckFailed(); // Random element order check failed\n error LastElementCheckFailed(); // Last element order check failed\n error ReserveCheckFailed(bytes32 trALast); // Reserve size estimation check failed\n\n // ----------------------------- CONSTRUCTOR ------------------------------\n\n /**\n * @param staking the address of the linked Staking contract.\n * @param postageContract the address of the linked PostageStamp contract.\n * @param oracleContract the address of the linked PriceOracle contract.\n */\n constructor(address staking, address postageContract, address oracleContract) {\n Stakes = IStakeRegistry(staking);\n PostageContract = IPostageStamp(postageContract);\n OracleContract = IPriceOracle(oracleContract);\n PAUSER_ROLE = keccak256(\"PAUSER_ROLE\");\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n _setupRole(PAUSER_ROLE, msg.sender);\n }\n\n ////////////////////////////////////////\n // STATE CHANGING //\n ////////////////////////////////////////\n\n /**\n * @notice Begin application for a round if eligible. Commit a hashed value for which the pre-image will be\n * subsequently revealed.\n * @dev If a node's overlay is _inProximity_(_depth_) of the _currentRoundAnchor_, that node may compute an\n * _obfuscatedHash_ by providing their _overlay_, reported storage _depth_, reserve commitment _hash_ and a\n * randomly generated, and secret _revealNonce_ to the _wrapCommit_ method.\n * @param _obfuscatedHash The calculated hash resultant of the required pre-image values.\n * and be derived from the same key pair as the message sender.\n * @param _roundNumber Node needs to provide round number for which commit is valid\n */\n function commit(bytes32 _obfuscatedHash, uint64 _roundNumber) external whenNotPaused {\n uint64 cr = currentRound();\n bytes32 _overlay = Stakes.overlayOfAddress(msg.sender);\n uint256 _stake = Stakes.stakeOfAddress(msg.sender);\n\n if (!currentPhaseCommit()) {\n revert NotCommitPhase();\n }\n if (block.number % ROUND_LENGTH == (ROUND_LENGTH / 4) - 1) {\n revert PhaseLastBlock();\n }\n\n if (cr > _roundNumber) {\n revert CommitRoundOver();\n }\n\n if (cr < _roundNumber) {\n revert CommitRoundNotStarted();\n }\n\n if (_stake < MIN_STAKE) {\n revert BelowMinimumStake();\n }\n\n if (Stakes.lastUpdatedBlockNumberOfAddress(msg.sender) >= block.number - 2 * ROUND_LENGTH) {\n revert MustStake2Rounds();\n }\n\n // if we are in a new commit phase, reset the array of commits and\n // set the currentCommitRound to be the current one\n if (cr != currentCommitRound) {\n delete currentCommits;\n currentCommitRound = cr;\n }\n\n uint256 commitsArrayLength = currentCommits.length;\n\n for (uint256 i = 0; i < commitsArrayLength; ) {\n if (currentCommits[i].overlay == _overlay) {\n revert AlreadyCommited();\n }\n\n unchecked {\n ++i;\n }\n }\n\n currentCommits.push(\n Commit({\n overlay: _overlay,\n owner: msg.sender,\n revealed: false,\n stake: _stake,\n obfuscatedHash: _obfuscatedHash,\n revealIndex: 0\n })\n );\n\n emit Committed(_roundNumber, _overlay);\n }\n\n /**\n * @notice Reveal the pre-image values used to generate commit provided during this round's commit phase.\n * @param _depth The reported depth.\n * @param _hash The reserve commitment hash.\n * @param _revealNonce The nonce used to generate the commit that is being revealed.\n */\n function reveal(uint8 _depth, bytes32 _hash, bytes32 _revealNonce) external whenNotPaused {\n uint64 cr = currentRound();\n bytes32 _overlay = Stakes.overlayOfAddress(msg.sender);\n\n if (_depth < currentMinimumDepth()) {\n revert OutOfDepth();\n }\n\n if (!currentPhaseReveal()) {\n revert NotRevealPhase();\n }\n\n if (cr != currentCommitRound) {\n revert NoCommitsReceived();\n }\n\n if (cr != currentRevealRound) {\n currentRevealRoundAnchor = currentRoundAnchor();\n delete currentReveals;\n // We set currentRevealRound ONLY after we set current anchor\n currentRevealRound = cr;\n emit CurrentRevealAnchor(cr, currentRevealRoundAnchor);\n updateRandomness();\n }\n\n bytes32 obfuscatedHash = wrapCommit(_overlay, _depth, _hash, _revealNonce);\n uint256 id = findCommit(_overlay, obfuscatedHash);\n Commit memory revealedCommit = currentCommits[id];\n\n // Check that commit is in proximity of the current anchor\n if (!inProximity(revealedCommit.overlay, currentRevealRoundAnchor, _depth)) {\n revert OutOfDepthReveal(currentRevealRoundAnchor);\n }\n // Check that the commit has not already been revealed\n if (revealedCommit.revealed) {\n revert AlreadyRevealed();\n }\n\n currentCommits[id].revealed = true;\n currentCommits[id].revealIndex = currentReveals.length;\n\n currentReveals.push(\n Reveal({\n overlay: revealedCommit.overlay,\n owner: revealedCommit.owner,\n depth: _depth,\n stake: revealedCommit.stake,\n stakeDensity: revealedCommit.stake * uint256(2 ** _depth),\n hash: _hash\n })\n );\n\n emit Revealed(\n cr,\n revealedCommit.overlay,\n revealedCommit.stake,\n revealedCommit.stake * uint256(2 ** _depth),\n _hash,\n _depth\n );\n }\n\n /**\n * @notice Helper function to get this round truth\n * @dev\n */\n function claim(\n ChunkInclusionProof calldata entryProof1,\n ChunkInclusionProof calldata entryProof2,\n ChunkInclusionProof calldata entryProofLast\n ) external whenNotPaused {\n winnerSelection();\n\n Reveal memory winnerSelected = winner;\n uint256 indexInRC1;\n uint256 indexInRC2;\n bytes32 _currentRevealRoundAnchor = currentRevealRoundAnchor;\n bytes32 _seed = seed;\n\n // rand(14)\n indexInRC1 = uint256(_seed) % 15;\n // rand(13)\n indexInRC2 = uint256(_seed) % 14;\n if (indexInRC2 >= indexInRC1) {\n indexInRC2++;\n }\n\n if (!inProximity(entryProofLast.proveSegment, _currentRevealRoundAnchor, winnerSelected.depth)) {\n revert OutOfDepthClaim(3);\n }\n\n inclusionFunction(entryProofLast, 30);\n stampFunction(entryProofLast);\n socFunction(entryProofLast);\n\n if (!inProximity(entryProof1.proveSegment, _currentRevealRoundAnchor, winnerSelected.depth)) {\n revert OutOfDepthClaim(2);\n }\n\n inclusionFunction(entryProof1, indexInRC1 * 2);\n stampFunction(entryProof1);\n socFunction(entryProof1);\n\n if (!inProximity(entryProof2.proveSegment, _currentRevealRoundAnchor, winnerSelected.depth)) {\n revert OutOfDepthClaim(1);\n }\n\n inclusionFunction(entryProof2, indexInRC2 * 2);\n stampFunction(entryProof2);\n socFunction(entryProof2);\n\n checkOrder(\n indexInRC1,\n indexInRC2,\n entryProof1.proofSegments[0],\n entryProof2.proofSegments[0],\n entryProofLast.proofSegments[0]\n );\n\n estimateSize(entryProofLast.proofSegments[0]);\n\n PostageContract.withdraw(winnerSelected.owner);\n emit WinnerSelected(winnerSelected);\n emit ChunkCount(PostageContract.validChunkCount());\n }\n\n function winnerSelection() internal {\n uint64 cr = currentRound();\n\n if (!currentPhaseClaim()) {\n revert NotClaimPhase();\n }\n\n if (cr != currentRevealRound) {\n revert NoReveals();\n }\n\n if (cr <= currentClaimRound) {\n revert AlreadyClaimed();\n }\n\n uint256 currentWinnerSelectionSum = 0;\n uint256 redundancyCount = 0;\n bytes32 randomNumber;\n uint256 randomNumberTrunc;\n\n bytes32 truthRevealedHash;\n uint8 truthRevealedDepth;\n uint256 currentCommitsLength = currentCommits.length;\n\n emit CountCommits(currentCommitsLength);\n emit CountReveals(currentReveals.length);\n\n (truthRevealedHash, truthRevealedDepth) = getCurrentTruth();\n emit TruthSelected(truthRevealedHash, truthRevealedDepth);\n string memory winnerSelectionAnchor = currentWinnerSelectionAnchor();\n\n for (uint256 i = 0; i < currentCommitsLength; ) {\n Commit memory currentCommit = currentCommits[i];\n uint256 revIndex = currentCommit.revealIndex;\n Reveal memory currentReveal = currentReveals[revIndex];\n\n // Select winner with valid truth\n if (\n currentCommit.revealed &&\n truthRevealedHash == currentReveal.hash &&\n truthRevealedDepth == currentReveal.depth\n ) {\n currentWinnerSelectionSum += currentReveal.stakeDensity;\n randomNumber = keccak256(abi.encodePacked(winnerSelectionAnchor, redundancyCount));\n randomNumberTrunc = uint256(randomNumber & MAX_H);\n\n if (randomNumberTrunc * currentWinnerSelectionSum < currentReveal.stakeDensity * (uint256(MAX_H) + 1)) {\n winner = currentReveal;\n }\n\n redundancyCount++;\n }\n\n // Freeze deposit if any truth is false, make it a penaltyRandomFactor chance for this to happen\n if (\n currentCommit.revealed &&\n (truthRevealedHash != currentReveal.hash || truthRevealedDepth != currentReveal.depth) &&\n (block.prevrandao % 100 < penaltyRandomFactor)\n ) {\n Stakes.freezeDeposit(\n currentReveal.owner,\n penaltyMultiplierDisagreement * ROUND_LENGTH * uint256(2 ** truthRevealedDepth)\n );\n }\n\n // Slash deposits if revealed is false\n if (!currentCommit.revealed) {\n // slash in later phase (ph5)\n // Stakes.slashDeposit(currentCommits[i].overlay, currentCommits[i].stake);\n Stakes.freezeDeposit(\n currentCommit.owner,\n penaltyMultiplierNonRevealed * ROUND_LENGTH * uint256(2 ** truthRevealedDepth)\n );\n }\n unchecked {\n ++i;\n }\n }\n\n OracleContract.adjustPrice(uint16(redundancyCount));\n currentClaimRound = cr;\n }\n\n function inclusionFunction(ChunkInclusionProof calldata entryProof, uint256 indexInRC) internal {\n uint256 randomChunkSegmentIndex = uint256(seed) % 128;\n bytes32 calculatedTransformedAddr = TransformedBMTChunk.transformedChunkAddressFromInclusionProof(\n entryProof.proofSegments3,\n entryProof.proveSegment2,\n randomChunkSegmentIndex,\n entryProof.chunkSpan,\n currentRevealRoundAnchor\n );\n\n emit transformedChunkAddressFromInclusionProof(indexInRC, calculatedTransformedAddr);\n\n if (\n winner.hash !=\n BMTChunk.chunkAddressFromInclusionProof(\n entryProof.proofSegments,\n entryProof.proveSegment,\n indexInRC,\n 32 * 32\n )\n ) {\n revert InclusionProofFailed(1, calculatedTransformedAddr);\n }\n\n if (entryProof.proofSegments2[0] != entryProof.proofSegments3[0]) {\n revert InclusionProofFailed(2, calculatedTransformedAddr);\n }\n\n bytes32 originalAddress = entryProof.socProof.length > 0\n ? entryProof.socProof[0].chunkAddr // soc attestation in socFunction\n : entryProof.proveSegment;\n\n if (\n originalAddress !=\n BMTChunk.chunkAddressFromInclusionProof(\n entryProof.proofSegments2,\n entryProof.proveSegment2,\n randomChunkSegmentIndex,\n entryProof.chunkSpan\n )\n ) {\n revert InclusionProofFailed(3, calculatedTransformedAddr);\n }\n\n // In case of SOC, the transformed address is hashed together with its address in the sample\n if (entryProof.socProof.length > 0) {\n calculatedTransformedAddr = keccak256(\n abi.encode(\n entryProof.proveSegment, // SOC address\n calculatedTransformedAddr\n )\n );\n }\n\n if (entryProof.proofSegments[0] != calculatedTransformedAddr) {\n revert InclusionProofFailed(4, calculatedTransformedAddr);\n }\n }\n\n /**\n * @notice Set freezing parameters\n */\n function setFreezingParams(\n uint8 _penaltyMultiplierDisagreement,\n uint8 _penaltyMultiplierNonRevealed,\n uint8 _penaltyRandomFactor\n ) external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert NotAdmin();\n }\n\n penaltyMultiplierDisagreement = _penaltyMultiplierDisagreement;\n penaltyMultiplierNonRevealed = _penaltyMultiplierNonRevealed;\n penaltyRandomFactor = _penaltyRandomFactor;\n }\n\n /**\n * @notice changes the max sample value used for reserve estimation\n */\n function setSampleMaxValue(uint256 _sampleMaxValue) external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert NotAdmin();\n }\n\n sampleMaxValue = _sampleMaxValue;\n }\n\n /**\n * @notice Updates the source of randomness. Uses block.difficulty in pre-merge chains, this is substituted\n * to block.prevrandao in post merge chains.\n */\n function updateRandomness() private {\n seed = keccak256(abi.encode(seed, block.prevrandao));\n }\n\n /**\n * @dev Pause the contract. The contract is provably stopped by renouncing\n the pauser role and the admin role after pausing, can only be called by the `PAUSER`\n */\n function pause() public {\n if (!hasRole(PAUSER_ROLE, msg.sender)) {\n revert OnlyPauser();\n }\n\n _pause();\n }\n\n /**\n * @dev Unpause the contract, can only be called by the pauser when paused\n */\n function unPause() public {\n if (!hasRole(PAUSER_ROLE, msg.sender)) {\n revert OnlyPauser();\n }\n _unpause();\n }\n\n ////////////////////////////////////////\n // STATE READING //\n ////////////////////////////////////////\n\n // ----------------------------- Anchor calculations ------------------------------\n\n /**\n * @notice Returns the current random seed which is used to determine later utilised random numbers.\n * If rounds have elapsed without reveals, hash the seed with an incremented nonce to produce a new\n * random seed and hence a new round anchor.\n */\n function currentSeed() public view returns (bytes32) {\n uint64 cr = currentRound();\n bytes32 currentSeedValue = seed;\n\n if (cr > currentRevealRound + 1) {\n uint256 difference = cr - currentRevealRound - 1;\n currentSeedValue = keccak256(abi.encodePacked(currentSeedValue, difference));\n }\n\n return currentSeedValue;\n }\n\n /**\n * @notice Returns the seed which will become current once the next commit phase begins.\n * Used to determine what the next round's anchor will be.\n */\n function nextSeed() public view returns (bytes32) {\n uint64 cr = currentRound() + 1;\n bytes32 currentSeedValue = seed;\n\n if (cr > currentRevealRound + 1) {\n uint256 difference = cr - currentRevealRound - 1;\n currentSeedValue = keccak256(abi.encodePacked(currentSeedValue, difference));\n }\n\n return currentSeedValue;\n }\n\n /**\n * @notice The random value used to choose the selected truth teller.\n */\n function currentTruthSelectionAnchor() private view returns (string memory) {\n if (!currentPhaseClaim()) {\n revert NotClaimPhase();\n }\n\n uint64 cr = currentRound();\n if (cr != currentRevealRound) {\n revert NoReveals();\n }\n\n return string(abi.encodePacked(seed, \"0\"));\n }\n\n /**\n * @notice The random value used to choose the selected beneficiary.\n */\n function currentWinnerSelectionAnchor() private view returns (string memory) {\n if (!currentPhaseClaim()) {\n revert NotClaimPhase();\n }\n uint64 cr = currentRound();\n if (cr != currentRevealRound) {\n revert NoReveals();\n }\n\n return string(abi.encodePacked(seed, \"1\"));\n }\n\n /**\n * @notice The anchor used to determine eligibility for the current round.\n * @dev A node must be within proximity order of less than or equal to the storage depth they intend to report.\n */\n function currentRoundAnchor() public view returns (bytes32 returnVal) {\n // This will be called in reveal phase and set as currentRevealRoundAnchor or in\n // commit phase when checking eligibility for next round by isParticipatingInUpcomingRound\n if (currentPhaseCommit() || (currentRound() > currentRevealRound && !currentPhaseClaim())) {\n return currentSeed();\n }\n\n // This will be called by isParticipatingInUpcomingRound check in claim phase\n if (currentPhaseClaim()) {\n return nextSeed();\n }\n\n // Without this, this function will output 0x0 after first reveal which is value and we prefere it reverts\n if (currentPhaseReveal() && currentRound() == currentRevealRound) {\n revert FirstRevealDone();\n }\n }\n\n /**\n * @notice Returns true if an overlay address _A_ is within proximity order _minimum_ of _B_.\n * @param A An overlay address to compare.\n * @param B An overlay address to compare.\n * @param minimum Minimum proximity order.\n */\n function inProximity(bytes32 A, bytes32 B, uint8 minimum) public pure returns (bool) {\n if (minimum == 0) {\n return true;\n }\n\n return uint256(A ^ B) < uint256(2 ** (256 - minimum));\n }\n\n // ----------------------------- Commit ------------------------------\n\n /**\n * @notice The number of the current round.\n */\n function currentRound() public view returns (uint64) {\n return uint64(block.number / ROUND_LENGTH);\n }\n\n /**\n * @notice Returns true if current block is during commit phase.\n */\n function currentPhaseCommit() public view returns (bool) {\n if (block.number % ROUND_LENGTH < ROUND_LENGTH / 4) {\n return true;\n }\n return false;\n }\n\n /**\n * @notice Determine if a the owner of a given overlay can participate in the upcoming round.\n * @param _owner The address of the applicant from.\n * @param _depth The storage depth the applicant intends to report.\n */\n function isParticipatingInUpcomingRound(address _owner, uint8 _depth) public view returns (bool) {\n if (currentPhaseReveal()) {\n revert WrongPhase();\n }\n\n if (Stakes.lastUpdatedBlockNumberOfAddress(_owner) >= block.number - 2 * ROUND_LENGTH) {\n revert MustStake2Rounds();\n }\n\n if (Stakes.stakeOfAddress(_owner) < MIN_STAKE) {\n revert BelowMinimumStake();\n }\n\n return inProximity(Stakes.overlayOfAddress(_owner), currentRoundAnchor(), _depth);\n }\n\n // ----------------------------- Reveal ------------------------------\n\n /**\n * @notice Returns minimum depth reveal has to have to participate in this round\n */\n function currentMinimumDepth() public view returns (uint8) {\n // We are checking value in reveal phase, as the currentCommitRound is set to the current round\n // but the currentClaimRound is still set to the last time claim was made\n // We add 1 to ensure that for the next round the minimum depth is the same as last winner depth\n\n uint256 difference = currentCommitRound - currentClaimRound;\n uint8 skippedRounds = uint8(difference > 254 ? 254 : difference) + 1;\n\n uint8 lastWinnerDepth = winner.depth;\n\n // We ensure that skippedRounds is not bigger than lastWinnerDepth, because of overflow\n return skippedRounds >= lastWinnerDepth ? 0 : lastWinnerDepth - skippedRounds;\n }\n\n /**\n * @notice Helper function to get this node reveal in commits\n * @dev\n */\n function findCommit(bytes32 _overlay, bytes32 _obfuscatedHash) internal view returns (uint256) {\n for (uint256 i = 0; i < currentCommits.length; ) {\n if (currentCommits[i].overlay == _overlay && _obfuscatedHash == currentCommits[i].obfuscatedHash) {\n return i;\n }\n unchecked {\n ++i;\n }\n }\n revert NoMatchingCommit();\n }\n\n /**\n * @notice Hash the pre-image values to the obsfucated hash.\n * @dev _revealNonce_ must be randomly generated, used once and kept secret until the reveal phase.\n * @param _overlay The overlay address of the applicant.\n * @param _depth The reported depth.\n * @param _hash The reserve commitment hash.\n * @param revealNonce A random, single use, secret nonce.\n */\n function wrapCommit(\n bytes32 _overlay,\n uint8 _depth,\n bytes32 _hash,\n bytes32 revealNonce\n ) public pure returns (bytes32) {\n return keccak256(abi.encodePacked(_overlay, _depth, _hash, revealNonce));\n }\n\n /**\n * @notice Returns true if current block is during reveal phase.\n */\n function currentPhaseReveal() public view returns (bool) {\n uint256 number = block.number % ROUND_LENGTH;\n if (number >= ROUND_LENGTH / 4 && number < ROUND_LENGTH / 2) {\n return true;\n }\n return false;\n }\n\n /**\n * @notice Returns true if current block is during reveal phase.\n */\n function currentRoundReveals() public view returns (Reveal[] memory) {\n if (!currentPhaseClaim()) {\n revert NotClaimPhase();\n }\n uint64 cr = currentRound();\n if (cr != currentRevealRound) {\n revert NoReveals();\n }\n\n return currentReveals;\n }\n\n // ----------------------------- Claim ------------------------------\n\n /**\n * @notice Returns true if current block is during claim phase.\n */\n function currentPhaseClaim() public view returns (bool) {\n if (block.number % ROUND_LENGTH >= ROUND_LENGTH / 2) {\n return true;\n }\n return false;\n }\n\n function getCurrentTruth() internal view returns (bytes32 Hash, uint8 Depth) {\n uint256 currentSum;\n bytes32 randomNumber;\n uint256 randomNumberTrunc;\n\n bytes32 truthRevealedHash;\n uint8 truthRevealedDepth;\n uint256 revIndex;\n string memory truthSelectionAnchor = currentTruthSelectionAnchor();\n uint256 commitsArrayLength = currentCommits.length;\n\n for (uint256 i = 0; i < commitsArrayLength; ) {\n if (currentCommits[i].revealed) {\n revIndex = currentCommits[i].revealIndex;\n currentSum += currentReveals[revIndex].stakeDensity;\n randomNumber = keccak256(abi.encodePacked(truthSelectionAnchor, i));\n randomNumberTrunc = uint256(randomNumber & MAX_H);\n\n // question is whether randomNumber / MAX_H < probability\n // where probability is stakeDensity / currentSum\n // to avoid resorting to floating points all divisions should be\n // simplified with multiplying both sides (as long as divisor > 0)\n // randomNumber / (MAX_H + 1) < stakeDensity / currentSum\n // ( randomNumber / (MAX_H + 1) ) * currentSum < stakeDensity\n // randomNumber * currentSum < stakeDensity * (MAX_H + 1)\n if (randomNumberTrunc * currentSum < currentReveals[revIndex].stakeDensity * (uint256(MAX_H) + 1)) {\n truthRevealedHash = currentReveals[revIndex].hash;\n truthRevealedDepth = currentReveals[revIndex].depth;\n }\n }\n unchecked {\n ++i;\n }\n }\n\n return (truthRevealedHash, truthRevealedDepth);\n }\n\n /**\n * @notice Determine if a the owner of a given overlay will be the beneficiary of the claim phase.\n * @param _overlay The overlay address of the applicant.\n */\n function isWinner(bytes32 _overlay) public view returns (bool) {\n if (!currentPhaseClaim()) {\n revert NotClaimPhase();\n }\n\n uint64 cr = currentRound();\n if (cr != currentRevealRound) {\n revert NoReveals();\n }\n\n if (cr <= currentClaimRound) {\n revert AlreadyClaimed();\n }\n\n uint256 currentWinnerSelectionSum;\n bytes32 winnerIs;\n bytes32 randomNumber;\n uint256 randomNumberTrunc;\n bytes32 truthRevealedHash;\n uint8 truthRevealedDepth;\n uint256 revIndex;\n string memory winnerSelectionAnchor = currentWinnerSelectionAnchor();\n uint256 redundancyCount = 0;\n\n // Get current truth\n (truthRevealedHash, truthRevealedDepth) = getCurrentTruth();\n uint256 commitsArrayLength = currentCommits.length;\n\n for (uint256 i = 0; i < commitsArrayLength; ) {\n revIndex = currentCommits[i].revealIndex;\n\n // Deterministically read winner\n if (\n currentCommits[i].revealed &&\n truthRevealedHash == currentReveals[revIndex].hash &&\n truthRevealedDepth == currentReveals[revIndex].depth\n ) {\n currentWinnerSelectionSum += currentReveals[revIndex].stakeDensity;\n randomNumber = keccak256(abi.encodePacked(winnerSelectionAnchor, redundancyCount));\n randomNumberTrunc = uint256(randomNumber & MAX_H);\n\n if (\n randomNumberTrunc * currentWinnerSelectionSum <\n currentReveals[revIndex].stakeDensity * (uint256(MAX_H) + 1)\n ) {\n winnerIs = currentReveals[revIndex].overlay;\n }\n\n redundancyCount++;\n }\n unchecked {\n ++i;\n }\n }\n\n return (winnerIs == _overlay);\n }\n\n // ----------------------------- Claim verifications ------------------------------\n\n function socFunction(ChunkInclusionProof calldata entryProof) internal pure {\n if (entryProof.socProof.length == 0) return;\n\n if (\n !Signatures.socVerify(\n entryProof.socProof[0].signer, // signer Ethereum address to check against\n entryProof.socProof[0].signature,\n entryProof.socProof[0].identifier,\n entryProof.socProof[0].chunkAddr\n )\n ) {\n revert SocVerificationFailed(entryProof.socProof[0].chunkAddr);\n }\n\n if (\n calculateSocAddress(entryProof.socProof[0].identifier, entryProof.socProof[0].signer) !=\n entryProof.proveSegment\n ) {\n revert SocCalcNotMatching(entryProof.socProof[0].chunkAddr);\n }\n }\n\n function stampFunction(ChunkInclusionProof calldata entryProof) internal view {\n // authentic\n (address batchOwner, uint8 batchDepth, uint8 bucketDepth, , , ) = PostageContract.batches(\n entryProof.postageProof.postageId\n );\n\n // alive\n if (batchOwner == address(0)) {\n revert BatchDoesNotExist(entryProof.postageProof.postageId); // Batch does not exist or expired\n }\n\n uint32 postageIndex = getPostageIndex(entryProof.postageProof.index);\n uint256 maxPostageIndex = postageStampIndexCount(batchDepth, bucketDepth);\n // available\n if (postageIndex >= maxPostageIndex) {\n revert IndexOutsideSet(entryProof.postageProof.postageId);\n }\n\n // aligned\n uint64 postageBucket = getPostageBucket(entryProof.postageProof.index);\n uint64 addressBucket = addressToBucket(entryProof.proveSegment, bucketDepth);\n if (postageBucket != addressBucket) {\n revert BucketDiffers(entryProof.postageProof.postageId);\n }\n\n // authorized\n if (\n !Signatures.postageVerify(\n batchOwner,\n entryProof.postageProof.signature,\n entryProof.proveSegment,\n entryProof.postageProof.postageId,\n entryProof.postageProof.index,\n entryProof.postageProof.timeStamp\n )\n ) {\n revert SigRecoveryFailed(entryProof.postageProof.postageId);\n }\n }\n\n function addressToBucket(bytes32 swarmAddress, uint8 bucketDepth) internal pure returns (uint32) {\n uint32 prefix = uint32(uint256(swarmAddress) >> (256 - 32));\n return prefix >> (32 - bucketDepth);\n }\n\n function postageStampIndexCount(uint8 postageDepth, uint8 bucketDepth) internal pure returns (uint256) {\n return 1 << (postageDepth - bucketDepth);\n }\n\n function getPostageIndex(uint64 signedIndex) internal pure returns (uint32) {\n return uint32(signedIndex);\n }\n\n function getPostageBucket(uint64 signedIndex) internal pure returns (uint64) {\n return uint32(signedIndex >> 32);\n }\n\n function calculateSocAddress(bytes32 identifier, address signer) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(identifier, signer));\n }\n\n function checkOrder(uint256 a, uint256 b, bytes32 trA1, bytes32 trA2, bytes32 trALast) internal pure {\n if (a < b) {\n if (uint256(trA1) >= uint256(trA2)) {\n revert RandomElementCheckFailed();\n }\n if (uint256(trA2) >= uint256(trALast)) {\n revert LastElementCheckFailed();\n }\n } else {\n if (uint256(trA2) >= uint256(trA1)) {\n revert RandomElementCheckFailed();\n }\n if (uint256(trA1) >= uint256(trALast)) {\n revert LastElementCheckFailed();\n }\n }\n }\n\n function estimateSize(bytes32 trALast) internal view {\n if (uint256(trALast) >= sampleMaxValue) {\n revert ReserveCheckFailed(trALast);\n }\n }\n}\n" + "content": "// SPDX-License-Identifier: BSD-3-Clause\npragma solidity ^0.8.19;\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"@openzeppelin/contracts/security/Pausable.sol\";\nimport \"./Util/TransformedChunkProof.sol\";\nimport \"./Util/ChunkProof.sol\";\nimport \"./Util/Signatures.sol\";\nimport \"./interface/IPostageStamp.sol\";\n\ninterface IPriceOracle {\n function adjustPrice(uint16 redundancy) external;\n}\n\ninterface IStakeRegistry {\n struct Stake {\n bytes32 overlay;\n uint256 stakeAmount;\n uint256 lastUpdatedBlockNumber;\n }\n\n function freezeDeposit(address _owner, uint256 _time) external;\n\n function lastUpdatedBlockNumberOfAddress(address _owner) external view returns (uint256);\n\n function overlayOfAddress(address _owner) external view returns (bytes32);\n\n function heightOfAddress(address _owner) external view returns (uint8);\n\n function nodeEffectiveStake(address _owner) external view returns (uint256);\n}\n\n/**\n * @title Redistribution contract\n * @author The Swarm Authors\n * @dev Implements a Schelling Co-ordination game to form consensus around the Reserve Commitment hash. This takes\n * place in three phases: _commit_, _reveal_ and _claim_.\n *\n * A node, upon establishing that it _isParticipatingInUpcomingRound_, i.e. it's overlay falls within proximity order\n * of its reported depth with the _currentRoundAnchor_, prepares a \"reserve commitment hash\" using the chunks\n * it currently stores in its reserve and calculates the \"storage depth\" (see Bee for details). These values, if calculated\n * honestly, and with the right chunks stored, should be the same for every node in a neighbourhood. This is the Schelling point.\n * Each eligible node can then use these values, together with a random, single use, secret _revealNonce_ and their\n * _overlay_ as the pre-image values for the obsfucated _commit_, using the _wrapCommit_ method.\n *\n * Once the _commit_ round has elapsed, participating nodes must provide the values used to calculate their obsfucated\n * _commit_ hash, which, once verified for correctness and proximity to the anchor are retained in the _currentReveals_.\n * Nodes that have committed but do not reveal the correct values used to create the pre-image will have their stake\n * \"frozen\" for a period of rounds proportional to their reported depth.\n *\n * During the _reveal_ round, randomness is updated after every successful reveal. Once the reveal round is concluded,\n * the _currentRoundAnchor_ is updated and users can determine if they will be eligible their overlay will be eligible\n * for the next commit phase using _isParticipatingInUpcomingRound_.\n *\n * When the _reveal_ phase has been concluded, the claim phase can begin. At this point, the truth teller and winner\n * are already determined. By calling _isWinner_, an applicant node can run the relevant logic to determine if they have\n * been selected as the beneficiary of this round. When calling _claim_, the current pot from the PostageStamp contract\n * is withdrawn and transferred to that beneficiaries address. Nodes that have revealed values that differ from the truth,\n * have their stakes \"frozen\" for a period of rounds proportional to their reported depth.\n */\n\ncontract Redistribution is AccessControl, Pausable {\n // ----------------------------- Type declarations ------------------------------\n\n // An eligible user may commit to an _obfuscatedHash_ during the commit phase...\n struct Commit {\n bytes32 overlay;\n address owner;\n bool revealed;\n uint8 height;\n uint256 stake;\n bytes32 obfuscatedHash;\n uint256 revealIndex;\n }\n // ...then provide the actual values that are the constituents of the pre-image of the _obfuscatedHash_\n // during the reveal phase.\n struct Reveal {\n bytes32 overlay;\n address owner;\n uint8 depth;\n uint256 stake;\n uint256 stakeDensity;\n bytes32 hash;\n }\n\n struct ChunkInclusionProof {\n bytes32[] proofSegments;\n bytes32 proveSegment;\n // _RCspan is known for RC 32*32\n\n // Inclusion proof of transformed address\n bytes32[] proofSegments2;\n bytes32 proveSegment2;\n // proveSegmentIndex2 known from deterministic random selection;\n uint64 chunkSpan;\n bytes32[] proofSegments3;\n // _proveSegment3 known, is equal _proveSegment2\n // proveSegmentIndex3 know, is equal _proveSegmentIndex2;\n // chunkSpan2 is equal to chunkSpan (as the data is the same)\n //\n PostageProof postageProof;\n SOCProof[] socProof;\n }\n\n struct SOCProof {\n address signer; // signer Ethereum address to check against\n bytes signature;\n bytes32 identifier; //\n bytes32 chunkAddr; // wrapped chunk address\n }\n\n struct PostageProof {\n bytes signature;\n bytes32 postageId;\n uint64 index;\n uint64 timeStamp;\n // address signer; it is provided by the postage stamp contract\n // bytes32 chunkAddr; it equals to the proveSegment argument\n }\n\n // The address of the linked PostageStamp contract.\n IPostageStamp public PostageContract;\n // The address of the linked PriceOracle contract.\n IPriceOracle public OracleContract;\n // The address of the linked Staking contract.\n IStakeRegistry public Stakes;\n\n // Commits for the current round.\n Commit[] public currentCommits;\n // Reveals for the current round.\n Reveal[] public currentReveals;\n\n // The current anchor that being processed for the reveal and claim phases of the round.\n bytes32 private currentRevealRoundAnchor;\n\n // The current random value from which we will random.\n // inputs for selection of the truth teller and beneficiary.\n bytes32 private seed;\n\n // The number of the currently active round phases.\n uint64 public currentCommitRound;\n uint64 public currentRevealRound;\n uint64 public currentClaimRound;\n\n // Settings for slashing and freezing\n uint8 private penaltyMultiplierDisagreement = 1;\n uint8 private penaltyMultiplierNonRevealed = 2;\n uint8 private penaltyRandomFactor = 100; // Use 100 as value to ignore random factor in freezing penalty\n\n // alpha=0.097612 beta=0.0716570 k=16\n uint256 private sampleMaxValue = 1284401000000000000000000000000000000000000000000000000000000000000000000;\n\n // The reveal of the winner of the last round.\n Reveal public winner;\n\n // The length of a round in blocks.\n uint256 private constant ROUND_LENGTH = 152;\n\n // Maximum value of the keccack256 hash.\n bytes32 private constant MAX_H = 0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff;\n\n // ----------------------------- Events ------------------------------\n\n /**\n * @dev Emitted when the winner of a round is selected in the claim phase\n */\n event WinnerSelected(Reveal winner);\n\n /**\n * @dev Emitted when the truth oracle of a round is selected in the claim phase.\n */\n event TruthSelected(bytes32 hash, uint8 depth);\n\n // Next two events to be removed after testing phase pending some other usefulness being found.\n /**\n * @dev Emits the number of commits being processed by the claim phase.\n */\n event CountCommits(uint256 _count);\n\n /**\n * @dev Emits the number of reveals being processed by the claim phase.\n */\n event CountReveals(uint256 _count);\n\n /**\n * @dev Logs that an overlay has committed\n */\n event Committed(uint256 roundNumber, bytes32 overlay);\n /**\n * @dev Emit from Postagestamp contract valid chunk count at the end of claim\n */\n event ChunkCount(uint256 validChunkCount);\n\n /**\n * @dev Bytes32 anhor of current reveal round\n */\n event CurrentRevealAnchor(uint256 roundNumber, bytes32 anchor);\n\n /**\n * @dev Logs that an overlay has revealed\n */\n event Revealed(\n uint256 roundNumber,\n bytes32 overlay,\n uint256 stake,\n uint256 stakeDensity,\n bytes32 reserveCommitment,\n uint8 depth\n );\n\n /**\n * @dev Logs for inclusion proof\n */\n event transformedChunkAddressFromInclusionProof(uint256 indexInRC, bytes32 chunkAddress);\n\n // ----------------------------- Errors ------------------------------\n\n error NotCommitPhase(); // Game is not in commit phase\n error NoCommitsReceived(); // Round didn't receive any commits\n error PhaseLastBlock(); // We don't permit commits in last block of the phase\n error CommitRoundOver(); // Commit phase in this round is over\n error CommitRoundNotStarted(); // Commit phase in this round has not started yet\n error NotMatchingOwner(); // Sender of commit is not matching the overlay address\n error MustStake2Rounds(); // Before entering the game node must stake 2 rounds prior\n error NotStaked(); // Node didn't add any staking\n error WrongPhase(); // Checking in wrong phase, need to check duing claim phase of current round for next round or commit in current round\n error AlreadyCommitted(); // Node already committed in this round\n error NotRevealPhase(); // Game is not in reveal phase\n error OutOfDepthReveal(bytes32); // Anchor is out of reported depth in Reveal phase, anchor data available as argument\n error OutOfDepthClaim(uint8); // Anchor is out of reported depth in Claim phase, entryProof index is argument\n error OutOfDepth(); // Anchor is out of reported depth\n error AlreadyRevealed(); // Node already revealed\n error NoMatchingCommit(); // No matching commit and hash\n error NotClaimPhase(); // Game is not in the claim phase\n error NoReveals(); // Round did not receive any reveals\n error FirstRevealDone(); // We don't want to return value after first reveal\n error AlreadyClaimed(); // This round was already claimed\n error NotAdmin(); // Caller of trx is not admin\n error OnlyPauser(); // Only account with pauser role can call pause/unpause\n error SocVerificationFailed(bytes32); // Soc verification failed for this element\n error SocCalcNotMatching(bytes32); // Soc address calculation does not match with the witness\n error IndexOutsideSet(bytes32); // Stamp available: index resides outside of the valid index set\n error SigRecoveryFailed(bytes32); // Stamp authorized: signature recovery failed for element\n error BatchDoesNotExist(bytes32); // Stamp alive: batch remaining balance validation failed for attached stamp\n error BucketDiffers(bytes32); // Stamp aligned: postage bucket differs from address bucket\n error InclusionProofFailed(uint8, bytes32);\n // 1 = RC inclusion proof failed for element\n // 2 = First sister segment in data must match,\n // 3 = Inclusion proof failed for original address of element\n // 4 = Inclusion proof failed for transformed address of element\n error RandomElementCheckFailed(); // Random element order check failed\n error LastElementCheckFailed(); // Last element order check failed\n error ReserveCheckFailed(bytes32 trALast); // Reserve size estimation check failed\n\n // ----------------------------- CONSTRUCTOR ------------------------------\n\n /**\n * @param staking the address of the linked Staking contract.\n * @param postageContract the address of the linked PostageStamp contract.\n * @param oracleContract the address of the linked PriceOracle contract.\n */\n constructor(address staking, address postageContract, address oracleContract) {\n Stakes = IStakeRegistry(staking);\n PostageContract = IPostageStamp(postageContract);\n OracleContract = IPriceOracle(oracleContract);\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n }\n\n ////////////////////////////////////////\n // STATE CHANGING //\n ////////////////////////////////////////\n\n /**\n * @notice Begin application for a round if eligible. Commit a hashed value for which the pre-image will be\n * subsequently revealed.\n * @dev If a node's overlay is _inProximity_(_depth_) of the _currentRoundAnchor_, that node may compute an\n * _obfuscatedHash_ by providing their _overlay_, reported storage _depth_, reserve commitment _hash_ and a\n * randomly generated, and secret _revealNonce_ to the _wrapCommit_ method.\n * @param _obfuscatedHash The calculated hash resultant of the required pre-image values.\n * and be derived from the same key pair as the message sender.\n * @param _roundNumber Node needs to provide round number for which commit is valid\n */\n function commit(bytes32 _obfuscatedHash, uint64 _roundNumber) external whenNotPaused {\n uint64 cr = currentRound();\n bytes32 _overlay = Stakes.overlayOfAddress(msg.sender);\n uint256 _stake = Stakes.nodeEffectiveStake(msg.sender);\n uint256 _lastUpdate = Stakes.lastUpdatedBlockNumberOfAddress(msg.sender);\n uint8 _height = Stakes.heightOfAddress(msg.sender);\n\n if (!currentPhaseCommit()) {\n revert NotCommitPhase();\n }\n if (block.number % ROUND_LENGTH == (ROUND_LENGTH / 4) - 1) {\n revert PhaseLastBlock();\n }\n\n if (cr > _roundNumber) {\n revert CommitRoundOver();\n }\n\n if (cr < _roundNumber) {\n revert CommitRoundNotStarted();\n }\n\n if (_lastUpdate == 0) {\n revert NotStaked();\n }\n\n if (_lastUpdate >= block.number - 2 * ROUND_LENGTH) {\n revert MustStake2Rounds();\n }\n\n // if we are in a new commit phase, reset the array of commits and\n // set the currentCommitRound to be the current one\n if (cr != currentCommitRound) {\n delete currentCommits;\n currentCommitRound = cr;\n }\n\n uint256 commitsArrayLength = currentCommits.length;\n\n for (uint256 i = 0; i < commitsArrayLength; ) {\n if (currentCommits[i].overlay == _overlay) {\n revert AlreadyCommitted();\n }\n\n unchecked {\n ++i;\n }\n }\n\n currentCommits.push(\n Commit({\n overlay: _overlay,\n owner: msg.sender,\n revealed: false,\n height: _height,\n stake: _stake,\n obfuscatedHash: _obfuscatedHash,\n revealIndex: 0\n })\n );\n\n emit Committed(_roundNumber, _overlay);\n }\n\n /**\n * @notice Reveal the pre-image values used to generate commit provided during this round's commit phase.\n * @param _depth The reported depth.\n * @param _hash The reserve commitment hash.\n * @param _revealNonce The nonce used to generate the commit that is being revealed.\n */\n function reveal(uint8 _depth, bytes32 _hash, bytes32 _revealNonce) external whenNotPaused {\n uint64 cr = currentRound();\n bytes32 _overlay = Stakes.overlayOfAddress(msg.sender);\n\n if (_depth < currentMinimumDepth()) {\n revert OutOfDepth();\n }\n\n if (!currentPhaseReveal()) {\n revert NotRevealPhase();\n }\n\n if (cr != currentCommitRound) {\n revert NoCommitsReceived();\n }\n\n if (cr != currentRevealRound) {\n currentRevealRoundAnchor = currentRoundAnchor();\n delete currentReveals;\n // We set currentRevealRound ONLY after we set current anchor\n currentRevealRound = cr;\n emit CurrentRevealAnchor(cr, currentRevealRoundAnchor);\n updateRandomness();\n }\n\n bytes32 obfuscatedHash = wrapCommit(_overlay, _depth, _hash, _revealNonce);\n uint256 id = findCommit(_overlay, obfuscatedHash);\n Commit memory revealedCommit = currentCommits[id];\n uint8 depthResponsibility = _depth - revealedCommit.height;\n\n // Check that commit is in proximity of the current anchor\n if (!inProximity(revealedCommit.overlay, currentRevealRoundAnchor, depthResponsibility)) {\n revert OutOfDepthReveal(currentRevealRoundAnchor);\n }\n // Check that the commit has not already been revealed\n if (revealedCommit.revealed) {\n revert AlreadyRevealed();\n }\n\n currentCommits[id].revealed = true;\n currentCommits[id].revealIndex = currentReveals.length;\n\n currentReveals.push(\n Reveal({\n overlay: revealedCommit.overlay,\n owner: revealedCommit.owner,\n depth: _depth,\n stake: revealedCommit.stake,\n stakeDensity: revealedCommit.stake * uint256(2 ** depthResponsibility),\n hash: _hash\n })\n );\n\n emit Revealed(\n cr,\n revealedCommit.overlay,\n revealedCommit.stake,\n revealedCommit.stake * uint256(2 ** _depth),\n _hash,\n _depth\n );\n }\n\n /**\n * @notice Helper function to get this round truth\n * @dev\n */\n function claim(\n ChunkInclusionProof calldata entryProof1,\n ChunkInclusionProof calldata entryProof2,\n ChunkInclusionProof calldata entryProofLast\n ) external whenNotPaused {\n winnerSelection();\n\n Reveal memory winnerSelected = winner;\n uint256 indexInRC1;\n uint256 indexInRC2;\n bytes32 _currentRevealRoundAnchor = currentRevealRoundAnchor;\n bytes32 _seed = seed;\n\n // rand(14)\n indexInRC1 = uint256(_seed) % 15;\n // rand(13)\n indexInRC2 = uint256(_seed) % 14;\n if (indexInRC2 >= indexInRC1) {\n indexInRC2++;\n }\n\n if (!inProximity(entryProofLast.proveSegment, _currentRevealRoundAnchor, winnerSelected.depth)) {\n revert OutOfDepthClaim(3);\n }\n\n inclusionFunction(entryProofLast, 30);\n stampFunction(entryProofLast);\n socFunction(entryProofLast);\n\n if (!inProximity(entryProof1.proveSegment, _currentRevealRoundAnchor, winnerSelected.depth)) {\n revert OutOfDepthClaim(2);\n }\n\n inclusionFunction(entryProof1, indexInRC1 * 2);\n stampFunction(entryProof1);\n socFunction(entryProof1);\n\n if (!inProximity(entryProof2.proveSegment, _currentRevealRoundAnchor, winnerSelected.depth)) {\n revert OutOfDepthClaim(1);\n }\n\n inclusionFunction(entryProof2, indexInRC2 * 2);\n stampFunction(entryProof2);\n socFunction(entryProof2);\n\n checkOrder(\n indexInRC1,\n indexInRC2,\n entryProof1.proofSegments[0],\n entryProof2.proofSegments[0],\n entryProofLast.proofSegments[0]\n );\n\n estimateSize(entryProofLast.proofSegments[0]);\n\n PostageContract.withdraw(winnerSelected.owner);\n emit WinnerSelected(winnerSelected);\n emit ChunkCount(PostageContract.validChunkCount());\n }\n\n function winnerSelection() internal {\n uint64 cr = currentRound();\n\n if (!currentPhaseClaim()) {\n revert NotClaimPhase();\n }\n\n if (cr != currentRevealRound) {\n revert NoReveals();\n }\n\n if (cr <= currentClaimRound) {\n revert AlreadyClaimed();\n }\n\n uint256 currentWinnerSelectionSum = 0;\n uint256 redundancyCount = 0;\n bytes32 randomNumber;\n uint256 randomNumberTrunc;\n\n bytes32 truthRevealedHash;\n uint8 truthRevealedDepth;\n uint256 currentCommitsLength = currentCommits.length;\n\n emit CountCommits(currentCommitsLength);\n emit CountReveals(currentReveals.length);\n\n (truthRevealedHash, truthRevealedDepth) = getCurrentTruth();\n emit TruthSelected(truthRevealedHash, truthRevealedDepth);\n string memory winnerSelectionAnchor = currentWinnerSelectionAnchor();\n\n for (uint256 i = 0; i < currentCommitsLength; ) {\n Commit memory currentCommit = currentCommits[i];\n uint256 revIndex = currentCommit.revealIndex;\n Reveal memory currentReveal = currentReveals[revIndex];\n\n // Select winner with valid truth\n if (\n currentCommit.revealed &&\n truthRevealedHash == currentReveal.hash &&\n truthRevealedDepth == currentReveal.depth\n ) {\n currentWinnerSelectionSum += currentReveal.stakeDensity;\n randomNumber = keccak256(abi.encodePacked(winnerSelectionAnchor, redundancyCount));\n randomNumberTrunc = uint256(randomNumber & MAX_H);\n\n if (randomNumberTrunc * currentWinnerSelectionSum < currentReveal.stakeDensity * (uint256(MAX_H) + 1)) {\n winner = currentReveal;\n }\n\n redundancyCount++;\n }\n\n // Freeze deposit if any truth is false, make it a penaltyRandomFactor chance for this to happen\n if (\n currentCommit.revealed &&\n (truthRevealedHash != currentReveal.hash || truthRevealedDepth != currentReveal.depth) &&\n (block.prevrandao % 100 < penaltyRandomFactor)\n ) {\n Stakes.freezeDeposit(\n currentReveal.owner,\n penaltyMultiplierDisagreement * ROUND_LENGTH * uint256(2 ** truthRevealedDepth)\n );\n }\n\n // Slash deposits if revealed is false\n if (!currentCommit.revealed) {\n // slash in later phase (ph5)\n // Stakes.slashDeposit(currentCommits[i].overlay, currentCommits[i].stake);\n Stakes.freezeDeposit(\n currentCommit.owner,\n penaltyMultiplierNonRevealed * ROUND_LENGTH * uint256(2 ** truthRevealedDepth)\n );\n }\n unchecked {\n ++i;\n }\n }\n\n OracleContract.adjustPrice(uint16(redundancyCount));\n currentClaimRound = cr;\n }\n\n function inclusionFunction(ChunkInclusionProof calldata entryProof, uint256 indexInRC) internal {\n uint256 randomChunkSegmentIndex = uint256(seed) % 128;\n bytes32 calculatedTransformedAddr = TransformedBMTChunk.transformedChunkAddressFromInclusionProof(\n entryProof.proofSegments3,\n entryProof.proveSegment2,\n randomChunkSegmentIndex,\n entryProof.chunkSpan,\n currentRevealRoundAnchor\n );\n\n emit transformedChunkAddressFromInclusionProof(indexInRC, calculatedTransformedAddr);\n\n if (\n winner.hash !=\n BMTChunk.chunkAddressFromInclusionProof(\n entryProof.proofSegments,\n entryProof.proveSegment,\n indexInRC,\n 32 * 32\n )\n ) {\n revert InclusionProofFailed(1, calculatedTransformedAddr);\n }\n\n if (entryProof.proofSegments2[0] != entryProof.proofSegments3[0]) {\n revert InclusionProofFailed(2, calculatedTransformedAddr);\n }\n\n bytes32 originalAddress = entryProof.socProof.length > 0\n ? entryProof.socProof[0].chunkAddr // soc attestation in socFunction\n : entryProof.proveSegment;\n\n if (\n originalAddress !=\n BMTChunk.chunkAddressFromInclusionProof(\n entryProof.proofSegments2,\n entryProof.proveSegment2,\n randomChunkSegmentIndex,\n entryProof.chunkSpan\n )\n ) {\n revert InclusionProofFailed(3, calculatedTransformedAddr);\n }\n\n // In case of SOC, the transformed address is hashed together with its address in the sample\n if (entryProof.socProof.length > 0) {\n calculatedTransformedAddr = keccak256(\n abi.encode(\n entryProof.proveSegment, // SOC address\n calculatedTransformedAddr\n )\n );\n }\n\n if (entryProof.proofSegments[0] != calculatedTransformedAddr) {\n revert InclusionProofFailed(4, calculatedTransformedAddr);\n }\n }\n\n /**\n * @notice Set freezing parameters\n */\n function setFreezingParams(\n uint8 _penaltyMultiplierDisagreement,\n uint8 _penaltyMultiplierNonRevealed,\n uint8 _penaltyRandomFactor\n ) external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert NotAdmin();\n }\n\n penaltyMultiplierDisagreement = _penaltyMultiplierDisagreement;\n penaltyMultiplierNonRevealed = _penaltyMultiplierNonRevealed;\n penaltyRandomFactor = _penaltyRandomFactor;\n }\n\n /**\n * @notice changes the max sample value used for reserve estimation\n */\n function setSampleMaxValue(uint256 _sampleMaxValue) external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert NotAdmin();\n }\n\n sampleMaxValue = _sampleMaxValue;\n }\n\n /**\n * @notice Updates the source of randomness. Uses block.difficulty in pre-merge chains, this is substituted\n * to block.prevrandao in post merge chains.\n */\n function updateRandomness() private {\n seed = keccak256(abi.encode(seed, block.prevrandao));\n }\n\n /**\n * @dev Pause the contract. The contract is provably stopped by renouncing\n the pauser role and the admin role after pausing, can only be called by the `PAUSER`\n */\n function pause() public {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert OnlyPauser();\n }\n\n _pause();\n }\n\n /**\n * @dev Unpause the contract, can only be called by the pauser when paused\n */\n function unPause() public {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert OnlyPauser();\n }\n _unpause();\n }\n\n ////////////////////////////////////////\n // STATE READING //\n ////////////////////////////////////////\n\n // ----------------------------- Anchor calculations ------------------------------\n\n /**\n * @notice Returns the current random seed which is used to determine later utilised random numbers.\n * If rounds have elapsed without reveals, hash the seed with an incremented nonce to produce a new\n * random seed and hence a new round anchor.\n */\n function currentSeed() public view returns (bytes32) {\n uint64 cr = currentRound();\n bytes32 currentSeedValue = seed;\n\n if (cr > currentRevealRound + 1) {\n uint256 difference = cr - currentRevealRound - 1;\n currentSeedValue = keccak256(abi.encodePacked(currentSeedValue, difference));\n }\n\n return currentSeedValue;\n }\n\n /**\n * @notice Returns the seed which will become current once the next commit phase begins.\n * Used to determine what the next round's anchor will be.\n */\n function nextSeed() public view returns (bytes32) {\n uint64 cr = currentRound() + 1;\n bytes32 currentSeedValue = seed;\n\n if (cr > currentRevealRound + 1) {\n uint256 difference = cr - currentRevealRound - 1;\n currentSeedValue = keccak256(abi.encodePacked(currentSeedValue, difference));\n }\n\n return currentSeedValue;\n }\n\n /**\n * @notice The random value used to choose the selected truth teller.\n */\n function currentTruthSelectionAnchor() private view returns (string memory) {\n if (!currentPhaseClaim()) {\n revert NotClaimPhase();\n }\n\n uint64 cr = currentRound();\n if (cr != currentRevealRound) {\n revert NoReveals();\n }\n\n return string(abi.encodePacked(seed, \"0\"));\n }\n\n /**\n * @notice The random value used to choose the selected beneficiary.\n */\n function currentWinnerSelectionAnchor() private view returns (string memory) {\n if (!currentPhaseClaim()) {\n revert NotClaimPhase();\n }\n uint64 cr = currentRound();\n if (cr != currentRevealRound) {\n revert NoReveals();\n }\n\n return string(abi.encodePacked(seed, \"1\"));\n }\n\n /**\n * @notice The anchor used to determine eligibility for the current round.\n * @dev A node must be within proximity order of less than or equal to the storage depth they intend to report.\n */\n function currentRoundAnchor() public view returns (bytes32 returnVal) {\n // This will be called in reveal phase and set as currentRevealRoundAnchor or in\n // commit phase when checking eligibility for next round by isParticipatingInUpcomingRound\n if (currentPhaseCommit() || (currentRound() > currentRevealRound && !currentPhaseClaim())) {\n return currentSeed();\n }\n\n // This will be called by isParticipatingInUpcomingRound check in claim phase\n if (currentPhaseClaim()) {\n return nextSeed();\n }\n\n // Without this, this function will output 0x0 after first reveal which is value and we prefere it reverts\n if (currentPhaseReveal() && currentRound() == currentRevealRound) {\n revert FirstRevealDone();\n }\n }\n\n /**\n * @notice Returns true if an overlay address _A_ is within proximity order _minimum_ of _B_.\n * @param A An overlay address to compare.\n * @param B An overlay address to compare.\n * @param minimum Minimum proximity order.\n */\n function inProximity(bytes32 A, bytes32 B, uint8 minimum) public pure returns (bool) {\n if (minimum == 0) {\n return true;\n }\n\n return uint256(A ^ B) < uint256(2 ** (256 - minimum));\n }\n\n // ----------------------------- Commit ------------------------------\n\n /**\n * @notice The number of the current round.\n */\n function currentRound() public view returns (uint64) {\n return uint64(block.number / ROUND_LENGTH);\n }\n\n /**\n * @notice Returns true if current block is during commit phase.\n */\n function currentPhaseCommit() public view returns (bool) {\n if (block.number % ROUND_LENGTH < ROUND_LENGTH / 4) {\n return true;\n }\n return false;\n }\n\n /**\n * @notice Determine if a the owner of a given overlay can participate in the upcoming round.\n * @param _owner The address of the applicant from.\n * @param _depth The storage depth the applicant intends to report.\n */\n function isParticipatingInUpcomingRound(address _owner, uint8 _depth) public view returns (bool) {\n uint256 _lastUpdate = Stakes.lastUpdatedBlockNumberOfAddress(_owner);\n uint8 _depthResponsibility = _depth - Stakes.heightOfAddress(_owner);\n\n if (currentPhaseReveal()) {\n revert WrongPhase();\n }\n\n if (_lastUpdate == 0) {\n revert NotStaked();\n }\n\n if (_lastUpdate >= block.number - 2 * ROUND_LENGTH) {\n revert MustStake2Rounds();\n }\n\n return inProximity(Stakes.overlayOfAddress(_owner), currentRoundAnchor(), _depthResponsibility);\n }\n\n // ----------------------------- Reveal ------------------------------\n\n /**\n * @notice Returns minimum depth reveal has to have to participate in this round\n */\n function currentMinimumDepth() public view returns (uint8) {\n // We are checking value in reveal phase, as the currentCommitRound is set to the current round\n // but the currentClaimRound is still set to the last time claim was made\n // We add 1 to ensure that for the next round the minimum depth is the same as last winner depth\n\n uint256 difference = currentCommitRound - currentClaimRound;\n uint8 skippedRounds = uint8(difference > 254 ? 254 : difference) + 1;\n\n uint8 lastWinnerDepth = winner.depth;\n\n // We ensure that skippedRounds is not bigger than lastWinnerDepth, because of overflow\n return skippedRounds >= lastWinnerDepth ? 0 : lastWinnerDepth - skippedRounds;\n }\n\n /**\n * @notice Helper function to get this node reveal in commits\n * @dev\n */\n function findCommit(bytes32 _overlay, bytes32 _obfuscatedHash) internal view returns (uint256) {\n for (uint256 i = 0; i < currentCommits.length; ) {\n if (currentCommits[i].overlay == _overlay && _obfuscatedHash == currentCommits[i].obfuscatedHash) {\n return i;\n }\n unchecked {\n ++i;\n }\n }\n revert NoMatchingCommit();\n }\n\n /**\n * @notice Hash the pre-image values to the obsfucated hash.\n * @dev _revealNonce_ must be randomly generated, used once and kept secret until the reveal phase.\n * @param _overlay The overlay address of the applicant.\n * @param _depth The reported depth.\n * @param _hash The reserve commitment hash.\n * @param revealNonce A random, single use, secret nonce.\n */\n function wrapCommit(\n bytes32 _overlay,\n uint8 _depth,\n bytes32 _hash,\n bytes32 revealNonce\n ) public pure returns (bytes32) {\n return keccak256(abi.encodePacked(_overlay, _depth, _hash, revealNonce));\n }\n\n /**\n * @notice Returns true if current block is during reveal phase.\n */\n function currentPhaseReveal() public view returns (bool) {\n uint256 number = block.number % ROUND_LENGTH;\n if (number >= ROUND_LENGTH / 4 && number < ROUND_LENGTH / 2) {\n return true;\n }\n return false;\n }\n\n /**\n * @notice Returns true if current block is during reveal phase.\n */\n function currentRoundReveals() public view returns (Reveal[] memory) {\n if (!currentPhaseClaim()) {\n revert NotClaimPhase();\n }\n uint64 cr = currentRound();\n if (cr != currentRevealRound) {\n revert NoReveals();\n }\n\n return currentReveals;\n }\n\n // ----------------------------- Claim ------------------------------\n\n /**\n * @notice Returns true if current block is during claim phase.\n */\n function currentPhaseClaim() public view returns (bool) {\n if (block.number % ROUND_LENGTH >= ROUND_LENGTH / 2) {\n return true;\n }\n return false;\n }\n\n function getCurrentTruth() internal view returns (bytes32 Hash, uint8 Depth) {\n uint256 currentSum;\n bytes32 randomNumber;\n uint256 randomNumberTrunc;\n\n bytes32 truthRevealedHash;\n uint8 truthRevealedDepth;\n uint256 revIndex;\n string memory truthSelectionAnchor = currentTruthSelectionAnchor();\n uint256 commitsArrayLength = currentCommits.length;\n\n for (uint256 i = 0; i < commitsArrayLength; ) {\n if (currentCommits[i].revealed) {\n revIndex = currentCommits[i].revealIndex;\n currentSum += currentReveals[revIndex].stakeDensity;\n randomNumber = keccak256(abi.encodePacked(truthSelectionAnchor, i));\n randomNumberTrunc = uint256(randomNumber & MAX_H);\n\n // question is whether randomNumber / MAX_H < probability\n // where probability is stakeDensity / currentSum\n // to avoid resorting to floating points all divisions should be\n // simplified with multiplying both sides (as long as divisor > 0)\n // randomNumber / (MAX_H + 1) < stakeDensity / currentSum\n // ( randomNumber / (MAX_H + 1) ) * currentSum < stakeDensity\n // randomNumber * currentSum < stakeDensity * (MAX_H + 1)\n if (randomNumberTrunc * currentSum < currentReveals[revIndex].stakeDensity * (uint256(MAX_H) + 1)) {\n truthRevealedHash = currentReveals[revIndex].hash;\n truthRevealedDepth = currentReveals[revIndex].depth;\n }\n }\n unchecked {\n ++i;\n }\n }\n\n return (truthRevealedHash, truthRevealedDepth);\n }\n\n /**\n * @notice Determine if a the owner of a given overlay will be the beneficiary of the claim phase.\n * @param _overlay The overlay address of the applicant.\n */\n function isWinner(bytes32 _overlay) public view returns (bool) {\n if (!currentPhaseClaim()) {\n revert NotClaimPhase();\n }\n\n uint64 cr = currentRound();\n if (cr != currentRevealRound) {\n revert NoReveals();\n }\n\n if (cr <= currentClaimRound) {\n revert AlreadyClaimed();\n }\n\n uint256 currentWinnerSelectionSum;\n bytes32 winnerIs;\n bytes32 randomNumber;\n uint256 randomNumberTrunc;\n bytes32 truthRevealedHash;\n uint8 truthRevealedDepth;\n uint256 revIndex;\n string memory winnerSelectionAnchor = currentWinnerSelectionAnchor();\n uint256 redundancyCount = 0;\n\n // Get current truth\n (truthRevealedHash, truthRevealedDepth) = getCurrentTruth();\n uint256 commitsArrayLength = currentCommits.length;\n\n for (uint256 i = 0; i < commitsArrayLength; ) {\n revIndex = currentCommits[i].revealIndex;\n\n // Deterministically read winner\n if (\n currentCommits[i].revealed &&\n truthRevealedHash == currentReveals[revIndex].hash &&\n truthRevealedDepth == currentReveals[revIndex].depth\n ) {\n currentWinnerSelectionSum += currentReveals[revIndex].stakeDensity;\n randomNumber = keccak256(abi.encodePacked(winnerSelectionAnchor, redundancyCount));\n randomNumberTrunc = uint256(randomNumber & MAX_H);\n\n if (\n randomNumberTrunc * currentWinnerSelectionSum <\n currentReveals[revIndex].stakeDensity * (uint256(MAX_H) + 1)\n ) {\n winnerIs = currentReveals[revIndex].overlay;\n }\n\n redundancyCount++;\n }\n unchecked {\n ++i;\n }\n }\n\n return (winnerIs == _overlay);\n }\n\n // ----------------------------- Claim verifications ------------------------------\n\n function socFunction(ChunkInclusionProof calldata entryProof) internal pure {\n if (entryProof.socProof.length == 0) return;\n\n if (\n !Signatures.socVerify(\n entryProof.socProof[0].signer, // signer Ethereum address to check against\n entryProof.socProof[0].signature,\n entryProof.socProof[0].identifier,\n entryProof.socProof[0].chunkAddr\n )\n ) {\n revert SocVerificationFailed(entryProof.socProof[0].chunkAddr);\n }\n\n if (\n calculateSocAddress(entryProof.socProof[0].identifier, entryProof.socProof[0].signer) !=\n entryProof.proveSegment\n ) {\n revert SocCalcNotMatching(entryProof.socProof[0].chunkAddr);\n }\n }\n\n function stampFunction(ChunkInclusionProof calldata entryProof) internal view {\n // authentic\n (address batchOwner, uint8 batchDepth, uint8 bucketDepth, , , ) = PostageContract.batches(\n entryProof.postageProof.postageId\n );\n\n // alive\n if (batchOwner == address(0)) {\n revert BatchDoesNotExist(entryProof.postageProof.postageId); // Batch does not exist or expired\n }\n\n uint32 postageIndex = getPostageIndex(entryProof.postageProof.index);\n uint256 maxPostageIndex = postageStampIndexCount(batchDepth, bucketDepth);\n // available\n if (postageIndex >= maxPostageIndex) {\n revert IndexOutsideSet(entryProof.postageProof.postageId);\n }\n\n // aligned\n uint64 postageBucket = getPostageBucket(entryProof.postageProof.index);\n uint64 addressBucket = addressToBucket(entryProof.proveSegment, bucketDepth);\n if (postageBucket != addressBucket) {\n revert BucketDiffers(entryProof.postageProof.postageId);\n }\n\n // authorized\n if (\n !Signatures.postageVerify(\n batchOwner,\n entryProof.postageProof.signature,\n entryProof.proveSegment,\n entryProof.postageProof.postageId,\n entryProof.postageProof.index,\n entryProof.postageProof.timeStamp\n )\n ) {\n revert SigRecoveryFailed(entryProof.postageProof.postageId);\n }\n }\n\n function addressToBucket(bytes32 swarmAddress, uint8 bucketDepth) internal pure returns (uint32) {\n uint32 prefix = uint32(uint256(swarmAddress) >> (256 - 32));\n return prefix >> (32 - bucketDepth);\n }\n\n function postageStampIndexCount(uint8 postageDepth, uint8 bucketDepth) internal pure returns (uint256) {\n return 1 << (postageDepth - bucketDepth);\n }\n\n function getPostageIndex(uint64 signedIndex) internal pure returns (uint32) {\n return uint32(signedIndex);\n }\n\n function getPostageBucket(uint64 signedIndex) internal pure returns (uint64) {\n return uint32(signedIndex >> 32);\n }\n\n function calculateSocAddress(bytes32 identifier, address signer) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(identifier, signer));\n }\n\n function checkOrder(uint256 a, uint256 b, bytes32 trA1, bytes32 trA2, bytes32 trALast) internal pure {\n if (a < b) {\n if (uint256(trA1) >= uint256(trA2)) {\n revert RandomElementCheckFailed();\n }\n if (uint256(trA2) >= uint256(trALast)) {\n revert LastElementCheckFailed();\n }\n } else {\n if (uint256(trA2) >= uint256(trA1)) {\n revert RandomElementCheckFailed();\n }\n if (uint256(trA1) >= uint256(trALast)) {\n revert LastElementCheckFailed();\n }\n }\n }\n\n function estimateSize(bytes32 trALast) internal view {\n if (uint256(trALast) >= sampleMaxValue) {\n revert ReserveCheckFailed(trALast);\n }\n }\n}\n" }, "src/Staking.sol": { - "content": "// SPDX-License-Identifier: BSD-3-Clause\npragma solidity ^0.8.19;\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"@openzeppelin/contracts/security/Pausable.sol\";\n\n/**\n * @title Staking contract for the Swarm storage incentives\n * @author The Swarm Authors\n * @dev Allows users to stake tokens in order to be eligible for the Redistribution Schelling co-ordination game.\n * Stakes are frozen or slashed by the Redistribution contract in response to violations of the\n * protocol.\n */\n\ncontract StakeRegistry is AccessControl, Pausable {\n // ----------------------------- State variables ------------------------------\n\n struct Stake {\n // Overlay of the node that is being staked\n bytes32 overlay;\n // Amount of tokens staked\n uint256 stakeAmount;\n // Block height the stake was updated\n uint256 lastUpdatedBlockNumber;\n // Used to indicate presents in stakes struct\n bool isValue;\n }\n\n // Associate every stake id with node address data.\n mapping(address => Stake) public stakes;\n\n // Role allowed to pause\n bytes32 public constant PAUSER_ROLE = keccak256(\"PAUSER_ROLE\");\n // Role allowed to freeze and slash entries\n bytes32 public constant REDISTRIBUTOR_ROLE = keccak256(\"REDISTRIBUTOR_ROLE\");\n\n // Swarm network ID\n uint64 NetworkId;\n\n // Address of the staked ERC20 token\n address public immutable bzzToken;\n\n // ----------------------------- Events ------------------------------\n\n /**\n * @dev Emitted when a stake is created or updated by `owner` of the `overlay` by `stakeamount`, during `lastUpdatedBlock`.\n */\n event StakeUpdated(address indexed owner, uint256 stakeAmount, bytes32 overlay, uint256 lastUpdatedBlock);\n\n /**\n * @dev Emitted when a stake for address `slashed` is slashed by `amount`.\n */\n event StakeSlashed(address slashed, bytes32 overlay, uint256 amount);\n\n /**\n * @dev Emitted when a stake for address `frozen` is frozen for `time` blocks.\n */\n event StakeFrozen(address frozen, bytes32 overlay, uint256 time);\n\n /**\n * @dev Emitted when a address changes overlay it uses\n */\n event OverlayChanged(address owner, bytes32 overlay);\n\n // ----------------------------- Errors ------------------------------\n\n error TransferFailed(); // Used when token transfers fail\n error Frozen(); // Used when an action cannot proceed because the overlay is frozen\n error Unauthorized(); // Used where only the owner can perform the action\n error OnlyRedistributor(); // Used when only the redistributor role is allowed\n error OnlyPauser(); // Used when only the pauser role is allowed\n\n // ----------------------------- CONSTRUCTOR ------------------------------\n\n /**\n * @param _bzzToken Address of the staked ERC20 token\n * @param _NetworkId Swarm network ID\n */\n constructor(address _bzzToken, uint64 _NetworkId) {\n NetworkId = _NetworkId;\n bzzToken = _bzzToken;\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n _setupRole(PAUSER_ROLE, msg.sender);\n }\n\n ////////////////////////////////////////\n // STATE SETTING //\n ////////////////////////////////////////\n\n /**\n * @notice Create a new stake or update an existing one, change overlay of node\n * @dev At least `_initialBalancePerChunk*2^depth` number of tokens need to be preapproved for this contract.\n * @param _setNonce Nonce that was used for overlay calculation.\n * @param _addAmount Deposited amount of ERC20 tokens.\n */\n function manageStake(bytes32 _setNonce, uint256 _addAmount) external whenNotPaused {\n bytes32 _previousOverlay = stakes[msg.sender].overlay;\n bytes32 _newOverlay = keccak256(abi.encodePacked(msg.sender, reverse(NetworkId), _setNonce));\n\n if (stakes[msg.sender].isValue && !addressNotFrozen(msg.sender)) revert Frozen();\n uint256 updatedAmount = stakes[msg.sender].isValue ? _addAmount + stakes[msg.sender].stakeAmount : _addAmount;\n\n stakes[msg.sender] = Stake({\n overlay: _newOverlay,\n stakeAmount: updatedAmount,\n lastUpdatedBlockNumber: block.number,\n isValue: true\n });\n\n // Transfer tokens and emit event that stake has been updated\n if (_addAmount > 0) {\n if (!ERC20(bzzToken).transferFrom(msg.sender, address(this), _addAmount)) revert TransferFailed();\n emit StakeUpdated(msg.sender, updatedAmount, _newOverlay, block.number);\n }\n\n // Emit overlay change event\n if (_previousOverlay != _newOverlay) {\n emit OverlayChanged(msg.sender, _newOverlay);\n }\n }\n\n /**\n * @dev Withdraw stake only when the staking contract is paused,\n * @param _amount The amount of ERC20 tokens to be withdrawn\n */\n function withdrawFromStake(uint256 _amount) external whenPaused {\n Stake memory stake = stakes[msg.sender];\n\n // We cap the limit to not be over what is possible\n uint256 withDrawLimit = (_amount > stake.stakeAmount) ? stake.stakeAmount : _amount;\n stake.stakeAmount -= withDrawLimit;\n\n if (stake.stakeAmount == 0) {\n delete stakes[msg.sender];\n } else {\n stakes[msg.sender].lastUpdatedBlockNumber = block.number;\n }\n\n if (!ERC20(bzzToken).transfer(msg.sender, withDrawLimit)) revert TransferFailed();\n }\n\n /**\n * @dev Freeze an existing stake, can only be called by the redistributor\n * @param _owner the addres selected\n * @param _time penalty length in blocknumbers\n */\n function freezeDeposit(address _owner, uint256 _time) external {\n if (!hasRole(REDISTRIBUTOR_ROLE, msg.sender)) revert OnlyRedistributor();\n\n if (stakes[_owner].isValue) {\n stakes[_owner].lastUpdatedBlockNumber = block.number + _time;\n emit StakeFrozen(_owner, stakes[_owner].overlay, _time);\n }\n }\n\n /**\n * @dev Slash an existing stake, can only be called by the `redistributor`\n * @param _owner the _owner adress selected\n * @param _amount the amount to be slashed\n */\n function slashDeposit(address _owner, uint256 _amount) external {\n if (!hasRole(REDISTRIBUTOR_ROLE, msg.sender)) revert OnlyRedistributor();\n\n if (stakes[_owner].isValue) {\n if (stakes[_owner].stakeAmount > _amount) {\n stakes[_owner].stakeAmount -= _amount;\n stakes[_owner].lastUpdatedBlockNumber = block.number;\n } else {\n delete stakes[_owner];\n }\n }\n emit StakeSlashed(_owner, stakes[_owner].overlay, _amount);\n }\n\n function changeNetworkId(uint64 _NetworkId) external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) revert Unauthorized();\n NetworkId = _NetworkId;\n }\n\n /**\n * @dev Pause the contract. The contract is provably stopped by renouncing\n the pauser role and the admin role after pausing, can only be called by the `PAUSER`\n */\n function pause() public {\n if (!hasRole(PAUSER_ROLE, msg.sender)) revert OnlyPauser();\n _pause();\n }\n\n /**\n * @dev Unpause the contract, can only be called by the pauser when paused\n */\n function unPause() public {\n if (!hasRole(PAUSER_ROLE, msg.sender)) revert OnlyPauser();\n _unpause();\n }\n\n ////////////////////////////////////////\n // STATE READING //\n ////////////////////////////////////////\n\n /**\n * @dev Checks to see if `address` is frozen.\n * @param _owner owner of staked address\n *\n * Returns a boolean value indicating whether the operation succeeded.\n */\n function addressNotFrozen(address _owner) internal view returns (bool) {\n return stakes[_owner].lastUpdatedBlockNumber < block.number;\n }\n\n /**\n * @dev Returns the current `stakeAmount` of `address`.\n * @param _owner _owner of node\n */\n function stakeOfAddress(address _owner) public view returns (uint256) {\n return stakes[_owner].stakeAmount;\n }\n\n /**\n * @dev Returns the current usable `stakeAmount` of `address`.\n * Checks whether the stake is currently frozen.\n * @param _owner owner of node\n */\n function usableStakeOfAddress(address _owner) public view returns (uint256) {\n return addressNotFrozen(_owner) ? stakes[_owner].stakeAmount : 0;\n }\n\n /**\n * @dev Returns the `lastUpdatedBlockNumber` of `address`.\n */\n function lastUpdatedBlockNumberOfAddress(address _owner) public view returns (uint256) {\n return stakes[_owner].lastUpdatedBlockNumber;\n }\n\n /**\n * @dev Returns the currently used overlay of the address.\n * @param _owner address of node\n */\n function overlayOfAddress(address _owner) public view returns (bytes32) {\n return stakes[_owner].overlay;\n }\n\n /**\n * @dev Please both Endians 🥚.\n * @param input Eth address used for overlay calculation.\n */\n function reverse(uint64 input) internal pure returns (uint64 v) {\n v = input;\n\n // swap bytes\n v = ((v & 0xFF00FF00FF00FF00) >> 8) | ((v & 0x00FF00FF00FF00FF) << 8);\n\n // swap 2-byte long pairs\n v = ((v & 0xFFFF0000FFFF0000) >> 16) | ((v & 0x0000FFFF0000FFFF) << 16);\n\n // swap 4-byte long pairs\n v = (v >> 32) | (v << 32);\n }\n}\n" + "content": "// SPDX-License-Identifier: BSD-3-Clause\npragma solidity ^0.8.19;\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"@openzeppelin/contracts/security/Pausable.sol\";\n\ninterface IPriceOracle {\n function currentPrice() external view returns (uint32);\n}\n\n/**\n * @title Staking contract for the Swarm storage incentives\n * @author The Swarm Authors\n * @dev Allows users to stake tokens in order to be eligible for the Redistribution Schelling co-ordination game.\n * Stakes are frozen or slashed by the Redistribution contract in response to violations of the\n * protocol.\n */\n\ncontract StakeRegistry is AccessControl, Pausable {\n // ----------------------------- State variables ------------------------------\n\n struct Stake {\n // Overlay of the node that is being staked\n bytes32 overlay;\n // Stake balance expressed through price oracle\n uint256 committedStake;\n // Stake balance expressed in BZZ\n uint256 potentialStake;\n // Block height the stake was updated, also used as flag to check if the stake is set\n uint256 lastUpdatedBlockNumber;\n // Node indicating its increased reserve\n uint8 height;\n }\n\n // Associate every stake id with node address data.\n mapping(address => Stake) public stakes;\n\n // Role allowed to freeze and slash entries\n bytes32 public constant REDISTRIBUTOR_ROLE = keccak256(\"REDISTRIBUTOR_ROLE\");\n\n // Swarm network ID\n uint64 NetworkId;\n\n // The miniumum stake allowed to be staked using the Staking contract.\n uint64 private constant MIN_STAKE = 100000000000000000;\n\n // Address of the staked ERC20 token\n address public immutable bzzToken;\n\n // The address of the linked PriceOracle contract.\n IPriceOracle public OracleContract;\n\n // ----------------------------- Events ------------------------------\n\n /**\n * @dev Emitted when a stake is created or updated by `owner` of the `overlay`.\n */\n event StakeUpdated(\n address indexed owner,\n uint256 committedStake,\n uint256 potentialStake,\n bytes32 overlay,\n uint256 lastUpdatedBlock,\n uint8 height\n );\n\n /**\n * @dev Emitted when a stake for address `slashed` is slashed by `amount`.\n */\n event StakeSlashed(address slashed, bytes32 overlay, uint256 amount);\n\n /**\n * @dev Emitted when a stake for address `frozen` is frozen for `time` blocks.\n */\n event StakeFrozen(address frozen, bytes32 overlay, uint256 time);\n\n /**\n * @dev Emitted when a address changes overlay it uses\n */\n event OverlayChanged(address owner, bytes32 overlay);\n\n /**\n * @dev Emitted when a stake for address is withdrawn\n */\n event StakeWithdrawn(address node, uint256 amount);\n\n // ----------------------------- Errors ------------------------------\n\n error TransferFailed(); // Used when token transfers fail\n error Frozen(); // Used when an action cannot proceed because the overlay is frozen\n error Unauthorized(); // Used where only the owner can perform the action\n error OnlyRedistributor(); // Used when only the redistributor role is allowed\n error OnlyPauser(); // Used when only the pauser role is allowed\n error BelowMinimumStake(); // Node participating in game has stake below minimum treshold\n\n // ----------------------------- CONSTRUCTOR ------------------------------\n\n /**\n * @param _bzzToken Address of the staked ERC20 token\n * @param _NetworkId Swarm network ID\n */\n constructor(address _bzzToken, uint64 _NetworkId, address _oracleContract) {\n NetworkId = _NetworkId;\n bzzToken = _bzzToken;\n OracleContract = IPriceOracle(_oracleContract);\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n }\n\n ////////////////////////////////////////\n // STATE SETTING //\n ////////////////////////////////////////\n\n /**\n * @notice Create a new stake or update an existing one, change overlay of node\n * @dev At least `_initialBalancePerChunk*2^depth` number of tokens need to be preapproved for this contract.\n * @param _setNonce Nonce that was used for overlay calculation.\n * @param _addAmount Deposited amount of ERC20 tokens, equals to added Potential stake value\n * @param _height increased reserve by registering the number of doublings\n */\n function manageStake(bytes32 _setNonce, uint256 _addAmount, uint8 _height) external whenNotPaused {\n bytes32 _previousOverlay = stakes[msg.sender].overlay;\n uint256 _stakingSet = stakes[msg.sender].lastUpdatedBlockNumber;\n bytes32 _newOverlay = keccak256(abi.encodePacked(msg.sender, reverse(NetworkId), _setNonce));\n uint256 _addCommittedStake = _addAmount / OracleContract.currentPrice(); // losing some decimals from start 10n16 becomes 99999999999984000\n\n // First time adding stake, check the minimum is added\n if (_addAmount < MIN_STAKE && _stakingSet == 0) {\n revert BelowMinimumStake();\n }\n\n if (_stakingSet != 0 && !addressNotFrozen(msg.sender)) revert Frozen();\n uint256 updatedCommittedStake = stakes[msg.sender].committedStake + _addCommittedStake;\n uint256 updatedPotentialStake = stakes[msg.sender].potentialStake + _addAmount;\n\n stakes[msg.sender] = Stake({\n overlay: _newOverlay,\n committedStake: updatedCommittedStake,\n potentialStake: updatedPotentialStake,\n lastUpdatedBlockNumber: block.number,\n height: _height\n });\n\n // Transfer tokens and emit event that stake has been updated\n if (_addAmount > 0) {\n if (!ERC20(bzzToken).transferFrom(msg.sender, address(this), _addAmount)) revert TransferFailed();\n emit StakeUpdated(\n msg.sender,\n updatedCommittedStake,\n updatedPotentialStake,\n _newOverlay,\n block.number,\n _height\n );\n }\n\n // Emit overlay change event\n if (_previousOverlay != _newOverlay) {\n emit OverlayChanged(msg.sender, _newOverlay);\n }\n }\n\n /**\n * @dev Withdraw node stake surplus\n */\n function withdrawFromStake() external {\n uint256 _potentialStake = stakes[msg.sender].potentialStake;\n uint256 _surplusStake = _potentialStake -\n calculateEffectiveStake(stakes[msg.sender].committedStake, _potentialStake, stakes[msg.sender].height);\n\n if (_surplusStake > 0) {\n stakes[msg.sender].potentialStake -= _surplusStake;\n if (!ERC20(bzzToken).transfer(msg.sender, _surplusStake)) revert TransferFailed();\n emit StakeWithdrawn(msg.sender, _surplusStake);\n }\n }\n\n /**\n * @dev Migrate stake only when the staking contract is paused,\n * can only be called by the owner of the stake\n */\n function migrateStake() external whenPaused {\n // We take out all the stake so user can migrate stake to other contract\n if (lastUpdatedBlockNumberOfAddress(msg.sender) != 0) {\n if (!ERC20(bzzToken).transfer(msg.sender, stakes[msg.sender].potentialStake)) revert TransferFailed();\n delete stakes[msg.sender];\n }\n }\n\n /**\n * @dev Freeze an existing stake, can only be called by the redistributor\n * @param _owner the addres selected\n * @param _time penalty length in blocknumbers\n */\n function freezeDeposit(address _owner, uint256 _time) external {\n if (!hasRole(REDISTRIBUTOR_ROLE, msg.sender)) revert OnlyRedistributor();\n\n if (stakes[_owner].lastUpdatedBlockNumber != 0) {\n stakes[_owner].lastUpdatedBlockNumber = block.number + _time;\n emit StakeFrozen(_owner, stakes[_owner].overlay, _time);\n }\n }\n\n /**\n * @dev Slash an existing stake, can only be called by the `redistributor`\n * @param _owner the _owner adress selected\n * @param _amount the amount to be slashed\n */\n function slashDeposit(address _owner, uint256 _amount) external {\n if (!hasRole(REDISTRIBUTOR_ROLE, msg.sender)) revert OnlyRedistributor();\n\n if (stakes[_owner].lastUpdatedBlockNumber != 0) {\n if (stakes[_owner].potentialStake > _amount) {\n stakes[_owner].potentialStake -= _amount;\n stakes[_owner].lastUpdatedBlockNumber = block.number;\n } else {\n delete stakes[_owner];\n }\n }\n emit StakeSlashed(_owner, stakes[_owner].overlay, _amount);\n }\n\n function changeNetworkId(uint64 _NetworkId) external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) revert Unauthorized();\n NetworkId = _NetworkId;\n }\n\n /**\n * @dev Pause the contract. The contract is provably stopped by renouncing\n the pauser role and the admin role after pausing, can only be called by the `PAUSER`\n */\n function pause() public {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) revert OnlyPauser();\n _pause();\n }\n\n /**\n * @dev Unpause the contract, can only be called by the pauser when paused\n */\n function unPause() public {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) revert OnlyPauser();\n _unpause();\n }\n\n ////////////////////////////////////////\n // STATE READING //\n ////////////////////////////////////////\n\n /**\n * @dev Checks to see if `address` is frozen.\n * @param _owner owner of staked address\n *\n * Returns a boolean value indicating whether the operation succeeded.\n */\n function addressNotFrozen(address _owner) internal view returns (bool) {\n return stakes[_owner].lastUpdatedBlockNumber < block.number;\n }\n\n /**\n * @dev Returns the current `effectiveStake` of `address`. previously usable stake\n * @param _owner _owner of node\n */\n function nodeEffectiveStake(address _owner) public view returns (uint256) {\n return\n addressNotFrozen(_owner)\n ? calculateEffectiveStake(\n stakes[_owner].committedStake,\n stakes[_owner].potentialStake,\n stakes[_owner].height\n )\n : 0;\n }\n\n /**\n * @dev Check the amount that is possible to withdraw as surplus\n */\n function withdrawableStake() public view returns (uint256) {\n uint256 _potentialStake = stakes[msg.sender].potentialStake;\n return\n _potentialStake -\n calculateEffectiveStake(stakes[msg.sender].committedStake, _potentialStake, stakes[msg.sender].height);\n }\n\n /**\n * @dev Returns the `lastUpdatedBlockNumber` of `address`.\n */\n function lastUpdatedBlockNumberOfAddress(address _owner) public view returns (uint256) {\n return stakes[_owner].lastUpdatedBlockNumber;\n }\n\n /**\n * @dev Returns the currently used overlay of the address.\n * @param _owner address of node\n */\n function overlayOfAddress(address _owner) public view returns (bytes32) {\n return stakes[_owner].overlay;\n }\n\n /**\n * @dev Returns the currently height of the address.\n * @param _owner address of node\n */\n function heightOfAddress(address _owner) public view returns (uint8) {\n return stakes[_owner].height;\n }\n\n function calculateEffectiveStake(\n uint256 committedStake,\n uint256 potentialStakeBalance,\n uint8 height\n ) internal view returns (uint256) {\n // Calculate the product of committedStake and unitPrice to get price in BZZ\n uint256 committedStakeBzz = (2 ** height) * committedStake * OracleContract.currentPrice();\n\n // Return the minimum value between committedStakeBzz and potentialStakeBalance\n if (committedStakeBzz < potentialStakeBalance) {\n return committedStakeBzz;\n } else {\n return potentialStakeBalance;\n }\n }\n\n /**\n * @dev Please both Endians 🥚.\n * @param input Eth address used for overlay calculation.\n */\n function reverse(uint64 input) internal pure returns (uint64 v) {\n v = input;\n\n // swap bytes\n v = ((v & 0xFF00FF00FF00FF00) >> 8) | ((v & 0x00FF00FF00FF00FF) << 8);\n\n // swap 2-byte long pairs\n v = ((v & 0xFFFF0000FFFF0000) >> 16) | ((v & 0x0000FFFF0000FFFF) << 16);\n\n // swap 4-byte long pairs\n v = (v >> 32) | (v << 32);\n }\n}\n" }, "src/TestToken.sol": { "content": "// SPDX-License-Identifier: BSD-3-Clause\npragma solidity ^0.8.19;\n\nimport \"@openzeppelin/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol\";\n\ncontract TestToken is ERC20PresetMinterPauser {\n uint256 private _initialSupply;\n\n constructor(string memory name, string memory symbol, uint256 initialSupply) ERC20PresetMinterPauser(name, symbol) {\n _initialSupply = initialSupply;\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n _mint(msg.sender, initialSupply);\n }\n\n // We use 16 decimals for BZZ/sBZZ token so we need to override it here\n function decimals() public view virtual override returns (uint8) {\n return 16;\n }\n}\n" diff --git a/deployments/testnetlight/solcInputs/72863154353a753995d89fd6bb12e809.json b/deployments/testnetlight/solcInputs/41be6e483972c5595f927d43f8daf6cc.json similarity index 68% rename from deployments/testnetlight/solcInputs/72863154353a753995d89fd6bb12e809.json rename to deployments/testnetlight/solcInputs/41be6e483972c5595f927d43f8daf6cc.json index 803edd46..0e780ebe 100644 --- a/deployments/testnetlight/solcInputs/72863154353a753995d89fd6bb12e809.json +++ b/deployments/testnetlight/solcInputs/41be6e483972c5595f927d43f8daf6cc.json @@ -62,13 +62,13 @@ "content": "// SPDX-License-Identifier: BSD-3-Clause\npragma solidity ^0.8.19;\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"@openzeppelin/contracts/security/Pausable.sol\";\nimport \"./OrderStatisticsTree/HitchensOrderStatisticsTreeLib.sol\";\n\n/**\n * @title PostageStamp contract\n * @author The Swarm Authors\n * @dev The postage stamp contracts allows users to create and manage postage stamp batches.\n * The current balance for each batch is stored ordered in descending order of normalised balance.\n * Balance is normalised to be per chunk and the total spend since the contract was deployed, i.e. when a batch\n * is bought, its per-chunk balance is supplemented with the current cost of storing one chunk since the beginning of time,\n * as if the batch had existed since the contract's inception. During the _expiry_ process, each of these balances is\n * checked against the _currentTotalOutPayment_, a similarly normalised figure that represents the current cost of\n * storing one chunk since the beginning of time. A batch with a normalised balance less than _currentTotalOutPayment_\n * is treated as expired.\n *\n * The _currentTotalOutPayment_ is calculated using _totalOutPayment_ which is updated during _setPrice_ events so\n * that the applicable per-chunk prices can be charged for the relevant periods of time. This can then be multiplied\n * by the amount of chunks which are allowed to be stamped by each batch to get the actual cost of storage.\n *\n * The amount of chunks a batch can stamp is determined by the _bucketDepth_. A batch may store a maximum of 2^depth chunks.\n * The global figure for the currently allowed chunks is tracked by _validChunkCount_ and updated during batch _expiry_ events.\n */\n\ncontract PostageStamp is AccessControl, Pausable {\n using HitchensOrderStatisticsTreeLib for HitchensOrderStatisticsTreeLib.Tree;\n\n // ----------------------------- State variables ------------------------------\n\n // Address of the ERC20 token this contract references.\n address public bzzToken;\n\n // Minimum allowed depth of bucket.\n uint8 public minimumBucketDepth;\n\n // Role allowed to increase totalOutPayment.\n bytes32 public immutable PRICE_ORACLE_ROLE;\n\n // Role allowed to pause\n bytes32 public immutable PAUSER_ROLE;\n // Role allowed to withdraw the pot.\n bytes32 public immutable REDISTRIBUTOR_ROLE;\n\n // Associate every batch id with batch data.\n mapping(bytes32 => Batch) public batches;\n // Store every batch id ordered by normalisedBalance.\n HitchensOrderStatisticsTreeLib.Tree tree;\n\n // Total out payment per chunk, at the blockheight of the last price change.\n uint256 private totalOutPayment;\n\n // Combined global chunk capacity of valid batches remaining at the blockheight expire() was last called.\n uint256 public validChunkCount;\n\n // Lottery pot at last update.\n uint256 public pot;\n\n // Normalised balance at the blockheight expire() was last called.\n uint256 public lastExpiryBalance;\n\n // Price from the last update.\n uint64 public lastPrice;\n\n // blocks in 24 hours ~ 24 * 60 * 60 / 5 = 17280\n uint64 public minimumValidityBlocks = 17280;\n\n // Block at which the last update occured.\n uint64 public lastUpdatedBlock;\n\n // ----------------------------- Type declarations ------------------------------\n\n struct Batch {\n // Owner of this batch (0 if not valid).\n address owner;\n // Current depth of this batch.\n uint8 depth;\n // Bucket depth defined in this batch\n uint8 bucketDepth;\n // Whether this batch is immutable.\n bool immutableFlag;\n // Normalised balance per chunk.\n uint256 normalisedBalance;\n // When was this batch last updated\n uint256 lastUpdatedBlockNumber;\n }\n\n struct ImportBatch {\n bytes32 batchId;\n address owner;\n uint8 depth;\n uint8 bucketDepth;\n bool immutableFlag;\n uint256 remainingBalance;\n }\n\n // ----------------------------- Events ------------------------------\n\n /**\n * @dev Emitted when a new batch is created.\n */\n event BatchCreated(\n bytes32 indexed batchId,\n uint256 totalAmount,\n uint256 normalisedBalance,\n address owner,\n uint8 depth,\n uint8 bucketDepth,\n bool immutableFlag\n );\n\n /**\n * @dev Emitted when an pot is Withdrawn.\n */\n event PotWithdrawn(address recipient, uint256 totalAmount);\n\n /**\n * @dev Emitted when an existing batch is topped up.\n */\n event BatchTopUp(bytes32 indexed batchId, uint256 topupAmount, uint256 normalisedBalance);\n\n /**\n * @dev Emitted when the depth of an existing batch increases.\n */\n event BatchDepthIncrease(bytes32 indexed batchId, uint8 newDepth, uint256 normalisedBalance);\n\n /**\n *@dev Emitted on every price update.\n */\n event PriceUpdate(uint256 price);\n\n /**\n *@dev Emitted on every batch failed in bulk batch creation\n */\n event CopyBatchFailed(uint index, bytes32 batchId);\n\n // ----------------------------- Errors ------------------------------\n\n error ZeroAddress(); // Owner cannot be the zero address\n error InvalidDepth(); // Invalid bucket depth\n error BatchExists(); // Batch already exists\n error InsufficientBalance(); // Insufficient initial balance for 24h minimum validity\n error TransferFailed(); // Failed transfer of BZZ tokens\n error ZeroBalance(); // NormalisedBalance cannot be zero\n error AdministratorOnly(); // Only administrator can use copy method\n error BatchDoesNotExist(); // Batch does not exist or has expired\n error BatchExpired(); // Batch already expired\n error BatchTooSmall(); // Batch too small to renew\n error NotBatchOwner(); // Not batch owner\n error DepthNotIncreasing(); // Depth not increasing\n error PriceOracleOnly(); // Only price oracle can set the price\n error InsufficienChunkCount(); // Insufficient valid chunk count\n error TotalOutpaymentDecreased(); // Current total outpayment should never decrease\n error NoBatchesExist(); // There are no batches\n error OnlyPauser(); // Only Pauser role can pause or unpause contracts\n error OnlyRedistributor(); // Only redistributor role can withdraw from the contract\n\n // ----------------------------- CONSTRUCTOR ------------------------------\n\n /**\n * @param _bzzToken The ERC20 token address to reference in this contract.\n * @param _minimumBucketDepth The minimum bucket depth of batches that can be purchased.\n */\n constructor(address _bzzToken, uint8 _minimumBucketDepth) {\n bzzToken = _bzzToken;\n minimumBucketDepth = _minimumBucketDepth;\n PRICE_ORACLE_ROLE = keccak256(\"PRICE_ORACLE_ROLE\");\n PAUSER_ROLE = keccak256(\"PAUSER_ROLE\");\n REDISTRIBUTOR_ROLE = keccak256(\"REDISTRIBUTOR_ROLE\");\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n _setupRole(PAUSER_ROLE, msg.sender);\n }\n\n ////////////////////////////////////////\n // STATE CHANGING //\n ////////////////////////////////////////\n\n /**\n * @notice Create a new batch.\n * @dev At least `_initialBalancePerChunk*2^depth` tokens must be approved in the ERC20 token contract.\n * @param _owner Owner of the new batch.\n * @param _initialBalancePerChunk Initial balance per chunk.\n * @param _depth Initial depth of the new batch.\n * @param _nonce A random value used in the batch id derivation to allow multiple batches per owner.\n * @param _immutable Whether the batch is mutable.\n */\n function createBatch(\n address _owner,\n uint256 _initialBalancePerChunk,\n uint8 _depth,\n uint8 _bucketDepth,\n bytes32 _nonce,\n bool _immutable\n ) external whenNotPaused returns (bytes32) {\n if (_owner == address(0)) {\n revert ZeroAddress();\n }\n\n if (_bucketDepth == 0 || _bucketDepth < minimumBucketDepth || _bucketDepth >= _depth) {\n revert InvalidDepth();\n }\n\n bytes32 batchId = keccak256(abi.encode(msg.sender, _nonce));\n if (batches[batchId].owner != address(0)) {\n revert BatchExists();\n }\n\n if (_initialBalancePerChunk < minimumInitialBalancePerChunk()) {\n revert InsufficientBalance();\n }\n\n uint256 totalAmount = _initialBalancePerChunk * (1 << _depth);\n if (!ERC20(bzzToken).transferFrom(msg.sender, address(this), totalAmount)) {\n revert TransferFailed();\n }\n\n uint256 normalisedBalance = currentTotalOutPayment() + (_initialBalancePerChunk);\n if (normalisedBalance == 0) {\n revert ZeroBalance();\n }\n\n expireLimited(type(uint256).max);\n validChunkCount += 1 << _depth;\n\n batches[batchId] = Batch({\n owner: _owner,\n depth: _depth,\n bucketDepth: _bucketDepth,\n immutableFlag: _immutable,\n normalisedBalance: normalisedBalance,\n lastUpdatedBlockNumber: block.number\n });\n\n tree.insert(batchId, normalisedBalance);\n\n emit BatchCreated(batchId, totalAmount, normalisedBalance, _owner, _depth, _bucketDepth, _immutable);\n\n return batchId;\n }\n\n /**\n * @notice Manually create a new batch when facilitating migration, can only be called by the Admin role.\n * @dev At least `_initialBalancePerChunk*2^depth` tokens must be approved in the ERC20 token contract.\n * @param _owner Owner of the new batch.\n * @param _initialBalancePerChunk Initial balance per chunk of the batch.\n * @param _depth Initial depth of the new batch.\n * @param _batchId BatchId being copied (from previous version contract data).\n * @param _immutable Whether the batch is mutable.\n */\n function copyBatch(\n address _owner,\n uint256 _initialBalancePerChunk,\n uint8 _depth,\n uint8 _bucketDepth,\n bytes32 _batchId,\n bool _immutable\n ) public whenNotPaused {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert AdministratorOnly();\n }\n\n if (_owner == address(0)) {\n revert ZeroAddress();\n }\n\n if (_bucketDepth == 0 || _bucketDepth >= _depth) {\n revert InvalidDepth();\n }\n\n if (batches[_batchId].owner != address(0)) {\n revert BatchExists();\n }\n\n uint256 totalAmount = _initialBalancePerChunk * (1 << _depth);\n uint256 normalisedBalance = currentTotalOutPayment() + (_initialBalancePerChunk);\n if (normalisedBalance == 0) {\n revert ZeroBalance();\n }\n\n //update validChunkCount to remove currently expired batches\n expireLimited(type(uint256).max);\n\n validChunkCount += 1 << _depth;\n\n batches[_batchId] = Batch({\n owner: _owner,\n depth: _depth,\n bucketDepth: _bucketDepth,\n immutableFlag: _immutable,\n normalisedBalance: normalisedBalance,\n lastUpdatedBlockNumber: block.number\n });\n\n tree.insert(_batchId, normalisedBalance);\n\n emit BatchCreated(_batchId, totalAmount, normalisedBalance, _owner, _depth, _bucketDepth, _immutable);\n }\n\n /**\n * @notice Import batches in bulk\n * @dev Import batches in bulk to lower the number of transactions needed,\n * @dev becase of block limitations 90 batches per trx is ceiling, 60 to 70 sweetspot\n * @param bulkBatches array of batches\n */\n function copyBatchBulk(ImportBatch[] calldata bulkBatches) external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert AdministratorOnly();\n }\n for (uint i = 0; i < bulkBatches.length; i++) {\n ImportBatch memory _batch = bulkBatches[i];\n try\n this.copyBatch(\n _batch.owner,\n _batch.remainingBalance,\n _batch.depth,\n _batch.bucketDepth,\n _batch.batchId,\n _batch.immutableFlag\n )\n {\n // Successful copyBatch call\n } catch {\n // copyBatch failed, handle error\n emit CopyBatchFailed(i, _batch.batchId);\n }\n }\n }\n\n /**\n * @notice Top up an existing batch.\n * @dev At least `_topupAmountPerChunk*2^depth` tokens must be approved in the ERC20 token contract.\n * @param _batchId The id of an existing batch.\n * @param _topupAmountPerChunk The amount of additional tokens to add per chunk.\n */\n function topUp(bytes32 _batchId, uint256 _topupAmountPerChunk) external whenNotPaused {\n Batch memory batch = batches[_batchId];\n\n if (batch.owner == address(0)) {\n revert BatchDoesNotExist();\n }\n\n if (batch.normalisedBalance <= currentTotalOutPayment()) {\n revert BatchExpired();\n }\n\n if (batch.depth <= minimumBucketDepth) {\n revert BatchTooSmall();\n }\n\n if (remainingBalance(_batchId) + (_topupAmountPerChunk) < minimumInitialBalancePerChunk()) {\n revert InsufficientBalance();\n }\n\n // per chunk balance multiplied by the batch size in chunks must be transferred from the sender\n uint256 totalAmount = _topupAmountPerChunk * (1 << batch.depth);\n if (!ERC20(bzzToken).transferFrom(msg.sender, address(this), totalAmount)) {\n revert TransferFailed();\n }\n\n // update by removing batch and then reinserting\n tree.remove(_batchId, batch.normalisedBalance);\n batch.normalisedBalance = batch.normalisedBalance + (_topupAmountPerChunk);\n tree.insert(_batchId, batch.normalisedBalance);\n\n batches[_batchId].normalisedBalance = batch.normalisedBalance;\n emit BatchTopUp(_batchId, totalAmount, batch.normalisedBalance);\n }\n\n /**\n * @notice Increase the depth of an existing batch.\n * @dev Can only be called by the owner of the batch.\n * @param _batchId the id of an existing batch.\n * @param _newDepth the new (larger than the previous one) depth for this batch.\n */\n function increaseDepth(bytes32 _batchId, uint8 _newDepth) external whenNotPaused {\n Batch memory batch = batches[_batchId];\n\n if (batch.owner != msg.sender) {\n revert NotBatchOwner();\n }\n\n if (!(minimumBucketDepth < _newDepth && batch.depth < _newDepth)) {\n revert DepthNotIncreasing();\n }\n\n if (batch.normalisedBalance <= currentTotalOutPayment()) {\n revert BatchExpired();\n }\n\n uint8 depthChange = _newDepth - batch.depth;\n uint256 newRemainingBalance = remainingBalance(_batchId) / (1 << depthChange);\n\n if (newRemainingBalance < minimumInitialBalancePerChunk()) {\n revert InsufficientBalance();\n }\n\n expireLimited(type(uint256).max);\n validChunkCount += (1 << _newDepth) - (1 << batch.depth);\n tree.remove(_batchId, batch.normalisedBalance);\n batches[_batchId].depth = _newDepth;\n batches[_batchId].lastUpdatedBlockNumber = block.number;\n\n batch.normalisedBalance = currentTotalOutPayment() + newRemainingBalance;\n batches[_batchId].normalisedBalance = batch.normalisedBalance;\n tree.insert(_batchId, batch.normalisedBalance);\n\n emit BatchDepthIncrease(_batchId, _newDepth, batch.normalisedBalance);\n }\n\n /**\n * @notice Set a new price.\n * @dev Can only be called by the price oracle role.\n * @param _price The new price.\n */\n function setPrice(uint256 _price) external {\n if (!hasRole(PRICE_ORACLE_ROLE, msg.sender)) {\n revert PriceOracleOnly();\n }\n\n if (lastPrice != 0) {\n totalOutPayment = currentTotalOutPayment();\n }\n\n lastPrice = uint64(_price);\n lastUpdatedBlock = uint64(block.number);\n\n emit PriceUpdate(_price);\n }\n\n function setMinimumValidityBlocks(uint64 _value) external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert AdministratorOnly();\n }\n\n minimumValidityBlocks = _value;\n }\n\n /**\n * @notice Reclaims a limited number of expired batches\n * @dev Can be used if reclaiming all expired batches would exceed the block gas limit, causing other\n * contract method calls to fail.\n * @param limit The maximum number of batches to expire.\n */\n function expireLimited(uint256 limit) public {\n // the lower bound of the normalised balance for which we will check if batches have expired\n uint256 _lastExpiryBalance = lastExpiryBalance;\n uint256 i;\n for (i; i < limit; ) {\n if (isBatchesTreeEmpty()) {\n lastExpiryBalance = currentTotalOutPayment();\n break;\n }\n // get the batch with the smallest normalised balance\n bytes32 fbi = firstBatchId();\n // if the batch with the smallest balance has not yet expired\n // we have already reached the end of the batches we need\n // to expire, so exit the loop\n if (remainingBalance(fbi) > 0) {\n // the upper bound of the normalised balance for which we will check if batches have expired\n // value is updated when there are no expired batches left\n lastExpiryBalance = currentTotalOutPayment();\n break;\n }\n // otherwise, the batch with the smallest balance has expired,\n // so we must remove the chunks this batch contributes to the global validChunkCount\n Batch memory batch = batches[fbi];\n uint256 batchSize = 1 << batch.depth;\n\n if (validChunkCount < batchSize) {\n revert InsufficienChunkCount();\n }\n validChunkCount -= batchSize;\n // since the batch expired _during_ the period we must add\n // remaining normalised payout for this batch only\n pot += batchSize * (batch.normalisedBalance - _lastExpiryBalance);\n tree.remove(fbi, batch.normalisedBalance);\n delete batches[fbi];\n\n unchecked {\n ++i;\n }\n }\n // then, for all batches that have _not_ expired during the period\n // add the total normalised payout of all batches\n // multiplied by the remaining total valid chunk count\n // to the pot for the period since the last expiry\n\n if (lastExpiryBalance < _lastExpiryBalance) {\n revert TotalOutpaymentDecreased();\n }\n\n // then, for all batches that have _not_ expired during the period\n // add the total normalised payout of all batches\n // multiplied by the remaining total valid chunk count\n // to the pot for the period since the last expiry\n pot += validChunkCount * (lastExpiryBalance - _lastExpiryBalance);\n }\n\n /**\n * @notice The current pot.\n */\n function totalPot() public returns (uint256) {\n expireLimited(type(uint256).max);\n uint256 balance = ERC20(bzzToken).balanceOf(address(this));\n return pot < balance ? pot : balance;\n }\n\n /**\n * @notice Withdraw the pot, authorised callers only.\n * @param beneficiary Recieves the current total pot.\n */\n\n function withdraw(address beneficiary) external {\n if (!hasRole(REDISTRIBUTOR_ROLE, msg.sender)) {\n revert OnlyRedistributor();\n }\n\n uint256 totalAmount = totalPot();\n if (!ERC20(bzzToken).transfer(beneficiary, totalAmount)) {\n revert TransferFailed();\n }\n\n emit PotWithdrawn(beneficiary, totalAmount);\n pot = 0;\n }\n\n /**\n * @notice Pause the contract.\n * @dev Can only be called by the pauser when not paused.\n * The contract can be provably stopped by renouncing the pauser role and the admin role once paused.\n */\n function pause() public {\n if (!hasRole(PAUSER_ROLE, msg.sender)) {\n revert OnlyPauser();\n }\n _pause();\n }\n\n /**\n * @notice Unpause the contract.\n * @dev Can only be called by the pauser role while paused.\n */\n function unPause() public {\n if (!hasRole(PAUSER_ROLE, msg.sender)) {\n revert OnlyPauser();\n }\n\n _unpause();\n }\n\n ////////////////////////////////////////\n // STATE READING //\n ////////////////////////////////////////\n\n /**\n * @notice Total per-chunk cost since the contract's deployment.\n * @dev Returns the total normalised all-time per chunk payout.\n * Only Batches with a normalised balance greater than this are valid.\n */\n function currentTotalOutPayment() public view returns (uint256) {\n uint256 blocks = block.number - lastUpdatedBlock;\n uint256 increaseSinceLastUpdate = lastPrice * (blocks);\n return totalOutPayment + (increaseSinceLastUpdate);\n }\n\n function minimumInitialBalancePerChunk() public view returns (uint256) {\n return minimumValidityBlocks * lastPrice;\n }\n\n /**\n * @notice Return the per chunk balance not yet used up.\n * @param _batchId The id of an existing batch.\n */\n function remainingBalance(bytes32 _batchId) public view returns (uint256) {\n Batch memory batch = batches[_batchId];\n\n if (batch.owner == address(0)) {\n revert BatchDoesNotExist(); // Batch does not exist or expired\n }\n\n if (batch.normalisedBalance <= currentTotalOutPayment()) {\n return 0;\n }\n\n return batch.normalisedBalance - currentTotalOutPayment();\n }\n\n /**\n * @notice Indicates whether expired batches exist.\n */\n function expiredBatchesExist() public view returns (bool) {\n if (isBatchesTreeEmpty()) {\n return false;\n }\n return (remainingBalance(firstBatchId()) <= 0);\n }\n\n /**\n * @notice Return true if no batches exist\n */\n function isBatchesTreeEmpty() public view returns (bool) {\n return tree.count() == 0;\n }\n\n /**\n * @notice Get the first batch id ordered by ascending normalised balance.\n * @dev If more than one batch id, return index at 0, if no batches, revert.\n */\n function firstBatchId() public view returns (bytes32) {\n uint256 val = tree.first();\n if (val == 0) {\n revert NoBatchesExist();\n }\n return tree.valueKeyAtIndex(val, 0);\n }\n\n function batchOwner(bytes32 _batchId) public view returns (address) {\n return batches[_batchId].owner;\n }\n\n function batchDepth(bytes32 _batchId) public view returns (uint8) {\n return batches[_batchId].depth;\n }\n\n function batchBucketDepth(bytes32 _batchId) public view returns (uint8) {\n return batches[_batchId].bucketDepth;\n }\n\n function batchImmutableFlag(bytes32 _batchId) public view returns (bool) {\n return batches[_batchId].immutableFlag;\n }\n\n function batchNormalisedBalance(bytes32 _batchId) public view returns (uint256) {\n return batches[_batchId].normalisedBalance;\n }\n\n function batchLastUpdatedBlockNumber(bytes32 _batchId) public view returns (uint256) {\n return batches[_batchId].lastUpdatedBlockNumber;\n }\n}\n" }, "src/PriceOracle.sol": { - "content": "// SPDX-License-Identifier: BSD-3-Clause\npragma solidity ^0.8.19;\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"./interface/IPostageStamp.sol\";\n\n/**\n * @title PriceOracle contract.\n * @author The Swarm Authors.\n * @dev The price oracle contract emits a price feed using events.\n */\n\ncontract PriceOracle is AccessControl {\n // ----------------------------- State variables ------------------------------\n\n // The address of the linked PostageStamp contract\n IPostageStamp public postageStamp;\n\n uint16 targetRedundancy = 4;\n uint16 maxConsideredExtraRedundancy = 4;\n\n // When the contract is paused, price changes are not effective\n bool public isPaused = false;\n\n // The number of the last round price adjusting happend\n uint64 public lastAdjustedRound;\n\n // The minimum price allowed\n uint32 public minimumPriceUpscaled = 24000 << 10; // we upscale it by 2^10\n\n // The priceBase to modulate the price\n uint32 public priceBase = 524288;\n\n uint64 public currentPriceUpScaled = minimumPriceUpscaled;\n\n // Constants used to modulate the price, see below usage\n uint32[9] public changeRate = [524324, 524315, 524306, 524297, 524288, 524279, 524270, 524261, 524252];\n\n // Role allowed to update price\n bytes32 public immutable PRICE_UPDATER_ROLE;\n\n // The length of a round in blocks.\n uint8 private constant ROUND_LENGTH = 152;\n\n // ----------------------------- Events ------------------------------\n\n /**\n *@dev Emitted on every price update.\n */\n event PriceUpdate(uint256 price);\n\n // ----------------------------- Custom Errors ------------------------------\n error CallerNotAdmin(); // Caller is not the admin\n error CallerNotPriceUpdater(); // Caller is not a price updater\n error PriceAlreadyAdjusted(); // Price already adjusted in this round\n error UnexpectedZero(); // Redundancy needs to be higher then 0\n\n // ----------------------------- CONSTRUCTOR ------------------------------\n\n constructor(address _postageStamp) {\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n postageStamp = IPostageStamp(_postageStamp);\n lastAdjustedRound = currentRound();\n PRICE_UPDATER_ROLE = keccak256(\"PRICE_UPDATER_ROLE\");\n }\n\n ////////////////////////////////////////\n // STATE SETTING //\n ////////////////////////////////////////\n\n /**\n * @notice Manually set the price.\n * @dev Can only be called by the admin role.\n * @param _price The new price.\n */ function setPrice(uint32 _price) external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert CallerNotAdmin();\n }\n\n uint64 _currentPriceUpScaled = _price << 10;\n uint64 _minimumPriceUpscaled = minimumPriceUpscaled;\n\n // Enforce minimum price\n if (_currentPriceUpScaled < _minimumPriceUpscaled) {\n _currentPriceUpScaled = _minimumPriceUpscaled;\n }\n currentPriceUpScaled = _currentPriceUpScaled;\n\n // Price in postagestamp is set at 256 so we need to upcast it\n postageStamp.setPrice(uint256(currentPrice()));\n emit PriceUpdate(currentPrice());\n }\n\n function adjustPrice(uint16 redundancy) external {\n if (isPaused == false) {\n if (!hasRole(PRICE_UPDATER_ROLE, msg.sender)) {\n revert CallerNotPriceUpdater();\n }\n\n uint16 usedRedundancy = redundancy;\n uint64 currentRoundNumber = currentRound();\n\n // Price can only be adjusted once per round\n if (currentRoundNumber <= lastAdjustedRound) {\n revert PriceAlreadyAdjusted();\n }\n // Redundancy may not be zero\n if (redundancy == 0) {\n revert UnexpectedZero();\n }\n\n // Enforce maximum considered extra redundancy\n uint16 maxConsideredRedundancy = targetRedundancy + maxConsideredExtraRedundancy;\n if (redundancy > maxConsideredRedundancy) {\n usedRedundancy = maxConsideredRedundancy;\n }\n\n uint64 _currentPriceUpScaled = currentPriceUpScaled;\n uint64 _minimumPriceUpscaled = minimumPriceUpscaled;\n uint32 _priceBase = priceBase;\n\n // Set the number of rounds that were skipped\n uint64 skippedRounds = currentRoundNumber - lastAdjustedRound - 1;\n\n // We first apply the increase/decrease rate for the current round\n uint32 _changeRate = changeRate[usedRedundancy];\n _currentPriceUpScaled = (_changeRate * _currentPriceUpScaled) / _priceBase;\n\n // If previous rounds were skipped, use MAX price increase for the previous rounds\n if (skippedRounds > 0) {\n _changeRate = changeRate[0];\n for (uint64 i = 0; i < skippedRounds; i++) {\n _currentPriceUpScaled = (_changeRate * _currentPriceUpScaled) / _priceBase;\n }\n }\n\n // Enforce minimum price\n if (_currentPriceUpScaled < _minimumPriceUpscaled) {\n _currentPriceUpScaled = _minimumPriceUpscaled;\n }\n\n currentPriceUpScaled = _currentPriceUpScaled;\n lastAdjustedRound = currentRoundNumber;\n postageStamp.setPrice(uint256(currentPrice()));\n emit PriceUpdate(currentPrice());\n }\n }\n\n function pause() external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert CallerNotAdmin();\n }\n isPaused = true;\n }\n\n function unPause() external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert CallerNotAdmin();\n }\n isPaused = false;\n }\n\n ////////////////////////////////////////\n // STATE READING //\n ////////////////////////////////////////\n\n /**\n * @notice Return the number of the current round.\n */\n function currentRound() public view returns (uint64) {\n // We downcasted to uint64 as uint64 has 18,446,744,073,709,551,616 places\n // as each round is 152 x 5 = 760, each day has around 113 rounds which is 41245 in a year\n // it results 4.4724801e+14 years to run this game\n return uint64(block.number / uint256(ROUND_LENGTH));\n }\n\n /**\n * @notice Return the price downscaled\n */\n function currentPrice() public view returns (uint32) {\n // We downcasted to uint32 and bitshift it by 2^10\n return uint32((currentPriceUpScaled) >> 10);\n }\n\n /**\n * @notice Return the price downscaled\n */\n function minimumPrice() public view returns (uint32) {\n // We downcasted to uint32 and bitshift it by 2^10\n return uint32((minimumPriceUpscaled) >> 10);\n }\n}\n" + "content": "// SPDX-License-Identifier: BSD-3-Clause\npragma solidity ^0.8.19;\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"./interface/IPostageStamp.sol\";\n\n/**\n * @title PriceOracle contract.\n * @author The Swarm Authors.\n * @dev The price oracle contract emits a price feed using events.\n */\n\ncontract PriceOracle is AccessControl {\n // ----------------------------- State variables ------------------------------\n\n // The address of the linked PostageStamp contract\n IPostageStamp public postageStamp;\n\n uint16 targetRedundancy = 4;\n uint16 maxConsideredExtraRedundancy = 4;\n\n // When the contract is paused, price changes are not effective\n bool public isPaused = false;\n\n // The number of the last round price adjusting happend\n uint64 public lastAdjustedRound;\n\n // The minimum price allowed\n uint32 public minimumPriceUpscaled = 24000 << 10; // we upscale it by 2^10\n\n // The priceBase to modulate the price\n uint32 public priceBase = 1048576;\n\n uint64 public currentPriceUpScaled = minimumPriceUpscaled;\n\n // Constants used to modulate the price, see below usage\n uint32[9] public changeRate = [1049417, 1049206, 1048996, 1048786, 1048576, 1048366, 1048156, 1047946, 1047736];\n\n // Role allowed to update price\n bytes32 public immutable PRICE_UPDATER_ROLE;\n\n // The length of a round in blocks.\n uint8 private constant ROUND_LENGTH = 152;\n\n // ----------------------------- Events ------------------------------\n\n /**\n *@dev Emitted on every price update.\n */\n event PriceUpdate(uint256 price);\n\n // ----------------------------- Custom Errors ------------------------------\n error CallerNotAdmin(); // Caller is not the admin\n error CallerNotPriceUpdater(); // Caller is not a price updater\n error PriceAlreadyAdjusted(); // Price already adjusted in this round\n error UnexpectedZero(); // Redundancy needs to be higher then 0\n\n // ----------------------------- CONSTRUCTOR ------------------------------\n\n constructor(address _postageStamp) {\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n postageStamp = IPostageStamp(_postageStamp);\n lastAdjustedRound = currentRound();\n PRICE_UPDATER_ROLE = keccak256(\"PRICE_UPDATER_ROLE\");\n emit PriceUpdate(currentPrice());\n }\n\n ////////////////////////////////////////\n // STATE SETTING //\n ////////////////////////////////////////\n\n /**\n * @notice Manually set the price.\n * @dev Can only be called by the admin role.\n * @param _price The new price.\n */ function setPrice(uint32 _price) external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert CallerNotAdmin();\n }\n\n uint64 _currentPriceUpScaled = _price << 10;\n uint64 _minimumPriceUpscaled = minimumPriceUpscaled;\n\n // Enforce minimum price\n if (_currentPriceUpScaled < _minimumPriceUpscaled) {\n _currentPriceUpScaled = _minimumPriceUpscaled;\n }\n currentPriceUpScaled = _currentPriceUpScaled;\n\n // Price in postagestamp is set at 256 so we need to upcast it\n postageStamp.setPrice(uint256(currentPrice()));\n emit PriceUpdate(currentPrice());\n }\n\n function adjustPrice(uint16 redundancy) external {\n if (isPaused == false) {\n if (!hasRole(PRICE_UPDATER_ROLE, msg.sender)) {\n revert CallerNotPriceUpdater();\n }\n\n uint16 usedRedundancy = redundancy;\n uint64 currentRoundNumber = currentRound();\n\n // Price can only be adjusted once per round\n if (currentRoundNumber <= lastAdjustedRound) {\n revert PriceAlreadyAdjusted();\n }\n // Redundancy may not be zero\n if (redundancy == 0) {\n revert UnexpectedZero();\n }\n\n // Enforce maximum considered extra redundancy\n uint16 maxConsideredRedundancy = targetRedundancy + maxConsideredExtraRedundancy;\n if (redundancy > maxConsideredRedundancy) {\n usedRedundancy = maxConsideredRedundancy;\n }\n\n uint64 _currentPriceUpScaled = currentPriceUpScaled;\n uint64 _minimumPriceUpscaled = minimumPriceUpscaled;\n uint32 _priceBase = priceBase;\n\n // Set the number of rounds that were skipped\n uint64 skippedRounds = currentRoundNumber - lastAdjustedRound - 1;\n\n // We first apply the increase/decrease rate for the current round\n uint32 _changeRate = changeRate[usedRedundancy];\n _currentPriceUpScaled = (_changeRate * _currentPriceUpScaled) / _priceBase;\n\n // If previous rounds were skipped, use MAX price increase for the previous rounds\n if (skippedRounds > 0) {\n _changeRate = changeRate[0];\n for (uint64 i = 0; i < skippedRounds; i++) {\n _currentPriceUpScaled = (_changeRate * _currentPriceUpScaled) / _priceBase;\n }\n }\n\n // Enforce minimum price\n if (_currentPriceUpScaled < _minimumPriceUpscaled) {\n _currentPriceUpScaled = _minimumPriceUpscaled;\n }\n\n currentPriceUpScaled = _currentPriceUpScaled;\n lastAdjustedRound = currentRoundNumber;\n postageStamp.setPrice(uint256(currentPrice()));\n emit PriceUpdate(currentPrice());\n }\n }\n\n function pause() external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert CallerNotAdmin();\n }\n isPaused = true;\n }\n\n function unPause() external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert CallerNotAdmin();\n }\n isPaused = false;\n }\n\n ////////////////////////////////////////\n // STATE READING //\n ////////////////////////////////////////\n\n /**\n * @notice Return the number of the current round.\n */\n function currentRound() public view returns (uint64) {\n // We downcasted to uint64 as uint64 has 18,446,744,073,709,551,616 places\n // as each round is 152 x 5 = 760, each day has around 113 rounds which is 41245 in a year\n // it results 4.4724801e+14 years to run this game\n return uint64(block.number / uint256(ROUND_LENGTH));\n }\n\n /**\n * @notice Return the price downscaled\n */\n function currentPrice() public view returns (uint32) {\n // We downcasted to uint32 and bitshift it by 2^10\n return uint32((currentPriceUpScaled) >> 10);\n }\n\n /**\n * @notice Return the price downscaled\n */\n function minimumPrice() public view returns (uint32) {\n // We downcasted to uint32 and bitshift it by 2^10\n return uint32((minimumPriceUpscaled) >> 10);\n }\n}\n" }, "src/Redistribution.sol": { - "content": "// SPDX-License-Identifier: BSD-3-Clause\npragma solidity ^0.8.19;\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"@openzeppelin/contracts/security/Pausable.sol\";\nimport \"./Util/TransformedChunkProof.sol\";\nimport \"./Util/ChunkProof.sol\";\nimport \"./Util/Signatures.sol\";\nimport \"./interface/IPostageStamp.sol\";\n\ninterface IPriceOracle {\n function adjustPrice(uint16 redundancy) external;\n}\n\ninterface IStakeRegistry {\n function freezeDeposit(bytes32 overlay, uint256 time) external;\n\n function lastUpdatedBlockNumberOfOverlay(bytes32 overlay) external view returns (uint256);\n\n function ownerOfOverlay(bytes32 overlay) external view returns (address);\n\n function stakeOfOverlay(bytes32 overlay) external view returns (uint256);\n}\n\n/**\n * @title Redistribution contract\n * @author The Swarm Authors\n * @dev Implements a Schelling Co-ordination game to form consensus around the Reserve Commitment hash. This takes\n * place in three phases: _commit_, _reveal_ and _claim_.\n *\n * A node, upon establishing that it _isParticipatingInUpcomingRound_, i.e. it's overlay falls within proximity order\n * of its reported depth with the _currentRoundAnchor_, prepares a \"reserve commitment hash\" using the chunks\n * it currently stores in its reserve and calculates the \"storage depth\" (see Bee for details). These values, if calculated\n * honestly, and with the right chunks stored, should be the same for every node in a neighbourhood. This is the Schelling point.\n * Each eligible node can then use these values, together with a random, single use, secret _revealNonce_ and their\n * _overlay_ as the pre-image values for the obsfucated _commit_, using the _wrapCommit_ method.\n *\n * Once the _commit_ round has elapsed, participating nodes must provide the values used to calculate their obsfucated\n * _commit_ hash, which, once verified for correctness and proximity to the anchor are retained in the _currentReveals_.\n * Nodes that have commited but do not reveal the correct values used to create the pre-image will have their stake\n * \"frozen\" for a period of rounds proportional to their reported depth.\n *\n * During the _reveal_ round, randomness is updated after every successful reveal. Once the reveal round is concluded,\n * the _currentRoundAnchor_ is updated and users can determine if they will be eligible their overlay will be eligible\n * for the next commit phase using _isParticipatingInUpcomingRound_.\n *\n * When the _reveal_ phase has been concluded, the claim phase can begin. At this point, the truth teller and winner\n * are already determined. By calling _isWinner_, an applicant node can run the relevant logic to determine if they have\n * been selected as the beneficiary of this round. When calling _claim_, the current pot from the PostageStamp contract\n * is withdrawn and transferred to that beneficiaries address. Nodes that have revealed values that differ from the truth,\n * have their stakes \"frozen\" for a period of rounds proportional to their reported depth.\n */\n\ncontract Redistribution is AccessControl, Pausable {\n // ----------------------------- Type declarations ------------------------------\n\n // An eligible user may commit to an _obfuscatedHash_ during the commit phase...\n struct Commit {\n bytes32 overlay;\n address owner;\n bool revealed;\n uint256 stake;\n bytes32 obfuscatedHash;\n uint256 revealIndex;\n }\n // ...then provide the actual values that are the constituents of the pre-image of the _obfuscatedHash_\n // during the reveal phase.\n struct Reveal {\n bytes32 overlay;\n address owner;\n uint8 depth;\n uint256 stake;\n uint256 stakeDensity;\n bytes32 hash;\n }\n\n struct ChunkInclusionProof {\n bytes32[] proofSegments;\n bytes32 proveSegment;\n // _RCspan is known for RC 32*32\n\n // Inclusion proof of transformed address\n bytes32[] proofSegments2;\n bytes32 proveSegment2;\n // proveSegmentIndex2 known from deterministic random selection;\n uint64 chunkSpan;\n bytes32[] proofSegments3;\n // _proveSegment3 known, is equal _proveSegment2\n // proveSegmentIndex3 know, is equal _proveSegmentIndex2;\n // chunkSpan2 is equal to chunkSpan (as the data is the same)\n //\n PostageProof postageProof;\n SOCProof[] socProof;\n }\n\n struct SOCProof {\n address signer; // signer Ethereum address to check against\n bytes signature;\n bytes32 identifier; //\n bytes32 chunkAddr; // wrapped chunk address\n }\n\n struct PostageProof {\n bytes signature;\n bytes32 postageId;\n uint64 index;\n uint64 timeStamp;\n // address signer; it is provided by the postage stamp contract\n // bytes32 chunkAddr; it equals to the proveSegment argument\n }\n\n // The address of the linked PostageStamp contract.\n IPostageStamp public PostageContract;\n // The address of the linked PriceOracle contract.\n IPriceOracle public OracleContract;\n // The address of the linked Staking contract.\n IStakeRegistry public Stakes;\n\n // Commits for the current round.\n Commit[] public currentCommits;\n // Reveals for the current round.\n Reveal[] public currentReveals;\n\n // The current anchor that being processed for the reveal and claim phases of the round.\n bytes32 private currentRevealRoundAnchor;\n\n // The current random value from which we will random.\n // inputs for selection of the truth teller and beneficiary.\n bytes32 private seed;\n\n // The number of the currently active round phases.\n uint64 public currentCommitRound;\n uint64 public currentRevealRound;\n uint64 public currentClaimRound;\n\n // Settings for slashing and freezing\n uint8 private penaltyMultiplierDisagreement = 1;\n uint8 private penaltyMultiplierNonRevealed = 2;\n uint8 private penaltyRandomFactor = 20;\n\n // alpha=0.097612 beta=0.0716570 k=16\n uint256 private sampleMaxValue = 1284401000000000000000000000000000000000000000000000000000000000000000000;\n\n // The reveal of the winner of the last round.\n Reveal public winner;\n\n // The length of a round in blocks.\n uint256 private constant ROUND_LENGTH = 152;\n\n // The miniumum stake allowed to be staked using the Staking contract.\n uint64 private constant MIN_STAKE = 100000000000000000;\n\n // Maximum value of the keccack256 hash.\n bytes32 private constant MAX_H = 0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff;\n\n // Role allowed to pause.\n bytes32 private immutable PAUSER_ROLE;\n\n // ----------------------------- Events ------------------------------\n\n /**\n * @dev Emitted when the winner of a round is selected in the claim phase\n */\n event WinnerSelected(Reveal winner);\n\n /**\n * @dev Emitted when the truth oracle of a round is selected in the claim phase.\n */\n event TruthSelected(bytes32 hash, uint8 depth);\n\n // Next two events to be removed after testing phase pending some other usefulness being found.\n /**\n * @dev Emits the number of commits being processed by the claim phase.\n */\n event CountCommits(uint256 _count);\n\n /**\n * @dev Emits the number of reveals being processed by the claim phase.\n */\n event CountReveals(uint256 _count);\n\n /**\n * @dev Logs that an overlay has committed\n */\n event Committed(uint256 roundNumber, bytes32 overlay);\n /**\n * @dev Emit from Postagestamp contract valid chunk count at the end of claim\n */\n event ChunkCount(uint256 validChunkCount);\n\n /**\n * @dev Bytes32 anhor of current reveal round\n */\n event CurrentRevealAnchor(uint256 roundNumber, bytes32 anchor);\n\n /**\n * @dev Logs that an overlay has revealed\n */\n event Revealed(\n uint256 roundNumber,\n bytes32 overlay,\n uint256 stake,\n uint256 stakeDensity,\n bytes32 reserveCommitment,\n uint8 depth\n );\n\n /**\n * @dev Logs for inclusion proof\n */\n event transformedChunkAddressFromInclusionProof(uint256 indexInRC, bytes32 chunkAddress);\n\n // ----------------------------- Errors ------------------------------\n\n error NotCommitPhase(); // Game is not in commit phase\n error NoCommitsReceived(); // Round didn't receive any commits\n error PhaseLastBlock(); // We don't permit commits in last block of the phase\n error BelowMinimumStake(); // Node participating in game has stake below minimum treshold\n error CommitRoundOver(); // Commit phase in this round is over\n error CommitRoundNotStarted(); // Commit phase in this round has not started yet\n error NotMatchingOwner(); // Sender of commit is not matching the overlay address\n error MustStake2Rounds(); // Before entering the game node must stake 2 rounds prior\n error WrongPhase(); // Checking in wrong phase, need to check duing claim phase of current round for next round or commit in current round\n error AlreadyCommited(); // Node already commited in this round\n error NotRevealPhase(); // Game is not in reveal phase\n error OutOfDepthReveal(bytes32); // Anchor is out of reported depth in Reveal phase, anchor data available as argument\n error OutOfDepthClaim(uint8); // Anchor is out of reported depth in Claim phase, entryProof index is argument\n error OutOfDepth(); // Anchor is out of reported depth\n error AlreadyRevealed(); // Node already revealed\n error NoMatchingCommit(); // No matching commit and hash\n error NotClaimPhase(); // Game is not in the claim phase\n error NoReveals(); // Round did not receive any reveals\n error FirstRevealDone(); // We don't want to return value after first reveal\n error AlreadyClaimed(); // This round was already claimed\n error NotAdmin(); // Caller of trx is not admin\n error OnlyPauser(); // Only account with pauser role can call pause/unpause\n error SocVerificationFailed(bytes32); // Soc verification failed for this element\n error SocCalcNotMatching(bytes32); // Soc address calculation does not match with the witness\n error IndexOutsideSet(bytes32); // Stamp available: index resides outside of the valid index set\n error SigRecoveryFailed(bytes32); // Stamp authorized: signature recovery failed for element\n error BatchDoesNotExist(bytes32); // Stamp alive: batch remaining balance validation failed for attached stamp\n error BucketDiffers(bytes32); // Stamp aligned: postage bucket differs from address bucket\n error InclusionProofFailed(uint8, bytes32);\n // 1 = RC inclusion proof failed for element\n // 2 = First sister segment in data must match,\n // 3 = Inclusion proof failed for original address of element\n // 4 = Inclusion proof failed for transformed address of element\n error RandomElementCheckFailed(); // Random element order check failed\n error LastElementCheckFailed(); // Last element order check failed\n error ReserveCheckFailed(bytes32 trALast); // Reserve size estimation check failed\n\n // ----------------------------- CONSTRUCTOR ------------------------------\n\n /**\n * @param staking the address of the linked Staking contract.\n * @param postageContract the address of the linked PostageStamp contract.\n * @param oracleContract the address of the linked PriceOracle contract.\n */\n constructor(address staking, address postageContract, address oracleContract) {\n Stakes = IStakeRegistry(staking);\n PostageContract = IPostageStamp(postageContract);\n OracleContract = IPriceOracle(oracleContract);\n PAUSER_ROLE = keccak256(\"PAUSER_ROLE\");\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n _setupRole(PAUSER_ROLE, msg.sender);\n }\n\n ////////////////////////////////////////\n // STATE CHANGING //\n ////////////////////////////////////////\n\n /**\n * @notice Begin application for a round if eligible. Commit a hashed value for which the pre-image will be\n * subsequently revealed.\n * @dev If a node's overlay is _inProximity_(_depth_) of the _currentRoundAnchor_, that node may compute an\n * _obfuscatedHash_ by providing their _overlay_, reported storage _depth_, reserve commitment _hash_ and a\n * randomly generated, and secret _revealNonce_ to the _wrapCommit_ method.\n * @param _obfuscatedHash The calculated hash resultant of the required pre-image values.\n * @param _overlay The overlay referenced in the pre-image. Must be staked by at least the minimum value,\n * and be derived from the same key pair as the message sender.\n */\n function commit(bytes32 _obfuscatedHash, bytes32 _overlay, uint64 _roundNumber) external whenNotPaused {\n uint64 cr = currentRound();\n uint256 nstake = Stakes.stakeOfOverlay(_overlay);\n\n if (!currentPhaseCommit()) {\n revert NotCommitPhase();\n }\n if (block.number % ROUND_LENGTH == (ROUND_LENGTH / 4) - 1) {\n revert PhaseLastBlock();\n }\n\n if (cr > _roundNumber) {\n revert CommitRoundOver();\n }\n\n if (cr < _roundNumber) {\n revert CommitRoundNotStarted();\n }\n\n if (nstake < MIN_STAKE) {\n revert BelowMinimumStake();\n }\n\n if (Stakes.ownerOfOverlay(_overlay) != msg.sender) {\n revert NotMatchingOwner();\n }\n\n if (Stakes.lastUpdatedBlockNumberOfOverlay(_overlay) >= block.number - 2 * ROUND_LENGTH) {\n revert MustStake2Rounds();\n }\n\n // if we are in a new commit phase, reset the array of commits and\n // set the currentCommitRound to be the current one\n if (cr != currentCommitRound) {\n delete currentCommits;\n currentCommitRound = cr;\n }\n\n uint256 commitsArrayLength = currentCommits.length;\n\n for (uint256 i = 0; i < commitsArrayLength; ) {\n if (currentCommits[i].overlay == _overlay) {\n revert AlreadyCommited();\n }\n\n unchecked {\n ++i;\n }\n }\n\n currentCommits.push(\n Commit({\n overlay: _overlay,\n owner: msg.sender,\n revealed: false,\n stake: nstake,\n obfuscatedHash: _obfuscatedHash,\n revealIndex: 0\n })\n );\n\n emit Committed(_roundNumber, _overlay);\n }\n\n /**\n * @notice Reveal the pre-image values used to generate commit provided during this round's commit phase.\n * @param _overlay The overlay address of the applicant.\n * @param _depth The reported depth.\n * @param _hash The reserve commitment hash.\n * @param _revealNonce The nonce used to generate the commit that is being revealed.\n */\n function reveal(bytes32 _overlay, uint8 _depth, bytes32 _hash, bytes32 _revealNonce) external whenNotPaused {\n uint64 cr = currentRound();\n\n if (_depth < currentMinimumDepth()) {\n revert OutOfDepth();\n }\n\n if (!currentPhaseReveal()) {\n revert NotRevealPhase();\n }\n\n if (cr != currentCommitRound) {\n revert NoCommitsReceived();\n }\n\n if (cr != currentRevealRound) {\n currentRevealRoundAnchor = currentRoundAnchor();\n delete currentReveals;\n // We set currentRevealRound ONLY after we set current anchor\n currentRevealRound = cr;\n emit CurrentRevealAnchor(cr, currentRevealRoundAnchor);\n updateRandomness();\n }\n\n bytes32 obfuscatedHash = wrapCommit(_overlay, _depth, _hash, _revealNonce);\n uint256 id = findCommit(_overlay, obfuscatedHash);\n Commit memory revealedCommit = currentCommits[id];\n\n // Check that commit is in proximity of the current anchor\n if (!inProximity(revealedCommit.overlay, currentRevealRoundAnchor, _depth)) {\n revert OutOfDepthReveal(currentRevealRoundAnchor);\n }\n // Check that the commit has not already been revealed\n if (revealedCommit.revealed) {\n revert AlreadyRevealed();\n }\n\n currentCommits[id].revealed = true;\n currentCommits[id].revealIndex = currentReveals.length;\n\n currentReveals.push(\n Reveal({\n overlay: revealedCommit.overlay,\n owner: revealedCommit.owner,\n depth: _depth,\n stake: revealedCommit.stake,\n stakeDensity: revealedCommit.stake * uint256(2 ** _depth),\n hash: _hash\n })\n );\n\n emit Revealed(\n cr,\n revealedCommit.overlay,\n revealedCommit.stake,\n revealedCommit.stake * uint256(2 ** _depth),\n _hash,\n _depth\n );\n }\n\n /**\n * @notice Helper function to get this round truth\n * @dev\n */\n function claim(\n ChunkInclusionProof calldata entryProof1,\n ChunkInclusionProof calldata entryProof2,\n ChunkInclusionProof calldata entryProofLast\n ) external whenNotPaused {\n winnerSelection();\n\n Reveal memory winnerSelected = winner;\n uint256 indexInRC1;\n uint256 indexInRC2;\n bytes32 _currentRevealRoundAnchor = currentRevealRoundAnchor;\n bytes32 _seed = seed;\n\n // rand(14)\n indexInRC1 = uint256(_seed) % 15;\n // rand(13)\n indexInRC2 = uint256(_seed) % 14;\n if (indexInRC2 >= indexInRC1) {\n indexInRC2++;\n }\n\n if (!inProximity(entryProofLast.proveSegment, _currentRevealRoundAnchor, winnerSelected.depth)) {\n revert OutOfDepthClaim(3);\n }\n\n inclusionFunction(entryProofLast, 30);\n stampFunction(entryProofLast);\n socFunction(entryProofLast);\n\n if (!inProximity(entryProof1.proveSegment, _currentRevealRoundAnchor, winnerSelected.depth)) {\n revert OutOfDepthClaim(2);\n }\n\n inclusionFunction(entryProof1, indexInRC1 * 2);\n stampFunction(entryProof1);\n socFunction(entryProof1);\n\n if (!inProximity(entryProof2.proveSegment, _currentRevealRoundAnchor, winnerSelected.depth)) {\n revert OutOfDepthClaim(1);\n }\n\n inclusionFunction(entryProof2, indexInRC2 * 2);\n stampFunction(entryProof2);\n socFunction(entryProof2);\n\n checkOrder(\n indexInRC1,\n indexInRC2,\n entryProof1.proofSegments[0],\n entryProof2.proofSegments[0],\n entryProofLast.proofSegments[0]\n );\n\n estimateSize(entryProofLast.proofSegments[0]);\n\n PostageContract.withdraw(winnerSelected.owner);\n emit WinnerSelected(winnerSelected);\n emit ChunkCount(PostageContract.validChunkCount());\n }\n\n function winnerSelection() internal {\n uint64 cr = currentRound();\n\n if (!currentPhaseClaim()) {\n revert NotClaimPhase();\n }\n\n if (cr != currentRevealRound) {\n revert NoReveals();\n }\n\n if (cr <= currentClaimRound) {\n revert AlreadyClaimed();\n }\n\n uint256 currentWinnerSelectionSum = 0;\n uint256 redundancyCount = 0;\n bytes32 randomNumber;\n uint256 randomNumberTrunc;\n\n bytes32 truthRevealedHash;\n uint8 truthRevealedDepth;\n uint256 currentCommitsLength = currentCommits.length;\n\n emit CountCommits(currentCommitsLength);\n emit CountReveals(currentReveals.length);\n\n (truthRevealedHash, truthRevealedDepth) = getCurrentTruth();\n emit TruthSelected(truthRevealedHash, truthRevealedDepth);\n string memory winnerSelectionAnchor = currentWinnerSelectionAnchor();\n\n for (uint256 i = 0; i < currentCommitsLength; ) {\n Commit memory currentCommit = currentCommits[i];\n uint256 revIndex = currentCommit.revealIndex;\n Reveal memory currentReveal = currentReveals[revIndex];\n\n // Select winner with valid truth\n if (\n currentCommit.revealed &&\n truthRevealedHash == currentReveal.hash &&\n truthRevealedDepth == currentReveal.depth\n ) {\n currentWinnerSelectionSum += currentReveal.stakeDensity;\n randomNumber = keccak256(abi.encodePacked(winnerSelectionAnchor, redundancyCount));\n randomNumberTrunc = uint256(randomNumber & MAX_H);\n\n if (randomNumberTrunc * currentWinnerSelectionSum < currentReveal.stakeDensity * (uint256(MAX_H) + 1)) {\n winner = currentReveal;\n }\n\n redundancyCount++;\n }\n\n // Freeze deposit if any truth is false, make it a penaltyRandomFactor chance for this to happen\n if (\n currentCommit.revealed &&\n (truthRevealedHash != currentReveal.hash || truthRevealedDepth != currentReveal.depth) &&\n (block.prevrandao % 100 < penaltyRandomFactor)\n ) {\n Stakes.freezeDeposit(\n currentReveal.overlay,\n penaltyMultiplierDisagreement * ROUND_LENGTH * uint256(2 ** truthRevealedDepth)\n );\n }\n\n // Slash deposits if revealed is false\n if (!currentCommit.revealed) {\n // slash in later phase (ph5)\n // Stakes.slashDeposit(currentCommits[i].overlay, currentCommits[i].stake);\n Stakes.freezeDeposit(\n currentCommit.overlay,\n penaltyMultiplierNonRevealed * ROUND_LENGTH * uint256(2 ** truthRevealedDepth)\n );\n }\n unchecked {\n ++i;\n }\n }\n\n OracleContract.adjustPrice(uint16(redundancyCount));\n currentClaimRound = cr;\n }\n\n function inclusionFunction(ChunkInclusionProof calldata entryProof, uint256 indexInRC) internal {\n uint256 randomChunkSegmentIndex = uint256(seed) % 128;\n bytes32 calculatedTransformedAddr = TransformedBMTChunk.transformedChunkAddressFromInclusionProof(\n entryProof.proofSegments3,\n entryProof.proveSegment2,\n randomChunkSegmentIndex,\n entryProof.chunkSpan,\n currentRevealRoundAnchor\n );\n\n emit transformedChunkAddressFromInclusionProof(indexInRC, calculatedTransformedAddr);\n\n if (\n winner.hash !=\n BMTChunk.chunkAddressFromInclusionProof(\n entryProof.proofSegments,\n entryProof.proveSegment,\n indexInRC,\n 32 * 32\n )\n ) {\n revert InclusionProofFailed(1, calculatedTransformedAddr);\n }\n\n if (entryProof.proofSegments2[0] != entryProof.proofSegments3[0]) {\n revert InclusionProofFailed(2, calculatedTransformedAddr);\n }\n\n bytes32 originalAddress = entryProof.socProof.length > 0\n ? entryProof.socProof[0].chunkAddr // soc attestation in socFunction\n : entryProof.proveSegment;\n\n if (\n originalAddress !=\n BMTChunk.chunkAddressFromInclusionProof(\n entryProof.proofSegments2,\n entryProof.proveSegment2,\n randomChunkSegmentIndex,\n entryProof.chunkSpan\n )\n ) {\n revert InclusionProofFailed(3, calculatedTransformedAddr);\n }\n\n // In case of SOC, the transformed address is hashed together with its address in the sample\n if (entryProof.socProof.length > 0) {\n calculatedTransformedAddr = keccak256(\n abi.encode(\n entryProof.proveSegment, // SOC address\n calculatedTransformedAddr\n )\n );\n }\n\n if (entryProof.proofSegments[0] != calculatedTransformedAddr) {\n revert InclusionProofFailed(4, calculatedTransformedAddr);\n }\n }\n\n /**\n * @notice Set freezing parameters\n */\n function setFreezingParams(\n uint8 _penaltyMultiplierDisagreement,\n uint8 _penaltyMultiplierNonRevealed,\n uint8 _penaltyRandomFactor\n ) external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert NotAdmin();\n }\n\n penaltyMultiplierDisagreement = _penaltyMultiplierDisagreement;\n penaltyMultiplierNonRevealed = _penaltyMultiplierNonRevealed;\n // Use 100 as value to ignore random factor in freezing penalty\n penaltyRandomFactor = _penaltyRandomFactor;\n }\n\n /**\n * @notice changes the max sample value used for reserve estimation\n */\n function setSampleMaxValue(uint256 _sampleMaxValue) external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert NotAdmin();\n }\n\n sampleMaxValue = _sampleMaxValue;\n }\n\n /**\n * @notice Updates the source of randomness. Uses block.difficulty in pre-merge chains, this is substituted\n * to block.prevrandao in post merge chains.\n */\n function updateRandomness() private {\n seed = keccak256(abi.encode(seed, block.prevrandao));\n }\n\n /**\n * @dev Pause the contract. The contract is provably stopped by renouncing\n the pauser role and the admin role after pausing, can only be called by the `PAUSER`\n */\n function pause() public {\n if (!hasRole(PAUSER_ROLE, msg.sender)) {\n revert OnlyPauser();\n }\n\n _pause();\n }\n\n /**\n * @dev Unpause the contract, can only be called by the pauser when paused\n */\n function unPause() public {\n if (!hasRole(PAUSER_ROLE, msg.sender)) {\n revert OnlyPauser();\n }\n _unpause();\n }\n\n ////////////////////////////////////////\n // STATE READING //\n ////////////////////////////////////////\n\n // ----------------------------- Anchor calculations ------------------------------\n\n /**\n * @notice Returns the current random seed which is used to determine later utilised random numbers.\n * If rounds have elapsed without reveals, hash the seed with an incremented nonce to produce a new\n * random seed and hence a new round anchor.\n */\n function currentSeed() public view returns (bytes32) {\n uint64 cr = currentRound();\n bytes32 currentSeedValue = seed;\n\n if (cr > currentRevealRound + 1) {\n uint256 difference = cr - currentRevealRound - 1;\n currentSeedValue = keccak256(abi.encodePacked(currentSeedValue, difference));\n }\n\n return currentSeedValue;\n }\n\n /**\n * @notice Returns the seed which will become current once the next commit phase begins.\n * Used to determine what the next round's anchor will be.\n */\n function nextSeed() public view returns (bytes32) {\n uint64 cr = currentRound() + 1;\n bytes32 currentSeedValue = seed;\n\n if (cr > currentRevealRound + 1) {\n uint256 difference = cr - currentRevealRound - 1;\n currentSeedValue = keccak256(abi.encodePacked(currentSeedValue, difference));\n }\n\n return currentSeedValue;\n }\n\n /**\n * @notice The random value used to choose the selected truth teller.\n */\n function currentTruthSelectionAnchor() private view returns (string memory) {\n if (!currentPhaseClaim()) {\n revert NotClaimPhase();\n }\n\n uint64 cr = currentRound();\n if (cr != currentRevealRound) {\n revert NoReveals();\n }\n\n return string(abi.encodePacked(seed, \"0\"));\n }\n\n /**\n * @notice The random value used to choose the selected beneficiary.\n */\n function currentWinnerSelectionAnchor() private view returns (string memory) {\n if (!currentPhaseClaim()) {\n revert NotClaimPhase();\n }\n uint64 cr = currentRound();\n if (cr != currentRevealRound) {\n revert NoReveals();\n }\n\n return string(abi.encodePacked(seed, \"1\"));\n }\n\n /**\n * @notice The anchor used to determine eligibility for the current round.\n * @dev A node must be within proximity order of less than or equal to the storage depth they intend to report.\n */\n function currentRoundAnchor() public view returns (bytes32 returnVal) {\n // This will be called in reveal phase and set as currentRevealRoundAnchor or in\n // commit phase when checking eligibility for next round by isParticipatingInUpcomingRound\n if (currentPhaseCommit() || (currentRound() > currentRevealRound && !currentPhaseClaim())) {\n return currentSeed();\n }\n\n // This will be called by isParticipatingInUpcomingRound check in claim phase\n if (currentPhaseClaim()) {\n return nextSeed();\n }\n\n // Without this, this function will output 0x0 after first reveal which is value and we prefere it reverts\n if (currentPhaseReveal() && currentRound() == currentRevealRound) {\n revert FirstRevealDone();\n }\n }\n\n /**\n * @notice Returns true if an overlay address _A_ is within proximity order _minimum_ of _B_.\n * @param A An overlay address to compare.\n * @param B An overlay address to compare.\n * @param minimum Minimum proximity order.\n */\n function inProximity(bytes32 A, bytes32 B, uint8 minimum) public pure returns (bool) {\n if (minimum == 0) {\n return true;\n }\n return uint256(A ^ B) < uint256(2 ** (256 - minimum));\n }\n\n // ----------------------------- Commit ------------------------------\n\n /**\n * @notice The number of the current round.\n */\n function currentRound() public view returns (uint64) {\n return uint64(block.number / ROUND_LENGTH);\n }\n\n /**\n * @notice Returns true if current block is during commit phase.\n */\n function currentPhaseCommit() public view returns (bool) {\n if (block.number % ROUND_LENGTH < ROUND_LENGTH / 4) {\n return true;\n }\n return false;\n }\n\n /**\n * @notice Determine if a the owner of a given overlay can participate in the upcoming round.\n * @param overlay The overlay address of the applicant.\n * @param depth The storage depth the applicant intends to report.\n */\n function isParticipatingInUpcomingRound(bytes32 overlay, uint8 depth) public view returns (bool) {\n if (currentPhaseReveal()) {\n revert WrongPhase();\n }\n\n if (Stakes.lastUpdatedBlockNumberOfOverlay(overlay) >= block.number - 2 * ROUND_LENGTH) {\n revert MustStake2Rounds();\n }\n\n if (Stakes.stakeOfOverlay(overlay) < MIN_STAKE) {\n revert BelowMinimumStake();\n }\n\n return inProximity(overlay, currentRoundAnchor(), depth);\n }\n\n // ----------------------------- Reveal ------------------------------\n\n /**\n * @notice Returns minimum depth reveal has to have to participate in this round\n */\n function currentMinimumDepth() public view returns (uint8) {\n // We are checking value in reveal phase, as the currentCommitRound is set to the current round\n // but the currentClaimRound is still set to the last time claim was made\n // We add 1 to ensure that for the next round the minimum depth is the same as last winner depth\n\n uint256 difference = currentCommitRound - currentClaimRound;\n uint8 skippedRounds = uint8(difference > 254 ? 254 : difference) + 1;\n\n uint8 lastWinnerDepth = winner.depth;\n\n // We ensure that skippedRounds is not bigger than lastWinnerDepth, because of overflow\n return skippedRounds >= lastWinnerDepth ? 0 : lastWinnerDepth - skippedRounds;\n }\n\n /**\n * @notice Helper function to get this node reveal in commits\n * @dev\n */\n function findCommit(bytes32 _overlay, bytes32 _obfuscatedHash) internal view returns (uint256) {\n for (uint256 i = 0; i < currentCommits.length; ) {\n if (currentCommits[i].overlay == _overlay && _obfuscatedHash == currentCommits[i].obfuscatedHash) {\n return i;\n }\n unchecked {\n ++i;\n }\n }\n revert NoMatchingCommit();\n }\n\n /**\n * @notice Hash the pre-image values to the obsfucated hash.\n * @dev _revealNonce_ must be randomly generated, used once and kept secret until the reveal phase.\n * @param _overlay The overlay address of the applicant.\n * @param _depth The reported depth.\n * @param _hash The reserve commitment hash.\n * @param revealNonce A random, single use, secret nonce.\n */\n function wrapCommit(\n bytes32 _overlay,\n uint8 _depth,\n bytes32 _hash,\n bytes32 revealNonce\n ) public pure returns (bytes32) {\n return keccak256(abi.encodePacked(_overlay, _depth, _hash, revealNonce));\n }\n\n /**\n * @notice Returns true if current block is during reveal phase.\n */\n function currentPhaseReveal() public view returns (bool) {\n uint256 number = block.number % ROUND_LENGTH;\n if (number >= ROUND_LENGTH / 4 && number < ROUND_LENGTH / 2) {\n return true;\n }\n return false;\n }\n\n /**\n * @notice Returns true if current block is during reveal phase.\n */\n function currentRoundReveals() public view returns (Reveal[] memory) {\n if (!currentPhaseClaim()) {\n revert NotClaimPhase();\n }\n uint64 cr = currentRound();\n if (cr != currentRevealRound) {\n revert NoReveals();\n }\n\n return currentReveals;\n }\n\n // ----------------------------- Claim ------------------------------\n\n /**\n * @notice Returns true if current block is during claim phase.\n */\n function currentPhaseClaim() public view returns (bool) {\n if (block.number % ROUND_LENGTH >= ROUND_LENGTH / 2) {\n return true;\n }\n return false;\n }\n\n function getCurrentTruth() internal view returns (bytes32 Hash, uint8 Depth) {\n uint256 currentSum;\n bytes32 randomNumber;\n uint256 randomNumberTrunc;\n\n bytes32 truthRevealedHash;\n uint8 truthRevealedDepth;\n uint256 revIndex;\n string memory truthSelectionAnchor = currentTruthSelectionAnchor();\n uint256 commitsArrayLength = currentCommits.length;\n\n for (uint256 i = 0; i < commitsArrayLength; ) {\n if (currentCommits[i].revealed) {\n revIndex = currentCommits[i].revealIndex;\n currentSum += currentReveals[revIndex].stakeDensity;\n randomNumber = keccak256(abi.encodePacked(truthSelectionAnchor, i));\n randomNumberTrunc = uint256(randomNumber & MAX_H);\n\n // question is whether randomNumber / MAX_H < probability\n // where probability is stakeDensity / currentSum\n // to avoid resorting to floating points all divisions should be\n // simplified with multiplying both sides (as long as divisor > 0)\n // randomNumber / (MAX_H + 1) < stakeDensity / currentSum\n // ( randomNumber / (MAX_H + 1) ) * currentSum < stakeDensity\n // randomNumber * currentSum < stakeDensity * (MAX_H + 1)\n if (randomNumberTrunc * currentSum < currentReveals[revIndex].stakeDensity * (uint256(MAX_H) + 1)) {\n truthRevealedHash = currentReveals[revIndex].hash;\n truthRevealedDepth = currentReveals[revIndex].depth;\n }\n }\n unchecked {\n ++i;\n }\n }\n\n return (truthRevealedHash, truthRevealedDepth);\n }\n\n /**\n * @notice Determine if a the owner of a given overlay will be the beneficiary of the claim phase.\n * @param _overlay The overlay address of the applicant.\n */\n function isWinner(bytes32 _overlay) public view returns (bool) {\n if (!currentPhaseClaim()) {\n revert NotClaimPhase();\n }\n\n uint64 cr = currentRound();\n if (cr != currentRevealRound) {\n revert NoReveals();\n }\n\n if (cr <= currentClaimRound) {\n revert AlreadyClaimed();\n }\n\n uint256 currentWinnerSelectionSum;\n bytes32 winnerIs;\n bytes32 randomNumber;\n uint256 randomNumberTrunc;\n bytes32 truthRevealedHash;\n uint8 truthRevealedDepth;\n uint256 revIndex;\n string memory winnerSelectionAnchor = currentWinnerSelectionAnchor();\n uint256 redundancyCount = 0;\n\n // Get current truth\n (truthRevealedHash, truthRevealedDepth) = getCurrentTruth();\n uint256 commitsArrayLength = currentCommits.length;\n\n for (uint256 i = 0; i < commitsArrayLength; ) {\n revIndex = currentCommits[i].revealIndex;\n\n // Deterministically read winner\n if (\n currentCommits[i].revealed &&\n truthRevealedHash == currentReveals[revIndex].hash &&\n truthRevealedDepth == currentReveals[revIndex].depth\n ) {\n currentWinnerSelectionSum += currentReveals[revIndex].stakeDensity;\n randomNumber = keccak256(abi.encodePacked(winnerSelectionAnchor, redundancyCount));\n randomNumberTrunc = uint256(randomNumber & MAX_H);\n\n if (\n randomNumberTrunc * currentWinnerSelectionSum <\n currentReveals[revIndex].stakeDensity * (uint256(MAX_H) + 1)\n ) {\n winnerIs = currentReveals[revIndex].overlay;\n }\n\n redundancyCount++;\n }\n unchecked {\n ++i;\n }\n }\n\n return (winnerIs == _overlay);\n }\n\n // ----------------------------- Claim verifications ------------------------------\n\n function socFunction(ChunkInclusionProof calldata entryProof) internal pure {\n if (entryProof.socProof.length == 0) return;\n\n if (\n !Signatures.socVerify(\n entryProof.socProof[0].signer, // signer Ethereum address to check against\n entryProof.socProof[0].signature,\n entryProof.socProof[0].identifier,\n entryProof.socProof[0].chunkAddr\n )\n ) {\n revert SocVerificationFailed(entryProof.socProof[0].chunkAddr);\n }\n\n if (\n calculateSocAddress(entryProof.socProof[0].identifier, entryProof.socProof[0].signer) !=\n entryProof.proveSegment\n ) {\n revert SocCalcNotMatching(entryProof.socProof[0].chunkAddr);\n }\n }\n\n function stampFunction(ChunkInclusionProof calldata entryProof) internal view {\n // authentic\n (address batchOwner, uint8 batchDepth, uint8 bucketDepth, , , ) = PostageContract.batches(\n entryProof.postageProof.postageId\n );\n\n // alive\n if (batchOwner == address(0)) {\n revert BatchDoesNotExist(entryProof.postageProof.postageId); // Batch does not exist or expired\n }\n\n uint32 postageIndex = getPostageIndex(entryProof.postageProof.index);\n uint256 maxPostageIndex = postageStampIndexCount(batchDepth, bucketDepth);\n // available\n if (postageIndex >= maxPostageIndex) {\n revert IndexOutsideSet(entryProof.postageProof.postageId);\n }\n\n // aligned\n uint64 postageBucket = getPostageBucket(entryProof.postageProof.index);\n uint64 addressBucket = addressToBucket(entryProof.proveSegment, bucketDepth);\n if (postageBucket != addressBucket) {\n revert BucketDiffers(entryProof.postageProof.postageId);\n }\n\n // authorized\n if (\n !Signatures.postageVerify(\n batchOwner,\n entryProof.postageProof.signature,\n entryProof.proveSegment,\n entryProof.postageProof.postageId,\n entryProof.postageProof.index,\n entryProof.postageProof.timeStamp\n )\n ) {\n revert SigRecoveryFailed(entryProof.postageProof.postageId);\n }\n }\n\n function addressToBucket(bytes32 swarmAddress, uint8 bucketDepth) internal pure returns (uint32) {\n uint32 prefix = uint32(uint256(swarmAddress) >> (256 - 32));\n return prefix >> (32 - bucketDepth);\n }\n\n function postageStampIndexCount(uint8 postageDepth, uint8 bucketDepth) internal pure returns (uint256) {\n return 1 << (postageDepth - bucketDepth);\n }\n\n function getPostageIndex(uint64 signedIndex) internal pure returns (uint32) {\n return uint32(signedIndex);\n }\n\n function getPostageBucket(uint64 signedIndex) internal pure returns (uint64) {\n return uint32(signedIndex >> 32);\n }\n\n function calculateSocAddress(bytes32 identifier, address signer) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(identifier, signer));\n }\n\n function checkOrder(uint256 a, uint256 b, bytes32 trA1, bytes32 trA2, bytes32 trALast) internal pure {\n if (a < b) {\n if (uint256(trA1) >= uint256(trA2)) {\n revert RandomElementCheckFailed();\n }\n if (uint256(trA2) >= uint256(trALast)) {\n revert LastElementCheckFailed();\n }\n } else {\n if (uint256(trA2) >= uint256(trA1)) {\n revert RandomElementCheckFailed();\n }\n if (uint256(trA1) >= uint256(trALast)) {\n revert LastElementCheckFailed();\n }\n }\n }\n\n function estimateSize(bytes32 trALast) internal view {\n if (uint256(trALast) >= sampleMaxValue) {\n revert ReserveCheckFailed(trALast);\n }\n }\n}\n" + "content": "// SPDX-License-Identifier: BSD-3-Clause\npragma solidity ^0.8.19;\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"@openzeppelin/contracts/security/Pausable.sol\";\nimport \"./Util/TransformedChunkProof.sol\";\nimport \"./Util/ChunkProof.sol\";\nimport \"./Util/Signatures.sol\";\nimport \"./interface/IPostageStamp.sol\";\n\ninterface IPriceOracle {\n function adjustPrice(uint16 redundancy) external;\n}\n\ninterface IStakeRegistry {\n struct Stake {\n bytes32 overlay;\n uint256 stakeAmount;\n uint256 lastUpdatedBlockNumber;\n }\n\n function freezeDeposit(address _owner, uint256 _time) external;\n\n function lastUpdatedBlockNumberOfAddress(address _owner) external view returns (uint256);\n\n function overlayOfAddress(address _owner) external view returns (bytes32);\n\n function heightOfAddress(address _owner) external view returns (uint8);\n\n function nodeEffectiveStake(address _owner) external view returns (uint256);\n}\n\n/**\n * @title Redistribution contract\n * @author The Swarm Authors\n * @dev Implements a Schelling Co-ordination game to form consensus around the Reserve Commitment hash. This takes\n * place in three phases: _commit_, _reveal_ and _claim_.\n *\n * A node, upon establishing that it _isParticipatingInUpcomingRound_, i.e. it's overlay falls within proximity order\n * of its reported depth with the _currentRoundAnchor_, prepares a \"reserve commitment hash\" using the chunks\n * it currently stores in its reserve and calculates the \"storage depth\" (see Bee for details). These values, if calculated\n * honestly, and with the right chunks stored, should be the same for every node in a neighbourhood. This is the Schelling point.\n * Each eligible node can then use these values, together with a random, single use, secret _revealNonce_ and their\n * _overlay_ as the pre-image values for the obsfucated _commit_, using the _wrapCommit_ method.\n *\n * Once the _commit_ round has elapsed, participating nodes must provide the values used to calculate their obsfucated\n * _commit_ hash, which, once verified for correctness and proximity to the anchor are retained in the _currentReveals_.\n * Nodes that have committed but do not reveal the correct values used to create the pre-image will have their stake\n * \"frozen\" for a period of rounds proportional to their reported depth.\n *\n * During the _reveal_ round, randomness is updated after every successful reveal. Once the reveal round is concluded,\n * the _currentRoundAnchor_ is updated and users can determine if they will be eligible their overlay will be eligible\n * for the next commit phase using _isParticipatingInUpcomingRound_.\n *\n * When the _reveal_ phase has been concluded, the claim phase can begin. At this point, the truth teller and winner\n * are already determined. By calling _isWinner_, an applicant node can run the relevant logic to determine if they have\n * been selected as the beneficiary of this round. When calling _claim_, the current pot from the PostageStamp contract\n * is withdrawn and transferred to that beneficiaries address. Nodes that have revealed values that differ from the truth,\n * have their stakes \"frozen\" for a period of rounds proportional to their reported depth.\n */\n\ncontract Redistribution is AccessControl, Pausable {\n // ----------------------------- Type declarations ------------------------------\n\n // An eligible user may commit to an _obfuscatedHash_ during the commit phase...\n struct Commit {\n bytes32 overlay;\n address owner;\n bool revealed;\n uint8 height;\n uint256 stake;\n bytes32 obfuscatedHash;\n uint256 revealIndex;\n }\n // ...then provide the actual values that are the constituents of the pre-image of the _obfuscatedHash_\n // during the reveal phase.\n struct Reveal {\n bytes32 overlay;\n address owner;\n uint8 depth;\n uint256 stake;\n uint256 stakeDensity;\n bytes32 hash;\n }\n\n struct ChunkInclusionProof {\n bytes32[] proofSegments;\n bytes32 proveSegment;\n // _RCspan is known for RC 32*32\n\n // Inclusion proof of transformed address\n bytes32[] proofSegments2;\n bytes32 proveSegment2;\n // proveSegmentIndex2 known from deterministic random selection;\n uint64 chunkSpan;\n bytes32[] proofSegments3;\n // _proveSegment3 known, is equal _proveSegment2\n // proveSegmentIndex3 know, is equal _proveSegmentIndex2;\n // chunkSpan2 is equal to chunkSpan (as the data is the same)\n //\n PostageProof postageProof;\n SOCProof[] socProof;\n }\n\n struct SOCProof {\n address signer; // signer Ethereum address to check against\n bytes signature;\n bytes32 identifier; //\n bytes32 chunkAddr; // wrapped chunk address\n }\n\n struct PostageProof {\n bytes signature;\n bytes32 postageId;\n uint64 index;\n uint64 timeStamp;\n // address signer; it is provided by the postage stamp contract\n // bytes32 chunkAddr; it equals to the proveSegment argument\n }\n\n // The address of the linked PostageStamp contract.\n IPostageStamp public PostageContract;\n // The address of the linked PriceOracle contract.\n IPriceOracle public OracleContract;\n // The address of the linked Staking contract.\n IStakeRegistry public Stakes;\n\n // Commits for the current round.\n Commit[] public currentCommits;\n // Reveals for the current round.\n Reveal[] public currentReveals;\n\n // The current anchor that being processed for the reveal and claim phases of the round.\n bytes32 private currentRevealRoundAnchor;\n\n // The current random value from which we will random.\n // inputs for selection of the truth teller and beneficiary.\n bytes32 private seed;\n\n // The number of the currently active round phases.\n uint64 public currentCommitRound;\n uint64 public currentRevealRound;\n uint64 public currentClaimRound;\n\n // Settings for slashing and freezing\n uint8 private penaltyMultiplierDisagreement = 1;\n uint8 private penaltyMultiplierNonRevealed = 2;\n uint8 private penaltyRandomFactor = 100; // Use 100 as value to ignore random factor in freezing penalty\n\n // alpha=0.097612 beta=0.0716570 k=16\n uint256 private sampleMaxValue = 1284401000000000000000000000000000000000000000000000000000000000000000000;\n\n // The reveal of the winner of the last round.\n Reveal public winner;\n\n // The length of a round in blocks.\n uint256 private constant ROUND_LENGTH = 152;\n\n // Maximum value of the keccack256 hash.\n bytes32 private constant MAX_H = 0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff;\n\n // ----------------------------- Events ------------------------------\n\n /**\n * @dev Emitted when the winner of a round is selected in the claim phase\n */\n event WinnerSelected(Reveal winner);\n\n /**\n * @dev Emitted when the truth oracle of a round is selected in the claim phase.\n */\n event TruthSelected(bytes32 hash, uint8 depth);\n\n // Next two events to be removed after testing phase pending some other usefulness being found.\n /**\n * @dev Emits the number of commits being processed by the claim phase.\n */\n event CountCommits(uint256 _count);\n\n /**\n * @dev Emits the number of reveals being processed by the claim phase.\n */\n event CountReveals(uint256 _count);\n\n /**\n * @dev Logs that an overlay has committed\n */\n event Committed(uint256 roundNumber, bytes32 overlay);\n /**\n * @dev Emit from Postagestamp contract valid chunk count at the end of claim\n */\n event ChunkCount(uint256 validChunkCount);\n\n /**\n * @dev Bytes32 anhor of current reveal round\n */\n event CurrentRevealAnchor(uint256 roundNumber, bytes32 anchor);\n\n /**\n * @dev Logs that an overlay has revealed\n */\n event Revealed(\n uint256 roundNumber,\n bytes32 overlay,\n uint256 stake,\n uint256 stakeDensity,\n bytes32 reserveCommitment,\n uint8 depth\n );\n\n /**\n * @dev Logs for inclusion proof\n */\n event transformedChunkAddressFromInclusionProof(uint256 indexInRC, bytes32 chunkAddress);\n\n // ----------------------------- Errors ------------------------------\n\n error NotCommitPhase(); // Game is not in commit phase\n error NoCommitsReceived(); // Round didn't receive any commits\n error PhaseLastBlock(); // We don't permit commits in last block of the phase\n error CommitRoundOver(); // Commit phase in this round is over\n error CommitRoundNotStarted(); // Commit phase in this round has not started yet\n error NotMatchingOwner(); // Sender of commit is not matching the overlay address\n error MustStake2Rounds(); // Before entering the game node must stake 2 rounds prior\n error NotStaked(); // Node didn't add any staking\n error WrongPhase(); // Checking in wrong phase, need to check duing claim phase of current round for next round or commit in current round\n error AlreadyCommitted(); // Node already committed in this round\n error NotRevealPhase(); // Game is not in reveal phase\n error OutOfDepthReveal(bytes32); // Anchor is out of reported depth in Reveal phase, anchor data available as argument\n error OutOfDepthClaim(uint8); // Anchor is out of reported depth in Claim phase, entryProof index is argument\n error OutOfDepth(); // Anchor is out of reported depth\n error AlreadyRevealed(); // Node already revealed\n error NoMatchingCommit(); // No matching commit and hash\n error NotClaimPhase(); // Game is not in the claim phase\n error NoReveals(); // Round did not receive any reveals\n error FirstRevealDone(); // We don't want to return value after first reveal\n error AlreadyClaimed(); // This round was already claimed\n error NotAdmin(); // Caller of trx is not admin\n error OnlyPauser(); // Only account with pauser role can call pause/unpause\n error SocVerificationFailed(bytes32); // Soc verification failed for this element\n error SocCalcNotMatching(bytes32); // Soc address calculation does not match with the witness\n error IndexOutsideSet(bytes32); // Stamp available: index resides outside of the valid index set\n error SigRecoveryFailed(bytes32); // Stamp authorized: signature recovery failed for element\n error BatchDoesNotExist(bytes32); // Stamp alive: batch remaining balance validation failed for attached stamp\n error BucketDiffers(bytes32); // Stamp aligned: postage bucket differs from address bucket\n error InclusionProofFailed(uint8, bytes32);\n // 1 = RC inclusion proof failed for element\n // 2 = First sister segment in data must match,\n // 3 = Inclusion proof failed for original address of element\n // 4 = Inclusion proof failed for transformed address of element\n error RandomElementCheckFailed(); // Random element order check failed\n error LastElementCheckFailed(); // Last element order check failed\n error ReserveCheckFailed(bytes32 trALast); // Reserve size estimation check failed\n\n // ----------------------------- CONSTRUCTOR ------------------------------\n\n /**\n * @param staking the address of the linked Staking contract.\n * @param postageContract the address of the linked PostageStamp contract.\n * @param oracleContract the address of the linked PriceOracle contract.\n */\n constructor(address staking, address postageContract, address oracleContract) {\n Stakes = IStakeRegistry(staking);\n PostageContract = IPostageStamp(postageContract);\n OracleContract = IPriceOracle(oracleContract);\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n }\n\n ////////////////////////////////////////\n // STATE CHANGING //\n ////////////////////////////////////////\n\n /**\n * @notice Begin application for a round if eligible. Commit a hashed value for which the pre-image will be\n * subsequently revealed.\n * @dev If a node's overlay is _inProximity_(_depth_) of the _currentRoundAnchor_, that node may compute an\n * _obfuscatedHash_ by providing their _overlay_, reported storage _depth_, reserve commitment _hash_ and a\n * randomly generated, and secret _revealNonce_ to the _wrapCommit_ method.\n * @param _obfuscatedHash The calculated hash resultant of the required pre-image values.\n * and be derived from the same key pair as the message sender.\n * @param _roundNumber Node needs to provide round number for which commit is valid\n */\n function commit(bytes32 _obfuscatedHash, uint64 _roundNumber) external whenNotPaused {\n uint64 cr = currentRound();\n bytes32 _overlay = Stakes.overlayOfAddress(msg.sender);\n uint256 _stake = Stakes.nodeEffectiveStake(msg.sender);\n uint256 _lastUpdate = Stakes.lastUpdatedBlockNumberOfAddress(msg.sender);\n uint8 _height = Stakes.heightOfAddress(msg.sender);\n\n if (!currentPhaseCommit()) {\n revert NotCommitPhase();\n }\n if (block.number % ROUND_LENGTH == (ROUND_LENGTH / 4) - 1) {\n revert PhaseLastBlock();\n }\n\n if (cr > _roundNumber) {\n revert CommitRoundOver();\n }\n\n if (cr < _roundNumber) {\n revert CommitRoundNotStarted();\n }\n\n if (_lastUpdate == 0) {\n revert NotStaked();\n }\n\n if (_lastUpdate >= block.number - 2 * ROUND_LENGTH) {\n revert MustStake2Rounds();\n }\n\n // if we are in a new commit phase, reset the array of commits and\n // set the currentCommitRound to be the current one\n if (cr != currentCommitRound) {\n delete currentCommits;\n currentCommitRound = cr;\n }\n\n uint256 commitsArrayLength = currentCommits.length;\n\n for (uint256 i = 0; i < commitsArrayLength; ) {\n if (currentCommits[i].overlay == _overlay) {\n revert AlreadyCommitted();\n }\n\n unchecked {\n ++i;\n }\n }\n\n currentCommits.push(\n Commit({\n overlay: _overlay,\n owner: msg.sender,\n revealed: false,\n height: _height,\n stake: _stake,\n obfuscatedHash: _obfuscatedHash,\n revealIndex: 0\n })\n );\n\n emit Committed(_roundNumber, _overlay);\n }\n\n /**\n * @notice Reveal the pre-image values used to generate commit provided during this round's commit phase.\n * @param _depth The reported depth.\n * @param _hash The reserve commitment hash.\n * @param _revealNonce The nonce used to generate the commit that is being revealed.\n */\n function reveal(uint8 _depth, bytes32 _hash, bytes32 _revealNonce) external whenNotPaused {\n uint64 cr = currentRound();\n bytes32 _overlay = Stakes.overlayOfAddress(msg.sender);\n\n if (_depth < currentMinimumDepth()) {\n revert OutOfDepth();\n }\n\n if (!currentPhaseReveal()) {\n revert NotRevealPhase();\n }\n\n if (cr != currentCommitRound) {\n revert NoCommitsReceived();\n }\n\n if (cr != currentRevealRound) {\n currentRevealRoundAnchor = currentRoundAnchor();\n delete currentReveals;\n // We set currentRevealRound ONLY after we set current anchor\n currentRevealRound = cr;\n emit CurrentRevealAnchor(cr, currentRevealRoundAnchor);\n updateRandomness();\n }\n\n bytes32 obfuscatedHash = wrapCommit(_overlay, _depth, _hash, _revealNonce);\n uint256 id = findCommit(_overlay, obfuscatedHash);\n Commit memory revealedCommit = currentCommits[id];\n uint8 depthResponsibility = _depth - revealedCommit.height;\n\n // Check that commit is in proximity of the current anchor\n if (!inProximity(revealedCommit.overlay, currentRevealRoundAnchor, depthResponsibility)) {\n revert OutOfDepthReveal(currentRevealRoundAnchor);\n }\n // Check that the commit has not already been revealed\n if (revealedCommit.revealed) {\n revert AlreadyRevealed();\n }\n\n currentCommits[id].revealed = true;\n currentCommits[id].revealIndex = currentReveals.length;\n\n currentReveals.push(\n Reveal({\n overlay: revealedCommit.overlay,\n owner: revealedCommit.owner,\n depth: _depth,\n stake: revealedCommit.stake,\n stakeDensity: revealedCommit.stake * uint256(2 ** depthResponsibility),\n hash: _hash\n })\n );\n\n emit Revealed(\n cr,\n revealedCommit.overlay,\n revealedCommit.stake,\n revealedCommit.stake * uint256(2 ** depthResponsibility),\n _hash,\n _depth\n );\n }\n\n /**\n * @notice Helper function to get this round truth\n * @dev\n */\n function claim(\n ChunkInclusionProof calldata entryProof1,\n ChunkInclusionProof calldata entryProof2,\n ChunkInclusionProof calldata entryProofLast\n ) external whenNotPaused {\n winnerSelection();\n\n Reveal memory winnerSelected = winner;\n uint256 indexInRC1;\n uint256 indexInRC2;\n bytes32 _currentRevealRoundAnchor = currentRevealRoundAnchor;\n bytes32 _seed = seed;\n\n // rand(14)\n indexInRC1 = uint256(_seed) % 15;\n // rand(13)\n indexInRC2 = uint256(_seed) % 14;\n if (indexInRC2 >= indexInRC1) {\n indexInRC2++;\n }\n\n if (!inProximity(entryProofLast.proveSegment, _currentRevealRoundAnchor, winnerSelected.depth)) {\n revert OutOfDepthClaim(3);\n }\n\n inclusionFunction(entryProofLast, 30);\n stampFunction(entryProofLast);\n socFunction(entryProofLast);\n\n if (!inProximity(entryProof1.proveSegment, _currentRevealRoundAnchor, winnerSelected.depth)) {\n revert OutOfDepthClaim(2);\n }\n\n inclusionFunction(entryProof1, indexInRC1 * 2);\n stampFunction(entryProof1);\n socFunction(entryProof1);\n\n if (!inProximity(entryProof2.proveSegment, _currentRevealRoundAnchor, winnerSelected.depth)) {\n revert OutOfDepthClaim(1);\n }\n\n inclusionFunction(entryProof2, indexInRC2 * 2);\n stampFunction(entryProof2);\n socFunction(entryProof2);\n\n checkOrder(\n indexInRC1,\n indexInRC2,\n entryProof1.proofSegments[0],\n entryProof2.proofSegments[0],\n entryProofLast.proofSegments[0]\n );\n\n estimateSize(entryProofLast.proofSegments[0]);\n\n PostageContract.withdraw(winnerSelected.owner);\n emit WinnerSelected(winnerSelected);\n emit ChunkCount(PostageContract.validChunkCount());\n }\n\n function winnerSelection() internal {\n uint64 cr = currentRound();\n\n if (!currentPhaseClaim()) {\n revert NotClaimPhase();\n }\n\n if (cr != currentRevealRound) {\n revert NoReveals();\n }\n\n if (cr <= currentClaimRound) {\n revert AlreadyClaimed();\n }\n\n uint256 currentWinnerSelectionSum = 0;\n uint256 redundancyCount = 0;\n bytes32 randomNumber;\n uint256 randomNumberTrunc;\n\n bytes32 truthRevealedHash;\n uint8 truthRevealedDepth;\n uint256 currentCommitsLength = currentCommits.length;\n\n emit CountCommits(currentCommitsLength);\n emit CountReveals(currentReveals.length);\n\n (truthRevealedHash, truthRevealedDepth) = getCurrentTruth();\n emit TruthSelected(truthRevealedHash, truthRevealedDepth);\n string memory winnerSelectionAnchor = currentWinnerSelectionAnchor();\n\n for (uint256 i = 0; i < currentCommitsLength; ) {\n Commit memory currentCommit = currentCommits[i];\n uint256 revIndex = currentCommit.revealIndex;\n Reveal memory currentReveal = currentReveals[revIndex];\n\n // Select winner with valid truth\n if (\n currentCommit.revealed &&\n truthRevealedHash == currentReveal.hash &&\n truthRevealedDepth == currentReveal.depth\n ) {\n currentWinnerSelectionSum += currentReveal.stakeDensity;\n randomNumber = keccak256(abi.encodePacked(winnerSelectionAnchor, redundancyCount));\n randomNumberTrunc = uint256(randomNumber & MAX_H);\n\n if (randomNumberTrunc * currentWinnerSelectionSum < currentReveal.stakeDensity * (uint256(MAX_H) + 1)) {\n winner = currentReveal;\n }\n\n redundancyCount++;\n }\n\n // Freeze deposit if any truth is false, make it a penaltyRandomFactor chance for this to happen\n if (\n currentCommit.revealed &&\n (truthRevealedHash != currentReveal.hash || truthRevealedDepth != currentReveal.depth) &&\n (block.prevrandao % 100 < penaltyRandomFactor)\n ) {\n Stakes.freezeDeposit(\n currentReveal.owner,\n penaltyMultiplierDisagreement * ROUND_LENGTH * uint256(2 ** truthRevealedDepth)\n );\n }\n\n // Slash deposits if revealed is false\n if (!currentCommit.revealed) {\n // slash in later phase (ph5)\n // Stakes.slashDeposit(currentCommits[i].overlay, currentCommits[i].stake);\n Stakes.freezeDeposit(\n currentCommit.owner,\n penaltyMultiplierNonRevealed * ROUND_LENGTH * uint256(2 ** truthRevealedDepth)\n );\n }\n unchecked {\n ++i;\n }\n }\n\n OracleContract.adjustPrice(uint16(redundancyCount));\n currentClaimRound = cr;\n }\n\n function inclusionFunction(ChunkInclusionProof calldata entryProof, uint256 indexInRC) internal {\n uint256 randomChunkSegmentIndex = uint256(seed) % 128;\n bytes32 calculatedTransformedAddr = TransformedBMTChunk.transformedChunkAddressFromInclusionProof(\n entryProof.proofSegments3,\n entryProof.proveSegment2,\n randomChunkSegmentIndex,\n entryProof.chunkSpan,\n currentRevealRoundAnchor\n );\n\n emit transformedChunkAddressFromInclusionProof(indexInRC, calculatedTransformedAddr);\n\n if (\n winner.hash !=\n BMTChunk.chunkAddressFromInclusionProof(\n entryProof.proofSegments,\n entryProof.proveSegment,\n indexInRC,\n 32 * 32\n )\n ) {\n revert InclusionProofFailed(1, calculatedTransformedAddr);\n }\n\n if (entryProof.proofSegments2[0] != entryProof.proofSegments3[0]) {\n revert InclusionProofFailed(2, calculatedTransformedAddr);\n }\n\n bytes32 originalAddress = entryProof.socProof.length > 0\n ? entryProof.socProof[0].chunkAddr // soc attestation in socFunction\n : entryProof.proveSegment;\n\n if (\n originalAddress !=\n BMTChunk.chunkAddressFromInclusionProof(\n entryProof.proofSegments2,\n entryProof.proveSegment2,\n randomChunkSegmentIndex,\n entryProof.chunkSpan\n )\n ) {\n revert InclusionProofFailed(3, calculatedTransformedAddr);\n }\n\n // In case of SOC, the transformed address is hashed together with its address in the sample\n if (entryProof.socProof.length > 0) {\n calculatedTransformedAddr = keccak256(\n abi.encode(\n entryProof.proveSegment, // SOC address\n calculatedTransformedAddr\n )\n );\n }\n\n if (entryProof.proofSegments[0] != calculatedTransformedAddr) {\n revert InclusionProofFailed(4, calculatedTransformedAddr);\n }\n }\n\n /**\n * @notice Set freezing parameters\n */\n function setFreezingParams(\n uint8 _penaltyMultiplierDisagreement,\n uint8 _penaltyMultiplierNonRevealed,\n uint8 _penaltyRandomFactor\n ) external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert NotAdmin();\n }\n\n penaltyMultiplierDisagreement = _penaltyMultiplierDisagreement;\n penaltyMultiplierNonRevealed = _penaltyMultiplierNonRevealed;\n penaltyRandomFactor = _penaltyRandomFactor;\n }\n\n /**\n * @notice changes the max sample value used for reserve estimation\n */\n function setSampleMaxValue(uint256 _sampleMaxValue) external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert NotAdmin();\n }\n\n sampleMaxValue = _sampleMaxValue;\n }\n\n /**\n * @notice Updates the source of randomness. Uses block.difficulty in pre-merge chains, this is substituted\n * to block.prevrandao in post merge chains.\n */\n function updateRandomness() private {\n seed = keccak256(abi.encode(seed, block.prevrandao));\n }\n\n /**\n * @dev Pause the contract. The contract is provably stopped by renouncing\n the pauser role and the admin role after pausing, can only be called by the `PAUSER`\n */\n function pause() public {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert OnlyPauser();\n }\n\n _pause();\n }\n\n /**\n * @dev Unpause the contract, can only be called by the pauser when paused\n */\n function unPause() public {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert OnlyPauser();\n }\n _unpause();\n }\n\n ////////////////////////////////////////\n // STATE READING //\n ////////////////////////////////////////\n\n // ----------------------------- Anchor calculations ------------------------------\n\n /**\n * @notice Returns the current random seed which is used to determine later utilised random numbers.\n * If rounds have elapsed without reveals, hash the seed with an incremented nonce to produce a new\n * random seed and hence a new round anchor.\n */\n function currentSeed() public view returns (bytes32) {\n uint64 cr = currentRound();\n bytes32 currentSeedValue = seed;\n\n if (cr > currentRevealRound + 1) {\n uint256 difference = cr - currentRevealRound - 1;\n currentSeedValue = keccak256(abi.encodePacked(currentSeedValue, difference));\n }\n\n return currentSeedValue;\n }\n\n /**\n * @notice Returns the seed which will become current once the next commit phase begins.\n * Used to determine what the next round's anchor will be.\n */\n function nextSeed() public view returns (bytes32) {\n uint64 cr = currentRound() + 1;\n bytes32 currentSeedValue = seed;\n\n if (cr > currentRevealRound + 1) {\n uint256 difference = cr - currentRevealRound - 1;\n currentSeedValue = keccak256(abi.encodePacked(currentSeedValue, difference));\n }\n\n return currentSeedValue;\n }\n\n /**\n * @notice The random value used to choose the selected truth teller.\n */\n function currentTruthSelectionAnchor() private view returns (string memory) {\n if (!currentPhaseClaim()) {\n revert NotClaimPhase();\n }\n\n uint64 cr = currentRound();\n if (cr != currentRevealRound) {\n revert NoReveals();\n }\n\n return string(abi.encodePacked(seed, \"0\"));\n }\n\n /**\n * @notice The random value used to choose the selected beneficiary.\n */\n function currentWinnerSelectionAnchor() private view returns (string memory) {\n if (!currentPhaseClaim()) {\n revert NotClaimPhase();\n }\n uint64 cr = currentRound();\n if (cr != currentRevealRound) {\n revert NoReveals();\n }\n\n return string(abi.encodePacked(seed, \"1\"));\n }\n\n /**\n * @notice The anchor used to determine eligibility for the current round.\n * @dev A node must be within proximity order of less than or equal to the storage depth they intend to report.\n */\n function currentRoundAnchor() public view returns (bytes32 returnVal) {\n // This will be called in reveal phase and set as currentRevealRoundAnchor or in\n // commit phase when checking eligibility for next round by isParticipatingInUpcomingRound\n if (currentPhaseCommit() || (currentRound() > currentRevealRound && !currentPhaseClaim())) {\n return currentSeed();\n }\n\n // This will be called by isParticipatingInUpcomingRound check in claim phase\n if (currentPhaseClaim()) {\n return nextSeed();\n }\n\n // Without this, this function will output 0x0 after first reveal which is value and we prefere it reverts\n if (currentPhaseReveal() && currentRound() == currentRevealRound) {\n revert FirstRevealDone();\n }\n }\n\n /**\n * @notice Returns true if an overlay address _A_ is within proximity order _minimum_ of _B_.\n * @param A An overlay address to compare.\n * @param B An overlay address to compare.\n * @param minimum Minimum proximity order.\n */\n function inProximity(bytes32 A, bytes32 B, uint8 minimum) public pure returns (bool) {\n if (minimum == 0) {\n return true;\n }\n\n return uint256(A ^ B) < uint256(2 ** (256 - minimum));\n }\n\n // ----------------------------- Commit ------------------------------\n\n /**\n * @notice The number of the current round.\n */\n function currentRound() public view returns (uint64) {\n return uint64(block.number / ROUND_LENGTH);\n }\n\n /**\n * @notice Returns true if current block is during commit phase.\n */\n function currentPhaseCommit() public view returns (bool) {\n if (block.number % ROUND_LENGTH < ROUND_LENGTH / 4) {\n return true;\n }\n return false;\n }\n\n /**\n * @notice Determine if a the owner of a given overlay can participate in the upcoming round.\n * @param _owner The address of the applicant from.\n * @param _depth The storage depth the applicant intends to report.\n */\n function isParticipatingInUpcomingRound(address _owner, uint8 _depth) public view returns (bool) {\n uint256 _lastUpdate = Stakes.lastUpdatedBlockNumberOfAddress(_owner);\n uint8 _depthResponsibility = _depth - Stakes.heightOfAddress(_owner);\n\n if (currentPhaseReveal()) {\n revert WrongPhase();\n }\n\n if (_lastUpdate == 0) {\n revert NotStaked();\n }\n\n if (_lastUpdate >= block.number - 2 * ROUND_LENGTH) {\n revert MustStake2Rounds();\n }\n\n return inProximity(Stakes.overlayOfAddress(_owner), currentRoundAnchor(), _depthResponsibility);\n }\n\n // ----------------------------- Reveal ------------------------------\n\n /**\n * @notice Returns minimum depth reveal has to have to participate in this round\n */\n function currentMinimumDepth() public view returns (uint8) {\n // We are checking value in reveal phase, as the currentCommitRound is set to the current round\n // but the currentClaimRound is still set to the last time claim was made\n // We add 1 to ensure that for the next round the minimum depth is the same as last winner depth\n\n uint256 difference = currentCommitRound - currentClaimRound;\n uint8 skippedRounds = uint8(difference > 254 ? 254 : difference) + 1;\n\n uint8 lastWinnerDepth = winner.depth;\n\n // We ensure that skippedRounds is not bigger than lastWinnerDepth, because of overflow\n return skippedRounds >= lastWinnerDepth ? 0 : lastWinnerDepth - skippedRounds;\n }\n\n /**\n * @notice Helper function to get this node reveal in commits\n * @dev\n */\n function findCommit(bytes32 _overlay, bytes32 _obfuscatedHash) internal view returns (uint256) {\n for (uint256 i = 0; i < currentCommits.length; ) {\n if (currentCommits[i].overlay == _overlay && _obfuscatedHash == currentCommits[i].obfuscatedHash) {\n return i;\n }\n unchecked {\n ++i;\n }\n }\n revert NoMatchingCommit();\n }\n\n /**\n * @notice Hash the pre-image values to the obsfucated hash.\n * @dev _revealNonce_ must be randomly generated, used once and kept secret until the reveal phase.\n * @param _overlay The overlay address of the applicant.\n * @param _depth The reported depth.\n * @param _hash The reserve commitment hash.\n * @param revealNonce A random, single use, secret nonce.\n */\n function wrapCommit(\n bytes32 _overlay,\n uint8 _depth,\n bytes32 _hash,\n bytes32 revealNonce\n ) public pure returns (bytes32) {\n return keccak256(abi.encodePacked(_overlay, _depth, _hash, revealNonce));\n }\n\n /**\n * @notice Returns true if current block is during reveal phase.\n */\n function currentPhaseReveal() public view returns (bool) {\n uint256 number = block.number % ROUND_LENGTH;\n if (number >= ROUND_LENGTH / 4 && number < ROUND_LENGTH / 2) {\n return true;\n }\n return false;\n }\n\n /**\n * @notice Returns true if current block is during reveal phase.\n */\n function currentRoundReveals() public view returns (Reveal[] memory) {\n if (!currentPhaseClaim()) {\n revert NotClaimPhase();\n }\n uint64 cr = currentRound();\n if (cr != currentRevealRound) {\n revert NoReveals();\n }\n\n return currentReveals;\n }\n\n // ----------------------------- Claim ------------------------------\n\n /**\n * @notice Returns true if current block is during claim phase.\n */\n function currentPhaseClaim() public view returns (bool) {\n if (block.number % ROUND_LENGTH >= ROUND_LENGTH / 2) {\n return true;\n }\n return false;\n }\n\n function getCurrentTruth() internal view returns (bytes32 Hash, uint8 Depth) {\n uint256 currentSum;\n bytes32 randomNumber;\n uint256 randomNumberTrunc;\n\n bytes32 truthRevealedHash;\n uint8 truthRevealedDepth;\n uint256 revIndex;\n string memory truthSelectionAnchor = currentTruthSelectionAnchor();\n uint256 commitsArrayLength = currentCommits.length;\n\n for (uint256 i = 0; i < commitsArrayLength; ) {\n if (currentCommits[i].revealed) {\n revIndex = currentCommits[i].revealIndex;\n currentSum += currentReveals[revIndex].stakeDensity;\n randomNumber = keccak256(abi.encodePacked(truthSelectionAnchor, i));\n randomNumberTrunc = uint256(randomNumber & MAX_H);\n\n // question is whether randomNumber / MAX_H < probability\n // where probability is stakeDensity / currentSum\n // to avoid resorting to floating points all divisions should be\n // simplified with multiplying both sides (as long as divisor > 0)\n // randomNumber / (MAX_H + 1) < stakeDensity / currentSum\n // ( randomNumber / (MAX_H + 1) ) * currentSum < stakeDensity\n // randomNumber * currentSum < stakeDensity * (MAX_H + 1)\n if (randomNumberTrunc * currentSum < currentReveals[revIndex].stakeDensity * (uint256(MAX_H) + 1)) {\n truthRevealedHash = currentReveals[revIndex].hash;\n truthRevealedDepth = currentReveals[revIndex].depth;\n }\n }\n unchecked {\n ++i;\n }\n }\n\n return (truthRevealedHash, truthRevealedDepth);\n }\n\n /**\n * @notice Determine if a the owner of a given overlay will be the beneficiary of the claim phase.\n * @param _overlay The overlay address of the applicant.\n */\n function isWinner(bytes32 _overlay) public view returns (bool) {\n if (!currentPhaseClaim()) {\n revert NotClaimPhase();\n }\n\n uint64 cr = currentRound();\n if (cr != currentRevealRound) {\n revert NoReveals();\n }\n\n if (cr <= currentClaimRound) {\n revert AlreadyClaimed();\n }\n\n uint256 currentWinnerSelectionSum;\n bytes32 winnerIs;\n bytes32 randomNumber;\n uint256 randomNumberTrunc;\n bytes32 truthRevealedHash;\n uint8 truthRevealedDepth;\n uint256 revIndex;\n string memory winnerSelectionAnchor = currentWinnerSelectionAnchor();\n uint256 redundancyCount = 0;\n\n // Get current truth\n (truthRevealedHash, truthRevealedDepth) = getCurrentTruth();\n uint256 commitsArrayLength = currentCommits.length;\n\n for (uint256 i = 0; i < commitsArrayLength; ) {\n revIndex = currentCommits[i].revealIndex;\n\n // Deterministically read winner\n if (\n currentCommits[i].revealed &&\n truthRevealedHash == currentReveals[revIndex].hash &&\n truthRevealedDepth == currentReveals[revIndex].depth\n ) {\n currentWinnerSelectionSum += currentReveals[revIndex].stakeDensity;\n randomNumber = keccak256(abi.encodePacked(winnerSelectionAnchor, redundancyCount));\n randomNumberTrunc = uint256(randomNumber & MAX_H);\n\n if (\n randomNumberTrunc * currentWinnerSelectionSum <\n currentReveals[revIndex].stakeDensity * (uint256(MAX_H) + 1)\n ) {\n winnerIs = currentReveals[revIndex].overlay;\n }\n\n redundancyCount++;\n }\n unchecked {\n ++i;\n }\n }\n\n return (winnerIs == _overlay);\n }\n\n // ----------------------------- Claim verifications ------------------------------\n\n function socFunction(ChunkInclusionProof calldata entryProof) internal pure {\n if (entryProof.socProof.length == 0) return;\n\n if (\n !Signatures.socVerify(\n entryProof.socProof[0].signer, // signer Ethereum address to check against\n entryProof.socProof[0].signature,\n entryProof.socProof[0].identifier,\n entryProof.socProof[0].chunkAddr\n )\n ) {\n revert SocVerificationFailed(entryProof.socProof[0].chunkAddr);\n }\n\n if (\n calculateSocAddress(entryProof.socProof[0].identifier, entryProof.socProof[0].signer) !=\n entryProof.proveSegment\n ) {\n revert SocCalcNotMatching(entryProof.socProof[0].chunkAddr);\n }\n }\n\n function stampFunction(ChunkInclusionProof calldata entryProof) internal view {\n // authentic\n (address batchOwner, uint8 batchDepth, uint8 bucketDepth, , , ) = PostageContract.batches(\n entryProof.postageProof.postageId\n );\n\n // alive\n if (batchOwner == address(0)) {\n revert BatchDoesNotExist(entryProof.postageProof.postageId); // Batch does not exist or expired\n }\n\n uint32 postageIndex = getPostageIndex(entryProof.postageProof.index);\n uint256 maxPostageIndex = postageStampIndexCount(batchDepth, bucketDepth);\n // available\n if (postageIndex >= maxPostageIndex) {\n revert IndexOutsideSet(entryProof.postageProof.postageId);\n }\n\n // aligned\n uint64 postageBucket = getPostageBucket(entryProof.postageProof.index);\n uint64 addressBucket = addressToBucket(entryProof.proveSegment, bucketDepth);\n if (postageBucket != addressBucket) {\n revert BucketDiffers(entryProof.postageProof.postageId);\n }\n\n // authorized\n if (\n !Signatures.postageVerify(\n batchOwner,\n entryProof.postageProof.signature,\n entryProof.proveSegment,\n entryProof.postageProof.postageId,\n entryProof.postageProof.index,\n entryProof.postageProof.timeStamp\n )\n ) {\n revert SigRecoveryFailed(entryProof.postageProof.postageId);\n }\n }\n\n function addressToBucket(bytes32 swarmAddress, uint8 bucketDepth) internal pure returns (uint32) {\n uint32 prefix = uint32(uint256(swarmAddress) >> (256 - 32));\n return prefix >> (32 - bucketDepth);\n }\n\n function postageStampIndexCount(uint8 postageDepth, uint8 bucketDepth) internal pure returns (uint256) {\n return 1 << (postageDepth - bucketDepth);\n }\n\n function getPostageIndex(uint64 signedIndex) internal pure returns (uint32) {\n return uint32(signedIndex);\n }\n\n function getPostageBucket(uint64 signedIndex) internal pure returns (uint64) {\n return uint32(signedIndex >> 32);\n }\n\n function calculateSocAddress(bytes32 identifier, address signer) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(identifier, signer));\n }\n\n function checkOrder(uint256 a, uint256 b, bytes32 trA1, bytes32 trA2, bytes32 trALast) internal pure {\n if (a < b) {\n if (uint256(trA1) >= uint256(trA2)) {\n revert RandomElementCheckFailed();\n }\n if (uint256(trA2) >= uint256(trALast)) {\n revert LastElementCheckFailed();\n }\n } else {\n if (uint256(trA2) >= uint256(trA1)) {\n revert RandomElementCheckFailed();\n }\n if (uint256(trA1) >= uint256(trALast)) {\n revert LastElementCheckFailed();\n }\n }\n }\n\n function estimateSize(bytes32 trALast) internal view {\n if (uint256(trALast) >= sampleMaxValue) {\n revert ReserveCheckFailed(trALast);\n }\n }\n}\n" }, "src/Staking.sol": { - "content": "// SPDX-License-Identifier: BSD-3-Clause\npragma solidity ^0.8.19;\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"@openzeppelin/contracts/security/Pausable.sol\";\n\n/**\n * @title Staking contract for the Swarm storage incentives\n * @author The Swarm Authors\n * @dev Allows users to stake tokens in order to be eligible for the Redistribution Schelling co-ordination game.\n * Stakes are not withdrawable unless the contract is paused, e.g. in the event of migration to a new staking\n * contract. Stakes are frozen or slashed by the Redistribution contract in response to violations of the\n * protocol.\n */\n\ncontract StakeRegistry is AccessControl, Pausable {\n /**\n * @dev Emitted when a stake is created or updated by `owner` of the `overlay` by `stakeamount`, during `lastUpdatedBlock`.\n */\n event StakeUpdated(bytes32 indexed overlay, uint256 stakeAmount, address owner, uint256 lastUpdatedBlock);\n\n /**\n * @dev Emitted when a stake for overlay `slashed` is slashed by `amount`.\n */\n event StakeSlashed(bytes32 slashed, uint256 amount);\n\n /**\n * @dev Emitted when a stake for overlay `frozen` for `time` blocks.\n */\n event StakeFrozen(bytes32 slashed, uint256 time);\n\n struct Stake {\n // Overlay of the node that is being staked\n bytes32 overlay;\n // Amount of tokens staked\n uint256 stakeAmount;\n // Owner of `overlay`\n address owner;\n // Block height the stake was updated\n uint256 lastUpdatedBlockNumber;\n // Used to indicate presents in stakes struct\n bool isValue;\n }\n\n // Associate every stake id with overlay data.\n mapping(bytes32 => Stake) public stakes;\n\n // Role allowed to pause\n bytes32 public constant PAUSER_ROLE = keccak256(\"PAUSER_ROLE\");\n // Role allowed to freeze and slash entries\n bytes32 public constant REDISTRIBUTOR_ROLE = keccak256(\"REDISTRIBUTOR_ROLE\");\n\n // Swarm network ID\n uint64 NetworkId;\n\n // Address of the staked ERC20 token\n address public bzzToken;\n\n /**\n * @param _bzzToken Address of the staked ERC20 token\n * @param _NetworkId Swarm network ID\n */\n constructor(address _bzzToken, uint64 _NetworkId) {\n NetworkId = _NetworkId;\n bzzToken = _bzzToken;\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n _setupRole(PAUSER_ROLE, msg.sender);\n }\n\n /**\n * @dev Checks to see if `overlay` is frozen.\n * @param overlay Overlay of staked overlay\n *\n * Returns a boolean value indicating whether the operation succeeded.\n */\n function overlayNotFrozen(bytes32 overlay) internal view returns (bool) {\n return stakes[overlay].lastUpdatedBlockNumber < block.number;\n }\n\n /**\n * @dev Returns the current `stakeAmount` of `overlay`.\n * @param overlay Overlay of node\n */\n function stakeOfOverlay(bytes32 overlay) public view returns (uint256) {\n return stakes[overlay].stakeAmount;\n }\n\n /**\n * @dev Returns the current usable `stakeAmount` of `overlay`.\n * Checks whether the stake is currently frozen.\n * @param overlay Overlay of node\n */\n function usableStakeOfOverlay(bytes32 overlay) public view returns (uint256) {\n return overlayNotFrozen(overlay) ? stakes[overlay].stakeAmount : 0;\n }\n\n /**\n * @dev Returns the `lastUpdatedBlockNumber` of `overlay`.\n */\n function lastUpdatedBlockNumberOfOverlay(bytes32 overlay) public view returns (uint256) {\n return stakes[overlay].lastUpdatedBlockNumber;\n }\n\n /**\n * @dev Returns the eth address of the owner of `overlay`.\n * @param overlay Overlay of node\n */\n function ownerOfOverlay(bytes32 overlay) public view returns (address) {\n return stakes[overlay].owner;\n }\n\n /**\n * @dev Please both Endians 🥚.\n * @param input Eth address used for overlay calculation.\n */\n function reverse(uint64 input) internal pure returns (uint64 v) {\n v = input;\n\n // swap bytes\n v = ((v & 0xFF00FF00FF00FF00) >> 8) | ((v & 0x00FF00FF00FF00FF) << 8);\n\n // swap 2-byte long pairs\n v = ((v & 0xFFFF0000FFFF0000) >> 16) | ((v & 0x0000FFFF0000FFFF) << 16);\n\n // swap 4-byte long pairs\n v = (v >> 32) | (v << 32);\n }\n\n /**\n * @notice Create a new stake or update an existing one.\n * @dev At least `_initialBalancePerChunk*2^depth` number of tokens need to be preapproved for this contract.\n * @param _owner Eth address used for overlay calculation.\n * @param nonce Nonce that was used for overlay calculation.\n * @param amount Deposited amount of ERC20 tokens.\n */\n function depositStake(address _owner, bytes32 nonce, uint256 amount) external whenNotPaused {\n require(_owner == msg.sender, \"only owner can update stake\");\n\n bytes32 overlay = keccak256(abi.encodePacked(_owner, reverse(NetworkId), nonce));\n\n uint256 updatedAmount = amount;\n\n if (stakes[overlay].isValue) {\n require(overlayNotFrozen(overlay), \"overlay currently frozen\");\n updatedAmount = amount + stakes[overlay].stakeAmount;\n }\n\n require(ERC20(bzzToken).transferFrom(msg.sender, address(this), amount), \"failed transfer\");\n\n emit StakeUpdated(overlay, updatedAmount, _owner, block.number);\n\n stakes[overlay] = Stake({\n owner: _owner,\n overlay: overlay,\n stakeAmount: updatedAmount,\n lastUpdatedBlockNumber: block.number,\n isValue: true\n });\n }\n\n /**\n * @dev Withdraw stake only when the staking contract is paused,\n * can only be called by the owner specific to the associated `overlay`\n * @param overlay The overlay to withdraw from\n * @param amount The amount of ERC20 tokens to be withdrawn\n */\n function withdrawFromStake(bytes32 overlay, uint256 amount) external whenPaused {\n require(stakes[overlay].owner == msg.sender, \"only owner can withdraw stake\");\n uint256 withDrawLimit = amount;\n if (amount > stakes[overlay].stakeAmount) {\n withDrawLimit = stakes[overlay].stakeAmount;\n }\n\n if (withDrawLimit < stakes[overlay].stakeAmount) {\n stakes[overlay].stakeAmount -= withDrawLimit;\n stakes[overlay].lastUpdatedBlockNumber = block.number;\n require(ERC20(bzzToken).transfer(msg.sender, withDrawLimit), \"failed withdrawal\");\n } else {\n delete stakes[overlay];\n require(ERC20(bzzToken).transfer(msg.sender, withDrawLimit), \"failed withdrawal\");\n }\n }\n\n /**\n * @dev Freeze an existing stake, can only be called by the redistributor\n * @param overlay the overlay selected\n * @param time penalty length in blocknumbers\n */\n function freezeDeposit(bytes32 overlay, uint256 time) external {\n require(hasRole(REDISTRIBUTOR_ROLE, msg.sender), \"only redistributor can freeze stake\");\n\n if (stakes[overlay].isValue) {\n emit StakeFrozen(overlay, time);\n stakes[overlay].lastUpdatedBlockNumber = block.number + time;\n }\n }\n\n /**\n * @dev Slash an existing stake, can only be called by the `redistributor`\n * @param overlay the overlay selected\n * @param amount the amount to be slashed\n */\n function slashDeposit(bytes32 overlay, uint256 amount) external {\n require(hasRole(REDISTRIBUTOR_ROLE, msg.sender), \"only redistributor can slash stake\");\n emit StakeSlashed(overlay, amount);\n if (stakes[overlay].isValue) {\n if (stakes[overlay].stakeAmount > amount) {\n stakes[overlay].stakeAmount -= amount;\n stakes[overlay].lastUpdatedBlockNumber = block.number;\n } else {\n delete stakes[overlay];\n }\n }\n }\n\n /**\n * @dev Pause the contract. The contract is provably stopped by renouncing\n the pauser role and the admin role after pausing, can only be called by the `PAUSER`\n */\n function pause() public {\n require(hasRole(PAUSER_ROLE, msg.sender), \"only pauser can pause\");\n _pause();\n }\n\n /**\n * @dev Unpause the contract, can only be called by the pauser when paused\n */\n function unPause() public {\n require(hasRole(PAUSER_ROLE, msg.sender), \"only pauser can unpause\");\n _unpause();\n }\n\n function changeNetworkId(uint64 _NetworkId) external {\n require(hasRole(DEFAULT_ADMIN_ROLE, msg.sender), \"only admin can change Network ID\");\n NetworkId = _NetworkId;\n }\n}\n" + "content": "// SPDX-License-Identifier: BSD-3-Clause\npragma solidity ^0.8.19;\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"@openzeppelin/contracts/security/Pausable.sol\";\n\ninterface IPriceOracle {\n function currentPrice() external view returns (uint32);\n}\n\n/**\n * @title Staking contract for the Swarm storage incentives\n * @author The Swarm Authors\n * @dev Allows users to stake tokens in order to be eligible for the Redistribution Schelling co-ordination game.\n * Stakes are frozen or slashed by the Redistribution contract in response to violations of the\n * protocol.\n */\n\ncontract StakeRegistry is AccessControl, Pausable {\n // ----------------------------- State variables ------------------------------\n\n struct Stake {\n // Overlay of the node that is being staked\n bytes32 overlay;\n // Stake balance expressed through price oracle\n uint256 committedStake;\n // Stake balance expressed in BZZ\n uint256 potentialStake;\n // Block height the stake was updated, also used as flag to check if the stake is set\n uint256 lastUpdatedBlockNumber;\n // Node indicating its increased reserve\n uint8 height;\n }\n\n // Associate every stake id with node address data.\n mapping(address => Stake) public stakes;\n\n // Role allowed to freeze and slash entries\n bytes32 public constant REDISTRIBUTOR_ROLE = keccak256(\"REDISTRIBUTOR_ROLE\");\n\n // Swarm network ID\n uint64 NetworkId;\n\n // The miniumum stake allowed to be staked using the Staking contract.\n uint64 private constant MIN_STAKE = 100000000000000000;\n\n // Address of the staked ERC20 token\n address public immutable bzzToken;\n\n // The address of the linked PriceOracle contract.\n IPriceOracle public OracleContract;\n\n // ----------------------------- Events ------------------------------\n\n /**\n * @dev Emitted when a stake is created or updated by `owner` of the `overlay`.\n */\n event StakeUpdated(\n address indexed owner,\n uint256 committedStake,\n uint256 potentialStake,\n bytes32 overlay,\n uint256 lastUpdatedBlock,\n uint8 height\n );\n\n /**\n * @dev Emitted when a stake for address `slashed` is slashed by `amount`.\n */\n event StakeSlashed(address slashed, bytes32 overlay, uint256 amount);\n\n /**\n * @dev Emitted when a stake for address `frozen` is frozen for `time` blocks.\n */\n event StakeFrozen(address frozen, bytes32 overlay, uint256 time);\n\n /**\n * @dev Emitted when a address changes overlay it uses\n */\n event OverlayChanged(address owner, bytes32 overlay);\n\n /**\n * @dev Emitted when a stake for address is withdrawn\n */\n event StakeWithdrawn(address node, uint256 amount);\n\n // ----------------------------- Errors ------------------------------\n\n error TransferFailed(); // Used when token transfers fail\n error Frozen(); // Used when an action cannot proceed because the overlay is frozen\n error Unauthorized(); // Used where only the owner can perform the action\n error OnlyRedistributor(); // Used when only the redistributor role is allowed\n error OnlyPauser(); // Used when only the pauser role is allowed\n error BelowMinimumStake(); // Node participating in game has stake below minimum treshold\n\n // ----------------------------- CONSTRUCTOR ------------------------------\n\n /**\n * @param _bzzToken Address of the staked ERC20 token\n * @param _NetworkId Swarm network ID\n */\n constructor(address _bzzToken, uint64 _NetworkId, address _oracleContract) {\n NetworkId = _NetworkId;\n bzzToken = _bzzToken;\n OracleContract = IPriceOracle(_oracleContract);\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n }\n\n ////////////////////////////////////////\n // STATE SETTING //\n ////////////////////////////////////////\n\n /**\n * @notice Create a new stake or update an existing one, change overlay of node\n * @dev At least `_initialBalancePerChunk*2^depth` number of tokens need to be preapproved for this contract.\n * @param _setNonce Nonce that was used for overlay calculation.\n * @param _addAmount Deposited amount of ERC20 tokens, equals to added Potential stake value\n * @param _height increased reserve by registering the number of doublings\n */\n function manageStake(bytes32 _setNonce, uint256 _addAmount, uint8 _height) external whenNotPaused {\n bytes32 _previousOverlay = stakes[msg.sender].overlay;\n uint256 _stakingSet = stakes[msg.sender].lastUpdatedBlockNumber;\n bytes32 _newOverlay = keccak256(abi.encodePacked(msg.sender, reverse(NetworkId), _setNonce));\n uint256 _addCommittedStake = _addAmount / (OracleContract.currentPrice() * 2 ** _height); // losing some decimals from start 10n16 becomes 99999999999984000\n\n // First time adding stake, check the minimum is added, take into account height\n if (_addAmount < MIN_STAKE * 2 ** _height && _stakingSet == 0) {\n revert BelowMinimumStake();\n }\n\n if (_stakingSet != 0 && !addressNotFrozen(msg.sender)) revert Frozen();\n uint256 updatedCommittedStake = stakes[msg.sender].committedStake + _addCommittedStake;\n uint256 updatedPotentialStake = stakes[msg.sender].potentialStake + _addAmount;\n\n stakes[msg.sender] = Stake({\n overlay: _newOverlay,\n committedStake: updatedCommittedStake,\n potentialStake: updatedPotentialStake,\n lastUpdatedBlockNumber: block.number,\n height: _height\n });\n\n // Transfer tokens and emit event that stake has been updated\n if (_addAmount > 0) {\n if (!ERC20(bzzToken).transferFrom(msg.sender, address(this), _addAmount)) revert TransferFailed();\n emit StakeUpdated(\n msg.sender,\n updatedCommittedStake,\n updatedPotentialStake,\n _newOverlay,\n block.number,\n _height\n );\n }\n\n // Emit overlay change event\n if (_previousOverlay != _newOverlay) {\n emit OverlayChanged(msg.sender, _newOverlay);\n }\n }\n\n /**\n * @dev Withdraw node stake surplus\n */\n function withdrawFromStake() external {\n uint256 _potentialStake = stakes[msg.sender].potentialStake;\n uint256 _surplusStake = _potentialStake -\n calculateEffectiveStake(stakes[msg.sender].committedStake, _potentialStake, stakes[msg.sender].height);\n\n if (_surplusStake > 0) {\n stakes[msg.sender].potentialStake -= _surplusStake;\n if (!ERC20(bzzToken).transfer(msg.sender, _surplusStake)) revert TransferFailed();\n emit StakeWithdrawn(msg.sender, _surplusStake);\n }\n }\n\n /**\n * @dev Migrate stake only when the staking contract is paused,\n * can only be called by the owner of the stake\n */\n function migrateStake() external whenPaused {\n // We take out all the stake so user can migrate stake to other contract\n if (lastUpdatedBlockNumberOfAddress(msg.sender) != 0) {\n if (!ERC20(bzzToken).transfer(msg.sender, stakes[msg.sender].potentialStake)) revert TransferFailed();\n delete stakes[msg.sender];\n }\n }\n\n /**\n * @dev Freeze an existing stake, can only be called by the redistributor\n * @param _owner the addres selected\n * @param _time penalty length in blocknumbers\n */\n function freezeDeposit(address _owner, uint256 _time) external {\n if (!hasRole(REDISTRIBUTOR_ROLE, msg.sender)) revert OnlyRedistributor();\n\n if (stakes[_owner].lastUpdatedBlockNumber != 0) {\n stakes[_owner].lastUpdatedBlockNumber = block.number + _time;\n emit StakeFrozen(_owner, stakes[_owner].overlay, _time);\n }\n }\n\n /**\n * @dev Slash an existing stake, can only be called by the `redistributor`\n * @param _owner the _owner adress selected\n * @param _amount the amount to be slashed\n */\n function slashDeposit(address _owner, uint256 _amount) external {\n if (!hasRole(REDISTRIBUTOR_ROLE, msg.sender)) revert OnlyRedistributor();\n\n if (stakes[_owner].lastUpdatedBlockNumber != 0) {\n if (stakes[_owner].potentialStake > _amount) {\n stakes[_owner].potentialStake -= _amount;\n stakes[_owner].lastUpdatedBlockNumber = block.number;\n } else {\n delete stakes[_owner];\n }\n }\n emit StakeSlashed(_owner, stakes[_owner].overlay, _amount);\n }\n\n function changeNetworkId(uint64 _NetworkId) external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) revert Unauthorized();\n NetworkId = _NetworkId;\n }\n\n /**\n * @dev Pause the contract. The contract is provably stopped by renouncing\n the pauser role and the admin role after pausing, can only be called by the `PAUSER`\n */\n function pause() public {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) revert OnlyPauser();\n _pause();\n }\n\n /**\n * @dev Unpause the contract, can only be called by the pauser when paused\n */\n function unPause() public {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) revert OnlyPauser();\n _unpause();\n }\n\n ////////////////////////////////////////\n // STATE READING //\n ////////////////////////////////////////\n\n /**\n * @dev Checks to see if `address` is frozen.\n * @param _owner owner of staked address\n *\n * Returns a boolean value indicating whether the operation succeeded.\n */\n function addressNotFrozen(address _owner) internal view returns (bool) {\n return stakes[_owner].lastUpdatedBlockNumber < block.number;\n }\n\n /**\n * @dev Returns the current `effectiveStake` of `address`. previously usable stake\n * @param _owner _owner of node\n */\n function nodeEffectiveStake(address _owner) public view returns (uint256) {\n return\n addressNotFrozen(_owner)\n ? calculateEffectiveStake(\n stakes[_owner].committedStake,\n stakes[_owner].potentialStake,\n stakes[_owner].height\n )\n : 0;\n }\n\n /**\n * @dev Check the amount that is possible to withdraw as surplus\n */\n function withdrawableStake() public view returns (uint256) {\n uint256 _potentialStake = stakes[msg.sender].potentialStake;\n return\n _potentialStake -\n calculateEffectiveStake(stakes[msg.sender].committedStake, _potentialStake, stakes[msg.sender].height);\n }\n\n /**\n * @dev Returns the `lastUpdatedBlockNumber` of `address`.\n */\n function lastUpdatedBlockNumberOfAddress(address _owner) public view returns (uint256) {\n return stakes[_owner].lastUpdatedBlockNumber;\n }\n\n /**\n * @dev Returns the currently used overlay of the address.\n * @param _owner address of node\n */\n function overlayOfAddress(address _owner) public view returns (bytes32) {\n return stakes[_owner].overlay;\n }\n\n /**\n * @dev Returns the currently height of the address.\n * @param _owner address of node\n */\n function heightOfAddress(address _owner) public view returns (uint8) {\n return stakes[_owner].height;\n }\n\n function calculateEffectiveStake(\n uint256 committedStake,\n uint256 potentialStakeBalance,\n uint8 height\n ) internal view returns (uint256) {\n // Calculate the product of committedStake and unitPrice to get price in BZZ\n uint256 committedStakeBzz = (2 ** height) * committedStake * OracleContract.currentPrice();\n\n // Return the minimum value between committedStakeBzz and potentialStakeBalance\n if (committedStakeBzz < potentialStakeBalance) {\n return committedStakeBzz;\n } else {\n return potentialStakeBalance;\n }\n }\n\n /**\n * @dev Please both Endians 🥚.\n * @param input Eth address used for overlay calculation.\n */\n function reverse(uint64 input) internal pure returns (uint64 v) {\n v = input;\n\n // swap bytes\n v = ((v & 0xFF00FF00FF00FF00) >> 8) | ((v & 0x00FF00FF00FF00FF) << 8);\n\n // swap 2-byte long pairs\n v = ((v & 0xFFFF0000FFFF0000) >> 16) | ((v & 0x0000FFFF0000FFFF) << 16);\n\n // swap 4-byte long pairs\n v = (v >> 32) | (v << 32);\n }\n}\n" }, "src/TestToken.sol": { "content": "// SPDX-License-Identifier: BSD-3-Clause\npragma solidity ^0.8.19;\n\nimport \"@openzeppelin/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol\";\n\ncontract TestToken is ERC20PresetMinterPauser {\n uint256 private _initialSupply;\n\n constructor(string memory name, string memory symbol, uint256 initialSupply) ERC20PresetMinterPauser(name, symbol) {\n _initialSupply = initialSupply;\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n _mint(msg.sender, initialSupply);\n }\n\n // We use 16 decimals for BZZ/sBZZ token so we need to override it here\n function decimals() public view virtual override returns (uint8) {\n return 16;\n }\n}\n" diff --git a/deployments/testnetlight/solcInputs/99c9ef5f7ef53ea99ef6c816b26b1e5c.json b/deployments/testnetlight/solcInputs/99c9ef5f7ef53ea99ef6c816b26b1e5c.json new file mode 100644 index 00000000..de0b639f --- /dev/null +++ b/deployments/testnetlight/solcInputs/99c9ef5f7ef53ea99ef6c816b26b1e5c.json @@ -0,0 +1,118 @@ +{ + "language": "Solidity", + "sources": { + "@openzeppelin/contracts/access/AccessControl.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (access/AccessControl.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IAccessControl.sol\";\nimport \"../utils/Context.sol\";\nimport \"../utils/Strings.sol\";\nimport \"../utils/introspection/ERC165.sol\";\n\n/**\n * @dev Contract module that allows children to implement role-based access\n * control mechanisms. This is a lightweight version that doesn't allow enumerating role\n * members except through off-chain means by accessing the contract event logs. Some\n * applications may benefit from on-chain enumerability, for those cases see\n * {AccessControlEnumerable}.\n *\n * Roles are referred to by their `bytes32` identifier. These should be exposed\n * in the external API and be unique. The best way to achieve this is by\n * using `public constant` hash digests:\n *\n * ```\n * bytes32 public constant MY_ROLE = keccak256(\"MY_ROLE\");\n * ```\n *\n * Roles can be used to represent a set of permissions. To restrict access to a\n * function call, use {hasRole}:\n *\n * ```\n * function foo() public {\n * require(hasRole(MY_ROLE, msg.sender));\n * ...\n * }\n * ```\n *\n * Roles can be granted and revoked dynamically via the {grantRole} and\n * {revokeRole} functions. Each role has an associated admin role, and only\n * accounts that have a role's admin role can call {grantRole} and {revokeRole}.\n *\n * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means\n * that only accounts with this role will be able to grant or revoke other\n * roles. More complex role relationships can be created by using\n * {_setRoleAdmin}.\n *\n * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to\n * grant and revoke this role. Extra precautions should be taken to secure\n * accounts that have been granted it.\n */\nabstract contract AccessControl is Context, IAccessControl, ERC165 {\n struct RoleData {\n mapping(address => bool) members;\n bytes32 adminRole;\n }\n\n mapping(bytes32 => RoleData) private _roles;\n\n bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;\n\n /**\n * @dev Modifier that checks that an account has a specific role. Reverts\n * with a standardized message including the required role.\n *\n * The format of the revert reason is given by the following regular expression:\n *\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\n *\n * _Available since v4.1._\n */\n modifier onlyRole(bytes32 role) {\n _checkRole(role);\n _;\n }\n\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);\n }\n\n /**\n * @dev Returns `true` if `account` has been granted `role`.\n */\n function hasRole(bytes32 role, address account) public view virtual override returns (bool) {\n return _roles[role].members[account];\n }\n\n /**\n * @dev Revert with a standard message if `_msgSender()` is missing `role`.\n * Overriding this function changes the behavior of the {onlyRole} modifier.\n *\n * Format of the revert message is described in {_checkRole}.\n *\n * _Available since v4.6._\n */\n function _checkRole(bytes32 role) internal view virtual {\n _checkRole(role, _msgSender());\n }\n\n /**\n * @dev Revert with a standard message if `account` is missing `role`.\n *\n * The format of the revert reason is given by the following regular expression:\n *\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\n */\n function _checkRole(bytes32 role, address account) internal view virtual {\n if (!hasRole(role, account)) {\n revert(\n string(\n abi.encodePacked(\n \"AccessControl: account \",\n Strings.toHexString(account),\n \" is missing role \",\n Strings.toHexString(uint256(role), 32)\n )\n )\n );\n }\n }\n\n /**\n * @dev Returns the admin role that controls `role`. See {grantRole} and\n * {revokeRole}.\n *\n * To change a role's admin, use {_setRoleAdmin}.\n */\n function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {\n return _roles[role].adminRole;\n }\n\n /**\n * @dev Grants `role` to `account`.\n *\n * If `account` had not been already granted `role`, emits a {RoleGranted}\n * event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n *\n * May emit a {RoleGranted} event.\n */\n function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\n _grantRole(role, account);\n }\n\n /**\n * @dev Revokes `role` from `account`.\n *\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n *\n * May emit a {RoleRevoked} event.\n */\n function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\n _revokeRole(role, account);\n }\n\n /**\n * @dev Revokes `role` from the calling account.\n *\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\n * purpose is to provide a mechanism for accounts to lose their privileges\n * if they are compromised (such as when a trusted device is misplaced).\n *\n * If the calling account had been revoked `role`, emits a {RoleRevoked}\n * event.\n *\n * Requirements:\n *\n * - the caller must be `account`.\n *\n * May emit a {RoleRevoked} event.\n */\n function renounceRole(bytes32 role, address account) public virtual override {\n require(account == _msgSender(), \"AccessControl: can only renounce roles for self\");\n\n _revokeRole(role, account);\n }\n\n /**\n * @dev Grants `role` to `account`.\n *\n * If `account` had not been already granted `role`, emits a {RoleGranted}\n * event. Note that unlike {grantRole}, this function doesn't perform any\n * checks on the calling account.\n *\n * May emit a {RoleGranted} event.\n *\n * [WARNING]\n * ====\n * This function should only be called from the constructor when setting\n * up the initial roles for the system.\n *\n * Using this function in any other way is effectively circumventing the admin\n * system imposed by {AccessControl}.\n * ====\n *\n * NOTE: This function is deprecated in favor of {_grantRole}.\n */\n function _setupRole(bytes32 role, address account) internal virtual {\n _grantRole(role, account);\n }\n\n /**\n * @dev Sets `adminRole` as ``role``'s admin role.\n *\n * Emits a {RoleAdminChanged} event.\n */\n function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {\n bytes32 previousAdminRole = getRoleAdmin(role);\n _roles[role].adminRole = adminRole;\n emit RoleAdminChanged(role, previousAdminRole, adminRole);\n }\n\n /**\n * @dev Grants `role` to `account`.\n *\n * Internal function without access restriction.\n *\n * May emit a {RoleGranted} event.\n */\n function _grantRole(bytes32 role, address account) internal virtual {\n if (!hasRole(role, account)) {\n _roles[role].members[account] = true;\n emit RoleGranted(role, account, _msgSender());\n }\n }\n\n /**\n * @dev Revokes `role` from `account`.\n *\n * Internal function without access restriction.\n *\n * May emit a {RoleRevoked} event.\n */\n function _revokeRole(bytes32 role, address account) internal virtual {\n if (hasRole(role, account)) {\n _roles[role].members[account] = false;\n emit RoleRevoked(role, account, _msgSender());\n }\n }\n}\n" + }, + "@openzeppelin/contracts/access/AccessControlEnumerable.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (access/AccessControlEnumerable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IAccessControlEnumerable.sol\";\nimport \"./AccessControl.sol\";\nimport \"../utils/structs/EnumerableSet.sol\";\n\n/**\n * @dev Extension of {AccessControl} that allows enumerating the members of each role.\n */\nabstract contract AccessControlEnumerable is IAccessControlEnumerable, AccessControl {\n using EnumerableSet for EnumerableSet.AddressSet;\n\n mapping(bytes32 => EnumerableSet.AddressSet) private _roleMembers;\n\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n return interfaceId == type(IAccessControlEnumerable).interfaceId || super.supportsInterface(interfaceId);\n }\n\n /**\n * @dev Returns one of the accounts that have `role`. `index` must be a\n * value between 0 and {getRoleMemberCount}, non-inclusive.\n *\n * Role bearers are not sorted in any particular way, and their ordering may\n * change at any point.\n *\n * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure\n * you perform all queries on the same block. See the following\n * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]\n * for more information.\n */\n function getRoleMember(bytes32 role, uint256 index) public view virtual override returns (address) {\n return _roleMembers[role].at(index);\n }\n\n /**\n * @dev Returns the number of accounts that have `role`. Can be used\n * together with {getRoleMember} to enumerate all bearers of a role.\n */\n function getRoleMemberCount(bytes32 role) public view virtual override returns (uint256) {\n return _roleMembers[role].length();\n }\n\n /**\n * @dev Overload {_grantRole} to track enumerable memberships\n */\n function _grantRole(bytes32 role, address account) internal virtual override {\n super._grantRole(role, account);\n _roleMembers[role].add(account);\n }\n\n /**\n * @dev Overload {_revokeRole} to track enumerable memberships\n */\n function _revokeRole(bytes32 role, address account) internal virtual override {\n super._revokeRole(role, account);\n _roleMembers[role].remove(account);\n }\n}\n" + }, + "@openzeppelin/contracts/access/IAccessControl.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev External interface of AccessControl declared to support ERC165 detection.\n */\ninterface IAccessControl {\n /**\n * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`\n *\n * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite\n * {RoleAdminChanged} not being emitted signaling this.\n *\n * _Available since v3.1._\n */\n event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);\n\n /**\n * @dev Emitted when `account` is granted `role`.\n *\n * `sender` is the account that originated the contract call, an admin role\n * bearer except when using {AccessControl-_setupRole}.\n */\n event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);\n\n /**\n * @dev Emitted when `account` is revoked `role`.\n *\n * `sender` is the account that originated the contract call:\n * - if using `revokeRole`, it is the admin role bearer\n * - if using `renounceRole`, it is the role bearer (i.e. `account`)\n */\n event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);\n\n /**\n * @dev Returns `true` if `account` has been granted `role`.\n */\n function hasRole(bytes32 role, address account) external view returns (bool);\n\n /**\n * @dev Returns the admin role that controls `role`. See {grantRole} and\n * {revokeRole}.\n *\n * To change a role's admin, use {AccessControl-_setRoleAdmin}.\n */\n function getRoleAdmin(bytes32 role) external view returns (bytes32);\n\n /**\n * @dev Grants `role` to `account`.\n *\n * If `account` had not been already granted `role`, emits a {RoleGranted}\n * event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n */\n function grantRole(bytes32 role, address account) external;\n\n /**\n * @dev Revokes `role` from `account`.\n *\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n */\n function revokeRole(bytes32 role, address account) external;\n\n /**\n * @dev Revokes `role` from the calling account.\n *\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\n * purpose is to provide a mechanism for accounts to lose their privileges\n * if they are compromised (such as when a trusted device is misplaced).\n *\n * If the calling account had been granted `role`, emits a {RoleRevoked}\n * event.\n *\n * Requirements:\n *\n * - the caller must be `account`.\n */\n function renounceRole(bytes32 role, address account) external;\n}\n" + }, + "@openzeppelin/contracts/access/IAccessControlEnumerable.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (access/IAccessControlEnumerable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IAccessControl.sol\";\n\n/**\n * @dev External interface of AccessControlEnumerable declared to support ERC165 detection.\n */\ninterface IAccessControlEnumerable is IAccessControl {\n /**\n * @dev Returns one of the accounts that have `role`. `index` must be a\n * value between 0 and {getRoleMemberCount}, non-inclusive.\n *\n * Role bearers are not sorted in any particular way, and their ordering may\n * change at any point.\n *\n * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure\n * you perform all queries on the same block. See the following\n * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]\n * for more information.\n */\n function getRoleMember(bytes32 role, uint256 index) external view returns (address);\n\n /**\n * @dev Returns the number of accounts that have `role`. Can be used\n * together with {getRoleMember} to enumerate all bearers of a role.\n */\n function getRoleMemberCount(bytes32 role) external view returns (uint256);\n}\n" + }, + "@openzeppelin/contracts/security/Pausable.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which allows children to implement an emergency stop\n * mechanism that can be triggered by an authorized account.\n *\n * This module is used through inheritance. It will make available the\n * modifiers `whenNotPaused` and `whenPaused`, which can be applied to\n * the functions of your contract. Note that they will not be pausable by\n * simply including this module, only once the modifiers are put in place.\n */\nabstract contract Pausable is Context {\n /**\n * @dev Emitted when the pause is triggered by `account`.\n */\n event Paused(address account);\n\n /**\n * @dev Emitted when the pause is lifted by `account`.\n */\n event Unpaused(address account);\n\n bool private _paused;\n\n /**\n * @dev Initializes the contract in unpaused state.\n */\n constructor() {\n _paused = false;\n }\n\n /**\n * @dev Modifier to make a function callable only when the contract is not paused.\n *\n * Requirements:\n *\n * - The contract must not be paused.\n */\n modifier whenNotPaused() {\n _requireNotPaused();\n _;\n }\n\n /**\n * @dev Modifier to make a function callable only when the contract is paused.\n *\n * Requirements:\n *\n * - The contract must be paused.\n */\n modifier whenPaused() {\n _requirePaused();\n _;\n }\n\n /**\n * @dev Returns true if the contract is paused, and false otherwise.\n */\n function paused() public view virtual returns (bool) {\n return _paused;\n }\n\n /**\n * @dev Throws if the contract is paused.\n */\n function _requireNotPaused() internal view virtual {\n require(!paused(), \"Pausable: paused\");\n }\n\n /**\n * @dev Throws if the contract is not paused.\n */\n function _requirePaused() internal view virtual {\n require(paused(), \"Pausable: not paused\");\n }\n\n /**\n * @dev Triggers stopped state.\n *\n * Requirements:\n *\n * - The contract must not be paused.\n */\n function _pause() internal virtual whenNotPaused {\n _paused = true;\n emit Paused(_msgSender());\n }\n\n /**\n * @dev Returns to normal state.\n *\n * Requirements:\n *\n * - The contract must be paused.\n */\n function _unpause() internal virtual whenPaused {\n _paused = false;\n emit Unpaused(_msgSender());\n }\n}\n" + }, + "@openzeppelin/contracts/token/ERC20/ERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/ERC20.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC20.sol\";\nimport \"./extensions/IERC20Metadata.sol\";\nimport \"../../utils/Context.sol\";\n\n/**\n * @dev Implementation of the {IERC20} interface.\n *\n * This implementation is agnostic to the way tokens are created. This means\n * that a supply mechanism has to be added in a derived contract using {_mint}.\n * For a generic mechanism see {ERC20PresetMinterPauser}.\n *\n * TIP: For a detailed writeup see our guide\n * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How\n * to implement supply mechanisms].\n *\n * We have followed general OpenZeppelin Contracts guidelines: functions revert\n * instead returning `false` on failure. This behavior is nonetheless\n * conventional and does not conflict with the expectations of ERC20\n * applications.\n *\n * Additionally, an {Approval} event is emitted on calls to {transferFrom}.\n * This allows applications to reconstruct the allowance for all accounts just\n * by listening to said events. Other implementations of the EIP may not emit\n * these events, as it isn't required by the specification.\n *\n * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}\n * functions have been added to mitigate the well-known issues around setting\n * allowances. See {IERC20-approve}.\n */\ncontract ERC20 is Context, IERC20, IERC20Metadata {\n mapping(address => uint256) private _balances;\n\n mapping(address => mapping(address => uint256)) private _allowances;\n\n uint256 private _totalSupply;\n\n string private _name;\n string private _symbol;\n\n /**\n * @dev Sets the values for {name} and {symbol}.\n *\n * The default value of {decimals} is 18. To select a different value for\n * {decimals} you should overload it.\n *\n * All two of these values are immutable: they can only be set once during\n * construction.\n */\n constructor(string memory name_, string memory symbol_) {\n _name = name_;\n _symbol = symbol_;\n }\n\n /**\n * @dev Returns the name of the token.\n */\n function name() public view virtual override returns (string memory) {\n return _name;\n }\n\n /**\n * @dev Returns the symbol of the token, usually a shorter version of the\n * name.\n */\n function symbol() public view virtual override returns (string memory) {\n return _symbol;\n }\n\n /**\n * @dev Returns the number of decimals used to get its user representation.\n * For example, if `decimals` equals `2`, a balance of `505` tokens should\n * be displayed to a user as `5.05` (`505 / 10 ** 2`).\n *\n * Tokens usually opt for a value of 18, imitating the relationship between\n * Ether and Wei. This is the value {ERC20} uses, unless this function is\n * overridden;\n *\n * NOTE: This information is only used for _display_ purposes: it in\n * no way affects any of the arithmetic of the contract, including\n * {IERC20-balanceOf} and {IERC20-transfer}.\n */\n function decimals() public view virtual override returns (uint8) {\n return 18;\n }\n\n /**\n * @dev See {IERC20-totalSupply}.\n */\n function totalSupply() public view virtual override returns (uint256) {\n return _totalSupply;\n }\n\n /**\n * @dev See {IERC20-balanceOf}.\n */\n function balanceOf(address account) public view virtual override returns (uint256) {\n return _balances[account];\n }\n\n /**\n * @dev See {IERC20-transfer}.\n *\n * Requirements:\n *\n * - `to` cannot be the zero address.\n * - the caller must have a balance of at least `amount`.\n */\n function transfer(address to, uint256 amount) public virtual override returns (bool) {\n address owner = _msgSender();\n _transfer(owner, to, amount);\n return true;\n }\n\n /**\n * @dev See {IERC20-allowance}.\n */\n function allowance(address owner, address spender) public view virtual override returns (uint256) {\n return _allowances[owner][spender];\n }\n\n /**\n * @dev See {IERC20-approve}.\n *\n * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on\n * `transferFrom`. This is semantically equivalent to an infinite approval.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function approve(address spender, uint256 amount) public virtual override returns (bool) {\n address owner = _msgSender();\n _approve(owner, spender, amount);\n return true;\n }\n\n /**\n * @dev See {IERC20-transferFrom}.\n *\n * Emits an {Approval} event indicating the updated allowance. This is not\n * required by the EIP. See the note at the beginning of {ERC20}.\n *\n * NOTE: Does not update the allowance if the current allowance\n * is the maximum `uint256`.\n *\n * Requirements:\n *\n * - `from` and `to` cannot be the zero address.\n * - `from` must have a balance of at least `amount`.\n * - the caller must have allowance for ``from``'s tokens of at least\n * `amount`.\n */\n function transferFrom(\n address from,\n address to,\n uint256 amount\n ) public virtual override returns (bool) {\n address spender = _msgSender();\n _spendAllowance(from, spender, amount);\n _transfer(from, to, amount);\n return true;\n }\n\n /**\n * @dev Atomically increases the allowance granted to `spender` by the caller.\n *\n * This is an alternative to {approve} that can be used as a mitigation for\n * problems described in {IERC20-approve}.\n *\n * Emits an {Approval} event indicating the updated allowance.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {\n address owner = _msgSender();\n _approve(owner, spender, allowance(owner, spender) + addedValue);\n return true;\n }\n\n /**\n * @dev Atomically decreases the allowance granted to `spender` by the caller.\n *\n * This is an alternative to {approve} that can be used as a mitigation for\n * problems described in {IERC20-approve}.\n *\n * Emits an {Approval} event indicating the updated allowance.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n * - `spender` must have allowance for the caller of at least\n * `subtractedValue`.\n */\n function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {\n address owner = _msgSender();\n uint256 currentAllowance = allowance(owner, spender);\n require(currentAllowance >= subtractedValue, \"ERC20: decreased allowance below zero\");\n unchecked {\n _approve(owner, spender, currentAllowance - subtractedValue);\n }\n\n return true;\n }\n\n /**\n * @dev Moves `amount` of tokens from `from` to `to`.\n *\n * This internal function is equivalent to {transfer}, and can be used to\n * e.g. implement automatic token fees, slashing mechanisms, etc.\n *\n * Emits a {Transfer} event.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `from` must have a balance of at least `amount`.\n */\n function _transfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual {\n require(from != address(0), \"ERC20: transfer from the zero address\");\n require(to != address(0), \"ERC20: transfer to the zero address\");\n\n _beforeTokenTransfer(from, to, amount);\n\n uint256 fromBalance = _balances[from];\n require(fromBalance >= amount, \"ERC20: transfer amount exceeds balance\");\n unchecked {\n _balances[from] = fromBalance - amount;\n // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by\n // decrementing then incrementing.\n _balances[to] += amount;\n }\n\n emit Transfer(from, to, amount);\n\n _afterTokenTransfer(from, to, amount);\n }\n\n /** @dev Creates `amount` tokens and assigns them to `account`, increasing\n * the total supply.\n *\n * Emits a {Transfer} event with `from` set to the zero address.\n *\n * Requirements:\n *\n * - `account` cannot be the zero address.\n */\n function _mint(address account, uint256 amount) internal virtual {\n require(account != address(0), \"ERC20: mint to the zero address\");\n\n _beforeTokenTransfer(address(0), account, amount);\n\n _totalSupply += amount;\n unchecked {\n // Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.\n _balances[account] += amount;\n }\n emit Transfer(address(0), account, amount);\n\n _afterTokenTransfer(address(0), account, amount);\n }\n\n /**\n * @dev Destroys `amount` tokens from `account`, reducing the\n * total supply.\n *\n * Emits a {Transfer} event with `to` set to the zero address.\n *\n * Requirements:\n *\n * - `account` cannot be the zero address.\n * - `account` must have at least `amount` tokens.\n */\n function _burn(address account, uint256 amount) internal virtual {\n require(account != address(0), \"ERC20: burn from the zero address\");\n\n _beforeTokenTransfer(account, address(0), amount);\n\n uint256 accountBalance = _balances[account];\n require(accountBalance >= amount, \"ERC20: burn amount exceeds balance\");\n unchecked {\n _balances[account] = accountBalance - amount;\n // Overflow not possible: amount <= accountBalance <= totalSupply.\n _totalSupply -= amount;\n }\n\n emit Transfer(account, address(0), amount);\n\n _afterTokenTransfer(account, address(0), amount);\n }\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.\n *\n * This internal function is equivalent to `approve`, and can be used to\n * e.g. set automatic allowances for certain subsystems, etc.\n *\n * Emits an {Approval} event.\n *\n * Requirements:\n *\n * - `owner` cannot be the zero address.\n * - `spender` cannot be the zero address.\n */\n function _approve(\n address owner,\n address spender,\n uint256 amount\n ) internal virtual {\n require(owner != address(0), \"ERC20: approve from the zero address\");\n require(spender != address(0), \"ERC20: approve to the zero address\");\n\n _allowances[owner][spender] = amount;\n emit Approval(owner, spender, amount);\n }\n\n /**\n * @dev Updates `owner` s allowance for `spender` based on spent `amount`.\n *\n * Does not update the allowance amount in case of infinite allowance.\n * Revert if not enough allowance is available.\n *\n * Might emit an {Approval} event.\n */\n function _spendAllowance(\n address owner,\n address spender,\n uint256 amount\n ) internal virtual {\n uint256 currentAllowance = allowance(owner, spender);\n if (currentAllowance != type(uint256).max) {\n require(currentAllowance >= amount, \"ERC20: insufficient allowance\");\n unchecked {\n _approve(owner, spender, currentAllowance - amount);\n }\n }\n }\n\n /**\n * @dev Hook that is called before any transfer of tokens. This includes\n * minting and burning.\n *\n * Calling conditions:\n *\n * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n * will be transferred to `to`.\n * - when `from` is zero, `amount` tokens will be minted for `to`.\n * - when `to` is zero, `amount` of ``from``'s tokens will be burned.\n * - `from` and `to` are never both zero.\n *\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n */\n function _beforeTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual {}\n\n /**\n * @dev Hook that is called after any transfer of tokens. This includes\n * minting and burning.\n *\n * Calling conditions:\n *\n * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n * has been transferred to `to`.\n * - when `from` is zero, `amount` tokens have been minted for `to`.\n * - when `to` is zero, `amount` of ``from``'s tokens have been burned.\n * - `from` and `to` are never both zero.\n *\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n */\n function _afterTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual {}\n}\n" + }, + "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/extensions/ERC20Burnable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../ERC20.sol\";\nimport \"../../../utils/Context.sol\";\n\n/**\n * @dev Extension of {ERC20} that allows token holders to destroy both their own\n * tokens and those that they have an allowance for, in a way that can be\n * recognized off-chain (via event analysis).\n */\nabstract contract ERC20Burnable is Context, ERC20 {\n /**\n * @dev Destroys `amount` tokens from the caller.\n *\n * See {ERC20-_burn}.\n */\n function burn(uint256 amount) public virtual {\n _burn(_msgSender(), amount);\n }\n\n /**\n * @dev Destroys `amount` tokens from `account`, deducting from the caller's\n * allowance.\n *\n * See {ERC20-_burn} and {ERC20-allowance}.\n *\n * Requirements:\n *\n * - the caller must have allowance for ``accounts``'s tokens of at least\n * `amount`.\n */\n function burnFrom(address account, uint256 amount) public virtual {\n _spendAllowance(account, _msgSender(), amount);\n _burn(account, amount);\n }\n}\n" + }, + "@openzeppelin/contracts/token/ERC20/extensions/ERC20Pausable.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.2) (token/ERC20/extensions/ERC20Pausable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../ERC20.sol\";\nimport \"../../../security/Pausable.sol\";\n\n/**\n * @dev ERC20 token with pausable token transfers, minting and burning.\n *\n * Useful for scenarios such as preventing trades until the end of an evaluation\n * period, or having an emergency switch for freezing all token transfers in the\n * event of a large bug.\n *\n * IMPORTANT: This contract does not include public pause and unpause functions. In\n * addition to inheriting this contract, you must define both functions, invoking the\n * {Pausable-_pause} and {Pausable-_unpause} internal functions, with appropriate\n * access control, e.g. using {AccessControl} or {Ownable}. Not doing so will\n * make the contract unpausable.\n */\nabstract contract ERC20Pausable is ERC20, Pausable {\n /**\n * @dev See {ERC20-_beforeTokenTransfer}.\n *\n * Requirements:\n *\n * - the contract must not be paused.\n */\n function _beforeTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual override {\n super._beforeTokenTransfer(from, to, amount);\n\n require(!paused(), \"ERC20Pausable: token transfer while paused\");\n }\n}\n" + }, + "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20.sol\";\n\n/**\n * @dev Interface for the optional metadata functions from the ERC20 standard.\n *\n * _Available since v4.1._\n */\ninterface IERC20Metadata is IERC20 {\n /**\n * @dev Returns the name of the token.\n */\n function name() external view returns (string memory);\n\n /**\n * @dev Returns the symbol of the token.\n */\n function symbol() external view returns (string memory);\n\n /**\n * @dev Returns the decimals places of the token.\n */\n function decimals() external view returns (uint8);\n}\n" + }, + "@openzeppelin/contracts/token/ERC20/IERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n /**\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\n * another (`to`).\n *\n * Note that `value` may be zero.\n */\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n /**\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n * a call to {approve}. `value` is the new allowance.\n */\n event Approval(address indexed owner, address indexed spender, uint256 value);\n\n /**\n * @dev Returns the amount of tokens in existence.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns the amount of tokens owned by `account`.\n */\n function balanceOf(address account) external view returns (uint256);\n\n /**\n * @dev Moves `amount` tokens from the caller's account to `to`.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transfer(address to, uint256 amount) external returns (bool);\n\n /**\n * @dev Returns the remaining number of tokens that `spender` will be\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\n * zero by default.\n *\n * This value changes when {approve} or {transferFrom} are called.\n */\n function allowance(address owner, address spender) external view returns (uint256);\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\n * that someone may use both the old and the new allowance by unfortunate\n * transaction ordering. One possible solution to mitigate this race\n * condition is to first reduce the spender's allowance to 0 and set the\n * desired value afterwards:\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n *\n * Emits an {Approval} event.\n */\n function approve(address spender, uint256 amount) external returns (bool);\n\n /**\n * @dev Moves `amount` tokens from `from` to `to` using the\n * allowance mechanism. `amount` is then deducted from the caller's\n * allowance.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(\n address from,\n address to,\n uint256 amount\n ) external returns (bool);\n}\n" + }, + "@openzeppelin/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/presets/ERC20PresetMinterPauser.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../ERC20.sol\";\nimport \"../extensions/ERC20Burnable.sol\";\nimport \"../extensions/ERC20Pausable.sol\";\nimport \"../../../access/AccessControlEnumerable.sol\";\nimport \"../../../utils/Context.sol\";\n\n/**\n * @dev {ERC20} token, including:\n *\n * - ability for holders to burn (destroy) their tokens\n * - a minter role that allows for token minting (creation)\n * - a pauser role that allows to stop all token transfers\n *\n * This contract uses {AccessControl} to lock permissioned functions using the\n * different roles - head to its documentation for details.\n *\n * The account that deploys the contract will be granted the minter and pauser\n * roles, as well as the default admin role, which will let it grant both minter\n * and pauser roles to other accounts.\n *\n * _Deprecated in favor of https://wizard.openzeppelin.com/[Contracts Wizard]._\n */\ncontract ERC20PresetMinterPauser is Context, AccessControlEnumerable, ERC20Burnable, ERC20Pausable {\n bytes32 public constant MINTER_ROLE = keccak256(\"MINTER_ROLE\");\n bytes32 public constant PAUSER_ROLE = keccak256(\"PAUSER_ROLE\");\n\n /**\n * @dev Grants `DEFAULT_ADMIN_ROLE`, `MINTER_ROLE` and `PAUSER_ROLE` to the\n * account that deploys the contract.\n *\n * See {ERC20-constructor}.\n */\n constructor(string memory name, string memory symbol) ERC20(name, symbol) {\n _setupRole(DEFAULT_ADMIN_ROLE, _msgSender());\n\n _setupRole(MINTER_ROLE, _msgSender());\n _setupRole(PAUSER_ROLE, _msgSender());\n }\n\n /**\n * @dev Creates `amount` new tokens for `to`.\n *\n * See {ERC20-_mint}.\n *\n * Requirements:\n *\n * - the caller must have the `MINTER_ROLE`.\n */\n function mint(address to, uint256 amount) public virtual {\n require(hasRole(MINTER_ROLE, _msgSender()), \"ERC20PresetMinterPauser: must have minter role to mint\");\n _mint(to, amount);\n }\n\n /**\n * @dev Pauses all token transfers.\n *\n * See {ERC20Pausable} and {Pausable-_pause}.\n *\n * Requirements:\n *\n * - the caller must have the `PAUSER_ROLE`.\n */\n function pause() public virtual {\n require(hasRole(PAUSER_ROLE, _msgSender()), \"ERC20PresetMinterPauser: must have pauser role to pause\");\n _pause();\n }\n\n /**\n * @dev Unpauses all token transfers.\n *\n * See {ERC20Pausable} and {Pausable-_unpause}.\n *\n * Requirements:\n *\n * - the caller must have the `PAUSER_ROLE`.\n */\n function unpause() public virtual {\n require(hasRole(PAUSER_ROLE, _msgSender()), \"ERC20PresetMinterPauser: must have pauser role to unpause\");\n _unpause();\n }\n\n function _beforeTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual override(ERC20, ERC20Pausable) {\n super._beforeTokenTransfer(from, to, amount);\n }\n}\n" + }, + "@openzeppelin/contracts/utils/Context.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n}\n" + }, + "@openzeppelin/contracts/utils/introspection/ERC165.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC165.sol\";\n\n/**\n * @dev Implementation of the {IERC165} interface.\n *\n * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check\n * for the additional interface id that will be supported. For example:\n *\n * ```solidity\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\n * }\n * ```\n *\n * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.\n */\nabstract contract ERC165 is IERC165 {\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n return interfaceId == type(IERC165).interfaceId;\n }\n}\n" + }, + "@openzeppelin/contracts/utils/introspection/IERC165.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC165 standard, as defined in the\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\n *\n * Implementers can declare support of contract interfaces, which can then be\n * queried by others ({ERC165Checker}).\n *\n * For an implementation, see {ERC165}.\n */\ninterface IERC165 {\n /**\n * @dev Returns true if this contract implements the interface defined by\n * `interfaceId`. See the corresponding\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\n * to learn more about how these ids are created.\n *\n * This function call must use less than 30 000 gas.\n */\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n" + }, + "@openzeppelin/contracts/utils/math/Math.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Standard math utilities missing in the Solidity language.\n */\nlibrary Math {\n enum Rounding {\n Down, // Toward negative infinity\n Up, // Toward infinity\n Zero // Toward zero\n }\n\n /**\n * @dev Returns the largest of two numbers.\n */\n function max(uint256 a, uint256 b) internal pure returns (uint256) {\n return a > b ? a : b;\n }\n\n /**\n * @dev Returns the smallest of two numbers.\n */\n function min(uint256 a, uint256 b) internal pure returns (uint256) {\n return a < b ? a : b;\n }\n\n /**\n * @dev Returns the average of two numbers. The result is rounded towards\n * zero.\n */\n function average(uint256 a, uint256 b) internal pure returns (uint256) {\n // (a + b) / 2 can overflow.\n return (a & b) + (a ^ b) / 2;\n }\n\n /**\n * @dev Returns the ceiling of the division of two numbers.\n *\n * This differs from standard division with `/` in that it rounds up instead\n * of rounding down.\n */\n function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {\n // (a + b - 1) / b can overflow on addition, so we distribute.\n return a == 0 ? 0 : (a - 1) / b + 1;\n }\n\n /**\n * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0\n * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)\n * with further edits by Uniswap Labs also under MIT license.\n */\n function mulDiv(\n uint256 x,\n uint256 y,\n uint256 denominator\n ) internal pure returns (uint256 result) {\n unchecked {\n // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use\n // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256\n // variables such that product = prod1 * 2^256 + prod0.\n uint256 prod0; // Least significant 256 bits of the product\n uint256 prod1; // Most significant 256 bits of the product\n assembly {\n let mm := mulmod(x, y, not(0))\n prod0 := mul(x, y)\n prod1 := sub(sub(mm, prod0), lt(mm, prod0))\n }\n\n // Handle non-overflow cases, 256 by 256 division.\n if (prod1 == 0) {\n return prod0 / denominator;\n }\n\n // Make sure the result is less than 2^256. Also prevents denominator == 0.\n require(denominator > prod1);\n\n ///////////////////////////////////////////////\n // 512 by 256 division.\n ///////////////////////////////////////////////\n\n // Make division exact by subtracting the remainder from [prod1 prod0].\n uint256 remainder;\n assembly {\n // Compute remainder using mulmod.\n remainder := mulmod(x, y, denominator)\n\n // Subtract 256 bit number from 512 bit number.\n prod1 := sub(prod1, gt(remainder, prod0))\n prod0 := sub(prod0, remainder)\n }\n\n // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.\n // See https://cs.stackexchange.com/q/138556/92363.\n\n // Does not overflow because the denominator cannot be zero at this stage in the function.\n uint256 twos = denominator & (~denominator + 1);\n assembly {\n // Divide denominator by twos.\n denominator := div(denominator, twos)\n\n // Divide [prod1 prod0] by twos.\n prod0 := div(prod0, twos)\n\n // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.\n twos := add(div(sub(0, twos), twos), 1)\n }\n\n // Shift in bits from prod1 into prod0.\n prod0 |= prod1 * twos;\n\n // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such\n // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for\n // four bits. That is, denominator * inv = 1 mod 2^4.\n uint256 inverse = (3 * denominator) ^ 2;\n\n // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works\n // in modular arithmetic, doubling the correct bits in each step.\n inverse *= 2 - denominator * inverse; // inverse mod 2^8\n inverse *= 2 - denominator * inverse; // inverse mod 2^16\n inverse *= 2 - denominator * inverse; // inverse mod 2^32\n inverse *= 2 - denominator * inverse; // inverse mod 2^64\n inverse *= 2 - denominator * inverse; // inverse mod 2^128\n inverse *= 2 - denominator * inverse; // inverse mod 2^256\n\n // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.\n // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is\n // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1\n // is no longer required.\n result = prod0 * inverse;\n return result;\n }\n }\n\n /**\n * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.\n */\n function mulDiv(\n uint256 x,\n uint256 y,\n uint256 denominator,\n Rounding rounding\n ) internal pure returns (uint256) {\n uint256 result = mulDiv(x, y, denominator);\n if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {\n result += 1;\n }\n return result;\n }\n\n /**\n * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.\n *\n * Inspired by Henry S. Warren, Jr.'s \"Hacker's Delight\" (Chapter 11).\n */\n function sqrt(uint256 a) internal pure returns (uint256) {\n if (a == 0) {\n return 0;\n }\n\n // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.\n //\n // We know that the \"msb\" (most significant bit) of our target number `a` is a power of 2 such that we have\n // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.\n //\n // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`\n // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`\n // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`\n //\n // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.\n uint256 result = 1 << (log2(a) >> 1);\n\n // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,\n // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at\n // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision\n // into the expected uint128 result.\n unchecked {\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n return min(result, a / result);\n }\n }\n\n /**\n * @notice Calculates sqrt(a), following the selected rounding direction.\n */\n function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = sqrt(a);\n return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);\n }\n }\n\n /**\n * @dev Return the log in base 2, rounded down, of a positive value.\n * Returns 0 if given 0.\n */\n function log2(uint256 value) internal pure returns (uint256) {\n uint256 result = 0;\n unchecked {\n if (value >> 128 > 0) {\n value >>= 128;\n result += 128;\n }\n if (value >> 64 > 0) {\n value >>= 64;\n result += 64;\n }\n if (value >> 32 > 0) {\n value >>= 32;\n result += 32;\n }\n if (value >> 16 > 0) {\n value >>= 16;\n result += 16;\n }\n if (value >> 8 > 0) {\n value >>= 8;\n result += 8;\n }\n if (value >> 4 > 0) {\n value >>= 4;\n result += 4;\n }\n if (value >> 2 > 0) {\n value >>= 2;\n result += 2;\n }\n if (value >> 1 > 0) {\n result += 1;\n }\n }\n return result;\n }\n\n /**\n * @dev Return the log in base 2, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log2(value);\n return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);\n }\n }\n\n /**\n * @dev Return the log in base 10, rounded down, of a positive value.\n * Returns 0 if given 0.\n */\n function log10(uint256 value) internal pure returns (uint256) {\n uint256 result = 0;\n unchecked {\n if (value >= 10**64) {\n value /= 10**64;\n result += 64;\n }\n if (value >= 10**32) {\n value /= 10**32;\n result += 32;\n }\n if (value >= 10**16) {\n value /= 10**16;\n result += 16;\n }\n if (value >= 10**8) {\n value /= 10**8;\n result += 8;\n }\n if (value >= 10**4) {\n value /= 10**4;\n result += 4;\n }\n if (value >= 10**2) {\n value /= 10**2;\n result += 2;\n }\n if (value >= 10**1) {\n result += 1;\n }\n }\n return result;\n }\n\n /**\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log10(value);\n return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);\n }\n }\n\n /**\n * @dev Return the log in base 256, rounded down, of a positive value.\n * Returns 0 if given 0.\n *\n * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.\n */\n function log256(uint256 value) internal pure returns (uint256) {\n uint256 result = 0;\n unchecked {\n if (value >> 128 > 0) {\n value >>= 128;\n result += 16;\n }\n if (value >> 64 > 0) {\n value >>= 64;\n result += 8;\n }\n if (value >> 32 > 0) {\n value >>= 32;\n result += 4;\n }\n if (value >> 16 > 0) {\n value >>= 16;\n result += 2;\n }\n if (value >> 8 > 0) {\n result += 1;\n }\n }\n return result;\n }\n\n /**\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log256(value);\n return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);\n }\n }\n}\n" + }, + "@openzeppelin/contracts/utils/Strings.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./math/Math.sol\";\n\n/**\n * @dev String operations.\n */\nlibrary Strings {\n bytes16 private constant _SYMBOLS = \"0123456789abcdef\";\n uint8 private constant _ADDRESS_LENGTH = 20;\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` decimal representation.\n */\n function toString(uint256 value) internal pure returns (string memory) {\n unchecked {\n uint256 length = Math.log10(value) + 1;\n string memory buffer = new string(length);\n uint256 ptr;\n /// @solidity memory-safe-assembly\n assembly {\n ptr := add(buffer, add(32, length))\n }\n while (true) {\n ptr--;\n /// @solidity memory-safe-assembly\n assembly {\n mstore8(ptr, byte(mod(value, 10), _SYMBOLS))\n }\n value /= 10;\n if (value == 0) break;\n }\n return buffer;\n }\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\n */\n function toHexString(uint256 value) internal pure returns (string memory) {\n unchecked {\n return toHexString(value, Math.log256(value) + 1);\n }\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\n */\n function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\n bytes memory buffer = new bytes(2 * length + 2);\n buffer[0] = \"0\";\n buffer[1] = \"x\";\n for (uint256 i = 2 * length + 1; i > 1; --i) {\n buffer[i] = _SYMBOLS[value & 0xf];\n value >>= 4;\n }\n require(value == 0, \"Strings: hex length insufficient\");\n return string(buffer);\n }\n\n /**\n * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.\n */\n function toHexString(address addr) internal pure returns (string memory) {\n return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);\n }\n}\n" + }, + "@openzeppelin/contracts/utils/structs/EnumerableSet.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/structs/EnumerableSet.sol)\n// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Library for managing\n * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive\n * types.\n *\n * Sets have the following properties:\n *\n * - Elements are added, removed, and checked for existence in constant time\n * (O(1)).\n * - Elements are enumerated in O(n). No guarantees are made on the ordering.\n *\n * ```\n * contract Example {\n * // Add the library methods\n * using EnumerableSet for EnumerableSet.AddressSet;\n *\n * // Declare a set state variable\n * EnumerableSet.AddressSet private mySet;\n * }\n * ```\n *\n * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)\n * and `uint256` (`UintSet`) are supported.\n *\n * [WARNING]\n * ====\n * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure\n * unusable.\n * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.\n *\n * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an\n * array of EnumerableSet.\n * ====\n */\nlibrary EnumerableSet {\n // To implement this library for multiple types with as little code\n // repetition as possible, we write it in terms of a generic Set type with\n // bytes32 values.\n // The Set implementation uses private functions, and user-facing\n // implementations (such as AddressSet) are just wrappers around the\n // underlying Set.\n // This means that we can only create new EnumerableSets for types that fit\n // in bytes32.\n\n struct Set {\n // Storage of set values\n bytes32[] _values;\n // Position of the value in the `values` array, plus 1 because index 0\n // means a value is not in the set.\n mapping(bytes32 => uint256) _indexes;\n }\n\n /**\n * @dev Add a value to a set. O(1).\n *\n * Returns true if the value was added to the set, that is if it was not\n * already present.\n */\n function _add(Set storage set, bytes32 value) private returns (bool) {\n if (!_contains(set, value)) {\n set._values.push(value);\n // The value is stored at length-1, but we add 1 to all indexes\n // and use 0 as a sentinel value\n set._indexes[value] = set._values.length;\n return true;\n } else {\n return false;\n }\n }\n\n /**\n * @dev Removes a value from a set. O(1).\n *\n * Returns true if the value was removed from the set, that is if it was\n * present.\n */\n function _remove(Set storage set, bytes32 value) private returns (bool) {\n // We read and store the value's index to prevent multiple reads from the same storage slot\n uint256 valueIndex = set._indexes[value];\n\n if (valueIndex != 0) {\n // Equivalent to contains(set, value)\n // To delete an element from the _values array in O(1), we swap the element to delete with the last one in\n // the array, and then remove the last element (sometimes called as 'swap and pop').\n // This modifies the order of the array, as noted in {at}.\n\n uint256 toDeleteIndex = valueIndex - 1;\n uint256 lastIndex = set._values.length - 1;\n\n if (lastIndex != toDeleteIndex) {\n bytes32 lastValue = set._values[lastIndex];\n\n // Move the last value to the index where the value to delete is\n set._values[toDeleteIndex] = lastValue;\n // Update the index for the moved value\n set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex\n }\n\n // Delete the slot where the moved value was stored\n set._values.pop();\n\n // Delete the index for the deleted slot\n delete set._indexes[value];\n\n return true;\n } else {\n return false;\n }\n }\n\n /**\n * @dev Returns true if the value is in the set. O(1).\n */\n function _contains(Set storage set, bytes32 value) private view returns (bool) {\n return set._indexes[value] != 0;\n }\n\n /**\n * @dev Returns the number of values on the set. O(1).\n */\n function _length(Set storage set) private view returns (uint256) {\n return set._values.length;\n }\n\n /**\n * @dev Returns the value stored at position `index` in the set. O(1).\n *\n * Note that there are no guarantees on the ordering of values inside the\n * array, and it may change when more values are added or removed.\n *\n * Requirements:\n *\n * - `index` must be strictly less than {length}.\n */\n function _at(Set storage set, uint256 index) private view returns (bytes32) {\n return set._values[index];\n }\n\n /**\n * @dev Return the entire set in an array\n *\n * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n */\n function _values(Set storage set) private view returns (bytes32[] memory) {\n return set._values;\n }\n\n // Bytes32Set\n\n struct Bytes32Set {\n Set _inner;\n }\n\n /**\n * @dev Add a value to a set. O(1).\n *\n * Returns true if the value was added to the set, that is if it was not\n * already present.\n */\n function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {\n return _add(set._inner, value);\n }\n\n /**\n * @dev Removes a value from a set. O(1).\n *\n * Returns true if the value was removed from the set, that is if it was\n * present.\n */\n function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {\n return _remove(set._inner, value);\n }\n\n /**\n * @dev Returns true if the value is in the set. O(1).\n */\n function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {\n return _contains(set._inner, value);\n }\n\n /**\n * @dev Returns the number of values in the set. O(1).\n */\n function length(Bytes32Set storage set) internal view returns (uint256) {\n return _length(set._inner);\n }\n\n /**\n * @dev Returns the value stored at position `index` in the set. O(1).\n *\n * Note that there are no guarantees on the ordering of values inside the\n * array, and it may change when more values are added or removed.\n *\n * Requirements:\n *\n * - `index` must be strictly less than {length}.\n */\n function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {\n return _at(set._inner, index);\n }\n\n /**\n * @dev Return the entire set in an array\n *\n * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n */\n function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {\n bytes32[] memory store = _values(set._inner);\n bytes32[] memory result;\n\n /// @solidity memory-safe-assembly\n assembly {\n result := store\n }\n\n return result;\n }\n\n // AddressSet\n\n struct AddressSet {\n Set _inner;\n }\n\n /**\n * @dev Add a value to a set. O(1).\n *\n * Returns true if the value was added to the set, that is if it was not\n * already present.\n */\n function add(AddressSet storage set, address value) internal returns (bool) {\n return _add(set._inner, bytes32(uint256(uint160(value))));\n }\n\n /**\n * @dev Removes a value from a set. O(1).\n *\n * Returns true if the value was removed from the set, that is if it was\n * present.\n */\n function remove(AddressSet storage set, address value) internal returns (bool) {\n return _remove(set._inner, bytes32(uint256(uint160(value))));\n }\n\n /**\n * @dev Returns true if the value is in the set. O(1).\n */\n function contains(AddressSet storage set, address value) internal view returns (bool) {\n return _contains(set._inner, bytes32(uint256(uint160(value))));\n }\n\n /**\n * @dev Returns the number of values in the set. O(1).\n */\n function length(AddressSet storage set) internal view returns (uint256) {\n return _length(set._inner);\n }\n\n /**\n * @dev Returns the value stored at position `index` in the set. O(1).\n *\n * Note that there are no guarantees on the ordering of values inside the\n * array, and it may change when more values are added or removed.\n *\n * Requirements:\n *\n * - `index` must be strictly less than {length}.\n */\n function at(AddressSet storage set, uint256 index) internal view returns (address) {\n return address(uint160(uint256(_at(set._inner, index))));\n }\n\n /**\n * @dev Return the entire set in an array\n *\n * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n */\n function values(AddressSet storage set) internal view returns (address[] memory) {\n bytes32[] memory store = _values(set._inner);\n address[] memory result;\n\n /// @solidity memory-safe-assembly\n assembly {\n result := store\n }\n\n return result;\n }\n\n // UintSet\n\n struct UintSet {\n Set _inner;\n }\n\n /**\n * @dev Add a value to a set. O(1).\n *\n * Returns true if the value was added to the set, that is if it was not\n * already present.\n */\n function add(UintSet storage set, uint256 value) internal returns (bool) {\n return _add(set._inner, bytes32(value));\n }\n\n /**\n * @dev Removes a value from a set. O(1).\n *\n * Returns true if the value was removed from the set, that is if it was\n * present.\n */\n function remove(UintSet storage set, uint256 value) internal returns (bool) {\n return _remove(set._inner, bytes32(value));\n }\n\n /**\n * @dev Returns true if the value is in the set. O(1).\n */\n function contains(UintSet storage set, uint256 value) internal view returns (bool) {\n return _contains(set._inner, bytes32(value));\n }\n\n /**\n * @dev Returns the number of values in the set. O(1).\n */\n function length(UintSet storage set) internal view returns (uint256) {\n return _length(set._inner);\n }\n\n /**\n * @dev Returns the value stored at position `index` in the set. O(1).\n *\n * Note that there are no guarantees on the ordering of values inside the\n * array, and it may change when more values are added or removed.\n *\n * Requirements:\n *\n * - `index` must be strictly less than {length}.\n */\n function at(UintSet storage set, uint256 index) internal view returns (uint256) {\n return uint256(_at(set._inner, index));\n }\n\n /**\n * @dev Return the entire set in an array\n *\n * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n */\n function values(UintSet storage set) internal view returns (uint256[] memory) {\n bytes32[] memory store = _values(set._inner);\n uint256[] memory result;\n\n /// @solidity memory-safe-assembly\n assembly {\n result := store\n }\n\n return result;\n }\n}\n" + }, + "src/interface/IPostageStamp.sol": { + "content": "// SPDX-License-Identifier: BSD-3-Clause\npragma solidity ^0.8.19;\n\ninterface IPostageStamp {\n function withdraw(address beneficiary) external;\n\n function setPrice(uint256 _price) external;\n\n function validChunkCount() external view returns (uint256);\n\n function batchOwner(bytes32 _batchId) external view returns (address);\n\n function batchDepth(bytes32 _batchId) external view returns (uint8);\n\n function batchBucketDepth(bytes32 _batchId) external view returns (uint8);\n\n function remainingBalance(bytes32 _batchId) external view returns (uint256);\n\n function minimumInitialBalancePerChunk() external view returns (uint256);\n\n function batches(\n bytes32\n )\n external\n view\n returns (\n address owner,\n uint8 depth,\n uint8 bucketDepth,\n bool immutableFlag,\n uint256 normalisedBalance,\n uint256 lastUpdatedBlockNumber\n );\n}\n" + }, + "src/OrderStatisticsTree/HitchensOrderStatisticsTreeLib.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\n/*\nHitchens Order Statistics Tree v0.99\n\nA Solidity Red-Black Tree library to store and maintain a sorted data\nstructure in a Red-Black binary search tree, with O(log 2n) insert, remove\nand search time (and gas, approximately)\n\nhttps://github.com/rob-Hitchens/OrderStatisticsTree\n\nCopyright (c) Rob Hitchens. the MIT License\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\nSignificant portions from BokkyPooBahsRedBlackTreeLibrary,\nhttps://github.com/bokkypoobah/BokkyPooBahsRedBlackTreeLibrary\n\nTHIS SOFTWARE IS NOT TESTED OR AUDITED. DO NOT USE FOR PRODUCTION.\n*/\n\nlibrary HitchensOrderStatisticsTreeLib {\n uint private constant EMPTY = 0;\n struct Node {\n uint parent;\n uint left;\n uint right;\n bool red;\n bytes32[] keys;\n mapping(bytes32 => uint) keyMap;\n uint count;\n }\n struct Tree {\n uint root;\n mapping(uint => Node) nodes;\n }\n\n error ValueDoesNotExist(); // Provided value doesn't exist in the tree.\n error ValueCannotBeZero(); // Value to insert cannot be zero\n error ValueKeyPairExists(); // Value and Key pair exists. Cannot be inserted again.\n\n function first(Tree storage self) internal view returns (uint _value) {\n _value = self.root;\n if (_value == EMPTY) return 0;\n while (self.nodes[_value].left != EMPTY) {\n _value = self.nodes[_value].left;\n }\n }\n\n function exists(Tree storage self, uint value) internal view returns (bool _exists) {\n if (value == EMPTY) return false;\n if (value == self.root) return true;\n if (self.nodes[value].parent != EMPTY) return true;\n return false;\n }\n\n function keyExists(Tree storage self, bytes32 key, uint value) internal view returns (bool _exists) {\n if (!exists(self, value)) return false;\n return self.nodes[value].keys[self.nodes[value].keyMap[key]] == key;\n }\n\n function getNode(\n Tree storage self,\n uint value\n ) internal view returns (uint _parent, uint _left, uint _right, bool _red, uint keyCount, uint __count) {\n if (!exists(self, value)) {\n revert ValueDoesNotExist();\n }\n\n Node storage gn = self.nodes[value];\n return (gn.parent, gn.left, gn.right, gn.red, gn.keys.length, gn.keys.length + gn.count);\n }\n\n function getNodeCount(Tree storage self, uint value) internal view returns (uint __count) {\n Node storage gn = self.nodes[value];\n return gn.keys.length + gn.count;\n }\n\n function valueKeyAtIndex(Tree storage self, uint value, uint index) internal view returns (bytes32 _key) {\n if (!exists(self, value)) {\n revert ValueDoesNotExist();\n }\n return self.nodes[value].keys[index];\n }\n\n function count(Tree storage self) internal view returns (uint _count) {\n return getNodeCount(self, self.root);\n }\n\n /* We don't use this functionality, so it is commented out to make audit easier\n\n function percentile(Tree storage self, uint value) internal view returns(uint _percentile) {\n uint denominator = count(self);\n uint numerator = rank(self, value);\n _percentile = ((uint(1000) * numerator)/denominator+(uint(5)))/uint(10);\n }\n function permil(Tree storage self, uint value) internal view returns(uint _permil) {\n uint denominator = count(self);\n uint numerator = rank(self, value);\n _permil = ((uint(10000) * numerator)/denominator+(uint(5)))/uint(10);\n }\n function atPercentile(Tree storage self, uint _percentile) internal view returns(uint _value) {\n uint findRank = (((_percentile * count(self))/uint(10)) + uint(5)) / uint(10);\n return atRank(self,findRank);\n }\n function atPermil(Tree storage self, uint _permil) internal view returns(uint _value) {\n uint findRank = (((_permil * count(self))/uint(100)) + uint(5)) / uint(10);\n return atRank(self,findRank);\n }\n function median(Tree storage self) internal view returns(uint value) {\n return atPercentile(self,50);\n }\n function below(Tree storage self, uint value) public view returns(uint _below) {\n if(count(self) > 0 && value > 0) _below = rank(self,value)-uint(1);\n }\n function above(Tree storage self, uint value) public view returns(uint _above) {\n if(count(self) > 0) _above = count(self)-rank(self,value);\n }\n function valueBelowEstimate(Tree storage self, uint estimate) public view returns(uint _below) {\n if(count(self) > 0 && estimate > 0) {\n uint highestValue = last(self);\n uint lowestValue = first(self);\n if(estimate < lowestValue) {\n return 0;\n }\n if(estimate >= highestValue) {\n return highestValue;\n }\n uint rankOfValue = rank(self, estimate); // approximation\n _below = atRank(self, rankOfValue);\n if(_below > estimate) { // fix error in approximation\n rankOfValue--;\n _below = atRank(self, rankOfValue);\n }\n }\n }\n function valueAboveEstimate(Tree storage self, uint estimate) public view returns(uint _above) {\n if(count(self) > 0 && estimate > 0) {\n uint highestValue = last(self);\n uint lowestValue = first(self);\n if(estimate > highestValue) {\n return 0;\n }\n if(estimate <= lowestValue) {\n return lowestValue;\n }\n uint rankOfValue = rank(self, estimate); // approximation\n _above = atRank(self, rankOfValue);\n if(_above < estimate) { // fix error in approximation\n rankOfValue++;\n _above = atRank(self, rankOfValue);\n }\n }\n }\n function rank(Tree storage self, uint value) internal view returns(uint _rank) {\n if(count(self) > 0) {\n bool finished;\n uint cursor = self.root;\n Node storage c = self.nodes[cursor];\n uint smaller = getNodeCount(self,c.left);\n while (!finished) {\n uint keyCount = c.keys.length;\n if(cursor == value) {\n finished = true;\n } else {\n if(cursor < value) {\n cursor = c.right;\n c = self.nodes[cursor];\n smaller += keyCount + getNodeCount(self,c.left);\n } else {\n cursor = c.left;\n c = self.nodes[cursor];\n smaller -= (keyCount + getNodeCount(self,c.right));\n }\n }\n if (!exists(self,cursor)) {\n finished = true;\n }\n }\n return smaller + 1;\n }\n }\n function atRank(Tree storage self, uint _rank) internal view returns(uint _value) {\n bool finished;\n uint cursor = self.root;\n Node storage c = self.nodes[cursor];\n uint smaller = getNodeCount(self,c.left);\n while (!finished) {\n _value = cursor;\n c = self.nodes[cursor];\n uint keyCount = c.keys.length;\n if(smaller + 1 >= _rank && smaller + keyCount <= _rank) {\n _value = cursor;\n finished = true;\n } else {\n if(smaller + keyCount <= _rank) {\n cursor = c.right;\n c = self.nodes[cursor];\n smaller += keyCount + getNodeCount(self,c.left);\n } else {\n cursor = c.left;\n c = self.nodes[cursor];\n smaller -= (keyCount + getNodeCount(self,c.right));\n }\n }\n if (!exists(self,cursor)) {\n finished = true;\n }\n }\n }\n*/\n\n function insert(Tree storage self, bytes32 key, uint value) internal {\n if (value == EMPTY) {\n revert ValueCannotBeZero();\n }\n if (keyExists(self, key, value)) {\n revert ValueKeyPairExists();\n }\n uint cursor;\n uint probe = self.root;\n while (probe != EMPTY) {\n cursor = probe;\n if (value < probe) {\n probe = self.nodes[probe].left;\n } else if (value > probe) {\n probe = self.nodes[probe].right;\n } else if (value == probe) {\n self.nodes[probe].keys.push(key);\n self.nodes[probe].keyMap[key] = self.nodes[probe].keys.length - uint(1);\n return;\n }\n self.nodes[cursor].count++;\n }\n Node storage nValue = self.nodes[value];\n nValue.parent = cursor;\n nValue.left = EMPTY;\n nValue.right = EMPTY;\n nValue.red = true;\n nValue.keys.push(key);\n nValue.keyMap[key] = nValue.keys.length - uint(1);\n if (cursor == EMPTY) {\n self.root = value;\n } else if (value < cursor) {\n self.nodes[cursor].left = value;\n } else {\n self.nodes[cursor].right = value;\n }\n insertFixup(self, value);\n }\n\n function remove(Tree storage self, bytes32 key, uint value) internal {\n if (value == EMPTY) {\n revert ValueCannotBeZero();\n }\n if (!keyExists(self, key, value)) {\n revert ValueDoesNotExist();\n }\n\n Node storage nValue = self.nodes[value];\n uint rowToDelete = nValue.keyMap[key];\n bytes32 last = nValue.keys[nValue.keys.length - uint(1)];\n nValue.keys[rowToDelete] = last;\n nValue.keyMap[last] = rowToDelete;\n nValue.keys.pop();\n\n uint probe;\n uint cursor;\n\n if (nValue.keys.length == 0) {\n if (self.nodes[value].left == EMPTY || self.nodes[value].right == EMPTY) {\n cursor = value;\n } else {\n cursor = self.nodes[value].right;\n while (self.nodes[cursor].left != EMPTY) {\n cursor = self.nodes[cursor].left;\n }\n }\n\n if (self.nodes[cursor].left != EMPTY) {\n probe = self.nodes[cursor].left;\n } else {\n probe = self.nodes[cursor].right;\n }\n\n uint cursorParent = self.nodes[cursor].parent;\n self.nodes[probe].parent = cursorParent;\n\n if (cursorParent != EMPTY) {\n if (cursor == self.nodes[cursorParent].left) {\n self.nodes[cursorParent].left = probe;\n } else {\n self.nodes[cursorParent].right = probe;\n }\n } else {\n self.root = probe;\n }\n\n bool doFixup = !self.nodes[cursor].red;\n\n if (cursor != value) {\n replaceParent(self, cursor, value);\n self.nodes[cursor].left = self.nodes[value].left;\n self.nodes[self.nodes[cursor].left].parent = cursor;\n self.nodes[cursor].right = self.nodes[value].right;\n self.nodes[self.nodes[cursor].right].parent = cursor;\n self.nodes[cursor].red = self.nodes[value].red;\n (cursor, value) = (value, cursor);\n fixCountRecurse(self, value);\n }\n\n if (doFixup) {\n removeFixup(self, probe);\n }\n\n fixCountRecurse(self, cursorParent);\n delete self.nodes[cursor];\n }\n }\n\n function fixCountRecurse(Tree storage self, uint value) private {\n while (value != EMPTY) {\n self.nodes[value].count =\n getNodeCount(self, self.nodes[value].left) +\n getNodeCount(self, self.nodes[value].right);\n value = self.nodes[value].parent;\n }\n }\n\n function treeMinimum(Tree storage self, uint value) private view returns (uint) {\n while (self.nodes[value].left != EMPTY) {\n value = self.nodes[value].left;\n }\n return value;\n }\n\n function treeMaximum(Tree storage self, uint value) private view returns (uint) {\n while (self.nodes[value].right != EMPTY) {\n value = self.nodes[value].right;\n }\n return value;\n }\n\n function rotateLeft(Tree storage self, uint value) private {\n uint cursor = self.nodes[value].right;\n uint parent = self.nodes[value].parent;\n uint cursorLeft = self.nodes[cursor].left;\n self.nodes[value].right = cursorLeft;\n if (cursorLeft != EMPTY) {\n self.nodes[cursorLeft].parent = value;\n }\n self.nodes[cursor].parent = parent;\n if (parent == EMPTY) {\n self.root = cursor;\n } else if (value == self.nodes[parent].left) {\n self.nodes[parent].left = cursor;\n } else {\n self.nodes[parent].right = cursor;\n }\n self.nodes[cursor].left = value;\n self.nodes[value].parent = cursor;\n self.nodes[value].count =\n getNodeCount(self, self.nodes[value].left) +\n getNodeCount(self, self.nodes[value].right);\n self.nodes[cursor].count =\n getNodeCount(self, self.nodes[cursor].left) +\n getNodeCount(self, self.nodes[cursor].right);\n }\n\n function rotateRight(Tree storage self, uint value) private {\n uint cursor = self.nodes[value].left;\n uint parent = self.nodes[value].parent;\n uint cursorRight = self.nodes[cursor].right;\n self.nodes[value].left = cursorRight;\n if (cursorRight != EMPTY) {\n self.nodes[cursorRight].parent = value;\n }\n self.nodes[cursor].parent = parent;\n if (parent == EMPTY) {\n self.root = cursor;\n } else if (value == self.nodes[parent].right) {\n self.nodes[parent].right = cursor;\n } else {\n self.nodes[parent].left = cursor;\n }\n self.nodes[cursor].right = value;\n self.nodes[value].parent = cursor;\n self.nodes[value].count =\n getNodeCount(self, self.nodes[value].left) +\n getNodeCount(self, self.nodes[value].right);\n self.nodes[cursor].count =\n getNodeCount(self, self.nodes[cursor].left) +\n getNodeCount(self, self.nodes[cursor].right);\n }\n\n function insertFixup(Tree storage self, uint value) private {\n uint cursor;\n while (value != self.root && self.nodes[self.nodes[value].parent].red) {\n uint valueParent = self.nodes[value].parent;\n if (valueParent == self.nodes[self.nodes[valueParent].parent].left) {\n cursor = self.nodes[self.nodes[valueParent].parent].right;\n if (self.nodes[cursor].red) {\n self.nodes[valueParent].red = false;\n self.nodes[cursor].red = false;\n self.nodes[self.nodes[valueParent].parent].red = true;\n value = self.nodes[valueParent].parent;\n } else {\n if (value == self.nodes[valueParent].right) {\n value = valueParent;\n rotateLeft(self, value);\n }\n valueParent = self.nodes[value].parent;\n self.nodes[valueParent].red = false;\n self.nodes[self.nodes[valueParent].parent].red = true;\n rotateRight(self, self.nodes[valueParent].parent);\n }\n } else {\n cursor = self.nodes[self.nodes[valueParent].parent].left;\n if (self.nodes[cursor].red) {\n self.nodes[valueParent].red = false;\n self.nodes[cursor].red = false;\n self.nodes[self.nodes[valueParent].parent].red = true;\n value = self.nodes[valueParent].parent;\n } else {\n if (value == self.nodes[valueParent].left) {\n value = valueParent;\n rotateRight(self, value);\n }\n valueParent = self.nodes[value].parent;\n self.nodes[valueParent].red = false;\n self.nodes[self.nodes[valueParent].parent].red = true;\n rotateLeft(self, self.nodes[valueParent].parent);\n }\n }\n }\n self.nodes[self.root].red = false;\n }\n\n function replaceParent(Tree storage self, uint a, uint b) private {\n uint bParent = self.nodes[b].parent;\n self.nodes[a].parent = bParent;\n if (bParent == EMPTY) {\n self.root = a;\n } else {\n if (b == self.nodes[bParent].left) {\n self.nodes[bParent].left = a;\n } else {\n self.nodes[bParent].right = a;\n }\n }\n }\n\n function removeFixup(Tree storage self, uint value) private {\n uint cursor;\n while (value != self.root && !self.nodes[value].red) {\n uint valueParent = self.nodes[value].parent;\n if (value == self.nodes[valueParent].left) {\n cursor = self.nodes[valueParent].right;\n if (self.nodes[cursor].red) {\n self.nodes[cursor].red = false;\n self.nodes[valueParent].red = true;\n rotateLeft(self, valueParent);\n cursor = self.nodes[valueParent].right;\n }\n if (!self.nodes[self.nodes[cursor].left].red && !self.nodes[self.nodes[cursor].right].red) {\n self.nodes[cursor].red = true;\n value = valueParent;\n } else {\n if (!self.nodes[self.nodes[cursor].right].red) {\n self.nodes[self.nodes[cursor].left].red = false;\n self.nodes[cursor].red = true;\n rotateRight(self, cursor);\n cursor = self.nodes[valueParent].right;\n }\n self.nodes[cursor].red = self.nodes[valueParent].red;\n self.nodes[valueParent].red = false;\n self.nodes[self.nodes[cursor].right].red = false;\n rotateLeft(self, valueParent);\n value = self.root;\n }\n } else {\n cursor = self.nodes[valueParent].left;\n if (self.nodes[cursor].red) {\n self.nodes[cursor].red = false;\n self.nodes[valueParent].red = true;\n rotateRight(self, valueParent);\n cursor = self.nodes[valueParent].left;\n }\n if (!self.nodes[self.nodes[cursor].right].red && !self.nodes[self.nodes[cursor].left].red) {\n self.nodes[cursor].red = true;\n value = valueParent;\n } else {\n if (!self.nodes[self.nodes[cursor].left].red) {\n self.nodes[self.nodes[cursor].right].red = false;\n self.nodes[cursor].red = true;\n rotateLeft(self, cursor);\n cursor = self.nodes[valueParent].left;\n }\n self.nodes[cursor].red = self.nodes[valueParent].red;\n self.nodes[valueParent].red = false;\n self.nodes[self.nodes[cursor].left].red = false;\n rotateRight(self, valueParent);\n value = self.root;\n }\n }\n }\n self.nodes[value].red = false;\n }\n}\n" + }, + "src/PostageStamp.sol": { + "content": "// SPDX-License-Identifier: BSD-3-Clause\npragma solidity ^0.8.19;\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"@openzeppelin/contracts/security/Pausable.sol\";\nimport \"./OrderStatisticsTree/HitchensOrderStatisticsTreeLib.sol\";\n\n/**\n * @title PostageStamp contract\n * @author The Swarm Authors\n * @dev The postage stamp contracts allows users to create and manage postage stamp batches.\n * The current balance for each batch is stored ordered in descending order of normalised balance.\n * Balance is normalised to be per chunk and the total spend since the contract was deployed, i.e. when a batch\n * is bought, its per-chunk balance is supplemented with the current cost of storing one chunk since the beginning of time,\n * as if the batch had existed since the contract's inception. During the _expiry_ process, each of these balances is\n * checked against the _currentTotalOutPayment_, a similarly normalised figure that represents the current cost of\n * storing one chunk since the beginning of time. A batch with a normalised balance less than _currentTotalOutPayment_\n * is treated as expired.\n *\n * The _currentTotalOutPayment_ is calculated using _totalOutPayment_ which is updated during _setPrice_ events so\n * that the applicable per-chunk prices can be charged for the relevant periods of time. This can then be multiplied\n * by the amount of chunks which are allowed to be stamped by each batch to get the actual cost of storage.\n *\n * The amount of chunks a batch can stamp is determined by the _bucketDepth_. A batch may store a maximum of 2^depth chunks.\n * The global figure for the currently allowed chunks is tracked by _validChunkCount_ and updated during batch _expiry_ events.\n */\n\ncontract PostageStamp is AccessControl, Pausable {\n using HitchensOrderStatisticsTreeLib for HitchensOrderStatisticsTreeLib.Tree;\n\n // ----------------------------- State variables ------------------------------\n\n // Address of the ERC20 token this contract references.\n address public bzzToken;\n\n // Minimum allowed depth of bucket.\n uint8 public minimumBucketDepth;\n\n // Role allowed to increase totalOutPayment.\n bytes32 public immutable PRICE_ORACLE_ROLE;\n\n // Role allowed to pause\n bytes32 public immutable PAUSER_ROLE;\n // Role allowed to withdraw the pot.\n bytes32 public immutable REDISTRIBUTOR_ROLE;\n\n // Associate every batch id with batch data.\n mapping(bytes32 => Batch) public batches;\n // Store every batch id ordered by normalisedBalance.\n HitchensOrderStatisticsTreeLib.Tree tree;\n\n // Total out payment per chunk, at the blockheight of the last price change.\n uint256 private totalOutPayment;\n\n // Combined global chunk capacity of valid batches remaining at the blockheight expire() was last called.\n uint256 public validChunkCount;\n\n // Lottery pot at last update.\n uint256 public pot;\n\n // Normalised balance at the blockheight expire() was last called.\n uint256 public lastExpiryBalance;\n\n // Price from the last update.\n uint64 public lastPrice;\n\n // blocks in 24 hours ~ 24 * 60 * 60 / 5 = 17280\n uint64 public minimumValidityBlocks = 17280;\n\n // Block at which the last update occured.\n uint64 public lastUpdatedBlock;\n\n // ----------------------------- Type declarations ------------------------------\n\n struct Batch {\n // Owner of this batch (0 if not valid).\n address owner;\n // Current depth of this batch.\n uint8 depth;\n // Bucket depth defined in this batch\n uint8 bucketDepth;\n // Whether this batch is immutable.\n bool immutableFlag;\n // Normalised balance per chunk.\n uint256 normalisedBalance;\n // When was this batch last updated\n uint256 lastUpdatedBlockNumber;\n }\n\n struct ImportBatch {\n bytes32 batchId;\n address owner;\n uint8 depth;\n uint8 bucketDepth;\n bool immutableFlag;\n uint256 remainingBalance;\n }\n\n // ----------------------------- Events ------------------------------\n\n /**\n * @dev Emitted when a new batch is created.\n */\n event BatchCreated(\n bytes32 indexed batchId,\n uint256 totalAmount,\n uint256 normalisedBalance,\n address owner,\n uint8 depth,\n uint8 bucketDepth,\n bool immutableFlag\n );\n\n /**\n * @dev Emitted when an pot is Withdrawn.\n */\n event PotWithdrawn(address recipient, uint256 totalAmount);\n\n /**\n * @dev Emitted when an existing batch is topped up.\n */\n event BatchTopUp(bytes32 indexed batchId, uint256 topupAmount, uint256 normalisedBalance);\n\n /**\n * @dev Emitted when the depth of an existing batch increases.\n */\n event BatchDepthIncrease(bytes32 indexed batchId, uint8 newDepth, uint256 normalisedBalance);\n\n /**\n *@dev Emitted on every price update.\n */\n event PriceUpdate(uint256 price);\n\n /**\n *@dev Emitted on every batch failed in bulk batch creation\n */\n event CopyBatchFailed(uint index, bytes32 batchId);\n\n // ----------------------------- Errors ------------------------------\n\n error ZeroAddress(); // Owner cannot be the zero address\n error InvalidDepth(); // Invalid bucket depth\n error BatchExists(); // Batch already exists\n error InsufficientBalance(); // Insufficient initial balance for 24h minimum validity\n error TransferFailed(); // Failed transfer of BZZ tokens\n error ZeroBalance(); // NormalisedBalance cannot be zero\n error AdministratorOnly(); // Only administrator can use copy method\n error BatchDoesNotExist(); // Batch does not exist or has expired\n error BatchExpired(); // Batch already expired\n error BatchTooSmall(); // Batch too small to renew\n error NotBatchOwner(); // Not batch owner\n error DepthNotIncreasing(); // Depth not increasing\n error PriceOracleOnly(); // Only price oracle can set the price\n error InsufficienChunkCount(); // Insufficient valid chunk count\n error TotalOutpaymentDecreased(); // Current total outpayment should never decrease\n error NoBatchesExist(); // There are no batches\n error OnlyPauser(); // Only Pauser role can pause or unpause contracts\n error OnlyRedistributor(); // Only redistributor role can withdraw from the contract\n\n // ----------------------------- CONSTRUCTOR ------------------------------\n\n /**\n * @param _bzzToken The ERC20 token address to reference in this contract.\n * @param _minimumBucketDepth The minimum bucket depth of batches that can be purchased.\n */\n constructor(address _bzzToken, uint8 _minimumBucketDepth) {\n bzzToken = _bzzToken;\n minimumBucketDepth = _minimumBucketDepth;\n PRICE_ORACLE_ROLE = keccak256(\"PRICE_ORACLE_ROLE\");\n PAUSER_ROLE = keccak256(\"PAUSER_ROLE\");\n REDISTRIBUTOR_ROLE = keccak256(\"REDISTRIBUTOR_ROLE\");\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n _setupRole(PAUSER_ROLE, msg.sender);\n }\n\n ////////////////////////////////////////\n // STATE CHANGING //\n ////////////////////////////////////////\n\n /**\n * @notice Create a new batch.\n * @dev At least `_initialBalancePerChunk*2^depth` tokens must be approved in the ERC20 token contract.\n * @param _owner Owner of the new batch.\n * @param _initialBalancePerChunk Initial balance per chunk.\n * @param _depth Initial depth of the new batch.\n * @param _nonce A random value used in the batch id derivation to allow multiple batches per owner.\n * @param _immutable Whether the batch is mutable.\n */\n function createBatch(\n address _owner,\n uint256 _initialBalancePerChunk,\n uint8 _depth,\n uint8 _bucketDepth,\n bytes32 _nonce,\n bool _immutable\n ) external whenNotPaused returns (bytes32) {\n if (_owner == address(0)) {\n revert ZeroAddress();\n }\n\n if (_bucketDepth == 0 || _bucketDepth < minimumBucketDepth || _bucketDepth >= _depth) {\n revert InvalidDepth();\n }\n\n bytes32 batchId = keccak256(abi.encode(msg.sender, _nonce));\n if (batches[batchId].owner != address(0)) {\n revert BatchExists();\n }\n\n if (_initialBalancePerChunk < minimumInitialBalancePerChunk()) {\n revert InsufficientBalance();\n }\n\n uint256 totalAmount = _initialBalancePerChunk * (1 << _depth);\n if (!ERC20(bzzToken).transferFrom(msg.sender, address(this), totalAmount)) {\n revert TransferFailed();\n }\n\n uint256 normalisedBalance = currentTotalOutPayment() + (_initialBalancePerChunk);\n if (normalisedBalance == 0) {\n revert ZeroBalance();\n }\n\n expireLimited(type(uint256).max);\n validChunkCount += 1 << _depth;\n\n batches[batchId] = Batch({\n owner: _owner,\n depth: _depth,\n bucketDepth: _bucketDepth,\n immutableFlag: _immutable,\n normalisedBalance: normalisedBalance,\n lastUpdatedBlockNumber: block.number\n });\n\n tree.insert(batchId, normalisedBalance);\n\n emit BatchCreated(batchId, totalAmount, normalisedBalance, _owner, _depth, _bucketDepth, _immutable);\n\n return batchId;\n }\n\n /**\n * @notice Manually create a new batch when facilitating migration, can only be called by the Admin role.\n * @dev At least `_initialBalancePerChunk*2^depth` tokens must be approved in the ERC20 token contract.\n * @param _owner Owner of the new batch.\n * @param _initialBalancePerChunk Initial balance per chunk of the batch.\n * @param _depth Initial depth of the new batch.\n * @param _batchId BatchId being copied (from previous version contract data).\n * @param _immutable Whether the batch is mutable.\n */\n function copyBatch(\n address _owner,\n uint256 _initialBalancePerChunk,\n uint8 _depth,\n uint8 _bucketDepth,\n bytes32 _batchId,\n bool _immutable\n ) public whenNotPaused {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert AdministratorOnly();\n }\n\n if (_owner == address(0)) {\n revert ZeroAddress();\n }\n\n if (_bucketDepth == 0 || _bucketDepth >= _depth) {\n revert InvalidDepth();\n }\n\n if (batches[_batchId].owner != address(0)) {\n revert BatchExists();\n }\n\n uint256 totalAmount = _initialBalancePerChunk * (1 << _depth);\n uint256 normalisedBalance = currentTotalOutPayment() + (_initialBalancePerChunk);\n if (normalisedBalance == 0) {\n revert ZeroBalance();\n }\n\n //update validChunkCount to remove currently expired batches\n expireLimited(type(uint256).max);\n\n validChunkCount += 1 << _depth;\n\n batches[_batchId] = Batch({\n owner: _owner,\n depth: _depth,\n bucketDepth: _bucketDepth,\n immutableFlag: _immutable,\n normalisedBalance: normalisedBalance,\n lastUpdatedBlockNumber: block.number\n });\n\n tree.insert(_batchId, normalisedBalance);\n\n emit BatchCreated(_batchId, totalAmount, normalisedBalance, _owner, _depth, _bucketDepth, _immutable);\n }\n\n /**\n * @notice Import batches in bulk\n * @dev Import batches in bulk to lower the number of transactions needed,\n * @dev becase of block limitations 90 batches per trx is ceiling, 60 to 70 sweetspot\n * @param bulkBatches array of batches\n */\n function copyBatchBulk(ImportBatch[] calldata bulkBatches) external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert AdministratorOnly();\n }\n for (uint i = 0; i < bulkBatches.length; i++) {\n ImportBatch memory _batch = bulkBatches[i];\n try\n this.copyBatch(\n _batch.owner,\n _batch.remainingBalance,\n _batch.depth,\n _batch.bucketDepth,\n _batch.batchId,\n _batch.immutableFlag\n )\n {\n // Successful copyBatch call\n } catch {\n // copyBatch failed, handle error\n emit CopyBatchFailed(i, _batch.batchId);\n }\n }\n }\n\n /**\n * @notice Top up an existing batch.\n * @dev At least `_topupAmountPerChunk*2^depth` tokens must be approved in the ERC20 token contract.\n * @param _batchId The id of an existing batch.\n * @param _topupAmountPerChunk The amount of additional tokens to add per chunk.\n */\n function topUp(bytes32 _batchId, uint256 _topupAmountPerChunk) external whenNotPaused {\n Batch memory batch = batches[_batchId];\n\n if (batch.owner == address(0)) {\n revert BatchDoesNotExist();\n }\n\n if (batch.normalisedBalance <= currentTotalOutPayment()) {\n revert BatchExpired();\n }\n\n if (batch.depth <= minimumBucketDepth) {\n revert BatchTooSmall();\n }\n\n if (remainingBalance(_batchId) + (_topupAmountPerChunk) < minimumInitialBalancePerChunk()) {\n revert InsufficientBalance();\n }\n\n // per chunk balance multiplied by the batch size in chunks must be transferred from the sender\n uint256 totalAmount = _topupAmountPerChunk * (1 << batch.depth);\n if (!ERC20(bzzToken).transferFrom(msg.sender, address(this), totalAmount)) {\n revert TransferFailed();\n }\n\n // update by removing batch and then reinserting\n tree.remove(_batchId, batch.normalisedBalance);\n batch.normalisedBalance = batch.normalisedBalance + (_topupAmountPerChunk);\n tree.insert(_batchId, batch.normalisedBalance);\n\n batches[_batchId].normalisedBalance = batch.normalisedBalance;\n emit BatchTopUp(_batchId, totalAmount, batch.normalisedBalance);\n }\n\n /**\n * @notice Increase the depth of an existing batch.\n * @dev Can only be called by the owner of the batch.\n * @param _batchId the id of an existing batch.\n * @param _newDepth the new (larger than the previous one) depth for this batch.\n */\n function increaseDepth(bytes32 _batchId, uint8 _newDepth) external whenNotPaused {\n Batch memory batch = batches[_batchId];\n\n if (batch.owner != msg.sender) {\n revert NotBatchOwner();\n }\n\n if (!(minimumBucketDepth < _newDepth && batch.depth < _newDepth)) {\n revert DepthNotIncreasing();\n }\n\n if (batch.normalisedBalance <= currentTotalOutPayment()) {\n revert BatchExpired();\n }\n\n uint8 depthChange = _newDepth - batch.depth;\n uint256 newRemainingBalance = remainingBalance(_batchId) / (1 << depthChange);\n\n if (newRemainingBalance < minimumInitialBalancePerChunk()) {\n revert InsufficientBalance();\n }\n\n expireLimited(type(uint256).max);\n validChunkCount += (1 << _newDepth) - (1 << batch.depth);\n tree.remove(_batchId, batch.normalisedBalance);\n batches[_batchId].depth = _newDepth;\n batches[_batchId].lastUpdatedBlockNumber = block.number;\n\n batch.normalisedBalance = currentTotalOutPayment() + newRemainingBalance;\n batches[_batchId].normalisedBalance = batch.normalisedBalance;\n tree.insert(_batchId, batch.normalisedBalance);\n\n emit BatchDepthIncrease(_batchId, _newDepth, batch.normalisedBalance);\n }\n\n /**\n * @notice Set a new price.\n * @dev Can only be called by the price oracle role.\n * @param _price The new price.\n */\n function setPrice(uint256 _price) external {\n if (!hasRole(PRICE_ORACLE_ROLE, msg.sender)) {\n revert PriceOracleOnly();\n }\n\n if (lastPrice != 0) {\n totalOutPayment = currentTotalOutPayment();\n }\n\n lastPrice = uint64(_price);\n lastUpdatedBlock = uint64(block.number);\n\n emit PriceUpdate(_price);\n }\n\n function setMinimumValidityBlocks(uint64 _value) external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert AdministratorOnly();\n }\n\n minimumValidityBlocks = _value;\n }\n\n /**\n * @notice Reclaims a limited number of expired batches\n * @dev Can be used if reclaiming all expired batches would exceed the block gas limit, causing other\n * contract method calls to fail.\n * @param limit The maximum number of batches to expire.\n */\n function expireLimited(uint256 limit) public {\n // the lower bound of the normalised balance for which we will check if batches have expired\n uint256 _lastExpiryBalance = lastExpiryBalance;\n uint256 i;\n for (i; i < limit; ) {\n if (isBatchesTreeEmpty()) {\n lastExpiryBalance = currentTotalOutPayment();\n break;\n }\n // get the batch with the smallest normalised balance\n bytes32 fbi = firstBatchId();\n // if the batch with the smallest balance has not yet expired\n // we have already reached the end of the batches we need\n // to expire, so exit the loop\n if (remainingBalance(fbi) > 0) {\n // the upper bound of the normalised balance for which we will check if batches have expired\n // value is updated when there are no expired batches left\n lastExpiryBalance = currentTotalOutPayment();\n break;\n }\n // otherwise, the batch with the smallest balance has expired,\n // so we must remove the chunks this batch contributes to the global validChunkCount\n Batch memory batch = batches[fbi];\n uint256 batchSize = 1 << batch.depth;\n\n if (validChunkCount < batchSize) {\n revert InsufficienChunkCount();\n }\n validChunkCount -= batchSize;\n // since the batch expired _during_ the period we must add\n // remaining normalised payout for this batch only\n pot += batchSize * (batch.normalisedBalance - _lastExpiryBalance);\n tree.remove(fbi, batch.normalisedBalance);\n delete batches[fbi];\n\n unchecked {\n ++i;\n }\n }\n // then, for all batches that have _not_ expired during the period\n // add the total normalised payout of all batches\n // multiplied by the remaining total valid chunk count\n // to the pot for the period since the last expiry\n\n if (lastExpiryBalance < _lastExpiryBalance) {\n revert TotalOutpaymentDecreased();\n }\n\n // then, for all batches that have _not_ expired during the period\n // add the total normalised payout of all batches\n // multiplied by the remaining total valid chunk count\n // to the pot for the period since the last expiry\n pot += validChunkCount * (lastExpiryBalance - _lastExpiryBalance);\n }\n\n /**\n * @notice The current pot.\n */\n function totalPot() public returns (uint256) {\n expireLimited(type(uint256).max);\n uint256 balance = ERC20(bzzToken).balanceOf(address(this));\n return pot < balance ? pot : balance;\n }\n\n /**\n * @notice Withdraw the pot, authorised callers only.\n * @param beneficiary Recieves the current total pot.\n */\n\n function withdraw(address beneficiary) external {\n if (!hasRole(REDISTRIBUTOR_ROLE, msg.sender)) {\n revert OnlyRedistributor();\n }\n\n uint256 totalAmount = totalPot();\n if (!ERC20(bzzToken).transfer(beneficiary, totalAmount)) {\n revert TransferFailed();\n }\n\n emit PotWithdrawn(beneficiary, totalAmount);\n pot = 0;\n }\n\n /**\n * @notice Pause the contract.\n * @dev Can only be called by the pauser when not paused.\n * The contract can be provably stopped by renouncing the pauser role and the admin role once paused.\n */\n function pause() public {\n if (!hasRole(PAUSER_ROLE, msg.sender)) {\n revert OnlyPauser();\n }\n _pause();\n }\n\n /**\n * @notice Unpause the contract.\n * @dev Can only be called by the pauser role while paused.\n */\n function unPause() public {\n if (!hasRole(PAUSER_ROLE, msg.sender)) {\n revert OnlyPauser();\n }\n\n _unpause();\n }\n\n ////////////////////////////////////////\n // STATE READING //\n ////////////////////////////////////////\n\n /**\n * @notice Total per-chunk cost since the contract's deployment.\n * @dev Returns the total normalised all-time per chunk payout.\n * Only Batches with a normalised balance greater than this are valid.\n */\n function currentTotalOutPayment() public view returns (uint256) {\n uint256 blocks = block.number - lastUpdatedBlock;\n uint256 increaseSinceLastUpdate = lastPrice * (blocks);\n return totalOutPayment + (increaseSinceLastUpdate);\n }\n\n function minimumInitialBalancePerChunk() public view returns (uint256) {\n return minimumValidityBlocks * lastPrice;\n }\n\n /**\n * @notice Return the per chunk balance not yet used up.\n * @param _batchId The id of an existing batch.\n */\n function remainingBalance(bytes32 _batchId) public view returns (uint256) {\n Batch memory batch = batches[_batchId];\n\n if (batch.owner == address(0)) {\n revert BatchDoesNotExist(); // Batch does not exist or expired\n }\n\n if (batch.normalisedBalance <= currentTotalOutPayment()) {\n return 0;\n }\n\n return batch.normalisedBalance - currentTotalOutPayment();\n }\n\n /**\n * @notice Indicates whether expired batches exist.\n */\n function expiredBatchesExist() public view returns (bool) {\n if (isBatchesTreeEmpty()) {\n return false;\n }\n return (remainingBalance(firstBatchId()) <= 0);\n }\n\n /**\n * @notice Return true if no batches exist\n */\n function isBatchesTreeEmpty() public view returns (bool) {\n return tree.count() == 0;\n }\n\n /**\n * @notice Get the first batch id ordered by ascending normalised balance.\n * @dev If more than one batch id, return index at 0, if no batches, revert.\n */\n function firstBatchId() public view returns (bytes32) {\n uint256 val = tree.first();\n if (val == 0) {\n revert NoBatchesExist();\n }\n return tree.valueKeyAtIndex(val, 0);\n }\n\n function batchOwner(bytes32 _batchId) public view returns (address) {\n return batches[_batchId].owner;\n }\n\n function batchDepth(bytes32 _batchId) public view returns (uint8) {\n return batches[_batchId].depth;\n }\n\n function batchBucketDepth(bytes32 _batchId) public view returns (uint8) {\n return batches[_batchId].bucketDepth;\n }\n\n function batchImmutableFlag(bytes32 _batchId) public view returns (bool) {\n return batches[_batchId].immutableFlag;\n }\n\n function batchNormalisedBalance(bytes32 _batchId) public view returns (uint256) {\n return batches[_batchId].normalisedBalance;\n }\n\n function batchLastUpdatedBlockNumber(bytes32 _batchId) public view returns (uint256) {\n return batches[_batchId].lastUpdatedBlockNumber;\n }\n}\n" + }, + "src/PriceOracle.sol": { + "content": "// SPDX-License-Identifier: BSD-3-Clause\npragma solidity ^0.8.19;\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"./interface/IPostageStamp.sol\";\n\n/**\n * @title PriceOracle contract.\n * @author The Swarm Authors.\n * @dev The price oracle contract emits a price feed using events.\n */\n\ncontract PriceOracle is AccessControl {\n // ----------------------------- State variables ------------------------------\n\n // The address of the linked PostageStamp contract\n IPostageStamp public postageStamp;\n\n uint16 targetRedundancy = 4;\n uint16 maxConsideredExtraRedundancy = 4;\n\n // When the contract is paused, price changes are not effective\n bool public isPaused = false;\n\n // The number of the last round price adjusting happend\n uint64 public lastAdjustedRound;\n\n // The minimum price allowed\n uint32 public minimumPriceUpscaled = 24000 << 10; // we upscale it by 2^10\n\n // The priceBase to modulate the price\n uint32 public priceBase = 1048576;\n\n uint64 public currentPriceUpScaled = minimumPriceUpscaled;\n\n // Constants used to modulate the price, see below usage\n uint32[9] public changeRate = [1049417, 1049206, 1048996, 1048786, 1048576, 1048366, 1048156, 1047946, 1047736];\n\n // Role allowed to update price\n bytes32 public immutable PRICE_UPDATER_ROLE;\n\n // The length of a round in blocks.\n uint8 private constant ROUND_LENGTH = 152;\n\n // ----------------------------- Events ------------------------------\n\n /**\n *@dev Emitted on every price update.\n */\n event PriceUpdate(uint256 price);\n event StampPriceUpdateFailed(uint256 attemptedPrice);\n\n // ----------------------------- Custom Errors ------------------------------\n error CallerNotAdmin(); // Caller is not the admin\n error CallerNotPriceUpdater(); // Caller is not a price updater\n error PriceAlreadyAdjusted(); // Price already adjusted in this round\n error UnexpectedZero(); // Redundancy needs to be higher then 0\n\n // ----------------------------- CONSTRUCTOR ------------------------------\n\n constructor(address _postageStamp) {\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n postageStamp = IPostageStamp(_postageStamp);\n lastAdjustedRound = currentRound();\n PRICE_UPDATER_ROLE = keccak256(\"PRICE_UPDATER_ROLE\");\n emit PriceUpdate(currentPrice());\n }\n\n ////////////////////////////////////////\n // STATE SETTING //\n ////////////////////////////////////////\n\n /**\n * @notice Manually set the price.\n * @dev Can only be called by the admin role.\n * @param _price The new price.\n */ function setPrice(uint32 _price) external returns (bool) {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert CallerNotAdmin();\n }\n\n uint64 _currentPriceUpScaled = _price << 10;\n uint64 _minimumPriceUpscaled = minimumPriceUpscaled;\n\n // Enforce minimum price\n if (_currentPriceUpScaled < _minimumPriceUpscaled) {\n _currentPriceUpScaled = _minimumPriceUpscaled;\n }\n currentPriceUpScaled = _currentPriceUpScaled;\n\n // Check if the setting of price in postagestamp succeded\n (bool success, ) = address(postageStamp).call(\n abi.encodeWithSignature(\"setPrice(uint256)\", uint256(currentPrice()))\n );\n if (!success) {\n emit StampPriceUpdateFailed(currentPrice());\n return false;\n }\n emit PriceUpdate(currentPrice());\n return true;\n }\n\n function adjustPrice(uint16 redundancy) external returns (bool) {\n if (isPaused == false) {\n if (!hasRole(PRICE_UPDATER_ROLE, msg.sender)) {\n revert CallerNotPriceUpdater();\n }\n\n uint16 usedRedundancy = redundancy;\n uint64 currentRoundNumber = currentRound();\n\n // Price can only be adjusted once per round\n if (currentRoundNumber <= lastAdjustedRound) {\n revert PriceAlreadyAdjusted();\n }\n // Redundancy may not be zero\n if (redundancy == 0) {\n revert UnexpectedZero();\n }\n\n // Enforce maximum considered extra redundancy\n uint16 maxConsideredRedundancy = targetRedundancy + maxConsideredExtraRedundancy;\n if (redundancy > maxConsideredRedundancy) {\n usedRedundancy = maxConsideredRedundancy;\n }\n\n uint64 _currentPriceUpScaled = currentPriceUpScaled;\n uint64 _minimumPriceUpscaled = minimumPriceUpscaled;\n uint32 _priceBase = priceBase;\n\n // Set the number of rounds that were skipped\n uint64 skippedRounds = currentRoundNumber - lastAdjustedRound - 1;\n\n // We first apply the increase/decrease rate for the current round\n uint32 _changeRate = changeRate[usedRedundancy];\n _currentPriceUpScaled = (_changeRate * _currentPriceUpScaled) / _priceBase;\n\n // If previous rounds were skipped, use MAX price increase for the previous rounds\n if (skippedRounds > 0) {\n _changeRate = changeRate[0];\n for (uint64 i = 0; i < skippedRounds; i++) {\n _currentPriceUpScaled = (_changeRate * _currentPriceUpScaled) / _priceBase;\n }\n }\n\n // Enforce minimum price\n if (_currentPriceUpScaled < _minimumPriceUpscaled) {\n _currentPriceUpScaled = _minimumPriceUpscaled;\n }\n\n currentPriceUpScaled = _currentPriceUpScaled;\n lastAdjustedRound = currentRoundNumber;\n\n // Check if the price set in postagestamp succeded\n (bool success, ) = address(postageStamp).call(\n abi.encodeWithSignature(\"setPrice(uint256)\", uint256(currentPrice()))\n );\n if (!success) {\n emit StampPriceUpdateFailed(currentPrice());\n return false;\n }\n emit PriceUpdate(currentPrice());\n return true;\n }\n return false;\n }\n\n function pause() external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert CallerNotAdmin();\n }\n isPaused = true;\n }\n\n function unPause() external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert CallerNotAdmin();\n }\n isPaused = false;\n }\n\n ////////////////////////////////////////\n // STATE READING //\n ////////////////////////////////////////\n\n /**\n * @notice Return the number of the current round.\n */\n function currentRound() public view returns (uint64) {\n // We downcasted to uint64 as uint64 has 18,446,744,073,709,551,616 places\n // as each round is 152 x 5 = 760, each day has around 113 rounds which is 41245 in a year\n // it results 4.4724801e+14 years to run this game\n return uint64(block.number / uint256(ROUND_LENGTH));\n }\n\n /**\n * @notice Return the price downscaled\n */\n function currentPrice() public view returns (uint32) {\n // We downcasted to uint32 and bitshift it by 2^10\n return uint32((currentPriceUpScaled) >> 10);\n }\n\n /**\n * @notice Return the price downscaled\n */\n function minimumPrice() public view returns (uint32) {\n // We downcasted to uint32 and bitshift it by 2^10\n return uint32((minimumPriceUpscaled) >> 10);\n }\n}\n" + }, + "src/Redistribution.sol": { + "content": "// SPDX-License-Identifier: BSD-3-Clause\npragma solidity ^0.8.19;\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"@openzeppelin/contracts/security/Pausable.sol\";\nimport \"./Util/TransformedChunkProof.sol\";\nimport \"./Util/ChunkProof.sol\";\nimport \"./Util/Signatures.sol\";\nimport \"./interface/IPostageStamp.sol\";\n\ninterface IPriceOracle {\n function adjustPrice(uint16 redundancy) external returns (bool);\n}\n\ninterface IStakeRegistry {\n struct Stake {\n bytes32 overlay;\n uint256 stakeAmount;\n uint256 lastUpdatedBlockNumber;\n }\n\n function freezeDeposit(address _owner, uint256 _time) external;\n\n function lastUpdatedBlockNumberOfAddress(address _owner) external view returns (uint256);\n\n function overlayOfAddress(address _owner) external view returns (bytes32);\n\n function heightOfAddress(address _owner) external view returns (uint8);\n\n function nodeEffectiveStake(address _owner) external view returns (uint256);\n}\n\n/**\n * @title Redistribution contract\n * @author The Swarm Authors\n * @dev Implements a Schelling Co-ordination game to form consensus around the Reserve Commitment hash. This takes\n * place in three phases: _commit_, _reveal_ and _claim_.\n *\n * A node, upon establishing that it _isParticipatingInUpcomingRound_, i.e. it's overlay falls within proximity order\n * of its reported depth with the _currentRoundAnchor_, prepares a \"reserve commitment hash\" using the chunks\n * it currently stores in its reserve and calculates the \"storage depth\" (see Bee for details). These values, if calculated\n * honestly, and with the right chunks stored, should be the same for every node in a neighbourhood. This is the Schelling point.\n * Each eligible node can then use these values, together with a random, single use, secret _revealNonce_ and their\n * _overlay_ as the pre-image values for the obsfucated _commit_, using the _wrapCommit_ method.\n *\n * Once the _commit_ round has elapsed, participating nodes must provide the values used to calculate their obsfucated\n * _commit_ hash, which, once verified for correctness and proximity to the anchor are retained in the _currentReveals_.\n * Nodes that have committed but do not reveal the correct values used to create the pre-image will have their stake\n * \"frozen\" for a period of rounds proportional to their reported depth.\n *\n * During the _reveal_ round, randomness is updated after every successful reveal. Once the reveal round is concluded,\n * the _currentRoundAnchor_ is updated and users can determine if they will be eligible their overlay will be eligible\n * for the next commit phase using _isParticipatingInUpcomingRound_.\n *\n * When the _reveal_ phase has been concluded, the claim phase can begin. At this point, the truth teller and winner\n * are already determined. By calling _isWinner_, an applicant node can run the relevant logic to determine if they have\n * been selected as the beneficiary of this round. When calling _claim_, the current pot from the PostageStamp contract\n * is withdrawn and transferred to that beneficiaries address. Nodes that have revealed values that differ from the truth,\n * have their stakes \"frozen\" for a period of rounds proportional to their reported depth.\n */\n\ncontract Redistribution is AccessControl, Pausable {\n // ----------------------------- Type declarations ------------------------------\n\n // An eligible user may commit to an _obfuscatedHash_ during the commit phase...\n struct Commit {\n bytes32 overlay;\n address owner;\n bool revealed;\n uint8 height;\n uint256 stake;\n bytes32 obfuscatedHash;\n uint256 revealIndex;\n }\n // ...then provide the actual values that are the constituents of the pre-image of the _obfuscatedHash_\n // during the reveal phase.\n struct Reveal {\n bytes32 overlay;\n address owner;\n uint8 depth;\n uint256 stake;\n uint256 stakeDensity;\n bytes32 hash;\n }\n\n struct ChunkInclusionProof {\n bytes32[] proofSegments;\n bytes32 proveSegment;\n // _RCspan is known for RC 32*32\n\n // Inclusion proof of transformed address\n bytes32[] proofSegments2;\n bytes32 proveSegment2;\n // proveSegmentIndex2 known from deterministic random selection;\n uint64 chunkSpan;\n bytes32[] proofSegments3;\n // _proveSegment3 known, is equal _proveSegment2\n // proveSegmentIndex3 know, is equal _proveSegmentIndex2;\n // chunkSpan2 is equal to chunkSpan (as the data is the same)\n //\n PostageProof postageProof;\n SOCProof[] socProof;\n }\n\n struct SOCProof {\n address signer; // signer Ethereum address to check against\n bytes signature;\n bytes32 identifier; //\n bytes32 chunkAddr; // wrapped chunk address\n }\n\n struct PostageProof {\n bytes signature;\n bytes32 postageId;\n uint64 index;\n uint64 timeStamp;\n // address signer; it is provided by the postage stamp contract\n // bytes32 chunkAddr; it equals to the proveSegment argument\n }\n\n // The address of the linked PostageStamp contract.\n IPostageStamp public PostageContract;\n // The address of the linked PriceOracle contract.\n IPriceOracle public OracleContract;\n // The address of the linked Staking contract.\n IStakeRegistry public Stakes;\n\n // Commits for the current round.\n Commit[] public currentCommits;\n // Reveals for the current round.\n Reveal[] public currentReveals;\n\n // The current anchor that being processed for the reveal and claim phases of the round.\n bytes32 private currentRevealRoundAnchor;\n\n // The current random value from which we will random.\n // inputs for selection of the truth teller and beneficiary.\n bytes32 private seed;\n\n // The number of the currently active round phases.\n uint64 public currentCommitRound;\n uint64 public currentRevealRound;\n uint64 public currentClaimRound;\n\n // Settings for slashing and freezing\n uint8 private penaltyMultiplierDisagreement = 1;\n uint8 private penaltyMultiplierNonRevealed = 2;\n uint8 private penaltyRandomFactor = 100; // Use 100 as value to ignore random factor in freezing penalty\n\n // alpha=0.097612 beta=0.0716570 k=16\n uint256 private sampleMaxValue = 1284401000000000000000000000000000000000000000000000000000000000000000000;\n\n // The reveal of the winner of the last round.\n Reveal public winner;\n\n // The length of a round in blocks.\n uint256 private constant ROUND_LENGTH = 152;\n\n // Maximum value of the keccack256 hash.\n bytes32 private constant MAX_H = 0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff;\n\n // ----------------------------- Events ------------------------------\n\n /**\n * @dev Emitted when the winner of a round is selected in the claim phase\n */\n event WinnerSelected(Reveal winner);\n\n /**\n * @dev Emitted when the truth oracle of a round is selected in the claim phase.\n */\n event TruthSelected(bytes32 hash, uint8 depth);\n\n // Next two events to be removed after testing phase pending some other usefulness being found.\n /**\n * @dev Emits the number of commits being processed by the claim phase.\n */\n event CountCommits(uint256 _count);\n\n /**\n * @dev Emits the number of reveals being processed by the claim phase.\n */\n event CountReveals(uint256 _count);\n\n /**\n * @dev Logs that an overlay has committed\n */\n event Committed(uint256 roundNumber, bytes32 overlay);\n /**\n * @dev Emit from Postagestamp contract valid chunk count at the end of claim\n */\n event ChunkCount(uint256 validChunkCount);\n\n /**\n * @dev Bytes32 anhor of current reveal round\n */\n event CurrentRevealAnchor(uint256 roundNumber, bytes32 anchor);\n\n /**\n * @dev Output external call status\n */\n event PriceAdjustmentSkipped(uint16 redundancyCount);\n\n /**\n * @dev Withdraw not successful in claim\n */\n event WithdrawFailed(address owner);\n\n /**\n * @dev Logs that an overlay has revealed\n */\n event Revealed(\n uint256 roundNumber,\n bytes32 overlay,\n uint256 stake,\n uint256 stakeDensity,\n bytes32 reserveCommitment,\n uint8 depth\n );\n\n /**\n * @dev Logs for inclusion proof\n */\n event transformedChunkAddressFromInclusionProof(uint256 indexInRC, bytes32 chunkAddress);\n\n // ----------------------------- Errors ------------------------------\n\n error NotCommitPhase(); // Game is not in commit phase\n error NoCommitsReceived(); // Round didn't receive any commits\n error PhaseLastBlock(); // We don't permit commits in last block of the phase\n error CommitRoundOver(); // Commit phase in this round is over\n error CommitRoundNotStarted(); // Commit phase in this round has not started yet\n error NotMatchingOwner(); // Sender of commit is not matching the overlay address\n error MustStake2Rounds(); // Before entering the game node must stake 2 rounds prior\n error NotStaked(); // Node didn't add any staking\n error WrongPhase(); // Checking in wrong phase, need to check duing claim phase of current round for next round or commit in current round\n error AlreadyCommitted(); // Node already committed in this round\n error NotRevealPhase(); // Game is not in reveal phase\n error OutOfDepthReveal(bytes32); // Anchor is out of reported depth in Reveal phase, anchor data available as argument\n error OutOfDepthClaim(uint8); // Anchor is out of reported depth in Claim phase, entryProof index is argument\n error OutOfDepth(); // Anchor is out of reported depth\n error AlreadyRevealed(); // Node already revealed\n error NoMatchingCommit(); // No matching commit and hash\n error NotClaimPhase(); // Game is not in the claim phase\n error NoReveals(); // Round did not receive any reveals\n error FirstRevealDone(); // We don't want to return value after first reveal\n error AlreadyClaimed(); // This round was already claimed\n error NotAdmin(); // Caller of trx is not admin\n error OnlyPauser(); // Only account with pauser role can call pause/unpause\n error SocVerificationFailed(bytes32); // Soc verification failed for this element\n error SocCalcNotMatching(bytes32); // Soc address calculation does not match with the witness\n error IndexOutsideSet(bytes32); // Stamp available: index resides outside of the valid index set\n error SigRecoveryFailed(bytes32); // Stamp authorized: signature recovery failed for element\n error BatchDoesNotExist(bytes32); // Stamp alive: batch remaining balance validation failed for attached stamp\n error BucketDiffers(bytes32); // Stamp aligned: postage bucket differs from address bucket\n error InclusionProofFailed(uint8, bytes32);\n // 1 = RC inclusion proof failed for element\n // 2 = First sister segment in data must match,\n // 3 = Inclusion proof failed for original address of element\n // 4 = Inclusion proof failed for transformed address of element\n error RandomElementCheckFailed(); // Random element order check failed\n error LastElementCheckFailed(); // Last element order check failed\n error ReserveCheckFailed(bytes32 trALast); // Reserve size estimation check failed\n\n // ----------------------------- CONSTRUCTOR ------------------------------\n\n /**\n * @param staking the address of the linked Staking contract.\n * @param postageContract the address of the linked PostageStamp contract.\n * @param oracleContract the address of the linked PriceOracle contract.\n */\n constructor(address staking, address postageContract, address oracleContract) {\n Stakes = IStakeRegistry(staking);\n PostageContract = IPostageStamp(postageContract);\n OracleContract = IPriceOracle(oracleContract);\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n }\n\n ////////////////////////////////////////\n // STATE CHANGING //\n ////////////////////////////////////////\n\n /**\n * @notice Begin application for a round if eligible. Commit a hashed value for which the pre-image will be\n * subsequently revealed.\n * @dev If a node's overlay is _inProximity_(_depth_) of the _currentRoundAnchor_, that node may compute an\n * _obfuscatedHash_ by providing their _overlay_, reported storage _depth_, reserve commitment _hash_ and a\n * randomly generated, and secret _revealNonce_ to the _wrapCommit_ method.\n * @param _obfuscatedHash The calculated hash resultant of the required pre-image values.\n * and be derived from the same key pair as the message sender.\n * @param _roundNumber Node needs to provide round number for which commit is valid\n */\n function commit(bytes32 _obfuscatedHash, uint64 _roundNumber) external whenNotPaused {\n uint64 cr = currentRound();\n bytes32 _overlay = Stakes.overlayOfAddress(msg.sender);\n uint256 _stake = Stakes.nodeEffectiveStake(msg.sender);\n uint256 _lastUpdate = Stakes.lastUpdatedBlockNumberOfAddress(msg.sender);\n uint8 _height = Stakes.heightOfAddress(msg.sender);\n\n if (!currentPhaseCommit()) {\n revert NotCommitPhase();\n }\n if (block.number % ROUND_LENGTH == (ROUND_LENGTH / 4) - 1) {\n revert PhaseLastBlock();\n }\n\n if (cr > _roundNumber) {\n revert CommitRoundOver();\n }\n\n if (cr < _roundNumber) {\n revert CommitRoundNotStarted();\n }\n\n if (_lastUpdate == 0) {\n revert NotStaked();\n }\n\n if (_lastUpdate >= block.number - 2 * ROUND_LENGTH) {\n revert MustStake2Rounds();\n }\n\n // if we are in a new commit phase, reset the array of commits and\n // set the currentCommitRound to be the current one\n if (cr != currentCommitRound) {\n delete currentCommits;\n currentCommitRound = cr;\n }\n\n uint256 commitsArrayLength = currentCommits.length;\n\n for (uint256 i = 0; i < commitsArrayLength; ) {\n if (currentCommits[i].overlay == _overlay) {\n revert AlreadyCommitted();\n }\n\n unchecked {\n ++i;\n }\n }\n\n currentCommits.push(\n Commit({\n overlay: _overlay,\n owner: msg.sender,\n revealed: false,\n height: _height,\n stake: _stake,\n obfuscatedHash: _obfuscatedHash,\n revealIndex: 0\n })\n );\n\n emit Committed(_roundNumber, _overlay);\n }\n\n /**\n * @notice Reveal the pre-image values used to generate commit provided during this round's commit phase.\n * @param _depth The reported depth.\n * @param _hash The reserve commitment hash.\n * @param _revealNonce The nonce used to generate the commit that is being revealed.\n */\n function reveal(uint8 _depth, bytes32 _hash, bytes32 _revealNonce) external whenNotPaused {\n uint64 cr = currentRound();\n bytes32 _overlay = Stakes.overlayOfAddress(msg.sender);\n\n if (_depth < currentMinimumDepth()) {\n revert OutOfDepth();\n }\n\n if (!currentPhaseReveal()) {\n revert NotRevealPhase();\n }\n\n if (cr != currentCommitRound) {\n revert NoCommitsReceived();\n }\n\n if (cr != currentRevealRound) {\n currentRevealRoundAnchor = currentRoundAnchor();\n delete currentReveals;\n // We set currentRevealRound ONLY after we set current anchor\n currentRevealRound = cr;\n emit CurrentRevealAnchor(cr, currentRevealRoundAnchor);\n updateRandomness();\n }\n\n bytes32 obfuscatedHash = wrapCommit(_overlay, _depth, _hash, _revealNonce);\n uint256 id = findCommit(_overlay, obfuscatedHash);\n Commit memory revealedCommit = currentCommits[id];\n uint8 depthResponsibility = _depth - revealedCommit.height;\n\n // Check that commit is in proximity of the current anchor\n if (!inProximity(revealedCommit.overlay, currentRevealRoundAnchor, depthResponsibility)) {\n revert OutOfDepthReveal(currentRevealRoundAnchor);\n }\n // Check that the commit has not already been revealed\n if (revealedCommit.revealed) {\n revert AlreadyRevealed();\n }\n\n currentCommits[id].revealed = true;\n currentCommits[id].revealIndex = currentReveals.length;\n\n currentReveals.push(\n Reveal({\n overlay: revealedCommit.overlay,\n owner: revealedCommit.owner,\n depth: _depth,\n stake: revealedCommit.stake,\n stakeDensity: revealedCommit.stake * uint256(2 ** depthResponsibility),\n hash: _hash\n })\n );\n\n emit Revealed(\n cr,\n revealedCommit.overlay,\n revealedCommit.stake,\n revealedCommit.stake * uint256(2 ** depthResponsibility),\n _hash,\n _depth\n );\n }\n\n /**\n * @notice Helper function to get this round truth\n * @dev\n */\n function claim(\n ChunkInclusionProof calldata entryProof1,\n ChunkInclusionProof calldata entryProof2,\n ChunkInclusionProof calldata entryProofLast\n ) external whenNotPaused {\n winnerSelection();\n\n Reveal memory winnerSelected = winner;\n uint256 indexInRC1;\n uint256 indexInRC2;\n bytes32 _currentRevealRoundAnchor = currentRevealRoundAnchor;\n bytes32 _seed = seed;\n\n // rand(14)\n indexInRC1 = uint256(_seed) % 15;\n // rand(13)\n indexInRC2 = uint256(_seed) % 14;\n if (indexInRC2 >= indexInRC1) {\n indexInRC2++;\n }\n\n if (!inProximity(entryProofLast.proveSegment, _currentRevealRoundAnchor, winnerSelected.depth)) {\n revert OutOfDepthClaim(3);\n }\n\n inclusionFunction(entryProofLast, 30);\n stampFunction(entryProofLast);\n socFunction(entryProofLast);\n\n if (!inProximity(entryProof1.proveSegment, _currentRevealRoundAnchor, winnerSelected.depth)) {\n revert OutOfDepthClaim(2);\n }\n\n inclusionFunction(entryProof1, indexInRC1 * 2);\n stampFunction(entryProof1);\n socFunction(entryProof1);\n\n if (!inProximity(entryProof2.proveSegment, _currentRevealRoundAnchor, winnerSelected.depth)) {\n revert OutOfDepthClaim(1);\n }\n\n inclusionFunction(entryProof2, indexInRC2 * 2);\n stampFunction(entryProof2);\n socFunction(entryProof2);\n\n checkOrder(\n indexInRC1,\n indexInRC2,\n entryProof1.proofSegments[0],\n entryProof2.proofSegments[0],\n entryProofLast.proofSegments[0]\n );\n\n estimateSize(entryProofLast.proofSegments[0]);\n\n // Do the check if the withdraw was success\n (bool success, ) = address(PostageContract).call(\n abi.encodeWithSignature(\"withdraw(address)\", winnerSelected.owner)\n );\n if (!success) {\n emit WithdrawFailed(winnerSelected.owner);\n }\n\n emit WinnerSelected(winnerSelected);\n emit ChunkCount(PostageContract.validChunkCount());\n }\n\n function winnerSelection() internal {\n uint64 cr = currentRound();\n\n if (!currentPhaseClaim()) {\n revert NotClaimPhase();\n }\n\n if (cr != currentRevealRound) {\n revert NoReveals();\n }\n\n if (cr <= currentClaimRound) {\n revert AlreadyClaimed();\n }\n\n uint256 currentWinnerSelectionSum = 0;\n uint256 redundancyCount = 0;\n bytes32 randomNumber;\n uint256 randomNumberTrunc;\n\n bytes32 truthRevealedHash;\n uint8 truthRevealedDepth;\n uint256 currentCommitsLength = currentCommits.length;\n\n emit CountCommits(currentCommitsLength);\n emit CountReveals(currentReveals.length);\n\n (truthRevealedHash, truthRevealedDepth) = getCurrentTruth();\n emit TruthSelected(truthRevealedHash, truthRevealedDepth);\n string memory winnerSelectionAnchor = currentWinnerSelectionAnchor();\n\n for (uint256 i = 0; i < currentCommitsLength; ) {\n Commit memory currentCommit = currentCommits[i];\n uint256 revIndex = currentCommit.revealIndex;\n Reveal memory currentReveal = currentReveals[revIndex];\n\n // Select winner with valid truth\n if (\n currentCommit.revealed &&\n truthRevealedHash == currentReveal.hash &&\n truthRevealedDepth == currentReveal.depth\n ) {\n currentWinnerSelectionSum += currentReveal.stakeDensity;\n randomNumber = keccak256(abi.encodePacked(winnerSelectionAnchor, redundancyCount));\n randomNumberTrunc = uint256(randomNumber & MAX_H);\n\n if (randomNumberTrunc * currentWinnerSelectionSum < currentReveal.stakeDensity * (uint256(MAX_H) + 1)) {\n winner = currentReveal;\n }\n\n redundancyCount++;\n }\n\n // Freeze deposit if any truth is false, make it a penaltyRandomFactor chance for this to happen\n if (\n currentCommit.revealed &&\n (truthRevealedHash != currentReveal.hash || truthRevealedDepth != currentReveal.depth) &&\n (block.prevrandao % 100 < penaltyRandomFactor)\n ) {\n Stakes.freezeDeposit(\n currentReveal.owner,\n penaltyMultiplierDisagreement * ROUND_LENGTH * uint256(2 ** truthRevealedDepth)\n );\n }\n\n // Slash deposits if revealed is false\n if (!currentCommit.revealed) {\n // slash in later phase (ph5)\n // Stakes.slashDeposit(currentCommits[i].overlay, currentCommits[i].stake);\n Stakes.freezeDeposit(\n currentCommit.owner,\n penaltyMultiplierNonRevealed * ROUND_LENGTH * uint256(2 ** truthRevealedDepth)\n );\n }\n unchecked {\n ++i;\n }\n }\n\n bool success = OracleContract.adjustPrice(uint16(redundancyCount));\n if (!success) {\n emit PriceAdjustmentSkipped(uint16(redundancyCount));\n }\n currentClaimRound = cr;\n }\n\n function inclusionFunction(ChunkInclusionProof calldata entryProof, uint256 indexInRC) internal {\n uint256 randomChunkSegmentIndex = uint256(seed) % 128;\n bytes32 calculatedTransformedAddr = TransformedBMTChunk.transformedChunkAddressFromInclusionProof(\n entryProof.proofSegments3,\n entryProof.proveSegment2,\n randomChunkSegmentIndex,\n entryProof.chunkSpan,\n currentRevealRoundAnchor\n );\n\n emit transformedChunkAddressFromInclusionProof(indexInRC, calculatedTransformedAddr);\n\n if (\n winner.hash !=\n BMTChunk.chunkAddressFromInclusionProof(\n entryProof.proofSegments,\n entryProof.proveSegment,\n indexInRC,\n 32 * 32\n )\n ) {\n revert InclusionProofFailed(1, calculatedTransformedAddr);\n }\n\n if (entryProof.proofSegments2[0] != entryProof.proofSegments3[0]) {\n revert InclusionProofFailed(2, calculatedTransformedAddr);\n }\n\n bytes32 originalAddress = entryProof.socProof.length > 0\n ? entryProof.socProof[0].chunkAddr // soc attestation in socFunction\n : entryProof.proveSegment;\n\n if (\n originalAddress !=\n BMTChunk.chunkAddressFromInclusionProof(\n entryProof.proofSegments2,\n entryProof.proveSegment2,\n randomChunkSegmentIndex,\n entryProof.chunkSpan\n )\n ) {\n revert InclusionProofFailed(3, calculatedTransformedAddr);\n }\n\n // In case of SOC, the transformed address is hashed together with its address in the sample\n if (entryProof.socProof.length > 0) {\n calculatedTransformedAddr = keccak256(\n abi.encode(\n entryProof.proveSegment, // SOC address\n calculatedTransformedAddr\n )\n );\n }\n\n if (entryProof.proofSegments[0] != calculatedTransformedAddr) {\n revert InclusionProofFailed(4, calculatedTransformedAddr);\n }\n }\n\n /**\n * @notice Set freezing parameters\n */\n function setFreezingParams(\n uint8 _penaltyMultiplierDisagreement,\n uint8 _penaltyMultiplierNonRevealed,\n uint8 _penaltyRandomFactor\n ) external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert NotAdmin();\n }\n\n penaltyMultiplierDisagreement = _penaltyMultiplierDisagreement;\n penaltyMultiplierNonRevealed = _penaltyMultiplierNonRevealed;\n penaltyRandomFactor = _penaltyRandomFactor;\n }\n\n /**\n * @notice changes the max sample value used for reserve estimation\n */\n function setSampleMaxValue(uint256 _sampleMaxValue) external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert NotAdmin();\n }\n\n sampleMaxValue = _sampleMaxValue;\n }\n\n /**\n * @notice Updates the source of randomness. Uses block.difficulty in pre-merge chains, this is substituted\n * to block.prevrandao in post merge chains.\n */\n function updateRandomness() private {\n seed = keccak256(abi.encode(seed, block.prevrandao));\n }\n\n /**\n * @dev Pause the contract. The contract is provably stopped by renouncing\n the pauser role and the admin role after pausing, can only be called by the `PAUSER`\n */\n function pause() public {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert OnlyPauser();\n }\n\n _pause();\n }\n\n /**\n * @dev Unpause the contract, can only be called by the pauser when paused\n */\n function unPause() public {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {\n revert OnlyPauser();\n }\n _unpause();\n }\n\n ////////////////////////////////////////\n // STATE READING //\n ////////////////////////////////////////\n\n // ----------------------------- Anchor calculations ------------------------------\n\n /**\n * @notice Returns the current random seed which is used to determine later utilised random numbers.\n * If rounds have elapsed without reveals, hash the seed with an incremented nonce to produce a new\n * random seed and hence a new round anchor.\n */\n function currentSeed() public view returns (bytes32) {\n uint64 cr = currentRound();\n bytes32 currentSeedValue = seed;\n\n if (cr > currentRevealRound + 1) {\n uint256 difference = cr - currentRevealRound - 1;\n currentSeedValue = keccak256(abi.encodePacked(currentSeedValue, difference));\n }\n\n return currentSeedValue;\n }\n\n /**\n * @notice Returns the seed which will become current once the next commit phase begins.\n * Used to determine what the next round's anchor will be.\n */\n function nextSeed() public view returns (bytes32) {\n uint64 cr = currentRound() + 1;\n bytes32 currentSeedValue = seed;\n\n if (cr > currentRevealRound + 1) {\n uint256 difference = cr - currentRevealRound - 1;\n currentSeedValue = keccak256(abi.encodePacked(currentSeedValue, difference));\n }\n\n return currentSeedValue;\n }\n\n /**\n * @notice The random value used to choose the selected truth teller.\n */\n function currentTruthSelectionAnchor() private view returns (string memory) {\n if (!currentPhaseClaim()) {\n revert NotClaimPhase();\n }\n\n uint64 cr = currentRound();\n if (cr != currentRevealRound) {\n revert NoReveals();\n }\n\n return string(abi.encodePacked(seed, \"0\"));\n }\n\n /**\n * @notice The random value used to choose the selected beneficiary.\n */\n function currentWinnerSelectionAnchor() private view returns (string memory) {\n if (!currentPhaseClaim()) {\n revert NotClaimPhase();\n }\n uint64 cr = currentRound();\n if (cr != currentRevealRound) {\n revert NoReveals();\n }\n\n return string(abi.encodePacked(seed, \"1\"));\n }\n\n /**\n * @notice The anchor used to determine eligibility for the current round.\n * @dev A node must be within proximity order of less than or equal to the storage depth they intend to report.\n */\n function currentRoundAnchor() public view returns (bytes32 returnVal) {\n // This will be called in reveal phase and set as currentRevealRoundAnchor or in\n // commit phase when checking eligibility for next round by isParticipatingInUpcomingRound\n if (currentPhaseCommit() || (currentRound() > currentRevealRound && !currentPhaseClaim())) {\n return currentSeed();\n }\n\n // This will be called by isParticipatingInUpcomingRound check in claim phase\n if (currentPhaseClaim()) {\n return nextSeed();\n }\n\n // Without this, this function will output 0x0 after first reveal which is value and we prefere it reverts\n if (currentPhaseReveal() && currentRound() == currentRevealRound) {\n revert FirstRevealDone();\n }\n }\n\n /**\n * @notice Returns true if an overlay address _A_ is within proximity order _minimum_ of _B_.\n * @param A An overlay address to compare.\n * @param B An overlay address to compare.\n * @param minimum Minimum proximity order.\n */\n function inProximity(bytes32 A, bytes32 B, uint8 minimum) public pure returns (bool) {\n if (minimum == 0) {\n return true;\n }\n\n return uint256(A ^ B) < uint256(2 ** (256 - minimum));\n }\n\n // ----------------------------- Commit ------------------------------\n\n /**\n * @notice The number of the current round.\n */\n function currentRound() public view returns (uint64) {\n return uint64(block.number / ROUND_LENGTH);\n }\n\n /**\n * @notice Returns true if current block is during commit phase.\n */\n function currentPhaseCommit() public view returns (bool) {\n if (block.number % ROUND_LENGTH < ROUND_LENGTH / 4) {\n return true;\n }\n return false;\n }\n\n /**\n * @notice Determine if a the owner of a given overlay can participate in the upcoming round.\n * @param _owner The address of the applicant from.\n * @param _depth The storage depth the applicant intends to report.\n */\n function isParticipatingInUpcomingRound(address _owner, uint8 _depth) public view returns (bool) {\n uint256 _lastUpdate = Stakes.lastUpdatedBlockNumberOfAddress(_owner);\n uint8 _depthResponsibility = _depth - Stakes.heightOfAddress(_owner);\n\n if (currentPhaseReveal()) {\n revert WrongPhase();\n }\n\n if (_lastUpdate == 0) {\n revert NotStaked();\n }\n\n if (_lastUpdate >= block.number - 2 * ROUND_LENGTH) {\n revert MustStake2Rounds();\n }\n\n return inProximity(Stakes.overlayOfAddress(_owner), currentRoundAnchor(), _depthResponsibility);\n }\n\n // ----------------------------- Reveal ------------------------------\n\n /**\n * @notice Returns minimum depth reveal has to have to participate in this round\n */\n function currentMinimumDepth() public view returns (uint8) {\n // We are checking value in reveal phase, as the currentCommitRound is set to the current round\n // but the currentClaimRound is still set to the last time claim was made\n // We add 1 to ensure that for the next round the minimum depth is the same as last winner depth\n\n uint256 difference = currentCommitRound - currentClaimRound;\n uint8 skippedRounds = uint8(difference > 254 ? 254 : difference) + 1;\n\n uint8 lastWinnerDepth = winner.depth;\n\n // We ensure that skippedRounds is not bigger than lastWinnerDepth, because of overflow\n return skippedRounds >= lastWinnerDepth ? 0 : lastWinnerDepth - skippedRounds;\n }\n\n /**\n * @notice Helper function to get this node reveal in commits\n * @dev\n */\n function findCommit(bytes32 _overlay, bytes32 _obfuscatedHash) internal view returns (uint256) {\n for (uint256 i = 0; i < currentCommits.length; ) {\n if (currentCommits[i].overlay == _overlay && _obfuscatedHash == currentCommits[i].obfuscatedHash) {\n return i;\n }\n unchecked {\n ++i;\n }\n }\n revert NoMatchingCommit();\n }\n\n /**\n * @notice Hash the pre-image values to the obsfucated hash.\n * @dev _revealNonce_ must be randomly generated, used once and kept secret until the reveal phase.\n * @param _overlay The overlay address of the applicant.\n * @param _depth The reported depth.\n * @param _hash The reserve commitment hash.\n * @param revealNonce A random, single use, secret nonce.\n */\n function wrapCommit(\n bytes32 _overlay,\n uint8 _depth,\n bytes32 _hash,\n bytes32 revealNonce\n ) public pure returns (bytes32) {\n return keccak256(abi.encodePacked(_overlay, _depth, _hash, revealNonce));\n }\n\n /**\n * @notice Returns true if current block is during reveal phase.\n */\n function currentPhaseReveal() public view returns (bool) {\n uint256 number = block.number % ROUND_LENGTH;\n if (number >= ROUND_LENGTH / 4 && number < ROUND_LENGTH / 2) {\n return true;\n }\n return false;\n }\n\n /**\n * @notice Returns true if current block is during reveal phase.\n */\n function currentRoundReveals() public view returns (Reveal[] memory) {\n if (!currentPhaseClaim()) {\n revert NotClaimPhase();\n }\n uint64 cr = currentRound();\n if (cr != currentRevealRound) {\n revert NoReveals();\n }\n\n return currentReveals;\n }\n\n // ----------------------------- Claim ------------------------------\n\n /**\n * @notice Returns true if current block is during claim phase.\n */\n function currentPhaseClaim() public view returns (bool) {\n if (block.number % ROUND_LENGTH >= ROUND_LENGTH / 2) {\n return true;\n }\n return false;\n }\n\n function getCurrentTruth() internal view returns (bytes32 Hash, uint8 Depth) {\n uint256 currentSum;\n bytes32 randomNumber;\n uint256 randomNumberTrunc;\n\n bytes32 truthRevealedHash;\n uint8 truthRevealedDepth;\n uint256 revIndex;\n string memory truthSelectionAnchor = currentTruthSelectionAnchor();\n uint256 commitsArrayLength = currentCommits.length;\n\n for (uint256 i = 0; i < commitsArrayLength; ) {\n if (currentCommits[i].revealed) {\n revIndex = currentCommits[i].revealIndex;\n currentSum += currentReveals[revIndex].stakeDensity;\n randomNumber = keccak256(abi.encodePacked(truthSelectionAnchor, i));\n randomNumberTrunc = uint256(randomNumber & MAX_H);\n\n // question is whether randomNumber / MAX_H < probability\n // where probability is stakeDensity / currentSum\n // to avoid resorting to floating points all divisions should be\n // simplified with multiplying both sides (as long as divisor > 0)\n // randomNumber / (MAX_H + 1) < stakeDensity / currentSum\n // ( randomNumber / (MAX_H + 1) ) * currentSum < stakeDensity\n // randomNumber * currentSum < stakeDensity * (MAX_H + 1)\n if (randomNumberTrunc * currentSum < currentReveals[revIndex].stakeDensity * (uint256(MAX_H) + 1)) {\n truthRevealedHash = currentReveals[revIndex].hash;\n truthRevealedDepth = currentReveals[revIndex].depth;\n }\n }\n unchecked {\n ++i;\n }\n }\n\n return (truthRevealedHash, truthRevealedDepth);\n }\n\n /**\n * @notice Determine if a the owner of a given overlay will be the beneficiary of the claim phase.\n * @param _overlay The overlay address of the applicant.\n */\n function isWinner(bytes32 _overlay) public view returns (bool) {\n if (!currentPhaseClaim()) {\n revert NotClaimPhase();\n }\n\n uint64 cr = currentRound();\n if (cr != currentRevealRound) {\n revert NoReveals();\n }\n\n if (cr <= currentClaimRound) {\n revert AlreadyClaimed();\n }\n\n uint256 currentWinnerSelectionSum;\n bytes32 winnerIs;\n bytes32 randomNumber;\n uint256 randomNumberTrunc;\n bytes32 truthRevealedHash;\n uint8 truthRevealedDepth;\n uint256 revIndex;\n string memory winnerSelectionAnchor = currentWinnerSelectionAnchor();\n uint256 redundancyCount = 0;\n\n // Get current truth\n (truthRevealedHash, truthRevealedDepth) = getCurrentTruth();\n uint256 commitsArrayLength = currentCommits.length;\n\n for (uint256 i = 0; i < commitsArrayLength; ) {\n revIndex = currentCommits[i].revealIndex;\n\n // Deterministically read winner\n if (\n currentCommits[i].revealed &&\n truthRevealedHash == currentReveals[revIndex].hash &&\n truthRevealedDepth == currentReveals[revIndex].depth\n ) {\n currentWinnerSelectionSum += currentReveals[revIndex].stakeDensity;\n randomNumber = keccak256(abi.encodePacked(winnerSelectionAnchor, redundancyCount));\n randomNumberTrunc = uint256(randomNumber & MAX_H);\n\n if (\n randomNumberTrunc * currentWinnerSelectionSum <\n currentReveals[revIndex].stakeDensity * (uint256(MAX_H) + 1)\n ) {\n winnerIs = currentReveals[revIndex].overlay;\n }\n\n redundancyCount++;\n }\n unchecked {\n ++i;\n }\n }\n\n return (winnerIs == _overlay);\n }\n\n // ----------------------------- Claim verifications ------------------------------\n\n function socFunction(ChunkInclusionProof calldata entryProof) internal pure {\n if (entryProof.socProof.length == 0) return;\n\n if (\n !Signatures.socVerify(\n entryProof.socProof[0].signer, // signer Ethereum address to check against\n entryProof.socProof[0].signature,\n entryProof.socProof[0].identifier,\n entryProof.socProof[0].chunkAddr\n )\n ) {\n revert SocVerificationFailed(entryProof.socProof[0].chunkAddr);\n }\n\n if (\n calculateSocAddress(entryProof.socProof[0].identifier, entryProof.socProof[0].signer) !=\n entryProof.proveSegment\n ) {\n revert SocCalcNotMatching(entryProof.socProof[0].chunkAddr);\n }\n }\n\n function stampFunction(ChunkInclusionProof calldata entryProof) internal view {\n // authentic\n (address batchOwner, uint8 batchDepth, uint8 bucketDepth, , , ) = PostageContract.batches(\n entryProof.postageProof.postageId\n );\n\n // alive\n if (batchOwner == address(0)) {\n revert BatchDoesNotExist(entryProof.postageProof.postageId); // Batch does not exist or expired\n }\n\n uint32 postageIndex = getPostageIndex(entryProof.postageProof.index);\n uint256 maxPostageIndex = postageStampIndexCount(batchDepth, bucketDepth);\n // available\n if (postageIndex >= maxPostageIndex) {\n revert IndexOutsideSet(entryProof.postageProof.postageId);\n }\n\n // aligned\n uint64 postageBucket = getPostageBucket(entryProof.postageProof.index);\n uint64 addressBucket = addressToBucket(entryProof.proveSegment, bucketDepth);\n if (postageBucket != addressBucket) {\n revert BucketDiffers(entryProof.postageProof.postageId);\n }\n\n // authorized\n if (\n !Signatures.postageVerify(\n batchOwner,\n entryProof.postageProof.signature,\n entryProof.proveSegment,\n entryProof.postageProof.postageId,\n entryProof.postageProof.index,\n entryProof.postageProof.timeStamp\n )\n ) {\n revert SigRecoveryFailed(entryProof.postageProof.postageId);\n }\n }\n\n function addressToBucket(bytes32 swarmAddress, uint8 bucketDepth) internal pure returns (uint32) {\n uint32 prefix = uint32(uint256(swarmAddress) >> (256 - 32));\n return prefix >> (32 - bucketDepth);\n }\n\n function postageStampIndexCount(uint8 postageDepth, uint8 bucketDepth) internal pure returns (uint256) {\n return 1 << (postageDepth - bucketDepth);\n }\n\n function getPostageIndex(uint64 signedIndex) internal pure returns (uint32) {\n return uint32(signedIndex);\n }\n\n function getPostageBucket(uint64 signedIndex) internal pure returns (uint64) {\n return uint32(signedIndex >> 32);\n }\n\n function calculateSocAddress(bytes32 identifier, address signer) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(identifier, signer));\n }\n\n function checkOrder(uint256 a, uint256 b, bytes32 trA1, bytes32 trA2, bytes32 trALast) internal pure {\n if (a < b) {\n if (uint256(trA1) >= uint256(trA2)) {\n revert RandomElementCheckFailed();\n }\n if (uint256(trA2) >= uint256(trALast)) {\n revert LastElementCheckFailed();\n }\n } else {\n if (uint256(trA2) >= uint256(trA1)) {\n revert RandomElementCheckFailed();\n }\n if (uint256(trA1) >= uint256(trALast)) {\n revert LastElementCheckFailed();\n }\n }\n }\n\n function estimateSize(bytes32 trALast) internal view {\n if (uint256(trALast) >= sampleMaxValue) {\n revert ReserveCheckFailed(trALast);\n }\n }\n}\n" + }, + "src/Staking.sol": { + "content": "// SPDX-License-Identifier: BSD-3-Clause\npragma solidity ^0.8.19;\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"@openzeppelin/contracts/security/Pausable.sol\";\n\ninterface IPriceOracle {\n function currentPrice() external view returns (uint32);\n}\n\n/**\n * @title Staking contract for the Swarm storage incentives\n * @author The Swarm Authors\n * @dev Allows users to stake tokens in order to be eligible for the Redistribution Schelling co-ordination game.\n * Stakes are frozen or slashed by the Redistribution contract in response to violations of the\n * protocol.\n */\n\ncontract StakeRegistry is AccessControl, Pausable {\n // ----------------------------- State variables ------------------------------\n\n struct Stake {\n // Overlay of the node that is being staked\n bytes32 overlay;\n // Stake balance expressed through price oracle\n uint256 committedStake;\n // Stake balance expressed in BZZ\n uint256 potentialStake;\n // Block height the stake was updated, also used as flag to check if the stake is set\n uint256 lastUpdatedBlockNumber;\n // Node indicating its increased reserve\n uint8 height;\n }\n\n // Associate every stake id with node address data.\n mapping(address => Stake) public stakes;\n\n // Role allowed to freeze and slash entries\n bytes32 public constant REDISTRIBUTOR_ROLE = keccak256(\"REDISTRIBUTOR_ROLE\");\n\n // Swarm network ID\n uint64 NetworkId;\n\n // The miniumum stake allowed to be staked using the Staking contract.\n uint64 private constant MIN_STAKE = 100000000000000000;\n\n // Address of the staked ERC20 token\n address public immutable bzzToken;\n\n // The address of the linked PriceOracle contract.\n IPriceOracle public OracleContract;\n\n // ----------------------------- Events ------------------------------\n\n /**\n * @dev Emitted when a stake is created or updated by `owner` of the `overlay`.\n */\n event StakeUpdated(\n address indexed owner,\n uint256 committedStake,\n uint256 potentialStake,\n bytes32 overlay,\n uint256 lastUpdatedBlock,\n uint8 height\n );\n\n /**\n * @dev Emitted when a stake for address `slashed` is slashed by `amount`.\n */\n event StakeSlashed(address slashed, bytes32 overlay, uint256 amount);\n\n /**\n * @dev Emitted when a stake for address `frozen` is frozen for `time` blocks.\n */\n event StakeFrozen(address frozen, bytes32 overlay, uint256 time);\n\n /**\n * @dev Emitted when a address changes overlay it uses\n */\n event OverlayChanged(address owner, bytes32 overlay);\n\n /**\n * @dev Emitted when a stake for address is withdrawn\n */\n event StakeWithdrawn(address node, uint256 amount);\n\n // ----------------------------- Errors ------------------------------\n\n error TransferFailed(); // Used when token transfers fail\n error Frozen(); // Used when an action cannot proceed because the overlay is frozen\n error Unauthorized(); // Used where only the owner can perform the action\n error OnlyRedistributor(); // Used when only the redistributor role is allowed\n error OnlyPauser(); // Used when only the pauser role is allowed\n error BelowMinimumStake(); // Node participating in game has stake below minimum treshold\n\n // ----------------------------- CONSTRUCTOR ------------------------------\n\n /**\n * @param _bzzToken Address of the staked ERC20 token\n * @param _NetworkId Swarm network ID\n */\n constructor(address _bzzToken, uint64 _NetworkId, address _oracleContract) {\n NetworkId = _NetworkId;\n bzzToken = _bzzToken;\n OracleContract = IPriceOracle(_oracleContract);\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n }\n\n ////////////////////////////////////////\n // STATE SETTING //\n ////////////////////////////////////////\n\n /**\n * @notice Create a new stake or update an existing one, change overlay of node\n * @dev At least `_initialBalancePerChunk*2^depth` number of tokens need to be preapproved for this contract.\n * @param _setNonce Nonce that was used for overlay calculation.\n * @param _addAmount Deposited amount of ERC20 tokens, equals to added Potential stake value\n * @param _height increased reserve by registering the number of doublings\n */\n function manageStake(bytes32 _setNonce, uint256 _addAmount, uint8 _height) external whenNotPaused {\n bytes32 _previousOverlay = stakes[msg.sender].overlay;\n uint256 _stakingSet = stakes[msg.sender].lastUpdatedBlockNumber;\n bytes32 _newOverlay = keccak256(abi.encodePacked(msg.sender, reverse(NetworkId), _setNonce));\n\n // First time adding stake, check the minimum is added, take into account height\n if (_addAmount < MIN_STAKE * 2 ** _height && _stakingSet == 0) {\n revert BelowMinimumStake();\n }\n\n if (_stakingSet != 0 && !addressNotFrozen(msg.sender)) revert Frozen();\n uint256 updatedPotentialStake = stakes[msg.sender].potentialStake + _addAmount;\n uint256 updatedCommittedStake = updatedPotentialStake / (OracleContract.currentPrice() * 2 ** _height);\n\n stakes[msg.sender] = Stake({\n overlay: _newOverlay,\n committedStake: updatedCommittedStake,\n potentialStake: updatedPotentialStake,\n lastUpdatedBlockNumber: block.number,\n height: _height\n });\n\n // Transfer tokens and emit event that stake has been updated\n if (_addAmount > 0) {\n if (!ERC20(bzzToken).transferFrom(msg.sender, address(this), _addAmount)) revert TransferFailed();\n emit StakeUpdated(\n msg.sender,\n updatedCommittedStake,\n updatedPotentialStake,\n _newOverlay,\n block.number,\n _height\n );\n }\n\n // Emit overlay change event\n if (_previousOverlay != _newOverlay) {\n emit OverlayChanged(msg.sender, _newOverlay);\n }\n }\n\n /**\n * @dev Withdraw node stake surplus\n */\n function withdrawFromStake() external {\n uint256 _potentialStake = stakes[msg.sender].potentialStake;\n uint256 _surplusStake = _potentialStake -\n calculateEffectiveStake(stakes[msg.sender].committedStake, _potentialStake, stakes[msg.sender].height);\n\n if (_surplusStake > 0) {\n stakes[msg.sender].potentialStake -= _surplusStake;\n if (!ERC20(bzzToken).transfer(msg.sender, _surplusStake)) revert TransferFailed();\n emit StakeWithdrawn(msg.sender, _surplusStake);\n }\n }\n\n /**\n * @dev Migrate stake only when the staking contract is paused,\n * can only be called by the owner of the stake\n */\n function migrateStake() external whenPaused {\n // We take out all the stake so user can migrate stake to other contract\n if (lastUpdatedBlockNumberOfAddress(msg.sender) != 0) {\n if (!ERC20(bzzToken).transfer(msg.sender, stakes[msg.sender].potentialStake)) revert TransferFailed();\n delete stakes[msg.sender];\n }\n }\n\n /**\n * @dev Freeze an existing stake, can only be called by the redistributor\n * @param _owner the addres selected\n * @param _time penalty length in blocknumbers\n */\n function freezeDeposit(address _owner, uint256 _time) external {\n if (!hasRole(REDISTRIBUTOR_ROLE, msg.sender)) revert OnlyRedistributor();\n\n if (stakes[_owner].lastUpdatedBlockNumber != 0) {\n stakes[_owner].lastUpdatedBlockNumber = block.number + _time;\n emit StakeFrozen(_owner, stakes[_owner].overlay, _time);\n }\n }\n\n /**\n * @dev Slash an existing stake, can only be called by the `redistributor`\n * @param _owner the _owner adress selected\n * @param _amount the amount to be slashed\n */\n function slashDeposit(address _owner, uint256 _amount) external {\n if (!hasRole(REDISTRIBUTOR_ROLE, msg.sender)) revert OnlyRedistributor();\n\n if (stakes[_owner].lastUpdatedBlockNumber != 0) {\n if (stakes[_owner].potentialStake > _amount) {\n stakes[_owner].potentialStake -= _amount;\n stakes[_owner].lastUpdatedBlockNumber = block.number;\n } else {\n delete stakes[_owner];\n }\n }\n emit StakeSlashed(_owner, stakes[_owner].overlay, _amount);\n }\n\n function changeNetworkId(uint64 _NetworkId) external {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) revert Unauthorized();\n NetworkId = _NetworkId;\n }\n\n /**\n * @dev Pause the contract. The contract is provably stopped by renouncing\n the pauser role and the admin role after pausing, can only be called by the `PAUSER`\n */\n function pause() public {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) revert OnlyPauser();\n _pause();\n }\n\n /**\n * @dev Unpause the contract, can only be called by the pauser when paused\n */\n function unPause() public {\n if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) revert OnlyPauser();\n _unpause();\n }\n\n ////////////////////////////////////////\n // STATE READING //\n ////////////////////////////////////////\n\n /**\n * @dev Checks to see if `address` is frozen.\n * @param _owner owner of staked address\n *\n * Returns a boolean value indicating whether the operation succeeded.\n */\n function addressNotFrozen(address _owner) internal view returns (bool) {\n return stakes[_owner].lastUpdatedBlockNumber < block.number;\n }\n\n /**\n * @dev Returns the current `effectiveStake` of `address`. previously usable stake\n * @param _owner _owner of node\n */\n function nodeEffectiveStake(address _owner) public view returns (uint256) {\n return\n addressNotFrozen(_owner)\n ? calculateEffectiveStake(\n stakes[_owner].committedStake,\n stakes[_owner].potentialStake,\n stakes[_owner].height\n )\n : 0;\n }\n\n /**\n * @dev Check the amount that is possible to withdraw as surplus\n */\n function withdrawableStake() public view returns (uint256) {\n uint256 _potentialStake = stakes[msg.sender].potentialStake;\n return\n _potentialStake -\n calculateEffectiveStake(stakes[msg.sender].committedStake, _potentialStake, stakes[msg.sender].height);\n }\n\n /**\n * @dev Returns the `lastUpdatedBlockNumber` of `address`.\n */\n function lastUpdatedBlockNumberOfAddress(address _owner) public view returns (uint256) {\n return stakes[_owner].lastUpdatedBlockNumber;\n }\n\n /**\n * @dev Returns the currently used overlay of the address.\n * @param _owner address of node\n */\n function overlayOfAddress(address _owner) public view returns (bytes32) {\n return stakes[_owner].overlay;\n }\n\n /**\n * @dev Returns the currently height of the address.\n * @param _owner address of node\n */\n function heightOfAddress(address _owner) public view returns (uint8) {\n return stakes[_owner].height;\n }\n\n function calculateEffectiveStake(\n uint256 committedStake,\n uint256 potentialStakeBalance,\n uint8 height\n ) internal view returns (uint256) {\n // Calculate the product of committedStake and unitPrice to get price in BZZ\n uint256 committedStakeBzz = (2 ** height) * committedStake * OracleContract.currentPrice();\n\n // Return the minimum value between committedStakeBzz and potentialStakeBalance\n if (committedStakeBzz < potentialStakeBalance) {\n return committedStakeBzz;\n } else {\n return potentialStakeBalance;\n }\n }\n\n /**\n * @dev Please both Endians 🥚.\n * @param input Eth address used for overlay calculation.\n */\n function reverse(uint64 input) internal pure returns (uint64 v) {\n v = input;\n\n // swap bytes\n v = ((v & 0xFF00FF00FF00FF00) >> 8) | ((v & 0x00FF00FF00FF00FF) << 8);\n\n // swap 2-byte long pairs\n v = ((v & 0xFFFF0000FFFF0000) >> 16) | ((v & 0x0000FFFF0000FFFF) << 16);\n\n // swap 4-byte long pairs\n v = (v >> 32) | (v << 32);\n }\n}\n" + }, + "src/TestToken.sol": { + "content": "// SPDX-License-Identifier: BSD-3-Clause\npragma solidity ^0.8.19;\n\nimport \"@openzeppelin/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol\";\n\ncontract TestToken is ERC20PresetMinterPauser {\n uint256 private _initialSupply;\n\n constructor(string memory name, string memory symbol, uint256 initialSupply) ERC20PresetMinterPauser(name, symbol) {\n _initialSupply = initialSupply;\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n _mint(msg.sender, initialSupply);\n }\n\n // We use 16 decimals for BZZ/sBZZ token so we need to override it here\n function decimals() public view virtual override returns (uint8) {\n return 16;\n }\n}\n" + }, + "src/Util/ChunkProof.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\nlibrary BMTChunk {\n // max chunk payload size\n uint256 public constant MAX_CHUNK_PAYLOAD_SIZE = 4096;\n // segment byte size\n uint256 public constant SEGMENT_SIZE = 32;\n\n /**\n * @notice Changes the endianness of a uint64.\n * @dev https://graphics.stanford.edu/~seander/bithacks.html#ReverseParallel\n * @param _b The unsigned integer to reverse\n * @return v - The reversed value\n */\n function reverseUint64(uint64 _b) public pure returns (uint64) {\n uint256 v = _b;\n\n // swap bytes\n v =\n ((v >> 8) & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) |\n ((v & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) << 8);\n // swap 2-byte long pairs\n v =\n ((v >> 16) & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) |\n ((v & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) << 16);\n // swap 4-byte long pairs\n v =\n ((v >> 32) & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) |\n ((v & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) << 32);\n\n return uint64(v);\n }\n\n /** Calculates the root hash from the provided inclusion proof segments and its corresponding segment index\n * @param _proofSegments Proof segments.\n * @param _proveSegment Segment to prove.\n * @param _proveSegmentIndex Prove segment index\n * @return _calculatedHash chunk hash\n */\n function rootHashFromInclusionProof(\n bytes32[] memory _proofSegments,\n bytes32 _proveSegment,\n uint256 _proveSegmentIndex\n ) internal pure returns (bytes32 _calculatedHash) {\n _calculatedHash = _proveSegment;\n for (uint256 i = 0; i < _proofSegments.length; i++) {\n bool mergeFromRight = _proveSegmentIndex % 2 == 0;\n _calculatedHash = mergeSegment(_calculatedHash, _proofSegments[i], mergeFromRight);\n _proveSegmentIndex >>= 1;\n }\n return _calculatedHash;\n }\n\n /**\n * Calculate the chunk address from the Binary Merkle Tree of the chunk data\n *\n * The BMT chunk address is the hash of the 8 byte span and the root\n * hash of a binary Merkle tree (BMT) built on the 32-byte segments\n * of the underlying data.\n * @param _proofSegments Proof segments.\n * @param _proveSegment Segment to prove.\n * @param _proveSegmentIndex Prove segment index\n * @param _chunkSpan chunk bytes length\n * @return _chunkHash chunk hash\n */\n function chunkAddressFromInclusionProof(\n bytes32[] memory _proofSegments,\n bytes32 _proveSegment,\n uint256 _proveSegmentIndex,\n uint64 _chunkSpan\n ) internal pure returns (bytes32) {\n bytes32 rootHash = rootHashFromInclusionProof(_proofSegments, _proveSegment, _proveSegmentIndex);\n return keccak256(abi.encodePacked(reverseUint64(_chunkSpan), rootHash));\n }\n\n function mergeSegment(\n bytes32 _calculatedHash,\n bytes32 _proofSegment,\n bool mergeFromRight\n ) internal pure returns (bytes32 res) {\n if (mergeFromRight) {\n res = keccak256(abi.encode(_calculatedHash, _proofSegment));\n } else {\n res = keccak256(abi.encode(_proofSegment, _calculatedHash));\n }\n return res;\n }\n}\n" + }, + "src/Util/Signatures.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\nlibrary Signatures {\n error InvalidSignatureLength();\n\n /** Hash of the message to sign */\n function getPostageMessageHash(\n bytes32 _chunkAddr,\n bytes32 _batchId,\n uint64 _index,\n uint64 _timeStamp\n ) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(_chunkAddr, _batchId, _index, _timeStamp));\n }\n\n function postageVerify(\n address _signer, // signer Ethereum address to check against\n bytes memory _signature,\n bytes32 _chunkAddr,\n bytes32 _postageId,\n uint64 _index,\n uint64 _timeStamp\n ) internal pure returns (bool) {\n bytes32 messageHash = getPostageMessageHash(_chunkAddr, _postageId, _index, _timeStamp);\n bytes32 ethMessageHash = getEthSignedMessageHash(messageHash);\n\n return recoverSigner(ethMessageHash, _signature) == _signer;\n }\n\n function getEthSignedMessageHash(bytes32 _messageHash) internal pure returns (bytes32) {\n /*\n Signature is produced by signing a keccak256 hash with the following format:\n \"\\x19Ethereum Signed Message\\n\" + len(msg) + msg\n */\n return keccak256(abi.encodePacked(\"\\x19Ethereum Signed Message:\\n32\", _messageHash));\n }\n\n function recoverSigner(\n bytes32 _ethSignedMessageHash, // it has to be prefixed message: https://ethereum.stackexchange.com/questions/19582/does-ecrecover-in-solidity-expects-the-x19ethereum-signed-message-n-prefix/21037\n bytes memory _signature\n ) internal pure returns (address) {\n (bytes32 r, bytes32 s, uint8 v) = splitSignature(_signature);\n\n return ecrecover(_ethSignedMessageHash, v, r, s);\n }\n\n function splitSignature(bytes memory sig) internal pure returns (bytes32 r_, bytes32 s_, uint8 v_) {\n if (sig.length != 65) {\n revert InvalidSignatureLength();\n }\n\n assembly {\n /*\n verbose explanation: https://ethereum.stackexchange.com/questions/135591/split-signature-function-in-solidity-by-example-docs\n First 32 bytes stores the length of the signature\n add(sig, 32) = pointer of sig + 32\n effectively, skips first 32 bytes of signature\n mload(p) loads next 32 bytes starting at the memory address p into memory\n */\n\n // first 32 bytes, after the length prefix\n r_ := mload(add(sig, 32))\n // second 32 bytes\n s_ := mload(add(sig, 64))\n // final byte (first byte of the next 32 bytes)\n v_ := byte(0, mload(add(sig, 96)))\n }\n\n // implicitly return (r, s, v)\n }\n\n function getSocMessageHash(bytes32 _identifier, bytes32 _chunkAddr) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(_identifier, _chunkAddr));\n }\n\n function socVerify(\n address _signer, // signer Ethereum address to check against\n bytes memory _signature,\n bytes32 _identifier,\n bytes32 _chunkAddr\n ) internal pure returns (bool) {\n bytes32 messageHash = getSocMessageHash(_identifier, _chunkAddr);\n bytes32 ethMessageHash = getEthSignedMessageHash(messageHash);\n\n return recoverSigner(ethMessageHash, _signature) == _signer;\n }\n}\n" + }, + "src/Util/TransformedChunkProof.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\nlibrary TransformedBMTChunk {\n // max chunk payload size\n uint256 public constant MAX_CHUNK_PAYLOAD_SIZE = 4096;\n // segment byte size\n uint256 public constant SEGMENT_SIZE = 32;\n\n /** Calculates the root hash from the provided inclusion proof segments and its corresponding segment index\n * @param _proofSegments Proof segments.\n * @param _proveSegment Segment to prove.\n * @param _proveSegmentIndex Prove segment index\n * @return _calculatedHash chunk hash\n */\n function transformedRootHashFromInclusionProof(\n bytes32[] memory _proofSegments,\n bytes32 _proveSegment,\n uint256 _proveSegmentIndex,\n bytes32 key\n ) internal pure returns (bytes32 _calculatedHash) {\n _calculatedHash = _proveSegment;\n for (uint256 i = 0; i < _proofSegments.length; i++) {\n bool mergeFromRight = _proveSegmentIndex % 2 == 0 ? true : false;\n _calculatedHash = transformedMergeSegment(_calculatedHash, _proofSegments[i], mergeFromRight, key);\n _proveSegmentIndex >>= 1;\n }\n\n return _calculatedHash;\n }\n\n /**\n * @notice Changes the endianness of a uint64.\n * @dev https://graphics.stanford.edu/~seander/bithacks.html#ReverseParallel\n * @param _b The unsigned integer to reverse\n * @return v - The reversed value\n */\n function reverseUint64(uint64 _b) public pure returns (uint64) {\n uint256 v = _b;\n\n // swap bytes\n v =\n ((v >> 8) & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) |\n ((v & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) << 8);\n // swap 2-byte long pairs\n v =\n ((v >> 16) & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) |\n ((v & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) << 16);\n // swap 4-byte long pairs\n v =\n ((v >> 32) & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) |\n ((v & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) << 32);\n\n return uint64(v);\n }\n\n /**\n * Calculate the chunk address from the Binary Merkle Tree of the chunk data\n *\n * The BMT chunk address is the hash of the 8 byte span and the root\n * hash of a binary Merkle tree (BMT) built on the 32-byte segments\n * of the underlying data.\n * @param _proofSegments Proof segments.\n * @param _proveSegment Segment to prove.\n * @param _proveSegmentIndex Prove segment index\n * @param _chunkSpan chunk bytes length\n * @return _chunkHash chunk hash\n */\n function transformedChunkAddressFromInclusionProof(\n bytes32[] memory _proofSegments,\n bytes32 _proveSegment,\n uint256 _proveSegmentIndex,\n uint64 _chunkSpan,\n bytes32 key\n ) internal pure returns (bytes32) {\n bytes32 rootHash = transformedRootHashFromInclusionProof(\n _proofSegments,\n _proveSegment,\n _proveSegmentIndex,\n key\n );\n return keccak256(abi.encodePacked(key, reverseUint64(_chunkSpan), rootHash));\n }\n\n function transformedMergeSegment(\n bytes32 _calculatedHash,\n bytes32 _proofSegment,\n bool mergeFromRight,\n bytes32 key\n ) internal pure returns (bytes32 res) {\n if (mergeFromRight) {\n res = keccak256(abi.encode(key, _calculatedHash, _proofSegment));\n } else {\n res = keccak256(abi.encode(key, _proofSegment, _calculatedHash));\n }\n return res;\n }\n}\n" + } + }, + "settings": { + "optimizer": { + "enabled": true, + "runs": 1000 + }, + "outputSelection": { + "*": { + "*": [ + "abi", + "evm.bytecode", + "evm.deployedBytecode", + "evm.methodIdentifiers", + "metadata", + "devdoc", + "userdoc", + "storageLayout", + "evm.gasEstimates" + ], + "": [ + "ast" + ] + } + }, + "metadata": { + "useLiteralContent": true + }, + "libraries": { + "": { + "__CACHE_BREAKER__": "0x00000000d41867734bbee4c6863d9255b2b06ac1" + } + } + } +} \ No newline at end of file diff --git a/hardhat.config.ts b/hardhat.config.ts index 1c0a50dc..51873158 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -200,7 +200,7 @@ const config: HardhatUserConfig = { chainId: 11155111, urls: { apiURL: 'https://api-sepolia.etherscan.io/api', - browserURL: 'https://sepolia.etherscan.io/address/', + browserURL: 'https://sepolia.etherscan.io/', }, }, { @@ -208,7 +208,7 @@ const config: HardhatUserConfig = { chainId: 11155111, urls: { apiURL: 'https://api-sepolia.etherscan.io/api', - browserURL: 'https://sepolia.etherscan.io/address/', + browserURL: 'https://sepolia.etherscan.io/', }, }, { diff --git a/src/PriceOracle.sol b/src/PriceOracle.sol index c2c25a66..5675f4f9 100644 --- a/src/PriceOracle.sol +++ b/src/PriceOracle.sol @@ -47,6 +47,7 @@ contract PriceOracle is AccessControl { *@dev Emitted on every price update. */ event PriceUpdate(uint256 price); + event StampPriceUpdateFailed(uint256 attemptedPrice); // ----------------------------- Custom Errors ------------------------------ error CallerNotAdmin(); // Caller is not the admin @@ -72,7 +73,7 @@ contract PriceOracle is AccessControl { * @notice Manually set the price. * @dev Can only be called by the admin role. * @param _price The new price. - */ function setPrice(uint32 _price) external { + */ function setPrice(uint32 _price) external returns (bool) { if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) { revert CallerNotAdmin(); } @@ -86,12 +87,19 @@ contract PriceOracle is AccessControl { } currentPriceUpScaled = _currentPriceUpScaled; - // Price in postagestamp is set at 256 so we need to upcast it - postageStamp.setPrice(uint256(currentPrice())); + // Check if the setting of price in postagestamp succeded + (bool success, ) = address(postageStamp).call( + abi.encodeWithSignature("setPrice(uint256)", uint256(currentPrice())) + ); + if (!success) { + emit StampPriceUpdateFailed(currentPrice()); + return false; + } emit PriceUpdate(currentPrice()); + return true; } - function adjustPrice(uint16 redundancy) external { + function adjustPrice(uint16 redundancy) external returns (bool) { if (isPaused == false) { if (!hasRole(PRICE_UPDATER_ROLE, msg.sender)) { revert CallerNotPriceUpdater(); @@ -119,7 +127,7 @@ contract PriceOracle is AccessControl { uint64 _minimumPriceUpscaled = minimumPriceUpscaled; uint32 _priceBase = priceBase; - // Set the number of rounds that were skipped + // Set the number of rounds that were skipped, we substract 1 as lastAdjustedRound is set below and default result is 1 uint64 skippedRounds = currentRoundNumber - lastAdjustedRound - 1; // We first apply the increase/decrease rate for the current round @@ -141,9 +149,19 @@ contract PriceOracle is AccessControl { currentPriceUpScaled = _currentPriceUpScaled; lastAdjustedRound = currentRoundNumber; - postageStamp.setPrice(uint256(currentPrice())); + + // Check if the price set in postagestamp succeded + (bool success, ) = address(postageStamp).call( + abi.encodeWithSignature("setPrice(uint256)", uint256(currentPrice())) + ); + if (!success) { + emit StampPriceUpdateFailed(currentPrice()); + return false; + } emit PriceUpdate(currentPrice()); + return true; } + return false; } function pause() external { diff --git a/src/Redistribution.sol b/src/Redistribution.sol index 3efdef56..936efe78 100644 --- a/src/Redistribution.sol +++ b/src/Redistribution.sol @@ -8,7 +8,7 @@ import "./Util/Signatures.sol"; import "./interface/IPostageStamp.sol"; interface IPriceOracle { - function adjustPrice(uint16 redundancy) external; + function adjustPrice(uint16 redundancy) external returns (bool); } interface IStakeRegistry { @@ -24,6 +24,8 @@ interface IStakeRegistry { function overlayOfAddress(address _owner) external view returns (bytes32); + function heightOfAddress(address _owner) external view returns (uint8); + function nodeEffectiveStake(address _owner) external view returns (uint256); } @@ -64,6 +66,7 @@ contract Redistribution is AccessControl, Pausable { bytes32 overlay; address owner; bool revealed; + uint8 height; uint256 stake; bytes32 obfuscatedHash; uint256 revealIndex; @@ -181,7 +184,7 @@ contract Redistribution is AccessControl, Pausable { /** * @dev Logs that an overlay has committed */ - event Committed(uint256 roundNumber, bytes32 overlay); + event Committed(uint256 roundNumber, bytes32 overlay, uint8 height); /** * @dev Emit from Postagestamp contract valid chunk count at the end of claim */ @@ -192,6 +195,16 @@ contract Redistribution is AccessControl, Pausable { */ event CurrentRevealAnchor(uint256 roundNumber, bytes32 anchor); + /** + * @dev Output external call status + */ + event PriceAdjustmentSkipped(uint16 redundancyCount); + + /** + * @dev Withdraw not successful in claim + */ + event WithdrawFailed(address owner); + /** * @dev Logs that an overlay has revealed */ @@ -281,6 +294,7 @@ contract Redistribution is AccessControl, Pausable { bytes32 _overlay = Stakes.overlayOfAddress(msg.sender); uint256 _stake = Stakes.nodeEffectiveStake(msg.sender); uint256 _lastUpdate = Stakes.lastUpdatedBlockNumberOfAddress(msg.sender); + uint8 _height = Stakes.heightOfAddress(msg.sender); if (!currentPhaseCommit()) { revert NotCommitPhase(); @@ -329,13 +343,14 @@ contract Redistribution is AccessControl, Pausable { overlay: _overlay, owner: msg.sender, revealed: false, + height: _height, stake: _stake, obfuscatedHash: _obfuscatedHash, revealIndex: 0 }) ); - emit Committed(_roundNumber, _overlay); + emit Committed(_roundNumber, _overlay, _height); } /** @@ -372,9 +387,10 @@ contract Redistribution is AccessControl, Pausable { bytes32 obfuscatedHash = wrapCommit(_overlay, _depth, _hash, _revealNonce); uint256 id = findCommit(_overlay, obfuscatedHash); Commit memory revealedCommit = currentCommits[id]; + uint8 depthResponsibility = _depth - revealedCommit.height; // Check that commit is in proximity of the current anchor - if (!inProximity(revealedCommit.overlay, currentRevealRoundAnchor, _depth)) { + if (!inProximity(revealedCommit.overlay, currentRevealRoundAnchor, depthResponsibility)) { revert OutOfDepthReveal(currentRevealRoundAnchor); } // Check that the commit has not already been revealed @@ -391,7 +407,7 @@ contract Redistribution is AccessControl, Pausable { owner: revealedCommit.owner, depth: _depth, stake: revealedCommit.stake, - stakeDensity: revealedCommit.stake * uint256(2 ** _depth), + stakeDensity: revealedCommit.stake * uint256(2 ** depthResponsibility), hash: _hash }) ); @@ -400,7 +416,7 @@ contract Redistribution is AccessControl, Pausable { cr, revealedCommit.overlay, revealedCommit.stake, - revealedCommit.stake * uint256(2 ** _depth), + revealedCommit.stake * uint256(2 ** depthResponsibility), _hash, _depth ); @@ -465,7 +481,14 @@ contract Redistribution is AccessControl, Pausable { estimateSize(entryProofLast.proofSegments[0]); - PostageContract.withdraw(winnerSelected.owner); + // Do the check if the withdraw was success + (bool success, ) = address(PostageContract).call( + abi.encodeWithSignature("withdraw(address)", winnerSelected.owner) + ); + if (!success) { + emit WithdrawFailed(winnerSelected.owner); + } + emit WinnerSelected(winnerSelected); emit ChunkCount(PostageContract.validChunkCount()); } @@ -549,7 +572,10 @@ contract Redistribution is AccessControl, Pausable { } } - OracleContract.adjustPrice(uint16(redundancyCount)); + bool success = OracleContract.adjustPrice(uint16(redundancyCount)); + if (!success) { + emit PriceAdjustmentSkipped(uint16(redundancyCount)); + } currentClaimRound = cr; } @@ -802,6 +828,7 @@ contract Redistribution is AccessControl, Pausable { */ function isParticipatingInUpcomingRound(address _owner, uint8 _depth) public view returns (bool) { uint256 _lastUpdate = Stakes.lastUpdatedBlockNumberOfAddress(_owner); + uint8 _depthResponsibility = _depth - Stakes.heightOfAddress(_owner); if (currentPhaseReveal()) { revert WrongPhase(); @@ -815,7 +842,7 @@ contract Redistribution is AccessControl, Pausable { revert MustStake2Rounds(); } - return inProximity(Stakes.overlayOfAddress(_owner), currentRoundAnchor(), _depth); + return inProximity(Stakes.overlayOfAddress(_owner), currentRoundAnchor(), _depthResponsibility); } // ----------------------------- Reveal ------------------------------ diff --git a/src/Staking.sol b/src/Staking.sol index 3a12ea55..cb902b8f 100644 --- a/src/Staking.sol +++ b/src/Staking.sol @@ -28,6 +28,8 @@ contract StakeRegistry is AccessControl, Pausable { uint256 potentialStake; // Block height the stake was updated, also used as flag to check if the stake is set uint256 lastUpdatedBlockNumber; + // Node indicating its increased reserve + uint8 height; } // Associate every stake id with node address data. @@ -51,14 +53,15 @@ contract StakeRegistry is AccessControl, Pausable { // ----------------------------- Events ------------------------------ /** - * @dev Emitted when a stake is created or updated by `owner` of the `overlay` by `committedStake`, and `potentialStake` during `lastUpdatedBlock`. + * @dev Emitted when a stake is created or updated by `owner` of the `overlay`. */ event StakeUpdated( address indexed owner, uint256 committedStake, uint256 potentialStake, bytes32 overlay, - uint256 lastUpdatedBlock + uint256 lastUpdatedBlock, + uint8 height ); /** @@ -112,33 +115,48 @@ contract StakeRegistry is AccessControl, Pausable { * @dev At least `_initialBalancePerChunk*2^depth` number of tokens need to be preapproved for this contract. * @param _setNonce Nonce that was used for overlay calculation. * @param _addAmount Deposited amount of ERC20 tokens, equals to added Potential stake value + * @param _height increased reserve by registering the number of doublings */ - function manageStake(bytes32 _setNonce, uint256 _addAmount) external whenNotPaused { + function manageStake(bytes32 _setNonce, uint256 _addAmount, uint8 _height) external whenNotPaused { bytes32 _previousOverlay = stakes[msg.sender].overlay; uint256 _stakingSet = stakes[msg.sender].lastUpdatedBlockNumber; bytes32 _newOverlay = keccak256(abi.encodePacked(msg.sender, reverse(NetworkId), _setNonce)); - uint256 _addCommittedStake = _addAmount / OracleContract.currentPrice(); // losing some decimals from start 10n16 becomes 99999999999984000 - // First time adding stake, check the minimum is added - if (_addAmount < MIN_STAKE && _stakingSet == 0) { + // First time adding stake, check the minimum is added, take into account height + if (_addAmount < MIN_STAKE * 2 ** _height && _stakingSet == 0) { revert BelowMinimumStake(); } if (_stakingSet != 0 && !addressNotFrozen(msg.sender)) revert Frozen(); - uint256 updatedCommittedStake = stakes[msg.sender].committedStake + _addCommittedStake; - uint256 updatedPotentialStake = stakes[msg.sender].potentialStake + _addAmount; + + uint256 updatedPotentialStake = stakes[msg.sender].potentialStake; + uint256 updatedCommittedStake = stakes[msg.sender].committedStake; + + // Only update stake values if _addAmount is greater than 0 + if (_addAmount > 0) { + updatedPotentialStake = stakes[msg.sender].potentialStake + _addAmount; + updatedCommittedStake = updatedPotentialStake / (OracleContract.currentPrice() * 2 ** _height); + } stakes[msg.sender] = Stake({ overlay: _newOverlay, committedStake: updatedCommittedStake, potentialStake: updatedPotentialStake, - lastUpdatedBlockNumber: block.number + lastUpdatedBlockNumber: block.number, + height: _height }); // Transfer tokens and emit event that stake has been updated if (_addAmount > 0) { if (!ERC20(bzzToken).transferFrom(msg.sender, address(this), _addAmount)) revert TransferFailed(); - emit StakeUpdated(msg.sender, updatedCommittedStake, updatedPotentialStake, _newOverlay, block.number); + emit StakeUpdated( + msg.sender, + updatedCommittedStake, + updatedPotentialStake, + _newOverlay, + block.number, + _height + ); } // Emit overlay change event @@ -153,7 +171,7 @@ contract StakeRegistry is AccessControl, Pausable { function withdrawFromStake() external { uint256 _potentialStake = stakes[msg.sender].potentialStake; uint256 _surplusStake = _potentialStake - - calculateEffectiveStake(stakes[msg.sender].committedStake, _potentialStake); + calculateEffectiveStake(stakes[msg.sender].committedStake, _potentialStake, stakes[msg.sender].height); if (_surplusStake > 0) { stakes[msg.sender].potentialStake -= _surplusStake; @@ -250,7 +268,11 @@ contract StakeRegistry is AccessControl, Pausable { function nodeEffectiveStake(address _owner) public view returns (uint256) { return addressNotFrozen(_owner) - ? calculateEffectiveStake(stakes[_owner].committedStake, stakes[_owner].potentialStake) + ? calculateEffectiveStake( + stakes[_owner].committedStake, + stakes[_owner].potentialStake, + stakes[_owner].height + ) : 0; } @@ -259,7 +281,9 @@ contract StakeRegistry is AccessControl, Pausable { */ function withdrawableStake() public view returns (uint256) { uint256 _potentialStake = stakes[msg.sender].potentialStake; - return _potentialStake - calculateEffectiveStake(stakes[msg.sender].committedStake, _potentialStake); + return + _potentialStake - + calculateEffectiveStake(stakes[msg.sender].committedStake, _potentialStake, stakes[msg.sender].height); } /** @@ -277,12 +301,21 @@ contract StakeRegistry is AccessControl, Pausable { return stakes[_owner].overlay; } + /** + * @dev Returns the currently height of the address. + * @param _owner address of node + */ + function heightOfAddress(address _owner) public view returns (uint8) { + return stakes[_owner].height; + } + function calculateEffectiveStake( uint256 committedStake, - uint256 potentialStakeBalance + uint256 potentialStakeBalance, + uint8 height ) internal view returns (uint256) { // Calculate the product of committedStake and unitPrice to get price in BZZ - uint256 committedStakeBzz = committedStake * OracleContract.currentPrice(); + uint256 committedStakeBzz = (2 ** height) * committedStake * OracleContract.currentPrice(); // Return the minimum value between committedStakeBzz and potentialStakeBalance if (committedStakeBzz < potentialStakeBalance) { diff --git a/src/interface/IPostageStamp.sol b/src/interface/IPostageStamp.sol index 7aa21a6c..2bf25886 100644 --- a/src/interface/IPostageStamp.sol +++ b/src/interface/IPostageStamp.sol @@ -4,6 +4,8 @@ pragma solidity ^0.8.19; interface IPostageStamp { function withdraw(address beneficiary) external; + function setPrice(uint256 _price) external; + function validChunkCount() external view returns (uint256); function batchOwner(bytes32 _batchId) external view returns (address); @@ -16,8 +18,6 @@ interface IPostageStamp { function minimumInitialBalancePerChunk() external view returns (uint256); - function setPrice(uint256 _price) external; - function batches( bytes32 ) diff --git a/test/Redistribution.test.ts b/test/Redistribution.test.ts index 90ab97ed..1add723e 100644 --- a/test/Redistribution.test.ts +++ b/test/Redistribution.test.ts @@ -58,9 +58,11 @@ const hash_0 = '0xb5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b const depth_0 = '0x06'; const reveal_nonce_0 = '0xb5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33'; const stakeAmount_0 = '100000000000000000'; +const stakeAmount_0_n_2 = '400000000000000000'; const effectiveStakeAmount_0 = '99999999999984000'; - const obfuscatedHash_0 = '0xb5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33'; +const height_0 = 0; +const height_0_n_2 = 2; //fake const overlay_f = '0xf4153f4153f4153f4153f4153f4153f4153f4153f4153f4153f4153f4153f415'; @@ -76,15 +78,19 @@ const nonce_1_n_25 = '0x00000000000000000000000000000000000000000000000000000000 const stakeAmount_1_n_25 = '200000000000000000'; const depth_1 = '0x06'; const reveal_nonce_1 = '0xb5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33'; +const height_1 = 0; let node_2: string; const overlay_2 = '0xa40db58e368ea6856a24c0264ebd73b049f3dc1c2347b1babc901d3e09842dec'; const stakeAmount_2 = '100000000000000000'; const effectiveStakeAmount_2 = '99999999999984000'; +const effectiveStakeAmount_2_n_2 = '100000000000000000'; const nonce_2 = '0xb5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33'; const hash_2 = '0xb5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33'; const depth_2 = '0x06'; const reveal_nonce_2 = '0xb5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33'; +const height_2 = 0; +const height_2_n_2 = 2; let node_3: string; const overlay_3 = '0xaf217eb0d652baf39ec9464a350c7afc812743fd75ccadf4fcceb6d19a1f190c'; @@ -93,11 +99,14 @@ const nonce_3 = '0xb5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555 const hash_3 = '0xb5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33'; const depth_3 = '0x06'; const reveal_nonce_3 = '0xb5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33'; +const height_3_n_2 = 3; +const effectiveStakeAmount_3 = '100000000000000000'; let node_4: string; const overlay_4 = '0xaedb2a8007316805b4d64b249ea39c5a1c4a9ce51dc8432724241f41ecb02efb'; const nonce_4 = '0xb5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33'; const depth_4 = '0x06'; +const height_4 = 0; // FDP Play node keys - claim data // queen node let node_5: string; @@ -107,6 +116,7 @@ const effectiveStakeAmount_5 = '99999999999984000'; const nonce_5 = '0x0000000000000000000000000000000000000000000000000000000000003ba6'; const reveal_nonce_5 = '0xb5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33'; const { depth: depth_5, hash: hash_5 } = node5_proof1; +const height_5 = 0; let node_6: string; const overlay_6 = '0x141680b0d9c7ab250672fd4603ac13e39e47de6e2c93d71bbdc66459a6c5e39f'; @@ -163,13 +173,14 @@ const errors = { commit: { notOwner: 'NotMatchingOwner()', notStaked: 'NotStaked()', - stakedRecently: 'MustStake2Rounds()', + mustStake2Rounds: 'MustStake2Rounds()', alreadyCommitted: 'AlreadyCommitted()', }, reveal: { noCommits: 'NoCommitsReceived()', doNotMatch: 'NoMatchingCommit()', outOfDepth: 'OutOfDepth()', + outOfDepthReveal: 'OutOfDepthReveal()', notInReveal: 'NotRevealPhase()', }, claim: { @@ -189,6 +200,12 @@ const errors = { socVerificationFailed: 'SocVerificationFailed()', socCalcNotMatching: 'SocCalcNotMatching()', }, + deposit: { + noBalance: 'ERC20: insufficient allowance', + noZeroAddress: 'owner cannot be the zero address', + onlyOwner: 'Unauthorized()', + belowMinimum: 'BelowMinimumStake()', + }, general: { onlyPauser: 'OnlyPauser()', }, @@ -236,26 +253,48 @@ describe('Redistribution', function () { it('should not create a commit with recently staked node', async function () { const sr_node_0 = await ethers.getContract('StakeRegistry', node_0); await mintAndApprove(deployer, node_0, sr_node_0.address, stakeAmount_0); - await sr_node_0.manageStake(nonce_0, stakeAmount_0); + await sr_node_0.manageStake(nonce_0, stakeAmount_0, height_0); expect(await redistribution.currentPhaseCommit()).to.be.true; const r_node_0 = await ethers.getContract('Redistribution', node_0); await expect(r_node_0['isParticipatingInUpcomingRound(address,uint8)'](node_0, depth_0)).to.be.revertedWith( - errors.commit.stakedRecently + errors.commit.mustStake2Rounds ); }); it('should create a commit with staked node', async function () { const sr_node_0 = await ethers.getContract('StakeRegistry', node_0); await mintAndApprove(deployer, node_0, sr_node_0.address, stakeAmount_0); - await sr_node_0.manageStake(nonce_0, stakeAmount_0); + await sr_node_0.manageStake(nonce_0, stakeAmount_0, height_0); + + expect(await redistribution.currentPhaseCommit()).to.be.true; + + const r_node_0 = await ethers.getContract('Redistribution', node_0); + await expect(r_node_0['isParticipatingInUpcomingRound(address,uint8)'](node_0, depth_0)).to.be.revertedWith( + errors.commit.mustStake2Rounds + ); + }); + + it('should create a commit with staked node and height 2 and not have enough funds', async function () { + const sr_node_0 = await ethers.getContract('StakeRegistry', node_0); + await mintAndApprove(deployer, node_0, sr_node_0.address, stakeAmount_0); + + await expect(sr_node_0.manageStake(nonce_0, stakeAmount_0, height_0_n_2)).to.be.revertedWith( + errors.deposit.belowMinimum + ); + }); + + it('should create a commit with staked node and height 2', async function () { + const sr_node_0 = await ethers.getContract('StakeRegistry', node_0); + await mintAndApprove(deployer, node_0, sr_node_0.address, stakeAmount_0_n_2); + await sr_node_0.manageStake(nonce_0, stakeAmount_0_n_2, height_0_n_2); expect(await redistribution.currentPhaseCommit()).to.be.true; const r_node_0 = await ethers.getContract('Redistribution', node_0); await expect(r_node_0['isParticipatingInUpcomingRound(address,uint8)'](node_0, depth_0)).to.be.revertedWith( - errors.commit.stakedRecently + errors.commit.mustStake2Rounds ); }); }); @@ -308,32 +347,32 @@ describe('Redistribution', function () { const sr_node_0 = await ethers.getContract('StakeRegistry', node_0); await mintAndApprove(deployer, node_0, sr_node_0.address, stakeAmount_0); - await sr_node_0.manageStake(nonce_0, stakeAmount_0); + await sr_node_0.manageStake(nonce_0, stakeAmount_0, height_0); const sr_node_1 = await ethers.getContract('StakeRegistry', node_1); await mintAndApprove(deployer, node_1, sr_node_1.address, stakeAmount_1); - await sr_node_1.manageStake(nonce_1, stakeAmount_1); + await sr_node_1.manageStake(nonce_1, stakeAmount_1, height_1); // 16 depth neighbourhood with node_5 const sr_node_1_n_25 = await ethers.getContract('StakeRegistry', node_1); await mintAndApprove(deployer, node_1, sr_node_1_n_25.address, stakeAmount_1); - await sr_node_1_n_25.manageStake(nonce_1_n_25, stakeAmount_1); + await sr_node_1_n_25.manageStake(nonce_1_n_25, stakeAmount_1, height_1); const sr_node_2 = await ethers.getContract('StakeRegistry', node_2); await mintAndApprove(deployer, node_2, sr_node_2.address, stakeAmount_2); - await sr_node_2.manageStake(nonce_2, stakeAmount_2); + await sr_node_2.manageStake(nonce_2, stakeAmount_2, height_2); const sr_node_3 = await ethers.getContract('StakeRegistry', node_3); await mintAndApprove(deployer, node_3, sr_node_3.address, stakeAmount_3); - await sr_node_3.manageStake(nonce_3, stakeAmount_3); + await sr_node_3.manageStake(nonce_3, stakeAmount_3, height_4); const sr_node_4 = await ethers.getContract('StakeRegistry', node_4); await mintAndApprove(deployer, node_4, sr_node_4.address, stakeAmount_3); - await sr_node_4.manageStake(nonce_4, stakeAmount_3); + await sr_node_4.manageStake(nonce_4, stakeAmount_3, height_4); const sr_node_5 = await ethers.getContract('StakeRegistry', node_5); await mintAndApprove(deployer, node_5, sr_node_5.address, stakeAmount_5); - await sr_node_5.manageStake(nonce_5, stakeAmount_5); + await sr_node_5.manageStake(nonce_5, stakeAmount_5, height_5); // We need to mine 2 rounds to make the staking possible // as this is the minimum time between staking and committing @@ -456,30 +495,97 @@ describe('Redistribution', function () { it('should create a commit with failed reveal if the overlay is out of reported depth', async function () { expect(await redistribution.currentPhaseCommit()).to.be.true; - const r_node_3 = await ethers.getContract('Redistribution', node_3); - expect(await redistribution.currentRoundAnchor()).to.be.eq(round2Anchor); const obfuscatedHash = encodeAndHash(overlay_3, '0x08', hash_3, reveal_nonce_3); - expect(await r_node_3.wrapCommit(overlay_3, '0x08', hash_3, reveal_nonce_3)).to.be.eq(obfuscatedHash); + const currentRound = await r_node_3.currentRound(); + await r_node_3.commit(obfuscatedHash, currentRound); + expect((await r_node_3.currentCommits(0)).obfuscatedHash).to.be.eq(obfuscatedHash); + await mineNBlocks(phaseLength); + await expect(r_node_3.reveal('0x08', hash_3, reveal_nonce_3)).to.be.revertedWith( + errors.reveal.outOfDepthReveal + ); + }); + + it('should create a commit with failed reveal if the overlay is out of reported depth but good reveal if height is changed', async function () { + expect(await redistribution.currentPhaseCommit()).to.be.true; + const r_node_3 = await ethers.getContract('Redistribution', node_3); + expect(await redistribution.currentRoundAnchor()).to.be.eq(round2Anchor); + + const obfuscatedHash = encodeAndHash(overlay_3, '0x08', hash_3, reveal_nonce_3); + expect(await r_node_3.wrapCommit(overlay_3, '0x08', hash_3, reveal_nonce_3)).to.be.eq(obfuscatedHash); const currentRound = await r_node_3.currentRound(); await r_node_3.commit(obfuscatedHash, currentRound); expect((await r_node_3.currentCommits(0)).obfuscatedHash).to.be.eq(obfuscatedHash); + await mineNBlocks(phaseLength); + await expect(r_node_3.reveal('0x08', hash_3, reveal_nonce_3)).to.be.revertedWith( + errors.reveal.outOfDepthReveal + ); + + // Change height and check if node is playing + const sr_node_3 = await ethers.getContract('StakeRegistry', node_3); + await sr_node_3.manageStake(nonce_3, 0, height_3_n_2); + await mineNBlocks(3 * phaseLength); + await mineToNode(redistribution, 3); + + expect(await redistribution.currentPhaseCommit()).to.be.true; + const obfuscatedHash2 = encodeAndHash(overlay_3, depth_3, hash_3, reveal_nonce_3); + const currentRound2 = await r_node_3.currentRound(); + + await expect(r_node_3.commit(obfuscatedHash2, currentRound2)) + .to.emit(redistribution, 'Committed') + .withArgs(currentRound2, overlay_3, height_3_n_2); + + expect((await r_node_3.currentCommits(0)).obfuscatedHash).to.be.eq(obfuscatedHash2); await mineNBlocks(phaseLength); + await r_node_3.reveal(depth_3, hash_3, reveal_nonce_3); - await expect(r_node_3.reveal('0x08', hash_3, reveal_nonce_3)).to.be.revertedWith(errors.reveal.outOfDepth); + expect((await r_node_3.currentReveals(0)).hash).to.be.eq(hash_3); + expect((await r_node_3.currentReveals(0)).overlay).to.be.eq(overlay_3); + expect((await r_node_3.currentReveals(0)).owner).to.be.eq(node_3); + expect((await r_node_3.currentReveals(0)).stake).to.be.eq(effectiveStakeAmount_3); + expect((await r_node_3.currentReveals(0)).depth).to.be.eq(parseInt(depth_3)); }); it('should create a commit with successful reveal if the overlay is within the reported depth', async function () { + const r_node_2 = await ethers.getContract('Redistribution', node_2); + await mineToNode(redistribution, 2); expect(await redistribution.currentPhaseCommit()).to.be.true; + const obfuscatedHash = encodeAndHash(overlay_2, depth_2, hash_2, reveal_nonce_2); + + const currentRound = await r_node_2.currentRound(); + + await expect(r_node_2.commit(obfuscatedHash, currentRound)) + .to.emit(redistribution, 'Committed') + .withArgs(currentRound, overlay_2, height_2); + + expect((await r_node_2.currentCommits(0)).obfuscatedHash).to.be.eq(obfuscatedHash); + + await mineNBlocks(phaseLength); + + await r_node_2.reveal(depth_2, hash_2, reveal_nonce_2); + + expect((await r_node_2.currentReveals(0)).hash).to.be.eq(hash_2); + expect((await r_node_2.currentReveals(0)).overlay).to.be.eq(overlay_2); + expect((await r_node_2.currentReveals(0)).owner).to.be.eq(node_2); + expect((await r_node_2.currentReveals(0)).stake).to.be.eq(effectiveStakeAmount_2); + expect((await r_node_2.currentReveals(0)).depth).to.be.eq(parseInt(depth_2)); + }); + + it('should create a commit with successful reveal if the overlay is within the reported depth with height 2', async function () { const r_node_2 = await ethers.getContract('Redistribution', node_2); + const sr_node_2 = await ethers.getContract('StakeRegistry', node_2); + await sr_node_2.manageStake(nonce_2, 0, height_2_n_2); + + await mineToNode(redistribution, 2); + expect(await redistribution.currentPhaseCommit()).to.be.true; const obfuscatedHash = encodeAndHash(overlay_2, depth_2, hash_2, reveal_nonce_2); @@ -487,7 +593,7 @@ describe('Redistribution', function () { await expect(r_node_2.commit(obfuscatedHash, currentRound)) .to.emit(redistribution, 'Committed') - .withArgs(currentRound, overlay_2); + .withArgs(currentRound, overlay_2, height_2_n_2); expect((await r_node_2.currentCommits(0)).obfuscatedHash).to.be.eq(obfuscatedHash); @@ -498,7 +604,7 @@ describe('Redistribution', function () { expect((await r_node_2.currentReveals(0)).hash).to.be.eq(hash_2); expect((await r_node_2.currentReveals(0)).overlay).to.be.eq(overlay_2); expect((await r_node_2.currentReveals(0)).owner).to.be.eq(node_2); - expect((await r_node_2.currentReveals(0)).stake).to.be.eq(effectiveStakeAmount_2); + expect((await r_node_2.currentReveals(0)).stake).to.be.eq(effectiveStakeAmount_2_n_2); expect((await r_node_2.currentReveals(0)).depth).to.be.eq(parseInt(depth_2)); }); diff --git a/test/Staking.test.ts b/test/Staking.test.ts index f9b76288..7054283a 100644 --- a/test/Staking.test.ts +++ b/test/Staking.test.ts @@ -7,6 +7,7 @@ const { read, execute } = deployments; let deployer: string; let redistributor: string; let pauser: string; +const roundLength = 152; const zeroBytes32 = '0x0000000000000000000000000000000000000000000000000000000000000000'; const freezeTime = 3; @@ -39,18 +40,23 @@ const stakeAmount_0 = '100000000000000000'; const updateStakeAmount_0 = '633633'; const updatedStakeAmount_0 = '100000000000633633'; const committedStakeAmount_0 = '4166666666666'; -const updatedCommittedStakeAmount_0 = '4166666666692'; +const updatedCommittedStakeAmount_0 = '4166666666693'; const doubled_stakeAmount_0 = '200000000000000000'; -const doubled_committedStakeAmount_0 = '8333333333332'; +const doubled_committedStakeAmount_0 = '8333333333333'; const nonce_0 = '0xb5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33'; +const height_0 = 0; +const height_0_n_1 = 1; let staker_1: string; const overlay_1 = '0xa6f955c72d7053f96b91b5470491a0c732b0175af56dcfb7a604b82b16719406'; const overlay_1_n_25 = '0x676766bbae530fd0483e4734e800569c95929b707b9c50f8717dc99f9f91e915'; const stakeAmount_1 = '100000000000000000'; -const stakeAmount_1_n = '10000000000000000'; +const stakeAmount_1_n = '100000000000000000'; +const doubled_stakeAmount_1 = '200000000000000000'; const nonce_1 = '0xb5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33'; const nonce_1_n_25 = '0x00000000000000000000000000000000000000000000000000000000000325dd'; +const height_1 = 0; +const height_1_n_1 = 1; const zeroStake = '0'; const zeroAmount = '0'; @@ -114,7 +120,9 @@ describe('Staking', function () { }); it('should not deposit stake if funds are unavailable', async function () { - await expect(stakeRegistry.manageStake(nonce_0, stakeAmount_0)).to.be.revertedWith(errors.deposit.noBalance); + await expect(stakeRegistry.manageStake(nonce_0, stakeAmount_0, height_0)).to.be.revertedWith( + errors.deposit.noBalance + ); }); it('should deposit stake correctly if funds are available', async function () { @@ -125,9 +133,9 @@ describe('Staking', function () { await mintAndApprove(staker_0, stakeRegistry.address, stakeAmount_0); expect(await token.balanceOf(staker_0)).to.be.eq(stakeAmount_0); - await expect(sr_staker_0.manageStake(nonce_0, stakeAmount_0)) + await expect(sr_staker_0.manageStake(nonce_0, stakeAmount_0, height_0)) .to.emit(stakeRegistry, 'StakeUpdated') - .withArgs(staker_0, committedStakeAmount_0, stakeAmount_0, overlay_0, updatedBlockNumber); + .withArgs(staker_0, committedStakeAmount_0, stakeAmount_0, overlay_0, updatedBlockNumber, height_0); expect(await token.balanceOf(staker_0)).to.be.eq(0); @@ -147,16 +155,23 @@ describe('Staking', function () { await mintAndApprove(staker_0, stakeRegistry.address, stakeAmount_0); expect(await token.balanceOf(staker_0)).to.be.eq(stakeAmount_0); - sr_staker_0.manageStake(nonce_0, stakeAmount_0); + sr_staker_0.manageStake(nonce_0, stakeAmount_0, height_0); const lastUpdatedBlockNumber = (await getBlockNumber()) + 3; await mintAndApprove(staker_0, stakeRegistry.address, updateStakeAmount_0); expect(await token.balanceOf(staker_0)).to.be.eq(updateStakeAmount_0); - await expect(sr_staker_0.manageStake(nonce_0, updateStakeAmount_0)) + await expect(sr_staker_0.manageStake(nonce_0, updateStakeAmount_0, zeroAmount)) .to.emit(stakeRegistry, 'StakeUpdated') - .withArgs(staker_0, updatedCommittedStakeAmount_0, updatedStakeAmount_0, overlay_0, lastUpdatedBlockNumber + 1); + .withArgs( + staker_0, + updatedCommittedStakeAmount_0, + updatedStakeAmount_0, + overlay_0, + lastUpdatedBlockNumber + 1, + height_0 + ); const staked = await stakeRegistry.stakes(staker_0); expect(staked.overlay).to.be.eq(overlay_0); @@ -175,7 +190,7 @@ describe('Staking', function () { const sr_staker_0 = await ethers.getContract('StakeRegistry', staker_0); await mintAndApprove(staker_0, stakeRegistry.address, stakeAmount_0); - await sr_staker_0.manageStake(nonce_0, stakeAmount_0); + await sr_staker_0.manageStake(nonce_0, stakeAmount_0, height_0); const stakeRegistryDeployer = await ethers.getContract('StakeRegistry', deployer); const redistributorRole = await stakeRegistryDeployer.REDISTRIBUTOR_ROLE(); @@ -206,7 +221,7 @@ describe('Staking', function () { const sr_staker_0 = await ethers.getContract('StakeRegistry', staker_0); await mintAndApprove(staker_0, stakeRegistry.address, stakeAmount_0); - await sr_staker_0.manageStake(nonce_0, stakeAmount_0); + await sr_staker_0.manageStake(nonce_0, stakeAmount_0, height_0); const lastUpdatedBlockNumber = await getBlockNumber(); const staked = await stakeRegistry.stakes(staker_0); @@ -228,7 +243,7 @@ describe('Staking', function () { sr_staker_0 = await ethers.getContract('StakeRegistry', staker_0); await mintAndApprove(staker_0, stakeRegistry.address, stakeAmount_0); - await sr_staker_0.manageStake(nonce_0, stakeAmount_0); + await sr_staker_0.manageStake(nonce_0, stakeAmount_0, height_0); const stakeRegistryDeployer = await ethers.getContract('StakeRegistry', deployer); const redistributorRole = await stakeRegistryDeployer.REDISTRIBUTOR_ROLE(); @@ -263,14 +278,23 @@ describe('Staking', function () { expect(staked.lastUpdatedBlockNumber).to.be.eq(updatedBlockNumber); await mintAndApprove(staker_0, stakeRegistry.address, stakeAmount_0); - await expect(sr_staker_0.manageStake(nonce_0, stakeAmount_0)).to.be.revertedWith(errors.freeze.currentlyFrozen); + await expect(sr_staker_0.manageStake(nonce_0, stakeAmount_0, height_0)).to.be.revertedWith( + errors.freeze.currentlyFrozen + ); mineNBlocks(3); const newUpdatedBlockNumber = (await getBlockNumber()) + 2; - await expect(sr_staker_0.manageStake(nonce_0, stakeAmount_0)) + await expect(sr_staker_0.manageStake(nonce_0, stakeAmount_0, height_0)) .to.emit(stakeRegistry, 'StakeUpdated') - .withArgs(staker_0, doubled_committedStakeAmount_0, doubled_stakeAmount_0, overlay_0, newUpdatedBlockNumber); + .withArgs( + staker_0, + doubled_committedStakeAmount_0, + doubled_stakeAmount_0, + overlay_0, + newUpdatedBlockNumber, + height_0 + ); }); }); @@ -285,7 +309,7 @@ describe('Staking', function () { sr_staker_0 = await ethers.getContract('StakeRegistry', staker_0); await mintAndApprove(staker_0, stakeRegistry.address, stakeAmount_0); - await sr_staker_0.manageStake(nonce_0, stakeAmount_0); + await sr_staker_0.manageStake(nonce_0, stakeAmount_0, height_0); const stakeRegistryDeployer = await ethers.getContract('StakeRegistry', deployer); const pauserRole = await stakeRegistryDeployer.DEFAULT_ADMIN_ROLE(); @@ -302,7 +326,9 @@ describe('Staking', function () { await stakeRegistryPauser.pause(); await mintAndApprove(staker_0, stakeRegistry.address, stakeAmount_0); - await expect(stakeRegistry.manageStake(nonce_0, stakeAmount_0)).to.be.revertedWith(errors.pause.currentlyPaused); + await expect(stakeRegistry.manageStake(nonce_0, stakeAmount_0, height_0)).to.be.revertedWith( + errors.pause.currentlyPaused + ); }); it('should not unpause contract without pauser role', async function () { @@ -318,7 +344,9 @@ describe('Staking', function () { await stakeRegistryPauser.pause(); await mintAndApprove(staker_0, stakeRegistry.address, stakeAmount_0); - await expect(stakeRegistry.manageStake(nonce_0, stakeAmount_0)).to.be.revertedWith(errors.pause.currentlyPaused); + await expect(stakeRegistry.manageStake(nonce_0, stakeAmount_0, height_0)).to.be.revertedWith( + errors.pause.currentlyPaused + ); }); it('should allow staking once unpaused', async function () { @@ -327,20 +355,30 @@ describe('Staking', function () { await mintAndApprove(staker_0, stakeRegistry.address, stakeAmount_0); - await expect(sr_staker_0.manageStake(nonce_0, stakeAmount_0)).to.be.revertedWith(errors.pause.currentlyPaused); + await expect(sr_staker_0.manageStake(nonce_0, stakeAmount_0, height_0)).to.be.revertedWith( + errors.pause.currentlyPaused + ); await stakeRegistryPauser.unPause(); const newUpdatedBlockNumber = (await getBlockNumber()) + 3; await mintAndApprove(staker_0, stakeRegistry.address, updateStakeAmount_0); - await expect(sr_staker_0.manageStake(nonce_0, updateStakeAmount_0)) + await expect(sr_staker_0.manageStake(nonce_0, updateStakeAmount_0, height_0)) .to.emit(stakeRegistry, 'StakeUpdated') - .withArgs(staker_0, updatedCommittedStakeAmount_0, updatedStakeAmount_0, overlay_0, newUpdatedBlockNumber); + .withArgs( + staker_0, + updatedCommittedStakeAmount_0, + updatedStakeAmount_0, + overlay_0, + newUpdatedBlockNumber, + height_0 + ); }); }); describe('stake surplus withdrawl and stake migrate', function () { let sr_staker_0: Contract; + let sr_staker_1: Contract; let updatedBlockNumber: number; beforeEach(async function () { @@ -348,12 +386,13 @@ describe('Staking', function () { token = await ethers.getContract('TestToken', deployer); stakeRegistry = await ethers.getContract('StakeRegistry'); sr_staker_0 = await ethers.getContract('StakeRegistry', staker_0); + sr_staker_1 = await ethers.getContract('StakeRegistry', staker_1); const priceOracle = await ethers.getContract('PriceOracle', deployer); // Bump up the price so we can test surplus withdrawls await priceOracle.setPrice(32000); await mintAndApprove(staker_0, stakeRegistry.address, stakeAmount_0); - await sr_staker_0.manageStake(nonce_0, stakeAmount_0); + await sr_staker_0.manageStake(nonce_0, stakeAmount_0, height_0); updatedBlockNumber = await getBlockNumber(); @@ -364,7 +403,7 @@ describe('Staking', function () { it('should not allow stake migration while unpaused', async function () { await mintAndApprove(staker_0, stakeRegistry.address, stakeAmount_0); - await sr_staker_0.manageStake(nonce_0, stakeAmount_0); + await sr_staker_0.manageStake(nonce_0, stakeAmount_0, height_0); await expect(sr_staker_0.migrateStake()).to.be.revertedWith(errors.pause.notCurrentlyPaused); }); @@ -394,9 +433,10 @@ describe('Staking', function () { }); it('should not allow deposit stake below minimum', async function () { - const sr_staker_1 = await ethers.getContract('StakeRegistry', staker_1); await mintAndApprove(staker_1, stakeRegistry.address, stakeAmount_1_n); - await expect(sr_staker_1.manageStake(nonce_1, stakeAmount_1_n)).to.be.revertedWith(errors.deposit.belowMinimum); + await expect(sr_staker_1.manageStake(nonce_1, stakeAmount_1_n, height_1_n_1)).to.be.revertedWith( + errors.deposit.belowMinimum + ); }); it('should make stake surplus withdrawal', async function () { @@ -420,6 +460,72 @@ describe('Staking', function () { expect(await token.balanceOf(staker_0)).to.not.eq(zeroAmount); }); + it('should make stake surplus withdrawal when height increases', async function () { + const staked_before = await sr_staker_0.stakes(staker_0); + const priceOracle = await ethers.getContract('PriceOracle', deployer); + + await priceOracle.setPrice(24000); + + // We are doubling here as we are adding another "amount" with another stakeAmount_0 + await mintAndApprove(staker_0, stakeRegistry.address, stakeAmount_0); + await sr_staker_0.manageStake(nonce_0, stakeAmount_0, height_0_n_1); + const staked_after = await sr_staker_0.stakes(staker_0); + + expect(staked_after.overlay).to.be.eq(overlay_0); + expect(staked_after.potentialStake).to.be.eq(doubled_stakeAmount_0); + expect(staked_before.lastUpdatedBlockNumber).to.be.eq(updatedBlockNumber); + + // Check that balance of wallet is 0 in the begining + expect(await token.balanceOf(staker_0)).to.be.eq(zeroAmount); + + await sr_staker_0.withdrawFromStake(); + + const effectiveStake = (await sr_staker_0.nodeEffectiveStake(staker_0)).toString(); + const tokenBalance = (await token.balanceOf(staker_0)).toString(); + const potentialStakeBalance = staked_after.potentialStake.toString(); + + expect(staked_after.potentialStake.gt(staked_before.potentialStake)).to.be.true; + expect(String(potentialStakeBalance - tokenBalance)).to.be.eq(effectiveStake); + expect(tokenBalance).to.not.eq(zeroAmount); + }); + + it('should make stake surplus withdrawal when height increases and then decreases', async function () { + const priceOracle = await ethers.getContract('PriceOracle', deployer); + + await priceOracle.setPrice(24000); + const price = await priceOracle.currentPrice(); + + // We are doubling here as we are adding another "amount" with another stakeAmount_0 + await mintAndApprove(staker_0, stakeRegistry.address, stakeAmount_0); + await sr_staker_0.manageStake(nonce_0, stakeAmount_0, height_0_n_1); + const staked_before = await sr_staker_0.stakes(staker_0); + + expect(staked_before.overlay).to.be.eq(overlay_0); + expect(staked_before.potentialStake).to.be.eq(doubled_stakeAmount_0); + expect(await token.balanceOf(staker_0)).to.be.eq(zeroAmount); + + // Mine 2 rounds so that values are valid, before that effectiveStake is zero as nodes cant play + await mineNBlocks(roundLength * 2); + const withdrawbleStakeBefore = await sr_staker_0.withdrawableStake(); + + // We are lowering height to 0 and again mining 2 rounds so values are valid + await sr_staker_0.manageStake(nonce_0, 0, height_0); + await mineNBlocks(roundLength * 2); + const staked_after = await sr_staker_0.stakes(staker_0); + // await priceOracle.setPrice(24000); + + const withdrawbleStakeAfter = await sr_staker_0.withdrawableStake(); + expect(withdrawbleStakeAfter.gt(withdrawbleStakeBefore)).to.be.true; + await sr_staker_0.withdrawFromStake(); + + const potentialStakeBalance = staked_after.potentialStake.toString(); + const tokenBalance = await token.balanceOf(staker_0); + const effectiveStake = (await sr_staker_0.nodeEffectiveStake(staker_0)).toString(); + + expect(String(potentialStakeBalance - tokenBalance)).to.be.eq(effectiveStake); + expect(tokenBalance).to.not.eq(zeroAmount); + }); + it('should make stake surplus withdrawal and not withdraw again after', async function () { const staked_before = await sr_staker_0.stakes(staker_0); const priceOracle = await ethers.getContract('PriceOracle', deployer); @@ -485,6 +591,59 @@ describe('Staking', function () { expect(staked_before.potentialStake).to.be.eq(staked_after.potentialStake); expect(await token.balanceOf(staker_0)).to.eq(zeroAmount); }); + + it('should check withdrawable stake of node if we increse and decrease height', async function () { + // Situation where we have 10 BZZ, then change height to 1 and add 10 more BZZ, then lower height to 0 and withdraw 10 + await mintAndApprove(staker_0, stakeRegistry.address, stakeAmount_0); + await sr_staker_0.manageStake(nonce_0, stakeAmount_0, height_0_n_1); + await mineNBlocks(roundLength * 2); + + // We should not be able to withdraw anything + const effectiveStake = (await sr_staker_0.nodeEffectiveStake(staker_0)).toString(); + const withdrawableStakeBefore = (await sr_staker_0.withdrawableStake()).toString(); + expect(withdrawableStakeBefore).to.be.eq('0'); + + // We should be able to withdraw inital stake of 10 BZZ + await sr_staker_0.manageStake(nonce_0, 0, height_0); + await mineNBlocks(roundLength * 2); + const withdrawableStakeAfter = (await sr_staker_0.withdrawableStake()).toString(); + expect(withdrawableStakeAfter).to.be.eq(stakeAmount_0); + }); + + it('should check withdrawable stake of node if we decrease height, height starting from 1 ', async function () { + // Situation where we have 20 BZZ and 1 height, then change back to 0, and withdrawl should be 10 BZZ + await mintAndApprove(staker_1, stakeRegistry.address, doubled_stakeAmount_1); + await sr_staker_1.manageStake(nonce_1, doubled_stakeAmount_1, height_1_n_1); + await mineNBlocks(roundLength * 2); + const withdrawableStakeBefore1 = (await sr_staker_1.withdrawableStake()).toString(); + expect(withdrawableStakeBefore1).to.be.eq('0'); + + // Decrease height and check withdrawable stake, should be 10 BZZ + await sr_staker_1.manageStake(nonce_1, 0, height_1); + await mineNBlocks(roundLength * 2); + const withdrawableStakeAfter2 = (await sr_staker_1.withdrawableStake()).toString(); + expect(withdrawableStakeAfter2).to.be.eq(stakeAmount_1); + }); + + it('should check withdrawable stake of node if we increrase then, decrease height, height starting from 0', async function () { + // Situation where we have 20 BZZ and 1 height, then change back to 0, and withdrawl should be 10 BZZ + await mintAndApprove(staker_1, stakeRegistry.address, doubled_stakeAmount_1); + await sr_staker_1.manageStake(nonce_1, doubled_stakeAmount_1, height_1); + await mineNBlocks(roundLength * 2); + const withdrawableStakeBefore1 = (await sr_staker_1.withdrawableStake()).toString(); + expect(withdrawableStakeBefore1).to.be.eq('0'); + + // Increase height and check withdrawable stake, should be still 0 + await sr_staker_1.manageStake(nonce_1, 0, height_1_n_1); + const withdrawableStakeAfter1 = (await sr_staker_1.withdrawableStake()).toString(); + expect(withdrawableStakeAfter1).to.be.eq('0'); + + // Decrease height and check withdrawable stake, should be 0 BZZ + await sr_staker_1.manageStake(nonce_1, 0, height_1); + await mineNBlocks(roundLength * 2); + const withdrawableStakeAfter2 = (await sr_staker_1.withdrawableStake()).toString(); + expect(withdrawableStakeAfter2).to.be.eq('0'); + }); }); describe('change overlay hex', function () { @@ -496,28 +655,28 @@ describe('Staking', function () { sr_staker_1 = await ethers.getContract('StakeRegistry', staker_1); await mintAndApprove(staker_1, sr_staker_1.address, stakeAmount_1); - await sr_staker_1.manageStake(nonce_1, stakeAmount_1); + await sr_staker_1.manageStake(nonce_1, stakeAmount_1, height_1); }); it('should change overlay hex', async function () { const current_overlay = await sr_staker_1.overlayOfAddress(staker_1); - await sr_staker_1.manageStake(nonce_1_n_25, 0); + await sr_staker_1.manageStake(nonce_1_n_25, 0, 0); const new_overlay = await sr_staker_1.overlayOfAddress(staker_1); expect(new_overlay).to.not.eq(current_overlay); }); it('should match new overlay hex', async function () { - await sr_staker_1.manageStake(nonce_1_n_25, 0); + await sr_staker_1.manageStake(nonce_1_n_25, zeroStake, height_1); const new_overlay = await sr_staker_1.overlayOfAddress(staker_1); expect(new_overlay).to.be.eq(overlay_1_n_25); }); it('should match old overlay hex after double change', async function () { - await sr_staker_1.manageStake(nonce_1_n_25, 0); + await sr_staker_1.manageStake(nonce_1_n_25, zeroStake, height_1); const new_overlay = await sr_staker_1.overlayOfAddress(staker_1); expect(new_overlay).to.be.eq(overlay_1_n_25); - await sr_staker_1.manageStake(nonce_1, 0); + await sr_staker_1.manageStake(nonce_1, zeroStake, height_1); const old_overlay = await sr_staker_1.overlayOfAddress(staker_1); expect(old_overlay).to.be.eq(overlay_1); }); diff --git a/test/Stats.test.ts b/test/Stats.test.ts index 6a6a939b..1ecfa7d0 100644 --- a/test/Stats.test.ts +++ b/test/Stats.test.ts @@ -64,7 +64,7 @@ async function nPlayerGames(nodes: string[], stakes: string[], effectiveStakes: for (let i = 0; i < nodes.length; i++) { const sr_node = await ethers.getContract('StakeRegistry', nodes[i]); await mintAndApprove(deployer, nodes[i], sr_node.address, stakes[i]); - await sr_node.manageStake(nonce, stakes[i]); + await sr_node.manageStake(nonce, stakes[i], 0); } const winDist: Outcome[] = []; diff --git a/testnet_deployed.json b/testnet_deployed.json index 3fb404b4..e502f06f 100644 --- a/testnet_deployed.json +++ b/testnet_deployed.json @@ -674,7 +674,7 @@ "bytecode": "0x60806040523480156200001157600080fd5b506040516200210f3803806200210f83398101604081905262000034916200044e565b8282818160056200004683826200054f565b5060066200005582826200054f565b50506007805460ff19169055506200006f600033620000f0565b6200009b7f9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a633620000f0565b620000c77f65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a33620000f0565b50506008819055620000db600033620000f0565b620000e7338262000100565b5050506200063d565b620000fc8282620001d7565b5050565b6001600160a01b0382166200015c5760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f20616464726573730060448201526064015b60405180910390fd5b6200016a6000838362000202565b80600460008282546200017e91906200061b565b90915550506001600160a01b0382166000818152600260209081526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b620001e382826200020f565b6000828152600160205260409020620001fd9082620002af565b505050565b620001fd838383620002cf565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16620000fc576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556200026b3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000620002c6836001600160a01b03841662000337565b90505b92915050565b60075460ff1615620001fd5760405162461bcd60e51b815260206004820152602a60248201527f45524332305061757361626c653a20746f6b656e207472616e736665722077686044820152691a5b19481c185d5cd95960b21b606482015260840162000153565b60008181526001830160205260408120546200038057508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155620002c9565b506000620002c9565b634e487b7160e01b600052604160045260246000fd5b600082601f830112620003b157600080fd5b81516001600160401b0380821115620003ce57620003ce62000389565b604051601f8301601f19908116603f01168101908282118183101715620003f957620003f962000389565b816040528381526020925086838588010111156200041657600080fd5b600091505b838210156200043a57858201830151818301840152908201906200041b565b600093810190920192909252949350505050565b6000806000606084860312156200046457600080fd5b83516001600160401b03808211156200047c57600080fd5b6200048a878388016200039f565b94506020860151915080821115620004a157600080fd5b50620004b0868287016200039f565b925050604084015190509250925092565b600181811c90821680620004d657607f821691505b602082108103620004f757634e487b7160e01b600052602260045260246000fd5b50919050565b601f821115620001fd57600081815260208120601f850160051c81016020861015620005265750805b601f850160051c820191505b81811015620005475782815560010162000532565b505050505050565b81516001600160401b038111156200056b576200056b62000389565b62000583816200057c8454620004c1565b84620004fd565b602080601f831160018114620005bb5760008415620005a25750858301515b600019600386901b1c1916600185901b17855562000547565b600085815260208120601f198616915b82811015620005ec57888601518255948401946001909101908401620005cb565b50858210156200060b5787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b80820180821115620002c957634e487b7160e01b600052601160045260246000fd5b611ac2806200064d6000396000f3fe608060405234801561001057600080fd5b50600436106101c45760003560e01c806370a08231116100f9578063a457c2d711610097578063d539139311610071578063d5391393146103d3578063d547741f146103fa578063dd62ed3e1461040d578063e63ab1e91461044657600080fd5b8063a457c2d71461039a578063a9059cbb146103ad578063ca15c873146103c057600080fd5b80639010d07c116100d35780639010d07c1461032857806391d148541461035357806395d89b411461038a578063a217fddf1461039257600080fd5b806370a08231146102e457806379cc67901461030d5780638456cb591461032057600080fd5b8063313ce567116101665780633f4ba83a116101405780633f4ba83a146102ab57806340c10f19146102b357806342966c68146102c65780635c975abb146102d957600080fd5b8063313ce5671461027657806336568abe14610285578063395093511461029857600080fd5b806318160ddd116101a257806318160ddd1461021957806323b872dd1461022b578063248a9ca31461023e5780632f2ff15d1461026157600080fd5b806301ffc9a7146101c957806306fdde03146101f1578063095ea7b314610206575b600080fd5b6101dc6101d7366004611776565b61046d565b60405190151581526020015b60405180910390f35b6101f96104b1565b6040516101e891906117c4565b6101dc610214366004611813565b610543565b6004545b6040519081526020016101e8565b6101dc61023936600461183d565b61055b565b61021d61024c366004611879565b60009081526020819052604090206001015490565b61027461026f366004611892565b61057f565b005b604051601081526020016101e8565b610274610293366004611892565b6105a9565b6101dc6102a6366004611813565b61063a565b610274610679565b6102746102c1366004611813565b61071f565b6102746102d4366004611879565b6107c5565b60075460ff166101dc565b61021d6102f23660046118be565b6001600160a01b031660009081526002602052604090205490565b61027461031b366004611813565b6107d2565b6102746107e7565b61033b6103363660046118d9565b61088b565b6040516001600160a01b0390911681526020016101e8565b6101dc610361366004611892565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b6101f96108aa565b61021d600081565b6101dc6103a8366004611813565b6108b9565b6101dc6103bb366004611813565b610963565b61021d6103ce366004611879565b610971565b61021d7f9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a681565b610274610408366004611892565b610988565b61021d61041b3660046118fb565b6001600160a01b03918216600090815260036020908152604080832093909416825291909152205490565b61021d7f65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a81565b60006001600160e01b031982167f5a05180f0000000000000000000000000000000000000000000000000000000014806104ab57506104ab826109ad565b92915050565b6060600580546104c090611925565b80601f01602080910402602001604051908101604052809291908181526020018280546104ec90611925565b80156105395780601f1061050e57610100808354040283529160200191610539565b820191906000526020600020905b81548152906001019060200180831161051c57829003601f168201915b5050505050905090565b600033610551818585610a14565b5060019392505050565b600033610569858285610b6c565b610574858585610bfe565b506001949350505050565b60008281526020819052604090206001015461059a81610dfd565b6105a48383610e07565b505050565b6001600160a01b038116331461062c5760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b6106368282610e29565b5050565b3360008181526003602090815260408083206001600160a01b03871684529091528120549091906105519082908690610674908790611975565b610a14565b6106a37f65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a33610361565b6107155760405162461bcd60e51b815260206004820152603960248201527f45524332305072657365744d696e7465725061757365723a206d75737420686160448201527f76652070617573657220726f6c6520746f20756e7061757365000000000000006064820152608401610623565b61071d610e4b565b565b6107497f9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a633610361565b6107bb5760405162461bcd60e51b815260206004820152603660248201527f45524332305072657365744d696e7465725061757365723a206d75737420686160448201527f7665206d696e74657220726f6c6520746f206d696e74000000000000000000006064820152608401610623565b6106368282610e9d565b6107cf3382610f6a565b50565b6107dd823383610b6c565b6106368282610f6a565b6108117f65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a33610361565b6108835760405162461bcd60e51b815260206004820152603760248201527f45524332305072657365744d696e7465725061757365723a206d75737420686160448201527f76652070617573657220726f6c6520746f2070617573650000000000000000006064820152608401610623565b61071d6110e1565b60008281526001602052604081206108a3908361111e565b9392505050565b6060600680546104c090611925565b3360008181526003602090815260408083206001600160a01b0387168452909152812054909190838110156109565760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f7760448201527f207a65726f0000000000000000000000000000000000000000000000000000006064820152608401610623565b6105748286868403610a14565b600033610551818585610bfe565b60008181526001602052604081206104ab9061112a565b6000828152602081905260409020600101546109a381610dfd565b6105a48383610e29565b60006001600160e01b031982167f7965db0b0000000000000000000000000000000000000000000000000000000014806104ab57507f01ffc9a7000000000000000000000000000000000000000000000000000000006001600160e01b03198316146104ab565b6001600160a01b038316610a8f5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460448201527f72657373000000000000000000000000000000000000000000000000000000006064820152608401610623565b6001600160a01b038216610b0b5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f20616464726560448201527f73730000000000000000000000000000000000000000000000000000000000006064820152608401610623565b6001600160a01b0383811660008181526003602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6001600160a01b038381166000908152600360209081526040808320938616835292905220546000198114610bf85781811015610beb5760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606401610623565b610bf88484848403610a14565b50505050565b6001600160a01b038316610c7a5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f20616460448201527f64726573730000000000000000000000000000000000000000000000000000006064820152608401610623565b6001600160a01b038216610cf65760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201527f65737300000000000000000000000000000000000000000000000000000000006064820152608401610623565b610d01838383611134565b6001600160a01b03831660009081526002602052604090205481811015610d905760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e742065786365656473206260448201527f616c616e636500000000000000000000000000000000000000000000000000006064820152608401610623565b6001600160a01b0380851660008181526002602052604080822086860390559286168082529083902080548601905591517fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef90610df09086815260200190565b60405180910390a3610bf8565b6107cf813361113f565b610e1182826111b2565b60008281526001602052604090206105a49082611250565b610e338282611265565b60008281526001602052604090206105a490826112e4565b610e536112f9565b6007805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b6001600160a01b038216610ef35760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610623565b610eff60008383611134565b8060046000828254610f119190611975565b90915550506001600160a01b0382166000818152600260209081526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b6001600160a01b038216610fe65760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f2061646472657360448201527f73000000000000000000000000000000000000000000000000000000000000006064820152608401610623565b610ff282600083611134565b6001600160a01b038216600090815260026020526040902054818110156110815760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e60448201527f63650000000000000000000000000000000000000000000000000000000000006064820152608401610623565b6001600160a01b03831660008181526002602090815260408083208686039055600480548790039055518581529192917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3505050565b6110e961134b565b6007805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258610e803390565b60006108a3838361139e565b60006104ab825490565b6105a48383836113c8565b6000828152602081815260408083206001600160a01b038516845290915290205460ff166106365761117081611441565b61117b836020611453565b60405160200161118c929190611988565b60408051601f198184030181529082905262461bcd60e51b8252610623916004016117c4565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610636576000828152602081815260408083206001600160a01b03851684529091529020805460ff1916600117905561120c3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b60006108a3836001600160a01b038416611634565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1615610636576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b60006108a3836001600160a01b038416611683565b60075460ff1661071d5760405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f74207061757365640000000000000000000000006044820152606401610623565b60075460ff161561071d5760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a20706175736564000000000000000000000000000000006044820152606401610623565b60008260000182815481106113b5576113b5611a09565b9060005260206000200154905092915050565b60075460ff16156105a45760405162461bcd60e51b815260206004820152602a60248201527f45524332305061757361626c653a20746f6b656e207472616e7366657220776860448201527f696c6520706175736564000000000000000000000000000000000000000000006064820152608401610623565b60606104ab6001600160a01b03831660145b60606000611462836002611a1f565b61146d906002611975565b67ffffffffffffffff81111561148557611485611a36565b6040519080825280601f01601f1916602001820160405280156114af576020820181803683370190505b5090507f3000000000000000000000000000000000000000000000000000000000000000816000815181106114e6576114e6611a09565b60200101906001600160f81b031916908160001a9053507f78000000000000000000000000000000000000000000000000000000000000008160018151811061153157611531611a09565b60200101906001600160f81b031916908160001a9053506000611555846002611a1f565b611560906001611975565b90505b60018111156115e5577f303132333435363738396162636465660000000000000000000000000000000085600f16601081106115a1576115a1611a09565b1a60f81b8282815181106115b7576115b7611a09565b60200101906001600160f81b031916908160001a90535060049490941c936115de81611a4c565b9050611563565b5083156108a35760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610623565b600081815260018301602052604081205461167b575081546001818101845560008481526020808220909301849055845484825282860190935260409020919091556104ab565b5060006104ab565b6000818152600183016020526040812054801561176c5760006116a7600183611a63565b85549091506000906116bb90600190611a63565b90508181146117205760008660000182815481106116db576116db611a09565b90600052602060002001549050808760000184815481106116fe576116fe611a09565b6000918252602080832090910192909255918252600188019052604090208390555b855486908061173157611731611a76565b6001900381819060005260206000200160009055905585600101600086815260200190815260200160002060009055600193505050506104ab565b60009150506104ab565b60006020828403121561178857600080fd5b81356001600160e01b0319811681146108a357600080fd5b60005b838110156117bb5781810151838201526020016117a3565b50506000910152565b60208152600082518060208401526117e38160408501602087016117a0565b601f01601f19169190910160400192915050565b80356001600160a01b038116811461180e57600080fd5b919050565b6000806040838503121561182657600080fd5b61182f836117f7565b946020939093013593505050565b60008060006060848603121561185257600080fd5b61185b846117f7565b9250611869602085016117f7565b9150604084013590509250925092565b60006020828403121561188b57600080fd5b5035919050565b600080604083850312156118a557600080fd5b823591506118b5602084016117f7565b90509250929050565b6000602082840312156118d057600080fd5b6108a3826117f7565b600080604083850312156118ec57600080fd5b50508035926020909101359150565b6000806040838503121561190e57600080fd5b611917836117f7565b91506118b5602084016117f7565b600181811c9082168061193957607f821691505b60208210810361195957634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fd5b808201808211156104ab576104ab61195f565b7f416363657373436f6e74726f6c3a206163636f756e74200000000000000000008152600083516119c08160178501602088016117a0565b7f206973206d697373696e6720726f6c652000000000000000000000000000000060179184019182015283516119fd8160288401602088016117a0565b01602801949350505050565b634e487b7160e01b600052603260045260246000fd5b80820281158282048414176104ab576104ab61195f565b634e487b7160e01b600052604160045260246000fd5b600081611a5b57611a5b61195f565b506000190190565b818103818111156104ab576104ab61195f565b634e487b7160e01b600052603160045260246000fdfea26469706673582212203620aca8c9d1a7c1605549c86f17d4dab4d7ed55f980b6be0398dcb6d883aaa064736f6c63430008130033", "address": "0x543dDb01Ba47acB11de34891cD86B675F04840db", "block": 4594507, - "url": "https://sepolia.etherscan.io/address/0x543dDb01Ba47acB11de34891cD86B675F04840db" + "url": "https://sepolia.etherscan.io/0x543dDb01Ba47acB11de34891cD86B675F04840db" }, "staking": { "abi": [ @@ -918,6 +918,12 @@ "internalType": "uint256", "name": "lastUpdatedBlock", "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint8", + "name": "height", + "type": "uint8" } ], "name": "StakeUpdated", @@ -1099,6 +1105,25 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "address", + "name": "_owner", + "type": "address" + } + ], + "name": "heightOfAddress", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -1129,6 +1154,11 @@ "internalType": "uint256", "name": "_addAmount", "type": "uint256" + }, + { + "internalType": "uint8", + "name": "_height", + "type": "uint8" } ], "name": "manageStake", @@ -1284,6 +1314,11 @@ "internalType": "uint256", "name": "lastUpdatedBlockNumber", "type": "uint256" + }, + { + "internalType": "uint8", + "name": "height", + "type": "uint8" } ], "stateMutability": "view", @@ -1336,10 +1371,10 @@ "type": "function" } ], - "bytecode": "0x60a06040523480156200001157600080fd5b5060405162001ab438038062001ab483398101604081905262000034916200015a565b6001805460ff19169055600380546001600160a01b03808616608052831668010000000000000000026001600160e01b03199091166001600160401b03851617179055620000846000336200008d565b505050620001b2565b6200009982826200009d565b5050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1662000099576000828152602081815260408083206001600160a01b03851684529091529020805460ff19166001179055620000f93390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b80516001600160a01b03811681146200015557600080fd5b919050565b6000806000606084860312156200017057600080fd5b6200017b846200013d565b60208501519093506001600160401b03811681146200019957600080fd5b9150620001a9604085016200013d565b90509250925092565b6080516118d1620001e36000396000818161029d0152818161051c015281816108c40152610a6801526118d16000f3fe608060405234801561001057600080fd5b50600436106101985760003560e01c8063830a053e116100e3578063d009b2d61161008c578063d547741f11610066578063d547741f14610405578063e8e8d87e14610418578063f7b188a51461042b57600080fd5b8063d009b2d6146103b3578063d1052d1f146103c6578063d48bfaeb146103f257600080fd5b806397adedb5116100bd57806397adedb51461035b578063a217fddf14610384578063a6471a1d1461038c57600080fd5b8063830a053e146103095780638456cb591461031c57806391d148541461032457600080fd5b80632f2ff15d116101455780635c975abb1161011f5780635c975abb146102d757806369da9114146102e25780636f1c5de71461030157600080fd5b80632f2ff15d1461027257806336568abe14610285578063420fc4db1461029857600080fd5b806312236a771161017657806312236a77146101e257806316934fc4146101ea578063248a9ca31461024157600080fd5b806301ffc9a71461019d5780630aed7b0d146101c557806310ae2147146101cf575b600080fd5b6101b06101ab36600461158f565b610433565b60405190151581526020015b60405180910390f35b6101cd6104cc565b005b6101cd6101dd3660046115d1565b6105d6565b6101cd6109eb565b6102216101f836600461160f565b600260208190526000918252604090912080546001820154928201546003909201549092919084565b6040805194855260208501939093529183015260608201526080016101bc565b61026461024f36600461162a565b60009081526020819052604090206001015490565b6040519081526020016101bc565b6101cd610280366004611643565b610b39565b6101cd610293366004611643565b610b63565b6102bf7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b0390911681526020016101bc565b60015460ff166101b0565b6003546102bf906801000000000000000090046001600160a01b031681565b610264610bf0565b61026461031736600461160f565b610c25565b6101cd610c7b565b6101b0610332366004611643565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b61026461036936600461160f565b6001600160a01b031660009081526002602052604090205490565b610264600081565b6102647f3e35b14a9f4fef84b59f9bdcd3044fc28783144b7e42bfb2cd075e6a02cb082881565b6101cd6103c136600461166f565b610cd2565b6102646103d436600461160f565b6001600160a01b031660009081526002602052604090206003015490565b6101cd610400366004611699565b610dae565b6101cd610413366004611643565b610e3a565b6101cd61042636600461166f565b610e5f565b6101cd610fcb565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f7965db0b0000000000000000000000000000000000000000000000000000000014806104c657507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008316145b92915050565b6104d4611022565b33600090815260026020526040902060030154156105d457336000818152600260208190526040918290200154905163a9059cbb60e01b8152600481019290925260248201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063a9059cbb906044016020604051808303816000875af115801561056d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061059191906116c3565b6105ae576040516312171d8360e31b815260040160405180910390fd5b336000908152600260208190526040822082815560018101839055908101829055600301555b565b6105de611074565b336000818152600260209081526040822080546003918201549154909491939265ff000000ff00600883811b91821664ff000000ff9490911c93841617601090811b67ff000000ff0000009290921666ff000000ff0000949094169390931790921c9190911780821b6bffffffffffffffff0000000016911c63ffffffff161760405160609290921b6bffffffffffffffffffffffff1916602083015260c01b7fffffffffffffffff000000000000000000000000000000000000000000000000166034820152603c8101869052605c016040516020818303038152906040528051906020012090506000600360089054906101000a90046001600160a01b03166001600160a01b0316639d1b464a6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561071c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061074091906116e5565b6107509063ffffffff1686611721565b905067016345785d8a000085108015610767575082155b1561079e576040517f8ecf3d0300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b82158015906107bf5750336000908152600260205260409020600301544311155b156107f6576040517fa8cab3d100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b33600090815260026020526040812060010154610814908390611743565b3360009081526002602081905260408220015491925090610836908890611743565b604080516080810182528681526020808201868152828401858152436060850190815233600090815260029485905295909520935184559051600184015551908201559051600390910155905086156109a0576040517f23b872dd000000000000000000000000000000000000000000000000000000008152336004820152306024820152604481018890527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906323b872dd906064016020604051808303816000875af1158015610915573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061093991906116c3565b610956576040516312171d8360e31b815260040160405180910390fd5b604080518381526020810183905290810185905243606082015233907ff3fb57c8e9287d05c0b3c8612031896c43149edcf7ca6f1b287ac836b4b5d5699060800160405180910390a25b8386146109e15760408051338152602081018690527fe188baf4bcb1c4413d19ba0eaef908614d30e8df9570d6fc4d584b75f4a37a3a910160405180910390a15b5050505050505050565b336000908152600260208190526040822090810154600190910154909190610a1390836110c7565b610a1d9083611756565b90508015610b35573360009081526002602081905260408220018054839290610a47908490611756565b909155505060405163a9059cbb60e01b8152336004820152602481018290527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063a9059cbb906044016020604051808303816000875af1158015610ab9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610add91906116c3565b610afa576040516312171d8360e31b815260040160405180910390fd5b60408051338152602081018390527f8108595eb6bad3acefa9da467d90cc2217686d5c5ac85460f8b7849c840645fc91015b60405180910390a15b5050565b600082815260208190526040902060010154610b548161116b565b610b5e8383611178565b505050565b6001600160a01b0381163314610be65760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b610b358282611216565b336000908152600260208190526040822090810154600190910154610c1590826110c7565b610c1f9082611756565b91505090565b6001600160a01b0381166000908152600260205260408120600301544311610c4e5760006104c6565b6001600160a01b038216600090815260026020819052604090912060018101549101546104c691906110c7565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff16610cca57604051631d77d47760e21b815260040160405180910390fd5b6105d4611295565b3360009081527f10fa80d2e578284bf61a483a3da84fbdd683a7e7256a9895dc4461ac543f4a16602052604090205460ff16610d2157604051630490edbf60e31b815260040160405180910390fd5b6001600160a01b03821660009081526002602052604090206003015415610b3557610d4c8143611743565b6001600160a01b038316600081815260026020908152604091829020600381019490945592548151928352928201929092529081018290527fd7863535575e7de6678ea9d340a4bfe0b84d77323bfa2ef602c3c1df82aea78090606001610b2c565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff16610e16576040517f82b4290000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6003805467ffffffffffffffff191667ffffffffffffffff92909216919091179055565b600082815260208190526040902060010154610e558161116b565b610b5e8383611216565b3360009081527f10fa80d2e578284bf61a483a3da84fbdd683a7e7256a9895dc4461ac543f4a16602052604090205460ff16610eae57604051630490edbf60e31b815260040160405180910390fd5b6001600160a01b03821660009081526002602052604090206003015415610f76576001600160a01b03821660009081526002602081905260409091200154811015610f47576001600160a01b03821660009081526002602081905260408220018054839290610f1e908490611756565b90915550506001600160a01b038216600090815260026020526040902043600390910155610f76565b6001600160a01b0382166000908152600260208190526040822082815560018101839055908101829055600301555b6001600160a01b0382166000818152600260209081526040918290205482519384529083015281018290527f5f52ce031e6eba64e8a81288196b93a3e422096e80aea812f1f5a77866359b3a90606001610b2c565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff1661101a57604051631d77d47760e21b815260040160405180910390fd5b6105d46112e9565b60015460ff166105d45760405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f74207061757365640000000000000000000000006044820152606401610bdd565b60015460ff16156105d45760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a20706175736564000000000000000000000000000000006044820152606401610bdd565b600080600360089054906101000a90046001600160a01b03166001600160a01b0316639d1b464a6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561111d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061114191906116e5565b6111519063ffffffff1685611769565b9050828110156111625790506104c6565b829150506104c6565b6111758133611322565b50565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610b35576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556111d23390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1615610b35576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b61129d611074565b6001805460ff1916811790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258335b6040516001600160a01b03909116815260200160405180910390a1565b6112f1611022565b6001805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa336112cc565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610b355761135381611395565b61135e8360206113a7565b60405160200161136f9291906117a4565b60408051601f198184030181529082905262461bcd60e51b8252610bdd91600401611825565b60606104c66001600160a01b03831660145b606060006113b6836002611769565b6113c1906002611743565b67ffffffffffffffff8111156113d9576113d9611858565b6040519080825280601f01601f191660200182016040528015611403576020820181803683370190505b5090507f30000000000000000000000000000000000000000000000000000000000000008160008151811061143a5761143a61186e565b60200101906001600160f81b031916908160001a9053507f7800000000000000000000000000000000000000000000000000000000000000816001815181106114855761148561186e565b60200101906001600160f81b031916908160001a90535060006114a9846002611769565b6114b4906001611743565b90505b6001811115611539577f303132333435363738396162636465660000000000000000000000000000000085600f16601081106114f5576114f561186e565b1a60f81b82828151811061150b5761150b61186e565b60200101906001600160f81b031916908160001a90535060049490941c9361153281611884565b90506114b7565b5083156115885760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610bdd565b9392505050565b6000602082840312156115a157600080fd5b81357fffffffff000000000000000000000000000000000000000000000000000000008116811461158857600080fd5b600080604083850312156115e457600080fd5b50508035926020909101359150565b80356001600160a01b038116811461160a57600080fd5b919050565b60006020828403121561162157600080fd5b611588826115f3565b60006020828403121561163c57600080fd5b5035919050565b6000806040838503121561165657600080fd5b82359150611666602084016115f3565b90509250929050565b6000806040838503121561168257600080fd5b61168b836115f3565b946020939093013593505050565b6000602082840312156116ab57600080fd5b813567ffffffffffffffff8116811461158857600080fd5b6000602082840312156116d557600080fd5b8151801515811461158857600080fd5b6000602082840312156116f757600080fd5b815163ffffffff8116811461158857600080fd5b634e487b7160e01b600052601160045260246000fd5b60008261173e57634e487b7160e01b600052601260045260246000fd5b500490565b808201808211156104c6576104c661170b565b818103818111156104c6576104c661170b565b80820281158282048414176104c6576104c661170b565b60005b8381101561179b578181015183820152602001611783565b50506000910152565b7f416363657373436f6e74726f6c3a206163636f756e74200000000000000000008152600083516117dc816017850160208801611780565b7f206973206d697373696e6720726f6c65200000000000000000000000000000006017918401918201528351611819816028840160208801611780565b01602801949350505050565b6020815260008251806020840152611844816040850160208701611780565b601f01601f19169190910160400192915050565b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b6000816118935761189361170b565b50600019019056fea26469706673582212208bfe4c61da67ab0201caa241720a421db808c61d5820cfde14e7a06f558c7b1164736f6c63430008130033", - "address": "0x5CF39e699b601c2EBc3e25b19Fd4102d8366b56F", - "block": 6596291, - "url": "https://sepolia.etherscan.io/address/0x5CF39e699b601c2EBc3e25b19Fd4102d8366b56F" + "bytecode": "0x60a06040523480156200001157600080fd5b5060405162001cca38038062001cca83398101604081905262000034916200015a565b6001805460ff19169055600380546001600160a01b03808616608052831668010000000000000000026001600160e01b03199091166001600160401b03851617179055620000846000336200008d565b505050620001b2565b6200009982826200009d565b5050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1662000099576000828152602081815260408083206001600160a01b03851684529091529020805460ff19166001179055620000f93390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b80516001600160a01b03811681146200015557600080fd5b919050565b6000806000606084860312156200017057600080fd5b6200017b846200013d565b60208501519093506001600160401b03811681146200019957600080fd5b9150620001a9604085016200013d565b90509250925092565b608051611ae7620001e3600039600081816102ea0152818161057c015281816106cb0152610b8f0152611ae76000f3fe608060405234801561001057600080fd5b50600436106101a35760003560e01c80636f1c5de7116100ee578063a6471a1d11610097578063d48bfaeb11610071578063d48bfaeb14610452578063d547741f14610465578063e8e8d87e14610478578063f7b188a51461048b57600080fd5b8063a6471a1d146103ec578063d009b2d614610413578063d1052d1f1461042657600080fd5b806391d14854116100c857806391d148541461038457806397adedb5146103bb578063a217fddf146103e457600080fd5b80636f1c5de714610361578063830a053e146103695780638456cb591461037c57600080fd5b80632f2ff15d116101505780635c975abb1161012a5780635c975abb14610324578063663e54f91461032f57806369da91141461034257600080fd5b80632f2ff15d146102bf57806336568abe146102d2578063420fc4db146102e557600080fd5b806316934fc41161018157806316934fc4146101e25780631d5480531461024d578063248a9ca31461028e57600080fd5b806301ffc9a7146101a85780630aed7b0d146101d057806312236a77146101da575b600080fd5b6101bb6101b6366004611695565b610493565b60405190151581526020015b60405180910390f35b6101d861052c565b005b6101d8610645565b6102226101f03660046116f3565b600260208190526000918252604090912080546001820154928201546003830154600490930154919392909160ff1685565b60408051958652602086019490945292840191909152606083015260ff16608082015260a0016101c7565b61027c61025b3660046116f3565b6001600160a01b031660009081526002602052604090206004015460ff1690565b60405160ff90911681526020016101c7565b6102b161029c36600461170e565b60009081526020819052604090206001015490565b6040519081526020016101c7565b6101d86102cd366004611727565b61079c565b6101d86102e0366004611727565b6107c6565b61030c7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b0390911681526020016101c7565b60015460ff166101bb565b6101d861033d366004611753565b610853565b60035461030c906801000000000000000090046001600160a01b031681565b6102b1610cbf565b6102b16103773660046116f3565b610cff565b6101d8610d60565b6101bb610392366004611727565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b6102b16103c93660046116f3565b6001600160a01b031660009081526002602052604090205490565b6102b1600081565b6102b17f3e35b14a9f4fef84b59f9bdcd3044fc28783144b7e42bfb2cd075e6a02cb082881565b6101d8610421366004611792565b610db7565b6102b16104343660046116f3565b6001600160a01b031660009081526002602052604090206003015490565b6101d86104603660046117bc565b610e93565b6101d8610473366004611727565b610f1f565b6101d8610486366004611792565b610f44565b6101d86110bf565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f7965db0b00000000000000000000000000000000000000000000000000000000148061052657507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008316145b92915050565b610534611116565b336000908152600260205260409020600301541561064357336000818152600260208190526040918290200154905163a9059cbb60e01b8152600481019290925260248201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063a9059cbb906044016020604051808303816000875af11580156105cd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105f191906117e6565b61060e576040516312171d8360e31b815260040160405180910390fd5b3360009081526002602081905260408220828155600181018390559081018290556003810191909155600401805460ff191690555b565b336000908152600260208190526040822090810154600182015460049092015490929161067691849060ff16611168565b610680908361181e565b905080156107985733600090815260026020819052604082200180548392906106aa90849061181e565b909155505060405163a9059cbb60e01b8152336004820152602481018290527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063a9059cbb906044016020604051808303816000875af115801561071c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061074091906117e6565b61075d576040516312171d8360e31b815260040160405180910390fd5b60408051338152602081018390527f8108595eb6bad3acefa9da467d90cc2217686d5c5ac85460f8b7849c840645fc91015b60405180910390a15b5050565b6000828152602081905260409020600101546107b781611225565b6107c18383611232565b505050565b6001600160a01b03811633146108495760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b61079882826112d0565b61085b61134f565b336000818152600260209081526040822080546003918201549154909491939265ff000000ff00600883811b91821664ff000000ff9490911c93841617601090811b67ff000000ff0000009290921666ff000000ff0000949094169390931790921c9190911780821b6bffffffffffffffff0000000016911c63ffffffff161760405160609290921b6bffffffffffffffffffffffff1916602083015260c01b7fffffffffffffffff000000000000000000000000000000000000000000000000166034820152603c8101879052605c016040516020818303038152906040528051906020012090508360026109519190611915565b6109639067016345785d8a0000611924565b8510801561096f575081155b156109a6576040517f8ecf3d0300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b81158015906109c75750336000908152600260205260409020600301544311155b156109fe576040517fa8cab3d100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b336000908152600260208190526040909120908101546001909101548615610ae0573360009081526002602081905260409091200154610a3f90889061193b565b9150610a4c866002611915565b600360089054906101000a90046001600160a01b03166001600160a01b0316639d1b464a6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610a9f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ac3919061194e565b63ffffffff16610ad39190611924565b610add9083611974565b90505b6040805160a0810182528481526020808201848152828401868152436060850190815260ff8c8116608087019081523360009081526002968790529790972095518655925160018601559051928401929092559051600383015591516004909101805460ff1916919092161790558615610c74576040517f23b872dd000000000000000000000000000000000000000000000000000000008152336004820152306024820152604481018890527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906323b872dd906064016020604051808303816000875af1158015610be0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c0491906117e6565b610c21576040516312171d8360e31b815260040160405180910390fd5b604080518281526020810184905290810184905243606082015260ff8716608082015233907f8fb3da6e133de1007392b10d429548e9c2565c791c52e1498b01b65d8797e74c9060a00160405180910390a25b828514610cb55760408051338152602081018590527fe188baf4bcb1c4413d19ba0eaef908614d30e8df9570d6fc4d584b75f4a37a3a910160405180910390a15b5050505050505050565b33600090815260026020819052604082209081015460018201546004909201549091610cef91839060ff16611168565b610cf9908261181e565b91505090565b6001600160a01b0381166000908152600260205260408120600301544311610d28576000610526565b6001600160a01b038216600090815260026020819052604090912060018101549181015460049091015461052692919060ff16611168565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff16610daf57604051631d77d47760e21b815260040160405180910390fd5b6106436113a2565b3360009081527f10fa80d2e578284bf61a483a3da84fbdd683a7e7256a9895dc4461ac543f4a16602052604090205460ff16610e0657604051630490edbf60e31b815260040160405180910390fd5b6001600160a01b0382166000908152600260205260409020600301541561079857610e31814361193b565b6001600160a01b038316600081815260026020908152604091829020600381019490945592548151928352928201929092529081018290527fd7863535575e7de6678ea9d340a4bfe0b84d77323bfa2ef602c3c1df82aea7809060600161078f565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff16610efb576040517f82b4290000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6003805467ffffffffffffffff191667ffffffffffffffff92909216919091179055565b600082815260208190526040902060010154610f3a81611225565b6107c183836112d0565b3360009081527f10fa80d2e578284bf61a483a3da84fbdd683a7e7256a9895dc4461ac543f4a16602052604090205460ff16610f9357604051630490edbf60e31b815260040160405180910390fd5b6001600160a01b0382166000908152600260205260409020600301541561106a576001600160a01b0382166000908152600260208190526040909120015481101561102c576001600160a01b0382166000908152600260208190526040822001805483929061100390849061181e565b90915550506001600160a01b03821660009081526002602052604090204360039091015561106a565b6001600160a01b03821660009081526002602081905260408220828155600181018390559081018290556003810191909155600401805460ff191690555b6001600160a01b0382166000818152600260209081526040918290205482519384529083015281018290527f5f52ce031e6eba64e8a81288196b93a3e422096e80aea812f1f5a77866359b3a9060600161078f565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff1661110e57604051631d77d47760e21b815260040160405180910390fd5b6106436113f6565b60015460ff166106435760405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f74207061757365640000000000000000000000006044820152606401610840565b600080600360089054906101000a90046001600160a01b03166001600160a01b0316639d1b464a6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156111be573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111e2919061194e565b63ffffffff16856111f4856002611915565b6111fe9190611924565b6112089190611924565b90508381101561121957905061121e565b839150505b9392505050565b61122f813361142f565b50565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610798576000828152602081815260408083206001600160a01b03851684529091529020805460ff1916600117905561128c3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1615610798576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b60015460ff16156106435760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a20706175736564000000000000000000000000000000006044820152606401610840565b6113aa61134f565b6001805460ff1916811790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258335b6040516001600160a01b03909116815260200160405180910390a1565b6113fe611116565b6001805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa336113d9565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1661079857611460816114a2565b61146b8360206114b4565b60405160200161147c9291906119ba565b60408051601f198184030181529082905262461bcd60e51b825261084091600401611a3b565b60606105266001600160a01b03831660145b606060006114c3836002611924565b6114ce90600261193b565b67ffffffffffffffff8111156114e6576114e6611a6e565b6040519080825280601f01601f191660200182016040528015611510576020820181803683370190505b5090507f30000000000000000000000000000000000000000000000000000000000000008160008151811061154757611547611a84565b60200101906001600160f81b031916908160001a9053507f78000000000000000000000000000000000000000000000000000000000000008160018151811061159257611592611a84565b60200101906001600160f81b031916908160001a90535060006115b6846002611924565b6115c190600161193b565b90505b6001811115611646577f303132333435363738396162636465660000000000000000000000000000000085600f166010811061160257611602611a84565b1a60f81b82828151811061161857611618611a84565b60200101906001600160f81b031916908160001a90535060049490941c9361163f81611a9a565b90506115c4565b50831561121e5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610840565b6000602082840312156116a757600080fd5b81357fffffffff000000000000000000000000000000000000000000000000000000008116811461121e57600080fd5b80356001600160a01b03811681146116ee57600080fd5b919050565b60006020828403121561170557600080fd5b61121e826116d7565b60006020828403121561172057600080fd5b5035919050565b6000806040838503121561173a57600080fd5b8235915061174a602084016116d7565b90509250929050565b60008060006060848603121561176857600080fd5b8335925060208401359150604084013560ff8116811461178757600080fd5b809150509250925092565b600080604083850312156117a557600080fd5b6117ae836116d7565b946020939093013593505050565b6000602082840312156117ce57600080fd5b813567ffffffffffffffff8116811461121e57600080fd5b6000602082840312156117f857600080fd5b8151801515811461121e57600080fd5b634e487b7160e01b600052601160045260246000fd5b8181038181111561052657610526611808565b600181815b8085111561186c57816000190482111561185257611852611808565b8085161561185f57918102915b93841c9390800290611836565b509250929050565b60008261188357506001610526565b8161189057506000610526565b81600181146118a657600281146118b0576118cc565b6001915050610526565b60ff8411156118c1576118c1611808565b50506001821b610526565b5060208310610133831016604e8410600b84101617156118ef575081810a610526565b6118f98383611831565b806000190482111561190d5761190d611808565b029392505050565b600061121e60ff841683611874565b808202811582820484141761052657610526611808565b8082018082111561052657610526611808565b60006020828403121561196057600080fd5b815163ffffffff8116811461121e57600080fd5b60008261199157634e487b7160e01b600052601260045260246000fd5b500490565b60005b838110156119b1578181015183820152602001611999565b50506000910152565b7f416363657373436f6e74726f6c3a206163636f756e74200000000000000000008152600083516119f2816017850160208801611996565b7f206973206d697373696e6720726f6c65200000000000000000000000000000006017918401918201528351611a2f816028840160208801611996565b01602801949350505050565b6020815260008251806020840152611a5a816040850160208701611996565b601f01601f19169190910160400192915050565b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b600081611aa957611aa9611808565b50600019019056fea2646970667358221220e15b5893be07329a6f2593445e71674f50d6bad57c5030abfefacec6cb27303464736f6c63430008130033", + "address": "0x4353A36f4376A273a65595Acd9bE6c63D90fC352", + "block": 7036319, + "url": "https://sepolia.etherscan.io/0x4353A36f4376A273a65595Acd9bE6c63D90fC352" }, "postageStamp": { "abi": [ @@ -2488,7 +2523,7 @@ "bytecode": "0x60e060405260098054600160401b600160801b03191669438000000000000000001790553480156200003057600080fd5b5060405162003bc938038062003bc98339810160408190526200005391620001c4565b600180546001600160b01b0319166101006001600160a01b0385160260ff60a81b191617600160a81b60ff8416021790557f1337d7d57528a8879766fdf2d0456253114c66c4fc263c97168bfdb007c64c666080527f65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a60a0527f3e35b14a9f4fef84b59f9bdcd3044fc28783144b7e42bfb2cd075e6a02cb082860c052620000fd60003362000114565b60a0516200010c903362000114565b505062000213565b62000120828262000124565b5050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1662000120576000828152602081815260408083206001600160a01b03851684529091529020805460ff19166001179055620001803390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b60008060408385031215620001d857600080fd5b82516001600160a01b0381168114620001f057600080fd5b602084015190925060ff811681146200020857600080fd5b809150509250929050565b60805160a05160c05161396a6200025f600039600081816105bb015261118b01526000818161075e015281816118ad0152611e2b015260008181610609015261199e015261396a6000f3fe608060405234801561001057600080fd5b50600436106102f45760003560e01c806381e508b911610191578063b998902f116100e3578063dd483cfb11610097578063ea612e1f11610071578063ea612e1f14610780578063f7b188a514610789578063f90ce5ba1461079157600080fd5b8063dd483cfb14610716578063df67438514610736578063e63ab1e91461075957600080fd5b8063d547741f116100c8578063d547741f146106c6578063d71ba7c4146106d9578063d968f44b146106ec57600080fd5b8063b998902f14610604578063c81e25ab1461062b57600080fd5b806391b7f5ed11610145578063a6471a1d1161011f578063a6471a1d146105b6578063a81064ee146105dd578063b67644b9146105f157600080fd5b806391b7f5ed1461056457806391d1485414610577578063a217fddf146105ae57600080fd5b80638a5e8e32116101765780638a5e8e321461054b5780638b82547f14610554578063906978421461055c57600080fd5b806381e508b91461051f5780638456cb591461054357600080fd5b8063420fc4db1161024a57806351b17cd0116101fe5780635c975abb116101d85780635c975abb146104f9578063628de87714610504578063711bfa2b1461051757600080fd5b806351b17cd0146104cb57806351cff8d9146104d35780635239af71146104e657600080fd5b806347aab79b1161022f57806347aab79b1461049c5780634ba2363a146104af5780634bb13e34146104b857600080fd5b8063420fc4db1461045a57806344beae8e1461047257600080fd5b80632182ddb1116102ac5780632f2ff15d116102865780632f2ff15d146103f857806332ac57dd1461040b57806336568abe1461044757600080fd5b80632182ddb11461037e578063248a9ca3146103bf57806324b570a9146103f057600080fd5b80631889b99b116102dd5780631889b99b1461034e57806318c8572f146103565780631a37b4851461036b57600080fd5b806301ffc9a7146102f9578063053f14da14610321575b600080fd5b61030c610307366004613427565b6107ac565b60405190151581526020015b60405180910390f35b6009546103359067ffffffffffffffff1681565b60405167ffffffffffffffff9091168152602001610318565b61030c610845565b6103696103643660046134aa565b610857565b005b610369610379366004613514565b610af1565b6103a761038c36600461353e565b6000908152600260205260409020546001600160a01b031690565b6040516001600160a01b039091168152602001610318565b6103e26103cd36600461353e565b60009081526020819052604090206001015490565b604051908152602001610318565b6103e2610b87565b610369610406366004613557565b610c3a565b61043561041936600461353e565b600090815260026020526040902054600160a81b900460ff1690565b60405160ff9091168152602001610318565b610369610455366004613557565b610c64565b6001546103a79061010090046001600160a01b031681565b61043561048036600461353e565b600090815260026020526040902054600160a01b900460ff1690565b6103696104aa366004613583565b610cf5565b6103e260075481565b6103696104c63660046135a6565b610fa8565b6103e2611131565b6103696104e136600461361b565b611189565b6103e26104f43660046134aa565b611306565b60015460ff1661030c565b61036961051236600461353e565b611664565b61030c611882565b6103e261052d36600461353e565b6000908152600260208190526040909120015490565b6103696118ab565b6103e260065481565b6103e261190e565b6103e2611964565b61036961057236600461353e565b61199c565b61030c610585366004613557565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b6103e2600081565b6103e27f000000000000000000000000000000000000000000000000000000000000000081565b60015461043590600160a81b900460ff1681565b6103696105ff366004613636565b611aab565b6103e27f000000000000000000000000000000000000000000000000000000000000000081565b61068661063936600461353e565b60026020819052600091825260409091208054600182015491909201546001600160a01b0383169260ff600160a01b8204811693600160a81b8304821693600160b01b9093049091169186565b604080516001600160a01b0397909716875260ff9586166020880152939094169285019290925215156060840152608083015260a082015260c001610318565b6103696106d4366004613557565b611d3f565b6103e26106e736600461353e565b611d64565b61030c6106fa36600461353e565b600090815260026020526040902054600160b01b900460ff1690565b6009546103359068010000000000000000900467ffffffffffffffff1681565b6103e261074436600461353e565b60009081526002602052604090206001015490565b6103e27f000000000000000000000000000000000000000000000000000000000000000081565b6103e260085481565b610369611e29565b60095461033590600160801b900467ffffffffffffffff1681565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f7965db0b00000000000000000000000000000000000000000000000000000000148061083f57507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008316145b92915050565b60006108516003611e8a565b15919050565b61085f611e9a565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff166108ae57604051635844c9e760e11b815260040160405180910390fd5b6001600160a01b0386166108d55760405163d92e233d60e01b815260040160405180910390fd5b60ff831615806108eb57508360ff168360ff1610155b1561090957604051630a0b2c3560e41b815260040160405180910390fd5b6000828152600260205260409020546001600160a01b03161561093f576040516311ab459f60e21b815260040160405180910390fd5b6000610951600160ff87161b8761366e565b905060008661095e611131565b6109689190613685565b90508060000361098b5760405163334ab3f560e11b815260040160405180910390fd5b610996600019611664565b8560ff166001901b600660008282546109af9190613685565b90915550506040805160c0810182526001600160a01b03808b16825260ff808a1660208085019182528a831685870190815289151560608701908152608087018981524360a0890190815260008e815260029586905299909920975188549551935192511515600160b01b0260ff60b01b19938816600160a81b029390931661ffff60a81b1994909716600160a01b0274ffffffffffffffffffffffffffffffffffffffffff19909616971696909617939093171692909217178355905160018301559151910155610a8360038583611eed565b60408051838152602081018390526001600160a01b038a168183015260ff88811660608301528716608082015284151560a0820152905185917f9b088e2c89b322a3c1d81515e1c88db3d386d022926f0e2d0b9b5813b7413d58919081900360c00190a25050505050505050565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff16610b4057604051635844c9e760e11b815260040160405180910390fd5b6009805467ffffffffffffffff90921668010000000000000000027fffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff909216919091179055565b6000610b94600019611664565b6001546040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015260009161010090046001600160a01b0316906370a0823190602401602060405180830381865afa158015610bfb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c1f9190613698565b90508060075410610c305780610c34565b6007545b91505090565b600082815260208190526040902060010154610c55816120f0565b610c5f83836120fd565b505050565b6001600160a01b0381163314610ce75760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b610cf1828261219b565b5050565b610cfd611e9a565b600082815260026020818152604092839020835160c08101855281546001600160a01b03811680835260ff600160a01b8304811695840195909552600160a81b8204851696830196909652600160b01b900490921615156060830152600181015460808301529091015460a0820152903314610da5576040517fb72bcb2f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60015460ff808416600160a81b90920416108015610dcc57508160ff16816020015160ff16105b610e02576040517fd5fd03fc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610e0a611131565b816080015111610e2d576040516368aebbc560e01b815260040160405180910390fd5b6000816020015183610e3f91906136b1565b90506000600160ff83161b610e5386611d64565b610e5d91906136ca565b9050610e67611964565b811015610e8757604051631e9acf1760e31b815260040160405180910390fd5b610e92600019611664565b826020015160ff166001901b8460ff166001901b610eb091906136ec565b60066000828254610ec19190613685565b90915550506080830151610ed990600390879061221a565b600085815260026020819052604090912080547fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff16600160a01b60ff8816021781554391015580610f28611131565b610f329190613685565b6080840181815260008781526002602052604090206001019190915551610f5d906003908790611eed565b60808301516040805160ff87168152602081019290925286917faf27998ec15e9d3809edad41aec1b5551d8412e71bd07c91611a0237ead1dc8e910160405180910390a25050505050565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff16610ff757604051635844c9e760e11b815260040160405180910390fd5b60005b81811015610c5f576000838383818110611016576110166136ff565b905060c0020180360381019061102c919061372b565b602081015160a082015160408084015160608501518551608087015193517f18c8572f0000000000000000000000000000000000000000000000000000000081526001600160a01b039096166004870152602486019490945260ff91821660448601521660648401526084830191909152151560a482015290915030906318c8572f9060c401600060405180830381600087803b1580156110cc57600080fd5b505af19250505080156110dd575060015b61111e5780516040805184815260208101929092527f7ded044f9ef68a0ffb6bdb48c80387f300787e7492659224ad140db77893950d910160405180910390a15b5080611129816137cd565b915050610ffa565b600954600090819061115490600160801b900467ffffffffffffffff16436136ec565b60095490915060009061117290839067ffffffffffffffff1661366e565b9050806005546111829190613685565b9250505090565b7f000000000000000000000000000000000000000000000000000000000000000060009081526020818152604080832033845290915290205460ff166111fb576040517f24876df800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000611205610b87565b6001546040517fa9059cbb0000000000000000000000000000000000000000000000000000000081526001600160a01b038581166004830152602482018490529293506101009091049091169063a9059cbb906044016020604051808303816000875af115801561127a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061129e91906137e6565b6112bb576040516312171d8360e31b815260040160405180910390fd5b604080516001600160a01b0384168152602081018390527ff5d8f9b1e7af440e1e7915f4693ccc004d1461a7dafd17ea7347d03decf298e1910160405180910390a150506000600755565b6000611310611e9a565b6001600160a01b0387166113375760405163d92e233d60e01b815260040160405180910390fd5b60ff84161580611356575060015460ff600160a81b9091048116908516105b8061136757508460ff168460ff1610155b1561138557604051630a0b2c3560e41b815260040160405180910390fd5b6040805133602082015290810184905260009060600160408051601f198184030181529181528151602092830120600081815260029093529120549091506001600160a01b0316156113ea576040516311ab459f60e21b815260040160405180910390fd5b6113f2611964565b87101561141257604051631e9acf1760e31b815260040160405180910390fd5b6000611424600160ff89161b8961366e565b6001546040516323b872dd60e01b81523360048201523060248201526044810183905291925061010090046001600160a01b0316906323b872dd906064016020604051808303816000875af1158015611481573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114a591906137e6565b6114c2576040516312171d8360e31b815260040160405180910390fd5b6000886114cd611131565b6114d79190613685565b9050806000036114fa5760405163334ab3f560e11b815260040160405180910390fd5b611505600019611664565b8760ff166001901b6006600082825461151e9190613685565b90915550506040805160c0810182526001600160a01b03808d16825260ff808c1660208085019182528c83168587019081528b151560608701908152608087018981524360a0890190815260008d815260029586905299909920975188549551935192511515600160b01b0260ff60b01b19938816600160a81b029390931661ffff60a81b1994909716600160a01b0274ffffffffffffffffffffffffffffffffffffffffff199096169716969096179390931716929092171783559051600183015591519101556115f260038483611eed565b60408051838152602081018390526001600160a01b038c168183015260ff8a811660608301528916608082015286151560a0820152905184917f9b088e2c89b322a3c1d81515e1c88db3d386d022926f0e2d0b9b5813b7413d58919081900360c00190a2509098975050505050505050565b60085460005b828110156118105761167a610845565b1561168f57611687611131565b600855611810565b600061169961190e565b905060006116a682611d64565b11156116bd576116b4611131565b60085550611810565b600081815260026020818152604092839020835160c08101855281546001600160a01b038116825260ff600160a01b82048116948301859052600160a81b8204811696830196909652600160b01b900490941615156060850152600180820154608086015292015460a084015260065491901b9081111561176a576040517f9b02220b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b806006600082825461177c91906136ec565b909155505060808201516117919086906136ec565b61179b908261366e565b600760008282546117ac9190613685565b909155505060808201516117c490600390859061221a565b50506000908152600260208190526040822080547fffffffffffffffffff000000000000000000000000000000000000000000000016815560018082018490559101919091550161166a565b81600854101561184c576040517f530da97a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8160085461185a91906136ec565b600654611867919061366e565b600760008282546118789190613685565b9091555050505050565b600061188c610845565b156118975750600090565b60006118a46106e761190e565b1115905090565b7f000000000000000000000000000000000000000000000000000000000000000060009081526020818152604080832033845290915290205460ff1661190457604051631d77d47760e21b815260040160405180910390fd5b61190c61256b565b565b60008061191b60036125bf565b905080600003611957576040517f46c83ec800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610c346003826000612606565b60095460009061198d9067ffffffffffffffff8082169168010000000000000000900416613803565b67ffffffffffffffff16905090565b7f000000000000000000000000000000000000000000000000000000000000000060009081526020818152604080832033845290915290205460ff16611a0e576040517fea0f601b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60095467ffffffffffffffff1615611a2c57611a28611131565b6005555b600980544367ffffffffffffffff908116600160801b027fffffffffffffffff0000000000000000ffffffffffffffff0000000000000000909216908416171790556040517fae46785019700e30375a5d7b4f91e32f8060ef085111f896ebf889450aa2ab5a90611aa09083815260200190565b60405180910390a150565b611ab3611e9a565b600082815260026020818152604092839020835160c08101855281546001600160a01b03811680835260ff600160a01b8304811695840195909552600160a81b8204851696830196909652600160b01b900490921615156060830152600181015460808301529091015460a082015290611b4057604051634ee9bc0f60e01b815260040160405180910390fd5b611b48611131565b816080015111611b6b576040516368aebbc560e01b815260040160405180910390fd5b600154602082015160ff600160a81b9092048216911611611bb8576040517f7103b80500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611bc0611964565b82611bca85611d64565b611bd49190613685565b1015611bf357604051631e9acf1760e31b815260040160405180910390fd5b6000816020015160ff166001901b83611c0c919061366e565b6001546040516323b872dd60e01b81523360048201523060248201526044810183905291925061010090046001600160a01b0316906323b872dd906064016020604051808303816000875af1158015611c69573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c8d91906137e6565b611caa576040516312171d8360e31b815260040160405180910390fd5b6080820151611cbd90600390869061221a565b828260800151611ccd9190613685565b60808301819052611ce2906003908690611eed565b60808201805160008681526002602090815260409182902060010192909255915182518481529182015285917faf5756c62d6c0722ef9be1f82bef97ab06ea5aea7f3eb8ad348422079f01d88d910160405180910390a250505050565b600082815260208190526040902060010154611d5a816120f0565b610c5f838361219b565b6000818152600260208181526040808420815160c08101835281546001600160a01b03811680835260ff600160a01b8304811696840196909652600160a81b8204861694830194909452600160b01b900490931615156060840152600181015460808401529092015460a082015290611df057604051634ee9bc0f60e01b815260040160405180910390fd5b611df8611131565b816080015111611e0b5750600092915050565b611e13611131565b8160800151611e2291906136ec565b9392505050565b7f000000000000000000000000000000000000000000000000000000000000000060009081526020818152604080832033845290915290205460ff16611e8257604051631d77d47760e21b815260040160405180910390fd5b61190c612668565b600061083f8283600001546126a1565b60015460ff161561190c5760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a20706175736564000000000000000000000000000000006044820152606401610cde565b80611f0b576040516363868c5560e11b815260040160405180910390fd5b611f168383836126cd565b15611f4d576040517f6082d5c100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b82546000905b80156120315780915080831015611f7d576000908152600180860160205260409091200154612008565b80831115611f9e576000908152600185016020526040902060020154612008565b808303612008576000818152600180870160209081526040832060040180548084018255818552918420909101879055918390529054611fde91906136ec565b60009182526001909501602090815260408083209583526005909501905292909220929092555050565b60008281526001860160205260408120600601805491612027836137cd565b9190505550611f53565b600083815260018087016020908152604083208581558083018490556002810184905560038101805460ff191684179055600481018054808501825581865292909420909101879055915461208691906136ec565b6000868152600583016020526040902055826120a4578386556120de565b828410156120c757600083815260018088016020526040909120018490556120de565b600083815260018701602052604090206002018490555b6120e88685612733565b505050505050565b6120fa813361299b565b50565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610cf1576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556121573390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1615610cf1576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b80612238576040516363868c5560e11b815260040160405180910390fd5b6122438383836126cd565b61226057604051635889b1c560e11b815260040160405180910390fd5b6000818152600180850160209081526040808420868552600581019092528320546004820180549294919391929091612298916136ec565b815481106122a8576122a86136ff565b90600052602060002001549050808360040183815481106122cb576122cb6136ff565b60009182526020808320909101929092558281526005850190915260409020829055600483018054806123005761230061382f565b6001900381819060005260206000200160009055905560008084600401805490506000036125615760008681526001808a0160205260409091200154158061235957506000868152600189016020526040902060020154155b156123655750846123ad565b5060008581526001880160205260409020600201545b60008181526001808a0160205260409091200154156123ad57600090815260018089016020526040909120015461237b565b60008181526001808a0160205260409091200154156123e15760008181526001808a016020526040909120015491506123f8565b600081815260018901602052604090206002015491505b600081815260018901602052604080822054848352912081905580156124685760008181526001808b0160205260409091200154820361244d5760008181526001808b0160205260409091200183905561246c565b600081815260018a016020526040902060020183905561246c565b8289555b600082815260018a01602052604090206003015460ff16158783146124ff576124968a848a612a0e565b600088815260018b8101602052604080832080830154878552828520938401819055845281842087905560028082015490840181905584529083208690556003908101549286905201805460ff191660ff90921615159190911790559196916124ff8a89612a87565b801561250f5761250f8a85612af4565b6125198a83612a87565b60008381526001808c01602052604082208281559081018290556002810182905560038101805460ff191690559061255460048301826133f5565b6006820160009055505050505b5050505050505050565b612573611e9a565b6001805460ff1916811790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258335b6040516001600160a01b03909116815260200160405180910390a1565b8054806125ce57506000919050565b5b6000818152600180840160205260409091200154156126015760009081526001808301602052604090912001546125cf565b919050565b60006126128484612f0d565b61262f57604051635889b1c560e11b815260040160405180910390fd5b60008381526001850160205260409020600401805483908110612654576126546136ff565b906000526020600020015490509392505050565b612670612f53565b6001805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa336125a2565b60008181526001830160205260408120600681015460048201546126c59190613685565b949350505050565b60006126d98483612f0d565b6126e557506000611e22565b60008281526001850160209081526040808320868452600581019092529091205460049091018054859290811061271e5761271e6136ff565b90600052602060002001541490509392505050565b60005b825482148015906127605750600082815260018401602052604080822054825290206003015460ff165b1561297957600082815260018085016020526040808320548084528184205484529220015481036128815760008181526001850160205260408082205482528082206002015480835291206003015490925060ff1615612808576000818152600180860160205260408083206003808201805460ff19908116909155878652838620820180548216905582548652928520018054909216909217905590829052549250612973565b6000818152600185016020526040902060020154830361282f5780925061282f8484612fa5565b50600082815260018085016020526040808320548084528184206003808201805460ff1990811690915582548752938620018054909316909317909155918290525461287c908590613122565b612973565b6000818152600180860160205260408083205483528083209091015480835291206003015490925060ff16156128ff576000818152600180860160205260408083206003808201805460ff19908116909155878652838620820180548216905582548652928520018054909216909217905590829052549250612973565b60008181526001808601602052604090912001548303612926578092506129268484613122565b50600082815260018085016020526040808320548084528184206003808201805460ff19908116909155825487529386200180549093169093179091559182905254612973908590612fa5565b50612736565b505080546000908152600190910160205260409020600301805460ff19169055565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610cf1576129cc81613202565b6129d7836020613214565b6040516020016129e8929190613869565b60408051601f198184030181529082905262461bcd60e51b8252610cde916004016138ea565b600081815260018401602052604080822054848352912081905580612a3557828455612a81565b60008181526001808601602052604090912001548203612a6a5760008181526001808601602052604090912001839055612a81565b600081815260018501602052604090206002018390555b50505050565b8015610cf1576000818152600183016020526040902060020154612aac9083906126a1565b6000828152600180850160205260409091200154612acb9084906126a1565b612ad59190613685565b6000918252600183016020526040909120600681019190915554612a87565b60005b82548214801590612b1c5750600082815260018401602052604090206003015460ff16155b15612eee5760008281526001808501602052604080832054808452922001548303612d175760008181526001850160205260408082206002015480835291206003015490925060ff1615612bbf576000828152600180860160205260408083206003908101805460ff19908116909155858552919093209092018054909216179055612ba88482612fa5565b600081815260018501602052604090206002015491505b60008281526001808601602052604080832090910154825290206003015460ff16158015612c0a5750600082815260018501602052604080822060020154825290206003015460ff16155b15612c3757600082815260018581016020526040909120600301805460ff19169091179055915081612ee8565b600082815260018501602052604080822060020154825290206003015460ff16612cb4576000828152600180860160205260408083208083015484529083206003908101805460ff1990811690915593869052018054909216179055612c9d8483613122565b600081815260018501602052604090206002015491505b600081815260018501602052604080822060039081018054868552838520808401805460ff909316151560ff199384161790558254821690925560029091015484529190922090910180549091169055612d0e8482612fa5565b83549250612ee8565b6000818152600180860160205260408083209091015480835291206003015490925060ff1615612d96576000828152600180860160205260408083206003908101805460ff19908116909155858552919093209092018054909216179055612d7f8482613122565b600081815260018086016020526040909120015491505b600082815260018501602052604080822060020154825290206003015460ff16158015612de1575060008281526001808601602052604080832090910154825290206003015460ff16155b15612e0e57600082815260018581016020526040909120600301805460ff19169091179055915081612ee8565b60008281526001808601602052604080832090910154825290206003015460ff16612e8d57600082815260018086016020526040808320600281015484529083206003908101805460ff1990811690915593869052018054909216179055612e768483612fa5565b600081815260018086016020526040909120015491505b60008181526001808601602052604080832060039081018054878652838620808401805460ff909316151560ff19938416179055825482169092559301548452922090910180549091169055612ee38482613122565b835492505b50612af7565b506000908152600190910160205260409020600301805460ff19169055565b600081612f1c5750600061083f565b82548203612f2c5750600161083f565b600082815260018401602052604090205415612f4a5750600161083f565b50600092915050565b60015460ff1661190c5760405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f74207061757365640000000000000000000000006044820152606401610cde565b600081815260018084016020526040808320600281018054915482865292852090930154938590529183905590918015612fed57600081815260018601602052604090208490555b600083815260018601602052604090208290558161300d57828555613059565b600082815260018087016020526040909120015484036130425760008281526001808701602052604090912001839055613059565b600082815260018601602052604090206002018390555b6000838152600180870160205260408083209091018690558582529020838155600201546130889086906126a1565b60008581526001808801602052604090912001546130a79087906126a1565b6130b19190613685565b60008581526001870160205260408082206006019290925584815220600201546130dc9086906126a1565b60008481526001808801602052604090912001546130fb9087906126a1565b6131059190613685565b600093845260019095016020525050604090206006019190915550565b6000818152600180840160205260408083209182018054925483855291842060020154938590528390559091801561316857600081815260018601602052604090208490555b6000838152600186016020526040902082905581613188578285556131d4565b600082815260018601602052604090206002015484036131bd57600082815260018601602052604090206002018390556131d4565b600082815260018087016020526040909120018390555b60008381526001860160205260408082206002908101879055868352912084815501546130889086906126a1565b606061083f6001600160a01b03831660145b6060600061322383600261366e565b61322e906002613685565b67ffffffffffffffff81111561324657613246613715565b6040519080825280601f01601f191660200182016040528015613270576020820181803683370190505b5090507f3000000000000000000000000000000000000000000000000000000000000000816000815181106132a7576132a76136ff565b60200101906001600160f81b031916908160001a9053507f7800000000000000000000000000000000000000000000000000000000000000816001815181106132f2576132f26136ff565b60200101906001600160f81b031916908160001a905350600061331684600261366e565b613321906001613685565b90505b60018111156133a6577f303132333435363738396162636465660000000000000000000000000000000085600f1660108110613362576133626136ff565b1a60f81b828281518110613378576133786136ff565b60200101906001600160f81b031916908160001a90535060049490941c9361339f8161391d565b9050613324565b508315611e225760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610cde565b50805460008255906000526020600020908101906120fa91905b80821115613423576000815560010161340f565b5090565b60006020828403121561343957600080fd5b81357fffffffff0000000000000000000000000000000000000000000000000000000081168114611e2257600080fd5b80356001600160a01b038116811461260157600080fd5b803560ff8116811461260157600080fd5b80151581146120fa57600080fd5b803561260181613491565b60008060008060008060c087890312156134c357600080fd5b6134cc87613469565b9550602087013594506134e160408801613480565b93506134ef60608801613480565b92506080870135915060a087013561350681613491565b809150509295509295509295565b60006020828403121561352657600080fd5b813567ffffffffffffffff81168114611e2257600080fd5b60006020828403121561355057600080fd5b5035919050565b6000806040838503121561356a57600080fd5b8235915061357a60208401613469565b90509250929050565b6000806040838503121561359657600080fd5b8235915061357a60208401613480565b600080602083850312156135b957600080fd5b823567ffffffffffffffff808211156135d157600080fd5b818501915085601f8301126135e557600080fd5b8135818111156135f457600080fd5b86602060c08302850101111561360957600080fd5b60209290920196919550909350505050565b60006020828403121561362d57600080fd5b611e2282613469565b6000806040838503121561364957600080fd5b50508035926020909101359150565b634e487b7160e01b600052601160045260246000fd5b808202811582820484141761083f5761083f613658565b8082018082111561083f5761083f613658565b6000602082840312156136aa57600080fd5b5051919050565b60ff828116828216039081111561083f5761083f613658565b6000826136e757634e487b7160e01b600052601260045260246000fd5b500490565b8181038181111561083f5761083f613658565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b600060c0828403121561373d57600080fd5b60405160c0810181811067ffffffffffffffff8211171561376e57634e487b7160e01b600052604160045260246000fd5b6040528235815261378160208401613469565b602082015261379260408401613480565b60408201526137a360608401613480565b60608201526137b46080840161349f565b608082015260a083013560a08201528091505092915050565b6000600182016137df576137df613658565b5060010190565b6000602082840312156137f857600080fd5b8151611e2281613491565b67ffffffffffffffff81811683821602808216919082811461382757613827613658565b505092915050565b634e487b7160e01b600052603160045260246000fd5b60005b83811015613860578181015183820152602001613848565b50506000910152565b7f416363657373436f6e74726f6c3a206163636f756e74200000000000000000008152600083516138a1816017850160208801613845565b7f206973206d697373696e6720726f6c652000000000000000000000000000000060179184019182015283516138de816028840160208801613845565b01602801949350505050565b6020815260008251806020840152613909816040850160208701613845565b601f01601f19169190910160400192915050565b60008161392c5761392c613658565b50600019019056fea2646970667358221220b8e989571a98a41404ede9329461cf1ff50f79df9ca172c5ded6755573d871c364736f6c63430008130033", "address": "0xcdfdC3752caaA826fE62531E0000C40546eC56A6", "block": 6596277, - "url": "https://sepolia.etherscan.io/address/0xcdfdC3752caaA826fE62531E0000C40546eC56A6" + "url": "https://sepolia.etherscan.io/0xcdfdC3752caaA826fE62531E0000C40546eC56A6" }, "priceOracle": { "abi": [ @@ -2611,6 +2646,19 @@ "name": "RoleRevoked", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "attemptedPrice", + "type": "uint256" + } + ], + "name": "StampPriceUpdateFailed", + "type": "event" + }, { "inputs": [], "name": "DEFAULT_ADMIN_ROLE", @@ -2646,7 +2694,13 @@ } ], "name": "adjustPrice", - "outputs": [], + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], "stateMutability": "nonpayable", "type": "function" }, @@ -2899,7 +2953,13 @@ } ], "name": "setPrice", - "outputs": [], + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], "stateMutability": "nonpayable", "type": "function" }, @@ -2930,10 +2990,10 @@ "type": "function" } ], - "bytecode": "0x600180546201000160a21b64ffffffffff60a01b1990911617905560028054600160401b600160c01b0319811663ffffffff68010000000000000000600160401b600160801b03199093166e0800000177000000000000000000009081179390930416600160801b02171790556101c06040526208002460a09081526208001b60c0526208001260e052620800096101005262080000610120526207fff7610140526207ffee610160526207ffe5610180526207ffdc6101a052620000c99060039060096200023b565b50348015620000d757600080fd5b506040516200163438038062001634833981016040819052620000fa91620002f4565b6200010760003362000177565b600180546001600160a01b0319166001600160a01b0383161790556200012c62000187565b600280546001600160401b0319166001600160401b0392909216919091179055507fd96ba01d6560c2ab35f2940dd8d70c5f5fe06236c72674237120515918198fb060805262000349565b6200018382826200019b565b5050565b60006200019660984362000326565b905090565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1662000183576000828152602081815260408083206001600160a01b03851684529091529020805460ff19166001179055620001f73390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b600283019183908215620002cb5791602002820160005b838211156200029757835183826101000a81548163ffffffff021916908362ffffff160217905550926020019260040160208160030104928301926001030262000252565b8015620002c95782816101000a81549063ffffffff021916905560040160208160030104928301926001030262000297565b505b50620002d9929150620002dd565b5090565b5b80821115620002d95760008155600101620002de565b6000602082840312156200030757600080fd5b81516001600160a01b03811681146200031f57600080fd5b9392505050565b6000826200034457634e487b7160e01b600052601260045260246000fd5b500490565b6080516112c86200036c600039600081816103ac015261080d01526112c86000f3fe608060405234801561001057600080fd5b50600436106101825760003560e01c806391d14854116100d8578063daafe0a51161008c578063f7b188a511610066578063f7b188a51461039f578063fb8d8101146103a7578063ffb98fe3146103ce57600080fd5b8063daafe0a514610346578063dcd8ffb814610359578063e0632c641461037457600080fd5b8063a217fddf116100bd578063a217fddf14610317578063b187bd261461031f578063d547741f1461033357600080fd5b806391d14854146102c55780639d1b464a146102fc57600080fd5b80637310561b1161013a5780637f386b6c116101145780637f386b6c146102995780638456cb59146102b55780638a19c8bc146102bd57600080fd5b80637310561b1461023557806374e7493b1461026a5780637e8effdd1461027d57600080fd5b80632f2ff15d1161016b5780632f2ff15d146101e057806336568abe146101f557806355bdcd231461020857600080fd5b806301ffc9a714610187578063248a9ca3146101af575b600080fd5b61019a610195366004610f6f565b6103e1565b60405190151581526020015b60405180910390f35b6101d26101bd366004610fb1565b60009081526020819052604090206001015490565b6040519081526020016101a6565b6101f36101ee366004610fca565b61047a565b005b6101f3610203366004610fca565b6104a4565b60025461021c9067ffffffffffffffff1681565b60405167ffffffffffffffff90911681526020016101a6565b600254610255906c01000000000000000000000000900463ffffffff1681565b60405163ffffffff90911681526020016101a6565b610255610278366004610fb1565b610535565b6002546102559068010000000000000000900463ffffffff1681565b600254680100000000000000009004600a1c623fffff16610255565b6101f3610565565b61021c6105c9565b61019a6102d3366004610fca565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b600254600160801b9004600a1c663fffffffffffff16610255565b6101d2600081565b60015461019a90600160c01b900460ff1681565b6101f3610341366004610fca565b6105db565b6101f3610354366004611006565b610600565b60025461021c90600160801b900467ffffffffffffffff1681565b600154610387906001600160a01b031681565b6040516001600160a01b0390911681526020016101a6565b6101f3610797565b6101d27f000000000000000000000000000000000000000000000000000000000000000081565b6101f36103dc36600461102c565b6107f5565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f7965db0b00000000000000000000000000000000000000000000000000000000148061047457507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008316145b92915050565b60008281526020819052604090206001015461049581610bdb565b61049f8383610be5565b505050565b6001600160a01b03811633146105275760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b6105318282610c83565b5050565b6003816009811061054557600080fd5b60089182820401919006600402915054906101000a900463ffffffff1681565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff166105b45760405163036c8cf960e11b815260040160405180910390fd5b6001805460ff60c01b1916600160c01b179055565b60006105d660984361107c565b905090565b6000828152602081905260409020600101546105f681610bdb565b61049f8383610c83565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff1661064f5760405163036c8cf960e11b815260040160405180910390fd5b60025463fffffc00600a83901b169068010000000000000000900463ffffffff168082101561067c578091505b6002805467ffffffffffffffff8416600160801b027fffffffffffffffff0000000000000000ffffffffffffffffffffffffffffffff9091161790556001546001600160a01b03166391b7f5ed6106e6600254663fffffffffffff600160801b909104600a1c1690565b63ffffffff166040518263ffffffff1660e01b815260040161070a91815260200190565b600060405180830381600087803b15801561072457600080fd5b505af1158015610738573d6000803e3d6000fd5b505050507fae46785019700e30375a5d7b4f91e32f8060ef085111f896ebf889450aa2ab5a61077a600254663fffffffffffff600160801b909104600a1c1690565b60405163ffffffff909116815260200160405180910390a1505050565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff166107e65760405163036c8cf960e11b815260040160405180910390fd5b6001805460ff60c01b19169055565b600154600160c01b900460ff161515600003610bd8577f000000000000000000000000000000000000000000000000000000000000000060009081526020818152604080832033845290915290205460ff1661087d576040517f262791ec00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8060006108886105c9565b60025490915067ffffffffffffffff908116908216116108d4576040517f08a5cb4c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8261ffff16600003610912576040517fb5ca2d7100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60015460009061095a9061ffff760100000000000000000000000000000000000000000000820481169174010000000000000000000000000000000000000000900416611090565b90508061ffff168461ffff161115610970578092505b60025467ffffffffffffffff600160801b820481169163ffffffff6801000000000000000082048116926c010000000000000000000000008304909116916000916001916109bf9116886110b2565b6109c991906110b2565b9050600060038861ffff16600981106109e4576109e46110d3565b60088104919091015460079091166004026101000a900463ffffffff90811691508316610a1186836110e9565b610a1b9190611115565b945067ffffffffffffffff821615610a8f575060035463ffffffff1660005b8267ffffffffffffffff168167ffffffffffffffff161015610a8d578363ffffffff16868363ffffffff16610a6f91906110e9565b610a799190611115565b955080610a858161113c565b915050610a3a565b505b8367ffffffffffffffff168567ffffffffffffffff161015610aaf578394505b600280547fffffffffffffffff0000000000000000ffffffffffffffff000000000000000016600160801b67ffffffffffffffff888116820267ffffffffffffffff191692909217918a1691909117918290556001546001600160a01b0316916391b7f5ed919004600a1c663fffffffffffff1663ffffffff166040518263ffffffff1660e01b8152600401610b4791815260200190565b600060405180830381600087803b158015610b6157600080fd5b505af1158015610b75573d6000803e3d6000fd5b505050507fae46785019700e30375a5d7b4f91e32f8060ef085111f896ebf889450aa2ab5a610bb7600254663fffffffffffff600160801b909104600a1c1690565b60405163ffffffff909116815260200160405180910390a150505050505050505b50565b610bd88133610d02565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610531576000828152602081815260408083206001600160a01b03851684529091529020805460ff19166001179055610c3f3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1615610531576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1661053157610d3381610d75565b610d3e836020610d87565b604051602001610d4f929190611187565b60408051601f198184030181529082905262461bcd60e51b825261051e91600401611208565b60606104746001600160a01b03831660145b60606000610d9683600261123b565b610da1906002611252565b67ffffffffffffffff811115610db957610db9611265565b6040519080825280601f01601f191660200182016040528015610de3576020820181803683370190505b5090507f300000000000000000000000000000000000000000000000000000000000000081600081518110610e1a57610e1a6110d3565b60200101906001600160f81b031916908160001a9053507f780000000000000000000000000000000000000000000000000000000000000081600181518110610e6557610e656110d3565b60200101906001600160f81b031916908160001a9053506000610e8984600261123b565b610e94906001611252565b90505b6001811115610f19577f303132333435363738396162636465660000000000000000000000000000000085600f1660108110610ed557610ed56110d3565b1a60f81b828281518110610eeb57610eeb6110d3565b60200101906001600160f81b031916908160001a90535060049490941c93610f128161127b565b9050610e97565b508315610f685760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e74604482015260640161051e565b9392505050565b600060208284031215610f8157600080fd5b81357fffffffff0000000000000000000000000000000000000000000000000000000081168114610f6857600080fd5b600060208284031215610fc357600080fd5b5035919050565b60008060408385031215610fdd57600080fd5b8235915060208301356001600160a01b0381168114610ffb57600080fd5b809150509250929050565b60006020828403121561101857600080fd5b813563ffffffff81168114610f6857600080fd5b60006020828403121561103e57600080fd5b813561ffff81168114610f6857600080fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b60008261108b5761108b611050565b500490565b61ffff8181168382160190808211156110ab576110ab611066565b5092915050565b67ffffffffffffffff8281168282160390808211156110ab576110ab611066565b634e487b7160e01b600052603260045260246000fd5b67ffffffffffffffff81811683821602808216919082811461110d5761110d611066565b505092915050565b600067ffffffffffffffff8084168061113057611130611050565b92169190910492915050565b600067ffffffffffffffff80831681810361115957611159611066565b6001019392505050565b60005b8381101561117e578181015183820152602001611166565b50506000910152565b7f416363657373436f6e74726f6c3a206163636f756e74200000000000000000008152600083516111bf816017850160208801611163565b7f206973206d697373696e6720726f6c652000000000000000000000000000000060179184019182015283516111fc816028840160208801611163565b01602801949350505050565b6020815260008251806020840152611227816040850160208701611163565b601f01601f19169190910160400192915050565b808202811582820484141761047457610474611066565b8082018082111561047457610474611066565b634e487b7160e01b600052604160045260246000fd5b60008161128a5761128a611066565b50600019019056fea2646970667358221220ae138e65b6afda072afc2642ba44cd4f0dba23acc91686a94131453ad482fce464736f6c63430008130033", - "address": "0xf19F9d88e963A61c735C1716F8A689Dc2887F463", - "block": 6596284, - "url": "https://sepolia.etherscan.io/address/0xf19F9d88e963A61c735C1716F8A689Dc2887F463" + "bytecode": "0x600180546201000160a21b64ffffffffff60a01b1990911617905560028054600160401b600160c01b0319811663ffffffff68010000000000000000600160401b600160801b03199093166e1000000177000000000000000000009081179390930416600160801b02171790556101c06040526210034960a09081526210027660c052621001a460e052621000d2610100526210000061012052620fff2e61014052620ffe5c61016052620ffd8a61018052620ffcb86101a052620000c990600390600962000291565b50348015620000d757600080fd5b506040516200181938038062001819833981016040819052620000fa916200034a565b62000107600033620001cd565b600180546001600160a01b0319166001600160a01b0383161790556200012c620001dd565b600280546001600160401b0319166001600160401b03929092169190911790557fd96ba01d6560c2ab35f2940dd8d70c5f5fe06236c72674237120515918198fb06080527fae46785019700e30375a5d7b4f91e32f8060ef085111f896ebf889450aa2ab5a620001ae600254600160801b9004600a1c663fffffffffffff1690565b60405163ffffffff909116815260200160405180910390a1506200039f565b620001d98282620001f1565b5050565b6000620001ec6098436200037c565b905090565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16620001d9576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556200024d3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b600283019183908215620003215791602002820160005b83821115620002ed57835183826101000a81548163ffffffff021916908362ffffff1602179055509260200192600401602081600301049283019260010302620002a8565b80156200031f5782816101000a81549063ffffffff0219169055600401602081600301049283019260010302620002ed565b505b506200032f92915062000333565b5090565b5b808211156200032f576000815560010162000334565b6000602082840312156200035d57600080fd5b81516001600160a01b03811681146200037557600080fd5b9392505050565b6000826200039a57634e487b7160e01b600052601260045260246000fd5b500490565b608051611457620003c2600039600081816103ac01526108bf01526114576000f3fe608060405234801561001057600080fd5b50600436106101825760003560e01c806391d14854116100d8578063daafe0a51161008c578063f7b188a511610066578063f7b188a51461039f578063fb8d8101146103a7578063ffb98fe3146103ce57600080fd5b8063daafe0a514610346578063dcd8ffb814610359578063e0632c641461037457600080fd5b8063a217fddf116100bd578063a217fddf14610317578063b187bd261461031f578063d547741f1461033357600080fd5b806391d14854146102c55780639d1b464a146102fc57600080fd5b80637310561b1161013a5780637f386b6c116101145780637f386b6c146102995780638456cb59146102b55780638a19c8bc146102bd57600080fd5b80637310561b1461023557806374e7493b1461026a5780637e8effdd1461027d57600080fd5b80632f2ff15d1161016b5780632f2ff15d146101e057806336568abe146101f557806355bdcd231461020857600080fd5b806301ffc9a714610187578063248a9ca3146101af575b600080fd5b61019a6101953660046110e2565b6103e1565b60405190151581526020015b60405180910390f35b6101d26101bd366004611124565b60009081526020819052604090206001015490565b6040519081526020016101a6565b6101f36101ee36600461113d565b61047a565b005b6101f361020336600461113d565b6104a4565b60025461021c9067ffffffffffffffff1681565b60405167ffffffffffffffff90911681526020016101a6565b600254610255906c01000000000000000000000000900463ffffffff1681565b60405163ffffffff90911681526020016101a6565b610255610278366004611124565b610535565b6002546102559068010000000000000000900463ffffffff1681565b600254680100000000000000009004600a1c623fffff16610255565b6101f3610565565b61021c6105c9565b61019a6102d336600461113d565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b600254600160801b9004600a1c663fffffffffffff16610255565b6101d2600081565b60015461019a90600160c01b900460ff1681565b6101f361034136600461113d565b6105db565b61019a610354366004611179565b610600565b60025461021c90600160801b900467ffffffffffffffff1681565b600154610387906001600160a01b031681565b6040516001600160a01b0390911681526020016101a6565b6101f3610847565b6101d27f000000000000000000000000000000000000000000000000000000000000000081565b61019a6103dc36600461119f565b6108a5565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f7965db0b00000000000000000000000000000000000000000000000000000000148061047457507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008316145b92915050565b60008281526020819052604090206001015461049581610d4b565b61049f8383610d58565b505050565b6001600160a01b03811633146105275760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b6105318282610df6565b5050565b6003816009811061054557600080fd5b60089182820401919006600402915054906101000a900463ffffffff1681565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff166105b45760405163036c8cf960e11b815260040160405180910390fd5b6001805460ff60c01b1916600160c01b179055565b60006105d66098436111ef565b905090565b6000828152602081905260409020600101546105f681610d4b565b61049f8383610df6565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604081205460ff1661064f5760405163036c8cf960e11b815260040160405180910390fd5b60025463fffffc00600a84901b169068010000000000000000900463ffffffff168082101561067c578091505b6002805467ffffffffffffffff8416600160801b027fffffffffffffffff0000000000000000ffffffffffffffffffffffffffffffff9091161790556001546000906001600160a01b03166106e4600254663fffffffffffff600160801b909104600a1c1690565b63ffffffff166040516024016106fc91815260200190565b60408051601f198184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff166391b7f5ed60e01b179052516107469190611227565b6000604051808303816000865af19150503d8060008114610783576040519150601f19603f3d011682016040523d82523d6000602084013e610788565b606091505b50509050806107ec576002547fd2821f4adadf1d64076091cc92984c0f001a300541dd58cff8e8e29d6290c33d90600160801b9004600a1c663fffffffffffff1660405163ffffffff909116815260200160405180910390a1506000949350505050565b6002547fae46785019700e30375a5d7b4f91e32f8060ef085111f896ebf889450aa2ab5a90600160801b9004600a1c663fffffffffffff1660405163ffffffff909116815260200160405180910390a1506001949350505050565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff166108965760405163036c8cf960e11b815260040160405180910390fd5b6001805460ff60c01b19169055565b600154600090600160c01b900460ff1615158103610d43577f000000000000000000000000000000000000000000000000000000000000000060009081526020818152604080832033845290915290205460ff1661092f576040517f262791ec00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b81600061093a6105c9565b60025490915067ffffffffffffffff90811690821611610986576040517f08a5cb4c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8361ffff166000036109c4576040517fb5ca2d7100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600154600090610a0c9061ffff760100000000000000000000000000000000000000000000820481169174010000000000000000000000000000000000000000900416611243565b90508061ffff168561ffff161115610a22578092505b60025467ffffffffffffffff600160801b820481169163ffffffff6801000000000000000082048116926c01000000000000000000000000830490911691600091600191610a71911688611265565b610a7b9190611265565b9050600060038861ffff1660098110610a9657610a96611286565b60088104919091015460079091166004026101000a900463ffffffff90811691508316610ac3868361129c565b610acd91906112c8565b945067ffffffffffffffff821615610b41575060035463ffffffff1660005b8267ffffffffffffffff168167ffffffffffffffff161015610b3f578363ffffffff16868363ffffffff16610b21919061129c565b610b2b91906112c8565b955080610b37816112ef565b915050610aec565b505b8367ffffffffffffffff168567ffffffffffffffff161015610b61578394505b600280547fffffffffffffffff0000000000000000ffffffffffffffff000000000000000016600160801b67ffffffffffffffff888116820267ffffffffffffffff191692909217918a1691909117918290556001546000926001600160a01b03909116919004600a1c663fffffffffffff1663ffffffff16604051602401610bec91815260200190565b60408051601f198184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff166391b7f5ed60e01b17905251610c369190611227565b6000604051808303816000865af19150503d8060008114610c73576040519150601f19603f3d011682016040523d82523d6000602084013e610c78565b606091505b5050905080610ce2576002547fd2821f4adadf1d64076091cc92984c0f001a300541dd58cff8e8e29d6290c33d90600160801b9004600a1c663fffffffffffff1660405163ffffffff909116815260200160405180910390a15060009a9950505050505050505050565b6002547fae46785019700e30375a5d7b4f91e32f8060ef085111f896ebf889450aa2ab5a90600160801b9004600a1c663fffffffffffff1660405163ffffffff909116815260200160405180910390a15060019a9950505050505050505050565b506000919050565b610d558133610e75565b50565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610531576000828152602081815260408083206001600160a01b03851684529091529020805460ff19166001179055610db23390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1615610531576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1661053157610ea681610ee8565b610eb1836020610efa565b604051602001610ec2929190611316565b60408051601f198184030181529082905262461bcd60e51b825261051e91600401611397565b60606104746001600160a01b03831660145b60606000610f098360026113ca565b610f149060026113e1565b67ffffffffffffffff811115610f2c57610f2c6113f4565b6040519080825280601f01601f191660200182016040528015610f56576020820181803683370190505b5090507f300000000000000000000000000000000000000000000000000000000000000081600081518110610f8d57610f8d611286565b60200101906001600160f81b031916908160001a9053507f780000000000000000000000000000000000000000000000000000000000000081600181518110610fd857610fd8611286565b60200101906001600160f81b031916908160001a9053506000610ffc8460026113ca565b6110079060016113e1565b90505b600181111561108c577f303132333435363738396162636465660000000000000000000000000000000085600f166010811061104857611048611286565b1a60f81b82828151811061105e5761105e611286565b60200101906001600160f81b031916908160001a90535060049490941c936110858161140a565b905061100a565b5083156110db5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e74604482015260640161051e565b9392505050565b6000602082840312156110f457600080fd5b81357fffffffff00000000000000000000000000000000000000000000000000000000811681146110db57600080fd5b60006020828403121561113657600080fd5b5035919050565b6000806040838503121561115057600080fd5b8235915060208301356001600160a01b038116811461116e57600080fd5b809150509250929050565b60006020828403121561118b57600080fd5b813563ffffffff811681146110db57600080fd5b6000602082840312156111b157600080fd5b813561ffff811681146110db57600080fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b6000826111fe576111fe6111c3565b500490565b60005b8381101561121e578181015183820152602001611206565b50506000910152565b60008251611239818460208701611203565b9190910192915050565b61ffff81811683821601908082111561125e5761125e6111d9565b5092915050565b67ffffffffffffffff82811682821603908082111561125e5761125e6111d9565b634e487b7160e01b600052603260045260246000fd5b67ffffffffffffffff8181168382160280821691908281146112c0576112c06111d9565b505092915050565b600067ffffffffffffffff808416806112e3576112e36111c3565b92169190910492915050565b600067ffffffffffffffff80831681810361130c5761130c6111d9565b6001019392505050565b7f416363657373436f6e74726f6c3a206163636f756e742000000000000000000081526000835161134e816017850160208801611203565b7f206973206d697373696e6720726f6c6520000000000000000000000000000000601791840191820152835161138b816028840160208801611203565b01602801949350505050565b60208152600082518060208401526113b6816040850160208701611203565b601f01601f19169190910160400192915050565b8082028115828204841417610474576104746111d9565b80820180821115610474576104746111d9565b634e487b7160e01b600052604160045260246000fd5b600081611419576114196111d9565b50600019019056fea2646970667358221220d9f2bae3059a195fbe106eecfa17d7818ae58f76c3efa4ab6bd7920ebaaf271664736f6c63430008130033", + "address": "0xC5241172f010AB24ff3eeC61B4c684E1A9482D2b", + "block": 7036312, + "url": "https://sepolia.etherscan.io/0xC5241172f010AB24ff3eeC61B4c684E1A9482D2b" }, "redistribution": { "abi": [ @@ -3215,6 +3275,12 @@ "internalType": "bytes32", "name": "overlay", "type": "bytes32" + }, + { + "indexed": false, + "internalType": "uint8", + "name": "height", + "type": "uint8" } ], "name": "Committed", @@ -3278,6 +3344,19 @@ "name": "Paused", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint16", + "name": "redundancyCount", + "type": "uint16" + } + ], + "name": "PriceAdjustmentSkipped", + "type": "event" + }, { "anonymous": false, "inputs": [ @@ -3473,6 +3552,19 @@ "name": "WinnerSelected", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "owner", + "type": "address" + } + ], + "name": "WithdrawFailed", + "type": "event" + }, { "anonymous": false, "inputs": [ @@ -3894,6 +3986,11 @@ "name": "revealed", "type": "bool" }, + { + "internalType": "uint8", + "name": "height", + "type": "uint8" + }, { "internalType": "uint256", "name": "stake", @@ -4466,10 +4563,10 @@ "type": "function" } ], - "bytecode": "0x60806040526008805462ffffff60c01b19166264020160c01b1790557dba1914b54e0348a1028d1a103a95ed55c4004b9d332400000000000000006009553480156200004a57600080fd5b5060405162004b0538038062004b058339810160408190526200006d916200019d565b60018054600380546001600160a01b03199081166001600160a01b03888116919091179092556001600160a81b0319909216610100868316021790925560028054909116918316919091179055620000c7600033620000d0565b505050620001e7565b620000dc8282620000e0565b5050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16620000dc576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556200013c3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b80516001600160a01b03811681146200019857600080fd5b919050565b600080600060608486031215620001b357600080fd5b620001be8462000180565b9250620001ce6020850162000180565b9150620001de6040850162000180565b90509250925092565b61490e80620001f76000396000f3fe608060405234801561001057600080fd5b50600436106102775760003560e01c806377c75d1011610160578063b6cd5822116100d8578063dfbf53ae1161008c578063f69ee1d111610071578063f69ee1d1146105d5578063f7b188a5146105e8578063fb00f2f3146105f057600080fd5b8063dfbf53ae14610592578063f4e6fcca146105c257600080fd5b8063ce987745116100bd578063ce98774514610564578063d1e8b63d14610577578063d547741f1461057f57600080fd5b8063b6cd582214610537578063c46b40291461054a57600080fd5b80638456cb591161012f5780638d8b6428116101145780638d8b6428146104f057806391d14854146104f8578063a217fddf1461052f57600080fd5b80638456cb59146104e05780638a19c8bc146104e857600080fd5b806377c75d101461045a5780637fe019c61461046d57806382b39b1b1461048857806383220626146104d857600080fd5b80635c975abb116101f357806364c34a85116101c257806369da9114116101a757806369da9114146103de5780636f94aaf2146103f157806372286cba1461040c57600080fd5b806364c34a85146103a957806369bfac01146103b157600080fd5b80635c975abb146103705780635d4844ea1461037b57806362fd29ae1461038e57806363f5cf7c1461039657600080fd5b80632a4e62491161024a5780632f3906da1161022f5780632f3906da1461034257806336568abe1461034a5780635838d6731461035d57600080fd5b80632a4e6249146103185780632f2ff15d1461032d57600080fd5b806301ffc9a71461027c5780631736d472146102a457806318350096146102b7578063248a9ca3146102e7575b600080fd5b61028f61028a36600461405f565b610603565b60405190151581526020015b60405180910390f35b61028f6102b23660046140ad565b61066c565b6001546102cf9061010090046001600160a01b031681565b6040516001600160a01b03909116815260200161029b565b61030a6102f53660046140e6565b60009081526020819052604090206001015490565b60405190815260200161029b565b6103206107fa565b60405161029b91906140ff565b61034061033b36600461418e565b610907565b005b61028f610931565b61034061035836600461418e565b61097b565b61034061036b3660046141d0565b610a0c565b60015460ff1661028f565b6003546102cf906001600160a01b031681565b61030a610f54565b6103406103a4366004614215565b611020565b61030a6113bb565b6008546103c59067ffffffffffffffff1681565b60405167ffffffffffffffff909116815260200161029b565b6002546102cf906001600160a01b031681565b6008546103c590600160801b900467ffffffffffffffff1681565b61041f61041a3660046140e6565b61149b565b604080519687526001600160a01b039095166020870152921515938501939093526060840152608083019190915260a082015260c00161029b565b61028f6104683660046140e6565b6114f2565b6008546103c590600160401b900467ffffffffffffffff1681565b61049b6104963660046140e6565b6117a2565b604080519687526001600160a01b03909516602087015260ff909316938501939093526060840152608083019190915260a082015260c00161029b565b61030a6117b2565b6103406117bd565b6103c5611816565b61028f611823565b61028f61050636600461418e565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b61030a600081565b61034061054536600461429d565b61184d565b610552611d8a565b60405160ff909116815260200161029b565b61030a6105723660046142d2565b611e0f565b61028f611e7d565b61034061058d36600461418e565b611ea2565b600a54600b54600c54600d54600e5461049b94936001600160a01b03811693600160a01b90910460ff1692909186565b6103406105d036600461430f565b611ec7565b6103406105e33660046140e6565b611fae565b610340612002565b61028f6105fe36600461435a565b612059565b60006001600160e01b031982167f7965db0b00000000000000000000000000000000000000000000000000000000148061066657507f01ffc9a7000000000000000000000000000000000000000000000000000000006001600160e01b03198316145b92915050565b60035460405163d1052d1f60e01b81526001600160a01b038481166004830152600092839291169063d1052d1f90602401602060405180830381865afa1580156106ba573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106de9190614388565b90506106e8610931565b1561071f576040517fe2586bcc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8060000361073f576040516273e5c360e31b815260040160405180910390fd5b61074b609860026143b7565b61075590436143ce565b811061077457604051630a0744c560e01b815260040160405180910390fd5b6003546040516397adedb560e01b81526001600160a01b0386811660048301526107f29216906397adedb590602401602060405180830381865afa1580156107c0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107e49190614388565b6107ec6113bb565b85612059565b949350505050565b6060610804611823565b61082157604051633788c6c160e11b815260040160405180910390fd5b600061082b611816565b60085490915067ffffffffffffffff808316600160401b909204161461086457604051636fbabc7760e01b815260040160405180910390fd5b6005805480602002602001604051908101604052809291908181526020016000905b828210156108fd5760008481526020908190206040805160c08101825260058602909201805483526001808201546001600160a01b03811685870152600160a01b900460ff169284019290925260028101546060840152600381015460808401526004015460a08301529083529092019101610886565b5050505091505090565b60008281526020819052604090206001015461092281612096565b61092c83836120a3565b505050565b60008061093f6098436143f7565b905061094d6004609861440b565b811015801561096657506109636002609861440b565b81105b1561097357600191505090565b600091505090565b6001600160a01b03811633146109fe5760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b610a088282612141565b5050565b610a146121c0565b6000610a1e611816565b6003546040516397adedb560e01b81523360048201529192506000916001600160a01b03909116906397adedb590602401602060405180830381865afa158015610a6c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a909190614388565b6003546040517f830a053e0000000000000000000000000000000000000000000000000000000081523360048201529192506000916001600160a01b039091169063830a053e90602401602060405180830381865afa158015610af7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b1b9190614388565b60035460405163d1052d1f60e01b81523360048201529192506000916001600160a01b039091169063d1052d1f90602401602060405180830381865afa158015610b69573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b8d9190614388565b9050610b97611e7d565b610bcd576040517fdc816a8700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001610bdb6004609861440b565b610be591906143ce565b610bf06098436143f7565b03610c27576040517f5baef6b600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8467ffffffffffffffff168467ffffffffffffffff161115610c75576040517f50ff7c0000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8467ffffffffffffffff168467ffffffffffffffff161015610cc3576040517f7a0c0fd600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b80600003610ce3576040516273e5c360e31b815260040160405180910390fd5b610cef609860026143b7565b610cf990436143ce565b8110610d1857604051630a0744c560e01b815260040160405180910390fd5b60085467ffffffffffffffff858116911614610d5857610d3a60046000613ff6565b6008805467ffffffffffffffff191667ffffffffffffffff86161790555b60045460005b81811015610dcb578460048281548110610d7a57610d7a61441f565b90600052602060002090600502016000015403610dc3576040517fbfec555800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600101610d5e565b506040805160c081018252858152336020808301918252600083850181815260608501898152608086018e815260a0870184815260048054600181018255955296517f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b60059095029485015594517f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19c8401805493516001600160a01b0390921674ffffffffffffffffffffffffffffffffffffffffff1990941693909317600160a01b9115159190910217909155517f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19d82015591517f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19e83015591517f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19f90910155815167ffffffffffffffff891681529081018690527f68e0867601a98978930107aee7f425665e61edd70ca594c68ca5da9e81f84c29910160405180910390a150505050505050565b600080610f5f611816565b610f6a906001614435565b60075460085491925090610f9090600160401b900467ffffffffffffffff166001614435565b67ffffffffffffffff168267ffffffffffffffff16111561066657600854600090600190610fcf90600160401b900467ffffffffffffffff168561445d565b610fd9919061445d565b67ffffffffffffffff1690508181604051602001611001929190918252602082015260400190565b6040516020818303038152906040528051906020012091505092915050565b6110286121c0565b611030612213565b6040805160c081018252600a548152600b546001600160a01b0381166020830152600160a01b900460ff1691810191909152600c546060820152600d546080820152600e5460a08201526006546007546000918291611090600f826143f7565b935061109d600e826143f7565b92508383106110b457826110b08161447e565b9350505b6110c78660200135838760400151612059565b6110e757604051633b5f43a360e01b8152600360048201526024016109f5565b6110f286601e61281f565b6110fb86612b31565b61110486612e3e565b6111178860200135838760400151612059565b61113757604051633b5f43a360e01b8152600260048201526024016109f5565b61114b886111468660026143b7565b61281f565b61115488612b31565b61115d88612e3e565b6111708760200135838760400151612059565b61119057604051633b5f43a360e01b8152600160048201526024016109f5565b61119f876111468560026143b7565b6111a887612b31565b6111b187612e3e565b61122784846111c08b80614497565b60008181106111d1576111d161441f565b602002919091013590506111e58b80614497565b60008181106111f6576111f661441f565b6020029190910135905061120a8b80614497565b600081811061121b5761121b61441f565b905060200201356130d2565b6112516112348780614497565b60008181106112455761124561441f565b9050602002013561315f565b60015460208601516040517f51cff8d90000000000000000000000000000000000000000000000000000000081526001600160a01b03918216600482015261010090920416906351cff8d990602401600060405180830381600087803b1580156112ba57600080fd5b505af11580156112ce573d6000803e3d6000fd5b505050507f788e77979e6e6a8a6a5d2c19c58b1ff9671298f54c85ac6f6aa30379aed5861a8560405161130191906144e8565b60405180910390a17fbee3fc8a3523c1a65fa9308ce1f2b8fd90c24975b141b754603194597846e4dd60018054906101000a90046001600160a01b03166001600160a01b0316638a5e8e326040518163ffffffff1660e01b8152600401602060405180830381865afa15801561137b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061139f9190614388565b6040519081526020015b60405180910390a15050505050505050565b60006113c5611e7d565b806114035750600854600160401b900467ffffffffffffffff166113e7611816565b67ffffffffffffffff161180156114035750611401611823565b155b15611415576114106117b2565b905090565b61141d611823565b1561142a57611410610f54565b611432610931565b80156114615750600854600160401b900467ffffffffffffffff16611455611816565b67ffffffffffffffff16145b15611498576040517f36b7884b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b90565b600481815481106114ab57600080fd5b6000918252602090912060059091020180546001820154600283015460038401546004909401549294506001600160a01b03821693600160a01b90920460ff169290919086565b60006114fc611823565b61151957604051633788c6c160e11b815260040160405180910390fd5b6000611523611816565b60085490915067ffffffffffffffff808316600160401b909204161461155c57604051636fbabc7760e01b815260040160405180910390fd5b60085467ffffffffffffffff600160801b90910481169082161161159357604051630c8d9eab60e31b815260040160405180910390fd5b6000806000806000806000806115a761319d565b905060006115b3613257565b600454919650945060005b8181101561178e57600481815481106115d9576115d961441f565b9060005260206000209060050201600401549450600481815481106116005761160061441f565b906000526020600020906005020160010160149054906101000a900460ff16801561164e5750600585815481106116395761163961441f565b90600052602060002090600502016004015487145b801561168c5750600585815481106116685761166861441f565b600091825260209091206001600590920201015460ff878116600160a01b90920416145b1561178657600585815481106116a4576116a461441f565b9060005260206000209060050201600301548b6116c19190614537565b9a5083836040516020016116d692919061456e565b60408051601f19818403018152919052805160209091012098506fffffffffffffffffffffffffffffffff808a169850611711906001614537565b600586815481106117245761172461441f565b90600052602060002090600502016003015461174091906143b7565b61174a8c8a6143b7565b101561177857600585815481106117635761176361441f565b90600052602060002090600502016000015499505b826117828161447e565b9350505b6001016115be565b505050959099149998505050505050505050565b600581815481106114ab57600080fd5b600080610f6a611816565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff1661180c57604051631d77d47760e21b815260040160405180910390fd5b611814613410565b565b600061141060984361440b565b60006118316002609861440b565b61183c6098436143f7565b106118475750600190565b50600090565b6118556121c0565b600061185f611816565b6003546040516397adedb560e01b81523360048201529192506000916001600160a01b03909116906397adedb590602401602060405180830381865afa1580156118ad573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118d19190614388565b90506118db611d8a565b60ff168560ff16101561191a576040517f83d9b7bd00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611922610931565b611958576040517fd1088db600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60085467ffffffffffffffff8381169116146119a0576040517f842a9e0a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60085467ffffffffffffffff838116600160401b9092041614611a88576119c56113bb565b6006556119d460056000613ff6565b600880547fffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff16600160401b67ffffffffffffffff8516908102919091179091556006546040805192835260208301919091527ff0ae472da9c8da86bda4991a549c03a3cb328b5f360ea11a5b8814f32bb85176910160405180910390a1611a88600754604080516020810192909252449082015260600160408051601f198184030181529190528051602090910120600755565b6000611a9682878787611e0f565b90506000611aa48383613464565b9050600060048281548110611abb57611abb61441f565b60009182526020918290206040805160c081018252600593909302909101805480845260018201546001600160a01b03811695850195909552600160a01b90940460ff1615159183019190915260028101546060830152600381015460808301526004015460a0820152600654909250611b3691908a612059565b611b72576006546040517f14ebbbe40000000000000000000000000000000000000000000000000000000081526004016109f591815260200190565b806040015115611bae576040517fa89ac15100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600160048381548110611bc357611bc361441f565b906000526020600020906005020160010160146101000a81548160ff02191690831515021790555060058054905060048381548110611c0457611c0461441f565b90600052602060002090600502016004018190555060056040518060c001604052808360000151815260200183602001516001600160a01b031681526020018a60ff168152602001836060015181526020018a6002611c639190614674565b8460600151611c7291906143b7565b815260209081018a90528254600181810185556000948552938290208351600590920201908155908201519281018054604084015160ff16600160a01b0274ffffffffffffffffffffffffffffffffffffffffff199091166001600160a01b0390951694909417939093179092556060808201516002808501919091556080830151600385015560a0909201516004909301929092558251918301517f13fc17fd71632266fe82092de6dd91a06b4fa68d8dc950492e5421cbed55a6a5928892909190611d40908d90614674565b8560600151611d4f91906143b7565b6040805167ffffffffffffffff909516855260208501939093529183015260608201526080810189905260ff8a1660a082015260c0016113a9565b6008546000908190611daf9067ffffffffffffffff600160801b82048116911661445d565b67ffffffffffffffff169050600060fe8211611dcb5781611dce565b60fe5b611dd9906001614683565b600b5490915060ff600160a01b9091048116908216811115611e0457611dff828261469c565b611e07565b60005b935050505090565b60408051602081018690527fff0000000000000000000000000000000000000000000000000000000000000060f886901b169181019190915260418101839052606181018290526000906081015b604051602081830303815290604052805190602001209050949350505050565b6000611e8b6004609861440b565b611e966098436143f7565b10156118475750600190565b600082815260208190526040902060010154611ebd81612096565b61092c8383612141565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff16611f1657604051637bfa4b9f60e01b815260040160405180910390fd5b600880547fffffffffffff0000ffffffffffffffffffffffffffffffffffffffffffffffff16600160c01b60ff958616027fffffffffffff00ffffffffffffffffffffffffffffffffffffffffffffffffff1617600160c81b93851693909302929092177fffffffffff00ffffffffffffffffffffffffffffffffffffffffffffffffffff16600160d01b9190931602919091179055565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff16611ffd57604051637bfa4b9f60e01b815260040160405180910390fd5b600955565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff1661205157604051631d77d47760e21b815260040160405180910390fd5b61181461350f565b60008160ff1660000361206e5750600161208f565b61207d60ff83166101006146b5565b6120889060026146d0565b8484181090505b9392505050565b6120a08133613548565b50565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610a08576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556120fd3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1615610a08576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b60015460ff16156118145760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a207061757365640000000000000000000000000000000060448201526064016109f5565b600061221d611816565b9050612227611823565b61224457604051633788c6c160e11b815260040160405180910390fd5b60085467ffffffffffffffff828116600160401b909204161461227a57604051636fbabc7760e01b815260040160405180910390fd5b60085467ffffffffffffffff600160801b9091048116908216116122b157604051630c8d9eab60e31b815260040160405180910390fd5b600454604051818152600091829182918291829182917f6752c5e71c95fb93bc7137adeb115a33fa4e54e2683e33d3f90c2bb1c4b6c2a59060200160405180910390a16005546040519081527f4c03de6a759749c0c9387b7014634dc5c6af610e1366023d90751c783a998f8d9060200160405180910390a1612332613257565b6040805183815260ff831660208201529295509093507f34e8eda4cd857cd2865becf58a47748f31415f4a382cbb2cc0c64b9a27c717be910160405180910390a1600061237d61319d565b905060005b828110156127595760006004828154811061239f5761239f61441f565b600091825260208083206040805160c08101825260059485029092018054835260018101546001600160a01b03811694840194909452600160a01b90930460ff16151590820152600282015460608201526003820154608082015260049091015460a0820181905282549194509291908390811061241f5761241f61441f565b60009182526020918290206040805160c0810182526005939093029091018054835260018101546001600160a01b03811694840194909452600160a01b90930460ff1682820152600283015460608301526003830154608083015260049092015460a082015290840151909150801561249b57508060a0015188145b80156124b05750806040015160ff168760ff16145b156125a55760808101516124c4908d614537565b9b50848b6040516020016124d992919061456e565b60408051601f19818403018152919052805160209091012099506fffffffffffffffffffffffffffffffff808b169950612514906001614537565b816080015161252391906143b7565b61252d8d8b6143b7565b1015612597578051600a556020810151600b8054604084015160ff16600160a01b0274ffffffffffffffffffffffffffffffffffffffffff199091166001600160a01b03909316929092179190911790556060810151600c556080810151600d5560a0810151600e555b8a6125a18161447e565b9b50505b826040015180156125ce57508060a00151881415806125ce5750806040015160ff168760ff1614155b80156125ef5750600854600160d01b900460ff166125ed6064446143f7565b105b1561269b5760035460208201516001600160a01b039091169063d009b2d6906126198a6002614674565b60085461263290609890600160c01b900460ff166143b7565b61263c91906143b7565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401600060405180830381600087803b15801561268257600080fd5b505af1158015612696573d6000803e3d6000fd5b505050505b826040015161274b5760035460208401516001600160a01b039091169063d009b2d6906126c98a6002614674565b6008546126e290609890600160c81b900460ff166143b7565b6126ec91906143b7565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401600060405180830381600087803b15801561273257600080fd5b505af1158015612746573d6000803e3d6000fd5b505050505b836001019350505050612382565b506002546040517fffb98fe300000000000000000000000000000000000000000000000000000000815261ffff891660048201526001600160a01b039091169063ffb98fe390602401600060405180830381600087803b1580156127bc57600080fd5b505af11580156127d0573d6000803e3d6000fd5b50506008805467ffffffffffffffff909c16600160801b027fffffffffffffffff0000000000000000ffffffffffffffffffffffffffffffff909c169b909b17909a5550505050505050505050565b600754600090612831906080906143f7565b9050600061289461284560a0860186614497565b8080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525050505060608601358461288c60a0890160808a016146e0565b6006546135bb565b60408051858152602081018390529192507f94e252069a85aa79db21f5bd8ca4e14dd3a3927aa492711017a2c8ddad95af00910160405180910390a161291c6128dd8580614497565b80806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250505050602086013585610400613733565b600e54146129475760405163755f0a2560e01b815260016004820152602481018290526044016109f5565b61295460a0850185614497565b60008181106129655761296561441f565b9050602002013584806040019061297c9190614497565b600081811061298d5761298d61441f565b90506020020135146129bc5760405163755f0a2560e01b815260026004820152602481018290526044016109f5565b6000806129cc60e0870187614497565b9050116129dd578460200135612a12565b6129ea60e0860186614497565b60008181106129fb576129fb61441f565b9050602002810190612a0d91906146fb565b606001355b9050612a70612a246040870187614497565b80806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250505050606087013585612a6b60a08a0160808b016146e0565b613733565b8114612a995760405163755f0a2560e01b815260036004820152602481018390526044016109f5565b6000612aa860e0870187614497565b90501115612ae05760408051602080880135908201529081018390526060016040516020818303038152906040528051906020012091505b81612aeb8680614497565b6000818110612afc57612afc61441f565b9050602002013514612b2a5760405163755f0a2560e01b8152600481810152602481018390526044016109f5565b5050505050565b6001546000908190819061010090046001600160a01b031663c81e25ab612b5b60c08701876146fb565b602001356040518263ffffffff1660e01b8152600401612b7d91815260200190565b60c060405180830381865afa158015612b9a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612bbe919061471b565b509396509194509250506001600160a01b0384169050612c1e57612be560c08501856146fb565b602001356040517f2396d34e0000000000000000000000000000000000000000000000000000000081526004016109f591815260200190565b6000612c41612c3060c08701876146fb565b6114989060608101906040016146e0565b90506000612c4f84846138a1565b9050808263ffffffff1610612ca457612c6b60c08701876146fb565b602001356040517f1362e4a00000000000000000000000000000000000000000000000000000000081526004016109f591815260200190565b6000612cd3612cb660c08901896146fb565b612cc79060608101906040016146e0565b60201c63ffffffff1690565b90506000612ce58860200135866138bc565b63ffffffff16905067ffffffffffffffff82168114612d4457612d0b60c08901896146fb565b602001356040517f6dd6a24f0000000000000000000000000000000000000000000000000000000081526004016109f591815260200190565b612dea87612d5560c08b018b6146fb565b612d5f9080614793565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050505060208b0135612da560c08d018d6146fb565b60200135612db660c08e018e6146fb565b612dc79060608101906040016146e0565b612dd460c08f018f6146fb565b612de59060808101906060016146e0565b6138e3565b612e3457612dfb60c08901896146fb565b602001356040517fdb12fb9d0000000000000000000000000000000000000000000000000000000081526004016109f591815260200190565b5050505050505050565b612e4b60e0820182614497565b9050600003612e575750565b612f78612e6760e0830183614497565b6000818110612e7857612e7861441f565b9050602002810190612e8a91906146fb565b612e989060208101906147da565b612ea560e0840184614497565b6000818110612eb657612eb661441f565b9050602002810190612ec891906146fb565b612ed6906020810190614793565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250612f189250505060e0850185614497565b6000818110612f2957612f2961441f565b9050602002810190612f3b91906146fb565b60400135612f4c60e0860186614497565b6000818110612f5d57612f5d61441f565b9050602002810190612f6f91906146fb565b6060013561397a565b612fe557612f8960e0820182614497565b6000818110612f9a57612f9a61441f565b9050602002810190612fac91906146fb565b606001356040517fd740df610000000000000000000000000000000000000000000000000000000081526004016109f591815260200190565b6020810135613064612ffa60e0840184614497565b600081811061300b5761300b61441f565b905060200281019061301d91906146fb565b6040013561302e60e0850185614497565b600081811061303f5761303f61441f565b905060200281019061305191906146fb565b61305f9060208101906147da565b613a0d565b146120a05761307660e0820182614497565b60008181106130875761308761441f565b905060200281019061309991906146fb565b606001356040517f82f2469d0000000000000000000000000000000000000000000000000000000081526004016109f591815260200190565b8385101561311f578183106130fa57604051633d386eb360e11b815260040160405180910390fd5b80821061311a57604051633588c6d360e11b815260040160405180910390fd5b612b2a565b82821061313f57604051633d386eb360e11b815260040160405180910390fd5b808310612b2a57604051633588c6d360e11b815260040160405180910390fd5b60095481106120a0576040517fb6052cdf000000000000000000000000000000000000000000000000000000008152600481018290526024016109f5565b60606131a7611823565b6131c457604051633788c6c160e11b815260040160405180910390fd5b60006131ce611816565b60085490915067ffffffffffffffff808316600160401b909204161461320757604051636fbabc7760e01b815260040160405180910390fd5b6007546040516020016132429181527f3100000000000000000000000000000000000000000000000000000000000000602082015260210190565b60405160208183030381529060405291505090565b600080600080600080600080600061326d613a5b565b60045490915060005b818110156133ff57600481815481106132915761329161441f565b906000526020600020906005020160010160149054906101000a900460ff16156133f757600481815481106132c8576132c861441f565b9060005260206000209060050201600401549350600584815481106132ef576132ef61441f565b9060005260206000209060050201600301548961330c9190614537565b9850828160405160200161332192919061456e565b60408051601f19818403018152919052805160209091012097506fffffffffffffffffffffffffffffffff808916975061335c906001614537565b6005858154811061336f5761336f61441f565b90600052602060002090600502016003015461338b91906143b7565b6133958a896143b7565b10156133f757600584815481106133ae576133ae61441f565b9060005260206000209060050201600401549550600584815481106133d5576133d561441f565b906000526020600020906005020160010160149054906101000a900460ff1694505b600101613276565b509399929850919650505050505050565b6134186121c0565b6001805460ff1916811790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258335b6040516001600160a01b03909116815260200160405180910390a1565b6000805b6004548110156134dc5783600482815481106134865761348661441f565b9060005260206000209060050201600001541480156134c85750600481815481106134b3576134b361441f565b90600052602060002090600502016003015483145b156134d4579050610666565b600101613468565b506040517fd950091500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b613517613ae4565b6001805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa33613447565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610a085761357981613b36565b613584836020613b48565b6040516020016135959291906147f7565b60408051601f198184030181529082905262461bcd60e51b82526109f591600401614878565b6000806135ca87878786613d0d565b9050826136cf856000808267ffffffffffffffff1690506008817eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff16901b600882901c7eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff161790506010817dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff16901b601082901c7dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff161790506020817bffffffff00000000ffffffff00000000ffffffff00000000ffffffff16901b602082901c7bffffffff00000000ffffffff00000000ffffffff00000000ffffffff1617905080915050919050565b826040516020016137119392919092835260c09190911b77ffffffffffffffffffffffffffffffffffffffffffffffff19166020830152602882015260480190565b6040516020818303038152906040528051906020012091505095945050505050565b600080613741868686613d83565b9050613845836000808267ffffffffffffffff1690506008817eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff16901b600882901c7eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff161790506010817dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff16901b601082901c7dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff161790506020817bffffffff00000000ffffffff00000000ffffffff00000000ffffffff16901b602082901c7bffffffff00000000ffffffff00000000ffffffff00000000ffffffff1617905080915050919050565b8160405160200161388092919060c09290921b77ffffffffffffffffffffffffffffffffffffffffffffffff19168252600882015260280190565b60405160208183030381529060405280519060200120915050949350505050565b60006138ad828461469c565b60ff166001901b905092915050565b600060e083901c6138ce83602061469c565b60ff168163ffffffff16901c91505092915050565b6000806138f286868686613deb565b9050600061394d826040517f19457468657265756d205369676e6564204d6573736167653a0a3332000000006020820152603c8101829052600090605c01604051602081830303815290604052805190602001209050919050565b9050886001600160a01b0316613963828a613e36565b6001600160a01b0316149998505050505050505050565b6000806139878484613eb5565b905060006139e2826040517f19457468657265756d205369676e6564204d6573736167653a0a3332000000006020820152603c8101829052600090605c01604051602081830303815290604052805190602001209050919050565b9050866001600160a01b03166139f88288613e36565b6001600160a01b031614979650505050505050565b60008282604051602001613a3d92919091825260601b6bffffffffffffffffffffffff1916602082015260340190565b60405160208183030381529060405280519060200120905092915050565b6060613a65611823565b613a8257604051633788c6c160e11b815260040160405180910390fd5b6000613a8c611816565b60085490915067ffffffffffffffff808316600160401b9092041614613ac557604051636fbabc7760e01b815260040160405180910390fd5b600754604051602001613242918152600360fc1b602082015260210190565b60015460ff166118145760405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f742070617573656400000000000000000000000060448201526064016109f5565b60606106666001600160a01b03831660145b60606000613b578360026143b7565b613b62906002614537565b67ffffffffffffffff811115613b7a57613b7a6148ab565b6040519080825280601f01601f191660200182016040528015613ba4576020820181803683370190505b509050600360fc1b81600081518110613bbf57613bbf61441f565b60200101906001600160f81b031916908160001a9053507f780000000000000000000000000000000000000000000000000000000000000081600181518110613c0a57613c0a61441f565b60200101906001600160f81b031916908160001a9053506000613c2e8460026143b7565b613c39906001614537565b90505b6001811115613cbe577f303132333435363738396162636465660000000000000000000000000000000085600f1660108110613c7a57613c7a61441f565b1a60f81b828281518110613c9057613c9061441f565b60200101906001600160f81b031916908160001a90535060049490941c93613cb7816148c1565b9050613c3c565b50831561208f5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e7460448201526064016109f5565b8260005b8551811015613d7a576000613d276002866143f7565b15613d33576000613d36565b60015b9050613d5d83888481518110613d4e57613d4e61441f565b60200260200101518387613ed1565b9250600185901c9450508080613d729061447e565b915050613d11565b50949350505050565b8160005b8451811015613de3576000613d9d6002856143f7565b6000149050613dc683878481518110613db857613db861441f565b602002602001015183613f31565b9250600184901c9350508080613ddb9061447e565b915050613d87565b509392505050565b604080516020810186905290810184905277ffffffffffffffffffffffffffffffffffffffffffffffff1960c084811b8216606084015283901b166068820152600090607001611e5d565b600080600080613e4585613f98565b6040805160008152602081018083528b905260ff8316918101919091526060810184905260808101839052929550909350915060019060a0016020604051602081039080840390855afa158015613ea0573d6000803e3d6000fd5b5050604051601f190151979650505050505050565b6040805160208101849052908101829052600090606001613a3d565b60008215613f11576040805160208101849052908101869052606081018590526080016040516020818303038152906040528051906020012090506107f2565b604080516020810184905290810185905260608101869052608001611e5d565b60008115613f6a57604080516020810186905290810184905260600160405160208183030381529060405280519060200120905061208f565b5050604080516020808201939093528082019390935280518084038201815260609093019052815191012090565b60008060008351604114613fd8576040517f4be6321b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50505060208101516040820151606090920151909260009190911a90565b50805460008255600502906000526020600020908101906120a091905b8082111561405b57600080825560018201805474ffffffffffffffffffffffffffffffffffffffffff1916905560028201819055600382018190556004820155600501614013565b5090565b60006020828403121561407157600080fd5b81356001600160e01b03198116811461208f57600080fd5b6001600160a01b03811681146120a057600080fd5b60ff811681146120a057600080fd5b600080604083850312156140c057600080fd5b82356140cb81614089565b915060208301356140db8161409e565b809150509250929050565b6000602082840312156140f857600080fd5b5035919050565b6020808252825182820181905260009190848201906040850190845b818110156141825761416f838551805182526001600160a01b03602082015116602083015260ff6040820151166040830152606081015160608301526080810151608083015260a081015160a08301525050565b9284019260c0929092019160010161411b565b50909695505050505050565b600080604083850312156141a157600080fd5b8235915060208301356140db81614089565b803567ffffffffffffffff811681146141cb57600080fd5b919050565b600080604083850312156141e357600080fd5b823591506141f3602084016141b3565b90509250929050565b6000610100828403121561420f57600080fd5b50919050565b60008060006060848603121561422a57600080fd5b833567ffffffffffffffff8082111561424257600080fd5b61424e878388016141fc565b9450602086013591508082111561426457600080fd5b614270878388016141fc565b9350604086013591508082111561428657600080fd5b50614293868287016141fc565b9150509250925092565b6000806000606084860312156142b257600080fd5b83356142bd8161409e565b95602085013595506040909401359392505050565b600080600080608085870312156142e857600080fd5b8435935060208501356142fa8161409e565b93969395505050506040820135916060013590565b60008060006060848603121561432457600080fd5b833561432f8161409e565b9250602084013561433f8161409e565b9150604084013561434f8161409e565b809150509250925092565b60008060006060848603121561436f57600080fd5b8335925060208401359150604084013561434f8161409e565b60006020828403121561439a57600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b8082028115828204841417610666576106666143a1565b81810381811115610666576106666143a1565b634e487b7160e01b600052601260045260246000fd5b600082614406576144066143e1565b500690565b60008261441a5761441a6143e1565b500490565b634e487b7160e01b600052603260045260246000fd5b67ffffffffffffffff818116838216019080821115614456576144566143a1565b5092915050565b67ffffffffffffffff828116828216039080821115614456576144566143a1565b600060018201614490576144906143a1565b5060010190565b6000808335601e198436030181126144ae57600080fd5b83018035915067ffffffffffffffff8211156144c957600080fd5b6020019150600581901b36038213156144e157600080fd5b9250929050565b60c081016106668284805182526001600160a01b03602082015116602083015260ff6040820151166040830152606081015160608301526080810151608083015260a081015160a08301525050565b80820180821115610666576106666143a1565b60005b8381101561456557818101518382015260200161454d565b50506000910152565b6000835161458081846020880161454a565b9190910191825250602001919050565b600181815b808511156145cb5781600019048211156145b1576145b16143a1565b808516156145be57918102915b93841c9390800290614595565b509250929050565b6000826145e257506001610666565b816145ef57506000610666565b8160018114614605576002811461460f5761462b565b6001915050610666565b60ff841115614620576146206143a1565b50506001821b610666565b5060208310610133831016604e8410600b841016171561464e575081810a610666565b6146588383614590565b806000190482111561466c5761466c6143a1565b029392505050565b600061208f60ff8416836145d3565b60ff8181168382160190811115610666576106666143a1565b60ff8281168282160390811115610666576106666143a1565b61ffff828116828216039080821115614456576144566143a1565b600061208f61ffff8416836145d3565b6000602082840312156146f257600080fd5b61208f826141b3565b60008235607e1983360301811261471157600080fd5b9190910192915050565b60008060008060008060c0878903121561473457600080fd5b865161473f81614089565b60208801519096506147508161409e565b60408801519095506147618161409e565b6060880151909450801515811461477757600080fd5b809350506080870151915060a087015190509295509295509295565b6000808335601e198436030181126147aa57600080fd5b83018035915067ffffffffffffffff8211156147c557600080fd5b6020019150368190038213156144e157600080fd5b6000602082840312156147ec57600080fd5b813561208f81614089565b7f416363657373436f6e74726f6c3a206163636f756e742000000000000000000081526000835161482f81601785016020880161454a565b7f206973206d697373696e6720726f6c6520000000000000000000000000000000601791840191820152835161486c81602884016020880161454a565b01602801949350505050565b602081526000825180602084015261489781604085016020870161454a565b601f01601f19169190910160400192915050565b634e487b7160e01b600052604160045260246000fd5b6000816148d0576148d06143a1565b50600019019056fea26469706673582212200f9f0a55ccd6f0cb7269fe52233ea174faebf4c052751953813f1866c96736b964736f6c63430008130033", - "address": "0xB648ad6EE25ad0EDF295E3cFf3799969B28A18D7", - "block": 6661233, - "url": "https://sepolia.etherscan.io/address/0xB648ad6EE25ad0EDF295E3cFf3799969B28A18D7" + "bytecode": "0x60806040526008805462ffffff60c01b19166264020160c01b1790557dba1914b54e0348a1028d1a103a95ed55c4004b9d332400000000000000006009553480156200004a57600080fd5b5060405162004e1538038062004e158339810160408190526200006d916200019d565b60018054600380546001600160a01b03199081166001600160a01b03888116919091179092556001600160a81b0319909216610100868316021790925560028054909116918316919091179055620000c7600033620000d0565b505050620001e7565b620000dc8282620000e0565b5050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16620000dc576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556200013c3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b80516001600160a01b03811681146200019857600080fd5b919050565b600080600060608486031215620001b357600080fd5b620001be8462000180565b9250620001ce6020850162000180565b9150620001de6040850162000180565b90509250925092565b614c1e80620001f76000396000f3fe608060405234801561001057600080fd5b50600436106102775760003560e01c806377c75d1011610160578063b6cd5822116100d8578063dfbf53ae1161008c578063f69ee1d111610071578063f69ee1d1146105df578063f7b188a5146105f2578063fb00f2f3146105fa57600080fd5b8063dfbf53ae1461059c578063f4e6fcca146105cc57600080fd5b8063ce987745116100bd578063ce9877451461056e578063d1e8b63d14610581578063d547741f1461058957600080fd5b8063b6cd582214610541578063c46b40291461055457600080fd5b80638456cb591161012f5780638d8b6428116101145780638d8b6428146104fa57806391d1485414610502578063a217fddf1461053957600080fd5b80638456cb59146104ea5780638a19c8bc146104f257600080fd5b806377c75d10146104645780637fe019c61461047757806382b39b1b1461049257806383220626146104e257600080fd5b80635c975abb116101f357806364c34a85116101c257806369da9114116101a757806369da9114146103de5780636f94aaf2146103f157806372286cba1461040c57600080fd5b806364c34a85146103a957806369bfac01146103b157600080fd5b80635c975abb146103705780635d4844ea1461037b57806362fd29ae1461038e57806363f5cf7c1461039657600080fd5b80632a4e62491161024a5780632f3906da1161022f5780632f3906da1461034257806336568abe1461034a5780635838d6731461035d57600080fd5b80632a4e6249146103185780632f2ff15d1461032d57600080fd5b806301ffc9a71461027c5780631736d472146102a457806318350096146102b7578063248a9ca3146102e7575b600080fd5b61028f61028a36600461431f565b61060d565b60405190151581526020015b60405180910390f35b61028f6102b236600461436d565b610676565b6001546102cf9061010090046001600160a01b031681565b6040516001600160a01b03909116815260200161029b565b61030a6102f53660046143a6565b60009081526020819052604090206001015490565b60405190815260200161029b565b610320610883565b60405161029b91906143bf565b61034061033b36600461444e565b610990565b005b61028f6109ba565b61034061035836600461444e565b610a04565b61034061036b366004614490565b610a95565b60015460ff1661028f565b6003546102cf906001600160a01b031681565b61030a611032565b6103406103a43660046144d5565b6110fe565b61030a611533565b6008546103c59067ffffffffffffffff1681565b60405167ffffffffffffffff909116815260200161029b565b6002546102cf906001600160a01b031681565b6008546103c590600160801b900467ffffffffffffffff1681565b61041f61041a3660046143a6565b611613565b604080519788526001600160a01b0390961660208801529315159486019490945260ff9091166060850152608084015260a083019190915260c082015260e00161029b565b61028f6104723660046143a6565b611671565b6008546103c590600160401b900467ffffffffffffffff1681565b6104a56104a03660046143a6565b611921565b604080519687526001600160a01b03909516602087015260ff909316938501939093526060840152608083019190915260a082015260c00161029b565b61030a611978565b610340611983565b6103c56119dc565b61028f6119e9565b61028f61051036600461444e565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b61030a600081565b61034061054f36600461455d565b611a13565b61055c611f6d565b60405160ff909116815260200161029b565b61030a61057c366004614592565b611ff2565b61028f612061565b61034061059736600461444e565b612086565b600a54600b54600c54600d54600e546104a594936001600160a01b03811693600160a01b90910460ff1692909186565b6103406105da3660046145cf565b6120ab565b6103406105ed3660046143a6565b612192565b6103406121e6565b61028f61060836600461461a565b61223d565b60006001600160e01b031982167f7965db0b00000000000000000000000000000000000000000000000000000000148061067057507f01ffc9a7000000000000000000000000000000000000000000000000000000006001600160e01b03198316145b92915050565b60035460405163d1052d1f60e01b81526001600160a01b038481166004830152600092839291169063d1052d1f90602401602060405180830381865afa1580156106c4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106e89190614648565b600354604051631d54805360e01b81526001600160a01b03878116600483015292935060009290911690631d54805390602401602060405180830381865afa158015610738573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061075c9190614661565b6107669085614694565b90506107706109ba565b156107a7576040517fe2586bcc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b816000036107c7576040516273e5c360e31b815260040160405180910390fd5b6107d3609860026146ad565b6107dd90436146c4565b82106107fc57604051630a0744c560e01b815260040160405180910390fd5b6003546040516397adedb560e01b81526001600160a01b03878116600483015261087a9216906397adedb590602401602060405180830381865afa158015610848573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061086c9190614648565b610874611533565b8361223d565b95945050505050565b606061088d6119e9565b6108aa57604051633788c6c160e11b815260040160405180910390fd5b60006108b46119dc565b60085490915067ffffffffffffffff808316600160401b90920416146108ed57604051636fbabc7760e01b815260040160405180910390fd5b6005805480602002602001604051908101604052809291908181526020016000905b828210156109865760008481526020908190206040805160c08101825260058602909201805483526001808201546001600160a01b03811685870152600160a01b900460ff169284019290925260028101546060840152600381015460808401526004015460a0830152908352909201910161090f565b5050505091505090565b6000828152602081905260409020600101546109ab8161227a565b6109b58383612287565b505050565b6000806109c86098436146ed565b90506109d660046098614701565b81101580156109ef57506109ec60026098614701565b81105b156109fc57600191505090565b600091505090565b6001600160a01b0381163314610a875760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b610a918282612325565b5050565b610a9d6123a4565b6000610aa76119dc565b6003546040516397adedb560e01b81523360048201529192506000916001600160a01b03909116906397adedb590602401602060405180830381865afa158015610af5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b199190614648565b6003546040517f830a053e0000000000000000000000000000000000000000000000000000000081523360048201529192506000916001600160a01b039091169063830a053e90602401602060405180830381865afa158015610b80573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ba49190614648565b60035460405163d1052d1f60e01b81523360048201529192506000916001600160a01b039091169063d1052d1f90602401602060405180830381865afa158015610bf2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c169190614648565b600354604051631d54805360e01b81523360048201529192506000916001600160a01b0390911690631d54805390602401602060405180830381865afa158015610c64573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c889190614661565b9050610c92612061565b610cc8576040517fdc816a8700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001610cd660046098614701565b610ce091906146c4565b610ceb6098436146ed565b03610d22576040517f5baef6b600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8567ffffffffffffffff168567ffffffffffffffff161115610d70576040517f50ff7c0000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8567ffffffffffffffff168567ffffffffffffffff161015610dbe576040517f7a0c0fd600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b81600003610dde576040516273e5c360e31b815260040160405180910390fd5b610dea609860026146ad565b610df490436146c4565b8210610e1357604051630a0744c560e01b815260040160405180910390fd5b60085467ffffffffffffffff868116911614610e5357610e356004600061423d565b6008805467ffffffffffffffff191667ffffffffffffffff87161790555b60045460005b81811015610ec6578560048281548110610e7557610e75614715565b90600052602060002090600502016000015403610ebe576040517fbfec555800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600101610e59565b5060046040518060e00160405280878152602001336001600160a01b031681526020016000151581526020018460ff1681526020018681526020018a8152602001600081525090806001815401808255809150506001900390600052602060002090600502016000909190919091506000820151816000015560208201518160010160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555060408201518160010160146101000a81548160ff02191690831515021790555060608201518160010160156101000a81548160ff021916908360ff1602179055506080820151816002015560a0820151816003015560c0820151816004015550507faadc88121471799d39ee2bbe1dd30a4ab57510e2a33bd6e537de5fafd2daa8868786846040516110209392919067ffffffffffffffff939093168352602083019190915260ff16604082015260600190565b60405180910390a15050505050505050565b60008061103d6119dc565b61104890600161472b565b6007546008549192509061106e90600160401b900467ffffffffffffffff16600161472b565b67ffffffffffffffff168267ffffffffffffffff161115610670576008546000906001906110ad90600160401b900467ffffffffffffffff1685614753565b6110b79190614753565b67ffffffffffffffff16905081816040516020016110df929190918252602082015260400190565b6040516020818303038152906040528051906020012091505092915050565b6111066123a4565b61110e6123f7565b6040805160c081018252600a548152600b546001600160a01b0381166020830152600160a01b900460ff1691810191909152600c546060820152600d546080820152600e5460a0820152600654600754600091829161116e600f826146ed565b935061117b600e826146ed565b9250838310611192578261118e81614774565b9350505b6111a5866020013583876040015161223d565b6111c557604051633b5f43a360e01b815260036004820152602401610a7e565b6111d086601e612a66565b6111d986612d78565b6111e286613085565b6111f5886020013583876040015161223d565b61121557604051633b5f43a360e01b815260026004820152602401610a7e565b611229886112248660026146ad565b612a66565b61123288612d78565b61123b88613085565b61124e876020013583876040015161223d565b61126e57604051633b5f43a360e01b815260016004820152602401610a7e565b61127d876112248560026146ad565b61128687612d78565b61128f87613085565b611305848461129e8b8061478d565b60008181106112af576112af614715565b602002919091013590506112c38b8061478d565b60008181106112d4576112d4614715565b602002919091013590506112e88b8061478d565b60008181106112f9576112f9614715565b90506020020135613319565b61132f611312878061478d565b600081811061132357611323614715565b905060200201356133a6565b60015460208601516040516001600160a01b03918216602482015260009261010090049091169060440160408051601f198184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f51cff8d900000000000000000000000000000000000000000000000000000000179052516113bc9190614802565b6000604051808303816000865af19150503d80600081146113f9576040519150601f19603f3d011682016040523d82523d6000602084013e6113fe565b606091505b5050905080611449576020808701516040516001600160a01b0390911681527f7ae187a0c04cf55b655ca83fa11d37854c882bf1fdcb588469b414731bb0e05a910160405180910390a15b7f788e77979e6e6a8a6a5d2c19c58b1ff9671298f54c85ac6f6aa30379aed5861a86604051611478919061481e565b60405180910390a17fbee3fc8a3523c1a65fa9308ce1f2b8fd90c24975b141b754603194597846e4dd60018054906101000a90046001600160a01b03166001600160a01b0316638a5e8e326040518163ffffffff1660e01b8152600401602060405180830381865afa1580156114f2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115169190614648565b6040519081526020015b60405180910390a1505050505050505050565b600061153d612061565b8061157b5750600854600160401b900467ffffffffffffffff1661155f6119dc565b67ffffffffffffffff1611801561157b57506115796119e9565b155b1561158d57611588611978565b905090565b6115956119e9565b156115a257611588611032565b6115aa6109ba565b80156115d95750600854600160401b900467ffffffffffffffff166115cd6119dc565b67ffffffffffffffff16145b15611610576040517f36b7884b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b90565b6004818154811061162357600080fd5b6000918252602090912060059091020180546001820154600283015460038401546004909401549294506001600160a01b0382169360ff600160a01b8404811694600160a81b909404169287565b600061167b6119e9565b61169857604051633788c6c160e11b815260040160405180910390fd5b60006116a26119dc565b60085490915067ffffffffffffffff808316600160401b90920416146116db57604051636fbabc7760e01b815260040160405180910390fd5b60085467ffffffffffffffff600160801b90910481169082161161171257604051630c8d9eab60e31b815260040160405180910390fd5b6000806000806000806000806117266133e4565b9050600061173261349e565b600454919650945060005b8181101561190d576004818154811061175857611758614715565b90600052602060002090600502016004015494506004818154811061177f5761177f614715565b906000526020600020906005020160010160149054906101000a900460ff1680156117cd5750600585815481106117b8576117b8614715565b90600052602060002090600502016004015487145b801561180b5750600585815481106117e7576117e7614715565b600091825260209091206001600590920201015460ff878116600160a01b90920416145b15611905576005858154811061182357611823614715565b9060005260206000209060050201600301548b611840919061486d565b9a508383604051602001611855929190614880565b60408051601f19818403018152919052805160209091012098506fffffffffffffffffffffffffffffffff808a16985061189090600161486d565b600586815481106118a3576118a3614715565b9060005260206000209060050201600301546118bf91906146ad565b6118c98c8a6146ad565b10156118f757600585815481106118e2576118e2614715565b90600052602060002090600502016000015499505b8261190181614774565b9350505b60010161173d565b505050959099149998505050505050505050565b6005818154811061193157600080fd5b6000918252602090912060059091020180546001820154600283015460038401546004909401549294506001600160a01b03821693600160a01b90920460ff169290919086565b6000806110486119dc565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff166119d257604051631d77d47760e21b815260040160405180910390fd5b6119da613657565b565b6000611588609843614701565b60006119f760026098614701565b611a026098436146ed565b10611a0d5750600190565b50600090565b611a1b6123a4565b6000611a256119dc565b6003546040516397adedb560e01b81523360048201529192506000916001600160a01b03909116906397adedb590602401602060405180830381865afa158015611a73573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a979190614648565b9050611aa1611f6d565b60ff168560ff161015611ae0576040517f83d9b7bd00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611ae86109ba565b611b1e576040517fd1088db600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60085467ffffffffffffffff838116911614611b66576040517f842a9e0a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60085467ffffffffffffffff838116600160401b9092041614611c4e57611b8b611533565b600655611b9a6005600061425e565b600880547fffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff16600160401b67ffffffffffffffff8516908102919091179091556006546040805192835260208301919091527ff0ae472da9c8da86bda4991a549c03a3cb328b5f360ea11a5b8814f32bb85176910160405180910390a1611c4e600754604080516020810192909252449082015260600160408051601f198184030181529190528051602090910120600755565b6000611c5c82878787611ff2565b90506000611c6a83836136ab565b9050600060048281548110611c8157611c81614715565b600091825260208083206040805160e08101825260059094029091018054845260018101546001600160a01b0381169385019390935260ff600160a01b84048116151592850192909252600160a81b909204166060830181905260028201546080840152600382015460a084015260049091015460c0830152909250611d07908a614694565b9050611d1a82600001516006548361223d565b611d56576006546040517f14ebbbe4000000000000000000000000000000000000000000000000000000008152600401610a7e91815260200190565b816040015115611d92576040517fa89ac15100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600160048481548110611da757611da7614715565b906000526020600020906005020160010160146101000a81548160ff02191690831515021790555060058054905060048481548110611de857611de8614715565b90600052602060002090600502016004018190555060056040518060c001604052808460000151815260200184602001516001600160a01b031681526020018b60ff16815260200184608001518152602001836002611e479190614986565b8560800151611e5691906146ad565b815260209081018b90528254600181810185556000948552938290208351600590920201908155908201519281018054604084015160ff16600160a01b0274ffffffffffffffffffffffffffffffffffffffffff199091166001600160a01b0390951694909417939093179092556060810151600280840191909155608080830151600385015560a0909201516004909301929092558351908401517f13fc17fd71632266fe82092de6dd91a06b4fa68d8dc950492e5421cbed55a6a59289929190611f23908690614986565b8660800151611f3291906146ad565b6040805167ffffffffffffffff90951685526020850193909352918301526060820152608081018a905260ff8b1660a082015260c001611520565b6008546000908190611f929067ffffffffffffffff600160801b820481169116614753565b67ffffffffffffffff169050600060fe8211611fae5781611fb1565b60fe5b611fbc906001614995565b600b5490915060ff600160a01b9091048116908216811115611fe757611fe28282614694565b611fea565b60005b935050505090565b60408051602081018690527fff0000000000000000000000000000000000000000000000000000000000000060f886901b169181019190915260418101839052606181018290526000906081015b6040516020818303038152906040528051906020012090505b949350505050565b600061206f60046098614701565b61207a6098436146ed565b1015611a0d5750600190565b6000828152602081905260409020600101546120a18161227a565b6109b58383612325565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff166120fa57604051637bfa4b9f60e01b815260040160405180910390fd5b600880547fffffffffffff0000ffffffffffffffffffffffffffffffffffffffffffffffff16600160c01b60ff958616027fffffffffffff00ffffffffffffffffffffffffffffffffffffffffffffffffff1617600160c81b93851693909302929092177fffffffffff00ffffffffffffffffffffffffffffffffffffffffffffffffffff16600160d01b9190931602919091179055565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff166121e157604051637bfa4b9f60e01b815260040160405180910390fd5b600955565b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604090205460ff1661223557604051631d77d47760e21b815260040160405180910390fd5b6119da613756565b60008160ff1660000361225257506001612273565b61226160ff83166101006149ae565b61226c9060026149c9565b8484181090505b9392505050565b612284813361378f565b50565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610a91576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556122e13390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1615610a91576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b60015460ff16156119da5760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a20706175736564000000000000000000000000000000006044820152606401610a7e565b60006124016119dc565b905061240b6119e9565b61242857604051633788c6c160e11b815260040160405180910390fd5b60085467ffffffffffffffff828116600160401b909204161461245e57604051636fbabc7760e01b815260040160405180910390fd5b60085467ffffffffffffffff600160801b90910481169082161161249557604051630c8d9eab60e31b815260040160405180910390fd5b600454604051818152600091829182918291829182917f6752c5e71c95fb93bc7137adeb115a33fa4e54e2683e33d3f90c2bb1c4b6c2a59060200160405180910390a16005546040519081527f4c03de6a759749c0c9387b7014634dc5c6af610e1366023d90751c783a998f8d9060200160405180910390a161251661349e565b6040805183815260ff831660208201529295509093507f34e8eda4cd857cd2865becf58a47748f31415f4a382cbb2cc0c64b9a27c717be910160405180910390a160006125616133e4565b905060005b8281101561294e5760006004828154811061258357612583614715565b600091825260208083206040805160e08101825260059485029092018054835260018101546001600160a01b0381169484019490945260ff600160a01b85048116151592840192909252600160a81b90930416606082015260028201546080820152600382015460a082015260049091015460c0820181905282549194509291908390811061261457612614614715565b60009182526020918290206040805160c0810182526005939093029091018054835260018101546001600160a01b03811694840194909452600160a01b90930460ff1682820152600283015460608301526003830154608083015260049092015460a082015290840151909150801561269057508060a0015188145b80156126a55750806040015160ff168760ff16145b1561279a5760808101516126b9908d61486d565b9b50848b6040516020016126ce929190614880565b60408051601f19818403018152919052805160209091012099506fffffffffffffffffffffffffffffffff808b16995061270990600161486d565b816080015161271891906146ad565b6127228d8b6146ad565b101561278c578051600a556020810151600b8054604084015160ff16600160a01b0274ffffffffffffffffffffffffffffffffffffffffff199091166001600160a01b03909316929092179190911790556060810151600c556080810151600d5560a0810151600e555b8a61279681614774565b9b50505b826040015180156127c357508060a00151881415806127c35750806040015160ff168760ff1614155b80156127e45750600854600160d01b900460ff166127e26064446146ed565b105b156128905760035460208201516001600160a01b039091169063d009b2d69061280e8a6002614986565b60085461282790609890600160c01b900460ff166146ad565b61283191906146ad565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401600060405180830381600087803b15801561287757600080fd5b505af115801561288b573d6000803e3d6000fd5b505050505b82604001516129405760035460208401516001600160a01b039091169063d009b2d6906128be8a6002614986565b6008546128d790609890600160c81b900460ff166146ad565b6128e191906146ad565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401600060405180830381600087803b15801561292757600080fd5b505af115801561293b573d6000803e3d6000fd5b505050505b836001019350505050612566565b506002546040517fffb98fe300000000000000000000000000000000000000000000000000000000815261ffff891660048201526000916001600160a01b03169063ffb98fe3906024016020604051808303816000875af11580156129b7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129db91906149e9565b905080612a1a5760405161ffff891681527f20378e5d379eabfa30444ecc5eb2b87d0d77bdbf5a58d80d008673b0ca6421419060200160405180910390a15b50506008805467ffffffffffffffff909916600160801b027fffffffffffffffff0000000000000000ffffffffffffffffffffffffffffffff9099169890981790975550505050505050565b600754600090612a78906080906146ed565b90506000612adb612a8c60a086018661478d565b80806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250505050606086013584612ad360a0890160808a01614a04565b600654613802565b60408051858152602081018390529192507f94e252069a85aa79db21f5bd8ca4e14dd3a3927aa492711017a2c8ddad95af00910160405180910390a1612b63612b24858061478d565b8080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525050505060208601358561040061397a565b600e5414612b8e5760405163755f0a2560e01b81526001600482015260248101829052604401610a7e565b612b9b60a085018561478d565b6000818110612bac57612bac614715565b90506020020135848060400190612bc3919061478d565b6000818110612bd457612bd4614715565b9050602002013514612c035760405163755f0a2560e01b81526002600482015260248101829052604401610a7e565b600080612c1360e087018761478d565b905011612c24578460200135612c59565b612c3160e086018661478d565b6000818110612c4257612c42614715565b9050602002810190612c549190614a1f565b606001355b9050612cb7612c6b604087018761478d565b80806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250505050606087013585612cb260a08a0160808b01614a04565b61397a565b8114612ce05760405163755f0a2560e01b81526003600482015260248101839052604401610a7e565b6000612cef60e087018761478d565b90501115612d275760408051602080880135908201529081018390526060016040516020818303038152906040528051906020012091505b81612d32868061478d565b6000818110612d4357612d43614715565b9050602002013514612d715760405163755f0a2560e01b815260048181015260248101839052604401610a7e565b5050505050565b6001546000908190819061010090046001600160a01b031663c81e25ab612da260c0870187614a1f565b602001356040518263ffffffff1660e01b8152600401612dc491815260200190565b60c060405180830381865afa158015612de1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e059190614a35565b509396509194509250506001600160a01b0384169050612e6557612e2c60c0850185614a1f565b602001356040517f2396d34e000000000000000000000000000000000000000000000000000000008152600401610a7e91815260200190565b6000612e88612e7760c0870187614a1f565b611610906060810190604001614a04565b90506000612e968484613ae8565b9050808263ffffffff1610612eeb57612eb260c0870187614a1f565b602001356040517f1362e4a0000000000000000000000000000000000000000000000000000000008152600401610a7e91815260200190565b6000612f1a612efd60c0890189614a1f565b612f0e906060810190604001614a04565b60201c63ffffffff1690565b90506000612f2c886020013586613b03565b63ffffffff16905067ffffffffffffffff82168114612f8b57612f5260c0890189614a1f565b602001356040517f6dd6a24f000000000000000000000000000000000000000000000000000000008152600401610a7e91815260200190565b61303187612f9c60c08b018b614a1f565b612fa69080614aa3565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050505060208b0135612fec60c08d018d614a1f565b60200135612ffd60c08e018e614a1f565b61300e906060810190604001614a04565b61301b60c08f018f614a1f565b61302c906080810190606001614a04565b613b2a565b61307b5761304260c0890189614a1f565b602001356040517fdb12fb9d000000000000000000000000000000000000000000000000000000008152600401610a7e91815260200190565b5050505050505050565b61309260e082018261478d565b905060000361309e5750565b6131bf6130ae60e083018361478d565b60008181106130bf576130bf614715565b90506020028101906130d19190614a1f565b6130df906020810190614aea565b6130ec60e084018461478d565b60008181106130fd576130fd614715565b905060200281019061310f9190614a1f565b61311d906020810190614aa3565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061315f9250505060e085018561478d565b600081811061317057613170614715565b90506020028101906131829190614a1f565b6040013561319360e086018661478d565b60008181106131a4576131a4614715565b90506020028101906131b69190614a1f565b60600135613bc1565b61322c576131d060e082018261478d565b60008181106131e1576131e1614715565b90506020028101906131f39190614a1f565b606001356040517fd740df61000000000000000000000000000000000000000000000000000000008152600401610a7e91815260200190565b60208101356132ab61324160e084018461478d565b600081811061325257613252614715565b90506020028101906132649190614a1f565b6040013561327560e085018561478d565b600081811061328657613286614715565b90506020028101906132989190614a1f565b6132a6906020810190614aea565b613c54565b14612284576132bd60e082018261478d565b60008181106132ce576132ce614715565b90506020028101906132e09190614a1f565b606001356040517f82f2469d000000000000000000000000000000000000000000000000000000008152600401610a7e91815260200190565b838510156133665781831061334157604051633d386eb360e11b815260040160405180910390fd5b80821061336157604051633588c6d360e11b815260040160405180910390fd5b612d71565b82821061338657604051633d386eb360e11b815260040160405180910390fd5b808310612d7157604051633588c6d360e11b815260040160405180910390fd5b6009548110612284576040517fb6052cdf00000000000000000000000000000000000000000000000000000000815260048101829052602401610a7e565b60606133ee6119e9565b61340b57604051633788c6c160e11b815260040160405180910390fd5b60006134156119dc565b60085490915067ffffffffffffffff808316600160401b909204161461344e57604051636fbabc7760e01b815260040160405180910390fd5b6007546040516020016134899181527f3100000000000000000000000000000000000000000000000000000000000000602082015260210190565b60405160208183030381529060405291505090565b60008060008060008060008060006134b4613ca2565b60045490915060005b8181101561364657600481815481106134d8576134d8614715565b906000526020600020906005020160010160149054906101000a900460ff161561363e576004818154811061350f5761350f614715565b90600052602060002090600502016004015493506005848154811061353657613536614715565b90600052602060002090600502016003015489613553919061486d565b98508281604051602001613568929190614880565b60408051601f19818403018152919052805160209091012097506fffffffffffffffffffffffffffffffff80891697506135a390600161486d565b600585815481106135b6576135b6614715565b9060005260206000209060050201600301546135d291906146ad565b6135dc8a896146ad565b101561363e57600584815481106135f5576135f5614715565b90600052602060002090600502016004015495506005848154811061361c5761361c614715565b906000526020600020906005020160010160149054906101000a900460ff1694505b6001016134bd565b509399929850919650505050505050565b61365f6123a4565b6001805460ff1916811790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258335b6040516001600160a01b03909116815260200160405180910390a1565b6000805b6004548110156137235783600482815481106136cd576136cd614715565b90600052602060002090600502016000015414801561370f5750600481815481106136fa576136fa614715565b90600052602060002090600502016003015483145b1561371b579050610670565b6001016136af565b506040517fd950091500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61375e613d2b565b6001805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa3361368e565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610a91576137c081613d7d565b6137cb836020613d8f565b6040516020016137dc929190614b07565b60408051601f198184030181529082905262461bcd60e51b8252610a7e91600401614b88565b60008061381187878786613f54565b905082613916856000808267ffffffffffffffff1690506008817eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff16901b600882901c7eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff161790506010817dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff16901b601082901c7dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff161790506020817bffffffff00000000ffffffff00000000ffffffff00000000ffffffff16901b602082901c7bffffffff00000000ffffffff00000000ffffffff00000000ffffffff1617905080915050919050565b826040516020016139589392919092835260c09190911b77ffffffffffffffffffffffffffffffffffffffffffffffff19166020830152602882015260480190565b6040516020818303038152906040528051906020012091505095945050505050565b600080613988868686613fca565b9050613a8c836000808267ffffffffffffffff1690506008817eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff16901b600882901c7eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff161790506010817dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff16901b601082901c7dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff161790506020817bffffffff00000000ffffffff00000000ffffffff00000000ffffffff16901b602082901c7bffffffff00000000ffffffff00000000ffffffff00000000ffffffff1617905080915050919050565b81604051602001613ac792919060c09290921b77ffffffffffffffffffffffffffffffffffffffffffffffff19168252600882015260280190565b60405160208183030381529060405280519060200120915050949350505050565b6000613af48284614694565b60ff166001901b905092915050565b600060e083901c613b15836020614694565b60ff168163ffffffff16901c91505092915050565b600080613b3986868686614032565b90506000613b94826040517f19457468657265756d205369676e6564204d6573736167653a0a3332000000006020820152603c8101829052600090605c01604051602081830303815290604052805190602001209050919050565b9050886001600160a01b0316613baa828a61407d565b6001600160a01b0316149998505050505050505050565b600080613bce84846140fc565b90506000613c29826040517f19457468657265756d205369676e6564204d6573736167653a0a3332000000006020820152603c8101829052600090605c01604051602081830303815290604052805190602001209050919050565b9050866001600160a01b0316613c3f828861407d565b6001600160a01b031614979650505050505050565b60008282604051602001613c8492919091825260601b6bffffffffffffffffffffffff1916602082015260340190565b60405160208183030381529060405280519060200120905092915050565b6060613cac6119e9565b613cc957604051633788c6c160e11b815260040160405180910390fd5b6000613cd36119dc565b60085490915067ffffffffffffffff808316600160401b9092041614613d0c57604051636fbabc7760e01b815260040160405180910390fd5b600754604051602001613489918152600360fc1b602082015260210190565b60015460ff166119da5760405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f74207061757365640000000000000000000000006044820152606401610a7e565b60606106706001600160a01b03831660145b60606000613d9e8360026146ad565b613da990600261486d565b67ffffffffffffffff811115613dc157613dc1614bbb565b6040519080825280601f01601f191660200182016040528015613deb576020820181803683370190505b509050600360fc1b81600081518110613e0657613e06614715565b60200101906001600160f81b031916908160001a9053507f780000000000000000000000000000000000000000000000000000000000000081600181518110613e5157613e51614715565b60200101906001600160f81b031916908160001a9053506000613e758460026146ad565b613e8090600161486d565b90505b6001811115613f05577f303132333435363738396162636465660000000000000000000000000000000085600f1660108110613ec157613ec1614715565b1a60f81b828281518110613ed757613ed7614715565b60200101906001600160f81b031916908160001a90535060049490941c93613efe81614bd1565b9050613e83565b5083156122735760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610a7e565b8260005b8551811015613fc1576000613f6e6002866146ed565b15613f7a576000613f7d565b60015b9050613fa483888481518110613f9557613f95614715565b60200260200101518387614118565b9250600185901c9450508080613fb990614774565b915050613f58565b50949350505050565b8160005b845181101561402a576000613fe46002856146ed565b600014905061400d83878481518110613fff57613fff614715565b602002602001015183614178565b9250600184901c935050808061402290614774565b915050613fce565b509392505050565b604080516020810186905290810184905277ffffffffffffffffffffffffffffffffffffffffffffffff1960c084811b8216606084015283901b166068820152600090607001612040565b60008060008061408c856141df565b6040805160008152602081018083528b905260ff8316918101919091526060810184905260808101839052929550909350915060019060a0016020604051602081039080840390855afa1580156140e7573d6000803e3d6000fd5b5050604051601f190151979650505050505050565b6040805160208101849052908101829052600090606001613c84565b6000821561415857604080516020810184905290810186905260608101859052608001604051602081830303815290604052805190602001209050612059565b604080516020810184905290810185905260608101869052608001612040565b600081156141b1576040805160208101869052908101849052606001604051602081830303815290604052805190602001209050612273565b5050604080516020808201939093528082019390935280518084038201815260609093019052815191012090565b6000806000835160411461421f576040517f4be6321b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50505060208101516040820151606090920151909260009190911a90565b5080546000825560050290600052602060002090810190612284919061427f565b508054600082556005029060005260206000209081019061228491906142d6565b5b808211156142d25760008082556001820180547fffffffffffffffffffff0000000000000000000000000000000000000000000016905560028201819055600382018190556004820155600501614280565b5090565b5b808211156142d257600080825560018201805474ffffffffffffffffffffffffffffffffffffffffff19169055600282018190556003820181905560048201556005016142d7565b60006020828403121561433157600080fd5b81356001600160e01b03198116811461227357600080fd5b6001600160a01b038116811461228457600080fd5b60ff8116811461228457600080fd5b6000806040838503121561438057600080fd5b823561438b81614349565b9150602083013561439b8161435e565b809150509250929050565b6000602082840312156143b857600080fd5b5035919050565b6020808252825182820181905260009190848201906040850190845b818110156144425761442f838551805182526001600160a01b03602082015116602083015260ff6040820151166040830152606081015160608301526080810151608083015260a081015160a08301525050565b9284019260c092909201916001016143db565b50909695505050505050565b6000806040838503121561446157600080fd5b82359150602083013561439b81614349565b803567ffffffffffffffff8116811461448b57600080fd5b919050565b600080604083850312156144a357600080fd5b823591506144b360208401614473565b90509250929050565b600061010082840312156144cf57600080fd5b50919050565b6000806000606084860312156144ea57600080fd5b833567ffffffffffffffff8082111561450257600080fd5b61450e878388016144bc565b9450602086013591508082111561452457600080fd5b614530878388016144bc565b9350604086013591508082111561454657600080fd5b50614553868287016144bc565b9150509250925092565b60008060006060848603121561457257600080fd5b833561457d8161435e565b95602085013595506040909401359392505050565b600080600080608085870312156145a857600080fd5b8435935060208501356145ba8161435e565b93969395505050506040820135916060013590565b6000806000606084860312156145e457600080fd5b83356145ef8161435e565b925060208401356145ff8161435e565b9150604084013561460f8161435e565b809150509250925092565b60008060006060848603121561462f57600080fd5b8335925060208401359150604084013561460f8161435e565b60006020828403121561465a57600080fd5b5051919050565b60006020828403121561467357600080fd5b81516122738161435e565b634e487b7160e01b600052601160045260246000fd5b60ff82811682821603908111156106705761067061467e565b80820281158282048414176106705761067061467e565b818103818111156106705761067061467e565b634e487b7160e01b600052601260045260246000fd5b6000826146fc576146fc6146d7565b500690565b600082614710576147106146d7565b500490565b634e487b7160e01b600052603260045260246000fd5b67ffffffffffffffff81811683821601908082111561474c5761474c61467e565b5092915050565b67ffffffffffffffff82811682821603908082111561474c5761474c61467e565b6000600182016147865761478661467e565b5060010190565b6000808335601e198436030181126147a457600080fd5b83018035915067ffffffffffffffff8211156147bf57600080fd5b6020019150600581901b36038213156147d757600080fd5b9250929050565b60005b838110156147f95781810151838201526020016147e1565b50506000910152565b600082516148148184602087016147de565b9190910192915050565b60c081016106708284805182526001600160a01b03602082015116602083015260ff6040820151166040830152606081015160608301526080810151608083015260a081015160a08301525050565b808201808211156106705761067061467e565b600083516148928184602088016147de565b9190910191825250602001919050565b600181815b808511156148dd5781600019048211156148c3576148c361467e565b808516156148d057918102915b93841c93908002906148a7565b509250929050565b6000826148f457506001610670565b8161490157506000610670565b816001811461491757600281146149215761493d565b6001915050610670565b60ff8411156149325761493261467e565b50506001821b610670565b5060208310610133831016604e8410600b8410161715614960575081810a610670565b61496a83836148a2565b806000190482111561497e5761497e61467e565b029392505050565b600061227360ff8416836148e5565b60ff81811683821601908111156106705761067061467e565b61ffff82811682821603908082111561474c5761474c61467e565b600061227361ffff8416836148e5565b8051801515811461448b57600080fd5b6000602082840312156149fb57600080fd5b612273826149d9565b600060208284031215614a1657600080fd5b61227382614473565b60008235607e1983360301811261481457600080fd5b60008060008060008060c08789031215614a4e57600080fd5b8651614a5981614349565b6020880151909650614a6a8161435e565b6040880151909550614a7b8161435e565b9350614a89606088016149d9565b92506080870151915060a087015190509295509295509295565b6000808335601e19843603018112614aba57600080fd5b83018035915067ffffffffffffffff821115614ad557600080fd5b6020019150368190038213156147d757600080fd5b600060208284031215614afc57600080fd5b813561227381614349565b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000815260008351614b3f8160178501602088016147de565b7f206973206d697373696e6720726f6c65200000000000000000000000000000006017918401918201528351614b7c8160288401602088016147de565b01602801949350505050565b6020815260008251806020840152614ba78160408501602087016147de565b601f01601f19169190910160400192915050565b634e487b7160e01b600052604160045260246000fd5b600081614be057614be061467e565b50600019019056fea2646970667358221220e6d529c753301d40b88db1b0768955eec9895788418077bb895e8f7739fb1b6964736f6c63430008130033", + "address": "0x18C415Ff11f05ae935Bc12caC0f4419440c60DE5", + "block": 7036326, + "url": "https://sepolia.etherscan.io/0x18C415Ff11f05ae935Bc12caC0f4419440c60DE5" } } }