Skip to main content

EthereumVaultConnector

Git Source

Inherits: Events, Errors, TransientStorage, IEVC

Author: Euler Labs (https://www.eulerlabs.com/)

This contract implements the Ethereum Vault Connector.

State Variables

name

Name of the Ethereum Vault Connector.

string public constant name = "Ethereum Vault Connector";

version

Version of the Ethereum Vault Connector.

string public constant version = "1";

ACCOUNT_ID_OFFSET

uint160 internal constant ACCOUNT_ID_OFFSET = 8;

HASHED_NAME

bytes32 internal constant HASHED_NAME = keccak256(bytes(name));

HASHED_VERSION

bytes32 internal constant HASHED_VERSION = keccak256(bytes(version));

TYPE_HASH

bytes32 internal constant TYPE_HASH =
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");

PERMIT_TYPEHASH

bytes32 internal constant PERMIT_TYPEHASH = keccak256(
"Permit(address signer,address sender,uint256 nonceNamespace,uint256 nonce,uint256 deadline,uint256 value,bytes data)"
);

CACHED_CHAIN_ID

uint256 internal immutable CACHED_CHAIN_ID;

CACHED_DOMAIN_SEPARATOR

bytes32 internal immutable CACHED_DOMAIN_SEPARATOR;

ownerLookup

mapping(bytes19 addressPrefix => OwnerStorage) internal ownerLookup;

operatorLookup

mapping(bytes19 addressPrefix => mapping(address operator => uint256 operatorBitField)) internal operatorLookup;

nonceLookup

mapping(bytes19 addressPrefix => mapping(uint256 nonceNamespace => uint256 nonce)) internal nonceLookup;

accountCollaterals

mapping(address account => SetStorage) internal accountCollaterals;

accountControllers

mapping(address account => SetStorage) internal accountControllers;

Functions

constructor

constructor();

receive

Fallback function to receive Ether.

receive() external payable;

onlyOwner

A modifier that allows only the address recorded as an owner of the address prefix to call the function.

The owner of an address prefix is an address that matches the address that has previously been recorded (or will be) as an owner in the ownerLookup.

modifier onlyOwner(bytes19 addressPrefix);

Parameters

NameTypeDescription
addressPrefixbytes19The address prefix for which it is checked whether the caller is the owner.

onlyOwnerOrOperator

A modifier that allows only the owner or an operator of the account to call the function.

The owner of an address prefix is an address that matches the address that has previously been recorded (or will be) as an owner in the ownerLookup. An operator of an account is an address that has been authorized by the owner of an account to perform operations on behalf of the owner.

modifier onlyOwnerOrOperator(address account);

Parameters

NameTypeDescription
accountaddressThe address of the account for which it is checked whether the caller is the owner or an operator.

onlyController

A modifier checks whether msg.sender is the only controller for the account.

The controller cannot use permit function in conjunction with this modifier.

modifier onlyController(address account);

nonReentrantChecks

A modifier that verifies whether account or vault status checks are re-entered.

modifier nonReentrantChecks();

nonReentrantChecksAndControlCollateral

A modifier that verifies whether account or vault status checks are re-entered as well as checks for controlCollateral re-entrancy.

modifier nonReentrantChecksAndControlCollateral();

nonReentrantChecksAcquireLock

A modifier that verifies whether account or vault status checks are re-entered and sets the lock.

This modifier also clears the current account on behalf of which the operation is performed as it shouldn't be relied upon when the checks are in progress.

modifier nonReentrantChecksAcquireLock();

getRawExecutionContext

Returns current raw execution context.

When checks in progress, on behalf of account is always address(0).

function getRawExecutionContext() external view returns (uint256 context);

Returns

NameTypeDescription
contextuint256Current raw execution context.

getCurrentOnBehalfOfAccount

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.

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.

function getCurrentOnBehalfOfAccount(address controllerToCheck)
external
view
returns (address onBehalfOfAccount, bool controllerEnabled);

Parameters

NameTypeDescription
controllerToCheckaddressThe 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.

Returns

NameTypeDescription
onBehalfOfAccountaddressAn account that has been authenticated and on behalf of which the operation is being executed at the moment.
controllerEnabledboolA 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).

areChecksDeferred

Checks if checks are deferred.

function areChecksDeferred() external view returns (bool);

Returns

NameTypeDescription
<none>boolA boolean indicating whether checks are deferred.

areChecksInProgress

Checks if checks are in progress.

function areChecksInProgress() external view returns (bool);

Returns

NameTypeDescription
<none>boolA boolean indicating whether checks are in progress.

isControlCollateralInProgress

Checks if control collateral is in progress.

function isControlCollateralInProgress() external view returns (bool);

Returns

NameTypeDescription
<none>boolA boolean indicating whether control collateral is in progress.

isOperatorAuthenticated

Checks if an operator is authenticated.

function isOperatorAuthenticated() external view returns (bool);

Returns

NameTypeDescription
<none>boolA boolean indicating whether an operator is authenticated.

isSimulationInProgress

Checks if a simulation is in progress.

function isSimulationInProgress() external view returns (bool);

Returns

NameTypeDescription
<none>boolA boolean indicating whether a simulation is in progress.

haveCommonOwner

Checks whether the specified account and the other account have the same owner.

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.

function haveCommonOwner(address account, address otherAccount) external pure returns (bool);

Parameters

NameTypeDescription
accountaddressThe address of the account that is being checked.
otherAccountaddressThe address of the other account that is being checked.

Returns

NameTypeDescription
<none>boolA boolean flag that indicates whether the accounts have the same owner.

getAddressPrefix

Returns the address prefix of the specified account.

The address prefix is the first 19 bytes of the account address.

function getAddressPrefix(address account) external pure returns (bytes19);

Parameters

NameTypeDescription
accountaddressThe address of the account whose address prefix is being retrieved.

Returns

NameTypeDescription
<none>bytes19A bytes19 value that represents the address prefix of the account.

getAccountOwner

Returns the owner for the specified account.

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.

function getAccountOwner(address account) external view returns (address);

Parameters

NameTypeDescription
accountaddressThe address of the account whose owner is being retrieved.

Returns

NameTypeDescription
<none>addressowner 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.

isLockdownMode

Checks if lockdown mode is enabled for a given address prefix.

function isLockdownMode(bytes19 addressPrefix) external view returns (bool);

Parameters

NameTypeDescription
addressPrefixbytes19The address prefix to check for lockdown mode status.

Returns

NameTypeDescription
<none>boolA boolean indicating whether lockdown mode is enabled.

isPermitDisabledMode

Checks if permit functionality is disabled for a given address prefix.

function isPermitDisabledMode(bytes19 addressPrefix) external view returns (bool);

Parameters

NameTypeDescription
addressPrefixbytes19The address prefix to check for permit functionality status.

Returns

NameTypeDescription
<none>boolA boolean indicating whether permit functionality is disabled.

getNonce

Returns the current nonce for a given address prefix and nonce namespace.

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.

function getNonce(bytes19 addressPrefix, uint256 nonceNamespace) external view returns (uint256);

Parameters

NameTypeDescription
addressPrefixbytes19The address prefix for which the nonce is being retrieved.
nonceNamespaceuint256The nonce namespace for which the nonce is being retrieved.

Returns

NameTypeDescription
<none>uint256nonce The current nonce for the given address prefix and nonce namespace.

getOperator

Returns the bit field for a given address prefix and operator.

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.

function getOperator(bytes19 addressPrefix, address operator) external view returns (uint256);

Parameters

NameTypeDescription
addressPrefixbytes19The address prefix for which the bit field is being retrieved.
operatoraddressThe address of the operator for which the bit field is being retrieved.

Returns

NameTypeDescription
<none>uint256operatorBitField 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.

isAccountOperatorAuthorized

Returns whether a given operator has been authorized for a given account.

function isAccountOperatorAuthorized(address account, address operator) external view returns (bool);

Parameters

NameTypeDescription
accountaddressThe address of the account whose operator is being checked.
operatoraddressThe address of the operator that is being checked.

Returns

NameTypeDescription
<none>boolauthorized A boolean value that indicates whether the operator is authorized for the account.

setLockdownMode

Enables or disables lockdown mode for a given address prefix.

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.

function setLockdownMode(bytes19 addressPrefix, bool enabled) public payable virtual onlyOwner(addressPrefix);

Parameters

NameTypeDescription
addressPrefixbytes19The address prefix for which the lockdown mode is being set.
enabledboolA boolean indicating whether to enable or disable lockdown mode.

setPermitDisabledMode

Enables or disables permit functionality for a given address prefix.

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.

function setPermitDisabledMode(bytes19 addressPrefix, bool enabled) public payable virtual onlyOwner(addressPrefix);

Parameters

NameTypeDescription
addressPrefixbytes19The address prefix for which the permit functionality is being set.
enabledboolA boolean indicating whether to enable or disable the disable-permit mode.

setNonce

Sets the nonce for a given address prefix and nonce namespace.

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.

function setNonce(
bytes19 addressPrefix,
uint256 nonceNamespace,
uint256 nonce
) public payable virtual onlyOwner(addressPrefix);

Parameters

NameTypeDescription
addressPrefixbytes19The address prefix for which the nonce is being set.
nonceNamespaceuint256The nonce namespace for which the nonce is being set.
nonceuint256The new nonce for the given address prefix and nonce namespace.

setOperator

Sets the bit field for a given address prefix and operator.

Uses authenticateCaller() function instead of onlyOwner() modifier to authenticate and get the caller address at once.

function setOperator(bytes19 addressPrefix, address operator, uint256 operatorBitField) public payable virtual;

Parameters

NameTypeDescription
addressPrefixbytes19The address prefix for which the bit field is being set.
operatoraddressThe 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.
operatorBitFielduint256The new bit field for the given address prefix and operator. Reverts if the provided value is equal to the currently stored value.

setAccountOperator

Authorizes or deauthorizes an operator for the account.

Uses authenticateCaller() function instead of onlyOwnerOrOperator() modifier to authenticate and get the caller address at once.

function setAccountOperator(address account, address operator, bool authorized) public payable virtual;

Parameters

NameTypeDescription
accountaddressThe address of the account whose operator is being set or unset.
operatoraddressThe address of the operator that is being installed or uninstalled. Can neither be the EVC address nor an address belonging to the same owner as the account.
authorizedboolA boolean value that indicates whether the operator is being authorized or deauthorized. Reverts if the provided value is equal to the currently stored value.

getCollaterals

Returns an array of collaterals enabled for an account.

A collateral is a vault for which an account's balances are under the control of the currently enabled controller vault.

function getCollaterals(address account) external view returns (address[] memory);

Parameters

NameTypeDescription
accountaddressThe address of the account whose collaterals are being queried.

Returns

NameTypeDescription
<none>address[]An array of addresses that are enabled collaterals for the account.

isCollateralEnabled

Returns whether a collateral is enabled for an account.

A collateral is a vault for which account's balances are under the control of the currently enabled controller vault.

function isCollateralEnabled(address account, address vault) external view returns (bool);

Parameters

NameTypeDescription
accountaddressThe address of the account that is being checked.
vaultaddressThe address of the collateral that is being checked.

Returns

NameTypeDescription
<none>boolA boolean value that indicates whether the vault is an enabled collateral for the account or not.

enableCollateral

Enables a collateral for an account.

A collaterals is a vault for which account's balances are under the control of the currently enabled controller vault. Only the owner or an operator of the account can call this function. Unless it's a duplicate, the collateral is added to the end of the array. There can be at most 10 unique collaterals enabled at a time. Account status checks are performed.

function enableCollateral(
address account,
address vault
) public payable virtual nonReentrantChecksAndControlCollateral onlyOwnerOrOperator(account);

Parameters

NameTypeDescription
accountaddressThe account address for which the collateral is being enabled.
vaultaddressThe address being enabled as a collateral.

disableCollateral

Disables a collateral for an account.

This function does not preserve the order of collaterals in the array obtained using the getCollaterals function; the order may change. A collateral is a vault for which account’s balances are under the control of the currently enabled controller vault. Only the owner or an operator of the account can call this function. Disabling a collateral might change the order of collaterals in the array obtained using getCollaterals function. Account status checks are performed.

function disableCollateral(
address account,
address vault
) public payable virtual nonReentrantChecksAndControlCollateral onlyOwnerOrOperator(account);

Parameters

NameTypeDescription
accountaddressThe account address for which the collateral is being disabled.
vaultaddressThe address of a collateral being disabled.

reorderCollaterals

Swaps the position of two collaterals so that they appear switched in the array of collaterals for a given account obtained by calling getCollaterals function.

A collateral is a vault for which account’s balances are under the control of the currently enabled controller vault. Only the owner or an operator of the account can call this function. The order of collaterals can be changed by specifying the indices of the two collaterals to be swapped. Indices are zero-based and must be in the range of 0 to the number of collaterals minus 1. index1 must be lower than index2. Account status checks are performed.

function reorderCollaterals(
address account,
uint8 index1,
uint8 index2
) public payable virtual nonReentrantChecksAndControlCollateral onlyOwnerOrOperator(account);

Parameters

NameTypeDescription
accountaddressThe address of the account for which the collaterals are being reordered.
index1uint8The index of the first collateral to be swapped.
index2uint8The index of the second collateral to be swapped.

getControllers

Returns an array of enabled controllers for an account.

A controller is a vault that has been chosen for an account to have special control over the account's balances in enabled collaterals vaults. A user can have multiple controllers during a call execution, but at most one can be selected when the account status check is performed.

function getControllers(address account) external view returns (address[] memory);

Parameters

NameTypeDescription
accountaddressThe address of the account whose controllers are being queried.

Returns

NameTypeDescription
<none>address[]An array of addresses that are the enabled controllers for the account.

isControllerEnabled

Returns whether a controller is enabled for an account.

A controller is a vault that has been chosen for an account to have special control over account’s balances in the enabled collaterals vaults.

function isControllerEnabled(address account, address vault) external view returns (bool);

Parameters

NameTypeDescription
accountaddressThe address of the account that is being checked.
vaultaddressThe address of the controller that is being checked.

Returns

NameTypeDescription
<none>boolA boolean value that indicates whether the vault is enabled controller for the account or not.

enableController

Enables a controller for an account.

A controller is a vault that has been chosen for an account to have special control over account’s balances in the enabled collaterals vaults. Only the owner or an operator of the account can call this function. Unless it's a duplicate, the controller is added to the end of the array. Transiently, there can be at most 10 unique controllers enabled at a time, but at most one can be enabled after the outermost checks-deferrable call concludes. Account status checks are performed.

function enableController(
address account,
address vault
) public payable virtual nonReentrantChecksAndControlCollateral onlyOwnerOrOperator(account);

Parameters

NameTypeDescription
accountaddressThe address for which the controller is being enabled.
vaultaddressThe address of the controller being enabled.

disableController

Disables a controller for an account.

A controller is a vault that has been chosen for an account to have special control over account’s balances in the enabled collaterals vaults. Only the vault itself can call this function. Disabling a controller might change the order of controllers in the array obtained using getControllers function. Account status checks are performed.

function disableController(address account) public payable virtual nonReentrantChecksAndControlCollateral;

Parameters

NameTypeDescription
accountaddressThe address for which the calling controller is being disabled.

permit

Executes signed arbitrary data by self-calling into the EVC.

Low-level call function is used to execute the arbitrary data signed by the owner or the operator on the EVC contract. During that call, EVC becomes msg.sender.

function permit(
address signer,
address sender,
uint256 nonceNamespace,
uint256 nonce,
uint256 deadline,
uint256 value,
bytes calldata data,
bytes calldata signature
) public payable virtual nonReentrantChecksAndControlCollateral;

Parameters

NameTypeDescription
signeraddressThe address signing the permit message (ECDSA) or verifying the permit message signature (ERC-1271). It's also the owner or the operator of all the accounts for which authentication will be needed during the execution of the arbitrary data call.
senderaddressThe address of the msg.sender which is expected to execute the data signed by the signer. If address(0) is passed, the msg.sender is ignored.
nonceNamespaceuint256The nonce namespace for which the nonce is being used.
nonceuint256The nonce for the given account and nonce namespace. A valid nonce value is considered to be the value currently stored and can take any value between 0 and type(uint256).max - 1.
deadlineuint256The timestamp after which the permit is considered expired.
valueuint256The 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.
databytesThe encoded data which is self-called on the EVC contract.
signaturebytesThe signature of the data signed by the signer.

call

Calls into a target contract as per data encoded.

This function defers the account and vault status checks (it's a checks-deferrable call). If the outermost call ends, the account and vault status checks are performed.

function call(
address targetContract,
address onBehalfOfAccount,
uint256 value,
bytes calldata data
) public payable virtual nonReentrantChecksAndControlCollateral returns (bytes memory result);

Parameters

NameTypeDescription
targetContractaddressThe address of the contract to be called.
onBehalfOfAccountaddressIf the target contract is msg.sender, the address of the account which will be set in the context. It assumes msg.sender has authenticated the account themselves. If the target contract is not msg.sender, the address of the account for which it is checked whether msg.sender is authorized to act on behalf of.
valueuint256The 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.
databytesThe encoded data which is called on the target contract.

Returns

NameTypeDescription
resultbytesThe result of the call.

controlCollateral

For a given account, calls into one of the enabled collateral vaults from the currently enabled controller vault as per data encoded.

This function defers the account and vault status checks (it's a checks-deferrable call). If the outermost call ends, the account and vault status checks are performed.

function controlCollateral(
address targetCollateral,
address onBehalfOfAccount,
uint256 value,
bytes calldata data
)
public
payable
virtual
nonReentrantChecksAndControlCollateral
onlyController(onBehalfOfAccount)
returns (bytes memory result);

Parameters

NameTypeDescription
targetCollateraladdressThe collateral address to be called.
onBehalfOfAccountaddressThe address of the account for which it is checked whether msg.sender is authorized to act on behalf.
valueuint256The 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.
databytesThe encoded data which is called on the target collateral.

Returns

NameTypeDescription
resultbytesThe result of the call.

batch

Executes multiple calls into the target contracts while checks deferred as per batch items provided.

This function defers the account and vault status checks (it's a checks-deferrable call). If the outermost call ends, the account and vault status checks are performed.

function batch(BatchItem[] calldata items) public payable virtual nonReentrantChecksAndControlCollateral;

Parameters

NameTypeDescription
itemsBatchItem[]An array of batch items to be executed.

batchRevert

Executes multiple calls into the target contracts while checks deferred as per batch items provided.

This function always reverts as it's only used for simulation purposes. This function cannot be called within a checks-deferrable call.

function batchRevert(BatchItem[] calldata items) public payable virtual nonReentrantChecksAndControlCollateral;

Parameters

NameTypeDescription
itemsBatchItem[]An array of batch items to be executed.

batchSimulation

Executes multiple calls into the target contracts while checks deferred as per batch items provided.

This function does not modify state and should only be used for simulation purposes. This function cannot be called within a checks-deferrable call.

function batchSimulation(BatchItem[] calldata items)
external
payable
virtual
returns (
BatchItemResult[] memory batchItemsResult,
StatusCheckResult[] memory accountsStatusCheckResult,
StatusCheckResult[] memory vaultsStatusCheckResult
);

Parameters

NameTypeDescription
itemsBatchItem[]An array of batch items to be executed.

Returns

NameTypeDescription
batchItemsResultBatchItemResult[]An array of batch item results for each item.
accountsStatusCheckResultStatusCheckResult[]An array of account status check results for each account.
vaultsStatusCheckResultStatusCheckResult[]An array of vault status check results for each vault.

getLastAccountStatusCheckTimestamp

Retrieves the timestamp of the last account status check performed for a specific account.

This function reverts if the checks are in progress.

function getLastAccountStatusCheckTimestamp(address account) external view nonReentrantChecks returns (uint256);

Parameters

NameTypeDescription
accountaddressThe address of the account for which the last status check timestamp is being queried.

Returns

NameTypeDescription
<none>uint256The timestamp of the last status check as a uint256.

isAccountStatusCheckDeferred

Checks whether the status check is deferred for a given account.

This function reverts if the checks are in progress.

function isAccountStatusCheckDeferred(address account) external view nonReentrantChecks returns (bool);

Parameters

NameTypeDescription
accountaddressThe address of the account for which it is checked whether the status check is deferred.

Returns

NameTypeDescription
<none>boolA boolean flag that indicates whether the status check is deferred or not.

requireAccountStatusCheck

Checks the status of an account and reverts if it is not valid.

If checks deferred, the account is added to the set of accounts to be checked at the end of the outermost checks-deferrable call. There can be at most 10 unique accounts added to the set at a time. Account status check is performed by calling into the selected controller vault and passing the array of currently enabled collaterals. If controller is not selected, the account is always considered valid.

function requireAccountStatusCheck(address account) public payable virtual;

Parameters

NameTypeDescription
accountaddressThe address of the account to be checked.

forgiveAccountStatusCheck

Forgives previously deferred account status check.

Account address is removed from the set of addresses for which status checks are deferred. This function can only be called by the currently enabled controller of a given account. Depending on the vault implementation, may be needed in the liquidation flow.

function forgiveAccountStatusCheck(address account)
public
payable
virtual
nonReentrantChecksAcquireLock
onlyController(account);

Parameters

NameTypeDescription
accountaddressThe address of the account for which the status check is forgiven.

isVaultStatusCheckDeferred

Checks whether the status check is deferred for a given vault.

This function reverts if the checks are in progress.

function isVaultStatusCheckDeferred(address vault) external view nonReentrantChecks returns (bool);

Parameters

NameTypeDescription
vaultaddressThe address of the vault for which it is checked whether the status check is deferred.

Returns

NameTypeDescription
<none>boolA boolean flag that indicates whether the status check is deferred or not.

requireVaultStatusCheck

Checks the status of a vault and reverts if it is not valid.

If checks deferred, the vault is added to the set of vaults to be checked at the end of the outermost checks-deferrable call. There can be at most 10 unique vaults added to the set at a time. This function can only be called by the vault itself.

function requireVaultStatusCheck() public payable virtual;

forgiveVaultStatusCheck

Forgives previously deferred vault status check.

Vault address is removed from the set of addresses for which status checks are deferred. This function can only be called by the vault itself.

function forgiveVaultStatusCheck() public payable virtual nonReentrantChecksAcquireLock;

requireAccountAndVaultStatusCheck

Checks the status of an account and a vault and reverts if it is not valid.

If checks deferred, the account and the vault are added to the respective sets of accounts and vaults to be checked at the end of the outermost checks-deferrable call. Account status check is performed by calling into selected controller vault and passing the array of currently enabled collaterals. If controller is not selected, the account is always considered valid. This function can only be called by the vault itself.

function requireAccountAndVaultStatusCheck(address account) public payable virtual;

Parameters

NameTypeDescription
accountaddressThe address of the account to be checked.

authenticateCaller

Authenticates the caller of a function.

This function checks if the caller is the owner or an authorized operator of the account, and if the account is not in lockdown mode.

function authenticateCaller(
address account,
bool allowOperator,
bool checkLockdownMode
) internal virtual returns (address);

Parameters

NameTypeDescription
accountaddressThe account address to authenticate the caller against.
allowOperatorboolA boolean indicating if operators are allowed to authenticate as the caller.
checkLockdownModeboolA boolean indicating if the function should check for lockdown mode on the account.

Returns

NameTypeDescription
<none>addressThe address of the authenticated caller.

authenticateCaller

Authenticates the caller of a function.

This function converts a bytes19 address prefix into a phantom account address which is an account address that belongs to the owner of the address prefix.

function authenticateCaller(
bytes19 addressPrefix,
bool allowOperator,
bool checkLockdownMode
) internal virtual returns (address);

Parameters

NameTypeDescription
addressPrefixbytes19The bytes19 address prefix to authenticate the caller against.
allowOperatorboolA boolean indicating if operators are allowed to authenticate as the caller.
checkLockdownModeboolA boolean indicating if the function should check for lockdown mode on the account.

Returns

NameTypeDescription
<none>addressThe address of the authenticated caller.

callWithContextInternal

Internal function to make a call to a target contract with a specific context.

This function sets the execution context for the duration of the call.

function callWithContextInternal(
address targetContract,
address onBehalfOfAccount,
uint256 value,
bytes calldata data
) internal virtual returns (bool success, bytes memory result);

Parameters

NameTypeDescription
targetContractaddressThe contract address to call.
onBehalfOfAccountaddressThe account address on behalf of which the call is made.
valueuint256The amount of value to send with the call.
databytesThe calldata to send with the call.

callWithAuthenticationInternal

Internal function to call a target contract with necessary authentication.

This function decides whether to use delegatecall or a regular call based on the target contract. If the target contract is this contract, it uses delegatecall to preserve msg.sender for authentication. Otherwise, it authenticates the caller if needed and proceeds with a regular call.

function callWithAuthenticationInternal(
address targetContract,
address onBehalfOfAccount,
uint256 value,
bytes calldata data
) internal virtual returns (bool success, bytes memory result);

Parameters

NameTypeDescription
targetContractaddressThe contract address to call.
onBehalfOfAccountaddressThe account address on behalf of which the call is made.
valueuint256The amount of value to send with the call.
databytesThe calldata to send with the call.

Returns

NameTypeDescription
successboolA boolean indicating if the call was successful.
resultbytesThe bytes returned from the call.

restoreExecutionContext

Restores the execution context from a cached state.

This function restores the execution context to a previously cached state, performing necessary status checks if they are no longer deferred. If checks are no longer deferred, it sets the execution context to indicate checks are in progress and clears the 'on behalf of' account. It then performs status checks for both accounts and vaults before restoring the execution context to the cached state.

function restoreExecutionContext(EC contextCache) internal virtual;

Parameters

NameTypeDescription
contextCacheECThe cached execution context to restore from.

checkAccountStatusInternal

Checks the status of an account internally.

This function first checks the number of controllers for the account. If there are no controllers enabled, it returns true immediately, indicating the account status is valid without further checks. If there is more than one controller, it reverts with an EVC_ControllerViolation error. For a single controller, it proceeds to call the controller to check the account status.

function checkAccountStatusInternal(address account) internal virtual returns (bool isValid, bytes memory result);

Parameters

NameTypeDescription
accountaddressThe account address to check the status for.

Returns

NameTypeDescription
isValidboolA boolean indicating if the account status is valid.
resultbytesThe bytes returned from the controller call, indicating the account status.

requireAccountStatusCheckInternal

function requireAccountStatusCheckInternal(address account) internal virtual;

requireAccountStatusCheckInternalNonReentrantChecks

function requireAccountStatusCheckInternalNonReentrantChecks(address account)
internal
virtual
nonReentrantChecksAcquireLock;

checkVaultStatusInternal

Checks the status of a vault internally.

This function makes an external call to the vault to check its status.

function checkVaultStatusInternal(address vault) internal returns (bool isValid, bytes memory result);

Parameters

NameTypeDescription
vaultaddressThe address of the vault to check the status for.

Returns

NameTypeDescription
isValidboolA boolean indicating if the vault status is valid.
resultbytesThe bytes returned from the vault call, indicating the vault status.

requireVaultStatusCheckInternal

function requireVaultStatusCheckInternal(address vault) internal virtual;

requireVaultStatusCheckInternalNonReentrantChecks

function requireVaultStatusCheckInternalNonReentrantChecks(address vault)
internal
virtual
nonReentrantChecksAcquireLock;

checkStatusAll

Checks the status of all entities in a set, either accounts or vaults, and clears the checks.

Iterates over either accountStatusChecks or vaultStatusChecks based on the setType and performs status checks. Clears the checks while performing them.

function checkStatusAll(SetType setType) internal virtual;

Parameters

NameTypeDescription
setTypeSetTypeThe type of set to perform the status checks on, either accounts or vaults.

checkStatusAllWithResult

function checkStatusAllWithResult(SetType setType) internal virtual returns (StatusCheckResult[] memory checksResult);

isSignerValid

Determines if the signer address is valid.

It's important to revisit this logic when deploying on chains other than the Ethereum mainnet. If new precompiles had been added to the Ethereum mainnet, the current implementation of the function would not be future-proof and would need to be updated.

function isSignerValid(address signer) internal pure virtual returns (bool);

Parameters

NameTypeDescription
signeraddressThe address of the signer to validate.

Returns

NameTypeDescription
<none>boolbool Returns true if the signer is valid, false otherwise.

getPermitHash

Computes the permit hash for a given set of parameters.

This function generates a permit hash using EIP712 typed data signing.

function getPermitHash(
address signer,
address sender,
uint256 nonceNamespace,
uint256 nonce,
uint256 deadline,
uint256 value,
bytes calldata data
) internal view returns (bytes32 permitHash);

Parameters

NameTypeDescription
signeraddressThe address of the signer.
senderaddress
nonceNamespaceuint256The namespace of the nonce.
nonceuint256The nonce value, ensuring permits are used once.
deadlineuint256The time until when the permit is valid.
valueuint256The value associated with the permit.
databytesCalldata associated with the permit.

Returns

NameTypeDescription
permitHashbytes32The computed permit hash.

recoverECDSASigner

Recovers the signer address from a hash and a signature. Based on: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/cryptography/ECDSA.sol Note that the function returns zero address if the signature is invalid hence the result always has to be checked against address zero.

function recoverECDSASigner(bytes32 hash, bytes memory signature) internal pure returns (address signer);

Parameters

NameTypeDescription
hashbytes32The hash of the signed data.
signaturebytesThe signature to recover the signer from.

Returns

NameTypeDescription
signeraddressThe address of the signer, or the zero address if signature recovery fails.

isValidERC1271Signature

Checks if a given signature is valid according to ERC-1271 standard.

This function is based on the implementation found in OpenZeppelin's SignatureChecker. See: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/cryptography/SignatureChecker.sol It performs a static call to the signer's address with the signature data and checks if the returned value matches the expected valid signature selector.

function isValidERC1271Signature(
address signer,
bytes32 hash,
bytes memory signature
) internal view returns (bool isValid);

Parameters

NameTypeDescription
signeraddressThe address of the signer to validate the signature against.
hashbytes32The hash of the data that was signed.
signaturebytesThe signature to validate.

Returns

NameTypeDescription
isValidboolTrue if the signature is valid according to ERC-1271, false otherwise.

calculateDomainSeparator

Calculates the EIP-712 domain separator for the contract.

function calculateDomainSeparator() internal view returns (bytes32);

Returns

NameTypeDescription
<none>bytes32The calculated EIP-712 domain separator as a bytes32 value.

_msgSender

Returns the message sender's address.

In the context of a permit self-call, it returns the account on behalf of which the call is made. Otherwise, it returns msg.sender.

function _msgSender() internal view virtual returns (address);

Returns

NameTypeDescription
<none>addressThe address of the message sender or the account on behalf of which the call is made.

inPermitSelfCall

Checks if the contract is in the context of a permit self-call.

EVC can only be msg.sender during the self-call in the permit function.

function inPermitSelfCall() internal view returns (bool);

Returns

NameTypeDescription
<none>boolTrue if the current call is a self-call within the permit function, false otherwise.

haveCommonOwnerInternal

Determines if two accounts have a common owner by comparing their address prefixes.

function haveCommonOwnerInternal(address account, address otherAccount) internal pure returns (bool result);

Parameters

NameTypeDescription
accountaddressThe first account address to compare.
otherAccountaddressThe second account address to compare.

Returns

NameTypeDescription
resultboolTrue if the accounts have a common owner, false otherwise.

getAddressPrefixInternal

Computes the address prefix for a given account address.

The address prefix is derived by right-shifting the account address by 8 bits which effectively reduces the address size to 19 bytes.

function getAddressPrefixInternal(address account) internal pure returns (bytes19);

Parameters

NameTypeDescription
accountaddressThe account address to compute the prefix for.

Returns

NameTypeDescription
<none>bytes19The computed address prefix as a bytes19 value.

getAccountOwnerInternal

Retrieves the owner of a given account by its address prefix.

function getAccountOwnerInternal(address account) internal view returns (address);

Parameters

NameTypeDescription
accountaddressThe account address to retrieve the owner for.

Returns

NameTypeDescription
<none>addressThe address of the account owner.

isAccountOperatorAuthorizedInternal

Checks if an operator is authorized for a specific account.

Determines operator authorization by checking if the operator's bit is set in the operator's bit field for the account's address prefix. If the owner is not registered (address(0)), it implies the operator cannot be authorized, hence returns false. The bitMask is calculated by shifting 1 left by the XOR of the owner's and account's address, effectively checking the operator's authorization for the specific account.

function isAccountOperatorAuthorizedInternal(
address account,
address operator
) internal view returns (bool isAuthorized);

Parameters

NameTypeDescription
accountaddressThe account address to check the operator authorization for.
operatoraddressThe operator address to check authorization status.

Returns

NameTypeDescription
isAuthorizedboolTrue if the operator is authorized for the account, false otherwise.

revertBytes

Reverts the transaction with a custom error message if provided, otherwise reverts with a generic empty error.

function revertBytes(bytes memory errMsg) internal pure;

Parameters

NameTypeDescription
errMsgbytesThe custom error message to revert the transaction with.

Structs

OwnerStorage

struct OwnerStorage {
address owner;
bool isLockdownMode;
bool isPermitDisabledMode;
}