Comment on page
Migration to Version 1.0
The SOR Version 1.0.0-0 introduces breaking changes but should be fairly easy to update. Benefits of updating include - support for multihop swaps and an easier to use wrapper interface as well as more efficient/faster processing.
The SOR is now instantiated as an object:
const SOR = new sor.SOR(Provider, GasPrice, MaxPools, ChainId, PoolsUrl)
SOR now has three main functions:
await SOR.setCostOutputToken(tokenOut)
- Calculates gas cost for swapping token on Balancer.
- The result is used to make more gas efficient swap recommendations.
- Result is cached for future use but can be updated by re-calling.
- Notice that outputToken is tokenOut if swapType == 'swapExactIn' and tokenIn if swapType == 'swapExactOut'
const isSuccess = await SOR.fetchPools()
- This fetches all Balancer pool information and on-chain balances.
- Retrieves pool information from static IPFS file rather than Subgraph.
- Retrieves on-chain balances using custom multicall contract.
- Returns true on success or false on error.
- Information is cached and used for all future processing, this results in fast processing of swaps, i.e. useful when changing swap amounts or types in a UI.
- Accurate/valid swaps rely on upM to date balance information so it is recommended this function is re-called to refresh as needed.
const [swaps, amount] = await SOR.getSwaps(tokenIn, tokenOut, swapType, swapAmount)
- Main function to process trade.
- Will return amount expected and a list of swaps that can be executed on-chain.
A new ExchangeProxy contract that supports multihop swaps has been deployed to the addresses below. For contract details please see Exchange Proxy.
- Mainnet:
0x3E66B66Fd1d0b02fDa6C811Da9E0547970DB2f21
- Kovant:
0x4e67bf5bD28Dd4b570FBAFe11D0633eCbA2754Ec
- For more information on SOR functions and to see code examples (including using with ExchangeProxy) please see Development & Examples.
Last modified 2yr ago