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

Create a guide about how to create helpers functions to create Futures #813

Open
alcuadrado opened this issue Sep 23, 2024 · 0 comments
Open
Labels
type:docs Documentation-related issue

Comments

@alcuadrado
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:docs Documentation-related issue
Projects
Status: Todo
Development

No branches or pull requests

1 participant