Transaction Hash:
Block:
13841868 at Dec-20-2021 11:59:28 AM +UTC
Transaction Fee:
0.008708790909655728 ETH
$18.17
Gas Used:
210,213 Gas / 41.428412656 Gwei
Emitted Events:
| 567 |
TransparentUpgradeableProxy.0x450a067d57712752555ba8fac2ec18dd15718b07539357bc1578ee837ef1422a( 0x450a067d57712752555ba8fac2ec18dd15718b07539357bc1578ee837ef1422a, 0x0000000000000000000000004da661e10ed88e3a69473bd7444d1a276c25bf42, 0000000000000000000000000000000000000000000000000000000000000002, 0000000000000000000000000000000000000000000000000000000000000001, 0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000000061c07020 )
|
| 568 |
Strong.Transfer( from=[Sender] 0x4da661e10ed88e3a69473bd7444d1a276c25bf42, to=0x4B5057B2c87Ec9e7C047fb00c0E406dfF2FDaCad, value=10000000000000000000 )
|
| 569 |
Strong.Approval( owner=[Sender] 0x4da661e10ed88e3a69473bd7444d1a276c25bf42, spender=[Receiver] TransparentUpgradeableProxy, value=115792089237316195423570985008687907853269984665640564039447584007913129639935 )
|
Account State Difference:
| Address | Before | After | State Difference | ||
|---|---|---|---|---|---|
| 0x4B5057B2...fF2FDaCad | 260.843151692728564364 Eth | 260.846751692728564364 Eth | 0.0036 | ||
| 0x4Da661E1...76C25BF42 |
0.23845545769693857 Eth
Nonce: 329
|
0.226146666787282842 Eth
Nonce: 330
| 0.012308790909655728 | ||
|
0x829BD824...93333A830
Miner
| (F2Pool Old) | 2,768.618821891151918855 Eth | 2,768.619137210651918855 Eth | 0.0003153195 | |
| 0x990f3419...87168017c | |||||
| 0xC5622f14...E5EB48568 | (StrongBlock: Node Rewards) |
Execution Trace
ETH 0.0036
TransparentUpgradeableProxy.afc9a71b( )
ETH 0.0036
MultiNodeV1.createNode( _nodeType=2, _useCredit=False )-
Strong.transferFrom( sender=0x4Da661E10Ed88e3a69473bD7444d1A276C25BF42, recipient=0x4B5057B2c87Ec9e7C047fb00c0E406dfF2FDaCad, amount=10000000000000000000 ) => ( True )
- ETH 0.0036
0x4b5057b2c87ec9e7c047fb00c0e406dff2fdacad.CALL( )
-
createNode[MultiNodeV1 (ln:176)]
getCreatingFeeInWei[MultiNodeV1 (ln:177)]getStrongFeeInWei[MultiNodeV1 (ln:178)]getNodesLimit[MultiNodeV1 (ln:179)]getNodeId[MultiNodeV1 (ln:185)]Created[MultiNodeV1 (ln:192)]getEntityCreditAvailable[MultiNodeV1 (ln:194)]getEntityRewards[MultiNodeV1 (ln:149)]getRewardAt[MultiNodeV1 (ln:144)]getNodeId[MultiNodeV1 (ln:107)]doesNodeExist[MultiNodeV1 (ln:111)]getNodeId[MultiNodeV1 (ln:62)]
hasNodeExpired[MultiNodeV1 (ln:112)]getNodeId[MultiNodeV1 (ln:71)]getRecurringPaymentCycle[MultiNodeV1 (ln:75)]getGracePeriod[MultiNodeV1 (ln:75)]
calcDecayedReward[MultiNodeV1 (ln:116)]_decPow[MultiNodeV1 (ln:54)]decMul[SbMath (ln:578)]decMul[SbMath (ln:581)]decMul[SbMath (ln:582)]decMul[SbMath (ln:586)]
getRewardBaseRate[MultiNodeV1 (ln:117)]getRewardDecayFactor[MultiNodeV1 (ln:118)]calcDecayedReward[MultiNodeV1 (ln:123)]_decPow[MultiNodeV1 (ln:54)]decMul[SbMath (ln:578)]decMul[SbMath (ln:581)]decMul[SbMath (ln:582)]decMul[SbMath (ln:586)]
getRewardBaseRate[MultiNodeV1 (ln:123)]getRewardDecayFactor[MultiNodeV1 (ln:123)]getNftBonusAt[MultiNodeV1 (ln:126)]getNodeId[MultiNodeV1 (ln:131)]getStakedNftBonusName[MultiNodeV1 (ln:134)]encode[MultiNodeV1 (ln:135)]encode[MultiNodeV1 (ln:135)]getNftBonusValue[MultiNodeV1 (ln:136)]getBonusValue[MultiNodeV1 (ln:138)]
transferFrom[MultiNodeV1 (ln:198)]transferFrom[MultiNodeV1 (ln:200)]sendValue[MultiNodeV1 (ln:203)]sendValue[MultiNodeV1 (ln:204)]payable[MultiNodeV1 (ln:204)]
File 1 of 3: TransparentUpgradeableProxy
File 2 of 3: Strong
File 3 of 3: MultiNodeV1
// 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 3: Strong
{"Address.sol":{"content":"// SPDX-License-Identifier: MIT\npragma solidity \u003e0.6.99 \u003c0.8.0;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n /**\n * @dev Returns true if `account` is a contract.\n *\n * [IMPORTANT]\n * ====\n * It is unsafe to assume that an address for which this function returns\n * false is an externally-owned account (EOA) and not a contract.\n *\n * Among others, `isContract` will return false for the following\n * types of addresses:\n *\n * - an externally-owned account\n * - a contract in construction\n * - an address where a contract will be created\n * - an address where a contract lived, but was destroyed\n * ====\n */\n function isContract(address account) internal view returns (bool) {\n // This method relies in extcodesize, which returns 0 for contracts in\n // construction, since the code is only stored at the end of the\n // constructor execution.\n\n uint256 size;\n // solhint-disable-next-line no-inline-assembly\n assembly { size := extcodesize(account) }\n return size \u003e 0;\n }\n\n /**\n * @dev Replacement for Solidity\u0027s `transfer`: sends `amount` wei to\n * `recipient`, forwarding all available gas and reverting on errors.\n *\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\n * imposed by `transfer`, making them unable to receive funds via\n * `transfer`. {sendValue} removes this limitation.\n *\n * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n *\n * IMPORTANT: because control is transferred to `recipient`, care must be\n * taken to not create reentrancy vulnerabilities. Consider using\n * {ReentrancyGuard} or the\n * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n */\n function sendValue(address payable recipient, uint256 amount) internal {\n require(address(this).balance \u003e= amount, \"Address: insufficient balance\");\n\n // solhint-disable-next-line avoid-low-level-calls, avoid-call-value\n (bool success, ) = recipient.call{ value: amount }(\"\");\n require(success, \"Address: unable to send value, recipient may have reverted\");\n }\n\n /**\n * @dev Performs a Solidity function call using a low level `call`. A\n * plain`call` is an unsafe replacement for a function call: use this\n * function instead.\n *\n * If `target` reverts with a revert reason, it is bubbled up by this\n * function (like regular Solidity function calls).\n *\n * Returns the raw returned data. To convert to the expected return value,\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n *\n * Requirements:\n *\n * - `target` must be a contract.\n * - calling `target` with `data` must not revert.\n *\n * _Available since v3.1._\n */\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionCall(target, data, \"Address: low-level call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n * `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {\n return _functionCallWithValue(target, data, 0, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but also transferring `value` wei to `target`.\n *\n * Requirements:\n *\n * - the calling contract must have an ETH balance of at least `value`.\n * - the called Solidity function must be `payable`.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n * with `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {\n require(address(this).balance \u003e= value, \"Address: insufficient balance for call\");\n return _functionCallWithValue(target, data, value, errorMessage);\n }\n\n function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {\n require(isContract(target), \"Address: call to non-contract\");\n\n // solhint-disable-next-line avoid-low-level-calls\n (bool success, bytes memory returndata) = target.call{ value: weiValue }(data);\n if (success) {\n return returndata;\n } else {\n // Look for revert reason and bubble it up if present\n if (returndata.length \u003e 0) {\n // The easiest way to bubble the revert reason is using memory via assembly\n\n // solhint-disable-next-line no-inline-assembly\n assembly {\n let returndata_size := mload(returndata)\n revert(add(32, returndata), returndata_size)\n }\n } else {\n revert(errorMessage);\n }\n }\n }\n}\n"},"Context.sol":{"content":"// SPDX-License-Identifier: MIT\npragma solidity \u003e0.6.99 \u003c0.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 GSN 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 payable) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes memory) {\n this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691\n return msg.data;\n }\n}\n"},"IERC20.sol":{"content":"// SPDX-License-Identifier: MIT\npragma solidity \u003e0.6.99 \u003c0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\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\u0027s account to `recipient`.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transfer(address recipient, 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\u0027s 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\u0027s 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 `sender` to `recipient` using the\n * allowance mechanism. `amount` is then deducted from the caller\u0027s\n * allowance.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);\n\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"},"SafeMath.sol":{"content":"// SPDX-License-Identifier: MIT\npragma solidity \u003e0.6.99 \u003c0.8.0;\n\n/**\n * @dev Wrappers over Solidity\u0027s arithmetic operations with added overflow\n * checks.\n *\n * Arithmetic operations in Solidity wrap on overflow. This can easily result\n * in bugs, because programmers usually assume that an overflow raises an\n * error, which is the standard behavior in high level programming languages.\n * `SafeMath` restores this intuition by reverting the transaction when an\n * operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it\u0027s recommended to use it always.\n */\nlibrary SafeMath {\n /**\n * @dev Returns the addition of two unsigned integers, reverting on\n * overflow.\n *\n * Counterpart to Solidity\u0027s `+` operator.\n *\n * Requirements:\n *\n * - Addition cannot overflow.\n */\n function add(uint256 a, uint256 b) internal pure returns (uint256) {\n uint256 c = a + b;\n require(c \u003e= a, \"SafeMath: addition overflow\");\n\n return c;\n }\n\n /**\n * @dev Returns the subtraction of two unsigned integers, reverting on\n * overflow (when the result is negative).\n *\n * Counterpart to Solidity\u0027s `-` operator.\n *\n * Requirements:\n *\n * - Subtraction cannot overflow.\n */\n function sub(uint256 a, uint256 b) internal pure returns (uint256) {\n return sub(a, b, \"SafeMath: subtraction overflow\");\n }\n\n /**\n * @dev Returns the subtraction of two unsigned integers, reverting with custom message on\n * overflow (when the result is negative).\n *\n * Counterpart to Solidity\u0027s `-` operator.\n *\n * Requirements:\n *\n * - Subtraction cannot overflow.\n */\n function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n require(b \u003c= a, errorMessage);\n uint256 c = a - b;\n\n return c;\n }\n\n /**\n * @dev Returns the multiplication of two unsigned integers, reverting on\n * overflow.\n *\n * Counterpart to Solidity\u0027s `*` operator.\n *\n * Requirements:\n *\n * - Multiplication cannot overflow.\n */\n function mul(uint256 a, uint256 b) internal pure returns (uint256) {\n // Gas optimization: this is cheaper than requiring \u0027a\u0027 not being zero, but the\n // benefit is lost if \u0027b\u0027 is also tested.\n // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522\n if (a == 0) {\n return 0;\n }\n\n uint256 c = a * b;\n require(c / a == b, \"SafeMath: multiplication overflow\");\n\n return c;\n }\n\n /**\n * @dev Returns the integer division of two unsigned integers. Reverts on\n * division by zero. The result is rounded towards zero.\n *\n * Counterpart to Solidity\u0027s `/` operator. Note: this function uses a\n * `revert` opcode (which leaves remaining gas untouched) while Solidity\n * uses an invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function div(uint256 a, uint256 b) internal pure returns (uint256) {\n return div(a, b, \"SafeMath: division by zero\");\n }\n\n /**\n * @dev Returns the integer division of two unsigned integers. Reverts with custom message on\n * division by zero. The result is rounded towards zero.\n *\n * Counterpart to Solidity\u0027s `/` operator. Note: this function uses a\n * `revert` opcode (which leaves remaining gas untouched) while Solidity\n * uses an invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n require(b \u003e 0, errorMessage);\n uint256 c = a / b;\n // assert(a == b * c + a % b); // There is no case in which this doesn\u0027t hold\n\n return c;\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n * Reverts when dividing by zero.\n *\n * Counterpart to Solidity\u0027s `%` operator. This function uses a `revert`\n * opcode (which leaves remaining gas untouched) while Solidity uses an\n * invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function mod(uint256 a, uint256 b) internal pure returns (uint256) {\n return mod(a, b, \"SafeMath: modulo by zero\");\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n * Reverts with custom message when dividing by zero.\n *\n * Counterpart to Solidity\u0027s `%` operator. This function uses a `revert`\n * opcode (which leaves remaining gas untouched) while Solidity uses an\n * invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n require(b != 0, errorMessage);\n return a % b;\n }\n}\n"},"Strong.sol":{"content":"// SPDX-License-Identifier: MIT\npragma solidity \u003e0.6.99 \u003c0.8.0;\n\nimport \"./Context.sol\";\nimport \"./IERC20.sol\";\nimport \"./SafeMath.sol\";\nimport \"./Address.sol\";\n\n/**\n * @dev Implementation of the {IERC20} interface.\n *\n * We have followed general OpenZeppelin guidelines: functions revert instead\n * of returning `false` on failure. This behavior is nonetheless conventional\n * and does not conflict with the expectations of ERC20 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\u0027t 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 Strong is Context, IERC20 {\n using SafeMath for uint256;\n using Address for address;\n\n mapping (address =\u003e uint256) private _balances;\n\n mapping (address =\u003e mapping (address =\u003e uint256)) private _allowances;\n\n uint256 private _totalSupply;\n\n string private _name = \"Strong\";\n string private _symbol = \"STRONG\";\n uint8 private _decimals = 18;\n\n /**\n * @dev Sets the specified balances for the specified addresses. \u0027addresses\u0027 and \u0027balances\u0027 arrays\n * are to be index aligned.\n */\n constructor (address[] memory addresses, uint[] memory balances) {\n require(addresses.length \u003e 0 \u0026\u0026 balances.length \u003e 0, \"STRONG: array length must be greater than zero\");\n require(addresses.length == balances.length, \"STRONG: arrays length mismatch\");\n\n for (uint i = 0; i \u003c addresses.length; i++) {\n _mint(addresses[i], balances[i]);\n }\n require(_totalSupply == 10000000e18, \"STRONG: totalSupply must equal 10 million\");\n }\n\n /**\n * @dev Returns the name of the token.\n */\n function name() public view 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 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 {_setupDecimals} is\n * called.\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 returns (uint8) {\n return _decimals;\n }\n\n /**\n * @dev See {IERC20-totalSupply}.\n */\n function totalSupply() public view override returns (uint256) {\n return _totalSupply;\n }\n\n /**\n * @dev See {IERC20-balanceOf}.\n */\n function balanceOf(address account) public view override returns (uint256) {\n return _balances[account];\n }\n\n /**\n * @dev See {IERC20-transfer}.\n *\n * Requirements:\n *\n * - `recipient` cannot be the zero address.\n * - the caller must have a balance of at least `amount`.\n */\n function transfer(address recipient, uint256 amount) public virtual override returns (bool) {\n _transfer(_msgSender(), recipient, 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 * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function approve(address spender, uint256 amount) public virtual override returns (bool) {\n _approve(_msgSender(), 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 * Requirements:\n * - `sender` and `recipient` cannot be the zero address.\n * - `sender` must have a balance of at least `amount`.\n * - the caller must have allowance for ``sender``\u0027s tokens of at least\n * `amount`.\n */\n function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {\n _transfer(sender, recipient, amount);\n _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, \"STRONG: transfer amount exceeds allowance\"));\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 _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(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 _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, \"STRONG: decreased allowance below zero\"));\n return true;\n }\n\n /**\n * @dev Moves tokens `amount` from `sender` to `recipient`.\n *\n * This is 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 * - `sender` cannot be the zero address.\n * - `recipient` cannot be the zero address.\n * - `sender` must have a balance of at least `amount`.\n */\n function _transfer(address sender, address recipient, uint256 amount) internal virtual {\n require(sender != address(0), \"STRONG: transfer from the zero address\");\n require(recipient != address(0), \"STRONG: transfer to the zero address\");\n\n _beforeTokenTransfer(sender, recipient, amount);\n\n _balances[sender] = _balances[sender].sub(amount, \"STRONG: transfer amount exceeds balance\");\n _balances[recipient] = _balances[recipient].add(amount);\n emit Transfer(sender, recipient, 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 * - `to` cannot be the zero address.\n */\n function _mint(address account, uint256 amount) internal virtual {\n require(account != address(0), \"STRONG: mint to the zero address\");\n\n _beforeTokenTransfer(address(0), account, amount);\n\n _totalSupply = _totalSupply.add(amount);\n _balances[account] = _balances[account].add(amount);\n emit Transfer(address(0), account, amount);\n }\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.\n *\n * This is 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(address owner, address spender, uint256 amount) internal virtual {\n require(owner != address(0), \"STRONG: approve from the zero address\");\n require(spender != address(0), \"STRONG: approve to the zero address\");\n\n _allowances[owner][spender] = amount;\n emit Approval(owner, spender, amount);\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``\u0027s tokens\n * will be to transferred to `to`.\n * - when `from` is zero, `amount` tokens will be minted for `to`.\n * - when `to` is zero, `amount` of ``from``\u0027s 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(address from, address to, uint256 amount) internal virtual { }\n}\n"}}File 3 of 3: MultiNodeV1
// 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 MultiNodeV1 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;
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");
}
}
// 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);
}