Executing FX Trades
Last updated
Last updated
Preparing a swap transaction on an FXPool is no different from preparing a swap transaction via the Balancer router (Xave FXPools are exposed via Balancer's Smart Order Router).
Please refer to Deployment Addresses to access FXPool parameters (such as poolId)
when interacting with the Balancer SOR and/or API. However, if you deployed your pool via the self service functionality, you will have to note the contract address of your deployment to fetch your FXPool's parameters
Please see the Balancer docs for instructions on how to trade on Xave via the Balancer router and API
You may also execute trades and interact with the Balancer Smart Order Router via API
Batch Swaps
Initialize the Balancer Vault Contract. Refer to the deployed addresses for the correct vault address.
Sort the addresses of the tokens to be swapped. Token ordering is very important in the Balancer Vault; each pool stores its tokens sorted numerically. Because of this, we will need to sort our own token lists when interacting with pools.
Determine the swap kind and scale it to the correct decimal.
Define swap settings. Here, we're specifying that the sender/recipient for the tokens going into/out of the trade are both the account that we initialized the script with. Note that with this granularity, it is possible to make a swap that sends the tokens to a different address.
We specify that {to/from}InternalBalance are both False. This will be the default use case for most users; however, you may have a use case that would benefit from Internal Balances.
Define swap steps. In this swap step, we assume that the pool contains both tokens. The deadline for a transaction is the time (in Unix timestamp) after which it will no longer attempt to make a trade.
Call queryBatchSwap to preview the input/output amount for the swap
Calculate amountOut with slippage. We are also scaling our limits to account for the token-specific decimals.
Finally, call the batchSwap