Skip to content

Conversation

@slimeonmyhead
Copy link

@slimeonmyhead slimeonmyhead commented Feb 6, 2025

Not sure if I'm missing anything with this fix, but it works with the parsers that I tested it on.
The check_min_accounts_req is still in place at the top, so it will only parse if the account is defined.

My solana knowledge is lacking here: Is there a situation where an instruction has an optional account in the sdk and doesn't default to some value in the on-chain call?

In the cases that I checked (such as meteora swap and jupiter route) the optional accounts are defaulted to the program.

@changeset-bot
Copy link

changeset-bot bot commented Feb 6, 2025

⚠️ No Changeset found

Latest commit: adc5d5f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@lorisleiva
Copy link
Member

I am not really qualified to review the domain logic of this renderer so pinging @kespinola so he can take a look. 🙏

Copy link
Contributor

@Nagaprasadvr Nagaprasadvr left a comment

Choose a reason for hiding this comment

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

few changes to fix logic

let ix_accounts = {{ instruction.name | pascalCase }}IxAccounts{
{% for account in instruction.accounts %}
{% if account.isOptional %}
{{ account.name | snakeCase }}: Some(Pubkey::new_from_array(ix.accounts[{{ account.index }}].0)).into(),
Copy link
Contributor

@Nagaprasadvr Nagaprasadvr Feb 12, 2025

Choose a reason for hiding this comment

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

u also need to check if accounts_len == instruction.accounts.len() then we can decide that optional account was passed and can set it to Some(...) or else we set it to None

also need to be careful with indexes of accounts depending on optional accounts

i guess u can do

let expected_ix_accounts_len = {{ instruction.accounts | length  }};

let ix_accounts = if accounts_len ==  expected_ix_accounts_len {
            {{ instruction.name | pascalCase }}IxAccounts{
            {% for account in instruction.accounts %}
                                    {% if account.isOptional %}
                                        {{ account.name | snakeCase }}: Some(Pubkey::new_from_array(ix.accounts[{{ account.index }}].0)).into(),
                                    {% else %}
                                        {{ account.name | snakeCase }}: ix.accounts[{{ account.index }}].0.into(),
                                    {% endif %}
             {% endfor %}
             }
          }
            else {
                {{ instruction.name | pascalCase }}IxAccounts{
                {% for account in instruction.accounts %}
                                    {% if account.isOptional %}
                                        {{ account.name | snakeCase }}: None
                                    {% else %}
                                        {{ account.name | snakeCase }}: ix.accounts[{{ account.index }}].0.into(),
                                    {% endif %}
                {% endfor %}
             }
          }

Copy link
Contributor

Choose a reason for hiding this comment

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

@slimeonmyhead do you have the time to implement these changes? We can also update.

@Nagaprasadvr
Copy link
Contributor

just checked rust sdk logic - which is defaulting to program id whn processing optional accounts , so we need to add checks for program id as well here

@Nagaprasadvr
Copy link
Contributor

hey @slimeonmyhead any updates on this ?

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.

4 participants