Error Reference
Common errors encountered when using the Hydrex SDK and how to diagnose and fix them.
SDK Errors
ADDRESSES_NOT_EQUALToken comparisonThrown when comparing tokens that have mismatched addresses. Ensure you are using the same token instance or comparing by address.
TICK_OUT_OF_RANGEPosition creationThe tick value is outside the allowable range [MIN_TICK, MAX_TICK]. Use nearestUsableTick() to align ticks to the pool's tick spacing.
ZERO_LIQUIDITYPosition / PoolA trade or position was attempted with zero liquidity. Check that tick bounds cover the current price.
PRICE_BOUNDSTick / Price conversionA price is outside the representable range. Ensure the price you're computing a tick for is within valid pool price bounds.
INSUFFICIENT_INPUT_AMOUNTSwap simulationThe input amount is insufficient to execute the trade. This typically happens when there is not enough liquidity in the range.
On-chain Revert Errors
STF (Safe Transfer From)
Too little received
Transaction too old
Price limit already exceeded
Retry Utility
The SDK exports a retry utility for retrying async operations with exponential backoff. Throw RetryableError to signal that the error is transient and the operation should be retried.
import { retry, RetryableError } from '@hydrexfi/hydrex-sdk';
const { promise, cancel } = retry(
async () => {
const result = await fetchSomeData();
if (!result) throw new RetryableError('No result yet');
return result;
},
{ n: 3, minWait: 500, maxWait: 2000 }
);
const result = await promise;
// cancel() to abort earlySlippage & Price Impact
Most reverts during swaps are caused by slippage settings that are too tight for current market conditions. Here are best practices:
// Use a reasonable slippage — too tight will cause reverts in volatile markets
const slippage = new Percent(50, 10_000); // 0.5% — good starting point
// For low-liquidity pools or large trades, increase tolerance:
const highSlippage = new Percent(100, 10_000); // 1%
// Check trade impact before submitting
if (trade.priceImpact.greaterThan(new Percent(3, 100))) {
console.warn('High price impact:', trade.priceImpact.toFixed(2) + '%');
}