Transaction Hash:
Block:
15260912 at Aug-02-2022 04:17:32 AM +UTC
Transaction Fee:
0.000811022392964275 ETH
$1.90
Gas Used:
78,025 Gas / 10.394391451 Gwei
Emitted Events:
| 231 |
TransparentUpgradeableProxy.0x1ff60751a354563b8db02f735046d6cecdd1ec33b27b453a7925da806b529adb( 0x1ff60751a354563b8db02f735046d6cecdd1ec33b27b453a7925da806b529adb, 0x000000000000000000000000ffc6c9fc360785e030b327fe6fdc4632941f80bd, 0000000000000000000000000000000000000000000000000000000000000002, 0000000000000000000000000000000000000000000000000000000000000002, 0000000000000000000000000000000000000000000000000000000062f086b4 )
|
Account State Difference:
| Address | Before | After | State Difference | ||
|---|---|---|---|---|---|
| 0x4B5057B2...fF2FDaCad | 182.525484042477269853 Eth | 182.534026899620126993 Eth | 0.00854285714285714 | ||
|
0x829BD824...93333A830
Miner
| (F2Pool Old) | 6,038.875019875771482788 Eth | 6,038.875136913271482788 Eth | 0.0001170375 | |
| 0xC5622f14...E5EB48568 | (StrongBlock: Node Rewards) | ||||
| 0xFFc6c9FC...2941f80BD |
0.036575622970874619 Eth
Nonce: 831
|
0.027221743435053204 Eth
Nonce: 832
| 0.009353879535821415 |
Execution Trace
ETH 0.00854285714285714
TransparentUpgradeableProxy.c290d691( )
ETH 0.00854285714285714
MultiNodeV2.pay( _nodeId=2 ) => ( 8542857142857140 )- ETH 0.00854285714285714
0x4b5057b2c87ec9e7c047fb00c0e406dff2fdacad.CALL( )
- ETH 0.00854285714285714
File 1 of 2: TransparentUpgradeableProxy
File 2 of 2: MultiNodeV2
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
// Kept for backwards compatibility with older versions of Hardhat and Truffle plugins.
contract AdminUpgradeabilityProxy is TransparentUpgradeableProxy {
constructor(address logic, address admin, bytes memory data) payable TransparentUpgradeableProxy(logic, admin, data) {}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../Proxy.sol";
import "./ERC1967Upgrade.sol";
/**
* @dev This contract implements an upgradeable proxy. It is upgradeable because calls are delegated to an
* implementation address that can be changed. This address is stored in storage in the location specified by
* https://eips.ethereum.org/EIPS/eip-1967[EIP1967], so that it doesn't conflict with the storage layout of the
* implementation behind the proxy.
*/
contract ERC1967Proxy is Proxy, ERC1967Upgrade {
/**
* @dev Initializes the upgradeable proxy with an initial implementation specified by `_logic`.
*
* If `_data` is nonempty, it's used as data in a delegate call to `_logic`. This will typically be an encoded
* function call, and allows initializating the storage of the proxy like a Solidity constructor.
*/
constructor(address _logic, bytes memory _data) payable {
assert(_IMPLEMENTATION_SLOT == bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1));
_upgradeToAndCall(_logic, _data, false);
}
/**
* @dev Returns the current implementation address.
*/
function _implementation() internal view virtual override returns (address impl) {
return ERC1967Upgrade._getImplementation();
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../ERC1967/ERC1967Proxy.sol";
/**
* @dev This contract implements a proxy that is upgradeable by an admin.
*
* To avoid https://medium.com/nomic-labs-blog/malicious-backdoors-in-ethereum-proxies-62629adf3357[proxy selector
* clashing], which can potentially be used in an attack, this contract uses the
* https://blog.openzeppelin.com/the-transparent-proxy-pattern/[transparent proxy pattern]. This pattern implies two
* things that go hand in hand:
*
* 1. If any account other than the admin calls the proxy, the call will be forwarded to the implementation, even if
* that call matches one of the admin functions exposed by the proxy itself.
* 2. If the admin calls the proxy, it can access the admin functions, but its calls will never be forwarded to the
* implementation. If the admin tries to call a function on the implementation it will fail with an error that says
* "admin cannot fallback to proxy target".
*
* These properties mean that the admin account can only be used for admin actions like upgrading the proxy or changing
* the admin, so it's best if it's a dedicated account that is not used for anything else. This will avoid headaches due
* to sudden errors when trying to call a function from the proxy implementation.
*
* Our recommendation is for the dedicated account to be an instance of the {ProxyAdmin} contract. If set up this way,
* you should think of the `ProxyAdmin` instance as the real administrative interface of your proxy.
*/
contract TransparentUpgradeableProxy is ERC1967Proxy {
/**
* @dev Initializes an upgradeable proxy managed by `_admin`, backed by the implementation at `_logic`, and
* optionally initialized with `_data` as explained in {ERC1967Proxy-constructor}.
*/
constructor(address _logic, address admin_, bytes memory _data) payable ERC1967Proxy(_logic, _data) {
assert(_ADMIN_SLOT == bytes32(uint256(keccak256("eip1967.proxy.admin")) - 1));
_changeAdmin(admin_);
}
/**
* @dev Modifier used internally that will delegate the call to the implementation unless the sender is the admin.
*/
modifier ifAdmin() {
if (msg.sender == _getAdmin()) {
_;
} else {
_fallback();
}
}
/**
* @dev Returns the current admin.
*
* NOTE: Only the admin can call this function. See {ProxyAdmin-getProxyAdmin}.
*
* TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using the
* https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
* `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103`
*/
function admin() external ifAdmin returns (address admin_) {
admin_ = _getAdmin();
}
/**
* @dev Returns the current implementation.
*
* NOTE: Only the admin can call this function. See {ProxyAdmin-getProxyImplementation}.
*
* TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using the
* https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
* `0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc`
*/
function implementation() external ifAdmin returns (address implementation_) {
implementation_ = _implementation();
}
/**
* @dev Changes the admin of the proxy.
*
* Emits an {AdminChanged} event.
*
* NOTE: Only the admin can call this function. See {ProxyAdmin-changeProxyAdmin}.
*/
function changeAdmin(address newAdmin) external virtual ifAdmin {
_changeAdmin(newAdmin);
}
/**
* @dev Upgrade the implementation of the proxy.
*
* NOTE: Only the admin can call this function. See {ProxyAdmin-upgrade}.
*/
function upgradeTo(address newImplementation) external ifAdmin {
_upgradeToAndCall(newImplementation, bytes(""), false);
}
/**
* @dev Upgrade the implementation of the proxy, and then call a function from the new implementation as specified
* by `data`, which should be an encoded function call. This is useful to initialize new storage variables in the
* proxied contract.
*
* NOTE: Only the admin can call this function. See {ProxyAdmin-upgradeAndCall}.
*/
function upgradeToAndCall(address newImplementation, bytes calldata data) external payable ifAdmin {
_upgradeToAndCall(newImplementation, data, true);
}
/**
* @dev Returns the current admin.
*/
function _admin() internal view virtual returns (address) {
return _getAdmin();
}
/**
* @dev Makes sure the admin cannot access the fallback function. See {Proxy-_beforeFallback}.
*/
function _beforeFallback() internal virtual override {
require(msg.sender != _getAdmin(), "TransparentUpgradeableProxy: admin cannot fallback to proxy target");
super._beforeFallback();
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./TransparentUpgradeableProxy.sol";
import "../../access/Ownable.sol";
/**
* @dev This is an auxiliary contract meant to be assigned as the admin of a {TransparentUpgradeableProxy}. For an
* explanation of why you would want to use this see the documentation for {TransparentUpgradeableProxy}.
*/
contract ProxyAdmin is Ownable {
/**
* @dev Returns the current implementation of `proxy`.
*
* Requirements:
*
* - This contract must be the admin of `proxy`.
*/
function getProxyImplementation(TransparentUpgradeableProxy proxy) public view virtual returns (address) {
// We need to manually run the static call since the getter cannot be flagged as view
// bytes4(keccak256("implementation()")) == 0x5c60da1b
(bool success, bytes memory returndata) = address(proxy).staticcall(hex"5c60da1b");
require(success);
return abi.decode(returndata, (address));
}
/**
* @dev Returns the current admin of `proxy`.
*
* Requirements:
*
* - This contract must be the admin of `proxy`.
*/
function getProxyAdmin(TransparentUpgradeableProxy proxy) public view virtual returns (address) {
// We need to manually run the static call since the getter cannot be flagged as view
// bytes4(keccak256("admin()")) == 0xf851a440
(bool success, bytes memory returndata) = address(proxy).staticcall(hex"f851a440");
require(success);
return abi.decode(returndata, (address));
}
/**
* @dev Changes the admin of `proxy` to `newAdmin`.
*
* Requirements:
*
* - This contract must be the current admin of `proxy`.
*/
function changeProxyAdmin(TransparentUpgradeableProxy proxy, address newAdmin) public virtual onlyOwner {
proxy.changeAdmin(newAdmin);
}
/**
* @dev Upgrades `proxy` to `implementation`. See {TransparentUpgradeableProxy-upgradeTo}.
*
* Requirements:
*
* - This contract must be the admin of `proxy`.
*/
function upgrade(TransparentUpgradeableProxy proxy, address implementation) public virtual onlyOwner {
proxy.upgradeTo(implementation);
}
/**
* @dev Upgrades `proxy` to `implementation` and calls a function on the new implementation. See
* {TransparentUpgradeableProxy-upgradeToAndCall}.
*
* Requirements:
*
* - This contract must be the admin of `proxy`.
*/
function upgradeAndCall(TransparentUpgradeableProxy proxy, address implementation, bytes memory data) public payable virtual onlyOwner {
proxy.upgradeToAndCall{value: msg.value}(implementation, data);
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM
* instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to
* be specified by overriding the virtual {_implementation} function.
*
* Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a
* different contract through the {_delegate} function.
*
* The success and return data of the delegated call will be returned back to the caller of the proxy.
*/
abstract contract Proxy {
/**
* @dev Delegates the current call to `implementation`.
*
* This function does not return to its internall call site, it will return directly to the external caller.
*/
function _delegate(address implementation) internal virtual {
// solhint-disable-next-line no-inline-assembly
assembly {
// Copy msg.data. We take full control of memory in this inline assembly
// block because it will not return to Solidity code. We overwrite the
// Solidity scratch pad at memory position 0.
calldatacopy(0, 0, calldatasize())
// Call the implementation.
// out and outsize are 0 because we don't know the size yet.
let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)
// Copy the returned data.
returndatacopy(0, 0, returndatasize())
switch result
// delegatecall returns 0 on error.
case 0 { revert(0, returndatasize()) }
default { return(0, returndatasize()) }
}
}
/**
* @dev This is a virtual function that should be overriden so it returns the address to which the fallback function
* and {_fallback} should delegate.
*/
function _implementation() internal view virtual returns (address);
/**
* @dev Delegates the current call to the address returned by `_implementation()`.
*
* This function does not return to its internall call site, it will return directly to the external caller.
*/
function _fallback() internal virtual {
_beforeFallback();
_delegate(_implementation());
}
/**
* @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other
* function in the contract matches the call data.
*/
fallback () external payable virtual {
_fallback();
}
/**
* @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if call data
* is empty.
*/
receive () external payable virtual {
_fallback();
}
/**
* @dev Hook that is called before falling back to the implementation. Can happen as part of a manual `_fallback`
* call, or as part of the Solidity `fallback` or `receive` functions.
*
* If overriden should call `super._beforeFallback()`.
*/
function _beforeFallback() internal virtual {
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;
import "../beacon/IBeacon.sol";
import "../../utils/Address.sol";
import "../../utils/StorageSlot.sol";
/**
* @dev This abstract contract provides getters and event emitting update functions for
* https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.
*
* _Available since v4.1._
*
* @custom:oz-upgrades-unsafe-allow delegatecall
*/
abstract contract ERC1967Upgrade {
// This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1
bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143;
/**
* @dev Storage slot with the address of the current implementation.
* This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is
* validated in the constructor.
*/
bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
/**
* @dev Emitted when the implementation is upgraded.
*/
event Upgraded(address indexed implementation);
/**
* @dev Returns the current implementation address.
*/
function _getImplementation() internal view returns (address) {
return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
}
/**
* @dev Stores a new address in the EIP1967 implementation slot.
*/
function _setImplementation(address newImplementation) private {
require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
}
/**
* @dev Perform implementation upgrade
*
* Emits an {Upgraded} event.
*/
function _upgradeTo(address newImplementation) internal {
_setImplementation(newImplementation);
emit Upgraded(newImplementation);
}
/**
* @dev Perform implementation upgrade with additional setup call.
*
* Emits an {Upgraded} event.
*/
function _upgradeToAndCall(address newImplementation, bytes memory data, bool forceCall) internal {
_setImplementation(newImplementation);
emit Upgraded(newImplementation);
if (data.length > 0 || forceCall) {
Address.functionDelegateCall(newImplementation, data);
}
}
/**
* @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call.
*
* Emits an {Upgraded} event.
*/
function _upgradeToAndCallSecure(address newImplementation, bytes memory data, bool forceCall) internal {
address oldImplementation = _getImplementation();
// Initial upgrade and setup call
_setImplementation(newImplementation);
if (data.length > 0 || forceCall) {
Address.functionDelegateCall(newImplementation, data);
}
// Perform rollback test if not already in progress
StorageSlot.BooleanSlot storage rollbackTesting = StorageSlot.getBooleanSlot(_ROLLBACK_SLOT);
if (!rollbackTesting.value) {
// Trigger rollback using upgradeTo from the new implementation
rollbackTesting.value = true;
Address.functionDelegateCall(
newImplementation,
abi.encodeWithSignature(
"upgradeTo(address)",
oldImplementation
)
);
rollbackTesting.value = false;
// Check rollback was effective
require(oldImplementation == _getImplementation(), "ERC1967Upgrade: upgrade breaks further upgrades");
// Finally reset to the new implementation and log the upgrade
_setImplementation(newImplementation);
emit Upgraded(newImplementation);
}
}
/**
* @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does
* not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that).
*
* Emits a {BeaconUpgraded} event.
*/
function _upgradeBeaconToAndCall(address newBeacon, bytes memory data, bool forceCall) internal {
_setBeacon(newBeacon);
emit BeaconUpgraded(newBeacon);
if (data.length > 0 || forceCall) {
Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data);
}
}
/**
* @dev Storage slot with the admin of the contract.
* This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is
* validated in the constructor.
*/
bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
/**
* @dev Emitted when the admin account has changed.
*/
event AdminChanged(address previousAdmin, address newAdmin);
/**
* @dev Returns the current admin.
*/
function _getAdmin() internal view returns (address) {
return StorageSlot.getAddressSlot(_ADMIN_SLOT).value;
}
/**
* @dev Stores a new address in the EIP1967 admin slot.
*/
function _setAdmin(address newAdmin) private {
require(newAdmin != address(0), "ERC1967: new admin is the zero address");
StorageSlot.getAddressSlot(_ADMIN_SLOT).value = newAdmin;
}
/**
* @dev Changes the admin of the proxy.
*
* Emits an {AdminChanged} event.
*/
function _changeAdmin(address newAdmin) internal {
emit AdminChanged(_getAdmin(), newAdmin);
_setAdmin(newAdmin);
}
/**
* @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
* This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor.
*/
bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;
/**
* @dev Emitted when the beacon is upgraded.
*/
event BeaconUpgraded(address indexed beacon);
/**
* @dev Returns the current beacon.
*/
function _getBeacon() internal view returns (address) {
return StorageSlot.getAddressSlot(_BEACON_SLOT).value;
}
/**
* @dev Stores a new beacon in the EIP1967 beacon slot.
*/
function _setBeacon(address newBeacon) private {
require(
Address.isContract(newBeacon),
"ERC1967: new beacon is not a contract"
);
require(
Address.isContract(IBeacon(newBeacon).implementation()),
"ERC1967: beacon implementation is not a contract"
);
StorageSlot.getAddressSlot(_BEACON_SLOT).value = newBeacon;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev This is the interface that {BeaconProxy} expects of its beacon.
*/
interface IBeacon {
/**
* @dev Must return an address that can be used as a delegate call target.
*
* {BeaconProxy} will check that this address is a contract.
*/
function implementation() external view returns (address);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
// solhint-disable-next-line no-inline-assembly
assembly { size := extcodesize(account) }
return size > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: value }(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.staticcall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.delegatecall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC1967 implementation slot:
* ```
* contract ERC1967 {
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*
* _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
assembly {
r.slot := slot
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../ERC1967/ERC1967Upgrade.sol";
/**
* @dev Base contract for building openzeppelin-upgrades compatible implementations for the {ERC1967Proxy}. It includes
* publicly available upgrade functions that are called by the plugin and by the secure upgrade mechanism to verify
* continuation of the upgradability.
*
* The {_authorizeUpgrade} function MUST be overridden to include access restriction to the upgrade mechanism.
*
* _Available since v4.1._
*/
abstract contract UUPSUpgradeable is ERC1967Upgrade {
function upgradeTo(address newImplementation) external virtual {
_authorizeUpgrade(newImplementation);
_upgradeToAndCallSecure(newImplementation, bytes(""), false);
}
function upgradeToAndCall(address newImplementation, bytes memory data) external payable virtual {
_authorizeUpgrade(newImplementation);
_upgradeToAndCallSecure(newImplementation, data, true);
}
function _authorizeUpgrade(address newImplementation) internal virtual;
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;
import "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";
abstract contract Proxiable is UUPSUpgradeable {
function _authorizeUpgrade(address newImplementation) internal override {
_beforeUpgrade(newImplementation);
}
function _beforeUpgrade(address newImplementation) internal virtual;
}
contract ChildOfProxiable is Proxiable {
function _beforeUpgrade(address newImplementation) internal virtual override {}
}
File 2 of 2: MultiNodeV2
// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
import "./interfaces/IERC20.sol";
import "./interfaces/IMultiNode.sol";
import "./interfaces/IStrongPool.sol";
import "./interfaces/IStrongNFTBonus.sol";
import "./lib/InternalCalls.sol";
import "./lib/MultiNodeSettings.sol";
import "./lib/SbMath.sol";
contract MultiNodeV2 is IMultiNode, InternalCalls, MultiNodeSettings {
uint private constant _SECONDS_IN_ONE_MINUTE = 60;
IERC20 public strongToken;
IStrongNFTBonus public strongNFTBonus;
uint public totalNodes;
uint public nodesLimit;
uint public takeStrongBips;
address payable public feeCollector;
mapping(address => bool) private serviceContractEnabled;
mapping(address => uint) public entityNodeCount;
mapping(address => uint) public entityCreditUsed;
mapping(address => mapping(uint => uint)) public entityNodeTypeCount;
mapping(bytes => uint) public entityNodeType;
mapping(bytes => uint) public entityNodeCreatedAt;
mapping(bytes => uint) public entityNodeLastPaidAt;
mapping(bytes => uint) public entityNodeLastClaimedAt;
// Events
event Created(address indexed entity, uint nodeType, uint nodeId, bool usedCredit, uint timestamp);
event Paid(address indexed entity, uint nodeType, uint nodeId, uint timestamp);
event Claimed(address indexed entity, uint nodeId, uint reward);
event MigratedFromService(address indexed service, address indexed entity, uint nodeType, uint nodeId, uint lastPaidAt);
event SetFeeCollector(address payable collector);
event SetNFTBonusContract(address strongNFTBonus);
event SetNodesLimit(uint limit);
event SetServiceContractEnabled(address service, bool enabled);
event SetTakeStrongBips(uint bips);
function init(
IERC20 _strongToken,
IStrongNFTBonus _strongNFTBonus,
address payable _feeCollector
) external onlyRole(adminControl.SUPER_ADMIN()) {
require(_feeCollector != address(0), "no address");
strongToken = _strongToken;
strongNFTBonus = _strongNFTBonus;
feeCollector = _feeCollector;
InternalCalls.init();
}
//
// Getters
// -------------------------------------------------------------------------------------------------------------------
function getRewardBalance() external view returns (uint) {
return strongToken.balanceOf(address(this));
}
function calcDecayedReward(uint _baseRate, uint _decayFactor, uint _minutesPassed) public pure returns (uint) {
uint power = SbMath._decPow(_decayFactor, _minutesPassed);
uint cumulativeFraction = SbMath.DECIMAL_PRECISION - power;
return _baseRate * cumulativeFraction / SbMath.DECIMAL_PRECISION;
}
function canNodeBePaid(address _entity, uint _nodeId) public view returns (bool) {
return doesNodeExist(_entity, _nodeId) && !hasNodeExpired(_entity, _nodeId) && !hasMaxPayments(_entity, _nodeId);
}
function doesNodeExist(address _entity, uint _nodeId) public view returns (bool) {
return entityNodeLastPaidAt[getNodeId(_entity, _nodeId)] > 0;
}
function isNodePastDue(address _entity, uint _nodeId) public view returns (bool) {
bytes memory id = getNodeId(_entity, _nodeId);
uint nodeType = entityNodeType[id];
uint lastPaidAt = entityNodeLastPaidAt[id];
return block.timestamp > (lastPaidAt + getRecurringPaymentCycle(nodeType));
}
function hasNodeExpired(address _entity, uint _nodeId) public view returns (bool) {
bytes memory id = getNodeId(_entity, _nodeId);
uint nodeType = entityNodeType[id];
uint lastPaidAt = entityNodeLastPaidAt[id];
if (lastPaidAt == 0) return true;
return block.timestamp > (lastPaidAt + getRecurringPaymentCycle(nodeType) + getGracePeriod(nodeType));
}
function hasMaxPayments(address _entity, uint _nodeId) public view returns (bool) {
bytes memory id = getNodeId(_entity, _nodeId);
uint nodeType = entityNodeType[id];
uint lastPaidAt = entityNodeLastPaidAt[id];
uint recurringPaymentCycle = getRecurringPaymentCycle(nodeType);
uint limit = block.timestamp + recurringPaymentCycle * getPayCyclesLimit(nodeType);
return lastPaidAt + recurringPaymentCycle >= limit;
}
function getNodeId(address _entity, uint _nodeId) public view returns (bytes memory) {
uint id = _nodeId != 0 ? _nodeId : entityNodeCount[_entity] + 1;
return abi.encodePacked(_entity, id);
}
function getNodeType(address _entity, uint _nodeId) public view returns (uint) {
return entityNodeType[getNodeId(_entity, _nodeId)];
}
function getNodeRecurringFee(address _entity, uint _nodeId) external view returns (uint) {
return getRecurringFeeInWei(entityNodeType[getNodeId(_entity, _nodeId)]);
}
function getNodeClaimingFee(address _entity, uint _nodeId, uint _timestamp) external view returns (uint) {
uint nodeType = entityNodeType[getNodeId(_entity, _nodeId)];
uint reward = getRewardAt(_entity, _nodeId, _timestamp);
return reward * getClaimingFeeNumerator(nodeType) / getClaimingFeeDenominator(nodeType);
}
function getNodePaidOn(address _entity, uint _nodeId) external view returns (uint) {
return entityNodeLastPaidAt[getNodeId(_entity, _nodeId)];
}
function getNodeReward(address _entity, uint _nodeId) external view returns (uint) {
return getRewardAt(_entity, _nodeId, block.timestamp);
}
function getRewardAt(address _entity, uint _nodeId, uint _timestamp) public view returns (uint) {
bytes memory id = getNodeId(_entity, _nodeId);
uint nodeType = entityNodeType[id];
uint lastClaimedAt = entityNodeLastClaimedAt[id] != 0 ? entityNodeLastClaimedAt[id] : entityNodeCreatedAt[id];
uint registeredAt = entityNodeCreatedAt[id];
if (!doesNodeExist(_entity, _nodeId)) return 0;
if (hasNodeExpired(_entity, _nodeId)) return 0;
if (_timestamp > block.timestamp) return 0;
if (_timestamp <= lastClaimedAt) return 0;
uint minutesTotal = (_timestamp - registeredAt) / _SECONDS_IN_ONE_MINUTE;
uint reward = calcDecayedReward(
getRewardBaseRate(nodeType),
getRewardDecayFactor(nodeType),
minutesTotal
);
if (lastClaimedAt > 0) {
uint minutesToLastClaim = (lastClaimedAt - registeredAt) / _SECONDS_IN_ONE_MINUTE;
uint rewardAtLastClaim = calcDecayedReward(getRewardBaseRate(nodeType), getRewardDecayFactor(nodeType), minutesToLastClaim);
reward = reward - rewardAtLastClaim;
}
uint bonus = getNftBonusAt(_entity, _nodeId, _timestamp);
return reward + bonus;
}
function getNftBonusAt(address _entity, uint _nodeId, uint _timestamp) public view returns (uint) {
if (address(strongNFTBonus) == address(0)) return 0;
bytes memory id = getNodeId(_entity, _nodeId);
uint nodeType = entityNodeType[id];
uint lastClaimedAt = entityNodeLastClaimedAt[id] != 0 ? entityNodeLastClaimedAt[id] : entityNodeCreatedAt[id];
string memory bonusName = strongNFTBonus.getStakedNftBonusName(_entity, uint128(_nodeId), address(this));
if (keccak256(abi.encode(bonusName)) == keccak256(abi.encode(""))) return 0;
uint bonusValue = getNftBonusValue(nodeType, bonusName);
return bonusValue > 0
? strongNFTBonus.getBonusValue(_entity, uint128(_nodeId), lastClaimedAt, _timestamp, bonusValue)
: 0;
}
function getEntityRewards(address _entity, uint _timestamp) public view returns (uint) {
uint reward = 0;
for (uint nodeId = 1; nodeId <= entityNodeCount[_entity]; nodeId++) {
reward = reward + getRewardAt(_entity, nodeId, _timestamp > 0 ? _timestamp : block.timestamp);
}
return reward;
}
function getEntityCreditAvailable(address _entity, uint _timestamp) public view returns (uint) {
return getEntityRewards(_entity, _timestamp) - entityCreditUsed[_entity];
}
function getNodesRecurringFee(address _entity, uint _fromNode, uint _toNode) external view returns (uint) {
uint fee = 0;
uint fromNode = _fromNode > 0 ? _fromNode : 1;
uint toNode = _toNode > 0 ? _toNode : entityNodeCount[_entity];
for (uint nodeId = fromNode; nodeId <= toNode; nodeId++) {
if (canNodeBePaid(_entity, nodeId)) fee = fee + getRecurringFeeInWei(getNodeType(_entity, nodeId));
}
return fee;
}
function getNodesClaimingFee(address _entity, uint _timestamp, uint _fromNode, uint _toNode) external view returns (uint) {
uint fee = 0;
uint fromNode = _fromNode > 0 ? _fromNode : 1;
uint toNode = _toNode > 0 ? _toNode : entityNodeCount[_entity];
for (uint nodeId = fromNode; nodeId <= toNode; nodeId++) {
uint reward = getRewardAt(_entity, nodeId, _timestamp > 0 ? _timestamp : block.timestamp);
if (reward > 0) {
uint nodeType = getNodeType(_entity, nodeId);
fee = fee + reward * getClaimingFeeNumerator(nodeType) / getClaimingFeeDenominator(nodeType);
}
}
return fee;
}
//
// Actions
// -------------------------------------------------------------------------------------------------------------------
function createNode(uint _nodeType, bool _useCredit) external payable {
uint fee = getCreatingFeeInWei(_nodeType);
uint strongFee = getStrongFeeInWei(_nodeType);
uint nodeTypeLimit = getNodesLimit(_nodeType);
require(nodeTypeActive[_nodeType], "invalid type");
require(nodesLimit == 0 || entityNodeCount[msg.sender] < nodesLimit, "over limit");
require(nodeTypeLimit == 0 || entityNodeTypeCount[msg.sender][_nodeType] < nodeTypeLimit, "over limit");
require(msg.value >= fee, "invalid fee");
uint nodeId = entityNodeCount[msg.sender] + 1;
bytes memory id = getNodeId(msg.sender, nodeId);
totalNodes = totalNodes + 1;
entityNodeType[id] = _nodeType;
entityNodeCreatedAt[id] = block.timestamp;
entityNodeLastPaidAt[id] = block.timestamp;
entityNodeCount[msg.sender] = entityNodeCount[msg.sender] + 1;
entityNodeTypeCount[msg.sender][_nodeType] = entityNodeTypeCount[msg.sender][_nodeType] + 1;
emit Created(msg.sender, _nodeType, nodeId, _useCredit, block.timestamp);
if (_useCredit) {
require(getEntityCreditAvailable(msg.sender, block.timestamp) >= strongFee, "not enough");
entityCreditUsed[msg.sender] = entityCreditUsed[msg.sender] + strongFee;
} else {
uint takeStrong = strongFee * takeStrongBips / 10000;
if (takeStrong > 0) {
require(strongToken.transferFrom(msg.sender, feeCollector, takeStrong), "transfer failed");
}
if (strongFee > takeStrong) {
require(strongToken.transferFrom(msg.sender, address(this), strongFee - takeStrong), "transfer failed");
}
}
sendValue(feeCollector, fee);
if (msg.value > fee) sendValue(payable(msg.sender), msg.value - fee);
}
function claim(uint _nodeId, uint _timestamp, address _toStrongPool) public payable returns (uint) {
address entity = msg.sender == address(strongNFTBonus) ? tx.origin : msg.sender;
bytes memory id = getNodeId(entity, _nodeId);
uint nodeType = entityNodeType[id];
uint lastClaimedAt = entityNodeLastClaimedAt[id] != 0 ? entityNodeLastClaimedAt[id] : entityNodeCreatedAt[id];
require(doesNodeExist(entity, _nodeId), "doesnt exist");
require(!hasNodeExpired(entity, _nodeId), "node expired");
require(!isNodePastDue(entity, _nodeId), "past due");
require(_timestamp <= block.timestamp, "bad timestamp");
require(lastClaimedAt + 900 < _timestamp, "too soon");
uint reward = getRewardAt(entity, _nodeId, _timestamp);
require(reward > 0, "no reward");
require(strongToken.balanceOf(address(this)) >= reward, "over balance");
uint fee = reward * getClaimingFeeNumerator(nodeType) / getClaimingFeeDenominator(nodeType);
require(msg.value >= fee, "invalid fee");
entityNodeLastClaimedAt[id] = _timestamp;
emit Claimed(entity, _nodeId, reward);
if (entityCreditUsed[msg.sender] > 0) {
if (entityCreditUsed[msg.sender] > reward) {
entityCreditUsed[msg.sender] = entityCreditUsed[msg.sender] - reward;
reward = 0;
} else {
reward = reward - entityCreditUsed[msg.sender];
entityCreditUsed[msg.sender] = 0;
}
}
if (reward > 0) {
if (_toStrongPool != address(0)) IStrongPool(_toStrongPool).mineFor(entity, reward);
else require(strongToken.transfer(entity, reward), "transfer failed");
}
sendValue(feeCollector, fee);
if (isUserCall() && msg.value > fee) sendValue(payable(msg.sender), msg.value - fee);
return fee;
}
function claimAll(uint _timestamp, address _toStrongPool, uint _fromNode, uint _toNode) external payable makesInternalCalls {
require(entityNodeCount[msg.sender] > 0, "no nodes");
uint valueLeft = msg.value;
uint fromNode = _fromNode > 0 ? _fromNode : 1;
uint toNode = _toNode > 0 ? _toNode : entityNodeCount[msg.sender];
for (uint nodeId = fromNode; nodeId <= toNode; nodeId++) {
uint reward = getRewardAt(msg.sender, nodeId, _timestamp);
if (reward > 0) {
require(valueLeft > 0, "not enough");
uint paid = claim(nodeId, _timestamp, _toStrongPool);
valueLeft = valueLeft - paid;
}
}
if (valueLeft > 0) sendValue(payable(msg.sender), valueLeft);
}
function pay(uint _nodeId) public payable returns (uint) {
bytes memory id = getNodeId(msg.sender, _nodeId);
uint nodeType = entityNodeType[id];
uint fee = getRecurringFeeInWei(nodeType);
require(canNodeBePaid(msg.sender, _nodeId), "cant pay");
require(msg.value >= fee, "invalid fee");
entityNodeLastPaidAt[id] = entityNodeLastPaidAt[id] + getRecurringPaymentCycle(nodeType);
emit Paid(msg.sender, nodeType, _nodeId, entityNodeLastPaidAt[id]);
sendValue(feeCollector, fee);
if (isUserCall() && msg.value > fee) sendValue(payable(msg.sender), msg.value - fee);
return fee;
}
function payAll(uint _fromNode, uint _toNode) external payable makesInternalCalls {
require(entityNodeCount[msg.sender] > 0, "no nodes");
uint valueLeft = msg.value;
uint fromNode = _fromNode > 0 ? _fromNode : 1;
uint toNode = _toNode > 0 ? _toNode : entityNodeCount[msg.sender];
for (uint nodeId = fromNode; nodeId <= toNode; nodeId++) {
if (!canNodeBePaid(msg.sender, nodeId)) continue;
require(valueLeft > 0, "not enough");
uint paid = pay(nodeId);
valueLeft = valueLeft - paid;
}
if (valueLeft > 0) sendValue(payable(msg.sender), valueLeft);
}
function migrateNode(address _entity, uint _nodeType, uint _lastPaidAt) external returns (uint) {
require(serviceContractEnabled[msg.sender], "no service");
require(nodeTypeActive[_nodeType], "invalid type");
uint nodeId = entityNodeCount[_entity] + 1;
bytes memory id = getNodeId(_entity, nodeId);
totalNodes = totalNodes + 1;
entityNodeType[id] = _nodeType;
entityNodeCreatedAt[id] = _lastPaidAt;
entityNodeLastPaidAt[id] = _lastPaidAt;
entityNodeCount[_entity] = entityNodeCount[_entity] + 1;
entityNodeTypeCount[_entity][_nodeType] = entityNodeTypeCount[_entity][_nodeType] + 1;
emit MigratedFromService(msg.sender, _entity, _nodeType, nodeId, _lastPaidAt);
return nodeId;
}
//
// Admin
// -------------------------------------------------------------------------------------------------------------------
function deposit(uint _amount) external onlyRole(adminControl.SUPER_ADMIN()) {
require(_amount > 0);
require(strongToken.transferFrom(msg.sender, address(this), _amount), "transfer failed");
}
function withdraw(address _destination, uint _amount) external onlyRole(adminControl.SUPER_ADMIN()) {
require(_amount > 0);
require(strongToken.balanceOf(address(this)) >= _amount, "over balance");
require(strongToken.transfer(_destination, _amount), "transfer failed");
}
function approveStrongPool(IStrongPool _strongPool, uint _amount) external onlyRole(adminControl.SUPER_ADMIN()) {
require(strongToken.approve(address(_strongPool), _amount), "approve failed");
}
function setFeeCollector(address payable _feeCollector) external onlyRole(adminControl.SUPER_ADMIN()) {
require(_feeCollector != address(0));
feeCollector = _feeCollector;
emit SetFeeCollector(_feeCollector);
}
function setNFTBonusContract(address _contract) external onlyRole(adminControl.SERVICE_ADMIN()) {
strongNFTBonus = IStrongNFTBonus(_contract);
emit SetNFTBonusContract(_contract);
}
function setNodesLimit(uint _limit) external onlyRole(adminControl.SERVICE_ADMIN()) {
nodesLimit = _limit;
emit SetNodesLimit(_limit);
}
function setServiceContractEnabled(address _contract, bool _enabled) external onlyRole(adminControl.SERVICE_ADMIN()) {
serviceContractEnabled[_contract] = _enabled;
emit SetServiceContractEnabled(_contract, _enabled);
}
function setTakeStrongBips(uint _bips) external onlyRole(adminControl.SUPER_ADMIN()) {
require(_bips <= 10000, "invalid value");
takeStrongBips = _bips;
emit SetTakeStrongBips(_bips);
}
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success,) = recipient.call{value : amount}("");
require(success, "send failed");
}
function setTokenContract(IERC20 tokenAddress) external onlyRole(adminControl.SUPER_ADMIN()) {
strongToken = tokenAddress;
}
function withdrawToken(IERC20 token, address recipient, uint256 amount) external onlyRole(adminControl.SUPER_ADMIN()) {
require(token.transfer(recipient, amount));
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0;
interface IMultiNode {
function doesNodeExist(address entity, uint nodeId) external view returns (bool);
function hasNodeExpired(address entity, uint nodeId) external view returns (bool);
function claim(uint nodeId, uint timestamp, address toStrongPool) external payable returns (uint);
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0;
interface IStrongPool {
function mineFor(address miner, uint256 amount) external;
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0;
interface IStrongNFTBonus {
function getBonus(address _entity, uint128 _nodeId, uint256 _from, uint256 _to) external view returns (uint256);
function getBonusValue(address _entity, uint128 _nodeId, uint256 _from, uint256 _to, uint256 _bonusValue) external view returns (uint256);
function getStakedNftBonusName(address _entity, uint128 _nodeId, address _serviceContract) external view returns (string memory);
function migrateNFT(address _entity, uint128 _fromNodeId, uint128 _toNodeId, address _toServiceContract) external;
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0;
import "./Context.sol";
abstract contract InternalCalls is Context {
uint private constant _NOT_MAKING_INTERNAL_CALLS = 1;
uint private constant _MAKING_INTERNAL_CALLS = 2;
uint private _internal_calls_status;
modifier makesInternalCalls() {
_internal_calls_status = _MAKING_INTERNAL_CALLS;
_;
_internal_calls_status = _NOT_MAKING_INTERNAL_CALLS;
}
function init() internal {
_internal_calls_status = _NOT_MAKING_INTERNAL_CALLS;
}
function isInternalCall() internal view returns (bool) {
return _internal_calls_status == _MAKING_INTERNAL_CALLS;
}
function isContractCall() internal view returns (bool) {
return _msgSender() != tx.origin;
}
function isUserCall() internal view returns (bool) {
return !isInternalCall() && !isContractCall();
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0;
import "./AdminAccess.sol";
contract MultiNodeSettings is AdminAccess {
uint constant public NODE_TYPE_REWARD_BASE_RATE = 0;
uint constant public NODE_TYPE_REWARD_DECAY_FACTOR = 1;
uint constant public NODE_TYPE_FEE_STRONG = 2;
uint constant public NODE_TYPE_FEE_CREATE = 3;
uint constant public NODE_TYPE_FEE_RECURRING = 4;
uint constant public NODE_TYPE_FEE_CLAIMING_NUMERATOR = 5;
uint constant public NODE_TYPE_FEE_CLAIMING_DENOMINATOR = 6;
uint constant public NODE_TYPE_RECURRING_CYCLE_SECONDS = 7;
uint constant public NODE_TYPE_GRACE_PERIOD_SECONDS = 8;
uint constant public NODE_TYPE_PAY_CYCLES_LIMIT = 9;
uint constant public NODE_TYPE_NODES_LIMIT = 10;
mapping(uint => bool) public nodeTypeActive;
mapping(uint => bool) public nodeTypeHasSettings;
mapping(uint => mapping(uint => uint)) public nodeTypeSettings;
mapping(uint => mapping(string => uint)) public nodeTypeNFTBonus;
// Events
event SetNodeTypeActive(uint nodeType, bool active);
event SetNodeTypeSetting(uint nodeType, uint settingId, uint value);
event SetNodeTypeHasSettings(uint nodeType, bool hasSettings);
event SetNodeTypeNFTBonus(uint nodeType, string bonusName, uint value);
//
// Getters
// -------------------------------------------------------------------------------------------------------------------
function getRewardBaseRate(uint _nodeType) public view returns (uint) {
return getCustomSettingOrDefaultIfZero(_nodeType, NODE_TYPE_REWARD_BASE_RATE);
}
function getRewardDecayFactor(uint _nodeType) public view returns (uint) {
return getCustomSettingOrDefaultIfZero(_nodeType, NODE_TYPE_REWARD_DECAY_FACTOR);
}
function getClaimingFeeNumerator(uint _nodeType) public view returns (uint) {
return getCustomSettingOrDefaultIfZero(_nodeType, NODE_TYPE_FEE_CLAIMING_NUMERATOR);
}
function getClaimingFeeDenominator(uint _nodeType) public view returns (uint) {
return getCustomSettingOrDefaultIfZero(_nodeType, NODE_TYPE_FEE_CLAIMING_DENOMINATOR);
}
function getCreatingFeeInWei(uint _nodeType) public view returns (uint) {
return getCustomSettingOrDefaultIfZero(_nodeType, NODE_TYPE_FEE_CREATE);
}
function getRecurringFeeInWei(uint _nodeType) public view returns (uint) {
return getCustomSettingOrDefaultIfZero(_nodeType, NODE_TYPE_FEE_RECURRING);
}
function getStrongFeeInWei(uint _nodeType) public view returns (uint) {
return getCustomSettingOrDefaultIfZero(_nodeType, NODE_TYPE_FEE_STRONG);
}
function getRecurringPaymentCycle(uint _nodeType) public view returns (uint) {
return getCustomSettingOrDefaultIfZero(_nodeType, NODE_TYPE_RECURRING_CYCLE_SECONDS);
}
function getGracePeriod(uint _nodeType) public view returns (uint) {
return getCustomSettingOrDefaultIfZero(_nodeType, NODE_TYPE_GRACE_PERIOD_SECONDS);
}
function getPayCyclesLimit(uint _nodeType) public view returns (uint) {
return getCustomSettingOrDefaultIfZero(_nodeType, NODE_TYPE_PAY_CYCLES_LIMIT);
}
function getNodesLimit(uint _nodeType) public view returns (uint) {
return getCustomSettingOrDefaultIfZero(_nodeType, NODE_TYPE_NODES_LIMIT);
}
function getNftBonusValue(uint _nodeType, string memory _bonusName) public view returns (uint) {
return nodeTypeNFTBonus[_nodeType][_bonusName] > 0
? nodeTypeNFTBonus[_nodeType][_bonusName]
: nodeTypeNFTBonus[0][_bonusName];
}
//
// Setters
// -------------------------------------------------------------------------------------------------------------------
function setNodeTypeActive(uint _nodeType, bool _active) external onlyRole(adminControl.SERVICE_ADMIN()) {
// Node type 0 is being used as a placeholder for the default settings for node types that don't have custom ones,
// So it shouldn't be activated and used to create nodes
require(_nodeType > 0, "invalid type");
nodeTypeActive[_nodeType] = _active;
emit SetNodeTypeActive(_nodeType, _active);
}
function setNodeTypeHasSettings(uint _nodeType, bool _hasSettings) external onlyRole(adminControl.SERVICE_ADMIN()) {
nodeTypeHasSettings[_nodeType] = _hasSettings;
emit SetNodeTypeHasSettings(_nodeType, _hasSettings);
}
function setNodeTypeSetting(uint _nodeType, uint _settingId, uint _value) external onlyRole(adminControl.SERVICE_ADMIN()) {
nodeTypeHasSettings[_nodeType] = true;
nodeTypeSettings[_nodeType][_settingId] = _value;
emit SetNodeTypeSetting(_nodeType, _settingId, _value);
}
function setNodeTypeNFTBonus(uint _nodeType, string memory _bonusName, uint _value) external onlyRole(adminControl.SERVICE_ADMIN()) {
nodeTypeNFTBonus[_nodeType][_bonusName] = _value;
emit SetNodeTypeNFTBonus(_nodeType, _bonusName, _value);
}
// -------------------------------------------------------------------------------------------------------------------
function getCustomSettingOrDefaultIfZero(uint _nodeType, uint _setting) internal view returns (uint) {
return nodeTypeHasSettings[_nodeType] && nodeTypeSettings[_nodeType][_setting] > 0
? nodeTypeSettings[_nodeType][_setting]
: nodeTypeSettings[0][_setting];
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
library SbMath {
uint internal constant DECIMAL_PRECISION = 1e18;
/*
* Multiply two decimal numbers and use normal rounding rules:
* -round product up if 19'th mantissa digit >= 5
* -round product down if 19'th mantissa digit < 5
*
* Used only inside the exponentiation, _decPow().
*/
function decMul(uint x, uint y) internal pure returns (uint decProd) {
uint prod_xy = x * y;
decProd = (prod_xy + (DECIMAL_PRECISION / 2)) / DECIMAL_PRECISION;
}
/*
* _decPow: Exponentiation function for 18-digit decimal base, and integer exponent n.
*
* Uses the efficient "exponentiation by squaring" algorithm. O(log(n)) complexity.
*
* The exponent is capped to avoid reverting due to overflow. The cap 525600000 equals
* "minutes in 1000 years": 60 * 24 * 365 * 1000
*/
function _decPow(uint _base, uint _minutes) internal pure returns (uint) {
if (_minutes > 525_600_000) _minutes = 525_600_000; // cap to avoid overflow
if (_minutes == 0) return DECIMAL_PRECISION;
uint y = DECIMAL_PRECISION;
uint x = _base;
uint n = _minutes;
// Exponentiation-by-squaring
while (n > 1) {
if (n % 2 == 0) {
x = decMul(x, x);
n = n / 2;
} else { // if (n % 2 != 0)
y = decMul(x, y);
x = decMul(x, x);
n = (n - 1) / 2;
}
}
return decMul(x, y);
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0;
/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with GSN meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0;
import "../interfaces/IAdminControl.sol";
abstract contract AdminAccess {
IAdminControl public adminControl;
modifier onlyRole(uint8 _role) {
require(address(adminControl) == address(0) || adminControl.hasRole(_role, msg.sender), "no access");
_;
}
function addAdminControlContract(IAdminControl _contract) external onlyRole(0) {
adminControl = _contract;
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0;
interface IAdminControl {
function hasRole(uint8 _role, address _account) external view returns (bool);
function SUPER_ADMIN() external view returns (uint8);
function ADMIN() external view returns (uint8);
function SERVICE_ADMIN() external view returns (uint8);
}