Learn more about swap errors you may see when using the Uniswap Protocol.
UniswapV2: K:
The Uniswap Protocol liquidity pool contract maintains a constant using the following function: x*y=k
.
The “k” represents the product of the reserves. It is this “k” to which the “k” error refers.
“Uniswap V2:K” error means that a trade was attempted and left the trading pair with lower reserves than should be there. As a result, the transaction is reverted.
Uniswap v3: SPL:
SPL stands for Square root price limit.
When swapping directly on a pool contract the sqrtPriceLimit is used to determine the highest price in the swap. This needs to be set when swapping on the pool directly.
If you use a set price the swap will not go past this price. It will finalize and complete the swap while not going beyond.
The Uniswap routers use the values for minimum or maximum sqrtPrice:
TickMath.MIN_SQRT_RATIO +1
TickMath.MAX_SQRT_RATIO -1
The price used for the sqrtPriceLimit must be above or below the current sqrtPrice, but not greater or less than the max/min sqrt_ratio.
STF Error:
Safe Transfer Failed.
This is an error seen in a few cases:
- Missing token contract approvals. To resolve this error, you will need to make sure all token contracts that need approvals have the proper amount approved
- The token is a Fee on Transfer or Honeypot token
- You do not have enough tokens. To resolve this error, verify all your inputs and outputs.
TRANSFER_FAILED / TF:
This means the core contract was unable to send tokens to the recipient.
This means:
- The token contract is broken, review your code and test on testnets.
- You need to approval a larger amount of tokens before swapping
- The token contract creator has disabled the transfer function to prevent the selling of the token
Uniswap v2: LOCKED / Uniswapv3: LOK
The LOCKED / LOK error is a guard built into the pool contract that prevents customized reentrancy contracts from attempting to return malicious code into the router contract at the end of a transaction.
If you see an error, it is possible that you have tried to call the same pool within the callback.
Additionally, this error is commonly encountered when using Ganache CLI to fork the Ethereum mainnet to a local instance as a part of a development environment. The error is a bug in Ganache-Cli that will hopefully be fixed in a future release by the truffle team.
Uniswap v2: EXPIRED / Uniswap v3: Transaction too old / Universal router: TransactionDeadlinePassed
This error is the result of a transaction that took too long to be accepted into a block.
The Uniswap web app does not set gas prices natively, so unless changed in the wallet you are using, gas settings are defaulted to the suggested gas prices in your wallet.
Sometimes a wallet gets it wrong, though, and sets the gas price too low. If a swap takes more than the deadline to execute, the core contract won’t allow it to go through.
You would either need to extend your deadline or increase the network costs. With swapping it is best to use the high Gwei price as this determines how fast validators will accept the transaction.
Finding accurate gas prices can be a challenge, here is a resource you can use to track Ethereum gas prices.
Price/Token Change Errors: (Too Little/Much received)
UniswapV2Router: INSUFFICIENT_B_AMOUNT
UniswapV2Router: INSUFFICIENT_A_AMOUNT
UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT
UniswapV2Router: EXCESSIVE_INPUT_AMOUNT
Insufficient WETH9 InsufficientToken
IIA: Insufficient input amount
InsufficientETH
V2TooLittleReceived
V2TooMuchRequested
V3TooLittleReceived
V3TooMuchRequested
V3InvalidAmountOut
These errors mean that the price moved after you submitted the transaction. If you wish to have the transaction executed regardless of the price, you will need to increase your slippage.
This error also occurs due to Fee On Transfer tokens, or tokens with swap and/or add liquidity functions. These change the input/output amounts during the transfer. You must also include slippage to cover these changes on top of the normal slippage.
The Uniswap protocol routers have a minimum output and a maximum input variable.
This allows for an acceptable percentage of loss due to price changes. This is what the slippage from the Uniswap web app is used for. Having the proper slippage set is important. Too high you risk frontrun, too low you risk transaction failure.
Uniswap v3: OLD:
The target must be chronologically after the oldest observation.
This usually occurs when you try to call an observation on a pool that hasn’t had its observations extended.
Uniswapv3: NP:
Burn cannot be called for a position unless the liquidity is 0.
Rare Errors:
T: The given tick must be less than, or equal to, the maximum tick
R: The sqrtPrice used can not be greater or less than the max/min sqrt_Ratio
TLU: The lower tick must be below the upper tick
TLM: The lower tick must be greater, or equal to, the minimum tick
TUM: The upper tick must be lesser than, or equal to, the maximum tick
AI: The pool is already initialized
M0: Mint 0, The balance of token0 in the given pool before minting must be less than, or equal to, the balance after minting
M1: Mint 1, The balance of token1 in the given pool before minting must be less than, or equal to, the balance after minting
AS: The amount specified cannot be zero
L: Liquidity in the pool must be greater than zero for a flash to be executed.
F0: The balance of token0 in the given pool before the flash transaction must be less than, or equal to, the balance of token0 after the flash plus the fee
F1: The balance of token1 in the given pool before the flash transaction must be less than, or equal to, the balance of token0 after the flash plus the fee