NxraDEXAdapter
Extends: BaseAdapter
The NxraDEXAdapter
is designed to interact with the Nexera Exchange.
This adapter enables users to harness the power of Nexera On-chain Limit Order Book DEX features and integrate them into their financial strategies.
Enums
OperateOperation
Defines the actions available for interacting with Nexera DEX:
MAKE
: Make a new orderTAKE_EXACT_TAKE
: Allocate a specific quantity of take Tokens within predefined limitsTAKE_EXACT_MAKE
: Acquire a specific quantity of make Tokens within predefined limitsCANCEL
: Cancel orders and refund the order maker
Structs
OperateExtraData
Used to indicate the appropriate action of an Operate Operation.
Members
Name | Type | Description |
---|---|---|
operateOperation | OperateOperation | The action to conduct |
operationData | bytes | Additional ABI encoded data related to the operation ( a , b , c ) |
fromBalance | bool | - If true, funds are withdrawn from caller's (msg.sender) wallet balance. - If false, funds are withdrawn from the caller's internal balance within the DEX contract, reflecting the caller's deposit.Note: Only utilized in the following operations: → OperateOperation.MAKE → OperateOperation.TAKE_EXACT_TAKE → OperateOperation.TAKE_EXACT_MAKE |
MakeData
Defines the necessary data for invoking the make
function of the Nexera DEX. It encapsulates the necessary data for making a new order in the Exchange.
Note: This structure serves as the non-encoded operation data within the broader OperateExtraData struct.
Members
Name | Type | Description |
---|---|---|
makeToken | IERC20 | The token to be sold |
takeToken | IERC20 | The token to be paid |
makeAmount | uint256 | The amount to be sold |
takeAmount | uint256 | The amount to be paid |
estimatedSortOrderId | uint32 | Order ID where the new order will be placed next to.This should be the order that is closest to the price of the new order |
maxInsertIterations | uint256 | Max iterations to match new order with existing ones |
maxTakeIterations | uint256 | Max iterations to find the correct new order position |
toBalance | bool | - If true, add matched orders to the caller's (msg.sender) internal balance within the DEX contract. - If false, send funds to the caller's wallet. |
TakeExactData
Defines the necessary data for invoking the takeExactTake
& takeExactMake
functions of the Nexera DEX. It encapsulates the necessary data required to acquire or allocate tokens from/to the Exchange.
Note: This structure serves as the non-encoded operation data within the broader OperateExtraData struct.
Members
Name | Type | Description |
---|---|---|
makeToken | IERC20 | takeExactTake : The token to be sold takeExactMake : The token to be bought |
takeToken | IERC20 | takeExactTake : The token to be paid takeExactMake : The token to pay with |
maxAmount | uint256 | takeExactTake : Total max amount to pay takeExactMake : Total max amount to buy |
minAmount | uint256 | takeExactTake : Total min amount to pay takeExactMake : Total min amount to buy |
maxMakePrice | uint256 | Max price for make token |
maxTakePrice | uint256 | Max price for take token |
maxIterations | uint256 | Max transactions to loop over |
receiver | address | Address to receive make tokens |
toBalance | bool | - If true, add matched orders to the caller's (msg.sender) internal balance within the DEX contract. - If false, send funds to the caller's wallet. |
CancelData
Defines the necessary data for invoking the cancel
function of the Nexera DEX. It encapsulates the necessary data required for cancelling orders that have been placed to the Exchange.
Note: This structure serves as the non-encoded operation data within the broader OperateExtraData struct.
Members
Name | Type | Description |
---|---|---|
ids | bytes | Order IDs to cancel |
toBalance | bool | - If true, add funds (tokens) to the caller's (msg.sender) internal balance within the DEX contract. - If false, send funds to the caller's wallet. |
Layout
Used to store crucial data for the Adapter's functionality in a specific storage slot.
Members
Name | Type | Description |
---|---|---|
exchange | IExchange | The interface representing the Nexera DEX contract instance |
State Variables
STORAGE_SLOT
Unique identifier for the storage slot where the Layout struct is stored.
Constructor
Sets the value of the STORAGE_SLOT state variable.
The value is computed as the keccak256 hash of the abi encoding of:
- The
Nexera-FI.NxraDEXAdapter
string literal - The address of this contract (NxraDEXAdapter)
Functions
initialize
Initializes the Adapter.
Parameters
Name | Type | Description |
---|---|---|
initData_ | bytes | The ABI encoded Layout data |
_deposit
Internal function for handling Deposit Operations.
This function is responsible for depositing tokens into the Nexera DEX, via invoking its deposit method.
Called by executeAction function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send. It should only contain the address and amount for the token to be deposited. The length of this array must equal to 1; otherwise the function reverts. |
<none> | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected token compositions to receive.Not used in this context. |
<none> | bytes | ABI encoded data (Not used in this context) |
_withdraw
Internal function for handling Withdraw Operations.
This function is responsible for withdrawing tokens from the Nexera DEX, via invoking its withdraw method.
Called by executeAction function.
Parameters
Name | Type | Description |
---|---|---|
<none> | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send.Not used in this context. |
expectedIn | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected token compositions to receive.It should only contain the address of the token to be withdrawn. The amount field is ignored as all tokens are withdrawn by default. The length of this array must equal to 1; otherwise the function reverts. |
<none> | bytes | ABI encoded data (Not used in this context) |
_operate
Internal function for handling Operate Operations.
This function is used for interacting with the Nexera DEX.
Called by executeAction function.
Parameters
Name | Type | Description |
---|---|---|
<none> | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send.Notes:- Not used in this context. - The tokens may already be deposited in the DEX see → OperateExtraData.fromBalance - extraData contains all the required data see → OperateExtraData.operationData . |
<none> | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected token compositions to receive.Notes:- Not used in this context. - extraData contains all the required data see → OperateExtraData.operationData . |
extraData | bytes | ABI encoded data of type OperateExtraData |
_collect
This function always raises the OPERATION_NOT_SUPPORTED error, as Collect is not an action supported within the Nexera DEX.
Called by executeAction function.
_swap
This function always raises the OPERATION_NOT_SUPPORTED error, as Swap is not an action supported within the Nexera DEX.
Called by executeAction function.
_make
Places a new order in the Nexera DEX, using its make
method. It transfers the necessary funds from the caller's balance into the respective market escrow.
Called by _operate function.
Parameters
Name | Type | Description |
---|---|---|
operationData | bytes | ABI encoded data of type MakeData |
_takeExactTake
Spends a specified amount of take tokens within predefined limits for executing a market order, acquiring make tokens at the prevailing market price.
Called by _operate function.
Parameters
Name | Type | Description |
---|---|---|
operationData | bytes | ABI encoded data of type TakeExactData |
_takeExactMake
Acquire a specified amount of make tokens within predefined limits for executing a market order, spending take tokens at the prevailing market price.
Called by _operate function.
Parameters
Name | Type | Description |
---|---|---|
operationData | bytes | ABI encoded data of type TakeExactData |
_cancel
Cancels the specified placed orders in the Nexera DEX and refunds the respective order maker, using the cancel
method of the Exchange.
Called by _operate function.
Parameters
Name | Type | Description |
---|---|---|
operationData | bytes | ABI encoded data of type CancelData |
layout
Retrieves a reference to the Layout struct stored at a specified storage slot.