Source Code
| Transaction Hash |
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
Latest 1 internal transaction
Advanced mode:
| Parent Transaction Hash | Block | From | To | |||
|---|---|---|---|---|---|---|
| 23236566 | 185 days ago | Contract Creation | 0 FRAX |
Cross-Chain Transactions
Loading...
Loading
Contract Name:
RewardVault
Compiler Version
v0.8.28+commit.7893614a
Optimization Enabled:
Yes with 200 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 {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IERC20, IERC20Metadata, IERC4626} from "@openzeppelin/contracts/interfaces/IERC4626.sol";
import {IStrategy} from "src/interfaces/IStrategy.sol";
import {IAllocator} from "src/interfaces/IAllocator.sol";
import {IAccountant} from "src/interfaces/IAccountant.sol";
import {IRewardVault} from "src/interfaces/IRewardVault.sol";
import {IProtocolController} from "src/interfaces/IProtocolController.sol";
import {ImmutableArgsParser} from "src/libraries/ImmutableArgsParser.sol";
/// @title RewardVault.
/// @author Stake DAO
/// @custom:github @stake-dao
/// @custom:contact [email protected]
/// @notice RewardVault is the user-facing ERC4626 vault for yield aggregation, serving as the entry point
/// for users to deposit LP tokens and earn rewards. It manages extra reward tokens from gauges
/// (e.g., LDO, BAL) while main protocol rewards (CRV) are handled by the Accountant. The vault
/// routes deposits and withdrawals through the Strategy and Allocator, maintaining full ERC4626
/// compliance for composability.
contract RewardVault is IRewardVault, IERC4626, ERC20 {
using Math for uint256;
using SafeCast for uint256;
using SafeERC20 for IERC20;
using ImmutableArgsParser for address;
///////////////////////////////////////////////////////////////
// --- EVENTS
///////////////////////////////////////////////////////////////
/// @notice Emitted when a new reward token is added to the vault
/// @param rewardToken The address of the reward token being added
/// @param distributor The authorized address that can distribute this reward
event RewardTokenAdded(address indexed rewardToken, address indexed distributor);
/// @notice Emitted when new rewards are deposited for distribution
/// @param rewardToken The token being distributed as rewards
/// @param amount The total amount of rewards being added
/// @param rewardRate The calculated rate at which rewards will be distributed (tokens/second)
event RewardsDeposited(address indexed rewardToken, uint256 amount, uint128 rewardRate);
/// @notice Emitted when the vault resumes operations
event OperationsResumed();
///////////////////////////////////////////////////////////////
// --- ERRORS
///////////////////////////////////////////////////////////////
/// @notice Thrown when an operation is attempted by an unauthorized caller
error NotApproved();
/// @notice Thrown when a zero address is provided where a valid address is required
error ZeroAddress();
/// @notice Thrown when a function is called by an address not in the allowed list
error OnlyAllowed();
/// @notice Thrown when a function is called by an address that isn't a registrar
error OnlyRegistrar();
/// @notice Thrown when a function is called by an address that isn't the protocol controller
error OnlyProtocolController();
/// @notice Thrown when a protocol ID is zero
error InvalidProtocolId();
/// @notice Thrown when attempting to allocate assets to an unapproved target
error TargetNotApproved();
/// @notice Thrown when attempting to interact with an unregistered reward token
error InvalidRewardToken();
/// @notice Thrown when attempting to add a reward token that's already registered
error RewardAlreadyExists();
/// @notice Thrown when an unauthorized address attempts to distribute rewards
error UnauthorizedRewardsDistributor();
///////////////////////////////////////////////////////////////
// --- CONSTANTS & IMMUTABLES
///////////////////////////////////////////////////////////////
/// @notice Default duration for reward distribution periods
uint32 public constant DEFAULT_REWARDS_DURATION = 7 days;
/// @notice Protocol identifier (e.g., bytes4(keccak256("CURVE")))
bytes4 public immutable PROTOCOL_ID;
/// @notice Accountant tracks user balances and main protocol rewards
IAccountant public immutable ACCOUNTANT;
/// @notice Central registry for strategies, allocators, and permissions
IProtocolController public immutable PROTOCOL_CONTROLLER;
/// @notice Determines reward claiming behavior during user actions
/// @dev HARVEST = claim on every action, CHECKPOINT = accumulate until manual harvest
IStrategy.HarvestPolicy public immutable POLICY;
///////////////////////////////////////////////////////////////
// --- STORAGE STRUCTURES
///////////////////////////////////////////////////////////////
/// @notice Tracks distribution parameters for each extra reward token
/// @dev Packed into 2 storage slots for gas efficiency
struct RewardData {
// Slot 1
address rewardsDistributor; // Who can add rewards for this token
uint32 lastUpdateTime; // Last time rewardPerTokenStored was updated
uint32 periodFinish; // When current reward period ends
// Slot 2
uint128 rewardRate; // Tokens distributed per second
uint128 rewardPerTokenStored; // Cumulative rewards per vault token (scaled by 1e18)
}
/// @notice Tracks user's reward state for each reward token
/// @dev Packed into 1 storage slot
struct AccountData {
uint128 rewardPerTokenPaid; // User's last synced rewardPerTokenStored
uint128 claimable; // Rewards ready to claim
}
///////////////////////////////////////////////////////////////
// --- STATE VARIABLES
///////////////////////////////////////////////////////////////
/// @notice List of extra reward tokens this vault distributes
address[] internal rewardTokens;
/// @notice Distribution parameters for each reward token
mapping(address rewardToken => RewardData rewardData) public rewardData;
/// @notice User reward accounting per token
mapping(address account => mapping(address rewardToken => AccountData accountData)) public accountData;
///////////////////////////////////////////////////////////////
// --- MODIFIERS
///////////////////////////////////////////////////////////////
/// @notice Restricts functions to the protocol controller
modifier onlyProtocolController() {
require(msg.sender == address(PROTOCOL_CONTROLLER), OnlyProtocolController());
_;
}
/// @notice Restricts functions to addresses with specific permissions
modifier onlyAllowed() {
require(PROTOCOL_CONTROLLER.allowed(address(this), msg.sender, msg.sig), OnlyAllowed());
_;
}
/// @notice Restricts functions to authorized vault deployers
modifier onlyRegistrar() {
require(PROTOCOL_CONTROLLER.isRegistrar(msg.sender), OnlyRegistrar());
_;
}
/// @notice Initializes the vault with basic ERC20 metadata
/// @dev Sets up the vault with a standard name and symbol prefix
/// @param protocolId The protocol ID.
/// @param protocolController The protocol controller address
/// @param accountant The accountant address
/// @param policy The harvest policy.
/// @custom:reverts ZeroAddress if the accountant or protocol controller address is the zero address.
constructor(bytes4 protocolId, address protocolController, address accountant, IStrategy.HarvestPolicy policy)
ERC20("", "")
{
require(accountant != address(0) && protocolController != address(0), ZeroAddress());
require(protocolId != bytes4(0), InvalidProtocolId());
PROTOCOL_ID = protocolId;
ACCOUNTANT = IAccountant(accountant);
PROTOCOL_CONTROLLER = IProtocolController(protocolController);
POLICY = policy;
}
///////////////////////////////////////////////////////////////
// --- DEPOSIT & MINT - PUBLIC
///////////////////////////////////////////////////////////////
function deposit(uint256 assets, address receiver) external returns (uint256) {
return deposit(assets, receiver, address(0));
}
/// @notice Deposits LP tokens and mints vault shares
/// @dev Allocator determines where to send the LP tokens (locker, sidecar, etc.)
/// @param assets Amount of LP tokens to deposit
/// @param receiver Address to receive vault shares (defaults to msg.sender if zero)
/// @param referrer Optional referrer for tracking (emitted in Accountant event)
/// @return _ Amount deposited (always equals assets due to 1:1 ratio)
function deposit(uint256 assets, address receiver, address referrer) public returns (uint256) {
if (receiver == address(0)) receiver = msg.sender;
_deposit(msg.sender, receiver, assets, assets, referrer);
return assets;
}
/// @notice Mints exact `shares` to `receiver` by depositing assets.
/// @dev Due to the 1:1 relationship between the assets and the shares,
/// the mint function is a wrapper of the deposit function.
/// @param shares The amount of shares to mint.
/// @param receiver The address to receive the minted shares.
/// @param referrer The address of the referrer. Can be the zero address.
/// @return _ The amount of shares minted.
function mint(uint256 shares, address receiver, address referrer) external returns (uint256) {
return deposit(shares, receiver, referrer);
}
/// @notice Mints exact `shares` to `receiver` by depositing assets.
/// @dev Due to the 1:1 relationship between the assets and the shares,
/// the mint function is a wrapper of the deposit function.
/// @param shares The amount of shares to mint.
/// @param receiver The address to receive the minted shares.
/// @return _ The amount of shares minted.
function mint(uint256 shares, address receiver) external returns (uint256) {
return deposit(shares, receiver, address(0));
}
///////////////////////////////////////////////////////////////
// --- DEPOSIT & MINT - PERMISSIONED
///////////////////////////////////////////////////////////////
/// @notice Deposits `assets` from `account` into the vault and mints shares to `account`.
/// @dev Only callable by allowed addresses. `account` should have approved this contract to transfer `assets`.
/// This function tracks the referrer address and handles deposit allocation through strategy and updates rewards.
/// @param account The address to deposit assets from and mint shares to.
/// @param receiver The address to receive the minted shares.
/// @param assets The amount of assets to deposit.
/// @param referrer The address of the referrer. Can be the zero address.
/// @return _ The amount of assets deposited.
/// @custom:reverts ZeroAddress if the account or receiver address is the zero address.
function deposit(address account, address receiver, uint256 assets, address referrer)
public
onlyAllowed
returns (uint256)
{
require(account != address(0) && receiver != address(0), ZeroAddress());
_deposit(account, receiver, assets, assets, referrer);
// return the amount of assets deposited. Thanks to the 1:1 relationship between assets and shares
// the amount of assets deposited is the same as the amount of shares minted
return assets;
}
///////////////////////////////////////////////////////////////
/// ~ DEPOSIT - INTERNAL
///////////////////////////////////////////////////////////////
/// @dev Internal function to deposit assets into the vault.
/// 1. Update the reward state for the receiver.
/// 2. Get the deposit allocation.
/// 3. Transfer assets to the targets.
/// 4. Trigger deposit on the strategy.
/// 5. Mint shares (accountant checkpoint).
/// 6. Emit Deposit event.
/// @param account The address of the account to deposit assets from.
/// @param receiver The address to receive the minted shares.
/// @param assets The amount of assets to deposit.
/// @param shares The amount of shares to mint.
/// @param referrer The address of the referrer. Can be the zero address.
function _deposit(address account, address receiver, uint256 assets, uint256 shares, address referrer) internal {
_deposit(account, receiver, assets, shares, referrer, false);
}
/// @dev Internal function to deposit assets into the vault with transfer mode option.
/// @param account The address of the account to deposit assets from.
/// @param receiver The address to receive the minted shares.
/// @param assets The amount of assets to deposit.
/// @param shares The amount of shares to mint.
/// @param referrer The address of the referrer. Can be the zero address.
/// @param useTransfer True to use safeTransfer (for resumeVault), false for safeTransferFrom
function _deposit(
address account,
address receiver,
uint256 assets,
uint256 shares,
address referrer,
bool useTransfer
) internal {
// 1. Update extra reward state before balance changes
if (receiver != address(0)) {
_checkpoint(receiver, address(0));
}
// Allocate funds to targets and deposit through strategy
IStrategy.PendingRewards memory pendingRewards = _allocateFunds(account, assets, useTransfer);
// Update Accountant balances and mint shares
_mint(receiver, shares, pendingRewards, POLICY, referrer);
emit Deposit(msg.sender, receiver, assets, shares);
}
/// @dev Allocates funds to targets and deposits through strategy
/// @param from Source of assets (user address or address(this) for resumeVault)
/// @param assets Amount to allocate
/// @param useTransfer True to use safeTransfer (resumeVault), false for safeTransferFrom (deposits)
/// @return pendingRewards Rewards harvested during deposit
function _allocateFunds(address from, uint256 assets, bool useTransfer)
internal
returns (IStrategy.PendingRewards memory pendingRewards)
{
// Ask allocator where to send the LP tokens (e.g., 70% locker, 30% Convex)
IAllocator.Allocation memory allocation = allocator().getDepositAllocation(asset(), gauge(), assets);
// Transfer LP tokens directly to allocation targets (bypasses vault)
IERC20 _asset = IERC20(asset());
for (uint256 i; i < allocation.targets.length; i++) {
if (allocation.amounts[i] == 0) continue;
require(PROTOCOL_CONTROLLER.isValidAllocationTarget(gauge(), allocation.targets[i]), TargetNotApproved());
if (useTransfer) {
SafeERC20.safeTransfer(_asset, allocation.targets[i], allocation.amounts[i]);
} else {
SafeERC20.safeTransferFrom(_asset, from, allocation.targets[i], allocation.amounts[i]);
}
}
// Strategy deposits into gauge/sidecar and may harvest if HARVEST policy
return strategy().deposit(allocation, POLICY);
}
///////////////////////////////////////////////////////////////
// --- EXTERNAL/PUBLIC USER-FACING - WITHDRAW & REDEEM
///////////////////////////////////////////////////////////////
/// @notice Burns vault shares and returns LP tokens to receiver
/// @dev Strategy handles withdrawing from gauge and sending tokens to receiver
/// @param assets Amount of LP tokens to withdraw
/// @param receiver Address to receive LP tokens (defaults to msg.sender if zero)
/// @param owner Address whose shares will be burned
/// @return _ Amount withdrawn (always equals assets due to 1:1 ratio)
/// @custom:reverts NotApproved if caller lacks sufficient allowance
function withdraw(uint256 assets, address receiver, address owner) public returns (uint256) {
if (receiver == address(0)) receiver = msg.sender;
// if the caller isn't the owner, check if the caller is allowed to withdraw the amount of assets
if (msg.sender != owner) {
uint256 allowed = allowance(owner, msg.sender);
require(assets <= allowed, NotApproved());
if (allowed != type(uint256).max) _spendAllowance(owner, msg.sender, assets);
}
_withdraw(owner, receiver, assets, assets);
// return the amount of assets withdrawn. Thanks to the 1:1 relationship between assets and shares
// the amount of assets withdrawn is the same as the amount of shares burned
return assets;
}
/// @notice Redeems `shares` from `owner` and sends assets to `receiver`.
/// @dev Checks allowances and calls strategy withdrawal logic. Due to the 1:1
/// relationship of the assets and the shares, the redeem function is a
/// wrapper of the withdraw function.
/// @param shares The amount of shares to redeem.
/// @param receiver The address to receive the assets.
/// @param owner The address to burn shares from.
/// @return _ The amount of shares burned.
function redeem(uint256 shares, address receiver, address owner) external returns (uint256) {
return withdraw(shares, receiver, owner);
}
/// @dev Internal function to withdraw assets from the vault.
function _withdraw(address owner, address receiver, uint256 assets, uint256 shares) internal {
// Update the reward state for the owner.
_checkpoint(owner, address(0));
// Get the address of the allocator contract from the protocol controller
// then fetch the withdrawal allocation from the allocator
IAllocator.Allocation memory allocation = allocator().getWithdrawalAllocation(asset(), gauge(), assets);
// Get the address of the strategy contract from the protocol controller
// then process the withdrawal of the allocation
IStrategy.PendingRewards memory pendingRewards = strategy().withdraw(allocation, POLICY, receiver);
// Burn the shares by calling the endpoint function of the accountant contract
_burn(owner, shares, pendingRewards, POLICY);
/// @dev If the gauge is shutdown, funds will sit here pending recovery
/// @dev Recovery mechanism: users can withdraw directly from vault
if (PROTOCOL_CONTROLLER.isShutdown(gauge())) {
// Transfer the assets to the receiver. The 1:1 relationship between assets and shares is maintained.
SafeERC20.safeTransfer(IERC20(asset()), receiver, shares);
}
emit Withdraw(msg.sender, receiver, owner, assets, shares);
}
///////////////////////////////////////////////////////////////
// --- EMERGENCY -
///////////////////////////////////////////////////////////////
/// @notice Resumes the vault operations
/// @dev Only callable by the protocol controller
/// @custom:reverts OnlyProtocolController if caller is not the protocol controller
function resumeVault() external onlyProtocolController {
uint256 assets = _safeTotalSupply();
// If there are no assets in the vault, we don't need to do anything
if (assets == 0) {
emit OperationsResumed();
return;
}
// Use internal deposit function with vault as both source and receiver
// No new shares are minted (amount = 0) since we're just re-depositing existing assets
_deposit({
account: address(0),
receiver: address(0),
assets: assets,
shares: 0,
referrer: address(0),
useTransfer: true
});
emit OperationsResumed();
}
///////////////////////////////////////////////////////////////
// --- EXTERNAL/PUBLIC USER-FACING - REWARDS
///////////////////////////////////////////////////////////////
/// @notice Claims rewards for multiple tokens in a single transaction
/// @dev Updates reward state and transfers claimed rewards to the receiver
/// @param tokens Array of reward token addresses to claim
/// @param receiver Address to receive the claimed rewards (defaults to msg.sender if zero)
/// @return amounts Array of amounts claimed for each token, in the same order as input tokens
function claim(address[] calldata tokens, address receiver) public returns (uint256[] memory amounts) {
return _claim(msg.sender, tokens, receiver);
}
/// @notice Claims rewards on behalf of another account (requires authorization)
/// @dev Only callable by addresses allowed by the protocol controller
/// @param account Address to claim rewards for
/// @param tokens Array of reward token addresses to claim
/// @param receiver Address to receive the claimed rewards
/// @return amounts Array of amounts claimed for each token
/// @custom:reverts OnlyAllowed if caller is not authorized
function claim(address account, address[] calldata tokens, address receiver)
public
onlyAllowed
returns (uint256[] memory amounts)
{
return _claim(account, tokens, receiver);
}
/// @dev Core reward claiming implementation
/// @param account Account whose rewards are being claimed
/// @param tokens Array of reward tokens to process
/// @param receiver Destination for the claimed rewards
/// @return amounts Array of claimed amounts per token
/// @custom:reverts InvalidRewardToken if any token is not registered
function _claim(address account, address[] calldata tokens, address receiver)
internal
returns (uint256[] memory amounts)
{
if (receiver == address(0)) receiver = account;
// Update all reward states before processing claims
_checkpoint(account, address(0));
amounts = new uint256[](tokens.length);
for (uint256 i; i < tokens.length; i++) {
address rewardToken = tokens[i];
require(isRewardToken(rewardToken), InvalidRewardToken());
// Calculate earned rewards since last claim
AccountData storage accountData_ = accountData[account][rewardToken];
uint256 accountEarned = accountData_.claimable;
if (accountEarned == 0) continue;
// Reset claimable amount
accountData_.claimable = 0;
// Transfer earned rewards to receiver
SafeERC20.safeTransfer(IERC20(rewardToken), receiver, accountEarned);
amounts[i] = accountEarned;
}
return amounts;
}
/// @notice Registers a new extra reward token for this vault
/// @dev Called by factory during vault deployment to setup gauge rewards
/// @param rewardToken Address of the extra reward token (e.g., LDO, BAL)
/// @param distributor Address that receives and distributes these rewards
/// @custom:reverts OnlyRegistrar if caller is not a registrar
/// @custom:reverts ZeroAddress if distributor is zero address
/// @custom:reverts RewardAlreadyExists if token is already registered
function addRewardToken(address rewardToken, address distributor) external onlyRegistrar {
require(distributor != address(0), ZeroAddress());
RewardData storage reward = rewardData[rewardToken];
require(!_isRewardToken(reward), RewardAlreadyExists());
rewardTokens.push(rewardToken);
reward.rewardsDistributor = distributor;
emit RewardTokenAdded(rewardToken, distributor);
}
/// @notice Deposits rewards for linear distribution over 7 days
/// @dev Automatically handles rollover of undistributed rewards
/// @param rewardToken Token to distribute (must be pre-registered)
/// @param amount Amount to distribute over the next period
/// @custom:reverts UnauthorizedRewardsDistributor if caller isn't the distributor
function depositRewards(address rewardToken, uint128 amount) external {
// Ensure all reward states are current
_checkpoint(address(0), address(0));
RewardData storage reward = rewardData[rewardToken];
require(reward.rewardsDistributor == msg.sender, UnauthorizedRewardsDistributor());
uint32 currentTime = uint32(block.timestamp);
uint32 periodFinish = reward.periodFinish;
uint128 newRewardRate;
// Calculate new reward rate, accounting for any remaining rewards
if (currentTime >= periodFinish) {
newRewardRate = Math.mulDiv(amount, 1e18, DEFAULT_REWARDS_DURATION).toUint128();
} else {
uint32 remainingTime = periodFinish - currentTime;
uint256 remainingRewardsUnscaled = Math.mulDiv(reward.rewardRate, remainingTime, 1e18);
newRewardRate = Math.mulDiv(amount + remainingRewardsUnscaled, 1e18, DEFAULT_REWARDS_DURATION).toUint128();
}
// Update reward distribution state
reward.lastUpdateTime = currentTime;
reward.periodFinish = currentTime + DEFAULT_REWARDS_DURATION;
reward.rewardRate = newRewardRate;
// Transfer rewards to vault
IERC20(rewardToken).safeTransferFrom(msg.sender, address(this), amount);
emit RewardsDeposited(rewardToken, amount, newRewardRate);
}
/// @notice Manually updates reward accounting for an account
/// @param account Account to update rewards for
function checkpoint(address account) external {
_checkpoint(account, address(0));
}
///////////////////////////////////////////////////////////////
// --- INTERNAL REWARD UPDATES & HELPERS ~
///////////////////////////////////////////////////////////////
/// @notice Syncs extra reward accounting for affected accounts
/// @dev Called before any balance change to ensure accurate reward distribution
/// @param _from Account losing balance (address(0) to skip)
/// @param _to Account gaining balance (address(0) to skip)
function _checkpoint(address _from, address _to) internal {
uint256 len = rewardTokens.length;
for (uint256 i; i < len; i++) {
address token = rewardTokens[i];
uint128 newRewardPerToken = _updateRewardToken(token);
if (_from != address(0)) {
_updateAccountData(_from, token, newRewardPerToken);
}
if (_to != address(0)) {
_updateAccountData(_to, token, newRewardPerToken);
}
}
}
/// @notice Updates the reward state for a specific token
/// @dev Calculates and stores new reward per token value
/// @param token The reward token to update
/// @return newRewardPerToken The newly calculated reward per token value
function _updateRewardToken(address token) internal returns (uint128 newRewardPerToken) {
RewardData storage reward = rewardData[token];
newRewardPerToken = _rewardPerToken(reward);
reward.lastUpdateTime = _lastTimeRewardApplicable(reward.periodFinish);
reward.rewardPerTokenStored = newRewardPerToken;
}
/// @notice Updates an account's reward data for a specific token
/// @dev Calculates and stores earned rewards since last update
/// @param account The account to update
/// @param token The reward token to process
/// @param newRewardPerToken Current reward per token value
function _updateAccountData(address account, address token, uint128 newRewardPerToken) internal {
AccountData storage accountData_ = accountData[account][token];
accountData_.claimable = _earned(account, token, accountData_.claimable, accountData_.rewardPerTokenPaid);
accountData_.rewardPerTokenPaid = newRewardPerToken;
}
/// @notice Checks if a reward token is properly registered
/// @dev A token is considered registered if it has a non-zero distributor
/// @param reward Storage pointer to the reward data
/// @return True if the reward token is registered
function _isRewardToken(RewardData storage reward) internal view returns (bool) {
return reward.rewardsDistributor != address(0);
}
/// @notice Calculates the latest timestamp for reward distribution
/// @dev Returns the earlier of current time or period finish
/// @param periodFinish The timestamp when the reward period ends
/// @return The latest timestamp for reward calculations
function _lastTimeRewardApplicable(uint32 periodFinish) internal view returns (uint32) {
return Math.min(block.timestamp, periodFinish).toUint32();
}
/// @notice Calculates the current reward per token value
/// @dev Accounts for time elapsed and total supply
/// @param reward Storage pointer to the reward data
/// @return Current reward per token, scaled by 1e18
function _rewardPerToken(RewardData storage reward) internal view returns (uint128) {
uint128 _totalSupply = _safeTotalSupply();
if (_totalSupply == 0) return reward.rewardPerTokenStored;
uint256 timeDelta = _lastTimeRewardApplicable(reward.periodFinish) - reward.lastUpdateTime;
uint256 rewardRatePerToken = 0;
if (timeDelta > 0) {
// Calculate additional rewards per token since last update
rewardRatePerToken = Math.mulDiv(timeDelta, reward.rewardRate, _totalSupply);
}
return (reward.rewardPerTokenStored + rewardRatePerToken).toUint128();
}
/// @notice Calculates earned rewards for an account
/// @dev Includes both stored claimable amount and newly earned rewards
/// @param account The account to calculate rewards for
/// @param token The reward token to calculate
/// @param userClaimable Previously stored claimable amount
/// @param userRewardPerTokenPaid Last checkpoint of reward per token for user
/// @return Total earned rewards as uint128
function _earned(address account, address token, uint128 userClaimable, uint128 userRewardPerTokenPaid)
internal
view
returns (uint128)
{
uint128 newEarned = balanceOf(account).mulDiv(rewardPerToken(token) - userRewardPerTokenPaid, 1e18).toUint128();
return userClaimable + newEarned;
}
///////////////////////////////////////////////////////////////
// --- VIEW / PURE METHODS ~
///////////////////////////////////////////////////////////////
/// @notice Checks if a reward token exists.
/// @dev The check is based on the assumption that the distributor is always set for a
/// active address and it can not be zero.
/// @param rewardToken The address of the reward token to check.
/// @return _ True if the reward token exists, false otherwise.
function isRewardToken(address rewardToken) public view returns (bool) {
RewardData storage reward = rewardData[rewardToken];
return _isRewardToken(reward);
}
/// @notice Returns the address of the underlying token.
/// @dev Retrieves the token address from the clone's immutable args.
/// @return _ The address of the underlying token used by the vault.
function asset() public view returns (address) {
return address(this).readAddress(20);
}
/// @notice Returns the total amount of underlying assets (1:1 with total shares).
/// @dev Due to the 1:1 relationship between assets and shares, the total assets
/// is the same as the total supply.
/// @return _ The total amount of underlying assets.
function totalAssets() external view returns (uint256) {
return totalSupply();
}
/// @notice Converts a given number of assets to the equivalent amount of shares (1:1).
/// @dev Due to the 1:1 relationship between assets and shares, the conversion is the same.
/// @param assets The amount of assets to convert to shares.
/// @return _ The amount of shares that would be received for the given amount of assets.
/// Basically the same value as the assets parameter.
function convertToShares(uint256 assets) external pure returns (uint256) {
return assets;
}
/// @notice Converts a given number of shares to the equivalent amount of assets (1:1).
/// @dev Due to the 1:1 relationship between assets and shares, the conversion is the same.
/// @param shares The amount of shares to convert to assets.
/// @return _ The amount of assets that would be received for the given amount of shares.
/// Basically the same value as the shares parameter.
function convertToAssets(uint256 shares) external pure returns (uint256) {
return shares;
}
/// @notice Returns the amount of assets that would be received for a given amount of shares.
/// @dev Due to the 1:1 relationship between assets and shares, the amount of assets
/// received is the same as the amount of shares deposited.
/// @param shares The amount of shares to deposit.
/// @return _ The amount of assets that would be received for the given amount of shares.
/// Basically the same value as the shares parameter.
function previewDeposit(uint256 shares) external pure returns (uint256) {
return shares;
}
/// @notice Returns the amount of shares that would be received for a given amount of assets.
/// @dev Due to the 1:1 relationship between assets and shares, the amount of shares
/// received is the same as the amount of assets deposited.
/// @param assets The amount of assets to mint.
/// @return _ The amount of shares that would be received for the given amount of assets.
/// Basically the same value as the assets parameter.
function previewMint(uint256 assets) external pure returns (uint256) {
return assets;
}
/// @notice Returns the amount of shares that would be received for a given amount of assets.
/// @dev Due to the 1:1 relationship between assets and shares, the amount of shares
/// received is the same as the amount of assets withdrawn.
/// @param assets The amount of assets to withdraw.
/// @return _ The amount of shares that would be received for the given amount of assets.
/// Basically the same value as the assets parameter.
function previewWithdraw(uint256 assets) external pure returns (uint256) {
return assets;
}
/// @notice Returns the amount of assets that would be received for a given amount of shares.
/// @dev Due to the 1:1 relationship between assets and shares, the amount of tokens
/// received is the same as the amount of shares redeemed.
/// @param shares The amount of shares to redeem.
/// @return _ The amount of assets that would be received for the given amount of shares.
/// Basically the same value as the shares parameter.
function previewRedeem(uint256 shares) external pure returns (uint256) {
return shares;
}
/// @notice Returns the maximum amount of assets that can be deposited.
/// @dev The parameter is not used and is included to satisfy the interface. Pass whatever you want to.
/// @return _ The maximum amount of assets that can be deposited.
function maxDeposit(address) public pure returns (uint256) {
return type(uint128).max;
}
/// @notice Returns the maximum amount of shares that can be minted.
/// @dev Due to the 1:1 relationship between assets and shares, the max mint
/// is the same as the max deposit.
/// @param _account The address of the account to calculate the max mint for.
/// @return _ The maximum amount of shares that can be minted.
function maxMint(address _account) external pure returns (uint256) {
return maxDeposit(_account);
}
/// @notice Returns the maximum amount of assets that can be withdrawn.
/// @param owner The address of the owner to calculate the max withdraw for.
/// @return _ The maximum amount of assets that can be withdrawn.
function maxWithdraw(address owner) public view returns (uint256) {
return balanceOf(owner);
}
/// @notice Returns the maximum amount of shares that can be redeemed.
/// @dev Due to the 1:1 relationship between assets and shares, the max redeem
/// is the same as the max withdraw.
/// @param owner The address of the owner to calculate the max redeem for.
/// @return _ The maximum amount of shares that can be redeemed.
function maxRedeem(address owner) external view returns (uint256) {
return maxWithdraw(owner);
}
/// @notice Returns the distributor address for a given reward token.
/// @param token The address of the reward token to calculate the distributor address for.
/// @return _ The distributor address for the given reward token.
function getRewardsDistributor(address token) external view returns (address) {
return rewardData[token].rewardsDistributor;
}
/// @notice Returns the last update time for a given reward token.
/// @param token The address of the reward token to calculate the last update time for.
/// @return _ The last update time for the given reward token.
function getLastUpdateTime(address token) external view returns (uint32) {
return rewardData[token].lastUpdateTime;
}
/// @notice Returns the period finish time for a given reward token.
/// @param token The address of the reward token to calculate the period finish time for.
/// @return _ The period finish time for the given reward token.
function getPeriodFinish(address token) external view returns (uint32) {
return rewardData[token].periodFinish;
}
/// @notice Returns the reward rate for a given reward token.
/// @param token The address of the reward token to calculate the reward rate for.
/// @return _ The reward rate for the given reward token.
function getRewardRate(address token) external view returns (uint128) {
return rewardData[token].rewardRate;
}
/// @notice Returns the reward per token stored for a given reward token.
/// @param token The address of the reward token to calculate the reward per token stored for.
/// @return _ The reward per token stored for the given reward token.
function getRewardPerTokenStored(address token) external view returns (uint128) {
return rewardData[token].rewardPerTokenStored;
}
/// @notice Returns the reward per token paid for a given reward token and account.
/// @param token The address of the reward token to calculate the reward per token paid for.
/// @param account The address of the account to calculate the reward per token paid for.
/// @return _ The reward per token paid for the given reward token and account.
function getRewardPerTokenPaid(address token, address account) external view returns (uint128) {
return accountData[account][token].rewardPerTokenPaid;
}
/// @notice Returns the claimable amount for a given reward token and account.
/// @param token The address of the reward token to calculate the claimable amount for.
/// @param account The address of the account to calculate the claimable amount for.
/// @return _ The claimable amount for the given reward token and account.
function getClaimable(address token, address account) external view returns (uint128) {
return accountData[account][token].claimable;
}
function getRewardTokens() external view returns (address[] memory) {
return rewardTokens;
}
/// @notice Returns the total supply of this vault fetched from the accountant contract.
/// @return _ The total supply of this vault.
function totalSupply() public view override(ERC20, IERC20) returns (uint256) {
return ACCOUNTANT.totalSupply(address(this));
}
/// @notice Returns the total supply of the vault safely casted as a uint128.
/// @return _ The total supply of the vault safely casted as a uint128.
/// @custom:reverts Overflow if the total supply is greater than the maximum value of a uint128.
function _safeTotalSupply() internal view returns (uint128) {
return totalSupply().toUint128();
}
/// @notice Returns the balance of the vault for a given account.
/// @param account The address of the account to calculate the balance for.
/// @return _ The balance of the vault for the given account.
function balanceOf(address account) public view override(ERC20, IERC20) returns (uint256) {
return ACCOUNTANT.balanceOf(address(this), account);
}
/// @notice Returns the last time reward is applicable for a given reward token
/// @dev Wrapper around internal _lastTimeRewardApplicable function
/// @param token The reward token to check
/// @return Latest applicable timestamp for rewards
function lastTimeRewardApplicable(address token) external view returns (uint256) {
return _lastTimeRewardApplicable(rewardData[token].periodFinish);
}
/// @notice Returns the reward per token for a given reward token
/// @dev Wrapper around internal _rewardPerToken function
/// @param token The reward token to calculate for
/// @return Current reward per token value
function rewardPerToken(address token) public view returns (uint128) {
return _rewardPerToken(rewardData[token]);
}
/// @notice Calculates total earned rewards for an account
/// @dev Includes both claimed and pending rewards
/// @param account Account to check rewards for
/// @param token Reward token to calculate
/// @return Total earned rewards
function earned(address account, address token) external view returns (uint128) {
AccountData storage accountData_ = accountData[account][token];
return _earned(account, token, accountData_.claimable, accountData_.rewardPerTokenPaid);
}
///////////////////////////////////////////////////////////////
// --- PROTOCOL_CONTROLLER / CLONE ARGUMENT GETTERS ~
///////////////////////////////////////////////////////////////
/// @notice Retrieves the gauge address from clone arguments
/// @dev Uses assembly to read from clone initialization data
/// @return _gauge The gauge contract address
/// @custom:reverts CloneArgsNotFound if clone is incorrectly initialized
function gauge() public view returns (address _gauge) {
return address(this).readAddress(0);
}
/// @notice Gets the allocator contract for this protocol type
/// @dev Fetches from protocol controller using PROTOCOL_ID
/// @return _allocator The allocator contract interface
function allocator() public view returns (IAllocator _allocator) {
return IAllocator(PROTOCOL_CONTROLLER.allocator(PROTOCOL_ID));
}
/// @notice Gets the strategy contract for this protocol type
/// @dev Fetches from protocol controller using PROTOCOL_ID
/// @return _strategy The strategy contract interface
function strategy() public view returns (IStrategy _strategy) {
return IStrategy(PROTOCOL_CONTROLLER.strategy(PROTOCOL_ID));
}
///////////////////////////////////////////////////////////////
// --- ERC20 OVERRIDES ~
///////////////////////////////////////////////////////////////
/// @notice Handles reward state updates during token transfers
/// @dev Updates balances via Accountant and reward states
/// @param from Address sending tokens
/// @param to Address receiving tokens
/// @param amount Number of tokens being transferred
function _update(address from, address to, uint256 amount) internal override {
// 1. Update Reward State
_checkpoint(from, to);
/// Get addresses where funds are allocated to.
address[] memory targets = allocator().getAllocationTargets(gauge());
/// Create an allocation struct to pass to the strategy.
/// We want to withdraw 0, just to get the pending rewards.
IAllocator.Allocation memory allocation = IAllocator.Allocation({
asset: asset(),
gauge: gauge(),
targets: targets,
amounts: new uint256[](targets.length)
});
/// Checkpoint to get the pending rewards.
/// @dev Strategy address used as receiver to avoid zero address validation in some tokens
IStrategy.PendingRewards memory pendingRewards = strategy().withdraw(allocation, POLICY, address(strategy()));
// 2. Update Balances via Accountant
ACCOUNTANT.checkpoint(gauge(), from, to, amount.toUint128(), pendingRewards, POLICY);
// 3. Emit Transfer event
emit Transfer(from, to, amount);
}
/// @notice Mints new vault shares
/// @dev Updates balances and processes pending rewards
/// @param to Recipient of new shares
/// @param amount Amount of shares to mint
/// @param pendingRewards Rewards to process during mint
/// @param policy The harvest policy.
/// @param referrer The address of the referrer. Can be the zero address.
function _mint(
address to,
uint256 amount,
IStrategy.PendingRewards memory pendingRewards,
IStrategy.HarvestPolicy policy,
address referrer
) internal {
ACCOUNTANT.checkpoint({
gauge: gauge(),
from: address(0),
to: to,
amount: amount.toUint128(),
pendingRewards: pendingRewards,
policy: policy,
referrer: referrer
});
emit Transfer(address(0), to, amount);
}
/// @notice Burns vault shares
/// @dev Updates balances and processes pending rewards
/// @param from Address to burn shares from
/// @param amount Amount of shares to burn
/// @param pendingRewards Rewards to process during burn
/// @param policy The harvest policy.
function _burn(
address from,
uint256 amount,
IStrategy.PendingRewards memory pendingRewards,
IStrategy.HarvestPolicy policy
) internal {
ACCOUNTANT.checkpoint({
gauge: gauge(),
from: from,
to: address(0),
amount: amount.toUint128(),
pendingRewards: pendingRewards,
policy: policy
});
emit Transfer(from, address(0), amount);
}
/// @notice Generates the vault's name
/// @dev Combines "StakeDAO", underlying asset name, and "Vault"
/// @return Full vault name
function name() public view override(ERC20, IERC20Metadata) returns (string memory) {
return string.concat("Stake DAO ", IERC20Metadata(asset()).name(), " Vault");
}
/// @notice Generates the vault's symbol
/// @dev Combines "sd-", underlying asset symbol, and "-vault"
/// @return Full vault symbol
function symbol() public view override(ERC20, IERC20Metadata) returns (string memory) {
return string.concat("sd-", IERC20Metadata(asset()).symbol(), "-vault");
}
/// @notice Gets the vault's decimal places
/// @dev Matches underlying asset decimals
/// @return Number of decimal places
function decimals() public view override(ERC20, IERC20Metadata) returns (uint8) {
return IERC20Metadata(asset()).decimals();
}
}// 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.2.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
import {IERC20Metadata} from "./extensions/IERC20Metadata.sol";
import {Context} from "../../utils/Context.sol";
import {IERC20Errors} from "../../interfaces/draft-IERC6093.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* The default value of {decimals} is 18. To change this, you should override
* this function so it returns a different value.
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC-20
* applications.
*/
abstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {
mapping(address account => uint256) private _balances;
mapping(address account => mapping(address spender => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the default value returned by this function, unless
* it's overridden.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `value`.
*/
function transfer(address to, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_transfer(owner, to, value);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `value` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Skips emitting an {Approval} event indicating an allowance update. This is not
* required by the ERC. See {xref-ERC20-_approve-address-address-uint256-bool-}[_approve].
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `value`.
* - the caller must have allowance for ``from``'s tokens of at least
* `value`.
*/
function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, value);
_transfer(from, to, value);
return true;
}
/**
* @dev Moves a `value` amount of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _transfer(address from, address to, uint256 value) internal {
if (from == address(0)) {
revert ERC20InvalidSender(address(0));
}
if (to == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(from, to, value);
}
/**
* @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
* (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
* this function.
*
* Emits a {Transfer} event.
*/
function _update(address from, address to, uint256 value) internal virtual {
if (from == address(0)) {
// Overflow check required: The rest of the code assumes that totalSupply never overflows
_totalSupply += value;
} else {
uint256 fromBalance = _balances[from];
if (fromBalance < value) {
revert ERC20InsufficientBalance(from, fromBalance, value);
}
unchecked {
// Overflow not possible: value <= fromBalance <= totalSupply.
_balances[from] = fromBalance - value;
}
}
if (to == address(0)) {
unchecked {
// Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
_totalSupply -= value;
}
} else {
unchecked {
// Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
_balances[to] += value;
}
}
emit Transfer(from, to, value);
}
/**
* @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
* Relies on the `_update` mechanism
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _mint(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(address(0), account, value);
}
/**
* @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
* Relies on the `_update` mechanism.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead
*/
function _burn(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidSender(address(0));
}
_update(account, address(0), value);
}
/**
* @dev Sets `value` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*
* Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
*/
function _approve(address owner, address spender, uint256 value) internal {
_approve(owner, spender, value, true);
}
/**
* @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.
*
* By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by
* `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any
* `Approval` event during `transferFrom` operations.
*
* Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to
* true using the following override:
*
* ```solidity
* function _approve(address owner, address spender, uint256 value, bool) internal virtual override {
* super._approve(owner, spender, value, true);
* }
* ```
*
* Requirements are the same as {_approve}.
*/
function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {
if (owner == address(0)) {
revert ERC20InvalidApprover(address(0));
}
if (spender == address(0)) {
revert ERC20InvalidSpender(address(0));
}
_allowances[owner][spender] = value;
if (emitEvent) {
emit Approval(owner, spender, value);
}
}
/**
* @dev Updates `owner` s allowance for `spender` based on spent `value`.
*
* Does not update the allowance value in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Does not emit an {Approval} event.
*/
function _spendAllowance(address owner, address spender, uint256 value) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance < type(uint256).max) {
if (currentAllowance < value) {
revert ERC20InsufficientAllowance(spender, currentAllowance, value);
}
unchecked {
_approve(owner, spender, currentAllowance - value, false);
}
}
}
}// 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.2.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC-20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
/**
* @dev An operation with an ERC-20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*
* NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
* only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
* set here.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
safeTransfer(token, to, value);
} else if (!token.transferAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
* has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferFromAndCallRelaxed(
IERC1363 token,
address from,
address to,
uint256 value,
bytes memory data
) internal {
if (to.code.length == 0) {
safeTransferFrom(token, from, to, value);
} else if (!token.transferFromAndCall(from, to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
* Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
* once without retrying, and relies on the returned value to be true.
*
* Reverts if the returned value is other than `true`.
*/
function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
forceApprove(token, to, value);
} else if (!token.approveAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
// bubble errors
if iszero(success) {
let ptr := mload(0x40)
returndatacopy(ptr, 0, returndatasize())
revert(ptr, returndatasize())
}
returnSize := returndatasize()
returnValue := mload(0)
}
if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
bool success;
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
returnSize := returndatasize()
returnValue := mload(0)
}
return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/IERC4626.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../token/ERC20/IERC20.sol";
import {IERC20Metadata} from "../token/ERC20/extensions/IERC20Metadata.sol";
/**
* @dev Interface of the ERC-4626 "Tokenized Vault Standard", as defined in
* https://eips.ethereum.org/EIPS/eip-4626[ERC-4626].
*/
interface IERC4626 is IERC20, IERC20Metadata {
event Deposit(address indexed sender, address indexed owner, uint256 assets, uint256 shares);
event Withdraw(
address indexed sender,
address indexed receiver,
address indexed owner,
uint256 assets,
uint256 shares
);
/**
* @dev Returns the address of the underlying token used for the Vault for accounting, depositing, and withdrawing.
*
* - MUST be an ERC-20 token contract.
* - MUST NOT revert.
*/
function asset() external view returns (address assetTokenAddress);
/**
* @dev Returns the total amount of the underlying asset that is “managed” by Vault.
*
* - SHOULD include any compounding that occurs from yield.
* - MUST be inclusive of any fees that are charged against assets in the Vault.
* - MUST NOT revert.
*/
function totalAssets() external view returns (uint256 totalManagedAssets);
/**
* @dev Returns the amount of shares that the Vault would exchange for the amount of assets provided, in an ideal
* scenario where all the conditions are met.
*
* - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
* - MUST NOT show any variations depending on the caller.
* - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
* - MUST NOT revert.
*
* NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
* “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
* from.
*/
function convertToShares(uint256 assets) external view returns (uint256 shares);
/**
* @dev Returns the amount of assets that the Vault would exchange for the amount of shares provided, in an ideal
* scenario where all the conditions are met.
*
* - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
* - MUST NOT show any variations depending on the caller.
* - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
* - MUST NOT revert.
*
* NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
* “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
* from.
*/
function convertToAssets(uint256 shares) external view returns (uint256 assets);
/**
* @dev Returns the maximum amount of the underlying asset that can be deposited into the Vault for the receiver,
* through a deposit call.
*
* - MUST return a limited value if receiver is subject to some deposit limit.
* - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of assets that may be deposited.
* - MUST NOT revert.
*/
function maxDeposit(address receiver) external view returns (uint256 maxAssets);
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their deposit at the current block, given
* current on-chain conditions.
*
* - MUST return as close to and no more than the exact amount of Vault shares that would be minted in a deposit
* call in the same transaction. I.e. deposit should return the same or more shares as previewDeposit if called
* in the same transaction.
* - MUST NOT account for deposit limits like those returned from maxDeposit and should always act as though the
* deposit would be accepted, regardless if the user has enough tokens approved, etc.
* - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToShares and previewDeposit SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by depositing.
*/
function previewDeposit(uint256 assets) external view returns (uint256 shares);
/**
* @dev Mints shares Vault shares to receiver by depositing exactly amount of underlying tokens.
*
* - MUST emit the Deposit event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
* deposit execution, and are accounted for during deposit.
* - MUST revert if all of assets cannot be deposited (due to deposit limit being reached, slippage, the user not
* approving enough underlying tokens to the Vault contract, etc).
*
* NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
*/
function deposit(uint256 assets, address receiver) external returns (uint256 shares);
/**
* @dev Returns the maximum amount of the Vault shares that can be minted for the receiver, through a mint call.
* - MUST return a limited value if receiver is subject to some mint limit.
* - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of shares that may be minted.
* - MUST NOT revert.
*/
function maxMint(address receiver) external view returns (uint256 maxShares);
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their mint at the current block, given
* current on-chain conditions.
*
* - MUST return as close to and no fewer than the exact amount of assets that would be deposited in a mint call
* in the same transaction. I.e. mint should return the same or fewer assets as previewMint if called in the
* same transaction.
* - MUST NOT account for mint limits like those returned from maxMint and should always act as though the mint
* would be accepted, regardless if the user has enough tokens approved, etc.
* - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToAssets and previewMint SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by minting.
*/
function previewMint(uint256 shares) external view returns (uint256 assets);
/**
* @dev Mints exactly shares Vault shares to receiver by depositing amount of underlying tokens.
*
* - MUST emit the Deposit event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the mint
* execution, and are accounted for during mint.
* - MUST revert if all of shares cannot be minted (due to deposit limit being reached, slippage, the user not
* approving enough underlying tokens to the Vault contract, etc).
*
* NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
*/
function mint(uint256 shares, address receiver) external returns (uint256 assets);
/**
* @dev Returns the maximum amount of the underlying asset that can be withdrawn from the owner balance in the
* Vault, through a withdraw call.
*
* - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
* - MUST NOT revert.
*/
function maxWithdraw(address owner) external view returns (uint256 maxAssets);
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their withdrawal at the current block,
* given current on-chain conditions.
*
* - MUST return as close to and no fewer than the exact amount of Vault shares that would be burned in a withdraw
* call in the same transaction. I.e. withdraw should return the same or fewer shares as previewWithdraw if
* called
* in the same transaction.
* - MUST NOT account for withdrawal limits like those returned from maxWithdraw and should always act as though
* the withdrawal would be accepted, regardless if the user has enough shares, etc.
* - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToShares and previewWithdraw SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by depositing.
*/
function previewWithdraw(uint256 assets) external view returns (uint256 shares);
/**
* @dev Burns shares from owner and sends exactly assets of underlying tokens to receiver.
*
* - MUST emit the Withdraw event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
* withdraw execution, and are accounted for during withdraw.
* - MUST revert if all of assets cannot be withdrawn (due to withdrawal limit being reached, slippage, the owner
* not having enough shares, etc).
*
* Note that some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
* Those methods should be performed separately.
*/
function withdraw(uint256 assets, address receiver, address owner) external returns (uint256 shares);
/**
* @dev Returns the maximum amount of Vault shares that can be redeemed from the owner balance in the Vault,
* through a redeem call.
*
* - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
* - MUST return balanceOf(owner) if owner is not subject to any withdrawal limit or timelock.
* - MUST NOT revert.
*/
function maxRedeem(address owner) external view returns (uint256 maxShares);
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their redeemption at the current block,
* given current on-chain conditions.
*
* - MUST return as close to and no more than the exact amount of assets that would be withdrawn in a redeem call
* in the same transaction. I.e. redeem should return the same or more assets as previewRedeem if called in the
* same transaction.
* - MUST NOT account for redemption limits like those returned from maxRedeem and should always act as though the
* redemption would be accepted, regardless if the user has enough shares, etc.
* - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToAssets and previewRedeem SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by redeeming.
*/
function previewRedeem(uint256 shares) external view returns (uint256 assets);
/**
* @dev Burns exactly shares from owner and sends assets of underlying tokens to receiver.
*
* - MUST emit the Withdraw event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
* redeem execution, and are accounted for during redeem.
* - MUST revert if all of shares cannot be redeemed (due to withdrawal limit being reached, slippage, the owner
* not having enough shares, etc).
*
* NOTE: some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
* Those methods should be performed separately.
*/
function redeem(uint256 shares, address receiver, address owner) external returns (uint256 assets);
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
import "src/interfaces/IAllocator.sol";
interface IStrategy {
/// @notice The policy for harvesting rewards.
enum HarvestPolicy {
CHECKPOINT,
HARVEST
}
struct PendingRewards {
uint128 feeSubjectAmount;
uint128 totalAmount;
}
function deposit(IAllocator.Allocation calldata allocation, HarvestPolicy policy)
external
returns (PendingRewards memory pendingRewards);
function withdraw(IAllocator.Allocation calldata allocation, HarvestPolicy policy, address receiver)
external
returns (PendingRewards memory pendingRewards);
function balanceOf(address gauge) external view returns (uint256 balance);
function harvest(address gauge, bytes calldata extraData) external returns (PendingRewards memory pendingRewards);
function flush() external;
function shutdown(address gauge) external;
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
interface IAllocator {
struct Allocation {
address asset;
address gauge;
address[] targets;
uint256[] amounts;
}
function getDepositAllocation(address asset, address gauge, uint256 amount)
external
view
returns (Allocation memory);
function getWithdrawalAllocation(address asset, address gauge, uint256 amount)
external
view
returns (Allocation memory);
function getRebalancedAllocation(address asset, address gauge, uint256 amount)
external
view
returns (Allocation memory);
function getAllocationTargets(address gauge) external view returns (address[] memory);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import {IStrategy} from "src/interfaces/IStrategy.sol";
interface IAccountant {
function checkpoint(
address gauge,
address from,
address to,
uint128 amount,
IStrategy.PendingRewards calldata pendingRewards,
IStrategy.HarvestPolicy policy
) external;
function checkpoint(
address gauge,
address from,
address to,
uint128 amount,
IStrategy.PendingRewards calldata pendingRewards,
IStrategy.HarvestPolicy policy,
address referrer
) external;
function totalSupply(address asset) external view returns (uint128);
function balanceOf(address asset, address account) external view returns (uint128);
function claim(address[] calldata _gauges, bytes[] calldata harvestData) external;
function claim(address[] calldata _gauges, bytes[] calldata harvestData, address receiver) external;
function claim(address[] calldata _gauges, address account, bytes[] calldata harvestData, address receiver)
external;
function claimProtocolFees() external;
function harvest(address[] calldata _gauges, bytes[] calldata _harvestData, address _receiver) external;
function REWARD_TOKEN() external view returns (address);
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
/// @title IRewardVault
/// @notice Interface for the RewardVault contract
interface IRewardVault {
function addRewardToken(address rewardsToken, address distributor) external;
function depositRewards(address _rewardsToken, uint128 _amount) external;
function deposit(uint256 assets, address receiver, address referrer) external returns (uint256 shares);
function deposit(address account, address receiver, uint256 assets, address referrer)
external
returns (uint256 shares);
function claim(address[] calldata tokens, address receiver) external returns (uint256[] memory amounts);
function claim(address account, address[] calldata tokens, address receiver)
external
returns (uint256[] memory amounts);
function getRewardsDistributor(address token) external view returns (address);
function getLastUpdateTime(address token) external view returns (uint32);
function getPeriodFinish(address token) external view returns (uint32);
function getRewardRate(address token) external view returns (uint128);
function getRewardPerTokenStored(address token) external view returns (uint128);
function getRewardPerTokenPaid(address token, address account) external view returns (uint128);
function getClaimable(address token, address account) external view returns (uint128);
function getRewardTokens() external view returns (address[] memory);
function lastTimeRewardApplicable(address token) external view returns (uint256);
function rewardPerToken(address token) external view returns (uint128);
function earned(address account, address token) external view returns (uint128);
function isRewardToken(address rewardToken) external view returns (bool);
function resumeVault() external;
}/// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
interface IProtocolController {
function vault(address) external view returns (address);
function asset(address) external view returns (address);
function rewardReceiver(address) external view returns (address);
function allowed(address, address, bytes4 selector) external view returns (bool);
function permissionSetters(address) external view returns (bool);
function isRegistrar(address) external view returns (bool);
function strategy(bytes4 protocolId) external view returns (address);
function allocator(bytes4 protocolId) external view returns (address);
function accountant(bytes4 protocolId) external view returns (address);
function feeReceiver(bytes4 protocolId) external view returns (address);
function factory(bytes4 protocolId) external view returns (address);
function isPaused(bytes4) external view returns (bool);
function isShutdown(address) external view returns (bool);
function registerVault(address _gauge, address _vault, address _asset, address _rewardReceiver, bytes4 _protocolId)
external;
function setValidAllocationTarget(address _gauge, address _target) external;
function removeValidAllocationTarget(address _gauge, address _target) external;
function isValidAllocationTarget(address _gauge, address _target) external view returns (bool);
function shutdown(address _gauge) external;
function setPermissionSetter(address _setter, bool _allowed) external;
function setPermission(address _contract, address _caller, bytes4 _selector, bool _allowed) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";
/// @title ImmutableArgsParser
/// @notice A library for reading immutable arguments from a clone.
library ImmutableArgsParser {
/// @dev Safely read an `address` from `clone`'s immutable args at `offset`.
function readAddress(address clone, uint256 offset) internal view returns (address result) {
bytes memory args = Clones.fetchCloneArgs(clone);
assembly {
// Load 32 bytes starting at `args + offset + 32`. Then shift right
// by 96 bits (12 bytes) so that the address is right‐aligned and
// the high bits are cleared.
result := shr(96, mload(add(add(args, 0x20), offset)))
}
}
/// @dev Safely read a `uint256` from `clone`'s immutable args at `offset`.
function readUint256(address clone, uint256 offset) internal view returns (uint256 result) {
bytes memory args = Clones.fetchCloneArgs(clone);
assembly {
// Load the entire 32‐byte word directly.
result := mload(add(add(args, 0x20), offset))
}
}
}// 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) (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) (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC-20 standard.
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/draft-IERC6093.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard ERC-20 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 tokens.
*/
interface IERC20Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC20InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC20InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
* @param spender Address that may be allowed to operate on tokens without being their owner.
* @param allowance Amount of tokens a `spender` is allowed to operate with.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC20InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `spender` to be approved. Used in approvals.
* @param spender Address that may be allowed to operate on tokens without being their owner.
*/
error ERC20InvalidSpender(address spender);
}
/**
* @dev Standard ERC-721 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-721 tokens.
*/
interface IERC721Errors {
/**
* @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in ERC-20.
* Used in balance queries.
* @param owner Address of the current owner of a token.
*/
error ERC721InvalidOwner(address owner);
/**
* @dev Indicates a `tokenId` whose `owner` is the zero address.
* @param tokenId Identifier number of a token.
*/
error ERC721NonexistentToken(uint256 tokenId);
/**
* @dev Indicates an error related to the ownership over a particular token. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param tokenId Identifier number of a token.
* @param owner Address of the current owner of a token.
*/
error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC721InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC721InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param tokenId Identifier number of a token.
*/
error ERC721InsufficientApproval(address operator, uint256 tokenId);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC721InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC721InvalidOperator(address operator);
}
/**
* @dev Standard ERC-1155 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-1155 tokens.
*/
interface IERC1155Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
* @param tokenId Identifier number of a token.
*/
error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC1155InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC1155InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param owner Address of the current owner of a token.
*/
error ERC1155MissingApprovalForAll(address operator, address owner);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC1155InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC1155InvalidOperator(address operator);
/**
* @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
* Used in batch transfers.
* @param idsLength Length of the array of token identifiers
* @param valuesLength Length of the array of token amounts
*/
error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/IERC1363.sol)
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";
/**
* @title IERC1363
* @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
*
* Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
* after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
*/
interface IERC1363 is IERC20, IERC165 {
/*
* Note: the ERC-165 identifier for this interface is 0xb0202a11.
* 0xb0202a11 ===
* bytes4(keccak256('transferAndCall(address,uint256)')) ^
* bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
* bytes4(keccak256('approveAndCall(address,uint256)')) ^
* bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
*/
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @param data Additional data with no specified format, sent in call to `spender`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.2.0) (proxy/Clones.sol)
pragma solidity ^0.8.20;
import {Create2} from "../utils/Create2.sol";
import {Errors} from "../utils/Errors.sol";
/**
* @dev https://eips.ethereum.org/EIPS/eip-1167[ERC-1167] is a standard for
* deploying minimal proxy contracts, also known as "clones".
*
* > To simply and cheaply clone contract functionality in an immutable way, this standard specifies
* > a minimal bytecode implementation that delegates all calls to a known, fixed address.
*
* The library includes functions to deploy a proxy using either `create` (traditional deployment) or `create2`
* (salted deterministic deployment). It also includes functions to predict the addresses of clones deployed using the
* deterministic method.
*/
library Clones {
error CloneArgumentsTooLong();
/**
* @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.
*
* This function uses the create opcode, which should never revert.
*/
function clone(address implementation) internal returns (address instance) {
return clone(implementation, 0);
}
/**
* @dev Same as {xref-Clones-clone-address-}[clone], but with a `value` parameter to send native currency
* to the new contract.
*
* NOTE: Using a non-zero value at creation will require the contract using this function (e.g. a factory)
* to always have enough balance for new deployments. Consider exposing this function under a payable method.
*/
function clone(address implementation, uint256 value) internal returns (address instance) {
if (address(this).balance < value) {
revert Errors.InsufficientBalance(address(this).balance, value);
}
assembly ("memory-safe") {
// Cleans the upper 96 bits of the `implementation` word, then packs the first 3 bytes
// of the `implementation` address with the bytecode before the address.
mstore(0x00, or(shr(0xe8, shl(0x60, implementation)), 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000))
// Packs the remaining 17 bytes of `implementation` with the bytecode after the address.
mstore(0x20, or(shl(0x78, implementation), 0x5af43d82803e903d91602b57fd5bf3))
instance := create(value, 0x09, 0x37)
}
if (instance == address(0)) {
revert Errors.FailedDeployment();
}
}
/**
* @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.
*
* This function uses the create2 opcode and a `salt` to deterministically deploy
* the clone. Using the same `implementation` and `salt` multiple times will revert, since
* the clones cannot be deployed twice at the same address.
*/
function cloneDeterministic(address implementation, bytes32 salt) internal returns (address instance) {
return cloneDeterministic(implementation, salt, 0);
}
/**
* @dev Same as {xref-Clones-cloneDeterministic-address-bytes32-}[cloneDeterministic], but with
* a `value` parameter to send native currency to the new contract.
*
* NOTE: Using a non-zero value at creation will require the contract using this function (e.g. a factory)
* to always have enough balance for new deployments. Consider exposing this function under a payable method.
*/
function cloneDeterministic(
address implementation,
bytes32 salt,
uint256 value
) internal returns (address instance) {
if (address(this).balance < value) {
revert Errors.InsufficientBalance(address(this).balance, value);
}
assembly ("memory-safe") {
// Cleans the upper 96 bits of the `implementation` word, then packs the first 3 bytes
// of the `implementation` address with the bytecode before the address.
mstore(0x00, or(shr(0xe8, shl(0x60, implementation)), 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000))
// Packs the remaining 17 bytes of `implementation` with the bytecode after the address.
mstore(0x20, or(shl(0x78, implementation), 0x5af43d82803e903d91602b57fd5bf3))
instance := create2(value, 0x09, 0x37, salt)
}
if (instance == address(0)) {
revert Errors.FailedDeployment();
}
}
/**
* @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
*/
function predictDeterministicAddress(
address implementation,
bytes32 salt,
address deployer
) internal pure returns (address predicted) {
assembly ("memory-safe") {
let ptr := mload(0x40)
mstore(add(ptr, 0x38), deployer)
mstore(add(ptr, 0x24), 0x5af43d82803e903d91602b57fd5bf3ff)
mstore(add(ptr, 0x14), implementation)
mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73)
mstore(add(ptr, 0x58), salt)
mstore(add(ptr, 0x78), keccak256(add(ptr, 0x0c), 0x37))
predicted := and(keccak256(add(ptr, 0x43), 0x55), 0xffffffffffffffffffffffffffffffffffffffff)
}
}
/**
* @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
*/
function predictDeterministicAddress(
address implementation,
bytes32 salt
) internal view returns (address predicted) {
return predictDeterministicAddress(implementation, salt, address(this));
}
/**
* @dev Deploys and returns the address of a clone that mimics the behavior of `implementation` with custom
* immutable arguments. These are provided through `args` and cannot be changed after deployment. To
* access the arguments within the implementation, use {fetchCloneArgs}.
*
* This function uses the create opcode, which should never revert.
*/
function cloneWithImmutableArgs(address implementation, bytes memory args) internal returns (address instance) {
return cloneWithImmutableArgs(implementation, args, 0);
}
/**
* @dev Same as {xref-Clones-cloneWithImmutableArgs-address-bytes-}[cloneWithImmutableArgs], but with a `value`
* parameter to send native currency to the new contract.
*
* NOTE: Using a non-zero value at creation will require the contract using this function (e.g. a factory)
* to always have enough balance for new deployments. Consider exposing this function under a payable method.
*/
function cloneWithImmutableArgs(
address implementation,
bytes memory args,
uint256 value
) internal returns (address instance) {
if (address(this).balance < value) {
revert Errors.InsufficientBalance(address(this).balance, value);
}
bytes memory bytecode = _cloneCodeWithImmutableArgs(implementation, args);
assembly ("memory-safe") {
instance := create(value, add(bytecode, 0x20), mload(bytecode))
}
if (instance == address(0)) {
revert Errors.FailedDeployment();
}
}
/**
* @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation` with custom
* immutable arguments. These are provided through `args` and cannot be changed after deployment. To
* access the arguments within the implementation, use {fetchCloneArgs}.
*
* This function uses the create2 opcode and a `salt` to deterministically deploy the clone. Using the same
* `implementation`, `args` and `salt` multiple times will revert, since the clones cannot be deployed twice
* at the same address.
*/
function cloneDeterministicWithImmutableArgs(
address implementation,
bytes memory args,
bytes32 salt
) internal returns (address instance) {
return cloneDeterministicWithImmutableArgs(implementation, args, salt, 0);
}
/**
* @dev Same as {xref-Clones-cloneDeterministicWithImmutableArgs-address-bytes-bytes32-}[cloneDeterministicWithImmutableArgs],
* but with a `value` parameter to send native currency to the new contract.
*
* NOTE: Using a non-zero value at creation will require the contract using this function (e.g. a factory)
* to always have enough balance for new deployments. Consider exposing this function under a payable method.
*/
function cloneDeterministicWithImmutableArgs(
address implementation,
bytes memory args,
bytes32 salt,
uint256 value
) internal returns (address instance) {
bytes memory bytecode = _cloneCodeWithImmutableArgs(implementation, args);
return Create2.deploy(value, salt, bytecode);
}
/**
* @dev Computes the address of a clone deployed using {Clones-cloneDeterministicWithImmutableArgs}.
*/
function predictDeterministicAddressWithImmutableArgs(
address implementation,
bytes memory args,
bytes32 salt,
address deployer
) internal pure returns (address predicted) {
bytes memory bytecode = _cloneCodeWithImmutableArgs(implementation, args);
return Create2.computeAddress(salt, keccak256(bytecode), deployer);
}
/**
* @dev Computes the address of a clone deployed using {Clones-cloneDeterministicWithImmutableArgs}.
*/
function predictDeterministicAddressWithImmutableArgs(
address implementation,
bytes memory args,
bytes32 salt
) internal view returns (address predicted) {
return predictDeterministicAddressWithImmutableArgs(implementation, args, salt, address(this));
}
/**
* @dev Get the immutable args attached to a clone.
*
* - If `instance` is a clone that was deployed using `clone` or `cloneDeterministic`, this
* function will return an empty array.
* - If `instance` is a clone that was deployed using `cloneWithImmutableArgs` or
* `cloneDeterministicWithImmutableArgs`, this function will return the args array used at
* creation.
* - If `instance` is NOT a clone deployed using this library, the behavior is undefined. This
* function should only be used to check addresses that are known to be clones.
*/
function fetchCloneArgs(address instance) internal view returns (bytes memory) {
bytes memory result = new bytes(instance.code.length - 45); // revert if length is too short
assembly ("memory-safe") {
extcodecopy(instance, add(result, 32), 45, mload(result))
}
return result;
}
/**
* @dev Helper that prepares the initcode of the proxy with immutable args.
*
* An assembly variant of this function requires copying the `args` array, which can be efficiently done using
* `mcopy`. Unfortunately, that opcode is not available before cancun. A pure solidity implementation using
* abi.encodePacked is more expensive but also more portable and easier to review.
*
* NOTE: https://eips.ethereum.org/EIPS/eip-170[EIP-170] limits the length of the contract code to 24576 bytes.
* With the proxy code taking 45 bytes, that limits the length of the immutable args to 24531 bytes.
*/
function _cloneCodeWithImmutableArgs(
address implementation,
bytes memory args
) private pure returns (bytes memory) {
if (args.length > 24531) revert CloneArgumentsTooLong();
return
abi.encodePacked(
hex"61",
uint16(args.length + 45),
hex"3d81600a3d39f3363d3d373d3d3d363d73",
implementation,
hex"5af43d82803e903d91602b57fd5bf3",
args
);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../token/ERC20/IERC20.sol";// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../utils/introspection/IERC165.sol";// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Create2.sol)
pragma solidity ^0.8.20;
import {Errors} from "./Errors.sol";
/**
* @dev Helper to make usage of the `CREATE2` EVM opcode easier and safer.
* `CREATE2` can be used to compute in advance the address where a smart
* contract will be deployed, which allows for interesting new mechanisms known
* as 'counterfactual interactions'.
*
* See the https://eips.ethereum.org/EIPS/eip-1014#motivation[EIP] for more
* information.
*/
library Create2 {
/**
* @dev There's no code to deploy.
*/
error Create2EmptyBytecode();
/**
* @dev Deploys a contract using `CREATE2`. The address where the contract
* will be deployed can be known in advance via {computeAddress}.
*
* The bytecode for a contract can be obtained from Solidity with
* `type(contractName).creationCode`.
*
* Requirements:
*
* - `bytecode` must not be empty.
* - `salt` must have not been used for `bytecode` already.
* - the factory must have a balance of at least `amount`.
* - if `amount` is non-zero, `bytecode` must have a `payable` constructor.
*/
function deploy(uint256 amount, bytes32 salt, bytes memory bytecode) internal returns (address addr) {
if (address(this).balance < amount) {
revert Errors.InsufficientBalance(address(this).balance, amount);
}
if (bytecode.length == 0) {
revert Create2EmptyBytecode();
}
assembly ("memory-safe") {
addr := create2(amount, add(bytecode, 0x20), mload(bytecode), salt)
// if no address was created, and returndata is not empty, bubble revert
if and(iszero(addr), not(iszero(returndatasize()))) {
let p := mload(0x40)
returndatacopy(p, 0, returndatasize())
revert(p, returndatasize())
}
}
if (addr == address(0)) {
revert Errors.FailedDeployment();
}
}
/**
* @dev Returns the address where a contract will be stored if deployed via {deploy}. Any change in the
* `bytecodeHash` or `salt` will result in a new destination address.
*/
function computeAddress(bytes32 salt, bytes32 bytecodeHash) internal view returns (address) {
return computeAddress(salt, bytecodeHash, address(this));
}
/**
* @dev Returns the address where a contract will be stored if deployed via {deploy} from a contract located at
* `deployer`. If `deployer` is this contract's address, returns the same value as {computeAddress}.
*/
function computeAddress(bytes32 salt, bytes32 bytecodeHash, address deployer) internal pure returns (address addr) {
assembly ("memory-safe") {
let ptr := mload(0x40) // Get free memory pointer
// | | ↓ ptr ... ↓ ptr + 0x0B (start) ... ↓ ptr + 0x20 ... ↓ ptr + 0x40 ... |
// |-------------------|---------------------------------------------------------------------------|
// | bytecodeHash | CCCCCCCCCCCCC...CC |
// | salt | BBBBBBBBBBBBB...BB |
// | deployer | 000000...0000AAAAAAAAAAAAAAAAAAA...AA |
// | 0xFF | FF |
// |-------------------|---------------------------------------------------------------------------|
// | memory | 000000...00FFAAAAAAAAAAAAAAAAAAA...AABBBBBBBBBBBBB...BBCCCCCCCCCCCCC...CC |
// | keccak(start, 85) | ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ |
mstore(add(ptr, 0x40), bytecodeHash)
mstore(add(ptr, 0x20), salt)
mstore(ptr, deployer) // Right-aligned with 12 preceding garbage bytes
let start := add(ptr, 0x0b) // The hashed data starts at the final garbage byte which we will set to 0xff
mstore8(start, 0xff)
addr := and(keccak256(start, 85), 0xffffffffffffffffffffffffffffffffffffffff)
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Errors.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of common custom errors used in multiple contracts
*
* IMPORTANT: Backwards compatibility is not guaranteed in future versions of the library.
* It is recommended to avoid relying on the error API for critical functionality.
*
* _Available since v5.1._
*/
library Errors {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error InsufficientBalance(uint256 balance, uint256 needed);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedCall();
/**
* @dev The deployment failed.
*/
error FailedDeployment();
/**
* @dev A necessary precompile is missing.
*/
error MissingPrecompile(address);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[ERC].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}{
"remappings": [
"forge-std/=node_modules/forge-std/",
"shared/=node_modules/@stake-dao/shared/",
"layerzerolabs/oft-evm/=node_modules/@layerzerolabs/oft-evm/",
"@safe/=node_modules/@safe-global/safe-smart-account/",
"@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/",
"@interfaces/=node_modules/@stake-dao/interfaces/src/interfaces/",
"@address-book/=node_modules/@stake-dao/address-book/",
"@layerzerolabs/=node_modules/@layerzerolabs/",
"@safe-global/=node_modules/@safe-global/",
"@solady/=node_modules/@solady/"
],
"optimizer": {
"enabled": true,
"runs": 200
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "ipfs",
"appendCBOR": true
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "cancun",
"viaIR": false,
"libraries": {}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"bytes4","name":"protocolId","type":"bytes4"},{"internalType":"address","name":"protocolController","type":"address"},{"internalType":"address","name":"accountant","type":"address"},{"internalType":"enum IStrategy.HarvestPolicy","name":"policy","type":"uint8"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"allowance","type":"uint256"},{"internalType":"uint256","name":"needed","type":"uint256"}],"name":"ERC20InsufficientAllowance","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"uint256","name":"balance","type":"uint256"},{"internalType":"uint256","name":"needed","type":"uint256"}],"name":"ERC20InsufficientBalance","type":"error"},{"inputs":[{"internalType":"address","name":"approver","type":"address"}],"name":"ERC20InvalidApprover","type":"error"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"}],"name":"ERC20InvalidReceiver","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"}],"name":"ERC20InvalidSender","type":"error"},{"inputs":[{"internalType":"address","name":"spender","type":"address"}],"name":"ERC20InvalidSpender","type":"error"},{"inputs":[],"name":"InvalidProtocolId","type":"error"},{"inputs":[],"name":"InvalidRewardToken","type":"error"},{"inputs":[],"name":"NotApproved","type":"error"},{"inputs":[],"name":"OnlyAllowed","type":"error"},{"inputs":[],"name":"OnlyProtocolController","type":"error"},{"inputs":[],"name":"OnlyRegistrar","type":"error"},{"inputs":[],"name":"RewardAlreadyExists","type":"error"},{"inputs":[{"internalType":"uint8","name":"bits","type":"uint8"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"SafeCastOverflowedUintDowncast","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[],"name":"TargetNotApproved","type":"error"},{"inputs":[],"name":"UnauthorizedRewardsDistributor","type":"error"},{"inputs":[],"name":"ZeroAddress","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[],"name":"OperationsResumed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"rewardToken","type":"address"},{"indexed":true,"internalType":"address","name":"distributor","type":"address"}],"name":"RewardTokenAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"rewardToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint128","name":"rewardRate","type":"uint128"}],"name":"RewardsDeposited","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"Withdraw","type":"event"},{"inputs":[],"name":"ACCOUNTANT","outputs":[{"internalType":"contract IAccountant","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DEFAULT_REWARDS_DURATION","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"POLICY","outputs":[{"internalType":"enum IStrategy.HarvestPolicy","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PROTOCOL_CONTROLLER","outputs":[{"internalType":"contract IProtocolController","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PROTOCOL_ID","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"address","name":"rewardToken","type":"address"}],"name":"accountData","outputs":[{"internalType":"uint128","name":"rewardPerTokenPaid","type":"uint128"},{"internalType":"uint128","name":"claimable","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"rewardToken","type":"address"},{"internalType":"address","name":"distributor","type":"address"}],"name":"addRewardToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"allocator","outputs":[{"internalType":"contract IAllocator","name":"_allocator","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"asset","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"checkpoint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"tokens","type":"address[]"},{"internalType":"address","name":"receiver","type":"address"}],"name":"claim","outputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"address[]","name":"tokens","type":"address[]"},{"internalType":"address","name":"receiver","type":"address"}],"name":"claim","outputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"convertToAssets","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"convertToShares","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"referrer","type":"address"}],"name":"deposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address","name":"referrer","type":"address"}],"name":"deposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"deposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"rewardToken","type":"address"},{"internalType":"uint128","name":"amount","type":"uint128"}],"name":"depositRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"address","name":"token","type":"address"}],"name":"earned","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"gauge","outputs":[{"internalType":"address","name":"_gauge","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"account","type":"address"}],"name":"getClaimable","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"getLastUpdateTime","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"getPeriodFinish","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"account","type":"address"}],"name":"getRewardPerTokenPaid","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"getRewardPerTokenStored","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"getRewardRate","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getRewardTokens","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"getRewardsDistributor","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"rewardToken","type":"address"}],"name":"isRewardToken","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"lastTimeRewardApplicable","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"maxDeposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"maxMint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"maxRedeem","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"maxWithdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"mint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"referrer","type":"address"}],"name":"mint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"previewDeposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"previewMint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"previewRedeem","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"previewWithdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"redeem","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"resumeVault","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"rewardToken","type":"address"}],"name":"rewardData","outputs":[{"internalType":"address","name":"rewardsDistributor","type":"address"},{"internalType":"uint32","name":"lastUpdateTime","type":"uint32"},{"internalType":"uint32","name":"periodFinish","type":"uint32"},{"internalType":"uint128","name":"rewardRate","type":"uint128"},{"internalType":"uint128","name":"rewardPerTokenStored","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"rewardPerToken","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"strategy","outputs":[{"internalType":"contract IStrategy","name":"_strategy","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalAssets","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}]Contract Creation Code
610100604052348015610010575f5ffd5b506040516137ee3803806137ee83398101604081905261002f9161013a565b60408051602080820183525f80835283519182019093529182529060036100568382610236565b5060046100638282610236565b5050506001600160a01b0382161580159061008657506001600160a01b03831615155b6100a35760405163d92e233d60e01b815260040160405180910390fd5b6001600160e01b031984166100cb576040516355e7c3d960e11b815260040160405180910390fd5b6001600160e01b031984166080526001600160a01b0380831660a052831660c0528060018111156100fe576100fe6102f0565b60e0816001811115610112576101126102f0565b8152505050505050610304565b80516001600160a01b0381168114610135575f5ffd5b919050565b5f5f5f5f6080858703121561014d575f5ffd5b84516001600160e01b031981168114610164575f5ffd5b93506101726020860161011f565b92506101806040860161011f565b9150606085015160028110610193575f5ffd5b939692955090935050565b634e487b7160e01b5f52604160045260245ffd5b600181811c908216806101c657607f821691505b6020821081036101e457634e487b7160e01b5f52602260045260245ffd5b50919050565b601f82111561023157805f5260205f20601f840160051c8101602085101561020f5750805b601f840160051c820191505b8181101561022e575f815560010161021b565b50505b505050565b81516001600160401b0381111561024f5761024f61019e565b6102638161025d84546101b2565b846101ea565b6020601f821160018114610295575f831561027e5750848201515b5f19600385901b1c1916600184901b17845561022e565b5f84815260208120601f198516915b828110156102c457878501518255602094850194600190920191016102a4565b50848210156102e157868401515f19600387901b60f8161c191681555b50505050600190811b01905550565b634e487b7160e01b5f52602160045260245ffd5b60805160a05160c05160e0516134246103ca5f395f81816108e601528181611b2801528181611c5f01528181611ce601528181612232015281816122fd015261272701525f818161074001528181610d4f01528181610ef90152818161106201528181611247015281816113cc0152818161149901528181611d0c015261258e01525f818161076701528181610c46015281816111c2015281816122ba015281816127a4015261287f01525f81816103e9015281816113a3015261147001526134245ff3fe608060405234801561000f575f5ffd5b5060043610610367575f3560e01c80638b9d2940116101c9578063ba087652116100fe578063da39b3e71161009e578063ea7cbff111610079578063ea7cbff114610928578063ef8b30f7146103b0578063f12297771461095c578063fa1af4f31461096f575f5ffd5b8063da39b3e7146108ce578063dadbccee146108e1578063dd62ed3e14610915575f5ffd5b8063c63d75b6116100d9578063c63d75b614610895578063c6e6f592146103b0578063ce96cb77146108a8578063d905777e146108bb575f5ffd5b8063ba08765214610863578063c2e9710114610876578063c4f59f9b14610880575f5ffd5b8063a8c62e7611610169578063aa5dcecc11610144578063aa5dcecc14610835578063b3d7f6b9146103b0578063b460af941461083d578063b5fd73f814610850575f5ffd5b8063a8c62e7614610807578063a9059cbb1461080f578063a972985e14610822575f5ffd5b806395a4cdcb116101a457806395a4cdcb146107c457806395d89b41146107cc5780639e8494a9146107d4578063a6f19c84146107ff575f5ffd5b80638b9d29401461076257806394bf804d146106cb578063958fde5214610789575f5ffd5b8063313ce5671161029f5780636154041a1161023f5780636e553f651161021a5780636e553f65146106cb5780636e8c271b146106de57806370a08231146107285780637aaf53e61461073b575f5ffd5b80636154041a146106185780636192e6c114610676578063638634ee146106b8575f5ffd5b80633fb814281161027a5780633fb8142814610510578063402d267d1461055957806348e5d9f8146105735780634cdad506146103b0575f5ffd5b8063313ce567146104c357806338d52e0f146104dd5780633bc1f1ed146104fd575f5ffd5b806318160ddd1161030a57806323cb2390116102e557806323cb23901461046a57806325181bb01461047d57806327f859101461049d5780632e2d2984146104b0575f5ffd5b806318160ddd14610424578063211dc32d1461042c57806323b872dd14610457575f5ffd5b806307a2d13a1161034557806307a2d13a146103b0578063095ea7b3146103c15780630a28a477146103b05780630db41f31146103e4575f5ffd5b806301e1d1141461036b57806304f0a5321461038657806306fdde031461039b575b5f5ffd5b6103736109a4565b6040519081526020015b60405180910390f35b610399610394366004612974565b6109b2565b005b6103a3610b87565b60405161037d91906129ab565b6103736103be3660046129e0565b90565b6103d46103cf3660046129f7565b610c16565b604051901515815260200161037d565b61040b7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160e01b0319909116815260200161037d565b610373610c2f565b61043f61043a366004612a21565b610cc5565b6040516001600160801b03909116815260200161037d565b6103d4610465366004612a4d565b610d15565b610399610478366004612a21565b610d3a565b61049061048b366004612ad2565b610ed2565b60405161037d9190612b24565b6104906104ab366004612b66565b610ee0565b6103736104be366004612bc9565b610fae565b6104cb610fd6565b60405160ff909116815260200161037d565b6104e561103e565b6040516001600160a01b03909116815260200161037d565b61037361050b366004612bfd565b61104a565b61043f61051e366004612a21565b6001600160a01b039081165f90815260076020908152604080832094909316825292909252902054600160801b90046001600160801b031690565b610373610567366004612c42565b506001600160801b0390565b6105d1610581366004612c42565b60066020525f9081526040902080546001909101546001600160a01b0382169163ffffffff600160a01b8204811692600160c01b90920416906001600160801b0380821691600160801b90041685565b604080516001600160a01b03909616865263ffffffff948516602087015293909216928401929092526001600160801b03918216606084015216608082015260a00161037d565b610656610626366004612a21565b600760209081525f92835260408084209091529082529020546001600160801b0380821691600160801b90041682565b604080516001600160801b0393841681529290911660208301520161037d565b61043f610684366004612a21565b6001600160a01b038082165f908152600760209081526040808320938616835292905220546001600160801b031692915050565b6103736106c6366004612c42565b611155565b6103736106d9366004612c5d565b61118f565b6107136106ec366004612c42565b6001600160a01b03165f90815260066020526040902054600160a01b900463ffffffff1690565b60405163ffffffff909116815260200161037d565b610373610736366004612c42565b61119b565b6104e57f000000000000000000000000000000000000000000000000000000000000000081565b6104e57f000000000000000000000000000000000000000000000000000000000000000081565b61043f610797366004612c42565b6001600160a01b03165f90815260066020526040902060010154600160801b90046001600160801b031690565b61039961123c565b6103a3611305565b6104e56107e2366004612c42565b6001600160a01b039081165f908152600660205260409020541690565b6104e5611380565b6104e561138b565b6103d461081d3660046129f7565b61143e565b610399610830366004612c42565b61144b565b6104e5611458565b61037361084b366004612bc9565b6114d0565b6103d461085e366004612c42565b611542565b610373610871366004612bc9565b61156c565b61071362093a8081565b610888611578565b60405161037d9190612cc3565b6103736108a3366004612c42565b6115d8565b6103736108b6366004612c42565b6115e6565b6103736108c9366004612c42565b6115f0565b6103736108dc366004612bc9565b6115fa565b6109087f000000000000000000000000000000000000000000000000000000000000000081565b60405161037d9190612cf5565b610373610923366004612a21565b611606565b61043f610936366004612c42565b6001600160a01b03165f908152600660205260409020600101546001600160801b031690565b61043f61096a366004612c42565b611630565b61071361097d366004612c42565b6001600160a01b03165f90815260066020526040902054600160c01b900463ffffffff1690565b5f6109ad610c2f565b905090565b6109bc5f5f611650565b6001600160a01b038083165f908152600660205260409020805490911633146109f85760405163e6a0987b60e01b815260040160405180910390fd5b8054429063ffffffff600160c01b9091048116905f9083168211610a4457610a3d610a386001600160801b038716670de0b6b3a764000062093a806116d5565b61178b565b9050610aad565b5f610a4f8484612d17565b60018601549091505f90610a7b906001600160801b031663ffffffff8416670de0b6b3a76400006116d5565b9050610aa8610a38610a96836001600160801b038b16612d33565b670de0b6b3a764000062093a806116d5565b925050505b835463ffffffff60a01b1916600160a01b63ffffffff851602178455610ad662093a8084612d46565b845463ffffffff60c01b1916600160c01b63ffffffff928316021785556001850180546001600160801b0319166001600160801b0384811691909117909155610b31916001600160a01b03891691339130918a16906117c716565b604080516001600160801b038088168252831660208201526001600160a01b038816917fe5e276353c6a9a47b95455b4825cdbfca509c196bf3398b1386b9a649d632927910160405180910390a2505050505050565b6060610b9161103e565b6001600160a01b03166306fdde036040518163ffffffff1660e01b81526004015f60405180830381865afa158015610bcb573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052610bf29190810190612dce565b604051602001610c029190612e77565b604051602081830303815290604052905090565b5f33610c2381858561182e565b60019150505b92915050565b6040516339370aa960e21b81523060048201525f907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063e4dc2aa490602401602060405180830381865afa158015610c93573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610cb79190612eab565b6001600160801b0316905090565b6001600160a01b038083165f90815260076020908152604080832093851683529290529081208054610d0d90859085906001600160801b03600160801b820481169116611840565b949350505050565b5f33610d22858285611894565b610d2d8585856118f2565b60019150505b9392505050565b60405163d5db72eb60e01b81523360048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063d5db72eb90602401602060405180830381865afa158015610d9c573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610dc09190612ec6565b610ddd57604051632fed761f60e01b815260040160405180910390fd5b6001600160a01b038116610e045760405163d92e233d60e01b815260040160405180910390fd5b6001600160a01b0382165f908152600660205260409020610e2e81546001600160a01b0316151590565b15610e4c57604051638b21c1ed60e01b815260040160405180910390fd5b600580546001810182555f9182527f036b6384b5eca791c62761152d0c79bb0604c104a5fb6f4eb0703f3154bb3db00180546001600160a01b038087166001600160a01b03199283168117909355845490861691168117845560405190927f3344e0a0f48738979c56a1b9f2cd3425597f76766d53e83439cab3fc30b067c791a3505050565b6060610d0d3385858561194f565b6040516217798b60e61b81526060906001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906305de62c090610f3d90309033906001600160e01b03195f351690600401612ee5565b602060405180830381865afa158015610f58573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610f7c9190612ec6565b610f9957604051634eaf9b5d60e11b815260040160405180910390fd5b610fa58585858561194f565b95945050505050565b5f6001600160a01b038316610fc1573392505b610fce3384868786611aa2565b509192915050565b5f610fdf61103e565b6001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa15801561101a573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906109ad9190612f12565b5f6109ad306014611ab7565b6040516217798b60e61b81525f906001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906305de62c0906110a690309033906001600160e01b031987351690600401612ee5565b602060405180830381865afa1580156110c1573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906110e59190612ec6565b61110257604051634eaf9b5d60e11b815260040160405180910390fd5b6001600160a01b0385161580159061112257506001600160a01b03841615155b61113f5760405163d92e233d60e01b815260040160405180910390fd5b61114c8585858686611aa2565b50909392505050565b6001600160a01b0381165f9081526006602052604081205461118390600160c01b900463ffffffff16611ad4565b63ffffffff1692915050565b5f610d3383835f610fae565b604051633de222bb60e21b81523060048201526001600160a01b0382811660248301525f917f00000000000000000000000000000000000000000000000000000000000000009091169063f7888aec90604401602060405180830381865afa158015611209573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061122d9190612eab565b6001600160801b031692915050565b336001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614611285576040516311db81c560e21b815260040160405180910390fd5b5f61128e611aed565b6001600160801b03169050805f036112cb576040517fce33decda06914c187ad6ac1fe22aea60b979d15269474e726bc1db8e0db308b905f90a150565b6112da5f5f835f5f6001611af9565b6040517fce33decda06914c187ad6ac1fe22aea60b979d15269474e726bc1db8e0db308b905f90a150565b606061130f61103e565b6001600160a01b03166395d89b416040518163ffffffff1660e01b81526004015f60405180830381865afa158015611349573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526113709190810190612dce565b604051602001610c029190612f32565b5f6109ad3082611ab7565b604051630165699560e21b81526001600160e01b03197f00000000000000000000000000000000000000000000000000000000000000001660048201525f907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690630595a654906024015b602060405180830381865afa15801561141a573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906109ad9190612f5f565b5f33610c238185856118f2565b611455815f611650565b50565b60405163ef64d76360e01b81526001600160e01b03197f00000000000000000000000000000000000000000000000000000000000000001660048201525f907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063ef64d763906024016113ff565b5f6001600160a01b0383166114e3573392505b336001600160a01b03831614611536575f6114fe8333611606565b9050808511156115215760405163c19f17a960e01b815260040160405180910390fd5b5f19811461153457611534833387611894565b505b610fce82848687611b9c565b6001600160a01b0381165f908152600660205260408120610d3381546001600160a01b0316151590565b5f610d0d8484846114d0565b606060058054806020026020016040519081016040528092919081815260200182805480156115ce57602002820191905f5260205f20905b81546001600160a01b031681526001909101906020018083116115b0575b5050505050905090565b5f6001600160801b03610c29565b5f610c298261119b565b5f610c29826115e6565b5f610d0d848484610fae565b6001600160a01b039182165f90815260016020908152604080832093909416825291909152205490565b6001600160a01b0381165f908152600660205260408120610c2990611e11565b6005545f5b818110156116cf575f6005828154811061167157611671612f7a565b5f9182526020822001546001600160a01b0316915061168f82611ec9565b90506001600160a01b038616156116ab576116ab868383611f44565b6001600160a01b038516156116c5576116c5858383611f44565b5050600101611655565b50505050565b5f838302815f1985870982811083820303915050805f03611709578382816116ff576116ff612f8e565b0492505050610d33565b808411611720576117206003851502601118611fb1565b5f848688095f868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b5f6001600160801b038211156117c3576040516306dfcc6560e41b815260806004820152602481018390526044015b60405180910390fd5b5090565b6040516001600160a01b0384811660248301528381166044830152606482018390526116cf9186918216906323b872dd906084015b604051602081830303815290604052915060e01b6020820180516001600160e01b038381831617835250505050611fc2565b61183b838383600161202e565b505050565b5f5f61187e610a388461185288611630565b61185c9190612fa2565b6001600160801b0316670de0b6b3a76400006118778a61119b565b91906116d5565b905061188a8185612fc1565b9695505050505050565b5f61189f8484611606565b90505f198110156116cf57818110156118e457604051637dc7a0d960e11b81526001600160a01b038416600482015260248101829052604481018390526064016117ba565b6116cf84848484035f61202e565b6001600160a01b03831661191b57604051634b637e8f60e11b81525f60048201526024016117ba565b6001600160a01b0382166119445760405163ec442f0560e01b81525f60048201526024016117ba565b61183b838383612100565b60606001600160a01b038216611963578491505b61196d855f611650565b826001600160401b0381111561198557611985612d62565b6040519080825280602002602001820160405280156119ae578160200160208202803683370190505b5090505f5b83811015611a99575f8585838181106119ce576119ce612f7a565b90506020020160208101906119e39190612c42565b90506119ee81611542565b611a0b5760405163dfde867160e01b815260040160405180910390fd5b6001600160a01b038781165f908152600760209081526040808320938516835292905290812080549091600160801b9091046001600160801b031690819003611a5657505050611a91565b81546001600160801b03168255611a6e8387836123bf565b80858581518110611a8157611a81612f7a565b6020026020010181815250505050505b6001016119b3565b50949350505050565b611ab085858585855f611af9565b5050505050565b5f5f611ac2846123f0565b929092016020015160601c9392505050565b5f610c29611ae8428463ffffffff1661245c565b61246b565b5f6109ad610a38610c2f565b6001600160a01b03851615611b1257611b12855f611650565b5f611b1e87868461249b565b9050611b4d8685837f0000000000000000000000000000000000000000000000000000000000000000876127a2565b60408051868152602081018690526001600160a01b0388169133917fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d7910160405180910390a350505050505050565b611ba6845f611650565b5f611baf611458565b6001600160a01b03166322ce4d86611bc561103e565b611bcd611380565b6040516001600160e01b031960e085901b1681526001600160a01b03928316600482015291166024820152604481018690526064015f60405180830381865afa158015611c1c573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052611c439190810190613075565b90505f611c4e61138b565b6001600160a01b0316632d8e2142837f0000000000000000000000000000000000000000000000000000000000000000886040518463ffffffff1660e01b8152600401611c9d9392919061320a565b60408051808303815f875af1158015611cb8573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611cdc9190613244565b9050611d0a8684837f000000000000000000000000000000000000000000000000000000000000000061287d565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316634bc5d735611d41611380565b6040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602401602060405180830381865afa158015611d83573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611da79190612ec6565b15611dbe57611dbe611db761103e565b86856123bf565b60408051858152602081018590526001600160a01b03808916929088169133917ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db910160405180910390a4505050505050565b5f5f611e1b611aed565b9050806001600160801b03165f03611e4657505060010154600160801b90046001600160801b031690565b82545f9063ffffffff600160a01b8204811691611e6b91600160c01b90910416611ad4565b611e759190612d17565b63ffffffff1690505f8115611ea5576001850154611ea29083906001600160801b039081169086166116d5565b90505b6001850154610fa590610a38908390600160801b90046001600160801b0316612d33565b6001600160a01b0381165f908152600660205260408120611ee981611e11565b8154909250611f0490600160c01b900463ffffffff16611ad4565b815463ffffffff91909116600160a01b0263ffffffff60a01b1990911617815560010180546001600160801b03808416600160801b029116179055919050565b6001600160a01b038084165f9081526007602090815260408083209386168352929052208054611f8a90859085906001600160801b03600160801b820481169116611840565b6001600160801b039283169216600160801b026001600160801b0319169190911790555050565b634e487b715f52806020526024601cfd5b5f5f60205f8451602086015f885af180611fe1576040513d5f823e3d81fd5b50505f513d91508115611ff8578060011415612005565b6001600160a01b0384163b155b156116cf57604051635274afe760e01b81526001600160a01b03851660048201526024016117ba565b6001600160a01b0384166120575760405163e602df0560e01b81525f60048201526024016117ba565b6001600160a01b03831661208057604051634a1406b160e11b81525f60048201526024016117ba565b6001600160a01b038085165f90815260016020908152604080832093871683529290522082905580156116cf57826001600160a01b0316846001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040516120f291815260200190565b60405180910390a350505050565b61210a8383611650565b5f612113611458565b6001600160a01b031663db8c1be9612129611380565b6040516001600160e01b031960e084901b1681526001600160a01b0390911660048201526024015f60405180830381865afa15801561216a573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f1916820160405261219191908101906132a2565b90505f60405180608001604052806121a761103e565b6001600160a01b031681526020016121bd611380565b6001600160a01b0316815260200183815260200183516001600160401b038111156121ea576121ea612d62565b604051908082528060200260200182016040528015612213578160200160208202803683370190505b50905290505f61222161138b565b6001600160a01b0316632d8e2142837f000000000000000000000000000000000000000000000000000000000000000061225961138b565b6040518463ffffffff1660e01b81526004016122779392919061320a565b60408051808303815f875af1158015612292573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906122b69190613244565b90507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316632ebae0c56122ef611380565b88886122fa8961178b565b867f00000000000000000000000000000000000000000000000000000000000000006040518763ffffffff1660e01b815260040161233d969594939291906132d3565b5f604051808303815f87803b158015612354575f5ffd5b505af1158015612366573d5f5f3e3d5ffd5b50505050846001600160a01b0316866001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef866040516123af91815260200190565b60405180910390a3505050505050565b6040516001600160a01b0383811660248301526044820183905261183b91859182169063a9059cbb906064016117fc565b60605f612408602d6001600160a01b0385163b61333d565b6001600160401b0381111561241f5761241f612d62565b6040519080825280601f01601f191660200182016040528015612449576020820181803683370190505b5090508051602d60208301853c92915050565b5f828218828410028218610d33565b5f63ffffffff8211156117c3576040516306dfcc6560e41b815260206004820152602481018390526044016117ba565b604080518082019091525f80825260208201525f6124b7611458565b6001600160a01b03166370f3971b6124cd61103e565b6124d5611380565b6040516001600160e01b031960e085901b1681526001600160a01b03928316600482015291166024820152604481018790526064015f60405180830381865afa158015612524573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f1916820160405261254b9190810190613075565b90505f61255661103e565b90505f5b82604001515181101561270d578260600151818151811061257d5761257d612f7a565b60200260200101515f0315612705577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316634cf64f336125c3611380565b856040015184815181106125d9576125d9612f7a565b60200260200101516040518363ffffffff1660e01b81526004016126139291906001600160a01b0392831681529116602082015260400190565b602060405180830381865afa15801561262e573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906126529190612ec6565b61266f5760405163cf3b351d60e01b815260040160405180910390fd5b84156126bf576126ba828460400151838151811061268f5761268f612f7a565b6020026020010151856060015184815181106126ad576126ad612f7a565b60200260200101516123bf565b612705565b6127058288856040015184815181106126da576126da612f7a565b6020026020010151866060015185815181106126f8576126f8612f7a565b60200260200101516117c7565b60010161255a565b5061271661138b565b6001600160a01b0316630c96a583837f00000000000000000000000000000000000000000000000000000000000000006040518363ffffffff1660e01b8152600401612763929190613350565b60408051808303815f875af115801561277e573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061188a9190613244565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663acc3c88c6127d9611380565b5f886127e48961178b565b8888886040518863ffffffff1660e01b81526004016128099796959493929190613371565b5f604051808303815f87803b158015612820575f5ffd5b505af1158015612832573d5f5f3e3d5ffd5b50506040518681526001600160a01b03881692505f91507fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a35050505050565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316632ebae0c56128b4611380565b865f6128bf8861178b565b87876040518763ffffffff1660e01b81526004016128e2969594939291906132d3565b5f604051808303815f87803b1580156128f9575f5ffd5b505af115801561290b573d5f5f3e3d5ffd5b50506040518581525f92506001600160a01b03871691507fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef906020016120f2565b6001600160a01b0381168114611455575f5ffd5b6001600160801b0381168114611455575f5ffd5b5f5f60408385031215612985575f5ffd5b82356129908161294c565b915060208301356129a081612960565b809150509250929050565b602081525f82518060208401528060208501604085015e5f604082850101526040601f19601f83011684010191505092915050565b5f602082840312156129f0575f5ffd5b5035919050565b5f5f60408385031215612a08575f5ffd5b8235612a138161294c565b946020939093013593505050565b5f5f60408385031215612a32575f5ffd5b8235612a3d8161294c565b915060208301356129a08161294c565b5f5f5f60608486031215612a5f575f5ffd5b8335612a6a8161294c565b92506020840135612a7a8161294c565b929592945050506040919091013590565b5f5f83601f840112612a9b575f5ffd5b5081356001600160401b03811115612ab1575f5ffd5b6020830191508360208260051b8501011115612acb575f5ffd5b9250929050565b5f5f5f60408486031215612ae4575f5ffd5b83356001600160401b03811115612af9575f5ffd5b612b0586828701612a8b565b9094509250506020840135612b198161294c565b809150509250925092565b602080825282518282018190525f918401906040840190835b81811015612b5b578351835260209384019390920191600101612b3d565b509095945050505050565b5f5f5f5f60608587031215612b79575f5ffd5b8435612b848161294c565b935060208501356001600160401b03811115612b9e575f5ffd5b612baa87828801612a8b565b9094509250506040850135612bbe8161294c565b939692955090935050565b5f5f5f60608486031215612bdb575f5ffd5b833592506020840135612bed8161294c565b91506040840135612b198161294c565b5f5f5f5f60808587031215612c10575f5ffd5b8435612c1b8161294c565b93506020850135612c2b8161294c565b9250604085013591506060850135612bbe8161294c565b5f60208284031215612c52575f5ffd5b8135610d338161294c565b5f5f60408385031215612c6e575f5ffd5b8235915060208301356129a08161294c565b5f8151808452602084019350602083015f5b82811015612cb95781516001600160a01b0316865260209586019590910190600101612c92565b5093949350505050565b602081525f610d336020830184612c80565b60028110612cf157634e487b7160e01b5f52602160045260245ffd5b9052565b60208101610c298284612cd5565b634e487b7160e01b5f52601160045260245ffd5b63ffffffff8281168282160390811115610c2957610c29612d03565b80820180821115610c2957610c29612d03565b63ffffffff8181168382160190811115610c2957610c29612d03565b634e487b7160e01b5f52604160045260245ffd5b604051608081016001600160401b0381118282101715612d9857612d98612d62565b60405290565b604051601f8201601f191681016001600160401b0381118282101715612dc657612dc6612d62565b604052919050565b5f60208284031215612dde575f5ffd5b81516001600160401b03811115612df3575f5ffd5b8201601f81018413612e03575f5ffd5b80516001600160401b03811115612e1c57612e1c612d62565b612e2f601f8201601f1916602001612d9e565b818152856020838501011115612e43575f5ffd5b8160208401602083015e5f91810160200191909152949350505050565b5f81518060208401855e5f93019283525090919050565b69029ba30b5b2902220a7960b51b81525f612e95600a830184612e60565b650815985d5b1d60d21b81526006019392505050565b5f60208284031215612ebb575f5ffd5b8151610d3381612960565b5f60208284031215612ed6575f5ffd5b81518015158114610d33575f5ffd5b6001600160a01b0393841681529190921660208201526001600160e01b0319909116604082015260600190565b5f60208284031215612f22575f5ffd5b815160ff81168114610d33575f5ffd5b6273642d60e81b81525f612f496003830184612e60565b650b5d985d5b1d60d21b81526006019392505050565b5f60208284031215612f6f575f5ffd5b8151610d338161294c565b634e487b7160e01b5f52603260045260245ffd5b634e487b7160e01b5f52601260045260245ffd5b6001600160801b038281168282160390811115610c2957610c29612d03565b6001600160801b038181168382160190811115610c2957610c29612d03565b5f6001600160401b03821115612ff857612ff8612d62565b5060051b60200190565b5f82601f830112613011575f5ffd5b815161302461301f82612fe0565b612d9e565b8082825260208201915060208360051b860101925085831115613045575f5ffd5b602085015b8381101561306b57805161305d8161294c565b83526020928301920161304a565b5095945050505050565b5f60208284031215613085575f5ffd5b81516001600160401b0381111561309a575f5ffd5b8201608081850312156130ab575f5ffd5b6130b3612d76565b81516130be8161294c565b815260208201516130ce8161294c565b602082015260408201516001600160401b038111156130eb575f5ffd5b6130f786828501613002565b60408301525060608201516001600160401b03811115613115575f5ffd5b80830192505084601f830112613129575f5ffd5b815161313761301f82612fe0565b8082825260208201915060208360051b860101925087831115613158575f5ffd5b6020850194505b8285101561317a57845182526020948501949091019061315f565b6060840152509095945050505050565b60018060a01b03815116825260018060a01b0360208201511660208301525f6040820151608060408501526131c26080850182612c80565b9050606083015184820360608601528181518084526020840191506020830193505f92505b8083101561306b57835182526020820191506020840193506001830192506131e7565b606081525f61321c606083018661318a565b905061322b6020830185612cd5565b6001600160a01b03929092166040919091015292915050565b5f6040828403128015613255575f5ffd5b50604080519081016001600160401b038111828210171561327857613278612d62565b604052825161328681612960565b8152602083015161329681612960565b60208201529392505050565b5f602082840312156132b2575f5ffd5b81516001600160401b038111156132c7575f5ffd5b610d0d84828501613002565b6001600160a01b0387811682528681166020830152851660408201526001600160801b038416606082015260e08101613325608083018580516001600160801b03908116835260209182015116910152565b61333260c0830184612cd5565b979650505050505050565b81810381811115610c2957610c29612d03565b604081525f613362604083018561318a565b9050610d336020830184612cd5565b6001600160a01b0388811682528781166020830152861660408201526001600160801b038516606082015261010081016133c4608083018680516001600160801b03908116835260209182015116910152565b6133d160c0830185612cd5565b6001600160a01b039290921660e09190910152969550505050505056fea2646970667358221220f065b4402bb3997c4d3ded629f33949446fa5f520e6569f64777daee2eb6b80064736f6c634300081c0033c715e373000000000000000000000000000000000000000000000000000000000000000000000000000000002d8bce1fae00a959354acd9ebf9174337a64d4fb00000000000000000000000093b4b9bd266ffa8af68e39edfa8cfe2a62011ce00000000000000000000000000000000000000000000000000000000000000001
Deployed Bytecode
0x608060405234801561000f575f5ffd5b5060043610610367575f3560e01c80638b9d2940116101c9578063ba087652116100fe578063da39b3e71161009e578063ea7cbff111610079578063ea7cbff114610928578063ef8b30f7146103b0578063f12297771461095c578063fa1af4f31461096f575f5ffd5b8063da39b3e7146108ce578063dadbccee146108e1578063dd62ed3e14610915575f5ffd5b8063c63d75b6116100d9578063c63d75b614610895578063c6e6f592146103b0578063ce96cb77146108a8578063d905777e146108bb575f5ffd5b8063ba08765214610863578063c2e9710114610876578063c4f59f9b14610880575f5ffd5b8063a8c62e7611610169578063aa5dcecc11610144578063aa5dcecc14610835578063b3d7f6b9146103b0578063b460af941461083d578063b5fd73f814610850575f5ffd5b8063a8c62e7614610807578063a9059cbb1461080f578063a972985e14610822575f5ffd5b806395a4cdcb116101a457806395a4cdcb146107c457806395d89b41146107cc5780639e8494a9146107d4578063a6f19c84146107ff575f5ffd5b80638b9d29401461076257806394bf804d146106cb578063958fde5214610789575f5ffd5b8063313ce5671161029f5780636154041a1161023f5780636e553f651161021a5780636e553f65146106cb5780636e8c271b146106de57806370a08231146107285780637aaf53e61461073b575f5ffd5b80636154041a146106185780636192e6c114610676578063638634ee146106b8575f5ffd5b80633fb814281161027a5780633fb8142814610510578063402d267d1461055957806348e5d9f8146105735780634cdad506146103b0575f5ffd5b8063313ce567146104c357806338d52e0f146104dd5780633bc1f1ed146104fd575f5ffd5b806318160ddd1161030a57806323cb2390116102e557806323cb23901461046a57806325181bb01461047d57806327f859101461049d5780632e2d2984146104b0575f5ffd5b806318160ddd14610424578063211dc32d1461042c57806323b872dd14610457575f5ffd5b806307a2d13a1161034557806307a2d13a146103b0578063095ea7b3146103c15780630a28a477146103b05780630db41f31146103e4575f5ffd5b806301e1d1141461036b57806304f0a5321461038657806306fdde031461039b575b5f5ffd5b6103736109a4565b6040519081526020015b60405180910390f35b610399610394366004612974565b6109b2565b005b6103a3610b87565b60405161037d91906129ab565b6103736103be3660046129e0565b90565b6103d46103cf3660046129f7565b610c16565b604051901515815260200161037d565b61040b7fc715e3730000000000000000000000000000000000000000000000000000000081565b6040516001600160e01b0319909116815260200161037d565b610373610c2f565b61043f61043a366004612a21565b610cc5565b6040516001600160801b03909116815260200161037d565b6103d4610465366004612a4d565b610d15565b610399610478366004612a21565b610d3a565b61049061048b366004612ad2565b610ed2565b60405161037d9190612b24565b6104906104ab366004612b66565b610ee0565b6103736104be366004612bc9565b610fae565b6104cb610fd6565b60405160ff909116815260200161037d565b6104e561103e565b6040516001600160a01b03909116815260200161037d565b61037361050b366004612bfd565b61104a565b61043f61051e366004612a21565b6001600160a01b039081165f90815260076020908152604080832094909316825292909252902054600160801b90046001600160801b031690565b610373610567366004612c42565b506001600160801b0390565b6105d1610581366004612c42565b60066020525f9081526040902080546001909101546001600160a01b0382169163ffffffff600160a01b8204811692600160c01b90920416906001600160801b0380821691600160801b90041685565b604080516001600160a01b03909616865263ffffffff948516602087015293909216928401929092526001600160801b03918216606084015216608082015260a00161037d565b610656610626366004612a21565b600760209081525f92835260408084209091529082529020546001600160801b0380821691600160801b90041682565b604080516001600160801b0393841681529290911660208301520161037d565b61043f610684366004612a21565b6001600160a01b038082165f908152600760209081526040808320938616835292905220546001600160801b031692915050565b6103736106c6366004612c42565b611155565b6103736106d9366004612c5d565b61118f565b6107136106ec366004612c42565b6001600160a01b03165f90815260066020526040902054600160a01b900463ffffffff1690565b60405163ffffffff909116815260200161037d565b610373610736366004612c42565b61119b565b6104e57f0000000000000000000000002d8bce1fae00a959354acd9ebf9174337a64d4fb81565b6104e57f00000000000000000000000093b4b9bd266ffa8af68e39edfa8cfe2a62011ce081565b61043f610797366004612c42565b6001600160a01b03165f90815260066020526040902060010154600160801b90046001600160801b031690565b61039961123c565b6103a3611305565b6104e56107e2366004612c42565b6001600160a01b039081165f908152600660205260409020541690565b6104e5611380565b6104e561138b565b6103d461081d3660046129f7565b61143e565b610399610830366004612c42565b61144b565b6104e5611458565b61037361084b366004612bc9565b6114d0565b6103d461085e366004612c42565b611542565b610373610871366004612bc9565b61156c565b61071362093a8081565b610888611578565b60405161037d9190612cc3565b6103736108a3366004612c42565b6115d8565b6103736108b6366004612c42565b6115e6565b6103736108c9366004612c42565b6115f0565b6103736108dc366004612bc9565b6115fa565b6109087f000000000000000000000000000000000000000000000000000000000000000181565b60405161037d9190612cf5565b610373610923366004612a21565b611606565b61043f610936366004612c42565b6001600160a01b03165f908152600660205260409020600101546001600160801b031690565b61043f61096a366004612c42565b611630565b61071361097d366004612c42565b6001600160a01b03165f90815260066020526040902054600160c01b900463ffffffff1690565b5f6109ad610c2f565b905090565b6109bc5f5f611650565b6001600160a01b038083165f908152600660205260409020805490911633146109f85760405163e6a0987b60e01b815260040160405180910390fd5b8054429063ffffffff600160c01b9091048116905f9083168211610a4457610a3d610a386001600160801b038716670de0b6b3a764000062093a806116d5565b61178b565b9050610aad565b5f610a4f8484612d17565b60018601549091505f90610a7b906001600160801b031663ffffffff8416670de0b6b3a76400006116d5565b9050610aa8610a38610a96836001600160801b038b16612d33565b670de0b6b3a764000062093a806116d5565b925050505b835463ffffffff60a01b1916600160a01b63ffffffff851602178455610ad662093a8084612d46565b845463ffffffff60c01b1916600160c01b63ffffffff928316021785556001850180546001600160801b0319166001600160801b0384811691909117909155610b31916001600160a01b03891691339130918a16906117c716565b604080516001600160801b038088168252831660208201526001600160a01b038816917fe5e276353c6a9a47b95455b4825cdbfca509c196bf3398b1386b9a649d632927910160405180910390a2505050505050565b6060610b9161103e565b6001600160a01b03166306fdde036040518163ffffffff1660e01b81526004015f60405180830381865afa158015610bcb573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052610bf29190810190612dce565b604051602001610c029190612e77565b604051602081830303815290604052905090565b5f33610c2381858561182e565b60019150505b92915050565b6040516339370aa960e21b81523060048201525f907f00000000000000000000000093b4b9bd266ffa8af68e39edfa8cfe2a62011ce06001600160a01b03169063e4dc2aa490602401602060405180830381865afa158015610c93573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610cb79190612eab565b6001600160801b0316905090565b6001600160a01b038083165f90815260076020908152604080832093851683529290529081208054610d0d90859085906001600160801b03600160801b820481169116611840565b949350505050565b5f33610d22858285611894565b610d2d8585856118f2565b60019150505b9392505050565b60405163d5db72eb60e01b81523360048201527f0000000000000000000000002d8bce1fae00a959354acd9ebf9174337a64d4fb6001600160a01b03169063d5db72eb90602401602060405180830381865afa158015610d9c573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610dc09190612ec6565b610ddd57604051632fed761f60e01b815260040160405180910390fd5b6001600160a01b038116610e045760405163d92e233d60e01b815260040160405180910390fd5b6001600160a01b0382165f908152600660205260409020610e2e81546001600160a01b0316151590565b15610e4c57604051638b21c1ed60e01b815260040160405180910390fd5b600580546001810182555f9182527f036b6384b5eca791c62761152d0c79bb0604c104a5fb6f4eb0703f3154bb3db00180546001600160a01b038087166001600160a01b03199283168117909355845490861691168117845560405190927f3344e0a0f48738979c56a1b9f2cd3425597f76766d53e83439cab3fc30b067c791a3505050565b6060610d0d3385858561194f565b6040516217798b60e61b81526060906001600160a01b037f0000000000000000000000002d8bce1fae00a959354acd9ebf9174337a64d4fb16906305de62c090610f3d90309033906001600160e01b03195f351690600401612ee5565b602060405180830381865afa158015610f58573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610f7c9190612ec6565b610f9957604051634eaf9b5d60e11b815260040160405180910390fd5b610fa58585858561194f565b95945050505050565b5f6001600160a01b038316610fc1573392505b610fce3384868786611aa2565b509192915050565b5f610fdf61103e565b6001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa15801561101a573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906109ad9190612f12565b5f6109ad306014611ab7565b6040516217798b60e61b81525f906001600160a01b037f0000000000000000000000002d8bce1fae00a959354acd9ebf9174337a64d4fb16906305de62c0906110a690309033906001600160e01b031987351690600401612ee5565b602060405180830381865afa1580156110c1573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906110e59190612ec6565b61110257604051634eaf9b5d60e11b815260040160405180910390fd5b6001600160a01b0385161580159061112257506001600160a01b03841615155b61113f5760405163d92e233d60e01b815260040160405180910390fd5b61114c8585858686611aa2565b50909392505050565b6001600160a01b0381165f9081526006602052604081205461118390600160c01b900463ffffffff16611ad4565b63ffffffff1692915050565b5f610d3383835f610fae565b604051633de222bb60e21b81523060048201526001600160a01b0382811660248301525f917f00000000000000000000000093b4b9bd266ffa8af68e39edfa8cfe2a62011ce09091169063f7888aec90604401602060405180830381865afa158015611209573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061122d9190612eab565b6001600160801b031692915050565b336001600160a01b037f0000000000000000000000002d8bce1fae00a959354acd9ebf9174337a64d4fb1614611285576040516311db81c560e21b815260040160405180910390fd5b5f61128e611aed565b6001600160801b03169050805f036112cb576040517fce33decda06914c187ad6ac1fe22aea60b979d15269474e726bc1db8e0db308b905f90a150565b6112da5f5f835f5f6001611af9565b6040517fce33decda06914c187ad6ac1fe22aea60b979d15269474e726bc1db8e0db308b905f90a150565b606061130f61103e565b6001600160a01b03166395d89b416040518163ffffffff1660e01b81526004015f60405180830381865afa158015611349573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526113709190810190612dce565b604051602001610c029190612f32565b5f6109ad3082611ab7565b604051630165699560e21b81526001600160e01b03197fc715e373000000000000000000000000000000000000000000000000000000001660048201525f907f0000000000000000000000002d8bce1fae00a959354acd9ebf9174337a64d4fb6001600160a01b031690630595a654906024015b602060405180830381865afa15801561141a573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906109ad9190612f5f565b5f33610c238185856118f2565b611455815f611650565b50565b60405163ef64d76360e01b81526001600160e01b03197fc715e373000000000000000000000000000000000000000000000000000000001660048201525f907f0000000000000000000000002d8bce1fae00a959354acd9ebf9174337a64d4fb6001600160a01b03169063ef64d763906024016113ff565b5f6001600160a01b0383166114e3573392505b336001600160a01b03831614611536575f6114fe8333611606565b9050808511156115215760405163c19f17a960e01b815260040160405180910390fd5b5f19811461153457611534833387611894565b505b610fce82848687611b9c565b6001600160a01b0381165f908152600660205260408120610d3381546001600160a01b0316151590565b5f610d0d8484846114d0565b606060058054806020026020016040519081016040528092919081815260200182805480156115ce57602002820191905f5260205f20905b81546001600160a01b031681526001909101906020018083116115b0575b5050505050905090565b5f6001600160801b03610c29565b5f610c298261119b565b5f610c29826115e6565b5f610d0d848484610fae565b6001600160a01b039182165f90815260016020908152604080832093909416825291909152205490565b6001600160a01b0381165f908152600660205260408120610c2990611e11565b6005545f5b818110156116cf575f6005828154811061167157611671612f7a565b5f9182526020822001546001600160a01b0316915061168f82611ec9565b90506001600160a01b038616156116ab576116ab868383611f44565b6001600160a01b038516156116c5576116c5858383611f44565b5050600101611655565b50505050565b5f838302815f1985870982811083820303915050805f03611709578382816116ff576116ff612f8e565b0492505050610d33565b808411611720576117206003851502601118611fb1565b5f848688095f868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b5f6001600160801b038211156117c3576040516306dfcc6560e41b815260806004820152602481018390526044015b60405180910390fd5b5090565b6040516001600160a01b0384811660248301528381166044830152606482018390526116cf9186918216906323b872dd906084015b604051602081830303815290604052915060e01b6020820180516001600160e01b038381831617835250505050611fc2565b61183b838383600161202e565b505050565b5f5f61187e610a388461185288611630565b61185c9190612fa2565b6001600160801b0316670de0b6b3a76400006118778a61119b565b91906116d5565b905061188a8185612fc1565b9695505050505050565b5f61189f8484611606565b90505f198110156116cf57818110156118e457604051637dc7a0d960e11b81526001600160a01b038416600482015260248101829052604481018390526064016117ba565b6116cf84848484035f61202e565b6001600160a01b03831661191b57604051634b637e8f60e11b81525f60048201526024016117ba565b6001600160a01b0382166119445760405163ec442f0560e01b81525f60048201526024016117ba565b61183b838383612100565b60606001600160a01b038216611963578491505b61196d855f611650565b826001600160401b0381111561198557611985612d62565b6040519080825280602002602001820160405280156119ae578160200160208202803683370190505b5090505f5b83811015611a99575f8585838181106119ce576119ce612f7a565b90506020020160208101906119e39190612c42565b90506119ee81611542565b611a0b5760405163dfde867160e01b815260040160405180910390fd5b6001600160a01b038781165f908152600760209081526040808320938516835292905290812080549091600160801b9091046001600160801b031690819003611a5657505050611a91565b81546001600160801b03168255611a6e8387836123bf565b80858581518110611a8157611a81612f7a565b6020026020010181815250505050505b6001016119b3565b50949350505050565b611ab085858585855f611af9565b5050505050565b5f5f611ac2846123f0565b929092016020015160601c9392505050565b5f610c29611ae8428463ffffffff1661245c565b61246b565b5f6109ad610a38610c2f565b6001600160a01b03851615611b1257611b12855f611650565b5f611b1e87868461249b565b9050611b4d8685837f0000000000000000000000000000000000000000000000000000000000000001876127a2565b60408051868152602081018690526001600160a01b0388169133917fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d7910160405180910390a350505050505050565b611ba6845f611650565b5f611baf611458565b6001600160a01b03166322ce4d86611bc561103e565b611bcd611380565b6040516001600160e01b031960e085901b1681526001600160a01b03928316600482015291166024820152604481018690526064015f60405180830381865afa158015611c1c573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052611c439190810190613075565b90505f611c4e61138b565b6001600160a01b0316632d8e2142837f0000000000000000000000000000000000000000000000000000000000000001886040518463ffffffff1660e01b8152600401611c9d9392919061320a565b60408051808303815f875af1158015611cb8573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611cdc9190613244565b9050611d0a8684837f000000000000000000000000000000000000000000000000000000000000000161287d565b7f0000000000000000000000002d8bce1fae00a959354acd9ebf9174337a64d4fb6001600160a01b0316634bc5d735611d41611380565b6040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602401602060405180830381865afa158015611d83573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611da79190612ec6565b15611dbe57611dbe611db761103e565b86856123bf565b60408051858152602081018590526001600160a01b03808916929088169133917ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db910160405180910390a4505050505050565b5f5f611e1b611aed565b9050806001600160801b03165f03611e4657505060010154600160801b90046001600160801b031690565b82545f9063ffffffff600160a01b8204811691611e6b91600160c01b90910416611ad4565b611e759190612d17565b63ffffffff1690505f8115611ea5576001850154611ea29083906001600160801b039081169086166116d5565b90505b6001850154610fa590610a38908390600160801b90046001600160801b0316612d33565b6001600160a01b0381165f908152600660205260408120611ee981611e11565b8154909250611f0490600160c01b900463ffffffff16611ad4565b815463ffffffff91909116600160a01b0263ffffffff60a01b1990911617815560010180546001600160801b03808416600160801b029116179055919050565b6001600160a01b038084165f9081526007602090815260408083209386168352929052208054611f8a90859085906001600160801b03600160801b820481169116611840565b6001600160801b039283169216600160801b026001600160801b0319169190911790555050565b634e487b715f52806020526024601cfd5b5f5f60205f8451602086015f885af180611fe1576040513d5f823e3d81fd5b50505f513d91508115611ff8578060011415612005565b6001600160a01b0384163b155b156116cf57604051635274afe760e01b81526001600160a01b03851660048201526024016117ba565b6001600160a01b0384166120575760405163e602df0560e01b81525f60048201526024016117ba565b6001600160a01b03831661208057604051634a1406b160e11b81525f60048201526024016117ba565b6001600160a01b038085165f90815260016020908152604080832093871683529290522082905580156116cf57826001600160a01b0316846001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040516120f291815260200190565b60405180910390a350505050565b61210a8383611650565b5f612113611458565b6001600160a01b031663db8c1be9612129611380565b6040516001600160e01b031960e084901b1681526001600160a01b0390911660048201526024015f60405180830381865afa15801561216a573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f1916820160405261219191908101906132a2565b90505f60405180608001604052806121a761103e565b6001600160a01b031681526020016121bd611380565b6001600160a01b0316815260200183815260200183516001600160401b038111156121ea576121ea612d62565b604051908082528060200260200182016040528015612213578160200160208202803683370190505b50905290505f61222161138b565b6001600160a01b0316632d8e2142837f000000000000000000000000000000000000000000000000000000000000000161225961138b565b6040518463ffffffff1660e01b81526004016122779392919061320a565b60408051808303815f875af1158015612292573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906122b69190613244565b90507f00000000000000000000000093b4b9bd266ffa8af68e39edfa8cfe2a62011ce06001600160a01b0316632ebae0c56122ef611380565b88886122fa8961178b565b867f00000000000000000000000000000000000000000000000000000000000000016040518763ffffffff1660e01b815260040161233d969594939291906132d3565b5f604051808303815f87803b158015612354575f5ffd5b505af1158015612366573d5f5f3e3d5ffd5b50505050846001600160a01b0316866001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef866040516123af91815260200190565b60405180910390a3505050505050565b6040516001600160a01b0383811660248301526044820183905261183b91859182169063a9059cbb906064016117fc565b60605f612408602d6001600160a01b0385163b61333d565b6001600160401b0381111561241f5761241f612d62565b6040519080825280601f01601f191660200182016040528015612449576020820181803683370190505b5090508051602d60208301853c92915050565b5f828218828410028218610d33565b5f63ffffffff8211156117c3576040516306dfcc6560e41b815260206004820152602481018390526044016117ba565b604080518082019091525f80825260208201525f6124b7611458565b6001600160a01b03166370f3971b6124cd61103e565b6124d5611380565b6040516001600160e01b031960e085901b1681526001600160a01b03928316600482015291166024820152604481018790526064015f60405180830381865afa158015612524573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f1916820160405261254b9190810190613075565b90505f61255661103e565b90505f5b82604001515181101561270d578260600151818151811061257d5761257d612f7a565b60200260200101515f0315612705577f0000000000000000000000002d8bce1fae00a959354acd9ebf9174337a64d4fb6001600160a01b0316634cf64f336125c3611380565b856040015184815181106125d9576125d9612f7a565b60200260200101516040518363ffffffff1660e01b81526004016126139291906001600160a01b0392831681529116602082015260400190565b602060405180830381865afa15801561262e573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906126529190612ec6565b61266f5760405163cf3b351d60e01b815260040160405180910390fd5b84156126bf576126ba828460400151838151811061268f5761268f612f7a565b6020026020010151856060015184815181106126ad576126ad612f7a565b60200260200101516123bf565b612705565b6127058288856040015184815181106126da576126da612f7a565b6020026020010151866060015185815181106126f8576126f8612f7a565b60200260200101516117c7565b60010161255a565b5061271661138b565b6001600160a01b0316630c96a583837f00000000000000000000000000000000000000000000000000000000000000016040518363ffffffff1660e01b8152600401612763929190613350565b60408051808303815f875af115801561277e573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061188a9190613244565b7f00000000000000000000000093b4b9bd266ffa8af68e39edfa8cfe2a62011ce06001600160a01b031663acc3c88c6127d9611380565b5f886127e48961178b565b8888886040518863ffffffff1660e01b81526004016128099796959493929190613371565b5f604051808303815f87803b158015612820575f5ffd5b505af1158015612832573d5f5f3e3d5ffd5b50506040518681526001600160a01b03881692505f91507fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a35050505050565b7f00000000000000000000000093b4b9bd266ffa8af68e39edfa8cfe2a62011ce06001600160a01b0316632ebae0c56128b4611380565b865f6128bf8861178b565b87876040518763ffffffff1660e01b81526004016128e2969594939291906132d3565b5f604051808303815f87803b1580156128f9575f5ffd5b505af115801561290b573d5f5f3e3d5ffd5b50506040518581525f92506001600160a01b03871691507fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef906020016120f2565b6001600160a01b0381168114611455575f5ffd5b6001600160801b0381168114611455575f5ffd5b5f5f60408385031215612985575f5ffd5b82356129908161294c565b915060208301356129a081612960565b809150509250929050565b602081525f82518060208401528060208501604085015e5f604082850101526040601f19601f83011684010191505092915050565b5f602082840312156129f0575f5ffd5b5035919050565b5f5f60408385031215612a08575f5ffd5b8235612a138161294c565b946020939093013593505050565b5f5f60408385031215612a32575f5ffd5b8235612a3d8161294c565b915060208301356129a08161294c565b5f5f5f60608486031215612a5f575f5ffd5b8335612a6a8161294c565b92506020840135612a7a8161294c565b929592945050506040919091013590565b5f5f83601f840112612a9b575f5ffd5b5081356001600160401b03811115612ab1575f5ffd5b6020830191508360208260051b8501011115612acb575f5ffd5b9250929050565b5f5f5f60408486031215612ae4575f5ffd5b83356001600160401b03811115612af9575f5ffd5b612b0586828701612a8b565b9094509250506020840135612b198161294c565b809150509250925092565b602080825282518282018190525f918401906040840190835b81811015612b5b578351835260209384019390920191600101612b3d565b509095945050505050565b5f5f5f5f60608587031215612b79575f5ffd5b8435612b848161294c565b935060208501356001600160401b03811115612b9e575f5ffd5b612baa87828801612a8b565b9094509250506040850135612bbe8161294c565b939692955090935050565b5f5f5f60608486031215612bdb575f5ffd5b833592506020840135612bed8161294c565b91506040840135612b198161294c565b5f5f5f5f60808587031215612c10575f5ffd5b8435612c1b8161294c565b93506020850135612c2b8161294c565b9250604085013591506060850135612bbe8161294c565b5f60208284031215612c52575f5ffd5b8135610d338161294c565b5f5f60408385031215612c6e575f5ffd5b8235915060208301356129a08161294c565b5f8151808452602084019350602083015f5b82811015612cb95781516001600160a01b0316865260209586019590910190600101612c92565b5093949350505050565b602081525f610d336020830184612c80565b60028110612cf157634e487b7160e01b5f52602160045260245ffd5b9052565b60208101610c298284612cd5565b634e487b7160e01b5f52601160045260245ffd5b63ffffffff8281168282160390811115610c2957610c29612d03565b80820180821115610c2957610c29612d03565b63ffffffff8181168382160190811115610c2957610c29612d03565b634e487b7160e01b5f52604160045260245ffd5b604051608081016001600160401b0381118282101715612d9857612d98612d62565b60405290565b604051601f8201601f191681016001600160401b0381118282101715612dc657612dc6612d62565b604052919050565b5f60208284031215612dde575f5ffd5b81516001600160401b03811115612df3575f5ffd5b8201601f81018413612e03575f5ffd5b80516001600160401b03811115612e1c57612e1c612d62565b612e2f601f8201601f1916602001612d9e565b818152856020838501011115612e43575f5ffd5b8160208401602083015e5f91810160200191909152949350505050565b5f81518060208401855e5f93019283525090919050565b69029ba30b5b2902220a7960b51b81525f612e95600a830184612e60565b650815985d5b1d60d21b81526006019392505050565b5f60208284031215612ebb575f5ffd5b8151610d3381612960565b5f60208284031215612ed6575f5ffd5b81518015158114610d33575f5ffd5b6001600160a01b0393841681529190921660208201526001600160e01b0319909116604082015260600190565b5f60208284031215612f22575f5ffd5b815160ff81168114610d33575f5ffd5b6273642d60e81b81525f612f496003830184612e60565b650b5d985d5b1d60d21b81526006019392505050565b5f60208284031215612f6f575f5ffd5b8151610d338161294c565b634e487b7160e01b5f52603260045260245ffd5b634e487b7160e01b5f52601260045260245ffd5b6001600160801b038281168282160390811115610c2957610c29612d03565b6001600160801b038181168382160190811115610c2957610c29612d03565b5f6001600160401b03821115612ff857612ff8612d62565b5060051b60200190565b5f82601f830112613011575f5ffd5b815161302461301f82612fe0565b612d9e565b8082825260208201915060208360051b860101925085831115613045575f5ffd5b602085015b8381101561306b57805161305d8161294c565b83526020928301920161304a565b5095945050505050565b5f60208284031215613085575f5ffd5b81516001600160401b0381111561309a575f5ffd5b8201608081850312156130ab575f5ffd5b6130b3612d76565b81516130be8161294c565b815260208201516130ce8161294c565b602082015260408201516001600160401b038111156130eb575f5ffd5b6130f786828501613002565b60408301525060608201516001600160401b03811115613115575f5ffd5b80830192505084601f830112613129575f5ffd5b815161313761301f82612fe0565b8082825260208201915060208360051b860101925087831115613158575f5ffd5b6020850194505b8285101561317a57845182526020948501949091019061315f565b6060840152509095945050505050565b60018060a01b03815116825260018060a01b0360208201511660208301525f6040820151608060408501526131c26080850182612c80565b9050606083015184820360608601528181518084526020840191506020830193505f92505b8083101561306b57835182526020820191506020840193506001830192506131e7565b606081525f61321c606083018661318a565b905061322b6020830185612cd5565b6001600160a01b03929092166040919091015292915050565b5f6040828403128015613255575f5ffd5b50604080519081016001600160401b038111828210171561327857613278612d62565b604052825161328681612960565b8152602083015161329681612960565b60208201529392505050565b5f602082840312156132b2575f5ffd5b81516001600160401b038111156132c7575f5ffd5b610d0d84828501613002565b6001600160a01b0387811682528681166020830152851660408201526001600160801b038416606082015260e08101613325608083018580516001600160801b03908116835260209182015116910152565b61333260c0830184612cd5565b979650505050505050565b81810381811115610c2957610c29612d03565b604081525f613362604083018561318a565b9050610d336020830184612cd5565b6001600160a01b0388811682528781166020830152861660408201526001600160801b038516606082015261010081016133c4608083018680516001600160801b03908116835260209182015116910152565b6133d160c0830185612cd5565b6001600160a01b039290921660e09190910152969550505050505056fea2646970667358221220f065b4402bb3997c4d3ded629f33949446fa5f520e6569f64777daee2eb6b80064736f6c634300081c0033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
c715e373000000000000000000000000000000000000000000000000000000000000000000000000000000002d8bce1fae00a959354acd9ebf9174337a64d4fb00000000000000000000000093b4b9bd266ffa8af68e39edfa8cfe2a62011ce00000000000000000000000000000000000000000000000000000000000000001
-----Decoded View---------------
Arg [0] : protocolId (bytes4): 0xc715e373
Arg [1] : protocolController (address): 0x2d8BcE1FaE00a959354aCD9eBf9174337A64d4fb
Arg [2] : accountant (address): 0x93b4B9bd266fFA8AF68e39EDFa8cFe2A62011Ce0
Arg [3] : policy (uint8): 1
-----Encoded View---------------
4 Constructor Arguments found :
Arg [0] : c715e37300000000000000000000000000000000000000000000000000000000
Arg [1] : 0000000000000000000000002d8bce1fae00a959354acd9ebf9174337a64d4fb
Arg [2] : 00000000000000000000000093b4b9bd266ffa8af68e39edfa8cfe2a62011ce0
Arg [3] : 0000000000000000000000000000000000000000000000000000000000000001
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in FRAX
0
Multichain Portfolio | 35 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
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.