Source Code
Overview
ETH Balance
0 ETH
ETH Value
$0.00View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Cross-Chain Transactions
Loading...
Loading
Contract Name:
KmiUsdRedemptionVaultWithSwapper
Compiler Version
v0.8.9+commit.e5eed63a
Optimization Enabled:
Yes with 200 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
import "../RedemptionVaultWithSwapper.sol";
import "./KmiUsdMidasAccessControlRoles.sol";
/**
* @title KmiUsdRedemptionVaultWithSwapper
* @notice Smart contract that handles kmiUSD redemptions
* @author RedDuck Software
*/
contract KmiUsdRedemptionVaultWithSwapper is
RedemptionVaultWithSwapper,
KmiUsdMidasAccessControlRoles
{
/**
* @dev leaving a storage gap for futures updates
*/
uint256[50] private __gap;
/**
* @inheritdoc ManageableVault
*/
function vaultRole() public pure override returns (bytes32) {
return KMI_USD_REDEMPTION_VAULT_ADMIN_ROLE;
}
}// 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.9.0) (access/AccessControl.sol)
pragma solidity ^0.8.0;
import "./IAccessControlUpgradeable.sol";
import "../utils/ContextUpgradeable.sol";
import "../utils/StringsUpgradeable.sol";
import "../utils/introspection/ERC165Upgradeable.sol";
import "../proxy/utils/Initializable.sol";
/**
* @dev Contract module that allows children to implement role-based access
* control mechanisms. This is a lightweight version that doesn't allow enumerating role
* members except through off-chain means by accessing the contract event logs. Some
* applications may benefit from on-chain enumerability, for those cases see
* {AccessControlEnumerable}.
*
* Roles are referred to by their `bytes32` identifier. These should be exposed
* in the external API and be unique. The best way to achieve this is by
* using `public constant` hash digests:
*
* ```solidity
* bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
* ```
*
* Roles can be used to represent a set of permissions. To restrict access to a
* function call, use {hasRole}:
*
* ```solidity
* function foo() public {
* require(hasRole(MY_ROLE, msg.sender));
* ...
* }
* ```
*
* Roles can be granted and revoked dynamically via the {grantRole} and
* {revokeRole} functions. Each role has an associated admin role, and only
* accounts that have a role's admin role can call {grantRole} and {revokeRole}.
*
* By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
* that only accounts with this role will be able to grant or revoke other
* roles. More complex role relationships can be created by using
* {_setRoleAdmin}.
*
* WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
* grant and revoke this role. Extra precautions should be taken to secure
* accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules}
* to enforce additional security measures for this role.
*/
abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControlUpgradeable, ERC165Upgradeable {
function __AccessControl_init() internal onlyInitializing {
}
function __AccessControl_init_unchained() internal onlyInitializing {
}
struct RoleData {
mapping(address => bool) members;
bytes32 adminRole;
}
mapping(bytes32 => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
/**
* @dev Modifier that checks that an account has a specific role. Reverts
* with a standardized message including the required role.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*
* _Available since v4.1._
*/
modifier onlyRole(bytes32 role) {
_checkRole(role);
_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControlUpgradeable).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) public view virtual override returns (bool) {
return _roles[role].members[account];
}
/**
* @dev Revert with a standard message if `_msgSender()` is missing `role`.
* Overriding this function changes the behavior of the {onlyRole} modifier.
*
* Format of the revert message is described in {_checkRole}.
*
* _Available since v4.6._
*/
function _checkRole(bytes32 role) internal view virtual {
_checkRole(role, _msgSender());
}
/**
* @dev Revert with a standard message if `account` is missing `role`.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*/
function _checkRole(bytes32 role, address account) internal view virtual {
if (!hasRole(role, account)) {
revert(
string(
abi.encodePacked(
"AccessControl: account ",
StringsUpgradeable.toHexString(account),
" is missing role ",
StringsUpgradeable.toHexString(uint256(role), 32)
)
)
);
}
}
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {
return _roles[role].adminRole;
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleGranted} event.
*/
function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_grantRole(role, account);
}
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleRevoked} event.
*/
function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
}
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been revoked `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*
* May emit a {RoleRevoked} event.
*/
function renounceRole(bytes32 role, address account) public virtual override {
require(account == _msgSender(), "AccessControl: can only renounce roles for self");
_revokeRole(role, account);
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event. Note that unlike {grantRole}, this function doesn't perform any
* checks on the calling account.
*
* May emit a {RoleGranted} event.
*
* [WARNING]
* ====
* This function should only be called from the constructor when setting
* up the initial roles for the system.
*
* Using this function in any other way is effectively circumventing the admin
* system imposed by {AccessControl}.
* ====
*
* NOTE: This function is deprecated in favor of {_grantRole}.
*/
function _setupRole(bytes32 role, address account) internal virtual {
_grantRole(role, account);
}
/**
* @dev Sets `adminRole` as ``role``'s admin role.
*
* Emits a {RoleAdminChanged} event.
*/
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
bytes32 previousAdminRole = getRoleAdmin(role);
_roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
/**
* @dev Grants `role` to `account`.
*
* Internal function without access restriction.
*
* May emit a {RoleGranted} event.
*/
function _grantRole(bytes32 role, address account) internal virtual {
if (!hasRole(role, account)) {
_roles[role].members[account] = true;
emit RoleGranted(role, account, _msgSender());
}
}
/**
* @dev Revokes `role` from `account`.
*
* Internal function without access restriction.
*
* May emit a {RoleRevoked} event.
*/
function _revokeRole(bytes32 role, address account) internal virtual {
if (hasRole(role, account)) {
_roles[role].members[account] = false;
emit RoleRevoked(role, account, _msgSender());
}
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[49] private __gap;
}// 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.9.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.2;
import "../../utils/AddressUpgradeable.sol";
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```solidity
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
*
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Indicates that the contract has been initialized.
* @custom:oz-retyped-from bool
*/
uint8 private _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private _initializing;
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint8 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts.
*
* Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a
* constructor.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
bool isTopLevelCall = !_initializing;
require(
(isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
"Initializable: contract is already initialized"
);
_initialized = 1;
if (isTopLevelCall) {
_initializing = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* A reinitializer may be used after the original initialization step. This is essential to configure modules that
* are added through upgrades and that require initialization.
*
* When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
* cannot be nested. If one is invoked in the context of another, execution will revert.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*
* WARNING: setting the version to 255 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint8 version) {
require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
_initialized = version;
_initializing = true;
_;
_initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
require(_initializing, "Initializable: contract is not initializing");
_;
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*
* Emits an {Initialized} event the first time it is successfully executed.
*/
function _disableInitializers() internal virtual {
require(!_initializing, "Initializable: contract is initializing");
if (_initialized != type(uint8).max) {
_initialized = type(uint8).max;
emit Initialized(type(uint8).max);
}
}
/**
* @dev Returns the highest version that has been initialized. See {reinitializer}.
*/
function _getInitializedVersion() internal view returns (uint8) {
return _initialized;
}
/**
* @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
*/
function _isInitializing() internal view returns (bool) {
return _initializing;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)
pragma solidity ^0.8.0;
import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.sol";
/**
* @dev Contract module which allows children to implement an emergency stop
* mechanism that can be triggered by an authorized account.
*
* This module is used through inheritance. It will make available the
* modifiers `whenNotPaused` and `whenPaused`, which can be applied to
* the functions of your contract. Note that they will not be pausable by
* simply including this module, only once the modifiers are put in place.
*/
abstract contract PausableUpgradeable is Initializable, ContextUpgradeable {
/**
* @dev Emitted when the pause is triggered by `account`.
*/
event Paused(address account);
/**
* @dev Emitted when the pause is lifted by `account`.
*/
event Unpaused(address account);
bool private _paused;
/**
* @dev Initializes the contract in unpaused state.
*/
function __Pausable_init() internal onlyInitializing {
__Pausable_init_unchained();
}
function __Pausable_init_unchained() internal onlyInitializing {
_paused = false;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
_requireNotPaused();
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
_requirePaused();
_;
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
return _paused;
}
/**
* @dev Throws if the contract is paused.
*/
function _requireNotPaused() internal view virtual {
require(!paused(), "Pausable: paused");
}
/**
* @dev Throws if the contract is not paused.
*/
function _requirePaused() internal view virtual {
require(paused(), "Pausable: not paused");
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
*/
function _pause() internal virtual whenNotPaused {
_paused = true;
emit Paused(_msgSender());
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/
function _unpause() internal virtual whenPaused {
_paused = false;
emit Unpaused(_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 (last updated v4.9.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.0;
import "./IERC20Upgradeable.sol";
import "./extensions/IERC20MetadataUpgradeable.sol";
import "../../utils/ContextUpgradeable.sol";
import "../../proxy/utils/Initializable.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* The default value of {decimals} is 18. To change this, you should override
* this function so it returns a different value.
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC20
* applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable, IERC20MetadataUpgradeable {
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
function __ERC20_init(string memory name_, string memory symbol_) internal onlyInitializing {
__ERC20_init_unchained(name_, symbol_);
}
function __ERC20_init_unchained(string memory name_, string memory symbol_) internal onlyInitializing {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the default value returned by this function, unless
* it's overridden.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual override returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address to, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_transfer(owner, to, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_approve(owner, spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
* - the caller must have allowance for ``from``'s tokens of at least
* `amount`.
*/
function transferFrom(address from, address to, uint256 amount) public virtual override returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, amount);
_transfer(from, to, amount);
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, allowance(owner, spender) + addedValue);
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
address owner = _msgSender();
uint256 currentAllowance = allowance(owner, spender);
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked {
_approve(owner, spender, currentAllowance - subtractedValue);
}
return true;
}
/**
* @dev Moves `amount` of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
*/
function _transfer(address from, address to, uint256 amount) internal virtual {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(from, to, amount);
uint256 fromBalance = _balances[from];
require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[from] = fromBalance - amount;
// Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by
// decrementing then incrementing.
_balances[to] += amount;
}
emit Transfer(from, to, amount);
_afterTokenTransfer(from, to, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply += amount;
unchecked {
// Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.
_balances[account] += amount;
}
emit Transfer(address(0), account, amount);
_afterTokenTransfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[account] = accountBalance - amount;
// Overflow not possible: amount <= accountBalance <= totalSupply.
_totalSupply -= amount;
}
emit Transfer(account, address(0), amount);
_afterTokenTransfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Updates `owner` s allowance for `spender` based on spent `amount`.
*
* Does not update the allowance amount in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Might emit an {Approval} event.
*/
function _spendAllowance(address owner, address spender, uint256 amount) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
require(currentAllowance >= amount, "ERC20: insufficient allowance");
unchecked {
_approve(owner, spender, currentAllowance - amount);
}
}
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual {}
/**
* @dev Hook that is called after any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* has been transferred to `to`.
* - when `from` is zero, `amount` tokens have been minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens have been burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(address from, address to, uint256 amount) 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[45] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/ERC20Pausable.sol)
pragma solidity ^0.8.0;
import "../ERC20Upgradeable.sol";
import "../../../security/PausableUpgradeable.sol";
import "../../../proxy/utils/Initializable.sol";
/**
* @dev ERC20 token with pausable token transfers, minting and burning.
*
* Useful for scenarios such as preventing trades until the end of an evaluation
* period, or having an emergency switch for freezing all token transfers in the
* event of a large bug.
*
* IMPORTANT: This contract does not include public pause and unpause functions. In
* addition to inheriting this contract, you must define both functions, invoking the
* {Pausable-_pause} and {Pausable-_unpause} internal functions, with appropriate
* access control, e.g. using {AccessControl} or {Ownable}. Not doing so will
* make the contract unpausable.
*/
abstract contract ERC20PausableUpgradeable is Initializable, ERC20Upgradeable, PausableUpgradeable {
function __ERC20Pausable_init() internal onlyInitializing {
__Pausable_init_unchained();
}
function __ERC20Pausable_init_unchained() internal onlyInitializing {
}
/**
* @dev See {ERC20-_beforeTokenTransfer}.
*
* Requirements:
*
* - the contract must not be paused.
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual override {
super._beforeTokenTransfer(from, to, amount);
require(!paused(), "ERC20Pausable: token transfer while paused");
}
/**
* @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/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.9.0) (token/ERC20/extensions/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 (last updated v4.9.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.9.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20Upgradeable.sol";
import "../extensions/IERC20PermitUpgradeable.sol";
import "../../../utils/AddressUpgradeable.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20Upgradeable {
using AddressUpgradeable for address;
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20Upgradeable token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20Upgradeable token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(IERC20Upgradeable token, address spender, uint256 value) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeIncreaseAllowance(IERC20Upgradeable token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeDecreaseAllowance(IERC20Upgradeable token, address spender, uint256 value) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Compatible with tokens that require the approval to be set to
* 0 before setting it to a non-zero value.
*/
function forceApprove(IERC20Upgradeable token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
* Revert on invalid signature.
*/
function safePermit(
IERC20PermitUpgradeable token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20Upgradeable token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20Upgradeable token, bytes memory data) private returns (bool) {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return
success && (returndata.length == 0 || abi.decode(returndata, (bool))) && AddressUpgradeable.isContract(address(token));
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library AddressUpgradeable {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}// 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.9.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library MathUpgradeable {
enum Rounding {
Down, // Toward negative infinity
Up, // Toward infinity
Zero // Toward zero
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds up instead
* of rounding down.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
* with further edits by Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
require(denominator > prod1, "Math: mulDiv overflow");
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
// See https://cs.stackexchange.com/q/138556/92363.
// Does not overflow because the denominator cannot be zero at this stage in the function.
uint256 twos = denominator & (~denominator + 1);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
// in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256, rounded down, of a positive value.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard signed math utilities missing in the Solidity language.
*/
library SignedMathUpgradeable {
/**
* @dev Returns the largest of two signed numbers.
*/
function max(int256 a, int256 b) internal pure returns (int256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two signed numbers.
*/
function min(int256 a, int256 b) internal pure returns (int256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two signed numbers without overflow.
* The result is rounded towards zero.
*/
function average(int256 a, int256 b) internal pure returns (int256) {
// Formula from the book "Hacker's Delight"
int256 x = (a & b) + ((a ^ b) >> 1);
return x + (int256(uint256(x) >> 255) & (a ^ b));
}
/**
* @dev Returns the absolute unsigned value of a signed value.
*/
function abs(int256 n) internal pure returns (uint256) {
unchecked {
// must be unchecked in order to support `n = type(int256).min`
return uint256(n >= 0 ? n : -n);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol)
pragma solidity ^0.8.0;
import "./math/MathUpgradeable.sol";
import "./math/SignedMathUpgradeable.sol";
/**
* @dev String operations.
*/
library StringsUpgradeable {
bytes16 private constant _SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = MathUpgradeable.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
/// @solidity memory-safe-assembly
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
/// @solidity memory-safe-assembly
assembly {
mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `int256` to its ASCII `string` decimal representation.
*/
function toString(int256 value) internal pure returns (string memory) {
return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMathUpgradeable.abs(value))));
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, MathUpgradeable.log256(value) + 1);
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}
/**
* @dev Returns true if the two strings are equal.
*/
function equal(string memory a, string memory b) internal pure returns (bool) {
return keccak256(bytes(a)) == keccak256(bytes(b));
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.
pragma solidity ^0.8.0;
/**
* @dev Library for managing
* https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
* types.
*
* Sets have the following properties:
*
* - Elements are added, removed, and checked for existence in constant time
* (O(1)).
* - Elements are enumerated in O(n). No guarantees are made on the ordering.
*
* ```solidity
* contract Example {
* // Add the library methods
* using EnumerableSet for EnumerableSet.AddressSet;
*
* // Declare a set state variable
* EnumerableSet.AddressSet private mySet;
* }
* ```
*
* As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
* and `uint256` (`UintSet`) are supported.
*
* [WARNING]
* ====
* Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
* unusable.
* See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
*
* In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
* array of EnumerableSet.
* ====
*/
library EnumerableSetUpgradeable {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Set type with
// bytes32 values.
// The Set implementation uses private functions, and user-facing
// implementations (such as AddressSet) are just wrappers around the
// underlying Set.
// This means that we can only create new EnumerableSets for types that fit
// in bytes32.
struct Set {
// Storage of set values
bytes32[] _values;
// Position of the value in the `values` array, plus 1 because index 0
// means a value is not in the set.
mapping(bytes32 => uint256) _indexes;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
// The value is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
set._indexes[value] = set._values.length;
return true;
} else {
return false;
}
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function _remove(Set storage set, bytes32 value) private returns (bool) {
// We read and store the value's index to prevent multiple reads from the same storage slot
uint256 valueIndex = set._indexes[value];
if (valueIndex != 0) {
// Equivalent to contains(set, value)
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
// the array, and then remove the last element (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 toDeleteIndex = valueIndex - 1;
uint256 lastIndex = set._values.length - 1;
if (lastIndex != toDeleteIndex) {
bytes32 lastValue = set._values[lastIndex];
// Move the last value to the index where the value to delete is
set._values[toDeleteIndex] = lastValue;
// Update the index for the moved value
set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex
}
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the index for the deleted slot
delete set._indexes[value];
return true;
} else {
return false;
}
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._indexes[value] != 0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function _at(Set storage set, uint256 index) private view returns (bytes32) {
return set._values[index];
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function _values(Set storage set) private view returns (bytes32[] memory) {
return set._values;
}
// Bytes32Set
struct Bytes32Set {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
bytes32[] memory store = _values(set._inner);
bytes32[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// AddressSet
struct AddressSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(AddressSet storage set) internal view returns (address[] memory) {
bytes32[] memory store = _values(set._inner);
address[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// UintSet
struct UintSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(UintSet storage set) internal view returns (uint256[] memory) {
bytes32[] memory store = _values(set._inner);
uint256[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Counters.sol)
pragma solidity ^0.8.0;
/**
* @title Counters
* @author Matt Condon (@shrugs)
* @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number
* of elements in a mapping, issuing ERC721 ids, or counting request ids.
*
* Include with `using Counters for Counters.Counter;`
*/
library Counters {
struct Counter {
// This variable should never be directly accessed by users of the library: interactions must be restricted to
// the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add
// this feature: see https://github.com/ethereum/solidity/issues/4637
uint256 _value; // default: 0
}
function current(Counter storage counter) internal view returns (uint256) {
return counter._value;
}
function increment(Counter storage counter) internal {
unchecked {
counter._value += 1;
}
}
function decrement(Counter storage counter) internal {
uint256 value = counter._value;
require(value > 0, "Counter: decrement overflow");
unchecked {
counter._value = value - 1;
}
}
function reset(Counter storage counter) internal {
counter._value = 0;
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
import {IERC20Upgradeable as IERC20} from "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import {IERC20MetadataUpgradeable as IERC20Metadata} from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol";
import {SafeERC20Upgradeable as SafeERC20} from "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";
import {EnumerableSetUpgradeable as EnumerableSet} from "@openzeppelin/contracts-upgradeable/utils/structs/EnumerableSetUpgradeable.sol";
import {Counters} from "@openzeppelin/contracts/utils/Counters.sol";
import "../interfaces/IManageableVault.sol";
import "../interfaces/IMToken.sol";
import "../interfaces/IDataFeed.sol";
import "../access/Greenlistable.sol";
import "../access/Blacklistable.sol";
import "../abstract/WithSanctionsList.sol";
import "../libraries/DecimalsCorrectionLibrary.sol";
import "../access/Pausable.sol";
/**
* @title ManageableVault
* @author RedDuck Software
* @notice Contract with base Vault methods
*/
abstract contract ManageableVault is
Pausable,
IManageableVault,
Blacklistable,
Greenlistable,
WithSanctionsList
{
using EnumerableSet for EnumerableSet.AddressSet;
using DecimalsCorrectionLibrary for uint256;
using SafeERC20 for IERC20;
using Counters for Counters.Counter;
/**
* @notice address that represents off-chain USD bank transfer
*/
address public constant MANUAL_FULLFILMENT_TOKEN = address(0x0);
/**
* @notice stable coin static rate 1:1 USD in 18 decimals
*/
uint256 public constant STABLECOIN_RATE = 10**18;
/**
* @notice last request id
*/
Counters.Counter public currentRequestId;
/**
* @notice 100 percent with base 100
* @dev for example, 10% will be (10 * 100)%
*/
uint256 public constant ONE_HUNDRED_PERCENT = 100 * 100;
uint256 public constant MAX_UINT = type(uint256).max;
/**
* @notice mToken token
*/
IMToken public mToken;
/**
* @notice mToken data feed contract
*/
IDataFeed public mTokenDataFeed;
/**
* @notice address to which tokens and mTokens will be sent
*/
address public tokensReceiver;
/**
* @dev fee for initial operations 1% = 100
*/
uint256 public instantFee;
/**
* @dev daily limit for initial operations
* if user exceed this limit he will need
* to create requests
*/
uint256 public instantDailyLimit;
/**
* @dev mapping days (number from 1970) to limit amount
*/
mapping(uint256 => uint256) public dailyLimits;
/**
* @notice address to which fees will be sent
*/
address public feeReceiver;
/**
* @notice variation tolerance of tokenOut rates for "safe" requests approve
*/
uint256 public variationTolerance;
/**
* @notice address restriction with zero fees
*/
mapping(address => bool) public waivedFeeRestriction;
/**
* @dev tokens that can be used as USD representation
*/
EnumerableSet.AddressSet internal _paymentTokens;
/**
* @notice mapping, token address to token config
*/
mapping(address => TokenConfig) public tokensConfig;
/**
* @notice basic min operations amount
*/
uint256 public minAmount;
/**
* @notice mapping, user address => is free frmo min amounts
*/
mapping(address => bool) public isFreeFromMinAmount;
/**
* @dev leaving a storage gap for futures updates
*/
uint256[50] private __gap;
/**
* @dev checks that msg.sender do have a vaultRole() role
*/
modifier onlyVaultAdmin() {
_onlyRole(vaultRole(), msg.sender);
_;
}
/**
* @dev upgradeable pattern contract`s initializer
* @param _ac address of MidasAccessControll contract
* @param _mTokenInitParams init params for mToken
* @param _receiversInitParams init params for receivers
* @param _instantInitParams init params for instant operations
* @param _sanctionsList address of sanctionsList contract
* @param _variationTolerance percent of prices diviation 1% = 100
* @param _minAmount basic min amount for operations
*/
// solhint-disable func-name-mixedcase
function __ManageableVault_init(
address _ac,
MTokenInitParams calldata _mTokenInitParams,
ReceiversInitParams calldata _receiversInitParams,
InstantInitParams calldata _instantInitParams,
address _sanctionsList,
uint256 _variationTolerance,
uint256 _minAmount
) internal onlyInitializing {
_validateAddress(_mTokenInitParams.mToken, false);
_validateAddress(_mTokenInitParams.mTokenDataFeed, false);
_validateAddress(_receiversInitParams.tokensReceiver, true);
_validateAddress(_receiversInitParams.feeReceiver, true);
require(_instantInitParams.instantDailyLimit > 0, "zero limit");
_validateFee(_variationTolerance, true);
_validateFee(_instantInitParams.instantFee, false);
mToken = IMToken(_mTokenInitParams.mToken);
__Pausable_init(_ac);
__Greenlistable_init_unchained();
__Blacklistable_init_unchained();
__WithSanctionsList_init_unchained(_sanctionsList);
tokensReceiver = _receiversInitParams.tokensReceiver;
feeReceiver = _receiversInitParams.feeReceiver;
instantFee = _instantInitParams.instantFee;
instantDailyLimit = _instantInitParams.instantDailyLimit;
minAmount = _minAmount;
variationTolerance = _variationTolerance;
mTokenDataFeed = IDataFeed(_mTokenInitParams.mTokenDataFeed);
}
/**
* @inheritdoc IManageableVault
*/
function withdrawToken(
address token,
uint256 amount,
address withdrawTo
) external onlyVaultAdmin {
IERC20(token).safeTransfer(withdrawTo, amount);
emit WithdrawToken(msg.sender, token, withdrawTo, amount);
}
/**
* @inheritdoc IManageableVault
*/
function addPaymentToken(
address token,
address dataFeed,
uint256 tokenFee,
uint256 allowance,
bool stable
) external onlyVaultAdmin {
require(_paymentTokens.add(token), "MV: already added");
_validateAddress(dataFeed, false);
_validateFee(tokenFee, false);
tokensConfig[token] = TokenConfig({
dataFeed: dataFeed,
fee: tokenFee,
allowance: allowance,
stable: stable
});
emit AddPaymentToken(
msg.sender,
token,
dataFeed,
tokenFee,
allowance,
stable
);
}
/**
* @inheritdoc IManageableVault
* @dev reverts if token is not presented
*/
function removePaymentToken(address token) external onlyVaultAdmin {
require(_paymentTokens.remove(token), "MV: not exists");
delete tokensConfig[token];
emit RemovePaymentToken(token, msg.sender);
}
/**
* @inheritdoc IManageableVault
* @dev reverts if new allowance zero
*/
function changeTokenAllowance(address token, uint256 allowance)
external
onlyVaultAdmin
{
if (token != MANUAL_FULLFILMENT_TOKEN) {
_requireTokenExists(token);
}
require(allowance > 0, "MV: zero allowance");
tokensConfig[token].allowance = allowance;
emit ChangeTokenAllowance(token, msg.sender, allowance);
}
/**
* @inheritdoc IManageableVault
* @dev reverts if new fee > 100%
*/
function changeTokenFee(address token, uint256 fee)
external
onlyVaultAdmin
{
_requireTokenExists(token);
_validateFee(fee, false);
tokensConfig[token].fee = fee;
emit ChangeTokenFee(token, msg.sender, fee);
}
/**
* @inheritdoc IManageableVault
* @dev reverts if new tolerance zero
*/
function setVariationTolerance(uint256 tolerance) external onlyVaultAdmin {
_validateFee(tolerance, true);
variationTolerance = tolerance;
emit SetVariationTolerance(msg.sender, tolerance);
}
/**
* @inheritdoc IManageableVault
*/
function setMinAmount(uint256 newAmount) external onlyVaultAdmin {
minAmount = newAmount;
emit SetMinAmount(msg.sender, newAmount);
}
/**
* @inheritdoc IManageableVault
* @dev reverts if account is already added
*/
function addWaivedFeeAccount(address account) external onlyVaultAdmin {
require(!waivedFeeRestriction[account], "MV: already added");
waivedFeeRestriction[account] = true;
emit AddWaivedFeeAccount(account, msg.sender);
}
/**
* @inheritdoc IManageableVault
* @dev reverts if account is already removed
*/
function removeWaivedFeeAccount(address account) external onlyVaultAdmin {
require(waivedFeeRestriction[account], "MV: not found");
waivedFeeRestriction[account] = false;
emit RemoveWaivedFeeAccount(account, msg.sender);
}
/**
* @inheritdoc IManageableVault
* @dev reverts address zero or equal address(this)
*/
function setFeeReceiver(address receiver) external onlyVaultAdmin {
_validateAddress(receiver, true);
feeReceiver = receiver;
emit SetFeeReceiver(msg.sender, receiver);
}
/**
* @inheritdoc IManageableVault
* @dev reverts address zero or equal address(this)
*/
function setTokensReceiver(address receiver) external onlyVaultAdmin {
_validateAddress(receiver, true);
tokensReceiver = receiver;
emit SetTokensReceiver(msg.sender, receiver);
}
/**
* @inheritdoc IManageableVault
*/
function setInstantFee(uint256 newInstantFee) external onlyVaultAdmin {
_validateFee(newInstantFee, false);
instantFee = newInstantFee;
emit SetInstantFee(msg.sender, newInstantFee);
}
/**
* @inheritdoc IManageableVault
*/
function setInstantDailyLimit(uint256 newInstantDailyLimit)
external
onlyVaultAdmin
{
require(newInstantDailyLimit > 0, "MV: limit zero");
instantDailyLimit = newInstantDailyLimit;
emit SetInstantDailyLimit(msg.sender, newInstantDailyLimit);
}
/**
* @inheritdoc IManageableVault
*/
function freeFromMinAmount(address user, bool enable)
external
onlyVaultAdmin
{
require(isFreeFromMinAmount[user] != enable, "DV: already free");
isFreeFromMinAmount[user] = enable;
emit FreeFromMinAmount(user, enable);
}
/**
* @notice returns array of stablecoins supported by the vault
* can be called only from permissioned actor.
* @return paymentTokens array of payment tokens
*/
function getPaymentTokens() external view returns (address[] memory) {
return _paymentTokens.values();
}
/**
* @notice AC role of vault administrator
* @return role bytes32 role
*/
function vaultRole() public view virtual returns (bytes32);
/**
* @inheritdoc WithSanctionsList
*/
function sanctionsListAdminRole()
public
view
virtual
override
returns (bytes32)
{
return vaultRole();
}
/**
* @inheritdoc Pausable
*/
function pauseAdminRole() public view override returns (bytes32) {
return vaultRole();
}
/**
* @dev do safeTransferFrom on a given token
* and converts `amount` from base18
* to amount with a correct precision. Sends tokens
* from `msg.sender` to `tokensReceiver`
* @param token address of token
* @param to address of user
* @param amount amount of `token` to transfer from `user` (decimals 18)
* @param tokenDecimals token decimals
*/
function _tokenTransferFromUser(
address token,
address to,
uint256 amount,
uint256 tokenDecimals
) internal returns (uint256 transferAmount) {
transferAmount = amount.convertFromBase18(tokenDecimals);
require(
amount == transferAmount.convertToBase18(tokenDecimals),
"MV: invalid rounding"
);
IERC20(token).safeTransferFrom(msg.sender, to, transferAmount);
}
/**
* @dev do safeTransferFrom on a given token
* and converts `amount` from base18
* to amount with a correct precision.
* @param token address of token
* @param from address
* @param to address
* @param amount amount of `token` to transfer from `user`
* @param tokenDecimals token decimals
*/
function _tokenTransferFromTo(
address token,
address from,
address to,
uint256 amount,
uint256 tokenDecimals
) internal {
uint256 transferAmount = amount.convertFromBase18(tokenDecimals);
require(
amount == transferAmount.convertToBase18(tokenDecimals),
"MV: invalid rounding"
);
IERC20(token).safeTransferFrom(from, to, transferAmount);
}
/**
* @dev do safeTransfer on a given token
* and converts `amount` from base18
* to amount with a correct precision. Sends tokens
* from `contract` to `user`
* @param token address of token
* @param to address of user
* @param amount amount of `token` to transfer from `user` (decimals 18)
* @param tokenDecimals token decimals
*/
function _tokenTransferToUser(
address token,
address to,
uint256 amount,
uint256 tokenDecimals
) internal {
uint256 transferAmount = amount.convertFromBase18(tokenDecimals);
require(
amount == transferAmount.convertToBase18(tokenDecimals),
"MV: invalid rounding"
);
IERC20(token).safeTransfer(to, transferAmount);
}
/**
* @dev retreives decimals of a given `token`
* @param token address of token
* @return decimals decinmals value of a given `token`
*/
function _tokenDecimals(address token) internal view returns (uint8) {
return IERC20Metadata(token).decimals();
}
/**
* @dev checks that `token` is presented in `_paymentTokens`
* @param token address of token
*/
function _requireTokenExists(address token) internal view virtual {
require(_paymentTokens.contains(token), "MV: token not exists");
}
/**
* @dev check if operation exceed daily limit and update limit data
* @param amount operation amount (decimals 18)
*/
function _requireAndUpdateLimit(uint256 amount) internal {
uint256 currentDayNumber = block.timestamp / 1 days;
uint256 nextLimitAmount = dailyLimits[currentDayNumber] + amount;
require(nextLimitAmount <= instantDailyLimit, "MV: exceed limit");
dailyLimits[currentDayNumber] = nextLimitAmount;
}
/**
* @dev check if operation exceed token allowance and update allowance
* @param token address of token
* @param amount operation amount (decimals 18)
*/
function _requireAndUpdateAllowance(address token, uint256 amount)
internal
{
uint256 prevAllowance = tokensConfig[token].allowance;
if (prevAllowance == MAX_UINT) return;
require(prevAllowance >= amount, "MV: exceed allowance");
tokensConfig[token].allowance -= amount;
}
/**
* @dev returns calculated fee amount depends on parameters
* if additionalFee not zero, token fee replaced with additionalFee
* @param sender sender address
* @param token token address
* @param amount amount of token (decimals 18)
* @param isInstant is instant operation
* @param additionalFee fee for fiat operations
* @return fee amount of input token
*/
function _getFeeAmount(
address sender,
address token,
uint256 amount,
bool isInstant,
uint256 additionalFee
) internal view returns (uint256) {
if (waivedFeeRestriction[sender]) return 0;
uint256 feePercent;
if (additionalFee == 0) {
TokenConfig storage tokenConfig = tokensConfig[token];
feePercent = tokenConfig.fee;
} else {
feePercent = additionalFee;
}
if (isInstant) feePercent += instantFee;
if (feePercent > ONE_HUNDRED_PERCENT) feePercent = ONE_HUNDRED_PERCENT;
return (amount * feePercent) / ONE_HUNDRED_PERCENT;
}
/**
* @dev check if prev and new prices diviation fit variationTolerance
* @param prevPrice previous rate
* @param newPrice new rate
*/
function _requireVariationTolerance(uint256 prevPrice, uint256 newPrice)
internal
view
{
uint256 priceDif = newPrice >= prevPrice
? newPrice - prevPrice
: prevPrice - newPrice;
uint256 priceDifPercent = (priceDif * ONE_HUNDRED_PERCENT) / prevPrice;
require(
priceDifPercent <= variationTolerance,
"MV: exceed price diviation"
);
}
function _validateUserAccess(address user)
internal
view
onlyGreenlisted(user)
onlyNotBlacklisted(user)
onlyNotSanctioned(user)
{}
/**
* @dev convert value to inputted decimals precision
* @param value value for format
* @param decimals decimals
* @return converted amount
*/
function _truncate(uint256 value, uint256 decimals)
internal
pure
returns (uint256)
{
return value.convertFromBase18(decimals).convertToBase18(decimals);
}
/**
* @dev check if fee <= 100% and check > 0 if needs
* @param fee fee value
* @param checkMin if need to check minimum
*/
function _validateFee(uint256 fee, bool checkMin) internal pure {
require(fee <= ONE_HUNDRED_PERCENT, "fee > 100%");
if (checkMin) require(fee > 0, "fee == 0");
}
/**
* @dev check if address not zero and not address(this)
* @param addr address to check
* @param selfCheck check if address not address(this)
*/
function _validateAddress(address addr, bool selfCheck) internal view {
require(addr != address(0), "zero address");
if (selfCheck) require(addr != address(this), "invalid address");
}
/**
* @dev get token rate depends on data feed and stablecoin flag
* @param dataFeed address of dataFeed from token config
* @param stable is stablecoin
*/
function _getTokenRate(address dataFeed, bool stable)
internal
view
virtual
returns (uint256)
{
// @dev if dataFeed returns rate, all peg checks passed
uint256 rate = IDataFeed(dataFeed).getDataInBase18();
if (stable) return STABLECOIN_RATE;
return rate;
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
/**
* @title MidasInitializable
* @author RedDuck Software
* @notice Base Initializable contract that implements constructor
* that calls _disableInitializers() to prevent
* initialization of implementation contract
*/
abstract contract MidasInitializable is Initializable {
constructor() {
_disableInitializers();
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
import "../interfaces/ISanctionsList.sol";
import "../access/WithMidasAccessControl.sol";
import "./MidasInitializable.sol";
/**
* @title WithSanctionsList
* @notice Base contract that uses sanctions oracle from
* Chainalysis to check that user is not sanctioned
* @author RedDuck Software
*/
abstract contract WithSanctionsList is WithMidasAccessControl {
/**
* @notice address of Chainalysis sanctions oracle
*/
address public sanctionsList;
/**
* @dev leaving a storage gap for futures updates
*/
uint256[50] private __gap;
/**
* @param caller function caller (msg.sender)
* @param newSanctionsList new address of `sanctionsList`
*/
event SetSanctionsList(
address indexed caller,
address indexed newSanctionsList
);
/**
* @dev checks that a given `user` is not sanctioned
*/
modifier onlyNotSanctioned(address user) {
address _sanctionsList = sanctionsList;
if (_sanctionsList != address(0)) {
require(
!ISanctionsList(_sanctionsList).isSanctioned(user),
"WSL: sanctioned"
);
}
_;
}
/**
* @dev upgradeable pattern contract`s initializer
*/
// solhint-disable func-name-mixedcase
function __WithSanctionsList_init(
address _accesControl,
address _sanctionsList
) internal onlyInitializing {
__WithMidasAccessControl_init(_accesControl);
__WithSanctionsList_init_unchained(_sanctionsList);
}
/**
* @dev upgradeable pattern contract`s initializer unchained
*/
// solhint-disable func-name-mixedcase
function __WithSanctionsList_init_unchained(address _sanctionsList)
internal
onlyInitializing
{
sanctionsList = _sanctionsList;
}
/**
* @notice updates `sanctionsList` address.
* can be called only from permissioned actor that have
* `sanctionsListAdminRole()` role
* @param newSanctionsList new sanctions list address
*/
function setSanctionsList(address newSanctionsList) external {
_onlyRole(sanctionsListAdminRole(), msg.sender);
sanctionsList = newSanctionsList;
emit SetSanctionsList(msg.sender, newSanctionsList);
}
/**
* @notice AC role of sanctions list admin
* @dev address that have this role can use `setSanctionsList`
* @return role bytes32 role
*/
function sanctionsListAdminRole() public view virtual returns (bytes32);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
import "./WithMidasAccessControl.sol";
/**
* @title Blacklistable
* @notice Base contract that implements basic functions and modifiers
* to work with blacklistable
* @author RedDuck Software
*/
abstract contract Blacklistable is WithMidasAccessControl {
/**
* @dev leaving a storage gap for futures updates
*/
uint256[50] private __gap;
/**
* @dev checks that a given `account` doesnt
* have BLACKLISTED_ROLE
*/
modifier onlyNotBlacklisted(address account) {
_onlyNotBlacklisted(account);
_;
}
/**
* @dev upgradeable pattern contract`s initializer
* @param _accessControl MidasAccessControl contract address
*/
// solhint-disable func-name-mixedcase
function __Blacklistable_init(address _accessControl)
internal
onlyInitializing
{
__WithMidasAccessControl_init(_accessControl);
__Blacklistable_init_unchained();
}
/**
* @dev upgradeable pattern contract`s initializer unchained
*/
// solhint-disable func-name-mixedcase
function __Blacklistable_init_unchained() internal onlyInitializing {}
/**
* @dev checks that a given `account` doesnt
* have BLACKLISTED_ROLE
*/
function _onlyNotBlacklisted(address account)
internal
view
onlyNotRole(BLACKLISTED_ROLE, account)
{}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
import "./WithMidasAccessControl.sol";
/**
* @title Greenlistable
* @notice Base contract that implements basic functions and modifiers
* to work with greenlistable
* @author RedDuck Software
*/
abstract contract Greenlistable is WithMidasAccessControl {
/**
* @notice is greenlist enabled
*/
bool public greenlistEnabled;
/**
* @dev leaving a storage gap for futures updates
*/
uint256[50] private __gap;
event SetGreenlistEnable(address indexed sender, bool enable);
/**
* @dev checks that a given `account`
* have `greenlistedRole()`
*/
modifier onlyGreenlisted(address account) {
if (greenlistEnabled) _onlyGreenlisted(account);
_;
}
/**
* @dev checks that a given `account`
* have `greenlistedRole()`
* do the check even if greenlist check is off
*/
modifier onlyAlwaysGreenlisted(address account) {
_onlyGreenlisted(account);
_;
}
/**
* @dev upgradeable pattern contract`s initializer
* @param _accessControl MidasAccessControl contract address
*/
// solhint-disable func-name-mixedcase
function __Greenlistable_init(address _accessControl)
internal
onlyInitializing
{
__WithMidasAccessControl_init(_accessControl);
__Greenlistable_init_unchained();
}
/**
* @dev upgradeable pattern contract`s initializer unchained
*/
// solhint-disable func-name-mixedcase
function __Greenlistable_init_unchained() internal onlyInitializing {}
/**
* @notice enable or disable greenlist.
* can be called only from permissioned actor.
* @param enable enable
*/
function setGreenlistEnable(bool enable) external {
_onlyGreenlistToggler(msg.sender);
require(greenlistEnabled != enable, "GL: same enable status");
greenlistEnabled = enable;
emit SetGreenlistEnable(msg.sender, enable);
}
/**
* @notice AC role of a greenlist
* @return role bytes32 role
*/
function greenlistedRole() public view virtual returns (bytes32) {
return GREENLISTED_ROLE;
}
/**
* @notice AC role of a greenlist toggler
* @return role bytes32 role
*/
function greenlistTogglerRole() public view virtual returns (bytes32);
/**
* @dev checks that a given `account`
* have a `greenlistedRole()`
*/
function _onlyGreenlisted(address account)
private
view
onlyRole(greenlistedRole(), account)
{}
/**
* @dev checks that a given `account`
* have a `greenlistTogglerRole()`
*/
function _onlyGreenlistToggler(address account)
internal
view
onlyRole(greenlistTogglerRole(), account)
{}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "./MidasAccessControlRoles.sol";
import "../abstract/MidasInitializable.sol";
/**
* @title MidasAccessControl
* @notice Smart contract that stores all roles for Midas project
* @author RedDuck Software
*/
contract MidasAccessControl is
AccessControlUpgradeable,
MidasInitializable,
MidasAccessControlRoles
{
/**
* @notice upgradeable pattern contract`s initializer
*/
function initialize() external initializer {
__AccessControl_init();
_setupRoles(msg.sender);
}
/**
* @notice grant multiple roles to multiple users
* in one transaction
* @dev length`s of 2 arays should match
* @param roles array of bytes32 roles
* @param addresses array of user addresses
*/
function grantRoleMult(bytes32[] memory roles, address[] memory addresses)
external
{
require(roles.length == addresses.length, "MAC: mismatch arrays");
for (uint256 i = 0; i < roles.length; i++) {
_checkRole(getRoleAdmin(roles[i]), msg.sender);
_grantRole(roles[i], addresses[i]);
}
}
/**
* @notice revoke multiple roles from multiple users
* in one transaction
* @dev length`s of 2 arays should match
* @param roles array of bytes32 roles
* @param addresses array of user addresses
*/
function revokeRoleMult(bytes32[] memory roles, address[] memory addresses)
external
{
require(roles.length == addresses.length, "MAC: mismatch arrays");
for (uint256 i = 0; i < roles.length; i++) {
_checkRole(getRoleAdmin(roles[i]), msg.sender);
_revokeRole(roles[i], addresses[i]);
}
}
//solhint-disable disable-next-line
function renounceRole(bytes32, address) public pure override {
revert("MAC: Forbidden");
}
/**
* @dev setup roles during the contracts initialization
*/
function _setupRoles(address admin) private {
_grantRole(DEFAULT_ADMIN_ROLE, admin);
_setRoleAdmin(BLACKLISTED_ROLE, BLACKLIST_OPERATOR_ROLE);
_setRoleAdmin(GREENLISTED_ROLE, GREENLIST_OPERATOR_ROLE);
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
/**
* @title MidasAccessControlRoles
* @notice Base contract that stores all roles descriptors
* @author RedDuck Software
*/
abstract contract MidasAccessControlRoles {
/**
* @notice actor that can change green list statuses of addresses
*/
bytes32 public constant GREENLIST_OPERATOR_ROLE =
keccak256("GREENLIST_OPERATOR_ROLE");
/**
* @notice actor that can change black list statuses of addresses
*/
bytes32 public constant BLACKLIST_OPERATOR_ROLE =
keccak256("BLACKLIST_OPERATOR_ROLE");
/**
* @notice actor that is greenlisted
*/
bytes32 public constant GREENLISTED_ROLE = keccak256("GREENLISTED_ROLE");
/**
* @notice actor that is blacklisted
*/
bytes32 public constant BLACKLISTED_ROLE = keccak256("BLACKLISTED_ROLE");
}// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.9;
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import "../access/WithMidasAccessControl.sol";
/**
* @title Pausable
* @notice Base contract that implements basic functions and modifiers
* with pause functionality
* @author RedDuck Software
*/
abstract contract Pausable is WithMidasAccessControl, PausableUpgradeable {
mapping(bytes4 => bool) public fnPaused;
/**
* @dev leaving a storage gap for futures updates
*/
uint256[50] private __gap;
/**
* @param caller caller address (msg.sender)
* @param fn function id
*/
event PauseFn(address indexed caller, bytes4 fn);
/**
* @param caller caller address (msg.sender)
* @param fn function id
*/
event UnpauseFn(address indexed caller, bytes4 fn);
modifier whenFnNotPaused(bytes4 fn) {
_requireNotPaused();
require(!fnPaused[fn], "Pausable: fn paused");
_;
}
/**
* @dev checks that a given `account`
* has a determinedPauseAdminRole
*/
modifier onlyPauseAdmin() {
_onlyRole(pauseAdminRole(), msg.sender);
_;
}
/**
* @dev upgradeable pattern contract`s initializer
* @param _accessControl MidasAccessControl contract address
*/
// solhint-disable-next-line func-name-mixedcase
function __Pausable_init(address _accessControl) internal onlyInitializing {
super.__Pausable_init();
__WithMidasAccessControl_init(_accessControl);
}
function pause() external onlyPauseAdmin {
_pause();
}
function unpause() external onlyPauseAdmin {
_unpause();
}
/**
* @dev pause specific function
* @param fn function id
*/
function pauseFn(bytes4 fn) external onlyPauseAdmin {
require(!fnPaused[fn], "Pausable: fn paused");
fnPaused[fn] = true;
emit PauseFn(msg.sender, fn);
}
/**
* @dev unpause specific function
* @param fn function id
*/
function unpauseFn(bytes4 fn) external onlyPauseAdmin {
require(fnPaused[fn], "Pausable: fn unpaused");
fnPaused[fn] = false;
emit UnpauseFn(msg.sender, fn);
}
/**
* @dev virtual function to determine pauseAdmin role
*/
function pauseAdminRole() public view virtual returns (bytes32);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
import "./MidasAccessControl.sol";
import "../abstract/MidasInitializable.sol";
/**
* @title WithMidasAccessControl
* @notice Base contract that consumes MidasAccessControl
* @author RedDuck Software
*/
abstract contract WithMidasAccessControl is
MidasInitializable,
MidasAccessControlRoles
{
/**
* @notice admin role
*/
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
/**
* @notice MidasAccessControl contract address
*/
MidasAccessControl public accessControl;
/**
* @dev leaving a storage gap for futures updates
*/
uint256[50] private __gap;
/**
* @dev checks that given `address` have `role`
*/
modifier onlyRole(bytes32 role, address account) {
_onlyRole(role, account);
_;
}
/**
* @dev checks that given `address` do not have `role`
*/
modifier onlyNotRole(bytes32 role, address account) {
_onlyNotRole(role, account);
_;
}
/**
* @dev upgradeable pattern contract`s initializer
*/
// solhint-disable func-name-mixedcase
function __WithMidasAccessControl_init(address _accessControl)
internal
onlyInitializing
{
require(_accessControl != address(0), "zero address");
accessControl = MidasAccessControl(_accessControl);
}
/**
* @dev checks that given `address` have `role`
*/
function _onlyRole(bytes32 role, address account) internal view {
require(accessControl.hasRole(role, account), "WMAC: hasnt role");
}
/**
* @dev checks that given `address` do not have `role`
*/
function _onlyNotRole(bytes32 role, address account) internal view {
require(!accessControl.hasRole(role, account), "WMAC: has role");
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20PausableUpgradeable.sol";
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
import "../access/WithMidasAccessControl.sol";
import "../libraries/DecimalsCorrectionLibrary.sol";
/**
* @title IDataFeed
* @author RedDuck Software
*/
interface IDataFeed {
/**
* @notice upgradeable pattern contract`s initializer
* @param _ac MidasAccessControl contract address
* @param _aggregator AggregatorV3Interface contract address
* @param _healthyDiff max. staleness time for data feed answers
* @param _minExpectedAnswer min.expected answer value from data feed
* @param _maxExpectedAnswer max.expected answer value from data feed
*/
function initialize(
address _ac,
address _aggregator,
uint256 _healthyDiff,
int256 _minExpectedAnswer,
int256 _maxExpectedAnswer
) external;
/**
* @notice updates `aggregator` address
* @param _aggregator new AggregatorV3Interface contract address
*/
function changeAggregator(address _aggregator) external;
/**
* @notice fetches answer from aggregator
* and converts it to the base18 precision
* @return answer fetched aggregator answer
*/
function getDataInBase18() external view returns (uint256 answer);
/**
* @dev describes a role, owner of which can manage this feed
* @return role descriptor
*/
function feedAdminRole() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
import "./IMToken.sol";
import "./IDataFeed.sol";
/**
* @param dataFeed data feed token/USD address
* @param fee fee by token, 1% = 100
* @param allowance token allowance (decimals 18)
*/
struct TokenConfig {
address dataFeed;
uint256 fee;
uint256 allowance;
bool stable;
}
enum RequestStatus {
Pending,
Processed,
Canceled
}
struct MTokenInitParams {
address mToken;
address mTokenDataFeed;
}
struct ReceiversInitParams {
address tokensReceiver;
address feeReceiver;
}
struct InstantInitParams {
uint256 instantFee;
uint256 instantDailyLimit;
}
/**
* @title IManageableVault
* @author RedDuck Software
*/
interface IManageableVault {
/**
* @param caller function caller (msg.sender)
* @param token token that was withdrawn
* @param withdrawTo address to which tokens were withdrawn
* @param amount `token` transfer amount
*/
event WithdrawToken(
address indexed caller,
address indexed token,
address indexed withdrawTo,
uint256 amount
);
/**
* @param caller function caller (msg.sender)
* @param token address of token that
* @param dataFeed token dataFeed address
* @param fee fee 1% = 100
* @param allowance token allowance (decimals 18)
* @param stable stablecoin flag
*/
event AddPaymentToken(
address indexed caller,
address indexed token,
address indexed dataFeed,
uint256 fee,
uint256 allowance,
bool stable
);
/**
* @param token address of token that
* @param caller function caller (msg.sender)
* @param allowance new allowance
*/
event ChangeTokenAllowance(
address indexed token,
address indexed caller,
uint256 allowance
);
/**
* @param token address of token that
* @param caller function caller (msg.sender)
* @param fee new fee
*/
event ChangeTokenFee(
address indexed token,
address indexed caller,
uint256 fee
);
/**
* @param token address of token that
* @param caller function caller (msg.sender)
*/
event RemovePaymentToken(address indexed token, address indexed caller);
/**
* @param account address of account
* @param caller function caller (msg.sender)
*/
event AddWaivedFeeAccount(address indexed account, address indexed caller);
/**
* @param account address of account
* @param caller function caller (msg.sender)
*/
event RemoveWaivedFeeAccount(
address indexed account,
address indexed caller
);
/**
* @param caller function caller (msg.sender)
* @param newFee new operation fee value
*/
event SetInstantFee(address indexed caller, uint256 newFee);
/**
* @param caller function caller (msg.sender)
* @param newAmount new min amount for operation
*/
event SetMinAmount(address indexed caller, uint256 newAmount);
/**
* @param caller function caller (msg.sender)
* @param newLimit new operation daily limit
*/
event SetInstantDailyLimit(address indexed caller, uint256 newLimit);
/**
* @param caller function caller (msg.sender)
* @param newTolerance percent of price diviation 1% = 100
*/
event SetVariationTolerance(address indexed caller, uint256 newTolerance);
/**
* @param caller function caller (msg.sender)
* @param reciever new reciever address
*/
event SetFeeReceiver(address indexed caller, address indexed reciever);
/**
* @param caller function caller (msg.sender)
* @param reciever new reciever address
*/
event SetTokensReceiver(address indexed caller, address indexed reciever);
/**
* @param user user address
* @param enable is enabled
*/
event FreeFromMinAmount(address indexed user, bool enable);
/**
* @notice The mTokenDataFeed contract address.
* @return The address of the mTokenDataFeed contract.
*/
function mTokenDataFeed() external view returns (IDataFeed);
/**
* @notice The mToken contract address.
* @return The address of the mToken contract.
*/
function mToken() external view returns (IMToken);
/**
* @notice withdraws `amount` of a given `token` from the contract.
* can be called only from permissioned actor.
* @param token token address
* @param amount token amount
* @param withdrawTo withdraw destination address
*/
function withdrawToken(
address token,
uint256 amount,
address withdrawTo
) external;
/**
* @notice adds a token to the stablecoins list.
* can be called only from permissioned actor.
* @param token token address
* @param dataFeed dataFeed address
* @param fee 1% = 100
* @param allowance token allowance (decimals 18)
* @param stable is stablecoin flag
*/
function addPaymentToken(
address token,
address dataFeed,
uint256 fee,
uint256 allowance,
bool stable
) external;
/**
* @notice removes a token from stablecoins list.
* can be called only from permissioned actor.
* @param token token address
*/
function removePaymentToken(address token) external;
/**
* @notice set new token allowance.
* if MAX_UINT = infinite allowance
* prev allowance rewrites by new
* can be called only from permissioned actor.
* @param token token address
* @param allowance new allowance (decimals 18)
*/
function changeTokenAllowance(address token, uint256 allowance) external;
/**
* @notice set new token fee.
* can be called only from permissioned actor.
* @param token token address
* @param fee new fee percent 1% = 100
*/
function changeTokenFee(address token, uint256 fee) external;
/**
* @notice set new prices diviation percent.
* can be called only from permissioned actor.
* @param tolerance new prices diviation percent 1% = 100
*/
function setVariationTolerance(uint256 tolerance) external;
/**
* @notice set new min amount.
* can be called only from permissioned actor.
* @param newAmount min amount for operations in mToken
*/
function setMinAmount(uint256 newAmount) external;
/**
* @notice adds a account to waived fee restriction.
* can be called only from permissioned actor.
* @param account user address
*/
function addWaivedFeeAccount(address account) external;
/**
* @notice removes a account from waived fee restriction.
* can be called only from permissioned actor.
* @param account user address
*/
function removeWaivedFeeAccount(address account) external;
/**
* @notice set new reciever for fees.
* can be called only from permissioned actor.
* @param reciever new fee reciever address
*/
function setFeeReceiver(address reciever) external;
/**
* @notice set new reciever for tokens.
* can be called only from permissioned actor.
* @param reciever new token reciever address
*/
function setTokensReceiver(address reciever) external;
/**
* @notice set operation fee percent.
* can be called only from permissioned actor.
* @param newInstantFee new instant operations fee percent 1& = 100
*/
function setInstantFee(uint256 newInstantFee) external;
/**
* @notice set operation daily limit.
* can be called only from permissioned actor.
* @param newInstantDailyLimit new operation daily limit (decimals 18)
*/
function setInstantDailyLimit(uint256 newInstantDailyLimit) external;
/**
* @notice frees given `user` from the minimal deposit
* amount validation in `initiateDepositRequest`
* @param user address of user
*/
function freeFromMinAmount(address user, bool enable) external;
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
/**
* @title IMToken
* @author RedDuck Software
*/
interface IMToken is IERC20Upgradeable {
/**
* @notice mints mToken token `amount` to a given `to` address.
* should be called only from permissioned actor
* @param to addres to mint tokens to
* @param amount amount to mint
*/
function mint(address to, uint256 amount) external;
/**
* @notice burns mToken token `amount` to a given `to` address.
* should be called only from permissioned actor
* @param from addres to burn tokens from
* @param amount amount to burn
*/
function burn(address from, uint256 amount) external;
/**
* @notice updates contract`s metadata.
* should be called only from permissioned actor
* @param key metadata map. key
* @param data metadata map. value
*/
function setMetadata(bytes32 key, bytes memory data) external;
/**
* @notice puts mToken token on pause.
* should be called only from permissioned actor
*/
function pause() external;
/**
* @notice puts mToken token on pause.
* should be called only from permissioned actor
*/
function unpause() external;
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
import "./IManageableVault.sol";
/**
* @notice Redeem request scruct
* @param sender user address who create
* @param tokenOut tokenOut address
* @param status request status
* @param amountMToken amount mToken
* @param mTokenRate rate of mToken at request creation time
* @param tokenOutRate rate of tokenOut at request creation time
*/
struct Request {
address sender;
address tokenOut;
RequestStatus status;
uint256 amountMToken;
uint256 mTokenRate;
uint256 tokenOutRate;
}
struct FiatRedeptionInitParams {
uint256 fiatAdditionalFee;
uint256 fiatFlatFee;
uint256 minFiatRedeemAmount;
}
/**
* @title IRedemptionVault
* @author RedDuck Software
*/
interface IRedemptionVault is IManageableVault {
/**
* @param user function caller (msg.sender)
* @param tokenOut address of tokenOut
* @param amount amount of mToken
* @param feeAmount fee amount in mToken
* @param amountTokenOut amount of tokenOut
*/
event RedeemInstant(
address indexed user,
address indexed tokenOut,
uint256 amount,
uint256 feeAmount,
uint256 amountTokenOut
);
/**
* @param user function caller (msg.sender)
* @param tokenOut address of tokenOut
* @param recipient address that receives tokens
* @param amount amount of mToken
* @param feeAmount fee amount in mToken
* @param amountTokenOut amount of tokenOut
*/
event RedeemInstantWithCustomRecipient(
address indexed user,
address indexed tokenOut,
address recipient,
uint256 amount,
uint256 feeAmount,
uint256 amountTokenOut
);
/**
* @param requestId request id
* @param user function caller (msg.sender)
* @param tokenOut address of tokenOut
* @param amountMTokenIn amount of mToken
* @param feeAmount fee amount in mToken
*/
event RedeemRequest(
uint256 indexed requestId,
address indexed user,
address indexed tokenOut,
uint256 amountMTokenIn,
uint256 feeAmount
);
/**
* @param requestId request id
* @param user function caller (msg.sender)
* @param tokenOut address of tokenOut
* @param recipient address that receives tokens
* @param amountMTokenIn amount of mToken
* @param feeAmount fee amount in mToken
*/
event RedeemRequestWithCustomRecipient(
uint256 indexed requestId,
address indexed user,
address indexed tokenOut,
address recipient,
uint256 amountMTokenIn,
uint256 feeAmount
);
/**
* @param requestId mint request id
* @param newMTokenRate net mToken rate
*/
event ApproveRequest(uint256 indexed requestId, uint256 newMTokenRate);
/**
* @param requestId mint request id
* @param newMTokenRate net mToken rate
*/
event SafeApproveRequest(uint256 indexed requestId, uint256 newMTokenRate);
/**
* @param requestId mint request id
* @param user address of user
*/
event RejectRequest(uint256 indexed requestId, address indexed user);
/**
* @param caller function caller (msg.sender)
* @param newMinAmount new min amount for fiat requests
*/
event SetMinFiatRedeemAmount(address indexed caller, uint256 newMinAmount);
/**
* @param caller function caller (msg.sender)
* @param feeInMToken fee amount in mToken
*/
event SetFiatFlatFee(address indexed caller, uint256 feeInMToken);
/**
* @param caller function caller (msg.sender)
* @param newfee new fiat fee percent 1% = 100
*/
event SetFiatAdditionalFee(address indexed caller, uint256 newfee);
/**
* @param caller function caller (msg.sender)
* @param redeemer new address of request redeemer
*/
event SetRequestRedeemer(address indexed caller, address redeemer);
/**
* @notice redeem mToken to tokenOut if daily limit and allowance not exceeded
* Burns mToken from the user.
* Transfers fee in mToken to feeReceiver
* Transfers tokenOut to user.
* @param tokenOut stable coin token address to redeem to
* @param amountMTokenIn amount of mToken to redeem (decimals 18)
* @param minReceiveAmount minimum expected amount of tokenOut to receive (decimals 18)
*/
function redeemInstant(
address tokenOut,
uint256 amountMTokenIn,
uint256 minReceiveAmount
) external;
/**
* @notice Does the same as original `redeemInstant` but allows specifying a custom tokensReceiver address.
* @param tokenOut stable coin token address to redeem to
* @param amountMTokenIn amount of mToken to redeem (decimals 18)
* @param minReceiveAmount minimum expected amount of tokenOut to receive (decimals 18)
* @param recipient address that receives tokens
*/
function redeemInstant(
address tokenOut,
uint256 amountMTokenIn,
uint256 minReceiveAmount,
address recipient
) external;
/**
* @notice creating redeem request if tokenOut not fiat
* Transfers amount in mToken to contract
* Transfers fee in mToken to feeReceiver
* @param tokenOut stable coin token address to redeem to
* @param amountMTokenIn amount of mToken to redeem (decimals 18)
* @return request id
*/
function redeemRequest(address tokenOut, uint256 amountMTokenIn)
external
returns (uint256);
/**
* @notice Does the same as original `redeemRequest` but allows specifying a custom tokensReceiver address.
* @param tokenOut stable coin token address to redeem to
* @param amountMTokenIn amount of mToken to redeem (decimals 18)
* @param recipient address that receives tokens
* @return request id
*/
function redeemRequest(
address tokenOut,
uint256 amountMTokenIn,
address recipient
) external returns (uint256);
/**
* @notice creating redeem request if tokenOut is fiat
* Transfers amount in mToken to contract
* Transfers fee in mToken to feeReceiver
* @param amountMTokenIn amount of mToken to redeem (decimals 18)
* @return request id
*/
function redeemFiatRequest(uint256 amountMTokenIn)
external
returns (uint256);
/**
* @notice approving requests from the `requestIds` array with the
* current mToken rate. WONT fail even if there is not enough liquidity
* to process all requests.
* Does same validation as `safeApproveRequest`.
* Transfers tokenOut to users
* Sets request flags to Processed.
* @param requestIds request ids array
*/
function safeBulkApproveRequest(uint256[] calldata requestIds) external;
/**
* @notice approving requests from the `requestIds` array using the `newMTokenRate`.
* WONT fail even if there is not enough liquidity to process all requests.
* Does same validation as `safeApproveRequest`.
* Transfers tokenOut to user
* Sets request flags to Processed.
* @param requestIds request ids array
* @param newMTokenRate new mToken rate inputted by vault admin
*/
function safeBulkApproveRequest(
uint256[] calldata requestIds,
uint256 newMTokenRate
) external;
/**
* @notice approving redeem request if not exceed tokenOut allowance
* Burns amount mToken from contract
* Transfers tokenOut to user
* Sets flag Processed
* @param requestId request id
* @param newMTokenRate new mToken rate inputted by vault admin
*/
function approveRequest(uint256 requestId, uint256 newMTokenRate) external;
/**
* @notice approving request if inputted token rate fit price diviation percent
* Burns amount mToken from contract
* Transfers tokenOut to user
* Sets flag Processed
* @param requestId request id
* @param newMTokenRate new mToken rate inputted by vault admin
*/
function safeApproveRequest(uint256 requestId, uint256 newMTokenRate)
external;
/**
* @notice rejecting request
* Sets request flag to Canceled.
* @param requestId request id
*/
function rejectRequest(uint256 requestId) external;
/**
* @notice set new min amount for fiat requests
* @param newValue new min amount
*/
function setMinFiatRedeemAmount(uint256 newValue) external;
/**
* @notice set fee amount in mToken for fiat requests
* @param feeInMToken fee amount in mToken
*/
function setFiatFlatFee(uint256 feeInMToken) external;
/**
* @notice set new fee percent for fiat requests
* @param newFee new fee percent 1% = 100
*/
function setFiatAdditionalFee(uint256 newFee) external;
/**
* @notice set address which is designated for standard redemptions, allowing tokens to be pulled from this address
* @param redeemer new address of request redeemer
*/
function setRequestRedeemer(address redeemer) external;
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
import "./IRedemptionVault.sol";
/**
* @title IRedemptionVaultWithSwapper
* @author RedDuck Software
*/
interface IRedemptionVaultWithSwapper is IRedemptionVault {
/**
* @param caller caller address (msg.sender)
* @param provider new LP address
*/
event SetLiquidityProvider(
address indexed caller,
address indexed provider
);
/**
* @param caller caller address (msg.sender)
* @param vault new underlying vault for swapper
*/
event SetSwapperVault(address indexed caller, address indexed vault);
/**
* @notice sets new liquidity provider address
* @param provider new liquidity provider address
*/
function setLiquidityProvider(address provider) external;
/**
* @notice sets new underlying vault for swapper
* @param vault new underlying vault for swapper
*/
function setSwapperVault(address vault) external;
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
// TODO: add natspec
interface ISanctionsList {
function isSanctioned(address addr) external view returns (bool);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
/**
* @title KmiUsdMidasAccessControlRoles
* @notice Base contract that stores all roles descriptors for kmiUSD contracts
* @author RedDuck Software
*/
abstract contract KmiUsdMidasAccessControlRoles {
/**
* @notice actor that can manage KmiUsdDepositVault
*/
bytes32 public constant KMI_USD_DEPOSIT_VAULT_ADMIN_ROLE =
keccak256("KMI_USD_DEPOSIT_VAULT_ADMIN_ROLE");
/**
* @notice actor that can manage KmiUsdRedemptionVault
*/
bytes32 public constant KMI_USD_REDEMPTION_VAULT_ADMIN_ROLE =
keccak256("KMI_USD_REDEMPTION_VAULT_ADMIN_ROLE");
/**
* @notice actor that can manage KmiUsdCustomAggregatorFeed and KmiUsdDataFeed
*/
bytes32 public constant KMI_USD_CUSTOM_AGGREGATOR_FEED_ADMIN_ROLE =
keccak256("KMI_USD_CUSTOM_AGGREGATOR_FEED_ADMIN_ROLE");
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
/**
* @title DecimalsCorrectionLibrary
* @author RedDuck Software
*/
library DecimalsCorrectionLibrary {
/**
* @dev converts `originalAmount` with `originalDecimals` into
* amount with `decidedDecimals`
* @param originalAmount amount to convert
* @param originalDecimals decimals of the original amount
* @param decidedDecimals decimals for the output amount
* @return amount converted amount with `decidedDecimals`
*/
function convert(
uint256 originalAmount,
uint256 originalDecimals,
uint256 decidedDecimals
) internal pure returns (uint256) {
if (originalAmount == 0) return 0;
if (originalDecimals == decidedDecimals) return originalAmount;
uint256 adjustedAmount;
if (originalDecimals > decidedDecimals) {
adjustedAmount =
originalAmount /
(10**(originalDecimals - decidedDecimals));
} else {
adjustedAmount =
originalAmount *
(10**(decidedDecimals - originalDecimals));
}
return adjustedAmount;
}
/**
* @dev converts `originalAmount` with decimals 18 into
* amount with `decidedDecimals`
* @param originalAmount amount to convert
* @param decidedDecimals decimals for the output amount
* @return amount converted amount with `decidedDecimals`
*/
function convertFromBase18(uint256 originalAmount, uint256 decidedDecimals)
internal
pure
returns (uint256)
{
return convert(originalAmount, 18, decidedDecimals);
}
/**
* @dev converts `originalAmount` with `originalDecimals` into
* amount with decimals 18
* @param originalAmount amount to convert
* @param originalDecimals decimals of the original amount
* @return amount converted amount with 18 decimals
*/
function convertToBase18(uint256 originalAmount, uint256 originalDecimals)
internal
pure
returns (uint256)
{
return convert(originalAmount, originalDecimals, 18);
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
import {IERC20Upgradeable as IERC20} from "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import {IERC20MetadataUpgradeable as IERC20Metadata} from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol";
import {Counters} from "@openzeppelin/contracts/utils/Counters.sol";
import "./interfaces/IRedemptionVault.sol";
import "./interfaces/IDataFeed.sol";
import "./abstract/ManageableVault.sol";
import "./access/Greenlistable.sol";
/**
* @title RedemptionVault
* @notice Smart contract that handles mToken redemptions
* @author RedDuck Software
*/
contract RedemptionVault is ManageableVault, IRedemptionVault {
using DecimalsCorrectionLibrary for uint256;
using Counters for Counters.Counter;
/**
* @notice return data of _calcAndValidateRedeem
* packed into a struct to avoid stack too deep errors
*/
struct CalcAndValidateRedeemResult {
/// @notice fee amount in mToken
uint256 feeAmount;
/// @notice amount of mToken without fee
uint256 amountMTokenWithoutFee;
}
/**
* @dev default role that grants admin rights to the contract
*/
bytes32 private constant _DEFAULT_REDEMPTION_VAULT_ADMIN_ROLE =
keccak256("REDEMPTION_VAULT_ADMIN_ROLE");
/**
* @dev selector for redeem instant
*/
bytes4 private constant _REDEEM_INSTANT_SELECTOR =
bytes4(keccak256("redeemInstant(address,uint256,uint256)"));
/**
* @dev selector for redeem instant with custom recipient
*/
bytes4 private constant _REDEEM_INSTANT_WITH_CUSTOM_RECIPIENT_SELECTOR =
bytes4(keccak256("redeemInstant(address,uint256,uint256,address)"));
/**
* @dev selector for redeem request
*/
bytes4 private constant _REDEEM_REQUEST_SELECTOR =
bytes4(keccak256("redeemRequest(address,uint256)"));
/**
* @dev selector for redeem request with custom recipient
*/
bytes4 private constant _REDEEM_REQUEST_WITH_CUSTOM_RECIPIENT_SELECTOR =
bytes4(keccak256("redeemRequest(address,uint256,address)"));
/**
* @notice min amount for fiat requests
*/
uint256 public minFiatRedeemAmount;
/**
* @notice fee percent for fiat requests
*/
uint256 public fiatAdditionalFee;
/**
* @notice static fee in mToken for fiat requests
*/
uint256 public fiatFlatFee;
/**
* @notice mapping, requestId to request data
*/
mapping(uint256 => Request) public redeemRequests;
/**
* @notice address is designated for standard redemptions, allowing tokens to be pulled from this address
*/
address public requestRedeemer;
/**
* @dev leaving a storage gap for futures updates
*/
uint256[50] private __gap;
/**
* @notice upgradeable pattern contract`s initializer
* @param _ac address of MidasAccessControll contract
* @param _mTokenInitParams init params for mToken
* @param _receiversInitParams init params for receivers
* @param _instantInitParams init params for instant operations
* @param _sanctionsList address of sanctionsList contract
* @param _variationTolerance percent of prices diviation 1% = 100
* @param _minAmount basic min amount for operations
* @param _fiatRedemptionInitParams params fiatAdditionalFee, fiatFlatFee, minFiatRedeemAmount
* @param _requestRedeemer address is designated for standard redemptions, allowing tokens to be pulled from this address
*/
function initialize(
address _ac,
MTokenInitParams calldata _mTokenInitParams,
ReceiversInitParams calldata _receiversInitParams,
InstantInitParams calldata _instantInitParams,
address _sanctionsList,
uint256 _variationTolerance,
uint256 _minAmount,
FiatRedeptionInitParams calldata _fiatRedemptionInitParams,
address _requestRedeemer
) external initializer {
__RedemptionVault_init(
_ac,
_mTokenInitParams,
_receiversInitParams,
_instantInitParams,
_sanctionsList,
_variationTolerance,
_minAmount,
_fiatRedemptionInitParams,
_requestRedeemer
);
}
// solhint-disable func-name-mixedcase
function __RedemptionVault_init(
address _ac,
MTokenInitParams calldata _mTokenInitParams,
ReceiversInitParams calldata _receiversInitParams,
InstantInitParams calldata _instantInitParams,
address _sanctionsList,
uint256 _variationTolerance,
uint256 _minAmount,
FiatRedeptionInitParams calldata _fiatRedemptionInitParams,
address _requestRedeemer
) internal onlyInitializing {
__ManageableVault_init(
_ac,
_mTokenInitParams,
_receiversInitParams,
_instantInitParams,
_sanctionsList,
_variationTolerance,
_minAmount
);
_validateFee(_fiatRedemptionInitParams.fiatAdditionalFee, false);
_validateAddress(_requestRedeemer, false);
minFiatRedeemAmount = _fiatRedemptionInitParams.minFiatRedeemAmount;
fiatAdditionalFee = _fiatRedemptionInitParams.fiatAdditionalFee;
fiatFlatFee = _fiatRedemptionInitParams.fiatFlatFee;
requestRedeemer = _requestRedeemer;
}
/**
* @inheritdoc IRedemptionVault
*/
function redeemInstant(
address tokenOut,
uint256 amountMTokenIn,
uint256 minReceiveAmount
) external whenFnNotPaused(_REDEEM_INSTANT_SELECTOR) {
_validateUserAccess(msg.sender);
(
CalcAndValidateRedeemResult memory calcResult,
uint256 amountTokenOutWithoutFee
) = _redeemInstant(
tokenOut,
amountMTokenIn,
minReceiveAmount,
msg.sender
);
emit RedeemInstant(
msg.sender,
tokenOut,
amountMTokenIn,
calcResult.feeAmount,
amountTokenOutWithoutFee
);
}
/**
* @inheritdoc IRedemptionVault
*/
function redeemInstant(
address tokenOut,
uint256 amountMTokenIn,
uint256 minReceiveAmount,
address recipient
) external whenFnNotPaused(_REDEEM_INSTANT_WITH_CUSTOM_RECIPIENT_SELECTOR) {
_validateUserAccess(msg.sender);
if (recipient != msg.sender) {
_validateUserAccess(recipient);
}
(
CalcAndValidateRedeemResult memory calcResult,
uint256 amountTokenOutWithoutFee
) = _redeemInstant(
tokenOut,
amountMTokenIn,
minReceiveAmount,
recipient
);
emit RedeemInstantWithCustomRecipient(
msg.sender,
tokenOut,
recipient,
amountMTokenIn,
calcResult.feeAmount,
amountTokenOutWithoutFee
);
}
/**
* @inheritdoc IRedemptionVault
*/
function redeemRequest(address tokenOut, uint256 amountMTokenIn)
external
whenFnNotPaused(_REDEEM_REQUEST_SELECTOR)
returns (
uint256 /*requestId*/
)
{
_validateUserAccess(msg.sender);
(
uint256 requestId,
CalcAndValidateRedeemResult memory calcResult
) = _redeemRequest(tokenOut, amountMTokenIn, false, msg.sender);
emit RedeemRequest(
requestId,
msg.sender,
tokenOut,
amountMTokenIn,
calcResult.feeAmount
);
return requestId;
}
/**
* @inheritdoc IRedemptionVault
*/
function redeemRequest(
address tokenOut,
uint256 amountMTokenIn,
address recipient
)
external
whenFnNotPaused(_REDEEM_REQUEST_WITH_CUSTOM_RECIPIENT_SELECTOR)
returns (
uint256 /*requestId*/
)
{
_validateUserAccess(msg.sender);
if (recipient != msg.sender) {
_validateUserAccess(recipient);
}
(
uint256 requestId,
CalcAndValidateRedeemResult memory calcResult
) = _redeemRequest(tokenOut, amountMTokenIn, false, recipient);
emit RedeemRequestWithCustomRecipient(
requestId,
msg.sender,
tokenOut,
recipient,
amountMTokenIn,
calcResult.feeAmount
);
return requestId;
}
/**
* @inheritdoc IRedemptionVault
*/
function redeemFiatRequest(uint256 amountMTokenIn)
external
whenFnNotPaused(this.redeemFiatRequest.selector)
returns (
uint256 /*requestId*/
)
{
_validateUserAccess(msg.sender);
(
uint256 requestId,
CalcAndValidateRedeemResult memory calcResult
) = _redeemRequest(
MANUAL_FULLFILMENT_TOKEN,
amountMTokenIn,
true,
msg.sender
);
emit RedeemRequest(
requestId,
msg.sender,
MANUAL_FULLFILMENT_TOKEN,
amountMTokenIn,
calcResult.feeAmount
);
return requestId;
}
/**
* @inheritdoc IRedemptionVault
*/
function safeBulkApproveRequest(uint256[] calldata requestIds) external {
uint256 currentMTokenRate = _getMTokenRate();
safeBulkApproveRequest(requestIds, currentMTokenRate);
}
/**
* @inheritdoc IRedemptionVault
*/
function approveRequest(uint256 requestId, uint256 newMTokenRate)
external
onlyVaultAdmin
{
_approveRequest(requestId, newMTokenRate, false, false);
emit ApproveRequest(requestId, newMTokenRate);
}
/**
* @inheritdoc IRedemptionVault
*/
function safeApproveRequest(uint256 requestId, uint256 newMTokenRate)
external
onlyVaultAdmin
{
_approveRequest(requestId, newMTokenRate, true, false);
emit SafeApproveRequest(requestId, newMTokenRate);
}
/**
* @inheritdoc IRedemptionVault
*/
function rejectRequest(uint256 requestId) external onlyVaultAdmin {
Request memory request = redeemRequests[requestId];
_validateRequest(request.sender, request.status);
redeemRequests[requestId].status = RequestStatus.Canceled;
emit RejectRequest(requestId, request.sender);
}
/**
* @inheritdoc IRedemptionVault
*/
function setMinFiatRedeemAmount(uint256 newValue) external onlyVaultAdmin {
minFiatRedeemAmount = newValue;
emit SetMinFiatRedeemAmount(msg.sender, newValue);
}
/**
* @inheritdoc IRedemptionVault
*/
function setFiatFlatFee(uint256 feeInMToken) external onlyVaultAdmin {
fiatFlatFee = feeInMToken;
emit SetFiatFlatFee(msg.sender, feeInMToken);
}
/**
* @inheritdoc IRedemptionVault
*/
function setFiatAdditionalFee(uint256 newFee) external onlyVaultAdmin {
_validateFee(newFee, false);
fiatAdditionalFee = newFee;
emit SetFiatAdditionalFee(msg.sender, newFee);
}
/**
* @inheritdoc IRedemptionVault
*/
function setRequestRedeemer(address redeemer) external onlyVaultAdmin {
_validateAddress(redeemer, false);
requestRedeemer = redeemer;
emit SetRequestRedeemer(msg.sender, redeemer);
}
/**
* @inheritdoc IRedemptionVault
*/
function safeBulkApproveRequest(
uint256[] calldata requestIds,
uint256 newOutRate
) public onlyVaultAdmin {
for (uint256 i = 0; i < requestIds.length; i++) {
bool success = _approveRequest(
requestIds[i],
newOutRate,
true,
true
);
if (!success) {
continue;
}
emit SafeApproveRequest(requestIds[i], newOutRate);
}
}
/**
* @inheritdoc ManageableVault
*/
function vaultRole() public pure virtual override returns (bytes32) {
return _DEFAULT_REDEMPTION_VAULT_ADMIN_ROLE;
}
/**
* @inheritdoc Greenlistable
*/
function greenlistTogglerRole()
public
view
virtual
override
returns (bytes32)
{
return vaultRole();
}
/**
* @dev validates approve
* burns amount from contract
* transfer tokenOut to user if not fiat
* sets flag Processed
* @param requestId request id
* @param newMTokenRate new mToken rate
* @param isSafe new mToken rate
* @param safeValidateLiquidity if true, checks if there is enough liquidity
* and if its not sufficient, function wont fail
*
* @return success true if success, false only in case if
* safeValidateLiquidity == true and there is not enough liquidity
*/
function _approveRequest(
uint256 requestId,
uint256 newMTokenRate,
bool isSafe,
bool safeValidateLiquidity
)
internal
returns (
bool /* success */
)
{
Request memory request = redeemRequests[requestId];
_validateRequest(request.sender, request.status);
if (isSafe) {
_requireVariationTolerance(request.mTokenRate, newMTokenRate);
}
bool isFiat = request.tokenOut == MANUAL_FULLFILMENT_TOKEN;
uint256 tokenDecimals = isFiat ? 18 : _tokenDecimals(request.tokenOut);
uint256 amountTokenOutWithoutFee = _truncate(
(request.amountMToken * newMTokenRate) / request.tokenOutRate,
tokenDecimals
);
if (!isFiat) {
if (
safeValidateLiquidity &&
!_validateLiquidity(
request.tokenOut,
amountTokenOutWithoutFee,
tokenDecimals
)
) {
return false;
}
_tokenTransferFromTo(
request.tokenOut,
requestRedeemer,
request.sender,
amountTokenOutWithoutFee,
tokenDecimals
);
}
_requireAndUpdateAllowance(request.tokenOut, amountTokenOutWithoutFee);
mToken.burn(address(this), request.amountMToken);
request.status = RequestStatus.Processed;
request.mTokenRate = newMTokenRate;
redeemRequests[requestId] = request;
return true;
}
/**
* @notice validates request
* if exist
* if not processed
* @param sender sender address
* @param status request status
*/
function _validateRequest(address sender, RequestStatus status)
internal
pure
{
require(sender != address(0), "RV: request not exist");
require(status == RequestStatus.Pending, "RV: request not pending");
}
/**
* @dev internal redeem instant logic
* @param tokenOut tokenOut address
* @param amountMTokenIn amount of mToken (decimals 18)
* @param minReceiveAmount min amount of tokenOut to receive (decimals 18)
* @param recipient recipient address
*
* @return calcResult calculated redeem result
* @return amountTokenOutWithoutFee amount of tokenOut without fee
*/
function _redeemInstant(
address tokenOut,
uint256 amountMTokenIn,
uint256 minReceiveAmount,
address recipient
)
internal
virtual
returns (
CalcAndValidateRedeemResult memory calcResult,
uint256 amountTokenOutWithoutFee
)
{
address user = msg.sender;
calcResult = _calcAndValidateRedeem(
user,
tokenOut,
amountMTokenIn,
true,
false
);
_requireAndUpdateLimit(amountMTokenIn);
address tokenOutCopy = tokenOut;
uint256 tokenDecimals = _tokenDecimals(tokenOutCopy);
(uint256 amountMTokenInUsd, uint256 mTokenRate) = _convertMTokenToUsd(
amountMTokenIn
);
(uint256 amountTokenOut, uint256 tokenOutRate) = _convertUsdToToken(
amountMTokenInUsd,
tokenOutCopy
);
amountTokenOutWithoutFee = _truncate(
(calcResult.amountMTokenWithoutFee * mTokenRate) / tokenOutRate,
tokenDecimals
);
require(
amountTokenOutWithoutFee >= minReceiveAmount,
"RV: minReceiveAmount > actual"
);
_requireAndUpdateAllowance(tokenOutCopy, amountTokenOut);
mToken.burn(user, calcResult.amountMTokenWithoutFee);
if (calcResult.feeAmount > 0)
_tokenTransferFromUser(
address(mToken),
feeReceiver,
calcResult.feeAmount,
18
);
_tokenTransferToUser(
tokenOutCopy,
recipient,
amountTokenOutWithoutFee,
tokenDecimals
);
}
/**
* @notice internal redeem request logic
* @param tokenOut tokenOut address
* @param amountMTokenIn amount of mToken (decimals 18)
*
* @return requestId request id
* @return calcResult calc result
*/
function _redeemRequest(
address tokenOut,
uint256 amountMTokenIn,
bool isFiat,
address recipient
)
internal
returns (
uint256 requestId,
CalcAndValidateRedeemResult memory calcResult
)
{
if (!isFiat) {
require(
tokenOut != MANUAL_FULLFILMENT_TOKEN,
"RV: tokenOut == fiat"
);
}
address user = msg.sender;
calcResult = _calcAndValidateRedeem(
user,
tokenOut,
amountMTokenIn,
false,
isFiat
);
address tokenOutCopy = tokenOut;
// assigning the default value which is gonna be used
// only for fiat redemptions
uint256 tokenOutRate = 1e18;
if (!isFiat) {
TokenConfig storage config = tokensConfig[tokenOutCopy];
tokenOutRate = _getTokenRate(config.dataFeed, config.stable);
}
uint256 mTokenRate = mTokenDataFeed.getDataInBase18();
_tokenTransferFromUser(
address(mToken),
address(this),
calcResult.amountMTokenWithoutFee,
18 // mToken always have 18 decimals
);
if (calcResult.feeAmount > 0)
_tokenTransferFromUser(
address(mToken),
feeReceiver,
calcResult.feeAmount,
18
);
requestId = currentRequestId.current();
currentRequestId.increment();
redeemRequests[requestId] = Request({
sender: recipient,
tokenOut: tokenOutCopy,
status: RequestStatus.Pending,
amountMToken: calcResult.amountMTokenWithoutFee,
mTokenRate: mTokenRate,
tokenOutRate: tokenOutRate
});
return (requestId, calcResult);
}
/**
* @dev calculates tokenOut amount from USD amount
* @param amountUsd amount of USD (decimals 18)
* @param tokenOut tokenOut address
*
* @return amountToken converted USD to tokenOut
* @return tokenRate conversion rate
*/
function _convertUsdToToken(uint256 amountUsd, address tokenOut)
internal
view
returns (uint256 amountToken, uint256 tokenRate)
{
require(amountUsd > 0, "RV: amount zero");
TokenConfig storage tokenConfig = tokensConfig[tokenOut];
tokenRate = _getTokenRate(tokenConfig.dataFeed, tokenConfig.stable);
require(tokenRate > 0, "RV: rate zero");
amountToken = (amountUsd * (10**18)) / tokenRate;
}
/**
* @dev calculates USD amount from mToken amount
* @param amountMToken amount of mToken (decimals 18)
*
* @return amountUsd converted amount to USD
* @return mTokenRate conversion rate
*/
function _convertMTokenToUsd(uint256 amountMToken)
internal
view
returns (uint256 amountUsd, uint256 mTokenRate)
{
require(amountMToken > 0, "RV: amount zero");
mTokenRate = _getMTokenRate();
amountUsd = (amountMToken * mTokenRate) / (10**18);
}
/**
* @dev validate redeem and calculate fee
* @param user user address
* @param tokenOut tokenOut address
* @param amountMTokenIn mToken amount (decimals 18)
* @param isInstant is instant operation
* @param isFiat is fiat operation
*
* @return result calc result
*/
function _calcAndValidateRedeem(
address user,
address tokenOut,
uint256 amountMTokenIn,
bool isInstant,
bool isFiat
) internal view returns (CalcAndValidateRedeemResult memory result) {
require(amountMTokenIn > 0, "RV: invalid amount");
if (!isFreeFromMinAmount[user]) {
uint256 minRedeemAmount = isFiat ? minFiatRedeemAmount : minAmount;
require(minRedeemAmount <= amountMTokenIn, "RV: amount < min");
}
result.feeAmount = _getFeeAmount(
user,
tokenOut,
amountMTokenIn,
isInstant,
isFiat ? fiatAdditionalFee : 0
);
if (isFiat) {
require(
tokenOut == MANUAL_FULLFILMENT_TOKEN,
"RV: tokenOut != fiat"
);
if (!waivedFeeRestriction[user]) result.feeAmount += fiatFlatFee;
} else {
_requireTokenExists(tokenOut);
}
require(amountMTokenIn > result.feeAmount, "RV: amountMTokenIn < fee");
result.amountMTokenWithoutFee = amountMTokenIn - result.feeAmount;
}
/*
* @dev validates that liquidity of provided token on `requestRedeemer` is enough
* @param token token address
* @param requiredLiquidity minimum required liquidity of `requestRedeemer`
* @param tokenDecimals `token` decimals
*
* @return false if not enough liquidity, otherwise true
*/
function _validateLiquidity(
address token,
uint256 requiredLiquidity,
uint256 tokenDecimals
)
internal
view
returns (
bool /* success */
)
{
uint256 balance = IERC20(token).balanceOf(requestRedeemer);
return balance >= requiredLiquidity.convertFromBase18(tokenDecimals);
}
/**
* @dev gets and validates mToken rate
* @return mTokenRate mToken rate
*/
function _getMTokenRate() private view returns (uint256 mTokenRate) {
mTokenRate = _getTokenRate(address(mTokenDataFeed), false);
require(mTokenRate > 0, "RV: rate zero");
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
import {IERC20Upgradeable as IERC20} from "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import {SafeERC20Upgradeable as SafeERC20} from "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";
import "./RedemptionVault.sol";
import "./interfaces/IRedemptionVault.sol";
import "./interfaces/IRedemptionVaultWithSwapper.sol";
import "./libraries/DecimalsCorrectionLibrary.sol";
/**
* @title RedemptionVaultWithSwapper
* @notice Smart contract that handles mToken redemption.
* In case of insufficient liquidity it uses a RV from a different
* Midas product to fulfill instant redemption.
* @dev mToken1 - is a main mToken of this vault
* mToken2 - is a token of a second vault that is triggered when
* current vault don`t have enough liquidity
* @author RedDuck Software
*/
contract RedemptionVaultWithSwapper is
IRedemptionVaultWithSwapper,
RedemptionVault
{
using DecimalsCorrectionLibrary for uint256;
using SafeERC20 for IERC20;
/**
* @dev added second gap here to match the storage layout
* from the previous contracts inheritance tree
*/
uint256[50] private ___gap;
/**
* @notice mToken1 redemption vault
* @dev The naming was not altered to maintain
* compatibility with the currently deployed contracts.
*/
IRedemptionVault public mTbillRedemptionVault;
address public liquidityProvider;
/**
* @dev leaving a storage gap for futures updates
*/
uint256[50] private __gap;
/**
* @notice upgradeable pattern contract`s initializer
* @param _ac address of MidasAccessControll contract
* @param _mTokenInitParams init params for mToken1
* @param _receiversInitParams init params for receivers
* @param _instantInitParams init params for instant operations
* @param _sanctionsList address of sanctionsList contract
* @param _variationTolerance percent of prices diviation 1% = 100
* @param _minAmount basic min amount for operations
* @param _fiatRedemptionInitParams params fiatAdditionalFee, fiatFlatFee, minFiatRedeemAmount
* @param _requestRedeemer address is designated for standard redemptions, allowing tokens to be pulled from this address
* @param _mTbillRedemptionVault mToken2 redemptionVault address
* @param _liquidityProvider liquidity provider for pull mToken2
*/
function initialize(
address _ac,
MTokenInitParams calldata _mTokenInitParams,
ReceiversInitParams calldata _receiversInitParams,
InstantInitParams calldata _instantInitParams,
address _sanctionsList,
uint256 _variationTolerance,
uint256 _minAmount,
FiatRedeptionInitParams calldata _fiatRedemptionInitParams,
address _requestRedeemer,
address _mTbillRedemptionVault,
address _liquidityProvider
) external initializer {
__RedemptionVault_init(
_ac,
_mTokenInitParams,
_receiversInitParams,
_instantInitParams,
_sanctionsList,
_variationTolerance,
_minAmount,
_fiatRedemptionInitParams,
_requestRedeemer
);
_validateAddress(_mTbillRedemptionVault, true);
_validateAddress(_liquidityProvider, false);
mTbillRedemptionVault = IRedemptionVault(_mTbillRedemptionVault);
liquidityProvider = _liquidityProvider;
}
/**
* @dev redeem mToken1 to tokenOut if daily limit and allowance not exceeded
* If contract don't have enough tokenOut, mToken1 will swap to mToken2 and redeem on mToken2 vault
* Burns mToken1 from the user, if swap need mToken1 just tranfers to contract.
* Transfers fee in mToken1 to feeReceiver
* Transfers tokenOut to user.
* @param tokenOut token out address
* @param amountMTokenIn amount of mToken1 to redeem
* @param minReceiveAmount minimum expected amount of tokenOut to receive (decimals 18)
*/
function _redeemInstant(
address tokenOut,
uint256 amountMTokenIn,
uint256 minReceiveAmount,
address recipient
)
internal
override
returns (
CalcAndValidateRedeemResult memory calcResult,
uint256 amountTokenOutWithoutFee
)
{
address user = msg.sender;
calcResult = _calcAndValidateRedeem(
user,
tokenOut,
amountMTokenIn,
true,
false
);
uint256 tokenDecimals = _tokenDecimals(tokenOut);
uint256 amountMTokenInCopy = amountMTokenIn;
address tokenOutCopy = tokenOut;
uint256 minReceiveAmountCopy = minReceiveAmount;
(uint256 amountMTokenInUsd, uint256 mTokenRate) = _convertMTokenToUsd(
amountMTokenInCopy
);
(uint256 amountTokenOut, uint256 tokenOutRate) = _convertUsdToToken(
amountMTokenInUsd,
tokenOutCopy
);
amountTokenOutWithoutFee = _truncate(
(calcResult.amountMTokenWithoutFee * mTokenRate) / tokenOutRate,
tokenDecimals
);
require(
amountTokenOutWithoutFee >= minReceiveAmountCopy,
"RVS: minReceiveAmount > actual"
);
if (calcResult.feeAmount > 0)
_tokenTransferFromUser(
address(mToken),
feeReceiver,
calcResult.feeAmount,
18
);
uint256 contractTokenOutBalance = IERC20(tokenOutCopy).balanceOf(
address(this)
);
_requireAndUpdateLimit(amountMTokenInCopy);
_requireAndUpdateAllowance(tokenOutCopy, amountTokenOut);
if (
contractTokenOutBalance >=
amountTokenOutWithoutFee.convertFromBase18(tokenDecimals)
) {
mToken.burn(user, calcResult.amountMTokenWithoutFee);
} else {
uint256 mTbillAmount = _swapMToken1ToMToken2(
calcResult.amountMTokenWithoutFee
);
IERC20(mTbillRedemptionVault.mToken()).safeIncreaseAllowance(
address(mTbillRedemptionVault),
mTbillAmount
);
mTbillRedemptionVault.redeemInstant(
tokenOutCopy,
mTbillAmount,
minReceiveAmountCopy
);
uint256 contractTokenOutBalanceAfterRedeem = IERC20(tokenOutCopy)
.balanceOf(address(this));
amountTokenOutWithoutFee = (contractTokenOutBalanceAfterRedeem -
contractTokenOutBalance).convertToBase18(tokenDecimals);
}
_tokenTransferToUser(
tokenOutCopy,
recipient,
amountTokenOutWithoutFee,
tokenDecimals
);
}
/**
* @inheritdoc IRedemptionVaultWithSwapper
*/
function setLiquidityProvider(address provider) external onlyVaultAdmin {
require(liquidityProvider != provider, "MRVS: already provider");
_validateAddress(provider, false);
liquidityProvider = provider;
emit SetLiquidityProvider(msg.sender, provider);
}
/**
* @inheritdoc IRedemptionVaultWithSwapper
*/
function setSwapperVault(address newVault) external onlyVaultAdmin {
require(
newVault != address(mTbillRedemptionVault),
"MRVS: already provider"
);
_validateAddress(newVault, true);
mTbillRedemptionVault = IRedemptionVault(newVault);
emit SetSwapperVault(msg.sender, newVault);
}
/**
* @notice Transfers mToken1 to liquidity provider
* Transfers mToken2 from liquidity provider to contract
* Returns amount on mToken2 using exchange rates
* @param mToken1Amount mToken1 token amount (decimals 18)
*/
function _swapMToken1ToMToken2(uint256 mToken1Amount)
internal
returns (uint256 mTokenAmount)
{
_tokenTransferFromUser(
address(mToken),
liquidityProvider,
mToken1Amount,
18
);
uint256 mTbillRate = mTbillRedemptionVault
.mTokenDataFeed()
.getDataInBase18();
uint256 mTokenRate = mTokenDataFeed.getDataInBase18();
mTokenAmount = (mToken1Amount * mTokenRate) / mTbillRate;
_tokenTransferFromTo(
address(mTbillRedemptionVault.mToken()),
liquidityProvider,
address(this),
mTokenAmount,
18
);
}
}{
"optimizer": {
"enabled": true,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"metadata": {
"useLiteralContent": true
}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":true,"internalType":"address","name":"dataFeed","type":"address"},{"indexed":false,"internalType":"uint256","name":"fee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"allowance","type":"uint256"},{"indexed":false,"internalType":"bool","name":"stable","type":"bool"}],"name":"AddPaymentToken","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"caller","type":"address"}],"name":"AddWaivedFeeAccount","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"requestId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newMTokenRate","type":"uint256"}],"name":"ApproveRequest","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"uint256","name":"allowance","type":"uint256"}],"name":"ChangeTokenAllowance","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"uint256","name":"fee","type":"uint256"}],"name":"ChangeTokenFee","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"bool","name":"enable","type":"bool"}],"name":"FreeFromMinAmount","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"bytes4","name":"fn","type":"bytes4"}],"name":"PauseFn","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"address","name":"tokenOut","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"feeAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountTokenOut","type":"uint256"}],"name":"RedeemInstant","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"address","name":"tokenOut","type":"address"},{"indexed":false,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"feeAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountTokenOut","type":"uint256"}],"name":"RedeemInstantWithCustomRecipient","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"requestId","type":"uint256"},{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"address","name":"tokenOut","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountMTokenIn","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"feeAmount","type":"uint256"}],"name":"RedeemRequest","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"requestId","type":"uint256"},{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"address","name":"tokenOut","type":"address"},{"indexed":false,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountMTokenIn","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"feeAmount","type":"uint256"}],"name":"RedeemRequestWithCustomRecipient","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"requestId","type":"uint256"},{"indexed":true,"internalType":"address","name":"user","type":"address"}],"name":"RejectRequest","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":true,"internalType":"address","name":"caller","type":"address"}],"name":"RemovePaymentToken","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"caller","type":"address"}],"name":"RemoveWaivedFeeAccount","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"requestId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newMTokenRate","type":"uint256"}],"name":"SafeApproveRequest","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"reciever","type":"address"}],"name":"SetFeeReceiver","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"uint256","name":"newfee","type":"uint256"}],"name":"SetFiatAdditionalFee","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"uint256","name":"feeInMToken","type":"uint256"}],"name":"SetFiatFlatFee","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"bool","name":"enable","type":"bool"}],"name":"SetGreenlistEnable","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"uint256","name":"newLimit","type":"uint256"}],"name":"SetInstantDailyLimit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"uint256","name":"newFee","type":"uint256"}],"name":"SetInstantFee","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"provider","type":"address"}],"name":"SetLiquidityProvider","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"uint256","name":"newAmount","type":"uint256"}],"name":"SetMinAmount","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"uint256","name":"newMinAmount","type":"uint256"}],"name":"SetMinFiatRedeemAmount","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"address","name":"redeemer","type":"address"}],"name":"SetRequestRedeemer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"newSanctionsList","type":"address"}],"name":"SetSanctionsList","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"vault","type":"address"}],"name":"SetSwapperVault","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"reciever","type":"address"}],"name":"SetTokensReceiver","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"uint256","name":"newTolerance","type":"uint256"}],"name":"SetVariationTolerance","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"bytes4","name":"fn","type":"bytes4"}],"name":"UnpauseFn","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":true,"internalType":"address","name":"withdrawTo","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"WithdrawToken","type":"event"},{"inputs":[],"name":"BLACKLISTED_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"BLACKLIST_OPERATOR_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"GREENLISTED_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"GREENLIST_OPERATOR_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"KMI_USD_CUSTOM_AGGREGATOR_FEED_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"KMI_USD_DEPOSIT_VAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"KMI_USD_REDEMPTION_VAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MANUAL_FULLFILMENT_TOKEN","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_UINT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ONE_HUNDRED_PERCENT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"STABLECOIN_RATE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"accessControl","outputs":[{"internalType":"contract MidasAccessControl","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"dataFeed","type":"address"},{"internalType":"uint256","name":"tokenFee","type":"uint256"},{"internalType":"uint256","name":"allowance","type":"uint256"},{"internalType":"bool","name":"stable","type":"bool"}],"name":"addPaymentToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"addWaivedFeeAccount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"requestId","type":"uint256"},{"internalType":"uint256","name":"newMTokenRate","type":"uint256"}],"name":"approveRequest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"allowance","type":"uint256"}],"name":"changeTokenAllowance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"fee","type":"uint256"}],"name":"changeTokenFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"currentRequestId","outputs":[{"internalType":"uint256","name":"_value","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"dailyLimits","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feeReceiver","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"fiatAdditionalFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"fiatFlatFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"name":"fnPaused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"bool","name":"enable","type":"bool"}],"name":"freeFromMinAmount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getPaymentTokens","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"greenlistEnabled","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"greenlistTogglerRole","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"greenlistedRole","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_ac","type":"address"},{"components":[{"internalType":"address","name":"mToken","type":"address"},{"internalType":"address","name":"mTokenDataFeed","type":"address"}],"internalType":"struct MTokenInitParams","name":"_mTokenInitParams","type":"tuple"},{"components":[{"internalType":"address","name":"tokensReceiver","type":"address"},{"internalType":"address","name":"feeReceiver","type":"address"}],"internalType":"struct ReceiversInitParams","name":"_receiversInitParams","type":"tuple"},{"components":[{"internalType":"uint256","name":"instantFee","type":"uint256"},{"internalType":"uint256","name":"instantDailyLimit","type":"uint256"}],"internalType":"struct InstantInitParams","name":"_instantInitParams","type":"tuple"},{"internalType":"address","name":"_sanctionsList","type":"address"},{"internalType":"uint256","name":"_variationTolerance","type":"uint256"},{"internalType":"uint256","name":"_minAmount","type":"uint256"},{"components":[{"internalType":"uint256","name":"fiatAdditionalFee","type":"uint256"},{"internalType":"uint256","name":"fiatFlatFee","type":"uint256"},{"internalType":"uint256","name":"minFiatRedeemAmount","type":"uint256"}],"internalType":"struct FiatRedeptionInitParams","name":"_fiatRedemptionInitParams","type":"tuple"},{"internalType":"address","name":"_requestRedeemer","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_ac","type":"address"},{"components":[{"internalType":"address","name":"mToken","type":"address"},{"internalType":"address","name":"mTokenDataFeed","type":"address"}],"internalType":"struct MTokenInitParams","name":"_mTokenInitParams","type":"tuple"},{"components":[{"internalType":"address","name":"tokensReceiver","type":"address"},{"internalType":"address","name":"feeReceiver","type":"address"}],"internalType":"struct ReceiversInitParams","name":"_receiversInitParams","type":"tuple"},{"components":[{"internalType":"uint256","name":"instantFee","type":"uint256"},{"internalType":"uint256","name":"instantDailyLimit","type":"uint256"}],"internalType":"struct InstantInitParams","name":"_instantInitParams","type":"tuple"},{"internalType":"address","name":"_sanctionsList","type":"address"},{"internalType":"uint256","name":"_variationTolerance","type":"uint256"},{"internalType":"uint256","name":"_minAmount","type":"uint256"},{"components":[{"internalType":"uint256","name":"fiatAdditionalFee","type":"uint256"},{"internalType":"uint256","name":"fiatFlatFee","type":"uint256"},{"internalType":"uint256","name":"minFiatRedeemAmount","type":"uint256"}],"internalType":"struct FiatRedeptionInitParams","name":"_fiatRedemptionInitParams","type":"tuple"},{"internalType":"address","name":"_requestRedeemer","type":"address"},{"internalType":"address","name":"_mTbillRedemptionVault","type":"address"},{"internalType":"address","name":"_liquidityProvider","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"instantDailyLimit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"instantFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isFreeFromMinAmount","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"liquidityProvider","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"mTbillRedemptionVault","outputs":[{"internalType":"contract IRedemptionVault","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"mToken","outputs":[{"internalType":"contract IMToken","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"mTokenDataFeed","outputs":[{"internalType":"contract IDataFeed","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minFiatRedeemAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"pauseAdminRole","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"fn","type":"bytes4"}],"name":"pauseFn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountMTokenIn","type":"uint256"}],"name":"redeemFiatRequest","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"uint256","name":"amountMTokenIn","type":"uint256"},{"internalType":"uint256","name":"minReceiveAmount","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"}],"name":"redeemInstant","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"uint256","name":"amountMTokenIn","type":"uint256"},{"internalType":"uint256","name":"minReceiveAmount","type":"uint256"}],"name":"redeemInstant","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"uint256","name":"amountMTokenIn","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"}],"name":"redeemRequest","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"uint256","name":"amountMTokenIn","type":"uint256"}],"name":"redeemRequest","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"redeemRequests","outputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"enum RequestStatus","name":"status","type":"uint8"},{"internalType":"uint256","name":"amountMToken","type":"uint256"},{"internalType":"uint256","name":"mTokenRate","type":"uint256"},{"internalType":"uint256","name":"tokenOutRate","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"requestId","type":"uint256"}],"name":"rejectRequest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"removePaymentToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"removeWaivedFeeAccount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"requestRedeemer","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"requestId","type":"uint256"},{"internalType":"uint256","name":"newMTokenRate","type":"uint256"}],"name":"safeApproveRequest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"requestIds","type":"uint256[]"}],"name":"safeBulkApproveRequest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"requestIds","type":"uint256[]"},{"internalType":"uint256","name":"newOutRate","type":"uint256"}],"name":"safeBulkApproveRequest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"sanctionsList","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"sanctionsListAdminRole","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"}],"name":"setFeeReceiver","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newFee","type":"uint256"}],"name":"setFiatAdditionalFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"feeInMToken","type":"uint256"}],"name":"setFiatFlatFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"enable","type":"bool"}],"name":"setGreenlistEnable","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newInstantDailyLimit","type":"uint256"}],"name":"setInstantDailyLimit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newInstantFee","type":"uint256"}],"name":"setInstantFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"provider","type":"address"}],"name":"setLiquidityProvider","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newAmount","type":"uint256"}],"name":"setMinAmount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newValue","type":"uint256"}],"name":"setMinFiatRedeemAmount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"redeemer","type":"address"}],"name":"setRequestRedeemer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newSanctionsList","type":"address"}],"name":"setSanctionsList","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newVault","type":"address"}],"name":"setSwapperVault","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"}],"name":"setTokensReceiver","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tolerance","type":"uint256"}],"name":"setVariationTolerance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"tokensConfig","outputs":[{"internalType":"address","name":"dataFeed","type":"address"},{"internalType":"uint256","name":"fee","type":"uint256"},{"internalType":"uint256","name":"allowance","type":"uint256"},{"internalType":"bool","name":"stable","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tokensReceiver","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"fn","type":"bytes4"}],"name":"unpauseFn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"variationTolerance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"vaultRole","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"waivedFeeRestriction","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"withdrawTo","type":"address"}],"name":"withdrawToken","outputs":[],"stateMutability":"nonpayable","type":"function"}]Contract Creation Code
60806040523480156200001157600080fd5b506200001c62000022565b620000e3565b600054610100900460ff16156200008f5760405162461bcd60e51b815260206004820152602760248201527f496e697469616c697a61626c653a20636f6e747261637420697320696e697469604482015266616c697a696e6760c81b606482015260840160405180910390fd5b60005460ff90811614620000e1576000805460ff191660ff9081179091556040519081527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b565b614fc280620000f36000396000f3fe608060405234801561001057600080fd5b506004361061048b5760003560e01c806385ab2c1311610262578063bfc2d46a11610151578063db74d8b5116100ce578063e85ba3e911610092578063e85ba3e914610ade578063eaf896fd14610b44578063ec571c6a14610b4c578063efdcd97414610b60578063f41759e714610b73578063f5d46c5114610b8657600080fd5b8063db74d8b514610a93578063dd0081c714610aa6578063e428877e14610aaf578063e5b5019a14610ac2578063e624c4bc14610acb57600080fd5b8063d35780b411610115578063d35780b414610a35578063d5f73f5c14610a48578063d7fd2bae14610a5b578063d9fbce8114610a7f578063daddcb161461060557600080fd5b8063bfc2d46a146109ef578063c3b6f93914610a02578063c47d51be14610a16578063ca5e553e14610a20578063cabccc7f1461060557600080fd5b8063a0c74afc116101df578063ad9e5649116101a3578063ad9e56491461090c578063b3f006741461091f578063bbae408614610933578063bc979af614610959578063bf115386146109c857600080fd5b8063a0c74afc146108c1578063a217fddf146108d4578063a3ece893146108dc578063a5125421146108e6578063a8f9a71d146108f957600080fd5b80638b53f75e116102265780638b53f75e14610866578063930b201214610879578063978ff560146108a05780639af40265146108af5780639b2cb5d8146108b757600080fd5b806385ab2c131461080757806388a6de681461081a578063897b06371461082d57806389cbaae6146108405780638a0ae6151461085357600080fd5b80633f4ba83a1161037e5780636254afb6116102fb57806373b7f873116102bf57806373b7f873146107bb57806373e9e01f146107ce578063769bc79c146107e25780637af5ca99146107f55780638456cb59146107ff57600080fd5b80636254afb61461074257806362b199c5146107565780636957463a1461077d5780636dc69e03146107905780637192de4b146107b157600080fd5b80635300b4ba116103425780635300b4ba146106de578063563b1dbf146107055780635ae2bfdb146107185780635b8bec55146107235780635c975abb1461073757600080fd5b80633f4ba83a14610676578063476abc761461067e57806349dc5e8d146106915780634a5971eb146106a45780634c20e9b9146106b757600080fd5b806327abf5181161040c5780633733337d116103d05780633733337d146106205780633807be7d146106335780633972183c1461064657806339dac34d146106505780633ccdbb281461066357600080fd5b806327abf518146105cc5780632c0a90a9146105df5780632d7788db146105f257806332b30cce1461060557806334c244891461060d57600080fd5b806315b9598a1161045357806315b9598a1461054b57806316683aa514610572578063191f3a3e146105875780631ed41163146105915780631fa1e8d4146105b857600080fd5b8063042da5ee146104905780630b5a57bd146104c9578063105ed2b2146104ec57806313007d55146104f957806315571a041461052a575b600080fd5b6104b461049e36600461467e565b61016b6020526000908152604090205460ff1681565b60405190151581526020015b60405180910390f35b6104b46104d736600461469b565b60976020526000908152604090205460ff1681565b60fc546104b49060ff1681565b600054610512906201000090046001600160a01b031681565b6040516001600160a01b0390911681526020016104c0565b61053d6105383660046146c5565b610b99565b6040519081526020016104c0565b61053d7f77c5b782690f31cd39b1abf2448215259a688a75920040c399d96a676bd1999d81565b61058561058036600461467e565b610c9d565b005b61053d6101a45481565b61053d7fd2576bd6a4c5558421de15cb8ecdf4eb3282aac06b94d4f004e8cd0d00f3ebd881565b61016554610512906001600160a01b031681565b6105856105da366004614715565b610d53565b6105856105ed366004614732565b610df8565b610585610600366004614754565b610e4f565b61053d610f57565b61058561061b366004614754565b610f66565b61058561062e36600461469b565b610fb4565b61058561064136600461469b565b611050565b61053d6101675481565b61058561065e36600461476d565b611110565b6105856106713660046146c5565b6111d7565b610585611252565b61058561068c36600461467e565b611267565b61058561069f36600461467e565b6112ca565b6105856106b23660046147d0565b611322565b61053d7f399c51febc66485c68c893eec57d25171ec297bcacececed07b76d2455734e2181565b61053d7f2fdc6683bc8d03effec5b41d3834f28bd219e06ca0a6a26fc737e44b1c7889ff81565b610585610713366004614754565b6113fe565b6101625461053d9081565b61020d54610512906001600160a01b031681565b60655460ff166104b4565b61016454610512906001600160a01b031681565b61053d7f548c7f0307ab2a7ea894e5c7e8c5353cc750bb9385ee2e945f189a9a83daa8ed81565b61058561078b366004614754565b611441565b61053d61079e366004614754565b6101686020526000908152604090205481565b61053d61016a5481565b6105856107c9366004614754565b6114c5565b6101a754610512906001600160a01b031681565b6105856107f0366004614754565b611513565b61053d6101a35481565b610585611556565b610585610815366004614879565b611569565b610585610828366004614732565b611667565b61058561083b366004614754565b6116b3565b61058561084e36600461467e565b6116f6565b6105856108613660046148c3565b6117b1565b6105856108743660046148ef565b611879565b61053d7fb81d2c6ada30c222c72e59cbb7f9918867981b6be5e0de70a02c28699231f04e81565b61053d670de0b6b3a764000081565b610512600081565b61053d61016f5481565b6105856108cf366004614970565b611951565b61053d600081565b61053d6101a55481565b6105856108f436600461467e565b61196d565b61058561090736600461467e565b611a2c565b61058561091a366004614754565b611a93565b61016954610512906001600160a01b031681565b7fd2576bd6a4c5558421de15cb8ecdf4eb3282aac06b94d4f004e8cd0d00f3ebd861053d565b61099c61096736600461467e565b61016e6020526000908152604090208054600182015460028301546003909301546001600160a01b0390921692909160ff1684565b604080516001600160a01b039095168552602085019390935291830152151560608201526080016104c0565b61053d7f7537f0610d8c5c0e3877e4eaf4bbfa46ce64756a4162f35656eb7046cfa8790681565b61053d6109fd3660046148c3565b611ae1565b61016354610512906001600160a01b031681565b61053d6101665481565b610a28611bc7565b6040516104c091906149b2565b610585610a433660046149ff565b611bd4565b61053d610a56366004614754565b611cfa565b6104b4610a6936600461467e565b6101706020526000908152604090205460ff1681565b61020c54610512906001600160a01b031681565b610585610aa13660046148c3565b611db1565b61053d61271081565b610585610abd36600461467e565b611e24565b61053d60001981565b610585610ad936600461467e565b611edc565b610b32610aec366004614754565b6101a660205260009081526040902080546001820154600283015460038401546004909401546001600160a01b039384169493831693600160a01b90930460ff16929086565b6040516104c096959493929190614ae6565b61053d611f97565b61012f54610512906001600160a01b031681565b610585610b6e36600461467e565b611fbb565b610585610b81366004614b3f565b61201e565b610585610b94366004614b9e565b612150565b60007f15571a04db30fd97c63b5be63c944e52a0a9a2af487d66beb3260a16c32f9bc2610bc4612206565b6001600160e01b0319811660009081526097602052604090205460ff1615610c075760405162461bcd60e51b8152600401610bfe90614bea565b60405180910390fd5b610c103361224c565b6001600160a01b0383163314610c2957610c298361224c565b600080610c398787600088612340565b8051604080516001600160a01b038a81168252602082018c9052818301939093529051939550919350891691339185917f691cd372bb63a5126a324513b634040d0ba3747c0a625207d99b6ba302c51a239181900360600190a45095945050505050565b610cae610ca8611f97565b336125c9565b6001600160a01b038116600090815261016b602052604090205460ff16610d075760405162461bcd60e51b815260206004820152600d60248201526c13558e881b9bdd08199bdd5b99609a1b6044820152606401610bfe565b6001600160a01b038116600081815261016b6020526040808220805460ff19169055513392917f57c4a95f59c12f0d4d846443c2d54c7d97f1505080199522fca2819e65213ca291a350565b610d5c33612697565b60fc5460ff1615158115151415610dae5760405162461bcd60e51b8152602060048201526016602482015275474c3a2073616d6520656e61626c652073746174757360501b6044820152606401610bfe565b60fc805460ff191682151590811790915560405190815233907fa8434267b880129bc4ba30249aa4a2ac349e8997c699282a9f70562f0f152f54906020015b60405180910390a250565b610e03610ca8611f97565b610e1082826000806126aa565b50817ff7d1fde87f32720fc30ce6847e0aae77e640b59bfac41b11b270358ccfa7a0ac82604051610e4391815260200190565b60405180910390a25050565b610e5a610ca8611f97565b60008181526101a660209081526040808320815160c08101835281546001600160a01b039081168252600183015490811694820194909452929091830190600160a01b900460ff166002811115610eb357610eb3614ad0565b6002811115610ec457610ec4614ad0565b815260200160028201548152602001600382015481526020016004820154815250509050610efa8160000151826040015161293a565b60008281526101a66020526040808220600101805460ff60a01b1916600160a11b179055825190516001600160a01b039091169184917ece63cc55966b103e4f4cb39f3426cb91718ad4f8eb4ad08c14a7ee749d81579190a35050565b6000610f61611f97565b905090565b610f71610ca8611f97565b610f7c8160016129e9565b61016a81905560405181815233907f018be394ba93a0dbca235443cfdc7173b2479180ad766083ce05199fbf3fc62490602001610ded565b610fbf610ca8610f57565b6001600160e01b0319811660009081526097602052604090205460ff1615610ff95760405162461bcd60e51b8152600401610bfe90614bea565b6001600160e01b03198116600081815260976020908152604091829020805460ff19166001179055905191825233917f2278e547293e53a66144c1743877f8388ac3101bd21cfd7c7f4ce8c15c14f5c19101610ded565b61105b610ca8610f57565b6001600160e01b0319811660009081526097602052604090205460ff166110bc5760405162461bcd60e51b815260206004820152601560248201527414185d5cd8589b194e88199b881d5b9c185d5cd959605a1b6044820152606401610bfe565b6001600160e01b03198116600081815260976020908152604091829020805460ff19169055905191825233917f929135cc6324f958693bb5f24a4dbc226a83c721523fc2785545019a3423b2d79101610ded565b61111b610ca8611f97565b6001600160a01b0382166000908152610170602052604090205460ff161515811515141561117e5760405162461bcd60e51b815260206004820152601060248201526f44563a20616c7265616479206672656560801b6044820152606401610bfe565b6001600160a01b03821660008181526101706020908152604091829020805460ff191685151590811790915591519182527f80f6f2f8801c6ac8fc60bf218b44fde97744d8709f69281972ec5557c10226cc9101610e43565b6111e2610ca8611f97565b6111f66001600160a01b0384168284612a69565b806001600160a01b0316836001600160a01b0316336001600160a01b03167f9ca7c1e047552a8048d924a5a8d3c150eb861086a72a9100e5f19d1176c1b7468560405161124591815260200190565b60405180910390a4505050565b61125d610ca8610f57565b611265612acc565b565b611272610ca8611f97565b61127d816001612b1e565b61016580546001600160a01b0319166001600160a01b03831690811790915560405133907fdb5a411e1a379f981ff6bc5284aa2c2522a9b8fd33a9db9ca19b34006cefbe9c90600090a350565b6112d5610ca8610f57565b61012f80546001600160a01b0319166001600160a01b03831690811790915560405133907f7f0c791852a03e270d4c2b78bbd4b959bca234de8d1ccf27eee03afaeafe63c490600090a350565b600054610100900460ff16158080156113425750600054600160ff909116105b8061135c5750303b15801561135c575060005460ff166001145b6113785760405162461bcd60e51b8152600401610bfe90614c17565b6000805460ff19166001179055801561139b576000805461ff0019166101001790555b6113ac8a8a8a8a8a8a8a8a8a612bb4565b80156113f2576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b50505050505050505050565b611409610ca8611f97565b6101a581905560405181815233907f72bae0b4c0979f93d77dce748bd8dfbc89d0f1cd524eee95367e3d2ce5eca93f90602001610ded565b61144c610ca8611f97565b6000811161148d5760405162461bcd60e51b815260206004820152600e60248201526d4d563a206c696d6974207a65726f60901b6044820152606401610bfe565b61016781905560405181815233907f5e8309fc6b2360e7438bc53790b00913395fffa870f39043fe63ddc8a438a9b290602001610ded565b6114d0610ca8611f97565b6114db8160006129e9565b6101a481905560405181815233907fa627d2a34207df740c6b90691350e2a762296cbf59affeb2282e6a54d631d4db90602001610ded565b61151e610ca8611f97565b6101a381905560405181815233907f8855fe6f9cbc4052017b3546fa14e167c5af2daad7f1c64db7f897fbcfb657b090602001610ded565b611561610ca8610f57565b611265612c43565b7f85ab2c1384c32949856b8251e03c48dafd9a1c9e9661d6ee6d38a46b7a508daa611592612206565b6001600160e01b0319811660009081526097602052604090205460ff16156115cc5760405162461bcd60e51b8152600401610bfe90614bea565b6115d53361224c565b6001600160a01b03821633146115ee576115ee8261224c565b6000806115fd87878787612c80565b8151604080516001600160a01b038981168252602082018c905291810192909252606082018390529294509092509088169033907f4fd0e2f3f27549d8d0c242f7193eaa0f61546e887fec39e69dfbff6b2384a4c39060800160405180910390a350505050505050565b611672610ca8611f97565b6116808282600160006126aa565b50817f03ea09e71742c9c754c9746b3e671ecb27fc372e3d29c31bac0192458ffd9d4b82604051610e4391815260200190565b6116be610ca8611f97565b61016f81905560405181815233907f57e764c1fef224e74706b109734513889970db6f1dde107b1bda66e10d80ca9b90602001610ded565b611701610ca8611f97565b61020c546001600160a01b03828116911614156117595760405162461bcd60e51b815260206004820152601660248201527526a92b299d1030b63932b0b23c90383937bb34b232b960511b6044820152606401610bfe565b611764816001612b1e565b61020c80546001600160a01b0319166001600160a01b03831690811790915560405133907fd081462190bc4f588c3e60685e37e27b800f5ac8b62c3edd7eecba5d1cecb9d590600090a350565b6117bc610ca8611f97565b6001600160a01b038216156117d4576117d482613057565b600081116118195760405162461bcd60e51b81526020600482015260126024820152714d563a207a65726f20616c6c6f77616e636560701b6044820152606401610bfe565b6001600160a01b038216600081815261016e602052604090819020600201839055513391907ff7273742887a46d8b97d83d1d12b6d8d8e6d21d814072369e2f4b355690221d79061186d9085815260200190565b60405180910390a35050565b7f8b53f75ebd6e3af54b2d42f7b3f6d41d997973b4f29dcd155e6a81f98c0f7d5a6118a2612206565b6001600160e01b0319811660009081526097602052604090205460ff16156118dc5760405162461bcd60e51b8152600401610bfe90614bea565b6118e53361224c565b6000806118f486868633612c80565b8151604080518981526020810192909252810182905291935091506001600160a01b0387169033907f1af12536d161c2c30ad907b0abe442f94c4a7824f2463585b3fc893275247cce9060600160405180910390a3505050505050565b600061195b6130a9565b9050611968838383612150565b505050565b611978610ca8611f97565b61198461016c82613108565b6119c15760405162461bcd60e51b815260206004820152600e60248201526d4d563a206e6f742065786973747360901b6044820152606401610bfe565b6001600160a01b038116600081815261016e602052604080822080546001600160a01b03191681556001810183905560028101839055600301805460ff19169055513392917f652fa2f5d587d3f1c189df0081b7bf3121f47d51d5471bf58d7d2c8a084894c391a350565b611a37610ca8611f97565b611a42816000612b1e565b6101a780546001600160a01b0319166001600160a01b03831690811790915560405190815233907f5059e224ac539671fe0261fc6672c365607aa98da29c849726ac5956902221b490602001610ded565b611a9e610ca8611f97565b611aa98160006129e9565b61016681905560405181815233907f45acc8bd6ebd6fbb59ce049b682c124aeccc93c468fcf60fecf61340e86e79d390602001610ded565b60007fbfc2d46a919432a5240e2d1b08da2f7ce0add499a19be62446ee561d32e12e22611b0c612206565b6001600160e01b0319811660009081526097602052604090205460ff1615611b465760405162461bcd60e51b8152600401610bfe90614bea565b611b4f3361224c565b600080611b5f8686600033612340565b91509150856001600160a01b0316336001600160a01b0316837f55ba94d231fa70a45e82b0a1c6a60ef72e41bb2455385128ee5cf8d98c0c1c0e888560000151604051611bb6929190918252602082015260400190565b60405180910390a450949350505050565b6060610f6161016c613126565b600054610100900460ff1615808015611bf45750600054600160ff909116105b80611c0e5750303b158015611c0e575060005460ff166001145b611c2a5760405162461bcd60e51b8152600401610bfe90614c17565b6000805460ff191660011790558015611c4d576000805461ff0019166101001790555b611c5e8c8c8c8c8c8c8c8c8c612bb4565b611c69836001612b1e565b611c74826000612b1e565b61020c80546001600160a01b038086166001600160a01b03199283161790925561020d8054928516929091169190911790558015611cec576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b505050505050505050505050565b600063357dcfd760e21b611d0c612206565b6001600160e01b0319811660009081526097602052604090205460ff1615611d465760405162461bcd60e51b8152600401610bfe90614bea565b611d4f3361224c565b600080611d60600086600133612340565b8051604080518981526020810192909252929450909250600091339185917f55ba94d231fa70a45e82b0a1c6a60ef72e41bb2455385128ee5cf8d98c0c1c0e910160405180910390a4509392505050565b611dbc610ca8611f97565b611dc582613057565b611dd08160006129e9565b6001600160a01b038216600081815261016e602052604090819020600101839055513391907f1582567d288d96695cf3fe7280c630a4f1c82fc7e665e1db58468f2960fef8699061186d9085815260200190565b611e2f610ca8611f97565b6001600160a01b038116600090815261016b602052604090205460ff1615611e8d5760405162461bcd60e51b815260206004820152601160248201527013558e88185b1c9958591e481859191959607a1b6044820152606401610bfe565b6001600160a01b038116600081815261016b6020526040808220805460ff19166001179055513392917f221f04b37331150bcfd05e2de362f50785c29ee4ab14f26d4495a51f3c02906091a350565b611ee7610ca8611f97565b61020d546001600160a01b0382811691161415611f3f5760405162461bcd60e51b815260206004820152601660248201527526a92b299d1030b63932b0b23c90383937bb34b232b960511b6044820152606401610bfe565b611f4a816000612b1e565b61020d80546001600160a01b0319166001600160a01b03831690811790915560405133907f96210ef89e9bcdbde362a89b05013b89c67c586c9de1243edbf07af800c5da1290600090a350565b7f399c51febc66485c68c893eec57d25171ec297bcacececed07b76d2455734e2190565b611fc6610ca8611f97565b611fd1816001612b1e565b61016980546001600160a01b0319166001600160a01b03831690811790915560405133907f1b092cca381ac00a07e1226c164f47c475d212f5e55699475a7f411811f77dd490600090a350565b612029610ca8611f97565b61203561016c8661313a565b6120755760405162461bcd60e51b815260206004820152601160248201527013558e88185b1c9958591e481859191959607a1b6044820152606401610bfe565b612080846000612b1e565b61208b8360006129e9565b604080516080810182526001600160a01b03868116808352602080840188815284860188815287151560608088018281528e8816600081815261016e88528b902099518a546001600160a01b0319169916989098178955935160018901559151600288015591516003909601805460ff19169615159690961790955585518981529182018890529481019490945292909133917f049000a9db89588d7bfb162bc0f7e4299ee8762430a468131c2caf0824f1f995910160405180910390a45050505050565b61215b610ca8611f97565b60005b8281101561220057600061218d85858481811061217d5761217d614c65565b90506020020135846001806126aa565b90508061219a57506121ee565b8484838181106121ac576121ac614c65565b905060200201357f03ea09e71742c9c754c9746b3e671ecb27fc372e3d29c31bac0192458ffd9d4b846040516121e491815260200190565b60405180910390a2505b806121f881614c91565b91505061215e565b50505050565b60655460ff16156112655760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610bfe565b60fc54819060ff1615612262576122628161314f565b8161226c81613175565b61012f5483906001600160a01b031680156123395760405163df592f7d60e01b81526001600160a01b03838116600483015282169063df592f7d9060240160206040518083038186803b1580156122c257600080fd5b505afa1580156122d6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122fa9190614cac565b156123395760405162461bcd60e51b815260206004820152600f60248201526e15d4d30e881cd85b98dd1a5bdb9959608a1b6044820152606401610bfe565b5050505050565b600061235f604051806040016040528060008152602001600081525090565b836123b1576001600160a01b0386166123b15760405162461bcd60e51b815260206004820152601460248201527314958e881d1bdad95b93dd5d080f4f48199a585d60621b6044820152606401610bfe565b336123c08188886000896131a1565b915086670de0b6b3a764000086612407576001600160a01b03808316600090815261016e602052604090208054600382015491926124039291169060ff16613399565b9150505b6101645460408051636369290560e01b815290516000926001600160a01b0316916363692905916004808301926020929190829003018186803b15801561244d57600080fd5b505afa158015612461573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124859190614cc9565b6101635460208701519192506124aa916001600160a01b039091169030906012613426565b508451156124d757610163546101695486516124d5926001600160a01b039081169216906012613426565b505b6101625495506124ec61016280546001019055565b6040805160c0810182526001600160a01b03808a1682528516602082015290810160008152602087810151818301526040808301859052606090920185905260008981526101a68252829020835181546001600160a01b039182166001600160a01b0319918216178355928501516001830180549190921693811684178255938501519193919290916001600160a81b03191617600160a01b83600281111561259757612597614ad0565b0217905550606082015160028201556080820151600382015560a0909101516004909101555050505094509492505050565b600054604051632474521560e21b8152600481018490526001600160a01b03838116602483015262010000909204909116906391d148549060440160206040518083038186803b15801561261c57600080fd5b505afa158015612630573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126549190614cac565b6126935760405162461bcd60e51b815260206004820152601060248201526f574d41433a206861736e7420726f6c6560801b6044820152606401610bfe565b5050565b61269f610f57565b8161196882826125c9565b60008481526101a660209081526040808320815160c08101835281546001600160a01b03908116825260018301549081169482019490945284939092830190600160a01b900460ff16600281111561270457612704614ad0565b600281111561271557612715614ad0565b81526020016002820154815260200160038201548152602001600482015481525050905061274b8160000151826040015161293a565b831561275f5761275f816080015186613471565b60208101516001600160a01b031615600081612787576127828360200151613504565b61278a565b60125b60ff16905060006127b98460a001518986606001516127a99190614ce2565b6127b39190614d01565b83613577565b90508261280c578580156127d957506127d784602001518284613587565b155b156127eb576000945050505050612932565b60208401516101a754855161280c92916001600160a01b0316908486613620565b61281a846020015182613673565b610163546060850151604051632770a7eb60e21b815230600482015260248101919091526001600160a01b0390911690639dc29fac90604401600060405180830381600087803b15801561286d57600080fd5b505af1158015612881573d6000803e3d6000fd5b505060016040878101828152608089018d905260008e81526101a66020908152929020895181546001600160a01b03199081166001600160a01b03928316178355938b0151948201805494851695909116948517815591518a96509094509290916001600160a81b03191617600160a01b83600281111561290457612904614ad0565b0217905550606082015160028201556080820151600382015560a09091015160049091015550600193505050505b949350505050565b6001600160a01b0382166129885760405162461bcd60e51b815260206004820152601560248201527414958e881c995c5d595cdd081b9bdd08195e1a5cdd605a1b6044820152606401610bfe565b600081600281111561299c5761299c614ad0565b146126935760405162461bcd60e51b815260206004820152601760248201527f52563a2072657175657374206e6f742070656e64696e670000000000000000006044820152606401610bfe565b612710821115612a285760405162461bcd60e51b815260206004820152600a602482015269666565203e203130302560b01b6044820152606401610bfe565b801561269357600082116126935760405162461bcd60e51b81526020600482015260086024820152670666565203d3d20360c41b6044820152606401610bfe565b6040516001600160a01b03831660248201526044810182905261196890849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915261371c565b612ad46137f1565b6065805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b6001600160a01b038216612b635760405162461bcd60e51b815260206004820152600c60248201526b7a65726f206164647265737360a01b6044820152606401610bfe565b8015612693576001600160a01b0382163014156126935760405162461bcd60e51b815260206004820152600f60248201526e696e76616c6964206164647265737360881b6044820152606401610bfe565b600054610100900460ff16612bdb5760405162461bcd60e51b8152600401610bfe90614d23565b612bea8989898989898961383a565b612bf6823560006129e9565b612c01816000612b1e565b60408201356101a35581356101a4556020909101356101a5556101a780546001600160a01b0319166001600160a01b0390921691909117905550505050505050565b612c4b612206565b6065805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258612b013390565b6040805180820190915260008082526020820152600033612ca58188886001866131a1565b92506000612cb288613504565b60ff169050868887600080612cc685613a12565b91509150600080612cd78487613a85565b91509150612cff81848d60200151612cef9190614ce2565b612cf99190614d01565b89613577565b9950848a1015612d515760405162461bcd60e51b815260206004820152601e60248201527f5256533a206d696e52656365697665416d6f756e74203e2061637475616c00006044820152606401610bfe565b8a5115612d7d5761016354610169548c51612d7b926001600160a01b039081169216906012613426565b505b6040516370a0823160e01b81523060048201526000906001600160a01b038816906370a082319060240160206040518083038186803b158015612dbf57600080fd5b505afa158015612dd3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612df79190614cc9565b9050612e0288613b65565b612e0c8784613673565b612e168b8a613bef565b8110612e8d576101635460208d0151604051632770a7eb60e21b81526001600160a01b038d811660048301526024820192909252911690639dc29fac90604401600060405180830381600087803b158015612e7057600080fd5b505af1158015612e84573d6000803e3d6000fd5b50505050613038565b6000612e9c8d60200151613bfd565b61020c546040805163c3b6f93960e01b81529051929350612f35926001600160a01b03909216918491839163c3b6f93991600480820192602092909190829003018186803b158015612eed57600080fd5b505afa158015612f01573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f259190614d6e565b6001600160a01b03169190613e5b565b61020c546040516345a9fbaf60e11b81526001600160a01b038a8116600483015260248201849052604482018a905290911690638b53f75e90606401600060405180830381600087803b158015612f8b57600080fd5b505af1158015612f9f573d6000803e3d6000fd5b50506040516370a0823160e01b8152306004820152600092506001600160a01b038b1691506370a082319060240160206040518083038186803b158015612fe557600080fd5b505afa158015612ff9573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061301d9190614cc9565b90506130338b61302d8584614d8b565b90613f17565b9c5050505b613044878e8d8c613f25565b5050505050505050505094509492505050565b61306361016c82613f6f565b6130a65760405162461bcd60e51b81526020600482015260146024820152734d563a20746f6b656e206e6f742065786973747360601b6044820152606401610bfe565b50565b610164546000906130c3906001600160a01b031682613399565b9050600081116131055760405162461bcd60e51b815260206004820152600d60248201526c52563a2072617465207a65726f60981b6044820152606401610bfe565b90565b600061311d836001600160a01b038416613f91565b90505b92915050565b6060600061313383614084565b9392505050565b600061311d836001600160a01b0384166140e0565b7fd2576bd6a4c5558421de15cb8ecdf4eb3282aac06b94d4f004e8cd0d00f3ebd861269f565b7f548c7f0307ab2a7ea894e5c7e8c5353cc750bb9385ee2e945f189a9a83daa8ed81611968828261412f565b6040805180820190915260008082526020820152600084116131fa5760405162461bcd60e51b815260206004820152601260248201527114958e881a5b9d985b1a5908185b5bdd5b9d60721b6044820152606401610bfe565b6001600160a01b0386166000908152610170602052604090205460ff166132775760008261322b5761016f54613230565b6101a3545b9050848111156132755760405162461bcd60e51b815260206004820152601060248201526f292b1d1030b6b7bab73a101e1036b4b760811b6044820152606401610bfe565b505b613293868686868661328a5760006141f8565b6101a4546141f8565b81528115613326576001600160a01b038516156132e95760405162461bcd60e51b815260206004820152601460248201527314958e881d1bdad95b93dd5d08084f48199a585d60621b6044820152606401610bfe565b6001600160a01b038616600090815261016b602052604090205460ff16613321576101a5548151829061331d908390614da2565b9052505b61332f565b61332f85613057565b8051841161337f5760405162461bcd60e51b815260206004820152601860248201527f52563a20616d6f756e744d546f6b656e496e203c2066656500000000000000006044820152606401610bfe565b805161338b9085614d8b565b602082015295945050505050565b600080836001600160a01b031663636929056040518163ffffffff1660e01b815260040160206040518083038186803b1580156133d557600080fd5b505afa1580156133e9573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061340d9190614cc9565b9050821561311d57670de0b6b3a7640000915050613120565b60006134328383613bef565b905061343e8183613f17565b831461345c5760405162461bcd60e51b8152600401610bfe90614dba565b6129326001600160a01b038616338684614299565b60008282101561348a576134858284614d8b565b613494565b6134948383614d8b565b90506000836134a561271084614ce2565b6134af9190614d01565b905061016a548111156122005760405162461bcd60e51b815260206004820152601a60248201527f4d563a2065786365656420707269636520646976696174696f6e0000000000006044820152606401610bfe565b6000816001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b15801561353f57600080fd5b505afa158015613553573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131209190614de8565b600061311d8261302d8582613bef565b6101a7546040516370a0823160e01b81526001600160a01b0391821660048201526000918291908616906370a082319060240160206040518083038186803b1580156135d257600080fd5b505afa1580156135e6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061360a9190614cc9565b90506136168484613bef565b1115949350505050565b600061362c8383613bef565b90506136388183613f17565b83146136565760405162461bcd60e51b8152600401610bfe90614dba565b61366b6001600160a01b038716868684614299565b505050505050565b6001600160a01b038216600090815261016e602052604090206002015460001981141561369f57505050565b818110156136e65760405162461bcd60e51b81526020600482015260146024820152734d563a2065786365656420616c6c6f77616e636560601b6044820152606401610bfe565b6001600160a01b038316600090815261016e602052604081206002018054849290613712908490614d8b565b9091555050505050565b6000613771826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166142d19092919063ffffffff16565b90508051600014806137925750808060200190518101906137929190614cac565b6119685760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610bfe565b60655460ff166112655760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610bfe565b600054610100900460ff166138615760405162461bcd60e51b8152600401610bfe90614d23565b613878613871602088018861467e565b6000612b1e565b61388b613871604088016020890161467e565b6138a261389b602087018761467e565b6001612b1e565b6138b561389b604087016020880161467e565b60008460200135116138f65760405162461bcd60e51b815260206004820152600a6024820152691e995c9bc81b1a5b5a5d60b21b6044820152606401610bfe565b6139018260016129e9565b61390d843560006129e9565b61391a602087018761467e565b61016380546001600160a01b0319166001600160a01b0392909216919091179055613944876142e0565b61394c614318565b613954614318565b61395d8361433f565b61396a602086018661467e565b61016580546001600160a01b0319166001600160a01b039290921691909117905561399b604086016020870161467e565b61016980546001600160a01b0319166001600160a01b03929092169190911790558335610166556020808501356101675561016f82905561016a8390556139e8906040880190880161467e565b61016480546001600160a01b0319166001600160a01b039290921691909117905550505050505050565b60008060008311613a575760405162461bcd60e51b815260206004820152600f60248201526e52563a20616d6f756e74207a65726f60881b6044820152606401610bfe565b613a5f6130a9565b9050670de0b6b3a7640000613a748285614ce2565b613a7e9190614d01565b9150915091565b60008060008411613aca5760405162461bcd60e51b815260206004820152600f60248201526e52563a20616d6f756e74207a65726f60881b6044820152606401610bfe565b6001600160a01b03808416600090815261016e60205260409020805460038201549192613afc9291169060ff16613399565b915060008211613b3e5760405162461bcd60e51b815260206004820152600d60248201526c52563a2072617465207a65726f60981b6044820152606401610bfe565b81613b5186670de0b6b3a7640000614ce2565b613b5b9190614d01565b9250509250929050565b6000613b746201518042614d01565b6000818152610168602052604081205491925090613b93908490614da2565b905061016754811115613bdb5760405162461bcd60e51b815260206004820152601060248201526f13558e88195e18d95959081b1a5b5a5d60821b6044820152606401610bfe565b600091825261016860205260409091205550565b600061311d83601284614389565b6101635461020d54600091613c21916001600160a01b039182169116846012613426565b5061020c546040805163312a57db60e11b815290516000926001600160a01b031691636254afb6916004808301926020929190829003018186803b158015613c6857600080fd5b505afa158015613c7c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ca09190614d6e565b6001600160a01b031663636929056040518163ffffffff1660e01b815260040160206040518083038186803b158015613cd857600080fd5b505afa158015613cec573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d109190614cc9565b9050600061016460009054906101000a90046001600160a01b03166001600160a01b031663636929056040518163ffffffff1660e01b815260040160206040518083038186803b158015613d6357600080fd5b505afa158015613d77573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d9b9190614cc9565b905081613da88286614ce2565b613db29190614d01565b9250613e5461020c60009054906101000a90046001600160a01b03166001600160a01b031663c3b6f9396040518163ffffffff1660e01b815260040160206040518083038186803b158015613e0657600080fd5b505afa158015613e1a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613e3e9190614d6e565b61020d546001600160a01b031630866012613620565b5050919050565b604051636eb1769f60e11b81523060048201526001600160a01b0383811660248301526000919085169063dd62ed3e9060440160206040518083038186803b158015613ea657600080fd5b505afa158015613eba573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ede9190614cc9565b90506122008463095ea7b360e01b85613ef78686614da2565b6040516001600160a01b0390921660248301526044820152606401612a95565b600061311d83836012614389565b6000613f318383613bef565b9050613f3d8183613f17565b8314613f5b5760405162461bcd60e51b8152600401610bfe90614dba565b6123396001600160a01b0386168583612a69565b6001600160a01b0381166000908152600183016020526040812054151561311d565b6000818152600183016020526040812054801561407a576000613fb5600183614d8b565b8554909150600090613fc990600190614d8b565b905081811461402e576000866000018281548110613fe957613fe9614c65565b906000526020600020015490508087600001848154811061400c5761400c614c65565b6000918252602080832090910192909255918252600188019052604090208390555b855486908061403f5761403f614e0b565b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050613120565b6000915050613120565b6060816000018054806020026020016040519081016040528092919081815260200182805480156140d457602002820191906000526020600020905b8154815260200190600101908083116140c0575b50505050509050919050565b600081815260018301602052604081205461412757508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155613120565b506000613120565b600054604051632474521560e21b8152600481018490526001600160a01b03838116602483015262010000909204909116906391d148549060440160206040518083038186803b15801561418257600080fd5b505afa158015614196573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906141ba9190614cac565b156126935760405162461bcd60e51b815260206004820152600e60248201526d574d41433a2068617320726f6c6560901b6044820152606401610bfe565b6001600160a01b038516600090815261016b602052604081205460ff161561422257506000614290565b60008261424c57506001600160a01b038516600090815261016e602052604090206001015461424f565b50815b831561426657610166546142639082614da2565b90505b61271081111561427557506127105b6127106142828287614ce2565b61428c9190614d01565b9150505b95945050505050565b6040516001600160a01b03808516602483015283166044820152606481018290526122009085906323b872dd60e01b90608401612a95565b606061293284846000856143f6565b600054610100900460ff166143075760405162461bcd60e51b8152600401610bfe90614d23565b61430f6144d1565b6130a681614500565b600054610100900460ff166112655760405162461bcd60e51b8152600401610bfe90614d23565b600054610100900460ff166143665760405162461bcd60e51b8152600401610bfe90614d23565b61012f80546001600160a01b0319166001600160a01b0392909216919091179055565b60008361439857506000613133565b818314156143a7575082613133565b6000828411156143d7576143bb8385614d8b565b6143c690600a614f05565b6143d09086614d01565b9050612932565b6143e18484614d8b565b6143ec90600a614f05565b6142909086614ce2565b6060824710156144575760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610bfe565b600080866001600160a01b031685876040516144739190614f3d565b60006040518083038185875af1925050503d80600081146144b0576040519150601f19603f3d011682016040523d82523d6000602084013e6144b5565b606091505b50915091506144c687838387614596565b979650505050505050565b600054610100900460ff166144f85760405162461bcd60e51b8152600401610bfe90614d23565b61126561460c565b600054610100900460ff166145275760405162461bcd60e51b8152600401610bfe90614d23565b6001600160a01b03811661456c5760405162461bcd60e51b815260206004820152600c60248201526b7a65726f206164647265737360a01b6044820152606401610bfe565b600080546001600160a01b03909216620100000262010000600160b01b0319909216919091179055565b606083156146025782516145fb576001600160a01b0385163b6145fb5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610bfe565b5081612932565b612932838361463f565b600054610100900460ff166146335760405162461bcd60e51b8152600401610bfe90614d23565b6065805460ff19169055565b81511561464f5781518083602001fd5b8060405162461bcd60e51b8152600401610bfe9190614f59565b6001600160a01b03811681146130a657600080fd5b60006020828403121561469057600080fd5b813561311d81614669565b6000602082840312156146ad57600080fd5b81356001600160e01b03198116811461311d57600080fd5b6000806000606084860312156146da57600080fd5b83356146e581614669565b92506020840135915060408401356146fc81614669565b809150509250925092565b80151581146130a657600080fd5b60006020828403121561472757600080fd5b813561311d81614707565b6000806040838503121561474557600080fd5b50508035926020909101359150565b60006020828403121561476657600080fd5b5035919050565b6000806040838503121561478057600080fd5b823561478b81614669565b9150602083013561479b81614707565b809150509250929050565b6000604082840312156147b857600080fd5b50919050565b6000606082840312156147b857600080fd5b60008060008060008060008060006101c08a8c0312156147ef57600080fd5b89356147fa81614669565b98506148098b60208c016147a6565b97506148188b60608c016147a6565b96506148278b60a08c016147a6565b955060e08a013561483781614669565b94506101008a013593506101208a013592506148578b6101408c016147be565b91506101a08a013561486881614669565b809150509295985092959850929598565b6000806000806080858703121561488f57600080fd5b843561489a81614669565b9350602085013592506040850135915060608501356148b881614669565b939692955090935050565b600080604083850312156148d657600080fd5b82356148e181614669565b946020939093013593505050565b60008060006060848603121561490457600080fd5b833561490f81614669565b95602085013595506040909401359392505050565b60008083601f84011261493657600080fd5b50813567ffffffffffffffff81111561494e57600080fd5b6020830191508360208260051b850101111561496957600080fd5b9250929050565b6000806020838503121561498357600080fd5b823567ffffffffffffffff81111561499a57600080fd5b6149a685828601614924565b90969095509350505050565b6020808252825182820181905260009190848201906040850190845b818110156149f35783516001600160a01b0316835292840192918401916001016149ce565b50909695505050505050565b60008060008060008060008060008060006102008c8e031215614a2157600080fd5b8b35614a2c81614669565b9a50614a3b8d60208e016147a6565b9950614a4a8d60608e016147a6565b9850614a598d60a08e016147a6565b975060e08c0135614a6981614669565b96506101008c013595506101208c01359450614a898d6101408e016147be565b93506101a08c0135614a9a81614669565b92506101c08c0135614aab81614669565b91506101e08c0135614abc81614669565b809150509295989b509295989b9093969950565b634e487b7160e01b600052602160045260246000fd5b6001600160a01b0387811682528616602082015260c0810160038610614b1c57634e487b7160e01b600052602160045260246000fd5b8560408301528460608301528360808301528260a0830152979650505050505050565b600080600080600060a08688031215614b5757600080fd5b8535614b6281614669565b94506020860135614b7281614669565b935060408601359250606086013591506080860135614b9081614707565b809150509295509295909350565b600080600060408486031215614bb357600080fd5b833567ffffffffffffffff811115614bca57600080fd5b614bd686828701614924565b909790965060209590950135949350505050565b60208082526013908201527214185d5cd8589b194e88199b881c185d5cd959606a1b604082015260600190565b6020808252602e908201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160408201526d191e481a5b9a5d1a585b1a5e995960921b606082015260800190565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b6000600019821415614ca557614ca5614c7b565b5060010190565b600060208284031215614cbe57600080fd5b815161311d81614707565b600060208284031215614cdb57600080fd5b5051919050565b6000816000190483118215151615614cfc57614cfc614c7b565b500290565b600082614d1e57634e487b7160e01b600052601260045260246000fd5b500490565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b600060208284031215614d8057600080fd5b815161311d81614669565b600082821015614d9d57614d9d614c7b565b500390565b60008219821115614db557614db5614c7b565b500190565b6020808252601490820152734d563a20696e76616c696420726f756e64696e6760601b604082015260600190565b600060208284031215614dfa57600080fd5b815160ff8116811461311d57600080fd5b634e487b7160e01b600052603160045260246000fd5b600181815b80851115614e5c578160001904821115614e4257614e42614c7b565b80851615614e4f57918102915b93841c9390800290614e26565b509250929050565b600082614e7357506001613120565b81614e8057506000613120565b8160018114614e965760028114614ea057614ebc565b6001915050613120565b60ff841115614eb157614eb1614c7b565b50506001821b613120565b5060208310610133831016604e8410600b8410161715614edf575081810a613120565b614ee98383614e21565b8060001904821115614efd57614efd614c7b565b029392505050565b600061311d8383614e64565b60005b83811015614f2c578181015183820152602001614f14565b838111156122005750506000910152565b60008251614f4f818460208701614f11565b9190910192915050565b6020815260008251806020840152614f78816040850160208701614f11565b601f01601f1916919091016040019291505056fea2646970667358221220d7f27dd06bc1246afa7333e6516528b8b3eee6e1c01e7d8b39a7398840e018d164736f6c63430008090033
Deployed Bytecode
0x608060405234801561001057600080fd5b506004361061048b5760003560e01c806385ab2c1311610262578063bfc2d46a11610151578063db74d8b5116100ce578063e85ba3e911610092578063e85ba3e914610ade578063eaf896fd14610b44578063ec571c6a14610b4c578063efdcd97414610b60578063f41759e714610b73578063f5d46c5114610b8657600080fd5b8063db74d8b514610a93578063dd0081c714610aa6578063e428877e14610aaf578063e5b5019a14610ac2578063e624c4bc14610acb57600080fd5b8063d35780b411610115578063d35780b414610a35578063d5f73f5c14610a48578063d7fd2bae14610a5b578063d9fbce8114610a7f578063daddcb161461060557600080fd5b8063bfc2d46a146109ef578063c3b6f93914610a02578063c47d51be14610a16578063ca5e553e14610a20578063cabccc7f1461060557600080fd5b8063a0c74afc116101df578063ad9e5649116101a3578063ad9e56491461090c578063b3f006741461091f578063bbae408614610933578063bc979af614610959578063bf115386146109c857600080fd5b8063a0c74afc146108c1578063a217fddf146108d4578063a3ece893146108dc578063a5125421146108e6578063a8f9a71d146108f957600080fd5b80638b53f75e116102265780638b53f75e14610866578063930b201214610879578063978ff560146108a05780639af40265146108af5780639b2cb5d8146108b757600080fd5b806385ab2c131461080757806388a6de681461081a578063897b06371461082d57806389cbaae6146108405780638a0ae6151461085357600080fd5b80633f4ba83a1161037e5780636254afb6116102fb57806373b7f873116102bf57806373b7f873146107bb57806373e9e01f146107ce578063769bc79c146107e25780637af5ca99146107f55780638456cb59146107ff57600080fd5b80636254afb61461074257806362b199c5146107565780636957463a1461077d5780636dc69e03146107905780637192de4b146107b157600080fd5b80635300b4ba116103425780635300b4ba146106de578063563b1dbf146107055780635ae2bfdb146107185780635b8bec55146107235780635c975abb1461073757600080fd5b80633f4ba83a14610676578063476abc761461067e57806349dc5e8d146106915780634a5971eb146106a45780634c20e9b9146106b757600080fd5b806327abf5181161040c5780633733337d116103d05780633733337d146106205780633807be7d146106335780633972183c1461064657806339dac34d146106505780633ccdbb281461066357600080fd5b806327abf518146105cc5780632c0a90a9146105df5780632d7788db146105f257806332b30cce1461060557806334c244891461060d57600080fd5b806315b9598a1161045357806315b9598a1461054b57806316683aa514610572578063191f3a3e146105875780631ed41163146105915780631fa1e8d4146105b857600080fd5b8063042da5ee146104905780630b5a57bd146104c9578063105ed2b2146104ec57806313007d55146104f957806315571a041461052a575b600080fd5b6104b461049e36600461467e565b61016b6020526000908152604090205460ff1681565b60405190151581526020015b60405180910390f35b6104b46104d736600461469b565b60976020526000908152604090205460ff1681565b60fc546104b49060ff1681565b600054610512906201000090046001600160a01b031681565b6040516001600160a01b0390911681526020016104c0565b61053d6105383660046146c5565b610b99565b6040519081526020016104c0565b61053d7f77c5b782690f31cd39b1abf2448215259a688a75920040c399d96a676bd1999d81565b61058561058036600461467e565b610c9d565b005b61053d6101a45481565b61053d7fd2576bd6a4c5558421de15cb8ecdf4eb3282aac06b94d4f004e8cd0d00f3ebd881565b61016554610512906001600160a01b031681565b6105856105da366004614715565b610d53565b6105856105ed366004614732565b610df8565b610585610600366004614754565b610e4f565b61053d610f57565b61058561061b366004614754565b610f66565b61058561062e36600461469b565b610fb4565b61058561064136600461469b565b611050565b61053d6101675481565b61058561065e36600461476d565b611110565b6105856106713660046146c5565b6111d7565b610585611252565b61058561068c36600461467e565b611267565b61058561069f36600461467e565b6112ca565b6105856106b23660046147d0565b611322565b61053d7f399c51febc66485c68c893eec57d25171ec297bcacececed07b76d2455734e2181565b61053d7f2fdc6683bc8d03effec5b41d3834f28bd219e06ca0a6a26fc737e44b1c7889ff81565b610585610713366004614754565b6113fe565b6101625461053d9081565b61020d54610512906001600160a01b031681565b60655460ff166104b4565b61016454610512906001600160a01b031681565b61053d7f548c7f0307ab2a7ea894e5c7e8c5353cc750bb9385ee2e945f189a9a83daa8ed81565b61058561078b366004614754565b611441565b61053d61079e366004614754565b6101686020526000908152604090205481565b61053d61016a5481565b6105856107c9366004614754565b6114c5565b6101a754610512906001600160a01b031681565b6105856107f0366004614754565b611513565b61053d6101a35481565b610585611556565b610585610815366004614879565b611569565b610585610828366004614732565b611667565b61058561083b366004614754565b6116b3565b61058561084e36600461467e565b6116f6565b6105856108613660046148c3565b6117b1565b6105856108743660046148ef565b611879565b61053d7fb81d2c6ada30c222c72e59cbb7f9918867981b6be5e0de70a02c28699231f04e81565b61053d670de0b6b3a764000081565b610512600081565b61053d61016f5481565b6105856108cf366004614970565b611951565b61053d600081565b61053d6101a55481565b6105856108f436600461467e565b61196d565b61058561090736600461467e565b611a2c565b61058561091a366004614754565b611a93565b61016954610512906001600160a01b031681565b7fd2576bd6a4c5558421de15cb8ecdf4eb3282aac06b94d4f004e8cd0d00f3ebd861053d565b61099c61096736600461467e565b61016e6020526000908152604090208054600182015460028301546003909301546001600160a01b0390921692909160ff1684565b604080516001600160a01b039095168552602085019390935291830152151560608201526080016104c0565b61053d7f7537f0610d8c5c0e3877e4eaf4bbfa46ce64756a4162f35656eb7046cfa8790681565b61053d6109fd3660046148c3565b611ae1565b61016354610512906001600160a01b031681565b61053d6101665481565b610a28611bc7565b6040516104c091906149b2565b610585610a433660046149ff565b611bd4565b61053d610a56366004614754565b611cfa565b6104b4610a6936600461467e565b6101706020526000908152604090205460ff1681565b61020c54610512906001600160a01b031681565b610585610aa13660046148c3565b611db1565b61053d61271081565b610585610abd36600461467e565b611e24565b61053d60001981565b610585610ad936600461467e565b611edc565b610b32610aec366004614754565b6101a660205260009081526040902080546001820154600283015460038401546004909401546001600160a01b039384169493831693600160a01b90930460ff16929086565b6040516104c096959493929190614ae6565b61053d611f97565b61012f54610512906001600160a01b031681565b610585610b6e36600461467e565b611fbb565b610585610b81366004614b3f565b61201e565b610585610b94366004614b9e565b612150565b60007f15571a04db30fd97c63b5be63c944e52a0a9a2af487d66beb3260a16c32f9bc2610bc4612206565b6001600160e01b0319811660009081526097602052604090205460ff1615610c075760405162461bcd60e51b8152600401610bfe90614bea565b60405180910390fd5b610c103361224c565b6001600160a01b0383163314610c2957610c298361224c565b600080610c398787600088612340565b8051604080516001600160a01b038a81168252602082018c9052818301939093529051939550919350891691339185917f691cd372bb63a5126a324513b634040d0ba3747c0a625207d99b6ba302c51a239181900360600190a45095945050505050565b610cae610ca8611f97565b336125c9565b6001600160a01b038116600090815261016b602052604090205460ff16610d075760405162461bcd60e51b815260206004820152600d60248201526c13558e881b9bdd08199bdd5b99609a1b6044820152606401610bfe565b6001600160a01b038116600081815261016b6020526040808220805460ff19169055513392917f57c4a95f59c12f0d4d846443c2d54c7d97f1505080199522fca2819e65213ca291a350565b610d5c33612697565b60fc5460ff1615158115151415610dae5760405162461bcd60e51b8152602060048201526016602482015275474c3a2073616d6520656e61626c652073746174757360501b6044820152606401610bfe565b60fc805460ff191682151590811790915560405190815233907fa8434267b880129bc4ba30249aa4a2ac349e8997c699282a9f70562f0f152f54906020015b60405180910390a250565b610e03610ca8611f97565b610e1082826000806126aa565b50817ff7d1fde87f32720fc30ce6847e0aae77e640b59bfac41b11b270358ccfa7a0ac82604051610e4391815260200190565b60405180910390a25050565b610e5a610ca8611f97565b60008181526101a660209081526040808320815160c08101835281546001600160a01b039081168252600183015490811694820194909452929091830190600160a01b900460ff166002811115610eb357610eb3614ad0565b6002811115610ec457610ec4614ad0565b815260200160028201548152602001600382015481526020016004820154815250509050610efa8160000151826040015161293a565b60008281526101a66020526040808220600101805460ff60a01b1916600160a11b179055825190516001600160a01b039091169184917ece63cc55966b103e4f4cb39f3426cb91718ad4f8eb4ad08c14a7ee749d81579190a35050565b6000610f61611f97565b905090565b610f71610ca8611f97565b610f7c8160016129e9565b61016a81905560405181815233907f018be394ba93a0dbca235443cfdc7173b2479180ad766083ce05199fbf3fc62490602001610ded565b610fbf610ca8610f57565b6001600160e01b0319811660009081526097602052604090205460ff1615610ff95760405162461bcd60e51b8152600401610bfe90614bea565b6001600160e01b03198116600081815260976020908152604091829020805460ff19166001179055905191825233917f2278e547293e53a66144c1743877f8388ac3101bd21cfd7c7f4ce8c15c14f5c19101610ded565b61105b610ca8610f57565b6001600160e01b0319811660009081526097602052604090205460ff166110bc5760405162461bcd60e51b815260206004820152601560248201527414185d5cd8589b194e88199b881d5b9c185d5cd959605a1b6044820152606401610bfe565b6001600160e01b03198116600081815260976020908152604091829020805460ff19169055905191825233917f929135cc6324f958693bb5f24a4dbc226a83c721523fc2785545019a3423b2d79101610ded565b61111b610ca8611f97565b6001600160a01b0382166000908152610170602052604090205460ff161515811515141561117e5760405162461bcd60e51b815260206004820152601060248201526f44563a20616c7265616479206672656560801b6044820152606401610bfe565b6001600160a01b03821660008181526101706020908152604091829020805460ff191685151590811790915591519182527f80f6f2f8801c6ac8fc60bf218b44fde97744d8709f69281972ec5557c10226cc9101610e43565b6111e2610ca8611f97565b6111f66001600160a01b0384168284612a69565b806001600160a01b0316836001600160a01b0316336001600160a01b03167f9ca7c1e047552a8048d924a5a8d3c150eb861086a72a9100e5f19d1176c1b7468560405161124591815260200190565b60405180910390a4505050565b61125d610ca8610f57565b611265612acc565b565b611272610ca8611f97565b61127d816001612b1e565b61016580546001600160a01b0319166001600160a01b03831690811790915560405133907fdb5a411e1a379f981ff6bc5284aa2c2522a9b8fd33a9db9ca19b34006cefbe9c90600090a350565b6112d5610ca8610f57565b61012f80546001600160a01b0319166001600160a01b03831690811790915560405133907f7f0c791852a03e270d4c2b78bbd4b959bca234de8d1ccf27eee03afaeafe63c490600090a350565b600054610100900460ff16158080156113425750600054600160ff909116105b8061135c5750303b15801561135c575060005460ff166001145b6113785760405162461bcd60e51b8152600401610bfe90614c17565b6000805460ff19166001179055801561139b576000805461ff0019166101001790555b6113ac8a8a8a8a8a8a8a8a8a612bb4565b80156113f2576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b50505050505050505050565b611409610ca8611f97565b6101a581905560405181815233907f72bae0b4c0979f93d77dce748bd8dfbc89d0f1cd524eee95367e3d2ce5eca93f90602001610ded565b61144c610ca8611f97565b6000811161148d5760405162461bcd60e51b815260206004820152600e60248201526d4d563a206c696d6974207a65726f60901b6044820152606401610bfe565b61016781905560405181815233907f5e8309fc6b2360e7438bc53790b00913395fffa870f39043fe63ddc8a438a9b290602001610ded565b6114d0610ca8611f97565b6114db8160006129e9565b6101a481905560405181815233907fa627d2a34207df740c6b90691350e2a762296cbf59affeb2282e6a54d631d4db90602001610ded565b61151e610ca8611f97565b6101a381905560405181815233907f8855fe6f9cbc4052017b3546fa14e167c5af2daad7f1c64db7f897fbcfb657b090602001610ded565b611561610ca8610f57565b611265612c43565b7f85ab2c1384c32949856b8251e03c48dafd9a1c9e9661d6ee6d38a46b7a508daa611592612206565b6001600160e01b0319811660009081526097602052604090205460ff16156115cc5760405162461bcd60e51b8152600401610bfe90614bea565b6115d53361224c565b6001600160a01b03821633146115ee576115ee8261224c565b6000806115fd87878787612c80565b8151604080516001600160a01b038981168252602082018c905291810192909252606082018390529294509092509088169033907f4fd0e2f3f27549d8d0c242f7193eaa0f61546e887fec39e69dfbff6b2384a4c39060800160405180910390a350505050505050565b611672610ca8611f97565b6116808282600160006126aa565b50817f03ea09e71742c9c754c9746b3e671ecb27fc372e3d29c31bac0192458ffd9d4b82604051610e4391815260200190565b6116be610ca8611f97565b61016f81905560405181815233907f57e764c1fef224e74706b109734513889970db6f1dde107b1bda66e10d80ca9b90602001610ded565b611701610ca8611f97565b61020c546001600160a01b03828116911614156117595760405162461bcd60e51b815260206004820152601660248201527526a92b299d1030b63932b0b23c90383937bb34b232b960511b6044820152606401610bfe565b611764816001612b1e565b61020c80546001600160a01b0319166001600160a01b03831690811790915560405133907fd081462190bc4f588c3e60685e37e27b800f5ac8b62c3edd7eecba5d1cecb9d590600090a350565b6117bc610ca8611f97565b6001600160a01b038216156117d4576117d482613057565b600081116118195760405162461bcd60e51b81526020600482015260126024820152714d563a207a65726f20616c6c6f77616e636560701b6044820152606401610bfe565b6001600160a01b038216600081815261016e602052604090819020600201839055513391907ff7273742887a46d8b97d83d1d12b6d8d8e6d21d814072369e2f4b355690221d79061186d9085815260200190565b60405180910390a35050565b7f8b53f75ebd6e3af54b2d42f7b3f6d41d997973b4f29dcd155e6a81f98c0f7d5a6118a2612206565b6001600160e01b0319811660009081526097602052604090205460ff16156118dc5760405162461bcd60e51b8152600401610bfe90614bea565b6118e53361224c565b6000806118f486868633612c80565b8151604080518981526020810192909252810182905291935091506001600160a01b0387169033907f1af12536d161c2c30ad907b0abe442f94c4a7824f2463585b3fc893275247cce9060600160405180910390a3505050505050565b600061195b6130a9565b9050611968838383612150565b505050565b611978610ca8611f97565b61198461016c82613108565b6119c15760405162461bcd60e51b815260206004820152600e60248201526d4d563a206e6f742065786973747360901b6044820152606401610bfe565b6001600160a01b038116600081815261016e602052604080822080546001600160a01b03191681556001810183905560028101839055600301805460ff19169055513392917f652fa2f5d587d3f1c189df0081b7bf3121f47d51d5471bf58d7d2c8a084894c391a350565b611a37610ca8611f97565b611a42816000612b1e565b6101a780546001600160a01b0319166001600160a01b03831690811790915560405190815233907f5059e224ac539671fe0261fc6672c365607aa98da29c849726ac5956902221b490602001610ded565b611a9e610ca8611f97565b611aa98160006129e9565b61016681905560405181815233907f45acc8bd6ebd6fbb59ce049b682c124aeccc93c468fcf60fecf61340e86e79d390602001610ded565b60007fbfc2d46a919432a5240e2d1b08da2f7ce0add499a19be62446ee561d32e12e22611b0c612206565b6001600160e01b0319811660009081526097602052604090205460ff1615611b465760405162461bcd60e51b8152600401610bfe90614bea565b611b4f3361224c565b600080611b5f8686600033612340565b91509150856001600160a01b0316336001600160a01b0316837f55ba94d231fa70a45e82b0a1c6a60ef72e41bb2455385128ee5cf8d98c0c1c0e888560000151604051611bb6929190918252602082015260400190565b60405180910390a450949350505050565b6060610f6161016c613126565b600054610100900460ff1615808015611bf45750600054600160ff909116105b80611c0e5750303b158015611c0e575060005460ff166001145b611c2a5760405162461bcd60e51b8152600401610bfe90614c17565b6000805460ff191660011790558015611c4d576000805461ff0019166101001790555b611c5e8c8c8c8c8c8c8c8c8c612bb4565b611c69836001612b1e565b611c74826000612b1e565b61020c80546001600160a01b038086166001600160a01b03199283161790925561020d8054928516929091169190911790558015611cec576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b505050505050505050505050565b600063357dcfd760e21b611d0c612206565b6001600160e01b0319811660009081526097602052604090205460ff1615611d465760405162461bcd60e51b8152600401610bfe90614bea565b611d4f3361224c565b600080611d60600086600133612340565b8051604080518981526020810192909252929450909250600091339185917f55ba94d231fa70a45e82b0a1c6a60ef72e41bb2455385128ee5cf8d98c0c1c0e910160405180910390a4509392505050565b611dbc610ca8611f97565b611dc582613057565b611dd08160006129e9565b6001600160a01b038216600081815261016e602052604090819020600101839055513391907f1582567d288d96695cf3fe7280c630a4f1c82fc7e665e1db58468f2960fef8699061186d9085815260200190565b611e2f610ca8611f97565b6001600160a01b038116600090815261016b602052604090205460ff1615611e8d5760405162461bcd60e51b815260206004820152601160248201527013558e88185b1c9958591e481859191959607a1b6044820152606401610bfe565b6001600160a01b038116600081815261016b6020526040808220805460ff19166001179055513392917f221f04b37331150bcfd05e2de362f50785c29ee4ab14f26d4495a51f3c02906091a350565b611ee7610ca8611f97565b61020d546001600160a01b0382811691161415611f3f5760405162461bcd60e51b815260206004820152601660248201527526a92b299d1030b63932b0b23c90383937bb34b232b960511b6044820152606401610bfe565b611f4a816000612b1e565b61020d80546001600160a01b0319166001600160a01b03831690811790915560405133907f96210ef89e9bcdbde362a89b05013b89c67c586c9de1243edbf07af800c5da1290600090a350565b7f399c51febc66485c68c893eec57d25171ec297bcacececed07b76d2455734e2190565b611fc6610ca8611f97565b611fd1816001612b1e565b61016980546001600160a01b0319166001600160a01b03831690811790915560405133907f1b092cca381ac00a07e1226c164f47c475d212f5e55699475a7f411811f77dd490600090a350565b612029610ca8611f97565b61203561016c8661313a565b6120755760405162461bcd60e51b815260206004820152601160248201527013558e88185b1c9958591e481859191959607a1b6044820152606401610bfe565b612080846000612b1e565b61208b8360006129e9565b604080516080810182526001600160a01b03868116808352602080840188815284860188815287151560608088018281528e8816600081815261016e88528b902099518a546001600160a01b0319169916989098178955935160018901559151600288015591516003909601805460ff19169615159690961790955585518981529182018890529481019490945292909133917f049000a9db89588d7bfb162bc0f7e4299ee8762430a468131c2caf0824f1f995910160405180910390a45050505050565b61215b610ca8611f97565b60005b8281101561220057600061218d85858481811061217d5761217d614c65565b90506020020135846001806126aa565b90508061219a57506121ee565b8484838181106121ac576121ac614c65565b905060200201357f03ea09e71742c9c754c9746b3e671ecb27fc372e3d29c31bac0192458ffd9d4b846040516121e491815260200190565b60405180910390a2505b806121f881614c91565b91505061215e565b50505050565b60655460ff16156112655760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610bfe565b60fc54819060ff1615612262576122628161314f565b8161226c81613175565b61012f5483906001600160a01b031680156123395760405163df592f7d60e01b81526001600160a01b03838116600483015282169063df592f7d9060240160206040518083038186803b1580156122c257600080fd5b505afa1580156122d6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122fa9190614cac565b156123395760405162461bcd60e51b815260206004820152600f60248201526e15d4d30e881cd85b98dd1a5bdb9959608a1b6044820152606401610bfe565b5050505050565b600061235f604051806040016040528060008152602001600081525090565b836123b1576001600160a01b0386166123b15760405162461bcd60e51b815260206004820152601460248201527314958e881d1bdad95b93dd5d080f4f48199a585d60621b6044820152606401610bfe565b336123c08188886000896131a1565b915086670de0b6b3a764000086612407576001600160a01b03808316600090815261016e602052604090208054600382015491926124039291169060ff16613399565b9150505b6101645460408051636369290560e01b815290516000926001600160a01b0316916363692905916004808301926020929190829003018186803b15801561244d57600080fd5b505afa158015612461573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124859190614cc9565b6101635460208701519192506124aa916001600160a01b039091169030906012613426565b508451156124d757610163546101695486516124d5926001600160a01b039081169216906012613426565b505b6101625495506124ec61016280546001019055565b6040805160c0810182526001600160a01b03808a1682528516602082015290810160008152602087810151818301526040808301859052606090920185905260008981526101a68252829020835181546001600160a01b039182166001600160a01b0319918216178355928501516001830180549190921693811684178255938501519193919290916001600160a81b03191617600160a01b83600281111561259757612597614ad0565b0217905550606082015160028201556080820151600382015560a0909101516004909101555050505094509492505050565b600054604051632474521560e21b8152600481018490526001600160a01b03838116602483015262010000909204909116906391d148549060440160206040518083038186803b15801561261c57600080fd5b505afa158015612630573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126549190614cac565b6126935760405162461bcd60e51b815260206004820152601060248201526f574d41433a206861736e7420726f6c6560801b6044820152606401610bfe565b5050565b61269f610f57565b8161196882826125c9565b60008481526101a660209081526040808320815160c08101835281546001600160a01b03908116825260018301549081169482019490945284939092830190600160a01b900460ff16600281111561270457612704614ad0565b600281111561271557612715614ad0565b81526020016002820154815260200160038201548152602001600482015481525050905061274b8160000151826040015161293a565b831561275f5761275f816080015186613471565b60208101516001600160a01b031615600081612787576127828360200151613504565b61278a565b60125b60ff16905060006127b98460a001518986606001516127a99190614ce2565b6127b39190614d01565b83613577565b90508261280c578580156127d957506127d784602001518284613587565b155b156127eb576000945050505050612932565b60208401516101a754855161280c92916001600160a01b0316908486613620565b61281a846020015182613673565b610163546060850151604051632770a7eb60e21b815230600482015260248101919091526001600160a01b0390911690639dc29fac90604401600060405180830381600087803b15801561286d57600080fd5b505af1158015612881573d6000803e3d6000fd5b505060016040878101828152608089018d905260008e81526101a66020908152929020895181546001600160a01b03199081166001600160a01b03928316178355938b0151948201805494851695909116948517815591518a96509094509290916001600160a81b03191617600160a01b83600281111561290457612904614ad0565b0217905550606082015160028201556080820151600382015560a09091015160049091015550600193505050505b949350505050565b6001600160a01b0382166129885760405162461bcd60e51b815260206004820152601560248201527414958e881c995c5d595cdd081b9bdd08195e1a5cdd605a1b6044820152606401610bfe565b600081600281111561299c5761299c614ad0565b146126935760405162461bcd60e51b815260206004820152601760248201527f52563a2072657175657374206e6f742070656e64696e670000000000000000006044820152606401610bfe565b612710821115612a285760405162461bcd60e51b815260206004820152600a602482015269666565203e203130302560b01b6044820152606401610bfe565b801561269357600082116126935760405162461bcd60e51b81526020600482015260086024820152670666565203d3d20360c41b6044820152606401610bfe565b6040516001600160a01b03831660248201526044810182905261196890849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915261371c565b612ad46137f1565b6065805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b6001600160a01b038216612b635760405162461bcd60e51b815260206004820152600c60248201526b7a65726f206164647265737360a01b6044820152606401610bfe565b8015612693576001600160a01b0382163014156126935760405162461bcd60e51b815260206004820152600f60248201526e696e76616c6964206164647265737360881b6044820152606401610bfe565b600054610100900460ff16612bdb5760405162461bcd60e51b8152600401610bfe90614d23565b612bea8989898989898961383a565b612bf6823560006129e9565b612c01816000612b1e565b60408201356101a35581356101a4556020909101356101a5556101a780546001600160a01b0319166001600160a01b0390921691909117905550505050505050565b612c4b612206565b6065805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258612b013390565b6040805180820190915260008082526020820152600033612ca58188886001866131a1565b92506000612cb288613504565b60ff169050868887600080612cc685613a12565b91509150600080612cd78487613a85565b91509150612cff81848d60200151612cef9190614ce2565b612cf99190614d01565b89613577565b9950848a1015612d515760405162461bcd60e51b815260206004820152601e60248201527f5256533a206d696e52656365697665416d6f756e74203e2061637475616c00006044820152606401610bfe565b8a5115612d7d5761016354610169548c51612d7b926001600160a01b039081169216906012613426565b505b6040516370a0823160e01b81523060048201526000906001600160a01b038816906370a082319060240160206040518083038186803b158015612dbf57600080fd5b505afa158015612dd3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612df79190614cc9565b9050612e0288613b65565b612e0c8784613673565b612e168b8a613bef565b8110612e8d576101635460208d0151604051632770a7eb60e21b81526001600160a01b038d811660048301526024820192909252911690639dc29fac90604401600060405180830381600087803b158015612e7057600080fd5b505af1158015612e84573d6000803e3d6000fd5b50505050613038565b6000612e9c8d60200151613bfd565b61020c546040805163c3b6f93960e01b81529051929350612f35926001600160a01b03909216918491839163c3b6f93991600480820192602092909190829003018186803b158015612eed57600080fd5b505afa158015612f01573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f259190614d6e565b6001600160a01b03169190613e5b565b61020c546040516345a9fbaf60e11b81526001600160a01b038a8116600483015260248201849052604482018a905290911690638b53f75e90606401600060405180830381600087803b158015612f8b57600080fd5b505af1158015612f9f573d6000803e3d6000fd5b50506040516370a0823160e01b8152306004820152600092506001600160a01b038b1691506370a082319060240160206040518083038186803b158015612fe557600080fd5b505afa158015612ff9573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061301d9190614cc9565b90506130338b61302d8584614d8b565b90613f17565b9c5050505b613044878e8d8c613f25565b5050505050505050505094509492505050565b61306361016c82613f6f565b6130a65760405162461bcd60e51b81526020600482015260146024820152734d563a20746f6b656e206e6f742065786973747360601b6044820152606401610bfe565b50565b610164546000906130c3906001600160a01b031682613399565b9050600081116131055760405162461bcd60e51b815260206004820152600d60248201526c52563a2072617465207a65726f60981b6044820152606401610bfe565b90565b600061311d836001600160a01b038416613f91565b90505b92915050565b6060600061313383614084565b9392505050565b600061311d836001600160a01b0384166140e0565b7fd2576bd6a4c5558421de15cb8ecdf4eb3282aac06b94d4f004e8cd0d00f3ebd861269f565b7f548c7f0307ab2a7ea894e5c7e8c5353cc750bb9385ee2e945f189a9a83daa8ed81611968828261412f565b6040805180820190915260008082526020820152600084116131fa5760405162461bcd60e51b815260206004820152601260248201527114958e881a5b9d985b1a5908185b5bdd5b9d60721b6044820152606401610bfe565b6001600160a01b0386166000908152610170602052604090205460ff166132775760008261322b5761016f54613230565b6101a3545b9050848111156132755760405162461bcd60e51b815260206004820152601060248201526f292b1d1030b6b7bab73a101e1036b4b760811b6044820152606401610bfe565b505b613293868686868661328a5760006141f8565b6101a4546141f8565b81528115613326576001600160a01b038516156132e95760405162461bcd60e51b815260206004820152601460248201527314958e881d1bdad95b93dd5d08084f48199a585d60621b6044820152606401610bfe565b6001600160a01b038616600090815261016b602052604090205460ff16613321576101a5548151829061331d908390614da2565b9052505b61332f565b61332f85613057565b8051841161337f5760405162461bcd60e51b815260206004820152601860248201527f52563a20616d6f756e744d546f6b656e496e203c2066656500000000000000006044820152606401610bfe565b805161338b9085614d8b565b602082015295945050505050565b600080836001600160a01b031663636929056040518163ffffffff1660e01b815260040160206040518083038186803b1580156133d557600080fd5b505afa1580156133e9573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061340d9190614cc9565b9050821561311d57670de0b6b3a7640000915050613120565b60006134328383613bef565b905061343e8183613f17565b831461345c5760405162461bcd60e51b8152600401610bfe90614dba565b6129326001600160a01b038616338684614299565b60008282101561348a576134858284614d8b565b613494565b6134948383614d8b565b90506000836134a561271084614ce2565b6134af9190614d01565b905061016a548111156122005760405162461bcd60e51b815260206004820152601a60248201527f4d563a2065786365656420707269636520646976696174696f6e0000000000006044820152606401610bfe565b6000816001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b15801561353f57600080fd5b505afa158015613553573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131209190614de8565b600061311d8261302d8582613bef565b6101a7546040516370a0823160e01b81526001600160a01b0391821660048201526000918291908616906370a082319060240160206040518083038186803b1580156135d257600080fd5b505afa1580156135e6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061360a9190614cc9565b90506136168484613bef565b1115949350505050565b600061362c8383613bef565b90506136388183613f17565b83146136565760405162461bcd60e51b8152600401610bfe90614dba565b61366b6001600160a01b038716868684614299565b505050505050565b6001600160a01b038216600090815261016e602052604090206002015460001981141561369f57505050565b818110156136e65760405162461bcd60e51b81526020600482015260146024820152734d563a2065786365656420616c6c6f77616e636560601b6044820152606401610bfe565b6001600160a01b038316600090815261016e602052604081206002018054849290613712908490614d8b565b9091555050505050565b6000613771826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166142d19092919063ffffffff16565b90508051600014806137925750808060200190518101906137929190614cac565b6119685760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610bfe565b60655460ff166112655760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610bfe565b600054610100900460ff166138615760405162461bcd60e51b8152600401610bfe90614d23565b613878613871602088018861467e565b6000612b1e565b61388b613871604088016020890161467e565b6138a261389b602087018761467e565b6001612b1e565b6138b561389b604087016020880161467e565b60008460200135116138f65760405162461bcd60e51b815260206004820152600a6024820152691e995c9bc81b1a5b5a5d60b21b6044820152606401610bfe565b6139018260016129e9565b61390d843560006129e9565b61391a602087018761467e565b61016380546001600160a01b0319166001600160a01b0392909216919091179055613944876142e0565b61394c614318565b613954614318565b61395d8361433f565b61396a602086018661467e565b61016580546001600160a01b0319166001600160a01b039290921691909117905561399b604086016020870161467e565b61016980546001600160a01b0319166001600160a01b03929092169190911790558335610166556020808501356101675561016f82905561016a8390556139e8906040880190880161467e565b61016480546001600160a01b0319166001600160a01b039290921691909117905550505050505050565b60008060008311613a575760405162461bcd60e51b815260206004820152600f60248201526e52563a20616d6f756e74207a65726f60881b6044820152606401610bfe565b613a5f6130a9565b9050670de0b6b3a7640000613a748285614ce2565b613a7e9190614d01565b9150915091565b60008060008411613aca5760405162461bcd60e51b815260206004820152600f60248201526e52563a20616d6f756e74207a65726f60881b6044820152606401610bfe565b6001600160a01b03808416600090815261016e60205260409020805460038201549192613afc9291169060ff16613399565b915060008211613b3e5760405162461bcd60e51b815260206004820152600d60248201526c52563a2072617465207a65726f60981b6044820152606401610bfe565b81613b5186670de0b6b3a7640000614ce2565b613b5b9190614d01565b9250509250929050565b6000613b746201518042614d01565b6000818152610168602052604081205491925090613b93908490614da2565b905061016754811115613bdb5760405162461bcd60e51b815260206004820152601060248201526f13558e88195e18d95959081b1a5b5a5d60821b6044820152606401610bfe565b600091825261016860205260409091205550565b600061311d83601284614389565b6101635461020d54600091613c21916001600160a01b039182169116846012613426565b5061020c546040805163312a57db60e11b815290516000926001600160a01b031691636254afb6916004808301926020929190829003018186803b158015613c6857600080fd5b505afa158015613c7c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ca09190614d6e565b6001600160a01b031663636929056040518163ffffffff1660e01b815260040160206040518083038186803b158015613cd857600080fd5b505afa158015613cec573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d109190614cc9565b9050600061016460009054906101000a90046001600160a01b03166001600160a01b031663636929056040518163ffffffff1660e01b815260040160206040518083038186803b158015613d6357600080fd5b505afa158015613d77573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d9b9190614cc9565b905081613da88286614ce2565b613db29190614d01565b9250613e5461020c60009054906101000a90046001600160a01b03166001600160a01b031663c3b6f9396040518163ffffffff1660e01b815260040160206040518083038186803b158015613e0657600080fd5b505afa158015613e1a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613e3e9190614d6e565b61020d546001600160a01b031630866012613620565b5050919050565b604051636eb1769f60e11b81523060048201526001600160a01b0383811660248301526000919085169063dd62ed3e9060440160206040518083038186803b158015613ea657600080fd5b505afa158015613eba573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ede9190614cc9565b90506122008463095ea7b360e01b85613ef78686614da2565b6040516001600160a01b0390921660248301526044820152606401612a95565b600061311d83836012614389565b6000613f318383613bef565b9050613f3d8183613f17565b8314613f5b5760405162461bcd60e51b8152600401610bfe90614dba565b6123396001600160a01b0386168583612a69565b6001600160a01b0381166000908152600183016020526040812054151561311d565b6000818152600183016020526040812054801561407a576000613fb5600183614d8b565b8554909150600090613fc990600190614d8b565b905081811461402e576000866000018281548110613fe957613fe9614c65565b906000526020600020015490508087600001848154811061400c5761400c614c65565b6000918252602080832090910192909255918252600188019052604090208390555b855486908061403f5761403f614e0b565b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050613120565b6000915050613120565b6060816000018054806020026020016040519081016040528092919081815260200182805480156140d457602002820191906000526020600020905b8154815260200190600101908083116140c0575b50505050509050919050565b600081815260018301602052604081205461412757508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155613120565b506000613120565b600054604051632474521560e21b8152600481018490526001600160a01b03838116602483015262010000909204909116906391d148549060440160206040518083038186803b15801561418257600080fd5b505afa158015614196573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906141ba9190614cac565b156126935760405162461bcd60e51b815260206004820152600e60248201526d574d41433a2068617320726f6c6560901b6044820152606401610bfe565b6001600160a01b038516600090815261016b602052604081205460ff161561422257506000614290565b60008261424c57506001600160a01b038516600090815261016e602052604090206001015461424f565b50815b831561426657610166546142639082614da2565b90505b61271081111561427557506127105b6127106142828287614ce2565b61428c9190614d01565b9150505b95945050505050565b6040516001600160a01b03808516602483015283166044820152606481018290526122009085906323b872dd60e01b90608401612a95565b606061293284846000856143f6565b600054610100900460ff166143075760405162461bcd60e51b8152600401610bfe90614d23565b61430f6144d1565b6130a681614500565b600054610100900460ff166112655760405162461bcd60e51b8152600401610bfe90614d23565b600054610100900460ff166143665760405162461bcd60e51b8152600401610bfe90614d23565b61012f80546001600160a01b0319166001600160a01b0392909216919091179055565b60008361439857506000613133565b818314156143a7575082613133565b6000828411156143d7576143bb8385614d8b565b6143c690600a614f05565b6143d09086614d01565b9050612932565b6143e18484614d8b565b6143ec90600a614f05565b6142909086614ce2565b6060824710156144575760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610bfe565b600080866001600160a01b031685876040516144739190614f3d565b60006040518083038185875af1925050503d80600081146144b0576040519150601f19603f3d011682016040523d82523d6000602084013e6144b5565b606091505b50915091506144c687838387614596565b979650505050505050565b600054610100900460ff166144f85760405162461bcd60e51b8152600401610bfe90614d23565b61126561460c565b600054610100900460ff166145275760405162461bcd60e51b8152600401610bfe90614d23565b6001600160a01b03811661456c5760405162461bcd60e51b815260206004820152600c60248201526b7a65726f206164647265737360a01b6044820152606401610bfe565b600080546001600160a01b03909216620100000262010000600160b01b0319909216919091179055565b606083156146025782516145fb576001600160a01b0385163b6145fb5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610bfe565b5081612932565b612932838361463f565b600054610100900460ff166146335760405162461bcd60e51b8152600401610bfe90614d23565b6065805460ff19169055565b81511561464f5781518083602001fd5b8060405162461bcd60e51b8152600401610bfe9190614f59565b6001600160a01b03811681146130a657600080fd5b60006020828403121561469057600080fd5b813561311d81614669565b6000602082840312156146ad57600080fd5b81356001600160e01b03198116811461311d57600080fd5b6000806000606084860312156146da57600080fd5b83356146e581614669565b92506020840135915060408401356146fc81614669565b809150509250925092565b80151581146130a657600080fd5b60006020828403121561472757600080fd5b813561311d81614707565b6000806040838503121561474557600080fd5b50508035926020909101359150565b60006020828403121561476657600080fd5b5035919050565b6000806040838503121561478057600080fd5b823561478b81614669565b9150602083013561479b81614707565b809150509250929050565b6000604082840312156147b857600080fd5b50919050565b6000606082840312156147b857600080fd5b60008060008060008060008060006101c08a8c0312156147ef57600080fd5b89356147fa81614669565b98506148098b60208c016147a6565b97506148188b60608c016147a6565b96506148278b60a08c016147a6565b955060e08a013561483781614669565b94506101008a013593506101208a013592506148578b6101408c016147be565b91506101a08a013561486881614669565b809150509295985092959850929598565b6000806000806080858703121561488f57600080fd5b843561489a81614669565b9350602085013592506040850135915060608501356148b881614669565b939692955090935050565b600080604083850312156148d657600080fd5b82356148e181614669565b946020939093013593505050565b60008060006060848603121561490457600080fd5b833561490f81614669565b95602085013595506040909401359392505050565b60008083601f84011261493657600080fd5b50813567ffffffffffffffff81111561494e57600080fd5b6020830191508360208260051b850101111561496957600080fd5b9250929050565b6000806020838503121561498357600080fd5b823567ffffffffffffffff81111561499a57600080fd5b6149a685828601614924565b90969095509350505050565b6020808252825182820181905260009190848201906040850190845b818110156149f35783516001600160a01b0316835292840192918401916001016149ce565b50909695505050505050565b60008060008060008060008060008060006102008c8e031215614a2157600080fd5b8b35614a2c81614669565b9a50614a3b8d60208e016147a6565b9950614a4a8d60608e016147a6565b9850614a598d60a08e016147a6565b975060e08c0135614a6981614669565b96506101008c013595506101208c01359450614a898d6101408e016147be565b93506101a08c0135614a9a81614669565b92506101c08c0135614aab81614669565b91506101e08c0135614abc81614669565b809150509295989b509295989b9093969950565b634e487b7160e01b600052602160045260246000fd5b6001600160a01b0387811682528616602082015260c0810160038610614b1c57634e487b7160e01b600052602160045260246000fd5b8560408301528460608301528360808301528260a0830152979650505050505050565b600080600080600060a08688031215614b5757600080fd5b8535614b6281614669565b94506020860135614b7281614669565b935060408601359250606086013591506080860135614b9081614707565b809150509295509295909350565b600080600060408486031215614bb357600080fd5b833567ffffffffffffffff811115614bca57600080fd5b614bd686828701614924565b909790965060209590950135949350505050565b60208082526013908201527214185d5cd8589b194e88199b881c185d5cd959606a1b604082015260600190565b6020808252602e908201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160408201526d191e481a5b9a5d1a585b1a5e995960921b606082015260800190565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b6000600019821415614ca557614ca5614c7b565b5060010190565b600060208284031215614cbe57600080fd5b815161311d81614707565b600060208284031215614cdb57600080fd5b5051919050565b6000816000190483118215151615614cfc57614cfc614c7b565b500290565b600082614d1e57634e487b7160e01b600052601260045260246000fd5b500490565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b600060208284031215614d8057600080fd5b815161311d81614669565b600082821015614d9d57614d9d614c7b565b500390565b60008219821115614db557614db5614c7b565b500190565b6020808252601490820152734d563a20696e76616c696420726f756e64696e6760601b604082015260600190565b600060208284031215614dfa57600080fd5b815160ff8116811461311d57600080fd5b634e487b7160e01b600052603160045260246000fd5b600181815b80851115614e5c578160001904821115614e4257614e42614c7b565b80851615614e4f57918102915b93841c9390800290614e26565b509250929050565b600082614e7357506001613120565b81614e8057506000613120565b8160018114614e965760028114614ea057614ebc565b6001915050613120565b60ff841115614eb157614eb1614c7b565b50506001821b613120565b5060208310610133831016604e8410600b8410161715614edf575081810a613120565b614ee98383614e21565b8060001904821115614efd57614efd614c7b565b029392505050565b600061311d8383614e64565b60005b83811015614f2c578181015183820152602001614f14565b838111156122005750506000910152565b60008251614f4f818460208701614f11565b9190910192915050565b6020815260008251806020840152614f78816040850160208701614f11565b601f01601f1916919091016040019291505056fea2646970667358221220d7f27dd06bc1246afa7333e6516528b8b3eee6e1c01e7d8b39a7398840e018d164736f6c63430008090033
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in ETH
0
Multichain Portfolio | 35 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.