Description:
Multi-signature wallet contract requiring multiple confirmations for transaction execution.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
{{
"language": "Solidity",
"sources": {
"src/twyne/EulerCollateralVault.sol": {
"content": "// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.28;
import {IEVault} from "euler-vault-kit/EVault/IEVault.sol";
import {EulerRouter} from "euler-price-oracle/src/EulerRouter.sol";
import {IEVC} from "ethereum-vault-connector/interfaces/IEthereumVaultConnector.sol";
import {CollateralVaultBase, SafeERC20, IERC20} from "src/twyne/CollateralVaultBase.sol";
import {VaultManager} from "src/twyne/VaultManager.sol";
import {SafeERC20Lib, IERC20 as IERC20_Euler} from "euler-vault-kit/EVault/shared/lib/SafeERC20Lib.sol";
import {Math} from "openzeppelin-contracts/utils/math/Math.sol";
/// @title EulerCollateralVault
/// @notice To contact the team regarding security matters, visit https://twyne.xyz/security
/// @dev Provides integration logic for Euler Finance as external protocol.
/// @notice In this contract, the EVC is authenticated before any action that may affect the state of the vault or an
/// account. This is done to ensure that if it's EVC calling, the account is correctly authorized.
contract EulerCollateralVault is CollateralVaultBase {
address public immutable targetAsset; // Euler targetVault only supports 1 asset, so store it as immutable
IEVC public immutable eulerEVC;
uint[50] private __gap;
/// @param _evc address of EVC deployed by Twyne
/// @param _targetVault address of the target vault to borrow from in Euler
constructor(address _evc, address _targetVault) CollateralVaultBase(_evc, _targetVault) {
targetAsset = IEVault(targetVault).asset();
eulerEVC = IEVC(IEVault(targetVault).EVC());
_disableInitializers();
}
/// @param __asset address of vault asset
/// @param __borrower address of vault owner
/// @param __liqLTV user-specified target LTV
/// @param __vaultManager VaultManager contract address
function initialize(
IERC20 __asset,
address __borrower,
uint __liqLTV,
VaultManager __vaultManager
) external initializer override {
__CollateralVaultBase_init(__asset, __borrower, __liqLTV, __vaultManager);
eulerEVC.enableCollateral(address(this), address(__asset)); // necessary for Euler Finance EVK borrowing
eulerEVC.enableController(address(this), targetVault); // necessary for Euler Finance EVK borrowing
SafeERC20.forceApprove(IERC20(targetAsset), targetVault, type(uint).max); // necessary for repay()
SafeERC20.forceApprove(IERC20(IEVault(address(__asset)).asset()), address(__asset), type(uint).max); // necessary for _depositUnderlying()
emit T_CollateralVaultInitialized();
}
/// @dev increment the version for proxy upgrades
function version() external override pure returns (uint) {
return 1;
}
///
// Functions defined in CollateralVaultBase requiring custom implementations
///
/// @notice returns the maximum assets that can be repaid to Euler target vault
function maxRepay() public view override returns (uint) {
// debtOfExact() isn't used here since it is a scaled value.
// See test_basicLiquidation_all_collateral() which asserts maxRepay value matches debtOf() value.
return IEVault(targetVault).debtOf(address(this));
}
/// @notice adjust credit reserved from intermediate vault
function _handleExcessCredit(uint __invariantCollateralAmount) internal override {
uint vaultAssets = totalAssetsDepositedOrReserved;
if (vaultAssets > __invariantCollateralAmount) {
totalAssetsDepositedOrReserved = vaultAssets - intermediateVault.repay(vaultAssets - __invariantCollateralAmount, address(this));
} else {
totalAssetsDepositedOrReserved = vaultAssets + intermediateVault.borrow(__invariantCollateralAmount - vaultAssets, address(this));
}
}
/// @notice Calculates the collateral assets that should be held by the collateral vault to comply with invariants
/// @return uint Returns the amount of collateral assets that the collateral vault should hold with zero excess credit
function _invariantCollateralAmount() internal view override returns (uint) {
uint userCollateral = totalAssetsDepositedOrReserved - maxRelease();
uint liqLTV_external = uint(IEVault(targetVault).LTVLiquidation(asset())) * uint(twyneVaultManager.externalLiqBuffers(asset())); // 1e8 precision
return Math.ceilDiv(userCollateral * twyneLiqLTV * MAXFACTOR, liqLTV_external);
}
/// @notice borrows target assets from Euler
function _borrow(uint _targetAmount, address _receiver)
internal
override
{
IEVault(targetVault).borrow(_targetAmount, _receiver);
}
/// @notice sends borrowed target assets to Euler
function _repay(uint _amount) internal override {
SafeERC20Lib.safeTransferFrom(IERC20_Euler(targetAsset), borrower, address(this), _amount, permit2);
IEVault(targetVault).repay(_amount, address(this));
}
/// @notice First receives the unwrapped token from the borrower, then sends borrowed target assets to Euler
function _depositUnderlying(uint underlying) internal override returns (uint) {
address __asset = asset();
address underlyingAsset = IEVault(__asset).asset();
SafeERC20Lib.safeTransferFrom(IERC20_Euler(underlyingAsset), borrower, address(this), underlying, permit2);
return IEVault(__asset).deposit(underlying, address(this));
}
///
// Twyne Custom Liquidation Logic
///
/// @notice perform checks to determine if this collateral vault is liquidatable
function _canLiquidate() internal view override returns (bool) {
// Liquidation scenario 1: If close to liquidation trigger of target asset protocol, liquidate on Twyne
// How: Check if within some margin (say, 2%) of this liquidation point
// Note: This method ignores the internal borrow, because Euler does not consider it at all
address __asset = asset();
// cache the debt owed to the targetVault
(uint externalCollateralValueScaledByLiqLTV, uint externalBorrowDebtValue) = IEVault(targetVault).accountLiquidity(address(this), true);
// externalCollateralValueScaledByLiqLTV is actual collateral value * externalLiquidationLTV, so it's lower than the real value
if (externalBorrowDebtValue * MAXFACTOR > uint(twyneVaultManager.externalLiqBuffers(__asset)) * externalCollateralValueScaledByLiqLTV) {
// note to avoid divide by zero case, don't divide by externalCollateralValueScaledByLiqLTV
return true;
}
// Liquidation scenario 2: If combined debt from internal and external borrow is approaching the total credit
// How: Cache the debt and credit values, convert all to the same currency, and check if they are within some
// margin (say, 4%)
// Note: EVK liquidation logic in the Twyne intermediate vault is blocked by BridgeHookTarget.sol fallback
// Definitions of variables:
// vaultOwnedCollateralAmount = total amount of assets held by the borrower's vault
// borrower owned collateral + intermediate vault borrowed principal
// internalBorrowDebtAmount = debt owed from the borrower's vault to the intermediate vault
// intermediate vault borrowed principal + intermediate vault borrow interest
// userOwnedCollateralAmount = vaultOwnedCollateralAmount - internalBorrowDebtAmount
// userOwnedCollateralValue = userOwnedCollateralAmount converted to USD
uint userCollateralValue = EulerRouter(twyneVaultManager.oracleRouter()).getQuote(
totalAssetsDepositedOrReserved - maxRelease(), __asset, IEVault(intermediateVault).unitOfAccount());
// note to avoid divide by zero case, don't divide by borrowerOwnedCollateralValue
return (externalBorrowDebtValue * MAXFACTOR > twyneLiqLTV * userCollateralValue);
}
/// @notice custom balanceOf implementation
/// @dev returns 0 on external liquidation, because:
/// handleExternalLiquidation() sets this vault's collateral balance to 0, balanceOf is then
/// called by the intermediate vault when someone settles the remaining bad debt.
function balanceOf(address user) external view nonReentrantView override returns (uint) {
if (user != address(this)) return 0;
if (borrower == address(0)) return 0;
uint _totalAssetsDepositedOrReserved = totalAssetsDepositedOrReserved;
// return 0 if externally liquidated
if (_totalAssetsDepositedOrReserved > IERC20(asset()).balanceOf(address(this))) return 0;
return _totalAssetsDepositedOrReserved - maxRelease();
}
/// @notice splits remaining collateral between liquidator, intermediate vault and borrow
function splitCollateralAfterExtLiq(uint _collateralBalance, uint _maxRepay, uint _maxRelease) internal view returns (uint, uint, uint) {
address __asset = asset();
uint liquidatorReward;
if (_maxRepay > 0) {
liquidatorReward = twyneVaultManager.oracleRouter().getQuote(
_maxRepay * MAXFACTOR / twyneVaultManager.maxTwyneLTVs(__asset),
targetAsset,
IEVault(__asset).asset()
);
liquidatorReward = Math.min(_collateralBalance, IEVault(__asset).convertToShares(liquidatorReward));
}
uint releaseAmount = Math.min(_collateralBalance - liquidatorReward, _maxRelease);
uint borrowerClaim = _collateralBalance - releaseAmount - liquidatorReward;
return (liquidatorReward, releaseAmount, borrowerClaim);
}
/// @notice to be called if the vault is liquidated by Euler
function handleExternalLiquidation() external override callThroughEVC nonReentrant {
createVaultSnapshot();
address __asset = asset();
uint amount = IERC20(__asset).balanceOf(address(this));
require(totalAssetsDepositedOrReserved > amount, NotExternallyLiquidated());
{
(uint externalCollateralValueScaledByLiqLTV, uint externalBorrowDebtValue) = IEVault(targetVault).accountLiquidity(address(this), true);
// Equality is needed for the complete liquidation case (entire debt and collateral is taken by Euler liquidator)
require(externalCollateralValueScaledByLiqLTV >= externalBorrowDebtValue, ExternalPositionUnhealthy());
}
uint _maxRelease = maxRelease();
address liquidator = _msgSender();
if (_maxRelease == 0) {
require(liquidator == borrower, NoLiquidationForZeroReserve());
}
uint _maxRepay = maxRepay();
(uint liquidatorReward, uint releaseAmount, uint borrowerClaim) = splitCollateralAfterExtLiq(amount, _maxRepay, _maxRelease);
if (_maxRepay > 0) {
// step 1: repay all external debt
SafeERC20Lib.safeTransferFrom(IERC20_Euler(targetAsset), liquidator, address(this), _maxRepay, permit2);
IEVault(targetVault).repay(_maxRepay, address(this));
// step 2: transfer collateral reward to liquidator
SafeERC20Lib.safeTransfer(IERC20_Euler(__asset), liquidator, liquidatorReward);
}
if (borrowerClaim > 0) {
// step 3: return some collateral to borrower
SafeERC20Lib.safeTransfer(IERC20_Euler(__asset), borrower, borrowerClaim);
}
if (releaseAmount > 0) {
// step 4: release remaining assets. Any non-zero bad debt left after this
// needs to be socialized via intermediateVault.liquidate in the same batch.
intermediateVault.repay(releaseAmount, address(this));
}
// reset the vault
delete totalAssetsDepositedOrReserved;
delete borrower;
evc.requireVaultStatusCheck();
emit T_HandleExternalLiquidation();
}
/// @notice allow users of the underlying protocol to seamlessly transfer their position to this vault
function teleport(uint toDeposit, uint toBorrow, uint8 subAccountId) external onlyBorrowerAndNotExtLiquidated whenNotPaused nonReentrant {
createVaultSnapshot();
totalAssetsDepositedOrReserved += toDeposit;
_handleExcessCredit(_invariantCollateralAmount());
address subAccount = address(uint160(uint160(borrower) ^ subAccountId));
if (toBorrow == type(uint).max) {
toBorrow = IEVault(targetVault).debtOf(subAccount);
}
IEVC.BatchItem[] memory items = new IEVC.BatchItem[](3);
items[0] = IEVC.BatchItem({
targetContract: asset(),
onBehalfOfAccount: address(this),
value: 0,
data: abi.encodeCall(IERC20.transferFrom, (subAccount, address(this), toDeposit)) // needs allowance
});
items[1] = IEVC.BatchItem({
targetContract: targetVault,
onBehalfOfAccount: address(this),
value: 0,
data: abi.encodeCall(IEVault(targetVault).borrow, (toBorrow, address(this)))
});
items[2] = IEVC.BatchItem({
targetContract: targetVault,
onBehalfOfAccount: address(this),
value: 0,
data: abi.encodeCall(IEVault(targetVault).repay, (toBorrow, subAccount))
});
eulerEVC.batch(items);
evc.requireAccountAndVaultStatusCheck(address(this));
emit T_Teleport(toDeposit, toBorrow);
}
}
"
},
"lib/euler-vault-kit/src/EVault/IEVault.sol": {
"content": "// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.8.0;
import {IVault as IEVCVault} from "ethereum-vault-connector/interfaces/IVault.sol";
// Full interface of EVault and all it's modules
/// @title IInitialize
/// @notice Interface of the initialization module of EVault
interface IInitialize {
/// @notice Initialization of the newly deployed proxy contract
/// @param proxyCreator Account which created the proxy or should be the initial governor
function initialize(address proxyCreator) external;
}
/// @title IERC20
/// @notice Interface of the EVault's Initialize module
interface IERC20 {
/// @notice Vault share token (eToken) name, ie "Euler Vault: DAI"
/// @return The name of the eToken
function name() external view returns (string memory);
/// @notice Vault share token (eToken) symbol, ie "eDAI"
/// @return The symbol of the eToken
function symbol() external view returns (string memory);
/// @notice Decimals, the same as the asset's or 18 if the asset doesn't implement `decimals()`
/// @return The decimals of the eToken
function decimals() external view returns (uint8);
/// @notice Sum of all eToken balances
/// @return The total supply of the eToken
function totalSupply() external view returns (uint256);
/// @notice Balance of a particular account, in eTokens
/// @param account Address to query
/// @return The balance of the account
function balanceOf(address account) external view returns (uint256);
/// @notice Retrieve the current allowance
/// @param holder The account holding the eTokens
/// @param spender Trusted address
/// @return The allowance from holder for spender
function allowance(address holder, address spender) external view returns (uint256);
/// @notice Transfer eTokens to another address
/// @param to Recipient account
/// @param amount In shares.
/// @return True if transfer succeeded
function transfer(address to, uint256 amount) external returns (bool);
/// @notice Transfer eTokens from one address to another
/// @param from This address must've approved the to address
/// @param to Recipient account
/// @param amount In shares
/// @return True if transfer succeeded
function transferFrom(address from, address to, uint256 amount) external returns (bool);
/// @notice Allow spender to access an amount of your eTokens
/// @param spender Trusted address
/// @param amount Use max uint for "infinite" allowance
/// @return True if approval succeeded
function approve(address spender, uint256 amount) external returns (bool);
}
/// @title IToken
/// @notice Interface of the EVault's Token module
interface IToken is IERC20 {
/// @notice Transfer the full eToken balance of an address to another
/// @param from This address must've approved the to address
/// @param to Recipient account
/// @return True if transfer succeeded
function transferFromMax(address from, address to) external returns (bool);
}
/// @title IERC4626
/// @notice Interface of an ERC4626 vault
interface IERC4626 {
/// @notice Vault's underlying asset
/// @return The vault's underlying asset
function asset() external view returns (address);
/// @notice Total amount of managed assets, cash and borrows
/// @return The total amount of assets
function totalAssets() external view returns (uint256);
/// @notice Calculate amount of assets corresponding to the requested shares amount
/// @param shares Amount of shares to convert
/// @return The amount of assets
function convertToAssets(uint256 shares) external view returns (uint256);
/// @notice Calculate amount of shares corresponding to the requested assets amount
/// @param assets Amount of assets to convert
/// @return The amount of shares
function convertToShares(uint256 assets) external view returns (uint256);
/// @notice Fetch the maximum amount of assets a user can deposit
/// @param account Address to query
/// @return The max amount of assets the account can deposit
function maxDeposit(address account) external view returns (uint256);
/// @notice Calculate an amount of shares that would be created by depositing assets
/// @param assets Amount of assets deposited
/// @return Amount of shares received
function previewDeposit(uint256 assets) external view returns (uint256);
/// @notice Fetch the maximum amount of shares a user can mint
/// @param account Address to query
/// @return The max amount of shares the account can mint
function maxMint(address account) external view returns (uint256);
/// @notice Calculate an amount of assets that would be required to mint requested amount of shares
/// @param shares Amount of shares to be minted
/// @return Required amount of assets
function previewMint(uint256 shares) external view returns (uint256);
/// @notice Fetch the maximum amount of assets a user is allowed to withdraw
/// @param owner Account holding the shares
/// @return The maximum amount of assets the owner is allowed to withdraw
function maxWithdraw(address owner) external view returns (uint256);
/// @notice Calculate the amount of shares that will be burned when withdrawing requested amount of assets
/// @param assets Amount of assets withdrawn
/// @return Amount of shares burned
function previewWithdraw(uint256 assets) external view returns (uint256);
/// @notice Fetch the maximum amount of shares a user is allowed to redeem for assets
/// @param owner Account holding the shares
/// @return The maximum amount of shares the owner is allowed to redeem
function maxRedeem(address owner) external view returns (uint256);
/// @notice Calculate the amount of assets that will be transferred when redeeming requested amount of shares
/// @param shares Amount of shares redeemed
/// @return Amount of assets transferred
function previewRedeem(uint256 shares) external view returns (uint256);
/// @notice Transfer requested amount of underlying tokens from sender to the vault pool in return for shares
/// @param amount Amount of assets to deposit (use max uint256 for full underlying token balance)
/// @param receiver An account to receive the shares
/// @return Amount of shares minted
/// @dev Deposit will round down the amount of assets that are converted to shares. To prevent losses consider using
/// mint instead.
function deposit(uint256 amount, address receiver) external returns (uint256);
/// @notice Transfer underlying tokens from sender to the vault pool in return for requested amount of shares
/// @param amount Amount of shares to be minted
/// @param receiver An account to receive the shares
/// @return Amount of assets deposited
function mint(uint256 amount, address receiver) external returns (uint256);
/// @notice Transfer requested amount of underlying tokens from the vault and decrease account's shares balance
/// @param amount Amount of assets to withdraw
/// @param receiver Account to receive the withdrawn assets
/// @param owner Account holding the shares to burn
/// @return Amount of shares burned
function withdraw(uint256 amount, address receiver, address owner) external returns (uint256);
/// @notice Burn requested shares and transfer corresponding underlying tokens from the vault to the receiver
/// @param amount Amount of shares to burn (use max uint256 to burn full owner balance)
/// @param receiver Account to receive the withdrawn assets
/// @param owner Account holding the shares to burn.
/// @return Amount of assets transferred
function redeem(uint256 amount, address receiver, address owner) external returns (uint256);
}
/// @title IVault
/// @notice Interface of the EVault's Vault module
interface IVault is IERC4626 {
/// @notice Balance of the fees accumulator, in shares
/// @return The accumulated fees in shares
function accumulatedFees() external view returns (uint256);
/// @notice Balance of the fees accumulator, in underlying units
/// @return The accumulated fees in asset units
function accumulatedFeesAssets() external view returns (uint256);
/// @notice Address of the original vault creator
/// @return The address of the creator
function creator() external view returns (address);
/// @notice Creates shares for the receiver, from excess asset balances of the vault (not accounted for in `cash`)
/// @param amount Amount of assets to claim (use max uint256 to claim all available assets)
/// @param receiver An account to receive the shares
/// @return Amount of shares minted
/// @dev Could be used as an alternative deposit flow in certain scenarios. E.g. swap directly to the vault, call
/// `skim` to claim deposit.
function skim(uint256 amount, address receiver) external returns (uint256);
}
/// @title IBorrowing
/// @notice Interface of the EVault's Borrowing module
interface IBorrowing {
/// @notice Sum of all outstanding debts, in underlying units (increases as interest is accrued)
/// @return The total borrows in asset units
function totalBorrows() external view returns (uint256);
/// @notice Sum of all outstanding debts, in underlying units scaled up by shifting
/// INTERNAL_DEBT_PRECISION_SHIFT bits
/// @return The total borrows in internal debt precision
function totalBorrowsExact() external view returns (uint256);
/// @notice Balance of vault assets as tracked by deposits/withdrawals and borrows/repays
/// @return The amount of assets the vault tracks as current direct holdings
function cash() external view returns (uint256);
/// @notice Debt owed by a particular account, in underlying units
/// @param account Address to query
/// @return The debt of the account in asset units
function debtOf(address account) external view returns (uint256);
/// @notice Debt owed by a particular account, in underlying units scaled up by shifting
/// INTERNAL_DEBT_PRECISION_SHIFT bits
/// @param account Address to query
/// @return The debt of the account in internal precision
function debtOfExact(address account) external view returns (uint256);
/// @notice Retrieves the current interest rate for an asset
/// @return The interest rate in yield-per-second, scaled by 10**27
function interestRate() external view returns (uint256);
/// @notice Retrieves the current interest rate accumulator for an asset
/// @return An opaque accumulator that increases as interest is accrued
function interestAccumulator() external view returns (uint256);
/// @notice Returns an address of the sidecar DToken
/// @return The address of the DToken
function dToken() external view returns (address);
/// @notice Transfer underlying tokens from the vault to the sender, and increase sender's debt
/// @param amount Amount of assets to borrow (use max uint256 for all available tokens)
/// @param receiver Account receiving the borrowed tokens
/// @return Amount of assets borrowed
function borrow(uint256 amount, address receiver) external returns (uint256);
/// @notice Transfer underlying tokens from the sender to the vault, and decrease receiver's debt
/// @param amount Amount of debt to repay in assets (use max uint256 for full debt)
/// @param receiver Account holding the debt to be repaid
/// @return Amount of assets repaid
function repay(uint256 amount, address receiver) external returns (uint256);
/// @notice Pay off liability with shares ("self-repay")
/// @param amount In asset units (use max uint256 to repay the debt in full or up to the available deposit)
/// @param receiver Account to remove debt from by burning sender's shares
/// @return shares Amount of shares burned
/// @return debt Amount of debt removed in assets
/// @dev Equivalent to withdrawing and repaying, but no assets are needed to be present in the vault
/// @dev Contrary to a regular `repay`, if account is unhealthy, the repay amount must bring the account back to
/// health, or the operation will revert during account status check
function repayWithShares(uint256 amount, address receiver) external returns (uint256 shares, uint256 debt);
/// @notice Take over debt from another account
/// @param amount Amount of debt in asset units (use max uint256 for all the account's debt)
/// @param from Account to pull the debt from
/// @dev Due to internal debt precision accounting, the liability reported on either or both accounts after
/// calling `pullDebt` may not match the `amount` requested precisely
function pullDebt(uint256 amount, address from) external;
/// @notice Request a flash-loan. A onFlashLoan() callback in msg.sender will be invoked, which must repay the loan
/// to the main Euler address prior to returning.
/// @param amount In asset units
/// @param data Passed through to the onFlashLoan() callback, so contracts don't need to store transient data in
/// storage
function flashLoan(uint256 amount, bytes calldata data) external;
/// @notice Updates interest accumulator and totalBorrows, credits reserves, re-targets interest rate, and logs
/// vault status
function touch() external;
}
/// @title ILiquidation
/// @notice Interface of the EVault's Liquidation module
interface ILiquidation {
/// @notice Checks to see if a liquidation would be profitable, without actually doing anything
/// @param liquidator Address that will initiate the liquidation
/// @param violator Address that may be in collateral violation
/// @param collateral Collateral which is to be seized
/// @return maxRepay Max amount of debt that can be repaid, in asset units
/// @return maxYield Yield in collateral corresponding to max allowed amount of debt to be repaid, in collateral
/// balance (shares for vaults)
function checkLiquidation(address liquidator, address violator, address collateral)
external
view
returns (uint256 maxRepay, uint256 maxYield);
/// @notice Attempts to perform a liquidation
/// @param violator Address that may be in collateral violation
/// @param collateral Collateral which is to be seized
/// @param repayAssets The amount of underlying debt to be transferred from violator to sender, in asset units (use
/// max uint256 to repay the maximum possible amount). Meant as slippage check together with `minYieldBalance`
/// @param minYieldBalance The minimum acceptable amount of collateral to be transferred from violator to sender, in
/// collateral balance units (shares for vaults). Meant as slippage check together with `repayAssets`
/// @dev If `repayAssets` is set to max uint256 it is assumed the caller will perform their own slippage checks to
/// make sure they are not taking on too much debt. This option is mainly meant for smart contract liquidators
function liquidate(address violator, address collateral, uint256 repayAssets, uint256 minYieldBalance) external;
}
/// @title IRiskManager
/// @notice Interface of the EVault's RiskManager module
interface IRiskManager is IEVCVault {
/// @notice Retrieve account's total liquidity
/// @param account Account holding debt in this vault
/// @param liquidation Flag to indicate if the calculation should be performed in liquidation vs account status
/// check mode, where different LTV values might apply.
/// @return collateralValue Total risk adjusted value of all collaterals in unit of account
/// @return liabilityValue Value of debt in unit of account
function accountLiquidity(address account, bool liquidation)
external
view
returns (uint256 collateralValue, uint256 liabilityValue);
/// @notice Retrieve account's liquidity per collateral
/// @param account Account holding debt in this vault
/// @param liquidation Flag to indicate if the calculation should be performed in liquidation vs account status
/// check mode, where different LTV values might apply.
/// @return collaterals Array of collaterals enabled
/// @return collateralValues Array of risk adjusted collateral values corresponding to items in collaterals array.
/// In unit of account
/// @return liabilityValue Value of debt in unit of account
function accountLiquidityFull(address account, bool liquidation)
external
view
returns (address[] memory collaterals, uint256[] memory collateralValues, uint256 liabilityValue);
/// @notice Release control of the account on EVC if no outstanding debt is present
function disableController() external;
/// @notice Checks the status of an account and reverts if account is not healthy
/// @param account The address of the account to be checked
/// @return magicValue Must return the bytes4 magic value 0xb168c58f (which is a selector of this function) when
/// account status is valid, or revert otherwise.
/// @dev Only callable by EVC during status checks
function checkAccountStatus(address account, address[] calldata collaterals) external view returns (bytes4);
/// @notice Checks the status of the vault and reverts if caps are exceeded
/// @return magicValue Must return the bytes4 magic value 0x4b3d1223 (which is a selector of this function) when
/// account status is valid, or revert otherwise.
/// @dev Only callable by EVC during status checks
function checkVaultStatus() external returns (bytes4);
}
/// @title IBalanceForwarder
/// @notice Interface of the EVault's BalanceForwarder module
interface IBalanceForwarder {
/// @notice Retrieve the address of rewards contract, tracking changes in account's balances
/// @return The balance tracker address
function balanceTrackerAddress() external view returns (address);
/// @notice Retrieves boolean indicating if the account opted in to forward balance changes to the rewards contract
/// @param account Address to query
/// @return True if balance forwarder is enabled
function balanceForwarderEnabled(address account) external view returns (bool);
/// @notice Enables balance forwarding for the authenticated account
/// @dev Only the authenticated account can enable balance forwarding for itself
/// @dev Should call the IBalanceTracker hook with the current account's balance
function enableBalanceForwarder() external;
/// @notice Disables balance forwarding for the authenticated account
/// @dev Only the authenticated account can disable balance forwarding for itself
/// @dev Should call the IBalanceTracker hook with the account's balance of 0
function disableBalanceForwarder() external;
}
/// @title IGovernance
/// @notice Interface of the EVault's Governance module
interface IGovernance {
/// @notice Retrieves the address of the governor
/// @return The governor address
function governorAdmin() external view returns (address);
/// @notice Retrieves address of the governance fee receiver
/// @return The fee receiver address
function feeReceiver() external view returns (address);
/// @notice Retrieves the interest fee in effect for the vault
/// @return Amount of interest that is redirected as a fee, as a fraction scaled by 1e4
function interestFee() external view returns (uint16);
/// @notice Looks up an asset's currently configured interest rate model
/// @return Address of the interest rate contract or address zero to indicate 0% interest
function interestRateModel() external view returns (address);
/// @notice Retrieves the ProtocolConfig address
/// @return The protocol config address
function protocolConfigAddress() external view returns (address);
/// @notice Retrieves the protocol fee share
/// @return A percentage share of fees accrued belonging to the protocol, in 1e4 scale
function protocolFeeShare() external view returns (uint256);
/// @notice Retrieves the address which will receive protocol's fees
/// @notice The protocol fee receiver address
function protocolFeeReceiver() external view returns (address);
/// @notice Retrieves supply and borrow caps in AmountCap format
/// @return supplyCap The supply cap in AmountCap format
/// @return borrowCap The borrow cap in AmountCap format
function caps() external view returns (uint16 supplyCap, uint16 borrowCap);
/// @notice Retrieves the borrow LTV of the collateral, which is used to determine if the account is healthy during
/// account status checks.
/// @param collateral The address of the collateral to query
/// @return Borrowing LTV in 1e4 scale
function LTVBorrow(address collateral) external view returns (uint16);
/// @notice Retrieves the current liquidation LTV, which is used to determine if the account is eligible for
/// liquidation
/// @param collateral The address of the collateral to query
/// @return Liquidation LTV in 1e4 scale
function LTVLiquidation(address collateral) external view returns (uint16);
/// @notice Retrieves LTV configuration for the collateral
/// @param collateral Collateral asset
/// @return borrowLTV The current value of borrow LTV for originating positions
/// @return liquidationLTV The value of fully converged liquidation LTV
/// @return initialLiquidationLTV The initial value of the liquidation LTV, when the ramp began
/// @return targetTimestamp The timestamp when the liquidation LTV is considered fully converged
/// @return rampDuration The time it takes for the liquidation LTV to converge from the initial value to the fully
/// converged value
function LTVFull(address collateral)
external
view
returns (
uint16 borrowLTV,
uint16 liquidationLTV,
uint16 initialLiquidationLTV,
uint48 targetTimestamp,
uint32 rampDuration
);
/// @notice Retrieves a list of collaterals with configured LTVs
/// @return List of asset collaterals
/// @dev Returned assets could have the ltv disabled (set to zero)
function LTVList() external view returns (address[] memory);
/// @notice Retrieves the maximum liquidation discount
/// @return The maximum liquidation discount in 1e4 scale
/// @dev The default value, which is zero, is deliberately bad, as it means there would be no incentive to liquidate
/// unhealthy users. The vault creator must take care to properly select the limit, given the underlying and
/// collaterals used.
function maxLiquidationDiscount() external view returns (uint16);
/// @notice Retrieves liquidation cool-off time, which must elapse after successful account status check before
/// account can be liquidated
/// @return The liquidation cool off time in seconds
function liquidationCoolOffTime() external view returns (uint16);
/// @notice Retrieves a hook target and a bitmask indicating which operations call the hook target
/// @return hookTarget Address of the hook target contract
/// @return hookedOps Bitmask with operations that should call the hooks. See Constants.sol for a list of operations
function hookConfig() external view returns (address hookTarget, uint32 hookedOps);
/// @notice Retrieves a bitmask indicating enabled config flags
/// @return Bitmask with config flags enabled
function configFlags() external view returns (uint32);
/// @notice Address of EthereumVaultConnector contract
/// @return The EVC address
function EVC() external view returns (address);
/// @notice Retrieves a reference asset used for liquidity calculations
/// @return The address of the reference asset
function unitOfAccount() external view returns (address);
/// @notice Retrieves the address of the oracle contract
/// @return The address of the oracle
function oracle() external view returns (address);
/// @notice Retrieves the Permit2 contract address
/// @return The address of the Permit2 contract
function permit2Address() external view returns (address);
/// @notice Splits accrued fees balance according to protocol fee share and transfers shares to the governor fee
/// receiver and protocol fee receiver
function convertFees() external;
/// @notice Set a new governor address
/// @param newGovernorAdmin The new governor address
/// @dev Set to zero address to renounce privileges and make the vault non-governed
function setGovernorAdmin(address newGovernorAdmin) external;
/// @notice Set a new governor fee receiver address
/// @param newFeeReceiver The new fee receiver address
function setFeeReceiver(address newFeeReceiver) external;
/// @notice Set a new LTV config
/// @param collateral Address of collateral to set LTV for
/// @param borrowLTV New borrow LTV, for assessing account's health during account status checks, in 1e4 scale
/// @param liquidationLTV New liquidation LTV after ramp ends in 1e4 scale
/// @param rampDuration Ramp duration in seconds
function setLTV(address collateral, uint16 borrowLTV, uint16 liquidationLTV, uint32 rampDuration) external;
/// @notice Set a new maximum liquidation discount
/// @param newDiscount New maximum liquidation discount in 1e4 scale
/// @dev If the discount is zero (the default), the liquidators will not be incentivized to liquidate unhealthy
/// accounts
function setMaxLiquidationDiscount(uint16 newDiscount) external;
/// @notice Set a new liquidation cool off time, which must elapse after successful account status check before
/// account can be liquidated
/// @param newCoolOffTime The new liquidation cool off time in seconds
/// @dev Setting cool off time to zero allows liquidating the account in the same block as the last successful
/// account status check
function setLiquidationCoolOffTime(uint16 newCoolOffTime) external;
/// @notice Set a new interest rate model contract
/// @param newModel The new IRM address
/// @dev If the new model reverts, perhaps due to governor error, the vault will silently use a zero interest
/// rate. Governor should make sure the new interest rates are computed as expected.
function setInterestRateModel(address newModel) external;
/// @notice Set a new hook target and a new bitmap indicating which operations should call the hook target.
/// Operations are defined in Constants.sol.
/// @param newHookTarget The new hook target address. Use address(0) to simply disable hooked operations
/// @param newHookedOps Bitmask with the new hooked operations
/// @dev All operations are initially disabled in a newly created vault. The vault creator must set their
/// own configuration to make the vault usable
function setHookConfig(address newHookTarget, uint32 newHookedOps) external;
/// @notice Set new bitmap indicating which config flags should be enabled. Flags are defined in Constants.sol
/// @param newConfigFlags Bitmask with the new config flags
function setConfigFlags(uint32 newConfigFlags) external;
/// @notice Set new supply and borrow caps in AmountCap format
/// @param supplyCap The new supply cap in AmountCap fromat
/// @param borrowCap The new borrow cap in AmountCap fromat
function setCaps(uint16 supplyCap, uint16 borrowCap) external;
/// @notice Set a new interest fee
/// @param newFee The new interest fee
function setInterestFee(uint16 newFee) external;
}
/// @title IEVault
/// @custom:security-contact security@euler.xyz
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice Interface of the EVault, an EVC enabled lending vault
interface IEVault is
IInitialize,
IToken,
IVault,
IBorrowing,
ILiquidation,
IRiskManager,
IBalanceForwarder,
IGovernance
{
/// @notice Fetch address of the `Initialize` module
function MODULE_INITIALIZE() external view returns (address);
/// @notice Fetch address of the `Token` module
function MODULE_TOKEN() external view returns (address);
/// @notice Fetch address of the `Vault` module
function MODULE_VAULT() external view returns (address);
/// @notice Fetch address of the `Borrowing` module
function MODULE_BORROWING() external view returns (address);
/// @notice Fetch address of the `Liquidation` module
function MODULE_LIQUIDATION() external view returns (address);
/// @notice Fetch address of the `RiskManager` module
function MODULE_RISKMANAGER() external view returns (address);
/// @notice Fetch address of the `BalanceForwarder` module
function MODULE_BALANCE_FORWARDER() external view returns (address);
/// @notice Fetch address of the `Governance` module
function MODULE_GOVERNANCE() external view returns (address);
}
"
},
"lib/euler-price-oracle/src/EulerRouter.sol": {
"content": "// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;
import {IERC4626} from "forge-std/interfaces/IERC4626.sol";
import {IPriceOracle} from "./interfaces/IPriceOracle.sol";
import {Errors} from "./lib/Errors.sol";
import {Governable} from "./lib/Governable.sol";
/// @title EulerRouter
/// @custom:security-contact security@euler.xyz
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice Default Oracle resolver for Euler lending products.
/// @dev Integration Note: The router supports pricing via `convertToAssets` for trusted `resolvedVaults`.
/// By ERC4626 spec `convert*` ignores liquidity restrictions, fees, slippage and per-user restrictions.
/// Therefore the reported price may not be realizable through `redeem` or `withdraw`.
contract EulerRouter is Governable, IPriceOracle {
/// @inheritdoc IPriceOracle
string public constant name = "EulerRouter";
/// @notice The PriceOracle to call if this router is not configured for base/quote.
/// @dev If `address(0)` then there is no fallback.
address public fallbackOracle;
/// @notice ERC4626 vaults resolved using internal pricing (`convertToAssets`).
mapping(address vault => address asset) public resolvedVaults;
/// @notice PriceOracle configured per asset pair.
/// @dev The keys are lexicographically sorted (asset0 < asset1).
mapping(address asset0 => mapping(address asset1 => address oracle)) internal oracles;
/// @notice Configure a PriceOracle to resolve an asset pair.
/// @param asset0 The address first in lexicographic order.
/// @param asset1 The address second in lexicographic order.
/// @param oracle The address of the PriceOracle that resolves the pair.
/// @dev If `oracle` is `address(0)` then the configuration was removed.
/// The keys are lexicographically sorted (asset0 < asset1).
event ConfigSet(address indexed asset0, address indexed asset1, address indexed oracle);
/// @notice Set a PriceOracle as a fallback resolver.
/// @param fallbackOracle The address of the PriceOracle that is called when base/quote is not configured.
/// @dev If `fallbackOracle` is `address(0)` then there is no fallback resolver.
event FallbackOracleSet(address indexed fallbackOracle);
/// @notice Mark an ERC4626 vault to be resolved to its `asset` via its `convert*` methods.
/// @param vault The address of the ERC4626 vault.
/// @param asset The address of the vault's asset.
/// @dev If `asset` is `address(0)` then the configuration was removed.
event ResolvedVaultSet(address indexed vault, address indexed asset);
/// @notice Deploy EulerRouter.
/// @param _governor The address of the governor.
constructor(address _evc, address _governor) Governable(_evc, _governor) {
if (_governor == address(0)) revert Errors.PriceOracle_InvalidConfiguration();
}
/// @notice Configure a PriceOracle to resolve base/quote and quote/base.
/// @param base The address of the base token.
/// @param quote The address of the quote token.
/// @param oracle The address of the PriceOracle to resolve the pair.
/// @dev Callable only by the governor.
function govSetConfig(address base, address quote, address oracle) external onlyEVCAccountOwner onlyGovernor {
// This case is handled by `resolveOracle`.
if (base == quote) revert Errors.PriceOracle_InvalidConfiguration();
(address asset0, address asset1) = _sort(base, quote);
oracles[asset0][asset1] = oracle;
emit ConfigSet(asset0, asset1, oracle);
}
/// @notice Configure an ERC4626 vault to use internal pricing via `convert*` methods.
/// @param vault The address of the ERC4626 vault.
/// @param set True to configure the vault, false to clear the record.
/// @dev Callable only by the governor. Vault must implement ERC4626.
/// Note: Before configuring a vault verify that its `convertToAssets` is secure.
function govSetResolvedVault(address vault, bool set) external onlyEVCAccountOwner onlyGovernor {
address asset = set ? IERC4626(vault).asset() : address(0);
resolvedVaults[vault] = asset;
emit ResolvedVaultSet(vault, asset);
}
/// @notice Set a PriceOracle as a fallback resolver.
/// @param _fallbackOracle The address of the PriceOracle that is called when base/quote is not configured.
/// @dev Callable only by the governor. `address(0)` removes the fallback.
function govSetFallbackOracle(address _fallbackOracle) external onlyEVCAccountOwner onlyGovernor {
fallbackOracle = _fallbackOracle;
emit FallbackOracleSet(_fallbackOracle);
}
/// @inheritdoc IPriceOracle
function getQuote(uint256 inAmount, address base, address quote) external view returns (uint256) {
address oracle;
(inAmount, base, quote, oracle) = resolveOracle(inAmount, base, quote);
if (base == quote) return inAmount;
return IPriceOracle(oracle).getQuote(inAmount, base, quote);
}
/// @inheritdoc IPriceOracle
function getQuotes(uint256 inAmount, address base, address quote) external view returns (uint256, uint256) {
address oracle;
(inAmount, base, quote, oracle) = resolveOracle(inAmount, base, quote);
if (base == quote) return (inAmount, inAmount);
return IPriceOracle(oracle).getQuotes(inAmount, base, quote);
}
/// @notice Get the PriceOracle configured for base/quote.
/// @param base The address of the base token.
/// @param quote The address of the quote token.
/// @return The configured `PriceOracle` for the pair or `address(0)` if no oracle is configured.
function getConfiguredOracle(address base, address quote) public view returns (address) {
(address asset0, address asset1) = _sort(base, quote);
return oracles[asset0][asset1];
}
/// @notice Resolve the PriceOracle to call for a given base/quote pair.
/// @param inAmount The amount of `base` to convert.
/// @param base The token that is being priced.
/// @param quote The token that is the unit of account.
/// @dev Implements the following resolution logic:
/// 1. Check the base case: `base == quote` and terminate if true.
/// 2. If a PriceOracle is configured for base/quote in the `oracles` mapping, return it.
/// 3. If `base` is configured as a resolved ERC4626 vault, call `convertToAssets(inAmount)`
/// and continue the recursion, substituting the ERC4626 `asset` for `base`.
/// 4. As a last resort, return the fallback oracle or revert if it is not set.
/// @return The resolved amount. This value may be different from the original `inAmount`
/// if the resolution path included an ERC4626 vault present in `resolvedVaults`.
/// @return The resolved base.
/// @return The resolved quote.
/// @return The resolved PriceOracle to call.
function resolveOracle(uint256 inAmount, address base, address quote)
public
view
returns (uint256, /* resolvedAmount */ address, /* base */ address, /* quote */ address /* oracle */ )
{
// 1. Check the base case.
if (base == quote) return (inAmount, base, quote, address(0));
// 2. Check if there is a PriceOracle configured for base/quote.
address oracle = getConfiguredOracle(base, quote);
if (oracle != address(0)) return (inAmount, base, quote, oracle);
// 3. Recursively resolve `base`.
address baseAsset = resolvedVaults[base];
if (baseAsset != address(0)) {
inAmount = IERC4626(base).convertToAssets(inAmount);
return resolveOracle(inAmount, baseAsset, quote);
}
// 4. Return the fallback or revert if not configured.
oracle = fallbackOracle;
if (oracle == address(0)) revert Errors.PriceOracle_NotSupported(base, quote);
return (inAmount, base, quote, oracle);
}
/// @notice Lexicographically sort two addresses.
/// @param assetA One of the assets in the pair.
/// @param assetB The other asset in the pair.
/// @return The address first in lexicographic order.
/// @return The address second in lexicographic order.
function _sort(address assetA, address assetB) internal pure returns (address, address) {
return assetA < assetB ? (assetA, assetB) : (assetB, assetA);
}
}
"
},
"lib/euler-vault-kit/lib/ethereum-vault-connector/src/interfaces/IEthereumVaultConnector.sol": {
"content": "// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.8.0;
/// @title IEVC
/// @custom:security-contact security@euler.xyz
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice This interface defines the methods for the Ethereum Vault Connector.
interface IEVC {
/// @notice A struct representing a batch item.
/// @dev Each batch item represents a single operation to be performed within a checks deferred context.
struct BatchItem {
/// @notice The target contract to be called.
address targetContract;
/// @notice The account on behalf of which the operation is to be performed. msg.sender must be authorized to
/// act on behalf of this account. Must be address(0) if the target contract is the EVC itself.
address onBehalfOfAccount;
/// @notice The amount of value to be forwarded with the call. If the value is type(uint256).max, the whole
/// balance of the EVC contract will be forwarded. Must be 0 if the target contract is the EVC itself.
uint256 value;
/// @notice The encoded data which is called on the target contract.
bytes data;
}
/// @notice A struct representing the result of a batch item operation.
/// @dev Used only for simulation purposes.
struct BatchItemResult {
/// @notice A boolean indicating whether the operation was successful.
bool success;
/// @notice The result of the operation.
bytes result;
}
/// @notice A struct representing the result of the account or vault status check.
/// @dev Used only for simulation purposes.
struct StatusCheckResult {
/// @notice The address of the account or vault for which the check was performed.
address checkedAddress;
/// @notice A boolean indicating whether the status of the account or vault is valid.
bool isValid;
/// @notice The result of the check.
bytes result;
}
/// @notice Returns current raw execution context.
/// @dev When checks in progress, on behalf of account is always address(0).
/// @return context Current raw execution context.
function getRawExecutionContext() external view returns (uint256 context);
/// @notice Returns an account on behalf of which the operation is being executed at the moment and whether the
/// controllerToCheck is an enabled controller for that account.
/// @dev This function should only be used by external smart contracts if msg.sender is the EVC. Otherwise, the
/// account address returned must not be trusted.
/// @dev When checks in progress, on behalf of account is always address(0). When address is zero, the function
/// reverts to protect the consumer from ever relying on the on behalf of account address which is in its default
/// state.
/// @param controllerToCheck The address of the controller for which it is checked whether it is an enabled
/// controller for the account on behalf of which the operation is being executed at the moment.
/// @return onBehalfOfAccount An account that has been authenticated and on behalf of which the operation is being
/// executed at the moment.
/// @return controllerEnabled A boolean value that indicates whether controllerToCheck is an enabled controller for
/// the account on behalf of which the operation is being executed at the moment. Always false if controllerToCheck
/// is address(0).
function getCurrentOnBehalfOfAccount(address controllerToCheck)
external
view
returns (address onBehalfOfAccount, bool controllerEnabled);
/// @notice Checks if checks are deferred.
/// @return A boolean indicating whether checks are deferred.
function areChecksDeferred() external view returns (bool);
/// @notice Checks if checks are in progress.
/// @return A boolean indicating whether checks are in progress.
function areChecksInProgress() external view returns (bool);
/// @notice Checks if control collateral is in progress.
/// @return A boolean indicating whether control collateral is in progress.
function isControlCollateralInProgress() external view returns (bool);
/// @notice Checks if an operator is authenticated.
/// @return A boolean indicating whether an operator is authenticated.
function isOperatorAuthenticated() external view returns (bool);
/// @notice Checks if a simulation is in progress.
/// @return A boolean indicating whether a simulation is in progress.
function isSimulationInProgress() external view returns (bool);
/// @notice Checks whether the specified account and the other account have the same owner.
/// @dev The function is used to check whether one account is authorized to perform operations on behalf of the
/// other. Accounts are considered to have a common owner if they share the first 19 bytes of their address.
/// @param account The address of the account that is being checked.
/// @param otherAccount The address of the other account that is being checked.
/// @return A boolean flag that indicates whether the accounts have the same owner.
function haveCommonOwner(address account, address otherAccount) external pure returns (bool);
/// @notice Returns the address prefix of the specified account.
/// @dev The address prefix is the first 19 bytes of the account address.
/// @param account The address of the account whose address prefix is being retrieved.
/// @return A bytes19 value that represents the address prefix of the account.
function getAddressPrefix(address account) external pure returns (bytes19);
/// @notice Returns the owner for the specified account.
/// @dev The function returns address(0) if the owner is not registered. Registration of the owner happens on the
/// initial
/// interaction with the EVC that requires authentication of an owner.
/// @param account The address of the account whose owner is being retrieved.
/// @return owner The address of the account owner. An account owner is an EOA/smart contract which address matches
/// the first 19 bytes of the account address.
function getAccountOwner(address account) external view returns (address);
/// @notice Checks if lockdown mode is enabled for a given address prefix.
/// @param addressPrefix The address prefix to check for lockdown mode status.
/// @return A boolean indicating whether lockdown mode is enabled.
function isLockdownMode(bytes19 addressPrefix) external view returns (bool);
/// @notice Checks if permit functionality is disabled for a given address prefix.
/// @param addressPrefix The address prefix to check for permit functionality status.
/// @return A boolean indicating whether permit functionality is disabled.
function isPermitDisabledMode(bytes19 addressPrefix) external view returns (bool);
/// @notice Returns the current nonce for a given address prefix and nonce namespace.
/// @dev Each nonce namespace provides 256 bit nonce that has to be used sequentially. There's no requirement to use
/// all the nonces for a given nonce namespace before moving to the next one which allows to use permit messages in
/// a non-sequential manner.
/// @param addressPrefix The address prefix for which the nonce is being retrieved.
/// @param nonceNamespace The nonce namespace for which the nonce is being retrieved.
/// @return nonce The current nonce for the given address prefix and nonce namespace.
function getNonce(bytes19 addressPrefix, uint256 nonceNamespace) external view returns (uint256 nonce);
/// @notice Returns the bit field for a given address prefix and operator.
/// @dev The bit field is used to store information about authorized operators for a given address prefix. Each bit
/// in the bit field corresponds to one account belonging to the same owner. If the bit is set, the operator is
/// authorized for the account.
/// @param addressPrefix The address prefix for which the bit field is being retrieved.
/// @param operator The address of the operator for which the bit field is being retrieved.
/// @return operatorBitField The bit field for the given address prefix and operator. The bit field defines which
/// accounts the operator is authorized for. It is a 256-position binary array like 0...010...0, marking the account
/// positionally in a uint256. The position in the bit field corresponds to the account ID (0-255), where 0 is the
/// owner account's ID.
function getOperator(bytes19 addressPrefix, address operator) external view returns (uint256 operatorBitField);
/// @notice Returns whether a given operator has been authorized for a given account.
/// @param account The address of the account whose operator is being checked.
/// @param operator The address of the operator that is being checked.
/// @return authorized A boolean value that indicates whether the operator is authorized for the account.
function isAccountOperatorAuthorized(address account, address operator) external view returns (bool authorized);
/// @notice Enables or disables lockdown mode for a given address prefix.
/// @dev This function can only be called by the owner of the address prefix. To disable this mode, the EVC
/// must be called directly. It is not possible to disable this mode by using checks-deferrable call or
/// permit message.
/// @param addressPrefix The address prefix for which the lockdown mode is being set.
/// @param enabled A boolean indicating whether to enable or disable lockdown mode.
function setLockdownMode(bytes19 addressPrefix, bool enabled) external payable;
/// @notice Enables or disables permit functionality for a given address prefix.
/// @dev This function can only be called by the owner of the address prefix. To disable this mode, the EVC
/// must be called directly. It is not possible to disable this mode by using checks-deferrable call or (by
/// definition) permit message. To support permit functionality by default, note that the logic was inverted here. To
/// disable the permit functionality, one must pass true as the second argument. To enable the permit
/// functionality, one must pass false as the second argument.
/// @param addressPrefix The address prefix for which the permit functionality is being set.
/// @param enabled A boolean indicating whether to enable or disable the disable-permit mode.
function setPermitDisabledMode(bytes19 addressPrefix, bool enabled) external payable;
/// @notice Sets the nonce for a given address prefix and nonce namespace.
/// @dev This function can only be called by the owner of the address prefix. Each nonce namespace provides a 256
/// bit nonce that has to be used sequentially. There's no requirement to use all the nonces for a given nonce
/// namespace before moving to the next one which allows the use of permit messages in a non-sequential manner. To
/// invalidate signed permit messages, set the nonce for a given nonce namespace accordingly. To invalidate all the
/// permit messages for a given nonce namespace, set the nonce to type(uint).max.
/// @param addressPrefix The address prefix for which the nonce is being set.
/// @param nonceNamespace The nonce namespace for which the nonce is being set.
/// @param nonce The new nonce for the given address prefix and nonce namespace.
function setNonce(bytes19 addressPrefix, uint256 nonceNamespace, uint256 nonce) external payable;
/// @notice Sets the bit field for a given address prefix and operator.
/// @dev This function can only be called by the owner of the address prefix. Each bit in the bit field corresponds
/// to one account belonging to the same owner. If the bit is set, the operator is authorized for the account.
/// @param addressPrefix The address prefix for which the bit field is being set.
/// @param operator The address of the operator for which the bit field is being set. Can neither be the EVC address
/// nor an address belonging to the same address prefix.
/// @param operatorBitField The new bit field for the given address prefix and operator. Reverts if the provided
/// value is equal to the currently stored value.
function setOperator(bytes19 addressPrefix, address operator, uint256 operatorBitField) external payable;
/// @notice Authorizes or deauthorizes an operator for the account.
/// @dev Only the owner or authorized operator of the account can call this function. An operator is an address t
Submitted on: 2025-09-17 12:30:20
Comments
Log in to comment.
No comments yet.