Nexera-FiAdapters & DeFi Protocols

WrappedNativeTokenAdapter

Git Source

Extends: BaseAdapter

The WrappedNativeTokenAdapter is designed to facilitate seamless interactions with Wrapped tokens. It enables swaps between native currency (e.g. ETH) and ERC-20 Wrapped native currency (e.g. WETH) and vice versa.

Wrapped tokens can be generated by transferring native currency to a smart contract, which locks the native currency and issues the corresponding wrapped ERC-20 token at a 1:1 ratio.

State Variables

WRAPPED_NATIVE_TOKEN

The address of the ERC-20 contract that wraps native currency.

address immutable WRAPPED_NATIVE_TOKEN;

Constructor

Sets the value of the WRAPPED_NATIVE_TOKEN state variable.

constructor(address WrappedNativeToken)

Functions

initialize

The initialize function has an empty body and serves as a structural requirement to comply with the BaseAdapter. It doesn't execute any specific actions.

function initialize(bytes calldata) external override;

Parameters

NameTypeDescription
<none>bytesABI encoded data (not used in this context)

_swap

Internal function for handling swaps between native currency and its ERC-20 wrapped version.

Called by executeAction function.

Depending on the provided input arguments, the _swap function behaves as follows:

  • If the out input argument contains the zero address denoting native currency as an output token, the function checks if the expectedIn input argument contains the address of the wrapped native token as an input token. If so, it invokes the deposit() function on the Wrapped native token contract (e.g. WETH9) to swap the specified amount of native currency (e.g. ETH) for its ERC-20 compatible version (e.g. WETH).

  • Conversely, if the expectedIn input argument contains the zero address denoting native currency as an input token, the function ensures that the out input argument contains the address of the wrapped native token as the output token. In this case, it invokes the withdraw() function on the Wrapped native token contract (e.g. WETH9) to swap the defined amount of wrapped token (e.g. WETH) for the respective amount of native currency (e.g. ETH).

  • In all other cases, the function reverts, indicating an invalid token swap.

function _swap(
    IAdapter.TokenAmount[] calldata out,
    IAdapter.TokenAmount[] calldata expectedIn,
    bytes calldata /*extraData*/
) internal override;

Parameters

NameTypeDescription
outIAdapter.TokenAmount[]Array of TokenAmount structs defining the token compositions to send as part of the swap. It should contain exactly one token composition (i.e. have length == 1).
expectedInIAdapter.TokenAmount[]Array of TokenAmount structs defining the expected token compositions to receive as part of the swap. It should contain exactly one token composition (i.e. have length == 1).
extraDatabytesABI encoded data (not used in this context)

_deposit

This function always raises the OPERATION_NOT_SUPPORTED error.

Called by executeAction function.

function _deposit(
    IAdapter.TokenAmount[] calldata /*out*/,
    IAdapter.TokenAmount[] calldata /*expectedIn*/,
    bytes calldata /*extraData*/
) internal virtual override;

_withdraw

This function always raises the OPERATION_NOT_SUPPORTED error.

Called by executeAction function.

function _withdraw(
    IAdapter.TokenAmount[] calldata /*out*/,
    IAdapter.TokenAmount[] calldata /*expectedIn*/,
    bytes calldata /*extraData*/
) internal virtual override;

_collect

This function always raises the OPERATION_NOT_SUPPORTED error.

Called by executeAction function.

function _collect(
    IAdapter.TokenAmount[] calldata /*out*/,
    IAdapter.TokenAmount[] calldata /*expectedIn*/,
    bytes calldata /*extraData*/
) internal virtual override;

_operate

This function always raises the OPERATION_NOT_SUPPORTED error.

Called by executeAction function.

function _operate(
    IAdapter.TokenAmount[] calldata /*out*/,
    IAdapter.TokenAmount[] calldata /*expectedIn*/,
    bytes calldata /*extraData*/
) internal virtual override;

On this page