Overview
ETH Balance
0 ETH
Eth Value
$0.00View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
Loading...
Loading
Cross-Chain Transactions
Loading...
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Contract Name:
MainP1
Compiler Version
v0.8.19+commit.7dd6d404
Optimization Enabled:
Yes with 200 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "../interfaces/IMain.sol";
import "../mixins/ComponentRegistry.sol";
import "../mixins/Auth.sol";
import "../mixins/Versioned.sol";
/**
* @title Main
* @notice The center of the system around which Components orbit.
*/
// solhint-disable max-states-count
contract MainP1 is Versioned, Initializable, Auth, ComponentRegistry, UUPSUpgradeable, IMain {
IERC20 public rsr;
/// @custom:oz-upgrades-unsafe-allow constructor
// solhint-disable-next-line no-empty-blocks
constructor() initializer {}
/// Initializer
function init(
Components memory components,
IERC20 rsr_,
uint48 shortFreeze_,
uint48 longFreeze_
) public virtual initializer {
require(address(rsr_) != address(0), "invalid RSR address");
__Auth_init(shortFreeze_, longFreeze_);
__ComponentRegistry_init(components);
__UUPSUpgradeable_init();
rsr = rsr_;
emit MainInitialized();
}
/// @custom:refresher
/// @custom:interaction CEI
/// @dev Not intended to be used in production, only for equivalence with P0
function poke() external {
// == Refresher ==
assetRegistry.refresh();
// == CE block ==
if (!frozen()) furnace.melt();
stRSR.payoutRewards();
}
function hasRole(bytes32 role, address account)
public
view
override(IAccessControlUpgradeable, AccessControlUpgradeable)
returns (bool)
{
return super.hasRole(role, account);
}
// === Upgradeability ===
// solhint-disable-next-line no-empty-blocks
function _authorizeUpgrade(address newImplementation) internal override onlyRole(OWNER) {}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[49] private __gap;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface AggregatorV3Interface {
function decimals() external view returns (uint8);
function description() external view returns (string memory);
function version() external view returns (uint256);
function getRoundData(uint80 _roundId)
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
);
function latestRoundData()
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/AccessControl.sol)
pragma solidity ^0.8.0;
import "./IAccessControlUpgradeable.sol";
import "../utils/ContextUpgradeable.sol";
import "../utils/StringsUpgradeable.sol";
import "../utils/introspection/ERC165Upgradeable.sol";
import "../proxy/utils/Initializable.sol";
/**
* @dev Contract module that allows children to implement role-based access
* control mechanisms. This is a lightweight version that doesn't allow enumerating role
* members except through off-chain means by accessing the contract event logs. Some
* applications may benefit from on-chain enumerability, for those cases see
* {AccessControlEnumerable}.
*
* Roles are referred to by their `bytes32` identifier. These should be exposed
* in the external API and be unique. The best way to achieve this is by
* using `public constant` hash digests:
*
* ```
* bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
* ```
*
* Roles can be used to represent a set of permissions. To restrict access to a
* function call, use {hasRole}:
*
* ```
* function foo() public {
* require(hasRole(MY_ROLE, msg.sender));
* ...
* }
* ```
*
* Roles can be granted and revoked dynamically via the {grantRole} and
* {revokeRole} functions. Each role has an associated admin role, and only
* accounts that have a role's admin role can call {grantRole} and {revokeRole}.
*
* By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
* that only accounts with this role will be able to grant or revoke other
* roles. More complex role relationships can be created by using
* {_setRoleAdmin}.
*
* WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
* grant and revoke this role. Extra precautions should be taken to secure
* accounts that have been granted it.
*/
abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControlUpgradeable, ERC165Upgradeable {
function __AccessControl_init() internal onlyInitializing {
}
function __AccessControl_init_unchained() internal onlyInitializing {
}
struct RoleData {
mapping(address => bool) members;
bytes32 adminRole;
}
mapping(bytes32 => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
/**
* @dev Modifier that checks that an account has a specific role. Reverts
* with a standardized message including the required role.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*
* _Available since v4.1._
*/
modifier onlyRole(bytes32 role) {
_checkRole(role);
_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControlUpgradeable).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) public view virtual override returns (bool) {
return _roles[role].members[account];
}
/**
* @dev Revert with a standard message if `_msgSender()` is missing `role`.
* Overriding this function changes the behavior of the {onlyRole} modifier.
*
* Format of the revert message is described in {_checkRole}.
*
* _Available since v4.6._
*/
function _checkRole(bytes32 role) internal view virtual {
_checkRole(role, _msgSender());
}
/**
* @dev Revert with a standard message if `account` is missing `role`.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*/
function _checkRole(bytes32 role, address account) internal view virtual {
if (!hasRole(role, account)) {
revert(
string(
abi.encodePacked(
"AccessControl: account ",
StringsUpgradeable.toHexString(uint160(account), 20),
" is missing role ",
StringsUpgradeable.toHexString(uint256(role), 32)
)
)
);
}
}
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {
return _roles[role].adminRole;
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleGranted} event.
*/
function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_grantRole(role, account);
}
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleRevoked} event.
*/
function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
}
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been revoked `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*
* May emit a {RoleRevoked} event.
*/
function renounceRole(bytes32 role, address account) public virtual override {
require(account == _msgSender(), "AccessControl: can only renounce roles for self");
_revokeRole(role, account);
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event. Note that unlike {grantRole}, this function doesn't perform any
* checks on the calling account.
*
* May emit a {RoleGranted} event.
*
* [WARNING]
* ====
* This function should only be called from the constructor when setting
* up the initial roles for the system.
*
* Using this function in any other way is effectively circumventing the admin
* system imposed by {AccessControl}.
* ====
*
* NOTE: This function is deprecated in favor of {_grantRole}.
*/
function _setupRole(bytes32 role, address account) internal virtual {
_grantRole(role, account);
}
/**
* @dev Sets `adminRole` as ``role``'s admin role.
*
* Emits a {RoleAdminChanged} event.
*/
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
bytes32 previousAdminRole = getRoleAdmin(role);
_roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
/**
* @dev Grants `role` to `account`.
*
* Internal function without access restriction.
*
* May emit a {RoleGranted} event.
*/
function _grantRole(bytes32 role, address account) internal virtual {
if (!hasRole(role, account)) {
_roles[role].members[account] = true;
emit RoleGranted(role, account, _msgSender());
}
}
/**
* @dev Revokes `role` from `account`.
*
* Internal function without access restriction.
*
* May emit a {RoleRevoked} event.
*/
function _revokeRole(bytes32 role, address account) internal virtual {
if (hasRole(role, account)) {
_roles[role].members[account] = false;
emit RoleRevoked(role, account, _msgSender());
}
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[49] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)
pragma solidity ^0.8.0;
/**
* @dev External interface of AccessControl declared to support ERC165 detection.
*/
interface IAccessControlUpgradeable {
/**
* @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
*
* `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
* {RoleAdminChanged} not being emitted signaling this.
*
* _Available since v3.1._
*/
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
/**
* @dev Emitted when `account` is granted `role`.
*
* `sender` is the account that originated the contract call, an admin role
* bearer except when using {AccessControl-_setupRole}.
*/
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Emitted when `account` is revoked `role`.
*
* `sender` is the account that originated the contract call:
* - if using `revokeRole`, it is the admin role bearer
* - if using `renounceRole`, it is the role bearer (i.e. `account`)
*/
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) external view returns (bool);
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {AccessControl-_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) external view returns (bytes32);
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been granted `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*/
function renounceRole(bytes32 role, address account) external;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
function __Ownable_init() internal onlyInitializing {
__Ownable_init_unchained();
}
function __Ownable_init_unchained() internal onlyInitializing {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions 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 {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[49] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (interfaces/draft-IERC1822.sol)
pragma solidity ^0.8.0;
/**
* @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified
* proxy whose upgrades are fully controlled by the current implementation.
*/
interface IERC1822ProxiableUpgradeable {
/**
* @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation
* address.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy.
*/
function proxiableUUID() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol)
pragma solidity ^0.8.0;
/**
* @dev This is the interface that {BeaconProxy} expects of its beacon.
*/
interface IBeaconUpgradeable {
/**
* @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
// OpenZeppelin Contracts (last updated v4.5.0) (proxy/ERC1967/ERC1967Upgrade.sol)
pragma solidity ^0.8.2;
import "../beacon/IBeaconUpgradeable.sol";
import "../../interfaces/draft-IERC1822Upgradeable.sol";
import "../../utils/AddressUpgradeable.sol";
import "../../utils/StorageSlotUpgradeable.sol";
import "../utils/Initializable.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 ERC1967UpgradeUpgradeable is Initializable {
function __ERC1967Upgrade_init() internal onlyInitializing {
}
function __ERC1967Upgrade_init_unchained() internal onlyInitializing {
}
// 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 StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value;
}
/**
* @dev Stores a new address in the EIP1967 implementation slot.
*/
function _setImplementation(address newImplementation) private {
require(AddressUpgradeable.isContract(newImplementation), "ERC1967: new implementation is not a contract");
StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
}
/**
* @dev Perform implementation upgrade
*
* Emits an {Upgraded} event.
*/
function _upgradeTo(address newImplementation) internal {
_setImplementation(newImplementation);
emit Upgraded(newImplementation);
}
/**
* @dev Perform implementation upgrade with additional setup call.
*
* Emits an {Upgraded} event.
*/
function _upgradeToAndCall(
address newImplementation,
bytes memory data,
bool forceCall
) internal {
_upgradeTo(newImplementation);
if (data.length > 0 || forceCall) {
_functionDelegateCall(newImplementation, data);
}
}
/**
* @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call.
*
* Emits an {Upgraded} event.
*/
function _upgradeToAndCallUUPS(
address newImplementation,
bytes memory data,
bool forceCall
) internal {
// Upgrades from old implementations will perform a rollback test. This test requires the new
// implementation to upgrade back to the old, non-ERC1822 compliant, implementation. Removing
// this special case will break upgrade paths from old UUPS implementation to new ones.
if (StorageSlotUpgradeable.getBooleanSlot(_ROLLBACK_SLOT).value) {
_setImplementation(newImplementation);
} else {
try IERC1822ProxiableUpgradeable(newImplementation).proxiableUUID() returns (bytes32 slot) {
require(slot == _IMPLEMENTATION_SLOT, "ERC1967Upgrade: unsupported proxiableUUID");
} catch {
revert("ERC1967Upgrade: new implementation is not UUPS");
}
_upgradeToAndCall(newImplementation, data, forceCall);
}
}
/**
* @dev Storage slot with the admin of the contract.
* This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is
* validated in the constructor.
*/
bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
/**
* @dev 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 StorageSlotUpgradeable.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");
StorageSlotUpgradeable.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 StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value;
}
/**
* @dev Stores a new beacon in the EIP1967 beacon slot.
*/
function _setBeacon(address newBeacon) private {
require(AddressUpgradeable.isContract(newBeacon), "ERC1967: new beacon is not a contract");
require(
AddressUpgradeable.isContract(IBeaconUpgradeable(newBeacon).implementation()),
"ERC1967: beacon implementation is not a contract"
);
StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value = newBeacon;
}
/**
* @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does
* not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that).
*
* Emits a {BeaconUpgraded} event.
*/
function _upgradeBeaconToAndCall(
address newBeacon,
bytes memory data,
bool forceCall
) internal {
_setBeacon(newBeacon);
emit BeaconUpgraded(newBeacon);
if (data.length > 0 || forceCall) {
_functionDelegateCall(IBeaconUpgradeable(newBeacon).implementation(), data);
}
}
/**
* @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) private returns (bytes memory) {
require(AddressUpgradeable.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 AddressUpgradeable.verifyCallResult(success, returndata, "Address: low-level delegate call failed");
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[50] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.2;
import "../../utils/AddressUpgradeable.sol";
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Indicates that the contract has been initialized.
* @custom:oz-retyped-from bool
*/
uint8 private _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private _initializing;
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint8 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts. Equivalent to `reinitializer(1)`.
*/
modifier initializer() {
bool isTopLevelCall = !_initializing;
require(
(isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
"Initializable: contract is already initialized"
);
_initialized = 1;
if (isTopLevelCall) {
_initializing = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* `initializer` is equivalent to `reinitializer(1)`, so a reinitializer may be used after the original
* initialization step. This is essential to configure modules that are added through upgrades and that require
* initialization.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*/
modifier reinitializer(uint8 version) {
require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
_initialized = version;
_initializing = true;
_;
_initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
require(_initializing, "Initializable: contract is not initializing");
_;
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*/
function _disableInitializers() internal virtual {
require(!_initializing, "Initializable: contract is initializing");
if (_initialized < type(uint8).max) {
_initialized = type(uint8).max;
emit Initialized(type(uint8).max);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (proxy/utils/UUPSUpgradeable.sol)
pragma solidity ^0.8.0;
import "../../interfaces/draft-IERC1822Upgradeable.sol";
import "../ERC1967/ERC1967UpgradeUpgradeable.sol";
import "./Initializable.sol";
/**
* @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an
* {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.
*
* A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is
* reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing
* `UUPSUpgradeable` with a custom implementation of upgrades.
*
* The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
*
* _Available since v4.1._
*/
abstract contract UUPSUpgradeable is Initializable, IERC1822ProxiableUpgradeable, ERC1967UpgradeUpgradeable {
function __UUPSUpgradeable_init() internal onlyInitializing {
}
function __UUPSUpgradeable_init_unchained() internal onlyInitializing {
}
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment
address private immutable __self = address(this);
/**
* @dev Check that the execution is being performed through a delegatecall call and that the execution context is
* a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case
* for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a
* function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to
* fail.
*/
modifier onlyProxy() {
require(address(this) != __self, "Function must be called through delegatecall");
require(_getImplementation() == __self, "Function must be called through active proxy");
_;
}
/**
* @dev Check that the execution is not being performed through a delegate call. This allows a function to be
* callable on the implementing contract but not through proxies.
*/
modifier notDelegated() {
require(address(this) == __self, "UUPSUpgradeable: must not be called through delegatecall");
_;
}
/**
* @dev Implementation of the ERC1822 {proxiableUUID} function. This returns the storage slot used by the
* implementation. It is used to validate that the this implementation remains valid after an upgrade.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.
*/
function proxiableUUID() external view virtual override notDelegated returns (bytes32) {
return _IMPLEMENTATION_SLOT;
}
/**
* @dev Upgrade the implementation of the proxy to `newImplementation`.
*
* Calls {_authorizeUpgrade}.
*
* Emits an {Upgraded} event.
*/
function upgradeTo(address newImplementation) external virtual onlyProxy {
_authorizeUpgrade(newImplementation);
_upgradeToAndCallUUPS(newImplementation, new bytes(0), false);
}
/**
* @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
* encoded in `data`.
*
* Calls {_authorizeUpgrade}.
*
* Emits an {Upgraded} event.
*/
function upgradeToAndCall(address newImplementation, bytes memory data) external payable virtual onlyProxy {
_authorizeUpgrade(newImplementation);
_upgradeToAndCallUUPS(newImplementation, data, true);
}
/**
* @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
* {upgradeTo} and {upgradeToAndCall}.
*
* Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
*
* ```solidity
* function _authorizeUpgrade(address) internal override onlyOwner {}
* ```
*/
function _authorizeUpgrade(address newImplementation) internal virtual;
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[50] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
interface IERC20PermitUpgradeable {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC20Upgradeable.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20MetadataUpgradeable is IERC20Upgradeable {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20Upgradeable {
/**
* @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);
/**
* @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 `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, 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 `from` to `to` 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 from,
address to,
uint256 amount
) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library AddressUpgradeable {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://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");
(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");
(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");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract ContextUpgradeable is Initializable {
function __Context_init() internal onlyInitializing {
}
function __Context_init_unchained() internal onlyInitializing {
}
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[50] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
pragma solidity ^0.8.0;
import "./IERC165Upgradeable.sol";
import "../../proxy/utils/Initializable.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165Upgradeable is Initializable, IERC165Upgradeable {
function __ERC165_init() internal onlyInitializing {
}
function __ERC165_init_unchained() internal onlyInitializing {
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165Upgradeable).interfaceId;
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[50] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165Upgradeable {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/StorageSlot.sol)
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 StorageSlotUpgradeable {
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) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Strings.sol)
pragma solidity ^0.8.0;
/**
* @dev String operations.
*/
library StringsUpgradeable {
bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
// Inspired by OraclizeAPI's implementation - MIT licence
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
while (value != 0) {
digits -= 1;
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
value /= 10;
}
return string(buffer);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "0x00";
}
uint256 temp = value;
uint256 length = 0;
while (temp != 0) {
length++;
temp >>= 8;
}
return toHexString(value, length);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _HEX_SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @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);
/**
* @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 `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, 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 `from` to `to` 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 from,
address to,
uint256 amount
) external returns (bool);
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "../libraries/Fixed.sol";
import "./IMain.sol";
import "./IRewardable.sol";
// Not used directly in the IAsset interface, but used by many consumers to save stack space
struct Price {
uint192 low; // {UoA/tok}
uint192 high; // {UoA/tok}
}
/**
* @title IAsset
* @notice Supertype. Any token that interacts with our system must be wrapped in an asset,
* whether it is used as RToken backing or not. Any token that can report a price in the UoA
* is eligible to be an asset.
*/
interface IAsset is IRewardable {
/// Refresh saved price
/// The Reserve protocol calls this at least once per transaction, before relying on
/// the Asset's other functions.
/// @dev Called immediately after deployment, before use
function refresh() external;
/// Should not revert
/// @return low {UoA/tok} The lower end of the price estimate
/// @return high {UoA/tok} The upper end of the price estimate
function price() external view returns (uint192 low, uint192 high);
/// Should not revert
/// lotLow should be nonzero when the asset might be worth selling
/// @return lotLow {UoA/tok} The lower end of the lot price estimate
/// @return lotHigh {UoA/tok} The upper end of the lot price estimate
function lotPrice() external view returns (uint192 lotLow, uint192 lotHigh);
/// @return {tok} The balance of the ERC20 in whole tokens
function bal(address account) external view returns (uint192);
/// @return The ERC20 contract of the token with decimals() available
function erc20() external view returns (IERC20Metadata);
/// @return The number of decimals in the ERC20; just for gas optimization
function erc20Decimals() external view returns (uint8);
/// @return If the asset is an instance of ICollateral or not
function isCollateral() external view returns (bool);
/// @return {UoA} The max trade volume, in UoA
function maxTradeVolume() external view returns (uint192);
/// @return {s} The timestamp of the last refresh() that saved prices
function lastSave() external view returns (uint48);
}
// Used only in Testing. Strictly speaking an Asset does not need to adhere to this interface
interface TestIAsset is IAsset {
/// @return The address of the chainlink feed
function chainlinkFeed() external view returns (AggregatorV3Interface);
/// {1} The max % deviation allowed by the oracle
function oracleError() external view returns (uint192);
/// @return {s} Seconds that an oracle value is considered valid
function oracleTimeout() external view returns (uint48);
/// @return {s} Seconds that the lotPrice should decay over, after stale price
function priceTimeout() external view returns (uint48);
}
/// CollateralStatus must obey a linear ordering. That is:
/// - being DISABLED is worse than being IFFY, or SOUND
/// - being IFFY is worse than being SOUND.
enum CollateralStatus {
SOUND,
IFFY, // When a peg is not holding or a chainlink feed is stale
DISABLED // When the collateral has completely defaulted
}
/// Upgrade-safe maximum operator for CollateralStatus
library CollateralStatusComparator {
/// @return Whether a is worse than b
function worseThan(CollateralStatus a, CollateralStatus b) internal pure returns (bool) {
return uint256(a) > uint256(b);
}
}
/**
* @title ICollateral
* @notice A subtype of Asset that consists of the tokens eligible to back the RToken.
*/
interface ICollateral is IAsset {
/// Emitted whenever the collateral status is changed
/// @param newStatus The old CollateralStatus
/// @param newStatus The updated CollateralStatus
event CollateralStatusChanged(
CollateralStatus indexed oldStatus,
CollateralStatus indexed newStatus
);
/// @dev refresh()
/// Refresh exchange rates and update default status.
/// VERY IMPORTANT: In any valid implemntation, status() MUST become DISABLED in refresh() if
/// refPerTok() has ever decreased since last call.
/// @return The canonical name of this collateral's target unit.
function targetName() external view returns (bytes32);
/// @return The status of this collateral asset. (Is it defaulting? Might it soon?)
function status() external view returns (CollateralStatus);
// ==== Exchange Rates ====
/// @return {ref/tok} Quantity of whole reference units per whole collateral tokens
function refPerTok() external view returns (uint192);
/// @return {target/ref} Quantity of whole target units per whole reference unit in the peg
function targetPerRef() external view returns (uint192);
}
// Used only in Testing. Strictly speaking a Collateral does not need to adhere to this interface
interface TestICollateral is TestIAsset, ICollateral {
/// @return The epoch timestamp when the collateral will default from IFFY to DISABLED
function whenDefault() external view returns (uint256);
/// @return The amount of time a collateral must be in IFFY status until being DISABLED
function delayUntilDefault() external view returns (uint48);
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "./IAsset.sol";
import "./IComponent.sol";
/// A serialization of the AssetRegistry to be passed around in the P1 impl for gas optimization
struct Registry {
IERC20[] erc20s;
IAsset[] assets;
}
/**
* @title IAssetRegistry
* @notice The AssetRegistry is in charge of maintaining the ERC20 tokens eligible
* to be handled by the rest of the system. If an asset is in the registry, this means:
* 1. Its ERC20 contract has been vetted
* 2. The asset is the only asset for that ERC20
* 3. The asset can be priced in the UoA, usually via an oracle
*/
interface IAssetRegistry is IComponent {
/// Emitted when an asset is added to the registry
/// @param erc20 The ERC20 contract for the asset
/// @param asset The asset contract added to the registry
event AssetRegistered(IERC20 indexed erc20, IAsset indexed asset);
/// Emitted when an asset is removed from the registry
/// @param erc20 The ERC20 contract for the asset
/// @param asset The asset contract removed from the registry
event AssetUnregistered(IERC20 indexed erc20, IAsset indexed asset);
// Initialization
function init(IMain main_, IAsset[] memory assets_) external;
/// Fully refresh all asset state
/// @custom:interaction
function refresh() external;
/// Register `asset`
/// If either the erc20 address or the asset was already registered, fail
/// @return true if the erc20 address was not already registered.
/// @custom:governance
function register(IAsset asset) external returns (bool);
/// Register `asset` if and only if its erc20 address is already registered.
/// If the erc20 address was not registered, revert.
/// @return swapped If the asset was swapped for a previously-registered asset
/// @custom:governance
function swapRegistered(IAsset asset) external returns (bool swapped);
/// Unregister an asset, requiring that it is already registered
/// @custom:governance
function unregister(IAsset asset) external;
/// @return {s} The timestamp of the last refresh
function lastRefresh() external view returns (uint48);
/// @return The corresponding asset for ERC20, or reverts if not registered
function toAsset(IERC20 erc20) external view returns (IAsset);
/// @return The corresponding collateral, or reverts if unregistered or not collateral
function toColl(IERC20 erc20) external view returns (ICollateral);
/// @return If the ERC20 is registered
function isRegistered(IERC20 erc20) external view returns (bool);
/// @return A list of all registered ERC20s
function erc20s() external view returns (IERC20[] memory);
/// @return reg The list of registered ERC20s and Assets, in the same order
function getRegistry() external view returns (Registry memory reg);
/// @return The number of registered ERC20s
function size() external view returns (uint256);
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "./IBroker.sol";
import "./IComponent.sol";
import "./ITrading.sol";
/**
* @title IBackingManager
* @notice The BackingManager handles changes in the ERC20 balances that back an RToken.
* - It computes which trades to perform, if any, and initiates these trades with the Broker.
* - rebalance()
* - If already collateralized, excess assets are transferred to RevenueTraders.
* - forwardRevenue(IERC20[] calldata erc20s)
*/
interface IBackingManager is IComponent, ITrading {
/// Emitted when the trading delay is changed
/// @param oldVal The old trading delay
/// @param newVal The new trading delay
event TradingDelaySet(uint48 oldVal, uint48 newVal);
/// Emitted when the backing buffer is changed
/// @param oldVal The old backing buffer
/// @param newVal The new backing buffer
event BackingBufferSet(uint192 oldVal, uint192 newVal);
// Initialization
function init(
IMain main_,
uint48 tradingDelay_,
uint192 backingBuffer_,
uint192 maxTradeSlippage_,
uint192 minTradeVolume_
) external;
// Give RToken max allowance over a registered token
/// @custom:refresher
/// @custom:interaction
function grantRTokenAllowance(IERC20) external;
/// Apply the overall backing policy using the specified TradeKind, taking a haircut if unable
/// @param kind TradeKind.DUTCH_AUCTION or TradeKind.BATCH_AUCTION
/// @custom:interaction RCEI
function rebalance(TradeKind kind) external;
/// Forward revenue to RevenueTraders; reverts if not fully collateralized
/// @param erc20s The tokens to forward
/// @custom:interaction RCEI
function forwardRevenue(IERC20[] calldata erc20s) external;
}
interface TestIBackingManager is IBackingManager, TestITrading {
function tradingDelay() external view returns (uint48);
function backingBuffer() external view returns (uint192);
function setTradingDelay(uint48 val) external;
function setBackingBuffer(uint192 val) external;
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "../libraries/Fixed.sol";
import "./IAsset.sol";
import "./IComponent.sol";
struct BasketRange {
uint192 bottom; // {BU}
uint192 top; // {BU}
}
/**
* @title IBasketHandler
* @notice The BasketHandler aims to maintain a reference basket of constant target unit amounts.
* When a collateral token defaults, a new reference basket of equal target units is set.
* When _all_ collateral tokens default for a target unit, only then is the basket allowed to fall
* in terms of target unit amounts. The basket is considered defaulted in this case.
*/
interface IBasketHandler is IComponent {
/// Emitted when the prime basket is set
/// @param erc20s The collateral tokens for the prime basket
/// @param targetAmts {target/BU} A list of quantities of target unit per basket unit
/// @param targetNames Each collateral token's targetName
event PrimeBasketSet(IERC20[] erc20s, uint192[] targetAmts, bytes32[] targetNames);
/// Emitted when the reference basket is set
/// @param nonce {basketNonce} The basket nonce
/// @param erc20s The list of collateral tokens in the reference basket
/// @param refAmts {ref/BU} The reference amounts of the basket collateral tokens
/// @param disabled True when the list of erc20s + refAmts may not be correct
event BasketSet(uint256 indexed nonce, IERC20[] erc20s, uint192[] refAmts, bool disabled);
/// Emitted when a backup config is set for a target unit
/// @param targetName The name of the target unit as a bytes32
/// @param max The max number to use from `erc20s`
/// @param erc20s The set of backup collateral tokens
event BackupConfigSet(bytes32 indexed targetName, uint256 max, IERC20[] erc20s);
/// Emitted when the warmup period is changed
/// @param oldVal The old warmup period
/// @param newVal The new warmup period
event WarmupPeriodSet(uint48 oldVal, uint48 newVal);
/// Emitted when the status of a basket has changed
/// @param oldStatus The previous basket status
/// @param newStatus The new basket status
event BasketStatusChanged(CollateralStatus oldStatus, CollateralStatus newStatus);
// Initialization
function init(IMain main_, uint48 warmupPeriod_) external;
/// Set the prime basket
/// @param erc20s The collateral tokens for the new prime basket
/// @param targetAmts The target amounts (in) {target/BU} for the new prime basket
/// required range: 1e9 values; absolute range irrelevant.
/// @custom:governance
function setPrimeBasket(IERC20[] memory erc20s, uint192[] memory targetAmts) external;
/// Set the backup configuration for a given target
/// @param targetName The name of the target as a bytes32
/// @param max The maximum number of collateral tokens to use from this target
/// Required range: 1-255
/// @param erc20s A list of ordered backup collateral tokens
/// @custom:governance
function setBackupConfig(
bytes32 targetName,
uint256 max,
IERC20[] calldata erc20s
) external;
/// Default the basket in order to schedule a basket refresh
/// @custom:protected
function disableBasket() external;
/// Governance-controlled setter to cause a basket switch explicitly
/// @custom:governance
/// @custom:interaction
function refreshBasket() external;
/// Track the basket status changes
/// @custom:refresher
function trackStatus() external;
/// @return If the BackingManager has sufficient collateral to redeem the entire RToken supply
function fullyCollateralized() external view returns (bool);
/// @return status The worst CollateralStatus of all collateral in the basket
function status() external view returns (CollateralStatus status);
/// @return If the basket is ready to issue and trade
function isReady() external view returns (bool);
/// @param erc20 The ERC20 token contract for the asset
/// @return {tok/BU} The whole token quantity of token in the reference basket
/// Returns 0 if erc20 is not registered or not in the basket
/// Returns FIX_MAX (in lieu of +infinity) if Collateral.refPerTok() is 0.
/// Otherwise, returns (token's basket.refAmts / token's Collateral.refPerTok())
function quantity(IERC20 erc20) external view returns (uint192);
/// Like quantity(), but unsafe because it DOES NOT CONFIRM THAT THE ASSET IS CORRECT
/// @param erc20 The ERC20 token contract for the asset
/// @param asset The registered asset plugin contract for the erc20
/// @return {tok/BU} The whole token quantity of token in the reference basket
/// Returns 0 if erc20 is not registered or not in the basket
/// Returns FIX_MAX (in lieu of +infinity) if Collateral.refPerTok() is 0.
/// Otherwise, returns (token's basket.refAmts / token's Collateral.refPerTok())
function quantityUnsafe(IERC20 erc20, IAsset asset) external view returns (uint192);
/// @param amount {BU}
/// @return erc20s The addresses of the ERC20 tokens in the reference basket
/// @return quantities {qTok} The quantity of each ERC20 token to issue `amount` baskets
function quote(uint192 amount, RoundingMode rounding)
external
view
returns (address[] memory erc20s, uint256[] memory quantities);
/// Return the redemption value of `amount` BUs for a linear combination of historical baskets
/// @param basketNonces An array of basket nonces to do redemption from
/// @param portions {1} An array of Fix quantities that must add up to FIX_ONE
/// @param amount {BU}
/// @return erc20s The backing collateral erc20s
/// @return quantities {qTok} ERC20 token quantities equal to `amount` BUs
function quoteCustomRedemption(
uint48[] memory basketNonces,
uint192[] memory portions,
uint192 amount
) external view returns (address[] memory erc20s, uint256[] memory quantities);
/// @return top {BU} The number of partial basket units: e.g max(coll.map((c) => c.balAsBUs())
/// bottom {BU} The number of whole basket units held by the account
function basketsHeldBy(address account) external view returns (BasketRange memory);
/// Should not revert
/// @return low {UoA/BU} The lower end of the price estimate
/// @return high {UoA/BU} The upper end of the price estimate
function price() external view returns (uint192 low, uint192 high);
/// Should not revert
/// lotLow should be nonzero if a BU could be worth selling
/// @return lotLow {UoA/tok} The lower end of the lot price estimate
/// @return lotHigh {UoA/tok} The upper end of the lot price estimate
function lotPrice() external view returns (uint192 lotLow, uint192 lotHigh);
/// @return timestamp The timestamp at which the basket was last set
function timestamp() external view returns (uint48);
/// @return The current basket nonce, regardless of status
function nonce() external view returns (uint48);
}
interface TestIBasketHandler is IBasketHandler {
function warmupPeriod() external view returns (uint48);
function setWarmupPeriod(uint48 val) external;
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "./IAsset.sol";
import "./IComponent.sol";
import "./IGnosis.sol";
import "./ITrade.sol";
enum TradeKind {
DUTCH_AUCTION,
BATCH_AUCTION
}
/// Cache of all (lot) prices for a pair to prevent re-lookup
struct TradePrices {
uint192 sellLow; // {UoA/sellTok} can be 0
uint192 sellHigh; // {UoA/sellTok} should not be 0
uint192 buyLow; // {UoA/buyTok} should not be 0
uint192 buyHigh; // {UoA/buyTok} should not be 0 or FIX_MAX
}
/// The data format that describes a request for trade with the Broker
struct TradeRequest {
IAsset sell;
IAsset buy;
uint256 sellAmount; // {qSellTok}
uint256 minBuyAmount; // {qBuyTok}
}
/**
* @title IBroker
* @notice The Broker deploys oneshot Trade contracts for Traders and monitors
* the continued proper functioning of trading platforms.
*/
interface IBroker is IComponent {
event GnosisSet(IGnosis oldVal, IGnosis newVal);
event BatchTradeImplementationSet(ITrade oldVal, ITrade newVal);
event DutchTradeImplementationSet(ITrade oldVal, ITrade newVal);
event BatchAuctionLengthSet(uint48 oldVal, uint48 newVal);
event DutchAuctionLengthSet(uint48 oldVal, uint48 newVal);
event BatchTradeDisabledSet(bool prevVal, bool newVal);
event DutchTradeDisabledSet(IERC20Metadata indexed erc20, bool prevVal, bool newVal);
// Initialization
function init(
IMain main_,
IGnosis gnosis_,
ITrade batchTradeImplemention_,
uint48 batchAuctionLength_,
ITrade dutchTradeImplemention_,
uint48 dutchAuctionLength_
) external;
/// Request a trade from the broker
/// @dev Requires setting an allowance in advance
/// @custom:interaction
function openTrade(
TradeKind kind,
TradeRequest memory req,
TradePrices memory prices
) external returns (ITrade);
/// Only callable by one of the trading contracts the broker deploys
function reportViolation() external;
function batchTradeDisabled() external view returns (bool);
function dutchTradeDisabled(IERC20Metadata erc20) external view returns (bool);
}
interface TestIBroker is IBroker {
function gnosis() external view returns (IGnosis);
function batchTradeImplementation() external view returns (ITrade);
function dutchTradeImplementation() external view returns (ITrade);
function batchAuctionLength() external view returns (uint48);
function dutchAuctionLength() external view returns (uint48);
function setGnosis(IGnosis newGnosis) external;
function setBatchTradeImplementation(ITrade newTradeImplementation) external;
function setBatchAuctionLength(uint48 newAuctionLength) external;
function setDutchTradeImplementation(ITrade newTradeImplementation) external;
function setDutchAuctionLength(uint48 newAuctionLength) external;
function enableBatchTrade() external;
function enableDutchTrade(IERC20Metadata erc20) external;
// only present on pre-3.0.0 Brokers; used by EasyAuction regression test
function disabled() external view returns (bool);
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "./IMain.sol";
import "./IVersioned.sol";
/**
* @title IComponent
* @notice A Component is the central building block of all our system contracts. Components
* contain important state that must be migrated during upgrades, and they delegate
* their ownership to Main's owner.
*/
interface IComponent is IVersioned {
function main() external view returns (IMain);
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "./IComponent.sol";
uint256 constant MAX_DISTRIBUTION = 1e4; // 10,000
uint8 constant MAX_DESTINATIONS = 100; // maximum number of RevenueShare destinations
struct RevenueShare {
uint16 rTokenDist; // {revShare} A value between [0, 10,000]
uint16 rsrDist; // {revShare} A value between [0, 10,000]
}
/// Assumes no more than 100 independent distributions.
struct RevenueTotals {
uint24 rTokenTotal; // {revShare}
uint24 rsrTotal; // {revShare}
}
/**
* @title IDistributor
* @notice The Distributor Component maintains a revenue distribution table that dictates
* how to divide revenue across the Furnace, StRSR, and any other destinations.
*/
interface IDistributor is IComponent {
/// Emitted when a distribution is set
/// @param dest The address set to receive the distribution
/// @param rTokenDist The distribution of RToken that should go to `dest`
/// @param rsrDist The distribution of RSR that should go to `dest`
event DistributionSet(address indexed dest, uint16 rTokenDist, uint16 rsrDist);
/// Emitted when revenue is distributed
/// @param erc20 The token being distributed, either RSR or the RToken itself
/// @param source The address providing the revenue
/// @param amount The amount of the revenue
event RevenueDistributed(IERC20 indexed erc20, address indexed source, uint256 amount);
// Initialization
function init(IMain main_, RevenueShare memory dist) external;
/// @custom:governance
function setDistribution(address dest, RevenueShare memory share) external;
/// Distribute the `erc20` token across all revenue destinations
/// Only callable by RevenueTraders
/// @custom:protected
function distribute(IERC20 erc20, uint256 amount) external;
/// @return revTotals The total of all destinations
function totals() external view returns (RevenueTotals memory revTotals);
}
interface TestIDistributor is IDistributor {
// solhint-disable-next-line func-name-mixedcase
function FURNACE() external view returns (address);
// solhint-disable-next-line func-name-mixedcase
function ST_RSR() external view returns (address);
/// @return rTokenDist The RToken distribution for the address
/// @return rsrDist The RSR distribution for the address
function distribution(address) external view returns (uint16 rTokenDist, uint16 rsrDist);
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "../libraries/Fixed.sol";
import "./IComponent.sol";
/**
* @title IFurnace
* @notice A helper contract to burn RTokens slowly and permisionlessly.
*/
interface IFurnace is IComponent {
// Initialization
function init(IMain main_, uint192 ratio_) external;
/// Emitted when the melting ratio is changed
/// @param oldRatio The old ratio
/// @param newRatio The new ratio
event RatioSet(uint192 oldRatio, uint192 newRatio);
function ratio() external view returns (uint192);
/// Needed value range: [0, 1], granularity 1e-9
/// @custom:governance
function setRatio(uint192) external;
/// Performs any RToken melting that has vested since the last payout.
/// @custom:refresher
function melt() external;
}
interface TestIFurnace is IFurnace {
function lastPayout() external view returns (uint256);
function lastPayoutBal() external view returns (uint256);
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
struct GnosisAuctionData {
IERC20 auctioningToken;
IERC20 biddingToken;
uint256 orderCancellationEndDate;
uint256 auctionEndDate;
bytes32 initialAuctionOrder;
uint256 minimumBiddingAmountPerOrder;
uint256 interimSumBidAmount;
bytes32 interimOrder;
bytes32 clearingPriceOrder;
uint96 volumeClearingPriceOrder;
bool minFundingThresholdNotReached;
bool isAtomicClosureAllowed;
uint256 feeNumerator;
uint256 minFundingThreshold;
}
/// The relevant portion of the interface of the live Gnosis EasyAuction contract
/// https://github.com/gnosis/ido-contracts/blob/main/contracts/EasyAuction.sol
interface IGnosis {
function initiateAuction(
IERC20 auctioningToken,
IERC20 biddingToken,
uint256 orderCancellationEndDate,
uint256 auctionEndDate,
uint96 auctionedSellAmount,
uint96 minBuyAmount,
uint256 minimumBiddingAmountPerOrder,
uint256 minFundingThreshold,
bool isAtomicClosureAllowed,
address accessManagerContract,
bytes memory accessManagerContractData
) external returns (uint256 auctionId);
function auctionData(uint256 auctionId) external view returns (GnosisAuctionData memory);
/// @param auctionId The external auction id
/// @dev See here for decoding: https://git.io/JMang
/// @return encodedOrder The order, encoded in a bytes 32
function settleAuction(uint256 auctionId) external returns (bytes32 encodedOrder);
/// @return The numerator over a 1000-valued denominator
function feeNumerator() external returns (uint256);
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts-upgradeable/access/IAccessControlUpgradeable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "./IAssetRegistry.sol";
import "./IBasketHandler.sol";
import "./IBackingManager.sol";
import "./IBroker.sol";
import "./IGnosis.sol";
import "./IFurnace.sol";
import "./IDistributor.sol";
import "./IRToken.sol";
import "./IRevenueTrader.sol";
import "./IStRSR.sol";
import "./ITrading.sol";
import "./IVersioned.sol";
// === Auth roles ===
bytes32 constant OWNER = bytes32(bytes("OWNER"));
bytes32 constant SHORT_FREEZER = bytes32(bytes("SHORT_FREEZER"));
bytes32 constant LONG_FREEZER = bytes32(bytes("LONG_FREEZER"));
bytes32 constant PAUSER = bytes32(bytes("PAUSER"));
/**
* Main is a central hub that maintains a list of Component contracts.
*
* Components:
* - perform a specific function
* - defer auth to Main
* - usually (but not always) contain sizeable state that require a proxy
*/
struct Components {
// Definitely need proxy
IRToken rToken;
IStRSR stRSR;
IAssetRegistry assetRegistry;
IBasketHandler basketHandler;
IBackingManager backingManager;
IDistributor distributor;
IFurnace furnace;
IBroker broker;
IRevenueTrader rsrTrader;
IRevenueTrader rTokenTrader;
}
interface IAuth is IAccessControlUpgradeable {
/// Emitted when `unfreezeAt` is changed
/// @param oldVal The old value of `unfreezeAt`
/// @param newVal The new value of `unfreezeAt`
event UnfreezeAtSet(uint48 oldVal, uint48 newVal);
/// Emitted when the short freeze duration governance param is changed
/// @param oldDuration The old short freeze duration
/// @param newDuration The new short freeze duration
event ShortFreezeDurationSet(uint48 oldDuration, uint48 newDuration);
/// Emitted when the long freeze duration governance param is changed
/// @param oldDuration The old long freeze duration
/// @param newDuration The new long freeze duration
event LongFreezeDurationSet(uint48 oldDuration, uint48 newDuration);
/// Emitted when the system is paused or unpaused for trading
/// @param oldVal The old value of `tradingPaused`
/// @param newVal The new value of `tradingPaused`
event TradingPausedSet(bool oldVal, bool newVal);
/// Emitted when the system is paused or unpaused for issuance
/// @param oldVal The old value of `issuancePaused`
/// @param newVal The new value of `issuancePaused`
event IssuancePausedSet(bool oldVal, bool newVal);
/**
* Trading Paused: Disable everything except for OWNER actions, RToken.issue, RToken.redeem,
* StRSR.stake, and StRSR.payoutRewards
* Issuance Paused: Disable RToken.issue
* Frozen: Disable everything except for OWNER actions + StRSR.stake (for governance)
*/
function tradingPausedOrFrozen() external view returns (bool);
function issuancePausedOrFrozen() external view returns (bool);
function frozen() external view returns (bool);
function shortFreeze() external view returns (uint48);
function longFreeze() external view returns (uint48);
// ====
// onlyRole(OWNER)
function freezeForever() external;
// onlyRole(SHORT_FREEZER)
function freezeShort() external;
// onlyRole(LONG_FREEZER)
function freezeLong() external;
// onlyRole(OWNER)
function unfreeze() external;
function pauseTrading() external;
function unpauseTrading() external;
function pauseIssuance() external;
function unpauseIssuance() external;
}
interface IComponentRegistry {
// === Component setters/getters ===
event RTokenSet(IRToken indexed oldVal, IRToken indexed newVal);
function rToken() external view returns (IRToken);
event StRSRSet(IStRSR oldVal, IStRSR newVal);
function stRSR() external view returns (IStRSR);
event AssetRegistrySet(IAssetRegistry oldVal, IAssetRegistry newVal);
function assetRegistry() external view returns (IAssetRegistry);
event BasketHandlerSet(IBasketHandler oldVal, IBasketHandler newVal);
function basketHandler() external view returns (IBasketHandler);
event BackingManagerSet(IBackingManager oldVal, IBackingManager newVal);
function backingManager() external view returns (IBackingManager);
event DistributorSet(IDistributor oldVal, IDistributor newVal);
function distributor() external view returns (IDistributor);
event RSRTraderSet(IRevenueTrader oldVal, IRevenueTrader newVal);
function rsrTrader() external view returns (IRevenueTrader);
event RTokenTraderSet(IRevenueTrader oldVal, IRevenueTrader newVal);
function rTokenTrader() external view returns (IRevenueTrader);
event FurnaceSet(IFurnace oldVal, IFurnace newVal);
function furnace() external view returns (IFurnace);
event BrokerSet(IBroker oldVal, IBroker newVal);
function broker() external view returns (IBroker);
}
/**
* @title IMain
* @notice The central hub for the entire system. Maintains components and an owner singleton role
*/
interface IMain is IVersioned, IAuth, IComponentRegistry {
function poke() external; // not used in p1
// === Initialization ===
event MainInitialized();
function init(
Components memory components,
IERC20 rsr_,
uint48 shortFreeze_,
uint48 longFreeze_
) external;
function rsr() external view returns (IERC20);
}
interface TestIMain is IMain {
/// @custom:governance
function setShortFreeze(uint48) external;
/// @custom:governance
function setLongFreeze(uint48) external;
function shortFreeze() external view returns (uint48);
function longFreeze() external view returns (uint48);
function longFreezes(address account) external view returns (uint256);
function tradingPaused() external view returns (bool);
function issuancePaused() external view returns (bool);
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "./IBroker.sol";
import "./IComponent.sol";
import "./ITrading.sol";
/**
* @title IRevenueTrader
* @notice The RevenueTrader is an extension of the trading mixin that trades all
* assets at its address for a single target asset. There are two runtime instances
* of the RevenueTrader, 1 for RToken and 1 for RSR.
*/
interface IRevenueTrader is IComponent, ITrading {
// Initialization
function init(
IMain main_,
IERC20 tokenToBuy_,
uint192 maxTradeSlippage_,
uint192 minTradeVolume_
) external;
/// Distribute tokenToBuy to its destinations
/// @dev Special-case of manageTokens()
/// @custom:interaction
function distributeTokenToBuy() external;
/// Return registered ERC20s to the BackingManager if distribution for tokenToBuy is 0
/// @custom:interaction
function returnTokens(IERC20[] memory erc20s) external;
/// Process some number of tokens
/// If the tokenToBuy is included in erc20s, RevenueTrader will distribute it at end of the tx
/// @param erc20s The ERC20s to manage; can be tokenToBuy or anything registered
/// @param kinds The kinds of auctions to launch: DUTCH_AUCTION | BATCH_AUCTION
/// @custom:interaction
function manageTokens(IERC20[] memory erc20s, TradeKind[] memory kinds) external;
function tokenToBuy() external view returns (IERC20);
}
// solhint-disable-next-line no-empty-blocks
interface TestIRevenueTrader is IRevenueTrader, TestITrading {
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "./IComponent.sol";
import "./IMain.sol";
/**
* @title IRewardable
* @notice A simple interface mixin to support claiming of rewards.
*/
interface IRewardable {
/// Emitted whenever a reward token balance is claimed
event RewardsClaimed(IERC20 indexed erc20, uint256 amount);
/// Claim rewards earned by holding a balance of the ERC20 token
/// Must emit `RewardsClaimed` for each token rewards are claimed for
/// @custom:interaction
function claimRewards() external;
}
/**
* @title IRewardableComponent
* @notice A simple interface mixin to support claiming of rewards.
*/
interface IRewardableComponent is IRewardable {
/// Claim rewards for a single ERC20
/// Must emit `RewardsClaimed` for each token rewards are claimed for
/// @custom:interaction
function claimRewardsSingle(IERC20 erc20) external;
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol";
// solhint-disable-next-line max-line-length
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/draft-IERC20PermitUpgradeable.sol";
import "../libraries/Fixed.sol";
import "../libraries/Throttle.sol";
import "./IAsset.sol";
import "./IComponent.sol";
import "./IMain.sol";
import "./IRewardable.sol";
/**
* @title IRToken
* @notice An RToken is an ERC20 that is permissionlessly issuable/redeemable and tracks an
* exchange rate against a single unit: baskets, or {BU} in our type notation.
*/
interface IRToken is IComponent, IERC20MetadataUpgradeable, IERC20PermitUpgradeable {
/// Emitted when an issuance of RToken occurs, whether it occurs via slow minting or not
/// @param issuer The address holding collateral tokens
/// @param recipient The address of the recipient of the RTokens
/// @param amount The quantity of RToken being issued
/// @param baskets The corresponding number of baskets
event Issuance(
address indexed issuer,
address indexed recipient,
uint256 amount,
uint192 baskets
);
/// Emitted when a redemption of RToken occurs
/// @param redeemer The address holding RToken
/// @param recipient The address of the account receiving the backing collateral tokens
/// @param amount The quantity of RToken being redeemed
/// @param baskets The corresponding number of baskets
/// @param amount {qRTok} The amount of RTokens canceled
event Redemption(
address indexed redeemer,
address indexed recipient,
uint256 amount,
uint192 baskets
);
/// Emitted when the number of baskets needed changes
/// @param oldBasketsNeeded Previous number of baskets units needed
/// @param newBasketsNeeded New number of basket units needed
event BasketsNeededChanged(uint192 oldBasketsNeeded, uint192 newBasketsNeeded);
/// Emitted when RToken is melted, i.e the RToken supply is decreased but basketsNeeded is not
/// @param amount {qRTok}
event Melted(uint256 amount);
/// Emitted when issuance SupplyThrottle params are set
event IssuanceThrottleSet(ThrottleLib.Params oldVal, ThrottleLib.Params newVal);
/// Emitted when redemption SupplyThrottle params are set
event RedemptionThrottleSet(ThrottleLib.Params oldVal, ThrottleLib.Params newVal);
// Initialization
function init(
IMain main_,
string memory name_,
string memory symbol_,
string memory mandate_,
ThrottleLib.Params calldata issuanceThrottleParams,
ThrottleLib.Params calldata redemptionThrottleParams
) external;
/// Issue an RToken with basket collateral
/// @param amount {qRTok} The quantity of RToken to issue
/// @custom:interaction
function issue(uint256 amount) external;
/// Issue an RToken with basket collateral, to a particular recipient
/// @param recipient The address to receive the issued RTokens
/// @param amount {qRTok} The quantity of RToken to issue
/// @custom:interaction
function issueTo(address recipient, uint256 amount) external;
/// Redeem RToken for basket collateral
/// @dev Use redeemCustom for non-current baskets
/// @param amount {qRTok} The quantity {qRToken} of RToken to redeem
/// @custom:interaction
function redeem(uint256 amount) external;
/// Redeem RToken for basket collateral to a particular recipient
/// @dev Use redeemCustom for non-current baskets
/// @param recipient The address to receive the backing collateral tokens
/// @param amount {qRTok} The quantity {qRToken} of RToken to redeem
/// @custom:interaction
function redeemTo(address recipient, uint256 amount) external;
/// Redeem RToken for a linear combination of historical baskets, to a particular recipient
/// @dev Allows partial redemptions up to the minAmounts
/// @param recipient The address to receive the backing collateral tokens
/// @param amount {qRTok} The quantity {qRToken} of RToken to redeem
/// @param basketNonces An array of basket nonces to do redemption from
/// @param portions {1} An array of Fix quantities that must add up to FIX_ONE
/// @param expectedERC20sOut An array of ERC20s expected out
/// @param minAmounts {qTok} The minimum ERC20 quantities the caller should receive
/// @custom:interaction
function redeemCustom(
address recipient,
uint256 amount,
uint48[] memory basketNonces,
uint192[] memory portions,
address[] memory expectedERC20sOut,
uint256[] memory minAmounts
) external;
/// Mint an amount of RToken equivalent to baskets BUs, scaling basketsNeeded up
/// Callable only by BackingManager
/// @param baskets {BU} The number of baskets to mint RToken for
/// @custom:protected
function mint(uint192 baskets) external;
/// Melt a quantity of RToken from the caller's account
/// @param amount {qRTok} The amount to be melted
/// @custom:protected
function melt(uint256 amount) external;
/// Burn an amount of RToken from caller's account and scale basketsNeeded down
/// Callable only by BackingManager
/// @custom:protected
function dissolve(uint256 amount) external;
/// Set the number of baskets needed directly, callable only by the BackingManager
/// @param basketsNeeded {BU} The number of baskets to target
/// needed range: pretty interesting
/// @custom:protected
function setBasketsNeeded(uint192 basketsNeeded) external;
/// @return {BU} How many baskets are being targeted
function basketsNeeded() external view returns (uint192);
/// @return {qRTok} The maximum issuance that can be performed in the current block
function issuanceAvailable() external view returns (uint256);
/// @return {qRTok} The maximum redemption that can be performed in the current block
function redemptionAvailable() external view returns (uint256);
}
interface TestIRToken is IRToken {
function setIssuanceThrottleParams(ThrottleLib.Params calldata) external;
function setRedemptionThrottleParams(ThrottleLib.Params calldata) external;
function issuanceThrottleParams() external view returns (ThrottleLib.Params memory);
function redemptionThrottleParams() external view returns (ThrottleLib.Params memory);
function increaseAllowance(address, uint256) external returns (bool);
function decreaseAllowance(address, uint256) external returns (bool);
function monetizeDonations(IERC20) external;
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol";
// solhint-disable-next-line max-line-length
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/draft-IERC20PermitUpgradeable.sol";
import "../libraries/Fixed.sol";
import "./IComponent.sol";
import "./IMain.sol";
/**
* @title IStRSR
* @notice An ERC20 token representing shares of the RSR over-collateralization pool.
*
* StRSR permits the BackingManager to take RSR in times of need. In return, the BackingManager
* benefits the StRSR pool with RSR rewards purchased with a portion of its revenue.
*
* In the absence of collateral default or losses due to slippage, StRSR should have a
* monotonically increasing exchange rate with respect to RSR, meaning that over time
* StRSR is redeemable for more RSR. It is non-rebasing.
*/
interface IStRSR is IERC20MetadataUpgradeable, IERC20PermitUpgradeable, IComponent {
/// Emitted when RSR is staked
/// @param era The era at time of staking
/// @param staker The address of the staker
/// @param rsrAmount {qRSR} How much RSR was staked
/// @param stRSRAmount {qStRSR} How much stRSR was minted by this staking
event Staked(
uint256 indexed era,
address indexed staker,
uint256 rsrAmount,
uint256 stRSRAmount
);
/// Emitted when an unstaking is started
/// @param draftId The id of the draft.
/// @param draftEra The era of the draft.
/// @param staker The address of the unstaker
/// The triple (staker, draftEra, draftId) is a unique ID
/// @param rsrAmount {qRSR} How much RSR this unstaking will be worth, absent seizures
/// @param stRSRAmount {qStRSR} How much stRSR was burned by this unstaking
event UnstakingStarted(
uint256 indexed draftId,
uint256 indexed draftEra,
address indexed staker,
uint256 rsrAmount,
uint256 stRSRAmount,
uint256 availableAt
);
/// Emitted when RSR is unstaked
/// @param firstId The beginning of the range of draft IDs withdrawn in this transaction
/// @param endId The end of range of draft IDs withdrawn in this transaction
/// (ID i was withdrawn if firstId <= i < endId)
/// @param draftEra The era of the draft.
/// The triple (staker, draftEra, id) is a unique ID among drafts
/// @param staker The address of the unstaker
/// @param rsrAmount {qRSR} How much RSR this unstaking was worth
event UnstakingCompleted(
uint256 indexed firstId,
uint256 indexed endId,
uint256 draftEra,
address indexed staker,
uint256 rsrAmount
);
/// Emitted when RSR unstaking is cancelled
/// @param firstId The beginning of the range of draft IDs withdrawn in this transaction
/// @param endId The end of range of draft IDs withdrawn in this transaction
/// (ID i was withdrawn if firstId <= i < endId)
/// @param draftEra The era of the draft.
/// The triple (staker, draftEra, id) is a unique ID among drafts
/// @param staker The address of the unstaker
/// @param rsrAmount {qRSR} How much RSR this unstaking was worth
event UnstakingCancelled(
uint256 indexed firstId,
uint256 indexed endId,
uint256 draftEra,
address indexed staker,
uint256 rsrAmount
);
/// Emitted whenever the exchange rate changes
event ExchangeRateSet(uint192 oldVal, uint192 newVal);
/// Emitted whenever RSR are paids out
event RewardsPaid(uint256 rsrAmt);
/// Emitted if all the RSR in the staking pool is seized and all balances are reset to zero.
event AllBalancesReset(uint256 indexed newEra);
/// Emitted if all the RSR in the unstakin pool is seized, and all ongoing unstaking is voided.
event AllUnstakingReset(uint256 indexed newEra);
event UnstakingDelaySet(uint48 oldVal, uint48 newVal);
event RewardRatioSet(uint192 oldVal, uint192 newVal);
event WithdrawalLeakSet(uint192 oldVal, uint192 newVal);
// Initialization
function init(
IMain main_,
string memory name_,
string memory symbol_,
uint48 unstakingDelay_,
uint192 rewardRatio_,
uint192 withdrawalLeak_
) external;
/// Gather and payout rewards from rsrTrader
/// @custom:interaction
function payoutRewards() external;
/// Stakes an RSR `amount` on the corresponding RToken to earn yield and over-collateralized
/// the system
/// @param amount {qRSR}
/// @custom:interaction
function stake(uint256 amount) external;
/// Begins a delayed unstaking for `amount` stRSR
/// @param amount {qStRSR}
/// @custom:interaction
function unstake(uint256 amount) external;
/// Complete delayed unstaking for the account, up to (but not including!) `endId`
/// @custom:interaction
function withdraw(address account, uint256 endId) external;
/// Cancel unstaking for the account, up to (but not including!) `endId`
/// @custom:interaction
function cancelUnstake(uint256 endId) external;
/// Seize RSR, only callable by main.backingManager()
/// @custom:protected
function seizeRSR(uint256 amount) external;
/// Reset all stakes and advance era
/// @custom:governance
function resetStakes() external;
/// Return the maximum valid value of endId such that withdraw(endId) should immediately work
function endIdForWithdraw(address account) external view returns (uint256 endId);
/// @return {qRSR/qStRSR} The exchange rate between RSR and StRSR
function exchangeRate() external view returns (uint192);
}
interface TestIStRSR is IStRSR {
function rewardRatio() external view returns (uint192);
function setRewardRatio(uint192) external;
function unstakingDelay() external view returns (uint48);
function setUnstakingDelay(uint48) external;
function withdrawalLeak() external view returns (uint192);
function setWithdrawalLeak(uint192) external;
function increaseAllowance(address, uint256) external returns (bool);
function decreaseAllowance(address, uint256) external returns (bool);
/// @return {qStRSR/qRSR} The exchange rate between StRSR and RSR
function exchangeRate() external view returns (uint192);
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "./IBroker.sol";
enum TradeStatus {
NOT_STARTED, // before init()
OPEN, // after init() and before settle()
CLOSED, // after settle()
// === Intermediate-tx state ===
PENDING // during init() or settle() (reentrancy protection)
}
/**
* Simple generalized trading interface for all Trade contracts to obey
*
* Usage: if (canSettle()) settle()
*/
interface ITrade {
/// Complete the trade and transfer tokens back to the origin trader
/// @return soldAmt {qSellTok} The quantity of tokens sold
/// @return boughtAmt {qBuyTok} The quantity of tokens bought
function settle() external returns (uint256 soldAmt, uint256 boughtAmt);
function sell() external view returns (IERC20Metadata);
function buy() external view returns (IERC20Metadata);
/// @return The timestamp at which the trade is projected to become settle-able
function endTime() external view returns (uint48);
/// @return True if the trade can be settled
/// @dev Should be guaranteed to be true eventually as an invariant
function canSettle() external view returns (bool);
/// @return TradeKind.DUTCH_AUCTION or TradeKind.BATCH_AUCTION
// solhint-disable-next-line func-name-mixedcase
function KIND() external view returns (TradeKind);
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "../libraries/Fixed.sol";
import "./IAsset.sol";
import "./IComponent.sol";
import "./ITrade.sol";
import "./IRewardable.sol";
/**
* @title ITrading
* @notice Common events and refresher function for all Trading contracts
*/
interface ITrading is IComponent, IRewardableComponent {
event MaxTradeSlippageSet(uint192 oldVal, uint192 newVal);
event MinTradeVolumeSet(uint192 oldVal, uint192 newVal);
/// Emitted when a trade is started
/// @param trade The one-time-use trade contract that was just deployed
/// @param sell The token to sell
/// @param buy The token to buy
/// @param sellAmount {qSellTok} The quantity of the selling token
/// @param minBuyAmount {qBuyTok} The minimum quantity of the buying token to accept
event TradeStarted(
ITrade indexed trade,
IERC20 indexed sell,
IERC20 indexed buy,
uint256 sellAmount,
uint256 minBuyAmount
);
/// Emitted after a trade ends
/// @param trade The one-time-use trade contract
/// @param sell The token to sell
/// @param buy The token to buy
/// @param sellAmount {qSellTok} The quantity of the token sold
/// @param buyAmount {qBuyTok} The quantity of the token bought
event TradeSettled(
ITrade indexed trade,
IERC20 indexed sell,
IERC20 indexed buy,
uint256 sellAmount,
uint256 buyAmount
);
/// Settle a single trade, expected to be used with multicall for efficient mass settlement
/// @param sell The sell token in the trade
/// @return The trade settled
/// @custom:refresher
function settleTrade(IERC20 sell) external returns (ITrade);
/// @return {%} The maximum trade slippage acceptable
function maxTradeSlippage() external view returns (uint192);
/// @return {UoA} The minimum trade volume in UoA, applies to all assets
function minTradeVolume() external view returns (uint192);
/// @return The ongoing trade for a sell token, or the zero address
function trades(IERC20 sell) external view returns (ITrade);
/// @return The number of ongoing trades open
function tradesOpen() external view returns (uint48);
/// @return The number of total trades ever opened
function tradesNonce() external view returns (uint256);
}
interface TestITrading is ITrading {
/// @custom:governance
function setMaxTradeSlippage(uint192 val) external;
/// @custom:governance
function setMinTradeVolume(uint192 val) external;
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
interface IVersioned {
function version() external view returns (string memory);
}// SPDX-License-Identifier: BlueOak-1.0.0 // solhint-disable func-name-mixedcase func-visibility pragma solidity ^0.8.19; /// @title FixedPoint, a fixed-point arithmetic library defining the custom type uint192 /// @author Matt Elder <[email protected]> and the Reserve Team <https://reserve.org> /** The logical type `uint192 ` is a 192 bit value, representing an 18-decimal Fixed-point fractional value. This is what's described in the Solidity documentation as "fixed192x18" -- a value represented by 192 bits, that makes 18 digits available to the right of the decimal point. The range of values that uint192 can represent is about [-1.7e20, 1.7e20]. Unless a function explicitly says otherwise, it will fail on overflow. To be clear, the following should hold: toFix(0) == 0 toFix(1) == 1e18 */ // Analysis notes: // Every function should revert iff its result is out of bounds. // Unless otherwise noted, when a rounding mode is given, that mode is applied to // a single division that may happen as the last step in the computation. // Unless otherwise noted, when a rounding mode is *not* given but is needed, it's FLOOR. // For each, we comment: // - @return is the value expressed in "value space", where uint192(1e18) "is" 1.0 // - as-ints: is the value expressed in "implementation space", where uint192(1e18) "is" 1e18 // The "@return" expression is suitable for actually using the library // The "as-ints" expression is suitable for testing // A uint value passed to this library was out of bounds for uint192 operations error UIntOutOfBounds(); bytes32 constant UIntOutofBoundsHash = keccak256(abi.encodeWithSignature("UIntOutOfBounds()")); // Used by P1 implementation for easier casting uint256 constant FIX_ONE_256 = 1e18; uint8 constant FIX_DECIMALS = 18; // If a particular uint192 is represented by the uint192 n, then the uint192 represents the // value n/FIX_SCALE. uint64 constant FIX_SCALE = 1e18; // FIX_SCALE Squared: uint128 constant FIX_SCALE_SQ = 1e36; // The largest integer that can be converted to uint192 . // This is a bit bigger than 3.1e39 uint192 constant FIX_MAX_INT = type(uint192).max / FIX_SCALE; uint192 constant FIX_ZERO = 0; // The uint192 representation of zero. uint192 constant FIX_ONE = FIX_SCALE; // The uint192 representation of one. uint192 constant FIX_MAX = type(uint192).max; // The largest uint192. (Not an integer!) uint192 constant FIX_MIN = 0; // The smallest uint192. /// An enum that describes a rounding approach for converting to ints enum RoundingMode { FLOOR, // Round towards zero ROUND, // Round to the nearest int CEIL // Round away from zero } RoundingMode constant FLOOR = RoundingMode.FLOOR; RoundingMode constant ROUND = RoundingMode.ROUND; RoundingMode constant CEIL = RoundingMode.CEIL; /* @dev Solidity 0.8.x only allows you to change one of type or size per type conversion. Thus, all the tedious-looking double conversions like uint256(uint256 (foo)) See: https://docs.soliditylang.org/en/v0.8.17/080-breaking-changes.html#new-restrictions */ /// Explicitly convert a uint256 to a uint192. Revert if the input is out of bounds. function _safeWrap(uint256 x) pure returns (uint192) { if (FIX_MAX < x) revert UIntOutOfBounds(); return uint192(x); } /// Convert a uint to its Fix representation. /// @return x // as-ints: x * 1e18 function toFix(uint256 x) pure returns (uint192) { return _safeWrap(x * FIX_SCALE); } /// Convert a uint to its fixed-point representation, and left-shift its value `shiftLeft` /// decimal digits. /// @return x * 10**shiftLeft // as-ints: x * 10**(shiftLeft + 18) function shiftl_toFix(uint256 x, int8 shiftLeft) pure returns (uint192) { return shiftl_toFix(x, shiftLeft, FLOOR); } /// @return x * 10**shiftLeft // as-ints: x * 10**(shiftLeft + 18) function shiftl_toFix( uint256 x, int8 shiftLeft, RoundingMode rounding ) pure returns (uint192) { // conditions for avoiding overflow if (x == 0) return 0; if (shiftLeft <= -96) return (rounding == CEIL ? 1 : 0); // 0 < uint.max / 10**77 < 0.5 if (40 <= shiftLeft) revert UIntOutOfBounds(); // 10**56 < FIX_MAX < 10**57 shiftLeft += 18; uint256 coeff = 10**abs(shiftLeft); uint256 shifted = (shiftLeft >= 0) ? x * coeff : _divrnd(x, coeff, rounding); return _safeWrap(shifted); } /// Divide a uint by a uint192, yielding a uint192 /// This may also fail if the result is MIN_uint192! not fixing this for optimization's sake. /// @return x / y // as-ints: x * 1e36 / y function divFix(uint256 x, uint192 y) pure returns (uint192) { // If we didn't have to worry about overflow, we'd just do `return x * 1e36 / _y` // If it's safe to do this operation the easy way, do it: if (x < uint256(type(uint256).max / FIX_SCALE_SQ)) { return _safeWrap(uint256(x * FIX_SCALE_SQ) / y); } else { return _safeWrap(mulDiv256(x, FIX_SCALE_SQ, y)); } } /// Divide a uint by a uint, yielding a uint192 /// @return x / y // as-ints: x * 1e18 / y function divuu(uint256 x, uint256 y) pure returns (uint192) { return _safeWrap(mulDiv256(FIX_SCALE, x, y)); } /// @return min(x,y) // as-ints: min(x,y) function fixMin(uint192 x, uint192 y) pure returns (uint192) { return x < y ? x : y; } /// @return max(x,y) // as-ints: max(x,y) function fixMax(uint192 x, uint192 y) pure returns (uint192) { return x > y ? x : y; } /// @return absoluteValue(x,y) // as-ints: absoluteValue(x,y) function abs(int256 x) pure returns (uint256) { return x < 0 ? uint256(-x) : uint256(x); } /// Divide two uints, returning a uint, using rounding mode `rounding`. /// @return numerator / divisor // as-ints: numerator / divisor function _divrnd( uint256 numerator, uint256 divisor, RoundingMode rounding ) pure returns (uint256) { uint256 result = numerator / divisor; if (rounding == FLOOR) return result; if (rounding == ROUND) { if (numerator % divisor > (divisor - 1) / 2) { result++; } } else { if (numerator % divisor > 0) { result++; } } return result; } library FixLib { /// Again, all arithmetic functions fail if and only if the result is out of bounds. /// Convert this fixed-point value to a uint. Round towards zero if needed. /// @return x // as-ints: x / 1e18 function toUint(uint192 x) internal pure returns (uint136) { return toUint(x, FLOOR); } /// Convert this uint192 to a uint /// @return x // as-ints: x / 1e18 with rounding function toUint(uint192 x, RoundingMode rounding) internal pure returns (uint136) { return uint136(_divrnd(uint256(x), FIX_SCALE, rounding)); } /// Return the uint192 shifted to the left by `decimal` digits /// (Similar to a bitshift but in base 10) /// @return x * 10**decimals // as-ints: x * 10**decimals function shiftl(uint192 x, int8 decimals) internal pure returns (uint192) { return shiftl(x, decimals, FLOOR); } /// Return the uint192 shifted to the left by `decimal` digits /// (Similar to a bitshift but in base 10) /// @return x * 10**decimals // as-ints: x * 10**decimals function shiftl( uint192 x, int8 decimals, RoundingMode rounding ) internal pure returns (uint192) { // Handle overflow cases if (x == 0) return 0; if (decimals <= -59) return (rounding == CEIL ? 1 : 0); // 59, because 1e58 > 2**192 if (58 <= decimals) revert UIntOutOfBounds(); // 58, because x * 1e58 > 2 ** 192 if x != 0 uint256 coeff = uint256(10**abs(decimals)); return _safeWrap(decimals >= 0 ? x * coeff : _divrnd(x, coeff, rounding)); } /// Add a uint192 to this uint192 /// @return x + y // as-ints: x + y function plus(uint192 x, uint192 y) internal pure returns (uint192) { return x + y; } /// Add a uint to this uint192 /// @return x + y // as-ints: x + y*1e18 function plusu(uint192 x, uint256 y) internal pure returns (uint192) { return _safeWrap(x + y * FIX_SCALE); } /// Subtract a uint192 from this uint192 /// @return x - y // as-ints: x - y function minus(uint192 x, uint192 y) internal pure returns (uint192) { return x - y; } /// Subtract a uint from this uint192 /// @return x - y // as-ints: x - y*1e18 function minusu(uint192 x, uint256 y) internal pure returns (uint192) { return _safeWrap(uint256(x) - uint256(y * FIX_SCALE)); } /// Multiply this uint192 by a uint192 /// Round truncated values to the nearest available value. 5e-19 rounds away from zero. /// @return x * y // as-ints: x * y/1e18 [division using ROUND, not FLOOR] function mul(uint192 x, uint192 y) internal pure returns (uint192) { return mul(x, y, ROUND); } /// Multiply this uint192 by a uint192 /// @return x * y // as-ints: x * y/1e18 function mul( uint192 x, uint192 y, RoundingMode rounding ) internal pure returns (uint192) { return _safeWrap(_divrnd(uint256(x) * uint256(y), FIX_SCALE, rounding)); } /// Multiply this uint192 by a uint /// @return x * y // as-ints: x * y function mulu(uint192 x, uint256 y) internal pure returns (uint192) { return _safeWrap(x * y); } /// Divide this uint192 by a uint192 /// @return x / y // as-ints: x * 1e18 / y function div(uint192 x, uint192 y) internal pure returns (uint192) { return div(x, y, FLOOR); } /// Divide this uint192 by a uint192 /// @return x / y // as-ints: x * 1e18 / y function div( uint192 x, uint192 y, RoundingMode rounding ) internal pure returns (uint192) { // Multiply-in FIX_SCALE before dividing by y to preserve precision. return _safeWrap(_divrnd(uint256(x) * FIX_SCALE, y, rounding)); } /// Divide this uint192 by a uint /// @return x / y // as-ints: x / y function divu(uint192 x, uint256 y) internal pure returns (uint192) { return divu(x, y, FLOOR); } /// Divide this uint192 by a uint /// @return x / y // as-ints: x / y function divu( uint192 x, uint256 y, RoundingMode rounding ) internal pure returns (uint192) { return _safeWrap(_divrnd(x, y, rounding)); } uint64 constant FIX_HALF = uint64(FIX_SCALE) / 2; /// Raise this uint192 to a nonnegative integer power. Requires that x_ <= FIX_ONE /// Gas cost is O(lg(y)), precision is +- 1e-18. /// @return x_ ** y // as-ints: x_ ** y / 1e18**(y-1) <- technically correct for y = 0. :D function powu(uint192 x_, uint48 y) internal pure returns (uint192) { require(x_ <= FIX_ONE); if (y == 1) return x_; if (x_ == FIX_ONE || y == 0) return FIX_ONE; uint256 x = uint256(x_) * FIX_SCALE; // x is D36 uint256 result = FIX_SCALE_SQ; // result is D36 while (true) { if (y & 1 == 1) result = (result * x + FIX_SCALE_SQ / 2) / FIX_SCALE_SQ; if (y <= 1) break; y = (y >> 1); x = (x * x + FIX_SCALE_SQ / 2) / FIX_SCALE_SQ; } return _safeWrap(result / FIX_SCALE); } /// Comparison operators... function lt(uint192 x, uint192 y) internal pure returns (bool) { return x < y; } function lte(uint192 x, uint192 y) internal pure returns (bool) { return x <= y; } function gt(uint192 x, uint192 y) internal pure returns (bool) { return x > y; } function gte(uint192 x, uint192 y) internal pure returns (bool) { return x >= y; } function eq(uint192 x, uint192 y) internal pure returns (bool) { return x == y; } function neq(uint192 x, uint192 y) internal pure returns (bool) { return x != y; } /// Return whether or not this uint192 is less than epsilon away from y. /// @return |x - y| < epsilon // as-ints: |x - y| < epsilon function near( uint192 x, uint192 y, uint192 epsilon ) internal pure returns (bool) { uint192 diff = x <= y ? y - x : x - y; return diff < epsilon; } // ================ Chained Operations ================ // The operation foo_bar() always means: // Do foo() followed by bar(), and overflow only if the _end_ result doesn't fit in an uint192 /// Shift this uint192 left by `decimals` digits, and convert to a uint /// @return x * 10**decimals // as-ints: x * 10**(decimals - 18) function shiftl_toUint(uint192 x, int8 decimals) internal pure returns (uint256) { return shiftl_toUint(x, decimals, FLOOR); } /// Shift this uint192 left by `decimals` digits, and convert to a uint. /// @return x * 10**decimals // as-ints: x * 10**(decimals - 18) function shiftl_toUint( uint192 x, int8 decimals, RoundingMode rounding ) internal pure returns (uint256) { // Handle overflow cases if (x == 0) return 0; // always computable, no matter what decimals is if (decimals <= -42) return (rounding == CEIL ? 1 : 0); if (96 <= decimals) revert UIntOutOfBounds(); decimals -= 18; // shift so that toUint happens at the same time. uint256 coeff = uint256(10**abs(decimals)); return decimals >= 0 ? uint256(x * coeff) : uint256(_divrnd(x, coeff, rounding)); } /// Multiply this uint192 by a uint, and output the result as a uint /// @return x * y // as-ints: x * y / 1e18 function mulu_toUint(uint192 x, uint256 y) internal pure returns (uint256) { return mulDiv256(uint256(x), y, FIX_SCALE); } /// Multiply this uint192 by a uint, and output the result as a uint /// @return x * y // as-ints: x * y / 1e18 function mulu_toUint( uint192 x, uint256 y, RoundingMode rounding ) internal pure returns (uint256) { return mulDiv256(uint256(x), y, FIX_SCALE, rounding); } /// Multiply this uint192 by a uint192 and output the result as a uint /// @return x * y // as-ints: x * y / 1e36 function mul_toUint(uint192 x, uint192 y) internal pure returns (uint256) { return mulDiv256(uint256(x), uint256(y), FIX_SCALE_SQ); } /// Multiply this uint192 by a uint192 and output the result as a uint /// @return x * y // as-ints: x * y / 1e36 function mul_toUint( uint192 x, uint192 y, RoundingMode rounding ) internal pure returns (uint256) { return mulDiv256(uint256(x), uint256(y), FIX_SCALE_SQ, rounding); } /// Compute x * y / z avoiding intermediate overflow /// @dev Only use if you need to avoid overflow; costlier than x * y / z /// @return x * y / z // as-ints: x * y / z function muluDivu( uint192 x, uint256 y, uint256 z ) internal pure returns (uint192) { return muluDivu(x, y, z, FLOOR); } /// Compute x * y / z, avoiding intermediate overflow /// @dev Only use if you need to avoid overflow; costlier than x * y / z /// @return x * y / z // as-ints: x * y / z function muluDivu( uint192 x, uint256 y, uint256 z, RoundingMode rounding ) internal pure returns (uint192) { return _safeWrap(mulDiv256(x, y, z, rounding)); } /// Compute x * y / z on Fixes, avoiding intermediate overflow /// @dev Only use if you need to avoid overflow; costlier than x * y / z /// @return x * y / z // as-ints: x * y / z function mulDiv( uint192 x, uint192 y, uint192 z ) internal pure returns (uint192) { return mulDiv(x, y, z, FLOOR); } /// Compute x * y / z on Fixes, avoiding intermediate overflow /// @dev Only use if you need to avoid overflow; costlier than x * y / z /// @return x * y / z // as-ints: x * y / z function mulDiv( uint192 x, uint192 y, uint192 z, RoundingMode rounding ) internal pure returns (uint192) { return _safeWrap(mulDiv256(x, y, z, rounding)); } // === safe*() === /// Multiply two fixes, rounding up to FIX_MAX and down to 0 /// @param a First param to multiply /// @param b Second param to multiply function safeMul( uint192 a, uint192 b, RoundingMode rounding ) internal pure returns (uint192) { // untestable: // a will never = 0 here because of the check in _price() if (a == 0 || b == 0) return 0; // untestable: // a = FIX_MAX iff b = 0 if (a == FIX_MAX || b == FIX_MAX) return FIX_MAX; // return FIX_MAX instead of throwing overflow errors. unchecked { // p and mul *are* Fix values, so have 18 decimals (D18) uint256 rawDelta = uint256(b) * a; // {D36} = {D18} * {D18} // if we overflowed, then return FIX_MAX if (rawDelta / b != a) return FIX_MAX; uint256 shiftDelta = rawDelta; // add in rounding if (rounding == RoundingMode.ROUND) shiftDelta += (FIX_ONE / 2); else if (rounding == RoundingMode.CEIL) shiftDelta += FIX_ONE - 1; // untestable (here there be dragons): // (below explanation is for the ROUND case, but it extends to the FLOOR/CEIL too) // A) shiftDelta = rawDelta + (FIX_ONE / 2) // shiftDelta overflows if: // B) shiftDelta = MAX_UINT256 - FIX_ONE/2 + 1 // rawDelta + (FIX_ONE/2) = MAX_UINT256 - FIX_ONE/2 + 1 // b * a = MAX_UINT256 - FIX_ONE + 1 // therefore shiftDelta overflows if: // C) b = (MAX_UINT256 - FIX_ONE + 1) / a // MAX_UINT256 ~= 1e77 , FIX_MAX ~= 6e57 (6e20 difference in magnitude) // a <= 1e21 (MAX_TARGET_AMT) // a must be between 1e19 & 1e20 in order for b in (C) to be uint192, // but a would have to be < 1e18 in order for (A) to overflow if (shiftDelta < rawDelta) return FIX_MAX; // return FIX_MAX if return result would truncate if (shiftDelta / FIX_ONE > FIX_MAX) return FIX_MAX; // return _div(rawDelta, FIX_ONE, rounding) return uint192(shiftDelta / FIX_ONE); // {D18} = {D36} / {D18} } } /// Divide two fixes, rounding up to FIX_MAX and down to 0 /// @param a Numerator /// @param b Denominator function safeDiv( uint192 a, uint192 b, RoundingMode rounding ) internal pure returns (uint192) { if (a == 0) return 0; if (b == 0) return FIX_MAX; uint256 raw = _divrnd(FIX_ONE_256 * a, uint256(b), rounding); if (raw >= FIX_MAX) return FIX_MAX; return uint192(raw); // don't need _safeWrap } /// Multiplies two fixes and divide by a third /// @param a First to multiply /// @param b Second to multiply /// @param c Denominator function safeMulDiv( uint192 a, uint192 b, uint192 c, RoundingMode rounding ) internal pure returns (uint192 result) { if (a == 0 || b == 0) return 0; if (a == FIX_MAX || b == FIX_MAX || c == 0) return FIX_MAX; uint256 result_256; unchecked { (uint256 hi, uint256 lo) = fullMul(a, b); if (hi >= c) return FIX_MAX; uint256 mm = mulmod(a, b, c); if (mm > lo) hi -= 1; lo -= mm; uint256 pow2 = c & (0 - c); uint256 c_256 = uint256(c); // Warning: Should not access c below this line c_256 /= pow2; lo /= pow2; lo += hi * ((0 - pow2) / pow2 + 1); uint256 r = 1; r *= 2 - c_256 * r; r *= 2 - c_256 * r; r *= 2 - c_256 * r; r *= 2 - c_256 * r; r *= 2 - c_256 * r; r *= 2 - c_256 * r; r *= 2 - c_256 * r; r *= 2 - c_256 * r; result_256 = lo * r; // Apply rounding if (rounding == CEIL) { if (mm > 0) result_256 += 1; } else if (rounding == ROUND) { if (mm > ((c_256 - 1) / 2)) result_256 += 1; } } if (result_256 >= FIX_MAX) return FIX_MAX; return uint192(result_256); } } // ================ a couple pure-uint helpers================ // as-ints comments are omitted here, because they're the same as @return statements, because // these are all pure uint functions /// Return (x*y/z), avoiding intermediate overflow. // Adapted from sources: // https://medium.com/coinmonks/4db014e080b1, https://medium.com/wicketh/afa55870a65 // and quite a few of the other excellent "Mathemagic" posts from https://medium.com/wicketh /// @dev Only use if you need to avoid overflow; costlier than x * y / z /// @return result x * y / z function mulDiv256( uint256 x, uint256 y, uint256 z ) pure returns (uint256 result) { unchecked { (uint256 hi, uint256 lo) = fullMul(x, y); if (hi >= z) revert UIntOutOfBounds(); uint256 mm = mulmod(x, y, z); if (mm > lo) hi -= 1; lo -= mm; uint256 pow2 = z & (0 - z); z /= pow2; lo /= pow2; lo += hi * ((0 - pow2) / pow2 + 1); uint256 r = 1; r *= 2 - z * r; r *= 2 - z * r; r *= 2 - z * r; r *= 2 - z * r; r *= 2 - z * r; r *= 2 - z * r; r *= 2 - z * r; r *= 2 - z * r; result = lo * r; } } /// Return (x*y/z), avoiding intermediate overflow. /// @dev Only use if you need to avoid overflow; costlier than x * y / z /// @return x * y / z function mulDiv256( uint256 x, uint256 y, uint256 z, RoundingMode rounding ) pure returns (uint256) { uint256 result = mulDiv256(x, y, z); if (rounding == FLOOR) return result; uint256 mm = mulmod(x, y, z); if (rounding == CEIL) { if (mm > 0) result += 1; } else { if (mm > ((z - 1) / 2)) result += 1; // z should be z-1 } return result; } /// Return (x*y) as a "virtual uint512" (lo, hi), representing (hi*2**256 + lo) /// Adapted from sources: /// https://medium.com/wicketh/27650fec525d, https://medium.com/coinmonks/4db014e080b1 /// @dev Intended to be internal to this library /// @return hi (hi, lo) satisfies hi*(2**256) + lo == x * y /// @return lo (paired with `hi`) function fullMul(uint256 x, uint256 y) pure returns (uint256 hi, uint256 lo) { unchecked { uint256 mm = mulmod(x, y, uint256(0) - uint256(1)); lo = x * y; hi = mm - lo; if (mm < lo) hi -= 1; } }
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "./Fixed.sol";
uint48 constant ONE_HOUR = 3600; // {seconds/hour}
/**
* @title ThrottleLib
* A library that implements a usage throttle that can be used to ensure net issuance
* or net redemption for an RToken never exceeds some bounds per unit time (hour).
*
* It is expected for the RToken to use this library with two instances, one for issuance
* and one for redemption. Issuance causes the available redemption amount to increase, and
* visa versa.
*/
library ThrottleLib {
using FixLib for uint192;
struct Params {
uint256 amtRate; // {qRTok/hour} a quantity of RToken hourly; cannot be 0
uint192 pctRate; // {1/hour} a fraction of RToken hourly; can be 0
}
struct Throttle {
// === Gov params ===
Params params;
// === Cache ===
uint48 lastTimestamp; // {seconds}
uint256 lastAvailable; // {qRTok}
}
/// Reverts if usage amount exceeds available amount
/// @param supply {qRTok} Total RToken supply beforehand
/// @param amount {qRTok} Amount of RToken to use. Should be negative for the issuance
/// throttle during redemption and for the redemption throttle during issuance.
function useAvailable(
Throttle storage throttle,
uint256 supply,
int256 amount
) internal {
// untestable: amtRate will always be greater > 0 due to previous validations
if (throttle.params.amtRate == 0 && throttle.params.pctRate == 0) return;
// Calculate hourly limit
uint256 limit = hourlyLimit(throttle, supply); // {qRTok}
// Calculate available amount before supply change
uint256 available = currentlyAvailable(throttle, limit);
// Update throttle.timestamp if available amount changed or at limit
if (available != throttle.lastAvailable || available == limit) {
throttle.lastTimestamp = uint48(block.timestamp);
}
// Update throttle.lastAvailable
if (amount > 0) {
require(uint256(amount) <= available, "supply change throttled");
available -= uint256(amount);
// untestable: the final else statement, amount will never be 0
} else if (amount < 0) {
available += uint256(-amount);
}
throttle.lastAvailable = available;
}
/// @param limit {qRTok/hour} The hourly limit
/// @return available {qRTok} Amount currently available for consumption
function currentlyAvailable(Throttle storage throttle, uint256 limit)
internal
view
returns (uint256 available)
{
uint48 delta = uint48(block.timestamp) - throttle.lastTimestamp; // {seconds}
available = throttle.lastAvailable + (limit * delta) / ONE_HOUR;
if (available > limit) available = limit;
}
/// @return limit {qRTok} The hourly limit
function hourlyLimit(Throttle storage throttle, uint256 supply)
internal
view
returns (uint256 limit)
{
Params storage params = throttle.params;
// Calculate hourly limit as: max(params.amtRate, supply.mul(params.pctRate))
limit = (supply * params.pctRate) / FIX_ONE_256; // {qRTok}
if (params.amtRate > limit) limit = params.amtRate;
}
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "../interfaces/IMain.sol";
uint256 constant LONG_FREEZE_CHARGES = 6; // 6 uses
uint48 constant MAX_UNFREEZE_AT = type(uint48).max;
uint48 constant MAX_SHORT_FREEZE = 2592000; // 1 month
uint48 constant MAX_LONG_FREEZE = 31536000; // 1 year
/**
* @title Auth
* @notice Provides fine-grained access controls and exports frozen/paused states to Components.
*/
abstract contract Auth is AccessControlUpgradeable, IAuth {
/**
* System-wide states (does not impact ERC20 functions)
* - Frozen: only allow OWNER actions and staking.
* - Trading Paused: only allow OWNER actions, issuance, redemption, staking,
* and rewards payout.
* - Issuance Paused: disallow issuance
*
* Typically freezing thaws on its own in a predetermined number of blocks.
* However, OWNER can freeze forever and unfreeze.
*/
/// The rest of the contract uses the shorthand; these declarations are here for getters
bytes32 public constant OWNER_ROLE = OWNER;
bytes32 public constant SHORT_FREEZER_ROLE = SHORT_FREEZER;
bytes32 public constant LONG_FREEZER_ROLE = LONG_FREEZER;
bytes32 public constant PAUSER_ROLE = PAUSER;
// === Freezing ===
mapping(address => uint256) public longFreezes;
uint48 public unfreezeAt; // {s} uint48.max to pause indefinitely
uint48 public shortFreeze; // {s} length of an initial freeze
uint48 public longFreeze; // {s} length of a freeze extension
// === Pausing ===
/// @custom:oz-renamed-from paused
bool public tradingPaused;
bool public issuancePaused;
/* ==== Invariants ====
0 <= longFreeze[a] <= LONG_FREEZE_CHARGES for all addrs a
set{a has LONG_FREEZER} == set{a : longFreeze[a] == 0}
*/
// checks:
// - __Auth_init has not previously been called
// - 0 < shortFreeze_ <= MAX_SHORT_FREEZE
// - 0 < longFreeze_ <= MAX_LONG_FREEZE
// effects:
// - caller has only the OWNER role
// - OWNER is the admin role for all roles
// - shortFreeze' == shortFreeze_
// - longFreeze' == longFreeze_
// questions: (what do I know about the values of paused and unfreezeAt?)
// untestable:
// `else` branch of `onlyInitializing` (ie. revert) is currently untestable.
// This function is only called inside other `init` functions, each of which is wrapped
// in an `initializer` modifier, which would fail first.
// solhint-disable-next-line func-name-mixedcase
function __Auth_init(uint48 shortFreeze_, uint48 longFreeze_) internal onlyInitializing {
__AccessControl_init();
// Role setup
_setRoleAdmin(OWNER, OWNER);
_setRoleAdmin(SHORT_FREEZER, OWNER);
_setRoleAdmin(LONG_FREEZER, OWNER);
_setRoleAdmin(PAUSER, OWNER);
_grantRole(OWNER, _msgSender());
setShortFreeze(shortFreeze_);
setLongFreeze(longFreeze_);
}
// checks: caller is an admin for role, account is not 0
// effects:
// - account has the `role` role
// - if role is LONG_FREEZER, then longFreezes'[account] == LONG_FREEZE_CHARGES
function grantRole(bytes32 role, address account)
public
override(AccessControlUpgradeable, IAccessControlUpgradeable)
onlyRole(getRoleAdmin(role))
{
require(account != address(0), "cannot grant role to address 0");
if (role == LONG_FREEZER) longFreezes[account] = LONG_FREEZE_CHARGES;
_grantRole(role, account);
}
// ==== System-wide views ====
// returns: bool(main is frozen) == now < unfreezeAt
function frozen() public view returns (bool) {
return block.timestamp < unfreezeAt;
}
/// @dev This -or- condition is a performance optimization for the consuming Component
// returns: bool(main is frozen or tradingPaused) == tradingPaused || (now < unfreezeAt)
function tradingPausedOrFrozen() public view returns (bool) {
return tradingPaused || block.timestamp < unfreezeAt;
}
/// @dev This -or- condition is a performance optimization for the consuming Component
// returns: bool(main is frozen or issuancePaused) == issuancePaused || (now < unfreezeAt)
function issuancePausedOrFrozen() public view returns (bool) {
return issuancePaused || block.timestamp < unfreezeAt;
}
// === Freezing ===
/// Enter a freeze for the `shortFreeze` duration
// checks:
// - caller has the SHORT_FREEZER role
// - now + shortFreeze >= unfreezeAt (that is, this call should increase unfreezeAt)
// effects:
// - unfreezeAt' = now + shortFreeze
// - after, caller does not have the SHORT_FREEZER role
function freezeShort() external onlyRole(SHORT_FREEZER) {
// Revoke short freezer role after one use
_revokeRole(SHORT_FREEZER, _msgSender());
freezeUntil(uint48(block.timestamp) + shortFreeze);
}
/// Enter a freeze by the `longFreeze` duration
// checks:
// - caller has the LONG_FREEZER role
// - longFreezes[caller] > 0
// - now + longFreeze >= unfreezeAt (that is, this call should increase unfreezeAt)
// effects:
// - unfreezeAt' = now + longFreeze
// - longFreezes'[caller] = longFreezes[caller] - 1
// - if longFreezes'[caller] == 0 then caller loses the LONG_FREEZER role
function freezeLong() external onlyRole(LONG_FREEZER) {
longFreezes[_msgSender()] -= 1; // reverts on underflow
// Revoke on 0 charges as a cleanup step
if (longFreezes[_msgSender()] == 0) _revokeRole(LONG_FREEZER, _msgSender());
freezeUntil(uint48(block.timestamp) + longFreeze);
}
/// Enter a permanent freeze
// checks:
// - caller has the OWNER role
// - unfreezeAt != type(uint48).max
// effects: unfreezeAt' = type(uint48).max
function freezeForever() external onlyRole(OWNER) {
freezeUntil(MAX_UNFREEZE_AT);
}
/// End all freezes
// checks:
// - unfreezeAt > now (i.e, frozen() == true before the call)
// - caller has the OWNER role
// effects: unfreezeAt' = now (i.e, frozen() == false after the call)
function unfreeze() external onlyRole(OWNER) {
emit UnfreezeAtSet(unfreezeAt, uint48(block.timestamp));
unfreezeAt = uint48(block.timestamp);
}
// === Pausing ===
// checks: caller has PAUSER
// effects: tradingPaused' = true
function pauseTrading() external onlyRole(PAUSER) {
emit TradingPausedSet(tradingPaused, true);
tradingPaused = true;
}
// checks: caller has PAUSER
// effects: tradingPaused' = false
function unpauseTrading() external onlyRole(PAUSER) {
emit TradingPausedSet(tradingPaused, false);
tradingPaused = false;
}
// checks: caller has PAUSER
// effects: issuancePaused' = true
function pauseIssuance() external onlyRole(PAUSER) {
emit IssuancePausedSet(issuancePaused, true);
issuancePaused = true;
}
// checks: caller has PAUSER
// effects: issuancePaused' = false
function unpauseIssuance() external onlyRole(PAUSER) {
emit IssuancePausedSet(issuancePaused, false);
issuancePaused = false;
}
// === Gov params ===
/// @custom:governance
function setShortFreeze(uint48 shortFreeze_) public onlyRole(OWNER) {
require(shortFreeze_ > 0 && shortFreeze_ <= MAX_SHORT_FREEZE, "short freeze out of range");
emit ShortFreezeDurationSet(shortFreeze, shortFreeze_);
shortFreeze = shortFreeze_;
}
/// @custom:governance
function setLongFreeze(uint48 longFreeze_) public onlyRole(OWNER) {
require(longFreeze_ > 0 && longFreeze_ <= MAX_LONG_FREEZE, "long freeze out of range");
emit LongFreezeDurationSet(longFreeze, longFreeze_);
longFreeze = longFreeze_;
}
// === Private Helper ===
// checks: newUnfreezeAt > unfreezeAt
// effects: unfreezeAt' = newUnfreezeAt
function freezeUntil(uint48 newUnfreezeAt) private {
require(newUnfreezeAt > unfreezeAt, "frozen");
emit UnfreezeAtSet(unfreezeAt, newUnfreezeAt);
unfreezeAt = newUnfreezeAt;
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[48] private __gap;
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "../interfaces/IMain.sol";
import "./Auth.sol";
/**
* @title ComponentRegistry
*/
abstract contract ComponentRegistry is Initializable, Auth, IComponentRegistry {
// untestable:
// `else` branch of `onlyInitializing` (ie. revert) is currently untestable.
// This function is only called inside other `init` functions, each of which is wrapped
// in an `initializer` modifier, which would fail first.
// solhint-disable-next-line func-name-mixedcase
function __ComponentRegistry_init(Components memory components_) internal onlyInitializing {
_setBackingManager(components_.backingManager);
_setBasketHandler(components_.basketHandler);
_setRSRTrader(components_.rsrTrader);
_setRTokenTrader(components_.rTokenTrader);
_setAssetRegistry(components_.assetRegistry);
_setDistributor(components_.distributor);
_setFurnace(components_.furnace);
_setBroker(components_.broker);
_setStRSR(components_.stRSR);
_setRToken(components_.rToken);
}
// === Components ===
IRToken public rToken;
function _setRToken(IRToken val) private {
require(address(val) != address(0), "invalid RToken address");
emit RTokenSet(rToken, val);
rToken = val;
}
IStRSR public stRSR;
function _setStRSR(IStRSR val) private {
require(address(val) != address(0), "invalid StRSR address");
emit StRSRSet(stRSR, val);
stRSR = val;
}
IAssetRegistry public assetRegistry;
function _setAssetRegistry(IAssetRegistry val) private {
require(address(val) != address(0), "invalid AssetRegistry address");
emit AssetRegistrySet(assetRegistry, val);
assetRegistry = val;
}
IBasketHandler public basketHandler;
function _setBasketHandler(IBasketHandler val) private {
require(address(val) != address(0), "invalid BasketHandler address");
emit BasketHandlerSet(basketHandler, val);
basketHandler = val;
}
IBackingManager public backingManager;
function _setBackingManager(IBackingManager val) private {
require(address(val) != address(0), "invalid BackingManager address");
emit BackingManagerSet(backingManager, val);
backingManager = val;
}
IDistributor public distributor;
function _setDistributor(IDistributor val) private {
require(address(val) != address(0), "invalid Distributor address");
emit DistributorSet(distributor, val);
distributor = val;
}
IRevenueTrader public rsrTrader;
function _setRSRTrader(IRevenueTrader val) private {
require(address(val) != address(0), "invalid RSRTrader address");
emit RSRTraderSet(rsrTrader, val);
rsrTrader = val;
}
IRevenueTrader public rTokenTrader;
function _setRTokenTrader(IRevenueTrader val) private {
require(address(val) != address(0), "invalid RTokenTrader address");
emit RTokenTraderSet(rTokenTrader, val);
rTokenTrader = val;
}
IFurnace public furnace;
function _setFurnace(IFurnace val) private {
require(address(val) != address(0), "invalid Furnace address");
emit FurnaceSet(furnace, val);
furnace = val;
}
IBroker public broker;
function _setBroker(IBroker val) private {
require(address(val) != address(0), "invalid Broker address");
emit BrokerSet(broker, val);
broker = val;
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[40] private __gap;
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "../interfaces/IVersioned.sol";
// This value should be updated on each release
string constant VERSION = "3.0.0";
/**
* @title Versioned
* @notice A mix-in to track semantic versioning uniformly across contracts.
*/
abstract contract Versioned is IVersioned {
function version() public pure virtual override returns (string memory) {
return VERSION;
}
}{
"optimizer": {
"enabled": true,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"libraries": {}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"previousAdmin","type":"address"},{"indexed":false,"internalType":"address","name":"newAdmin","type":"address"}],"name":"AdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IAssetRegistry","name":"oldVal","type":"address"},{"indexed":false,"internalType":"contract IAssetRegistry","name":"newVal","type":"address"}],"name":"AssetRegistrySet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IBackingManager","name":"oldVal","type":"address"},{"indexed":false,"internalType":"contract IBackingManager","name":"newVal","type":"address"}],"name":"BackingManagerSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IBasketHandler","name":"oldVal","type":"address"},{"indexed":false,"internalType":"contract IBasketHandler","name":"newVal","type":"address"}],"name":"BasketHandlerSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"beacon","type":"address"}],"name":"BeaconUpgraded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IBroker","name":"oldVal","type":"address"},{"indexed":false,"internalType":"contract IBroker","name":"newVal","type":"address"}],"name":"BrokerSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IDistributor","name":"oldVal","type":"address"},{"indexed":false,"internalType":"contract IDistributor","name":"newVal","type":"address"}],"name":"DistributorSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IFurnace","name":"oldVal","type":"address"},{"indexed":false,"internalType":"contract IFurnace","name":"newVal","type":"address"}],"name":"FurnaceSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"oldVal","type":"bool"},{"indexed":false,"internalType":"bool","name":"newVal","type":"bool"}],"name":"IssuancePausedSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint48","name":"oldDuration","type":"uint48"},{"indexed":false,"internalType":"uint48","name":"newDuration","type":"uint48"}],"name":"LongFreezeDurationSet","type":"event"},{"anonymous":false,"inputs":[],"name":"MainInitialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IRevenueTrader","name":"oldVal","type":"address"},{"indexed":false,"internalType":"contract IRevenueTrader","name":"newVal","type":"address"}],"name":"RSRTraderSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract IRToken","name":"oldVal","type":"address"},{"indexed":true,"internalType":"contract IRToken","name":"newVal","type":"address"}],"name":"RTokenSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IRevenueTrader","name":"oldVal","type":"address"},{"indexed":false,"internalType":"contract IRevenueTrader","name":"newVal","type":"address"}],"name":"RTokenTraderSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint48","name":"oldDuration","type":"uint48"},{"indexed":false,"internalType":"uint48","name":"newDuration","type":"uint48"}],"name":"ShortFreezeDurationSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IStRSR","name":"oldVal","type":"address"},{"indexed":false,"internalType":"contract IStRSR","name":"newVal","type":"address"}],"name":"StRSRSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"oldVal","type":"bool"},{"indexed":false,"internalType":"bool","name":"newVal","type":"bool"}],"name":"TradingPausedSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint48","name":"oldVal","type":"uint48"},{"indexed":false,"internalType":"uint48","name":"newVal","type":"uint48"}],"name":"UnfreezeAtSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"implementation","type":"address"}],"name":"Upgraded","type":"event"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"LONG_FREEZER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"OWNER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PAUSER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SHORT_FREEZER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"assetRegistry","outputs":[{"internalType":"contract IAssetRegistry","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"backingManager","outputs":[{"internalType":"contract IBackingManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"basketHandler","outputs":[{"internalType":"contract IBasketHandler","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"broker","outputs":[{"internalType":"contract IBroker","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"distributor","outputs":[{"internalType":"contract IDistributor","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"freezeForever","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"freezeLong","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"freezeShort","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"frozen","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"furnace","outputs":[{"internalType":"contract IFurnace","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"contract IRToken","name":"rToken","type":"address"},{"internalType":"contract IStRSR","name":"stRSR","type":"address"},{"internalType":"contract IAssetRegistry","name":"assetRegistry","type":"address"},{"internalType":"contract IBasketHandler","name":"basketHandler","type":"address"},{"internalType":"contract IBackingManager","name":"backingManager","type":"address"},{"internalType":"contract IDistributor","name":"distributor","type":"address"},{"internalType":"contract IFurnace","name":"furnace","type":"address"},{"internalType":"contract IBroker","name":"broker","type":"address"},{"internalType":"contract IRevenueTrader","name":"rsrTrader","type":"address"},{"internalType":"contract IRevenueTrader","name":"rTokenTrader","type":"address"}],"internalType":"struct Components","name":"components","type":"tuple"},{"internalType":"contract IERC20","name":"rsr_","type":"address"},{"internalType":"uint48","name":"shortFreeze_","type":"uint48"},{"internalType":"uint48","name":"longFreeze_","type":"uint48"}],"name":"init","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"issuancePaused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"issuancePausedOrFrozen","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"longFreeze","outputs":[{"internalType":"uint48","name":"","type":"uint48"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"longFreezes","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pauseIssuance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"pauseTrading","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"poke","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"proxiableUUID","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rToken","outputs":[{"internalType":"contract IRToken","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rTokenTrader","outputs":[{"internalType":"contract IRevenueTrader","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"rsr","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rsrTrader","outputs":[{"internalType":"contract IRevenueTrader","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint48","name":"longFreeze_","type":"uint48"}],"name":"setLongFreeze","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint48","name":"shortFreeze_","type":"uint48"}],"name":"setShortFreeze","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"shortFreeze","outputs":[{"internalType":"uint48","name":"","type":"uint48"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"stRSR","outputs":[{"internalType":"contract IStRSR","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tradingPaused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tradingPausedOrFrozen","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"unfreeze","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unfreezeAt","outputs":[{"internalType":"uint48","name":"","type":"uint48"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"unpauseIssuance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unpauseTrading","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"}],"name":"upgradeTo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"upgradeToAndCall","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"pure","type":"function"}]Contract Creation Code
60a0604052306080523480156200001557600080fd5b50600054610100900460ff1615808015620000375750600054600160ff909116105b80620000535750303b15801562000053575060005460ff166001145b620000bb5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b606482015260840160405180910390fd5b6000805460ff191660011790558015620000df576000805461ff0019166101001790555b801562000126576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b50608051612e936200015f60003960008181610cff01528181610d3f01528181610e6401528181610ea4015261104b0152612e936000f3fe6080604052600436106102885760003560e01c8063590f6b1a1161015a578063bfe10928116100c1578063df23cbb11161007a578063df23cbb114610790578063e083b5e6146107a5578063e58378bb146107d2578063e63ab1e9146107e7578063f8aa0c4e146107fc578063fe8aa12a1461082257600080fd5b8063bfe10928146106ce578063c691af92146106ee578063c99dc3dd1461070f578063d547741f14610730578063dc8af5f614610750578063de1611cf1461077057600080fd5b806394c7f2991161011357806394c7f2991461062f578063979d7e861461064457806398f73e5214610664578063992e1d6a14610679578063a217fddf14610699578063abff0110146106ae57600080fd5b8063590f6b1a14610591578063656e96e1146105a65780636a28f000146105c6578063705a6618146105db57806375a8f926146105fa57806391d148541461060f57600080fd5b806336568abe116101fe5780634f1ef286116101b75780634f1ef286146104d45780635187ae68146104e757806352d1902d14610507578063531367631461051c57806353e23e2e1461053c57806354fd4d501461055d57600080fd5b806336568abe1461041f5780633659cfe61461043f57806340c65f721461045f57806341bf0c4e1461047f578063456068d21461049f5780634780a5e5146104b457600080fd5b8063248a9ca311610250578063248a9ca3146103225780632585a270146103605780632b56d18a146103755780632d870960146103b25780632f2439b1146103c75780632f2ff15d146103ff57600080fd5b806301ffc9a71461028d578063054f7d9c146102c25780630f702ed3146102e15780631031e36e146102f8578063181783581461030d575b600080fd5b34801561029957600080fd5b506102ad6102a836600461283a565b610837565b60405190151581526020015b60405180910390f35b3480156102ce57600080fd5b5060985465ffffffffffff1642106102ad565b3480156102ed57600080fd5b506102f661086e565b005b34801561030457600080fd5b506102f6610906565b34801561031957600080fd5b506102f6610995565b34801561032e57600080fd5b5061035261033d366004612864565b60009081526065602052604090206001015490565b6040519081526020016102b9565b34801561036c57600080fd5b506102f6610ae7565b34801561038157600080fd5b5060985461039b90600160301b900465ffffffffffff1681565b60405165ffffffffffff90911681526020016102b9565b3480156103be57600080fd5b50610352610b70565b3480156103d357600080fd5b5060cc546103e7906001600160a01b031681565b6040516001600160a01b0390911681526020016102b9565b34801561040b57600080fd5b506102f661041a366004612892565b610ba1565b34801561042b57600080fd5b506102f661043a366004612892565b610c77565b34801561044b57600080fd5b506102f661045a3660046128c2565b610cf5565b34801561046b57600080fd5b5060c9546103e7906001600160a01b031681565b34801561048b57600080fd5b5060d0546103e7906001600160a01b031681565b3480156104ab57600080fd5b506102f6610dd1565b3480156104c057600080fd5b5060ca546103e7906001600160a01b031681565b6102f66104e2366004612950565b610e5a565b3480156104f357600080fd5b506102f6610502366004612a13565b610f26565b34801561051357600080fd5b5061035261103e565b34801561052857600080fd5b5060cf546103e7906001600160a01b031681565b34801561054857600080fd5b506098546102ad90600160901b900460ff1681565b34801561056957600080fd5b5060408051808201825260058152640332e302e360dc1b602082015290516102b99190612a52565b34801561059d57600080fd5b506103526110f1565b3480156105b257600080fd5b5060d1546103e7906001600160a01b031681565b3480156105d257600080fd5b506102f6611120565b3480156105e757600080fd5b5060985461039b9065ffffffffffff1681565b34801561060657600080fd5b506102ad6111b3565b34801561061b57600080fd5b506102ad61062a366004612892565b6111dc565b34801561063b57600080fd5b506102f661120a565b34801561065057600080fd5b5060cb546103e7906001600160a01b031681565b34801561067057600080fd5b506102ad611249565b34801561068557600080fd5b506102f6610694366004612a90565b611270565b3480156106a557600080fd5b50610352600081565b3480156106ba57600080fd5b5060d2546103e7906001600160a01b031681565b3480156106da57600080fd5b5060ce546103e7906001600160a01b031681565b3480156106fa57600080fd5b506098546102ad90600160981b900460ff1681565b34801561071b57600080fd5b5061015f546103e7906001600160a01b031681565b34801561073c57600080fd5b506102f661074b366004612892565b611429565b34801561075c57600080fd5b5060cd546103e7906001600160a01b031681565b34801561077c57600080fd5b506102f661078b366004612a13565b61144e565b34801561079c57600080fd5b506102f6611568565b3480156107b157600080fd5b506103526107c03660046128c2565b60976020526000908152604090205481565b3480156107de57600080fd5b506103526115f7565b3480156107f357600080fd5b5061035261161e565b34801561080857600080fd5b5060985461039b90600160601b900465ffffffffffff1681565b34801561082e57600080fd5b506102f6611646565b60006001600160e01b03198216637965db0b60e01b148061086857506301ffc9a760e01b6001600160e01b03198316145b92915050565b6040518060400160405280600d81526020016c29a427a92a2fa32922a2ad22a960991b81525061089d90612ba2565b6108a681611709565b6108de6040518060400160405280600d81526020016c29a427a92a2fa32922a2ad22a960991b8152506108d890612ba2565b33611713565b609854610903906108fe90600160301b900465ffffffffffff1642612bdf565b61177a565b50565b604051806040016040528060068152602001652820aaa9a2a960d11b81525061092e90612ba2565b61093781611709565b60985460408051600160901b90920460ff1615158252600160208301527f87161063ac9982961a7044485445fe4f7bb1a458f731e5ad5ca31b97f3d452bf910160405180910390a1506098805460ff60901b1916600160901b179055565b60cb60009054906101000a90046001600160a01b03166001600160a01b031663f8ac93e86040518163ffffffff1660e01b8152600401600060405180830381600087803b1580156109e557600080fd5b505af11580156109f9573d6000803e3d6000fd5b50505050610a1060985465ffffffffffff16421090565b610a7d5760d160009054906101000a90046001600160a01b03166001600160a01b0316635220f5106040518163ffffffff1660e01b8152600401600060405180830381600087803b158015610a6457600080fd5b505af1158015610a78573d6000803e3d6000fd5b505050505b60ca60009054906101000a90046001600160a01b03166001600160a01b031663296130866040518163ffffffff1660e01b8152600401600060405180830381600087803b158015610acd57600080fd5b505af1158015610ae1573d6000803e3d6000fd5b50505050565b604051806040016040528060068152602001652820aaa9a2a960d11b815250610b0f90612ba2565b610b1881611709565b60985460408051600160981b90920460ff1615158252600060208301527f5ab09e6f82d5fade96a17975df4c40286cfcce3b71eeea0f1c76567f0296447d910160405180910390a1506098805460ff60981b19169055565b6040518060400160405280600c81526020016b2627a723afa32922a2ad22a960a11b815250610b9e90612ba2565b81565b600082815260656020526040902060010154610bbc81611709565b6001600160a01b038216610c175760405162461bcd60e51b815260206004820152601e60248201527f63616e6e6f74206772616e7420726f6c6520746f20616464726573732030000060448201526064015b60405180910390fd5b6040518060400160405280600c81526020016b2627a723afa32922a2ad22a960a11b815250610c4590612ba2565b8303610c68576001600160a01b0382166000908152609760205260409020600690555b610c728383611826565b505050565b6001600160a01b0381163314610ce75760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b6064820152608401610c0e565b610cf18282611713565b5050565b6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000163003610d3d5760405162461bcd60e51b8152600401610c0e90612c05565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316610d86600080516020612e17833981519152546001600160a01b031690565b6001600160a01b031614610dac5760405162461bcd60e51b8152600401610c0e90612c51565b610db5816118ac565b60408051600080825260208201909252610903918391906118dc565b604051806040016040528060068152602001652820aaa9a2a960d11b815250610df990612ba2565b610e0281611709565b60985460408051600160901b90920460ff1615158252600060208301527f87161063ac9982961a7044485445fe4f7bb1a458f731e5ad5ca31b97f3d452bf910160405180910390a1506098805460ff60901b19169055565b6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000163003610ea25760405162461bcd60e51b8152600401610c0e90612c05565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316610eeb600080516020612e17833981519152546001600160a01b031690565b6001600160a01b031614610f115760405162461bcd60e51b8152600401610c0e90612c51565b610f1a826118ac565b610cf1828260016118dc565b6040518060400160405280600581526020016427aba722a960d91b815250610f4d90612ba2565b610f5681611709565b60008265ffffffffffff16118015610f7a57506301e1338065ffffffffffff831611155b610fc65760405162461bcd60e51b815260206004820152601860248201527f6c6f6e6720667265657a65206f7574206f662072616e676500000000000000006044820152606401610c0e565b6098546040805165ffffffffffff600160601b9093048316815291841660208301527f2b855a9093ce8fb8bd37179aa306b424a5008d3a000751f4c2e721c51b89f9a2910160405180910390a1506098805465ffffffffffff909216600160601b0265ffffffffffff60601b19909216919091179055565b6000306001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146110de5760405162461bcd60e51b815260206004820152603860248201527f555550535570677261646561626c653a206d757374206e6f742062652063616c60448201527f6c6564207468726f7567682064656c656761746563616c6c00000000000000006064820152608401610c0e565b50600080516020612e1783398151915290565b6040518060400160405280600d81526020016c29a427a92a2fa32922a2ad22a960991b815250610b9e90612ba2565b6040518060400160405280600581526020016427aba722a960d91b81525061114790612ba2565b61115081611709565b6098546040805165ffffffffffff92831681524290921660208301527f4fd793fe252ef26ede0a814ca52971990ff5ade10f86376fb1914bfb17c57e08910160405180910390a1506098805465ffffffffffff19164265ffffffffffff16179055565b609854600090600160981b900460ff16806111d7575060985465ffffffffffff1642105b905090565b60008281526065602090815260408083206001600160a01b038516845290915281205460ff165b9392505050565b6040518060400160405280600581526020016427aba722a960d91b81525061123190612ba2565b61123a81611709565b61090365ffffffffffff61177a565b609854600090600160901b900460ff16806111d757505060985465ffffffffffff16421090565b600054610100900460ff16158080156112905750600054600160ff909116105b806112aa5750303b1580156112aa575060005460ff166001145b61130d5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610c0e565b6000805460ff191660011790558015611330576000805461ff0019166101001790555b6001600160a01b03841661137c5760405162461bcd60e51b8152602060048201526013602482015272696e76616c696420525352206164647265737360681b6044820152606401610c0e565b6113868383611a47565b61138f85611b9c565b611397611c45565b61015f80546001600160a01b0319166001600160a01b0386161790556040517fb3d8a26384852953cab1d93ea954a4ac74e1dc9f5c29576d4a4f45cdb230130e90600090a18015611422576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b5050505050565b60008281526065602052604090206001015461144481611709565b610c728383611713565b6040518060400160405280600581526020016427aba722a960d91b81525061147590612ba2565b61147e81611709565b60008265ffffffffffff161180156114a1575062278d0065ffffffffffff831611155b6114ed5760405162461bcd60e51b815260206004820152601960248201527f73686f727420667265657a65206f7574206f662072616e6765000000000000006044820152606401610c0e565b6098546040805165ffffffffffff600160301b9093048316815291841660208301527f84af4c1855ea2ef70449c6ae7119d367873ea35277b9681e0e47898900266f94910160405180910390a1506098805465ffffffffffff909216600160301b026bffffffffffff00000000000019909216919091179055565b604051806040016040528060068152602001652820aaa9a2a960d11b81525061159090612ba2565b61159981611709565b60985460408051600160981b90920460ff1615158252600160208301527f5ab09e6f82d5fade96a17975df4c40286cfcce3b71eeea0f1c76567f0296447d910160405180910390a1506098805460ff60981b1916600160981b179055565b6040518060400160405280600581526020016427aba722a960d91b815250610b9e90612ba2565b604051806040016040528060068152602001652820aaa9a2a960d11b815250610b9e90612ba2565b6040518060400160405280600c81526020016b2627a723afa32922a2ad22a960a11b81525061167490612ba2565b61167d81611709565b33600090815260976020526040812080546001929061169d908490612c9d565b90915550503360009081526097602052604081205490036116e9576116e96040518060400160405280600c81526020016b2627a723afa32922a2ad22a960a11b8152506108d890612ba2565b609854610903906108fe90600160601b900465ffffffffffff1642612bdf565b6109038133611c6e565b61171d82826111dc565b15610cf15760008281526065602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b60985465ffffffffffff908116908216116117c05760405162461bcd60e51b8152602060048201526006602482015265333937bd32b760d11b6044820152606401610c0e565b6098546040805165ffffffffffff928316815291831660208301527f4fd793fe252ef26ede0a814ca52971990ff5ade10f86376fb1914bfb17c57e08910160405180910390a16098805465ffffffffffff191665ffffffffffff92909216919091179055565b61183082826111dc565b610cf15760008281526065602090815260408083206001600160a01b03851684529091529020805460ff191660011790556118683390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6040518060400160405280600581526020016427aba722a960d91b8152506118d390612ba2565b610cf181611709565b7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd91435460ff161561190f57610c7283611cd2565b826001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015611969575060408051601f3d908101601f1916820190925261196691810190612cb0565b60015b6119cc5760405162461bcd60e51b815260206004820152602e60248201527f45524331393637557067726164653a206e657720696d706c656d656e7461746960448201526d6f6e206973206e6f74205555505360901b6064820152608401610c0e565b600080516020612e178339815191528114611a3b5760405162461bcd60e51b815260206004820152602960248201527f45524331393637557067726164653a20756e737570706f727465642070726f786044820152681a58589b195555525160ba1b6064820152608401610c0e565b50610c72838383611d6e565b600054610100900460ff16611a6e5760405162461bcd60e51b8152600401610c0e90612cc9565b611a76611c45565b611acc6040518060400160405280600581526020016427aba722a960d91b815250611aa090612ba2565b6040518060400160405280600581526020016427aba722a960d91b815250611ac790612ba2565b611d93565b611afe6040518060400160405280600d81526020016c29a427a92a2fa32922a2ad22a960991b815250611aa090612ba2565b611b2f6040518060400160405280600c81526020016b2627a723afa32922a2ad22a960a11b815250611aa090612ba2565b611b5a604051806040016040528060068152602001652820aaa9a2a960d11b815250611aa090612ba2565b611b8a6040518060400160405280600581526020016427aba722a960d91b815250611b8490612ba2565b33611826565b611b938261144e565b610cf181610f26565b600054610100900460ff16611bc35760405162461bcd60e51b8152600401610c0e90612cc9565b611bd08160800151611dde565b611bdd8160600151611e9d565b611beb816101000151611f5c565b611bf981610120015161201b565b611c0681604001516120da565b611c138160a00151612199565b611c208160c00151612258565b611c2d8160e00151612317565b611c3a81602001516123cf565b805161090390612486565b600054610100900460ff16611c6c5760405162461bcd60e51b8152600401610c0e90612cc9565b565b611c7882826111dc565b610cf157611c90816001600160a01b03166014612531565b611c9b836020612531565b604051602001611cac929190612d14565b60408051601f198184030181529082905262461bcd60e51b8252610c0e91600401612a52565b6001600160a01b0381163b611d3f5760405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b6064820152608401610c0e565b600080516020612e1783398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b611d77836126cd565b600082511180611d845750805b15610c7257610ae1838361270d565b600082815260656020526040808220600101805490849055905190918391839186917fbd79b86ffe0ab8e8776151514217cd7cacd52c909f66475c3af44e129f0b00ff9190a4505050565b6001600160a01b038116611e345760405162461bcd60e51b815260206004820152601e60248201527f696e76616c6964204261636b696e674d616e61676572206164647265737300006044820152606401610c0e565b60cd546040517fd4ec685c4e7367fc82d24a1c90d8c91c07a0e204b5b4655fc1a6d5b6b9d9eeb791611e73916001600160a01b03909116908490612d89565b60405180910390a160cd80546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b038116611ef35760405162461bcd60e51b815260206004820152601d60248201527f696e76616c6964204261736b657448616e646c657220616464726573730000006044820152606401610c0e565b60cc546040517fa41efa7d680b9ae9379ca75b956c50587b28ed07453f7d19388c7199397a1e8e91611f32916001600160a01b03909116908490612d89565b60405180910390a160cc80546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b038116611fb25760405162461bcd60e51b815260206004820152601960248201527f696e76616c6964205253525472616465722061646472657373000000000000006044820152606401610c0e565b60cf546040517f2fa6596476f0ebdb5fef9a37bedb7ef956e0e1c4e094464cbf49c38f44f7e8d191611ff1916001600160a01b03909116908490612d89565b60405180910390a160cf80546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b0381166120715760405162461bcd60e51b815260206004820152601c60248201527f696e76616c69642052546f6b656e5472616465722061646472657373000000006044820152606401610c0e565b60d0546040517f0d76a5d5849780e9a81127e61df7ee55bf3f766bc326510d3a52ede3caea168f916120b0916001600160a01b03909116908490612d89565b60405180910390a160d080546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b0381166121305760405162461bcd60e51b815260206004820152601d60248201527f696e76616c6964204173736574526567697374727920616464726573730000006044820152606401610c0e565b60cb546040517f5c69d378772ea2f02015deabd3b7ee1db0851dba819e216585de7a155d22a1489161216f916001600160a01b03909116908490612d89565b60405180910390a160cb80546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b0381166121ef5760405162461bcd60e51b815260206004820152601b60248201527f696e76616c6964204469737472696275746f72206164647265737300000000006044820152606401610c0e565b60ce546040517f8c6eabd1db7fe5a1951a7c78767c0e3633c5352578d15d45f99aa4c4db01c55a9161222e916001600160a01b03909116908490612d89565b60405180910390a160ce80546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b0381166122ae5760405162461bcd60e51b815260206004820152601760248201527f696e76616c6964204675726e61636520616464726573730000000000000000006044820152606401610c0e565b60d1546040517fe0c9d7fae2ccca1a3980ce26aada40d9f7fc84406cdb3adbdcfb8f9dd21c9b53916122ed916001600160a01b03909116908490612d89565b60405180910390a160d180546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b0381166123665760405162461bcd60e51b8152602060048201526016602482015275696e76616c69642042726f6b6572206164647265737360501b6044820152606401610c0e565b60d2546040517fc29cab4074359a76aba74458623910a8b95269ded89ad9f98cd2db1de3ead356916123a5916001600160a01b03909116908490612d89565b60405180910390a160d280546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b03811661241d5760405162461bcd60e51b8152602060048201526015602482015274696e76616c6964205374525352206164647265737360581b6044820152606401610c0e565b60ca546040517f1b29dc90e15d6ade122a9e27d886b4a077e66131c7e0cc805fc303e49690c9fc9161245c916001600160a01b03909116908490612d89565b60405180910390a160ca80546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b0381166124d55760405162461bcd60e51b8152602060048201526016602482015275696e76616c69642052546f6b656e206164647265737360501b6044820152606401610c0e565b60c9546040516001600160a01b038084169216907f2d2909c1d06afe38080a70d63a8793874674efb0fdf3b3bf3fd046056688b3ea90600090a360c980546001600160a01b0319166001600160a01b0392909216919091179055565b60606000612540836002612da3565b61254b906002612dba565b67ffffffffffffffff811115612563576125636128df565b6040519080825280601f01601f19166020018201604052801561258d576020820181803683370190505b509050600360fc1b816000815181106125a8576125a8612dcd565b60200101906001600160f81b031916908160001a905350600f60fb1b816001815181106125d7576125d7612dcd565b60200101906001600160f81b031916908160001a90535060006125fb846002612da3565b612606906001612dba565b90505b600181111561267e576f181899199a1a9b1b9c1cb0b131b232b360811b85600f166010811061263a5761263a612dcd565b1a60f81b82828151811061265057612650612dcd565b60200101906001600160f81b031916908160001a90535060049490941c9361267781612de3565b9050612609565b5083156112035760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610c0e565b6126d681611cd2565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a250565b60606001600160a01b0383163b6127755760405162461bcd60e51b815260206004820152602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f6044820152651b9d1c9858dd60d21b6064820152608401610c0e565b600080846001600160a01b0316846040516127909190612dfa565b600060405180830381855af49150503d80600081146127cb576040519150601f19603f3d011682016040523d82523d6000602084013e6127d0565b606091505b50915091506127f88282604051806060016040528060278152602001612e3760279139612801565b95945050505050565b60608315612810575081611203565b8251156128205782518084602001fd5b8160405162461bcd60e51b8152600401610c0e9190612a52565b60006020828403121561284c57600080fd5b81356001600160e01b03198116811461120357600080fd5b60006020828403121561287657600080fd5b5035919050565b6001600160a01b038116811461090357600080fd5b600080604083850312156128a557600080fd5b8235915060208301356128b78161287d565b809150509250929050565b6000602082840312156128d457600080fd5b81356112038161287d565b634e487b7160e01b600052604160045260246000fd5b604051610140810167ffffffffffffffff81118282101715612919576129196128df565b60405290565b604051601f8201601f1916810167ffffffffffffffff81118282101715612948576129486128df565b604052919050565b6000806040838503121561296357600080fd5b823561296e8161287d565b915060208381013567ffffffffffffffff8082111561298c57600080fd5b818601915086601f8301126129a057600080fd5b8135818111156129b2576129b26128df565b6129c4601f8201601f1916850161291f565b915080825287848285010111156129da57600080fd5b80848401858401376000848284010152508093505050509250929050565b803565ffffffffffff81168114612a0e57600080fd5b919050565b600060208284031215612a2557600080fd5b611203826129f8565b60005b83811015612a49578181015183820152602001612a31565b50506000910152565b6020815260008251806020840152612a71816040850160208701612a2e565b601f01601f19169190910160400192915050565b8035612a0e8161287d565b6000806000808486036101a0811215612aa857600080fd5b61014080821215612ab857600080fd5b612ac06128f5565b9150612acb87612a85565b8252612ad960208801612a85565b6020830152612aea60408801612a85565b6040830152612afb60608801612a85565b6060830152612b0c60808801612a85565b6080830152612b1d60a08801612a85565b60a0830152612b2e60c08801612a85565b60c0830152612b3f60e08801612a85565b60e0830152610100612b52818901612a85565b90830152610120612b64888201612a85565b8184015250819550612b77818801612a85565b94505050612b8861016086016129f8565b9150612b9761018086016129f8565b905092959194509250565b80516020808301519190811015612bc3576000198160200360031b1b821691505b50919050565b634e487b7160e01b600052601160045260246000fd5b65ffffffffffff818116838216019080821115612bfe57612bfe612bc9565b5092915050565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b19195b1959d85d1958d85b1b60a21b606082015260800190565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b6163746976652070726f787960a01b606082015260800190565b8181038181111561086857610868612bc9565b600060208284031215612cc257600080fd5b5051919050565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000815260008351612d4c816017850160208801612a2e565b7001034b99036b4b9b9b4b733903937b6329607d1b6017918401918201528351612d7d816028840160208801612a2e565b01602801949350505050565b6001600160a01b0392831681529116602082015260400190565b808202811582820484141761086857610868612bc9565b8082018082111561086857610868612bc9565b634e487b7160e01b600052603260045260246000fd5b600081612df257612df2612bc9565b506000190190565b60008251612e0c818460208701612a2e565b919091019291505056fe360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a264697066735822122047339a15725b818d9ed901f38d81cf253801ef8dda251fd3e34107d663b8991d64736f6c63430008130033
Deployed Bytecode
0x6080604052600436106102885760003560e01c8063590f6b1a1161015a578063bfe10928116100c1578063df23cbb11161007a578063df23cbb114610790578063e083b5e6146107a5578063e58378bb146107d2578063e63ab1e9146107e7578063f8aa0c4e146107fc578063fe8aa12a1461082257600080fd5b8063bfe10928146106ce578063c691af92146106ee578063c99dc3dd1461070f578063d547741f14610730578063dc8af5f614610750578063de1611cf1461077057600080fd5b806394c7f2991161011357806394c7f2991461062f578063979d7e861461064457806398f73e5214610664578063992e1d6a14610679578063a217fddf14610699578063abff0110146106ae57600080fd5b8063590f6b1a14610591578063656e96e1146105a65780636a28f000146105c6578063705a6618146105db57806375a8f926146105fa57806391d148541461060f57600080fd5b806336568abe116101fe5780634f1ef286116101b75780634f1ef286146104d45780635187ae68146104e757806352d1902d14610507578063531367631461051c57806353e23e2e1461053c57806354fd4d501461055d57600080fd5b806336568abe1461041f5780633659cfe61461043f57806340c65f721461045f57806341bf0c4e1461047f578063456068d21461049f5780634780a5e5146104b457600080fd5b8063248a9ca311610250578063248a9ca3146103225780632585a270146103605780632b56d18a146103755780632d870960146103b25780632f2439b1146103c75780632f2ff15d146103ff57600080fd5b806301ffc9a71461028d578063054f7d9c146102c25780630f702ed3146102e15780631031e36e146102f8578063181783581461030d575b600080fd5b34801561029957600080fd5b506102ad6102a836600461283a565b610837565b60405190151581526020015b60405180910390f35b3480156102ce57600080fd5b5060985465ffffffffffff1642106102ad565b3480156102ed57600080fd5b506102f661086e565b005b34801561030457600080fd5b506102f6610906565b34801561031957600080fd5b506102f6610995565b34801561032e57600080fd5b5061035261033d366004612864565b60009081526065602052604090206001015490565b6040519081526020016102b9565b34801561036c57600080fd5b506102f6610ae7565b34801561038157600080fd5b5060985461039b90600160301b900465ffffffffffff1681565b60405165ffffffffffff90911681526020016102b9565b3480156103be57600080fd5b50610352610b70565b3480156103d357600080fd5b5060cc546103e7906001600160a01b031681565b6040516001600160a01b0390911681526020016102b9565b34801561040b57600080fd5b506102f661041a366004612892565b610ba1565b34801561042b57600080fd5b506102f661043a366004612892565b610c77565b34801561044b57600080fd5b506102f661045a3660046128c2565b610cf5565b34801561046b57600080fd5b5060c9546103e7906001600160a01b031681565b34801561048b57600080fd5b5060d0546103e7906001600160a01b031681565b3480156104ab57600080fd5b506102f6610dd1565b3480156104c057600080fd5b5060ca546103e7906001600160a01b031681565b6102f66104e2366004612950565b610e5a565b3480156104f357600080fd5b506102f6610502366004612a13565b610f26565b34801561051357600080fd5b5061035261103e565b34801561052857600080fd5b5060cf546103e7906001600160a01b031681565b34801561054857600080fd5b506098546102ad90600160901b900460ff1681565b34801561056957600080fd5b5060408051808201825260058152640332e302e360dc1b602082015290516102b99190612a52565b34801561059d57600080fd5b506103526110f1565b3480156105b257600080fd5b5060d1546103e7906001600160a01b031681565b3480156105d257600080fd5b506102f6611120565b3480156105e757600080fd5b5060985461039b9065ffffffffffff1681565b34801561060657600080fd5b506102ad6111b3565b34801561061b57600080fd5b506102ad61062a366004612892565b6111dc565b34801561063b57600080fd5b506102f661120a565b34801561065057600080fd5b5060cb546103e7906001600160a01b031681565b34801561067057600080fd5b506102ad611249565b34801561068557600080fd5b506102f6610694366004612a90565b611270565b3480156106a557600080fd5b50610352600081565b3480156106ba57600080fd5b5060d2546103e7906001600160a01b031681565b3480156106da57600080fd5b5060ce546103e7906001600160a01b031681565b3480156106fa57600080fd5b506098546102ad90600160981b900460ff1681565b34801561071b57600080fd5b5061015f546103e7906001600160a01b031681565b34801561073c57600080fd5b506102f661074b366004612892565b611429565b34801561075c57600080fd5b5060cd546103e7906001600160a01b031681565b34801561077c57600080fd5b506102f661078b366004612a13565b61144e565b34801561079c57600080fd5b506102f6611568565b3480156107b157600080fd5b506103526107c03660046128c2565b60976020526000908152604090205481565b3480156107de57600080fd5b506103526115f7565b3480156107f357600080fd5b5061035261161e565b34801561080857600080fd5b5060985461039b90600160601b900465ffffffffffff1681565b34801561082e57600080fd5b506102f6611646565b60006001600160e01b03198216637965db0b60e01b148061086857506301ffc9a760e01b6001600160e01b03198316145b92915050565b6040518060400160405280600d81526020016c29a427a92a2fa32922a2ad22a960991b81525061089d90612ba2565b6108a681611709565b6108de6040518060400160405280600d81526020016c29a427a92a2fa32922a2ad22a960991b8152506108d890612ba2565b33611713565b609854610903906108fe90600160301b900465ffffffffffff1642612bdf565b61177a565b50565b604051806040016040528060068152602001652820aaa9a2a960d11b81525061092e90612ba2565b61093781611709565b60985460408051600160901b90920460ff1615158252600160208301527f87161063ac9982961a7044485445fe4f7bb1a458f731e5ad5ca31b97f3d452bf910160405180910390a1506098805460ff60901b1916600160901b179055565b60cb60009054906101000a90046001600160a01b03166001600160a01b031663f8ac93e86040518163ffffffff1660e01b8152600401600060405180830381600087803b1580156109e557600080fd5b505af11580156109f9573d6000803e3d6000fd5b50505050610a1060985465ffffffffffff16421090565b610a7d5760d160009054906101000a90046001600160a01b03166001600160a01b0316635220f5106040518163ffffffff1660e01b8152600401600060405180830381600087803b158015610a6457600080fd5b505af1158015610a78573d6000803e3d6000fd5b505050505b60ca60009054906101000a90046001600160a01b03166001600160a01b031663296130866040518163ffffffff1660e01b8152600401600060405180830381600087803b158015610acd57600080fd5b505af1158015610ae1573d6000803e3d6000fd5b50505050565b604051806040016040528060068152602001652820aaa9a2a960d11b815250610b0f90612ba2565b610b1881611709565b60985460408051600160981b90920460ff1615158252600060208301527f5ab09e6f82d5fade96a17975df4c40286cfcce3b71eeea0f1c76567f0296447d910160405180910390a1506098805460ff60981b19169055565b6040518060400160405280600c81526020016b2627a723afa32922a2ad22a960a11b815250610b9e90612ba2565b81565b600082815260656020526040902060010154610bbc81611709565b6001600160a01b038216610c175760405162461bcd60e51b815260206004820152601e60248201527f63616e6e6f74206772616e7420726f6c6520746f20616464726573732030000060448201526064015b60405180910390fd5b6040518060400160405280600c81526020016b2627a723afa32922a2ad22a960a11b815250610c4590612ba2565b8303610c68576001600160a01b0382166000908152609760205260409020600690555b610c728383611826565b505050565b6001600160a01b0381163314610ce75760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b6064820152608401610c0e565b610cf18282611713565b5050565b6001600160a01b037f000000000000000000000000f5366f67ff66a3cefcb18809a762d5b5931febf8163003610d3d5760405162461bcd60e51b8152600401610c0e90612c05565b7f000000000000000000000000f5366f67ff66a3cefcb18809a762d5b5931febf86001600160a01b0316610d86600080516020612e17833981519152546001600160a01b031690565b6001600160a01b031614610dac5760405162461bcd60e51b8152600401610c0e90612c51565b610db5816118ac565b60408051600080825260208201909252610903918391906118dc565b604051806040016040528060068152602001652820aaa9a2a960d11b815250610df990612ba2565b610e0281611709565b60985460408051600160901b90920460ff1615158252600060208301527f87161063ac9982961a7044485445fe4f7bb1a458f731e5ad5ca31b97f3d452bf910160405180910390a1506098805460ff60901b19169055565b6001600160a01b037f000000000000000000000000f5366f67ff66a3cefcb18809a762d5b5931febf8163003610ea25760405162461bcd60e51b8152600401610c0e90612c05565b7f000000000000000000000000f5366f67ff66a3cefcb18809a762d5b5931febf86001600160a01b0316610eeb600080516020612e17833981519152546001600160a01b031690565b6001600160a01b031614610f115760405162461bcd60e51b8152600401610c0e90612c51565b610f1a826118ac565b610cf1828260016118dc565b6040518060400160405280600581526020016427aba722a960d91b815250610f4d90612ba2565b610f5681611709565b60008265ffffffffffff16118015610f7a57506301e1338065ffffffffffff831611155b610fc65760405162461bcd60e51b815260206004820152601860248201527f6c6f6e6720667265657a65206f7574206f662072616e676500000000000000006044820152606401610c0e565b6098546040805165ffffffffffff600160601b9093048316815291841660208301527f2b855a9093ce8fb8bd37179aa306b424a5008d3a000751f4c2e721c51b89f9a2910160405180910390a1506098805465ffffffffffff909216600160601b0265ffffffffffff60601b19909216919091179055565b6000306001600160a01b037f000000000000000000000000f5366f67ff66a3cefcb18809a762d5b5931febf816146110de5760405162461bcd60e51b815260206004820152603860248201527f555550535570677261646561626c653a206d757374206e6f742062652063616c60448201527f6c6564207468726f7567682064656c656761746563616c6c00000000000000006064820152608401610c0e565b50600080516020612e1783398151915290565b6040518060400160405280600d81526020016c29a427a92a2fa32922a2ad22a960991b815250610b9e90612ba2565b6040518060400160405280600581526020016427aba722a960d91b81525061114790612ba2565b61115081611709565b6098546040805165ffffffffffff92831681524290921660208301527f4fd793fe252ef26ede0a814ca52971990ff5ade10f86376fb1914bfb17c57e08910160405180910390a1506098805465ffffffffffff19164265ffffffffffff16179055565b609854600090600160981b900460ff16806111d7575060985465ffffffffffff1642105b905090565b60008281526065602090815260408083206001600160a01b038516845290915281205460ff165b9392505050565b6040518060400160405280600581526020016427aba722a960d91b81525061123190612ba2565b61123a81611709565b61090365ffffffffffff61177a565b609854600090600160901b900460ff16806111d757505060985465ffffffffffff16421090565b600054610100900460ff16158080156112905750600054600160ff909116105b806112aa5750303b1580156112aa575060005460ff166001145b61130d5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610c0e565b6000805460ff191660011790558015611330576000805461ff0019166101001790555b6001600160a01b03841661137c5760405162461bcd60e51b8152602060048201526013602482015272696e76616c696420525352206164647265737360681b6044820152606401610c0e565b6113868383611a47565b61138f85611b9c565b611397611c45565b61015f80546001600160a01b0319166001600160a01b0386161790556040517fb3d8a26384852953cab1d93ea954a4ac74e1dc9f5c29576d4a4f45cdb230130e90600090a18015611422576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b5050505050565b60008281526065602052604090206001015461144481611709565b610c728383611713565b6040518060400160405280600581526020016427aba722a960d91b81525061147590612ba2565b61147e81611709565b60008265ffffffffffff161180156114a1575062278d0065ffffffffffff831611155b6114ed5760405162461bcd60e51b815260206004820152601960248201527f73686f727420667265657a65206f7574206f662072616e6765000000000000006044820152606401610c0e565b6098546040805165ffffffffffff600160301b9093048316815291841660208301527f84af4c1855ea2ef70449c6ae7119d367873ea35277b9681e0e47898900266f94910160405180910390a1506098805465ffffffffffff909216600160301b026bffffffffffff00000000000019909216919091179055565b604051806040016040528060068152602001652820aaa9a2a960d11b81525061159090612ba2565b61159981611709565b60985460408051600160981b90920460ff1615158252600160208301527f5ab09e6f82d5fade96a17975df4c40286cfcce3b71eeea0f1c76567f0296447d910160405180910390a1506098805460ff60981b1916600160981b179055565b6040518060400160405280600581526020016427aba722a960d91b815250610b9e90612ba2565b604051806040016040528060068152602001652820aaa9a2a960d11b815250610b9e90612ba2565b6040518060400160405280600c81526020016b2627a723afa32922a2ad22a960a11b81525061167490612ba2565b61167d81611709565b33600090815260976020526040812080546001929061169d908490612c9d565b90915550503360009081526097602052604081205490036116e9576116e96040518060400160405280600c81526020016b2627a723afa32922a2ad22a960a11b8152506108d890612ba2565b609854610903906108fe90600160601b900465ffffffffffff1642612bdf565b6109038133611c6e565b61171d82826111dc565b15610cf15760008281526065602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b60985465ffffffffffff908116908216116117c05760405162461bcd60e51b8152602060048201526006602482015265333937bd32b760d11b6044820152606401610c0e565b6098546040805165ffffffffffff928316815291831660208301527f4fd793fe252ef26ede0a814ca52971990ff5ade10f86376fb1914bfb17c57e08910160405180910390a16098805465ffffffffffff191665ffffffffffff92909216919091179055565b61183082826111dc565b610cf15760008281526065602090815260408083206001600160a01b03851684529091529020805460ff191660011790556118683390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6040518060400160405280600581526020016427aba722a960d91b8152506118d390612ba2565b610cf181611709565b7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd91435460ff161561190f57610c7283611cd2565b826001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015611969575060408051601f3d908101601f1916820190925261196691810190612cb0565b60015b6119cc5760405162461bcd60e51b815260206004820152602e60248201527f45524331393637557067726164653a206e657720696d706c656d656e7461746960448201526d6f6e206973206e6f74205555505360901b6064820152608401610c0e565b600080516020612e178339815191528114611a3b5760405162461bcd60e51b815260206004820152602960248201527f45524331393637557067726164653a20756e737570706f727465642070726f786044820152681a58589b195555525160ba1b6064820152608401610c0e565b50610c72838383611d6e565b600054610100900460ff16611a6e5760405162461bcd60e51b8152600401610c0e90612cc9565b611a76611c45565b611acc6040518060400160405280600581526020016427aba722a960d91b815250611aa090612ba2565b6040518060400160405280600581526020016427aba722a960d91b815250611ac790612ba2565b611d93565b611afe6040518060400160405280600d81526020016c29a427a92a2fa32922a2ad22a960991b815250611aa090612ba2565b611b2f6040518060400160405280600c81526020016b2627a723afa32922a2ad22a960a11b815250611aa090612ba2565b611b5a604051806040016040528060068152602001652820aaa9a2a960d11b815250611aa090612ba2565b611b8a6040518060400160405280600581526020016427aba722a960d91b815250611b8490612ba2565b33611826565b611b938261144e565b610cf181610f26565b600054610100900460ff16611bc35760405162461bcd60e51b8152600401610c0e90612cc9565b611bd08160800151611dde565b611bdd8160600151611e9d565b611beb816101000151611f5c565b611bf981610120015161201b565b611c0681604001516120da565b611c138160a00151612199565b611c208160c00151612258565b611c2d8160e00151612317565b611c3a81602001516123cf565b805161090390612486565b600054610100900460ff16611c6c5760405162461bcd60e51b8152600401610c0e90612cc9565b565b611c7882826111dc565b610cf157611c90816001600160a01b03166014612531565b611c9b836020612531565b604051602001611cac929190612d14565b60408051601f198184030181529082905262461bcd60e51b8252610c0e91600401612a52565b6001600160a01b0381163b611d3f5760405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b6064820152608401610c0e565b600080516020612e1783398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b611d77836126cd565b600082511180611d845750805b15610c7257610ae1838361270d565b600082815260656020526040808220600101805490849055905190918391839186917fbd79b86ffe0ab8e8776151514217cd7cacd52c909f66475c3af44e129f0b00ff9190a4505050565b6001600160a01b038116611e345760405162461bcd60e51b815260206004820152601e60248201527f696e76616c6964204261636b696e674d616e61676572206164647265737300006044820152606401610c0e565b60cd546040517fd4ec685c4e7367fc82d24a1c90d8c91c07a0e204b5b4655fc1a6d5b6b9d9eeb791611e73916001600160a01b03909116908490612d89565b60405180910390a160cd80546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b038116611ef35760405162461bcd60e51b815260206004820152601d60248201527f696e76616c6964204261736b657448616e646c657220616464726573730000006044820152606401610c0e565b60cc546040517fa41efa7d680b9ae9379ca75b956c50587b28ed07453f7d19388c7199397a1e8e91611f32916001600160a01b03909116908490612d89565b60405180910390a160cc80546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b038116611fb25760405162461bcd60e51b815260206004820152601960248201527f696e76616c6964205253525472616465722061646472657373000000000000006044820152606401610c0e565b60cf546040517f2fa6596476f0ebdb5fef9a37bedb7ef956e0e1c4e094464cbf49c38f44f7e8d191611ff1916001600160a01b03909116908490612d89565b60405180910390a160cf80546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b0381166120715760405162461bcd60e51b815260206004820152601c60248201527f696e76616c69642052546f6b656e5472616465722061646472657373000000006044820152606401610c0e565b60d0546040517f0d76a5d5849780e9a81127e61df7ee55bf3f766bc326510d3a52ede3caea168f916120b0916001600160a01b03909116908490612d89565b60405180910390a160d080546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b0381166121305760405162461bcd60e51b815260206004820152601d60248201527f696e76616c6964204173736574526567697374727920616464726573730000006044820152606401610c0e565b60cb546040517f5c69d378772ea2f02015deabd3b7ee1db0851dba819e216585de7a155d22a1489161216f916001600160a01b03909116908490612d89565b60405180910390a160cb80546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b0381166121ef5760405162461bcd60e51b815260206004820152601b60248201527f696e76616c6964204469737472696275746f72206164647265737300000000006044820152606401610c0e565b60ce546040517f8c6eabd1db7fe5a1951a7c78767c0e3633c5352578d15d45f99aa4c4db01c55a9161222e916001600160a01b03909116908490612d89565b60405180910390a160ce80546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b0381166122ae5760405162461bcd60e51b815260206004820152601760248201527f696e76616c6964204675726e61636520616464726573730000000000000000006044820152606401610c0e565b60d1546040517fe0c9d7fae2ccca1a3980ce26aada40d9f7fc84406cdb3adbdcfb8f9dd21c9b53916122ed916001600160a01b03909116908490612d89565b60405180910390a160d180546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b0381166123665760405162461bcd60e51b8152602060048201526016602482015275696e76616c69642042726f6b6572206164647265737360501b6044820152606401610c0e565b60d2546040517fc29cab4074359a76aba74458623910a8b95269ded89ad9f98cd2db1de3ead356916123a5916001600160a01b03909116908490612d89565b60405180910390a160d280546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b03811661241d5760405162461bcd60e51b8152602060048201526015602482015274696e76616c6964205374525352206164647265737360581b6044820152606401610c0e565b60ca546040517f1b29dc90e15d6ade122a9e27d886b4a077e66131c7e0cc805fc303e49690c9fc9161245c916001600160a01b03909116908490612d89565b60405180910390a160ca80546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b0381166124d55760405162461bcd60e51b8152602060048201526016602482015275696e76616c69642052546f6b656e206164647265737360501b6044820152606401610c0e565b60c9546040516001600160a01b038084169216907f2d2909c1d06afe38080a70d63a8793874674efb0fdf3b3bf3fd046056688b3ea90600090a360c980546001600160a01b0319166001600160a01b0392909216919091179055565b60606000612540836002612da3565b61254b906002612dba565b67ffffffffffffffff811115612563576125636128df565b6040519080825280601f01601f19166020018201604052801561258d576020820181803683370190505b509050600360fc1b816000815181106125a8576125a8612dcd565b60200101906001600160f81b031916908160001a905350600f60fb1b816001815181106125d7576125d7612dcd565b60200101906001600160f81b031916908160001a90535060006125fb846002612da3565b612606906001612dba565b90505b600181111561267e576f181899199a1a9b1b9c1cb0b131b232b360811b85600f166010811061263a5761263a612dcd565b1a60f81b82828151811061265057612650612dcd565b60200101906001600160f81b031916908160001a90535060049490941c9361267781612de3565b9050612609565b5083156112035760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610c0e565b6126d681611cd2565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a250565b60606001600160a01b0383163b6127755760405162461bcd60e51b815260206004820152602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f6044820152651b9d1c9858dd60d21b6064820152608401610c0e565b600080846001600160a01b0316846040516127909190612dfa565b600060405180830381855af49150503d80600081146127cb576040519150601f19603f3d011682016040523d82523d6000602084013e6127d0565b606091505b50915091506127f88282604051806060016040528060278152602001612e3760279139612801565b95945050505050565b60608315612810575081611203565b8251156128205782518084602001fd5b8160405162461bcd60e51b8152600401610c0e9190612a52565b60006020828403121561284c57600080fd5b81356001600160e01b03198116811461120357600080fd5b60006020828403121561287657600080fd5b5035919050565b6001600160a01b038116811461090357600080fd5b600080604083850312156128a557600080fd5b8235915060208301356128b78161287d565b809150509250929050565b6000602082840312156128d457600080fd5b81356112038161287d565b634e487b7160e01b600052604160045260246000fd5b604051610140810167ffffffffffffffff81118282101715612919576129196128df565b60405290565b604051601f8201601f1916810167ffffffffffffffff81118282101715612948576129486128df565b604052919050565b6000806040838503121561296357600080fd5b823561296e8161287d565b915060208381013567ffffffffffffffff8082111561298c57600080fd5b818601915086601f8301126129a057600080fd5b8135818111156129b2576129b26128df565b6129c4601f8201601f1916850161291f565b915080825287848285010111156129da57600080fd5b80848401858401376000848284010152508093505050509250929050565b803565ffffffffffff81168114612a0e57600080fd5b919050565b600060208284031215612a2557600080fd5b611203826129f8565b60005b83811015612a49578181015183820152602001612a31565b50506000910152565b6020815260008251806020840152612a71816040850160208701612a2e565b601f01601f19169190910160400192915050565b8035612a0e8161287d565b6000806000808486036101a0811215612aa857600080fd5b61014080821215612ab857600080fd5b612ac06128f5565b9150612acb87612a85565b8252612ad960208801612a85565b6020830152612aea60408801612a85565b6040830152612afb60608801612a85565b6060830152612b0c60808801612a85565b6080830152612b1d60a08801612a85565b60a0830152612b2e60c08801612a85565b60c0830152612b3f60e08801612a85565b60e0830152610100612b52818901612a85565b90830152610120612b64888201612a85565b8184015250819550612b77818801612a85565b94505050612b8861016086016129f8565b9150612b9761018086016129f8565b905092959194509250565b80516020808301519190811015612bc3576000198160200360031b1b821691505b50919050565b634e487b7160e01b600052601160045260246000fd5b65ffffffffffff818116838216019080821115612bfe57612bfe612bc9565b5092915050565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b19195b1959d85d1958d85b1b60a21b606082015260800190565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b6163746976652070726f787960a01b606082015260800190565b8181038181111561086857610868612bc9565b600060208284031215612cc257600080fd5b5051919050565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000815260008351612d4c816017850160208801612a2e565b7001034b99036b4b9b9b4b733903937b6329607d1b6017918401918201528351612d7d816028840160208801612a2e565b01602801949350505050565b6001600160a01b0392831681529116602082015260400190565b808202811582820484141761086857610868612bc9565b8082018082111561086857610868612bc9565b634e487b7160e01b600052603260045260246000fd5b600081612df257612df2612bc9565b506000190190565b60008251612e0c818460208701612a2e565b919091019291505056fe360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a264697066735822122047339a15725b818d9ed901f38d81cf253801ef8dda251fd3e34107d663b8991d64736f6c63430008130033
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in ETH
0
Multichain Portfolio | 33 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.