Contract Source Code:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IERC4626} from "@openzeppelin/contracts/interfaces/IERC4626.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import {IAccessHub} from "../interfaces/IAccessHub.sol";
import {IVoter} from "../interfaces/IVoter.sol";
import {IXShadow} from "../interfaces/IXShadow.sol";
import {IVoteModule} from "../interfaces/IVoteModule.sol";
import {IX33} from "../interfaces/IX33.sol";
import {Ix33Adapter} from "../interfaces/Ix33Adapter.sol";
import {Errors} from "contracts/libraries/Errors.sol";
/// @title Adapter for x33 to be able to vote on the new Voter
/// @dev this will become the new Operator for x33
contract x33Adapter is Ix33Adapter, ReentrancyGuard {
IVoter public immutable voter;
IX33 public immutable x33;
IXShadow public immutable xShadow;
address public immutable accessHub;
address public operator;
modifier onlyOperator() {
require(msg.sender == operator, Errors.NOT_AUTHORIZED(msg.sender));
_;
}
modifier onlyAccessHub() {
require(msg.sender == voter.accessHub(), Errors.NOT_ACCESSHUB());
_;
}
modifier update(address user) {
IAccessHub(accessHub).preX33UpdateHook(user);
_;
IAccessHub(accessHub).postX33UpdateHook();
}
constructor(address _x33, address _voter) {
operator = msg.sender;
x33 = IX33(_x33);
xShadow = IXShadow(IX33(_x33).xShadow());
voter = IVoter(_voter);
accessHub = IVoter(_voter).accessHub();
}
/// @inheritdoc Ix33Adapter
function submitVotes(address[] calldata _pools, uint256[] calldata _weights) external onlyOperator {
/// @dev cast vote on behalf of x33
IX33.AggregatorParams memory _params = IX33.AggregatorParams({
aggregator: address(voter),
tokenIn: address(this),
amountIn: 0,
minAmountOut: 0,
callData: abi.encodeWithSelector(IVoter.vote.selector, address(x33), _pools, _weights)
});
x33.swapIncentiveViaAggregator(_params);
}
/// @inheritdoc Ix33Adapter
function compound() external onlyOperator {
x33.compound();
}
/// @inheritdoc Ix33Adapter
function claimRebase() external onlyOperator {
x33.claimRebase();
}
/// @inheritdoc Ix33Adapter
function rebaseX33() external onlyOperator {
IAccessHub(x33.accessHub()).rebaseX33();
}
/// @inheritdoc Ix33Adapter
function claimIncentives(address[] calldata _feeDistributors, address[][] calldata _tokens) external onlyOperator {
x33.claimIncentives(_feeDistributors, _tokens);
}
/// @inheritdoc Ix33Adapter
function swapIncentiveViaAggregator(IX33.AggregatorParams calldata _params) external nonReentrant onlyOperator {
x33.swapIncentiveViaAggregator(_params);
}
/// @inheritdoc Ix33Adapter
function unlock() external onlyOperator {
x33.unlock();
}
/// @inheritdoc Ix33Adapter
function transferOperator(address _newOperator) external onlyAccessHub {
address currentOperator = operator;
/// @dev set the new operator
operator = _newOperator;
emit NewOperator(currentOperator, operator);
}
/// @inheritdoc Ix33Adapter
function rescue(address token) external onlyAccessHub {
IERC20(token).transfer(msg.sender, IERC20(token).balanceOf(address(this)));
}
/// @dev does nothing, just so x33 can call approve when voting
function approve(address, uint256) external pure returns (bool) {
return true;
}
//////////////////////////
/// IERC4626 Functions ///
//////////////////////////
// @TODO tests
function deposit(uint256 assets, address receiver) external update(msg.sender) returns (uint256 shares) {
// transfer xShadow to here before depositing for the user
xShadow.transferFrom(msg.sender, address(this), assets);
// approve xShadow to x33
xShadow.approve(address(x33), assets);
// deposit to x33 and send to receiver
return IERC4626(address(x33)).deposit(assets, receiver);
}
function mint(uint256 shares, address receiver) external update(msg.sender) returns (uint256 assets) {
// convert shares to assets to get the amount of xShadow needed, need to round up
assets = IERC4626(address(x33)).convertToAssets(shares) + 1;
// transfer xShadow to here before depositing for the user
xShadow.transferFrom(msg.sender, address(this), assets);
// approve xShadow to x33
xShadow.approve(address(x33), assets);
// deposit to x33 and send to receiver
return IERC4626(address(x33)).mint(shares, receiver);
}
/// @dev this isn't exactly compilant with ERC4626 because we can't maniulate approvals on x33 through here
/// so we do not allow withdrawing from another user other than the msg.sender
function withdraw(uint256 assets, address receiver) external update(msg.sender) returns (uint256 shares) {
return IERC4626(address(x33)).withdraw(assets, receiver, msg.sender);
}
/// @dev this isn't exactly compilant with ERC4626 because we can't maniulate approvals on x33 through here
/// so we do not allow withdrawing from another user other than the msg.sender
function redeem(uint256 shares, address receiver) external update(msg.sender) returns (uint256 assets) {
return IERC4626(address(x33)).redeem(shares, receiver, msg.sender);
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
import {IERC20Metadata} from "./extensions/IERC20Metadata.sol";
import {Context} from "../../utils/Context.sol";
import {IERC20Errors} from "../../interfaces/draft-IERC6093.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* The default value of {decimals} is 18. To change this, you should override
* this function so it returns a different value.
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC-20
* applications.
*/
abstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {
mapping(address account => uint256) private _balances;
mapping(address account => mapping(address spender => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the default value returned by this function, unless
* it's overridden.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `value`.
*/
function transfer(address to, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_transfer(owner, to, value);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `value` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Skips emitting an {Approval} event indicating an allowance update. This is not
* required by the ERC. See {xref-ERC20-_approve-address-address-uint256-bool-}[_approve].
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `value`.
* - the caller must have allowance for ``from``'s tokens of at least
* `value`.
*/
function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, value);
_transfer(from, to, value);
return true;
}
/**
* @dev Moves a `value` amount of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _transfer(address from, address to, uint256 value) internal {
if (from == address(0)) {
revert ERC20InvalidSender(address(0));
}
if (to == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(from, to, value);
}
/**
* @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
* (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
* this function.
*
* Emits a {Transfer} event.
*/
function _update(address from, address to, uint256 value) internal virtual {
if (from == address(0)) {
// Overflow check required: The rest of the code assumes that totalSupply never overflows
_totalSupply += value;
} else {
uint256 fromBalance = _balances[from];
if (fromBalance < value) {
revert ERC20InsufficientBalance(from, fromBalance, value);
}
unchecked {
// Overflow not possible: value <= fromBalance <= totalSupply.
_balances[from] = fromBalance - value;
}
}
if (to == address(0)) {
unchecked {
// Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
_totalSupply -= value;
}
} else {
unchecked {
// Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
_balances[to] += value;
}
}
emit Transfer(from, to, value);
}
/**
* @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
* Relies on the `_update` mechanism
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _mint(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(address(0), account, value);
}
/**
* @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
* Relies on the `_update` mechanism.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead
*/
function _burn(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidSender(address(0));
}
_update(account, address(0), value);
}
/**
* @dev Sets `value` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*
* Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
*/
function _approve(address owner, address spender, uint256 value) internal {
_approve(owner, spender, value, true);
}
/**
* @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.
*
* By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by
* `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any
* `Approval` event during `transferFrom` operations.
*
* Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to
* true using the following override:
*
* ```solidity
* function _approve(address owner, address spender, uint256 value, bool) internal virtual override {
* super._approve(owner, spender, value, true);
* }
* ```
*
* Requirements are the same as {_approve}.
*/
function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {
if (owner == address(0)) {
revert ERC20InvalidApprover(address(0));
}
if (spender == address(0)) {
revert ERC20InvalidSpender(address(0));
}
_allowances[owner][spender] = value;
if (emitEvent) {
emit Approval(owner, spender, value);
}
}
/**
* @dev Updates `owner` s allowance for `spender` based on spent `value`.
*
* Does not update the allowance value in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Does not emit an {Approval} event.
*/
function _spendAllowance(address owner, address spender, uint256 value) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
if (currentAllowance < value) {
revert ERC20InsufficientAllowance(spender, currentAllowance, value);
}
unchecked {
_approve(owner, spender, currentAllowance - value, false);
}
}
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (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/IERC4626.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../token/ERC20/IERC20.sol";
import {IERC20Metadata} from "../token/ERC20/extensions/IERC20Metadata.sol";
/**
* @dev Interface of the ERC-4626 "Tokenized Vault Standard", as defined in
* https://eips.ethereum.org/EIPS/eip-4626[ERC-4626].
*/
interface IERC4626 is IERC20, IERC20Metadata {
event Deposit(address indexed sender, address indexed owner, uint256 assets, uint256 shares);
event Withdraw(
address indexed sender,
address indexed receiver,
address indexed owner,
uint256 assets,
uint256 shares
);
/**
* @dev Returns the address of the underlying token used for the Vault for accounting, depositing, and withdrawing.
*
* - MUST be an ERC-20 token contract.
* - MUST NOT revert.
*/
function asset() external view returns (address assetTokenAddress);
/**
* @dev Returns the total amount of the underlying asset that is “managed” by Vault.
*
* - SHOULD include any compounding that occurs from yield.
* - MUST be inclusive of any fees that are charged against assets in the Vault.
* - MUST NOT revert.
*/
function totalAssets() external view returns (uint256 totalManagedAssets);
/**
* @dev Returns the amount of shares that the Vault would exchange for the amount of assets provided, in an ideal
* scenario where all the conditions are met.
*
* - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
* - MUST NOT show any variations depending on the caller.
* - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
* - MUST NOT revert.
*
* NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
* “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
* from.
*/
function convertToShares(uint256 assets) external view returns (uint256 shares);
/**
* @dev Returns the amount of assets that the Vault would exchange for the amount of shares provided, in an ideal
* scenario where all the conditions are met.
*
* - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
* - MUST NOT show any variations depending on the caller.
* - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
* - MUST NOT revert.
*
* NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
* “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
* from.
*/
function convertToAssets(uint256 shares) external view returns (uint256 assets);
/**
* @dev Returns the maximum amount of the underlying asset that can be deposited into the Vault for the receiver,
* through a deposit call.
*
* - MUST return a limited value if receiver is subject to some deposit limit.
* - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of assets that may be deposited.
* - MUST NOT revert.
*/
function maxDeposit(address receiver) external view returns (uint256 maxAssets);
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their deposit at the current block, given
* current on-chain conditions.
*
* - MUST return as close to and no more than the exact amount of Vault shares that would be minted in a deposit
* call in the same transaction. I.e. deposit should return the same or more shares as previewDeposit if called
* in the same transaction.
* - MUST NOT account for deposit limits like those returned from maxDeposit and should always act as though the
* deposit would be accepted, regardless if the user has enough tokens approved, etc.
* - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToShares and previewDeposit SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by depositing.
*/
function previewDeposit(uint256 assets) external view returns (uint256 shares);
/**
* @dev Mints shares Vault shares to receiver by depositing exactly amount of underlying tokens.
*
* - MUST emit the Deposit event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
* deposit execution, and are accounted for during deposit.
* - MUST revert if all of assets cannot be deposited (due to deposit limit being reached, slippage, the user not
* approving enough underlying tokens to the Vault contract, etc).
*
* NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
*/
function deposit(uint256 assets, address receiver) external returns (uint256 shares);
/**
* @dev Returns the maximum amount of the Vault shares that can be minted for the receiver, through a mint call.
* - MUST return a limited value if receiver is subject to some mint limit.
* - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of shares that may be minted.
* - MUST NOT revert.
*/
function maxMint(address receiver) external view returns (uint256 maxShares);
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their mint at the current block, given
* current on-chain conditions.
*
* - MUST return as close to and no fewer than the exact amount of assets that would be deposited in a mint call
* in the same transaction. I.e. mint should return the same or fewer assets as previewMint if called in the
* same transaction.
* - MUST NOT account for mint limits like those returned from maxMint and should always act as though the mint
* would be accepted, regardless if the user has enough tokens approved, etc.
* - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToAssets and previewMint SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by minting.
*/
function previewMint(uint256 shares) external view returns (uint256 assets);
/**
* @dev Mints exactly shares Vault shares to receiver by depositing amount of underlying tokens.
*
* - MUST emit the Deposit event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the mint
* execution, and are accounted for during mint.
* - MUST revert if all of shares cannot be minted (due to deposit limit being reached, slippage, the user not
* approving enough underlying tokens to the Vault contract, etc).
*
* NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
*/
function mint(uint256 shares, address receiver) external returns (uint256 assets);
/**
* @dev Returns the maximum amount of the underlying asset that can be withdrawn from the owner balance in the
* Vault, through a withdraw call.
*
* - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
* - MUST NOT revert.
*/
function maxWithdraw(address owner) external view returns (uint256 maxAssets);
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their withdrawal at the current block,
* given current on-chain conditions.
*
* - MUST return as close to and no fewer than the exact amount of Vault shares that would be burned in a withdraw
* call in the same transaction. I.e. withdraw should return the same or fewer shares as previewWithdraw if
* called
* in the same transaction.
* - MUST NOT account for withdrawal limits like those returned from maxWithdraw and should always act as though
* the withdrawal would be accepted, regardless if the user has enough shares, etc.
* - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToShares and previewWithdraw SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by depositing.
*/
function previewWithdraw(uint256 assets) external view returns (uint256 shares);
/**
* @dev Burns shares from owner and sends exactly assets of underlying tokens to receiver.
*
* - MUST emit the Withdraw event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
* withdraw execution, and are accounted for during withdraw.
* - MUST revert if all of assets cannot be withdrawn (due to withdrawal limit being reached, slippage, the owner
* not having enough shares, etc).
*
* Note that some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
* Those methods should be performed separately.
*/
function withdraw(uint256 assets, address receiver, address owner) external returns (uint256 shares);
/**
* @dev Returns the maximum amount of Vault shares that can be redeemed from the owner balance in the Vault,
* through a redeem call.
*
* - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
* - MUST return balanceOf(owner) if owner is not subject to any withdrawal limit or timelock.
* - MUST NOT revert.
*/
function maxRedeem(address owner) external view returns (uint256 maxShares);
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their redeemption at the current block,
* given current on-chain conditions.
*
* - MUST return as close to and no more than the exact amount of assets that would be withdrawn in a redeem call
* in the same transaction. I.e. redeem should return the same or more assets as previewRedeem if called in the
* same transaction.
* - MUST NOT account for redemption limits like those returned from maxRedeem and should always act as though the
* redemption would be accepted, regardless if the user has enough shares, etc.
* - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToAssets and previewRedeem SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by redeeming.
*/
function previewRedeem(uint256 shares) external view returns (uint256 assets);
/**
* @dev Burns exactly shares from owner and sends assets of underlying tokens to receiver.
*
* - MUST emit the Withdraw event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
* redeem execution, and are accounted for during redeem.
* - MUST revert if all of shares cannot be redeemed (due to withdrawal limit being reached, slippage, the owner
* not having enough shares, etc).
*
* NOTE: some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
* Those methods should be performed separately.
*/
function redeem(uint256 shares, address receiver, address owner) external returns (uint256 assets);
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
import {Address} from "../../../utils/Address.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/ReentrancyGuard.sol)
pragma solidity ^0.8.20;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,
* consider using {ReentrancyGuardTransient} instead.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant NOT_ENTERED = 1;
uint256 private constant ENTERED = 2;
uint256 private _status;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
constructor() {
_status = NOT_ENTERED;
}
/**
* @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 (_status == ENTERED) {
revert ReentrancyGuardReentrantCall();
}
// Any calls to nonReentrant after this point will fail
_status = ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = NOT_ENTERED;
}
/**
* @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 _status == ENTERED;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {IAccessControlEnumerable} from "@openzeppelin/contracts/access/extensions/IAccessControlEnumerable.sol";
import {IVoteModule} from "contracts/interfaces/IVoteModule.sol";
import {IVoter} from "contracts/interfaces/IVoter.sol";
interface IAccessHub0 {
/// @dev Struct to hold initialization parameters
struct InitParams {
address timelock;
address treasury;
address voter;
address minter;
address launcherPlugin;
address xShadow;
address x33;
address shadowV3PoolFactory;
address poolFactory;
address clGaugeFactory;
address gaugeFactory;
address feeRecipientFactory;
address feeDistributorFactory;
address feeCollector;
address voteModule;
address x33Adapter;
}
/// @notice initializing function for setting values in the AccessHub
function initialize(InitParams calldata params) external;
/// @notice function for reinitializing values in the AccessHub
function reinit(InitParams calldata params) external;
/// @notice function for adding expansion packs to AccessHub
function registerExpansionPack(address _newExpansionPack) external;
/// @notice function for replacing an expansion pack on AccessHub
function replaceExpansionPack(address _oldExpansionPack, address _newExpansionPack) external;
/// @notice function for removing expansion packs from AccessHub
function removeExpansionPack(address _expansionPack) external;
/// @notice returns all expansion packs
function getAllExpansionPacks() external view returns (address[] memory);
/// @notice returns expansion pack length
function getAllExpansionPackLength() external view returns (uint256);
/// @notice returns expansion pack at index
function getExpansionPack(uint256 index) external view returns (address);
/// @notice sets the swap fees for multiple pairs
function setSwapFees(address[] calldata _pools, uint24[] calldata _swapFees, bool[] calldata _concentrated)
external;
/// @notice sets the split of fees between LPs and voters
function setFeeSplitCL(address[] calldata _pools, uint8[] calldata _feeProtocol) external;
/// @notice sets the split of fees between LPs and voters for legacy pools
function setFeeSplitLegacy(address[] calldata _pools, uint256[] calldata _feeSplits) external;
/**
* Voter governance
*/
/// @notice sets a new governor address in the voter.sol contract
function setNewGovernorInVoter(address _newGovernor) external;
/// @notice sets a new governor address in the voter.sol contract
function setNewGovernorInOldVoter(address _newGovernor) external;
/// @notice whitelists a token for governance, or removes if boolean is set to false
function governanceWhitelist(address[] calldata _token, bool[] calldata _whitelisted) external;
/// @notice kills active gauges, removing them from earning further emissions, and claims their fees prior
function killGauge(address[] calldata _pairs) external;
/// @notice revives inactive/killed gauges
function reviveGauge(address[] calldata _pairs) external;
/// @notice sets a new NFP Manager
function setNfpManager(address _nfpManager) external;
/// @notice syncs NFP Managers for gauges
function syncNfpManager(address[] calldata gauges) external;
/// @notice sets the ratio of xShadow/Shadow awarded globally to LPs
function setEmissionsRatioInVoter(uint256 _pct) external;
/// @notice sets the ratio of xShadow/Shadow awarded globally to LPs
function setEmissionsRatioInOldVoter(uint256 _pct) external;
/// @notice allows governance to retrieve emissions in the voter contract that will not be distributed due to the gauge being inactive
/// @dev allows per-period retrieval for granularity
function retrieveStuckEmissionsToGovernance(address _gauge, uint256 _period) external;
/// @notice allows governance to retrieve emissions in the voter contract that will not be distributed due to the gauge being inactive
/// @dev allows per-period retrieval for granularity
function retrieveStuckEmissionsToGovernanceFromOldVoter(address _gauge, uint256 _period) external;
/// @notice allows governance to designate a gauge as the "main" one, to prevent governance spam and confusion
function setMainGaugeForClPair(address tokenA, address tokenB, address gauge) external;
function createGaugeForPool(address _pool) external;
function resetVotesOnBehalfOf(address _user) external;
function pokeVotesOnBehalfOf(address _user) external;
function votesOnBehalfOf(address _user, address[] calldata _pools, uint256[] calldata _weights) external;
/**
* Reward List Functions
*/
/// @notice function for removing rewards for feeDistributors
function removeFeeDistributorRewards(address[] calldata _pools, address[] calldata _rewards) external;
/**
* FeeCollector functions
*/
/// @notice Sets the treasury address to a new value.
/// @param newTreasury The new address to set as the treasury.
function setTreasuryInFeeCollector(address newTreasury) external;
/// @notice Sets the value of treasury fees to a new amount.
/// @param _treasuryFees The new amount of treasury fees to be set.
function setTreasuryFeesInFeeCollector(uint256 _treasuryFees) external;
/**
* FeeRecipientFactory functions
*/
/// @notice set the fee % to be sent to the treasury
/// @param _feeToTreasury the fee % to be sent to the treasury
function setFeeToTreasuryInFeeRecipientFactory(uint256 _feeToTreasury) external;
/// @notice set a new treasury address
/// @param _treasury the new address
function setTreasuryInFeeRecipientFactory(address _treasury) external;
/**
* CL Pool Factory functions
*/
/// @notice enables a tickSpacing with the given initialFee amount
/// @dev unlike UniswapV3, we map via the tickSpacing rather than the fee tier
/// @dev tickSpacings may never be removed once enabled
/// @param tickSpacing The spacing between ticks to be enforced for all pools created
/// @param initialFee The initial fee amount, denominated in hundredths of a bip (i.e. 1e-6)
function enableTickSpacing(int24 tickSpacing, uint24 initialFee) external;
/// @notice sets the feeProtocol (feeSplit) for new CL pools and stored in the factory
function setGlobalClFeeProtocol(uint8 _feeProtocolGlobal) external;
/// @notice sets the address of the voter in the v3 factory for gauge fee setting
function setVoterAddressInFactoryV3(address _voter) external;
/// @notice sets the address of the feeCollector in the v3 factory for fee routing
function setFeeCollectorInFactoryV3(address _newFeeCollector) external;
/**
* Legacy Pool Factory functions
*/
/// @notice sets the treasury address in the legacy factory
function setTreasuryInLegacyFactory(address _treasury) external;
/// @notice enables or disables if there is a feeSplit when no gauge for legacy pairs
function setFeeSplitWhenNoGauge(bool status) external;
/// @notice set the default feeSplit in the legacy factory
function setLegacyFeeSplitGlobal(uint256 _feeSplit) external;
/// @notice set the fee recipient for legacy pairs
function setLegacyFeeRecipient(address _pair, address _feeRecipient) external;
/// @notice set the default swap fee for legacy pools
function setLegacyFeeGlobal(uint256 _fee) external;
/// @notice sets whether a pair can have skim() called or not for rebasing purposes
function setSkimEnabledLegacy(address _pair, bool _status) external;
/**
* VoteModule Functions
*/
/// @notice sets addresses as exempt or removes their exemption
function setCooldownExemption(address[] calldata _candidates, bool[] calldata _exempt) external;
/// @notice function to change the cooldown in the voteModule
function setNewVoteModuleCooldown(uint256 _newCooldown) external;
/// @notice allows resetting of inactive votes to prevent dead votes
function kickInactive(address[] calldata _nonparticipants) external;
/**
* Timelock gated functions
*/
/// @notice timelock gated payload execution in case tokens get stuck or other unexpected behaviors
function execute(address _target, bytes calldata _payload) external;
/// @notice timelock gated function to change the timelock
function setNewTimelock(address _timelock) external;
/// @notice function for initializing the voter contract with its dependencies
function initializeVoter(IVoter.InitializationParams memory inputs) external;
/// @notice backup distribute
function backupDistribute() external;
/// @notice backup distribute batch
function backupDistributeBatch(uint256 startIndex, uint256 batchSize) external;
/// @notice process required state changes before x33 updates
function preX33UpdateHook(address user) external;
/// @notice process required state changes after x33 updates
function postX33UpdateHook() external;
/// @notice allow distributing emissions via the accessHub
function notifyEmissions(address[] calldata pools, uint256[] calldata emissions) external;
/// @notice rescues token from Access Hub
function rescue(address token) external;
/// @notice rescues token from x33
function rescueFromX33(address _token, uint256 _amount) external;
/// @notice rescues token from x33 adapater
function rescueFromX33Adapter(address _token) external;
}
interface IAccessHub1 {
/// @notice protocol timelock address
function timelock() external view returns (address timelock);
/// @notice protocol treasury address
function treasury() external view returns (address treasury);
/// @notice central voter contract
function voter() external view returns (address);
/// @notice weekly emissions minter
function minter() external view returns (address);
/// @notice launchpad plugin for augmenting feeshare
function launcherPlugin() external view returns (address);
/// @notice xShadow contract
function xShadow() external view returns (address);
/// @notice X33 contract
function x33() external view returns (address);
/// @notice adapter for X33 contract
function x33Adapter() external view returns (address);
/// @notice CL V3 factory
function shadowV3PoolFactory() external view returns (address);
/// @notice legacy pair factory
function poolFactory() external view returns (address);
/// @notice legacy fees holder contract
function feeRecipientFactory() external view returns (address);
/// @notice fee collector contract
function feeCollector() external view returns (address);
/// @notice voteModule contract
function voteModule() external view returns (address);
/// @notice NFPManager contract
function nfpManager() external view returns (address);
/// @notice concentrated (v3) gauge factory
function clGaugeFactory() external view returns (address _clGaugeFactory);
/// @notice legacy gauge factory address
function gaugeFactory() external view returns (address _gaugeFactory);
/// @notice the feeDistributor factory address
function feeDistributorFactory() external view returns (address _feeDistributorFactory);
/**
* xShadow Functions
*/
/// @notice enables or disables the transfer whitelist in xShadow
function transferWhitelistInXShadow(address[] calldata _who, bool[] calldata _whitelisted) external;
/// @notice enables or disables the transfer TO whitelists in xShadow
function transferToWhitelistInXShadow(address[] calldata _who, bool[] calldata _whitelisted) external;
/// @notice enables or disables the governance in xShadow
function toggleXShadowGovernance(bool enable) external;
/// @notice allows redemption from the operator
function operatorRedeemXShadow(uint256 _amount) external;
/// @notice migrates the xShadow operator
function migrateOperator(address _operator) external;
/// @notice rescues any trapped tokens in xShadow
function rescueTrappedTokens(address[] calldata _tokens, uint256[] calldata _amounts) external;
/// @notice set dust threshold before a rebase can happen
function setRebaseThreshold(uint256 _newThreshold) external;
/**
* LauncherPlugin specific functions
*/
/// @notice allows migrating the parameters from one pool to the other
/// @param _oldPool the current address of the pair
/// @param _newPool the new pool's address
function migratePoolInLauncherPlugin(address _oldPool, address _newPool) external;
/// @notice set launcher configurations for a pool
/// @param _pool address of the pool
/// @param _take the fee that goes to the designated recipient
/// @param _recipient the address that receives the fees
function setConfigsInLauncherPlugin(address _pool, uint256 _take, address _recipient) external;
/// @notice enables the pool for LauncherConfigs
/// @param _pool address of the pool
function enablePoolInLauncherPlugin(address _pool) external;
/// @notice disables the pool for LauncherConfigs
/// @dev clears mappings
/// @param _pool address of the pool
function disablePoolInLauncherPlugin(address _pool) external;
/// @notice sets a new operator address
/// @param _newOperator new operator address
function setOperatorInLauncherPlugin(address _newOperator) external;
/// @notice gives authority to a new contract/address
/// @param _newAuthority the suggested new authority
function grantAuthorityInLauncherPlugin(address _newAuthority, string calldata _label) external;
/// @notice governance ability to label each authority in the system with an arbitrary string
function labelAuthorityInLauncherPlugin(address _authority, string calldata _label) external;
/// @notice removes authority from a contract/address
/// @param _oldAuthority the to-be-removed authority
function revokeAuthorityInLauncherPlugin(address _oldAuthority) external;
/**
* X33 Functions
*/
/// @notice transfers the x33 operator address
function transferOperatorInX33(address _newOperator) external;
/// @notice whitelists aggregators in x33
function whitelistAggregatorInX33(address _newAggregator) external;
/**
* Minter Functions
*/
/// @notice sets the inflation multiplier
/// @param _multiplier the multiplier
function setEmissionsMultiplierInMinter(uint256 _multiplier) external;
/// @notice sets the inflation multiplier
/// @param _multiplier the multiplier
function setEmissionsMultiplierInOldMinter(uint256 _multiplier) external;
///////////////////////////
/// Unordered Functions ///
///////////////////////////
// These functions are not ordered according to contracts since AccessHub is full
/// @notice poke votes for multiple users
function pokeVotesOnBehalfOf(address[] calldata _users) external;
/// @notice rebase using x33 tokens within the x33 contract
function rebaseX33() external;
/// @notice flash operations that needs a helper contract
function flashExpand(address _flashExpansion, bytes memory data) external;
/// @notice whitelist new gauge and fee distributor
function whitelistGaugeAndFeeDistributorOnXShadow(address gauge, address feeDistributor) external;
/// @notice create gauge on new voter
function migrateGauges(address[] calldata gauges) external;
}
interface IAccessHubTemp {
function registerExpansionPack2(address _newExpansionPack) external;
function replaceExpansionPack2(address _oldExpansionPack, address _newExpansionPack) external;
function removeExpansionPack2(address _expansionPack) external;
function flashExpand2(address _flashExpansion, bytes memory data) external;
/// @notice migrates fees to marble
function migrateGaugeToMarble(address[] calldata gauges) external;
}
interface IAccessHub is IAccessControlEnumerable, IAccessHub0, IAccessHub1 {
function DEFAULT_ADMIN_ROLE() external view returns (bytes32);
function SWAP_FEE_SETTER() external view returns (bytes32);
function PROTOCOL_OPERATOR() external view returns (bytes32);
/// @notice central voter contract
function oldVoter() external view returns (address);
/// @notice weekly emissions minter
function oldMinter() external view returns (address);
/// @notice launchpad plugin for augmenting feeshare
function oldLauncherPlugin() external view returns (address);
/// @notice legacy fees holder contract
function oldFeeRecipientFactory() external view returns (address);
/// @notice fee collector contract
function oldFeeCollector() external view returns (address);
/// @notice concentrated (v3) gauge factory
function oldClGaugeFactory() external view returns (address);
/// @notice legacy gauge factory address
function oldGaugeFactory() external view returns (address);
/// @notice the feeDistributor factory address
function oldFeeDistributorFactory() external view returns (address);
}
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;
pragma abicoder v2;
interface IVoter {
event GaugeCreated(address indexed gauge, address creator, address feeDistributor, address indexed pool);
event GaugeKilled(address indexed gauge);
event GaugeRevived(address indexed gauge);
event Voted(address indexed owner, uint256 weight, address indexed pool);
event Abstained(address indexed owner, uint256 weight);
event Deposit(address indexed lp, address indexed gauge, address indexed owner, uint256 amount);
event Withdraw(address indexed lp, address indexed gauge, address indexed owner, uint256 amount);
event NotifyReward(address indexed sender, address indexed reward, uint256 amount);
event DistributeReward(address indexed sender, address indexed gauge, uint256 amount);
event EmissionsRatio(address indexed caller, uint256 oldRatio, uint256 newRatio);
event NewGovernor(address indexed sender, address indexed governor);
event Whitelisted(address indexed whitelister, address indexed token);
event WhitelistRevoked(address indexed forbidder, address indexed token, bool status);
event MainTickSpacingChanged(address indexed token0, address indexed token1, int24 indexed newMainTickSpacing);
event Poke(address indexed user);
event EmissionsRedirected(address indexed sourceGauge, address indexed destinationGauge);
struct InitializationParams {
address shadow;
address legacyFactory;
address gauges;
address feeDistributorFactory;
address minter;
address msig;
address xShadow;
address clFactory;
address clGaugeFactory;
address nfpManager;
address feeRecipientFactory;
address voteModule;
address launcherPlugin;
address poolUpdater;
}
function initialize(InitializationParams memory inputs) external;
/// @notice denominator basis
function BASIS() external view returns (uint256);
/// @notice ratio of xShadow emissions globally
function xRatio() external view returns (uint256);
/// @notice xShadow contract address
function xShadow() external view returns (address);
/// @notice legacy factory address (uni-v2/stableswap)
function legacyFactory() external view returns (address);
/// @notice concentrated liquidity factory
function clFactory() external view returns (address);
/// @notice gauge factory for CL
function clGaugeFactory() external view returns (address);
/// @notice pool updater for CL
function poolUpdater() external view returns (address);
/// @notice legacy fee recipient factory
function feeRecipientFactory() external view returns (address);
/// @notice peripheral NFPManager contract
function nfpManager() external view returns (address);
/// @notice returns the address of the current governor
/// @return _governor address of the governor
function governor() external view returns (address _governor);
/// @notice the address of the vote module
/// @return _voteModule the vote module contract address
function voteModule() external view returns (address _voteModule);
/// @notice address of the central access Hub
function accessHub() external view returns (address);
/// @notice the address of the shadow launcher plugin to enable third party launchers
/// @return _launcherPlugin the address of the plugin
function launcherPlugin() external view returns (address _launcherPlugin);
/// @notice distributes emissions from the minter to the voter
/// @param amount the amount of tokens to notify
function notifyRewardAmount(uint256 amount) external;
/// @notice distributes the emissions for a specific gauge
/// @param _gauge the gauge address
function distribute(address _gauge) external;
/// @notice returns the address of the gauge factory
/// @param _gaugeFactory gauge factory address
function gaugeFactory() external view returns (address _gaugeFactory);
/// @notice returns the address of the feeDistributor factory
/// @return _feeDistributorFactory feeDist factory address
function feeDistributorFactory() external view returns (address _feeDistributorFactory);
/// @notice returns the address of the minter contract
/// @return _minter address of the minter
function minter() external view returns (address _minter);
/// @notice check if the gauge is active for governance use
/// @param _gauge address of the gauge
/// @return _trueOrFalse if the gauge is alive
function isAlive(address _gauge) external view returns (bool _trueOrFalse);
/// @notice allows the token to be paired with other whitelisted assets to participate in governance
/// @param _token the address of the token
function whitelist(address _token) external;
/// @notice effectively disqualifies a token from governance
/// @param _token the address of the token
function revokeWhitelist(address _token) external;
/// @notice returns if the address is a gauge
/// @param gauge address of the gauge
/// @return _trueOrFalse boolean if the address is a gauge
function isGauge(address gauge) external view returns (bool _trueOrFalse);
/// @notice disable a gauge from governance
/// @param _gauge address of the gauge
function killGauge(address _gauge) external;
/// @notice re-activate a dead gauge
/// @param _gauge address of the gauge
function reviveGauge(address _gauge) external;
/// @notice re-cast a tokenID's votes
/// @param owner address of the owner
function poke(address owner) external;
/// @notice sets the main destinationGauge of a token pairing
/// @param tokenA address of tokenA
/// @param tokenB address of tokenB
/// @param destinationGauge the main gauge to set to
function redirectEmissions(address tokenA, address tokenB, address destinationGauge) external;
/// @notice returns if the address is a fee distributor
/// @param _feeDistributor address of the feeDist
/// @return _trueOrFalse if the address is a fee distributor
function isFeeDistributor(address _feeDistributor) external view returns (bool _trueOrFalse);
/// @notice returns the address of the emission's token
/// @return _shadow emissions token contract address
function shadow() external view returns (address _shadow);
/// @notice returns the address of the pool's gauge, if any
/// @param _pool pool address
/// @return _gauge gauge address
function gaugeForPool(address _pool) external view returns (address _gauge);
/// @notice returns the address of the pool's feeDistributor, if any
/// @param _gauge address of the gauge
/// @return _feeDistributor address of the pool's feedist
function feeDistributorForGauge(address _gauge) external view returns (address _feeDistributor);
/// @notice returns the gauge address of a CL pool
/// @param tokenA address of token A in the pair
/// @param tokenB address of token B in the pair
/// @param tickSpacing tickspacing of the pool
/// @return gauge address of the gauge
function gaugeForClPool(address tokenA, address tokenB, int24 tickSpacing) external view returns (address gauge);
/// @notice returns the array of all tickspacings for the tokenA/tokenB combination
/// @param tokenA address of token A in the pair
/// @param tokenB address of token B in the pair
/// @return _ts array of all the tickspacings
function tickSpacingsForPair(address tokenA, address tokenB) external view returns (int24[] memory _ts);
/// @notice returns the destination of a gauge redirect
/// @param gauge address of gauge
function gaugeRedirect(address gauge) external view returns (address);
/// @notice returns the block.timestamp divided by 1 week in seconds
/// @return period the period used for gauges
function getPeriod() external view returns (uint256 period);
/// @notice cast a vote to direct emissions to gauges and earn incentives
/// @param owner address of the owner
/// @param _pools the list of pools to vote on
/// @param _weights an arbitrary weight per pool which will be normalized to 100% regardless of numerical inputs
function vote(address owner, address[] calldata _pools, uint256[] calldata _weights) external;
/// @notice reset the vote of an address
/// @param owner address of the owner
function reset(address owner) external;
/// @notice set the governor address
/// @param _governor the new governor address
function setGovernor(address _governor) external;
/// @notice recover stuck emissions
/// @param _gauge the gauge address
/// @param _period the period
function stuckEmissionsRecovery(address _gauge, uint256 _period) external;
/// @notice creates a legacy gauge for the pool
/// @param _pool pool's address
/// @return _gauge address of the new gauge
function createGauge(address _pool) external returns (address _gauge);
/// @notice create a concentrated liquidity gauge
/// @param tokenA the address of tokenA
/// @param tokenB the address of tokenB
/// @param tickSpacing the tickspacing of the pool
/// @return _clGauge address of the new gauge
function createCLGauge(address tokenA, address tokenB, int24 tickSpacing) external returns (address _clGauge);
/// @notice claim concentrated liquidity gauge rewards for specific NFP token ids
/// @param _gauges array of gauges
/// @param _tokens two dimensional array for the tokens to claim
/// @param _nfpTokenIds two dimensional array for the NFPs
function claimClGaugeRewards(
address[] calldata _gauges,
address[][] calldata _tokens,
uint256[][] calldata _nfpTokenIds
) external;
/// @notice claim arbitrary rewards from specific feeDists
/// @param owner address of the owner
/// @param _feeDistributors address of the feeDists
/// @param _tokens two dimensional array for the tokens to claim
function claimIncentives(address owner, address[] calldata _feeDistributors, address[][] calldata _tokens)
external;
/// @notice claim arbitrary rewards from specific feeDists and break up legacy pairs
/// @param owner address of the owner
/// @param _feeDistributors address of the feeDists
/// @param _tokens two dimensional array for the tokens to claim
function claimLegacyIncentives(address owner, address[] calldata _feeDistributors, address[][] calldata _tokens)
external;
/// @notice claim arbitrary rewards from specific gauges
/// @param _gauges address of the gauges
/// @param _tokens two dimensional array for the tokens to claim
function claimRewards(address[] calldata _gauges, address[][] calldata _tokens) external;
/// @notice claim arbitrary rewards from specific legacy gauges, and exit to shadow
/// @param _gauges address of the gauges
/// @param _tokens two dimensional array for the tokens to claim
function claimLegacyRewardsAndExit(address[] calldata _gauges, address[][] calldata _tokens) external;
/// @notice claim arbitrary rewards from specific cl gauges, and exit to shadow
/// @param _gauges address of the gauges
/// @param _tokens two dimensional array for the tokens to claim
/// @param _nfpTokenIds two dimensional array for the nfp to claim
function claimClGaugeRewardsAndExit(
address[] memory _gauges,
address[][] memory _tokens,
uint256[][] memory _nfpTokenIds
) external;
/// @notice distribute emissions to a gauge for a specific period
/// @param _gauge address of the gauge
/// @param _period value of the period
function distributeForPeriod(address _gauge, uint256 _period) external;
/// @notice attempt distribution of emissions to all gauges
function distributeAll() external;
/// @notice distribute emissions to gauges by index
/// @param startIndex start of the loop
/// @param endIndex end of the loop
function batchDistributeByIndex(uint256 startIndex, uint256 endIndex) external;
/// @notice lets governance update lastDistro period for a gauge
/// @dev should only be used if distribute() is running out of gas
/// @dev gaugePeriodDistributed will stop double claiming
/// @param _gauge gauge to update
/// @param _period period to update to
function updateLastDistro(address _gauge, uint256 _period) external;
/// @notice returns the votes cast for a tokenID
/// @param owner address of the owner
/// @return votes an array of votes casted
/// @return weights an array of the weights casted per pool
function getVotes(address owner, uint256 period)
external
view
returns (address[] memory votes, uint256[] memory weights);
/// @notice returns an array of all the pools
/// @return _pools the array of pools
function getAllPools() external view returns (address[] memory _pools);
/// @notice returns the length of pools
function getPoolsLength() external view returns (uint256);
/// @notice returns the pool at index
function getPool(uint256 index) external view returns (address);
/// @notice returns an array of all the gauges
/// @return _gauges the array of gauges
function getAllGauges() external view returns (address[] memory _gauges);
/// @notice returns the length of gauges
function getGaugesLength() external view returns (uint256);
/// @notice returns the gauge at index
function getGauge(uint256 index) external view returns (address);
/// @notice returns an array of all the feeDists
/// @return _feeDistributors the array of feeDists
function getAllFeeDistributors() external view returns (address[] memory _feeDistributors);
/// @notice sets the xShadowRatio default
function setGlobalRatio(uint256 _xRatio) external;
/// @notice whether the token is whitelisted in governance
function isWhitelisted(address _token) external view returns (bool _tf);
/// @notice function for removing malicious or stuffed tokens
function removeFeeDistributorReward(address _feeDist, address _token) external;
/// @notice returns the total votes for a pool in a specific period
/// @param pool the pool address to check
/// @param period the period to check
/// @return votes the total votes for the pool in that period
function poolTotalVotesPerPeriod(address pool, uint256 period) external view returns (uint256 votes);
/// @notice returns the pool address for a given gauge
/// @param gauge address of the gauge
/// @return pool address of the pool
function poolForGauge(address gauge) external view returns (address pool);
/// @notice returns the pool address for a given feeDistributor
/// @param feeDistributor address of the feeDistributor
/// @return pool address of the pool
function poolForFeeDistributor(address feeDistributor) external view returns (address pool);
/// @notice returns the voting power used by a voter for a period
/// @param user address of the user
/// @param period the period to check
function userVotingPowerPerPeriod(address user, uint256 period) external view returns (uint256 votingPower);
/// @notice returns the total votes for a specific period
/// @param period the period to check
/// @return weight the total votes for that period
function totalVotesPerPeriod(uint256 period) external view returns (uint256 weight);
/// @notice returns the total rewards allocated for a specific period
/// @param period the period to check
/// @return amount the total rewards for that period
function totalRewardPerPeriod(uint256 period) external view returns (uint256 amount);
/// @notice returns the last distribution period for a gauge
/// @param _gauge address of the gauge
/// @return period the last period distributions occurred
function lastDistro(address _gauge) external view returns (uint256 period);
/// @notice returns if the gauge is a Cl gauge
/// @param gauge the gauge to check
function isClGauge(address gauge) external view returns (bool);
/// @notice returns if the gauge is a legacy gauge
/// @param gauge the gauge to check
function isLegacyGauge(address gauge) external view returns (bool);
/// @notice sets a new NFP manager
function setNfpManager(address _nfpManager) external;
}
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IVoter} from "./IVoter.sol";
import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";
interface IXShadow is IERC20 {
struct VestPosition {
/// @dev amount of xShadow
uint256 amount;
/// @dev start unix timestamp
uint256 start;
/// @dev start + MAX_VEST (end timestamp)
uint256 maxEnd;
/// @dev vest identifier (starting from 0)
uint256 vestID;
}
event CancelVesting(address indexed user, uint256 indexed vestId, uint256 amount);
event ExitVesting(address indexed user, uint256 indexed vestId, uint256 amount);
event InstantExit(address indexed user, uint256);
event NewSlashingPenalty(uint256 penalty);
event NewVest(address indexed user, uint256 indexed vestId, uint256 indexed amount);
event NewVestingTimes(uint256 min, uint256 max);
event Converted(address indexed user, uint256);
event Exemption(address indexed candidate, bool status, bool success);
event XShadowRedeemed(address indexed user, uint256);
event NewOperator(address indexed o, address indexed n);
event Rebase(address indexed caller, uint256 amount);
event NewRebaseThreshold(uint256 threshold);
/// @notice returns info on a user's vests
function vestInfo(address user, uint256)
external
view
returns (uint256 amount, uint256 start, uint256 maxEnd, uint256 vestID);
/// @notice address of the shadow token
function SHADOW() external view returns (IERC20);
/// @notice address of the voter
function VOTER() external view returns (IVoter);
function MINTER() external view returns (address);
function ACCESS_HUB() external view returns (address);
/// @notice address of the operator
function operator() external view returns (address);
/// @notice address of the VoteModule
function VOTE_MODULE() external view returns (address);
/// @notice max slashing amount
function SLASHING_PENALTY() external view returns (uint256);
/// @notice denominator
function BASIS() external view returns (uint256);
/// @notice the minimum vesting length
function MIN_VEST() external view returns (uint256);
/// @notice the maximum vesting length
function MAX_VEST() external view returns (uint256);
function shadow() external view returns (address);
/// @notice the last period rebases were distributed
function lastDistributedPeriod() external view returns (uint256);
/// @notice amount of pvp rebase penalties accumulated pending to be distributed
function pendingRebase() external view returns (uint256);
/// @notice dust threshold before a rebase can happen
function rebaseThreshold() external view returns (uint256);
/// @notice pauses the contract
function pause() external;
/// @notice unpauses the contract
function unpause() external;
/**
*
*/
// General use functions
/**
*
*/
/// @dev mints xShadows for each shadow.
function convertEmissionsToken(uint256 _amount) external;
/// @notice function called by the minter to send the rebases once a week
function rebase() external;
/**
* @dev exit instantly with a penalty
* @param _amount amount of xShadows to exit
*/
function exit(uint256 _amount) external returns (uint256 _exitedAmount);
/// @dev vesting xShadows --> emissionToken functionality
function createVest(uint256 _amount) external;
/// @dev handles all situations regarding exiting vests
function exitVest(uint256 _vestID) external;
/**
*
*/
// Permissioned functions, timelock/operator gated
/**
*
*/
/// @dev allows the operator to redeem collected xShadows
function operatorRedeem(uint256 _amount) external;
/// @dev allows rescue of any non-stake token
function rescueTrappedTokens(address[] calldata _tokens, uint256[] calldata _amounts) external;
/// @notice migrates the operator to another contract
function migrateOperator(address _operator) external;
/// @notice set exemption status for an address
function setExemption(address[] calldata _exemptee, bool[] calldata _exempt) external;
function setExemptionTo(address[] calldata _exemptee, bool[] calldata _exempt) external;
/// @notice set dust threshold before a rebase can happen
function setRebaseThreshold(uint256 _newThreshold) external;
/**
*
*/
// Getter functions
/**
*
*/
/// @notice returns the amount of SHADOW within the contract
function getBalanceResiding() external view returns (uint256);
/// @notice returns the total number of individual vests the user has
function usersTotalVests(address _who) external view returns (uint256 _numOfVests);
/// @notice whether the address is exempt
/// @param _who who to check
/// @return _exempt whether it's exempt
function isExempt(address _who) external view returns (bool _exempt);
/// @notice returns the vest info for a user
/// @param _who who to check
/// @param _vestID vest ID to check
/// @return VestPosition vest info
function getVestInfo(address _who, uint256 _vestID) external view returns (VestPosition memory);
}
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;
interface IVoteModule {
/**
* Events
*/
event Deposit(address indexed from, uint256 amount);
event Withdraw(address indexed from, uint256 amount);
event NotifyReward(address indexed from, uint256 amount);
event ClaimRewards(address indexed from, uint256 amount);
event ExemptedFromCooldown(address indexed candidate, bool status);
event NewDuration(uint256 oldDuration, uint256 newDuration);
event NewCooldown(uint256 oldCooldown, uint256 newCooldown);
event Delegate(address indexed delegator, address indexed delegatee, bool indexed isAdded);
event SetAdmin(address indexed owner, address indexed operator, bool indexed isAdded);
/**
* Functions
*/
function delegates(address) external view returns (address);
/// @notice mapping for admins for a specific address
/// @param owner the owner to check against
/// @return operator the address that is designated as an admin/operator
function admins(address owner) external view returns (address operator);
function accessHub() external view returns (address);
/// @notice reward supply for a period
function rewardSupply(uint256 period) external view returns (uint256);
/// @notice user claimed reward amount for a period
/// @dev same mapping order as FeeDistributor so the name is a bit odd
function userClaimed(uint256 period, address owner) external view returns (uint256);
/// @notice last claimed period for a user
function userLastClaimPeriod(address owner) external view returns (uint256);
/// @notice returns the current period
function getPeriod() external view returns (uint256);
/// @notice returns the amount of unclaimed rebase earned by the user
function earned(address account) external view returns (uint256 _reward);
/// @notice returns the amount of unclaimed rebase earned by the user for a period
function periodEarned(uint256 period, address user) external view returns (uint256 amount);
/// @notice the time which users can deposit and withdraw
function unlockTime() external view returns (uint256 _timestamp);
/// @notice claims pending rebase rewards
function getReward() external;
/// @notice claims pending rebase rewards for a period
function getPeriodReward(uint256 period) external;
/// @notice allows users to set their own last claimed period in case they haven't claimed in a while
/// @param period the new period to start loops from
function setUserLastClaimPeriod(uint256 period) external;
/// @notice deposits all xShadow in the caller's wallet
function depositAll() external;
/// @notice deposit a specified amount of xShadow
function deposit(uint256 amount) external;
/// @notice withdraw all xShadow
function withdrawAll() external;
/// @notice withdraw a specified amount of xShadow
function withdraw(uint256 amount) external;
/// @notice check for admin perms
/// @param operator the address to check
/// @param owner the owner to check against for permissions
function isAdminFor(address operator, address owner) external view returns (bool approved);
/// @notice check for delegations
/// @param delegate the address to check
/// @param owner the owner to check against for permissions
function isDelegateFor(address delegate, address owner) external view returns (bool approved);
/// @notice used by the xShadow contract to notify pending rebases
/// @param amount the amount of Shadow to be notified from exit penalties
function notifyRewardAmount(uint256 amount) external;
/// @notice the address of the xShadow token (staking/voting token)
/// @return _xShadow the address
function xShadow() external view returns (address _xShadow);
/// @notice address of the voter contract
/// @return _voter the voter contract address
function voter() external view returns (address _voter);
/// @notice returns the total voting power (equal to total supply in the VoteModule)
/// @return _totalSupply the total voting power
function totalSupply() external view returns (uint256 _totalSupply);
/// @notice voting power
/// @param user the address to check
/// @return amount the staked balance
function balanceOf(address user) external view returns (uint256 amount);
/// @notice delegate voting perms to another address
/// @param delegatee who you delegate to
/// @dev set address(0) to revoke
function delegate(address delegatee) external;
/// @notice give admin permissions to a another address
/// @param operator the address to give administrative perms to
/// @dev set address(0) to revoke
function setAdmin(address operator) external;
function cooldownExempt(address) external view returns (bool);
function setCooldownExemption(address, bool) external;
/// @notice lock period after rebase starts accruing
function cooldown() external returns (uint256);
function setNewCooldown(uint256) external;
}
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IXShadow} from "contracts/interfaces/IXShadow.sol";
interface IX33 is IERC20 {
/// @dev parameters passed to the aggregator swap
struct AggregatorParams {
address aggregator; // address of the whitelisted aggregator
address tokenIn; // token to swap from
uint256 amountIn; // amount of tokenIn to swap
uint256 minAmountOut; // minimum amount of tokenOut to receive
bytes callData; // encoded swap calldata
}
event Entered(address indexed user, uint256 amount, uint256 ratioAtDeposit);
event Exited(address indexed user, uint256 _outAmount, uint256 ratioAtWithdrawal);
event NewOperator(address _oldOperator, address _newOperator);
event Compounded(uint256 oldRatio, uint256 newRatio, uint256 amount);
event SwappedBribe(address indexed operator, address indexed tokenIn, uint256 amountIn, uint256 amountOut);
event Rebased(uint256 oldRatio, uint256 newRatio, uint256 amount);
/// @notice Event emitted when an aggregator's whitelist status changes
event AggregatorWhitelistUpdated(address aggregator, bool status);
event Unlocked(uint256 _ts);
event UpdatedIndex(uint256 _index);
event ClaimedIncentives(address[] feeDistributors, address[][] tokens);
function whitelistedAggregators(address aggregator) external returns (bool);
/// @notice submits the optimized votes for the epoch
function submitVotes(address[] calldata _pools, uint256[] calldata _weights) external;
/// @notice swap function using aggregators to process rewards into SHADOW
function swapIncentiveViaAggregator(AggregatorParams calldata _params) external;
/// @notice claims the rebase accrued to x33
function claimRebase() external;
/// @notice compounds any existing SHADOW within the contract
function compound() external;
/// @notice direct claim
function claimIncentives(address[] calldata _feeDistributors, address[][] calldata _tokens) external;
/// @notice rescue stuck tokens
function rescue(address _token, uint256 _amount) external;
/// @notice allows the operator to unlock the contract for the current period
function unlock() external;
/// @notice add or remove an aggregator from the whitelist (timelocked)
/// @param _aggregator address of the aggregator to update
/// @param _status new whitelist status
function whitelistAggregator(address _aggregator, bool _status) external;
/// @notice transfers the operator via accesshub
function transferOperator(address _newOperator) external;
/// @notice simple getPeriod call
function getPeriod() external view returns (uint256 period);
/// @notice if the contract is unlocked for deposits
function isUnlocked() external view returns (bool);
/// @notice determines whether the cooldown is active
function isCooldownActive() external view returns (bool);
/// @notice address of the current operator
function operator() external view returns (address);
/// @notice accessHub address
function accessHub() external view returns (address);
/// @notice returns the ratio of xShadow per X33 token
function ratio() external view returns (uint256 _ratio);
/// @notice the most recent active period the contract has interacted in
function activePeriod() external view returns (uint256);
/// @notice whether the periods are unlocked
function periodUnlockStatus(uint256 _period) external view returns (bool unlocked);
/// @notice the shadow token
function shadow() external view returns (IERC20);
/// @notice the xShadow token
function xShadow() external view returns (IXShadow);
}
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IXShadow} from "contracts/interfaces/IXShadow.sol";
import {IX33} from "contracts/interfaces/IX33.sol";
interface Ix33Adapter {
event NewOperator(address _oldOperator, address _newOperator);
/// @notice submits the optimized votes for the epoch
function submitVotes(address[] calldata _pools, uint256[] calldata _weights) external;
/// @notice swap function using aggregators to process rewards into SHADOW
function swapIncentiveViaAggregator(IX33.AggregatorParams calldata _params) external;
/// @notice claims the rebase accrued to x33
function claimRebase() external;
/// @notice compounds any existing SHADOW within the contract
function compound() external;
/// @notice redeems x33 tokens in the x33 contract then deposit it in VoteModule
function rebaseX33() external;
/// @notice direct claim
function claimIncentives(address[] calldata _feeDistributors, address[][] calldata _tokens) external;
/// @notice allows the operator to unlock the contract for the current period
function unlock() external;
/// @notice transfers the operator via accesshub
function transferOperator(address _newOperator) external;
/// @notice rescues stuck tokens
function rescue(address token) external;
/// @notice address of the current operator
function operator() external view returns (address);
/// @notice accessHub address
function accessHub() external view returns (address);
function deposit(uint256 assets, address receiver) external returns (uint256 shares);
function mint(uint256 shares, address receiver) external returns (uint256 assets);
/// @dev this isn't exactly compilant with ERC4626 because we can't maniulate approvals on x33 through here
/// so we do not allow withdrawing from another user other than the msg.sender
function withdraw(uint256 assets, address receiver) external returns (uint256 shares);
/// @dev this isn't exactly compilant with ERC4626 because we can't maniulate approvals on x33 through here
/// so we do not allow withdrawing from another user other than the msg.sender
function redeem(uint256 shares, address receiver) external returns (uint256 assets);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @title Central Errors Library
/// @notice Contains all custom errors used across the protocol
/// @dev Centralized error definitions to prevent redundancy
library Errors {
/*//////////////////////////////////////////////////////////////
VOTER ERRORS
//////////////////////////////////////////////////////////////*/
/// @notice Thrown when attempting to interact with an already active gauge
/// @param gauge The address of the gauge
error ACTIVE_GAUGE(address gauge);
/// @notice Thrown when attempting to interact with an inactive gauge
/// @param gauge The address of the gauge
error GAUGE_INACTIVE(address gauge);
/// @notice Thrown when attempting to whitelist an already whitelisted token
/// @param token The address of the token
error ALREADY_WHITELISTED(address token);
/// @notice Thrown when caller is not authorized to perform an action
/// @param caller The address of the unauthorized caller
error NOT_AUTHORIZED(address caller);
/// @notice Thrown when token is not whitelisted
/// @param token The address of the non-whitelisted token
error NOT_WHITELISTED(address token);
/// @notice Thrown when both tokens in a pair are not whitelisted
error BOTH_NOT_WHITELISTED();
/// @notice Thrown when address is not a valid pool
/// @param pool The invalid pool address
error NOT_POOL(address pool);
/// @notice Thrown when pool is not seeded in PoolUpdater
/// @param pool The invalid pool address
error NOT_SEEDED(address pool);
/// @notice Thrown when contract is not initialized
error NOT_INIT();
/// @notice Thrown when array lengths don't match
error LENGTH_MISMATCH();
/// @notice Thrown when pool doesn't have an associated gauge
/// @param pool The address of the pool
error NO_GAUGE(address pool);
/// @notice Thrown when rewards are already distributed for a period
/// @param gauge The gauge address
/// @param period The distribution period
error ALREADY_DISTRIBUTED(address gauge, uint256 period);
/// @notice Thrown when attempting to vote with zero amount
/// @param pool The pool address
error ZERO_VOTE(address pool);
/// @notice Thrown when ratio exceeds maximum allowed
/// @param _xRatio The excessive ratio value
error RATIO_TOO_HIGH(uint256 _xRatio);
/// @notice Thrown when vote operation fails
error VOTE_UNSUCCESSFUL();
/*//////////////////////////////////////////////////////////////
GAUGE V3 ERRORS
//////////////////////////////////////////////////////////////*/
/// @notice Thrown when the pool already has a gauge
/// @param pool The address of the pool
error GAUGE_EXISTS(address pool);
/// @notice Thrown when caller is not the voter
/// @param caller The address of the invalid caller
error NOT_VOTER(address caller);
/// @notice Thrown when amount is not greater than zero
/// @param amt The invalid amount
error NOT_GT_ZERO(uint256 amt);
/// @notice Thrown when attempting to claim future rewards
error CANT_CLAIM_FUTURE();
/// @notice Throw when gauge can't determine if using secondsInRange from the pool is safe
error NEED_TEAM_TO_UPDATE();
/*//////////////////////////////////////////////////////////////
GAUGE ERRORS
//////////////////////////////////////////////////////////////*/
/// @notice Thrown when amount is zero
error ZERO_AMOUNT();
/// @notice Thrown when stake notification fails
error CANT_NOTIFY_STAKE();
/// @notice Thrown when reward amount is too high
error REWARD_TOO_HIGH();
/// @notice Thrown when amount exceeds remaining balance
/// @param amount The requested amount
/// @param remaining The remaining balance
error NOT_GREATER_THAN_REMAINING(uint256 amount, uint256 remaining);
/// @notice Thrown when token operation fails
/// @param token The address of the problematic token
error TOKEN_ERROR(address token);
/// @notice Thrown when an address is not an NfpManager
error NOT_NFP_MANAGER(address nfpManager);
/*//////////////////////////////////////////////////////////////
FEE DISTRIBUTOR ERRORS
//////////////////////////////////////////////////////////////*/
/// @notice Thrown when period is not finalized
/// @param period The unfinalized period
error NOT_FINALIZED(uint256 period);
/// @notice Thrown when the destination of a redirect is not a feeDistributor
/// @param destination Destination of the redirect
error NOT_FEE_DISTRIBUTOR(address destination);
/// @notice Thrown when the destination of a redirect's pool/pair has completely different tokens
error DIFFERENT_DESTINATION_TOKENS();
/*//////////////////////////////////////////////////////////////
PAIR ERRORS
//////////////////////////////////////////////////////////////*/
/// @notice Thrown when ratio is unstable
error UNSTABLE_RATIO();
/// @notice Thrown when safe transfer fails
error SAFE_TRANSFER_FAILED();
/// @notice Thrown on arithmetic overflow
error OVERFLOW();
/// @notice Thrown when skim operation is disabled
error SKIM_DISABLED();
/// @notice Thrown when insufficient liquidity is minted
error INSUFFICIENT_LIQUIDITY_MINTED();
/// @notice Thrown when insufficient liquidity is burned
error INSUFFICIENT_LIQUIDITY_BURNED();
/// @notice Thrown when output amount is insufficient
error INSUFFICIENT_OUTPUT_AMOUNT();
/// @notice Thrown when input amount is insufficient
error INSUFFICIENT_INPUT_AMOUNT();
/// @notice Generic insufficient liquidity error
error INSUFFICIENT_LIQUIDITY();
/// @notice Invalid transfer error
error INVALID_TRANSFER();
/// @notice K value error in AMM
error K();
/*//////////////////////////////////////////////////////////////
PAIR FACTORY ERRORS
//////////////////////////////////////////////////////////////*/
/// @notice Thrown when fee is too high
error FEE_TOO_HIGH();
/// @notice Thrown when fee is zero
error ZERO_FEE();
/// @notice Thrown when token assortment is invalid
error INVALID_ASSORTMENT();
/// @notice Thrown when address is zero
error ZERO_ADDRESS();
/// @notice Thrown when pair already exists
error PAIR_EXISTS();
/// @notice Thrown when fee split is invalid
error INVALID_FEE_SPLIT();
/*//////////////////////////////////////////////////////////////
FEE RECIPIENT FACTORY ERRORS
//////////////////////////////////////////////////////////////*/
/// @notice Thrown when treasury fee is invalid
error INVALID_TREASURY_FEE();
/*//////////////////////////////////////////////////////////////
ROUTER ERRORS
//////////////////////////////////////////////////////////////*/
/// @notice Thrown when deadline has expired
error EXPIRED();
/// @notice Thrown when tokens are identical
error IDENTICAL();
/// @notice Thrown when amount is insufficient
error INSUFFICIENT_AMOUNT();
/// @notice Thrown when path is invalid
error INVALID_PATH();
/// @notice Thrown when token B amount is insufficient
error INSUFFICIENT_B_AMOUNT();
/// @notice Thrown when token A amount is insufficient
error INSUFFICIENT_A_AMOUNT();
/// @notice Thrown when input amount is excessive
error EXCESSIVE_INPUT_AMOUNT();
/// @notice Thrown when ETH transfer fails
error ETH_TRANSFER_FAILED();
/// @notice Thrown when reserves are invalid
error INVALID_RESERVES();
/*//////////////////////////////////////////////////////////////
MINTER ERRORS
//////////////////////////////////////////////////////////////*/
/// @notice Thrown when epoch 0 has already started
error STARTED();
/// @notice Thrown when emissions haven't started
error EMISSIONS_NOT_STARTED();
/// @notice Thrown when deviation is too high
error TOO_HIGH();
/// @notice Thrown when no value change detected
error NO_CHANGE();
/// @notice Thrown when updating emissions in same period
error SAME_PERIOD();
/// @notice Thrown when contract setup is invalid
error INVALID_CONTRACT();
/// @notice Thrown when legacy factory doesn't have feeSplitWhenNoGauge on
error FEE_SPLIT_WHEN_NO_GAUGE_IS_OFF();
/*//////////////////////////////////////////////////////////////
ACCESS HUB ERRORS
//////////////////////////////////////////////////////////////*/
/// @notice Thrown when addresses are identical
error SAME_ADDRESS();
/// @notice Thrown when caller is not timelock
/// @param caller The invalid caller address
error NOT_TIMELOCK(address caller);
/// @notice Thrown when manual execution fails
/// @param reason The failure reason
error MANUAL_EXECUTION_FAILURE(bytes reason);
/// @notice Thrown when kick operation is forbidden
/// @param target The target address
error KICK_FORBIDDEN(address target);
/// @notice Thrown when the function called on AccessHub is not found
error FUNCTION_NOT_FOUND();
/// @notice Thrown when the expansion pack can't be added
error FAILED_TO_ADD();
/// @notice Thrown when the expansion pack can't be removed
error FAILED_TO_REMOVE();
/// @notice Throw when someone other than x33Adapter calls rebaseX33Callback
error NOT_X33_ADAPTER();
/*//////////////////////////////////////////////////////////////
VOTE MODULE ERRORS
//////////////////////////////////////////////////////////////*/
/// @notice Thrown when caller is not xShadow
error NOT_XSHADOW();
/// @notice Thrown when cooldown period is still active
error COOLDOWN_ACTIVE();
/// @notice Thrown when caller is not vote module
error NOT_VOTEMODULE();
/// @notice Thrown when caller is unauthorized
error UNAUTHORIZED();
/// @notice Thrown when caller is not access hub
error NOT_ACCESSHUB();
/// @notice Thrown when address is invalid
error INVALID_ADDRESS();
/*//////////////////////////////////////////////////////////////
LAUNCHER PLUGIN ERRORS
//////////////////////////////////////////////////////////////*/
/// @notice Thrown when caller is not authority
error NOT_AUTHORITY();
/// @notice Thrown when already an authority
error ALREADY_AUTHORITY();
/// @notice Thrown when caller is not operator
error NOT_OPERATOR();
/// @notice Thrown when already an operator
error ALREADY_OPERATOR();
/// @notice Thrown when pool is not enabled
/// @param pool The disabled pool address
error NOT_ENABLED(address pool);
/// @notice Thrown when fee distributor is missing
error NO_FEEDIST();
/// @notice Thrown when already enabled
error ENABLED();
/// @notice Thrown when take value is invalid
error INVALID_TAKE();
/*//////////////////////////////////////////////////////////////
X33 ERRORS
//////////////////////////////////////////////////////////////*/
/// @notice Thrown when value is zero
error ZERO();
/// @notice Thrown when amount is insufficient
error NOT_ENOUGH();
/// @notice Thrown when value doesn't conform to scale
/// @param value The non-conforming value
error NOT_CONFORMED_TO_SCALE(uint256 value);
/// @notice Thrown when contract is locked
error LOCKED();
/// @notice Thrown when rebase is in progress
error REBASE_IN_PROGRESS();
/// @notice Thrown when aggregator reverts
/// @param reason The revert reason
error AGGREGATOR_REVERTED(bytes reason);
/// @notice Thrown when output amount is too low
/// @param amount The insufficient amount
error AMOUNT_OUT_TOO_LOW(uint256 amount);
/// @notice Thrown when aggregator is not whitelisted
/// @param aggregator The non-whitelisted aggregator address
error AGGREGATOR_NOT_WHITELISTED(address aggregator);
/// @notice Thrown when token is forbidden
/// @param token The forbidden token address
error FORBIDDEN_TOKEN(address token);
/*//////////////////////////////////////////////////////////////
XSHADOW ERRORS
//////////////////////////////////////////////////////////////*/
/// @notice Thrown when caller is not minter
error NOT_MINTER();
/// @notice Thrown when no vest exists
error NO_VEST();
/// @notice Thrown when already exempt
error ALREADY_EXEMPT();
/// @notice Thrown when not exempt
error NOT_EXEMPT();
/// @notice Thrown when rescue operation is not allowed
error CANT_RESCUE();
/// @notice Thrown when array lengths mismatch
error ARRAY_LENGTHS();
/// @notice Thrown when vesting periods overlap
error VEST_OVERLAP();
/*//////////////////////////////////////////////////////////////
V3 FACTORY ERRORS
//////////////////////////////////////////////////////////////*/
/// @notice Thrown when tokens are identical
error IDENTICAL_TOKENS();
/// @notice Thrown when fee is too large
error FEE_TOO_LARGE();
/// @notice Address zero error
error ADDRESS_ZERO();
/// @notice Fee zero error
error F0();
/// @notice Thrown when value is out of bounds
/// @param value The out of bounds value
error OOB(uint8 value);
/*//////////////////////////////////////////////////////////////
POOL UPDATER ERRORS
//////////////////////////////////////////////////////////////*/
/// @notice Thrown when seeding for a pool fails
error TRANSFER_FROM_FOR_SEEDING_FAILED(address token, uint256 amount);
/// @notice Thrown when seeding for a pool fails
error SEEDING_FAILED();
/// @notice Thrown when updatePools is called too early
error TOO_EARLY();
/// @notice Thrown when a callback is called when an update isn't running
error NOT_RUNNING();
/// @notice Thrown when updatePools didn't perform any updates
error NO_UPDATES();
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC-20 standard.
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/draft-IERC6093.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard ERC-20 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 tokens.
*/
interface IERC20Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC20InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC20InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
* @param spender Address that may be allowed to operate on tokens without being their owner.
* @param allowance Amount of tokens a `spender` is allowed to operate with.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC20InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `spender` to be approved. Used in approvals.
* @param spender Address that may be allowed to operate on tokens without being their owner.
*/
error ERC20InvalidSpender(address spender);
}
/**
* @dev Standard ERC-721 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-721 tokens.
*/
interface IERC721Errors {
/**
* @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in ERC-20.
* Used in balance queries.
* @param owner Address of the current owner of a token.
*/
error ERC721InvalidOwner(address owner);
/**
* @dev Indicates a `tokenId` whose `owner` is the zero address.
* @param tokenId Identifier number of a token.
*/
error ERC721NonexistentToken(uint256 tokenId);
/**
* @dev Indicates an error related to the ownership over a particular token. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param tokenId Identifier number of a token.
* @param owner Address of the current owner of a token.
*/
error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC721InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC721InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param tokenId Identifier number of a token.
*/
error ERC721InsufficientApproval(address operator, uint256 tokenId);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC721InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC721InvalidOperator(address operator);
}
/**
* @dev Standard ERC-1155 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-1155 tokens.
*/
interface IERC1155Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
* @param tokenId Identifier number of a token.
*/
error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC1155InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC1155InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param owner Address of the current owner of a token.
*/
error ERC1155MissingApprovalForAll(address operator, address owner);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC1155InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC1155InvalidOperator(address operator);
/**
* @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
* Used in batch transfers.
* @param idsLength Length of the array of token identifiers
* @param valuesLength Length of the array of token amounts
*/
error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/IERC1363.sol)
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";
/**
* @title IERC1363
* @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
*
* Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
* after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
*/
interface IERC1363 is IERC20, IERC165 {
/*
* Note: the ERC-165 identifier for this interface is 0xb0202a11.
* 0xb0202a11 ===
* bytes4(keccak256('transferAndCall(address,uint256)')) ^
* bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
* bytes4(keccak256('approveAndCall(address,uint256)')) ^
* bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
*/
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @param data Additional data with no specified format, sent in call to `spender`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Address.sol)
pragma solidity ^0.8.20;
import {Errors} from "./Errors.sol";
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert Errors.InsufficientBalance(address(this).balance, amount);
}
(bool success, ) = recipient.call{value: amount}("");
if (!success) {
revert Errors.FailedCall();
}
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason or custom error, it is bubbled
* up by this function (like regular Solidity function calls). However, if
* the call reverted with no returned reason, this function reverts with a
* {Errors.FailedCall} error.
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert Errors.InsufficientBalance(address(this).balance, value);
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
* was not a contract or bubbling up the revert reason (falling back to {Errors.FailedCall}) in case
* of an unsuccessful call.
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
// only check if target is a contract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
/**
* @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
* revert reason or with a default {Errors.FailedCall} error.
*/
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
/**
* @dev Reverts with returndata if present. Otherwise reverts with {Errors.FailedCall}.
*/
function _revert(bytes memory returndata) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
assembly ("memory-safe") {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert Errors.FailedCall();
}
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (access/extensions/IAccessControlEnumerable.sol)
pragma solidity ^0.8.20;
import {IAccessControl} from "../IAccessControl.sol";
/**
* @dev External interface of AccessControlEnumerable declared to support ERC-165 detection.
*/
interface IAccessControlEnumerable is IAccessControl {
/**
* @dev Returns one of the accounts that have `role`. `index` must be a
* value between 0 and {getRoleMemberCount}, non-inclusive.
*
* Role bearers are not sorted in any particular way, and their ordering may
* change at any point.
*
* WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
* you perform all queries on the same block. See the following
* https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
* for more information.
*/
function getRoleMember(bytes32 role, uint256 index) external view returns (address);
/**
* @dev Returns the number of accounts that have `role`. Can be used
* together with {getRoleMember} to enumerate all bearers of a role.
*/
function getRoleMemberCount(bytes32 role) external view returns (uint256);
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Pausable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which allows children to implement an emergency stop
* mechanism that can be triggered by an authorized account.
*
* This module is used through inheritance. It will make available the
* modifiers `whenNotPaused` and `whenPaused`, which can be applied to
* the functions of your contract. Note that they will not be pausable by
* simply including this module, only once the modifiers are put in place.
*/
abstract contract Pausable is Context {
bool private _paused;
/**
* @dev Emitted when the pause is triggered by `account`.
*/
event Paused(address account);
/**
* @dev Emitted when the pause is lifted by `account`.
*/
event Unpaused(address account);
/**
* @dev The operation failed because the contract is paused.
*/
error EnforcedPause();
/**
* @dev The operation failed because the contract is not paused.
*/
error ExpectedPause();
/**
* @dev Initializes the contract in unpaused state.
*/
constructor() {
_paused = false;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
_requireNotPaused();
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
_requirePaused();
_;
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
return _paused;
}
/**
* @dev Throws if the contract is paused.
*/
function _requireNotPaused() internal view virtual {
if (paused()) {
revert EnforcedPause();
}
}
/**
* @dev Throws if the contract is not paused.
*/
function _requirePaused() internal view virtual {
if (!paused()) {
revert ExpectedPause();
}
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
*/
function _pause() internal virtual whenNotPaused {
_paused = true;
emit Paused(_msgSender());
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/
function _unpause() internal virtual whenPaused {
_paused = false;
emit Unpaused(_msgSender());
}
}
// 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/Errors.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of common custom errors used in multiple contracts
*
* IMPORTANT: Backwards compatibility is not guaranteed in future versions of the library.
* It is recommended to avoid relying on the error API for critical functionality.
*
* _Available since v5.1._
*/
library Errors {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error InsufficientBalance(uint256 balance, uint256 needed);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedCall();
/**
* @dev The deployment failed.
*/
error FailedDeployment();
/**
* @dev A necessary precompile is missing.
*/
error MissingPrecompile(address);
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (access/IAccessControl.sol)
pragma solidity ^0.8.20;
/**
* @dev External interface of AccessControl declared to support ERC-165 detection.
*/
interface IAccessControl {
/**
* @dev The `account` is missing a role.
*/
error AccessControlUnauthorizedAccount(address account, bytes32 neededRole);
/**
* @dev The caller of a function is not the expected one.
*
* NOTE: Don't confuse with {AccessControlUnauthorizedAccount}.
*/
error AccessControlBadConfirmation();
/**
* @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
*
* `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
* {RoleAdminChanged} not being emitted signaling this.
*/
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
/**
* @dev Emitted when `account` is granted `role`.
*
* `sender` is the account that originated the contract call. This account bears the admin role (for the granted role).
* Expected in cases where the role was granted using the internal {AccessControl-_grantRole}.
*/
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Emitted when `account` is revoked `role`.
*
* `sender` is the account that originated the contract call:
* - if using `revokeRole`, it is the admin role bearer
* - if using `renounceRole`, it is the role bearer (i.e. `account`)
*/
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) external view returns (bool);
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {AccessControl-_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) external view returns (bytes32);
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been granted `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `callerConfirmation`.
*/
function renounceRole(bytes32 role, address callerConfirmation) external;
}
// 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);
}