gnolang / gno

Gno: An interpreted, stack-based Go virtual machine to build succinct and composable apps + gno.land: a blockchain for timeless code and fair open-source.
https://gno.land/
Other
896 stars 375 forks source link

Factory Pattern Gno #1895

Open kazai777 opened 7 months ago

kazai777 commented 7 months ago

Description

Hi 👋 I thought of creating a feature that would use the same principle as the Factory Pattern in Solidity. And I wanted to know if other people had already thought about this or if anyone had already started working on it?

leohhhn commented 7 months ago

Hey, this is currently something that we do not support. As discussed with @moul, this might be something that we will implement, but not right now - instead of relying only on known concepts from other languages like Solidity, we want to experiment with new blockchain programming patterns. One of these is this PR.

Basically, the idea is to have a central "registry" contract, that you can call NewToken in to make your contract, instead of having to deploy your own. Then, you would be calling each of the common GRC20 functions along with an identifier to the token that you want to execute the functions on.

I would suggest you try to play around with these ideas, and possibly even check out what other languages do for this specific case (Move, Rust for Solana/NEAR, etc). See what sort of limitations each of them have, what are the pros/cons, and possibly take an idea or two from them. Solidity was the first to do many things, which is why it's so well known, but at times it might not show the most optimal way of doing something, which is why we are very keen on exploring :)

kazai777 commented 7 months ago

Thanks for the reply, I'll look into it and try some things out :)

moul commented 7 months ago

Another option is to consider using something developed by @ilgooz's team. I will leave it to him to decide when and what to reveal.

moul commented 7 months ago

I plan to write another pattern example using Go objects. In this case, the factory will not expose an API with a named prefix. Instead, it will initialize an object that can be registered and exposed by other contracts, like a registry.

kazai777 commented 7 months ago

I was thinking of something more general, for example if a dapp needs a contract to manage funds, it would be nice to be able to create contracts independent of the contract itself to centralize management in one place. To take the lottery as an example, it would be nice for each lottery to have its own contract and be able to manage funds independently of the others. For example, each time a new lottery is created, a new contract would be created and would be unique to the lottery itself.