Nexera-FiOrchestrator

Orchestrator

Git Source

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.

event NativeReceived(address from, uint256 amount);

Structs

Layout

Used to store crucial data for the Orchestrator's functionality in a specific storage slot.

struct Layout {
    address owner;
    address executor;
    mapping(address => bool) whitelistedAdapters;
    mapping(address => bool) whitelistedTokens;
}

Members

NameTypeDescription
owneraddressThe owner of the Orchestrator instance (owner of funds allocated to Orchestrator)
executoraddressThe executor of the Orchestrator instance (service which executes actions)
whitelistedAdaptersmappingMapping of Adapters' addresses to their whitelist status (allowed Adapters)
whitelistedTokensmappingMapping of Tokens' addresses to their whitelist status (allowed tokens)

Action

Encapsulates the essential data required for executing an action.

struct Action {
    IAdapter adapter;
    IAdapter.Operation op;
    IAdapter.TokenAmount[] send;
    IAdapter.TokenAmount[] minReceive;
    bytes extraData;
}

Members

NameTypeDescription
adapterIAdapterThe address of Adapter to be utilized for the action
opIAdapter.OperationThe operation to be conducted by the Adapter
sendIAdapter.TokenAmount[]Array of TokenAmount structs defining the token compositions to be sent to the Adapter
minReceiveIAdapter.TokenAmount[]Array of TokenAmount structs defining the expected minimum token compositions to be received from the Adapter
extraDatabytesABI encoded data specific to the Adapter's operation

State Variables

STORAGE_SLOT

Unique identifier for the storage slot where the Layout struct is stored.

bytes32 internal constant STORAGE_SLOT = keccak256("Nexera-FI.Orchestrator");

Constructor

Prevents initialization of the implementation contract by invoking _disableInitializers() (see Initializable).

constructor()

Receive

Provides the ability to accept native coins from various protocols and accounts.

receive() external payable

Modifiers

onlyOwner

Ensures that only the owner of the Orchestrator instance can access the execution of the function.

modifier onlyOwner

onlyExecutor

Ensures that only the configured executor of the Orchestrator instance can access the execution of the function.

modifier onlyExecutor

Functions

initialize

Initializes the Orchestrator instance by setting the owner.

function initialize() external initializer;

transferOwnership

Sets a new owner for the Orchestrator instance.

Only callable by the owner of the instance.

function transferOwnership(address newOwner) external onlyOwner;

Parameters

NameTypeDescription
newOwneraddressThe address to set as the new owner

setExecutor

Sets a new executor for the Orchestrator instance.

Only callable by the owner of the instance.

function setExecutor(address newExecutor) external onlyOwner;

Parameters

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

function addWhitelistedAdapters(address[] calldata whitelistedAdapters) external onlyOwner;

Parameters

NameTypeDescription
whitelistedAdaptersaddress[]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.

function addWhitelistedTokens(address[] calldata whitelistedTokens) external onlyOwner;

Parameters

NameTypeDescription
whitelistedTokensaddress[]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.

function removeWhitelistedAdapters(address[] calldata whitelistedAdapters) external onlyOwner;

Parameters

NameTypeDescription
whitelistedAdaptersaddress[]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.

function removeWhitelistedTokens(address[] calldata whitelistedTokens) external onlyOwner;

Parameters

NameTypeDescription
whitelistedTokensaddress[]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.

function isWhitelistedAdapter(address account) public view returns (bool);

Parameters

NameTypeDescription
accountaddressThe address to check for whitelist status

Returns

NameTypeDescription
<none>boolTrue if account is a whitelisted Adapter, false otherwise

isWhitelistedToken

Checks if a given address is a whitelisted token in the Orchestrator instance.

function isWhitelistedToken(address account) public view returns (bool);

Parameters

NameTypeDescription
accountaddressThe address to check for whitelist status

Returns

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

function withdraw(address token, uint256 amount, address payable target) external onlyOwner;

Parameters

NameTypeDescription
tokenaddressThe address of the token to withdraw.- address(0) indicates native currency- non zero address indicates ERC-20 token
amountuint256The amount to withdraw
targetaddressThe address to receive the withdrawn funds

withdrawBatch

Withdraws specified amounts of tokens from the Orchestrator instance.

Only callable by the owner of the instance.

function withdrawBatch(
    address[] calldata tokens,
    uint256[] calldata amounts,
    address payable target
) external onlyOwner;

Parameters

NameTypeDescription
tokensaddress[]An array of tokens' addresses to withdraw.- address(0) indicates native currency- non zero address indicates ERC-20 token
amountsuint256[]An array of amounts corresponding to each specified token to withdraw
targetaddressThe address to receive the withdrawn funds

execute

Executes a series of specified actions.

Only callable by the configured executor of the instance.

function execute(Action[] calldata actions)
    external
    payable
    onlyExecutor
    returns (IAdapter.TokenAmount[][] memory totalReceived);

Parameters

NameTypeDescription
actionsAction[]An array of Action structs specifying the actions to execute

Returns

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

function initializeAdapter(address adapter, bytes calldata initData) external onlyOwner;

Parameters

NameTypeDescription
adapteraddressThe address of the target Adapter
initDatabytesABI encoded intialization data specific to the target Adapter

_executeAction

Executes a single specified action.

Called by execute function.

function _executeAction(Action calldata action) internal returns (IAdapter.TokenAmount[] memory actualReceived);

Parameters

NameTypeDescription
actionActionThe necessary data specifying the action to be executed

Returns

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

function _isAdapterAndTokensWhitelisted(Action calldata action) internal view returns (bool);

Parameters

NameTypeDescription
actionActionThe Action struct containing the respective data to check

Returns

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

function layout() internal pure returns (Layout storage l);

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.

function onERC721Received(address, address, uint256, bytes calldata) external pure override returns (bytes4);