Source Code
Latest 22 from a total of 22 transactions
| Transaction Hash |
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
| Claim | 23236337 | 187 days ago | IN | 0 FRAX | 0.00019163 | ||||
| Claim Protocol F... | 23236002 | 187 days ago | IN | 0 FRAX | 0.00011365 | ||||
| Accept Ownership | 23236002 | 187 days ago | IN | 0 FRAX | 0.0001136 | ||||
| Claim | 23235940 | 187 days ago | IN | 0 FRAX | 0.00012198 | ||||
| Claim | 23235854 | 187 days ago | IN | 0 FRAX | 0.00014781 | ||||
| Claim | 23235659 | 187 days ago | IN | 0 FRAX | 0.00013683 | ||||
| Claim | 23235650 | 187 days ago | IN | 0 FRAX | 0.00013489 | ||||
| Claim | 23193069 | 188 days ago | IN | 0 FRAX | 0.00022855 | ||||
| Claim | 23193011 | 188 days ago | IN | 0 FRAX | 0.00021596 | ||||
| Claim | 23084122 | 190 days ago | IN | 0 FRAX | 0.0000455 | ||||
| Claim | 23042811 | 191 days ago | IN | 0 FRAX | 0.00008564 | ||||
| Harvest | 23018141 | 192 days ago | IN | 0 FRAX | 0.00066023 | ||||
| Claim | 22941395 | 193 days ago | IN | 0 FRAX | 0.00121155 | ||||
| Claim | 22742135 | 198 days ago | IN | 0 FRAX | 0.00007212 | ||||
| Harvest | 22729566 | 198 days ago | IN | 0 FRAX | 0.00024589 | ||||
| Harvest | 22633134 | 200 days ago | IN | 0 FRAX | 0.00044959 | ||||
| Harvest | 22583218 | 202 days ago | IN | 0 FRAX | 0.00009486 | ||||
| Harvest | 22547139 | 202 days ago | IN | 0 FRAX | 0.00044126 | ||||
| Harvest | 22331172 | 207 days ago | IN | 0 FRAX | 0.00056639 | ||||
| Claim | 21768027 | 221 days ago | IN | 0 FRAX | 0.000267 | ||||
| Transfer Ownersh... | 21763474 | 221 days ago | IN | 0 FRAX | 0.00015792 | ||||
| Set Harvest Fee ... | 21763472 | 221 days ago | IN | 0 FRAX | 0.00015789 |
Advanced mode: Intended for advanced users or developers and will display all Internal Transactions including zero value transfers.
Latest 25 internal transactions (View All)
Advanced mode:
| Parent Transaction Hash | Block | From | To | ||||
|---|---|---|---|---|---|---|---|
| 23236337 | 187 days ago | 0 FRAX | |||||
| 23236337 | 187 days ago | 0 FRAX | |||||
| 23236337 | 187 days ago | 0 FRAX | |||||
| 23236337 | 187 days ago | 0 FRAX | |||||
| 23236337 | 187 days ago | 0 FRAX | |||||
| 23236337 | 187 days ago | 0 FRAX | |||||
| 23236002 | 187 days ago | 0 FRAX | |||||
| 23236002 | 187 days ago | 0 FRAX | |||||
| 23236001 | 187 days ago | 0 FRAX | |||||
| 23235940 | 187 days ago | 0 FRAX | |||||
| 23235940 | 187 days ago | 0 FRAX | |||||
| 23235940 | 187 days ago | 0 FRAX | |||||
| 23235940 | 187 days ago | 0 FRAX | |||||
| 23235940 | 187 days ago | 0 FRAX | |||||
| 23235940 | 187 days ago | 0 FRAX | |||||
| 23235854 | 187 days ago | 0 FRAX | |||||
| 23235854 | 187 days ago | 0 FRAX | |||||
| 23235854 | 187 days ago | 0 FRAX | |||||
| 23235854 | 187 days ago | 0 FRAX | |||||
| 23235854 | 187 days ago | 0 FRAX | |||||
| 23235854 | 187 days ago | 0 FRAX | |||||
| 23235659 | 187 days ago | 0 FRAX | |||||
| 23235659 | 187 days ago | 0 FRAX | |||||
| 23235659 | 187 days ago | 0 FRAX | |||||
| 23235659 | 187 days ago | 0 FRAX |
Cross-Chain Transactions
Loading...
Loading
Contract Name:
Accountant
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 {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
import {Ownable2Step, Ownable} from "@openzeppelin/contracts/access/Ownable2Step.sol";
import {SafeERC20, IERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {ReentrancyGuardTransient} from "@openzeppelin/contracts/utils/ReentrancyGuardTransient.sol";
import {IStrategy} from "src/interfaces/IStrategy.sol";
import {IAccountant} from "src/interfaces/IAccountant.sol";
import {IProtocolController} from "src/interfaces/IProtocolController.sol";
/// @title Accountant - Reward Distribution and Accounting System
/// @notice Central accounting system that tracks user balances and distributes rewards across all vaults
/// @dev Uses integral-based accounting for gas-efficient reward distribution:
/// - Rewards are tracked as integrals (cumulative reward per token)
/// - User rewards = (current integral - last user integral) * user balance
/// Two reward distribution policies:
/// - HARVEST: Claims rewards from gauge on every user action (higher gas, immediate rewards)
/// - CHECKPOINT: Accumulates rewards in gauge until manual harvest, but users can claim
/// from the shared reward pool if tokens are available (cross-vault liquidity)
contract Accountant is ReentrancyGuardTransient, Ownable2Step, IAccountant {
using Math for uint256;
using Math for uint128;
using SafeCast for uint256;
using SafeERC20 for IERC20;
//////////////////////////////////////////////////////
// --- STORAGE STRUCTURES
//////////////////////////////////////////////////////
/// @notice Tracks reward and supply data for each vault
/// @dev Packed struct to minimize storage costs (3 storage slots)
struct VaultData {
uint256 integral; // Cumulative reward per token (scaled by SCALING_FACTOR)
uint128 supply; // Total supply of vault tokens
uint128 feeSubjectAmount; // Amount of rewards subject to fees
uint128 totalAmount; // Total reward amount including fee-exempt rewards
uint128 netCredited; // Net rewards already credited to users (after fees)
uint128 reservedHarvestFee; // Harvest fees reserved but not yet paid out
uint128 reservedProtocolFee; // Protocol fees reserved but not yet accrued
}
/// @notice Tracks individual user positions within a vault
/// @dev Integral tracking enables O(1) reward calculations
struct AccountData {
uint128 balance; // User's token balance in the vault
uint256 integral; // Last integral value when user's rewards were updated
uint256 pendingRewards; // Rewards earned but not yet claimed
}
/// @notice Struct that defines the fees parameters.
struct FeesParams {
uint128 protocolFeePercent;
uint128 harvestFeePercent;
}
//////////////////////////////////////////////////////
// --- CONSTANTS & IMMUTABLES
//////////////////////////////////////////////////////
/// @notice Precision multiplier for integral calculations (1e27 for maximum precision)
/// @dev Higher precision prevents rounding errors in reward distribution
uint128 public constant SCALING_FACTOR = 1e27;
/// @notice Maximum combined fee percentage to protect users (40%)
uint128 public constant MAX_FEE_PERCENT = 0.4e18;
/// @notice Minimum rewards threshold to update integrals in CHECKPOINT mode
/// @dev Prevents precision loss from tiny reward amounts
uint128 public constant MIN_MEANINGFUL_REWARDS = 1e18;
/// @notice Central registry for protocol components
IProtocolController public immutable PROTOCOL_CONTROLLER;
/// @notice The reward token distributed by this accountant (e.g., CRV)
address public immutable REWARD_TOKEN;
/// @notice Protocol identifier this accountant manages
bytes4 public immutable PROTOCOL_ID;
/// @notice Default protocol fee charged on rewards (15%)
uint128 internal constant DEFAULT_PROTOCOL_FEE = 0.15e18;
/// @notice Default harvest fee paid to harvesters (0.1%)
/// @dev Expressed as 0.001 in decimal form (0.001 * 100% = 0.1%)
/// @dev Compensates for gas costs when calling harvest() function
uint128 internal constant DEFAULT_HARVEST_FEE = 0.001e18;
//////////////////////////////////////////////////////
// --- STATE VARIABLES
//////////////////////////////////////////////////////
/// @notice The feesParams struct.
FeesParams public feesParams;
/// @notice The total protocol fees collected but not yet claimed.
uint256 public protocolFeesAccrued;
/// @notice Supply of vaults.
/// @dev Vault address -> VaultData.
mapping(address vault => VaultData vaultData) public vaults;
/// @notice Balances of accounts per vault.
/// @dev Vault address -> Account address -> AccountData.
mapping(address vault => mapping(address account => AccountData accountData)) public accounts;
//////////////////////////////////////////////////////
// --- ERRORS
//////////////////////////////////////////////////////
/// @notice Error thrown when the caller is not a vault.
error OnlyVault();
/// @notice Error thrown when the caller is not allowed.
error OnlyAllowed();
/// @notice Error thrown when the strategy is not set.
error NoStrategy();
/// @notice Error thrown when the fee receiver is not set.
error NoFeeReceiver();
/// @notice Error thrown when there are no pending rewards.
error NoPendingRewards();
/// @notice Error thrown when the pending rewards are not enough.
error InsufficientPendingRewards();
/// @notice Error thrown when the net credits are not enough.
error NetCreditsNotEnough();
/// @notice Error thrown when the fees exceed the rewards.
error FeesExceedRewards();
/// @notice Error thrown when a fee exceeds the maximum allowed
error FeeExceedsMaximum();
/// @notice Error thrown when the vault is invalid
error InvalidVault();
/// @notice Error thrown when harvest data length doesn't match vaults length
error InvalidHarvestDataLength();
/// @notice Error thrown when the protocol controller is invalid
error InvalidProtocolController();
/// @notice Error thrown when the reward token is invalid
error InvalidRewardToken();
/// @notice Error thrown when the protocol ID is invalid
error InvalidProtocolId();
/// @notice Error thrown when the harvester has not transferred the correct amount of tokens to the Accountant contract
error HarvestTokenNotReceived();
//////////////////////////////////////////////////////
// --- EVENTS
//////////////////////////////////////////////////////
/// @notice Emitted when protocol fees are claimed.
event ProtocolFeesClaimed(uint256 amount);
/// @notice Emitted when a vault harvests rewards.
event Harvest(
address indexed vault,
uint256 integral,
uint256 supply,
uint256 amount,
uint256 protocolFee,
uint256 harvesterFee
);
/// @notice Emitted when a checkpoint is made.
event Checkpoint(
address indexed vault,
address indexed from,
address indexed to,
uint128 amount,
uint256 integral,
uint256 supply,
IStrategy.HarvestPolicy policy
);
/// @notice Emitted when an account checkpoint is made.
event AccountCheckpoint(
address indexed vault, address indexed account, uint128 balance, uint256 integral, uint256 pendingRewards
);
/// @notice Emitted when a user claims rewards.
event RewardsClaimed(address indexed vault, address indexed account, address receiver, uint256 amount);
/// @notice Emitted when the protocol fee percent is updated.
event ProtocolFeePercentSet(uint128 oldProtocolFeePercent, uint128 newProtocolFeePercent);
/// @notice Emitted when the harvest fee percent is updated.
event HarvestFeePercentSet(uint128 oldHarvestFeePercent, uint128 newHarvestFeePercent);
/// @notice Emitted when a deposit is made via a referrer
/// @param referrer The address of the referrer
/// @param referree The address of the referree (the address that receives the shares)
/// @param assets The amount of assets deposited (1:1 with shares)
event Referrer(address indexed referrer, address referree, uint128 assets);
//////////////////////////////////////////////////////
// --- MODIFIERS
//////////////////////////////////////////////////////
/// @notice Restricts access to addresses with specific function permissions
/// @dev Used for harvest() and other privileged operations
modifier onlyAllowed() {
require(PROTOCOL_CONTROLLER.allowed(address(this), msg.sender, msg.sig), OnlyAllowed());
_;
}
//////////////////////////////////////////////////////
// --- CONSTRUCTOR
//////////////////////////////////////////////////////
/// @notice Initializes the Accountant contract with owner, registry, and reward token.
/// @param _owner The address of the contract owner.
/// @param _registry The address of the registry contract.
/// @param _rewardToken The address of the reward token.
/// @param _protocolId The bytes4 ID of the protocol
/// @custom:throws OwnableInvalidOwner If the owner is the zero address.
/// @custom:throws InvalidProtocolController If the protocol controller is the zero address.
/// @custom:throws InvalidRewardToken If the reward token is the zero address.
constructor(address _owner, address _registry, address _rewardToken, bytes4 _protocolId) Ownable(_owner) {
require(_registry != address(0), InvalidProtocolController());
require(_rewardToken != address(0), InvalidRewardToken());
require(_protocolId != bytes4(0), InvalidProtocolId());
/// set the immutable variables
PROTOCOL_CONTROLLER = IProtocolController(_registry);
REWARD_TOKEN = _rewardToken;
PROTOCOL_ID = _protocolId;
/// set the initial fees to the default values, and emit the update events
feesParams = FeesParams({protocolFeePercent: DEFAULT_PROTOCOL_FEE, harvestFeePercent: DEFAULT_HARVEST_FEE});
emit HarvestFeePercentSet(0, DEFAULT_HARVEST_FEE);
emit ProtocolFeePercentSet(0, DEFAULT_PROTOCOL_FEE);
}
//////////////////////////////////////////////////////
// --- CHECKPOINT OPERATIONS
//////////////////////////////////////////////////////
/// @notice Updates user balances and distributes rewards on every vault action
/// @dev Core accounting function called by vaults during transfers, mints, and burns
///
/// Token Operations:
/// - Mint (from = 0): Increases supply, updates receiver's reward integral
/// - Burn (to = 0): Decreases supply, updates sender's reward integral
/// - Transfer: Updates both sender and receiver integrals
///
/// Reward Distribution Policies:
/// - HARVEST: Claims rewards on every action, only protocol fee charged
/// - CHECKPOINT: Accumulates rewards until harvest(), both fees charged
/// In CHECKPOINT, fees are reserved (not immediately accrued) to ensure
/// the harvester receives proper compensation when they eventually harvest
/// @param gauge The underlying gauge address of the vault.
/// @param from The source address (address(0) for minting).
/// @param to The destination address (address(0) for burning).
/// @param amount The amount of tokens being transferred/minted/burned.
/// @param pendingRewards New rewards to be distributed to the vault.
/// @param policy The harvest policy to use.
/// @custom:throws OnlyVault If caller is not the registered vault for the gauge.
function checkpoint(
address gauge,
address from,
address to,
uint128 amount,
IStrategy.PendingRewards calldata pendingRewards,
IStrategy.HarvestPolicy policy
) public nonReentrant {
require(PROTOCOL_CONTROLLER.vaults(gauge) == msg.sender, OnlyVault());
VaultData storage _vault = vaults[msg.sender];
uint128 supply = _vault.supply;
uint256 integral = _vault.integral;
// Process any pending rewards if they exist and there is supply
if (pendingRewards.totalAmount > 0 && supply > 0) {
// Calculate the new rewards to be added to the vault.
uint128 newRewards = pendingRewards.totalAmount - _vault.totalAmount;
uint128 newFeeSubjectAmount = pendingRewards.feeSubjectAmount - _vault.feeSubjectAmount;
/// @dev Guard against fees exceeding the rewards.
require(pendingRewards.feeSubjectAmount <= pendingRewards.totalAmount, FeesExceedRewards());
uint128 totalFees;
if (policy == IStrategy.HarvestPolicy.HARVEST && newRewards > 0) {
// Calculate total fees in one operation
// We charge only protocol fee on the harvested rewards.
// @dev This prevents over-extraction by ensuring fees are calculated only on new rewards
if (newFeeSubjectAmount > 0) {
totalFees = newFeeSubjectAmount.mulDiv(getProtocolFeePercent(), 1e18).toUint128();
// Update protocol fees accrued.
protocolFeesAccrued += totalFees;
}
// Update integral with new rewards per token
integral += (newRewards - totalFees).mulDiv(SCALING_FACTOR, supply);
}
// If the new rewards are above the minimum meaningful rewards,
// we update the integral and pending rewards.
// Otherwise, we don't update the integral to avoid precision loss. It won't be lost, just delayed.
else if (policy == IStrategy.HarvestPolicy.CHECKPOINT && newRewards >= MIN_MEANINGFUL_REWARDS) {
// Calculate total fees in one operation
// We charge protocol and harvest fees on the unclaimed rewards.
if (newFeeSubjectAmount > 0) {
totalFees = newFeeSubjectAmount.mulDiv(getProtocolFeePercent(), 1e18).toUint128();
_vault.reservedProtocolFee += totalFees;
}
// Get harvest fee for the unclaimed rewards.
uint128 harvestFee = newRewards.mulDiv(getHarvestFeePercent(), 1e18).toUint128();
// The net rewards we are *actually crediting* now
uint128 netIncrement = newRewards - totalFees - harvestFee;
// Update integral with new rewards per token
integral += netIncrement.mulDiv(SCALING_FACTOR, supply);
// Record how many total net rewards we've credited so far
_vault.netCredited += netIncrement;
// Record the harvest fee for the unclaimed rewards
_vault.reservedHarvestFee += harvestFee;
// Update the total amount and the fee subject amount of the Vault
_vault.totalAmount = pendingRewards.totalAmount;
// Update the fee subject amount of the Vault
_vault.feeSubjectAmount = pendingRewards.feeSubjectAmount;
}
}
// Handle token operations
if (from == address(0)) {
// Minting operation
supply += amount;
} else {
// Update sender's balance and rewards
_updateAccountState({
vault: msg.sender,
account: from,
amount: amount,
currentIntegral: integral,
isDecrease: true
});
}
if (to == address(0)) {
// Burning operation
supply -= amount;
} else {
// Update receiver's balance and rewards
_updateAccountState({
vault: msg.sender,
account: to,
amount: amount,
currentIntegral: integral,
isDecrease: false
});
}
// Update vault data with new supply and integral
_vault.integral = integral;
_vault.supply = supply;
emit Checkpoint(msg.sender, from, to, amount, integral, supply, policy);
}
/// @notice Checkpoints the state of the vault on every account action.
/// @dev This function is a wrapper of `checkpoint` that emits the `Referrer` event.
/// @param gauge The underlying gauge address of the vault.
/// @param from The source address (address(0) for minting).
/// @param to The destination address (address(0) for burning).
/// @param amount The amount of tokens being transferred/minted/burned.
/// @param pendingRewards New rewards to be distributed to the vault.
/// @param policy The harvest policy to use.
/// @param referrer The address of the referrer.
/// @custom:throws OnlyVault If caller is not the registered vault for the gauge.
function checkpoint(
address gauge,
address from,
address to,
uint128 amount,
IStrategy.PendingRewards calldata pendingRewards,
IStrategy.HarvestPolicy policy,
address referrer
) external {
// call the checkpoint function as normal (the function check if the caller is the authorized vault)
checkpoint(gauge, from, to, amount, pendingRewards, policy);
// emit the referrer deposit event if the referrer is set
if (referrer != address(0)) emit Referrer(referrer, to, amount);
}
/// @dev Updates account state during operations.
/// @param vault The vault address.
/// @param account The account to update.
/// @param amount The amount to add/subtract.
/// @param isDecrease Whether to decrease (true) or increase (false) the balance.
/// @param currentIntegral The current reward integral to checkpoint against.
function _updateAccountState(
address vault,
address account,
uint128 amount,
bool isDecrease,
uint256 currentIntegral
) private {
AccountData storage accountData = accounts[vault][account];
// cache the balance in the stack for gas optimization
uint128 accountBalance = accountData.balance;
// Update pending rewards based on the integral difference.
accountData.pendingRewards +=
(currentIntegral - accountData.integral).mulDiv(uint256(accountBalance), SCALING_FACTOR);
accountData.balance = isDecrease ? accountBalance - amount : accountBalance + amount;
accountData.integral = currentIntegral;
// Emit the account checkpoint event
emit AccountCheckpoint(vault, account, accountData.balance, currentIntegral, accountData.pendingRewards);
}
/// @notice Returns the total supply of tokens in a vault.
/// @param vault The vault address to query.
/// @return _ The total supply of tokens in the vault.
function totalSupply(address vault) external view returns (uint128) {
return vaults[vault].supply;
}
/// @notice Returns the token balance of an account in a vault.
/// @param vault The vault address to query.
/// @param account The account address to check.
/// @return _ The account's token balance in the vault.
function balanceOf(address vault, address account) external view returns (uint128) {
return accounts[vault][account].balance;
}
/// @notice Returns the pending rewards for a vault.
/// @param vault The vault address to query.
/// @return The pending rewards for the vault.
function getPendingRewards(address vault) external view returns (uint128) {
return vaults[vault].totalAmount;
}
/// @notice Returns the pending rewards for an account in a vault.
/// @param vault The vault address to query.
/// @param account The account address to check.
/// @return _ The pending rewards for the account in the vault.
function getPendingRewards(address vault, address account) external view returns (uint256) {
return accounts[vault][account].pendingRewards;
}
//////////////////////////////////////////////////////
// --- HARVEST OPERATIONS
//////////////////////////////////////////////////////
/// @notice Harvests rewards from multiple gauges and distributes them to vaults
/// @dev Called by harvesters to claim rewards from external protocols and update integrals
/// @param _gauges Array of gauges to harvest from
/// @param _harvestData Protocol-specific data for harvesting each gauge
/// @param _receiver Address that will receive the harvest fee as compensation
/// @custom:throws InvalidHarvestDataLength If array lengths don't match
function harvest(address[] calldata _gauges, bytes[] calldata _harvestData, address _receiver) external {
require(_gauges.length == _harvestData.length, InvalidHarvestDataLength());
_harvest(_gauges, _harvestData, _receiver);
}
/// @dev Batch harvests rewards and updates vault integrals
/// @dev Gas optimizations:
/// 1. Single strategy.flush() call at the end for all rewards
/// 2. One token transfer for all harvested rewards
/// 3. Defers rewards using transient storage during harvest
function _harvest(address[] memory _gauges, bytes[] memory harvestData, address receiver) internal nonReentrant {
// Cache strategy to avoid multiple SLOADs
address strategy = PROTOCOL_CONTROLLER.strategy(PROTOCOL_ID);
require(strategy != address(0), NoStrategy());
// Fetch the balance of the Accountant contract before harvesting.
uint256 balanceBefore = IERC20(REWARD_TOKEN).balanceOf(address(this));
uint256 totalHarvesterFee;
uint256 totalRewardsAmount;
// First pass: harvest all gauges and update vault states
for (uint256 i; i < _gauges.length; i++) {
address gauge = _gauges[i];
address vault = PROTOCOL_CONTROLLER.vaults(gauge);
require(vault != address(0), InvalidVault());
VaultData storage _vault = vaults[vault];
// 1. Pull rewards from the strategy
IStrategy.PendingRewards memory pendingRewards = IStrategy(strategy).harvest(gauge, harvestData[i]);
// 2. Under‑delivery guard (totals must cover soft credits)
// @dev Critical security check: ensures strategy cannot under-report rewards
// @dev Prevents loss of user funds by validating reward amounts match expectations
require(
pendingRewards.totalAmount >= _vault.totalAmount
&& pendingRewards.feeSubjectAmount >= _vault.feeSubjectAmount,
InsufficientPendingRewards()
);
/// @dev Guard against fees exceeding the rewards.
require(pendingRewards.feeSubjectAmount <= pendingRewards.totalAmount, FeesExceedRewards());
// Skip if strategy reports zero
if (pendingRewards.totalAmount == 0) continue;
// 3. Aggregate global rewards
totalRewardsAmount += pendingRewards.totalAmount;
// 4. Start accounting
uint256 protocolFee = _vault.reservedProtocolFee;
uint256 harvesterFee = _vault.reservedHarvestFee;
uint256 netCredited = _vault.netCredited;
// Strategy must at least make LPs whole
uint256 netAfterReservedFees = pendingRewards.totalAmount - protocolFee - harvesterFee;
require(netAfterReservedFees >= netCredited, NetCreditsNotEnough());
if (netAfterReservedFees > netCredited && _vault.supply > 0) {
uint256 newRewards = netAfterReservedFees - netCredited;
/// Take the fee from the net delta
uint256 newHarvesterFee = newRewards.mulDiv(getHarvestFeePercent(), 1e18);
/// Update the harvester fee
harvesterFee += newHarvesterFee;
if (pendingRewards.feeSubjectAmount > _vault.feeSubjectAmount) {
uint256 newFeeSubjectAmount = pendingRewards.feeSubjectAmount - _vault.feeSubjectAmount;
uint256 newProtocolFee = newFeeSubjectAmount.mulDiv(getProtocolFeePercent(), 1e18);
protocolFee += newProtocolFee;
// Adjust newRewards to account for protocol fee
newRewards -= newProtocolFee;
}
// Add only that delta to the integral
_vault.integral += (newRewards - newHarvesterFee).mulDiv(SCALING_FACTOR, _vault.supply);
}
/// Update the total harvester fee
totalHarvesterFee += harvesterFee;
/// Update the total protocol fee
protocolFeesAccrued += protocolFee;
_vault.netCredited = 0; // fully settled thanks to the guard
_vault.totalAmount = 0;
_vault.feeSubjectAmount = 0;
_vault.reservedHarvestFee = 0;
_vault.reservedProtocolFee = 0;
emit Harvest(vault, _vault.integral, _vault.supply, pendingRewards.totalAmount, protocolFee, harvesterFee);
}
// If no valid harvests, return early
if (totalRewardsAmount == 0) return;
// Flush all accumulated rewards at once
IStrategy(strategy).flush();
// Check that the strategy has transferred the correct amount of reward tokens to this contract
require(
IERC20(REWARD_TOKEN).balanceOf(address(this)) >= balanceBefore + totalRewardsAmount,
HarvestTokenNotReceived()
);
// Transfer total harvester fee if any
if (totalHarvesterFee > 0) {
IERC20(REWARD_TOKEN).safeTransfer(receiver, totalHarvesterFee);
}
}
/// @notice Returns the current harvest fee percentage.
/// @return _ The harvest fee percentage.
function getHarvestFeePercent() public view returns (uint128) {
return feesParams.harvestFeePercent;
}
/// @notice Updates the harvest fee percentage.
/// @param newHarvestFeePercent New harvest fee percentage (scaled by 1e18).
/// @custom:throws FeeExceedsMaximum If fee would exceed maximum.
function setHarvestFeePercent(uint128 newHarvestFeePercent) external onlyOwner {
FeesParams storage currentFees = feesParams;
// check that the new total fee (protocol + harvest) is valid
uint256 totalFee = uint256(currentFees.protocolFeePercent) + uint256(newHarvestFeePercent);
require(totalFee <= MAX_FEE_PERCENT, FeeExceedsMaximum());
// emit the harvest event before updating the storage pointer
emit HarvestFeePercentSet(currentFees.harvestFeePercent, newHarvestFeePercent);
// set the new protocol fee percent
feesParams.harvestFeePercent = newHarvestFeePercent;
}
//////////////////////////////////////////////////////
// --- CLAIM OPERATIONS
//////////////////////////////////////////////////////
/// @notice Claims rewards from multiple vaults for the caller
/// @dev In CHECKPOINT mode, can claim if rewards are available in the contract
/// @param _gauges Array of gauges to claim rewards from
/// @param harvestData Optional: triggers harvest before claim if provided
/// @custom:throws NoPendingRewards If there are no rewards to claim
function claim(address[] calldata _gauges, bytes[] calldata harvestData) external {
claim(_gauges, harvestData, msg.sender);
}
/// @notice Claims rewards and sends to a specific receiver
/// @dev Optionally harvests first if harvestData is provided
/// @param _gauges Array of gauges to claim rewards from
/// @param harvestData Optional harvest data (empty array to skip harvest)
/// @param receiver Address that will receive the claimed rewards
/// @custom:throws NoPendingRewards If there are no rewards to claim
function claim(address[] calldata _gauges, bytes[] calldata harvestData, address receiver) public {
require(harvestData.length == 0 || harvestData.length == _gauges.length, InvalidHarvestDataLength());
if (harvestData.length != 0) {
_harvest(_gauges, harvestData, receiver);
}
_claim({_gauges: _gauges, account: msg.sender, receiver: receiver});
}
/// @notice Claims multiple vault rewards on behalf of an account.
/// @param _gauges Array of gauges to claim rewards from.
/// @param account Address to claim rewards for.
/// @param harvestData Optional harvest data for each gauge. Empty bytes for gauges that don't need harvesting.
/// @dev expected to be called by authorized accounts only
/// @custom:throws OnlyAllowed If caller is not allowed to claim on behalf of others.
/// @custom:throws NoPendingRewards If there are no rewards to claim.
function claim(address[] calldata _gauges, address account, bytes[] calldata harvestData) external {
claim(_gauges, account, harvestData, account);
}
/// @notice Claims multiple vault rewards on behalf of an account and sends them to a specific address.
/// @param _gauges Array of gauges to claim rewards from.
/// @param account Address to claim rewards for.
/// @param harvestData Optional harvest data for each gauge. Empty bytes for gauges that don't need harvesting.
/// @param receiver Address that will receive the claimed rewards.
/// @dev expected to be called by authorized accounts only
/// @custom:throws OnlyAllowed If caller is not allowed to claim on behalf of others.
/// @custom:throws NoPendingRewards If there are no rewards to claim.
function claim(address[] calldata _gauges, address account, bytes[] calldata harvestData, address receiver)
public
onlyAllowed
{
require(harvestData.length == 0 || harvestData.length == _gauges.length, InvalidHarvestDataLength());
if (harvestData.length != 0) {
_harvest(_gauges, harvestData, receiver);
}
_claim({_gauges: _gauges, account: account, receiver: receiver});
}
/// @dev Internal implementation of claim functionality.
/// @param _gauges Array of gauges to claim rewards from.
/// @param account Address to claim rewards for.
/// @param receiver Address that will receive the claimed rewards.
/// @custom:throws NoPendingRewards If the total claimed amount is zero.
function _claim(address[] calldata _gauges, address account, address receiver) internal nonReentrant {
uint256 totalAmount;
address vault;
// For each gauge, check if the account has any rewards to claim
for (uint256 i; i < _gauges.length; i++) {
vault = PROTOCOL_CONTROLLER.vaults(_gauges[i]);
require(vault != address(0), InvalidVault());
// Get the account data for this gauge
AccountData storage accountData = accounts[vault][account];
// Get the current balance for this vault
uint128 balance = accountData.balance;
// If account has any rewards to claim for this vault, calculate the amount. Otherwise, skip.
if (balance != 0 || accountData.pendingRewards != 0) {
// Get vault's and account's integral
uint256 accountIntegral = accountData.integral;
uint256 vaultIntegral = vaults[vault].integral;
// If vault's integral is higher than account's integral, calculate the rewards and update the total.
uint256 claimableAmount = accountData.pendingRewards;
if (vaultIntegral > accountIntegral) {
claimableAmount += (vaultIntegral - accountIntegral).mulDiv(balance, SCALING_FACTOR);
}
// In any case, add the pending rewards to the total amount
totalAmount += claimableAmount;
// Update account's integral with the current value of Vault's integral
accountData.integral = vaultIntegral;
// reset the stored pending rewards for this vault
accountData.pendingRewards = 0;
// Emit the account checkpoint event
emit AccountCheckpoint(vault, account, balance, vaultIntegral, 0);
// Emit the claim event
emit RewardsClaimed(vault, account, receiver, claimableAmount);
}
}
// If there is no amount to claim for any vault, revert.
require(totalAmount != 0, NoPendingRewards());
// Transfer accumulated rewards to the receiver
IERC20(REWARD_TOKEN).safeTransfer(receiver, totalAmount);
}
//////////////////////////////////////////////////////
// --- FEE MANAGEMENT
//////////////////////////////////////////////////////
/// @notice Returns the current protocol fee percentage.
/// @return _ The protocol fee percentage.
function getProtocolFeePercent() public view returns (uint128) {
return feesParams.protocolFeePercent;
}
/// @notice Updates the protocol fee percentage.
/// @param newProtocolFeePercent New protocol fee percentage (scaled by 1e18).
/// @custom:throws FeeExceedsMaximum If fee would exceed maximum.
function setProtocolFeePercent(uint128 newProtocolFeePercent) external onlyOwner {
FeesParams storage currentFees = feesParams;
// check that the total fee (protocol + harvest) is valid
uint128 totalFee = newProtocolFeePercent + currentFees.harvestFeePercent;
require(totalFee <= MAX_FEE_PERCENT, FeeExceedsMaximum());
// emit the update event
emit ProtocolFeePercentSet(currentFees.protocolFeePercent, newProtocolFeePercent);
// set the new protocol fee percent
currentFees.protocolFeePercent = newProtocolFeePercent;
}
/// @notice Claims accumulated protocol fees.
/// @dev Transfers fees to the configured fee receiver.
/// @custom:throws NoFeeReceiver If the fee receiver is not set.
function claimProtocolFees() external nonReentrant {
// get the fee receiver from the protocol controller and check that it is valid
address feeReceiver = PROTOCOL_CONTROLLER.feeReceiver(PROTOCOL_ID);
require(feeReceiver != address(0), NoFeeReceiver());
// get the protocol fees accrued until now and reset the stored value
uint256 currentAccruedProtocolFees = protocolFeesAccrued;
protocolFeesAccrued = 0;
// transfer the accrued protocol fees to the fee receiver and emit the claim event
IERC20(REWARD_TOKEN).safeTransfer(feeReceiver, currentAccruedProtocolFees);
emit ProtocolFeesClaimed(currentAccruedProtocolFees);
}
/// @notice Returns the total fee percentage (protocol + harvest).
/// @return _ The total fee percentage.
function getTotalFeePercent() external view returns (uint128) {
return feesParams.protocolFeePercent + feesParams.harvestFeePercent;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/Math.sol)
pragma solidity ^0.8.20;
import {Panic} from "../Panic.sol";
import {SafeCast} from "./SafeCast.sol";
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Floor, // Toward negative infinity
Ceil, // Toward positive infinity
Trunc, // Toward zero
Expand // Away from zero
}
/**
* @dev Returns the addition of two unsigned integers, with an success flag (no overflow).
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with an success flag (no overflow).
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an success flag (no overflow).
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a success flag (no division by zero).
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a success flag (no division by zero).
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.
*
* IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.
* However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute
* one branch when needed, making this function more expensive.
*/
function ternary(bool condition, uint256 a, uint256 b) internal pure returns (uint256) {
unchecked {
// branchless ternary works because:
// b ^ (a ^ b) == a
// b ^ 0 == b
return b ^ ((a ^ b) * SafeCast.toUint(condition));
}
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return ternary(a > b, a, b);
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return ternary(a < b, a, b);
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds towards infinity instead
* of rounding towards zero.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
if (b == 0) {
// Guarantee the same behavior as in a regular Solidity division.
Panic.panic(Panic.DIVISION_BY_ZERO);
}
// The following calculation ensures accurate ceiling division without overflow.
// Since a is non-zero, (a - 1) / b will not overflow.
// The largest possible result occurs when (a - 1) / b is type(uint256).max,
// but the largest value we can obtain is type(uint256).max - 1, which happens
// when a = type(uint256).max and b = 1.
unchecked {
return SafeCast.toUint(a > 0) * ((a - 1) / b + 1);
}
}
/**
* @dev Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
* denominator == 0.
*
* Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
* Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2²⁵⁶ and mod 2²⁵⁶ - 1, then use
// the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2²⁵⁶ + prod0.
uint256 prod0 = x * y; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2²⁵⁶. Also prevents denominator == 0.
if (denominator <= prod1) {
Panic.panic(ternary(denominator == 0, Panic.DIVISION_BY_ZERO, Panic.UNDER_OVERFLOW));
}
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator.
// Always >= 1. See https://cs.stackexchange.com/q/138556/92363.
uint256 twos = denominator & (0 - denominator);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2²⁵⁶ / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2²⁵⁶. Now that denominator is an odd number, it has an inverse modulo 2²⁵⁶ such
// that denominator * inv ≡ 1 mod 2²⁵⁶. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv ≡ 1 mod 2⁴.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also
// works in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2⁸
inverse *= 2 - denominator * inverse; // inverse mod 2¹⁶
inverse *= 2 - denominator * inverse; // inverse mod 2³²
inverse *= 2 - denominator * inverse; // inverse mod 2⁶⁴
inverse *= 2 - denominator * inverse; // inverse mod 2¹²⁸
inverse *= 2 - denominator * inverse; // inverse mod 2²⁵⁶
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2²⁵⁶. Since the preconditions guarantee that the outcome is
// less than 2²⁵⁶, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @dev Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
return mulDiv(x, y, denominator) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0);
}
/**
* @dev Calculate the modular multiplicative inverse of a number in Z/nZ.
*
* If n is a prime, then Z/nZ is a field. In that case all elements are inversible, except 0.
* If n is not a prime, then Z/nZ is not a field, and some elements might not be inversible.
*
* If the input value is not inversible, 0 is returned.
*
* NOTE: If you know for sure that n is (big) a prime, it may be cheaper to use Fermat's little theorem and get the
* inverse using `Math.modExp(a, n - 2, n)`. See {invModPrime}.
*/
function invMod(uint256 a, uint256 n) internal pure returns (uint256) {
unchecked {
if (n == 0) return 0;
// The inverse modulo is calculated using the Extended Euclidean Algorithm (iterative version)
// Used to compute integers x and y such that: ax + ny = gcd(a, n).
// When the gcd is 1, then the inverse of a modulo n exists and it's x.
// ax + ny = 1
// ax = 1 + (-y)n
// ax ≡ 1 (mod n) # x is the inverse of a modulo n
// If the remainder is 0 the gcd is n right away.
uint256 remainder = a % n;
uint256 gcd = n;
// Therefore the initial coefficients are:
// ax + ny = gcd(a, n) = n
// 0a + 1n = n
int256 x = 0;
int256 y = 1;
while (remainder != 0) {
uint256 quotient = gcd / remainder;
(gcd, remainder) = (
// The old remainder is the next gcd to try.
remainder,
// Compute the next remainder.
// Can't overflow given that (a % gcd) * (gcd // (a % gcd)) <= gcd
// where gcd is at most n (capped to type(uint256).max)
gcd - remainder * quotient
);
(x, y) = (
// Increment the coefficient of a.
y,
// Decrement the coefficient of n.
// Can overflow, but the result is casted to uint256 so that the
// next value of y is "wrapped around" to a value between 0 and n - 1.
x - y * int256(quotient)
);
}
if (gcd != 1) return 0; // No inverse exists.
return ternary(x < 0, n - uint256(-x), uint256(x)); // Wrap the result if it's negative.
}
}
/**
* @dev Variant of {invMod}. More efficient, but only works if `p` is known to be a prime greater than `2`.
*
* From https://en.wikipedia.org/wiki/Fermat%27s_little_theorem[Fermat's little theorem], we know that if p is
* prime, then `a**(p-1) ≡ 1 mod p`. As a consequence, we have `a * a**(p-2) ≡ 1 mod p`, which means that
* `a**(p-2)` is the modular multiplicative inverse of a in Fp.
*
* NOTE: this function does NOT check that `p` is a prime greater than `2`.
*/
function invModPrime(uint256 a, uint256 p) internal view returns (uint256) {
unchecked {
return Math.modExp(a, p - 2, p);
}
}
/**
* @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m)
*
* Requirements:
* - modulus can't be zero
* - underlying staticcall to precompile must succeed
*
* IMPORTANT: The result is only valid if the underlying call succeeds. When using this function, make
* sure the chain you're using it on supports the precompiled contract for modular exponentiation
* at address 0x05 as specified in https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise,
* the underlying function will succeed given the lack of a revert, but the result may be incorrectly
* interpreted as 0.
*/
function modExp(uint256 b, uint256 e, uint256 m) internal view returns (uint256) {
(bool success, uint256 result) = tryModExp(b, e, m);
if (!success) {
Panic.panic(Panic.DIVISION_BY_ZERO);
}
return result;
}
/**
* @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m).
* It includes a success flag indicating if the operation succeeded. Operation will be marked as failed if trying
* to operate modulo 0 or if the underlying precompile reverted.
*
* IMPORTANT: The result is only valid if the success flag is true. When using this function, make sure the chain
* you're using it on supports the precompiled contract for modular exponentiation at address 0x05 as specified in
* https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise, the underlying function will succeed given the lack
* of a revert, but the result may be incorrectly interpreted as 0.
*/
function tryModExp(uint256 b, uint256 e, uint256 m) internal view returns (bool success, uint256 result) {
if (m == 0) return (false, 0);
assembly ("memory-safe") {
let ptr := mload(0x40)
// | Offset | Content | Content (Hex) |
// |-----------|------------|--------------------------------------------------------------------|
// | 0x00:0x1f | size of b | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x20:0x3f | size of e | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x40:0x5f | size of m | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x60:0x7f | value of b | 0x<.............................................................b> |
// | 0x80:0x9f | value of e | 0x<.............................................................e> |
// | 0xa0:0xbf | value of m | 0x<.............................................................m> |
mstore(ptr, 0x20)
mstore(add(ptr, 0x20), 0x20)
mstore(add(ptr, 0x40), 0x20)
mstore(add(ptr, 0x60), b)
mstore(add(ptr, 0x80), e)
mstore(add(ptr, 0xa0), m)
// Given the result < m, it's guaranteed to fit in 32 bytes,
// so we can use the memory scratch space located at offset 0.
success := staticcall(gas(), 0x05, ptr, 0xc0, 0x00, 0x20)
result := mload(0x00)
}
}
/**
* @dev Variant of {modExp} that supports inputs of arbitrary length.
*/
function modExp(bytes memory b, bytes memory e, bytes memory m) internal view returns (bytes memory) {
(bool success, bytes memory result) = tryModExp(b, e, m);
if (!success) {
Panic.panic(Panic.DIVISION_BY_ZERO);
}
return result;
}
/**
* @dev Variant of {tryModExp} that supports inputs of arbitrary length.
*/
function tryModExp(
bytes memory b,
bytes memory e,
bytes memory m
) internal view returns (bool success, bytes memory result) {
if (_zeroBytes(m)) return (false, new bytes(0));
uint256 mLen = m.length;
// Encode call args in result and move the free memory pointer
result = abi.encodePacked(b.length, e.length, mLen, b, e, m);
assembly ("memory-safe") {
let dataPtr := add(result, 0x20)
// Write result on top of args to avoid allocating extra memory.
success := staticcall(gas(), 0x05, dataPtr, mload(result), dataPtr, mLen)
// Overwrite the length.
// result.length > returndatasize() is guaranteed because returndatasize() == m.length
mstore(result, mLen)
// Set the memory pointer after the returned data.
mstore(0x40, add(dataPtr, mLen))
}
}
/**
* @dev Returns whether the provided byte array is zero.
*/
function _zeroBytes(bytes memory byteArray) private pure returns (bool) {
for (uint256 i = 0; i < byteArray.length; ++i) {
if (byteArray[i] != 0) {
return false;
}
}
return true;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
* towards zero.
*
* This method is based on Newton's method for computing square roots; the algorithm is restricted to only
* using integer operations.
*/
function sqrt(uint256 a) internal pure returns (uint256) {
unchecked {
// Take care of easy edge cases when a == 0 or a == 1
if (a <= 1) {
return a;
}
// In this function, we use Newton's method to get a root of `f(x) := x² - a`. It involves building a
// sequence x_n that converges toward sqrt(a). For each iteration x_n, we also define the error between
// the current value as `ε_n = | x_n - sqrt(a) |`.
//
// For our first estimation, we consider `e` the smallest power of 2 which is bigger than the square root
// of the target. (i.e. `2**(e-1) ≤ sqrt(a) < 2**e`). We know that `e ≤ 128` because `(2¹²⁸)² = 2²⁵⁶` is
// bigger than any uint256.
//
// By noticing that
// `2**(e-1) ≤ sqrt(a) < 2**e → (2**(e-1))² ≤ a < (2**e)² → 2**(2*e-2) ≤ a < 2**(2*e)`
// we can deduce that `e - 1` is `log2(a) / 2`. We can thus compute `x_n = 2**(e-1)` using a method similar
// to the msb function.
uint256 aa = a;
uint256 xn = 1;
if (aa >= (1 << 128)) {
aa >>= 128;
xn <<= 64;
}
if (aa >= (1 << 64)) {
aa >>= 64;
xn <<= 32;
}
if (aa >= (1 << 32)) {
aa >>= 32;
xn <<= 16;
}
if (aa >= (1 << 16)) {
aa >>= 16;
xn <<= 8;
}
if (aa >= (1 << 8)) {
aa >>= 8;
xn <<= 4;
}
if (aa >= (1 << 4)) {
aa >>= 4;
xn <<= 2;
}
if (aa >= (1 << 2)) {
xn <<= 1;
}
// We now have x_n such that `x_n = 2**(e-1) ≤ sqrt(a) < 2**e = 2 * x_n`. This implies ε_n ≤ 2**(e-1).
//
// We can refine our estimation by noticing that the middle of that interval minimizes the error.
// If we move x_n to equal 2**(e-1) + 2**(e-2), then we reduce the error to ε_n ≤ 2**(e-2).
// This is going to be our x_0 (and ε_0)
xn = (3 * xn) >> 1; // ε_0 := | x_0 - sqrt(a) | ≤ 2**(e-2)
// From here, Newton's method give us:
// x_{n+1} = (x_n + a / x_n) / 2
//
// One should note that:
// x_{n+1}² - a = ((x_n + a / x_n) / 2)² - a
// = ((x_n² + a) / (2 * x_n))² - a
// = (x_n⁴ + 2 * a * x_n² + a²) / (4 * x_n²) - a
// = (x_n⁴ + 2 * a * x_n² + a² - 4 * a * x_n²) / (4 * x_n²)
// = (x_n⁴ - 2 * a * x_n² + a²) / (4 * x_n²)
// = (x_n² - a)² / (2 * x_n)²
// = ((x_n² - a) / (2 * x_n))²
// ≥ 0
// Which proves that for all n ≥ 1, sqrt(a) ≤ x_n
//
// This gives us the proof of quadratic convergence of the sequence:
// ε_{n+1} = | x_{n+1} - sqrt(a) |
// = | (x_n + a / x_n) / 2 - sqrt(a) |
// = | (x_n² + a - 2*x_n*sqrt(a)) / (2 * x_n) |
// = | (x_n - sqrt(a))² / (2 * x_n) |
// = | ε_n² / (2 * x_n) |
// = ε_n² / | (2 * x_n) |
//
// For the first iteration, we have a special case where x_0 is known:
// ε_1 = ε_0² / | (2 * x_0) |
// ≤ (2**(e-2))² / (2 * (2**(e-1) + 2**(e-2)))
// ≤ 2**(2*e-4) / (3 * 2**(e-1))
// ≤ 2**(e-3) / 3
// ≤ 2**(e-3-log2(3))
// ≤ 2**(e-4.5)
//
// For the following iterations, we use the fact that, 2**(e-1) ≤ sqrt(a) ≤ x_n:
// ε_{n+1} = ε_n² / | (2 * x_n) |
// ≤ (2**(e-k))² / (2 * 2**(e-1))
// ≤ 2**(2*e-2*k) / 2**e
// ≤ 2**(e-2*k)
xn = (xn + a / xn) >> 1; // ε_1 := | x_1 - sqrt(a) | ≤ 2**(e-4.5) -- special case, see above
xn = (xn + a / xn) >> 1; // ε_2 := | x_2 - sqrt(a) | ≤ 2**(e-9) -- general case with k = 4.5
xn = (xn + a / xn) >> 1; // ε_3 := | x_3 - sqrt(a) | ≤ 2**(e-18) -- general case with k = 9
xn = (xn + a / xn) >> 1; // ε_4 := | x_4 - sqrt(a) | ≤ 2**(e-36) -- general case with k = 18
xn = (xn + a / xn) >> 1; // ε_5 := | x_5 - sqrt(a) | ≤ 2**(e-72) -- general case with k = 36
xn = (xn + a / xn) >> 1; // ε_6 := | x_6 - sqrt(a) | ≤ 2**(e-144) -- general case with k = 72
// Because e ≤ 128 (as discussed during the first estimation phase), we know have reached a precision
// ε_6 ≤ 2**(e-144) < 1. Given we're operating on integers, then we can ensure that xn is now either
// sqrt(a) or sqrt(a) + 1.
return xn - SafeCast.toUint(xn > a / xn);
}
}
/**
* @dev Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && result * result < a);
}
}
/**
* @dev Return the log in base 2 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
uint256 exp;
unchecked {
exp = 128 * SafeCast.toUint(value > (1 << 128) - 1);
value >>= exp;
result += exp;
exp = 64 * SafeCast.toUint(value > (1 << 64) - 1);
value >>= exp;
result += exp;
exp = 32 * SafeCast.toUint(value > (1 << 32) - 1);
value >>= exp;
result += exp;
exp = 16 * SafeCast.toUint(value > (1 << 16) - 1);
value >>= exp;
result += exp;
exp = 8 * SafeCast.toUint(value > (1 << 8) - 1);
value >>= exp;
result += exp;
exp = 4 * SafeCast.toUint(value > (1 << 4) - 1);
value >>= exp;
result += exp;
exp = 2 * SafeCast.toUint(value > (1 << 2) - 1);
value >>= exp;
result += exp;
result += SafeCast.toUint(value > 1);
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << result < value);
}
}
/**
* @dev Return the log in base 10 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 10 ** result < value);
}
}
/**
* @dev Return the log in base 256 of a positive value rounded towards zero.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
uint256 isGt;
unchecked {
isGt = SafeCast.toUint(value > (1 << 128) - 1);
value >>= isGt * 128;
result += isGt * 16;
isGt = SafeCast.toUint(value > (1 << 64) - 1);
value >>= isGt * 64;
result += isGt * 8;
isGt = SafeCast.toUint(value > (1 << 32) - 1);
value >>= isGt * 32;
result += isGt * 4;
isGt = SafeCast.toUint(value > (1 << 16) - 1);
value >>= isGt * 16;
result += isGt * 2;
result += SafeCast.toUint(value > (1 << 8) - 1);
}
return result;
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << (result << 3) < value);
}
}
/**
* @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
*/
function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
return uint8(rounding) % 2 == 1;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
pragma solidity ^0.8.20;
/**
* @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeCast {
/**
* @dev Value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);
/**
* @dev An int value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedIntToUint(int256 value);
/**
* @dev Value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);
/**
* @dev An uint value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedUintToInt(uint256 value);
/**
* @dev Returns the downcasted uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toUint248(uint256 value) internal pure returns (uint248) {
if (value > type(uint248).max) {
revert SafeCastOverflowedUintDowncast(248, value);
}
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toUint240(uint256 value) internal pure returns (uint240) {
if (value > type(uint240).max) {
revert SafeCastOverflowedUintDowncast(240, value);
}
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toUint232(uint256 value) internal pure returns (uint232) {
if (value > type(uint232).max) {
revert SafeCastOverflowedUintDowncast(232, value);
}
return uint232(value);
}
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
if (value > type(uint224).max) {
revert SafeCastOverflowedUintDowncast(224, value);
}
return uint224(value);
}
/**
* @dev Returns the downcasted uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toUint216(uint256 value) internal pure returns (uint216) {
if (value > type(uint216).max) {
revert SafeCastOverflowedUintDowncast(216, value);
}
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toUint208(uint256 value) internal pure returns (uint208) {
if (value > type(uint208).max) {
revert SafeCastOverflowedUintDowncast(208, value);
}
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toUint200(uint256 value) internal pure returns (uint200) {
if (value > type(uint200).max) {
revert SafeCastOverflowedUintDowncast(200, value);
}
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toUint192(uint256 value) internal pure returns (uint192) {
if (value > type(uint192).max) {
revert SafeCastOverflowedUintDowncast(192, value);
}
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toUint184(uint256 value) internal pure returns (uint184) {
if (value > type(uint184).max) {
revert SafeCastOverflowedUintDowncast(184, value);
}
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toUint176(uint256 value) internal pure returns (uint176) {
if (value > type(uint176).max) {
revert SafeCastOverflowedUintDowncast(176, value);
}
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toUint168(uint256 value) internal pure returns (uint168) {
if (value > type(uint168).max) {
revert SafeCastOverflowedUintDowncast(168, value);
}
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toUint160(uint256 value) internal pure returns (uint160) {
if (value > type(uint160).max) {
revert SafeCastOverflowedUintDowncast(160, value);
}
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toUint152(uint256 value) internal pure returns (uint152) {
if (value > type(uint152).max) {
revert SafeCastOverflowedUintDowncast(152, value);
}
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toUint144(uint256 value) internal pure returns (uint144) {
if (value > type(uint144).max) {
revert SafeCastOverflowedUintDowncast(144, value);
}
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toUint136(uint256 value) internal pure returns (uint136) {
if (value > type(uint136).max) {
revert SafeCastOverflowedUintDowncast(136, value);
}
return uint136(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toUint128(uint256 value) internal pure returns (uint128) {
if (value > type(uint128).max) {
revert SafeCastOverflowedUintDowncast(128, value);
}
return uint128(value);
}
/**
* @dev Returns the downcasted uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toUint120(uint256 value) internal pure returns (uint120) {
if (value > type(uint120).max) {
revert SafeCastOverflowedUintDowncast(120, value);
}
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toUint112(uint256 value) internal pure returns (uint112) {
if (value > type(uint112).max) {
revert SafeCastOverflowedUintDowncast(112, value);
}
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toUint104(uint256 value) internal pure returns (uint104) {
if (value > type(uint104).max) {
revert SafeCastOverflowedUintDowncast(104, value);
}
return uint104(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toUint96(uint256 value) internal pure returns (uint96) {
if (value > type(uint96).max) {
revert SafeCastOverflowedUintDowncast(96, value);
}
return uint96(value);
}
/**
* @dev Returns the downcasted uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toUint88(uint256 value) internal pure returns (uint88) {
if (value > type(uint88).max) {
revert SafeCastOverflowedUintDowncast(88, value);
}
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toUint80(uint256 value) internal pure returns (uint80) {
if (value > type(uint80).max) {
revert SafeCastOverflowedUintDowncast(80, value);
}
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toUint72(uint256 value) internal pure returns (uint72) {
if (value > type(uint72).max) {
revert SafeCastOverflowedUintDowncast(72, value);
}
return uint72(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toUint64(uint256 value) internal pure returns (uint64) {
if (value > type(uint64).max) {
revert SafeCastOverflowedUintDowncast(64, value);
}
return uint64(value);
}
/**
* @dev Returns the downcasted uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toUint56(uint256 value) internal pure returns (uint56) {
if (value > type(uint56).max) {
revert SafeCastOverflowedUintDowncast(56, value);
}
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toUint48(uint256 value) internal pure returns (uint48) {
if (value > type(uint48).max) {
revert SafeCastOverflowedUintDowncast(48, value);
}
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toUint40(uint256 value) internal pure returns (uint40) {
if (value > type(uint40).max) {
revert SafeCastOverflowedUintDowncast(40, value);
}
return uint40(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toUint32(uint256 value) internal pure returns (uint32) {
if (value > type(uint32).max) {
revert SafeCastOverflowedUintDowncast(32, value);
}
return uint32(value);
}
/**
* @dev Returns the downcasted uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toUint24(uint256 value) internal pure returns (uint24) {
if (value > type(uint24).max) {
revert SafeCastOverflowedUintDowncast(24, value);
}
return uint24(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toUint16(uint256 value) internal pure returns (uint16) {
if (value > type(uint16).max) {
revert SafeCastOverflowedUintDowncast(16, value);
}
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toUint8(uint256 value) internal pure returns (uint8) {
if (value > type(uint8).max) {
revert SafeCastOverflowedUintDowncast(8, value);
}
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*/
function toUint256(int256 value) internal pure returns (uint256) {
if (value < 0) {
revert SafeCastOverflowedIntToUint(value);
}
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(248, value);
}
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(240, value);
}
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(232, value);
}
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(224, value);
}
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(216, value);
}
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(208, value);
}
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(200, value);
}
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(192, value);
}
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(184, value);
}
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(176, value);
}
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(168, value);
}
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(160, value);
}
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(152, value);
}
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(144, value);
}
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(136, value);
}
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toInt128(int256 value) internal pure returns (int128 downcasted) {
downcasted = int128(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(128, value);
}
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(120, value);
}
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(112, value);
}
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(104, value);
}
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(96, value);
}
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(88, value);
}
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(80, value);
}
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(72, value);
}
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toInt64(int256 value) internal pure returns (int64 downcasted) {
downcasted = int64(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(64, value);
}
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(56, value);
}
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(48, value);
}
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(40, value);
}
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toInt32(int256 value) internal pure returns (int32 downcasted) {
downcasted = int32(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(32, value);
}
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(24, value);
}
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toInt16(int256 value) internal pure returns (int16 downcasted) {
downcasted = int16(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(16, value);
}
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toInt8(int256 value) internal pure returns (int8 downcasted) {
downcasted = int8(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(8, value);
}
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
if (value > uint256(type(int256).max)) {
revert SafeCastOverflowedUintToInt(value);
}
return int256(value);
}
/**
* @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.
*/
function toUint(bool b) internal pure returns (uint256 u) {
assembly ("memory-safe") {
u := iszero(iszero(b))
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (access/Ownable2Step.sol)
pragma solidity ^0.8.20;
import {Ownable} from "./Ownable.sol";
/**
* @dev Contract module which provides access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* This extension of the {Ownable} contract includes a two-step mechanism to transfer
* ownership, where the new owner must call {acceptOwnership} in order to replace the
* old one. This can help prevent common mistakes, such as transfers of ownership to
* incorrect accounts, or to contracts that are unable to interact with the
* permission system.
*
* The initial owner is specified at deployment time in the constructor for `Ownable`. This
* can later be changed with {transferOwnership} and {acceptOwnership}.
*
* This module is used through inheritance. It will make available all functions
* from parent (Ownable).
*/
abstract contract Ownable2Step is Ownable {
address private _pendingOwner;
event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);
/**
* @dev Returns the address of the pending owner.
*/
function pendingOwner() public view virtual returns (address) {
return _pendingOwner;
}
/**
* @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
* Can only be called by the current owner.
*
* Setting `newOwner` to the zero address is allowed; this can be used to cancel an initiated ownership transfer.
*/
function transferOwnership(address newOwner) public virtual override onlyOwner {
_pendingOwner = newOwner;
emit OwnershipTransferStarted(owner(), newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual override {
delete _pendingOwner;
super._transferOwnership(newOwner);
}
/**
* @dev The new owner accepts the ownership transfer.
*/
function acceptOwnership() public virtual {
address sender = _msgSender();
if (pendingOwner() != sender) {
revert OwnableUnauthorizedAccount(sender);
}
_transferOwnership(sender);
}
}// 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) (utils/ReentrancyGuardTransient.sol)
pragma solidity ^0.8.24;
import {TransientSlot} from "./TransientSlot.sol";
/**
* @dev Variant of {ReentrancyGuard} that uses transient storage.
*
* NOTE: This variant only works on networks where EIP-1153 is available.
*
* _Available since v5.1._
*/
abstract contract ReentrancyGuardTransient {
using TransientSlot for *;
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ReentrancyGuard")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant REENTRANCY_GUARD_STORAGE =
0x9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be NOT_ENTERED
if (_reentrancyGuardEntered()) {
revert ReentrancyGuardReentrantCall();
}
// Any calls to nonReentrant after this point will fail
REENTRANCY_GUARD_STORAGE.asBoolean().tstore(true);
}
function _nonReentrantAfter() private {
REENTRANCY_GUARD_STORAGE.asBoolean().tstore(false);
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return REENTRANCY_GUARD_STORAGE.asBoolean().tload();
}
}// 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;
}// 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 _vaults, bytes[] calldata harvestData) external;
function claim(address[] calldata _vaults, bytes[] calldata harvestData, address receiver) external;
function claim(address[] calldata _vaults, address account, bytes[] calldata harvestData) external;
function claim(address[] calldata _vaults, address account, bytes[] calldata harvestData, address receiver)
external;
function claimProtocolFees() external;
function harvest(address[] calldata _vaults, bytes[] calldata _harvestData, address _receiver) external;
function REWARD_TOKEN() external view returns (address);
}/// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
interface IProtocolController {
function vaults(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 isShutdown(address) external view returns (bool);
function isFullyWithdrawn(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 markGaugeAsFullyWithdrawn(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
// 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.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}// 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) (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.1.0) (utils/TransientSlot.sol)
// This file was procedurally generated from scripts/generate/templates/TransientSlot.js.
pragma solidity ^0.8.24;
/**
* @dev Library for reading and writing value-types to specific transient storage slots.
*
* Transient slots are often used to store temporary values that are removed after the current transaction.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* * Example reading and writing values using transient storage:
* ```solidity
* contract Lock {
* using TransientSlot for *;
*
* // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.
* bytes32 internal constant _LOCK_SLOT = 0xf4678858b2b588224636b8522b729e7722d32fc491da849ed75b3fdf3c84f542;
*
* modifier locked() {
* require(!_LOCK_SLOT.asBoolean().tload());
*
* _LOCK_SLOT.asBoolean().tstore(true);
* _;
* _LOCK_SLOT.asBoolean().tstore(false);
* }
* }
* ```
*
* TIP: Consider using this library along with {SlotDerivation}.
*/
library TransientSlot {
/**
* @dev UDVT that represent a slot holding a address.
*/
type AddressSlot is bytes32;
/**
* @dev Cast an arbitrary slot to a AddressSlot.
*/
function asAddress(bytes32 slot) internal pure returns (AddressSlot) {
return AddressSlot.wrap(slot);
}
/**
* @dev UDVT that represent a slot holding a bool.
*/
type BooleanSlot is bytes32;
/**
* @dev Cast an arbitrary slot to a BooleanSlot.
*/
function asBoolean(bytes32 slot) internal pure returns (BooleanSlot) {
return BooleanSlot.wrap(slot);
}
/**
* @dev UDVT that represent a slot holding a bytes32.
*/
type Bytes32Slot is bytes32;
/**
* @dev Cast an arbitrary slot to a Bytes32Slot.
*/
function asBytes32(bytes32 slot) internal pure returns (Bytes32Slot) {
return Bytes32Slot.wrap(slot);
}
/**
* @dev UDVT that represent a slot holding a uint256.
*/
type Uint256Slot is bytes32;
/**
* @dev Cast an arbitrary slot to a Uint256Slot.
*/
function asUint256(bytes32 slot) internal pure returns (Uint256Slot) {
return Uint256Slot.wrap(slot);
}
/**
* @dev UDVT that represent a slot holding a int256.
*/
type Int256Slot is bytes32;
/**
* @dev Cast an arbitrary slot to a Int256Slot.
*/
function asInt256(bytes32 slot) internal pure returns (Int256Slot) {
return Int256Slot.wrap(slot);
}
/**
* @dev Load the value held at location `slot` in transient storage.
*/
function tload(AddressSlot slot) internal view returns (address value) {
assembly ("memory-safe") {
value := tload(slot)
}
}
/**
* @dev Store `value` at location `slot` in transient storage.
*/
function tstore(AddressSlot slot, address value) internal {
assembly ("memory-safe") {
tstore(slot, value)
}
}
/**
* @dev Load the value held at location `slot` in transient storage.
*/
function tload(BooleanSlot slot) internal view returns (bool value) {
assembly ("memory-safe") {
value := tload(slot)
}
}
/**
* @dev Store `value` at location `slot` in transient storage.
*/
function tstore(BooleanSlot slot, bool value) internal {
assembly ("memory-safe") {
tstore(slot, value)
}
}
/**
* @dev Load the value held at location `slot` in transient storage.
*/
function tload(Bytes32Slot slot) internal view returns (bytes32 value) {
assembly ("memory-safe") {
value := tload(slot)
}
}
/**
* @dev Store `value` at location `slot` in transient storage.
*/
function tstore(Bytes32Slot slot, bytes32 value) internal {
assembly ("memory-safe") {
tstore(slot, value)
}
}
/**
* @dev Load the value held at location `slot` in transient storage.
*/
function tload(Uint256Slot slot) internal view returns (uint256 value) {
assembly ("memory-safe") {
value := tload(slot)
}
}
/**
* @dev Store `value` at location `slot` in transient storage.
*/
function tstore(Uint256Slot slot, uint256 value) internal {
assembly ("memory-safe") {
tstore(slot, value)
}
}
/**
* @dev Load the value held at location `slot` in transient storage.
*/
function tload(Int256Slot slot) internal view returns (int256 value) {
assembly ("memory-safe") {
value := tload(slot)
}
}
/**
* @dev Store `value` at location `slot` in transient storage.
*/
function tstore(Int256Slot slot, int256 value) internal {
assembly ("memory-safe") {
tstore(slot, value)
}
}
}// 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
// 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.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/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":"address","name":"_owner","type":"address"},{"internalType":"address","name":"_registry","type":"address"},{"internalType":"address","name":"_rewardToken","type":"address"},{"internalType":"bytes4","name":"_protocolId","type":"bytes4"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"FeeExceedsMaximum","type":"error"},{"inputs":[],"name":"FeesExceedRewards","type":"error"},{"inputs":[],"name":"HarvestTokenNotReceived","type":"error"},{"inputs":[],"name":"InsufficientPendingRewards","type":"error"},{"inputs":[],"name":"InvalidHarvestDataLength","type":"error"},{"inputs":[],"name":"InvalidProtocolController","type":"error"},{"inputs":[],"name":"InvalidProtocolId","type":"error"},{"inputs":[],"name":"InvalidRewardToken","type":"error"},{"inputs":[],"name":"InvalidVault","type":"error"},{"inputs":[],"name":"NetCreditsNotEnough","type":"error"},{"inputs":[],"name":"NoFeeReceiver","type":"error"},{"inputs":[],"name":"NoPendingRewards","type":"error"},{"inputs":[],"name":"NoStrategy","type":"error"},{"inputs":[],"name":"OnlyAllowed","type":"error"},{"inputs":[],"name":"OnlyVault","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"inputs":[],"name":"ReentrancyGuardReentrantCall","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"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"vault","type":"address"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint128","name":"balance","type":"uint128"},{"indexed":false,"internalType":"uint256","name":"integral","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"pendingRewards","type":"uint256"}],"name":"AccountCheckpoint","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"vault","type":"address"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint128","name":"amount","type":"uint128"},{"indexed":false,"internalType":"uint256","name":"integral","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"supply","type":"uint256"},{"indexed":false,"internalType":"enum IStrategy.HarvestPolicy","name":"policy","type":"uint8"}],"name":"Checkpoint","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"vault","type":"address"},{"indexed":false,"internalType":"uint256","name":"integral","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"supply","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"protocolFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"harvesterFee","type":"uint256"}],"name":"Harvest","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint128","name":"oldHarvestFeePercent","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"newHarvestFeePercent","type":"uint128"}],"name":"HarvestFeePercentSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferStarted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint128","name":"oldProtocolFeePercent","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"newProtocolFeePercent","type":"uint128"}],"name":"ProtocolFeePercentSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"ProtocolFeesClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"referrer","type":"address"},{"indexed":false,"internalType":"address","name":"referree","type":"address"},{"indexed":false,"internalType":"uint128","name":"assets","type":"uint128"}],"name":"Referrer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"vault","type":"address"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"RewardsClaimed","type":"event"},{"inputs":[],"name":"MAX_FEE_PERCENT","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MIN_MEANINGFUL_REWARDS","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"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":[],"name":"REWARD_TOKEN","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SCALING_FACTOR","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"acceptOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"},{"internalType":"address","name":"account","type":"address"}],"name":"accounts","outputs":[{"internalType":"uint128","name":"balance","type":"uint128"},{"internalType":"uint256","name":"integral","type":"uint256"},{"internalType":"uint256","name":"pendingRewards","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"},{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"gauge","type":"address"},{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint128","name":"amount","type":"uint128"},{"components":[{"internalType":"uint128","name":"feeSubjectAmount","type":"uint128"},{"internalType":"uint128","name":"totalAmount","type":"uint128"}],"internalType":"struct IStrategy.PendingRewards","name":"pendingRewards","type":"tuple"},{"internalType":"enum IStrategy.HarvestPolicy","name":"policy","type":"uint8"}],"name":"checkpoint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"gauge","type":"address"},{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint128","name":"amount","type":"uint128"},{"components":[{"internalType":"uint128","name":"feeSubjectAmount","type":"uint128"},{"internalType":"uint128","name":"totalAmount","type":"uint128"}],"internalType":"struct IStrategy.PendingRewards","name":"pendingRewards","type":"tuple"},{"internalType":"enum IStrategy.HarvestPolicy","name":"policy","type":"uint8"},{"internalType":"address","name":"referrer","type":"address"}],"name":"checkpoint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_gauges","type":"address[]"},{"internalType":"address","name":"account","type":"address"},{"internalType":"bytes[]","name":"harvestData","type":"bytes[]"}],"name":"claim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_gauges","type":"address[]"},{"internalType":"address","name":"account","type":"address"},{"internalType":"bytes[]","name":"harvestData","type":"bytes[]"},{"internalType":"address","name":"receiver","type":"address"}],"name":"claim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_gauges","type":"address[]"},{"internalType":"bytes[]","name":"harvestData","type":"bytes[]"}],"name":"claim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_gauges","type":"address[]"},{"internalType":"bytes[]","name":"harvestData","type":"bytes[]"},{"internalType":"address","name":"receiver","type":"address"}],"name":"claim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"claimProtocolFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"feesParams","outputs":[{"internalType":"uint128","name":"protocolFeePercent","type":"uint128"},{"internalType":"uint128","name":"harvestFeePercent","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getHarvestFeePercent","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"},{"internalType":"address","name":"account","type":"address"}],"name":"getPendingRewards","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"}],"name":"getPendingRewards","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getProtocolFeePercent","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTotalFeePercent","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"_gauges","type":"address[]"},{"internalType":"bytes[]","name":"_harvestData","type":"bytes[]"},{"internalType":"address","name":"_receiver","type":"address"}],"name":"harvest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"protocolFeesAccrued","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint128","name":"newHarvestFeePercent","type":"uint128"}],"name":"setHarvestFeePercent","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint128","name":"newProtocolFeePercent","type":"uint128"}],"name":"setProtocolFeePercent","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"}],"name":"totalSupply","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"}],"name":"vaults","outputs":[{"internalType":"uint256","name":"integral","type":"uint256"},{"internalType":"uint128","name":"supply","type":"uint128"},{"internalType":"uint128","name":"feeSubjectAmount","type":"uint128"},{"internalType":"uint128","name":"totalAmount","type":"uint128"},{"internalType":"uint128","name":"netCredited","type":"uint128"},{"internalType":"uint128","name":"reservedHarvestFee","type":"uint128"},{"internalType":"uint128","name":"reservedProtocolFee","type":"uint128"}],"stateMutability":"view","type":"function"}]Contract Creation Code
60e060405234801561000f575f5ffd5b50604051612b36380380612b3683398101604081905261002e9161023f565b836001600160a01b03811661005c57604051631e4fbdf760e01b81525f600482015260240160405180910390fd5b610065816101b9565b506001600160a01b03831661008d57604051631f0e497160e31b815260040160405180910390fd5b6001600160a01b0382166100b45760405163dfde867160e01b815260040160405180910390fd5b6001600160e01b031981166100dc576040516355e7c3d960e11b815260040160405180910390fd5b6001600160a01b03838116608052821660a0526001600160e01b0319811660c052604080518082018252670214e8348c4f0000815266038d7ea4c68000602091820181905276038d7ea4c6800000000000000000000214e8348c4f000060025582515f8152918201527f9eff170752bff88fe482ef6885f2ea7d13c27a72a64aa0968e4e40e2092e2ffb910160405180910390a1604080515f8152670214e8348c4f000060208201527f23c1335b4285bea37ccdc6223b0269c10c388464aad09ed312747fa9c3a8d8e3910160405180910390a15050505061029f565b600180546001600160a01b03191690556101d2816101d5565b50565b5f80546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b80516001600160a01b038116811461023a575f5ffd5b919050565b5f5f5f5f60808587031215610252575f5ffd5b61025b85610224565b935061026960208601610224565b925061027760408601610224565b60608601519092506001600160e01b031981168114610294575f5ffd5b939692955090935050565b60805160a05160c0516128126103245f395f81816101f001528181610c0f01526115d101525f818161033b01528181610ce7015281816116ab01528181611c4901528181611cec0152611fb701525f81816102c10152818161067301528181610c3801528181611073015281816115fa0152818161176d0152611d3601526128125ff3fe608060405234801561000f575f5ffd5b50600436106101e7575f3560e01c8063ad74b77511610109578063e4dc2aa41161009e578063f0a235111161006e578063f0a2351114610589578063f2fde38b1461059c578063f6ed2017146105af578063f7888aec146105e3575f5ffd5b8063e4dc2aa41461051c578063e84f983614610550578063ef4cadc514610563578063ef933df014610576575f5ffd5b8063cd3f29e9116100d9578063cd3f29e9146104d4578063d6e22a43146104e5578063e0b735d5146104f8578063e30c39781461050b575f5ffd5b8063ad74b77514610412578063af5db8c51461047a578063b621e75a1461048d578063bc7e75ba14610496575f5ffd5b80637a27db571161017f5780638f9493c41161014f5780638f9493c41461032357806399248ea714610336578063a622ee7c1461035d578063acc3c88c146103ff575f5ffd5b80637a27db571461029b5780637aaf53e6146102bc57806389acf147146102fb5780638da5cb5b14610313575f5ffd5b80634a7d0369116101ba5780634a7d03691461027457806367d817401461027c578063715018a61461028b57806379ba509714610293575f5ffd5b80630db41f31146101eb578063235d2035146102305780632ebae0c51461025057806337e08bcd14610265575b5f5ffd5b6102127f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160e01b031990911681526020015b60405180910390f35b610238610624565b6040516001600160801b039091168152602001610227565b61026361025e36600461210c565b61064a565b005b610238670de0b6b3a764000081565b610263610bef565b61023867058d15e17628000081565b610263610d4d565b610263610d5e565b6102ae6102a9366004612185565b610da7565b604051908152602001610227565b6102e37f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b039091168152602001610227565b600254600160801b90046001600160801b0316610238565b5f546001600160a01b03166102e3565b610263610331366004612203565b610dd6565b6102e37f000000000000000000000000000000000000000000000000000000000000000081565b6103ba61036b366004612284565b60046020525f9081526040902080546001820154600283015460039093015491926001600160801b0380831693600160801b938490048216938383169381900483169282811692919091041687565b604080519788526001600160801b03968716602089015294861694870194909452918416606086015283166080850152821660a08401521660c082015260e001610227565b61026361040d36600461229f565b610e45565b610455610420366004612185565b600560209081525f92835260408084209091529082529020805460018201546002909201546001600160801b03909116919083565b604080516001600160801b039094168452602084019290925290820152606001610227565b61026361048836600461232e565b610eba565b6102ae60035481565b6002546104b4906001600160801b0380821691600160801b90041682565b604080516001600160801b03938416815292909116602083015201610227565b6002546001600160801b0316610238565b6102636104f33660046123ae565b610ec8565b6102636105063660046123ae565b610f8b565b6001546001600160a01b03166102e3565b61023861052a366004612284565b6001600160a01b03165f908152600460205260409020600101546001600160801b031690565b61026361055e3660046123c9565b611048565b6102386b033b2e3c9fd0803ce800000081565b61026361058436600461245b565b61117e565b610263610597366004612203565b611191565b6102636105aa366004612284565b61120e565b6102386105bd366004612284565b6001600160a01b03165f908152600460205260409020600201546001600160801b031690565b6102386105f1366004612185565b6001600160a01b039182165f9081526005602090815260408083209390941682529190915220546001600160801b031690565b6002545f90610645906001600160801b03600160801b8204811691166124d9565b905090565b61065261127e565b604051632988bb9f60e21b81526001600160a01b03878116600483015233917f00000000000000000000000000000000000000000000000000000000000000009091169063a622ee7c90602401602060405180830381865afa1580156106ba573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906106de91906124f8565b6001600160a01b03161461070557604051638d1af8bd60e01b815260040160405180910390fd5b335f9081526004602090815260408083206001810154815491946001600160801b03909116939192909161073d9188019088016123ae565b6001600160801b031611801561075b57505f826001600160801b0316115b15610b135760028301545f906001600160801b031661078060408801602089016123ae565b61078a9190612513565b60018501549091505f90600160801b90046001600160801b03166107b160208901896123ae565b6107bb9190612513565b90506107cd60408801602089016123ae565b6001600160801b03166107e360208901896123ae565b6001600160801b0316111561080b576040516342c745c960e11b815260040160405180910390fd5b5f600187600181111561082057610820612532565b14801561083557505f836001600160801b0316115b156108e8576001600160801b038216156108a35761088161087c6108616002546001600160801b031690565b6001600160801b038581169116670de0b6b3a76400006112eb565b6113a2565b9050806001600160801b031660035f82825461089d9190612546565b90915550505b6108d76b033b2e3c9fd0803ce80000006001600160801b0387166108c78487612513565b6001600160801b031691906112eb565b6108e19085612546565b9350610b0f565b5f8760018111156108fb576108fb612532565b1480156109195750670de0b6b3a76400006001600160801b03841610155b15610b0f576001600160801b038216156109925761094561087c6108616002546001600160801b031690565b9050808660030160108282829054906101000a90046001600160801b031661096d91906124d9565b92506101000a8154816001600160801b0302191690836001600160801b031602179055505b5f6109ce61087c6109b36002546001600160801b03600160801b9091041690565b6001600160801b038781169116670de0b6b3a76400006112eb565b90505f816109dc8487612513565b6109e69190612513565b9050610a0c6001600160801b03808316906b033b2e3c9fd0803ce8000000908a166112eb565b610a169087612546565b9550808860020160108282829054906101000a90046001600160801b0316610a3e91906124d9565b92506101000a8154816001600160801b0302191690836001600160801b0316021790555081886003015f8282829054906101000a90046001600160801b0316610a8791906124d9565b92506101000a8154816001600160801b0302191690836001600160801b03160217905550896020016020810190610abe91906123ae565b6002890180546001600160801b0319166001600160801b0392909216919091179055610aed60208b018b6123ae565b6001890180546001600160801b03928316600160801b02921691909117905550505b5050505b6001600160a01b038816610b3257610b2b86836124d9565b9150610b40565b610b403389886001856113d9565b6001600160a01b038716610b5f57610b588683612513565b9150610b6c565b610b6c3388885f856113d9565b8083556001830180546001600160801b0319166001600160801b0384161790556040516001600160a01b0388811691908a169033907f339a4cbd642293d5eff4d6861612c8ec7e4b266309b85297707a1402d718a43090610bd4908b90879089908c90612559565b60405180910390a4505050610be76114eb565b505050505050565b610bf761127e565b6040516304f8a13960e11b81526001600160e01b03197f00000000000000000000000000000000000000000000000000000000000000001660048201525f907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906309f1427290602401602060405180830381865afa158015610c85573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610ca991906124f8565b90506001600160a01b038116610cd257604051633ab55dcd60e11b815260040160405180910390fd5b600380545f909155610d0e6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168383611515565b6040518181527f2322a767e1914d2df0d776d643d2bfa5b7752ea9a452f75878d7bca357cb55ff9060200160405180910390a15050610d4b6114eb565b565b610d5561156c565b610d4b5f611598565b60015433906001600160a01b03168114610d9b5760405163118cdaa760e01b81526001600160a01b03821660048201526024015b60405180910390fd5b610da481611598565b50565b6001600160a01b038083165f908152600560209081526040808320938516835292905220600201545b92915050565b838214610df657604051633aa788ff60e01b815260040160405180910390fd5b610e3e8585808060200260200160405190810160405280939291908181526020018383602002808284375f92019190915250610e3892508691508790506125e7565b836115b1565b5050505050565b610e5387878787878761064a565b6001600160a01b03811615610eb157604080516001600160a01b0387811682526001600160801b03871660208301528316917f89f9f0365414a9cdee54b1ac6ad8f46c1f9679ad366e151559a01811b6f3888a910160405180910390a25b50505050505050565b610e3e858585858588611048565b610ed061156c565b600280545f90610ef090600160801b90046001600160801b0316846124d9565b905067058d15e1762800006001600160801b0382161115610f2457604051632be7087760e21b815260040160405180910390fd5b8154604080516001600160801b03928316815291851660208301527f23c1335b4285bea37ccdc6223b0269c10c388464aad09ed312747fa9c3a8d8e3910160405180910390a15080546001600160801b0319166001600160801b0392909216919091179055565b610f9361156c565b600280545f90610faf906001600160801b038086169116612546565b905067058d15e176280000811115610fda57604051632be7087760e21b815260040160405180910390fd5b815460408051600160801b9092046001600160801b039081168352851660208301527f9eff170752bff88fe482ef6885f2ea7d13c27a72a64aa0968e4e40e2092e2ffb910160405180910390a15050600280546001600160801b03928316600160801b029216919091179055565b6040516217798b60e61b81523060048201523360248201525f356001600160e01b03191660448201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906305de62c090606401602060405180830381865afa1580156110c0573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906110e491906126c9565b61110157604051634eaf9b5d60e11b815260040160405180910390fd5b81158061110d57508185145b61112a57604051633aa788ff60e01b815260040160405180910390fd5b8115611172576111728686808060200260200160405190810160405280939291908181526020018383602002808284375f92019190915250610e3892508691508790506125e7565b610be786868684611d20565b61118b8484848433611191565b50505050565b81158061119d57508184145b6111ba57604051633aa788ff60e01b815260040160405180910390fd5b8115611202576112028585808060200260200160405190810160405280939291908181526020018383602002808284375f92019190915250610e3892508691508790506125e7565b610e3e85853384611d20565b61121661156c565b600180546001600160a01b0383166001600160a01b031990911681179091556112465f546001600160a01b031690565b6001600160a01b03167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e2270060405160405180910390a350565b7f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f005c156112be57604051633ee5aeb560e01b815260040160405180910390fd5b610d4b60017f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f005b90611fe8565b5f838302815f1985870982811083820303915050805f0361131f57838281611315576113156126e8565b049250505061139b565b808411611336576113366003851502601118611fef565b5f848688095f868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150505b9392505050565b5f6001600160801b038211156113d5576040516306dfcc6560e41b81526080600482015260248101839052604401610d92565b5090565b6001600160a01b038086165f908152600560209081526040808320938816835292905220805460018201546001600160801b03909116906114359082906b033b2e3c9fd0803ce80000009061142e90876126fc565b91906112eb565b826002015f8282546114479190612546565b909155508490506114615761145c85826124d9565b61146b565b61146b8582612513565b82546001600160801b0319166001600160801b0391909116908117835560018301849055600283015460408051928352602083018690528201526001600160a01b0387811691908916907f1b0be1ed1ab434e3149bf758ffce7336b52dee930bbbc92b27577f579d5e66af9060600160405180910390a350505050505050565b610d4b5f7f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f006112e5565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b179052611567908490612000565b505050565b5f546001600160a01b03163314610d4b5760405163118cdaa760e01b8152336004820152602401610d92565b600180546001600160a01b0319169055610da48161206c565b6115b961127e565b604051630165699560e21b81526001600160e01b03197f00000000000000000000000000000000000000000000000000000000000000001660048201525f907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690630595a65490602401602060405180830381865afa158015611647573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061166b91906124f8565b90506001600160a01b03811661169457604051635c7f4b4760e11b815260040160405180910390fd5b6040516370a0823160e01b81523060048201525f907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906370a0823190602401602060405180830381865afa1580156116f8573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061171c919061270f565b90505f5f5f5b8751811015611bc9575f88828151811061173e5761173e612726565b6020908102919091010151604051632988bb9f60e21b81526001600160a01b0380831660048301529192505f917f0000000000000000000000000000000000000000000000000000000000000000169063a622ee7c90602401602060405180830381865afa1580156117b2573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906117d691906124f8565b90506001600160a01b0381166117ff57604051630681d31960e51b815260040160405180910390fd5b6001600160a01b038082165f9081526004602052604081208b5190928a1690637399bfe89086908e908990811061183857611838612726565b60200260200101516040518363ffffffff1660e01b815260040161185d92919061273a565b60408051808303815f875af1158015611878573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061189c919061277e565b600283015460208201519192506001600160801b039081169116108015906118dd5750600182015481516001600160801b03600160801b9092048216911610155b6118fa5760405163a36c94e560e01b815260040160405180910390fd5b80602001516001600160801b0316815f01516001600160801b03161115611934576040516342c745c960e11b815260040160405180910390fd5b80602001516001600160801b03165f036119515750505050611bc1565b6020810151611969906001600160801b031687612546565b6003830154600284015460208401519298506001600160801b03600160801b8084048216949382169392048116915f9184916119a7918791166126fc565b6119b191906126fc565b9050818110156119d457604051631de4df8560e31b815260040160405180910390fd5b81811180156119ef575060018601546001600160801b031615155b15611b0d575f6119ff83836126fc565b90505f611a38611a1f6002546001600160801b03600160801b9091041690565b83906001600160801b0316670de0b6b3a76400006112eb565b9050611a448186612546565b600189015488519196506001600160801b03600160801b909104811691161115611aca57600188015487515f91611a8c91600160801b9091046001600160801b031690612513565b6001600160801b031690505f611aad611a1f6002546001600160801b031690565b9050611ab98189612546565b9750611ac581856126fc565b935050505b6001880154611af4906b033b2e3c9fd0803ce8000000906001600160801b031661142e84866126fc565b885f015f828254611b059190612546565b909155505050505b611b17838c612546565b9a508360035f828254611b2a9190612546565b90915550505f600287018190556001870180546001600160801b0390811691829055600389019290925587546020888101516040805193845291830193909352919092169082015260608101859052608081018490526001600160a01b038816907feaedd1267621f4a8ee97011faf0e67800ad3063714bd179f078c980bb9a3fa3d9060a00160405180910390a250505050505050505b600101611722565b50805f03611bda5750505050611d18565b836001600160a01b0316636b9f96ea6040518163ffffffff1660e01b81526004015f604051808303815f87803b158015611c12575f5ffd5b505af1158015611c24573d5f5f3e3d5ffd5b505050508083611c349190612546565b6040516370a0823160e01b81523060048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906370a0823190602401602060405180830381865afa158015611c96573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611cba919061270f565b1015611cd9576040516306829f6360e51b815260040160405180910390fd5b8115611d1357611d136001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168684611515565b505050505b6115676114eb565b611d2861127e565b5f5f5f5b85811015611f89577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663a622ee7c888884818110611d7557611d75612726565b9050602002016020810190611d8a9190612284565b6040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602401602060405180830381865afa158015611dcc573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611df091906124f8565b91506001600160a01b038216611e1957604051630681d31960e51b815260040160405180910390fd5b6001600160a01b038083165f90815260056020908152604080832093891683529290522080546001600160801b031680151580611e595750600282015415155b15611f7f5760018201546001600160a01b0385165f90815260046020526040902054600284015482821115611eb957611eac6001600160801b0385166b033b2e3c9fd0803ce800000061142e86866126fc565b611eb69082612546565b90505b611ec38189612546565b600186018390555f60028701819055604080516001600160801b038816815260208101869052908101919091529098506001600160a01b03808c1691908916907f1b0be1ed1ab434e3149bf758ffce7336b52dee930bbbc92b27577f579d5e66af9060600160405180910390a3604080516001600160a01b038b8116825260208201849052808d1692908a16917f5637d7f962248a7f05a7ab69eec6446e31f3d0a299d997f135a65c62806e7891910160405180910390a35050505b5050600101611d2c565b50815f03611faa57604051635b8f50bf60e11b815260040160405180910390fd5b611fde6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168484611515565b505061118b6114eb565b80825d5050565b634e487b715f52806020526024601cfd5b5f5f60205f8451602086015f885af18061201f576040513d5f823e3d81fd5b50505f513d91508115612036578060011415612043565b6001600160a01b0384163b155b1561118b57604051635274afe760e01b81526001600160a01b0385166004820152602401610d92565b5f80546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6001600160a01b0381168114610da4575f5ffd5b6001600160801b0381168114610da4575f5ffd5b5f604082840312156120f3575f5ffd5b50919050565b803560028110612107575f5ffd5b919050565b5f5f5f5f5f5f60e08789031215612121575f5ffd5b863561212c816120bb565b9550602087013561213c816120bb565b9450604087013561214c816120bb565b9350606087013561215c816120cf565b925061216b88608089016120e3565b915061217960c088016120f9565b90509295509295509295565b5f5f60408385031215612196575f5ffd5b82356121a1816120bb565b915060208301356121b1816120bb565b809150509250929050565b5f5f83601f8401126121cc575f5ffd5b5081356001600160401b038111156121e2575f5ffd5b6020830191508360208260051b85010111156121fc575f5ffd5b9250929050565b5f5f5f5f5f60608688031215612217575f5ffd5b85356001600160401b0381111561222c575f5ffd5b612238888289016121bc565b90965094505060208601356001600160401b03811115612256575f5ffd5b612262888289016121bc565b9094509250506040860135612276816120bb565b809150509295509295909350565b5f60208284031215612294575f5ffd5b813561139b816120bb565b5f5f5f5f5f5f5f610100888a0312156122b6575f5ffd5b87356122c1816120bb565b965060208801356122d1816120bb565b955060408801356122e1816120bb565b945060608801356122f1816120cf565b93506123008960808a016120e3565b925061230e60c089016120f9565b915060e088013561231e816120bb565b8091505092959891949750929550565b5f5f5f5f5f60608688031215612342575f5ffd5b85356001600160401b03811115612357575f5ffd5b612363888289016121bc565b9096509450506020860135612377816120bb565b925060408601356001600160401b03811115612391575f5ffd5b61239d888289016121bc565b969995985093965092949392505050565b5f602082840312156123be575f5ffd5b813561139b816120cf565b5f5f5f5f5f5f608087890312156123de575f5ffd5b86356001600160401b038111156123f3575f5ffd5b6123ff89828a016121bc565b9097509550506020870135612413816120bb565b935060408701356001600160401b0381111561242d575f5ffd5b61243989828a016121bc565b909450925050606087013561244d816120bb565b809150509295509295509295565b5f5f5f5f6040858703121561246e575f5ffd5b84356001600160401b03811115612483575f5ffd5b61248f878288016121bc565b90955093505060208501356001600160401b038111156124ad575f5ffd5b6124b9878288016121bc565b95989497509550505050565b634e487b7160e01b5f52601160045260245ffd5b6001600160801b038181168382160190811115610dd057610dd06124c5565b5f60208284031215612508575f5ffd5b815161139b816120bb565b6001600160801b038281168282160390811115610dd057610dd06124c5565b634e487b7160e01b5f52602160045260245ffd5b80820180821115610dd057610dd06124c5565b6001600160801b0385811682526020820185905283166040820152608081016002831061259457634e487b7160e01b5f52602160045260245ffd5b82606083015295945050505050565b634e487b7160e01b5f52604160045260245ffd5b604051601f8201601f191681016001600160401b03811182821017156125df576125df6125a3565b604052919050565b5f6001600160401b038311156125ff576125ff6125a3565b8260051b61260f602082016125b7565b84815290830190602081019036831115612627575f5ffd5b845b838110156126bf5780356001600160401b03811115612646575f5ffd5b860136601f820112612656575f5ffd5b80356001600160401b0381111561266f5761266f6125a3565b612682601f8201601f19166020016125b7565b818152366020838501011115612696575f5ffd5b816020840160208301375f60208383010152808652505050602083019250602081019050612629565b5095945050505050565b5f602082840312156126d9575f5ffd5b8151801515811461139b575f5ffd5b634e487b7160e01b5f52601260045260245ffd5b81810381811115610dd057610dd06124c5565b5f6020828403121561271f575f5ffd5b5051919050565b634e487b7160e01b5f52603260045260245ffd5b60018060a01b0383168152604060208201525f82518060408401528060208501606085015e5f606082850101526060601f19601f8301168401019150509392505050565b5f604082840312801561278f575f5ffd5b50604080519081016001600160401b03811182821017156127b2576127b26125a3565b60405282516127c0816120cf565b815260208301516127d0816120cf565b6020820152939250505056fea264697066735822122078ed433352f526840a0b8c77bca7d6e874c00661c532a78950e9d77d78164f8e64736f6c634300081c0033000000000000000000000000000755fbe4a24d7478bfcfc1e561afce82d1ff620000000000000000000000004d4c2c4777625e97be1985682fae5a53f5c44a80000000000000000000000000331b9182088e2a7d6d3fe4742aba1fb231aecc56c715e37300000000000000000000000000000000000000000000000000000000
Deployed Bytecode
0x608060405234801561000f575f5ffd5b50600436106101e7575f3560e01c8063ad74b77511610109578063e4dc2aa41161009e578063f0a235111161006e578063f0a2351114610589578063f2fde38b1461059c578063f6ed2017146105af578063f7888aec146105e3575f5ffd5b8063e4dc2aa41461051c578063e84f983614610550578063ef4cadc514610563578063ef933df014610576575f5ffd5b8063cd3f29e9116100d9578063cd3f29e9146104d4578063d6e22a43146104e5578063e0b735d5146104f8578063e30c39781461050b575f5ffd5b8063ad74b77514610412578063af5db8c51461047a578063b621e75a1461048d578063bc7e75ba14610496575f5ffd5b80637a27db571161017f5780638f9493c41161014f5780638f9493c41461032357806399248ea714610336578063a622ee7c1461035d578063acc3c88c146103ff575f5ffd5b80637a27db571461029b5780637aaf53e6146102bc57806389acf147146102fb5780638da5cb5b14610313575f5ffd5b80634a7d0369116101ba5780634a7d03691461027457806367d817401461027c578063715018a61461028b57806379ba509714610293575f5ffd5b80630db41f31146101eb578063235d2035146102305780632ebae0c51461025057806337e08bcd14610265575b5f5ffd5b6102127fc715e3730000000000000000000000000000000000000000000000000000000081565b6040516001600160e01b031990911681526020015b60405180910390f35b610238610624565b6040516001600160801b039091168152602001610227565b61026361025e36600461210c565b61064a565b005b610238670de0b6b3a764000081565b610263610bef565b61023867058d15e17628000081565b610263610d4d565b610263610d5e565b6102ae6102a9366004612185565b610da7565b604051908152602001610227565b6102e37f0000000000000000000000004d4c2c4777625e97be1985682fae5a53f5c44a8081565b6040516001600160a01b039091168152602001610227565b600254600160801b90046001600160801b0316610238565b5f546001600160a01b03166102e3565b610263610331366004612203565b610dd6565b6102e37f000000000000000000000000331b9182088e2a7d6d3fe4742aba1fb231aecc5681565b6103ba61036b366004612284565b60046020525f9081526040902080546001820154600283015460039093015491926001600160801b0380831693600160801b938490048216938383169381900483169282811692919091041687565b604080519788526001600160801b03968716602089015294861694870194909452918416606086015283166080850152821660a08401521660c082015260e001610227565b61026361040d36600461229f565b610e45565b610455610420366004612185565b600560209081525f92835260408084209091529082529020805460018201546002909201546001600160801b03909116919083565b604080516001600160801b039094168452602084019290925290820152606001610227565b61026361048836600461232e565b610eba565b6102ae60035481565b6002546104b4906001600160801b0380821691600160801b90041682565b604080516001600160801b03938416815292909116602083015201610227565b6002546001600160801b0316610238565b6102636104f33660046123ae565b610ec8565b6102636105063660046123ae565b610f8b565b6001546001600160a01b03166102e3565b61023861052a366004612284565b6001600160a01b03165f908152600460205260409020600101546001600160801b031690565b61026361055e3660046123c9565b611048565b6102386b033b2e3c9fd0803ce800000081565b61026361058436600461245b565b61117e565b610263610597366004612203565b611191565b6102636105aa366004612284565b61120e565b6102386105bd366004612284565b6001600160a01b03165f908152600460205260409020600201546001600160801b031690565b6102386105f1366004612185565b6001600160a01b039182165f9081526005602090815260408083209390941682529190915220546001600160801b031690565b6002545f90610645906001600160801b03600160801b8204811691166124d9565b905090565b61065261127e565b604051632988bb9f60e21b81526001600160a01b03878116600483015233917f0000000000000000000000004d4c2c4777625e97be1985682fae5a53f5c44a809091169063a622ee7c90602401602060405180830381865afa1580156106ba573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906106de91906124f8565b6001600160a01b03161461070557604051638d1af8bd60e01b815260040160405180910390fd5b335f9081526004602090815260408083206001810154815491946001600160801b03909116939192909161073d9188019088016123ae565b6001600160801b031611801561075b57505f826001600160801b0316115b15610b135760028301545f906001600160801b031661078060408801602089016123ae565b61078a9190612513565b60018501549091505f90600160801b90046001600160801b03166107b160208901896123ae565b6107bb9190612513565b90506107cd60408801602089016123ae565b6001600160801b03166107e360208901896123ae565b6001600160801b0316111561080b576040516342c745c960e11b815260040160405180910390fd5b5f600187600181111561082057610820612532565b14801561083557505f836001600160801b0316115b156108e8576001600160801b038216156108a35761088161087c6108616002546001600160801b031690565b6001600160801b038581169116670de0b6b3a76400006112eb565b6113a2565b9050806001600160801b031660035f82825461089d9190612546565b90915550505b6108d76b033b2e3c9fd0803ce80000006001600160801b0387166108c78487612513565b6001600160801b031691906112eb565b6108e19085612546565b9350610b0f565b5f8760018111156108fb576108fb612532565b1480156109195750670de0b6b3a76400006001600160801b03841610155b15610b0f576001600160801b038216156109925761094561087c6108616002546001600160801b031690565b9050808660030160108282829054906101000a90046001600160801b031661096d91906124d9565b92506101000a8154816001600160801b0302191690836001600160801b031602179055505b5f6109ce61087c6109b36002546001600160801b03600160801b9091041690565b6001600160801b038781169116670de0b6b3a76400006112eb565b90505f816109dc8487612513565b6109e69190612513565b9050610a0c6001600160801b03808316906b033b2e3c9fd0803ce8000000908a166112eb565b610a169087612546565b9550808860020160108282829054906101000a90046001600160801b0316610a3e91906124d9565b92506101000a8154816001600160801b0302191690836001600160801b0316021790555081886003015f8282829054906101000a90046001600160801b0316610a8791906124d9565b92506101000a8154816001600160801b0302191690836001600160801b03160217905550896020016020810190610abe91906123ae565b6002890180546001600160801b0319166001600160801b0392909216919091179055610aed60208b018b6123ae565b6001890180546001600160801b03928316600160801b02921691909117905550505b5050505b6001600160a01b038816610b3257610b2b86836124d9565b9150610b40565b610b403389886001856113d9565b6001600160a01b038716610b5f57610b588683612513565b9150610b6c565b610b6c3388885f856113d9565b8083556001830180546001600160801b0319166001600160801b0384161790556040516001600160a01b0388811691908a169033907f339a4cbd642293d5eff4d6861612c8ec7e4b266309b85297707a1402d718a43090610bd4908b90879089908c90612559565b60405180910390a4505050610be76114eb565b505050505050565b610bf761127e565b6040516304f8a13960e11b81526001600160e01b03197fc715e373000000000000000000000000000000000000000000000000000000001660048201525f907f0000000000000000000000004d4c2c4777625e97be1985682fae5a53f5c44a806001600160a01b0316906309f1427290602401602060405180830381865afa158015610c85573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610ca991906124f8565b90506001600160a01b038116610cd257604051633ab55dcd60e11b815260040160405180910390fd5b600380545f909155610d0e6001600160a01b037f000000000000000000000000331b9182088e2a7d6d3fe4742aba1fb231aecc56168383611515565b6040518181527f2322a767e1914d2df0d776d643d2bfa5b7752ea9a452f75878d7bca357cb55ff9060200160405180910390a15050610d4b6114eb565b565b610d5561156c565b610d4b5f611598565b60015433906001600160a01b03168114610d9b5760405163118cdaa760e01b81526001600160a01b03821660048201526024015b60405180910390fd5b610da481611598565b50565b6001600160a01b038083165f908152600560209081526040808320938516835292905220600201545b92915050565b838214610df657604051633aa788ff60e01b815260040160405180910390fd5b610e3e8585808060200260200160405190810160405280939291908181526020018383602002808284375f92019190915250610e3892508691508790506125e7565b836115b1565b5050505050565b610e5387878787878761064a565b6001600160a01b03811615610eb157604080516001600160a01b0387811682526001600160801b03871660208301528316917f89f9f0365414a9cdee54b1ac6ad8f46c1f9679ad366e151559a01811b6f3888a910160405180910390a25b50505050505050565b610e3e858585858588611048565b610ed061156c565b600280545f90610ef090600160801b90046001600160801b0316846124d9565b905067058d15e1762800006001600160801b0382161115610f2457604051632be7087760e21b815260040160405180910390fd5b8154604080516001600160801b03928316815291851660208301527f23c1335b4285bea37ccdc6223b0269c10c388464aad09ed312747fa9c3a8d8e3910160405180910390a15080546001600160801b0319166001600160801b0392909216919091179055565b610f9361156c565b600280545f90610faf906001600160801b038086169116612546565b905067058d15e176280000811115610fda57604051632be7087760e21b815260040160405180910390fd5b815460408051600160801b9092046001600160801b039081168352851660208301527f9eff170752bff88fe482ef6885f2ea7d13c27a72a64aa0968e4e40e2092e2ffb910160405180910390a15050600280546001600160801b03928316600160801b029216919091179055565b6040516217798b60e61b81523060048201523360248201525f356001600160e01b03191660448201527f0000000000000000000000004d4c2c4777625e97be1985682fae5a53f5c44a806001600160a01b0316906305de62c090606401602060405180830381865afa1580156110c0573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906110e491906126c9565b61110157604051634eaf9b5d60e11b815260040160405180910390fd5b81158061110d57508185145b61112a57604051633aa788ff60e01b815260040160405180910390fd5b8115611172576111728686808060200260200160405190810160405280939291908181526020018383602002808284375f92019190915250610e3892508691508790506125e7565b610be786868684611d20565b61118b8484848433611191565b50505050565b81158061119d57508184145b6111ba57604051633aa788ff60e01b815260040160405180910390fd5b8115611202576112028585808060200260200160405190810160405280939291908181526020018383602002808284375f92019190915250610e3892508691508790506125e7565b610e3e85853384611d20565b61121661156c565b600180546001600160a01b0383166001600160a01b031990911681179091556112465f546001600160a01b031690565b6001600160a01b03167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e2270060405160405180910390a350565b7f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f005c156112be57604051633ee5aeb560e01b815260040160405180910390fd5b610d4b60017f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f005b90611fe8565b5f838302815f1985870982811083820303915050805f0361131f57838281611315576113156126e8565b049250505061139b565b808411611336576113366003851502601118611fef565b5f848688095f868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150505b9392505050565b5f6001600160801b038211156113d5576040516306dfcc6560e41b81526080600482015260248101839052604401610d92565b5090565b6001600160a01b038086165f908152600560209081526040808320938816835292905220805460018201546001600160801b03909116906114359082906b033b2e3c9fd0803ce80000009061142e90876126fc565b91906112eb565b826002015f8282546114479190612546565b909155508490506114615761145c85826124d9565b61146b565b61146b8582612513565b82546001600160801b0319166001600160801b0391909116908117835560018301849055600283015460408051928352602083018690528201526001600160a01b0387811691908916907f1b0be1ed1ab434e3149bf758ffce7336b52dee930bbbc92b27577f579d5e66af9060600160405180910390a350505050505050565b610d4b5f7f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f006112e5565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b179052611567908490612000565b505050565b5f546001600160a01b03163314610d4b5760405163118cdaa760e01b8152336004820152602401610d92565b600180546001600160a01b0319169055610da48161206c565b6115b961127e565b604051630165699560e21b81526001600160e01b03197fc715e373000000000000000000000000000000000000000000000000000000001660048201525f907f0000000000000000000000004d4c2c4777625e97be1985682fae5a53f5c44a806001600160a01b031690630595a65490602401602060405180830381865afa158015611647573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061166b91906124f8565b90506001600160a01b03811661169457604051635c7f4b4760e11b815260040160405180910390fd5b6040516370a0823160e01b81523060048201525f907f000000000000000000000000331b9182088e2a7d6d3fe4742aba1fb231aecc566001600160a01b0316906370a0823190602401602060405180830381865afa1580156116f8573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061171c919061270f565b90505f5f5f5b8751811015611bc9575f88828151811061173e5761173e612726565b6020908102919091010151604051632988bb9f60e21b81526001600160a01b0380831660048301529192505f917f0000000000000000000000004d4c2c4777625e97be1985682fae5a53f5c44a80169063a622ee7c90602401602060405180830381865afa1580156117b2573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906117d691906124f8565b90506001600160a01b0381166117ff57604051630681d31960e51b815260040160405180910390fd5b6001600160a01b038082165f9081526004602052604081208b5190928a1690637399bfe89086908e908990811061183857611838612726565b60200260200101516040518363ffffffff1660e01b815260040161185d92919061273a565b60408051808303815f875af1158015611878573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061189c919061277e565b600283015460208201519192506001600160801b039081169116108015906118dd5750600182015481516001600160801b03600160801b9092048216911610155b6118fa5760405163a36c94e560e01b815260040160405180910390fd5b80602001516001600160801b0316815f01516001600160801b03161115611934576040516342c745c960e11b815260040160405180910390fd5b80602001516001600160801b03165f036119515750505050611bc1565b6020810151611969906001600160801b031687612546565b6003830154600284015460208401519298506001600160801b03600160801b8084048216949382169392048116915f9184916119a7918791166126fc565b6119b191906126fc565b9050818110156119d457604051631de4df8560e31b815260040160405180910390fd5b81811180156119ef575060018601546001600160801b031615155b15611b0d575f6119ff83836126fc565b90505f611a38611a1f6002546001600160801b03600160801b9091041690565b83906001600160801b0316670de0b6b3a76400006112eb565b9050611a448186612546565b600189015488519196506001600160801b03600160801b909104811691161115611aca57600188015487515f91611a8c91600160801b9091046001600160801b031690612513565b6001600160801b031690505f611aad611a1f6002546001600160801b031690565b9050611ab98189612546565b9750611ac581856126fc565b935050505b6001880154611af4906b033b2e3c9fd0803ce8000000906001600160801b031661142e84866126fc565b885f015f828254611b059190612546565b909155505050505b611b17838c612546565b9a508360035f828254611b2a9190612546565b90915550505f600287018190556001870180546001600160801b0390811691829055600389019290925587546020888101516040805193845291830193909352919092169082015260608101859052608081018490526001600160a01b038816907feaedd1267621f4a8ee97011faf0e67800ad3063714bd179f078c980bb9a3fa3d9060a00160405180910390a250505050505050505b600101611722565b50805f03611bda5750505050611d18565b836001600160a01b0316636b9f96ea6040518163ffffffff1660e01b81526004015f604051808303815f87803b158015611c12575f5ffd5b505af1158015611c24573d5f5f3e3d5ffd5b505050508083611c349190612546565b6040516370a0823160e01b81523060048201527f000000000000000000000000331b9182088e2a7d6d3fe4742aba1fb231aecc566001600160a01b0316906370a0823190602401602060405180830381865afa158015611c96573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611cba919061270f565b1015611cd9576040516306829f6360e51b815260040160405180910390fd5b8115611d1357611d136001600160a01b037f000000000000000000000000331b9182088e2a7d6d3fe4742aba1fb231aecc56168684611515565b505050505b6115676114eb565b611d2861127e565b5f5f5f5b85811015611f89577f0000000000000000000000004d4c2c4777625e97be1985682fae5a53f5c44a806001600160a01b031663a622ee7c888884818110611d7557611d75612726565b9050602002016020810190611d8a9190612284565b6040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602401602060405180830381865afa158015611dcc573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611df091906124f8565b91506001600160a01b038216611e1957604051630681d31960e51b815260040160405180910390fd5b6001600160a01b038083165f90815260056020908152604080832093891683529290522080546001600160801b031680151580611e595750600282015415155b15611f7f5760018201546001600160a01b0385165f90815260046020526040902054600284015482821115611eb957611eac6001600160801b0385166b033b2e3c9fd0803ce800000061142e86866126fc565b611eb69082612546565b90505b611ec38189612546565b600186018390555f60028701819055604080516001600160801b038816815260208101869052908101919091529098506001600160a01b03808c1691908916907f1b0be1ed1ab434e3149bf758ffce7336b52dee930bbbc92b27577f579d5e66af9060600160405180910390a3604080516001600160a01b038b8116825260208201849052808d1692908a16917f5637d7f962248a7f05a7ab69eec6446e31f3d0a299d997f135a65c62806e7891910160405180910390a35050505b5050600101611d2c565b50815f03611faa57604051635b8f50bf60e11b815260040160405180910390fd5b611fde6001600160a01b037f000000000000000000000000331b9182088e2a7d6d3fe4742aba1fb231aecc56168484611515565b505061118b6114eb565b80825d5050565b634e487b715f52806020526024601cfd5b5f5f60205f8451602086015f885af18061201f576040513d5f823e3d81fd5b50505f513d91508115612036578060011415612043565b6001600160a01b0384163b155b1561118b57604051635274afe760e01b81526001600160a01b0385166004820152602401610d92565b5f80546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6001600160a01b0381168114610da4575f5ffd5b6001600160801b0381168114610da4575f5ffd5b5f604082840312156120f3575f5ffd5b50919050565b803560028110612107575f5ffd5b919050565b5f5f5f5f5f5f60e08789031215612121575f5ffd5b863561212c816120bb565b9550602087013561213c816120bb565b9450604087013561214c816120bb565b9350606087013561215c816120cf565b925061216b88608089016120e3565b915061217960c088016120f9565b90509295509295509295565b5f5f60408385031215612196575f5ffd5b82356121a1816120bb565b915060208301356121b1816120bb565b809150509250929050565b5f5f83601f8401126121cc575f5ffd5b5081356001600160401b038111156121e2575f5ffd5b6020830191508360208260051b85010111156121fc575f5ffd5b9250929050565b5f5f5f5f5f60608688031215612217575f5ffd5b85356001600160401b0381111561222c575f5ffd5b612238888289016121bc565b90965094505060208601356001600160401b03811115612256575f5ffd5b612262888289016121bc565b9094509250506040860135612276816120bb565b809150509295509295909350565b5f60208284031215612294575f5ffd5b813561139b816120bb565b5f5f5f5f5f5f5f610100888a0312156122b6575f5ffd5b87356122c1816120bb565b965060208801356122d1816120bb565b955060408801356122e1816120bb565b945060608801356122f1816120cf565b93506123008960808a016120e3565b925061230e60c089016120f9565b915060e088013561231e816120bb565b8091505092959891949750929550565b5f5f5f5f5f60608688031215612342575f5ffd5b85356001600160401b03811115612357575f5ffd5b612363888289016121bc565b9096509450506020860135612377816120bb565b925060408601356001600160401b03811115612391575f5ffd5b61239d888289016121bc565b969995985093965092949392505050565b5f602082840312156123be575f5ffd5b813561139b816120cf565b5f5f5f5f5f5f608087890312156123de575f5ffd5b86356001600160401b038111156123f3575f5ffd5b6123ff89828a016121bc565b9097509550506020870135612413816120bb565b935060408701356001600160401b0381111561242d575f5ffd5b61243989828a016121bc565b909450925050606087013561244d816120bb565b809150509295509295509295565b5f5f5f5f6040858703121561246e575f5ffd5b84356001600160401b03811115612483575f5ffd5b61248f878288016121bc565b90955093505060208501356001600160401b038111156124ad575f5ffd5b6124b9878288016121bc565b95989497509550505050565b634e487b7160e01b5f52601160045260245ffd5b6001600160801b038181168382160190811115610dd057610dd06124c5565b5f60208284031215612508575f5ffd5b815161139b816120bb565b6001600160801b038281168282160390811115610dd057610dd06124c5565b634e487b7160e01b5f52602160045260245ffd5b80820180821115610dd057610dd06124c5565b6001600160801b0385811682526020820185905283166040820152608081016002831061259457634e487b7160e01b5f52602160045260245ffd5b82606083015295945050505050565b634e487b7160e01b5f52604160045260245ffd5b604051601f8201601f191681016001600160401b03811182821017156125df576125df6125a3565b604052919050565b5f6001600160401b038311156125ff576125ff6125a3565b8260051b61260f602082016125b7565b84815290830190602081019036831115612627575f5ffd5b845b838110156126bf5780356001600160401b03811115612646575f5ffd5b860136601f820112612656575f5ffd5b80356001600160401b0381111561266f5761266f6125a3565b612682601f8201601f19166020016125b7565b818152366020838501011115612696575f5ffd5b816020840160208301375f60208383010152808652505050602083019250602081019050612629565b5095945050505050565b5f602082840312156126d9575f5ffd5b8151801515811461139b575f5ffd5b634e487b7160e01b5f52601260045260245ffd5b81810381811115610dd057610dd06124c5565b5f6020828403121561271f575f5ffd5b5051919050565b634e487b7160e01b5f52603260045260245ffd5b60018060a01b0383168152604060208201525f82518060408401528060208501606085015e5f606082850101526060601f19601f8301168401019150509392505050565b5f604082840312801561278f575f5ffd5b50604080519081016001600160401b03811182821017156127b2576127b26125a3565b60405282516127c0816120cf565b815260208301516127d0816120cf565b6020820152939250505056fea264697066735822122078ed433352f526840a0b8c77bca7d6e874c00661c532a78950e9d77d78164f8e64736f6c634300081c0033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000000755fbe4a24d7478bfcfc1e561afce82d1ff620000000000000000000000004d4c2c4777625e97be1985682fae5a53f5c44a80000000000000000000000000331b9182088e2a7d6d3fe4742aba1fb231aecc56c715e37300000000000000000000000000000000000000000000000000000000
-----Decoded View---------------
Arg [0] : _owner (address): 0x000755Fbe4A24d7478bfcFC1E561AfCE82d1ff62
Arg [1] : _registry (address): 0x4D4c2C4777625e97be1985682fAE5A53f5C44A80
Arg [2] : _rewardToken (address): 0x331B9182088e2A7d6D3Fe4742AbA1fB231aEcc56
Arg [3] : _protocolId (bytes4): 0xc715e373
-----Encoded View---------------
4 Constructor Arguments found :
Arg [0] : 000000000000000000000000000755fbe4a24d7478bfcfc1e561afce82d1ff62
Arg [1] : 0000000000000000000000004d4c2c4777625e97be1985682fae5a53f5c44a80
Arg [2] : 000000000000000000000000331b9182088e2a7d6d3fe4742aba1fb231aecc56
Arg [3] : c715e37300000000000000000000000000000000000000000000000000000000
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.