WrappedNativeTokenAdapter
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.
Constructor
Sets the value of the WRAPPED_NATIVE_TOKEN state variable.
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.
Parameters
Name | Type | Description |
---|---|---|
<none> | bytes | ABI 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 theexpectedIn
input argument contains the address of the wrapped native token as an input token. If so, it invokes thedeposit()
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 theout
input argument contains the address of the wrapped native token as the output token. In this case, it invokes thewithdraw()
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.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.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). |
expectedIn | IAdapter.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). |
extraData | bytes | ABI encoded data (not used in this context) |
_deposit
This function always raises the OPERATION_NOT_SUPPORTED error.
Called by executeAction function.
_withdraw
This function always raises the OPERATION_NOT_SUPPORTED error.
Called by executeAction function.
_collect
This function always raises the OPERATION_NOT_SUPPORTED error.
Called by executeAction function.
_operate
This function always raises the OPERATION_NOT_SUPPORTED error.
Called by executeAction function.