If you are new to Nabla, we recommend you start with the section first.
We will go through the steps to get an on-chain swap quote and show you how to execute an ERC20-to-ERC20 swap with Nabla.
For this, we are going to call the following functions at the contract as our entry point:
quoteSwapExactTokensForTokens and
swapExactTokensForTokens
Let's begin
1. Retrieve price update data
Nabla is an oracle based DEX.
You need to submit signed price update data to Nabla contracts, for hubs either using Pyth or Nabla Oracle price feeds.
You can check what price update data is needed, either
Pyth price update data or
Nabla price update data
for a pool ensemble/hub in the under "Router".
Pyth price update data
Get the price feed ids (one time task)
You can retrieve the Pyth price feed ids (bytes32) from the `` for the assets you are interested in.
In case of USDC and WETH on Arbitrum:
The data field is the needed price update data for moving forward with a swap.
For Pyth price update data, there is also a SSE streaming endpoint available
Nabla price update data
Get the price feed ids (one time task)
The price feed ids used for Nabla price update data are identical to Pyth. This is to ensure alignment with pool ensembles/hubs that still using Pyth price feeds and to ensure ease of integration.
Query Nabla Quote API
Please contact us if you're interested in integrating Nabla Quote API
The price updata data is considered as valid if on-chain update is "not too old".
Also, if another bot or user updates the price on-chain that is newer than the one you have submitted, this newer price is taken.
The price feed ids from Pyth are listed here:
We have just received the price information about the assets we are interested in.
Now we can feed the prices directly into the quoting function:
Example quote with foundry's cast for 1k USDC (6 decimal precision) to WETH through :
We have received price updata data and are happy with the quote, we can now perform a swap through .
For this to work we need to feed the price update data into the swap function as ``.
If all requirements are met (e.g. minimum amount to accept & price update data not too old) the swap will execute successfully.
Done
Thanks for integrating with Nabla
If you have questions, please do not hesitate to get in contact and ask in our Discord or Telegram.