BaseAdapter
Extends: IAdapter
The BaseAdapter
abstract contract serves as the foundational blueprint for all Adapters within the Nexera-Fi protocol. It defines a set of essential functionalities and interface requirements that all Adapters must adhere to.
By inheriting this contract, developers ensure that their Adapter implementations meet the required standards and seamlessly integrate with the Nexera-Fi protocol.
Custom Errors
CONSTRAINTS_VALIDATION_FAIL
Raised when the execution of an Action results in spending more than expected or receiving less than expected.
Parameters
Name | Type | Description |
---|---|---|
token | address | The address of the token for which the validation constraint failed |
expectedAmount | uint256 | The expected amount of the token to be received or spent |
actualAmount | uint256 | The actual amount of the token that was received or spent |
expectedPositive | bool | True if expected to receive or spent >= expectedAmount , false otherwise |
actualPositive | bool | True if received or spent >= actualAmount , false otherwise |
OPERATION_NOT_SUPPORTED
Raised when the Action to be executed is undefined or not supported by the Adapter.
Functions
initialize
Virtual intialization function for Adapters.
Developers should override this function to appropriately initialize their Adapter implementation.
Parameters
Name | Type | Description |
---|---|---|
initData_ | bytes | ABI encoded initialization data |
executeAction
Executes an operation-related action on a 3rd party service (DEX, Liquidity Pool, etc).
Parameters
Name | Type | Description |
---|---|---|
op | IAdapter.Operation | Enum key representing the operation to execute |
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send |
expectedIn | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected token compositions to receive |
extraData | bytes | Extra ABI encoded data specific to the Adapter, required for the operation action |
Returns
Name | Type | Description |
---|---|---|
actualIn | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions actually received |
_swap
Virtual internal swap
function for Adapters.
Developers should override this function as follows:
- If the implementation supports the SWAP operation, override it with code to handle the operation
- If the implementation does not support the SWAP operation, raise the
OPERATION_NOT_SUPPORTED
error
Called by executeAction function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send |
expectedIn | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected token compositions to receive |
extraData | bytes | Extra ABI encoded data specific to the Adapter, required for the swap operation |
_deposit
Virtual internal deposit
function for Adapters.
Developers should override this function as follows:
- If the implementation supports the DEPOSIT operation, override it with code to handle the operation
- If the implementation does not support the DEPOSIT operation, raise the
OPERATION_NOT_SUPPORTED
error
Called by executeAction function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send |
expectedIn | IAdapter.TokenAmount[] | Array ofTokenAmount structs defining the expected token compositions to receive |
extraData | bytes | Extra ABI encoded data specific to the Adapter, required for the deposit operation |
_withdraw
Virtual internal withdraw
function for Adapters.
Developers should override this function as follows:
- If the implementation supports the WITHDRAW operation, override it with code to handle the operation
- If the implementation does not support the WITHDRAW operation, raise the
OPERATION_NOT_SUPPORTED
error
Called by executeAction function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send (should be empty array) |
expectedIn | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected token compositions to receive |
extraData | bytes | Extra ABI encoded data specific to the Adapter, required for the withdraw operation |
_collect
Virtual internal collect
function for Adapters.
Developers should override this function as follows:
- If the implementation supports the COLLECT operation, override it with code to handle the operation
- If the implementation does not support the COLLECT operation, raise the
OPERATION_NOT_SUPPORTED
error
Called by executeAction function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send (should be empty array) |
expectedIn | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected token compositions to receive |
extraData | bytes | Extra ABI encoded data specific to the Adapter, required for the collect operation |
_operate
Virtual internal operate
function for Adapters.
Developers should override this function as follows:
- If the implementation supports the OPERATE operation, override it with code to handle the operation
- If the implementation does not support the OPERATE operation, raise the
OPERATION_NOT_SUPPORTED
error
Called by executeAction function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send |
expectedIn | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected token compositions to receive |
extraData | bytes | Extra ABI encoded data specific to the Adapter, required for the operate operation |
_getBalances
Private view function used to retrieve token balances of Adapter.
This function is designed to calculate the balances of specified tokens based on the provided out
and expectedIn
arrays.
Called by executeAction function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the output token compositions |
expectedIn | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected input token compositions |
Returns
Name | Type | Description |
---|---|---|
balances | uint256[] | Array with the Adapter's balances for the provided tokens |
_calculateAndValidateBalanceDiff
Private pure function used to calculate and validate token balance differences after an operation.
This function is responsible for calculating the differences in token balances before and after an operation, ensuring that the result meets the expected constraints. It performs validation on both spent and received tokens based on the provided inputs and the operation type.
Called by executeAction function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the output token compositions |
expectedIn | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected input token compositions |
balancesBefore | uint256[] | Array of Adapter's initial token balances before the operation |
balancesAfter | uint256[] | Array of Adapter's resulting token balances after the operation |
op | IAdapter.Operation | Enum key representing the targeted operation |
Returns
Name | Type | Description |
---|---|---|
spent | IAdapter.TokenAmount[] | Array of TokenAmount structs representing the tokens spent during the operation |
received | IAdapter.TokenAmount[] | Array of TokenAmount structs representing the tokens received after the operation |
_balanceOf
Private view function used to retrieve the Adapter's balance of a specified token.
This function retrieves the balance of either a native token (e.g. Ether) or an ERC-20 token held by the implementation contract.
Called by _getBalances function.
Parameters
Name | Type | Description |
---|---|---|
tokenOrNative | address | The address of the token for which the balance is to be retrieved. address(0) indicates native token |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The balance of the specified token held by the implementation contract |