Integration Guide
Welcome to the Nabla integration guide.
If you are new to Nabla, we recommend you start with the Developer overview 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 NablaPortal 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 deployed contracts section under "Router".
2. Get an on-chain quote
We have just received the price information about the assets we are interested in. Now we can feed the prices directly into the NablaPortal quoting function:
NablaPortal.quoteSwapExactTokensForTokens(
uint256 _amountIn,
address[] _tokenPath,
address[] _routerPath,
[priceTokenA, priceTokenB]
) external view returns (uint256 amountOut_)
Example quote with foundry's cast for 1k USDC (6 decimal precision) to WETH through Nabla's Main Crypto Hub on Arbitrum:
cast call 0xcB94Eee869a2041F3B44da423F78134aFb6b676B \
"quoteSwapExactTokensForTokens(uint256 amountIn, address[] tokenPath, address[] routerPath, uint256[] tokenPrices)(uint256)" \
1000000000 \
"[0xaf88d065e77c8cC2239327C5EDb3A432268e5831,0x272dF896f4D0c97F65e787f861bb6e882776a155]" \
"[0x7bcFc8b8ff61456ad7C5E2be8517D01df006d18d]" \
"[100003959,305192675883]" \
--rpc-url $(ARBITRUM_MAINNET_RPC_URL)
3. Perform a swap
We have received price updata data and are happy with the quote, we can now perform a swap through NablaPortal. For this to work we need to feed the price update data into the swap function as `_priceUpdateData`.
NablaPortal.swapExactTokensForTokens(
uint256 _amountIn,
uint256 _amountOutMin,
address[] calldata _tokenPath,
address[] calldata _routerPath,
address _to,
uint256 _deadline,
bytes[] calldata _priceUpdateData
)
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.
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.
Last updated