1

As an exercise, I am trying to deploy a large contract that is greater than the 24kB limit imposed by the Spurious Dragon hardfork. So, I am looking at Uniswap V3 as an aim and my goal is to deploy a fork of Uniswap V3 as an exercise.

Running truffle migrate with UniswapV3Router.sol as a target results in a contract that is ~125kB which is greater than the 24kB limit.The compiler replaces all import statements in UniswapV3Router.sol with the code/library being imported. So, essentially UniswapV3Router.sol becomes a 3000 line of code file. So there is the problem, since that is a very large contract.

This is where UniswapV3Router.sol is deployed on etherscan: https://etherscan.io/address/0xe592427a0aece92de3edee1f18e0157c05861564#code where there are cleary 34 individual contracts uploaded as illustrated by: enter image description here

So, how to deploy multiple .sol files to the same contract address? In other words, how to achieve the same result as shown on etherscan?

2
  • This is strange indeed. As far as I know, the address to which you deploy a contract is a random one. Not sure how would one set a multitude of smart contracts on the same address. (Good question, I am interested in the answer too)
    – Sky
    Jan 14 at 7:56
  • Can someone confirm whether EIP-2535: Diamonds and the use of delegatecalls is going in the right direction as a solution to this problem? Jan 15 at 4:20
0

The contract SwapRounter inherits a couple of contracts/interfaces and embeds a number of internal libaries. Additional interfaces are needed to allow the contract to interact with other contracts (such as IERC20).

As stated by etherscan, only the SwapRouter.sol contract was deployed at this address. To reduce the contract size, you can turn on the Solidity Optimizer (like the Uniswap team).

Edit: They have used 1.000.000 optimizer runs.

2
  • Am I missing something where the interfaces and internal libraries each exist at separate contract addresses? If so, are they somehow included during compilation or deployment? Jan 18 at 10:05
  • On etherscan they are only shown as separate files that have been checked this way. You can try to verify a flattened contract and it should look different. Internal libraries are embedded in the bytecode of the deployed contract.
    – ikijong
    Jan 19 at 10:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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