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

Typegen - predicate typegen to support configurable constants #1014

Closed
danielbate opened this issue May 23, 2023 · 4 comments · Fixed by #1031
Closed

Typegen - predicate typegen to support configurable constants #1014

danielbate opened this issue May 23, 2023 · 4 comments · Fixed by #1031
Assignees
Labels
feat Issue is a feature

Comments

@danielbate
Copy link
Member

danielbate commented May 23, 2023

Now that predicates support configurable constants in #998, we should look to support them in typegen.

Predicates with configurable constants are instantiated like so:

const predicate = new Predicate(bytecode, abi, wallet.provider, configurableConstants);

However the autogenerated predicate factory created using typegen doesn't offer any way of passing configurables:

export class {{capitalizedName}}__factory {
static readonly abi = _abi
static readonly bin = _bin;
static createInstance(provider?: Provider) {
const { abi, bin } = {{capitalizedName}}__factory
const predicate = new Predicate(bin, abi, provider);
return predicate;
}

We should be able to infer from the ABI that the predicate contains configurable constants and the types of them, and provide a way for them to be easily passed to the factory instance. This could be done by amending the createInstance signature should configurables be present.

@danielbate danielbate added the feat Issue is a feature label May 23, 2023
@danielbate
Copy link
Member Author

@FuelLabs/sdk-ts I'd be quite keen to pick this one up over the next week or so unless anyone has any objections?

@arboleya
Copy link
Member

arboleya commented May 23, 2023

Fantastic, this is the issue I said I'd pick up yesterday on the sync, but you're more than welcome to do it yourself! ⚡

Predicates, Scripts, and Contracts will be practically the same. Since the code sharing between them should be prevalent, the three might fit in a single PR. Do you want to do all three?

I suspect we will end up with something like this:

export type {{capitalizedName}}Constants { 
  ...
}

static createInstance(provider?: Provider, configurable?: {{capitalizedName}}Constants) { 
  ... 
}

@danielbate
Copy link
Member Author

danielbate commented May 24, 2023

@arboleya Ah apologies, I do remember you mentioning it now. If that's alright with you I'd really like to! It had also been raised in the forum.

@danielbate danielbate self-assigned this May 24, 2023
@arboleya
Copy link
Member

No worries, man. Thank you.

If you need anything, just let me know.

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

Successfully merging a pull request may close this issue.

2 participants