Skip to content

Conversation

@rustopian
Copy link
Contributor

@rustopian rustopian commented Dec 4, 2025

Problem

Some programs, such as stake, use tuples for instruction arguments rather than structs with named fields. Codama currently does not support this pattern, and programs may not want to change their interface to use structs.

Tuple arguments are not necessarily bad practice, as the nature of these arguments can be clarified by using named types, such as stake's Initialize(Authorized, Lockup), rather than relying on struct field names for clarity.

Solution

Support tuples. Keys arg0, arg1 etc. are used for backwards compatibility.

When tuples are used in a program rather than structs with named fields, the related named type definitions should be properly decorated with #[derive(CodamaType)] so that the purpose of each argument is clear in the generated clients. The new tests briefly demonstrate how this can be done.

@rustopian rustopian changed the title [WIP] support tuple instruction args support tuple instruction args Dec 4, 2025
Copy link
Member

@lorisleiva lorisleiva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this! As discussed offline, we can add name customisation later on. Something like this:

#[derive(CodamaInstructions)]
enum FluxCapacitorInstructions {
    #[codama(account(name = "clock_sysvar"))]
    Charge(
        #[codama(name = "percentage")]
        Percentage,
        #[codama(name = "is_valid")]
        bool
    ),
}

@rustopian
Copy link
Contributor Author

rustopian commented Dec 4, 2025

        #[codama(name = "is_valid")]
        bool

Wouldn't want to accidentally charge an invalid flux capacitor, kids.

Thanks @lorisleiva! feel free to merge whenever it's convenient 🙏

@lorisleiva lorisleiva merged commit 7007bd8 into codama-idl:main Dec 4, 2025
2 checks passed
@rustopian rustopian deleted the tuple-ixn-args branch December 4, 2025 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants