0

Hello guys I need some help!

Could someone explain me how to set the token order (token0 / token1) of a liquidity pair?

I’m using UniswapsV2 - Factory contract.

Currently when i create a pool with tokenA & tokenB. I expect tokenA to become token0, and tokenB to become token1. But this is not the case..

The function I use to create pair:

function createPair(address tokenA, address tokenB) external returns (address pair);

I did some digging in the code of the contract, and the problem i see is: the contract sorts the token order by itself. Take a look at this code: https://github.com/Uniswap/v2-core/blob/4dd59067c76dea4a0e8e4bfdda41877a6b16dedc/contracts/UniswapV2Factory.sol#L25

(address token0, address token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);

So basically it sorts the token by a lower / higher value address ..

But what if tokenB has a higher value then tokenA but i still want tokenA to be token0 and tokenB to become token1.

How can i achieve this?

My liquidity pair should be:

TEST/WETH

But now it becomes:

WETH/TEST

I really hope someone could help me with this!

Thanks in advance

1 Answer 1

1

You can't choose your own order. The order is determinated based on the tokens addresses.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.