I am using ethers-rs to write a defi app. I need to calculate the CREATE2 address in rust. I couldn't find the equivalent of abi.encodePacked(token0, token1)
in rust.
The code used in Uniswap's library (https://vomtom.at/how-to-use-uniswap-v2-as-a-developer):
// calculates the CREATE2 address for a pair without making any external calls
function pairFor(address factory, address tokenA, address tokenB) internal pure returns (address pair) {
(address token0, address token1) = sortTokens(tokenA, tokenB);
pair = address(uint(keccak256(abi.encodePacked(
hex'ff',
factory,
keccak256(abi.encodePacked(token0, token1)),
hex'96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f' // init code hash
))));
}
Unfortunately I didn't get much help from the internet.
What's the equivalent for abi.encodePacked in rust.
Regards.