0

I have this contract called Pool.sol, and an external library for deploying it:

pragma solidity ^0.8.0;

// Contracts
import "../Pool.sol";

library DeployerOfPools {
    function deployPool(
        address debtToken,
        address collateralToken,
        int32 leverageTier,
        address oracle
    ) external returns (address) {
        // Create pool
        return address(new Pool{salt: bytes32(0)}(debtToken, collateralToken, leverageTier, oracle));
    }

    function getAddress(
        address factory,
        address debtToken,
        address collateralToken,
        int32 leverageTier,
        address oracle
    ) external pure returns (address) {
        return
            address(
                uint160(
                    uint256(
                        keccak256(
                            abi.encodePacked(
                                hex"ff",
                                factory,
                                bytes32(0), // Salt
                                keccak256(
                                    abi.encodePacked(
                                        type(Pool).creationCode,
                                        abi.encode(debtToken, collateralToken, leverageTier, oracle)
                                    )
                                )
                            )
                        )
                    )
                )
            );
    }
}

Strangely upon compilation I get the following sizes:

 ·····························|··············|·················
 |  Pool                      ·      22.889  ·                │
 ·····························|··············|·················
 |  DeployerOfPools           ·      33.230  ·                │
 ·····························|··············|·················

This is the library which is essentially a Pool.sol wrapper with a bit of code is 10 kB or 45% larger! Why on Earth?

1 Answer 1

0

So I found out why. It turns out the sauce is in the constructor. Any imports needed for executing the code in the constructor, will be imported to the wrapping library.

In my specific case, the constructor of Pool.sol did some floating point arithmetic, and so it imported the contract FloatingPoint.sol making it much larger

Your Answer

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

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