Orchestrator
Extends: Initializable, IERC721Receiver
The Orchestrator
contract facilitates the coordination and execution of diverse actions such as deposits, withdrawals, and swaps across multiple DeFi protocols by leveraging associated Adapters.
This is the implementation contract, users can deploy ownable instances via the OrchestratorFactory.
Events
NativeReceived
Emitted when amount
of native currency is received from from
address.
Structs
Layout
Used to store crucial data for the Orchestrator's functionality in a specific storage slot.
Members
Name | Type | Description |
---|---|---|
owner | address | The owner of the Orchestrator instance (owner of funds allocated to Orchestrator) |
executor | address | The executor of the Orchestrator instance (service which executes actions) |
whitelistedAdapters | mapping | Mapping of Adapters' addresses to their whitelist status (allowed Adapters) |
whitelistedTokens | mapping | Mapping of Tokens' addresses to their whitelist status (allowed tokens) |
Action
Encapsulates the essential data required for executing an action.
Members
Name | Type | Description |
---|---|---|
adapter | IAdapter | The address of Adapter to be utilized for the action |
op | IAdapter.Operation | The operation to be conducted by the Adapter |
send | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to be sent to the Adapter |
minReceive | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected minimum token compositions to be received from the Adapter |
extraData | bytes | ABI encoded data specific to the Adapter's operation |
State Variables
STORAGE_SLOT
Unique identifier for the storage slot where the Layout struct is stored.
Constructor
Prevents initialization of the implementation contract by invoking _disableInitializers()
(see Initializable).
Receive
Provides the ability to accept native coins from various protocols and accounts.
Modifiers
onlyOwner
Ensures that only the owner of the Orchestrator instance can access the execution of the function.
onlyExecutor
Ensures that only the configured executor of the Orchestrator instance can access the execution of the function.
Functions
initialize
Initializes the Orchestrator instance by setting the owner.
transferOwnership
Sets a new owner for the Orchestrator instance.
Only callable by the owner of the instance.
Parameters
Name | Type | Description |
---|---|---|
newOwner | address | The address to set as the new owner |
setExecutor
Sets a new executor for the Orchestrator instance.
Only callable by the owner of the instance.
Parameters
Name | Type | Description |
---|---|---|
newExecutor | address | The address to set as the new executor |
addWhitelistedAdapters
Adds one or more addresses to the whitelist of Adapters allowed by the Orchestrator instance.
Only callable by the owner of the instance.
Parameters
Name | Type | Description |
---|---|---|
whitelistedAdapters | address[] | An array of Adapters' addresses to be added to the whitelist |
addWhitelistedTokens
Adds one or more addresses to the whitelist of tokens allowed by the Orchestrator instance.
Only callable by the owner of the instance.
Parameters
Name | Type | Description |
---|---|---|
whitelistedTokens | address[] | An array of tokens' addresses to be added to the whitelist |
removeWhitelistedAdapters
Removes one or more addresses from the whitelist of Adapters allowed by the Orchestrator instance.
Only callable by the owner of the instance.
Parameters
Name | Type | Description |
---|---|---|
whitelistedAdapters | address[] | An array of Adapters' addresses to be removed from the whitelist |
removeWhitelistedTokens
Removes one or more addresses from the whitelist of tokens allowed by the Orchestrator instance.
Only callable by the owner of the instance.
Parameters
Name | Type | Description |
---|---|---|
whitelistedTokens | address[] | An array of tokens' addresses to be removed from the whitelist |
isWhitelistedAdapter
Checks if a given address is a whitelisted Adapter in the Orchestrator instance.
Parameters
Name | Type | Description |
---|---|---|
account | address | The address to check for whitelist status |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | True if account is a whitelisted Adapter, false otherwise |
isWhitelistedToken
Checks if a given address is a whitelisted token in the Orchestrator instance.
Parameters
Name | Type | Description |
---|---|---|
account | address | The address to check for whitelist status |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | True if account is a whitelisted token, false otherwise |
withdraw
Withdraws a specified amount of token
from the Orchestrator instance.
Only callable by the owner of the instance.
Parameters
Name | Type | Description |
---|---|---|
token | address | The address of the token to withdraw.- address(0) indicates native currency- non zero address indicates ERC-20 token |
amount | uint256 | The amount to withdraw |
target | address | The address to receive the withdrawn funds |
withdrawBatch
Withdraws specified amounts of tokens
from the Orchestrator instance.
Only callable by the owner of the instance.
Parameters
Name | Type | Description |
---|---|---|
tokens | address[] | An array of tokens' addresses to withdraw.- address(0) indicates native currency- non zero address indicates ERC-20 token |
amounts | uint256[] | An array of amounts corresponding to each specified token to withdraw |
target | address | The address to receive the withdrawn funds |
execute
Executes a series of specified actions.
Only callable by the configured executor of the instance.
Parameters
Name | Type | Description |
---|---|---|
actions | Action[] | An array of Action structs specifying the actions to execute |
Returns
Name | Type | Description |
---|---|---|
totalReceived | IAdapter.TokenAmount[][] | A 2D array of TokenAmount structs containing the token compositions received from each executed action.Each row corresponds to a specific action, and the respective columns correspond to the assets involved in that action |
initializeAdapter
Initializes a whitelisted Adapter in the context of the Orchestrator instance by invoking the Adapter's initialize
function through delegatecall.
Reverts if adapter
is not whitelisted.
Only callable by the owner of the instance.
Parameters
Name | Type | Description |
---|---|---|
adapter | address | The address of the target Adapter |
initData | bytes | ABI encoded intialization data specific to the target Adapter |
_executeAction
Executes a single specified action.
Called by execute function.
Parameters
Name | Type | Description |
---|---|---|
action | Action | The necessary data specifying the action to be executed |
Returns
Name | Type | Description |
---|---|---|
actualReceived | IAdapter.TokenAmount[] | An array of TokenAmount structs containing the token compositions received from the executed action |
_isAdapterAndTokensWhitelisted
Checks whether the Adapter and tokens specified by action
are whitelisted in the Orchestrator instance.
Called by execute
function.
Parameters
Name | Type | Description |
---|---|---|
action | Action | The Action struct containing the respective data to check |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | True if both Adapter and all tokens specified in action are whitelisted, false otherwise |
layout
Retrieves a reference to the Layout struct stored at the storage slot specified by STORAGE_SLOT.
onERC721Received
Implements the ERC-721 standard's onERC721Received
interface, enabling Orchestrator instances to receive custody of ERC-721 tokens.
This function only returns its selector using this.onERC721Received.selector
.