foundry-rs / starknet-foundry

Blazing fast toolkit for developing Starknet contracts.
https://foundry-rs.github.io/starknet-foundry/
MIT License
324 stars 173 forks source link

Research constructor dispatchers support #695

Open MaksymilianDemitraszek opened 1 year ago

MaksymilianDemitraszek commented 1 year ago

Dispatchers should also support constructors in some way, probably should be upstreamed to the compiler.

Arcticae commented 1 year ago

Dispatchers are not bound to the contracts themselves, since what binds them is the address and knowledge that we have a right interface. This might be not doable because of that, without providing class_hash from the user. Is this something that is going to be an issue?

Arcticae commented 1 year ago

Should be doable via a plugin or upstream to compilator

cptartur commented 11 months ago

Dispatchers could also generate a static method for deploying a instance of the contract from the provided class hash that would return Self. Something like


Dispatcher {
  // ...
  construct(class_hash: ClassHash, arg1: Type1, arg2: Type2, ...) -> Self {
    // perform deploy
    let addr = ...;
    Self { addr }
  }
}
Arcticae commented 11 months ago

Dispatchers could also generate a static method for deploying a instance of the contract from the provided class hash that would return Self. Something like...

That is actually not much different from the current deploy on the ContractClass, and would require also a custom plugin (or a modification/overriding of the cairo one) so that will be difficult to implement

MaksymilianDemitraszek commented 10 months ago

@cptartur You can have different constructor signatures for a specific trait.

cptartur commented 10 months ago

@cptartur You can have different constructor signatures for a specific trait.

Are you sure about that? I think that contract implementation can only have a single constructor.

MaksymilianDemitraszek commented 10 months ago

@cptartur Contract implementation has one, but dispatchers are generated per trait not per implementation. So you are able to have multiple contract implementations per one dispatcher.