EthereumVaultConnector
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
Name | Type | Description |
---|---|---|
addressPrefix | bytes19 | The 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
Name | Type | Description |
---|---|---|
account | address | The 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
Name | Type | Description |
---|---|---|
context | uint256 | Current 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
Name | Type | Description |
---|---|---|
controllerToCheck | address | 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. |
Returns
Name | Type | Description |
---|---|---|
onBehalfOfAccount | address | An account that has been authenticated and on behalf of which the operation is being executed at the moment. |
controllerEnabled | bool | 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). |
areChecksDeferred
Checks if checks are deferred.
function areChecksDeferred() external view returns (bool);
Returns
Name | Type | Description |
---|---|---|
<none> | bool | A boolean indicating whether checks are deferred. |
areChecksInProgress
Checks if checks are in progress.
function areChecksInProgress() external view returns (bool);
Returns
Name | Type | Description |
---|---|---|
<none> | bool | A boolean indicating whether checks are in progress. |
isControlCollateralInProgress
Checks if control collateral is in progress.
function isControlCollateralInProgress() external view returns (bool);
Returns
Name | Type | Description |
---|---|---|
<none> | bool | A boolean indicating whether control collateral is in progress. |
isOperatorAuthenticated
Checks if an operator is authenticated.
function isOperatorAuthenticated() external view returns (bool);
Returns
Name | Type | Description |
---|---|---|
<none> | bool | A boolean indicating whether an operator is authenticated. |
isSimulationInProgress
Checks if a simulation is in progress.
function isSimulationInProgress() external view returns (bool);
Returns
Name | Type | Description |
---|---|---|
<none> | bool | A 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
Name | Type | Description |
---|---|---|
account | address | The address of the account that is being checked. |
otherAccount | address | The address of the other account that is being checked. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | A 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
Name | Type | Description |
---|---|---|
account | address | The address of the account whose address prefix is being retrieved. |
Returns
Name | Type | Description |
---|---|---|
<none> | bytes19 | A 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
Name | Type | Description |
---|---|---|
account | address | The address of the account whose owner is being retrieved. |
Returns
Name | Type | Description |
---|---|---|
<none> | address | 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. |
isLockdownMode
Checks if lockdown mode is enabled for a given address prefix.
function isLockdownMode(bytes19 addressPrefix) external view returns (bool);
Parameters
Name | Type | Description |
---|---|---|
addressPrefix | bytes19 | The address prefix to check for lockdown mode status. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | A 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
Name | Type | Description |
---|---|---|
addressPrefix | bytes19 | The address prefix to check for permit functionality status. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | A 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
Name | Type | Description |
---|---|---|
addressPrefix | bytes19 | The address prefix for which the nonce is being retrieved. |
nonceNamespace | uint256 | The nonce namespace for which the nonce is being retrieved. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | nonce 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
Name | Type | Description |
---|---|---|
addressPrefix | bytes19 | The address prefix for which the bit field is being retrieved. |
operator | address | The address of the operator for which the bit field is being retrieved. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | 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. |
isAccountOperatorAuthorized
Returns whether a given operator has been authorized for a given account.
function isAccountOperatorAuthorized(address account, address operator) external view returns (bool);
Parameters
Name | Type | Description |
---|---|---|
account | address | The address of the account whose operator is being checked. |
operator | address | The address of the operator that is being checked. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | authorized 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
Name | Type | Description |
---|---|---|
addressPrefix | bytes19 | The address prefix for which the lockdown mode is being set. |
enabled | bool | A 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
Name | Type | Description |
---|---|---|
addressPrefix | bytes19 | The address prefix for which the permit functionality is being set. |
enabled | bool | A 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
Name | Type | Description |
---|---|---|
addressPrefix | bytes19 | The address prefix for which the nonce is being set. |
nonceNamespace | uint256 | The nonce namespace for which the nonce is being set. |
nonce | uint256 | The 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
Name | Type | Description |
---|---|---|
addressPrefix | bytes19 | The address prefix for which the bit field is being set. |
operator | address | 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. |
operatorBitField | uint256 | The 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
Name | Type | Description |
---|---|---|
account | address | The address of the account whose operator is being set or unset. |
operator | address | The 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. |
authorized | bool | A 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
Name | Type | Description |
---|---|---|
account | address | The address of the account whose collaterals are being queried. |
Returns
Name | Type | Description |
---|---|---|
<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
Name | Type | Description |
---|---|---|
account | address | The address of the account that is being checked. |
vault | address | The address of the collateral that is being checked. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | A 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
Name | Type | Description |
---|---|---|
account | address | The account address for which the collateral is being enabled. |
vault | address | The 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
Name | Type | Description |
---|---|---|
account | address | The account address for which the collateral is being disabled. |
vault | address | The 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
Name | Type | Description |
---|---|---|
account | address | The address of the account for which the collaterals are being reordered. |
index1 | uint8 | The index of the first collateral to be swapped. |
index2 | uint8 | The 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
Name | Type | Description |
---|---|---|
account | address | The address of the account whose controllers are being queried. |
Returns
Name | Type | Description |
---|---|---|
<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
Name | Type | Description |
---|---|---|
account | address | The address of the account that is being checked. |
vault | address | The address of the controller that is being checked. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | A 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
Name | Type | Description |
---|---|---|
account | address | The address for which the controller is being enabled. |
vault | address | The 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
Name | Type | Description |
---|---|---|
account | address | The 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
Name | Type | Description |
---|---|---|
signer | address | The 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. |
sender | address | The 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. |
nonceNamespace | uint256 | The nonce namespace for which the nonce is being used. |
nonce | uint256 | The 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. |
deadline | uint256 | The timestamp after which the permit is considered expired. |
value | uint256 | 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. |
data | bytes | The encoded data which is self-called on the EVC contract. |
signature | bytes | The 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
Name | Type | Description |
---|---|---|
targetContract | address | The address of the contract to be called. |
onBehalfOfAccount | address | If 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. |
value | uint256 | 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. |
data | bytes | The encoded data which is called on the target contract. |
Returns
Name | Type | Description |
---|---|---|
result | bytes | The 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
Name | Type | Description |
---|---|---|
targetCollateral | address | The collateral address to be called. |
onBehalfOfAccount | address | The address of the account for which it is checked whether msg.sender is authorized to act on behalf. |
value | uint256 | 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. |
data | bytes | The encoded data which is called on the target collateral. |
Returns
Name | Type | Description |
---|---|---|
result | bytes | The 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
Name | Type | Description |
---|---|---|
items | BatchItem[] | 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
Name | Type | Description |
---|---|---|
items | BatchItem[] | 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
Name | Type | Description |
---|---|---|
items | BatchItem[] | An array of batch items to be executed. |
Returns
Name | Type | Description |
---|---|---|
batchItemsResult | BatchItemResult[] | An array of batch item results for each item. |
accountsStatusCheckResult | StatusCheckResult[] | An array of account status check results for each account. |
vaultsStatusCheckResult | StatusCheckResult[] | 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
Name | Type | Description |
---|---|---|
account | address | The address of the account for which the last status check timestamp is being queried. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The 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
Name | Type | Description |
---|---|---|
account | address | The address of the account for which it is checked whether the status check is deferred. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | A 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
Name | Type | Description |
---|---|---|
account | address | The 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
Name | Type | Description |
---|---|---|
account | address | The 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
Name | Type | Description |
---|---|---|
vault | address | The address of the vault for which it is checked whether the status check is deferred. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | A 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
Name | Type | Description |
---|---|---|
account | address | The 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
Name | Type | Description |
---|---|---|
account | address | The account address to authenticate the caller against. |
allowOperator | bool | A boolean indicating if operators are allowed to authenticate as the caller. |
checkLockdownMode | bool | A boolean indicating if the function should check for lockdown mode on the account. |
Returns
Name | Type | Description |
---|---|---|
<none> | address | The 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
Name | Type | Description |
---|---|---|
addressPrefix | bytes19 | The bytes19 address prefix to authenticate the caller against. |
allowOperator | bool | A boolean indicating if operators are allowed to authenticate as the caller. |
checkLockdownMode | bool | A boolean indicating if the function should check for lockdown mode on the account. |
Returns
Name | Type | Description |
---|---|---|
<none> | address | The 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
Name | Type | Description |
---|---|---|
targetContract | address | The contract address to call. |
onBehalfOfAccount | address | The account address on behalf of which the call is made. |
value | uint256 | The amount of value to send with the call. |
data | bytes | The 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
Name | Type | Description |
---|---|---|
targetContract | address | The contract address to call. |
onBehalfOfAccount | address | The account address on behalf of which the call is made. |
value | uint256 | The amount of value to send with the call. |
data | bytes | The calldata to send with the call. |
Returns
Name | Type | Description |
---|---|---|
success | bool | A boolean indicating if the call was successful. |
result | bytes | The 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
Name | Type | Description |
---|---|---|
contextCache | EC | The 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
Name | Type | Description |
---|---|---|
account | address | The account address to check the status for. |
Returns
Name | Type | Description |
---|---|---|
isValid | bool | A boolean indicating if the account status is valid. |
result | bytes | The 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
Name | Type | Description |
---|---|---|
vault | address | The address of the vault to check the status for. |
Returns
Name | Type | Description |
---|---|---|
isValid | bool | A boolean indicating if the vault status is valid. |
result | bytes | The 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
Name | Type | Description |
---|---|---|
setType | SetType | The 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
Name | Type | Description |
---|---|---|
signer | address | The address of the signer to validate. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | bool 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
Name | Type | Description |
---|---|---|
signer | address | The address of the signer. |
sender | address | |
nonceNamespace | uint256 | The namespace of the nonce. |
nonce | uint256 | The nonce value, ensuring permits are used once. |
deadline | uint256 | The time until when the permit is valid. |
value | uint256 | The value associated with the permit. |
data | bytes | Calldata associated with the permit. |
Returns
Name | Type | Description |
---|---|---|
permitHash | bytes32 | The 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
Name | Type | Description |
---|---|---|
hash | bytes32 | The hash of the signed data. |
signature | bytes | The signature to recover the signer from. |
Returns
Name | Type | Description |
---|---|---|
signer | address | The 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
Name | Type | Description |
---|---|---|
signer | address | The address of the signer to validate the signature against. |
hash | bytes32 | The hash of the data that was signed. |
signature | bytes | The signature to validate. |
Returns
Name | Type | Description |
---|---|---|
isValid | bool | True 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
Name | Type | Description |
---|---|---|
<none> | bytes32 | The 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
Name | Type | Description |
---|---|---|
<none> | address | The 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
Name | Type | Description |
---|---|---|
<none> | bool | True 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
Name | Type | Description |
---|---|---|
account | address | The first account address to compare. |
otherAccount | address | The second account address to compare. |
Returns
Name | Type | Description |
---|---|---|
result | bool | True 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
Name | Type | Description |
---|---|---|
account | address | The account address to compute the prefix for. |
Returns
Name | Type | Description |
---|---|---|
<none> | bytes19 | The 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
Name | Type | Description |
---|---|---|
account | address | The account address to retrieve the owner for. |
Returns
Name | Type | Description |
---|---|---|
<none> | address | The 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
Name | Type | Description |
---|---|---|
account | address | The account address to check the operator authorization for. |
operator | address | The operator address to check authorization status. |
Returns
Name | Type | Description |
---|---|---|
isAuthorized | bool | True 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
Name | Type | Description |
---|---|---|
errMsg | bytes | The custom error message to revert the transaction with. |
Structs
OwnerStorage
struct OwnerStorage {
address owner;
bool isLockdownMode;
bool isPermitDisabledMode;
}