refresh
The refresh
method updates the route with the latest market data, returning a new Route
instance with updated prices and paths.
Signature
async refresh(): Promise<Route>
Returns
Returns a Promise that resolves to a new Route
instance with updated market data.
Example Usage
const symphony = new Symphony();
// Get initial route
const route = await symphony.getRoute(tokenIn, tokenOut, "1.0");
// Wait some time...
// Get updated route with same tokens and amount and latest prices
const updatedRoute = await route.refresh();
// Use the updated route for swap
const { swapReceipt } = await updatedRoute.swap();
Notes
- The method creates a new route instance with the same parameters but fresh market data
- Useful when the original route might be stale due to time passing
- The new route will have updated:
- Prices
- Optimal swap path
- Original route instance remains unchanged
Error Handling
The method will throw an error if:
- The tokens are no longer available for swap
- The Symphony API is unreachable
- The amount is invalid or exceeds available liquidity