Nexera-FiAdapters & DeFi ProtocolsNexera Exchange

NxraDEXAdapter

Git Source

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 order
  • TAKE_EXACT_TAKE: Allocate a specific quantity of take Tokens within predefined limits
  • TAKE_EXACT_MAKE: Acquire a specific quantity of make Tokens within predefined limits
  • CANCEL: Cancel orders and refund the order maker
enum OperateOperation {
    MAKE, 
    TAKE_EXACT_TAKE,
    TAKE_EXACT_MAKE,
    CANCEL
}

Structs

OperateExtraData

Used to indicate the appropriate action of an Operate Operation.

struct OperateExtraData {
    OperateOperation operateOperation;
    bytes operationData;
    bool fromBalance;
}

Members

NameTypeDescription
operateOperationOperateOperationThe action to conduct
operationDatabytesAdditional ABI encoded data related to the operation ( a , b , c )
fromBalancebool- 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.

struct MakeData {
    IERC20 makeToken; 
    IERC20 takeToken;
    uint256 makeAmount; 
    uint256 takeAmount;
    uint32 estimatedSortOrderId;
    uint256 maxInsertIterations;
    uint256 maxTakeIterations;
    bool toBalance;
}

Members

NameTypeDescription
makeTokenIERC20The token to be sold
takeTokenIERC20The token to be paid
makeAmountuint256The amount to be sold
takeAmountuint256The amount to be paid
estimatedSortOrderIduint32Order 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
maxInsertIterationsuint256Max iterations to match new order with existing ones
maxTakeIterationsuint256Max iterations to find the correct new order position
toBalancebool- 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.

struct TakeExactData {
    IERC20 makeToken;
    IERC20 takeToken;
    uint256 maxAmount;
    uint256 minAmount;
    uint256 maxMakePrice;
    uint256 maxTakePrice;
    uint256 maxIterations;
    address receiver;
    bool toBalance;
}

Members

NameTypeDescription
makeTokenIERC20takeExactTake: The token to be sold takeExactMake: The token to be bought
takeTokenIERC20takeExactTake: The token to be paid takeExactMake: The token to pay with
maxAmountuint256takeExactTake: Total max amount to pay takeExactMake: Total max amount to buy
minAmountuint256takeExactTake: Total min amount to pay takeExactMake: Total min amount to buy
maxMakePriceuint256Max price for make token
maxTakePriceuint256Max price for take token
maxIterationsuint256Max transactions to loop over
receiveraddressAddress to receive make tokens
toBalancebool- 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.

struct CancelData {
    bytes ids;
    bool toBalance;
}

Members

NameTypeDescription
idsbytesOrder IDs to cancel
toBalancebool- 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.

struct Layout {
    IExchange exchange;
}

Members

NameTypeDescription
exchangeIExchangeThe interface representing the Nexera DEX contract instance

State Variables

STORAGE_SLOT

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

bytes32 internal immutable STORAGE_SLOT;

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)
constructor();

Functions

initialize

Initializes the Adapter.

function initialize(bytes calldata initData_) external override;

Parameters

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

function _deposit(
    IAdapter.TokenAmount[] calldata out,
    IAdapter.TokenAmount[] calldata,
    bytes calldata
) internal override;

Parameters

NameTypeDescription
outIAdapter.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>bytesABI 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.

function _withdraw(
    IAdapter.TokenAmount[] calldata,
    IAdapter.TokenAmount[] calldata expectedIn,
    bytes calldata
) internal override;

Parameters

NameTypeDescription
<none>IAdapter.TokenAmount[]Array of TokenAmount structs defining the token compositions to send.Not used in this context.
expectedInIAdapter.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>bytesABI 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.

function _operate(
    IAdapter.TokenAmount[] calldata,
    IAdapter.TokenAmount[] calldata,
    bytes calldata extraData
) internal override;

Parameters

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

function _collect(
    IAdapter.TokenAmount[] calldata,
    IAdapter.TokenAmount[] calldata,
    bytes calldata
) internal virtual override;

_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.

function _swap(
    IAdapter.TokenAmount[] calldata,
    IAdapter.TokenAmount[] calldata,
    bytes calldata
) internal virtual override;

_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.

function _make(bytes memory operationData) internal;

Parameters

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

function _takeExactTake(bytes memory operationData) internal;

Parameters

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

function _takeExactMake(bytes memory operationData) internal;

Parameters

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

function _cancel(bytes memory operationData) internal;

Parameters

NameTypeDescription
operationDatabytesABI encoded data of type CancelData

layout

Retrieves a reference to the Layout struct stored at a specified storage slot.

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

On this page