Feature Tip: Add private address tag to any address under My Name Tag !
Source Code
Overview
ETH Balance
0 ETH
Eth Value
$0.00View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
Loading...
Loading
Cross-Chain Transactions
Loading...
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Contract Name:
RTokenP1
Compiler Version
v0.8.19+commit.7dd6d404
Optimization Enabled:
Yes with 200 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
// solhint-disable-next-line max-line-length
import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";
import "../interfaces/IMain.sol";
import "../interfaces/IRToken.sol";
import "../libraries/Fixed.sol";
import "../libraries/Throttle.sol";
import "../vendor/ERC20PermitUpgradeable.sol";
import "./mixins/Component.sol";
/**
* @title RTokenP1
* An ERC20 with an elastic supply and governable exchange rate to basket units.
*/
contract RTokenP1 is ComponentP1, ERC20PermitUpgradeable, IRToken {
using FixLib for uint192;
using ThrottleLib for ThrottleLib.Throttle;
using SafeERC20Upgradeable for IERC20Upgradeable;
uint256 public constant MIN_THROTTLE_RATE_AMT = 1e18; // {qRTok}
uint256 public constant MAX_THROTTLE_RATE_AMT = 1e48; // {qRTok}
uint192 public constant MAX_THROTTLE_PCT_AMT = 1e18; // {qRTok}
uint192 public constant MIN_EXCHANGE_RATE = 1e9; // D18{BU/rTok}
uint192 public constant MAX_EXCHANGE_RATE = 1e27; // D18{BU/rTok}
/// The mandate describes what goals its governors should try to achieve. By succinctly
/// explaining the RToken’s purpose and what the RToken is intended to do, it provides common
/// ground for the governors to decide upon priorities and how to weigh tradeoffs.
///
/// Example Mandates:
///
/// - Capital preservation first. Spending power preservation second. Permissionless
/// access third.
/// - Capital preservation above all else. All revenues fund the over-collateralization pool.
/// - Risk-neutral pursuit of profit for token holders.
/// Maximize (gross revenue - payments for over-collateralization and governance).
/// - This RToken holds only FooCoin, to provide a trade for hedging against its
/// possible collapse.
///
/// The mandate may also be a URI to a longer body of text, presumably on IPFS or some other
/// immutable data store.
string public mandate;
// ==== Peer components ====
IAssetRegistry private assetRegistry;
IBasketHandler private basketHandler;
IBackingManager private backingManager;
IFurnace private furnace;
// The number of baskets that backingManager must hold
// in order for this RToken to be fully collateralized.
// The exchange rate for issuance and redemption is totalSupply()/basketsNeeded {BU}/{qRTok}.
uint192 public basketsNeeded; // D18{BU}
// === Supply throttles ===
ThrottleLib.Throttle private issuanceThrottle;
ThrottleLib.Throttle private redemptionThrottle;
function init(
IMain main_,
string calldata name_,
string calldata symbol_,
string calldata mandate_,
ThrottleLib.Params calldata issuanceThrottleParams_,
ThrottleLib.Params calldata redemptionThrottleParams_
) external initializer {
require(bytes(name_).length != 0, "name empty");
require(bytes(symbol_).length != 0, "symbol empty");
require(bytes(mandate_).length != 0, "mandate empty");
__Component_init(main_);
__ERC20_init(name_, symbol_);
__ERC20Permit_init(name_);
assetRegistry = main_.assetRegistry();
basketHandler = main_.basketHandler();
backingManager = main_.backingManager();
furnace = main_.furnace();
mandate = mandate_;
setIssuanceThrottleParams(issuanceThrottleParams_);
setRedemptionThrottleParams(redemptionThrottleParams_);
issuanceThrottle.lastTimestamp = uint48(block.timestamp);
redemptionThrottle.lastTimestamp = uint48(block.timestamp);
}
/// Issue an RToken on the current basket
/// Do no use inifite approvals. Instead, use BasketHandler.quote() to determine the amount
/// of backing tokens to approve.
/// @param amount {qTok} The quantity of RToken to issue
/// @custom:interaction nearly CEI, but see comments around handling of refunds
function issue(uint256 amount) public {
issueTo(_msgSender(), amount);
}
/// Issue an RToken on the current basket, to a particular recipient
/// Do no use inifite approvals. Instead, use BasketHandler.quote() to determine the amount
/// of backing tokens to approve.
/// @param recipient The address to receive the issued RTokens
/// @param amount {qRTok} The quantity of RToken to issue
/// @custom:interaction RCEI
// BU exchange rate cannot decrease, and it can only increase when < FIX_ONE.
function issueTo(address recipient, uint256 amount) public notIssuancePausedOrFrozen {
require(amount != 0, "Cannot issue zero");
// == Refresh ==
assetRegistry.refresh();
// == Checks-effects block ==
address issuer = _msgSender(); // OK to save: it can't be changed in reentrant runs
// Ensure basket is ready, SOUND and not in warmup period
require(basketHandler.isReady(), "basket not ready");
uint256 supply = totalSupply();
// Revert if issuance exceeds either supply throttle
issuanceThrottle.useAvailable(supply, int256(amount)); // reverts on over-issuance
redemptionThrottle.useAvailable(supply, -int256(amount)); // shouldn't revert
// AT THIS POINT:
// all contract invariants hold
// furnace melting is up-to-date
// asset states are up-to-date
// throttle is up-to-date
// amtBaskets: the BU change to be recorded by this issuance
// D18{BU} = D18{BU} * {qRTok} / {qRTok}
// revert-on-overflow provided by FixLib functions
uint192 amtBaskets = supply != 0
? basketsNeeded.muluDivu(amount, supply, CEIL)
: _safeWrap(amount);
emit Issuance(issuer, recipient, amount, amtBaskets);
(address[] memory erc20s, uint256[] memory deposits) = basketHandler.quote(
amtBaskets,
CEIL
);
// == Interactions: Create RToken + transfer tokens to BackingManager ==
_scaleUp(recipient, amtBaskets, supply);
for (uint256 i = 0; i < erc20s.length; ++i) {
IERC20Upgradeable(erc20s[i]).safeTransferFrom(
issuer,
address(backingManager),
deposits[i]
);
}
}
/// Redeem RToken for basket collateral
/// @param amount {qTok} The quantity {qRToken} of RToken to redeem
/// @custom:interaction CEI
function redeem(uint256 amount) external {
redeemTo(_msgSender(), amount);
}
/// Redeem RToken for basket collateral to a particular recipient
// checks:
// amount > 0
// amount <= balanceOf(caller)
//
// effects:
// (so totalSupply -= amount and balanceOf(caller) -= amount)
// basketsNeeded' / totalSupply' >== basketsNeeded / totalSupply
// burn(caller, amount)
//
// actions:
// let erc20s = basketHandler.erc20s()
// for each token in erc20s:
// let tokenAmt = (amount * basketsNeeded / totalSupply) current baskets
// do token.transferFrom(backingManager, caller, tokenAmt)
// BU exchange rate cannot decrease, and it can only increase when < FIX_ONE.
/// @param recipient The address to receive the backing collateral tokens
/// @param amount {qRTok} The quantity {qRToken} of RToken to redeem
/// @custom:interaction RCEI
function redeemTo(address recipient, uint256 amount) public notFrozen {
// == Refresh ==
assetRegistry.refresh();
// == Checks and Effects ==
address caller = _msgSender();
require(amount != 0, "Cannot redeem zero");
require(amount <= balanceOf(caller), "insufficient balance");
require(basketHandler.fullyCollateralized(), "partial redemption; use redeemCustom");
// redemption while IFFY/DISABLED allowed
uint256 supply = totalSupply();
// Revert if redemption exceeds either supply throttle
issuanceThrottle.useAvailable(supply, -int256(amount));
redemptionThrottle.useAvailable(supply, int256(amount)); // reverts on over-redemption
// {BU}
uint192 baskets = _scaleDown(caller, amount);
emit Redemption(caller, recipient, amount, baskets);
(address[] memory erc20s, uint256[] memory amounts) = basketHandler.quote(baskets, FLOOR);
// === Interactions ===
for (uint256 i = 0; i < erc20s.length; ++i) {
if (amounts[i] == 0) continue;
// Send withdrawal
// slither-disable-next-line arbitrary-send-erc20
IERC20Upgradeable(erc20s[i]).safeTransferFrom(
address(backingManager),
recipient,
amounts[i]
);
}
}
/// Redeem RToken for a linear combination of historical baskets, to a particular recipient
// checks:
// amount > 0
// amount <= balanceOf(caller)
// sum(portions) == FIX_ONE
// nonce >= basketHandler.primeNonce() for nonce in basketNonces
//
// effects:
// (so totalSupply -= amount and balanceOf(caller) -= amount)
// basketsNeeded' / totalSupply' >== basketsNeeded / totalSupply
// burn(caller, amount)
//
// actions:
// for each token in erc20s:
// let tokenAmt = (amount * basketsNeeded / totalSupply) custom baskets
// let prorataAmt = (amount / totalSupply) * token.balanceOf(backingManager)
// do token.transferFrom(backingManager, caller, min(tokenAmt, prorataAmt))
// BU exchange rate cannot decrease, and it can only increase when < FIX_ONE.
/// @dev Allows partial redemptions up to the minAmounts
/// @param recipient The address to receive the backing collateral tokens
/// @param amount {qRTok} The quantity {qRToken} of RToken to redeem
/// @param basketNonces An array of basket nonces to do redemption from
/// @param portions {1} An array of Fix quantities that must add up to FIX_ONE
/// @param expectedERC20sOut An array of ERC20s expected out
/// @param minAmounts {qTok} The minimum ERC20 quantities the caller should receive
/// @custom:interaction RCEI
function redeemCustom(
address recipient,
uint256 amount,
uint48[] memory basketNonces,
uint192[] memory portions,
address[] memory expectedERC20sOut,
uint256[] memory minAmounts
) external notFrozen {
// == Refresh ==
assetRegistry.refresh();
// == Checks and Effects ==
require(amount != 0, "Cannot redeem zero");
require(amount <= balanceOf(_msgSender()), "insufficient balance");
uint256 portionsSum;
for (uint256 i = 0; i < portions.length; ++i) {
portionsSum += portions[i];
}
require(portionsSum == FIX_ONE, "portions do not add up to FIX_ONE");
uint256 supply = totalSupply();
// Revert if redemption exceeds either supply throttle
issuanceThrottle.useAvailable(supply, -int256(amount));
redemptionThrottle.useAvailable(supply, int256(amount)); // reverts on over-redemption
// {BU}
uint192 baskets = _scaleDown(_msgSender(), amount);
emit Redemption(_msgSender(), recipient, amount, baskets);
// === Get basket redemption amounts ===
(address[] memory erc20s, uint256[] memory amounts) = basketHandler.quoteCustomRedemption(
basketNonces,
portions,
baskets
);
// ==== Prorate redemption ====
// i.e, set amounts = min(amounts, balances * amount / totalSupply)
// where balances[i] = erc20s[i].balanceOf(backingManager)
// Bound each withdrawal by the prorata share, in case we're currently under-collateralized
for (uint256 i = 0; i < erc20s.length; ++i) {
// {qTok} = {qTok} * {qRTok} / {qRTok}
uint256 prorata = mulDiv256(
IERC20(erc20s[i]).balanceOf(address(backingManager)),
amount,
supply
); // FLOOR
if (prorata < amounts[i]) amounts[i] = prorata;
}
// === Save initial recipient balances ===
uint256[] memory pastBals = new uint256[](expectedERC20sOut.length);
for (uint256 i = 0; i < expectedERC20sOut.length; ++i) {
pastBals[i] = IERC20(expectedERC20sOut[i]).balanceOf(recipient);
// we haven't verified this ERC20 is registered but this is always a staticcall
}
// === Interactions ===
// Distribute tokens; revert if empty redemption
{
bool allZero = true;
for (uint256 i = 0; i < erc20s.length; ++i) {
if (amounts[i] == 0) continue; // unregistered ERC20s will have 0 amount
if (allZero) allZero = false;
// Send withdrawal
// slither-disable-next-line arbitrary-send-erc20
IERC20Upgradeable(erc20s[i]).safeTransferFrom(
address(backingManager),
recipient,
amounts[i]
);
}
if (allZero) revert("empty redemption");
}
// === Post-checks ===
// Check post-balances
for (uint256 i = 0; i < expectedERC20sOut.length; ++i) {
uint256 bal = IERC20(expectedERC20sOut[i]).balanceOf(recipient);
// we haven't verified this ERC20 is registered but this is always a staticcall
require(bal - pastBals[i] >= minAmounts[i], "redemption below minimum");
}
}
/// Mint an amount of RToken equivalent to baskets BUs, scaling basketsNeeded up
/// Callable only by BackingManager
/// @param baskets {BU} The number of baskets to mint RToken for
/// @custom:protected
// checks: caller is backingManager
// effects:
// bal'[recipient] = bal[recipient] + amtRToken
// totalSupply' = totalSupply + amtRToken
// basketsNeeded' = basketsNeeded + baskets
// BU exchange rate cannot decrease, and it can only increase when < FIX_ONE.
function mint(uint192 baskets) external {
require(_msgSender() == address(backingManager), "not backing manager");
_scaleUp(address(backingManager), baskets, totalSupply());
}
/// Melt a quantity of RToken from the caller's account, increasing the basket rate
/// @param amtRToken {qRTok} The amtRToken to be melted
/// @custom:protected
// checks: caller is furnace
// effects:
// bal'[caller] = bal[caller] - amtRToken
// totalSupply' = totalSupply - amtRToken
// BU exchange rate cannot decrease
// BU exchange rate CAN increase, but we already trust furnace to do this slowly
function melt(uint256 amtRToken) external {
address caller = _msgSender();
require(caller == address(furnace), "furnace only");
_burn(caller, amtRToken);
emit Melted(amtRToken);
}
/// Burn an amount of RToken from caller's account and scale basketsNeeded down
/// Callable only by backingManager
/// @param amount {qRTok}
/// @custom:protected
// checks: caller is backingManager
// effects:
// bal'[recipient] = bal[recipient] - amtRToken
// totalSupply' = totalSupply - amtRToken
// basketsNeeded' = basketsNeeded - baskets
// BU exchange rate cannot decrease, and it can only increase when < FIX_ONE.
function dissolve(uint256 amount) external {
address caller = _msgSender();
require(caller == address(backingManager), "not backing manager");
_scaleDown(caller, amount);
}
/// An affordance of last resort for Main in order to ensure re-capitalization
/// @custom:protected
// checks: caller is backingManager
// effects: basketsNeeded' = basketsNeeded_
function setBasketsNeeded(uint192 basketsNeeded_) external notTradingPausedOrFrozen {
require(_msgSender() == address(backingManager), "not backing manager");
emit BasketsNeededChanged(basketsNeeded, basketsNeeded_);
basketsNeeded = basketsNeeded_;
// == P0 exchangeRateIsValidAfter modifier ==
uint256 supply = totalSupply();
require(supply != 0, "0 supply");
// Note: These are D18s, even though they are uint256s. This is because
// we cannot assume we stay inside our valid range here, as that is what
// we are checking in the first place
uint256 low = (FIX_ONE_256 * basketsNeeded_) / supply; // D18{BU/rTok}
uint256 high = (FIX_ONE_256 * basketsNeeded_ + (supply - 1)) / supply; // D18{BU/rTok}
// here we take advantage of an implicit upcast from uint192 exchange rates
require(low >= MIN_EXCHANGE_RATE && high <= MAX_EXCHANGE_RATE, "BU rate out of range");
}
/// Sends all token balance of erc20 (if it is registered) to the BackingManager
/// @custom:interaction
function monetizeDonations(IERC20 erc20) external notTradingPausedOrFrozen {
require(assetRegistry.isRegistered(erc20), "erc20 unregistered");
IERC20Upgradeable(address(erc20)).safeTransfer(
address(backingManager),
erc20.balanceOf(address(this))
);
}
// ==== Throttle setters/getters ====
/// @return {qRTok} The maximum issuance that can be performed in the current block
function issuanceAvailable() external view returns (uint256) {
return issuanceThrottle.currentlyAvailable(issuanceThrottle.hourlyLimit(totalSupply()));
}
/// @return available {qRTok} The maximum redemption that can be performed in the current block
function redemptionAvailable() external view returns (uint256 available) {
uint256 supply = totalSupply();
available = redemptionThrottle.currentlyAvailable(redemptionThrottle.hourlyLimit(supply));
if (supply < available) available = supply;
}
/// @return The issuance throttle parametrization
function issuanceThrottleParams() external view returns (ThrottleLib.Params memory) {
return issuanceThrottle.params;
}
/// @return The redemption throttle parametrization
function redemptionThrottleParams() external view returns (ThrottleLib.Params memory) {
return redemptionThrottle.params;
}
/// @custom:governance
function setIssuanceThrottleParams(ThrottleLib.Params calldata params) public governance {
require(params.amtRate >= MIN_THROTTLE_RATE_AMT, "issuance amtRate too small");
require(params.amtRate <= MAX_THROTTLE_RATE_AMT, "issuance amtRate too big");
require(params.pctRate <= MAX_THROTTLE_PCT_AMT, "issuance pctRate too big");
issuanceThrottle.useAvailable(totalSupply(), 0);
emit IssuanceThrottleSet(issuanceThrottle.params, params);
issuanceThrottle.params = params;
}
/// @custom:governance
function setRedemptionThrottleParams(ThrottleLib.Params calldata params) public governance {
require(params.amtRate >= MIN_THROTTLE_RATE_AMT, "redemption amtRate too small");
require(params.amtRate <= MAX_THROTTLE_RATE_AMT, "redemption amtRate too big");
require(params.pctRate <= MAX_THROTTLE_PCT_AMT, "redemption pctRate too big");
redemptionThrottle.useAvailable(totalSupply(), 0);
emit RedemptionThrottleSet(redemptionThrottle.params, params);
redemptionThrottle.params = params;
}
// ==== Private ====
/// Mint an amount of RToken equivalent to amtBaskets and scale basketsNeeded up
/// @param recipient The address to receive the RTokens
/// @param amtBaskets {BU} The number of amtBaskets to mint RToken for
/// @param totalSupply {qRTok} The current totalSupply
// effects:
// bal'[recipient] = bal[recipient] + amtRToken
// totalSupply' = totalSupply + amtRToken
// basketsNeeded' = basketsNeeded + amtBaskets
// BU exchange rate cannot decrease, and it can only increase when < FIX_ONE.
function _scaleUp(
address recipient,
uint192 amtBaskets,
uint256 totalSupply
) private {
// take advantage of 18 decimals during casting
uint256 amtRToken = totalSupply != 0
? amtBaskets.muluDivu(totalSupply, basketsNeeded) // {rTok} = {BU} * {qRTok} * {qRTok}
: amtBaskets; // {rTok}
emit BasketsNeededChanged(basketsNeeded, basketsNeeded + amtBaskets);
basketsNeeded += amtBaskets;
// Mint RToken to recipient
_mint(recipient, amtRToken);
}
/// Burn an amount of RToken and scale basketsNeeded down
/// @param account The address to dissolve RTokens from
/// @param amtRToken {qRTok} The amount of RToken to be dissolved
/// @return amtBaskets {BU} The equivalent number of baskets dissolved
// effects:
// bal'[recipient] = bal[recipient] - amtRToken
// totalSupply' = totalSupply - amtRToken
// basketsNeeded' = basketsNeeded - amtBaskets
// BU exchange rate cannot decrease, and it can only increase when < FIX_ONE.
function _scaleDown(address account, uint256 amtRToken) private returns (uint192 amtBaskets) {
// D18{BU} = D18{BU} * {qRTok} / {qRTok}
amtBaskets = basketsNeeded.muluDivu(amtRToken, totalSupply()); // FLOOR
emit BasketsNeededChanged(basketsNeeded, basketsNeeded - amtBaskets);
basketsNeeded -= amtBaskets;
// Burn RToken from account; reverts if not enough balance
_burn(account, amtRToken);
}
/**
* @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.
*/
function _beforeTokenTransfer(
address,
address to,
uint256
) internal virtual override {
require(to != address(this), "RToken transfer to self");
}
/**
* @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
*
* RToken uses 56 slots, not 50.
*/
uint256[42] private __gap;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface AggregatorV3Interface {
function decimals() external view returns (uint8);
function description() external view returns (string memory);
function version() external view returns (uint256);
function getRoundData(uint80 _roundId)
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
);
function latestRoundData()
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts 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.5.0) (interfaces/draft-IERC1822.sol)
pragma solidity ^0.8.0;
/**
* @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified
* proxy whose upgrades are fully controlled by the current implementation.
*/
interface IERC1822ProxiableUpgradeable {
/**
* @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation
* address.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy.
*/
function proxiableUUID() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (interfaces/IERC1271.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC1271 standard signature validation method for
* contracts as defined in https://eips.ethereum.org/EIPS/eip-1271[ERC-1271].
*
* _Available since v4.1._
*/
interface IERC1271Upgradeable {
/**
* @dev Should return whether the signature provided is valid for the provided data
* @param hash Hash of the data to be signed
* @param signature Signature byte array associated with _data
*/
function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC1967.sol)
pragma solidity ^0.8.0;
/**
* @dev ERC-1967: Proxy Storage Slots. This interface contains the events defined in the ERC.
*
* _Available since v4.8.3._
*/
interface IERC1967Upgradeable {
/**
* @dev Emitted when the implementation is upgraded.
*/
event Upgraded(address indexed implementation);
/**
* @dev Emitted when the admin account has changed.
*/
event AdminChanged(address previousAdmin, address newAdmin);
/**
* @dev Emitted when the beacon is changed.
*/
event BeaconUpgraded(address indexed beacon);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC5267.sol)
pragma solidity ^0.8.0;
interface IERC5267Upgradeable {
/**
* @dev MAY be emitted to signal that the domain could have changed.
*/
event EIP712DomainChanged();
/**
* @dev returns the fields and values that describe the domain separator used by this contract for EIP-712
* signature.
*/
function eip712Domain()
external
view
returns (
bytes1 fields,
string memory name,
string memory version,
uint256 chainId,
address verifyingContract,
bytes32 salt,
uint256[] memory extensions
);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol)
pragma solidity ^0.8.0;
/**
* @dev This is the interface that {BeaconProxy} expects of its beacon.
*/
interface IBeaconUpgradeable {
/**
* @dev Must return an address that can be used as a delegate call target.
*
* {BeaconProxy} will check that this address is a contract.
*/
function implementation() external view returns (address);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/ERC1967/ERC1967Upgrade.sol)
pragma solidity ^0.8.2;
import "../beacon/IBeaconUpgradeable.sol";
import "../../interfaces/IERC1967Upgradeable.sol";
import "../../interfaces/draft-IERC1822Upgradeable.sol";
import "../../utils/AddressUpgradeable.sol";
import "../../utils/StorageSlotUpgradeable.sol";
import {Initializable} from "../utils/Initializable.sol";
/**
* @dev This abstract contract provides getters and event emitting update functions for
* https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.
*
* _Available since v4.1._
*/
abstract contract ERC1967UpgradeUpgradeable is Initializable, IERC1967Upgradeable {
// This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1
bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143;
/**
* @dev Storage slot with the address of the current implementation.
* This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is
* validated in the constructor.
*/
bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
function __ERC1967Upgrade_init() internal onlyInitializing {
}
function __ERC1967Upgrade_init_unchained() internal onlyInitializing {
}
/**
* @dev Returns the current implementation address.
*/
function _getImplementation() internal view returns (address) {
return StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value;
}
/**
* @dev Stores a new address in the EIP1967 implementation slot.
*/
function _setImplementation(address newImplementation) private {
require(AddressUpgradeable.isContract(newImplementation), "ERC1967: new implementation is not a contract");
StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
}
/**
* @dev Perform implementation upgrade
*
* Emits an {Upgraded} event.
*/
function _upgradeTo(address newImplementation) internal {
_setImplementation(newImplementation);
emit Upgraded(newImplementation);
}
/**
* @dev Perform implementation upgrade with additional setup call.
*
* Emits an {Upgraded} event.
*/
function _upgradeToAndCall(address newImplementation, bytes memory data, bool forceCall) internal {
_upgradeTo(newImplementation);
if (data.length > 0 || forceCall) {
AddressUpgradeable.functionDelegateCall(newImplementation, data);
}
}
/**
* @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call.
*
* Emits an {Upgraded} event.
*/
function _upgradeToAndCallUUPS(address newImplementation, bytes memory data, bool forceCall) internal {
// Upgrades from old implementations will perform a rollback test. This test requires the new
// implementation to upgrade back to the old, non-ERC1822 compliant, implementation. Removing
// this special case will break upgrade paths from old UUPS implementation to new ones.
if (StorageSlotUpgradeable.getBooleanSlot(_ROLLBACK_SLOT).value) {
_setImplementation(newImplementation);
} else {
try IERC1822ProxiableUpgradeable(newImplementation).proxiableUUID() returns (bytes32 slot) {
require(slot == _IMPLEMENTATION_SLOT, "ERC1967Upgrade: unsupported proxiableUUID");
} catch {
revert("ERC1967Upgrade: new implementation is not UUPS");
}
_upgradeToAndCall(newImplementation, data, forceCall);
}
}
/**
* @dev Storage slot with the admin of the contract.
* This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is
* validated in the constructor.
*/
bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
/**
* @dev Returns the current admin.
*/
function _getAdmin() internal view returns (address) {
return StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value;
}
/**
* @dev Stores a new address in the EIP1967 admin slot.
*/
function _setAdmin(address newAdmin) private {
require(newAdmin != address(0), "ERC1967: new admin is the zero address");
StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value = newAdmin;
}
/**
* @dev Changes the admin of the proxy.
*
* Emits an {AdminChanged} event.
*/
function _changeAdmin(address newAdmin) internal {
emit AdminChanged(_getAdmin(), newAdmin);
_setAdmin(newAdmin);
}
/**
* @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
* This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor.
*/
bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;
/**
* @dev Returns the current beacon.
*/
function _getBeacon() internal view returns (address) {
return StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value;
}
/**
* @dev Stores a new beacon in the EIP1967 beacon slot.
*/
function _setBeacon(address newBeacon) private {
require(AddressUpgradeable.isContract(newBeacon), "ERC1967: new beacon is not a contract");
require(
AddressUpgradeable.isContract(IBeaconUpgradeable(newBeacon).implementation()),
"ERC1967: beacon implementation is not a contract"
);
StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value = newBeacon;
}
/**
* @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does
* not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that).
*
* Emits a {BeaconUpgraded} event.
*/
function _upgradeBeaconToAndCall(address newBeacon, bytes memory data, bool forceCall) internal {
_setBeacon(newBeacon);
emit BeaconUpgraded(newBeacon);
if (data.length > 0 || forceCall) {
AddressUpgradeable.functionDelegateCall(IBeaconUpgradeable(newBeacon).implementation(), 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 (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.9.0) (proxy/utils/UUPSUpgradeable.sol)
pragma solidity ^0.8.0;
import "../../interfaces/draft-IERC1822Upgradeable.sol";
import "../ERC1967/ERC1967UpgradeUpgradeable.sol";
import {Initializable} from "./Initializable.sol";
/**
* @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an
* {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.
*
* A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is
* reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing
* `UUPSUpgradeable` with a custom implementation of upgrades.
*
* The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
*
* _Available since v4.1._
*/
abstract contract UUPSUpgradeable is Initializable, IERC1822ProxiableUpgradeable, ERC1967UpgradeUpgradeable {
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment
address private immutable __self = address(this);
/**
* @dev Check that the execution is being performed through a delegatecall call and that the execution context is
* a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case
* for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a
* function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to
* fail.
*/
modifier onlyProxy() {
require(address(this) != __self, "Function must be called through delegatecall");
require(_getImplementation() == __self, "Function must be called through active proxy");
_;
}
/**
* @dev Check that the execution is not being performed through a delegate call. This allows a function to be
* callable on the implementing contract but not through proxies.
*/
modifier notDelegated() {
require(address(this) == __self, "UUPSUpgradeable: must not be called through delegatecall");
_;
}
function __UUPSUpgradeable_init() internal onlyInitializing {
}
function __UUPSUpgradeable_init_unchained() internal onlyInitializing {
}
/**
* @dev Implementation of the ERC1822 {proxiableUUID} function. This returns the storage slot used by the
* implementation. It is used to validate the implementation's compatibility when performing an upgrade.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.
*/
function proxiableUUID() external view virtual override notDelegated returns (bytes32) {
return _IMPLEMENTATION_SLOT;
}
/**
* @dev Upgrade the implementation of the proxy to `newImplementation`.
*
* Calls {_authorizeUpgrade}.
*
* Emits an {Upgraded} event.
*
* @custom:oz-upgrades-unsafe-allow-reachable delegatecall
*/
function upgradeTo(address newImplementation) public virtual onlyProxy {
_authorizeUpgrade(newImplementation);
_upgradeToAndCallUUPS(newImplementation, new bytes(0), false);
}
/**
* @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
* encoded in `data`.
*
* Calls {_authorizeUpgrade}.
*
* Emits an {Upgraded} event.
*
* @custom:oz-upgrades-unsafe-allow-reachable delegatecall
*/
function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual onlyProxy {
_authorizeUpgrade(newImplementation);
_upgradeToAndCallUUPS(newImplementation, data, true);
}
/**
* @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
* {upgradeTo} and {upgradeToAndCall}.
*
* Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
*
* ```solidity
* function _authorizeUpgrade(address) internal override onlyOwner {}
* ```
*/
function _authorizeUpgrade(address newImplementation) internal virtual;
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[50] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (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 {Initializable} from "../../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/draft-IERC20Permit.sol) pragma solidity ^0.8.0; // EIP-2612 is Final as of 2022-11-01. This file is deprecated. import "./IERC20PermitUpgradeable.sol";
// 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.4) (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.
*
* ==== Security Considerations
*
* There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
* expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
* considered as an intention to spend the allowance in any specific way. The second is that because permits have
* built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
* take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
* generally recommended is:
*
* ```solidity
* function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
* try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
* doThing(..., value);
* }
*
* function doThing(..., uint256 value) public {
* token.safeTransferFrom(msg.sender, address(this), value);
* ...
* }
* ```
*
* Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
* `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
* {SafeERC20-safeTransferFrom}).
*
* Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
* contracts should have entry points that don't rely on permit.
*/
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].
*
* CAUTION: See Security Considerations above.
*/
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.3) (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. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*/
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 (last updated v4.9.4) (utils/Context.sol)
pragma solidity ^0.8.0;
import {Initializable} from "../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;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
/**
* @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/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 CountersUpgradeable {
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 // OpenZeppelin Contracts (last updated v4.8.0) (utils/cryptography/draft-EIP712.sol) pragma solidity ^0.8.0; // EIP-712 is Final as of 2022-08-11. This file is deprecated. import "./EIP712Upgradeable.sol";
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/cryptography/ECDSA.sol)
pragma solidity ^0.8.0;
import "../StringsUpgradeable.sol";
/**
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
*
* These functions can be used to verify that a message was signed by the holder
* of the private keys of a given address.
*/
library ECDSAUpgradeable {
enum RecoverError {
NoError,
InvalidSignature,
InvalidSignatureLength,
InvalidSignatureS,
InvalidSignatureV // Deprecated in v4.8
}
function _throwError(RecoverError error) private pure {
if (error == RecoverError.NoError) {
return; // no error: do nothing
} else if (error == RecoverError.InvalidSignature) {
revert("ECDSA: invalid signature");
} else if (error == RecoverError.InvalidSignatureLength) {
revert("ECDSA: invalid signature length");
} else if (error == RecoverError.InvalidSignatureS) {
revert("ECDSA: invalid signature 's' value");
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature` or error string. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*
* Documentation for signature generation:
* - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
* - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
*
* _Available since v4.3._
*/
function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
/// @solidity memory-safe-assembly
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
return tryRecover(hash, v, r, s);
} else {
return (address(0), RecoverError.InvalidSignatureLength);
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature`. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*/
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, signature);
_throwError(error);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
*
* See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
*
* _Available since v4.3._
*/
function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError) {
bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
uint8 v = uint8((uint256(vs) >> 255) + 27);
return tryRecover(hash, v, r, s);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
*
* _Available since v4.2._
*/
function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, r, vs);
_throwError(error);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `v`,
* `r` and `s` signature fields separately.
*
* _Available since v4.3._
*/
function tryRecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address, RecoverError) {
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
// the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
// signatures from current libraries generate a unique signature with an s-value in the lower half order.
//
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
// these malleable signatures as well.
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
return (address(0), RecoverError.InvalidSignatureS);
}
// If the signature is valid (and not malleable), return the signer address
address signer = ecrecover(hash, v, r, s);
if (signer == address(0)) {
return (address(0), RecoverError.InvalidSignature);
}
return (signer, RecoverError.NoError);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, v, r, s);
_throwError(error);
return recovered;
}
/**
* @dev Returns an Ethereum Signed Message, created from a `hash`. This
* produces hash corresponding to the one signed with the
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
* JSON-RPC method as part of EIP-191.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32 message) {
// 32 is the length in bytes of hash,
// enforced by the type signature above
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, "\x19Ethereum Signed Message:\n32")
mstore(0x1c, hash)
message := keccak256(0x00, 0x3c)
}
}
/**
* @dev Returns an Ethereum Signed Message, created from `s`. This
* produces hash corresponding to the one signed with the
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
* JSON-RPC method as part of EIP-191.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", StringsUpgradeable.toString(s.length), s));
}
/**
* @dev Returns an Ethereum Signed Typed Data, created from a
* `domainSeparator` and a `structHash`. This produces hash corresponding
* to the one signed with the
* https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
* JSON-RPC method as part of EIP-712.
*
* See {recover}.
*/
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 data) {
/// @solidity memory-safe-assembly
assembly {
let ptr := mload(0x40)
mstore(ptr, "\x19\x01")
mstore(add(ptr, 0x02), domainSeparator)
mstore(add(ptr, 0x22), structHash)
data := keccak256(ptr, 0x42)
}
}
/**
* @dev Returns an Ethereum Signed Data with intended validator, created from a
* `validator` and `data` according to the version 0 of EIP-191.
*
* See {recover}.
*/
function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19\x00", validator, data));
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/cryptography/EIP712.sol)
pragma solidity ^0.8.8;
import "./ECDSAUpgradeable.sol";
import "../../interfaces/IERC5267Upgradeable.sol";
import {Initializable} from "../../proxy/utils/Initializable.sol";
/**
* @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.
*
* The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible,
* thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding
* they need in their contracts using a combination of `abi.encode` and `keccak256`.
*
* This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding
* scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA
* ({_hashTypedDataV4}).
*
* The implementation of the domain separator was designed to be as efficient as possible while still properly updating
* the chain id to protect against replay attacks on an eventual fork of the chain.
*
* NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method
* https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].
*
* NOTE: In the upgradeable version of this contract, the cached values will correspond to the address, and the domain
* separator of the implementation contract. This will cause the `_domainSeparatorV4` function to always rebuild the
* separator from the immutable values, which is cheaper than accessing a cached version in cold storage.
*
* _Available since v3.4._
*
* @custom:storage-size 52
*/
abstract contract EIP712Upgradeable is Initializable, IERC5267Upgradeable {
bytes32 private constant _TYPE_HASH =
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
/// @custom:oz-renamed-from _HASHED_NAME
bytes32 private _hashedName;
/// @custom:oz-renamed-from _HASHED_VERSION
bytes32 private _hashedVersion;
string private _name;
string private _version;
/**
* @dev Initializes the domain separator and parameter caches.
*
* The meaning of `name` and `version` is specified in
* https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]:
*
* - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.
* - `version`: the current major version of the signing domain.
*
* NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
* contract upgrade].
*/
function __EIP712_init(string memory name, string memory version) internal onlyInitializing {
__EIP712_init_unchained(name, version);
}
function __EIP712_init_unchained(string memory name, string memory version) internal onlyInitializing {
_name = name;
_version = version;
// Reset prior values in storage if upgrading
_hashedName = 0;
_hashedVersion = 0;
}
/**
* @dev Returns the domain separator for the current chain.
*/
function _domainSeparatorV4() internal view returns (bytes32) {
return _buildDomainSeparator();
}
function _buildDomainSeparator() private view returns (bytes32) {
return keccak256(abi.encode(_TYPE_HASH, _EIP712NameHash(), _EIP712VersionHash(), block.chainid, address(this)));
}
/**
* @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this
* function returns the hash of the fully encoded EIP712 message for this domain.
*
* This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:
*
* ```solidity
* bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(
* keccak256("Mail(address to,string contents)"),
* mailTo,
* keccak256(bytes(mailContents))
* )));
* address signer = ECDSA.recover(digest, signature);
* ```
*/
function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {
return ECDSAUpgradeable.toTypedDataHash(_domainSeparatorV4(), structHash);
}
/**
* @dev See {EIP-5267}.
*
* _Available since v4.9._
*/
function eip712Domain()
public
view
virtual
override
returns (
bytes1 fields,
string memory name,
string memory version,
uint256 chainId,
address verifyingContract,
bytes32 salt,
uint256[] memory extensions
)
{
// If the hashed name and version in storage are non-zero, the contract hasn't been properly initialized
// and the EIP712 domain is not reliable, as it will be missing name and version.
require(_hashedName == 0 && _hashedVersion == 0, "EIP712: Uninitialized");
return (
hex"0f", // 01111
_EIP712Name(),
_EIP712Version(),
block.chainid,
address(this),
bytes32(0),
new uint256[](0)
);
}
/**
* @dev The name parameter for the EIP712 domain.
*
* NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs
* are a concern.
*/
function _EIP712Name() internal virtual view returns (string memory) {
return _name;
}
/**
* @dev The version parameter for the EIP712 domain.
*
* NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs
* are a concern.
*/
function _EIP712Version() internal virtual view returns (string memory) {
return _version;
}
/**
* @dev The hash of the name parameter for the EIP712 domain.
*
* NOTE: In previous versions this function was virtual. In this version you should override `_EIP712Name` instead.
*/
function _EIP712NameHash() internal view returns (bytes32) {
string memory name = _EIP712Name();
if (bytes(name).length > 0) {
return keccak256(bytes(name));
} else {
// If the name is empty, the contract may have been upgraded without initializing the new storage.
// We return the name hash in storage if non-zero, otherwise we assume the name is empty by design.
bytes32 hashedName = _hashedName;
if (hashedName != 0) {
return hashedName;
} else {
return keccak256("");
}
}
}
/**
* @dev The hash of the version parameter for the EIP712 domain.
*
* NOTE: In previous versions this function was virtual. In this version you should override `_EIP712Version` instead.
*/
function _EIP712VersionHash() internal view returns (bytes32) {
string memory version = _EIP712Version();
if (bytes(version).length > 0) {
return keccak256(bytes(version));
} else {
// If the version is empty, the contract may have been upgraded without initializing the new storage.
// We return the version hash in storage if non-zero, otherwise we assume the version is empty by design.
bytes32 hashedVersion = _hashedVersion;
if (hashedVersion != 0) {
return hashedVersion;
} else {
return keccak256("");
}
}
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[48] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/cryptography/SignatureChecker.sol)
pragma solidity ^0.8.0;
import "./ECDSAUpgradeable.sol";
import "../../interfaces/IERC1271Upgradeable.sol";
/**
* @dev Signature verification helper that can be used instead of `ECDSA.recover` to seamlessly support both ECDSA
* signatures from externally owned accounts (EOAs) as well as ERC1271 signatures from smart contract wallets like
* Argent and Gnosis Safe.
*
* _Available since v4.1._
*/
library SignatureCheckerUpgradeable {
/**
* @dev Checks if a signature is valid for a given signer and data hash. If the signer is a smart contract, the
* signature is validated against that smart contract using ERC1271, otherwise it's validated using `ECDSA.recover`.
*
* NOTE: Unlike ECDSA signatures, contract signatures are revocable, and the outcome of this function can thus
* change through time. It could return true at block N and false at block N+1 (or the opposite).
*/
function isValidSignatureNow(address signer, bytes32 hash, bytes memory signature) internal view returns (bool) {
(address recovered, ECDSAUpgradeable.RecoverError error) = ECDSAUpgradeable.tryRecover(hash, signature);
return
(error == ECDSAUpgradeable.RecoverError.NoError && recovered == signer) ||
isValidERC1271SignatureNow(signer, hash, signature);
}
/**
* @dev Checks if a signature is valid for a given signer and data hash. The signature is validated
* against the signer smart contract using ERC1271.
*
* NOTE: Unlike ECDSA signatures, contract signatures are revocable, and the outcome of this function can thus
* change through time. It could return true at block N and false at block N+1 (or the opposite).
*/
function isValidERC1271SignatureNow(
address signer,
bytes32 hash,
bytes memory signature
) internal view returns (bool) {
(bool success, bytes memory result) = signer.staticcall(
abi.encodeWithSelector(IERC1271Upgradeable.isValidSignature.selector, hash, signature)
);
return (success &&
result.length >= 32 &&
abi.decode(result, (bytes32)) == bytes32(IERC1271Upgradeable.isValidSignature.selector));
}
}// 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/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.
pragma solidity ^0.8.0;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC1967 implementation slot:
* ```solidity
* contract ERC1967 {
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*
* _Available since v4.1 for `address`, `bool`, `bytes32`, `uint256`._
* _Available since v4.9 for `string`, `bytes`._
*/
library StorageSlotUpgradeable {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
struct StringSlot {
string value;
}
struct BytesSlot {
bytes value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` with member `value` located at `slot`.
*/
function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` representation of the string storage pointer `store`.
*/
function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}
/**
* @dev Returns an `BytesSlot` with member `value` located at `slot`.
*/
function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
*/
function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}
}// 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 v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 amount) external returns (bool);
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "../libraries/Fixed.sol";
import "./IMain.sol";
import "./IRewardable.sol";
// Not used directly in the IAsset interface, but used by many consumers to save stack space
struct Price {
uint192 low; // {UoA/tok}
uint192 high; // {UoA/tok}
}
/**
* @title IAsset
* @notice Supertype. Any token that interacts with our system must be wrapped in an asset,
* whether it is used as RToken backing or not. Any token that can report a price in the UoA
* is eligible to be an asset.
*/
interface IAsset is IRewardable {
/// Refresh saved price
/// The Reserve protocol calls this at least once per transaction, before relying on
/// the Asset's other functions.
/// @dev Called immediately after deployment, before use
function refresh() external;
/// Should not revert
/// low should be nonzero if the asset could be worth selling
/// @return low {UoA/tok} The lower end of the price estimate
/// @return high {UoA/tok} The upper end of the price estimate
function price() external view returns (uint192 low, uint192 high);
/// Should not revert
/// lotLow should be nonzero when the asset might be worth selling
/// @dev Deprecated. Phased out in 3.1.0, but left on interface for backwards compatibility
/// @return lotLow {UoA/tok} The lower end of the lot price estimate
/// @return lotHigh {UoA/tok} The upper end of the lot price estimate
function lotPrice() external view returns (uint192 lotLow, uint192 lotHigh);
/// @return {tok} The balance of the ERC20 in whole tokens
function bal(address account) external view returns (uint192);
/// @return The ERC20 contract of the token with decimals() available
function erc20() external view returns (IERC20Metadata);
/// @return The number of decimals in the ERC20; just for gas optimization
function erc20Decimals() external view returns (uint8);
/// @return If the asset is an instance of ICollateral or not
function isCollateral() external view returns (bool);
/// @return {UoA} The max trade volume, in UoA
function maxTradeVolume() external view returns (uint192);
/// @return {s} The timestamp of the last refresh() that saved prices
function lastSave() external view returns (uint48);
}
// Used only in Testing. Strictly speaking an Asset does not need to adhere to this interface
interface TestIAsset is IAsset {
/// @return The address of the chainlink feed
function chainlinkFeed() external view returns (AggregatorV3Interface);
/// {1} The max % deviation allowed by the oracle
function oracleError() external view returns (uint192);
/// @return {s} Seconds that an oracle value is considered valid
function oracleTimeout() external view returns (uint48);
/// @return {s} The maximum of all oracle timeouts on the plugin
function maxOracleTimeout() external view returns (uint48);
/// @return {s} Seconds that the price() should decay over, after stale price
function priceTimeout() external view returns (uint48);
/// @return {UoA/tok} The last saved low price
function savedLowPrice() external view returns (uint192);
/// @return {UoA/tok} The last saved high price
function savedHighPrice() external view returns (uint192);
}
/// CollateralStatus must obey a linear ordering. That is:
/// - being DISABLED is worse than being IFFY, or SOUND
/// - being IFFY is worse than being SOUND.
enum CollateralStatus {
SOUND,
IFFY, // When a peg is not holding or a chainlink feed is stale
DISABLED // When the collateral has completely defaulted
}
/// Upgrade-safe maximum operator for CollateralStatus
library CollateralStatusComparator {
/// @return Whether a is worse than b
function worseThan(CollateralStatus a, CollateralStatus b) internal pure returns (bool) {
return uint256(a) > uint256(b);
}
}
/**
* @title ICollateral
* @notice A subtype of Asset that consists of the tokens eligible to back the RToken.
*/
interface ICollateral is IAsset {
/// Emitted whenever the collateral status is changed
/// @param newStatus The old CollateralStatus
/// @param newStatus The updated CollateralStatus
event CollateralStatusChanged(
CollateralStatus indexed oldStatus,
CollateralStatus indexed newStatus
);
/// @dev refresh()
/// Refresh exchange rates and update default status.
/// VERY IMPORTANT: In any valid implemntation, status() MUST become DISABLED in refresh() if
/// refPerTok() has ever decreased since last call.
/// @return The canonical name of this collateral's target unit.
function targetName() external view returns (bytes32);
/// @return The status of this collateral asset. (Is it defaulting? Might it soon?)
function status() external view returns (CollateralStatus);
// ==== Exchange Rates ====
/// @return {ref/tok} Quantity of whole reference units per whole collateral tokens
function refPerTok() external view returns (uint192);
/// @return {target/ref} Quantity of whole target units per whole reference unit in the peg
function targetPerRef() external view returns (uint192);
}
// Used only in Testing. Strictly speaking a Collateral does not need to adhere to this interface
interface TestICollateral is TestIAsset, ICollateral {
/// @return The epoch timestamp when the collateral will default from IFFY to DISABLED
function whenDefault() external view returns (uint256);
/// @return The amount of time a collateral must be in IFFY status until being DISABLED
function delayUntilDefault() external view returns (uint48);
/// @return The underlying refPerTok, likely not included in all collaterals however.
function underlyingRefPerTok() external view returns (uint192);
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "./IAsset.sol";
import "./IComponent.sol";
/// A serialization of the AssetRegistry to be passed around in the P1 impl for gas optimization
struct Registry {
IERC20[] erc20s;
IAsset[] assets;
}
/**
* @title IAssetRegistry
* @notice The AssetRegistry is in charge of maintaining the ERC20 tokens eligible
* to be handled by the rest of the system. If an asset is in the registry, this means:
* 1. Its ERC20 contract has been vetted
* 2. The asset is the only asset for that ERC20
* 3. The asset can be priced in the UoA, usually via an oracle
*/
interface IAssetRegistry is IComponent {
/// Emitted when an asset is added to the registry
/// @param erc20 The ERC20 contract for the asset
/// @param asset The asset contract added to the registry
event AssetRegistered(IERC20 indexed erc20, IAsset indexed asset);
/// Emitted when an asset is removed from the registry
/// @param erc20 The ERC20 contract for the asset
/// @param asset The asset contract removed from the registry
event AssetUnregistered(IERC20 indexed erc20, IAsset indexed asset);
// Initialization
function init(IMain main_, IAsset[] memory assets_) external;
/// Fully refresh all asset state
/// @custom:refresher
function refresh() external;
/// Register `asset`
/// If either the erc20 address or the asset was already registered, fail
/// @return true if the erc20 address was not already registered.
/// @custom:governance
function register(IAsset asset) external returns (bool);
/// Register `asset` if and only if its erc20 address is already registered.
/// If the erc20 address was not registered, revert.
/// @return swapped If the asset was swapped for a previously-registered asset
/// @custom:governance
function swapRegistered(IAsset asset) external returns (bool swapped);
/// Unregister an asset, requiring that it is already registered
/// @custom:governance
function unregister(IAsset asset) external;
/// @return {s} The timestamp of the last refresh
function lastRefresh() external view returns (uint48);
/// @return The corresponding asset for ERC20, or reverts if not registered
function toAsset(IERC20 erc20) external view returns (IAsset);
/// @return The corresponding collateral, or reverts if unregistered or not collateral
function toColl(IERC20 erc20) external view returns (ICollateral);
/// @return If the ERC20 is registered
function isRegistered(IERC20 erc20) external view returns (bool);
/// @return A list of all registered ERC20s
function erc20s() external view returns (IERC20[] memory);
/// @return reg The list of registered ERC20s and Assets, in the same order
function getRegistry() external view returns (Registry memory reg);
/// @return The number of registered ERC20s
function size() external view returns (uint256);
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "./IAssetRegistry.sol";
import "./IBasketHandler.sol";
import "./IComponent.sol";
import "./IRToken.sol";
import "./IStRSR.sol";
import "./ITrading.sol";
/// Memory struct for RecollateralizationLibP1 + RTokenAsset
/// Struct purposes:
/// 1. Configure trading
/// 2. Stay under stack limit with fewer vars
/// 3. Cache information such as component addresses and basket quantities, to save on gas
struct TradingContext {
BasketRange basketsHeld; // {BU}
// basketsHeld.top is the number of partial baskets units held
// basketsHeld.bottom is the number of full basket units held
// Components
IBasketHandler bh;
IAssetRegistry ar;
IStRSR stRSR;
IERC20 rsr;
IRToken rToken;
// Gov Vars
uint192 minTradeVolume; // {UoA}
uint192 maxTradeSlippage; // {1}
// Cached values
uint192[] quantities; // {tok/BU} basket quantities
uint192[] bals; // {tok} balances in BackingManager + out on trades
}
/**
* @title IBackingManager
* @notice The BackingManager handles changes in the ERC20 balances that back an RToken.
* - It computes which trades to perform, if any, and initiates these trades with the Broker.
* - rebalance()
* - If already collateralized, excess assets are transferred to RevenueTraders.
* - forwardRevenue(IERC20[] calldata erc20s)
*/
interface IBackingManager is IComponent, ITrading {
/// Emitted when the trading delay is changed
/// @param oldVal The old trading delay
/// @param newVal The new trading delay
event TradingDelaySet(uint48 oldVal, uint48 newVal);
/// Emitted when the backing buffer is changed
/// @param oldVal The old backing buffer
/// @param newVal The new backing buffer
event BackingBufferSet(uint192 oldVal, uint192 newVal);
// Initialization
function init(
IMain main_,
uint48 tradingDelay_,
uint192 backingBuffer_,
uint192 maxTradeSlippage_,
uint192 minTradeVolume_
) external;
// Give RToken max allowance over a registered token
/// @custom:refresher
/// @custom:interaction
function grantRTokenAllowance(IERC20) external;
/// Apply the overall backing policy using the specified TradeKind, taking a haircut if unable
/// @param kind TradeKind.DUTCH_AUCTION or TradeKind.BATCH_AUCTION
/// @custom:interaction RCEI
function rebalance(TradeKind kind) external;
/// Forward revenue to RevenueTraders; reverts if not fully collateralized
/// @param erc20s The tokens to forward
/// @custom:interaction RCEI
function forwardRevenue(IERC20[] calldata erc20s) external;
/// Structs for trading
/// @param basketsHeld The number of baskets held by the BackingManager
/// @return ctx The TradingContext
/// @return reg Contents of AssetRegistry.getRegistry()
function tradingContext(BasketRange memory basketsHeld)
external
view
returns (TradingContext memory ctx, Registry memory reg);
}
interface TestIBackingManager is IBackingManager, TestITrading {
function tradingDelay() external view returns (uint48);
function backingBuffer() external view returns (uint192);
function setTradingDelay(uint48 val) external;
function setBackingBuffer(uint192 val) external;
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "../libraries/Fixed.sol";
import "./IAsset.sol";
import "./IComponent.sol";
struct BasketRange {
uint192 bottom; // {BU}
uint192 top; // {BU}
}
/**
* @title IBasketHandler
* @notice The BasketHandler aims to maintain a reference basket of constant target unit amounts.
* When a collateral token defaults, a new reference basket of equal target units is set.
* When _all_ collateral tokens default for a target unit, only then is the basket allowed to fall
* in terms of target unit amounts. The basket is considered defaulted in this case.
*/
interface IBasketHandler is IComponent {
/// Emitted when the prime basket is set
/// @param erc20s The collateral tokens for the prime basket
/// @param targetAmts {target/BU} A list of quantities of target unit per basket unit
/// @param targetNames Each collateral token's targetName
event PrimeBasketSet(IERC20[] erc20s, uint192[] targetAmts, bytes32[] targetNames);
/// Emitted when the reference basket is set
/// @param nonce {basketNonce} The basket nonce
/// @param erc20s The list of collateral tokens in the reference basket
/// @param refAmts {ref/BU} The reference amounts of the basket collateral tokens
/// @param disabled True when the list of erc20s + refAmts may not be correct
event BasketSet(uint256 indexed nonce, IERC20[] erc20s, uint192[] refAmts, bool disabled);
/// Emitted when a backup config is set for a target unit
/// @param targetName The name of the target unit as a bytes32
/// @param max The max number to use from `erc20s`
/// @param erc20s The set of backup collateral tokens
event BackupConfigSet(bytes32 indexed targetName, uint256 max, IERC20[] erc20s);
/// Emitted when the warmup period is changed
/// @param oldVal The old warmup period
/// @param newVal The new warmup period
event WarmupPeriodSet(uint48 oldVal, uint48 newVal);
/// Emitted when the status of a basket has changed
/// @param oldStatus The previous basket status
/// @param newStatus The new basket status
event BasketStatusChanged(CollateralStatus oldStatus, CollateralStatus newStatus);
/// Emitted when the last basket nonce available for redemption is changed
/// @param oldVal The old value of lastCollateralized
/// @param newVal The new value of lastCollateralized
event LastCollateralizedChanged(uint48 oldVal, uint48 newVal);
// Initialization
function init(
IMain main_,
uint48 warmupPeriod_,
bool reweightable_
) external;
/// Set the prime basket
/// For an index RToken (reweightable = true), use forceSetPrimeBasket to skip normalization
/// @param erc20s The collateral tokens for the new prime basket
/// @param targetAmts The target amounts (in) {target/BU} for the new prime basket
/// required range: 1e9 values; absolute range irrelevant.
/// @custom:governance
function setPrimeBasket(IERC20[] calldata erc20s, uint192[] calldata targetAmts) external;
/// Set the prime basket without normalizing targetAmts by the UoA of the current basket
/// Works the same as setPrimeBasket for non-index RTokens (reweightable = false)
/// @param erc20s The collateral tokens for the new prime basket
/// @param targetAmts The target amounts (in) {target/BU} for the new prime basket
/// required range: 1e9 values; absolute range irrelevant.
/// @custom:governance
function forceSetPrimeBasket(IERC20[] calldata erc20s, uint192[] calldata targetAmts) external;
/// Set the backup configuration for a given target
/// @param targetName The name of the target as a bytes32
/// @param max The maximum number of collateral tokens to use from this target
/// Required range: 1-255
/// @param erc20s A list of ordered backup collateral tokens
/// @custom:governance
function setBackupConfig(
bytes32 targetName,
uint256 max,
IERC20[] calldata erc20s
) external;
/// Default the basket in order to schedule a basket refresh
/// @custom:protected
function disableBasket() external;
/// Governance-controlled setter to cause a basket switch explicitly
/// @custom:governance
/// @custom:interaction
function refreshBasket() external;
/// Track basket status and collateralization changes
/// @custom:refresher
function trackStatus() external;
/// @return If the BackingManager has sufficient collateral to redeem the entire RToken supply
function fullyCollateralized() external view returns (bool);
/// @return status The worst CollateralStatus of all collateral in the basket
function status() external view returns (CollateralStatus status);
/// @return If the basket is ready to issue and trade
function isReady() external view returns (bool);
/// @param erc20 The ERC20 token contract for the asset
/// @return {tok/BU} The whole token quantity of token in the reference basket
/// Returns 0 if erc20 is not registered or not in the basket
/// Returns FIX_MAX (in lieu of +infinity) if Collateral.refPerTok() is 0.
/// Otherwise, returns (token's basket.refAmts / token's Collateral.refPerTok())
function quantity(IERC20 erc20) external view returns (uint192);
/// Like quantity(), but unsafe because it DOES NOT CONFIRM THAT THE ASSET IS CORRECT
/// @param erc20 The ERC20 token contract for the asset
/// @param asset The registered asset plugin contract for the erc20
/// @return {tok/BU} The whole token quantity of token in the reference basket
/// Returns 0 if erc20 is not registered or not in the basket
/// Returns FIX_MAX (in lieu of +infinity) if Collateral.refPerTok() is 0.
/// Otherwise, returns (token's basket.refAmts / token's Collateral.refPerTok())
function quantityUnsafe(IERC20 erc20, IAsset asset) external view returns (uint192);
/// @param amount {BU}
/// @return erc20s The addresses of the ERC20 tokens in the reference basket
/// @return quantities {qTok} The quantity of each ERC20 token to issue `amount` baskets
function quote(uint192 amount, RoundingMode rounding)
external
view
returns (address[] memory erc20s, uint256[] memory quantities);
/// Return the redemption value of `amount` BUs for a linear combination of historical baskets
/// @param basketNonces An array of basket nonces to do redemption from
/// @param portions {1} An array of Fix quantities that must add up to FIX_ONE
/// @param amount {BU}
/// @return erc20s The backing collateral erc20s
/// @return quantities {qTok} ERC20 token quantities equal to `amount` BUs
function quoteCustomRedemption(
uint48[] memory basketNonces,
uint192[] memory portions,
uint192 amount
) external view returns (address[] memory erc20s, uint256[] memory quantities);
/// @return top {BU} The number of partial basket units: e.g max(coll.map((c) => c.balAsBUs())
/// bottom {BU} The number of whole basket units held by the account
function basketsHeldBy(address account) external view returns (BasketRange memory);
/// Should not revert
/// low should be nonzero when BUs are worth selling
/// @return low {UoA/BU} The lower end of the price estimate
/// @return high {UoA/BU} The upper end of the price estimate
function price() external view returns (uint192 low, uint192 high);
/// Should not revert
/// lotLow should be nonzero if a BU could be worth selling
/// @dev Deprecated. Phased out in 3.1.0, but left on interface for backwards compatibility
/// @return lotLow {UoA/tok} The lower end of the lot price estimate
/// @return lotHigh {UoA/tok} The upper end of the lot price estimate
function lotPrice() external view returns (uint192 lotLow, uint192 lotHigh);
/// @return timestamp The timestamp at which the basket was last set
function timestamp() external view returns (uint48);
/// @return The current basket nonce, regardless of status
function nonce() external view returns (uint48);
}
interface TestIBasketHandler is IBasketHandler {
function lastCollateralized() external view returns (uint48);
function warmupPeriod() external view returns (uint48);
function setWarmupPeriod(uint48 val) external;
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "./IAsset.sol";
import "./IComponent.sol";
import "./IGnosis.sol";
import "./ITrade.sol";
enum TradeKind {
DUTCH_AUCTION,
BATCH_AUCTION
}
/// Cache of all prices for a pair to prevent re-lookup
struct TradePrices {
uint192 sellLow; // {UoA/sellTok} can be 0
uint192 sellHigh; // {UoA/sellTok} should not be 0
uint192 buyLow; // {UoA/buyTok} should not be 0
uint192 buyHigh; // {UoA/buyTok} should not be 0 or FIX_MAX
}
/// The data format that describes a request for trade with the Broker
struct TradeRequest {
IAsset sell;
IAsset buy;
uint256 sellAmount; // {qSellTok}
uint256 minBuyAmount; // {qBuyTok}
}
/**
* @title IBroker
* @notice The Broker deploys oneshot Trade contracts for Traders and monitors
* the continued proper functioning of trading platforms.
*/
interface IBroker is IComponent {
event GnosisSet(IGnosis oldVal, IGnosis newVal);
event BatchTradeImplementationSet(ITrade oldVal, ITrade newVal);
event DutchTradeImplementationSet(ITrade oldVal, ITrade newVal);
event BatchAuctionLengthSet(uint48 oldVal, uint48 newVal);
event DutchAuctionLengthSet(uint48 oldVal, uint48 newVal);
event BatchTradeDisabledSet(bool prevVal, bool newVal);
event DutchTradeDisabledSet(IERC20Metadata indexed erc20, bool prevVal, bool newVal);
// Initialization
function init(
IMain main_,
IGnosis gnosis_,
ITrade batchTradeImplemention_,
uint48 batchAuctionLength_,
ITrade dutchTradeImplemention_,
uint48 dutchAuctionLength_
) external;
/// Request a trade from the broker
/// @dev Requires setting an allowance in advance
/// @custom:interaction
function openTrade(
TradeKind kind,
TradeRequest memory req,
TradePrices memory prices
) external returns (ITrade);
/// Only callable by one of the trading contracts the broker deploys
function reportViolation() external;
function batchTradeDisabled() external view returns (bool);
function dutchTradeDisabled(IERC20Metadata erc20) external view returns (bool);
}
interface TestIBroker is IBroker {
function gnosis() external view returns (IGnosis);
function batchTradeImplementation() external view returns (ITrade);
function dutchTradeImplementation() external view returns (ITrade);
function batchAuctionLength() external view returns (uint48);
function dutchAuctionLength() external view returns (uint48);
function setGnosis(IGnosis newGnosis) external;
function setBatchTradeImplementation(ITrade newTradeImplementation) external;
function setBatchAuctionLength(uint48 newAuctionLength) external;
function setDutchTradeImplementation(ITrade newTradeImplementation) external;
function setDutchAuctionLength(uint48 newAuctionLength) external;
function enableBatchTrade() external;
function enableDutchTrade(IERC20Metadata erc20) external;
// only present on pre-3.0.0 Brokers; used by EasyAuction regression test
function disabled() external view returns (bool);
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "./IMain.sol";
import "./IVersioned.sol";
/**
* @title IComponent
* @notice A Component is the central building block of all our system contracts. Components
* contain important state that must be migrated during upgrades, and they delegate
* their ownership to Main's owner.
*/
interface IComponent is IVersioned {
function main() external view returns (IMain);
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "./IComponent.sol";
uint256 constant MAX_DISTRIBUTION = 1e4; // 10,000
uint8 constant MAX_DESTINATIONS = 100; // maximum number of RevenueShare destinations
struct RevenueShare {
uint16 rTokenDist; // {revShare} A value between [0, 10,000]
uint16 rsrDist; // {revShare} A value between [0, 10,000]
}
/// Assumes no more than 100 independent distributions.
struct RevenueTotals {
uint24 rTokenTotal; // {revShare}
uint24 rsrTotal; // {revShare}
}
/**
* @title IDistributor
* @notice The Distributor Component maintains a revenue distribution table that dictates
* how to divide revenue across the Furnace, StRSR, and any other destinations.
*/
interface IDistributor is IComponent {
/// Emitted when a distribution is set
/// @param dest The address set to receive the distribution
/// @param rTokenDist The distribution of RToken that should go to `dest`
/// @param rsrDist The distribution of RSR that should go to `dest`
event DistributionSet(address indexed dest, uint16 rTokenDist, uint16 rsrDist);
/// Emitted when revenue is distributed
/// @param erc20 The token being distributed, either RSR or the RToken itself
/// @param source The address providing the revenue
/// @param amount The amount of the revenue
event RevenueDistributed(IERC20 indexed erc20, address indexed source, uint256 amount);
// Initialization
function init(IMain main_, RevenueShare memory dist) external;
/// @custom:governance
function setDistribution(address dest, RevenueShare memory share) external;
/// Distribute the `erc20` token across all revenue destinations
/// Only callable by RevenueTraders
/// @custom:protected
function distribute(IERC20 erc20, uint256 amount) external;
/// @return revTotals The total of all destinations
function totals() external view returns (RevenueTotals memory revTotals);
}
interface TestIDistributor is IDistributor {
// solhint-disable-next-line func-name-mixedcase
function FURNACE() external view returns (address);
// solhint-disable-next-line func-name-mixedcase
function ST_RSR() external view returns (address);
/// @return rTokenDist The RToken distribution for the address
/// @return rsrDist The RSR distribution for the address
function distribution(address) external view returns (uint16 rTokenDist, uint16 rsrDist);
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "../libraries/Fixed.sol";
import "./IComponent.sol";
/**
* @title IFurnace
* @notice A helper contract to burn RTokens slowly and permisionlessly.
*/
interface IFurnace is IComponent {
// Initialization
function init(IMain main_, uint192 ratio_) external;
/// Emitted when the melting ratio is changed
/// @param oldRatio The old ratio
/// @param newRatio The new ratio
event RatioSet(uint192 oldRatio, uint192 newRatio);
function ratio() external view returns (uint192);
/// Needed value range: [0, 1], granularity 1e-9
/// @custom:governance
function setRatio(uint192) external;
/// Performs any RToken melting that has vested since the last payout.
/// @custom:refresher
function melt() external;
}
interface TestIFurnace is IFurnace {
function lastPayout() external view returns (uint256);
function lastPayoutBal() external view returns (uint256);
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
struct GnosisAuctionData {
IERC20 auctioningToken;
IERC20 biddingToken;
uint256 orderCancellationEndDate;
uint256 auctionEndDate;
bytes32 initialAuctionOrder;
uint256 minimumBiddingAmountPerOrder;
uint256 interimSumBidAmount;
bytes32 interimOrder;
bytes32 clearingPriceOrder;
uint96 volumeClearingPriceOrder;
bool minFundingThresholdNotReached;
bool isAtomicClosureAllowed;
uint256 feeNumerator;
uint256 minFundingThreshold;
}
/// The relevant portion of the interface of the live Gnosis EasyAuction contract
/// https://github.com/gnosis/ido-contracts/blob/main/contracts/EasyAuction.sol
interface IGnosis {
function initiateAuction(
IERC20 auctioningToken,
IERC20 biddingToken,
uint256 orderCancellationEndDate,
uint256 auctionEndDate,
uint96 auctionedSellAmount,
uint96 minBuyAmount,
uint256 minimumBiddingAmountPerOrder,
uint256 minFundingThreshold,
bool isAtomicClosureAllowed,
address accessManagerContract,
bytes memory accessManagerContractData
) external returns (uint256 auctionId);
function auctionData(uint256 auctionId) external view returns (GnosisAuctionData memory);
/// @param auctionId The external auction id
/// @dev See here for decoding: https://git.io/JMang
/// @return encodedOrder The order, encoded in a bytes 32
function settleAuction(uint256 auctionId) external returns (bytes32 encodedOrder);
/// @return The numerator over a 1000-valued denominator
function feeNumerator() external returns (uint256);
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts-upgradeable/access/IAccessControlUpgradeable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "./IAssetRegistry.sol";
import "./IBasketHandler.sol";
import "./IBackingManager.sol";
import "./IBroker.sol";
import "./IDistributor.sol";
import "./IFurnace.sol";
import "./IGnosis.sol";
import "./IRToken.sol";
import "./IRevenueTrader.sol";
import "./IStRSR.sol";
import "./ITrading.sol";
import "./IVersioned.sol";
// === Auth roles ===
bytes32 constant OWNER = bytes32(bytes("OWNER"));
bytes32 constant SHORT_FREEZER = bytes32(bytes("SHORT_FREEZER"));
bytes32 constant LONG_FREEZER = bytes32(bytes("LONG_FREEZER"));
bytes32 constant PAUSER = bytes32(bytes("PAUSER"));
/**
* Main is a central hub that maintains a list of Component contracts.
*
* Components:
* - perform a specific function
* - defer auth to Main
* - usually (but not always) contain sizeable state that require a proxy
*/
struct Components {
// Definitely need proxy
IRToken rToken;
IStRSR stRSR;
IAssetRegistry assetRegistry;
IBasketHandler basketHandler;
IBackingManager backingManager;
IDistributor distributor;
IFurnace furnace;
IBroker broker;
IRevenueTrader rsrTrader;
IRevenueTrader rTokenTrader;
}
interface IAuth is IAccessControlUpgradeable {
/// Emitted when `unfreezeAt` is changed
/// @param oldVal The old value of `unfreezeAt`
/// @param newVal The new value of `unfreezeAt`
event UnfreezeAtSet(uint48 oldVal, uint48 newVal);
/// Emitted when the short freeze duration governance param is changed
/// @param oldDuration The old short freeze duration
/// @param newDuration The new short freeze duration
event ShortFreezeDurationSet(uint48 oldDuration, uint48 newDuration);
/// Emitted when the long freeze duration governance param is changed
/// @param oldDuration The old long freeze duration
/// @param newDuration The new long freeze duration
event LongFreezeDurationSet(uint48 oldDuration, uint48 newDuration);
/// Emitted when the system is paused or unpaused for trading
/// @param oldVal The old value of `tradingPaused`
/// @param newVal The new value of `tradingPaused`
event TradingPausedSet(bool oldVal, bool newVal);
/// Emitted when the system is paused or unpaused for issuance
/// @param oldVal The old value of `issuancePaused`
/// @param newVal The new value of `issuancePaused`
event IssuancePausedSet(bool oldVal, bool newVal);
/**
* Trading Paused: Disable everything except for OWNER actions, RToken.issue, RToken.redeem,
* StRSR.stake, and StRSR.payoutRewards
* Issuance Paused: Disable RToken.issue
* Frozen: Disable everything except for OWNER actions + StRSR.stake (for governance)
*/
function tradingPausedOrFrozen() external view returns (bool);
function issuancePausedOrFrozen() external view returns (bool);
function frozen() external view returns (bool);
function shortFreeze() external view returns (uint48);
function longFreeze() external view returns (uint48);
// ====
// onlyRole(OWNER)
function freezeForever() external;
// onlyRole(SHORT_FREEZER)
function freezeShort() external;
// onlyRole(LONG_FREEZER)
function freezeLong() external;
// onlyRole(OWNER)
function unfreeze() external;
function pauseTrading() external;
function unpauseTrading() external;
function pauseIssuance() external;
function unpauseIssuance() external;
}
interface IComponentRegistry {
// === Component setters/getters ===
event RTokenSet(IRToken indexed oldVal, IRToken indexed newVal);
function rToken() external view returns (IRToken);
event StRSRSet(IStRSR oldVal, IStRSR newVal);
function stRSR() external view returns (IStRSR);
event AssetRegistrySet(IAssetRegistry oldVal, IAssetRegistry newVal);
function assetRegistry() external view returns (IAssetRegistry);
event BasketHandlerSet(IBasketHandler oldVal, IBasketHandler newVal);
function basketHandler() external view returns (IBasketHandler);
event BackingManagerSet(IBackingManager oldVal, IBackingManager newVal);
function backingManager() external view returns (IBackingManager);
event DistributorSet(IDistributor oldVal, IDistributor newVal);
function distributor() external view returns (IDistributor);
event RSRTraderSet(IRevenueTrader oldVal, IRevenueTrader newVal);
function rsrTrader() external view returns (IRevenueTrader);
event RTokenTraderSet(IRevenueTrader oldVal, IRevenueTrader newVal);
function rTokenTrader() external view returns (IRevenueTrader);
event FurnaceSet(IFurnace oldVal, IFurnace newVal);
function furnace() external view returns (IFurnace);
event BrokerSet(IBroker oldVal, IBroker newVal);
function broker() external view returns (IBroker);
}
/**
* @title IMain
* @notice The central hub for the entire system. Maintains components and an owner singleton role
*/
interface IMain is IVersioned, IAuth, IComponentRegistry {
function poke() external; // not used in p1
// === Initialization ===
event MainInitialized();
function init(
Components memory components,
IERC20 rsr_,
uint48 shortFreeze_,
uint48 longFreeze_
) external;
function rsr() external view returns (IERC20);
}
interface TestIMain is IMain {
/// @custom:governance
function setShortFreeze(uint48) external;
/// @custom:governance
function setLongFreeze(uint48) external;
function shortFreeze() external view returns (uint48);
function longFreeze() external view returns (uint48);
function longFreezes(address account) external view returns (uint256);
function tradingPaused() external view returns (bool);
function issuancePaused() external view returns (bool);
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "./IComponent.sol";
import "./ITrading.sol";
/**
* @title IRevenueTrader
* @notice The RevenueTrader is an extension of the trading mixin that trades all
* assets at its address for a single target asset. There are two runtime instances
* of the RevenueTrader, 1 for RToken and 1 for RSR.
*/
interface IRevenueTrader is IComponent, ITrading {
// Initialization
function init(
IMain main_,
IERC20 tokenToBuy_,
uint192 maxTradeSlippage_,
uint192 minTradeVolume_
) external;
/// Distribute tokenToBuy to its destinations
/// @dev Special-case of manageTokens()
/// @custom:interaction
function distributeTokenToBuy() external;
/// Return registered ERC20s to the BackingManager if distribution for tokenToBuy is 0
/// @custom:interaction
function returnTokens(IERC20[] memory erc20s) external;
/// Process some number of tokens
/// If the tokenToBuy is included in erc20s, RevenueTrader will distribute it at end of the tx
/// @param erc20s The ERC20s to manage; can be tokenToBuy or anything registered
/// @param kinds The kinds of auctions to launch: DUTCH_AUCTION | BATCH_AUCTION
/// @custom:interaction
function manageTokens(IERC20[] memory erc20s, TradeKind[] memory kinds) external;
function tokenToBuy() external view returns (IERC20);
}
// solhint-disable-next-line no-empty-blocks
interface TestIRevenueTrader is IRevenueTrader, TestITrading {
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
/**
* @title IRewardable
* @notice A simple interface mixin to support claiming of rewards.
*/
interface IRewardable {
/// Emitted whenever a reward token balance is claimed
/// @param erc20 The ERC20 of the reward token
/// @param amount {qTok}
event RewardsClaimed(IERC20 indexed erc20, uint256 amount);
/// Claim rewards earned by holding a balance of the ERC20 token
/// Must emit `RewardsClaimed` for each token rewards are claimed for
/// @custom:interaction
function claimRewards() external;
}
/**
* @title IRewardableComponent
* @notice A simple interface mixin to support claiming of rewards.
*/
interface IRewardableComponent is IRewardable {
/// Claim rewards for a single ERC20
/// Must emit `RewardsClaimed` for each token rewards are claimed for
/// @custom:interaction
function claimRewardsSingle(IERC20 erc20) external;
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol";
// solhint-disable-next-line max-line-length
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/draft-IERC20PermitUpgradeable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "../libraries/Fixed.sol";
import "../libraries/Throttle.sol";
import "./IComponent.sol";
/**
* @title IRToken
* @notice An RToken is an ERC20 that is permissionlessly issuable/redeemable and tracks an
* exchange rate against a single unit: baskets, or {BU} in our type notation.
*/
interface IRToken is IComponent, IERC20MetadataUpgradeable, IERC20PermitUpgradeable {
/// Emitted when an issuance of RToken occurs, whether it occurs via slow minting or not
/// @param issuer The address holding collateral tokens
/// @param recipient The address of the recipient of the RTokens
/// @param amount The quantity of RToken being issued
/// @param baskets The corresponding number of baskets
event Issuance(
address indexed issuer,
address indexed recipient,
uint256 amount,
uint192 baskets
);
/// Emitted when a redemption of RToken occurs
/// @param redeemer The address holding RToken
/// @param recipient The address of the account receiving the backing collateral tokens
/// @param amount The quantity of RToken being redeemed
/// @param baskets The corresponding number of baskets
/// @param amount {qRTok} The amount of RTokens canceled
event Redemption(
address indexed redeemer,
address indexed recipient,
uint256 amount,
uint192 baskets
);
/// Emitted when the number of baskets needed changes
/// @param oldBasketsNeeded Previous number of baskets units needed
/// @param newBasketsNeeded New number of basket units needed
event BasketsNeededChanged(uint192 oldBasketsNeeded, uint192 newBasketsNeeded);
/// Emitted when RToken is melted, i.e the RToken supply is decreased but basketsNeeded is not
/// @param amount {qRTok}
event Melted(uint256 amount);
/// Emitted when issuance SupplyThrottle params are set
event IssuanceThrottleSet(ThrottleLib.Params oldVal, ThrottleLib.Params newVal);
/// Emitted when redemption SupplyThrottle params are set
event RedemptionThrottleSet(ThrottleLib.Params oldVal, ThrottleLib.Params newVal);
// Initialization
function init(
IMain main_,
string memory name_,
string memory symbol_,
string memory mandate_,
ThrottleLib.Params calldata issuanceThrottleParams,
ThrottleLib.Params calldata redemptionThrottleParams
) external;
/// Issue an RToken with basket collateral
/// @param amount {qRTok} The quantity of RToken to issue
/// @custom:interaction
function issue(uint256 amount) external;
/// Issue an RToken with basket collateral, to a particular recipient
/// @param recipient The address to receive the issued RTokens
/// @param amount {qRTok} The quantity of RToken to issue
/// @custom:interaction
function issueTo(address recipient, uint256 amount) external;
/// Redeem RToken for basket collateral
/// @dev Use redeemCustom for non-current baskets
/// @param amount {qRTok} The quantity {qRToken} of RToken to redeem
/// @custom:interaction
function redeem(uint256 amount) external;
/// Redeem RToken for basket collateral to a particular recipient
/// @dev Use redeemCustom for non-current baskets
/// @param recipient The address to receive the backing collateral tokens
/// @param amount {qRTok} The quantity {qRToken} of RToken to redeem
/// @custom:interaction
function redeemTo(address recipient, uint256 amount) external;
/// Redeem RToken for a linear combination of historical baskets, to a particular recipient
/// @dev Allows partial redemptions up to the minAmounts
/// @param recipient The address to receive the backing collateral tokens
/// @param amount {qRTok} The quantity {qRToken} of RToken to redeem
/// @param basketNonces An array of basket nonces to do redemption from
/// @param portions {1} An array of Fix quantities that must add up to FIX_ONE
/// @param expectedERC20sOut An array of ERC20s expected out
/// @param minAmounts {qTok} The minimum ERC20 quantities the caller should receive
/// @custom:interaction
function redeemCustom(
address recipient,
uint256 amount,
uint48[] memory basketNonces,
uint192[] memory portions,
address[] memory expectedERC20sOut,
uint256[] memory minAmounts
) external;
/// Mint an amount of RToken equivalent to baskets BUs, scaling basketsNeeded up
/// Callable only by BackingManager
/// @param baskets {BU} The number of baskets to mint RToken for
/// @custom:protected
function mint(uint192 baskets) external;
/// Melt a quantity of RToken from the caller's account
/// @param amount {qRTok} The amount to be melted
/// @custom:protected
function melt(uint256 amount) external;
/// Burn an amount of RToken from caller's account and scale basketsNeeded down
/// Callable only by BackingManager
/// @custom:protected
function dissolve(uint256 amount) external;
/// Set the number of baskets needed directly, callable only by the BackingManager
/// @param basketsNeeded {BU} The number of baskets to target
/// needed range: pretty interesting
/// @custom:protected
function setBasketsNeeded(uint192 basketsNeeded) external;
/// @return {BU} How many baskets are being targeted
function basketsNeeded() external view returns (uint192);
/// @return {qRTok} The maximum issuance that can be performed in the current block
function issuanceAvailable() external view returns (uint256);
/// @return {qRTok} The maximum redemption that can be performed in the current block
function redemptionAvailable() external view returns (uint256);
}
interface TestIRToken is IRToken {
function setIssuanceThrottleParams(ThrottleLib.Params calldata) external;
function setRedemptionThrottleParams(ThrottleLib.Params calldata) external;
function issuanceThrottleParams() external view returns (ThrottleLib.Params memory);
function redemptionThrottleParams() external view returns (ThrottleLib.Params memory);
function increaseAllowance(address, uint256) external returns (bool);
function decreaseAllowance(address, uint256) external returns (bool);
function monetizeDonations(IERC20) external;
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol";
// solhint-disable-next-line max-line-length
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/draft-IERC20PermitUpgradeable.sol";
import "../libraries/Fixed.sol";
import "./IComponent.sol";
/**
* @title IStRSR
* @notice An ERC20 token representing shares of the RSR over-collateralization pool.
*
* StRSR permits the BackingManager to take RSR in times of need. In return, the BackingManager
* benefits the StRSR pool with RSR rewards purchased with a portion of its revenue.
*
* In the absence of collateral default or losses due to slippage, StRSR should have a
* monotonically increasing exchange rate with respect to RSR, meaning that over time
* StRSR is redeemable for more RSR. It is non-rebasing.
*/
interface IStRSR is IERC20MetadataUpgradeable, IERC20PermitUpgradeable, IComponent {
/// Emitted when RSR is staked
/// @param era The era at time of staking
/// @param staker The address of the staker
/// @param rsrAmount {qRSR} How much RSR was staked
/// @param stRSRAmount {qStRSR} How much stRSR was minted by this staking
event Staked(
uint256 indexed era,
address indexed staker,
uint256 rsrAmount,
uint256 stRSRAmount
);
/// Emitted when an unstaking is started
/// @param draftId The id of the draft.
/// @param draftEra The era of the draft.
/// @param staker The address of the unstaker
/// The triple (staker, draftEra, draftId) is a unique ID
/// @param rsrAmount {qRSR} How much RSR this unstaking will be worth, absent seizures
/// @param stRSRAmount {qStRSR} How much stRSR was burned by this unstaking
event UnstakingStarted(
uint256 indexed draftId,
uint256 indexed draftEra,
address indexed staker,
uint256 rsrAmount,
uint256 stRSRAmount,
uint256 availableAt
);
/// Emitted when RSR is unstaked
/// @param firstId The beginning of the range of draft IDs withdrawn in this transaction
/// @param endId The end of range of draft IDs withdrawn in this transaction
/// (ID i was withdrawn if firstId <= i < endId)
/// @param draftEra The era of the draft.
/// The triple (staker, draftEra, id) is a unique ID among drafts
/// @param staker The address of the unstaker
/// @param rsrAmount {qRSR} How much RSR this unstaking was worth
event UnstakingCompleted(
uint256 indexed firstId,
uint256 indexed endId,
uint256 draftEra,
address indexed staker,
uint256 rsrAmount
);
/// Emitted when RSR unstaking is cancelled
/// @param firstId The beginning of the range of draft IDs withdrawn in this transaction
/// @param endId The end of range of draft IDs withdrawn in this transaction
/// (ID i was withdrawn if firstId <= i < endId)
/// @param draftEra The era of the draft.
/// The triple (staker, draftEra, id) is a unique ID among drafts
/// @param staker The address of the unstaker
/// @param rsrAmount {qRSR} How much RSR this unstaking was worth
event UnstakingCancelled(
uint256 indexed firstId,
uint256 indexed endId,
uint256 draftEra,
address indexed staker,
uint256 rsrAmount
);
/// Emitted whenever the exchange rate changes
event ExchangeRateSet(uint192 oldVal, uint192 newVal);
/// Emitted whenever RSR are paids out
event RewardsPaid(uint256 rsrAmt);
/// Emitted if all the RSR in the staking pool is seized and all balances are reset to zero.
event AllBalancesReset(uint256 indexed newEra);
/// Emitted if all the RSR in the unstakin pool is seized, and all ongoing unstaking is voided.
event AllUnstakingReset(uint256 indexed newEra);
event UnstakingDelaySet(uint48 oldVal, uint48 newVal);
event RewardRatioSet(uint192 oldVal, uint192 newVal);
event WithdrawalLeakSet(uint192 oldVal, uint192 newVal);
// Initialization
function init(
IMain main_,
string memory name_,
string memory symbol_,
uint48 unstakingDelay_,
uint192 rewardRatio_,
uint192 withdrawalLeak_
) external;
/// Gather and payout rewards from rsrTrader
/// @custom:interaction
function payoutRewards() external;
/// Stakes an RSR `amount` on the corresponding RToken to earn yield and over-collateralized
/// the system
/// @param amount {qRSR}
/// @custom:interaction
function stake(uint256 amount) external;
/// Begins a delayed unstaking for `amount` stRSR
/// @param amount {qStRSR}
/// @custom:interaction
function unstake(uint256 amount) external;
/// Complete delayed unstaking for the account, up to (but not including!) `endId`
/// @custom:interaction
function withdraw(address account, uint256 endId) external;
/// Cancel unstaking for the account, up to (but not including!) `endId`
/// @custom:interaction
function cancelUnstake(uint256 endId) external;
/// Seize RSR, only callable by main.backingManager()
/// @custom:protected
function seizeRSR(uint256 amount) external;
/// Reset all stakes and advance era
/// @custom:governance
function resetStakes() external;
/// Return the maximum valid value of endId such that withdraw(endId) should immediately work
function endIdForWithdraw(address account) external view returns (uint256 endId);
/// @return {qRSR/qStRSR} The exchange rate between RSR and StRSR
function exchangeRate() external view returns (uint192);
}
interface TestIStRSR is IStRSR {
function rewardRatio() external view returns (uint192);
function setRewardRatio(uint192) external;
function unstakingDelay() external view returns (uint48);
function setUnstakingDelay(uint48) external;
function withdrawalLeak() external view returns (uint192);
function setWithdrawalLeak(uint192) external;
function increaseAllowance(address, uint256) external returns (bool);
function decreaseAllowance(address, uint256) external returns (bool);
/// @return {qStRSR/qRSR} The exchange rate between StRSR and RSR
function exchangeRate() external view returns (uint192);
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "./IBroker.sol";
import "./IVersioned.sol";
enum TradeStatus {
NOT_STARTED, // before init()
OPEN, // after init() and before settle()
CLOSED, // after settle()
// === Intermediate-tx state ===
PENDING // during init() or settle() (reentrancy protection)
}
/**
* Simple generalized trading interface for all Trade contracts to obey
*
* Usage: if (canSettle()) settle()
*/
interface ITrade is IVersioned {
/// Complete the trade and transfer tokens back to the origin trader
/// @return soldAmt {qSellTok} The quantity of tokens sold
/// @return boughtAmt {qBuyTok} The quantity of tokens bought
function settle() external returns (uint256 soldAmt, uint256 boughtAmt);
function sell() external view returns (IERC20Metadata);
function buy() external view returns (IERC20Metadata);
/// @return {tok} The sell amount of the trade, in whole tokens
function sellAmount() external view returns (uint192);
/// @return The timestamp at which the trade is projected to become settle-able
function endTime() external view returns (uint48);
/// @return True if the trade can be settled
/// @dev Should be guaranteed to be true eventually as an invariant
function canSettle() external view returns (bool);
/// @return TradeKind.DUTCH_AUCTION or TradeKind.BATCH_AUCTION
// solhint-disable-next-line func-name-mixedcase
function KIND() external view returns (TradeKind);
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "../libraries/Fixed.sol";
import "./IComponent.sol";
import "./ITrade.sol";
import "./IRewardable.sol";
/**
* @title ITrading
* @notice Common events and refresher function for all Trading contracts
*/
interface ITrading is IComponent, IRewardableComponent {
event MaxTradeSlippageSet(uint192 oldVal, uint192 newVal);
event MinTradeVolumeSet(uint192 oldVal, uint192 newVal);
/// Emitted when a trade is started
/// @param trade The one-time-use trade contract that was just deployed
/// @param sell The token to sell
/// @param buy The token to buy
/// @param sellAmount {qSellTok} The quantity of the selling token
/// @param minBuyAmount {qBuyTok} The minimum quantity of the buying token to accept
event TradeStarted(
ITrade indexed trade,
IERC20 indexed sell,
IERC20 indexed buy,
uint256 sellAmount,
uint256 minBuyAmount
);
/// Emitted after a trade ends
/// @param trade The one-time-use trade contract
/// @param sell The token to sell
/// @param buy The token to buy
/// @param sellAmount {qSellTok} The quantity of the token sold
/// @param buyAmount {qBuyTok} The quantity of the token bought
event TradeSettled(
ITrade indexed trade,
IERC20 indexed sell,
IERC20 indexed buy,
uint256 sellAmount,
uint256 buyAmount
);
/// Settle a single trade, expected to be used with multicall for efficient mass settlement
/// @param sell The sell token in the trade
/// @return The trade settled
/// @custom:refresher
function settleTrade(IERC20 sell) external returns (ITrade);
/// @return {%} The maximum trade slippage acceptable
function maxTradeSlippage() external view returns (uint192);
/// @return {UoA} The minimum trade volume in UoA, applies to all assets
function minTradeVolume() external view returns (uint192);
/// @return The ongoing trade for a sell token, or the zero address
function trades(IERC20 sell) external view returns (ITrade);
/// @return The number of ongoing trades open
function tradesOpen() external view returns (uint48);
/// @return The number of total trades ever opened
function tradesNonce() external view returns (uint256);
}
interface TestITrading is ITrading {
/// @custom:governance
function setMaxTradeSlippage(uint192 val) external;
/// @custom:governance
function setMinTradeVolume(uint192 val) external;
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
interface IVersioned {
function version() external view returns (string memory);
}// SPDX-License-Identifier: BlueOak-1.0.0
// solhint-disable func-name-mixedcase func-visibility
// slither-disable-start divide-before-multiply
pragma solidity ^0.8.19;
/// @title FixedPoint, a fixed-point arithmetic library defining the custom type uint192
/// @author Matt Elder <matt.elder@reserve.org> and the Reserve Team <https://reserve.org>
/** The logical type `uint192 ` is a 192 bit value, representing an 18-decimal Fixed-point
fractional value. This is what's described in the Solidity documentation as
"fixed192x18" -- a value represented by 192 bits, that makes 18 digits available to
the right of the decimal point.
The range of values that uint192 can represent is about [-1.7e20, 1.7e20].
Unless a function explicitly says otherwise, it will fail on overflow.
To be clear, the following should hold:
toFix(0) == 0
toFix(1) == 1e18
*/
// Analysis notes:
// Every function should revert iff its result is out of bounds.
// Unless otherwise noted, when a rounding mode is given, that mode is applied to
// a single division that may happen as the last step in the computation.
// Unless otherwise noted, when a rounding mode is *not* given but is needed, it's FLOOR.
// For each, we comment:
// - @return is the value expressed in "value space", where uint192(1e18) "is" 1.0
// - as-ints: is the value expressed in "implementation space", where uint192(1e18) "is" 1e18
// The "@return" expression is suitable for actually using the library
// The "as-ints" expression is suitable for testing
// A uint value passed to this library was out of bounds for uint192 operations
error UIntOutOfBounds();
bytes32 constant UIntOutofBoundsHash = keccak256(abi.encodeWithSignature("UIntOutOfBounds()"));
// Used by P1 implementation for easier casting
uint256 constant FIX_ONE_256 = 1e18;
uint8 constant FIX_DECIMALS = 18;
// If a particular uint192 is represented by the uint192 n, then the uint192 represents the
// value n/FIX_SCALE.
uint64 constant FIX_SCALE = 1e18;
// FIX_SCALE Squared:
uint128 constant FIX_SCALE_SQ = 1e36;
// The largest integer that can be converted to uint192 .
// This is a bit bigger than 3.1e39
uint192 constant FIX_MAX_INT = type(uint192).max / FIX_SCALE;
uint192 constant FIX_ZERO = 0; // The uint192 representation of zero.
uint192 constant FIX_ONE = FIX_SCALE; // The uint192 representation of one.
uint192 constant FIX_MAX = type(uint192).max; // The largest uint192. (Not an integer!)
uint192 constant FIX_MIN = 0; // The smallest uint192.
/// An enum that describes a rounding approach for converting to ints
enum RoundingMode {
FLOOR, // Round towards zero
ROUND, // Round to the nearest int
CEIL // Round away from zero
}
RoundingMode constant FLOOR = RoundingMode.FLOOR;
RoundingMode constant ROUND = RoundingMode.ROUND;
RoundingMode constant CEIL = RoundingMode.CEIL;
/* @dev Solidity 0.8.x only allows you to change one of type or size per type conversion.
Thus, all the tedious-looking double conversions like uint256(uint256 (foo))
See: https://docs.soliditylang.org/en/v0.8.17/080-breaking-changes.html#new-restrictions
*/
/// Explicitly convert a uint256 to a uint192. Revert if the input is out of bounds.
function _safeWrap(uint256 x) pure returns (uint192) {
if (FIX_MAX < x) revert UIntOutOfBounds();
return uint192(x);
}
/// Convert a uint to its Fix representation.
/// @return x
// as-ints: x * 1e18
function toFix(uint256 x) pure returns (uint192) {
return _safeWrap(x * FIX_SCALE);
}
/// Convert a uint to its fixed-point representation, and left-shift its value `shiftLeft`
/// decimal digits.
/// @return x * 10**shiftLeft
// as-ints: x * 10**(shiftLeft + 18)
function shiftl_toFix(uint256 x, int8 shiftLeft) pure returns (uint192) {
return shiftl_toFix(x, shiftLeft, FLOOR);
}
/// @return x * 10**shiftLeft
// as-ints: x * 10**(shiftLeft + 18)
function shiftl_toFix(
uint256 x,
int8 shiftLeft,
RoundingMode rounding
) pure returns (uint192) {
// conditions for avoiding overflow
if (x == 0) return 0;
if (shiftLeft <= -96) return (rounding == CEIL ? 1 : 0); // 0 < uint.max / 10**77 < 0.5
if (40 <= shiftLeft) revert UIntOutOfBounds(); // 10**56 < FIX_MAX < 10**57
shiftLeft += 18;
uint256 coeff = 10**abs(shiftLeft);
uint256 shifted = (shiftLeft >= 0) ? x * coeff : _divrnd(x, coeff, rounding);
return _safeWrap(shifted);
}
/// Divide a uint by a uint192, yielding a uint192
/// This may also fail if the result is MIN_uint192! not fixing this for optimization's sake.
/// @return x / y
// as-ints: x * 1e36 / y
function divFix(uint256 x, uint192 y) pure returns (uint192) {
// If we didn't have to worry about overflow, we'd just do `return x * 1e36 / _y`
// If it's safe to do this operation the easy way, do it:
if (x < uint256(type(uint256).max / FIX_SCALE_SQ)) {
return _safeWrap(uint256(x * FIX_SCALE_SQ) / y);
} else {
return _safeWrap(mulDiv256(x, FIX_SCALE_SQ, y));
}
}
/// Divide a uint by a uint, yielding a uint192
/// @return x / y
// as-ints: x * 1e18 / y
function divuu(uint256 x, uint256 y) pure returns (uint192) {
return _safeWrap(mulDiv256(FIX_SCALE, x, y));
}
/// @return min(x,y)
// as-ints: min(x,y)
function fixMin(uint192 x, uint192 y) pure returns (uint192) {
return x < y ? x : y;
}
/// @return max(x,y)
// as-ints: max(x,y)
function fixMax(uint192 x, uint192 y) pure returns (uint192) {
return x > y ? x : y;
}
/// @return absoluteValue(x,y)
// as-ints: absoluteValue(x,y)
function abs(int256 x) pure returns (uint256) {
return x < 0 ? uint256(-x) : uint256(x);
}
/// Divide two uints, returning a uint, using rounding mode `rounding`.
/// @return numerator / divisor
// as-ints: numerator / divisor
function _divrnd(
uint256 numerator,
uint256 divisor,
RoundingMode rounding
) pure returns (uint256) {
uint256 result = numerator / divisor;
if (rounding == FLOOR) return result;
if (rounding == ROUND) {
if (numerator % divisor > (divisor - 1) / 2) {
result++;
}
} else {
if (numerator % divisor != 0) {
result++;
}
}
return result;
}
library FixLib {
/// Again, all arithmetic functions fail if and only if the result is out of bounds.
/// Convert this fixed-point value to a uint. Round towards zero if needed.
/// @return x
// as-ints: x / 1e18
function toUint(uint192 x) internal pure returns (uint136) {
return toUint(x, FLOOR);
}
/// Convert this uint192 to a uint
/// @return x
// as-ints: x / 1e18 with rounding
function toUint(uint192 x, RoundingMode rounding) internal pure returns (uint136) {
return uint136(_divrnd(uint256(x), FIX_SCALE, rounding));
}
/// Return the uint192 shifted to the left by `decimal` digits
/// (Similar to a bitshift but in base 10)
/// @return x * 10**decimals
// as-ints: x * 10**decimals
function shiftl(uint192 x, int8 decimals) internal pure returns (uint192) {
return shiftl(x, decimals, FLOOR);
}
/// Return the uint192 shifted to the left by `decimal` digits
/// (Similar to a bitshift but in base 10)
/// @return x * 10**decimals
// as-ints: x * 10**decimals
function shiftl(
uint192 x,
int8 decimals,
RoundingMode rounding
) internal pure returns (uint192) {
// Handle overflow cases
if (x == 0) return 0;
if (decimals <= -59) return (rounding == CEIL ? 1 : 0); // 59, because 1e58 > 2**192
if (58 <= decimals) revert UIntOutOfBounds(); // 58, because x * 1e58 > 2 ** 192 if x != 0
uint256 coeff = uint256(10**abs(decimals));
return _safeWrap(decimals >= 0 ? x * coeff : _divrnd(x, coeff, rounding));
}
/// Add a uint192 to this uint192
/// @return x + y
// as-ints: x + y
function plus(uint192 x, uint192 y) internal pure returns (uint192) {
return x + y;
}
/// Add a uint to this uint192
/// @return x + y
// as-ints: x + y*1e18
function plusu(uint192 x, uint256 y) internal pure returns (uint192) {
return _safeWrap(x + y * FIX_SCALE);
}
/// Subtract a uint192 from this uint192
/// @return x - y
// as-ints: x - y
function minus(uint192 x, uint192 y) internal pure returns (uint192) {
return x - y;
}
/// Subtract a uint from this uint192
/// @return x - y
// as-ints: x - y*1e18
function minusu(uint192 x, uint256 y) internal pure returns (uint192) {
return _safeWrap(uint256(x) - uint256(y * FIX_SCALE));
}
/// Multiply this uint192 by a uint192
/// Round truncated values to the nearest available value. 5e-19 rounds away from zero.
/// @return x * y
// as-ints: x * y/1e18 [division using ROUND, not FLOOR]
function mul(uint192 x, uint192 y) internal pure returns (uint192) {
return mul(x, y, ROUND);
}
/// Multiply this uint192 by a uint192
/// @return x * y
// as-ints: x * y/1e18
function mul(
uint192 x,
uint192 y,
RoundingMode rounding
) internal pure returns (uint192) {
return _safeWrap(_divrnd(uint256(x) * uint256(y), FIX_SCALE, rounding));
}
/// Multiply this uint192 by a uint
/// @return x * y
// as-ints: x * y
function mulu(uint192 x, uint256 y) internal pure returns (uint192) {
return _safeWrap(x * y);
}
/// Divide this uint192 by a uint192
/// @return x / y
// as-ints: x * 1e18 / y
function div(uint192 x, uint192 y) internal pure returns (uint192) {
return div(x, y, FLOOR);
}
/// Divide this uint192 by a uint192
/// @return x / y
// as-ints: x * 1e18 / y
function div(
uint192 x,
uint192 y,
RoundingMode rounding
) internal pure returns (uint192) {
// Multiply-in FIX_SCALE before dividing by y to preserve precision.
return _safeWrap(_divrnd(uint256(x) * FIX_SCALE, y, rounding));
}
/// Divide this uint192 by a uint
/// @return x / y
// as-ints: x / y
function divu(uint192 x, uint256 y) internal pure returns (uint192) {
return divu(x, y, FLOOR);
}
/// Divide this uint192 by a uint
/// @return x / y
// as-ints: x / y
function divu(
uint192 x,
uint256 y,
RoundingMode rounding
) internal pure returns (uint192) {
return _safeWrap(_divrnd(x, y, rounding));
}
uint64 constant FIX_HALF = uint64(FIX_SCALE) / 2;
/// Raise this uint192 to a nonnegative integer power. Requires that x_ <= FIX_ONE
/// Gas cost is O(lg(y)), precision is +- 1e-18.
/// @return x_ ** y
// as-ints: x_ ** y / 1e18**(y-1) <- technically correct for y = 0. :D
function powu(uint192 x_, uint48 y) internal pure returns (uint192) {
require(x_ <= FIX_ONE);
if (y == 1) return x_;
if (x_ == FIX_ONE || y == 0) return FIX_ONE;
uint256 x = uint256(x_) * FIX_SCALE; // x is D36
uint256 result = FIX_SCALE_SQ; // result is D36
while (true) {
if (y & 1 == 1) result = (result * x + FIX_SCALE_SQ / 2) / FIX_SCALE_SQ;
if (y <= 1) break;
y = (y >> 1);
x = (x * x + FIX_SCALE_SQ / 2) / FIX_SCALE_SQ;
}
return _safeWrap(result / FIX_SCALE);
}
function sqrt(uint192 x) internal pure returns (uint192) {
return _safeWrap(sqrt256(x * FIX_ONE_256)); // FLOOR
}
/// Comparison operators...
function lt(uint192 x, uint192 y) internal pure returns (bool) {
return x < y;
}
function lte(uint192 x, uint192 y) internal pure returns (bool) {
return x <= y;
}
function gt(uint192 x, uint192 y) internal pure returns (bool) {
return x > y;
}
function gte(uint192 x, uint192 y) internal pure returns (bool) {
return x >= y;
}
function eq(uint192 x, uint192 y) internal pure returns (bool) {
return x == y;
}
function neq(uint192 x, uint192 y) internal pure returns (bool) {
return x != y;
}
/// Return whether or not this uint192 is less than epsilon away from y.
/// @return |x - y| < epsilon
// as-ints: |x - y| < epsilon
function near(
uint192 x,
uint192 y,
uint192 epsilon
) internal pure returns (bool) {
uint192 diff = x <= y ? y - x : x - y;
return diff < epsilon;
}
// ================ Chained Operations ================
// The operation foo_bar() always means:
// Do foo() followed by bar(), and overflow only if the _end_ result doesn't fit in an uint192
/// Shift this uint192 left by `decimals` digits, and convert to a uint
/// @return x * 10**decimals
// as-ints: x * 10**(decimals - 18)
function shiftl_toUint(uint192 x, int8 decimals) internal pure returns (uint256) {
return shiftl_toUint(x, decimals, FLOOR);
}
/// Shift this uint192 left by `decimals` digits, and convert to a uint.
/// @return x * 10**decimals
// as-ints: x * 10**(decimals - 18)
function shiftl_toUint(
uint192 x,
int8 decimals,
RoundingMode rounding
) internal pure returns (uint256) {
// Handle overflow cases
if (x == 0) return 0; // always computable, no matter what decimals is
if (decimals <= -42) return (rounding == CEIL ? 1 : 0);
if (96 <= decimals) revert UIntOutOfBounds();
decimals -= 18; // shift so that toUint happens at the same time.
uint256 coeff = uint256(10**abs(decimals));
return decimals >= 0 ? uint256(x * coeff) : uint256(_divrnd(x, coeff, rounding));
}
/// Multiply this uint192 by a uint, and output the result as a uint
/// @return x * y
// as-ints: x * y / 1e18
function mulu_toUint(uint192 x, uint256 y) internal pure returns (uint256) {
return mulDiv256(uint256(x), y, FIX_SCALE);
}
/// Multiply this uint192 by a uint, and output the result as a uint
/// @return x * y
// as-ints: x * y / 1e18
function mulu_toUint(
uint192 x,
uint256 y,
RoundingMode rounding
) internal pure returns (uint256) {
return mulDiv256(uint256(x), y, FIX_SCALE, rounding);
}
/// Multiply this uint192 by a uint192 and output the result as a uint
/// @return x * y
// as-ints: x * y / 1e36
function mul_toUint(uint192 x, uint192 y) internal pure returns (uint256) {
return mulDiv256(uint256(x), uint256(y), FIX_SCALE_SQ);
}
/// Multiply this uint192 by a uint192 and output the result as a uint
/// @return x * y
// as-ints: x * y / 1e36
function mul_toUint(
uint192 x,
uint192 y,
RoundingMode rounding
) internal pure returns (uint256) {
return mulDiv256(uint256(x), uint256(y), FIX_SCALE_SQ, rounding);
}
/// Compute x * y / z avoiding intermediate overflow
/// @dev Only use if you need to avoid overflow; costlier than x * y / z
/// @return x * y / z
// as-ints: x * y / z
function muluDivu(
uint192 x,
uint256 y,
uint256 z
) internal pure returns (uint192) {
return muluDivu(x, y, z, FLOOR);
}
/// Compute x * y / z, avoiding intermediate overflow
/// @dev Only use if you need to avoid overflow; costlier than x * y / z
/// @return x * y / z
// as-ints: x * y / z
function muluDivu(
uint192 x,
uint256 y,
uint256 z,
RoundingMode rounding
) internal pure returns (uint192) {
return _safeWrap(mulDiv256(x, y, z, rounding));
}
/// Compute x * y / z on Fixes, avoiding intermediate overflow
/// @dev Only use if you need to avoid overflow; costlier than x * y / z
/// @return x * y / z
// as-ints: x * y / z
function mulDiv(
uint192 x,
uint192 y,
uint192 z
) internal pure returns (uint192) {
return mulDiv(x, y, z, FLOOR);
}
/// Compute x * y / z on Fixes, avoiding intermediate overflow
/// @dev Only use if you need to avoid overflow; costlier than x * y / z
/// @return x * y / z
// as-ints: x * y / z
function mulDiv(
uint192 x,
uint192 y,
uint192 z,
RoundingMode rounding
) internal pure returns (uint192) {
return _safeWrap(mulDiv256(x, y, z, rounding));
}
// === safe*() ===
/// Multiply two fixes, rounding up to FIX_MAX and down to 0
/// @param a First param to multiply
/// @param b Second param to multiply
function safeMul(
uint192 a,
uint192 b,
RoundingMode rounding
) internal pure returns (uint192) {
// untestable:
// a will never = 0 here because of the check in _price()
if (a == 0 || b == 0) return 0;
// untestable:
// a = FIX_MAX iff b = 0
if (a == FIX_MAX || b == FIX_MAX) return FIX_MAX;
// return FIX_MAX instead of throwing overflow errors.
unchecked {
// p and mul *are* Fix values, so have 18 decimals (D18)
uint256 rawDelta = uint256(b) * a; // {D36} = {D18} * {D18}
// if we overflowed, then return FIX_MAX
if (rawDelta / b != a) return FIX_MAX;
uint256 shiftDelta = rawDelta;
// add in rounding
if (rounding == RoundingMode.ROUND) shiftDelta += (FIX_ONE / 2);
else if (rounding == RoundingMode.CEIL) shiftDelta += FIX_ONE - 1;
// untestable (here there be dragons):
// (below explanation is for the ROUND case, but it extends to the FLOOR/CEIL too)
// A) shiftDelta = rawDelta + (FIX_ONE / 2)
// shiftDelta overflows if:
// B) shiftDelta = MAX_UINT256 - FIX_ONE/2 + 1
// rawDelta + (FIX_ONE/2) = MAX_UINT256 - FIX_ONE/2 + 1
// b * a = MAX_UINT256 - FIX_ONE + 1
// therefore shiftDelta overflows if:
// C) b = (MAX_UINT256 - FIX_ONE + 1) / a
// MAX_UINT256 ~= 1e77 , FIX_MAX ~= 6e57 (6e20 difference in magnitude)
// a <= 1e21 (MAX_TARGET_AMT)
// a must be between 1e19 & 1e20 in order for b in (C) to be uint192,
// but a would have to be < 1e18 in order for (A) to overflow
if (shiftDelta < rawDelta) return FIX_MAX;
// return FIX_MAX if return result would truncate
if (shiftDelta / FIX_ONE > FIX_MAX) return FIX_MAX;
// return _div(rawDelta, FIX_ONE, rounding)
return uint192(shiftDelta / FIX_ONE); // {D18} = {D36} / {D18}
}
}
/// Divide two fixes, rounding up to FIX_MAX and down to 0
/// @param a Numerator
/// @param b Denominator
function safeDiv(
uint192 a,
uint192 b,
RoundingMode rounding
) internal pure returns (uint192) {
if (a == 0) return 0;
if (b == 0) return FIX_MAX;
uint256 raw = _divrnd(FIX_ONE_256 * a, uint256(b), rounding);
if (raw >= FIX_MAX) return FIX_MAX;
return uint192(raw); // don't need _safeWrap
}
/// Multiplies two fixes and divide by a third
/// @param a First to multiply
/// @param b Second to multiply
/// @param c Denominator
function safeMulDiv(
uint192 a,
uint192 b,
uint192 c,
RoundingMode rounding
) internal pure returns (uint192 result) {
if (a == 0 || b == 0) return 0;
if (a == FIX_MAX || b == FIX_MAX || c == 0) return FIX_MAX;
uint256 result_256;
unchecked {
(uint256 hi, uint256 lo) = fullMul(a, b);
if (hi >= c) return FIX_MAX;
uint256 mm = mulmod(a, b, c);
if (mm > lo) hi -= 1;
lo -= mm;
uint256 pow2 = c & (0 - c);
uint256 c_256 = uint256(c);
// Warning: Should not access c below this line
c_256 /= pow2;
lo /= pow2;
lo += hi * ((0 - pow2) / pow2 + 1);
uint256 r = 1;
r *= 2 - c_256 * r;
r *= 2 - c_256 * r;
r *= 2 - c_256 * r;
r *= 2 - c_256 * r;
r *= 2 - c_256 * r;
r *= 2 - c_256 * r;
r *= 2 - c_256 * r;
r *= 2 - c_256 * r;
result_256 = lo * r;
// Apply rounding
if (rounding == CEIL) {
if (mm != 0) result_256 += 1;
} else if (rounding == ROUND) {
if (mm > ((c_256 - 1) / 2)) result_256 += 1;
}
}
if (result_256 >= FIX_MAX) return FIX_MAX;
return uint192(result_256);
}
}
// ================ a couple pure-uint helpers================
// as-ints comments are omitted here, because they're the same as @return statements, because
// these are all pure uint functions
/// Return (x*y/z), avoiding intermediate overflow.
// Adapted from sources:
// https://medium.com/coinmonks/4db014e080b1, https://medium.com/wicketh/afa55870a65
// and quite a few of the other excellent "Mathemagic" posts from https://medium.com/wicketh
/// @dev Only use if you need to avoid overflow; costlier than x * y / z
/// @return result x * y / z
function mulDiv256(
uint256 x,
uint256 y,
uint256 z
) pure returns (uint256 result) {
unchecked {
(uint256 hi, uint256 lo) = fullMul(x, y);
if (hi >= z) revert UIntOutOfBounds();
uint256 mm = mulmod(x, y, z);
if (mm > lo) hi -= 1;
lo -= mm;
uint256 pow2 = z & (0 - z);
z /= pow2;
lo /= pow2;
lo += hi * ((0 - pow2) / pow2 + 1);
uint256 r = 1;
r *= 2 - z * r;
r *= 2 - z * r;
r *= 2 - z * r;
r *= 2 - z * r;
r *= 2 - z * r;
r *= 2 - z * r;
r *= 2 - z * r;
r *= 2 - z * r;
result = lo * r;
}
}
/// Return (x*y/z), avoiding intermediate overflow.
/// @dev Only use if you need to avoid overflow; costlier than x * y / z
/// @return x * y / z
function mulDiv256(
uint256 x,
uint256 y,
uint256 z,
RoundingMode rounding
) pure returns (uint256) {
uint256 result = mulDiv256(x, y, z);
if (rounding == FLOOR) return result;
uint256 mm = mulmod(x, y, z);
if (rounding == CEIL) {
if (mm != 0) result += 1;
} else {
if (mm > ((z - 1) / 2)) result += 1; // z should be z-1
}
return result;
}
/// Return (x*y) as a "virtual uint512" (lo, hi), representing (hi*2**256 + lo)
/// Adapted from sources:
/// https://medium.com/wicketh/27650fec525d, https://medium.com/coinmonks/4db014e080b1
/// @dev Intended to be internal to this library
/// @return hi (hi, lo) satisfies hi*(2**256) + lo == x * y
/// @return lo (paired with `hi`)
function fullMul(uint256 x, uint256 y) pure returns (uint256 hi, uint256 lo) {
unchecked {
uint256 mm = mulmod(x, y, uint256(0) - uint256(1));
lo = x * y;
hi = mm - lo;
if (mm < lo) hi -= 1;
}
}
// =============== from prbMath at commit 28055f6cd9a2367f9ad7ab6c8e01c9ac8e9acc61 ===============
/// @notice Calculates the square root of x using the Babylonian method.
///
/// @dev See https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method.
///
/// Notes:
/// - If x is not a perfect square, the result is rounded down.
/// - Credits to OpenZeppelin for the explanations in comments below.
///
/// @param x The uint256 number for which to calculate the square root.
/// @return result The result as a uint256.
function sqrt256(uint256 x) pure returns (uint256 result) {
if (x == 0) {
return 0;
}
// For our first guess, we calculate the biggest power of 2 which is smaller than the square root of x.
//
// We know that the "msb" (most significant bit) of x is a power of 2 such that we have:
//
// $$
// msb(x) <= x <= 2*msb(x)$
// $$
//
// We write $msb(x)$ as $2^k$, and we get:
//
// $$
// k = log_2(x)
// $$
//
// Thus, we can write the initial inequality as:
//
// $$
// 2^{log_2(x)} <= x <= 2*2^{log_2(x)+1} \\
// sqrt(2^k) <= sqrt(x) < sqrt(2^{k+1}) \\
// 2^{k/2} <= sqrt(x) < 2^{(k+1)/2} <= 2^{(k/2)+1}
// $$
//
// Consequently, $2^{log_2(x) /2} is a good first approximation of sqrt(x) with at least one correct bit.
uint256 xAux = uint256(x);
result = 1;
if (xAux >= 2**128) {
xAux >>= 128;
result <<= 64;
}
if (xAux >= 2**64) {
xAux >>= 64;
result <<= 32;
}
if (xAux >= 2**32) {
xAux >>= 32;
result <<= 16;
}
if (xAux >= 2**16) {
xAux >>= 16;
result <<= 8;
}
if (xAux >= 2**8) {
xAux >>= 8;
result <<= 4;
}
if (xAux >= 2**4) {
xAux >>= 4;
result <<= 2;
}
if (xAux >= 2**2) {
result <<= 1;
}
// At this point, `result` is an estimation with at least one bit of precision. We know the true value has at
// most 128 bits, 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 + x / result) >> 1;
result = (result + x / result) >> 1;
result = (result + x / result) >> 1;
result = (result + x / result) >> 1;
result = (result + x / result) >> 1;
result = (result + x / result) >> 1;
result = (result + x / result) >> 1;
// If x is not a perfect square, round the result toward zero.
uint256 roundedResult = x / result;
if (result >= roundedResult) {
result = roundedResult;
}
}
}
// slither-disable-end divide-before-multiply// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/cryptography/SignatureCheckerUpgradeable.sol";
/// Internal library for verifying metatx sigs for EOAs and smart contract wallets
/// See ERC1271
library PermitLib {
function requireSignature(
address owner,
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal view {
if (AddressUpgradeable.isContract(owner)) {
require(
IERC1271Upgradeable(owner).isValidSignature(hash, abi.encodePacked(r, s, v)) ==
0x1626ba7e,
"ERC1271: Unauthorized"
);
} else {
require(
SignatureCheckerUpgradeable.isValidSignatureNow(
owner,
hash,
abi.encodePacked(r, s, v)
),
"ERC20Permit: invalid signature"
);
}
}
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "./Fixed.sol";
uint48 constant ONE_HOUR = 3600; // {seconds/hour}
/**
* @title ThrottleLib
* A library that implements a usage throttle that can be used to ensure net issuance
* or net redemption for an RToken never exceeds some bounds per unit time (hour).
*
* It is expected for the RToken to use this library with two instances, one for issuance
* and one for redemption. Issuance causes the available redemption amount to increase, and
* visa versa.
*/
library ThrottleLib {
using FixLib for uint192;
struct Params {
uint256 amtRate; // {qRTok/hour} a quantity of RToken hourly; cannot be 0
uint192 pctRate; // {1/hour} a fraction of RToken hourly; can be 0
}
struct Throttle {
// === Gov params ===
Params params;
// === Cache ===
uint48 lastTimestamp; // {seconds}
uint256 lastAvailable; // {qRTok}
}
/// Reverts if usage amount exceeds available amount
/// @param supply {qRTok} Total RToken supply beforehand
/// @param amount {qRTok} Amount of RToken to use. Should be negative for the issuance
/// throttle during redemption and for the redemption throttle during issuance.
function useAvailable(
Throttle storage throttle,
uint256 supply,
int256 amount
) internal {
// untestable: amtRate will always be > 0 due to previous validations
if (throttle.params.amtRate == 0 && throttle.params.pctRate == 0) return;
// Calculate hourly limit
uint256 limit = hourlyLimit(throttle, supply); // {qRTok}
// Calculate available amount before supply change
uint256 available = currentlyAvailable(throttle, limit);
// Update throttle.timestamp if available amount changed or at limit
if (available != throttle.lastAvailable || available == limit) {
throttle.lastTimestamp = uint48(block.timestamp);
}
// Update throttle.lastAvailable
if (amount > 0) {
require(uint256(amount) <= available, "supply change throttled");
available -= uint256(amount);
// untestable: the final else statement, amount will never be 0
} else if (amount < 0) {
available += uint256(-amount);
}
throttle.lastAvailable = available;
}
/// @param limit {qRTok/hour} The hourly limit
/// @return available {qRTok} Amount currently available for consumption
function currentlyAvailable(Throttle storage throttle, uint256 limit)
internal
view
returns (uint256 available)
{
uint48 delta = uint48(block.timestamp) - throttle.lastTimestamp; // {seconds}
available = throttle.lastAvailable + (limit * delta) / ONE_HOUR;
if (available > limit) available = limit;
}
/// @return limit {qRTok} The hourly limit
function hourlyLimit(Throttle storage throttle, uint256 supply)
internal
view
returns (uint256 limit)
{
Params storage params = throttle.params;
// Calculate hourly limit as: max(params.amtRate, supply.mul(params.pctRate))
limit = (supply * params.pctRate) / FIX_ONE_256; // {qRTok}
if (params.amtRate > limit) limit = params.amtRate;
}
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "../interfaces/IVersioned.sol";
// This value should be updated on each release
string constant VERSION = "3.4.0";
/**
* @title Versioned
* @notice A mix-in to track semantic versioning uniformly across contracts.
*/
abstract contract Versioned is IVersioned {
function version() public pure virtual override returns (string memory) {
return VERSION;
}
}// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol";
import "../../interfaces/IComponent.sol";
import "../../interfaces/IMain.sol";
import "../../mixins/Versioned.sol";
/**
* Abstract superclass for system contracts registered in Main
*/
abstract contract ComponentP1 is
Versioned,
Initializable,
ContextUpgradeable,
UUPSUpgradeable,
IComponent
{
IMain public main;
/// @custom:oz-upgrades-unsafe-allow constructor
// solhint-disable-next-line no-empty-blocks
constructor() initializer {}
// Sets main for the component - Can only be called during initialization
// untestable:
// `else` branch of `onlyInitializing` (ie. revert) is currently untestable.
// This function is only called inside other `init` functions, each of which is wrapped
// in an `initializer` modifier, which would fail first.
// solhint-disable-next-line func-name-mixedcase
function __Component_init(IMain main_) internal onlyInitializing {
require(address(main_) != address(0), "main is zero address");
__UUPSUpgradeable_init();
main = main_;
}
// === See docs/pause-freeze-states.md ===
modifier notTradingPausedOrFrozen() {
require(!main.tradingPausedOrFrozen(), "frozen or trading paused");
_;
}
modifier notIssuancePausedOrFrozen() {
require(!main.issuancePausedOrFrozen(), "frozen or issuance paused");
_;
}
modifier notFrozen() {
require(!main.frozen(), "frozen");
_;
}
modifier governance() {
require(main.hasRole(OWNER, _msgSender()), "governance only");
_;
}
// solhint-disable-next-line no-empty-blocks
function _authorizeUpgrade(address newImplementation) internal view override governance {}
/**
* @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
// Taken from OZ release 4.7.3 at commit a035b235b4f2c9af4ba88edc4447f02e37f8d124
// The only modification that has been made is in the body of the `permit` function at line 83,
/// where we failover to SignatureChecker in order to handle approvals for smart contracts.
pragma solidity 0.8.19;
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/draft-IERC20PermitUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/cryptography/draft-EIP712Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/CountersUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "../libraries/Permit.sol";
import "../mixins/Versioned.sol";
/**
* @dev Implementation 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.
*
* Note: We have modified `permit` to support EIP-1271, technically violating EIP-2612.
*
* _Available since v3.4._
*
* @custom:storage-size 51
*/
abstract contract ERC20PermitUpgradeable is
Initializable,
ERC20Upgradeable,
IERC20PermitUpgradeable,
EIP712Upgradeable
{
using CountersUpgradeable for CountersUpgradeable.Counter;
mapping(address => CountersUpgradeable.Counter) private _nonces;
// solhint-disable-next-line var-name-mixedcase
bytes32 private constant _PERMIT_TYPEHASH =
keccak256(
"Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"
);
/**
* @dev In previous versions `_PERMIT_TYPEHASH` was declared as `immutable`.
* However, to ensure consistency with the upgradeable transpiler, we will continue
* to reserve a slot.
* @custom:oz-renamed-from _PERMIT_TYPEHASH
*/
// solhint-disable-next-line var-name-mixedcase
bytes32 private _PERMIT_TYPEHASH_DEPRECATED_SLOT;
// untestable:
// `else` branch of `onlyInitializing` (ie. revert) is currently untestable.
// This function is only called inside other `init` functions, each of which is wrapped
// in an `initializer` modifier, which would fail first.
/**
* @dev Initializes the {EIP712} domain separator using the `name` parameter, and setting `version` to
* the system-wide semver release version.
*
* It's a good idea to use the same `name` that is defined as the ERC20 token name.
*/
function __ERC20Permit_init(string memory name) internal onlyInitializing {
__EIP712_init_unchained(name, VERSION);
}
// untestable:
// This is not needed in the way we handle initializations
function __ERC20Permit_init_unchained(string memory) internal onlyInitializing {}
/**
* @dev See {IERC20Permit-permit}.
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) public virtual override {
require(block.timestamp <= deadline, "ERC20Permit: expired deadline");
bytes32 structHash = keccak256(
abi.encode(_PERMIT_TYPEHASH, owner, spender, value, _useNonce(owner), deadline)
);
/// ==== MODIFICATIONS START ====
PermitLib.requireSignature(owner, _hashTypedDataV4(structHash), v, r, s);
/// ==== MODIFICATIONS END ====
_approve(owner, spender, value);
}
/**
* @dev See {IERC20Permit-nonces}.
*/
function nonces(address owner) public view virtual override returns (uint256) {
return _nonces[owner].current();
}
/**
* @dev See {IERC20Permit-DOMAIN_SEPARATOR}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view override returns (bytes32) {
return _domainSeparatorV4();
}
/**
* @dev "Consume a nonce": return the current value and increment.
*
* _Available since v4.1._
*/
function _useNonce(address owner) internal virtual returns (uint256 current) {
CountersUpgradeable.Counter storage nonce = _nonces[owner];
current = nonce.current();
nonce.increment();
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[48] private __gap;
}{
"optimizer": {
"enabled": true,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"libraries": {}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[],"name":"UIntOutOfBounds","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"previousAdmin","type":"address"},{"indexed":false,"internalType":"address","name":"newAdmin","type":"address"}],"name":"AdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint192","name":"oldBasketsNeeded","type":"uint192"},{"indexed":false,"internalType":"uint192","name":"newBasketsNeeded","type":"uint192"}],"name":"BasketsNeededChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"beacon","type":"address"}],"name":"BeaconUpgraded","type":"event"},{"anonymous":false,"inputs":[],"name":"EIP712DomainChanged","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":"issuer","type":"address"},{"indexed":true,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint192","name":"baskets","type":"uint192"}],"name":"Issuance","type":"event"},{"anonymous":false,"inputs":[{"components":[{"internalType":"uint256","name":"amtRate","type":"uint256"},{"internalType":"uint192","name":"pctRate","type":"uint192"}],"indexed":false,"internalType":"struct ThrottleLib.Params","name":"oldVal","type":"tuple"},{"components":[{"internalType":"uint256","name":"amtRate","type":"uint256"},{"internalType":"uint192","name":"pctRate","type":"uint192"}],"indexed":false,"internalType":"struct ThrottleLib.Params","name":"newVal","type":"tuple"}],"name":"IssuanceThrottleSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Melted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"redeemer","type":"address"},{"indexed":true,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint192","name":"baskets","type":"uint192"}],"name":"Redemption","type":"event"},{"anonymous":false,"inputs":[{"components":[{"internalType":"uint256","name":"amtRate","type":"uint256"},{"internalType":"uint192","name":"pctRate","type":"uint192"}],"indexed":false,"internalType":"struct ThrottleLib.Params","name":"oldVal","type":"tuple"},{"components":[{"internalType":"uint256","name":"amtRate","type":"uint256"},{"internalType":"uint192","name":"pctRate","type":"uint192"}],"indexed":false,"internalType":"struct ThrottleLib.Params","name":"newVal","type":"tuple"}],"name":"RedemptionThrottleSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"implementation","type":"address"}],"name":"Upgraded","type":"event"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_EXCHANGE_RATE","outputs":[{"internalType":"uint192","name":"","type":"uint192"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_THROTTLE_PCT_AMT","outputs":[{"internalType":"uint192","name":"","type":"uint192"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_THROTTLE_RATE_AMT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MIN_EXCHANGE_RATE","outputs":[{"internalType":"uint192","name":"","type":"uint192"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MIN_THROTTLE_RATE_AMT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"basketsNeeded","outputs":[{"internalType":"uint192","name":"","type":"uint192"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"dissolve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"eip712Domain","outputs":[{"internalType":"bytes1","name":"fields","type":"bytes1"},{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"version","type":"string"},{"internalType":"uint256","name":"chainId","type":"uint256"},{"internalType":"address","name":"verifyingContract","type":"address"},{"internalType":"bytes32","name":"salt","type":"bytes32"},{"internalType":"uint256[]","name":"extensions","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IMain","name":"main_","type":"address"},{"internalType":"string","name":"name_","type":"string"},{"internalType":"string","name":"symbol_","type":"string"},{"internalType":"string","name":"mandate_","type":"string"},{"components":[{"internalType":"uint256","name":"amtRate","type":"uint256"},{"internalType":"uint192","name":"pctRate","type":"uint192"}],"internalType":"struct ThrottleLib.Params","name":"issuanceThrottleParams_","type":"tuple"},{"components":[{"internalType":"uint256","name":"amtRate","type":"uint256"},{"internalType":"uint192","name":"pctRate","type":"uint192"}],"internalType":"struct ThrottleLib.Params","name":"redemptionThrottleParams_","type":"tuple"}],"name":"init","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"issuanceAvailable","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"issuanceThrottleParams","outputs":[{"components":[{"internalType":"uint256","name":"amtRate","type":"uint256"},{"internalType":"uint192","name":"pctRate","type":"uint192"}],"internalType":"struct ThrottleLib.Params","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"issue","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"issueTo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"main","outputs":[{"internalType":"contract IMain","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"mandate","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amtRToken","type":"uint256"}],"name":"melt","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint192","name":"baskets","type":"uint192"}],"name":"mint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"erc20","type":"address"}],"name":"monetizeDonations","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"permit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"proxiableUUID","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"redeem","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint48[]","name":"basketNonces","type":"uint48[]"},{"internalType":"uint192[]","name":"portions","type":"uint192[]"},{"internalType":"address[]","name":"expectedERC20sOut","type":"address[]"},{"internalType":"uint256[]","name":"minAmounts","type":"uint256[]"}],"name":"redeemCustom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"redeemTo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"redemptionAvailable","outputs":[{"internalType":"uint256","name":"available","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"redemptionThrottleParams","outputs":[{"components":[{"internalType":"uint256","name":"amtRate","type":"uint256"},{"internalType":"uint192","name":"pctRate","type":"uint192"}],"internalType":"struct ThrottleLib.Params","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint192","name":"basketsNeeded_","type":"uint192"}],"name":"setBasketsNeeded","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"amtRate","type":"uint256"},{"internalType":"uint192","name":"pctRate","type":"uint192"}],"internalType":"struct ThrottleLib.Params","name":"params","type":"tuple"}],"name":"setIssuanceThrottleParams","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"amtRate","type":"uint256"},{"internalType":"uint192","name":"pctRate","type":"uint192"}],"internalType":"struct ThrottleLib.Params","name":"params","type":"tuple"}],"name":"setRedemptionThrottleParams","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"}],"name":"upgradeTo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"upgradeToAndCall","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"pure","type":"function"}]Contract Creation Code
60a0604052306080523480156200001557600080fd5b50600054610100900460ff1615808015620000375750600054600160ff909116105b80620000535750303b15801562000053575060005460ff166001145b620000bb5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b606482015260840160405180910390fd5b6000805460ff191660011790558015620000df576000805461ff0019166101001790555b801562000126576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b506080516156fc6200015f6000396000818161118f015281816111cf0152818161131f0152818161135f01526113f201526156fc6000f3fe6080604052600436106102675760003560e01c806372b8b05111610144578063aeb14bf6116100b6578063db006a751161007a578063db006a7514610778578063dd62ed3e14610798578063ddc95876146107b8578063dffeadd0146107fd578063f17d835c14610835578063f90b2bfe1461085557600080fd5b8063aeb14bf6146106e0578063b32deb3d14610700578063cc872b6614610720578063d505accf14610740578063d6122e921461076057600080fd5b80638e31ab2e116101085780638e31ab2e146105ec57806395d89b41146106515780639926020b14610666578063a16e15321461067b578063a457c2d7146106a0578063a9059cbb146106c057600080fd5b806372b8b0511461054f5780637ecebe001461056f5780637f2d27b91461058f57806384b0196e146105a45780638c83ed33146105cc57600080fd5b806339509351116101dd57806354fd4d50116101a157806354fd4d501461046a5780635beafb3d1461049857806363965449146104b85780636b2ba67d146104d857806370a08231146104f85780637121c2731461052e57600080fd5b806339509351146103ed57806339b1b96d1461040d5780634b35073f146104225780634f1ef2861461044257806352d1902d1461045557600080fd5b806323282f6e1161022f57806323282f6e1461032857806323b872dd1461035c5780632f7605fb1461037c578063313ce5671461039c5780633644e515146103b85780633659cfe6146103cd57600080fd5b806306fdde031461026c578063095ea7b3146102975780630b0e54d0146102c75780631207f0c1146102f157806318160ddd14610313575b600080fd5b34801561027857600080fd5b50610281610875565b60405161028e919061479e565b60405180910390f35b3480156102a357600080fd5b506102b76102b23660046147d6565b610907565b604051901515815260200161028e565b3480156102d357600080fd5b506102e3670de0b6b3a764000081565b60405190815260200161028e565b3480156102fd57600080fd5b5061031161030c3660046147d6565b610921565b005b34801561031f57600080fd5b5060cb546102e3565b34801561033457600080fd5b50610344670de0b6b3a764000081565b6040516001600160c01b03909116815260200161028e565b34801561036857600080fd5b506102b7610377366004614802565b610d38565b34801561038857600080fd5b506103116103973660046147d6565b610d5c565b3480156103a857600080fd5b506040516012815260200161028e565b3480156103c457600080fd5b506102e3611176565b3480156103d957600080fd5b506103116103e8366004614843565b611185565b3480156103f957600080fd5b506102b76104083660046147d6565b611264565b34801561041957600080fd5b50610281611286565b34801561042e57600080fd5b506103446b033b2e3c9fd0803ce800000081565b6103116104503660046148a7565b611315565b34801561046157600080fd5b506102e36113e5565b34801561047657600080fd5b506040805180820190915260058152640332e342e360dc1b6020820152610281565b3480156104a457600080fd5b506103116104b3366004614961565b611498565b3480156104c457600080fd5b506103116104d3366004614992565b6116ee565b3480156104e457600080fd5b506103116104f3366004614b76565b611955565b34801561050457600080fd5b506102e3610513366004614843565b6001600160a01b0316600090815260c9602052604090205490565b34801561053a57600080fd5b5061016654610344906001600160c01b031681565b34801561055b57600080fd5b5061031161056a366004614961565b6120de565b34801561057b57600080fd5b506102e361058a366004614843565b61232f565b34801561059b57600080fd5b506102e361234e565b3480156105b057600080fd5b506105b9612371565b60405161028e9796959493929190614c3c565b3480156105d857600080fd5b506103116105e7366004614cd2565b61240f565b3480156105f857600080fd5b506040805180820182526000808252602091820152815180830190925261016b54825261016c546001600160c01b0316908201525b60408051825181526020928301516001600160c01b0316928101929092520161028e565b34801561065d57600080fd5b5061028161249c565b34801561067257600080fd5b506102e36124ab565b34801561068757600080fd5b506102e36daf298d050e4395d69670b12b7f4160301b81565b3480156106ac57600080fd5b506102b76106bb3660046147d6565b6124e3565b3480156106cc57600080fd5b506102b76106db3660046147d6565b61255e565b3480156106ec57600080fd5b506103116106fb366004614992565b61256c565b34801561070c57600080fd5b5061031161071b366004614843565b6125c0565b34801561072c57600080fd5b5061031161073b366004614cd2565b6127b5565b34801561074c57600080fd5b5061031161075b366004614ceb565b6127bf565b34801561076c57600080fd5b50610344633b9aca0081565b34801561078457600080fd5b50610311610793366004614cd2565b6128ae565b3480156107a457600080fd5b506102e36107b3366004614d62565b6128b8565b3480156107c457600080fd5b5060408051808201825260008082526020918201528151808301909252610167548252610168546001600160c01b03169082015261062d565b34801561080957600080fd5b5060975461081d906001600160a01b031681565b6040516001600160a01b03909116815260200161028e565b34801561084157600080fd5b50610311610850366004614ddd565b6128e3565b34801561086157600080fd5b50610311610870366004614cd2565b612dd9565b606060cc805461088490614ead565b80601f01602080910402602001604051908101604052809291908181526020018280546108b090614ead565b80156108fd5780601f106108d2576101008083540402835291602001916108fd565b820191906000526020600020905b8154815290600101906020018083116108e057829003601f168201915b5050505050905090565b600033610915818585612e10565b60019150505b92915050565b609760009054906101000a90046001600160a01b03166001600160a01b03166375a8f9266040518163ffffffff1660e01b8152600401602060405180830381865afa158015610974573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109989190614ee1565b156109ea5760405162461bcd60e51b815260206004820152601960248201527f66726f7a656e206f722069737375616e6365207061757365640000000000000060448201526064015b60405180910390fd5b80600003610a2e5760405162461bcd60e51b815260206004820152601160248201527043616e6e6f74206973737565207a65726f60781b60448201526064016109e1565b61016260009054906101000a90046001600160a01b03166001600160a01b031663f8ac93e86040518163ffffffff1660e01b8152600401600060405180830381600087803b158015610a7f57600080fd5b505af1158015610a93573d6000803e3d6000fd5b505050506000610aa03390565b905061016360009054906101000a90046001600160a01b03166001600160a01b031663a094a0316040518163ffffffff1660e01b8152600401602060405180830381865afa158015610af6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b1a9190614ee1565b610b595760405162461bcd60e51b815260206004820152601060248201526f6261736b6574206e6f7420726561647960801b60448201526064016109e1565b6000610b6460cb5490565b9050610b736101678285612f34565b610b8a81610b8085614f19565b61016b9190612f34565b600081600003610ba257610b9d8461303e565b610bbc565b61016654610bbc906001600160c01b031685846002613068565b9050846001600160a01b0316836001600160a01b03167f93a73b97592126fd663d485c98f8a174c1d701035545e71ac88a05b71d6ad4ef8684604051610c159291909182526001600160c01b0316602082015260400190565b60405180910390a3610163546040516331883c3f60e21b815260009182916001600160a01b039091169063c620f0fc90610c56908690600290600401614f4b565b600060405180830381865afa158015610c73573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610c9b9190810190614fe1565b91509150610caa878486613092565b60005b8251811015610d2e57610d1e8661016460009054906101000a90046001600160a01b0316848481518110610ce357610ce36150a6565b6020026020010151868581518110610cfd57610cfd6150a6565b60200260200101516001600160a01b031661316c909392919063ffffffff16565b610d27816150bc565b9050610cad565b5050505050505050565b600033610d468582856131d7565b610d5185858561324b565b506001949350505050565b609760009054906101000a90046001600160a01b03166001600160a01b031663054f7d9c6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610daf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610dd39190614ee1565b15610e095760405162461bcd60e51b8152602060048201526006602482015265333937bd32b760d11b60448201526064016109e1565b61016260009054906101000a90046001600160a01b03166001600160a01b031663f8ac93e86040518163ffffffff1660e01b8152600401600060405180830381600087803b158015610e5a57600080fd5b505af1158015610e6e573d6000803e3d6000fd5b505050506000610e7b3390565b905081600003610ec25760405162461bcd60e51b815260206004820152601260248201527143616e6e6f742072656465656d207a65726f60701b60448201526064016109e1565b6001600160a01b038116600090815260c96020526040902054821115610f215760405162461bcd60e51b8152602060048201526014602482015273696e73756666696369656e742062616c616e636560601b60448201526064016109e1565b61016360009054906101000a90046001600160a01b03166001600160a01b031663e45a5b2d6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610f75573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f999190614ee1565b610ff15760405162461bcd60e51b8152602060048201526024808201527f7061727469616c20726564656d7074696f6e3b207573652072656465656d437560448201526373746f6d60e01b60648201526084016109e1565b6000610ffc60cb5490565b90506110158161100b85614f19565b6101679190612f34565b61102261016b8285612f34565b600061102e8385613401565b9050846001600160a01b0316836001600160a01b03167f49e15c2a707390f4ccf35ee268a61455f17aeb5b1983c01e1dd1f00b86a4725e86846040516110879291909182526001600160c01b0316602082015260400190565b60405180910390a3610163546040516331883c3f60e21b815260009182916001600160a01b039091169063c620f0fc906110c79086908590600401614f4b565b600060405180830381865afa1580156110e4573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261110c9190810190614fe1565b9150915060005b8251811015610d2e5781818151811061112e5761112e6150a6565b60200260200101516000031561116657610164548251611166916001600160a01b0316908a90859085908110610ce357610ce36150a6565b61116f816150bc565b9050611113565b60006111806134d0565b905090565b6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001630036111cd5760405162461bcd60e51b81526004016109e1906150d5565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316611216600080516020615680833981519152546001600160a01b031690565b6001600160a01b03161461123c5760405162461bcd60e51b81526004016109e190615121565b611245816134da565b604080516000808252602082019092526112619183919061359f565b50565b60003361091581858561127783836128b8565b611281919061516d565b612e10565b610161805461129490614ead565b80601f01602080910402602001604051908101604052809291908181526020018280546112c090614ead565b801561130d5780601f106112e25761010080835404028352916020019161130d565b820191906000526020600020905b8154815290600101906020018083116112f057829003601f168201915b505050505081565b6001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016300361135d5760405162461bcd60e51b81526004016109e1906150d5565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166113a6600080516020615680833981519152546001600160a01b031690565b6001600160a01b0316146113cc5760405162461bcd60e51b81526004016109e190615121565b6113d5826134da565b6113e18282600161359f565b5050565b6000306001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146114855760405162461bcd60e51b815260206004820152603860248201527f555550535570677261646561626c653a206d757374206e6f742062652063616c60448201527f6c6564207468726f7567682064656c656761746563616c6c000000000000000060648201526084016109e1565b5060008051602061568083398151915290565b60975460408051808201909152600581526427aba722a960d91b60208201526001600160a01b03909116906391d14854906114d290615180565b336040516001600160e01b031960e085901b16815260048101929092526001600160a01b03166024820152604401602060405180830381865afa15801561151d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115419190614ee1565b61155d5760405162461bcd60e51b81526004016109e1906151a4565b670de0b6b3a7640000813510156115b65760405162461bcd60e51b815260206004820152601a60248201527f69737375616e636520616d745261746520746f6f20736d616c6c00000000000060448201526064016109e1565b6daf298d050e4395d69670b12b7f4160301b813511156116185760405162461bcd60e51b815260206004820152601860248201527f69737375616e636520616d745261746520746f6f20626967000000000000000060448201526064016109e1565b670de0b6b3a76400006116316040830160208401614992565b6001600160c01b031611156116885760405162461bcd60e51b815260206004820152601860248201527f69737375616e6365207063745261746520746f6f20626967000000000000000060448201526064016109e1565b61169f61169460cb5490565b610167906000612f34565b6040517fa3e16a02f78ca4f5cf54ab43fd2cb34e5014ba4ec2e0cafb751203dcdd0aa827906116d3906101679084906151cd565b60405180910390a1806101676116e98282615214565b505050565b609760009054906101000a90046001600160a01b03166001600160a01b03166398f73e526040518163ffffffff1660e01b8152600401602060405180830381865afa158015611741573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117659190614ee1565b156117ad5760405162461bcd60e51b8152602060048201526018602482015277199c9bde995b881bdc881d1c98591a5b99c81c185d5cd95960421b60448201526064016109e1565b610164546001600160a01b0316336001600160a01b0316146117e15760405162461bcd60e51b81526004016109e190615249565b61016654604080516001600160c01b03928316815291831660208301527f0b0ca69be72e0611a1f79eedf91aece404ff14cb8fcfd0c997a72b68d4fdd478910160405180910390a161016680546001600160c01b0319166001600160c01b03831617905560cb54806000036118835760405162461bcd60e51b81526020600482015260086024820152673020737570706c7960c01b60448201526064016109e1565b6000816118a16001600160c01b038516670de0b6b3a7640000615276565b6118ab91906152a3565b90506000826118bb6001826152c5565b6118d66001600160c01b038716670de0b6b3a7640000615276565b6118e0919061516d565b6118ea91906152a3565b9050633b9aca00821080159061190c57506b033b2e3c9fd0803ce80000008111155b61194f5760405162461bcd60e51b815260206004820152601460248201527342552072617465206f7574206f662072616e676560601b60448201526064016109e1565b50505050565b609760009054906101000a90046001600160a01b03166001600160a01b031663054f7d9c6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156119a8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119cc9190614ee1565b15611a025760405162461bcd60e51b8152602060048201526006602482015265333937bd32b760d11b60448201526064016109e1565b61016260009054906101000a90046001600160a01b03166001600160a01b031663f8ac93e86040518163ffffffff1660e01b8152600401600060405180830381600087803b158015611a5357600080fd5b505af1158015611a67573d6000803e3d6000fd5b5050505084600003611ab05760405162461bcd60e51b815260206004820152601260248201527143616e6e6f742072656465656d207a65726f60701b60448201526064016109e1565b611ab933610513565b851115611aff5760405162461bcd60e51b8152602060048201526014602482015273696e73756666696369656e742062616c616e636560601b60448201526064016109e1565b6000805b8451811015611b4c57848181518110611b1e57611b1e6150a6565b60200260200101516001600160c01b031682611b3a919061516d565b9150611b45816150bc565b9050611b03565b50670de0b6b3a76400008114611bae5760405162461bcd60e51b815260206004820152602160248201527f706f7274696f6e7320646f206e6f742061646420757020746f204649585f4f4e6044820152604560f81b60648201526084016109e1565b6000611bb960cb5490565b9050611bc88161100b89614f19565b611bd561016b8289612f34565b6000611be13389613401565b604080518a81526001600160c01b03831660208201529192506001600160a01b038b169133917f49e15c2a707390f4ccf35ee268a61455f17aeb5b1983c01e1dd1f00b86a4725e910160405180910390a361016354604051630e3363af60e21b815260009182916001600160a01b03909116906338cd8ebc90611c6c908c908c9088906004016152d8565b600060405180830381865afa158015611c89573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611cb19190810190614fe1565b9150915060005b8251811015611dac576000611d58848381518110611cd857611cd86150a6565b6020908102919091010151610164546040516370a0823160e01b81526001600160a01b0391821660048201529116906370a0823190602401602060405180830381865afa158015611d2d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d519190615372565b8d8861370a565b9050828281518110611d6c57611d6c6150a6565b6020026020010151811015611d9b5780838381518110611d8e57611d8e6150a6565b6020026020010181815250505b50611da5816150bc565b9050611cb8565b506000875167ffffffffffffffff811115611dc957611dc9614860565b604051908082528060200260200182016040528015611df2578160200160208202803683370190505b50905060005b8851811015611eb657888181518110611e1357611e136150a6565b60209081029190910101516040516370a0823160e01b81526001600160a01b038f81166004830152909116906370a0823190602401602060405180830381865afa158015611e65573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e899190615372565b828281518110611e9b57611e9b6150a6565b6020908102919091010152611eaf816150bc565b9050611df8565b50600160005b8451811015611f4957838181518110611ed757611ed76150a6565b602002602001015160000315611f39578115611ef257600091505b611f3961016460009054906101000a90046001600160a01b03168f868481518110611f1f57611f1f6150a6565b6020026020010151888581518110610cfd57610cfd6150a6565b611f42816150bc565b9050611ebc565b508015611f8b5760405162461bcd60e51b815260206004820152601060248201526f32b6b83a3c903932b232b6b83a34b7b760811b60448201526064016109e1565b5060005b88518110156120cf576000898281518110611fac57611fac6150a6565b60200260200101516001600160a01b03166370a082318f6040518263ffffffff1660e01b8152600401611fee91906001600160a01b0391909116815260200190565b602060405180830381865afa15801561200b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061202f9190615372565b9050888281518110612043576120436150a6565b602002602001015183838151811061205d5761205d6150a6565b60200260200101518261207091906152c5565b10156120be5760405162461bcd60e51b815260206004820152601860248201527f726564656d7074696f6e2062656c6f77206d696e696d756d000000000000000060448201526064016109e1565b506120c8816150bc565b9050611f8f565b50505050505050505050505050565b60975460408051808201909152600581526427aba722a960d91b60208201526001600160a01b03909116906391d148549061211890615180565b336040516001600160e01b031960e085901b16815260048101929092526001600160a01b03166024820152604401602060405180830381865afa158015612163573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121879190614ee1565b6121a35760405162461bcd60e51b81526004016109e1906151a4565b670de0b6b3a7640000813510156121fc5760405162461bcd60e51b815260206004820152601c60248201527f726564656d7074696f6e20616d745261746520746f6f20736d616c6c0000000060448201526064016109e1565b6daf298d050e4395d69670b12b7f4160301b8135111561225e5760405162461bcd60e51b815260206004820152601a60248201527f726564656d7074696f6e20616d745261746520746f6f2062696700000000000060448201526064016109e1565b670de0b6b3a76400006122776040830160208401614992565b6001600160c01b031611156122ce5760405162461bcd60e51b815260206004820152601a60248201527f726564656d7074696f6e207063745261746520746f6f2062696700000000000060448201526064016109e1565b6122e56122da60cb5490565b61016b906000612f34565b6040517fae0adad2741496b9b813ff6121945ff13626d9b550f6d2852530d28a79051ac2906123199061016b9084906151cd565b60405180910390a18061016b6116e98282615214565b6001600160a01b038116600090815261012f602052604081205461091b565b600061118061236861235f60cb5490565b610167906137ed565b61016790613838565b60006060806000806000606060fb546000801b148015612391575060fc54155b6123d55760405162461bcd60e51b81526020600482015260156024820152741152540dcc4c8e88155b9a5b9a5d1a585b1a5e9959605a1b60448201526064016109e1565b6123dd613896565b6123e56138a5565b60408051600080825260208201909252600f60f81b9b939a50919850469750309650945092509050565b6101655433906001600160a01b0316811461245b5760405162461bcd60e51b815260206004820152600c60248201526b6675726e616365206f6e6c7960a01b60448201526064016109e1565b61246581836138b4565b6040518281527f12b02b431a920654430b36652724950afbd1e5279648b404790dbd036b1a58a79060200160405180910390a15050565b606060cd805461088490614ead565b6000806124b760cb5490565b90506124d16124c861016b836137ed565b61016b90613838565b9150818110156124df578091505b5090565b600033816124f182866128b8565b9050838110156125515760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b60648201526084016109e1565b610d518286868403612e10565b60003361091581858561324b565b610164546001600160a01b0316336001600160a01b0316146125a05760405162461bcd60e51b81526004016109e190615249565b61016454611261906001600160a01b0316826125bb60cb5490565b613092565b609760009054906101000a90046001600160a01b03166001600160a01b03166398f73e526040518163ffffffff1660e01b8152600401602060405180830381865afa158015612613573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126379190614ee1565b1561267f5760405162461bcd60e51b8152602060048201526018602482015277199c9bde995b881bdc881d1c98591a5b99c81c185d5cd95960421b60448201526064016109e1565b6101625460405163c3c5a54760e01b81526001600160a01b0383811660048301529091169063c3c5a54790602401602060405180830381865afa1580156126ca573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126ee9190614ee1565b61272f5760405162461bcd60e51b8152602060048201526012602482015271195c98cc8c081d5b9c9959da5cdd195c995960721b60448201526064016109e1565b610164546040516370a0823160e01b8152306004820152611261916001600160a01b0390811691908416906370a0823190602401602060405180830381865afa158015612780573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127a49190615372565b6001600160a01b03841691906139f4565b6112613382610921565b8342111561280f5760405162461bcd60e51b815260206004820152601d60248201527f45524332305065726d69743a206578706972656420646561646c696e6500000060448201526064016109e1565b60007f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c988888861283e8c613a24565b6040805160208101969096526001600160a01b0394851690860152929091166060840152608083015260a082015260c0810186905260e0016040516020818303038152906040528051906020012090506128a38861289b83613a4d565b868686613a7a565b610d2e888888612e10565b6112613382610d5c565b6001600160a01b03918216600090815260ca6020908152604080832093909416825291909152205490565b600054610100900460ff16158080156129035750600054600160ff909116105b8061291d5750303b15801561291d575060005460ff166001145b6129805760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b60648201526084016109e1565b6000805460ff1916600117905580156129a3576000805461ff0019166101001790555b60008890036129e15760405162461bcd60e51b815260206004820152600a6024820152696e616d6520656d70747960b01b60448201526064016109e1565b6000869003612a215760405162461bcd60e51b815260206004820152600c60248201526b73796d626f6c20656d70747960a01b60448201526064016109e1565b6000849003612a625760405162461bcd60e51b815260206004820152600d60248201526c6d616e6461746520656d70747960981b60448201526064016109e1565b612a6b8a613c1f565b612ade89898080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050604080516020601f8d018190048102820181019092528b815292508b91508a9081908401838280828437600092019190915250613cbd92505050565b612b1d89898080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250613cee92505050565b896001600160a01b031663979d7e866040518163ffffffff1660e01b8152600401602060405180830381865afa158015612b5b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b7f919061538b565b61016260006101000a8154816001600160a01b0302191690836001600160a01b03160217905550896001600160a01b0316632f2439b16040518163ffffffff1660e01b8152600401602060405180830381865afa158015612be4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c08919061538b565b61016360006101000a8154816001600160a01b0302191690836001600160a01b03160217905550896001600160a01b031663dc8af5f66040518163ffffffff1660e01b8152600401602060405180830381865afa158015612c6d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c91919061538b565b61016460006101000a8154816001600160a01b0302191690836001600160a01b03160217905550896001600160a01b031663656e96e16040518163ffffffff1660e01b8152600401602060405180830381865afa158015612cf6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d1a919061538b565b61016580546001600160a01b0319166001600160a01b0392909216919091179055610161612d498587836153f6565b50612d5383611498565b612d5c826120de565b610169805465ffffffffffff421665ffffffffffff19918216811790925561016d805490911690911790558015612dcd576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b50505050505050505050565b6101645433906001600160a01b03168114612e065760405162461bcd60e51b81526004016109e190615249565b6116e98183613401565b6001600160a01b038316612e725760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b60648201526084016109e1565b6001600160a01b038216612ed35760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b60648201526084016109e1565b6001600160a01b03838116600081815260ca602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b8254158015612f4e575060018301546001600160c01b0316155b15612f5857505050565b6000612f6484846137ed565b90506000612f728583613838565b9050846003015481141580612f8657508181145b15612fa75760028501805465ffffffffffff19164265ffffffffffff161790555b600083131561301157808311156130005760405162461bcd60e51b815260206004820152601760248201527f737570706c79206368616e6765207468726f74746c656400000000000000000060448201526064016109e1565b61300a83826152c5565b9050613030565b60008312156130305761302383614f19565b61302d908261516d565b90505b600390940193909355505050565b60006001600160c01b038211156124df5760405163f44398f560e01b815260040160405180910390fd5b6000613087613082866001600160c01b0316868686613d3c565b61303e565b90505b949350505050565b6000816000036130a257826130be565b610166546130be906001600160c01b0385811691859116613de9565b610166546001600160c01b0391821692507f0b0ca69be72e0611a1f79eedf91aece404ff14cb8fcfd0c997a72b68d4fdd47891166130fc85826154b6565b604080516001600160c01b0393841681529290911660208301520160405180910390a1610166805484919060009061313e9084906001600160c01b03166154b6565b92506101000a8154816001600160c01b0302191690836001600160c01b0316021790555061194f8482613df8565b6040516001600160a01b038085166024830152831660448201526064810182905261194f9085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152613ec5565b60006131e384846128b8565b9050600019811461194f578181101561323e5760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e636500000060448201526064016109e1565b61194f8484848403612e10565b6001600160a01b0383166132af5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b60648201526084016109e1565b6001600160a01b0382166133115760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b60648201526084016109e1565b61331c838383613f9a565b6001600160a01b038316600090815260c96020526040902054818110156133945760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b60648201526084016109e1565b6001600160a01b03808516600081815260c9602052604080822086860390559286168082529083902080548601905591517fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef906133f49086815260200190565b60405180910390a361194f565b60006134248261341060cb5490565b610166546001600160c01b03169190613de9565b610166549091507f0b0ca69be72e0611a1f79eedf91aece404ff14cb8fcfd0c997a72b68d4fdd478906001600160c01b031661346083826154d6565b604080516001600160c01b0393841681529290911660208301520160405180910390a161016680548291906000906134a29084906001600160c01b03166154d6565b92506101000a8154816001600160c01b0302191690836001600160c01b0316021790555061091b83836138b4565b6000611180613ff2565b60975460408051808201909152600581526427aba722a960d91b60208201526001600160a01b03909116906391d148549061351490615180565b336040516001600160e01b031960e085901b16815260048101929092526001600160a01b03166024820152604401602060405180830381865afa15801561355f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135839190614ee1565b6112615760405162461bcd60e51b81526004016109e1906151a4565b7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd91435460ff16156135d2576116e983614066565b826001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa92505050801561362c575060408051601f3d908101601f1916820190925261362991810190615372565b60015b61368f5760405162461bcd60e51b815260206004820152602e60248201527f45524331393637557067726164653a206e657720696d706c656d656e7461746960448201526d6f6e206973206e6f74205555505360901b60648201526084016109e1565b60008051602061568083398151915281146136fe5760405162461bcd60e51b815260206004820152602960248201527f45524331393637557067726164653a20756e737570706f727465642070726f786044820152681a58589b195555525160ba1b60648201526084016109e1565b506116e9838383614102565b60008060006137198686614127565b9150915083821061373d5760405163f44398f560e01b815260040160405180910390fd5b6000848061374d5761374d61528d565b868809905081811115613761576001830392505b90819003906000859003851680868161377c5761377c61528d565b04955080838161378e5761378e61528d565b0492508081600003816137a3576137a361528d565b046001019390930291909101600285810380870282030280870282030280870282030280870282030280870282030280870282030295860290039094029390930295945050505050565b60018201546000908390670de0b6b3a764000090613814906001600160c01b031685615276565b61381e91906152a3565b9150818160000154111561383157805491505b5092915050565b600282015460009081906138549065ffffffffffff16426154f6565b9050610e1061386b65ffffffffffff831685615276565b61387591906152a3565b8460030154613884919061516d565b91508282111561383157509092915050565b606060fd805461088490614ead565b606060fe805461088490614ead565b6001600160a01b0382166139145760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b60648201526084016109e1565b61392082600083613f9a565b6001600160a01b038216600090815260c96020526040902054818110156139945760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b60648201526084016109e1565b6001600160a01b038316600081815260c960209081526040808320868603905560cb80548790039055518581529192917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3505050565b6040516001600160a01b0383166024820152604481018290526116e990849063a9059cbb60e01b906064016131a0565b6001600160a01b038116600090815261012f602052604090208054600181018255905b50919050565b600061091b613a5a6134d0565b8360405161190160f01b8152600281019290925260228201526042902090565b6001600160a01b0385163b15613b8857604080516020810184905280820183905260f885901b6001600160f81b0319166060820152815160418183030181526061820192839052630b135d3f60e11b9092526001600160a01b03871691631626ba7e91613aeb918891606501615515565b602060405180830381865afa158015613b08573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613b2c919061552e565b6001600160e01b031916631626ba7e60e01b14613b835760405162461bcd60e51b8152602060048201526015602482015274115490cc4c8dcc4e88155b985d5d1a1bdc9a5e9959605a1b60448201526064016109e1565b613c18565b60408051602081018490529081018290526001600160f81b031960f885901b166060820152613bcc9086908690606101604051602081830303815290604052614154565b613c185760405162461bcd60e51b815260206004820152601e60248201527f45524332305065726d69743a20696e76616c6964207369676e6174757265000060448201526064016109e1565b5050505050565b600054610100900460ff16613c465760405162461bcd60e51b81526004016109e190615558565b6001600160a01b038116613c935760405162461bcd60e51b81526020600482015260146024820152736d61696e206973207a65726f206164647265737360601b60448201526064016109e1565b613c9b6141b5565b609780546001600160a01b0319166001600160a01b0392909216919091179055565b600054610100900460ff16613ce45760405162461bcd60e51b81526004016109e190615558565b6113e182826141de565b600054610100900460ff16613d155760405162461bcd60e51b81526004016109e190615558565b61126181604051806040016040528060058152602001640332e342e360dc1b81525061421e565b600080613d4a86868661370a565b90506000836002811115613d6057613d60614f35565b03613d6c57905061308a565b60008480613d7c57613d7c61528d565b86880990506002846002811115613d9557613d95614f35565b03613db3578015613dae57613dab60018361516d565b91505b613ddf565b6002613dc06001876152c5565b613dca91906152a3565b811115613ddf57613ddc60018361516d565b91505b5095945050505050565b600061308a8484846000613068565b6001600160a01b038216613e4e5760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f20616464726573730060448201526064016109e1565b613e5a60008383613f9a565b8060cb6000828254613e6c919061516d565b90915550506001600160a01b038216600081815260c960209081526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b6000613f1a826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661426d9092919063ffffffff16565b9050805160001480613f3b575080806020019051810190613f3b9190614ee1565b6116e95760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016109e1565b306001600160a01b038316036116e95760405162461bcd60e51b815260206004820152601760248201527f52546f6b656e207472616e7366657220746f2073656c6600000000000000000060448201526064016109e1565b60007f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f61401d61427c565b6140256142d5565b60408051602081019490945283019190915260608201524660808201523060a082015260c00160405160208183030381529060405280519060200120905090565b6001600160a01b0381163b6140d35760405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b60648201526084016109e1565b60008051602061568083398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b61410b83614306565b6000825111806141185750805b156116e95761194f8383614346565b600080806000198486099050838502915081810392508181101561414c576001830392505b509250929050565b60008060006141638585614372565b9092509050600081600481111561417c5761417c614f35565b14801561419a5750856001600160a01b0316826001600160a01b0316145b806141ab57506141ab8686866143b7565b9695505050505050565b600054610100900460ff166141dc5760405162461bcd60e51b81526004016109e190615558565b565b600054610100900460ff166142055760405162461bcd60e51b81526004016109e190615558565b60cc61421183826155a3565b5060cd6116e982826155a3565b600054610100900460ff166142455760405162461bcd60e51b81526004016109e190615558565b60fd61425183826155a3565b5060fe61425e82826155a3565b5050600060fb81905560fc5550565b606061308a84846000856144a3565b600080614287613896565b80519091501561429e578051602090910120919050565b60fb5480156142ad5792915050565b7fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a4709250505090565b6000806142e06138a5565b8051909150156142f7578051602090910120919050565b60fc5480156142ad5792915050565b61430f81614066565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a250565b606061436b83836040518060600160405280602781526020016156a06027913961457e565b9392505050565b60008082516041036143a85760208301516040840151606085015160001a61439c878285856145ec565b945094505050506143b0565b506000905060025b9250929050565b6000806000856001600160a01b0316631626ba7e60e01b86866040516024016143e1929190615515565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b031990941693909317909252905161441f9190615663565b600060405180830381855afa9150503d806000811461445a576040519150601f19603f3d011682016040523d82523d6000602084013e61445f565b606091505b509150915081801561447357506020815110155b80156141ab57508051630b135d3f60e11b906144989083016020908101908401615372565b149695505050505050565b6060824710156145045760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b60648201526084016109e1565b600080866001600160a01b031685876040516145209190615663565b60006040518083038185875af1925050503d806000811461455d576040519150601f19603f3d011682016040523d82523d6000602084013e614562565b606091505b5091509150614573878383876146b0565b979650505050505050565b6060600080856001600160a01b03168560405161459b9190615663565b600060405180830381855af49150503d80600081146145d6576040519150601f19603f3d011682016040523d82523d6000602084013e6145db565b606091505b50915091506141ab868383876146b0565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a083111561462357506000905060036146a7565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa158015614677573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b0381166146a0576000600192509250506146a7565b9150600090505b94509492505050565b6060831561471f578251600003614718576001600160a01b0385163b6147185760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016109e1565b508161308a565b61308a83838151156147345781518083602001fd5b8060405162461bcd60e51b81526004016109e1919061479e565b60005b83811015614769578181015183820152602001614751565b50506000910152565b6000815180845261478a81602086016020860161474e565b601f01601f19169290920160200192915050565b60208152600061436b6020830184614772565b6001600160a01b038116811461126157600080fd5b80356147d1816147b1565b919050565b600080604083850312156147e957600080fd5b82356147f4816147b1565b946020939093013593505050565b60008060006060848603121561481757600080fd5b8335614822816147b1565b92506020840135614832816147b1565b929592945050506040919091013590565b60006020828403121561485557600080fd5b813561436b816147b1565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff8111828210171561489f5761489f614860565b604052919050565b600080604083850312156148ba57600080fd5b82356148c5816147b1565b915060208381013567ffffffffffffffff808211156148e357600080fd5b818601915086601f8301126148f757600080fd5b81358181111561490957614909614860565b61491b601f8201601f19168501614876565b9150808252878482850101111561493157600080fd5b80848401858401376000848284010152508093505050509250929050565b600060408284031215613a4757600080fd5b60006040828403121561497357600080fd5b61436b838361494f565b6001600160c01b038116811461126157600080fd5b6000602082840312156149a457600080fd5b813561436b8161497d565b600067ffffffffffffffff8211156149c9576149c9614860565b5060051b60200190565b600082601f8301126149e457600080fd5b813560206149f96149f4836149af565b614876565b82815260059290921b84018101918181019086841115614a1857600080fd5b8286015b84811015614a4857803565ffffffffffff81168114614a3b5760008081fd5b8352918301918301614a1c565b509695505050505050565b600082601f830112614a6457600080fd5b81356020614a746149f4836149af565b82815260059290921b84018101918181019086841115614a9357600080fd5b8286015b84811015614a48578035614aaa8161497d565b8352918301918301614a97565b600082601f830112614ac857600080fd5b81356020614ad86149f4836149af565b82815260059290921b84018101918181019086841115614af757600080fd5b8286015b84811015614a48578035614b0e816147b1565b8352918301918301614afb565b600082601f830112614b2c57600080fd5b81356020614b3c6149f4836149af565b82815260059290921b84018101918181019086841115614b5b57600080fd5b8286015b84811015614a485780358352918301918301614b5f565b60008060008060008060c08789031215614b8f57600080fd5b614b98876147c6565b955060208701359450604087013567ffffffffffffffff80821115614bbc57600080fd5b614bc88a838b016149d3565b95506060890135915080821115614bde57600080fd5b614bea8a838b01614a53565b94506080890135915080821115614c0057600080fd5b614c0c8a838b01614ab7565b935060a0890135915080821115614c2257600080fd5b50614c2f89828a01614b1b565b9150509295509295509295565b60ff60f81b881681526000602060e081840152614c5c60e084018a614772565b8381036040850152614c6e818a614772565b606085018990526001600160a01b038816608086015260a0850187905284810360c0860152855180825283870192509083019060005b81811015614cc057835183529284019291840191600101614ca4565b50909c9b505050505050505050505050565b600060208284031215614ce457600080fd5b5035919050565b600080600080600080600060e0888a031215614d0657600080fd5b8735614d11816147b1565b96506020880135614d21816147b1565b95506040880135945060608801359350608088013560ff81168114614d4557600080fd5b9699959850939692959460a0840135945060c09093013592915050565b60008060408385031215614d7557600080fd5b8235614d80816147b1565b91506020830135614d90816147b1565b809150509250929050565b60008083601f840112614dad57600080fd5b50813567ffffffffffffffff811115614dc557600080fd5b6020830191508360208285010111156143b057600080fd5b60008060008060008060008060006101008a8c031215614dfc57600080fd5b8935614e07816147b1565b985060208a013567ffffffffffffffff80821115614e2457600080fd5b614e308d838e01614d9b565b909a50985060408c0135915080821115614e4957600080fd5b614e558d838e01614d9b565b909850965060608c0135915080821115614e6e57600080fd5b50614e7b8c828d01614d9b565b9095509350614e8f90508b60808c0161494f565b9150614e9e8b60c08c0161494f565b90509295985092959850929598565b600181811c90821680614ec157607f821691505b602082108103613a4757634e487b7160e01b600052602260045260246000fd5b600060208284031215614ef357600080fd5b8151801515811461436b57600080fd5b634e487b7160e01b600052601160045260246000fd5b6000600160ff1b8201614f2e57614f2e614f03565b5060000390565b634e487b7160e01b600052602160045260246000fd5b6001600160c01b03831681526040810160038310614f7957634e487b7160e01b600052602160045260246000fd5b8260208301529392505050565b600082601f830112614f9757600080fd5b81516020614fa76149f4836149af565b82815260059290921b84018101918181019086841115614fc657600080fd5b8286015b84811015614a485780518352918301918301614fca565b60008060408385031215614ff457600080fd5b825167ffffffffffffffff8082111561500c57600080fd5b818501915085601f83011261502057600080fd5b815160206150306149f4836149af565b82815260059290921b8401810191818101908984111561504f57600080fd5b948201945b83861015615076578551615067816147b1565b82529482019490820190615054565b9188015191965090935050508082111561508f57600080fd5b5061509c85828601614f86565b9150509250929050565b634e487b7160e01b600052603260045260246000fd5b6000600182016150ce576150ce614f03565b5060010190565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b19195b1959d85d1958d85b1b60a21b606082015260800190565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b6163746976652070726f787960a01b606082015260800190565b8082018082111561091b5761091b614f03565b80516020808301519190811015613a475760001960209190910360031b1b16919050565b6020808252600f908201526e676f7665726e616e6365206f6e6c7960881b604082015260600190565b8254815260018301546001600160c01b03908116602080840191909152833560408401526080830191908401356152038161497d565b818116606085015250509392505050565b8135815560018101602083013561522a8161497d565b81546001600160c01b0319166001600160c01b03919091161790555050565b6020808252601390820152723737ba103130b1b5b4b7339036b0b730b3b2b960691b604082015260600190565b808202811582820484141761091b5761091b614f03565b634e487b7160e01b600052601260045260246000fd5b6000826152c057634e487b7160e01b600052601260045260246000fd5b500490565b8181038181111561091b5761091b614f03565b606080825284519082018190526000906020906080840190828801845b8281101561531957815165ffffffffffff16845292840192908401906001016152f5565b5050508381038285015285518082528683019183019060005b818110156153575783516001600160c01b031683529284019291840191600101615332565b50506001600160c01b0386166040860152925061308a915050565b60006020828403121561538457600080fd5b5051919050565b60006020828403121561539d57600080fd5b815161436b816147b1565b601f8211156116e957600081815260208120601f850160051c810160208610156153cf5750805b601f850160051c820191505b818110156153ee578281556001016153db565b505050505050565b67ffffffffffffffff83111561540e5761540e614860565b6154228361541c8354614ead565b836153a8565b6000601f841160018114615456576000851561543e5750838201355b600019600387901b1c1916600186901b178355613c18565b600083815260209020601f19861690835b828110156154875786850135825560209485019460019092019101615467565b50868210156154a45760001960f88860031b161c19848701351681555b505060018560011b0183555050505050565b6001600160c01b0381811683821601908082111561383157613831614f03565b6001600160c01b0382811682821603908082111561383157613831614f03565b65ffffffffffff82811682821603908082111561383157613831614f03565b82815260406020820152600061308a6040830184614772565b60006020828403121561554057600080fd5b81516001600160e01b03198116811461436b57600080fd5b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b815167ffffffffffffffff8111156155bd576155bd614860565b6155d1816155cb8454614ead565b846153a8565b602080601f83116001811461560657600084156155ee5750858301515b600019600386901b1c1916600185901b1785556153ee565b600085815260208120601f198616915b8281101561563557888601518255948401946001909101908401615616565b50858210156156535787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b6000825161567581846020870161474e565b919091019291505056fe360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a2646970667358221220e118d7fc5a91259fd25aae3026a7f0addf30d763909d779e201f2f7cb0c69f3864736f6c63430008130033
Deployed Bytecode
0x6080604052600436106102675760003560e01c806372b8b05111610144578063aeb14bf6116100b6578063db006a751161007a578063db006a7514610778578063dd62ed3e14610798578063ddc95876146107b8578063dffeadd0146107fd578063f17d835c14610835578063f90b2bfe1461085557600080fd5b8063aeb14bf6146106e0578063b32deb3d14610700578063cc872b6614610720578063d505accf14610740578063d6122e921461076057600080fd5b80638e31ab2e116101085780638e31ab2e146105ec57806395d89b41146106515780639926020b14610666578063a16e15321461067b578063a457c2d7146106a0578063a9059cbb146106c057600080fd5b806372b8b0511461054f5780637ecebe001461056f5780637f2d27b91461058f57806384b0196e146105a45780638c83ed33146105cc57600080fd5b806339509351116101dd57806354fd4d50116101a157806354fd4d501461046a5780635beafb3d1461049857806363965449146104b85780636b2ba67d146104d857806370a08231146104f85780637121c2731461052e57600080fd5b806339509351146103ed57806339b1b96d1461040d5780634b35073f146104225780634f1ef2861461044257806352d1902d1461045557600080fd5b806323282f6e1161022f57806323282f6e1461032857806323b872dd1461035c5780632f7605fb1461037c578063313ce5671461039c5780633644e515146103b85780633659cfe6146103cd57600080fd5b806306fdde031461026c578063095ea7b3146102975780630b0e54d0146102c75780631207f0c1146102f157806318160ddd14610313575b600080fd5b34801561027857600080fd5b50610281610875565b60405161028e919061479e565b60405180910390f35b3480156102a357600080fd5b506102b76102b23660046147d6565b610907565b604051901515815260200161028e565b3480156102d357600080fd5b506102e3670de0b6b3a764000081565b60405190815260200161028e565b3480156102fd57600080fd5b5061031161030c3660046147d6565b610921565b005b34801561031f57600080fd5b5060cb546102e3565b34801561033457600080fd5b50610344670de0b6b3a764000081565b6040516001600160c01b03909116815260200161028e565b34801561036857600080fd5b506102b7610377366004614802565b610d38565b34801561038857600080fd5b506103116103973660046147d6565b610d5c565b3480156103a857600080fd5b506040516012815260200161028e565b3480156103c457600080fd5b506102e3611176565b3480156103d957600080fd5b506103116103e8366004614843565b611185565b3480156103f957600080fd5b506102b76104083660046147d6565b611264565b34801561041957600080fd5b50610281611286565b34801561042e57600080fd5b506103446b033b2e3c9fd0803ce800000081565b6103116104503660046148a7565b611315565b34801561046157600080fd5b506102e36113e5565b34801561047657600080fd5b506040805180820190915260058152640332e342e360dc1b6020820152610281565b3480156104a457600080fd5b506103116104b3366004614961565b611498565b3480156104c457600080fd5b506103116104d3366004614992565b6116ee565b3480156104e457600080fd5b506103116104f3366004614b76565b611955565b34801561050457600080fd5b506102e3610513366004614843565b6001600160a01b0316600090815260c9602052604090205490565b34801561053a57600080fd5b5061016654610344906001600160c01b031681565b34801561055b57600080fd5b5061031161056a366004614961565b6120de565b34801561057b57600080fd5b506102e361058a366004614843565b61232f565b34801561059b57600080fd5b506102e361234e565b3480156105b057600080fd5b506105b9612371565b60405161028e9796959493929190614c3c565b3480156105d857600080fd5b506103116105e7366004614cd2565b61240f565b3480156105f857600080fd5b506040805180820182526000808252602091820152815180830190925261016b54825261016c546001600160c01b0316908201525b60408051825181526020928301516001600160c01b0316928101929092520161028e565b34801561065d57600080fd5b5061028161249c565b34801561067257600080fd5b506102e36124ab565b34801561068757600080fd5b506102e36daf298d050e4395d69670b12b7f4160301b81565b3480156106ac57600080fd5b506102b76106bb3660046147d6565b6124e3565b3480156106cc57600080fd5b506102b76106db3660046147d6565b61255e565b3480156106ec57600080fd5b506103116106fb366004614992565b61256c565b34801561070c57600080fd5b5061031161071b366004614843565b6125c0565b34801561072c57600080fd5b5061031161073b366004614cd2565b6127b5565b34801561074c57600080fd5b5061031161075b366004614ceb565b6127bf565b34801561076c57600080fd5b50610344633b9aca0081565b34801561078457600080fd5b50610311610793366004614cd2565b6128ae565b3480156107a457600080fd5b506102e36107b3366004614d62565b6128b8565b3480156107c457600080fd5b5060408051808201825260008082526020918201528151808301909252610167548252610168546001600160c01b03169082015261062d565b34801561080957600080fd5b5060975461081d906001600160a01b031681565b6040516001600160a01b03909116815260200161028e565b34801561084157600080fd5b50610311610850366004614ddd565b6128e3565b34801561086157600080fd5b50610311610870366004614cd2565b612dd9565b606060cc805461088490614ead565b80601f01602080910402602001604051908101604052809291908181526020018280546108b090614ead565b80156108fd5780601f106108d2576101008083540402835291602001916108fd565b820191906000526020600020905b8154815290600101906020018083116108e057829003601f168201915b5050505050905090565b600033610915818585612e10565b60019150505b92915050565b609760009054906101000a90046001600160a01b03166001600160a01b03166375a8f9266040518163ffffffff1660e01b8152600401602060405180830381865afa158015610974573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109989190614ee1565b156109ea5760405162461bcd60e51b815260206004820152601960248201527f66726f7a656e206f722069737375616e6365207061757365640000000000000060448201526064015b60405180910390fd5b80600003610a2e5760405162461bcd60e51b815260206004820152601160248201527043616e6e6f74206973737565207a65726f60781b60448201526064016109e1565b61016260009054906101000a90046001600160a01b03166001600160a01b031663f8ac93e86040518163ffffffff1660e01b8152600401600060405180830381600087803b158015610a7f57600080fd5b505af1158015610a93573d6000803e3d6000fd5b505050506000610aa03390565b905061016360009054906101000a90046001600160a01b03166001600160a01b031663a094a0316040518163ffffffff1660e01b8152600401602060405180830381865afa158015610af6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b1a9190614ee1565b610b595760405162461bcd60e51b815260206004820152601060248201526f6261736b6574206e6f7420726561647960801b60448201526064016109e1565b6000610b6460cb5490565b9050610b736101678285612f34565b610b8a81610b8085614f19565b61016b9190612f34565b600081600003610ba257610b9d8461303e565b610bbc565b61016654610bbc906001600160c01b031685846002613068565b9050846001600160a01b0316836001600160a01b03167f93a73b97592126fd663d485c98f8a174c1d701035545e71ac88a05b71d6ad4ef8684604051610c159291909182526001600160c01b0316602082015260400190565b60405180910390a3610163546040516331883c3f60e21b815260009182916001600160a01b039091169063c620f0fc90610c56908690600290600401614f4b565b600060405180830381865afa158015610c73573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610c9b9190810190614fe1565b91509150610caa878486613092565b60005b8251811015610d2e57610d1e8661016460009054906101000a90046001600160a01b0316848481518110610ce357610ce36150a6565b6020026020010151868581518110610cfd57610cfd6150a6565b60200260200101516001600160a01b031661316c909392919063ffffffff16565b610d27816150bc565b9050610cad565b5050505050505050565b600033610d468582856131d7565b610d5185858561324b565b506001949350505050565b609760009054906101000a90046001600160a01b03166001600160a01b031663054f7d9c6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610daf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610dd39190614ee1565b15610e095760405162461bcd60e51b8152602060048201526006602482015265333937bd32b760d11b60448201526064016109e1565b61016260009054906101000a90046001600160a01b03166001600160a01b031663f8ac93e86040518163ffffffff1660e01b8152600401600060405180830381600087803b158015610e5a57600080fd5b505af1158015610e6e573d6000803e3d6000fd5b505050506000610e7b3390565b905081600003610ec25760405162461bcd60e51b815260206004820152601260248201527143616e6e6f742072656465656d207a65726f60701b60448201526064016109e1565b6001600160a01b038116600090815260c96020526040902054821115610f215760405162461bcd60e51b8152602060048201526014602482015273696e73756666696369656e742062616c616e636560601b60448201526064016109e1565b61016360009054906101000a90046001600160a01b03166001600160a01b031663e45a5b2d6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610f75573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f999190614ee1565b610ff15760405162461bcd60e51b8152602060048201526024808201527f7061727469616c20726564656d7074696f6e3b207573652072656465656d437560448201526373746f6d60e01b60648201526084016109e1565b6000610ffc60cb5490565b90506110158161100b85614f19565b6101679190612f34565b61102261016b8285612f34565b600061102e8385613401565b9050846001600160a01b0316836001600160a01b03167f49e15c2a707390f4ccf35ee268a61455f17aeb5b1983c01e1dd1f00b86a4725e86846040516110879291909182526001600160c01b0316602082015260400190565b60405180910390a3610163546040516331883c3f60e21b815260009182916001600160a01b039091169063c620f0fc906110c79086908590600401614f4b565b600060405180830381865afa1580156110e4573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261110c9190810190614fe1565b9150915060005b8251811015610d2e5781818151811061112e5761112e6150a6565b60200260200101516000031561116657610164548251611166916001600160a01b0316908a90859085908110610ce357610ce36150a6565b61116f816150bc565b9050611113565b60006111806134d0565b905090565b6001600160a01b037f000000000000000000000000784955641292b0014bc9ef82321300f0b6c7e36d1630036111cd5760405162461bcd60e51b81526004016109e1906150d5565b7f000000000000000000000000784955641292b0014bc9ef82321300f0b6c7e36d6001600160a01b0316611216600080516020615680833981519152546001600160a01b031690565b6001600160a01b03161461123c5760405162461bcd60e51b81526004016109e190615121565b611245816134da565b604080516000808252602082019092526112619183919061359f565b50565b60003361091581858561127783836128b8565b611281919061516d565b612e10565b610161805461129490614ead565b80601f01602080910402602001604051908101604052809291908181526020018280546112c090614ead565b801561130d5780601f106112e25761010080835404028352916020019161130d565b820191906000526020600020905b8154815290600101906020018083116112f057829003601f168201915b505050505081565b6001600160a01b037f000000000000000000000000784955641292b0014bc9ef82321300f0b6c7e36d16300361135d5760405162461bcd60e51b81526004016109e1906150d5565b7f000000000000000000000000784955641292b0014bc9ef82321300f0b6c7e36d6001600160a01b03166113a6600080516020615680833981519152546001600160a01b031690565b6001600160a01b0316146113cc5760405162461bcd60e51b81526004016109e190615121565b6113d5826134da565b6113e18282600161359f565b5050565b6000306001600160a01b037f000000000000000000000000784955641292b0014bc9ef82321300f0b6c7e36d16146114855760405162461bcd60e51b815260206004820152603860248201527f555550535570677261646561626c653a206d757374206e6f742062652063616c60448201527f6c6564207468726f7567682064656c656761746563616c6c000000000000000060648201526084016109e1565b5060008051602061568083398151915290565b60975460408051808201909152600581526427aba722a960d91b60208201526001600160a01b03909116906391d14854906114d290615180565b336040516001600160e01b031960e085901b16815260048101929092526001600160a01b03166024820152604401602060405180830381865afa15801561151d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115419190614ee1565b61155d5760405162461bcd60e51b81526004016109e1906151a4565b670de0b6b3a7640000813510156115b65760405162461bcd60e51b815260206004820152601a60248201527f69737375616e636520616d745261746520746f6f20736d616c6c00000000000060448201526064016109e1565b6daf298d050e4395d69670b12b7f4160301b813511156116185760405162461bcd60e51b815260206004820152601860248201527f69737375616e636520616d745261746520746f6f20626967000000000000000060448201526064016109e1565b670de0b6b3a76400006116316040830160208401614992565b6001600160c01b031611156116885760405162461bcd60e51b815260206004820152601860248201527f69737375616e6365207063745261746520746f6f20626967000000000000000060448201526064016109e1565b61169f61169460cb5490565b610167906000612f34565b6040517fa3e16a02f78ca4f5cf54ab43fd2cb34e5014ba4ec2e0cafb751203dcdd0aa827906116d3906101679084906151cd565b60405180910390a1806101676116e98282615214565b505050565b609760009054906101000a90046001600160a01b03166001600160a01b03166398f73e526040518163ffffffff1660e01b8152600401602060405180830381865afa158015611741573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117659190614ee1565b156117ad5760405162461bcd60e51b8152602060048201526018602482015277199c9bde995b881bdc881d1c98591a5b99c81c185d5cd95960421b60448201526064016109e1565b610164546001600160a01b0316336001600160a01b0316146117e15760405162461bcd60e51b81526004016109e190615249565b61016654604080516001600160c01b03928316815291831660208301527f0b0ca69be72e0611a1f79eedf91aece404ff14cb8fcfd0c997a72b68d4fdd478910160405180910390a161016680546001600160c01b0319166001600160c01b03831617905560cb54806000036118835760405162461bcd60e51b81526020600482015260086024820152673020737570706c7960c01b60448201526064016109e1565b6000816118a16001600160c01b038516670de0b6b3a7640000615276565b6118ab91906152a3565b90506000826118bb6001826152c5565b6118d66001600160c01b038716670de0b6b3a7640000615276565b6118e0919061516d565b6118ea91906152a3565b9050633b9aca00821080159061190c57506b033b2e3c9fd0803ce80000008111155b61194f5760405162461bcd60e51b815260206004820152601460248201527342552072617465206f7574206f662072616e676560601b60448201526064016109e1565b50505050565b609760009054906101000a90046001600160a01b03166001600160a01b031663054f7d9c6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156119a8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119cc9190614ee1565b15611a025760405162461bcd60e51b8152602060048201526006602482015265333937bd32b760d11b60448201526064016109e1565b61016260009054906101000a90046001600160a01b03166001600160a01b031663f8ac93e86040518163ffffffff1660e01b8152600401600060405180830381600087803b158015611a5357600080fd5b505af1158015611a67573d6000803e3d6000fd5b5050505084600003611ab05760405162461bcd60e51b815260206004820152601260248201527143616e6e6f742072656465656d207a65726f60701b60448201526064016109e1565b611ab933610513565b851115611aff5760405162461bcd60e51b8152602060048201526014602482015273696e73756666696369656e742062616c616e636560601b60448201526064016109e1565b6000805b8451811015611b4c57848181518110611b1e57611b1e6150a6565b60200260200101516001600160c01b031682611b3a919061516d565b9150611b45816150bc565b9050611b03565b50670de0b6b3a76400008114611bae5760405162461bcd60e51b815260206004820152602160248201527f706f7274696f6e7320646f206e6f742061646420757020746f204649585f4f4e6044820152604560f81b60648201526084016109e1565b6000611bb960cb5490565b9050611bc88161100b89614f19565b611bd561016b8289612f34565b6000611be13389613401565b604080518a81526001600160c01b03831660208201529192506001600160a01b038b169133917f49e15c2a707390f4ccf35ee268a61455f17aeb5b1983c01e1dd1f00b86a4725e910160405180910390a361016354604051630e3363af60e21b815260009182916001600160a01b03909116906338cd8ebc90611c6c908c908c9088906004016152d8565b600060405180830381865afa158015611c89573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611cb19190810190614fe1565b9150915060005b8251811015611dac576000611d58848381518110611cd857611cd86150a6565b6020908102919091010151610164546040516370a0823160e01b81526001600160a01b0391821660048201529116906370a0823190602401602060405180830381865afa158015611d2d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d519190615372565b8d8861370a565b9050828281518110611d6c57611d6c6150a6565b6020026020010151811015611d9b5780838381518110611d8e57611d8e6150a6565b6020026020010181815250505b50611da5816150bc565b9050611cb8565b506000875167ffffffffffffffff811115611dc957611dc9614860565b604051908082528060200260200182016040528015611df2578160200160208202803683370190505b50905060005b8851811015611eb657888181518110611e1357611e136150a6565b60209081029190910101516040516370a0823160e01b81526001600160a01b038f81166004830152909116906370a0823190602401602060405180830381865afa158015611e65573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e899190615372565b828281518110611e9b57611e9b6150a6565b6020908102919091010152611eaf816150bc565b9050611df8565b50600160005b8451811015611f4957838181518110611ed757611ed76150a6565b602002602001015160000315611f39578115611ef257600091505b611f3961016460009054906101000a90046001600160a01b03168f868481518110611f1f57611f1f6150a6565b6020026020010151888581518110610cfd57610cfd6150a6565b611f42816150bc565b9050611ebc565b508015611f8b5760405162461bcd60e51b815260206004820152601060248201526f32b6b83a3c903932b232b6b83a34b7b760811b60448201526064016109e1565b5060005b88518110156120cf576000898281518110611fac57611fac6150a6565b60200260200101516001600160a01b03166370a082318f6040518263ffffffff1660e01b8152600401611fee91906001600160a01b0391909116815260200190565b602060405180830381865afa15801561200b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061202f9190615372565b9050888281518110612043576120436150a6565b602002602001015183838151811061205d5761205d6150a6565b60200260200101518261207091906152c5565b10156120be5760405162461bcd60e51b815260206004820152601860248201527f726564656d7074696f6e2062656c6f77206d696e696d756d000000000000000060448201526064016109e1565b506120c8816150bc565b9050611f8f565b50505050505050505050505050565b60975460408051808201909152600581526427aba722a960d91b60208201526001600160a01b03909116906391d148549061211890615180565b336040516001600160e01b031960e085901b16815260048101929092526001600160a01b03166024820152604401602060405180830381865afa158015612163573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121879190614ee1565b6121a35760405162461bcd60e51b81526004016109e1906151a4565b670de0b6b3a7640000813510156121fc5760405162461bcd60e51b815260206004820152601c60248201527f726564656d7074696f6e20616d745261746520746f6f20736d616c6c0000000060448201526064016109e1565b6daf298d050e4395d69670b12b7f4160301b8135111561225e5760405162461bcd60e51b815260206004820152601a60248201527f726564656d7074696f6e20616d745261746520746f6f2062696700000000000060448201526064016109e1565b670de0b6b3a76400006122776040830160208401614992565b6001600160c01b031611156122ce5760405162461bcd60e51b815260206004820152601a60248201527f726564656d7074696f6e207063745261746520746f6f2062696700000000000060448201526064016109e1565b6122e56122da60cb5490565b61016b906000612f34565b6040517fae0adad2741496b9b813ff6121945ff13626d9b550f6d2852530d28a79051ac2906123199061016b9084906151cd565b60405180910390a18061016b6116e98282615214565b6001600160a01b038116600090815261012f602052604081205461091b565b600061118061236861235f60cb5490565b610167906137ed565b61016790613838565b60006060806000806000606060fb546000801b148015612391575060fc54155b6123d55760405162461bcd60e51b81526020600482015260156024820152741152540dcc4c8e88155b9a5b9a5d1a585b1a5e9959605a1b60448201526064016109e1565b6123dd613896565b6123e56138a5565b60408051600080825260208201909252600f60f81b9b939a50919850469750309650945092509050565b6101655433906001600160a01b0316811461245b5760405162461bcd60e51b815260206004820152600c60248201526b6675726e616365206f6e6c7960a01b60448201526064016109e1565b61246581836138b4565b6040518281527f12b02b431a920654430b36652724950afbd1e5279648b404790dbd036b1a58a79060200160405180910390a15050565b606060cd805461088490614ead565b6000806124b760cb5490565b90506124d16124c861016b836137ed565b61016b90613838565b9150818110156124df578091505b5090565b600033816124f182866128b8565b9050838110156125515760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b60648201526084016109e1565b610d518286868403612e10565b60003361091581858561324b565b610164546001600160a01b0316336001600160a01b0316146125a05760405162461bcd60e51b81526004016109e190615249565b61016454611261906001600160a01b0316826125bb60cb5490565b613092565b609760009054906101000a90046001600160a01b03166001600160a01b03166398f73e526040518163ffffffff1660e01b8152600401602060405180830381865afa158015612613573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126379190614ee1565b1561267f5760405162461bcd60e51b8152602060048201526018602482015277199c9bde995b881bdc881d1c98591a5b99c81c185d5cd95960421b60448201526064016109e1565b6101625460405163c3c5a54760e01b81526001600160a01b0383811660048301529091169063c3c5a54790602401602060405180830381865afa1580156126ca573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126ee9190614ee1565b61272f5760405162461bcd60e51b8152602060048201526012602482015271195c98cc8c081d5b9c9959da5cdd195c995960721b60448201526064016109e1565b610164546040516370a0823160e01b8152306004820152611261916001600160a01b0390811691908416906370a0823190602401602060405180830381865afa158015612780573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127a49190615372565b6001600160a01b03841691906139f4565b6112613382610921565b8342111561280f5760405162461bcd60e51b815260206004820152601d60248201527f45524332305065726d69743a206578706972656420646561646c696e6500000060448201526064016109e1565b60007f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c988888861283e8c613a24565b6040805160208101969096526001600160a01b0394851690860152929091166060840152608083015260a082015260c0810186905260e0016040516020818303038152906040528051906020012090506128a38861289b83613a4d565b868686613a7a565b610d2e888888612e10565b6112613382610d5c565b6001600160a01b03918216600090815260ca6020908152604080832093909416825291909152205490565b600054610100900460ff16158080156129035750600054600160ff909116105b8061291d5750303b15801561291d575060005460ff166001145b6129805760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b60648201526084016109e1565b6000805460ff1916600117905580156129a3576000805461ff0019166101001790555b60008890036129e15760405162461bcd60e51b815260206004820152600a6024820152696e616d6520656d70747960b01b60448201526064016109e1565b6000869003612a215760405162461bcd60e51b815260206004820152600c60248201526b73796d626f6c20656d70747960a01b60448201526064016109e1565b6000849003612a625760405162461bcd60e51b815260206004820152600d60248201526c6d616e6461746520656d70747960981b60448201526064016109e1565b612a6b8a613c1f565b612ade89898080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050604080516020601f8d018190048102820181019092528b815292508b91508a9081908401838280828437600092019190915250613cbd92505050565b612b1d89898080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250613cee92505050565b896001600160a01b031663979d7e866040518163ffffffff1660e01b8152600401602060405180830381865afa158015612b5b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b7f919061538b565b61016260006101000a8154816001600160a01b0302191690836001600160a01b03160217905550896001600160a01b0316632f2439b16040518163ffffffff1660e01b8152600401602060405180830381865afa158015612be4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c08919061538b565b61016360006101000a8154816001600160a01b0302191690836001600160a01b03160217905550896001600160a01b031663dc8af5f66040518163ffffffff1660e01b8152600401602060405180830381865afa158015612c6d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c91919061538b565b61016460006101000a8154816001600160a01b0302191690836001600160a01b03160217905550896001600160a01b031663656e96e16040518163ffffffff1660e01b8152600401602060405180830381865afa158015612cf6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d1a919061538b565b61016580546001600160a01b0319166001600160a01b0392909216919091179055610161612d498587836153f6565b50612d5383611498565b612d5c826120de565b610169805465ffffffffffff421665ffffffffffff19918216811790925561016d805490911690911790558015612dcd576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b50505050505050505050565b6101645433906001600160a01b03168114612e065760405162461bcd60e51b81526004016109e190615249565b6116e98183613401565b6001600160a01b038316612e725760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b60648201526084016109e1565b6001600160a01b038216612ed35760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b60648201526084016109e1565b6001600160a01b03838116600081815260ca602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b8254158015612f4e575060018301546001600160c01b0316155b15612f5857505050565b6000612f6484846137ed565b90506000612f728583613838565b9050846003015481141580612f8657508181145b15612fa75760028501805465ffffffffffff19164265ffffffffffff161790555b600083131561301157808311156130005760405162461bcd60e51b815260206004820152601760248201527f737570706c79206368616e6765207468726f74746c656400000000000000000060448201526064016109e1565b61300a83826152c5565b9050613030565b60008312156130305761302383614f19565b61302d908261516d565b90505b600390940193909355505050565b60006001600160c01b038211156124df5760405163f44398f560e01b815260040160405180910390fd5b6000613087613082866001600160c01b0316868686613d3c565b61303e565b90505b949350505050565b6000816000036130a257826130be565b610166546130be906001600160c01b0385811691859116613de9565b610166546001600160c01b0391821692507f0b0ca69be72e0611a1f79eedf91aece404ff14cb8fcfd0c997a72b68d4fdd47891166130fc85826154b6565b604080516001600160c01b0393841681529290911660208301520160405180910390a1610166805484919060009061313e9084906001600160c01b03166154b6565b92506101000a8154816001600160c01b0302191690836001600160c01b0316021790555061194f8482613df8565b6040516001600160a01b038085166024830152831660448201526064810182905261194f9085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152613ec5565b60006131e384846128b8565b9050600019811461194f578181101561323e5760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e636500000060448201526064016109e1565b61194f8484848403612e10565b6001600160a01b0383166132af5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b60648201526084016109e1565b6001600160a01b0382166133115760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b60648201526084016109e1565b61331c838383613f9a565b6001600160a01b038316600090815260c96020526040902054818110156133945760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b60648201526084016109e1565b6001600160a01b03808516600081815260c9602052604080822086860390559286168082529083902080548601905591517fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef906133f49086815260200190565b60405180910390a361194f565b60006134248261341060cb5490565b610166546001600160c01b03169190613de9565b610166549091507f0b0ca69be72e0611a1f79eedf91aece404ff14cb8fcfd0c997a72b68d4fdd478906001600160c01b031661346083826154d6565b604080516001600160c01b0393841681529290911660208301520160405180910390a161016680548291906000906134a29084906001600160c01b03166154d6565b92506101000a8154816001600160c01b0302191690836001600160c01b0316021790555061091b83836138b4565b6000611180613ff2565b60975460408051808201909152600581526427aba722a960d91b60208201526001600160a01b03909116906391d148549061351490615180565b336040516001600160e01b031960e085901b16815260048101929092526001600160a01b03166024820152604401602060405180830381865afa15801561355f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135839190614ee1565b6112615760405162461bcd60e51b81526004016109e1906151a4565b7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd91435460ff16156135d2576116e983614066565b826001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa92505050801561362c575060408051601f3d908101601f1916820190925261362991810190615372565b60015b61368f5760405162461bcd60e51b815260206004820152602e60248201527f45524331393637557067726164653a206e657720696d706c656d656e7461746960448201526d6f6e206973206e6f74205555505360901b60648201526084016109e1565b60008051602061568083398151915281146136fe5760405162461bcd60e51b815260206004820152602960248201527f45524331393637557067726164653a20756e737570706f727465642070726f786044820152681a58589b195555525160ba1b60648201526084016109e1565b506116e9838383614102565b60008060006137198686614127565b9150915083821061373d5760405163f44398f560e01b815260040160405180910390fd5b6000848061374d5761374d61528d565b868809905081811115613761576001830392505b90819003906000859003851680868161377c5761377c61528d565b04955080838161378e5761378e61528d565b0492508081600003816137a3576137a361528d565b046001019390930291909101600285810380870282030280870282030280870282030280870282030280870282030280870282030295860290039094029390930295945050505050565b60018201546000908390670de0b6b3a764000090613814906001600160c01b031685615276565b61381e91906152a3565b9150818160000154111561383157805491505b5092915050565b600282015460009081906138549065ffffffffffff16426154f6565b9050610e1061386b65ffffffffffff831685615276565b61387591906152a3565b8460030154613884919061516d565b91508282111561383157509092915050565b606060fd805461088490614ead565b606060fe805461088490614ead565b6001600160a01b0382166139145760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b60648201526084016109e1565b61392082600083613f9a565b6001600160a01b038216600090815260c96020526040902054818110156139945760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b60648201526084016109e1565b6001600160a01b038316600081815260c960209081526040808320868603905560cb80548790039055518581529192917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3505050565b6040516001600160a01b0383166024820152604481018290526116e990849063a9059cbb60e01b906064016131a0565b6001600160a01b038116600090815261012f602052604090208054600181018255905b50919050565b600061091b613a5a6134d0565b8360405161190160f01b8152600281019290925260228201526042902090565b6001600160a01b0385163b15613b8857604080516020810184905280820183905260f885901b6001600160f81b0319166060820152815160418183030181526061820192839052630b135d3f60e11b9092526001600160a01b03871691631626ba7e91613aeb918891606501615515565b602060405180830381865afa158015613b08573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613b2c919061552e565b6001600160e01b031916631626ba7e60e01b14613b835760405162461bcd60e51b8152602060048201526015602482015274115490cc4c8dcc4e88155b985d5d1a1bdc9a5e9959605a1b60448201526064016109e1565b613c18565b60408051602081018490529081018290526001600160f81b031960f885901b166060820152613bcc9086908690606101604051602081830303815290604052614154565b613c185760405162461bcd60e51b815260206004820152601e60248201527f45524332305065726d69743a20696e76616c6964207369676e6174757265000060448201526064016109e1565b5050505050565b600054610100900460ff16613c465760405162461bcd60e51b81526004016109e190615558565b6001600160a01b038116613c935760405162461bcd60e51b81526020600482015260146024820152736d61696e206973207a65726f206164647265737360601b60448201526064016109e1565b613c9b6141b5565b609780546001600160a01b0319166001600160a01b0392909216919091179055565b600054610100900460ff16613ce45760405162461bcd60e51b81526004016109e190615558565b6113e182826141de565b600054610100900460ff16613d155760405162461bcd60e51b81526004016109e190615558565b61126181604051806040016040528060058152602001640332e342e360dc1b81525061421e565b600080613d4a86868661370a565b90506000836002811115613d6057613d60614f35565b03613d6c57905061308a565b60008480613d7c57613d7c61528d565b86880990506002846002811115613d9557613d95614f35565b03613db3578015613dae57613dab60018361516d565b91505b613ddf565b6002613dc06001876152c5565b613dca91906152a3565b811115613ddf57613ddc60018361516d565b91505b5095945050505050565b600061308a8484846000613068565b6001600160a01b038216613e4e5760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f20616464726573730060448201526064016109e1565b613e5a60008383613f9a565b8060cb6000828254613e6c919061516d565b90915550506001600160a01b038216600081815260c960209081526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b6000613f1a826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661426d9092919063ffffffff16565b9050805160001480613f3b575080806020019051810190613f3b9190614ee1565b6116e95760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016109e1565b306001600160a01b038316036116e95760405162461bcd60e51b815260206004820152601760248201527f52546f6b656e207472616e7366657220746f2073656c6600000000000000000060448201526064016109e1565b60007f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f61401d61427c565b6140256142d5565b60408051602081019490945283019190915260608201524660808201523060a082015260c00160405160208183030381529060405280519060200120905090565b6001600160a01b0381163b6140d35760405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b60648201526084016109e1565b60008051602061568083398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b61410b83614306565b6000825111806141185750805b156116e95761194f8383614346565b600080806000198486099050838502915081810392508181101561414c576001830392505b509250929050565b60008060006141638585614372565b9092509050600081600481111561417c5761417c614f35565b14801561419a5750856001600160a01b0316826001600160a01b0316145b806141ab57506141ab8686866143b7565b9695505050505050565b600054610100900460ff166141dc5760405162461bcd60e51b81526004016109e190615558565b565b600054610100900460ff166142055760405162461bcd60e51b81526004016109e190615558565b60cc61421183826155a3565b5060cd6116e982826155a3565b600054610100900460ff166142455760405162461bcd60e51b81526004016109e190615558565b60fd61425183826155a3565b5060fe61425e82826155a3565b5050600060fb81905560fc5550565b606061308a84846000856144a3565b600080614287613896565b80519091501561429e578051602090910120919050565b60fb5480156142ad5792915050565b7fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a4709250505090565b6000806142e06138a5565b8051909150156142f7578051602090910120919050565b60fc5480156142ad5792915050565b61430f81614066565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a250565b606061436b83836040518060600160405280602781526020016156a06027913961457e565b9392505050565b60008082516041036143a85760208301516040840151606085015160001a61439c878285856145ec565b945094505050506143b0565b506000905060025b9250929050565b6000806000856001600160a01b0316631626ba7e60e01b86866040516024016143e1929190615515565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b031990941693909317909252905161441f9190615663565b600060405180830381855afa9150503d806000811461445a576040519150601f19603f3d011682016040523d82523d6000602084013e61445f565b606091505b509150915081801561447357506020815110155b80156141ab57508051630b135d3f60e11b906144989083016020908101908401615372565b149695505050505050565b6060824710156145045760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b60648201526084016109e1565b600080866001600160a01b031685876040516145209190615663565b60006040518083038185875af1925050503d806000811461455d576040519150601f19603f3d011682016040523d82523d6000602084013e614562565b606091505b5091509150614573878383876146b0565b979650505050505050565b6060600080856001600160a01b03168560405161459b9190615663565b600060405180830381855af49150503d80600081146145d6576040519150601f19603f3d011682016040523d82523d6000602084013e6145db565b606091505b50915091506141ab868383876146b0565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a083111561462357506000905060036146a7565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa158015614677573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b0381166146a0576000600192509250506146a7565b9150600090505b94509492505050565b6060831561471f578251600003614718576001600160a01b0385163b6147185760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016109e1565b508161308a565b61308a83838151156147345781518083602001fd5b8060405162461bcd60e51b81526004016109e1919061479e565b60005b83811015614769578181015183820152602001614751565b50506000910152565b6000815180845261478a81602086016020860161474e565b601f01601f19169290920160200192915050565b60208152600061436b6020830184614772565b6001600160a01b038116811461126157600080fd5b80356147d1816147b1565b919050565b600080604083850312156147e957600080fd5b82356147f4816147b1565b946020939093013593505050565b60008060006060848603121561481757600080fd5b8335614822816147b1565b92506020840135614832816147b1565b929592945050506040919091013590565b60006020828403121561485557600080fd5b813561436b816147b1565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff8111828210171561489f5761489f614860565b604052919050565b600080604083850312156148ba57600080fd5b82356148c5816147b1565b915060208381013567ffffffffffffffff808211156148e357600080fd5b818601915086601f8301126148f757600080fd5b81358181111561490957614909614860565b61491b601f8201601f19168501614876565b9150808252878482850101111561493157600080fd5b80848401858401376000848284010152508093505050509250929050565b600060408284031215613a4757600080fd5b60006040828403121561497357600080fd5b61436b838361494f565b6001600160c01b038116811461126157600080fd5b6000602082840312156149a457600080fd5b813561436b8161497d565b600067ffffffffffffffff8211156149c9576149c9614860565b5060051b60200190565b600082601f8301126149e457600080fd5b813560206149f96149f4836149af565b614876565b82815260059290921b84018101918181019086841115614a1857600080fd5b8286015b84811015614a4857803565ffffffffffff81168114614a3b5760008081fd5b8352918301918301614a1c565b509695505050505050565b600082601f830112614a6457600080fd5b81356020614a746149f4836149af565b82815260059290921b84018101918181019086841115614a9357600080fd5b8286015b84811015614a48578035614aaa8161497d565b8352918301918301614a97565b600082601f830112614ac857600080fd5b81356020614ad86149f4836149af565b82815260059290921b84018101918181019086841115614af757600080fd5b8286015b84811015614a48578035614b0e816147b1565b8352918301918301614afb565b600082601f830112614b2c57600080fd5b81356020614b3c6149f4836149af565b82815260059290921b84018101918181019086841115614b5b57600080fd5b8286015b84811015614a485780358352918301918301614b5f565b60008060008060008060c08789031215614b8f57600080fd5b614b98876147c6565b955060208701359450604087013567ffffffffffffffff80821115614bbc57600080fd5b614bc88a838b016149d3565b95506060890135915080821115614bde57600080fd5b614bea8a838b01614a53565b94506080890135915080821115614c0057600080fd5b614c0c8a838b01614ab7565b935060a0890135915080821115614c2257600080fd5b50614c2f89828a01614b1b565b9150509295509295509295565b60ff60f81b881681526000602060e081840152614c5c60e084018a614772565b8381036040850152614c6e818a614772565b606085018990526001600160a01b038816608086015260a0850187905284810360c0860152855180825283870192509083019060005b81811015614cc057835183529284019291840191600101614ca4565b50909c9b505050505050505050505050565b600060208284031215614ce457600080fd5b5035919050565b600080600080600080600060e0888a031215614d0657600080fd5b8735614d11816147b1565b96506020880135614d21816147b1565b95506040880135945060608801359350608088013560ff81168114614d4557600080fd5b9699959850939692959460a0840135945060c09093013592915050565b60008060408385031215614d7557600080fd5b8235614d80816147b1565b91506020830135614d90816147b1565b809150509250929050565b60008083601f840112614dad57600080fd5b50813567ffffffffffffffff811115614dc557600080fd5b6020830191508360208285010111156143b057600080fd5b60008060008060008060008060006101008a8c031215614dfc57600080fd5b8935614e07816147b1565b985060208a013567ffffffffffffffff80821115614e2457600080fd5b614e308d838e01614d9b565b909a50985060408c0135915080821115614e4957600080fd5b614e558d838e01614d9b565b909850965060608c0135915080821115614e6e57600080fd5b50614e7b8c828d01614d9b565b9095509350614e8f90508b60808c0161494f565b9150614e9e8b60c08c0161494f565b90509295985092959850929598565b600181811c90821680614ec157607f821691505b602082108103613a4757634e487b7160e01b600052602260045260246000fd5b600060208284031215614ef357600080fd5b8151801515811461436b57600080fd5b634e487b7160e01b600052601160045260246000fd5b6000600160ff1b8201614f2e57614f2e614f03565b5060000390565b634e487b7160e01b600052602160045260246000fd5b6001600160c01b03831681526040810160038310614f7957634e487b7160e01b600052602160045260246000fd5b8260208301529392505050565b600082601f830112614f9757600080fd5b81516020614fa76149f4836149af565b82815260059290921b84018101918181019086841115614fc657600080fd5b8286015b84811015614a485780518352918301918301614fca565b60008060408385031215614ff457600080fd5b825167ffffffffffffffff8082111561500c57600080fd5b818501915085601f83011261502057600080fd5b815160206150306149f4836149af565b82815260059290921b8401810191818101908984111561504f57600080fd5b948201945b83861015615076578551615067816147b1565b82529482019490820190615054565b9188015191965090935050508082111561508f57600080fd5b5061509c85828601614f86565b9150509250929050565b634e487b7160e01b600052603260045260246000fd5b6000600182016150ce576150ce614f03565b5060010190565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b19195b1959d85d1958d85b1b60a21b606082015260800190565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b6163746976652070726f787960a01b606082015260800190565b8082018082111561091b5761091b614f03565b80516020808301519190811015613a475760001960209190910360031b1b16919050565b6020808252600f908201526e676f7665726e616e6365206f6e6c7960881b604082015260600190565b8254815260018301546001600160c01b03908116602080840191909152833560408401526080830191908401356152038161497d565b818116606085015250509392505050565b8135815560018101602083013561522a8161497d565b81546001600160c01b0319166001600160c01b03919091161790555050565b6020808252601390820152723737ba103130b1b5b4b7339036b0b730b3b2b960691b604082015260600190565b808202811582820484141761091b5761091b614f03565b634e487b7160e01b600052601260045260246000fd5b6000826152c057634e487b7160e01b600052601260045260246000fd5b500490565b8181038181111561091b5761091b614f03565b606080825284519082018190526000906020906080840190828801845b8281101561531957815165ffffffffffff16845292840192908401906001016152f5565b5050508381038285015285518082528683019183019060005b818110156153575783516001600160c01b031683529284019291840191600101615332565b50506001600160c01b0386166040860152925061308a915050565b60006020828403121561538457600080fd5b5051919050565b60006020828403121561539d57600080fd5b815161436b816147b1565b601f8211156116e957600081815260208120601f850160051c810160208610156153cf5750805b601f850160051c820191505b818110156153ee578281556001016153db565b505050505050565b67ffffffffffffffff83111561540e5761540e614860565b6154228361541c8354614ead565b836153a8565b6000601f841160018114615456576000851561543e5750838201355b600019600387901b1c1916600186901b178355613c18565b600083815260209020601f19861690835b828110156154875786850135825560209485019460019092019101615467565b50868210156154a45760001960f88860031b161c19848701351681555b505060018560011b0183555050505050565b6001600160c01b0381811683821601908082111561383157613831614f03565b6001600160c01b0382811682821603908082111561383157613831614f03565b65ffffffffffff82811682821603908082111561383157613831614f03565b82815260406020820152600061308a6040830184614772565b60006020828403121561554057600080fd5b81516001600160e01b03198116811461436b57600080fd5b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b815167ffffffffffffffff8111156155bd576155bd614860565b6155d1816155cb8454614ead565b846153a8565b602080601f83116001811461560657600084156155ee5750858301515b600019600386901b1c1916600185901b1785556153ee565b600085815260208120601f198616915b8281101561563557888601518255948401946001909101908401615616565b50858210156156535787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b6000825161567581846020870161474e565b919091019291505056fe360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a2646970667358221220e118d7fc5a91259fd25aae3026a7f0addf30d763909d779e201f2f7cb0c69f3864736f6c63430008130033
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in ETH
0
Multichain Portfolio | 34 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.