Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Feature Request: UintN TemplateVar support for defining the length of an ARC4 StaticArray #95

Open
ericsharma opened this issue Feb 4, 2025 · 2 comments
Labels
enhancement New feature or request

Comments

@ericsharma
Copy link

ericsharma commented Feb 4, 2025

Definition of ARC4 StaticArray

An ARC4 StaticArray is an array of a fixed size. The item type is specified by the first generic parameter and the size is specified by the second.

Request

I'm requesting that the Puya-TS implementation of StaticArray support the ability to specify the size of the array with TemplateVar<UintN<8>>. This is currently not possible in Tealscript and I think it would be great to have in Puya-TS.

References

Idea briefly discussed in this discord thread

@ericsharma ericsharma changed the title Feature Request: Uint64 TemplateVar support for defining the length of an ARC4 StaticArray Feature Request: UintN TemplateVar support for defining the length of an ARC4 StaticArray Feb 5, 2025
@tristanmenzel
Copy link
Collaborator

I would be interested to see the real world use case of this feature as it's possible there are simpler solutions.

Having said that, currently template variables are persisted all the way into teal output and only replaced when outputting byte code. The idea being that the variables can be replaced with values as late as deploy time.

In the case of using a template variable in a type declaration, one would need to make the replacement in after reading the typescript source code and before creating the typescript program to parse those files. A simpler solution might be to just replace the value in your typescript source code with an external script prior to invoking build

@tristanmenzel tristanmenzel added the enhancement New feature or request label Feb 26, 2025
@ericsharma
Copy link
Author

The idea being that the variables can be replaced with values as late as deploy time.

This is what I want. For situations where the length of the static array is not known when writing the smart contract but IS known when deploying.

A simpler solution might be to just replace the value in your typescript source code with an external script prior to invoking build

I'm doing this in Tealscript and I don't find it simple at all. The DX is hacky and also requires me to rebuild every time I change the length of the array. For me, a simpler solution would be to build once and then change the length of the static array as I would any other template var.

Perhaps allowing for a template variable to be used in a type declaration is not the best way to accommodate this enhancement but I do think that there should be template variable support for static arrays.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants