-
Notifications
You must be signed in to change notification settings - Fork 90
Open
Milestone
Description
Describe the feature
If users create similar patterns of Futures, they would naturally want to avoid that repetition, and that can be done using normal javascript functions. The only special consideration that you have to take is that you don't want your IDs to be repeated every time you call the helper. Otherwise, they will class.
Let's create a short guide explaining this.
Good example of a helper
inspired in The Graph's modules
/**
* Deploys an upgradable instance of `contractName`
*
* @param m The module builder
* @param contractName The contract name to deploy (i.e. its initial implementation)
* @param instanceName A name should be given to this contract instance if you deploy multiple of them within the same module.
**/
export function myProxy(m: IgnitionModuleBuilder, contactName: string, instanceName = "") {
const implementation = m.contract(contractName, {id: `${contractName}${instanceName}`});
const proxy = m.contract("MyProxy", {id: `MyProxy_${contractName}${instanceName}`});
// ...
return {proxy, implementation};
}Bad example of a helper
This is the thing that want to avoid
export function myProxy_THIS_IS_WRONG_DO_NOT_USE(m: IgnitionModuleBuilder, contactName: string) {
const implementation = m.contract(contractName);
const proxy = m.contract("MyProxy");
// ...
return {proxy, implementation};
}This version can only be called once per module, as it will use "MyProxy" to generate the proxy's id. And, if we were to fix only that ID, it could only be called once per module and contractName, which could also be problematic.
For future reference
This pattern is already being used by The Graph here.
Search terms
No response
tmigone
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Status
Todo