Source Code
Overview
HYPE Balance
HYPE Value
$0.00View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Cross-Chain Transactions
Loading...
Loading
Contract Name:
Getters
Compiler Version
v0.8.28+commit.7893614a
Optimization Enabled:
Yes with 1000 runs
Other Settings:
cancun EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
import { IGetters } from "contracts/interfaces/IGetters.sol";
import { LibOracle } from "../libraries/LibOracle.sol";
import { LibGetters } from "../libraries/LibGetters.sol";
import { LibStorage as s } from "../libraries/LibStorage.sol";
import { LibWhitelist } from "../libraries/LibWhitelist.sol";
import "../../utils/Constants.sol";
import "../../utils/Errors.sol";
import "../Storage.sol";
/// @title Getters
/// @author Cooper Labs
/// @custom:contact [email protected]
/// @dev There may be duplicates in the info provided by the getters defined here
/// @dev This contract is an authorized fork of Angle's `Getters` contract
/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/parallelizer/facets/Getters.sol
contract Getters is IGetters {
/// @inheritdoc IGetters
function isValidSelector(bytes4 selector) external view returns (bool) {
return s.diamondStorage().selectorInfo[selector].facetAddress != address(0);
}
/// @inheritdoc IGetters
function tokenP() external view returns (ITokenP) {
return s.transmuterStorage().tokenP;
}
/// @inheritdoc IGetters
function getCollateralList() external view returns (address[] memory) {
return s.transmuterStorage().collateralList;
}
/// @inheritdoc IGetters
function getCollateralInfo(address collateral) external view returns (Collateral memory) {
return s.transmuterStorage().collaterals[collateral];
}
/// @inheritdoc IGetters
function getCollateralDecimals(address collateral) external view returns (uint8) {
return s.transmuterStorage().collaterals[collateral].decimals;
}
/// @inheritdoc IGetters
function getCollateralMintFees(address collateral)
external
view
returns (uint64[] memory xFeeMint, int64[] memory yFeeMint)
{
Collateral storage collatInfo = s.transmuterStorage().collaterals[collateral];
return (collatInfo.xFeeMint, collatInfo.yFeeMint);
}
/// @inheritdoc IGetters
function getCollateralBurnFees(address collateral)
external
view
returns (uint64[] memory xFeeBurn, int64[] memory yFeeBurn)
{
Collateral storage collatInfo = s.transmuterStorage().collaterals[collateral];
return (collatInfo.xFeeBurn, collatInfo.yFeeBurn);
}
/// @inheritdoc IGetters
function getRedemptionFees()
external
view
returns (uint64[] memory xRedemptionCurve, int64[] memory yRedemptionCurve)
{
ParallelizerStorage storage ts = s.transmuterStorage();
return (ts.xRedemptionCurve, ts.yRedemptionCurve);
}
/// @inheritdoc IGetters
/// @dev This function may revert and overflow if the collateral ratio is too big due to a too small
/// amount of `stablecoinsIssued`. Due to this, it is recommended to initialize the system with a non
/// negligible amount of `stablecoinsIssued` so DoS attacks on redemptions which use this function
/// become economically impossible
function getCollateralRatio() external view returns (uint64 collatRatio, uint256 stablecoinsIssued) {
ParallelizerStorage storage ts = s.transmuterStorage();
// Reentrant protection
if (ts.statusReentrant == ENTERED) revert ReentrantCall();
(collatRatio, stablecoinsIssued,,,) = LibGetters.getCollateralRatio();
}
/// @inheritdoc IGetters
function getIssuedByCollateral(address collateral)
external
view
returns (uint256 stablecoinsFromCollateral, uint256 stablecoinsIssued)
{
ParallelizerStorage storage ts = s.transmuterStorage();
uint256 _normalizer = ts.normalizer;
return (
(uint256(ts.collaterals[collateral].normalizedStables) * _normalizer) / BASE_27,
(uint256(ts.normalizedStables) * _normalizer) / BASE_27
);
}
/// @inheritdoc IGetters
function getTotalIssued() external view returns (uint256) {
ParallelizerStorage storage ts = s.transmuterStorage();
return (uint256(ts.normalizedStables) * uint256(ts.normalizer)) / BASE_27;
}
/// @inheritdoc IGetters
function getManagerData(address collateral) external view returns (bool, IERC20[] memory, bytes memory) {
Collateral storage collatInfo = s.transmuterStorage().collaterals[collateral];
if (collatInfo.isManaged > 0) {
return (true, collatInfo.managerData.subCollaterals, collatInfo.managerData.config);
}
return (false, new IERC20[](0), "");
}
/// @inheritdoc IGetters
/// @dev This function is not optimized for gas consumption as for instance the `burn` value for collateral
/// is computed twice: once in `readBurn` and once in `getBurnOracle`
function getOracleValues(address collateral)
external
view
returns (uint256 mint, uint256 burn, uint256 ratio, uint256 minRatio, uint256 redemption)
{
bytes memory oracleConfig = s.transmuterStorage().collaterals[collateral].oracleConfig;
(burn, ratio) = LibOracle.readBurn(oracleConfig);
(minRatio,) = LibOracle.getBurnOracle(collateral, oracleConfig);
return (LibOracle.readMint(oracleConfig), burn, ratio, minRatio, LibOracle.readRedemption(oracleConfig));
}
/// @inheritdoc IGetters
function getOracle(address collateral)
external
view
returns (
OracleReadType oracleType,
OracleReadType targetType,
bytes memory oracleData,
bytes memory targetData,
bytes memory hyperparameters
)
{
return LibOracle.getOracle(collateral);
}
/// @inheritdoc IGetters
function isPaused(address collateral, ActionType action) external view returns (bool) {
if (action == ActionType.Mint || action == ActionType.Burn) {
Collateral storage collatInfo = s.transmuterStorage().collaterals[collateral];
if (collatInfo.decimals == 0) revert NotCollateral();
if (action == ActionType.Mint) {
return collatInfo.isMintLive == 0;
} else {
return collatInfo.isBurnLive == 0;
}
} else {
return s.transmuterStorage().isRedemptionLive == 0;
}
}
/// @inheritdoc IGetters
function isTrusted(address sender) external view returns (bool) {
return s.transmuterStorage().isTrusted[sender] == 1;
}
/// @inheritdoc IGetters
function isTrustedSeller(address sender) external view returns (bool) {
return s.transmuterStorage().isSellerTrusted[sender] == 1;
}
/// @inheritdoc IGetters
function isWhitelistedForType(WhitelistType whitelistType, address sender) external view returns (bool) {
return s.transmuterStorage().isWhitelistedForType[whitelistType][sender] > 0;
}
/// @inheritdoc IGetters
/// @dev This function is non view as it may consult external non view functions from whitelist providers
function isWhitelistedForCollateral(address collateral, address sender) external returns (bool) {
Collateral storage collatInfo = s.transmuterStorage().collaterals[collateral];
return (collatInfo.onlyWhitelisted == 0 || LibWhitelist.checkWhitelist(collatInfo.whitelistData, sender));
}
/// @inheritdoc IGetters
function isWhitelistedCollateral(address collateral) external view returns (bool) {
return s.transmuterStorage().collaterals[collateral].onlyWhitelisted == 1;
}
/// @inheritdoc IGetters
function getCollateralWhitelistData(address collateral) external view returns (bytes memory) {
return s.transmuterStorage().collaterals[collateral].whitelistData;
}
/// @inheritdoc IGetters
function getStablecoinCap(address collateral) external view returns (uint256) {
return s.transmuterStorage().collaterals[collateral].stablecoinCap;
}
/// @inheritdoc IGetters
function accessManager() external view returns (address) {
return address(s.diamondStorage().accessManager);
}
/// @inheritdoc IGetters
function isConsumingScheduledOp() external view returns (bytes4) {
return s.transmuterStorage().consumingSchedule ? this.isConsumingScheduledOp.selector : bytes4(0);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (access/manager/IAccessManager.sol)
pragma solidity ^0.8.20;
import {Time} from "../../utils/types/Time.sol";
interface IAccessManager {
/**
* @dev A delayed operation was scheduled.
*/
event OperationScheduled(
bytes32 indexed operationId,
uint32 indexed nonce,
uint48 schedule,
address caller,
address target,
bytes data
);
/**
* @dev A scheduled operation was executed.
*/
event OperationExecuted(bytes32 indexed operationId, uint32 indexed nonce);
/**
* @dev A scheduled operation was canceled.
*/
event OperationCanceled(bytes32 indexed operationId, uint32 indexed nonce);
/**
* @dev Informational labelling for a roleId.
*/
event RoleLabel(uint64 indexed roleId, string label);
/**
* @dev Emitted when `account` is granted `roleId`.
*
* NOTE: The meaning of the `since` argument depends on the `newMember` argument.
* If the role is granted to a new member, the `since` argument indicates when the account becomes a member of the role,
* otherwise it indicates the execution delay for this account and roleId is updated.
*/
event RoleGranted(uint64 indexed roleId, address indexed account, uint32 delay, uint48 since, bool newMember);
/**
* @dev Emitted when `account` membership or `roleId` is revoked. Unlike granting, revoking is instantaneous.
*/
event RoleRevoked(uint64 indexed roleId, address indexed account);
/**
* @dev Role acting as admin over a given `roleId` is updated.
*/
event RoleAdminChanged(uint64 indexed roleId, uint64 indexed admin);
/**
* @dev Role acting as guardian over a given `roleId` is updated.
*/
event RoleGuardianChanged(uint64 indexed roleId, uint64 indexed guardian);
/**
* @dev Grant delay for a given `roleId` will be updated to `delay` when `since` is reached.
*/
event RoleGrantDelayChanged(uint64 indexed roleId, uint32 delay, uint48 since);
/**
* @dev Target mode is updated (true = closed, false = open).
*/
event TargetClosed(address indexed target, bool closed);
/**
* @dev Role required to invoke `selector` on `target` is updated to `roleId`.
*/
event TargetFunctionRoleUpdated(address indexed target, bytes4 selector, uint64 indexed roleId);
/**
* @dev Admin delay for a given `target` will be updated to `delay` when `since` is reached.
*/
event TargetAdminDelayUpdated(address indexed target, uint32 delay, uint48 since);
error AccessManagerAlreadyScheduled(bytes32 operationId);
error AccessManagerNotScheduled(bytes32 operationId);
error AccessManagerNotReady(bytes32 operationId);
error AccessManagerExpired(bytes32 operationId);
error AccessManagerLockedRole(uint64 roleId);
error AccessManagerBadConfirmation();
error AccessManagerUnauthorizedAccount(address msgsender, uint64 roleId);
error AccessManagerUnauthorizedCall(address caller, address target, bytes4 selector);
error AccessManagerUnauthorizedConsume(address target);
error AccessManagerUnauthorizedCancel(address msgsender, address caller, address target, bytes4 selector);
error AccessManagerInvalidInitialAdmin(address initialAdmin);
/**
* @dev Check if an address (`caller`) is authorised to call a given function on a given contract directly (with
* no restriction). Additionally, it returns the delay needed to perform the call indirectly through the {schedule}
* & {execute} workflow.
*
* This function is usually called by the targeted contract to control immediate execution of restricted functions.
* Therefore we only return true if the call can be performed without any delay. If the call is subject to a
* previously set delay (not zero), then the function should return false and the caller should schedule the operation
* for future execution.
*
* If `immediate` is true, the delay can be disregarded and the operation can be immediately executed, otherwise
* the operation can be executed if and only if delay is greater than 0.
*
* NOTE: The IAuthority interface does not include the `uint32` delay. This is an extension of that interface that
* is backward compatible. Some contracts may thus ignore the second return argument. In that case they will fail
* to identify the indirect workflow, and will consider calls that require a delay to be forbidden.
*
* NOTE: This function does not report the permissions of the admin functions in the manager itself. These are defined by the
* {AccessManager} documentation.
*/
function canCall(
address caller,
address target,
bytes4 selector
) external view returns (bool allowed, uint32 delay);
/**
* @dev Expiration delay for scheduled proposals. Defaults to 1 week.
*
* IMPORTANT: Avoid overriding the expiration with 0. Otherwise every contract proposal will be expired immediately,
* disabling any scheduling usage.
*/
function expiration() external view returns (uint32);
/**
* @dev Minimum setback for all delay updates, with the exception of execution delays. It
* can be increased without setback (and reset via {revokeRole} in the case event of an
* accidental increase). Defaults to 5 days.
*/
function minSetback() external view returns (uint32);
/**
* @dev Get whether the contract is closed disabling any access. Otherwise role permissions are applied.
*
* NOTE: When the manager itself is closed, admin functions are still accessible to avoid locking the contract.
*/
function isTargetClosed(address target) external view returns (bool);
/**
* @dev Get the role required to call a function.
*/
function getTargetFunctionRole(address target, bytes4 selector) external view returns (uint64);
/**
* @dev Get the admin delay for a target contract. Changes to contract configuration are subject to this delay.
*/
function getTargetAdminDelay(address target) external view returns (uint32);
/**
* @dev Get the id of the role that acts as an admin for the given role.
*
* The admin permission is required to grant the role, revoke the role and update the execution delay to execute
* an operation that is restricted to this role.
*/
function getRoleAdmin(uint64 roleId) external view returns (uint64);
/**
* @dev Get the role that acts as a guardian for a given role.
*
* The guardian permission allows canceling operations that have been scheduled under the role.
*/
function getRoleGuardian(uint64 roleId) external view returns (uint64);
/**
* @dev Get the role current grant delay.
*
* Its value may change at any point without an event emitted following a call to {setGrantDelay}.
* Changes to this value, including effect timepoint are notified in advance by the {RoleGrantDelayChanged} event.
*/
function getRoleGrantDelay(uint64 roleId) external view returns (uint32);
/**
* @dev Get the access details for a given account for a given role. These details include the timepoint at which
* membership becomes active, and the delay applied to all operation by this user that requires this permission
* level.
*
* Returns:
* [0] Timestamp at which the account membership becomes valid. 0 means role is not granted.
* [1] Current execution delay for the account.
* [2] Pending execution delay for the account.
* [3] Timestamp at which the pending execution delay will become active. 0 means no delay update is scheduled.
*/
function getAccess(
uint64 roleId,
address account
) external view returns (uint48 since, uint32 currentDelay, uint32 pendingDelay, uint48 effect);
/**
* @dev Check if a given account currently has the permission level corresponding to a given role. Note that this
* permission might be associated with an execution delay. {getAccess} can provide more details.
*/
function hasRole(uint64 roleId, address account) external view returns (bool isMember, uint32 executionDelay);
/**
* @dev Give a label to a role, for improved role discoverability by UIs.
*
* Requirements:
*
* - the caller must be a global admin
*
* Emits a {RoleLabel} event.
*/
function labelRole(uint64 roleId, string calldata label) external;
/**
* @dev Add `account` to `roleId`, or change its execution delay.
*
* This gives the account the authorization to call any function that is restricted to this role. An optional
* execution delay (in seconds) can be set. If that delay is non 0, the user is required to schedule any operation
* that is restricted to members of this role. The user will only be able to execute the operation after the delay has
* passed, before it has expired. During this period, admin and guardians can cancel the operation (see {cancel}).
*
* If the account has already been granted this role, the execution delay will be updated. This update is not
* immediate and follows the delay rules. For example, if a user currently has a delay of 3 hours, and this is
* called to reduce that delay to 1 hour, the new delay will take some time to take effect, enforcing that any
* operation executed in the 3 hours that follows this update was indeed scheduled before this update.
*
* Requirements:
*
* - the caller must be an admin for the role (see {getRoleAdmin})
* - granted role must not be the `PUBLIC_ROLE`
*
* Emits a {RoleGranted} event.
*/
function grantRole(uint64 roleId, address account, uint32 executionDelay) external;
/**
* @dev Remove an account from a role, with immediate effect. If the account does not have the role, this call has
* no effect.
*
* Requirements:
*
* - the caller must be an admin for the role (see {getRoleAdmin})
* - revoked role must not be the `PUBLIC_ROLE`
*
* Emits a {RoleRevoked} event if the account had the role.
*/
function revokeRole(uint64 roleId, address account) external;
/**
* @dev Renounce role permissions for the calling account with immediate effect. If the sender is not in
* the role this call has no effect.
*
* Requirements:
*
* - the caller must be `callerConfirmation`.
*
* Emits a {RoleRevoked} event if the account had the role.
*/
function renounceRole(uint64 roleId, address callerConfirmation) external;
/**
* @dev Change admin role for a given role.
*
* Requirements:
*
* - the caller must be a global admin
*
* Emits a {RoleAdminChanged} event
*/
function setRoleAdmin(uint64 roleId, uint64 admin) external;
/**
* @dev Change guardian role for a given role.
*
* Requirements:
*
* - the caller must be a global admin
*
* Emits a {RoleGuardianChanged} event
*/
function setRoleGuardian(uint64 roleId, uint64 guardian) external;
/**
* @dev Update the delay for granting a `roleId`.
*
* Requirements:
*
* - the caller must be a global admin
*
* Emits a {RoleGrantDelayChanged} event.
*/
function setGrantDelay(uint64 roleId, uint32 newDelay) external;
/**
* @dev Set the role required to call functions identified by the `selectors` in the `target` contract.
*
* Requirements:
*
* - the caller must be a global admin
*
* Emits a {TargetFunctionRoleUpdated} event per selector.
*/
function setTargetFunctionRole(address target, bytes4[] calldata selectors, uint64 roleId) external;
/**
* @dev Set the delay for changing the configuration of a given target contract.
*
* Requirements:
*
* - the caller must be a global admin
*
* Emits a {TargetAdminDelayUpdated} event.
*/
function setTargetAdminDelay(address target, uint32 newDelay) external;
/**
* @dev Set the closed flag for a contract.
*
* Closing the manager itself won't disable access to admin methods to avoid locking the contract.
*
* Requirements:
*
* - the caller must be a global admin
*
* Emits a {TargetClosed} event.
*/
function setTargetClosed(address target, bool closed) external;
/**
* @dev Return the timepoint at which a scheduled operation will be ready for execution. This returns 0 if the
* operation is not yet scheduled, has expired, was executed, or was canceled.
*/
function getSchedule(bytes32 id) external view returns (uint48);
/**
* @dev Return the nonce for the latest scheduled operation with a given id. Returns 0 if the operation has never
* been scheduled.
*/
function getNonce(bytes32 id) external view returns (uint32);
/**
* @dev Schedule a delayed operation for future execution, and return the operation identifier. It is possible to
* choose the timestamp at which the operation becomes executable as long as it satisfies the execution delays
* required for the caller. The special value zero will automatically set the earliest possible time.
*
* Returns the `operationId` that was scheduled. Since this value is a hash of the parameters, it can reoccur when
* the same parameters are used; if this is relevant, the returned `nonce` can be used to uniquely identify this
* scheduled operation from other occurrences of the same `operationId` in invocations of {execute} and {cancel}.
*
* Emits a {OperationScheduled} event.
*
* NOTE: It is not possible to concurrently schedule more than one operation with the same `target` and `data`. If
* this is necessary, a random byte can be appended to `data` to act as a salt that will be ignored by the target
* contract if it is using standard Solidity ABI encoding.
*/
function schedule(
address target,
bytes calldata data,
uint48 when
) external returns (bytes32 operationId, uint32 nonce);
/**
* @dev Execute a function that is delay restricted, provided it was properly scheduled beforehand, or the
* execution delay is 0.
*
* Returns the nonce that identifies the previously scheduled operation that is executed, or 0 if the
* operation wasn't previously scheduled (if the caller doesn't have an execution delay).
*
* Emits an {OperationExecuted} event only if the call was scheduled and delayed.
*/
function execute(address target, bytes calldata data) external payable returns (uint32);
/**
* @dev Cancel a scheduled (delayed) operation. Returns the nonce that identifies the previously scheduled
* operation that is cancelled.
*
* Requirements:
*
* - the caller must be the proposer, a guardian of the targeted function, or a global admin
*
* Emits a {OperationCanceled} event.
*/
function cancel(address caller, address target, bytes calldata data) external returns (uint32);
/**
* @dev Consume a scheduled operation targeting the caller. If such an operation exists, mark it as consumed
* (emit an {OperationExecuted} event and clean the state). Otherwise, throw an error.
*
* This is useful for contract that want to enforce that calls targeting them were scheduled on the manager,
* with all the verifications that it implies.
*
* Emit a {OperationExecuted} event.
*/
function consumeScheduledOp(address caller, bytes calldata data) external;
/**
* @dev Hashing function for delayed operations.
*/
function hashOperation(address caller, address target, bytes calldata data) external view returns (bytes32);
/**
* @dev Changes the authority of a target managed by this manager instance.
*
* Requirements:
*
* - the caller must be a global admin
*/
function updateAuthority(address target, address newAuthority) external;
}// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.5.0;
/// @title ICbETH
/// @notice Interface for the `cbETH` contract
interface ICbETH {
function exchangeRate() external view returns (uint256);
}// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.5.0;
/// @title ISfrxETH
/// @notice Interface for the `sfrxETH` contract
interface ISfrxETH {
function pricePerShare() external view returns (uint256);
}// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.5.0;
/// @title IKeyringGuard
/// @notice Interface for the `KeyringGuard` contract
interface IKeyringGuard {
function isAuthorized(address from, address to) external returns (bool passed);
}// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.5.0;
/// @title IStETH
/// @notice Interface for the `StETH` contract
interface IStETH {
function getPooledEthByShares(uint256 _sharesAmount) external view returns (uint256);
function submit(address) external payable returns (uint256);
function getSharesByPooledEth(uint256 _ethAmount) external view returns (uint256);
}// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.5.0;
/// @title IMorphoOracle
/// @notice Interface for the oracle contracts used within Morpho
interface IMorphoOracle {
function price() external view returns (uint256);
}// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.5.0;
/// @title IRETH
/// @notice Interface for the `rETH` contract
interface IRETH {
function getExchangeRate() external view returns (uint256);
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { IAccessManager } from "@openzeppelin/contracts/access/manager/IAccessManager.sol";
import { ITokenP } from "contracts/interfaces/ITokenP.sol";
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ENUMS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
enum FacetCutAction {
Add,
Replace,
Remove
}
enum ManagerType {
EXTERNAL
}
enum ActionType {
Mint,
Burn,
Redeem
}
enum TrustedType {
Updater,
Seller
}
enum QuoteType {
MintExactInput,
MintExactOutput,
BurnExactInput,
BurnExactOutput
}
enum OracleReadType {
CHAINLINK_FEEDS,
EXTERNAL,
NO_ORACLE,
STABLE,
WSTETH,
CBETH,
RETH,
SFRXETH,
MAX,
MORPHO_ORACLE
}
enum OracleQuoteType {
UNIT,
TARGET
}
enum WhitelistType {
BACKED
}
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
STRUCTS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
struct Permit2Details {
address to; // Address that will receive the funds
uint256 nonce; // Nonce of the transaction
bytes signature; // Permit signature of the user
}
struct FacetCut {
address facetAddress; // Facet contract address
FacetCutAction action; // Can be add, remove or replace
bytes4[] functionSelectors; // Ex. bytes4(keccak256("transfer(address,uint256)"))
}
struct Facet {
address facetAddress; // Facet contract address
bytes4[] functionSelectors; // Ex. bytes4(keccak256("transfer(address,uint256)"))
}
struct FacetInfo {
address facetAddress; // Facet contract address
uint16 selectorPosition; // Position in the list of all selectors
}
struct DiamondStorage {
bytes4[] selectors; // List of all available selectors
mapping(bytes4 => FacetInfo) selectorInfo; // Selector to (address, position in list)
IAccessManager accessManager; // Contract handling access management
}
struct ImplementationStorage {
address implementation; // Dummy implementation address for Etherscan usability
}
struct ManagerStorage {
IERC20[] subCollaterals; // Subtokens handled by the manager or strategies
bytes config; // Additional configuration data
}
struct Collateral {
uint8 isManaged; // If the collateral is managed through external strategies
uint8 isMintLive; // If minting from this asset is unpaused
uint8 isBurnLive; // If burning to this asset is unpaused
uint8 decimals; // IERC20Metadata(collateral).decimals()
uint8 onlyWhitelisted; // If only whitelisted addresses can burn or redeem for this token
uint216 normalizedStables; // Normalized amount of stablecoins issued from this collateral
uint64[] xFeeMint; // Increasing exposures in [0,BASE_9[
int64[] yFeeMint; // Mint fees at the exposures specified in `xFeeMint`
uint64[] xFeeBurn; // Decreasing exposures in ]0,BASE_9]
int64[] yFeeBurn; // Burn fees at the exposures specified in `xFeeBurn`
bytes oracleConfig; // Data about the oracle used for the collateral
bytes whitelistData; // For whitelisted collateral, data used to verify whitelists
ManagerStorage managerData; // For managed collateral, data used to handle the strategies
uint256 stablecoinCap; // Cap on the amount of stablecoins that can be issued from this collateral
}
struct ParallelizerStorage {
ITokenP tokenP; // tokenP handled by the system
uint8 isRedemptionLive; // If redemption is unpaused
uint8 statusReentrant; // If call is reentrant or not
bool consumingSchedule; // If the contract is consuming a scheduled operation
uint128 normalizedStables; // Normalized amount of stablecoins issued by the system
uint128 normalizer; // To reconcile `normalizedStables` values with the actual amount
address[] collateralList; // List of collateral assets supported by the system
uint64[] xRedemptionCurve; // Increasing collateral ratios > 0
int64[] yRedemptionCurve; // Value of the redemption fees at `xRedemptionCurve`
mapping(address => Collateral) collaterals; // Maps a collateral asset to its parameters
mapping(address => uint256) isTrusted; // If an address is trusted to update the normalizer value
mapping(address => uint256) isSellerTrusted; // If an address is trusted to sell accruing reward tokens or to run
// keeper jobs on oracles
mapping(WhitelistType => mapping(address => uint256)) isWhitelistedForType;
}
// Whether an address is whitelisted for a specific whitelist type// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { Math } from "@openzeppelin/contracts/utils/math/Math.sol";
import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol";
import { LibHelpers } from "./LibHelpers.sol";
import { LibManager } from "./LibManager.sol";
import { LibOracle } from "./LibOracle.sol";
import { LibStorage as s } from "./LibStorage.sol";
import "../../utils/Constants.sol";
import "../Storage.sol";
/// @title LibGetters
/// @author Cooper Labs
/// @custom:contact [email protected]
/// @dev This library is an authorized fork of Angle's `LibGetters` library
/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/parallelizer/libraries/LibGetters.sol
library LibGetters {
using Math for uint256;
using SafeCast for uint256;
/// @notice Internal version of the `getCollateralRatio` function with additional return values like `tokens` that
/// is the list of tokens supported by the system, or `balances` which is the amount of each token in `tokens`
/// controlled by the protocol
/// @dev In case some collaterals support external strategies (`isManaged>0`), this list may be bigger
/// than the `collateralList`
/// @dev `subCollateralsTracker` is an array which gives for each collateral asset in the collateral list an
/// accumulator helping to recompute the amount of sub-collateral for each collateral. If the array is:
/// [1,4,5], this means that the collateral with index 1 in the `collateralsList` has 4-1=3 sub-collaterals.
function getCollateralRatio()
internal
view
returns (
uint64 collatRatio,
uint256 stablecoinsIssued,
address[] memory tokens,
uint256[] memory balances,
uint256[] memory subCollateralsTracker
)
{
ParallelizerStorage storage ts = s.transmuterStorage();
uint256 totalCollateralization;
address[] memory collateralList = ts.collateralList;
uint256 collateralListLength = collateralList.length;
uint256 subCollateralsAmount;
// Building the `subCollateralsTracker` array which is useful when later sending the tokens as part of the
// redemption
subCollateralsTracker = new uint256[](collateralListLength);
for (uint256 i; i < collateralListLength; ++i) {
if (ts.collaterals[collateralList[i]].isManaged == 0) ++subCollateralsAmount;
else subCollateralsAmount += ts.collaterals[collateralList[i]].managerData.subCollaterals.length;
subCollateralsTracker[i] = subCollateralsAmount;
}
balances = new uint256[](subCollateralsAmount);
tokens = new address[](subCollateralsAmount);
{
uint256 countCollat;
for (uint256 i; i < collateralListLength; ++i) {
Collateral storage collateral = ts.collaterals[collateralList[i]];
uint256 collateralBalance; // Will be either the balance or the value of assets managed
if (collateral.isManaged > 0) {
// If a collateral is managed, the balances of the sub-collaterals cannot be directly obtained by
// calling `balanceOf` of the sub-collaterals
uint256[] memory subCollateralsBalances;
(subCollateralsBalances, collateralBalance) = LibManager.totalAssets(collateral.managerData.config);
uint256 numSubCollats = subCollateralsBalances.length;
for (uint256 k; k < numSubCollats; ++k) {
tokens[countCollat + k] = address(collateral.managerData.subCollaterals[k]);
balances[countCollat + k] = subCollateralsBalances[k];
}
countCollat += numSubCollats;
} else {
collateralBalance = IERC20(collateralList[i]).balanceOf(address(this));
tokens[countCollat] = collateralList[i];
balances[countCollat++] = collateralBalance;
}
uint256 oracleValue = LibOracle.readRedemption(collateral.oracleConfig);
totalCollateralization +=
(oracleValue * LibHelpers.convertDecimalTo(collateralBalance, collateral.decimals, 18)) / BASE_18;
}
}
// The `stablecoinsIssued` value need to be rounded up because it is then used as a divizer when computing
// the `collatRatio`
stablecoinsIssued = uint256(ts.normalizedStables).mulDiv(ts.normalizer, BASE_27, Math.Rounding.Ceil);
if (stablecoinsIssued > 0) {
collatRatio = (totalCollateralization.mulDiv(BASE_9, stablecoinsIssued, Math.Rounding.Ceil)).toUint64();
} else {
collatRatio = type(uint64).max;
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
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 value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of 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 value) 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 a `value` amount of tokens 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 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` 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 value) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Panic.sol)
pragma solidity ^0.8.20;
/**
* @dev Helper library for emitting standardized panic codes.
*
* ```solidity
* contract Example {
* using Panic for uint256;
*
* // Use any of the declared internal constants
* function foo() { Panic.GENERIC.panic(); }
*
* // Alternatively
* function foo() { Panic.panic(Panic.GENERIC); }
* }
* ```
*
* Follows the list from https://github.com/ethereum/solidity/blob/v0.8.24/libsolutil/ErrorCodes.h[libsolutil].
*
* _Available since v5.1._
*/
// slither-disable-next-line unused-state
library Panic {
/// @dev generic / unspecified error
uint256 internal constant GENERIC = 0x00;
/// @dev used by the assert() builtin
uint256 internal constant ASSERT = 0x01;
/// @dev arithmetic underflow or overflow
uint256 internal constant UNDER_OVERFLOW = 0x11;
/// @dev division or modulo by zero
uint256 internal constant DIVISION_BY_ZERO = 0x12;
/// @dev enum conversion error
uint256 internal constant ENUM_CONVERSION_ERROR = 0x21;
/// @dev invalid encoding in storage
uint256 internal constant STORAGE_ENCODING_ERROR = 0x22;
/// @dev empty array pop
uint256 internal constant EMPTY_ARRAY_POP = 0x31;
/// @dev array out of bounds access
uint256 internal constant ARRAY_OUT_OF_BOUNDS = 0x32;
/// @dev resource error (too large allocation or too large array)
uint256 internal constant RESOURCE_ERROR = 0x41;
/// @dev calling invalid internal function
uint256 internal constant INVALID_INTERNAL_FUNCTION = 0x51;
/// @dev Reverts with a panic code. Recommended to use with
/// the internal constants with predefined codes.
function panic(uint256 code) internal pure {
assembly ("memory-safe") {
mstore(0x00, 0x4e487b71)
mstore(0x20, code)
revert(0x1c, 0x24)
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/Math.sol)
pragma solidity ^0.8.20;
import {Panic} from "../Panic.sol";
import {SafeCast} from "./SafeCast.sol";
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Floor, // Toward negative infinity
Ceil, // Toward positive infinity
Trunc, // Toward zero
Expand // Away from zero
}
/**
* @dev Returns the addition of two unsigned integers, with an success flag (no overflow).
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with an success flag (no overflow).
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an success flag (no overflow).
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a success flag (no division by zero).
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a success flag (no division by zero).
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.
*
* IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.
* However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute
* one branch when needed, making this function more expensive.
*/
function ternary(bool condition, uint256 a, uint256 b) internal pure returns (uint256) {
unchecked {
// branchless ternary works because:
// b ^ (a ^ b) == a
// b ^ 0 == b
return b ^ ((a ^ b) * SafeCast.toUint(condition));
}
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return ternary(a > b, a, b);
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return ternary(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 towards infinity instead
* of rounding towards zero.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
if (b == 0) {
// Guarantee the same behavior as in a regular Solidity division.
Panic.panic(Panic.DIVISION_BY_ZERO);
}
// The following calculation ensures accurate ceiling division without overflow.
// Since a is non-zero, (a - 1) / b will not overflow.
// The largest possible result occurs when (a - 1) / b is type(uint256).max,
// but the largest value we can obtain is type(uint256).max - 1, which happens
// when a = type(uint256).max and b = 1.
unchecked {
return SafeCast.toUint(a > 0) * ((a - 1) / b + 1);
}
}
/**
* @dev Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
* denominator == 0.
*
* 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²⁵⁶ and mod 2²⁵⁶ - 1, then use
// the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2²⁵⁶ + prod0.
uint256 prod0 = x * y; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
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²⁵⁶. Also prevents denominator == 0.
if (denominator <= prod1) {
Panic.panic(ternary(denominator == 0, Panic.DIVISION_BY_ZERO, Panic.UNDER_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.
uint256 twos = denominator & (0 - denominator);
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²⁵⁶ / 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²⁵⁶. Now that denominator is an odd number, it has an inverse modulo 2²⁵⁶ such
// that denominator * inv ≡ 1 mod 2²⁵⁶. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv ≡ 1 mod 2⁴.
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⁸
inverse *= 2 - denominator * inverse; // inverse mod 2¹⁶
inverse *= 2 - denominator * inverse; // inverse mod 2³²
inverse *= 2 - denominator * inverse; // inverse mod 2⁶⁴
inverse *= 2 - denominator * inverse; // inverse mod 2¹²⁸
inverse *= 2 - denominator * inverse; // inverse mod 2²⁵⁶
// 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²⁵⁶. Since the preconditions guarantee that the outcome is
// less than 2²⁵⁶, 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;
}
}
/**
* @dev 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) {
return mulDiv(x, y, denominator) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0);
}
/**
* @dev Calculate the modular multiplicative inverse of a number in Z/nZ.
*
* If n is a prime, then Z/nZ is a field. In that case all elements are inversible, except 0.
* If n is not a prime, then Z/nZ is not a field, and some elements might not be inversible.
*
* If the input value is not inversible, 0 is returned.
*
* NOTE: If you know for sure that n is (big) a prime, it may be cheaper to use Fermat's little theorem and get the
* inverse using `Math.modExp(a, n - 2, n)`. See {invModPrime}.
*/
function invMod(uint256 a, uint256 n) internal pure returns (uint256) {
unchecked {
if (n == 0) return 0;
// The inverse modulo is calculated using the Extended Euclidean Algorithm (iterative version)
// Used to compute integers x and y such that: ax + ny = gcd(a, n).
// When the gcd is 1, then the inverse of a modulo n exists and it's x.
// ax + ny = 1
// ax = 1 + (-y)n
// ax ≡ 1 (mod n) # x is the inverse of a modulo n
// If the remainder is 0 the gcd is n right away.
uint256 remainder = a % n;
uint256 gcd = n;
// Therefore the initial coefficients are:
// ax + ny = gcd(a, n) = n
// 0a + 1n = n
int256 x = 0;
int256 y = 1;
while (remainder != 0) {
uint256 quotient = gcd / remainder;
(gcd, remainder) = (
// The old remainder is the next gcd to try.
remainder,
// Compute the next remainder.
// Can't overflow given that (a % gcd) * (gcd // (a % gcd)) <= gcd
// where gcd is at most n (capped to type(uint256).max)
gcd - remainder * quotient
);
(x, y) = (
// Increment the coefficient of a.
y,
// Decrement the coefficient of n.
// Can overflow, but the result is casted to uint256 so that the
// next value of y is "wrapped around" to a value between 0 and n - 1.
x - y * int256(quotient)
);
}
if (gcd != 1) return 0; // No inverse exists.
return ternary(x < 0, n - uint256(-x), uint256(x)); // Wrap the result if it's negative.
}
}
/**
* @dev Variant of {invMod}. More efficient, but only works if `p` is known to be a prime greater than `2`.
*
* From https://en.wikipedia.org/wiki/Fermat%27s_little_theorem[Fermat's little theorem], we know that if p is
* prime, then `a**(p-1) ≡ 1 mod p`. As a consequence, we have `a * a**(p-2) ≡ 1 mod p`, which means that
* `a**(p-2)` is the modular multiplicative inverse of a in Fp.
*
* NOTE: this function does NOT check that `p` is a prime greater than `2`.
*/
function invModPrime(uint256 a, uint256 p) internal view returns (uint256) {
unchecked {
return Math.modExp(a, p - 2, p);
}
}
/**
* @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m)
*
* Requirements:
* - modulus can't be zero
* - underlying staticcall to precompile must succeed
*
* IMPORTANT: The result is only valid if the underlying call succeeds. When using this function, make
* sure the chain you're using it on supports the precompiled contract for modular exponentiation
* at address 0x05 as specified in https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise,
* the underlying function will succeed given the lack of a revert, but the result may be incorrectly
* interpreted as 0.
*/
function modExp(uint256 b, uint256 e, uint256 m) internal view returns (uint256) {
(bool success, uint256 result) = tryModExp(b, e, m);
if (!success) {
Panic.panic(Panic.DIVISION_BY_ZERO);
}
return result;
}
/**
* @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m).
* It includes a success flag indicating if the operation succeeded. Operation will be marked as failed if trying
* to operate modulo 0 or if the underlying precompile reverted.
*
* IMPORTANT: The result is only valid if the success flag is true. When using this function, make sure the chain
* you're using it on supports the precompiled contract for modular exponentiation at address 0x05 as specified in
* https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise, the underlying function will succeed given the lack
* of a revert, but the result may be incorrectly interpreted as 0.
*/
function tryModExp(uint256 b, uint256 e, uint256 m) internal view returns (bool success, uint256 result) {
if (m == 0) return (false, 0);
assembly ("memory-safe") {
let ptr := mload(0x40)
// | Offset | Content | Content (Hex) |
// |-----------|------------|--------------------------------------------------------------------|
// | 0x00:0x1f | size of b | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x20:0x3f | size of e | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x40:0x5f | size of m | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x60:0x7f | value of b | 0x<.............................................................b> |
// | 0x80:0x9f | value of e | 0x<.............................................................e> |
// | 0xa0:0xbf | value of m | 0x<.............................................................m> |
mstore(ptr, 0x20)
mstore(add(ptr, 0x20), 0x20)
mstore(add(ptr, 0x40), 0x20)
mstore(add(ptr, 0x60), b)
mstore(add(ptr, 0x80), e)
mstore(add(ptr, 0xa0), m)
// Given the result < m, it's guaranteed to fit in 32 bytes,
// so we can use the memory scratch space located at offset 0.
success := staticcall(gas(), 0x05, ptr, 0xc0, 0x00, 0x20)
result := mload(0x00)
}
}
/**
* @dev Variant of {modExp} that supports inputs of arbitrary length.
*/
function modExp(bytes memory b, bytes memory e, bytes memory m) internal view returns (bytes memory) {
(bool success, bytes memory result) = tryModExp(b, e, m);
if (!success) {
Panic.panic(Panic.DIVISION_BY_ZERO);
}
return result;
}
/**
* @dev Variant of {tryModExp} that supports inputs of arbitrary length.
*/
function tryModExp(
bytes memory b,
bytes memory e,
bytes memory m
) internal view returns (bool success, bytes memory result) {
if (_zeroBytes(m)) return (false, new bytes(0));
uint256 mLen = m.length;
// Encode call args in result and move the free memory pointer
result = abi.encodePacked(b.length, e.length, mLen, b, e, m);
assembly ("memory-safe") {
let dataPtr := add(result, 0x20)
// Write result on top of args to avoid allocating extra memory.
success := staticcall(gas(), 0x05, dataPtr, mload(result), dataPtr, mLen)
// Overwrite the length.
// result.length > returndatasize() is guaranteed because returndatasize() == m.length
mstore(result, mLen)
// Set the memory pointer after the returned data.
mstore(0x40, add(dataPtr, mLen))
}
}
/**
* @dev Returns whether the provided byte array is zero.
*/
function _zeroBytes(bytes memory byteArray) private pure returns (bool) {
for (uint256 i = 0; i < byteArray.length; ++i) {
if (byteArray[i] != 0) {
return false;
}
}
return true;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
* towards zero.
*
* This method is based on Newton's method for computing square roots; the algorithm is restricted to only
* using integer operations.
*/
function sqrt(uint256 a) internal pure returns (uint256) {
unchecked {
// Take care of easy edge cases when a == 0 or a == 1
if (a <= 1) {
return a;
}
// In this function, we use Newton's method to get a root of `f(x) := x² - a`. It involves building a
// sequence x_n that converges toward sqrt(a). For each iteration x_n, we also define the error between
// the current value as `ε_n = | x_n - sqrt(a) |`.
//
// For our first estimation, we consider `e` the smallest power of 2 which is bigger than the square root
// of the target. (i.e. `2**(e-1) ≤ sqrt(a) < 2**e`). We know that `e ≤ 128` because `(2¹²⁸)² = 2²⁵⁶` is
// bigger than any uint256.
//
// By noticing that
// `2**(e-1) ≤ sqrt(a) < 2**e → (2**(e-1))² ≤ a < (2**e)² → 2**(2*e-2) ≤ a < 2**(2*e)`
// we can deduce that `e - 1` is `log2(a) / 2`. We can thus compute `x_n = 2**(e-1)` using a method similar
// to the msb function.
uint256 aa = a;
uint256 xn = 1;
if (aa >= (1 << 128)) {
aa >>= 128;
xn <<= 64;
}
if (aa >= (1 << 64)) {
aa >>= 64;
xn <<= 32;
}
if (aa >= (1 << 32)) {
aa >>= 32;
xn <<= 16;
}
if (aa >= (1 << 16)) {
aa >>= 16;
xn <<= 8;
}
if (aa >= (1 << 8)) {
aa >>= 8;
xn <<= 4;
}
if (aa >= (1 << 4)) {
aa >>= 4;
xn <<= 2;
}
if (aa >= (1 << 2)) {
xn <<= 1;
}
// We now have x_n such that `x_n = 2**(e-1) ≤ sqrt(a) < 2**e = 2 * x_n`. This implies ε_n ≤ 2**(e-1).
//
// We can refine our estimation by noticing that the middle of that interval minimizes the error.
// If we move x_n to equal 2**(e-1) + 2**(e-2), then we reduce the error to ε_n ≤ 2**(e-2).
// This is going to be our x_0 (and ε_0)
xn = (3 * xn) >> 1; // ε_0 := | x_0 - sqrt(a) | ≤ 2**(e-2)
// From here, Newton's method give us:
// x_{n+1} = (x_n + a / x_n) / 2
//
// One should note that:
// x_{n+1}² - a = ((x_n + a / x_n) / 2)² - a
// = ((x_n² + a) / (2 * x_n))² - a
// = (x_n⁴ + 2 * a * x_n² + a²) / (4 * x_n²) - a
// = (x_n⁴ + 2 * a * x_n² + a² - 4 * a * x_n²) / (4 * x_n²)
// = (x_n⁴ - 2 * a * x_n² + a²) / (4 * x_n²)
// = (x_n² - a)² / (2 * x_n)²
// = ((x_n² - a) / (2 * x_n))²
// ≥ 0
// Which proves that for all n ≥ 1, sqrt(a) ≤ x_n
//
// This gives us the proof of quadratic convergence of the sequence:
// ε_{n+1} = | x_{n+1} - sqrt(a) |
// = | (x_n + a / x_n) / 2 - sqrt(a) |
// = | (x_n² + a - 2*x_n*sqrt(a)) / (2 * x_n) |
// = | (x_n - sqrt(a))² / (2 * x_n) |
// = | ε_n² / (2 * x_n) |
// = ε_n² / | (2 * x_n) |
//
// For the first iteration, we have a special case where x_0 is known:
// ε_1 = ε_0² / | (2 * x_0) |
// ≤ (2**(e-2))² / (2 * (2**(e-1) + 2**(e-2)))
// ≤ 2**(2*e-4) / (3 * 2**(e-1))
// ≤ 2**(e-3) / 3
// ≤ 2**(e-3-log2(3))
// ≤ 2**(e-4.5)
//
// For the following iterations, we use the fact that, 2**(e-1) ≤ sqrt(a) ≤ x_n:
// ε_{n+1} = ε_n² / | (2 * x_n) |
// ≤ (2**(e-k))² / (2 * 2**(e-1))
// ≤ 2**(2*e-2*k) / 2**e
// ≤ 2**(e-2*k)
xn = (xn + a / xn) >> 1; // ε_1 := | x_1 - sqrt(a) | ≤ 2**(e-4.5) -- special case, see above
xn = (xn + a / xn) >> 1; // ε_2 := | x_2 - sqrt(a) | ≤ 2**(e-9) -- general case with k = 4.5
xn = (xn + a / xn) >> 1; // ε_3 := | x_3 - sqrt(a) | ≤ 2**(e-18) -- general case with k = 9
xn = (xn + a / xn) >> 1; // ε_4 := | x_4 - sqrt(a) | ≤ 2**(e-36) -- general case with k = 18
xn = (xn + a / xn) >> 1; // ε_5 := | x_5 - sqrt(a) | ≤ 2**(e-72) -- general case with k = 36
xn = (xn + a / xn) >> 1; // ε_6 := | x_6 - sqrt(a) | ≤ 2**(e-144) -- general case with k = 72
// Because e ≤ 128 (as discussed during the first estimation phase), we know have reached a precision
// ε_6 ≤ 2**(e-144) < 1. Given we're operating on integers, then we can ensure that xn is now either
// sqrt(a) or sqrt(a) + 1.
return xn - SafeCast.toUint(xn > a / xn);
}
}
/**
* @dev 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 + SafeCast.toUint(unsignedRoundsUp(rounding) && result * result < a);
}
}
/**
* @dev Return the log in base 2 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
uint256 exp;
unchecked {
exp = 128 * SafeCast.toUint(value > (1 << 128) - 1);
value >>= exp;
result += exp;
exp = 64 * SafeCast.toUint(value > (1 << 64) - 1);
value >>= exp;
result += exp;
exp = 32 * SafeCast.toUint(value > (1 << 32) - 1);
value >>= exp;
result += exp;
exp = 16 * SafeCast.toUint(value > (1 << 16) - 1);
value >>= exp;
result += exp;
exp = 8 * SafeCast.toUint(value > (1 << 8) - 1);
value >>= exp;
result += exp;
exp = 4 * SafeCast.toUint(value > (1 << 4) - 1);
value >>= exp;
result += exp;
exp = 2 * SafeCast.toUint(value > (1 << 2) - 1);
value >>= exp;
result += exp;
result += SafeCast.toUint(value > 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 + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << result < value);
}
}
/**
* @dev Return the log in base 10 of a positive value rounded towards zero.
* 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 + SafeCast.toUint(unsignedRoundsUp(rounding) && 10 ** result < value);
}
}
/**
* @dev Return the log in base 256 of a positive value rounded towards zero.
* 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;
uint256 isGt;
unchecked {
isGt = SafeCast.toUint(value > (1 << 128) - 1);
value >>= isGt * 128;
result += isGt * 16;
isGt = SafeCast.toUint(value > (1 << 64) - 1);
value >>= isGt * 64;
result += isGt * 8;
isGt = SafeCast.toUint(value > (1 << 32) - 1);
value >>= isGt * 32;
result += isGt * 4;
isGt = SafeCast.toUint(value > (1 << 16) - 1);
value >>= isGt * 16;
result += isGt * 2;
result += SafeCast.toUint(value > (1 << 8) - 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 + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << (result << 3) < value);
}
}
/**
* @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
*/
function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
return uint8(rounding) % 2 == 1;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
pragma solidity ^0.8.20;
/**
* @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeCast {
/**
* @dev Value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);
/**
* @dev An int value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedIntToUint(int256 value);
/**
* @dev Value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);
/**
* @dev An uint value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedUintToInt(uint256 value);
/**
* @dev Returns the downcasted uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toUint248(uint256 value) internal pure returns (uint248) {
if (value > type(uint248).max) {
revert SafeCastOverflowedUintDowncast(248, value);
}
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toUint240(uint256 value) internal pure returns (uint240) {
if (value > type(uint240).max) {
revert SafeCastOverflowedUintDowncast(240, value);
}
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toUint232(uint256 value) internal pure returns (uint232) {
if (value > type(uint232).max) {
revert SafeCastOverflowedUintDowncast(232, value);
}
return uint232(value);
}
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
if (value > type(uint224).max) {
revert SafeCastOverflowedUintDowncast(224, value);
}
return uint224(value);
}
/**
* @dev Returns the downcasted uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toUint216(uint256 value) internal pure returns (uint216) {
if (value > type(uint216).max) {
revert SafeCastOverflowedUintDowncast(216, value);
}
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toUint208(uint256 value) internal pure returns (uint208) {
if (value > type(uint208).max) {
revert SafeCastOverflowedUintDowncast(208, value);
}
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toUint200(uint256 value) internal pure returns (uint200) {
if (value > type(uint200).max) {
revert SafeCastOverflowedUintDowncast(200, value);
}
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toUint192(uint256 value) internal pure returns (uint192) {
if (value > type(uint192).max) {
revert SafeCastOverflowedUintDowncast(192, value);
}
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toUint184(uint256 value) internal pure returns (uint184) {
if (value > type(uint184).max) {
revert SafeCastOverflowedUintDowncast(184, value);
}
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toUint176(uint256 value) internal pure returns (uint176) {
if (value > type(uint176).max) {
revert SafeCastOverflowedUintDowncast(176, value);
}
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toUint168(uint256 value) internal pure returns (uint168) {
if (value > type(uint168).max) {
revert SafeCastOverflowedUintDowncast(168, value);
}
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toUint160(uint256 value) internal pure returns (uint160) {
if (value > type(uint160).max) {
revert SafeCastOverflowedUintDowncast(160, value);
}
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toUint152(uint256 value) internal pure returns (uint152) {
if (value > type(uint152).max) {
revert SafeCastOverflowedUintDowncast(152, value);
}
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toUint144(uint256 value) internal pure returns (uint144) {
if (value > type(uint144).max) {
revert SafeCastOverflowedUintDowncast(144, value);
}
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toUint136(uint256 value) internal pure returns (uint136) {
if (value > type(uint136).max) {
revert SafeCastOverflowedUintDowncast(136, value);
}
return uint136(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toUint128(uint256 value) internal pure returns (uint128) {
if (value > type(uint128).max) {
revert SafeCastOverflowedUintDowncast(128, value);
}
return uint128(value);
}
/**
* @dev Returns the downcasted uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toUint120(uint256 value) internal pure returns (uint120) {
if (value > type(uint120).max) {
revert SafeCastOverflowedUintDowncast(120, value);
}
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toUint112(uint256 value) internal pure returns (uint112) {
if (value > type(uint112).max) {
revert SafeCastOverflowedUintDowncast(112, value);
}
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toUint104(uint256 value) internal pure returns (uint104) {
if (value > type(uint104).max) {
revert SafeCastOverflowedUintDowncast(104, value);
}
return uint104(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toUint96(uint256 value) internal pure returns (uint96) {
if (value > type(uint96).max) {
revert SafeCastOverflowedUintDowncast(96, value);
}
return uint96(value);
}
/**
* @dev Returns the downcasted uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toUint88(uint256 value) internal pure returns (uint88) {
if (value > type(uint88).max) {
revert SafeCastOverflowedUintDowncast(88, value);
}
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toUint80(uint256 value) internal pure returns (uint80) {
if (value > type(uint80).max) {
revert SafeCastOverflowedUintDowncast(80, value);
}
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toUint72(uint256 value) internal pure returns (uint72) {
if (value > type(uint72).max) {
revert SafeCastOverflowedUintDowncast(72, value);
}
return uint72(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toUint64(uint256 value) internal pure returns (uint64) {
if (value > type(uint64).max) {
revert SafeCastOverflowedUintDowncast(64, value);
}
return uint64(value);
}
/**
* @dev Returns the downcasted uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toUint56(uint256 value) internal pure returns (uint56) {
if (value > type(uint56).max) {
revert SafeCastOverflowedUintDowncast(56, value);
}
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toUint48(uint256 value) internal pure returns (uint48) {
if (value > type(uint48).max) {
revert SafeCastOverflowedUintDowncast(48, value);
}
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toUint40(uint256 value) internal pure returns (uint40) {
if (value > type(uint40).max) {
revert SafeCastOverflowedUintDowncast(40, value);
}
return uint40(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toUint32(uint256 value) internal pure returns (uint32) {
if (value > type(uint32).max) {
revert SafeCastOverflowedUintDowncast(32, value);
}
return uint32(value);
}
/**
* @dev Returns the downcasted uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toUint24(uint256 value) internal pure returns (uint24) {
if (value > type(uint24).max) {
revert SafeCastOverflowedUintDowncast(24, value);
}
return uint24(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toUint16(uint256 value) internal pure returns (uint16) {
if (value > type(uint16).max) {
revert SafeCastOverflowedUintDowncast(16, value);
}
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toUint8(uint256 value) internal pure returns (uint8) {
if (value > type(uint8).max) {
revert SafeCastOverflowedUintDowncast(8, value);
}
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*/
function toUint256(int256 value) internal pure returns (uint256) {
if (value < 0) {
revert SafeCastOverflowedIntToUint(value);
}
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(248, value);
}
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(240, value);
}
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(232, value);
}
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(224, value);
}
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(216, value);
}
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(208, value);
}
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(200, value);
}
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(192, value);
}
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(184, value);
}
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(176, value);
}
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(168, value);
}
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(160, value);
}
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(152, value);
}
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(144, value);
}
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(136, value);
}
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toInt128(int256 value) internal pure returns (int128 downcasted) {
downcasted = int128(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(128, value);
}
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(120, value);
}
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(112, value);
}
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(104, value);
}
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(96, value);
}
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(88, value);
}
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(80, value);
}
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(72, value);
}
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toInt64(int256 value) internal pure returns (int64 downcasted) {
downcasted = int64(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(64, value);
}
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(56, value);
}
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(48, value);
}
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(40, value);
}
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toInt32(int256 value) internal pure returns (int32 downcasted) {
downcasted = int32(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(32, value);
}
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(24, value);
}
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toInt16(int256 value) internal pure returns (int16 downcasted) {
downcasted = int16(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(16, value);
}
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toInt8(int256 value) internal pure returns (int8 downcasted) {
downcasted = int8(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(8, value);
}
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
if (value > uint256(type(int256).max)) {
revert SafeCastOverflowedUintToInt(value);
}
return int256(value);
}
/**
* @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.
*/
function toUint(bool b) internal pure returns (uint256 u) {
assembly ("memory-safe") {
u := iszero(iszero(b))
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/types/Time.sol)
pragma solidity ^0.8.20;
import {Math} from "../math/Math.sol";
import {SafeCast} from "../math/SafeCast.sol";
/**
* @dev This library provides helpers for manipulating time-related objects.
*
* It uses the following types:
* - `uint48` for timepoints
* - `uint32` for durations
*
* While the library doesn't provide specific types for timepoints and duration, it does provide:
* - a `Delay` type to represent duration that can be programmed to change value automatically at a given point
* - additional helper functions
*/
library Time {
using Time for *;
/**
* @dev Get the block timestamp as a Timepoint.
*/
function timestamp() internal view returns (uint48) {
return SafeCast.toUint48(block.timestamp);
}
/**
* @dev Get the block number as a Timepoint.
*/
function blockNumber() internal view returns (uint48) {
return SafeCast.toUint48(block.number);
}
// ==================================================== Delay =====================================================
/**
* @dev A `Delay` is a uint32 duration that can be programmed to change value automatically at a given point in the
* future. The "effect" timepoint describes when the transitions happens from the "old" value to the "new" value.
* This allows updating the delay applied to some operation while keeping some guarantees.
*
* In particular, the {update} function guarantees that if the delay is reduced, the old delay still applies for
* some time. For example if the delay is currently 7 days to do an upgrade, the admin should not be able to set
* the delay to 0 and upgrade immediately. If the admin wants to reduce the delay, the old delay (7 days) should
* still apply for some time.
*
*
* The `Delay` type is 112 bits long, and packs the following:
*
* ```
* | [uint48]: effect date (timepoint)
* | | [uint32]: value before (duration)
* ↓ ↓ ↓ [uint32]: value after (duration)
* 0xAAAAAAAAAAAABBBBBBBBCCCCCCCC
* ```
*
* NOTE: The {get} and {withUpdate} functions operate using timestamps. Block number based delays are not currently
* supported.
*/
type Delay is uint112;
/**
* @dev Wrap a duration into a Delay to add the one-step "update in the future" feature
*/
function toDelay(uint32 duration) internal pure returns (Delay) {
return Delay.wrap(duration);
}
/**
* @dev Get the value at a given timepoint plus the pending value and effect timepoint if there is a scheduled
* change after this timepoint. If the effect timepoint is 0, then the pending value should not be considered.
*/
function _getFullAt(
Delay self,
uint48 timepoint
) private pure returns (uint32 valueBefore, uint32 valueAfter, uint48 effect) {
(valueBefore, valueAfter, effect) = self.unpack();
return effect <= timepoint ? (valueAfter, 0, 0) : (valueBefore, valueAfter, effect);
}
/**
* @dev Get the current value plus the pending value and effect timepoint if there is a scheduled change. If the
* effect timepoint is 0, then the pending value should not be considered.
*/
function getFull(Delay self) internal view returns (uint32 valueBefore, uint32 valueAfter, uint48 effect) {
return _getFullAt(self, timestamp());
}
/**
* @dev Get the current value.
*/
function get(Delay self) internal view returns (uint32) {
(uint32 delay, , ) = self.getFull();
return delay;
}
/**
* @dev Update a Delay object so that it takes a new duration after a timepoint that is automatically computed to
* enforce the old delay at the moment of the update. Returns the updated Delay object and the timestamp when the
* new delay becomes effective.
*/
function withUpdate(
Delay self,
uint32 newValue,
uint32 minSetback
) internal view returns (Delay updatedDelay, uint48 effect) {
uint32 value = self.get();
uint32 setback = uint32(Math.max(minSetback, value > newValue ? value - newValue : 0));
effect = timestamp() + setback;
return (pack(value, newValue, effect), effect);
}
/**
* @dev Split a delay into its components: valueBefore, valueAfter and effect (transition timepoint).
*/
function unpack(Delay self) internal pure returns (uint32 valueBefore, uint32 valueAfter, uint48 effect) {
uint112 raw = Delay.unwrap(self);
valueAfter = uint32(raw);
valueBefore = uint32(raw >> 32);
effect = uint48(raw >> 64);
return (valueBefore, valueAfter, effect);
}
/**
* @dev pack the components into a Delay object.
*/
function pack(uint32 valueBefore, uint32 valueAfter, uint48 effect) internal pure returns (Delay) {
return Delay.wrap((uint112(effect) << 64) | (uint112(valueBefore) << 32) | uint112(valueAfter));
}
}// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.28;
import { ITokenP } from "contracts/interfaces/ITokenP.sol";
import "../parallelizer/Storage.sol";
/// @title IGetters
/// @author Cooper Labs
/// @custom:contact [email protected]
/// @dev This interface is an authorized fork of Angle's `IGetters` interface
/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/interfaces/IGetters.sol
interface IGetters {
/// @notice Checks whether a given `selector` is actually a valid selector corresponding to a function in one of
/// the
/// facets of the proxy
function isValidSelector(bytes4 selector) external view returns (bool);
/// @notice Stablecoin minted by parallelizer
function tokenP() external view returns (ITokenP);
/// @notice Returns the list of collateral assets supported by the system
function getCollateralList() external view returns (address[] memory);
/// @notice Returns all the info in storage associated to a `collateral`
function getCollateralInfo(address collateral) external view returns (Collateral memory);
/// @notice Returns the decimals of a given `collateral`
function getCollateralDecimals(address collateral) external view returns (uint8);
/// @notice Returns the `xFee` and `yFee` arrays from which fees are computed when coming to mint
/// with `collateral`
function getCollateralMintFees(address collateral) external view returns (uint64[] memory, int64[] memory);
/// @notice Returns the `xFee` and `yFee` arrays from which fees are computed when coming to burn
/// for `collateral`
function getCollateralBurnFees(address collateral) external view returns (uint64[] memory, int64[] memory);
/// @notice Returns the `xFee` and `yFee` arrays used to compute the penalty factor depending on the collateral
/// ratio when users come to redeem
function getRedemptionFees() external view returns (uint64[] memory, int64[] memory);
/// @notice Returns the collateral ratio of Parallelizer in base `10**9` and a rounded version of the total amount
/// of stablecoins issued
function getCollateralRatio() external view returns (uint64 collatRatio, uint256 stablecoinsIssued);
/// @notice Returns the total amount of stablecoins issued through Parallelizer
function getTotalIssued() external view returns (uint256 stablecoinsIssued);
/// @notice Returns the amount of stablecoins issued from `collateral` and the total amount of stablecoins issued
/// through Parallelizer
function getIssuedByCollateral(address collateral)
external
view
returns (uint256 stablecoinsFromCollateral, uint256 stablecoinsIssued);
/// @notice Returns if a collateral is "managed" and the associated manager configuration
function getManagerData(address collateral)
external
view
returns (bool isManaged, IERC20[] memory subCollaterals, bytes memory config);
/// @notice Returns the oracle values associated to `collateral`
/// @return mint Oracle value to be used for a mint transaction with `collateral`
/// @return burn Oracle value that will be used for `collateral` for a burn transaction. This value
/// is then used along with oracle values for all other collateral assets to get a global burn value for the oracle
/// @return ratio Ratio, in base `10**18` between the oracle value of the `collateral` and its target price.
/// This value is 10**18 if the oracle is greater than the collateral price
/// @return minRatio Minimum ratio across all collateral assets between a collateral burn price and its target
/// price. This value is independent of `collateral` and is used to normalize the burn oracle value for burn
/// transactions.
/// @return redemption Oracle value that would be used to price `collateral` when computing the collateral ratio
/// during a redemption
function getOracleValues(address collateral)
external
view
returns (uint256 mint, uint256 burn, uint256 ratio, uint256 minRatio, uint256 redemption);
/// @notice Returns the data used to compute oracle values for `collateral`
/// @return oracleType Type of oracle (Chainlink, external smart contract, ...)
/// @return targetType Type passed to read the value of the target price
/// @return oracleData Extra data needed to read the oracle. For Chainlink oracles, this data is supposed to give
/// the addresses of the Chainlink feeds to read, the stale periods for each feed, ...
/// @return targetData Extra data needed to read the target price of the asset
function getOracle(address collateral)
external
view
returns (
OracleReadType oracleType,
OracleReadType targetType,
bytes memory oracleData,
bytes memory targetData,
bytes memory hyperparameters
);
/// @notice Returns if the associated functionality is paused or not
function isPaused(address collateral, ActionType action) external view returns (bool);
/// @notice Returns if `sender` is trusted to update normalizers
function isTrusted(address sender) external view returns (bool);
/// @notice Returns if `sender` is trusted to update sell rewards
function isTrustedSeller(address sender) external view returns (bool);
/// @notice Checks whether `sender` has a non null entry in the `isWhitelistedForType` storage mapping
/// @dev Note that ultimately whitelisting may depend as well on external providers
function isWhitelistedForType(WhitelistType whitelistType, address sender) external view returns (bool);
/// @notice Checks whether `sender` can deal with `collateral` during burns and redemptions
function isWhitelistedForCollateral(address collateral, address sender) external returns (bool);
/// @notice Checks whether only whitelisted address can deal with `collateral` during burns and redemptions
function isWhitelistedCollateral(address collateral) external view returns (bool);
/// @notice Gets the data needed to deal with whitelists for `collateral`
function getCollateralWhitelistData(address collateral) external view returns (bytes memory);
/// @notice Returns the stablecoin cap for `collateral`
function getStablecoinCap(address collateral) external view returns (uint256);
/// @notice Returns the address of the `accessManager` contract
function accessManager() external view returns (address);
/// @dev Returns true only in the context of a delayed restricted call, at the moment that the scheduled operation is
/// being consumed. Prevents denial of service for delayed restricted calls in the case that the contract performs
/// attacker controlled calls.
function isConsumingScheduledOp() external view returns (bytes4);
}// SPDX-License-Identifier: GPL-3.0 pragma solidity 0.8.28; /// @title IManager /// @author Cooper Labs /// @custom:contact [email protected] /// @dev This interface is an authorized fork of Angle's `IManager` interface /// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/interfaces/IManager.sol interface IManager { /// @notice Returns the amount of collateral managed by the Manager /// @return balances Balances of all the subCollaterals handled by the manager /// @dev MUST NOT revert function totalAssets() external view returns (uint256[] memory balances, uint256 totalValue); /// @notice Hook to invest `amount` of `collateral` /// @dev MUST revert if the manager cannot accept these funds /// @dev MUST have received the funds beforehand function invest(uint256 amount) external; /// @notice Sends `amount` of `collateral` to the `to` address /// @dev Called when `tokenP` are burnt and during redemptions // @dev MUST revert if there are not funds enough available /// @dev MUST be callable only by the parallelizer function release(address asset, address to, uint256 amount) external; /// @notice Gives the maximum amount of collateral immediately available for a transfer /// @dev Useful for integrators using `quoteIn` and `quoteOut` function maxAvailable() external view returns (uint256); }
// SPDX-License-Identifier: GPL-3.0 pragma solidity 0.8.28; /// @title IParallelizerOracle /// @author Cooper Labs /// @custom:contact [email protected] /// @dev This interface is an authorized fork of Angle's `IParallelizerOracle` interface /// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/interfaces/IParallelizerOracle.sol interface IParallelizerOracle { /// @notice Reads the oracle value for asset to use in a redemption to compute the collateral ratio function readRedemption() external view returns (uint256); /// @notice Reads the oracle value for asset to use in a mint. It should be comprehensive of the /// deviation from the target price function readMint() external view returns (uint256); /// @notice Reads the oracle value for asset to use in a burn transaction as well as the ratio /// between the current price and the target price for the asset function readBurn() external view returns (uint256 oracleValue, uint256 ratio); /// @notice Reads the oracle value for asset function read() external view returns (uint256); }
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.28;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
/// @title ITokenP
/// @author Cooper Labs
/// @custom:contact [email protected]
/// @notice Interface for the stablecoins `tokenP` contracts
/// @dev This interface is an authorized fork of Angle's `IAgToken` interface
/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/interfaces/IAgToken.sol
interface ITokenP is IERC20 {
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
MINTER ROLE ONLY FUNCTIONS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
/// @notice Lets a whitelisted contract mint tokenPs
/// @param account Address to mint to
/// @param amount Amount to mint
function mint(address account, uint256 amount) external;
/// @notice Burns `amount` tokens from a `burner` address after being asked to by `sender`
/// @param amount Amount of tokens to burn
/// @param burner Address to burn from
/// @param sender Address which requested the burn from `burner`
/// @dev This method is to be called by a contract with the minter right after being requested
/// to do so by a `sender` address willing to burn tokens from another `burner` address
/// @dev The method checks the allowance between the `sender` and the `burner`
function burnFrom(uint256 amount, address burner, address sender) external;
/// @notice Burns `amount` tokens from a `burner` address
/// @param amount Amount of tokens to burn
/// @param burner Address to burn from
/// @dev This method is to be called by a contract with a minter right on the tokenP after being
/// requested to do so by an address willing to burn tokens from its address
function burnSelf(uint256 amount, address burner) external;
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
EXTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
/// @notice Amount of decimals of the stablecoin
function decimals() external view returns (uint8);
}// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.5.0;
interface AggregatorV3Interface {
function decimals() external view returns (uint8);
function description() external view returns (string memory);
function version() external view returns (uint256);
// getRoundData and latestRoundData should both raise "No data present"
// if they do not have data to report, instead of returning unset values
// which could be misinterpreted as actual reported values.
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: GPL-3.0
pragma solidity 0.8.28;
import { Math } from "@openzeppelin/contracts/utils/math/Math.sol";
import "../Storage.sol";
/// @title LibHelpers
/// @author Cooper Labs
/// @custom:contact [email protected]
/// @dev This library is an authorized fork of Angle's `LibHelpers` library
/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/parallelizer/libraries/LibHelpers.sol
library LibHelpers {
/// @notice Rebases the units of `amount` from `fromDecimals` to `toDecimals`
function convertDecimalTo(uint256 amount, uint8 fromDecimals, uint8 toDecimals) internal pure returns (uint256) {
if (fromDecimals > toDecimals) return amount / 10 ** (fromDecimals - toDecimals);
else if (fromDecimals < toDecimals) return amount * 10 ** (toDecimals - fromDecimals);
else return amount;
}
/// @notice Checks whether a `token` is in a list `tokens` and returns the index of the token in the list
/// or -1 in the other case
function checkList(address token, address[] memory tokens) internal pure returns (int256) {
uint256 tokensLength = tokens.length;
for (uint256 i; i < tokensLength; ++i) {
if (token == tokens[i]) return int256(i);
}
return -1;
}
/// @notice Searches a sorted `array` and returns the first index that contains a value strictly greater
/// (or lower if increasingArray is false) to `element` minus 1
/// @dev If no such index exists (i.e. all values in the array are strictly lesser/greater than `element`),
/// either array length minus 1, or 0 are returned
/// @dev The time complexity of the search is O(log n).
/// @dev Inspired from OpenZeppelin Contracts v4.4.1:
/// https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Arrays.sol
/// @dev Modified by Angle Labs to support `uint64`, monotonous arrays and exclusive upper bounds
function findLowerBound(
bool increasingArray,
uint64[] memory array,
uint64 normalizerArray,
uint64 element
)
internal
pure
returns (uint256)
{
if (array.length == 0) {
return 0;
}
uint256 low = 1;
uint256 high = array.length;
if (
(increasingArray && array[high - 1] * normalizerArray <= element)
|| (!increasingArray && array[high - 1] * normalizerArray >= element)
) return high - 1;
while (low < high) {
uint256 mid = Math.average(low, high);
// Note that mid will always be strictly less than high (i.e. it will be a valid array index)
// because Math.average rounds down (it does integer division with truncation).
if (increasingArray ? array[mid] * normalizerArray > element : array[mid] * normalizerArray < element) {
high = mid;
} else {
low = mid + 1;
}
}
// At this point `low` is the exclusive upper bound.
// `low - 1` is the inclusive lower bound.
return low - 1;
}
/// @notice Evaluates for `x` a piecewise linear function defined with the breaking points in the arrays
/// `xArray` and `yArray`
/// @dev The values in the `xArray` must be increasing
function piecewiseLinear(uint64 x, uint64[] memory xArray, int64[] memory yArray) internal pure returns (int64) {
uint256 indexLowerBound = findLowerBound(true, xArray, 1, x);
if (indexLowerBound == 0 && x < xArray[0]) return yArray[0];
else if (indexLowerBound == xArray.length - 1) return yArray[xArray.length - 1];
return yArray[indexLowerBound]
+ ((yArray[indexLowerBound + 1] - yArray[indexLowerBound]) * int64(x - xArray[indexLowerBound]))
/ int64(xArray[indexLowerBound + 1] - xArray[indexLowerBound]);
}
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
import { IManager } from "contracts/interfaces/IManager.sol";
import "../Storage.sol";
/// @title LibManager
/// @author Cooper Labs
/// @custom:contact [email protected]
/// @dev Managed collateral assets may be handled through external smart contracts or directly through this library
/// @dev There is no implementation at this point for a managed collateral handled through this library, and
/// a new specific `ManagerType` would need to be added in this case
/// @dev This library is an authorized fork of Angle's `LibManager` library
/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/parallelizer/libraries/LibManager.sol
library LibManager {
/// @notice Checks to which address managed funds must be transferred
function transferRecipient(bytes memory config) internal view returns (address recipient) {
(ManagerType managerType, bytes memory data) = parseManagerConfig(config);
recipient = address(this);
if (managerType == ManagerType.EXTERNAL) return abi.decode(data, (address));
}
/// @notice Performs a transfer of `token` for a collateral that is managed to a `to` address
/// @dev `token` may not be the actual collateral itself, as some collaterals have subcollaterals associated
/// with it
/// @dev Eventually pulls funds from strategies
function release(address token, address to, uint256 amount, bytes memory config) internal {
(ManagerType managerType, bytes memory data) = parseManagerConfig(config);
if (managerType == ManagerType.EXTERNAL) abi.decode(data, (IManager)).release(token, to, amount);
}
/// @notice Gets the balances of all the tokens controlled through `managerData`
/// @return balances An array of size `subCollaterals` with current balances of all subCollaterals
/// including the one corresponding to the `managerData` given
/// @return totalValue The value of all the `subCollaterals` in `collateral`
/// @dev `subCollaterals` must always have as first token (index 0) the collateral itself
function totalAssets(bytes memory config) internal view returns (uint256[] memory balances, uint256 totalValue) {
(ManagerType managerType, bytes memory data) = parseManagerConfig(config);
if (managerType == ManagerType.EXTERNAL) return abi.decode(data, (IManager)).totalAssets();
}
/// @notice Calls a hook if needed after new funds have been transfered to a manager
function invest(uint256 amount, bytes memory config) internal {
(ManagerType managerType, bytes memory data) = parseManagerConfig(config);
if (managerType == ManagerType.EXTERNAL) abi.decode(data, (IManager)).invest(amount);
}
/// @notice Returns available underlying tokens, for instance if liquidity is fully used and
/// not withdrawable the function will return 0
function maxAvailable(bytes memory config) internal view returns (uint256 available) {
(ManagerType managerType, bytes memory data) = parseManagerConfig(config);
if (managerType == ManagerType.EXTERNAL) return abi.decode(data, (IManager)).maxAvailable();
}
/// @notice Decodes the `managerData` associated to a collateral
function parseManagerConfig(bytes memory config) internal pure returns (ManagerType managerType, bytes memory data) {
(managerType, data) = abi.decode(config, (ManagerType, bytes));
}
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
import { IParallelizerOracle } from "contracts/interfaces/IParallelizerOracle.sol";
import { AggregatorV3Interface } from "contracts/interfaces/external/chainlink/AggregatorV3Interface.sol";
import { IMorphoOracle } from "contracts/interfaces/external/morpho/IMorphoOracle.sol";
import { LibStorage as s } from "./LibStorage.sol";
import "../../utils/Constants.sol";
import "../../utils/Errors.sol";
import "../Storage.sol";
/// @title LibOracle
/// @author Cooper Labs
/// @custom:contact [email protected]
/// @dev This library is an authorized fork of Angle's `LibOracle` library
/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/parallelizer/libraries/LibOracle.sol
library LibOracle {
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ACTIONS SPECIFIC ORACLES
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
/// @notice Reads the oracle value used during a redemption to compute collateral ratio for `oracleConfig`
/// @dev This value is only sensitive to compute the collateral ratio and deduce a penalty factor
function readRedemption(bytes memory oracleConfig) internal view returns (uint256 oracleValue) {
(OracleReadType oracleType, OracleReadType targetType, bytes memory oracleData, bytes memory targetData,) =
_parseOracleConfig(oracleConfig);
if (oracleType == OracleReadType.EXTERNAL) {
IParallelizerOracle externalOracle = abi.decode(oracleData, (IParallelizerOracle));
return externalOracle.readRedemption();
} else {
(oracleValue,) = readSpotAndTarget(oracleType, targetType, oracleData, targetData, 0);
return oracleValue;
}
}
/// @notice Reads the oracle value used during mint operations for an asset with `oracleConfig`
/// @dev For assets which do not rely on external oracles, this value is the minimum between the processed oracle
/// value for the asset and its target price
function readMint(bytes memory oracleConfig) internal view returns (uint256 oracleValue) {
(
OracleReadType oracleType,
OracleReadType targetType,
bytes memory oracleData,
bytes memory targetData,
bytes memory hyperparameters
) = _parseOracleConfig(oracleConfig);
if (oracleType == OracleReadType.EXTERNAL) {
IParallelizerOracle externalOracle = abi.decode(oracleData, (IParallelizerOracle));
return externalOracle.readMint();
}
(uint128 userDeviation,) = abi.decode(hyperparameters, (uint128, uint128));
uint256 targetPrice;
(oracleValue, targetPrice) = readSpotAndTarget(oracleType, targetType, oracleData, targetData, userDeviation);
if (targetPrice < oracleValue) oracleValue = targetPrice;
}
/// @notice Reads the oracle value used for a burn operation for an asset with `oracleConfig`
/// @return oracleValue The actual oracle value obtained
/// @return ratio If `oracle value < target price`, the ratio between the oracle value and the target
/// price, otherwise `BASE_18`
function readBurn(bytes memory oracleConfig) internal view returns (uint256 oracleValue, uint256 ratio) {
(
OracleReadType oracleType,
OracleReadType targetType,
bytes memory oracleData,
bytes memory targetData,
bytes memory hyperparameters
) = _parseOracleConfig(oracleConfig);
if (oracleType == OracleReadType.EXTERNAL) {
IParallelizerOracle externalOracle = abi.decode(oracleData, (IParallelizerOracle));
return externalOracle.readBurn();
}
(uint128 userDeviation, uint128 burnRatioDeviation) = abi.decode(hyperparameters, (uint128, uint128));
uint256 targetPrice;
(oracleValue, targetPrice) = readSpotAndTarget(oracleType, targetType, oracleData, targetData, userDeviation);
// Firewall in case the oracle value reported is low compared to the target
// If the oracle value is slightly below its target, then no deviation is reported for the oracle and
// the price of burning the stablecoin for other assets is not impacted. Also, the oracle value of this asset
// is set to the target price, to not be open to direct arbitrage
ratio = BASE_18;
if (oracleValue * BASE_18 < targetPrice * (BASE_18 - burnRatioDeviation)) {
ratio = (oracleValue * BASE_18) / targetPrice;
} else if (oracleValue < targetPrice) {
oracleValue = targetPrice;
}
}
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
VIEW FUNCTIONS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
/// @notice Internal version of the `getOracle` function
function getOracle(address collateral)
internal
view
returns (OracleReadType, OracleReadType, bytes memory, bytes memory, bytes memory)
{
return _parseOracleConfig(s.transmuterStorage().collaterals[collateral].oracleConfig);
}
/// @notice Gets the oracle value and the ratio with respect to the target price when it comes to
/// burning for `collateral`
function getBurnOracle(
address collateral,
bytes memory oracleConfig
)
internal
view
returns (uint256 minRatio, uint256 oracleValue)
{
ParallelizerStorage storage ts = s.transmuterStorage();
minRatio = BASE_18;
address[] memory collateralList = ts.collateralList;
uint256 length = collateralList.length;
for (uint256 i; i < length; ++i) {
uint256 ratioObserved = BASE_18;
if (collateralList[i] != collateral) {
(, ratioObserved) = readBurn(ts.collaterals[collateralList[i]].oracleConfig);
} else {
(oracleValue, ratioObserved) = readBurn(oracleConfig);
}
if (ratioObserved < minRatio) minRatio = ratioObserved;
}
}
/// @notice Computes the `quoteAmount` (for Chainlink oracles) depending on a `quoteType` and a base value
/// (e.g the target price of the asset)
/// @dev For cases where the Chainlink feed directly looks into the value of the asset, `quoteAmount` is `BASE_18`.
/// For others, like wstETH for which Chainlink only has an oracle for stETH, `quoteAmount` is the target price
function quoteAmount(OracleQuoteType quoteType, uint256 baseValue) internal pure returns (uint256) {
if (quoteType == OracleQuoteType.UNIT) return BASE_18;
else return baseValue;
}
function readSpotAndTarget(
OracleReadType oracleType,
OracleReadType targetType,
bytes memory oracleData,
bytes memory targetData,
uint256 deviation
)
internal
view
returns (uint256 oracleValue, uint256 targetPrice)
{
targetPrice = read(targetType, BASE_18, targetData);
oracleValue = read(oracleType, targetPrice, oracleData);
// System may tolerate small deviations from target
// If the oracle value reported is reasonably close to the target
// --> disregard the oracle value and return the target price
if (
targetPrice * (BASE_18 - deviation) < oracleValue * BASE_18
&& oracleValue * BASE_18 < targetPrice * (BASE_18 + deviation)
) oracleValue = targetPrice;
}
/// @notice Reads an oracle value (or a target oracle value) for an asset based on its data parsed `oracleConfig`
function read(OracleReadType readType, uint256 baseValue, bytes memory data) internal view returns (uint256) {
if (readType == OracleReadType.CHAINLINK_FEEDS) {
(
AggregatorV3Interface[] memory circuitChainlink,
uint32[] memory stalePeriods,
uint8[] memory circuitChainIsMultiplied,
uint8[] memory chainlinkDecimals,
OracleQuoteType quoteType
) = abi.decode(data, (AggregatorV3Interface[], uint32[], uint8[], uint8[], OracleQuoteType));
uint256 quotePrice = quoteAmount(quoteType, baseValue);
uint256 listLength = circuitChainlink.length;
for (uint256 i; i < listLength; ++i) {
quotePrice = readChainlinkFeed(
quotePrice, circuitChainlink[i], circuitChainIsMultiplied[i], chainlinkDecimals[i], stalePeriods[i]
);
}
return quotePrice;
} else if (readType == OracleReadType.STABLE) {
return BASE_18;
} else if (readType == OracleReadType.NO_ORACLE) {
return baseValue;
} else if (readType == OracleReadType.WSTETH) {
return STETH.getPooledEthByShares(1 ether);
} else if (readType == OracleReadType.CBETH) {
return CBETH.exchangeRate();
} else if (readType == OracleReadType.RETH) {
return RETH.getExchangeRate();
} else if (readType == OracleReadType.SFRXETH) {
return SFRXETH.pricePerShare();
} else if (readType == OracleReadType.MAX) {
uint256 maxValue = abi.decode(data, (uint256));
return maxValue;
} else if (readType == OracleReadType.MORPHO_ORACLE) {
(address contractAddress, uint256 normalizationFactor) = abi.decode(data, (address, uint256));
return IMorphoOracle(contractAddress).price() / normalizationFactor;
}
// If the `OracleReadType` is `EXTERNAL`, it means that this function is called to compute a
// `targetPrice` in which case the `baseValue` is returned here
else {
return baseValue;
}
}
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
SPECIFIC HELPERS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
/// @notice Reads a Chainlink feed using a quote amount and converts the quote amount to the out-currency
/// @param _quoteAmount The amount for which to compute the price expressed in `BASE_18`
/// @param feed Chainlink feed to query
/// @param multiplied Whether the ratio outputted by Chainlink should be multiplied or divided to the `quoteAmount`
/// @param decimals Number of decimals of the corresponding Chainlink pair
/// @return The `quoteAmount` converted in out-currency
function readChainlinkFeed(
uint256 _quoteAmount,
AggregatorV3Interface feed,
uint8 multiplied,
uint256 decimals,
uint32 stalePeriod
)
internal
view
returns (uint256)
{
(, int256 ratio,, uint256 updatedAt,) = feed.latestRoundData();
if (ratio <= 0 || block.timestamp - updatedAt > stalePeriod) revert InvalidChainlinkRate();
// Checking whether we should multiply or divide by the ratio computed
if (multiplied == 1) return (_quoteAmount * uint256(ratio)) / (10 ** decimals);
else return (_quoteAmount * (10 ** decimals)) / uint256(ratio);
}
/// @notice Parses an `oracleConfig` into several sub fields
function _parseOracleConfig(bytes memory oracleConfig)
private
pure
returns (OracleReadType, OracleReadType, bytes memory, bytes memory, bytes memory)
{
return abi.decode(oracleConfig, (OracleReadType, OracleReadType, bytes, bytes, bytes));
}
function updateOracle(address collateral) internal {
ParallelizerStorage storage ts = s.transmuterStorage();
if (ts.collaterals[collateral].decimals == 0) revert NotCollateral();
(
OracleReadType oracleType,
OracleReadType targetType,
bytes memory oracleData,
bytes memory targetData,
bytes memory hyperparameters
) = _parseOracleConfig(ts.collaterals[collateral].oracleConfig);
if (targetType != OracleReadType.MAX) revert OracleUpdateFailed();
uint256 oracleValue = read(oracleType, BASE_18, oracleData);
uint256 maxValue = abi.decode(targetData, (uint256));
if (oracleValue > maxValue) {
ts.collaterals[collateral].oracleConfig = abi.encode(
oracleType,
targetType,
oracleData,
// There are no checks whether the value increased or not
abi.encode(oracleValue),
hyperparameters
);
} else {
revert OracleUpdateFailed();
}
}
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
import "../../utils/Constants.sol";
import { DiamondStorage, ImplementationStorage, ParallelizerStorage } from "../Storage.sol";
/// @title LibStorage
/// @author Cooper Labs
/// @custom:contact [email protected]
/// @dev This library is an authorized fork of Angle's `LibStorage` library
/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/parallelizer/libraries/LibStorage.sol
library LibStorage {
/// @notice Returns the storage struct stored at the `DIAMOND_STORAGE_POSITION` slot
/// @dev This struct handles the logic of the different facets used in the diamond proxy
function diamondStorage() internal pure returns (DiamondStorage storage ds) {
bytes32 position = DIAMOND_STORAGE_POSITION;
assembly ("memory-safe") {
ds.slot := position
}
}
/// @notice Returns the storage struct stored at the `TRANSMUTER_STORAGE_POSITION` slot
/// @dev This struct handles the particular logic of the Parallelizer system
function transmuterStorage() internal pure returns (ParallelizerStorage storage ts) {
bytes32 position = TRANSMUTER_STORAGE_POSITION;
assembly ("memory-safe") {
ts.slot := position
}
}
/// @notice Returns the storage struct stored at the `IMPLEMENTATION_STORAGE_POSITION` slot
/// @dev This struct handles the logic for making the contract easily usable on Etherscan
function implementationStorage() internal pure returns (ImplementationStorage storage ims) {
bytes32 position = IMPLEMENTATION_STORAGE_POSITION;
assembly ("memory-safe") {
ims.slot := position
}
}
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
import { IKeyringGuard } from "contracts/interfaces/external/keyring/IKeyringGuard.sol";
import { LibStorage as s } from "./LibStorage.sol";
import "../../utils/Errors.sol";
import "../Storage.sol";
/// @title LibWhitelist
/// @author Cooper Labs
/// @custom:contact [email protected]
/// @dev This library is an authorized fork of Angle's `LibWhitelist` library
/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/parallelizer/libraries/LibWhitelist.sol
library LibWhitelist {
/// @notice Checks whether `sender` is whitelisted for a collateral with `whitelistData`
function checkWhitelist(bytes memory whitelistData, address sender) internal returns (bool) {
(WhitelistType whitelistType, bytes memory data) = abi.decode(whitelistData, (WhitelistType, bytes));
if (s.transmuterStorage().isWhitelistedForType[whitelistType][sender] > 0) return true;
if (data.length != 0) {
if (whitelistType == WhitelistType.BACKED) {
address keyringGuard = abi.decode(data, (address));
if (keyringGuard != address(0)) return IKeyringGuard(keyringGuard).isAuthorized(address(this), sender);
}
}
return false;
}
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
import { ICbETH } from "contracts/interfaces/external/coinbase/ICbETH.sol";
import { ISfrxETH } from "contracts/interfaces/external/frax/ISfrxETH.sol";
import { IStETH } from "contracts/interfaces/external/lido/IStETH.sol";
import { IRETH } from "contracts/interfaces/external/rocketPool/IRETH.sol";
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
STORAGE SLOTS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
/// @dev Storage position of `DiamondStorage` structure
/// @dev Equals `keccak256("diamond.standard.diamond.storage") - 1`
bytes32 constant DIAMOND_STORAGE_POSITION = 0xc8fcad8db84d3cc18b4c41d551ea0ee66dd599cde068d998e57d5e09332c131b;
/// @dev Storage position of `ParallelizerStorage` structure
/// @dev Equals `keccak256("diamond.standard.parallelizer.storage") - 1`
bytes32 constant TRANSMUTER_STORAGE_POSITION = 0x4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c75;
/// @dev Storage position of `ImplementationStorage` structure
/// @dev Equals `keccak256("eip1967.proxy.implementation") - 1`
bytes32 constant IMPLEMENTATION_STORAGE_POSITION = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
MATHS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
uint256 constant BASE_6 = 1e6;
uint256 constant BASE_8 = 1e8;
uint256 constant BASE_9 = 1e9;
uint256 constant BASE_12 = 1e12;
uint256 constant BPS = 1e14;
uint256 constant BASE_18 = 1e18;
uint256 constant HALF_BASE_27 = 1e27 / 2;
uint256 constant BASE_27 = 1e27;
uint256 constant BASE_36 = 1e36;
uint256 constant MAX_BURN_FEE = 999_000_000;
uint256 constant MAX_MINT_FEE = BASE_12 - 1;
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
REENTRANT
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint8 constant NOT_ENTERED = 1;
uint8 constant ENTERED = 2;
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
REENTRANT
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
// Role IDs for the AccessManager
uint64 constant GOVERNOR_ROLE = 10;
uint64 constant GUARDIAN_ROLE = 20;
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
COMMON ADDRESSES
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
address constant PERMIT_2 = 0x000000000022D473030F116dDEE9F6B43aC78BA3;
address constant ODOS_ROUTER = 0xCf5540fFFCdC3d510B18bFcA6d2b9987b0772559;
address constant AGEUR = 0x1a7e4e63778B4f12a199C062f3eFdD288afCBce8;
ICbETH constant CBETH = ICbETH(0xBe9895146f7AF43049ca1c1AE358B0541Ea49704);
IRETH constant RETH = IRETH(0xae78736Cd615f374D3085123A210448E74Fc6393);
IStETH constant STETH = IStETH(0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84);
ISfrxETH constant SFRXETH = ISfrxETH(0xac3E018457B222d93114458476f3E3416Abbe38F);
address constant XEVT = 0x3Ee320c9F73a84D1717557af00695A34b26d1F1d;
address constant USDM = 0x59D9356E565Ab3A36dD77763Fc0d87fEaf85508C;
address constant STEAK_USDC = 0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB;
address constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
address constant EURC = 0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c;// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.28; error AccessManagedUnauthorized(address caller); error AlreadyAdded(); error CannotAddFunctionToDiamondThatAlreadyExists(bytes4 _selector); error CannotAddSelectorsToZeroAddress(bytes4[] _selectors); error CannotRemoveFunctionThatDoesNotExist(bytes4 _selector); error CannotRemoveImmutableFunction(bytes4 _selector); error CannotReplaceFunctionsFromFacetWithZeroAddress(bytes4[] _selectors); error CannotReplaceFunctionThatDoesNotExists(bytes4 _selector); error CannotReplaceFunctionWithTheSameFunctionFromTheSameFacet(bytes4 _selector); error CannotReplaceImmutableFunction(bytes4 _selector); error ContractHasNoCode(); error CollateralBacked(); error FunctionNotFound(bytes4 _functionSelector); error IncorrectFacetCutAction(uint8 _action); error InitializationFunctionReverted(address _initializationContractAddress, bytes _calldata); error InvalidChainlinkRate(); error InvalidLengths(); error InvalidNegativeFees(); error InvalidOracleType(); error InvalidParam(); error InvalidParams(); error InvalidRate(); error InvalidSwap(); error InvalidTokens(); error InvalidAccessManager(); error ManagerHasAssets(); error NoSelectorsProvidedForFacetForCut(address _facetAddress); error NotAllowed(); error NotCollateral(); error NotGovernor(); error NotGuardian(); error NotTrusted(); error NotTrustedOrGuardian(); error NotWhitelisted(); error OdosSwapFailed(); error OracleUpdateFailed(); error Paused(); error ReentrantCall(); error RemoveFacetAddressMustBeZeroAddress(address _facetAddress); error TooBigAmountIn(); error TooLate(); error TooSmallAmountOut(); error ZeroAddress(); error ZeroAmount(); error SwapError(); error SlippageTooHigh(); error InsufficientFunds();
{
"evmVersion": "cancun",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs",
"useLiteralContent": true
},
"optimizer": {
"enabled": true,
"runs": 1000
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"viaIR": true
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[],"name":"InvalidChainlinkRate","type":"error"},{"inputs":[],"name":"NotCollateral","type":"error"},{"inputs":[],"name":"ReentrantCall","type":"error"},{"inputs":[{"internalType":"uint8","name":"bits","type":"uint8"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"SafeCastOverflowedUintDowncast","type":"error"},{"inputs":[],"name":"accessManager","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"collateral","type":"address"}],"name":"getCollateralBurnFees","outputs":[{"internalType":"uint64[]","name":"xFeeBurn","type":"uint64[]"},{"internalType":"int64[]","name":"yFeeBurn","type":"int64[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"collateral","type":"address"}],"name":"getCollateralDecimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"collateral","type":"address"}],"name":"getCollateralInfo","outputs":[{"components":[{"internalType":"uint8","name":"isManaged","type":"uint8"},{"internalType":"uint8","name":"isMintLive","type":"uint8"},{"internalType":"uint8","name":"isBurnLive","type":"uint8"},{"internalType":"uint8","name":"decimals","type":"uint8"},{"internalType":"uint8","name":"onlyWhitelisted","type":"uint8"},{"internalType":"uint216","name":"normalizedStables","type":"uint216"},{"internalType":"uint64[]","name":"xFeeMint","type":"uint64[]"},{"internalType":"int64[]","name":"yFeeMint","type":"int64[]"},{"internalType":"uint64[]","name":"xFeeBurn","type":"uint64[]"},{"internalType":"int64[]","name":"yFeeBurn","type":"int64[]"},{"internalType":"bytes","name":"oracleConfig","type":"bytes"},{"internalType":"bytes","name":"whitelistData","type":"bytes"},{"components":[{"internalType":"contract IERC20[]","name":"subCollaterals","type":"address[]"},{"internalType":"bytes","name":"config","type":"bytes"}],"internalType":"struct ManagerStorage","name":"managerData","type":"tuple"},{"internalType":"uint256","name":"stablecoinCap","type":"uint256"}],"internalType":"struct Collateral","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCollateralList","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"collateral","type":"address"}],"name":"getCollateralMintFees","outputs":[{"internalType":"uint64[]","name":"xFeeMint","type":"uint64[]"},{"internalType":"int64[]","name":"yFeeMint","type":"int64[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCollateralRatio","outputs":[{"internalType":"uint64","name":"collatRatio","type":"uint64"},{"internalType":"uint256","name":"stablecoinsIssued","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"collateral","type":"address"}],"name":"getCollateralWhitelistData","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"collateral","type":"address"}],"name":"getIssuedByCollateral","outputs":[{"internalType":"uint256","name":"stablecoinsFromCollateral","type":"uint256"},{"internalType":"uint256","name":"stablecoinsIssued","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"collateral","type":"address"}],"name":"getManagerData","outputs":[{"internalType":"bool","name":"","type":"bool"},{"internalType":"contract IERC20[]","name":"","type":"address[]"},{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"collateral","type":"address"}],"name":"getOracle","outputs":[{"internalType":"enum OracleReadType","name":"oracleType","type":"uint8"},{"internalType":"enum OracleReadType","name":"targetType","type":"uint8"},{"internalType":"bytes","name":"oracleData","type":"bytes"},{"internalType":"bytes","name":"targetData","type":"bytes"},{"internalType":"bytes","name":"hyperparameters","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"collateral","type":"address"}],"name":"getOracleValues","outputs":[{"internalType":"uint256","name":"mint","type":"uint256"},{"internalType":"uint256","name":"burn","type":"uint256"},{"internalType":"uint256","name":"ratio","type":"uint256"},{"internalType":"uint256","name":"minRatio","type":"uint256"},{"internalType":"uint256","name":"redemption","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getRedemptionFees","outputs":[{"internalType":"uint64[]","name":"xRedemptionCurve","type":"uint64[]"},{"internalType":"int64[]","name":"yRedemptionCurve","type":"int64[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"collateral","type":"address"}],"name":"getStablecoinCap","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTotalIssued","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isConsumingScheduledOp","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"collateral","type":"address"},{"internalType":"enum ActionType","name":"action","type":"uint8"}],"name":"isPaused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"}],"name":"isTrusted","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"}],"name":"isTrustedSeller","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"selector","type":"bytes4"}],"name":"isValidSelector","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"collateral","type":"address"}],"name":"isWhitelistedCollateral","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"collateral","type":"address"},{"internalType":"address","name":"sender","type":"address"}],"name":"isWhitelistedForCollateral","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"enum WhitelistType","name":"whitelistType","type":"uint8"},{"internalType":"address","name":"sender","type":"address"}],"name":"isWhitelistedForType","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tokenP","outputs":[{"internalType":"contract ITokenP","name":"","type":"address"}],"stateMutability":"view","type":"function"}]Contract Creation Code
60808060405234601557612e4e908161001a8239f35b5f80fdfe60806040526004361015610011575f80fd5b5f3560e01c80630d126627146113b257806310d3d22e146113315780631978a5ed146112ec57806331da6b13146112c25780633335221014610f9d57806338c269eb14610e745780634ea3e34314610e2157806377dc342914610da3578063782513bd14610d6b578063847da7be14610d3e5780638db9653f14610cde5780638fb3603714610c4b57806394e35d9e14610b9357806396d6487914610b3957806399eeca4914610ac0578063a52aefd414610a29578063adc9d1f71461079d578063b718136114610738578063b85780bc146106f0578063cd377c5314610256578063eb7aac5f14610229578063f9839d89146101c4578063fdcb60681461017f5763fe7d0c5414610121575f80fd5b3461017b57602036600319011261017b576001600160a01b036101426113ee565b165f527f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7c6020526020600160405f205414604051908152f35b5f80fd5b3461017b575f36600319011261017b5760206001600160a01b037fc8fcad8db84d3cc18b4c41d551ea0ee66dd599cde068d998e57d5e09332c131d5416604051908152f35b3461017b57602036600319011261017b576020600160ff61021c6101e66113ee565b6001600160a01b03165f527f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7a60205260405f2090565b54831c1614604051908152f35b3461017b57602036600319011261017b57602060ff6102496101e66113ee565b5460181c16604051908152f35b3461017b575f36600319011261017b57600260ff7f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c755460a81c16146106c8575f61029e611aaa565b80515f916102ab826120a3565b5f905b8382106106595750506102c0836120a3565b926102ca816119cb565b906102d8604051928361169c565b8082526102e7601f19916119cb565b013660208301375f5f945b84861061040c578661034f7f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c76546b033b2e3c9fd0803ce80000006001600160801b0382169160801c610345828285612c0d565b92091515906120d5565b908115806103f85761036683633b9aca0084612c0d565b906103e45782633b9aca0061037e93091515906120d5565b9067ffffffffffffffff82116103b35767ffffffffffffffff60409216905b67ffffffffffffffff8351921682526020820152f35b507f6dfcc650000000000000000000000000000000000000000000000000000000005f52604060045260245260445ffd5b634e487b7160e01b5f52601260045260245ffd5b505060409067ffffffffffffffff9061039d565b90919293949561045f6001600160a01b036104278988611cdb565b51166001600160a01b03165f527f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7a60205260405f2090565b8054909360ff821615610563576007850161048461047f600888016118b0565b612234565b92908051925f908054915b8581106104f657505050506104ea936104dd6001969460ff6104d26104cd60056104c5670de0b6b3a7640000996104e3996120d5565b9d5b016118b0565b611dd5565b9360181c16906123b2565b90611a6f565b04906120d5565b960194939291906102f2565b8281101561054f57600190825f528c6105296001600160a01b038360205f2001541691610523848a6120d5565b90611cdb565b526105348186611cdb565b5161054861054283896120d5565b8d611cdb565b520161048f565b634e487b7160e01b5f52603260045260245ffd5b93916024919260206001600160a01b0361057d8c8b611cdb565b5116604051948580927f70a082310000000000000000000000000000000000000000000000000000000082523060048301525afa92831561064e575f9361061b575b50826105cb8b8a611cdb565b516001600160a01b03166105df888a611cdb565b526105e9876120e2565b966105f49087611cdb565b526104e36001946104dd6104ea9560ff6104d26104cd6005670de0b6b3a7640000986104c7565b9092506020813d8211610646575b816106366020938361169c565b8101031261017b5751918a6105bf565b3d9150610629565b6040513d5f823e3d90fd5b9091929360019060ff6106776001600160a01b036104278789611cdb565b541661069f57610686906120e2565b925b836106938285611cdb565b520190939291936102ae565b6106c29060076106ba6001600160a01b03610427888a611cdb565b0154906120d5565b92610688565b7f37ed32e8000000000000000000000000000000000000000000000000000000005f5260045ffd5b3461017b57602036600319011261017b5761070c6101e66113ee565b610724600261071d600184016116be565b92016117ca565b906107346040519283928361150e565b0390f35b3461017b575f36600319011261017b57610750611aaa565b6040518091602082016020835281518091526020604084019201905f5b81811061077b575050500390f35b82516001600160a01b031684528594506020938401939092019160010161076d565b3461017b575f36600319011261017b576040517f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c785480825281602081017f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c785f5260205f20925f905b8060038301106109d45761083b9454918181106109b9575b81811061099b575b81811061097d575b1061096f575b50038261169c565b604051907f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c795480835282602081017f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c795f5260205f20925f905b80600383011061092c576108ca945491818110610918575b818110610901575b8181106108ea575b106108d9575b50038361169c565b6107346040519283928361150e565b60c01d60070b8152602001856108c2565b9260206001918460801c60070b81520193016108bc565b9260206001918460401c60070b81520193016108b4565b9260206001918460070b81520193016108ac565b916004919350608060019186548060070b82528060401c60070b602083015280831c60070b604083015260c01d60070b6060820152019401920185929391610894565b60c01c815260200184610833565b92602060019167ffffffffffffffff8560801c16815201930161082d565b92602060019167ffffffffffffffff8560401c168152019301610825565b92602060019167ffffffffffffffff8516815201930161081d565b9160049193506080600191865467ffffffffffffffff8116825267ffffffffffffffff8160401c16602083015267ffffffffffffffff81841c16604083015260c01c6060820152019401920184929391610805565b3461017b57604036600319011261017b576020610a446113ee565b610a86610a4f611404565b916001600160a01b03165f527f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7a60205260405f2090565b9060ff8254841c1615918215610aa3575b50506040519015158152f35b610ab992506006610ab491016118b0565b611f2f565b8280610a97565b3461017b57604036600319011261017b57600435600181101561017b57610ae5611404565b90610aef81611aa0565b5f527f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7d6020526001600160a01b0360405f2091165f52602052602060405f20541515604051908152f35b3461017b57602036600319011261017b576001600160a01b03610b5a6113ee565b165f527f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7b6020526020600160405f205414604051908152f35b3461017b57602036600319011261017b576040610bae6113ee565b6b033b2e3c9fd0803ce8000000610c3e610c2d6001600160801b0383610c367f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7654968760801c9485916001600160a01b03165f527f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7a60205260405f2090565b5460281c611a6f565b049416611a6f565b0482519182526020820152f35b3461017b575f36600319011261017b577f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c755460b01c60ff1615610cd65760207f8fb36037000000000000000000000000000000000000000000000000000000005b7fffffffff0000000000000000000000000000000000000000000000000000000060405191168152f35b60205f610cac565b3461017b575f36600319011261017b5760206b033b2e3c9fd0803ce8000000610d357f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c76546001600160801b038160801c9116611a6f565b04604051908152f35b3461017b57602036600319011261017b57610d5a6101e66113ee565b610724600461071d600384016116be565b3461017b57602036600319011261017b57610734610d8f60066104c76101e66113ee565b60405191829160208352602083019061143b565b3461017b57602036600319011261017b576004357fffffffff00000000000000000000000000000000000000000000000000000000811680910361017b575f527fc8fcad8db84d3cc18b4c41d551ea0ee66dd599cde068d998e57d5e09332c131c60205260206001600160a01b0360405f2054161515604051908152f35b3461017b57602036600319011261017b57610734610e45610e406113ee565b6119e3565b610e66604094929451948594151585526060602086015260608501906114d2565b90838203604085015261143b565b3461017b57602036600319011261017b57610e8d6113ee565b610ecc60056104c7836001600160a01b03165f527f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7a60205260405f2090565b610ed581611b8d565b670de0b6b3a764000090610ee7611aaa565b8051906001600160a01b035f9716965b828110610f345750505060a09450610f17610f1185611cef565b94611dd5565b926040519485526020850152604084015260608301526080820152f35b876001600160a01b03610f478385611cdb565b511614610f8d57610f70610f6b60056104c76001600160a01b036104278688611cdb565b611b8d565b90505b858110610f84575b50600101610ef7565b94506001610f7b565b610f9687611b8d565b9050610f73565b3461017b57602036600319011261017b57610fb66113ee565b604051610fc28161164f565b5f8152602081015f9052604081015f9052606081015f9052608081015f905260a081015f905260c081016060905260e081016060905261010081016060905261012081016060905261014081016060905261016081016060905260405161102881611680565b6060815260208101606090526101808201526101a0015f905261107b906001600160a01b03165f527f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7a60205260405f2090565b6040516110878161164f565b815460ff8116825260208201928160081c60ff16845260408301918060101c60ff16835260608401908060181c60ff16825260808501908060201c60ff16825260a086019060281c8152600184016110de906116be565b60c087019081526110f1600286016117ca565b60e08801908152611104600387016116be565b610100890190815291611119600488016117ca565b6101208a019081529361112e600589016118b0565b6101408b019081529561114360068a016118b0565b976101608c01988952604051996111598b611680565b6111656007820161197a565b8b52611173600882016118b0565b60208c01526101808d019a8b52600901549a6101a08d019b8c52604051809e819e602083525160ff1660208301525160ff1690604001525160ff1660608d01525160ff1660808c01525160ff1660a08b0152517affffffffffffffffffffffffffffffffffffffffffffffffffffff1660c08a01525160e089016101c090526101e089016112009161145f565b9051888203601f19016101008a0152611219919061149c565b9051878203601f1901610120890152611232919061145f565b9051868203601f190161014088015261124b919061149c565b9051858203601f1901610160870152611264919061143b565b9051848203601f190161018086015261127d919061143b565b9051601f19848303016101a08501528051604083526040830161129f916114d2565b90602001519180820390602001526112b69161143b565b90516101c08301520390f35b3461017b57602036600319011261017b57602060096112e26101e66113ee565b0154604051908152f35b3461017b575f36600319011261017b5760206001600160a01b037f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c755416604051908152f35b3461017b57602036600319011261017b5761137b6113856107346113966113a461136961136460056104c76101e66113ee565b6120f0565b959260409891949851998a809a61141a565b602089019061141a565b60a0604088015260a087019061143b565b90858203606087015261143b565b90838203608085015261143b565b3461017b57604036600319011261017b576113cb6113ee565b60243590600382101561017b576020916113e49161156a565b6040519015158152f35b600435906001600160a01b038216820361017b57565b602435906001600160a01b038216820361017b57565b90600a8210156114275752565b634e487b7160e01b5f52602160045260245ffd5b805180835260209291819084018484015e5f828201840152601f01601f1916010190565b90602080835192838152019201905f5b81811061147c5750505090565b825167ffffffffffffffff1684526020938401939092019160010161146f565b90602080835192838152019201905f5b8181106114b95750505090565b825160070b8452602093840193909201916001016114ac565b90602080835192838152019201905f5b8181106114ef5750505090565b82516001600160a01b03168452602093840193909201916001016114e2565b9291604084019360408152825180955260206060820193015f955b808710611548575050611545939450602081840391015261149c565b90565b909360208060019267ffffffffffffffff885116815201950196019590611529565b6003821015908161142757821580938115611641575b5015611612576115c0906001600160a01b03165f527f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7a60205260405f2090565b549060ff8260181c16156115ea576114275760ff91156115e25760081c161590565b60101c161590565b7f373f15fc000000000000000000000000000000000000000000000000000000005f5260045ffd5b50505060ff7f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c755460a01c161590565b92505060015f92145f611580565b6101c0810190811067ffffffffffffffff82111761166c57604052565b634e487b7160e01b5f52604160045260245ffd5b6040810190811067ffffffffffffffff82111761166c57604052565b90601f8019910116810190811067ffffffffffffffff82111761166c57604052565b90604051918281549182825260208201905f5260205f20925f905b8060038301106117755761170e94549181811061175a575b81811061173c575b81811061171e575b106117105750038361169c565b565b60c01c81526020015f6108c2565b92602060019167ffffffffffffffff8560801c168152019301611701565b92602060019167ffffffffffffffff8560401c1681520193016116f9565b92602060019167ffffffffffffffff851681520193016116f1565b9160049193506080600191865467ffffffffffffffff8116825267ffffffffffffffff8160401c16602083015267ffffffffffffffff81841c16604083015260c01c60608201520194019201859293916116d9565b90604051918281549182825260208201905f5260205f20925f905b80600383011061186d5761170e945491818110611859575b818110611842575b81811061182b575b1061181a5750038361169c565b60c01d60070b81526020015f6108c2565b9260206001918460801c60070b815201930161180d565b9260206001918460401c60070b8152019301611805565b9260206001918460070b81520193016117fd565b916004919350608060019186548060070b82528060401c60070b602083015280831c60070b604083015260c01d60070b60608201520194019201859293916117e5565b90604051915f8154908160011c9260018316928315611970575b60208510841461195c57848752869390811561193a57506001146118f6575b5061170e9250038361169c565b90505f9291925260205f20905f915b81831061191e57505090602061170e928201015f6118e9565b6020919350806001915483858901015201910190918492611905565b90506020925061170e94915060ff191682840152151560051b8201015f6118e9565b634e487b7160e01b5f52602260045260245ffd5b93607f16936118ca565b90604051918281549182825260208201905f5260205f20925f5b8181106119a957505061170e9250038361169c565b84546001600160a01b0316835260019485019487945060209093019201611994565b67ffffffffffffffff811161166c5760051b60200190565b611a1d906001600160a01b03165f527f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7a60205260405f2090565b60ff815416611a54575060405190611a3660208361169c565b5f82525f3681375f9190604051611a4e60208261169c565b5f815290565b6001916115456008611a686007850161197a565b93016118b0565b81810292918115918404141715611a8257565b634e487b7160e01b5f52601160045260245ffd5b81156103e4570490565b6001111561142757565b604051907f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c775480835282602081017f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c775f5260205f20925f5b818110611b1757505061170e9250038361169c565b84546001600160a01b0316835260019485019487945060209093019201611b02565b9081602091031261017b57516001600160a01b038116810361017b5790565b51906001600160801b038216820361017b57565b919082604091031261017b576115456020611b8684611b58565b9301611b58565b611b96906120f0565b600a85949293969510156114275760018414611c425794611bd6939291611bce876020806001600160801b039a518301019101611b6c565b971693612191565b81939193670de0b6b3a76400009283820290828204851483151715611a82576001600160801b03168403848111611a8257611c119084611a6f565b1115611c315750818402918483041484151715611a825761154591611a96565b819093929310611c3e5750565b9250565b5050505060406001600160a01b03611c6584602080600497518301019101611b39565b168151938480927f4cb44a760000000000000000000000000000000000000000000000000000000082525afa91821561064e575f905f93611ca557509190565b9250506040823d604011611cd3575b81611cc16040938361169c565b8101031261017b576020825192015190565b3d9150611cb4565b805182101561054f5760209160051b010190565b611cf8906120f0565b600a859492939510156114275760018414611d4657906001600160801b03611d2d83602080611d359996518301019101611b6c565b501693612191565b819291928110611d425750565b9150565b5050505060206001600160a01b03611d68838380600496518301019101611b39565b16604051928380927f5ade93550000000000000000000000000000000000000000000000000000000082525afa90811561064e575f91611da6575090565b90506020813d602011611dcd575b81611dc16020938361169c565b8101031261017b575190565b3d9150611db4565b611dde906120f0565b50909291600a8310156114275760018303611e525750505060206001600160a01b03611e14838380600496518301019101611b39565b16604051928380927f6256f2c50000000000000000000000000000000000000000000000000000000082525afa90811561064e575f91611da6575090565b611e68929391611e6191612464565b809361289a565b90670de0b6b3a7640000808202828104821483151715611a8257818402848104831485151715611a82578082109283611eac575b505050611ea7575090565b905090565b909192508383041483151715611a8257105f8080611e9c565b81601f8201121561017b5780519067ffffffffffffffff821161166c5760405192611efa601f8401601f19166020018561169c565b8284526020838301011161017b57815f9260208093018386015e8301015290565b51906001600160a01b038216820361017b57565b8051810160408282031261017b57602082015191600183101561017b5760408101519167ffffffffffffffff831161017b57611f72926020809201920101611ec5565b90611f7c81611aa0565b805f527f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7d60205260405f206001600160a01b0384165f5260205260405f205461209b578151611fcd575b5050505f90565b611fd681611aa0565b15611fe2575b80611fc6565b60208180518101031261017b5761200360206001600160a01b039201611f1b565b16908115611fdc576001600160a01b0360446020925f60405195869485937f65e4ad9e0000000000000000000000000000000000000000000000000000000085523060048601521660248401525af190811561064e575f91612063575090565b90506020813d602011612093575b8161207e6020938361169c565b8101031261017b5751801515810361017b5790565b3d9150612071565b505050600190565b906120ad826119cb565b6120ba604051918261169c565b82815280926120cb601f19916119cb565b0190602036910137565b91908201809211611a8257565b5f198114611a825760010190565b8051810160a0826020830192031261017b576020820151600a81101561017b57604083015193600a85101561017b57606084015167ffffffffffffffff811161017b5783602061214292870101611ec5565b93608081015167ffffffffffffffff811161017b5784602061216692840101611ec5565b9360a08201519167ffffffffffffffff831161017b576121899201602001611ec5565b919493929190565b9394926121a2906121a99392612464565b809461289a565b9280670de0b6b3a764000003670de0b6b3a76400008111611a82576121ce9084611a6f565b670de0b6b3a7640000850290858204670de0b6b3a76400001486151715611a825781119182612206575b505061220057565b91508091565b909150670de0b6b3a76400000180670de0b6b3a764000011611a825761222c9084611a6f565b115f806121f8565b6060915f918051810160408282031261017b57602082015191600183101561017b5760408101519167ffffffffffffffff831161017b5761227c926020809201920101611ec5565b9061228681611aa0565b1561228e5750565b602091935080809350518101031261017b5760200151906001600160a01b03821680920361017b575f600492604051938480927f01e1d1140000000000000000000000000000000000000000000000000000000082525afa91821561064e575f905f936122fa57509190565b9250503d805f843e61230c818461169c565b82019160408184031261017b57805167ffffffffffffffff811161017b5781019280601f8501121561017b578351612343816119cb565b94612351604051968761169c565b81865260208087019260051b82010192831161017b57602001905b82821061237d575050506020015190565b815181526020918201910161236c565b9060ff8091169116039060ff8211611a8257565b60ff16604d8111611a8257600a0a90565b9060ff811660128111156123de5750906123d86123d360126115459461238d565b6123a1565b90611a96565b601211156123f857906104dd6123d361154593601261238d565b5090565b9080601f8301121561017b57815190612414826119cb565b92612422604051948561169c565b82845260208085019360051b82010191821161017b57602001915b81831061244a5750505090565b825160ff8116810361017b5781526020928301920161243d565b600a8110156114275780612674575090815182019160a0816020850194031261017b57602081015167ffffffffffffffff811161017b5781019280603f8501121561017b5760208401516124b7816119cb565b946124c5604051968761169c565b8186526020808088019360051b830101019083821161017b57604001915b81831061265457505050604082015167ffffffffffffffff811161017b57820181603f8201121561017b57602081015161251c816119cb565b9161252a604051938461169c565b8183526020808085019360051b830101019084821161017b57604001915b81831061263757505050606083015167ffffffffffffffff811161017b57826020612575928601016123fc565b91608084015167ffffffffffffffff811161017b5760a091602061259b928701016123fc565b930151600281101561017b57670de0b6b3a76400006125be919694929596612caa565b938351915f935b8385106125d55750505050505090565b9091929394969561262a6001916001600160a01b036125f4898c611cdb565b511660ff6126028a87611cdb565b511660ff6126108b89611cdb565b51169163ffffffff6126228c8b611cdb565b511693612ce9565b96979501939291906125c5565b825163ffffffff8116810361017b57815260209283019201612548565b82516001600160a01b038116810361017b578152602092830192016124e3565b6003810361268a575050670de0b6b3a764000090565b600281036126a0575050670de0b6b3a764000090565b600481036126f3575050604051630f451f7160e31b8152670de0b6b3a7640000600482015260208160248173ae7ab96520de3a18e5e111b5eaab095312d7fe845afa90811561064e575f91611da6575090565b60058103612738575050604051633ba0b9a960e01b815260208160048173be9895146f7af43049ca1c1ae358b0541ea497045afa90811561064e575f91611da6575090565b6006810361277d5750506040516339aa885b60e21b815260208160048173ae78736cd615f374d3085123a210448e74fc63935afa90811561064e575f91611da6575090565b600781036127c2575050604051634ca9858360e11b815260208160048173ac3e018457b222d93114458476f3e3416abbe38f5afa90811561064e575f91611da6575090565b600881036127e357506020815191818082019384920101031261017b575190565b60090361288d5760408180518101031261017b57806020604061280f826001600160a01b039501611f1b565b920151916004604051809581937fa035b1fe000000000000000000000000000000000000000000000000000000008352165afa801561064e575f90612859575b6115459250611a96565b506020823d602011612885575b816128736020938361169c565b8101031261017b57611545915161284f565b3d9150612866565b50670de0b6b3a764000090565b92919092600a8110156114275780612a6f57508051810160a0826020830192031261017b57602082015167ffffffffffffffff811161017b5782019381603f8601121561017b5760208501516128ef816119cb565b956128fd604051978861169c565b8187526020808089019360051b830101019084821161017b57604001915b818310612a4f57505050604083015167ffffffffffffffff811161017b5783019082603f8301121561017b576020820151612955816119cb565b92612963604051948561169c565b8184526020808086019360051b830101019085821161017b57604001915b818310612a3257505050606084015167ffffffffffffffff811161017b578360206129ae928701016123fc565b92608085015167ffffffffffffffff811161017b5760a09160206129d4928801016123fc565b94015190600282101561017b576129ef919694929596612caa565b938351915f935b838510612a065750505050505090565b90919293949695612a256001916001600160a01b036125f4898c611cdb565b96979501939291906129f6565b825163ffffffff8116810361017b57815260209283019201612981565b82516001600160a01b038116810361017b5781526020928301920161291b565b9192909160038103612a8a57505050670de0b6b3a764000090565b60028103612a985750905090565b60048103612aec57505050604051630f451f7160e31b8152670de0b6b3a7640000600482015260208160248173ae7ab96520de3a18e5e111b5eaab095312d7fe845afa90811561064e575f91611da6575090565b60058103612b3257505050604051633ba0b9a960e01b815260208160048173be9895146f7af43049ca1c1ae358b0541ea497045afa90811561064e575f91611da6575090565b60068103612b78575050506040516339aa885b60e21b815260208160048173ae78736cd615f374d3085123a210448e74fc63935afa90811561064e575f91611da6575090565b60078103612bbe57505050604051634ca9858360e11b815260208160048173ac3e018457b222d93114458476f3e3416abbe38f5afa90811561064e575f91611da6575090565b60088103612be05750506020815191818082019384920101031261017b575190565b600903611ea7575060408180518101031261017b57806020604061280f826001600160a01b039501611f1b565b91818302915f1981850993838086109503948086039514612c9d5784831115612c855790829109815f0382168092046002816003021880820260020302808202600203028082026002030280820260020302808202600203028091026002030293600183805f03040190848311900302920304170290565b82634e487b715f52156003026011186020526024601cfd5b5050906115459250611a96565b6002811015611427576115455750670de0b6b3a764000090565b519069ffffffffffffffffffff8216820361017b57565b604d8111611a8257600a0a90565b91909360a06001600160a01b0394956004604051809781937ffeaf968c000000000000000000000000000000000000000000000000000000008352165afa90811561064e575f945f92612dc2575b505f851391821592612da8575b5050612d805760ff16600103612d6b57612d6561154593926123d892611a6f565b91612cdb565b612d7b906104dd61154594612cdb565b611a96565b7fae193563000000000000000000000000000000000000000000000000000000005f5260045ffd5b4290810392508211611a825763ffffffff16105f80612d44565b9450905060a0843d60a011612e10575b81612ddf60a0938361169c565b8101031261017b57612df084612cc4565b506020840151612e07608060608701519601612cc4565b5093905f612d37565b3d9150612dd256fea26469706673582212200c57a3026d32af326299971b7e6464f43def9b4c98416396c6092c299675888464736f6c634300081c0033
Deployed Bytecode
0x60806040526004361015610011575f80fd5b5f3560e01c80630d126627146113b257806310d3d22e146113315780631978a5ed146112ec57806331da6b13146112c25780633335221014610f9d57806338c269eb14610e745780634ea3e34314610e2157806377dc342914610da3578063782513bd14610d6b578063847da7be14610d3e5780638db9653f14610cde5780638fb3603714610c4b57806394e35d9e14610b9357806396d6487914610b3957806399eeca4914610ac0578063a52aefd414610a29578063adc9d1f71461079d578063b718136114610738578063b85780bc146106f0578063cd377c5314610256578063eb7aac5f14610229578063f9839d89146101c4578063fdcb60681461017f5763fe7d0c5414610121575f80fd5b3461017b57602036600319011261017b576001600160a01b036101426113ee565b165f527f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7c6020526020600160405f205414604051908152f35b5f80fd5b3461017b575f36600319011261017b5760206001600160a01b037fc8fcad8db84d3cc18b4c41d551ea0ee66dd599cde068d998e57d5e09332c131d5416604051908152f35b3461017b57602036600319011261017b576020600160ff61021c6101e66113ee565b6001600160a01b03165f527f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7a60205260405f2090565b54831c1614604051908152f35b3461017b57602036600319011261017b57602060ff6102496101e66113ee565b5460181c16604051908152f35b3461017b575f36600319011261017b57600260ff7f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c755460a81c16146106c8575f61029e611aaa565b80515f916102ab826120a3565b5f905b8382106106595750506102c0836120a3565b926102ca816119cb565b906102d8604051928361169c565b8082526102e7601f19916119cb565b013660208301375f5f945b84861061040c578661034f7f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c76546b033b2e3c9fd0803ce80000006001600160801b0382169160801c610345828285612c0d565b92091515906120d5565b908115806103f85761036683633b9aca0084612c0d565b906103e45782633b9aca0061037e93091515906120d5565b9067ffffffffffffffff82116103b35767ffffffffffffffff60409216905b67ffffffffffffffff8351921682526020820152f35b507f6dfcc650000000000000000000000000000000000000000000000000000000005f52604060045260245260445ffd5b634e487b7160e01b5f52601260045260245ffd5b505060409067ffffffffffffffff9061039d565b90919293949561045f6001600160a01b036104278988611cdb565b51166001600160a01b03165f527f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7a60205260405f2090565b8054909360ff821615610563576007850161048461047f600888016118b0565b612234565b92908051925f908054915b8581106104f657505050506104ea936104dd6001969460ff6104d26104cd60056104c5670de0b6b3a7640000996104e3996120d5565b9d5b016118b0565b611dd5565b9360181c16906123b2565b90611a6f565b04906120d5565b960194939291906102f2565b8281101561054f57600190825f528c6105296001600160a01b038360205f2001541691610523848a6120d5565b90611cdb565b526105348186611cdb565b5161054861054283896120d5565b8d611cdb565b520161048f565b634e487b7160e01b5f52603260045260245ffd5b93916024919260206001600160a01b0361057d8c8b611cdb565b5116604051948580927f70a082310000000000000000000000000000000000000000000000000000000082523060048301525afa92831561064e575f9361061b575b50826105cb8b8a611cdb565b516001600160a01b03166105df888a611cdb565b526105e9876120e2565b966105f49087611cdb565b526104e36001946104dd6104ea9560ff6104d26104cd6005670de0b6b3a7640000986104c7565b9092506020813d8211610646575b816106366020938361169c565b8101031261017b5751918a6105bf565b3d9150610629565b6040513d5f823e3d90fd5b9091929360019060ff6106776001600160a01b036104278789611cdb565b541661069f57610686906120e2565b925b836106938285611cdb565b520190939291936102ae565b6106c29060076106ba6001600160a01b03610427888a611cdb565b0154906120d5565b92610688565b7f37ed32e8000000000000000000000000000000000000000000000000000000005f5260045ffd5b3461017b57602036600319011261017b5761070c6101e66113ee565b610724600261071d600184016116be565b92016117ca565b906107346040519283928361150e565b0390f35b3461017b575f36600319011261017b57610750611aaa565b6040518091602082016020835281518091526020604084019201905f5b81811061077b575050500390f35b82516001600160a01b031684528594506020938401939092019160010161076d565b3461017b575f36600319011261017b576040517f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c785480825281602081017f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c785f5260205f20925f905b8060038301106109d45761083b9454918181106109b9575b81811061099b575b81811061097d575b1061096f575b50038261169c565b604051907f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c795480835282602081017f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c795f5260205f20925f905b80600383011061092c576108ca945491818110610918575b818110610901575b8181106108ea575b106108d9575b50038361169c565b6107346040519283928361150e565b60c01d60070b8152602001856108c2565b9260206001918460801c60070b81520193016108bc565b9260206001918460401c60070b81520193016108b4565b9260206001918460070b81520193016108ac565b916004919350608060019186548060070b82528060401c60070b602083015280831c60070b604083015260c01d60070b6060820152019401920185929391610894565b60c01c815260200184610833565b92602060019167ffffffffffffffff8560801c16815201930161082d565b92602060019167ffffffffffffffff8560401c168152019301610825565b92602060019167ffffffffffffffff8516815201930161081d565b9160049193506080600191865467ffffffffffffffff8116825267ffffffffffffffff8160401c16602083015267ffffffffffffffff81841c16604083015260c01c6060820152019401920184929391610805565b3461017b57604036600319011261017b576020610a446113ee565b610a86610a4f611404565b916001600160a01b03165f527f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7a60205260405f2090565b9060ff8254841c1615918215610aa3575b50506040519015158152f35b610ab992506006610ab491016118b0565b611f2f565b8280610a97565b3461017b57604036600319011261017b57600435600181101561017b57610ae5611404565b90610aef81611aa0565b5f527f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7d6020526001600160a01b0360405f2091165f52602052602060405f20541515604051908152f35b3461017b57602036600319011261017b576001600160a01b03610b5a6113ee565b165f527f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7b6020526020600160405f205414604051908152f35b3461017b57602036600319011261017b576040610bae6113ee565b6b033b2e3c9fd0803ce8000000610c3e610c2d6001600160801b0383610c367f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7654968760801c9485916001600160a01b03165f527f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7a60205260405f2090565b5460281c611a6f565b049416611a6f565b0482519182526020820152f35b3461017b575f36600319011261017b577f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c755460b01c60ff1615610cd65760207f8fb36037000000000000000000000000000000000000000000000000000000005b7fffffffff0000000000000000000000000000000000000000000000000000000060405191168152f35b60205f610cac565b3461017b575f36600319011261017b5760206b033b2e3c9fd0803ce8000000610d357f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c76546001600160801b038160801c9116611a6f565b04604051908152f35b3461017b57602036600319011261017b57610d5a6101e66113ee565b610724600461071d600384016116be565b3461017b57602036600319011261017b57610734610d8f60066104c76101e66113ee565b60405191829160208352602083019061143b565b3461017b57602036600319011261017b576004357fffffffff00000000000000000000000000000000000000000000000000000000811680910361017b575f527fc8fcad8db84d3cc18b4c41d551ea0ee66dd599cde068d998e57d5e09332c131c60205260206001600160a01b0360405f2054161515604051908152f35b3461017b57602036600319011261017b57610734610e45610e406113ee565b6119e3565b610e66604094929451948594151585526060602086015260608501906114d2565b90838203604085015261143b565b3461017b57602036600319011261017b57610e8d6113ee565b610ecc60056104c7836001600160a01b03165f527f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7a60205260405f2090565b610ed581611b8d565b670de0b6b3a764000090610ee7611aaa565b8051906001600160a01b035f9716965b828110610f345750505060a09450610f17610f1185611cef565b94611dd5565b926040519485526020850152604084015260608301526080820152f35b876001600160a01b03610f478385611cdb565b511614610f8d57610f70610f6b60056104c76001600160a01b036104278688611cdb565b611b8d565b90505b858110610f84575b50600101610ef7565b94506001610f7b565b610f9687611b8d565b9050610f73565b3461017b57602036600319011261017b57610fb66113ee565b604051610fc28161164f565b5f8152602081015f9052604081015f9052606081015f9052608081015f905260a081015f905260c081016060905260e081016060905261010081016060905261012081016060905261014081016060905261016081016060905260405161102881611680565b6060815260208101606090526101808201526101a0015f905261107b906001600160a01b03165f527f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7a60205260405f2090565b6040516110878161164f565b815460ff8116825260208201928160081c60ff16845260408301918060101c60ff16835260608401908060181c60ff16825260808501908060201c60ff16825260a086019060281c8152600184016110de906116be565b60c087019081526110f1600286016117ca565b60e08801908152611104600387016116be565b610100890190815291611119600488016117ca565b6101208a019081529361112e600589016118b0565b6101408b019081529561114360068a016118b0565b976101608c01988952604051996111598b611680565b6111656007820161197a565b8b52611173600882016118b0565b60208c01526101808d019a8b52600901549a6101a08d019b8c52604051809e819e602083525160ff1660208301525160ff1690604001525160ff1660608d01525160ff1660808c01525160ff1660a08b0152517affffffffffffffffffffffffffffffffffffffffffffffffffffff1660c08a01525160e089016101c090526101e089016112009161145f565b9051888203601f19016101008a0152611219919061149c565b9051878203601f1901610120890152611232919061145f565b9051868203601f190161014088015261124b919061149c565b9051858203601f1901610160870152611264919061143b565b9051848203601f190161018086015261127d919061143b565b9051601f19848303016101a08501528051604083526040830161129f916114d2565b90602001519180820390602001526112b69161143b565b90516101c08301520390f35b3461017b57602036600319011261017b57602060096112e26101e66113ee565b0154604051908152f35b3461017b575f36600319011261017b5760206001600160a01b037f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c755416604051908152f35b3461017b57602036600319011261017b5761137b6113856107346113966113a461136961136460056104c76101e66113ee565b6120f0565b959260409891949851998a809a61141a565b602089019061141a565b60a0604088015260a087019061143b565b90858203606087015261143b565b90838203608085015261143b565b3461017b57604036600319011261017b576113cb6113ee565b60243590600382101561017b576020916113e49161156a565b6040519015158152f35b600435906001600160a01b038216820361017b57565b602435906001600160a01b038216820361017b57565b90600a8210156114275752565b634e487b7160e01b5f52602160045260245ffd5b805180835260209291819084018484015e5f828201840152601f01601f1916010190565b90602080835192838152019201905f5b81811061147c5750505090565b825167ffffffffffffffff1684526020938401939092019160010161146f565b90602080835192838152019201905f5b8181106114b95750505090565b825160070b8452602093840193909201916001016114ac565b90602080835192838152019201905f5b8181106114ef5750505090565b82516001600160a01b03168452602093840193909201916001016114e2565b9291604084019360408152825180955260206060820193015f955b808710611548575050611545939450602081840391015261149c565b90565b909360208060019267ffffffffffffffff885116815201950196019590611529565b6003821015908161142757821580938115611641575b5015611612576115c0906001600160a01b03165f527f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7a60205260405f2090565b549060ff8260181c16156115ea576114275760ff91156115e25760081c161590565b60101c161590565b7f373f15fc000000000000000000000000000000000000000000000000000000005f5260045ffd5b50505060ff7f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c755460a01c161590565b92505060015f92145f611580565b6101c0810190811067ffffffffffffffff82111761166c57604052565b634e487b7160e01b5f52604160045260245ffd5b6040810190811067ffffffffffffffff82111761166c57604052565b90601f8019910116810190811067ffffffffffffffff82111761166c57604052565b90604051918281549182825260208201905f5260205f20925f905b8060038301106117755761170e94549181811061175a575b81811061173c575b81811061171e575b106117105750038361169c565b565b60c01c81526020015f6108c2565b92602060019167ffffffffffffffff8560801c168152019301611701565b92602060019167ffffffffffffffff8560401c1681520193016116f9565b92602060019167ffffffffffffffff851681520193016116f1565b9160049193506080600191865467ffffffffffffffff8116825267ffffffffffffffff8160401c16602083015267ffffffffffffffff81841c16604083015260c01c60608201520194019201859293916116d9565b90604051918281549182825260208201905f5260205f20925f905b80600383011061186d5761170e945491818110611859575b818110611842575b81811061182b575b1061181a5750038361169c565b60c01d60070b81526020015f6108c2565b9260206001918460801c60070b815201930161180d565b9260206001918460401c60070b8152019301611805565b9260206001918460070b81520193016117fd565b916004919350608060019186548060070b82528060401c60070b602083015280831c60070b604083015260c01d60070b60608201520194019201859293916117e5565b90604051915f8154908160011c9260018316928315611970575b60208510841461195c57848752869390811561193a57506001146118f6575b5061170e9250038361169c565b90505f9291925260205f20905f915b81831061191e57505090602061170e928201015f6118e9565b6020919350806001915483858901015201910190918492611905565b90506020925061170e94915060ff191682840152151560051b8201015f6118e9565b634e487b7160e01b5f52602260045260245ffd5b93607f16936118ca565b90604051918281549182825260208201905f5260205f20925f5b8181106119a957505061170e9250038361169c565b84546001600160a01b0316835260019485019487945060209093019201611994565b67ffffffffffffffff811161166c5760051b60200190565b611a1d906001600160a01b03165f527f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7a60205260405f2090565b60ff815416611a54575060405190611a3660208361169c565b5f82525f3681375f9190604051611a4e60208261169c565b5f815290565b6001916115456008611a686007850161197a565b93016118b0565b81810292918115918404141715611a8257565b634e487b7160e01b5f52601160045260245ffd5b81156103e4570490565b6001111561142757565b604051907f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c775480835282602081017f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c775f5260205f20925f5b818110611b1757505061170e9250038361169c565b84546001600160a01b0316835260019485019487945060209093019201611b02565b9081602091031261017b57516001600160a01b038116810361017b5790565b51906001600160801b038216820361017b57565b919082604091031261017b576115456020611b8684611b58565b9301611b58565b611b96906120f0565b600a85949293969510156114275760018414611c425794611bd6939291611bce876020806001600160801b039a518301019101611b6c565b971693612191565b81939193670de0b6b3a76400009283820290828204851483151715611a82576001600160801b03168403848111611a8257611c119084611a6f565b1115611c315750818402918483041484151715611a825761154591611a96565b819093929310611c3e5750565b9250565b5050505060406001600160a01b03611c6584602080600497518301019101611b39565b168151938480927f4cb44a760000000000000000000000000000000000000000000000000000000082525afa91821561064e575f905f93611ca557509190565b9250506040823d604011611cd3575b81611cc16040938361169c565b8101031261017b576020825192015190565b3d9150611cb4565b805182101561054f5760209160051b010190565b611cf8906120f0565b600a859492939510156114275760018414611d4657906001600160801b03611d2d83602080611d359996518301019101611b6c565b501693612191565b819291928110611d425750565b9150565b5050505060206001600160a01b03611d68838380600496518301019101611b39565b16604051928380927f5ade93550000000000000000000000000000000000000000000000000000000082525afa90811561064e575f91611da6575090565b90506020813d602011611dcd575b81611dc16020938361169c565b8101031261017b575190565b3d9150611db4565b611dde906120f0565b50909291600a8310156114275760018303611e525750505060206001600160a01b03611e14838380600496518301019101611b39565b16604051928380927f6256f2c50000000000000000000000000000000000000000000000000000000082525afa90811561064e575f91611da6575090565b611e68929391611e6191612464565b809361289a565b90670de0b6b3a7640000808202828104821483151715611a8257818402848104831485151715611a82578082109283611eac575b505050611ea7575090565b905090565b909192508383041483151715611a8257105f8080611e9c565b81601f8201121561017b5780519067ffffffffffffffff821161166c5760405192611efa601f8401601f19166020018561169c565b8284526020838301011161017b57815f9260208093018386015e8301015290565b51906001600160a01b038216820361017b57565b8051810160408282031261017b57602082015191600183101561017b5760408101519167ffffffffffffffff831161017b57611f72926020809201920101611ec5565b90611f7c81611aa0565b805f527f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7d60205260405f206001600160a01b0384165f5260205260405f205461209b578151611fcd575b5050505f90565b611fd681611aa0565b15611fe2575b80611fc6565b60208180518101031261017b5761200360206001600160a01b039201611f1b565b16908115611fdc576001600160a01b0360446020925f60405195869485937f65e4ad9e0000000000000000000000000000000000000000000000000000000085523060048601521660248401525af190811561064e575f91612063575090565b90506020813d602011612093575b8161207e6020938361169c565b8101031261017b5751801515810361017b5790565b3d9150612071565b505050600190565b906120ad826119cb565b6120ba604051918261169c565b82815280926120cb601f19916119cb565b0190602036910137565b91908201809211611a8257565b5f198114611a825760010190565b8051810160a0826020830192031261017b576020820151600a81101561017b57604083015193600a85101561017b57606084015167ffffffffffffffff811161017b5783602061214292870101611ec5565b93608081015167ffffffffffffffff811161017b5784602061216692840101611ec5565b9360a08201519167ffffffffffffffff831161017b576121899201602001611ec5565b919493929190565b9394926121a2906121a99392612464565b809461289a565b9280670de0b6b3a764000003670de0b6b3a76400008111611a82576121ce9084611a6f565b670de0b6b3a7640000850290858204670de0b6b3a76400001486151715611a825781119182612206575b505061220057565b91508091565b909150670de0b6b3a76400000180670de0b6b3a764000011611a825761222c9084611a6f565b115f806121f8565b6060915f918051810160408282031261017b57602082015191600183101561017b5760408101519167ffffffffffffffff831161017b5761227c926020809201920101611ec5565b9061228681611aa0565b1561228e5750565b602091935080809350518101031261017b5760200151906001600160a01b03821680920361017b575f600492604051938480927f01e1d1140000000000000000000000000000000000000000000000000000000082525afa91821561064e575f905f936122fa57509190565b9250503d805f843e61230c818461169c565b82019160408184031261017b57805167ffffffffffffffff811161017b5781019280601f8501121561017b578351612343816119cb565b94612351604051968761169c565b81865260208087019260051b82010192831161017b57602001905b82821061237d575050506020015190565b815181526020918201910161236c565b9060ff8091169116039060ff8211611a8257565b60ff16604d8111611a8257600a0a90565b9060ff811660128111156123de5750906123d86123d360126115459461238d565b6123a1565b90611a96565b601211156123f857906104dd6123d361154593601261238d565b5090565b9080601f8301121561017b57815190612414826119cb565b92612422604051948561169c565b82845260208085019360051b82010191821161017b57602001915b81831061244a5750505090565b825160ff8116810361017b5781526020928301920161243d565b600a8110156114275780612674575090815182019160a0816020850194031261017b57602081015167ffffffffffffffff811161017b5781019280603f8501121561017b5760208401516124b7816119cb565b946124c5604051968761169c565b8186526020808088019360051b830101019083821161017b57604001915b81831061265457505050604082015167ffffffffffffffff811161017b57820181603f8201121561017b57602081015161251c816119cb565b9161252a604051938461169c565b8183526020808085019360051b830101019084821161017b57604001915b81831061263757505050606083015167ffffffffffffffff811161017b57826020612575928601016123fc565b91608084015167ffffffffffffffff811161017b5760a091602061259b928701016123fc565b930151600281101561017b57670de0b6b3a76400006125be919694929596612caa565b938351915f935b8385106125d55750505050505090565b9091929394969561262a6001916001600160a01b036125f4898c611cdb565b511660ff6126028a87611cdb565b511660ff6126108b89611cdb565b51169163ffffffff6126228c8b611cdb565b511693612ce9565b96979501939291906125c5565b825163ffffffff8116810361017b57815260209283019201612548565b82516001600160a01b038116810361017b578152602092830192016124e3565b6003810361268a575050670de0b6b3a764000090565b600281036126a0575050670de0b6b3a764000090565b600481036126f3575050604051630f451f7160e31b8152670de0b6b3a7640000600482015260208160248173ae7ab96520de3a18e5e111b5eaab095312d7fe845afa90811561064e575f91611da6575090565b60058103612738575050604051633ba0b9a960e01b815260208160048173be9895146f7af43049ca1c1ae358b0541ea497045afa90811561064e575f91611da6575090565b6006810361277d5750506040516339aa885b60e21b815260208160048173ae78736cd615f374d3085123a210448e74fc63935afa90811561064e575f91611da6575090565b600781036127c2575050604051634ca9858360e11b815260208160048173ac3e018457b222d93114458476f3e3416abbe38f5afa90811561064e575f91611da6575090565b600881036127e357506020815191818082019384920101031261017b575190565b60090361288d5760408180518101031261017b57806020604061280f826001600160a01b039501611f1b565b920151916004604051809581937fa035b1fe000000000000000000000000000000000000000000000000000000008352165afa801561064e575f90612859575b6115459250611a96565b506020823d602011612885575b816128736020938361169c565b8101031261017b57611545915161284f565b3d9150612866565b50670de0b6b3a764000090565b92919092600a8110156114275780612a6f57508051810160a0826020830192031261017b57602082015167ffffffffffffffff811161017b5782019381603f8601121561017b5760208501516128ef816119cb565b956128fd604051978861169c565b8187526020808089019360051b830101019084821161017b57604001915b818310612a4f57505050604083015167ffffffffffffffff811161017b5783019082603f8301121561017b576020820151612955816119cb565b92612963604051948561169c565b8184526020808086019360051b830101019085821161017b57604001915b818310612a3257505050606084015167ffffffffffffffff811161017b578360206129ae928701016123fc565b92608085015167ffffffffffffffff811161017b5760a09160206129d4928801016123fc565b94015190600282101561017b576129ef919694929596612caa565b938351915f935b838510612a065750505050505090565b90919293949695612a256001916001600160a01b036125f4898c611cdb565b96979501939291906129f6565b825163ffffffff8116810361017b57815260209283019201612981565b82516001600160a01b038116810361017b5781526020928301920161291b565b9192909160038103612a8a57505050670de0b6b3a764000090565b60028103612a985750905090565b60048103612aec57505050604051630f451f7160e31b8152670de0b6b3a7640000600482015260208160248173ae7ab96520de3a18e5e111b5eaab095312d7fe845afa90811561064e575f91611da6575090565b60058103612b3257505050604051633ba0b9a960e01b815260208160048173be9895146f7af43049ca1c1ae358b0541ea497045afa90811561064e575f91611da6575090565b60068103612b78575050506040516339aa885b60e21b815260208160048173ae78736cd615f374d3085123a210448e74fc63935afa90811561064e575f91611da6575090565b60078103612bbe57505050604051634ca9858360e11b815260208160048173ac3e018457b222d93114458476f3e3416abbe38f5afa90811561064e575f91611da6575090565b60088103612be05750506020815191818082019384920101031261017b575190565b600903611ea7575060408180518101031261017b57806020604061280f826001600160a01b039501611f1b565b91818302915f1981850993838086109503948086039514612c9d5784831115612c855790829109815f0382168092046002816003021880820260020302808202600203028082026002030280820260020302808202600203028091026002030293600183805f03040190848311900302920304170290565b82634e487b715f52156003026011186020526024601cfd5b5050906115459250611a96565b6002811015611427576115455750670de0b6b3a764000090565b519069ffffffffffffffffffff8216820361017b57565b604d8111611a8257600a0a90565b91909360a06001600160a01b0394956004604051809781937ffeaf968c000000000000000000000000000000000000000000000000000000008352165afa90811561064e575f945f92612dc2575b505f851391821592612da8575b5050612d805760ff16600103612d6b57612d6561154593926123d892611a6f565b91612cdb565b612d7b906104dd61154594612cdb565b611a96565b7fae193563000000000000000000000000000000000000000000000000000000005f5260045ffd5b4290810392508211611a825763ffffffff16105f80612d44565b9450905060a0843d60a011612e10575b81612ddf60a0938361169c565b8101031261017b57612df084612cc4565b506020840151612e07608060608701519601612cc4565b5093905f612d37565b3d9150612dd256fea26469706673582212200c57a3026d32af326299971b7e6464f43def9b4c98416396c6092c299675888464736f6c634300081c0033
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$123.84
Net Worth in HYPE
Token Allocations
USDP
100.00%
Multichain Portfolio | 35 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|---|---|---|---|---|
| SONIC | 100.00% | $0.999594 | 123.8885 | $123.84 |
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.