Skip to content

Fix: token2022 support#1249

Merged
GabrielePicco merged 10 commits into
masterfrom
fix/token-2022-support
May 29, 2026
Merged

Fix: token2022 support#1249
GabrielePicco merged 10 commits into
masterfrom
fix/token-2022-support

Conversation

@GabrielePicco
Copy link
Copy Markdown
Collaborator

@GabrielePicco GabrielePicco commented May 26, 2026

Summary by CodeRabbit

Release Notes

  • New Features

    • Added support for Token-2022 (SPL Token Extensions) program alongside standard SPL Token, enabling operations with Token-2022 accounts.
    • Enhanced ATA validation and projection logic with improved delegated account handling.
  • Tests

    • Expanded test coverage for Token-2022 ATA operations, delegation scenarios, and account projection functionality.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 26, 2026

Warning

Review limit reached

@GabrielePicco, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 16 minutes and 4 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 5764d0c1-4947-490a-98ea-1d1e616c6649

📥 Commits

Reviewing files that changed from the base of the PR and between f01c43c and 6dd40a9.

📒 Files selected for processing (2)
  • magicblock-chainlink/src/chainlink/fetch_cloner/tests.rs
  • magicblock-chainlink/src/testing/eatas.rs
📝 Walkthrough

Walkthrough

This PR extends ATA and eATA handling throughout the codebase to support the Token-2022 program alongside the standard Token Program. Core changes include introducing a TOKEN_2022_PROGRAM_ID constant, parameterized ATA derivation functions accepting an explicit token program, adding a bump field to EphemeralAta with new parsing and projection methods, and expanding try_derive_supported_ata_pubkeys to return both legacy and Token-2022 ATA candidates. Test helpers are refactored to build token-program-specific accounts flexibly. The FetchCloner greedy discovery path now derives and attempts both ATA candidates when handling delegated eATAs. Permission validation in scheduled commits accepts both token programs for eATA special cases. Comprehensive test coverage validates Token-2022 ATA projection, ownership preservation, layout correctness, and end-to-end fetch-and-clone flows.

Suggested reviewers

  • thlorenz
  • bmuddha
  • lucacillario
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/token-2022-support

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@GabrielePicco GabrielePicco force-pushed the fix/token-2022-support branch from 80c6028 to a1f8a1d Compare May 26, 2026 16:14
@chatgpt-codex-connector

This comment was marked as off-topic.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 945eda8181

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread magicblock-core/src/token_programs.rs
@GabrielePicco GabrielePicco requested a review from thlorenz May 26, 2026 16:57
@GabrielePicco GabrielePicco changed the title Fix: token 2022 support Fix: token2022 support May 26, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5332ee4e2e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread magicblock-chainlink/src/chainlink/fetch_cloner/mod.rs Outdated
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f6e7581ee4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread test-integration/configs/cloning-conf.ephem.toml Outdated
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@magicblock-chainlink/src/chainlink/fetch_cloner/mod.rs`:
- Around line 1375-1396: The code currently defaults ata_pubkey to
legacy_ata_pubkey and proceeds to project from eata_account even when neither
token_2022_ata_pubkey nor legacy_ata_pubkey were found in self.accounts_bank;
change the logic so that ata_pubkey is not pre-seeded (use Option for ata_pubkey
or only assign when a candidate is found), and after the loop if
in_bank_ata.is_none() simply return None instead of falling back to
eata_account; then call maybe_project_delegated_ata_from_eata only with the
found in_bank_ata (use in_bank_ata.as_ref().unwrap() safely) so the function
maybe_project_delegated_ata_from_eata(ata_account, eata_account, deleg_record)
is only invoked when an ATA was actually present in the bank.

In `@magicblock-chainlink/src/testing/eatas.rs`:
- Around line 25-32: The function create_token_2022_ata_account currently uses a
magic number 187 for the Token-2022 account data length; update the code by
adding a concise comment above or inline with create_token_2022_ata_account
(and/or where create_ata_account_with_token_program is called with
TOKEN_2022_PROGRAM_ID) explaining the breakdown of 187 (e.g., base account 165
bytes + 22 bytes for specific Token-2022 extensions used) so future maintainers
understand why 187 is chosen and when it should be changed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: a9269482-2dea-47a8-9ffd-99319b1caad3

📥 Commits

Reviewing files that changed from the base of the PR and between a49abaa and f6e7581.

📒 Files selected for processing (10)
  • magicblock-chainlink/src/chainlink/fetch_cloner/ata_projection.rs
  • magicblock-chainlink/src/chainlink/fetch_cloner/delegation.rs
  • magicblock-chainlink/src/chainlink/fetch_cloner/mod.rs
  • magicblock-chainlink/src/chainlink/fetch_cloner/tests.rs
  • magicblock-chainlink/src/testing/eatas.rs
  • magicblock-core/src/token_programs.rs
  • programs/magicblock/src/clone_account/process_clone.rs
  • programs/magicblock/src/magic_scheduled_base_intent.rs
  • programs/magicblock/src/schedule_transactions/process_schedule_commit_tests.rs
  • test-integration/configs/cloning-conf.ephem.toml
💤 Files with no reviewable changes (1)
  • programs/magicblock/src/clone_account/process_clone.rs

Comment thread magicblock-chainlink/src/chainlink/fetch_cloner/mod.rs Outdated
Comment thread magicblock-chainlink/src/testing/eatas.rs
Copy link
Copy Markdown
Collaborator

@thlorenz thlorenz left a comment

Choose a reason for hiding this comment

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

LGTM regarding correctness, but the implementation has some repetition and adds eATA specific knowledge to the fetch cloner which isn't ideal.

I explained in the comments how we should improve this before merging.

Comment thread magicblock-chainlink/src/chainlink/fetch_cloner/ata_projection.rs Outdated
Comment thread magicblock-chainlink/src/chainlink/fetch_cloner/mod.rs Outdated
Comment thread magicblock-chainlink/src/chainlink/fetch_cloner/mod.rs Outdated
Comment thread magicblock-chainlink/src/chainlink/fetch_cloner/mod.rs Outdated
@GabrielePicco
Copy link
Copy Markdown
Collaborator Author

LGTM regarding correctness, but the implementation has some repetition and adds eATA specific knowledge to the fetch cloner which isn't ideal.

I explained in the comments how we should improve this before merging.

Thanks @thlorenz, applied the suggestions

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@magicblock-chainlink/src/testing/eatas.rs`:
- Around line 37-53: The helper create_token_2022_ata_account_with_extensions
currently only computes data_len but returns an ATA whose data region beyond
SplAccount::LEN is zeroed; update it to actually initialize the Token-2022
TLV/extensions: after calling create_ata_account_with_token_program (or instead
of returning its Account directly), create/pack a spl_token_2022::state::Account
(Token2022Account) for the same owner/mint and use ExtensionType::populate or
the token-2022 packing helpers to write the requested account_extensions into
the account.data buffer so the returned Account contains the proper
Token2022Account header and initialized extension TLVs (referencing
create_token_2022_ata_account_with_extensions,
create_ata_account_with_token_program, Token2022Account, ExtensionType, and
TOKEN_2022_PROGRAM_ID).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 057ec09a-409b-4305-8f9b-2fbbb3978fea

📥 Commits

Reviewing files that changed from the base of the PR and between f6e7581 and f01c43c.

📒 Files selected for processing (5)
  • magicblock-chainlink/src/chainlink/fetch_cloner/ata_projection.rs
  • magicblock-chainlink/src/chainlink/fetch_cloner/mod.rs
  • magicblock-chainlink/src/chainlink/fetch_cloner/tests.rs
  • magicblock-chainlink/src/testing/eatas.rs
  • magicblock-core/src/token_programs.rs

Comment thread magicblock-chainlink/src/testing/eatas.rs Outdated
@GabrielePicco GabrielePicco merged commit d3fa68e into master May 29, 2026
33 checks passed
@GabrielePicco GabrielePicco deleted the fix/token-2022-support branch May 29, 2026 12:09
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