Title: Solidity__compiler__magicians_wanted_to_make_CREAT
Category: Protocol_Calls___happenings

Author: AlexeyAkhunov
Date: 2018-12-06T11:11:48.006Z

Yesterday I made this ERC20 contract (which is supposed to work under State rent when holders pay for storing their tokens): work: https://github.com/ledgerwatch/eth_state/blob/master/erc20/TokenContract.sol
As you can see in the code, Solidity provides create2 assembly function, but working with it is cumbersome. It would be much easier if there were 2 new features in Solidity:


new2 operator. Similar to new, but also accept salt parameter, and uses CREARE opcode. So in my Factory I would have written Holder holder = new2(Holder, _owner) without having to put the byte code of the Holder contract inside the function
Function create2_address, which allows computing address of CREATE2 contract. I would have used it twice, first in Token.getHolderContract function: address payable holder_address = create2_address(factory, a, Holder), and second in Holder.setOwner function: require(create2_address(factor, _owner, Holder) == address(this))


It would be great to have (at least in a branch) a version of Solidity (derived from the current) supporting these two things. That would make further development of contracts like that much easier.
EDIT: Also linked this to: https://github.com/ethereum/solidity/issues/2136

Author: jochem-brouwer
Date: 2019-01-07T14:53:44.667Z

Check this out! Should at least make your life a little bit easier!  (It is a contract exposing all functions as public but it can of course be rewritten as a library/contract where all functions are internal/private)


gist.github.com


https://gist.github.com/jochem-brouwer/118ff785686742cf7fdadde9cc544cbd
ConstantinopleTools.sol
/*
Copyright 2019 Jochem Brouwer

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

This file has been truncated. show original

Author: AlexeyAkhunov
Date: 2019-01-07T17:35:25.742Z

jochem-brouwer:

Check this out! Should at least make your life a little bit easier!


Thank you very much! Not exactly what I wanted, but a good start!

Author: efn
Date: 2019-05-13T12:37:21.096Z

Recently I also needed to implement the same thing
You can preserve a bit more of the new semantics by  doing: new(salt) C(args...) that will create the contract  C using args as arguments with create2.
The address could be accessed with C.create2Address(salt)