How to Sync and Skim In Uniswap

Leon Do
Coinmonks

--

Calling sync() and skim() in Remix.

Overview

In this article we will call the sync() function to fix stuck pairs. This happens when someone removes everything from a pool leaving dust. These small amounts might account for large changes. Syncing will update the reserves to the current balances.

This will work for Uniswap, Sushiswap, ETCSwap, PancakeSwap and many other AMM defi protocols.

According to Uniswap V2’s white paper:

To protect against bespoke token implementations that can update the pair contract’s balance, and to more gracefully handle tokens whose total supply can be greater than 2112 , Uniswap v2 has two bail-out functions: sync()and skim()

sync() functions as a recovery mechanism in the case that a token asynchronously deflates the balance of a pair. In this case, trades will receive sub-optimal rates, and if no liquidity provider is willing to rectify the situation, the pair is stuck. sync() exists to set the reserves of the contract to the current balances, providing a somewhat graceful recovery from this situation.

skim() functions as a recovery mechanism in case enough tokens are sent to an pair to overflow the two uint112 storage slots for reserves, which could otherwise cause trades to fail. skim() allows a user to withdraw the difference between the current balance of the pair and 2112 − 1 to the caller, if that difference is greater than 0.

Get Source Code

Verify the factory address. For Uniswap V2, its: 0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f

Visit the block explorer and copy the Contract Source Code

For simplicity, below is the source:

Remix

  • Copy paste source code to remix
  • Select Environment to Injected Provider
  • Select contract to UniswapV2Pair
  • Paste the address of the pair you want to sync. In this example it’s USDC-ETH
https://v2.info.uniswap.org/pair/0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc
  • Call sync()

And you’re synced!

Conclusion

Pairs can get out of sync when someone transfers tokens on one side for no reason. Or when the pool is very low. Sync forces reserves to match balances, while skim forces balances to match reserves.

New to trading? Try crypto trading bots or copy trading

--

--