Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

discussion: contract factories #2883

Closed
nmushegian opened this issue May 29, 2022 · 15 comments · Fixed by #2895
Closed

discussion: contract factories #2883

nmushegian opened this issue May 29, 2022 · 15 comments · Fixed by #2895

Comments

@nmushegian
Copy link

I must be missing something obvious, how do I do new MyContract() from inside a contract? I can't find any reference in the docs or in the issues... A language that can't make factories is a non-starter IMO and the forwarder pattern adds gas overhead to the deployed object

@nmushegian
Copy link
Author

On second thought forcing everyone to use a generic multifactory where we log the constructor bytes might actually be a good idea!!

@michwill
Copy link

Maybe you are looking for create_forwarder_to. Which, though, is not create2

https://vyper.readthedocs.io/en/stable/built-in-functions.html#chain-interaction

@nmushegian
Copy link
Author

I saw that, but that is not what I am looking for, I am looking for regular CREATE opcode

@nmushegian
Copy link
Author

A multi factory is not the same as a proxy, I want to actually make objects without the overhead

A similar pattern to forwarder could be “copier” which deploys a copy of code using EXTCODECOPY (whatever it’s called) at given address provided

@nmushegian
Copy link
Author

5 out of 5 people I have asked for a way to create contracts in vyper and not use a forwarded have shown me the forwarder, it is pretty remarkable how bad I am at communicating

@nmushegian
Copy link
Author

https://github.com/ricobank/multifab

I will close this now and make a new issue when we could maybe add this similar to forwarding contract that is currently built in

@fubuloubu
Copy link
Member

Typically I suggest just deploying separately, because it's just a huge waste of space to store one contract in another.

The link you shared is really interesting though, and might be a good idea for a built in function

@charles-cooper
Copy link
Member

charles-cooper commented May 29, 2022

maybe worth a new builtin, either create_copy_of(code_at: address) or create(bytecode: Bytes). @nmushegian thoughts?

@nmushegian
Copy link
Author

I think both would be good, maybe for these it makes sense just expose a typed version of select opcodes like create, create2, codecopy, I think all approaches have merits here I just need the ability to create new contracts from other contracts, defaulting to big multifactory right now

@nmushegian
Copy link
Author

Maybe generating 1 factory alongside each contract is a good approach too, then that factory defines the type

@charles-cooper
Copy link
Member

Maybe generating 1 factory alongside each contract is a good approach too, then that factory defines the type

can you sketch this a bit more?

@charles-cooper charles-cooper changed the title How to create new contract from contract? discussion: contract factories May 31, 2022
@charles-cooper
Copy link
Member

also related: #2891

@nmushegian
Copy link
Author

nmushegian commented Jun 5, 2022

- maybe a comparison table of approaches would be useful
	- costs for build, call, and original setup if applicable
	- regular CREATE/CREATE2
		- setup: makes parent contract deploy more expensive
		- build: direct create with bytes
		- call: lowest overhead
	- deploy forwarder
		- setup: target needs to be deployed / exist
		- build: deploy tiny proxy
		- call: DELEGATECALL overhead
	- build from factory
		- setup: need to deploy object per-factory
		- build: call to factory overhead
		- call: lowest overhead
	- build from multifab
		- setup: need to deploy multifab, and add type
		- build: call to multifab overhead
		- call: lowest overhead
	- EXTCODECOPY
		- setup: target contract must exist
		- build: copy overhead
		- call: lowest overhead

@charles-cooper
Copy link
Member

charles-cooper commented Jun 5, 2022

@nmushegian nice table -- can you expand on what a multifab is in your terminology? never mind, i figured it out, https://github.com/ricobank/multifab

@nmushegian
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants