Uniswap / v2-periphery

🎚 Peripheral smart contracts for interacting with Uniswap V2
https://uniswap.org/docs
GNU General Public License v3.0
1.14k stars 1.69k forks source link

CompileError: TypeError: Explicit type conversion not allowed from "uint256" to "address" #135

Closed glaksmono closed 2 years ago

glaksmono commented 2 years ago

I'm getting this error:

CompileError: TypeError: Explicit type conversion not allowed from "uint256" to "address".
  --> project:/contracts/UniswapV2Library.sol:21:16:
   |
21 |         pair = address(uint(keccak256(abi.encodePacked(
   |                ^ (Relevant source part starts here and spans across multiple lines).

Source of error: https://github.com/Uniswap/v2-periphery/blob/master/contracts/libraries/UniswapV2Library.sol#L20

Here's my truffle configuration:

❯ truffle version
Truffle v5.5.32 (core: 5.5.32)
Ganache v7.4.3
Solidity - 0.8.17 (solc-js)
Node v16.14.2
Web3.js v1.7.4

any ideas how to fix this?

mouseless0x commented 2 years ago

Any version of solidity greater than 0.8.0 won't allow you to convert from/to uint256<->address. If you compile the contracts with a solidity version lower than 0.8.0 it should compile without any errors.

See https://docs.soliditylang.org/en/latest/080-breaking-changes.html (New restriction section outlines this change)

glaksmono commented 2 years ago

Yeah, ended up doing this pair = address(uint160(uint(keccak256(abi.encodePacked(

seems like that sort it out

dvncan commented 4 months ago

Here is what I did re this response;

pool = address(
            uint160(
                bytes20(
                    keccak256(
                        abi.encodePacked(
                            hex'ff',
                            factory,
                            keccak256(abi.encode(key.token0, key.token1, key.fee)),
                            POOL_INIT_CODE_HASH
                        )
                    )
                )
            )
        );