Skip to content

Commit 3be9824

Browse files
mikemaccanaclaude
andcommitted
Fix metadata: add payer+system_program to TokenMetadataInitialize CPI
token-2022 v7's spl-token-metadata-interface requires explicit payer and system_program accounts at positions 4-5 to perform the account resize. Without them the handler returns InvalidRealloc instead of doing the alloc. Mark all payer instances as writable_signer to avoid access-mode conflicts. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent d1557a3 commit 3be9824

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

  • tokens/token-2022/metadata/quasar/src

tokens/token-2022/metadata/quasar/src/lib.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,14 @@ pub fn handle_initialize(
146146
// Data: [discriminator(8), name_len(u32 LE), name, symbol_len(u32 LE), symbol,
147147
// uri_len(u32 LE), uri]
148148
// (update_authority and mint are passed as accounts, not instruction data)
149-
// Accounts: [metadata(=mint, writable), update_authority(readonly),
150-
// mint(writable, same as metadata), mint_authority(signer)]
151-
// mint must be writable (not readonly) to avoid InvalidRealloc: the Solana
152-
// runtime rejects resizing an account that's also aliased as readonly.
149+
// Accounts for TokenMetadataInitialize:
150+
// 0: metadata (= mint, writable)
151+
// 1: update_authority (writable_signer — same as payer; must match access of accounts 3+4)
152+
// 2: mint (writable — same account as 0; must be writable to allow realloc without alias conflict)
153+
// 3: mint_authority (writable_signer — same as payer)
154+
// 4: payer for realloc (writable_signer — token-2022 v7 requires explicit payer+system_program)
155+
// 5: system_program (readonly — for the realloc CPI)
156+
// All payer instances are writable_signer to avoid access-mode conflict from deduplication.
153157
const MAX_META_IX: usize = 512;
154158
let mut buf = [0u8; MAX_META_IX];
155159
let mut pos = 0usize;
@@ -173,15 +177,19 @@ pub fn handle_initialize(
173177
accounts.token_program.to_account_view().address(),
174178
[
175179
InstructionAccount::writable(accounts.mint_account.to_account_view().address()),
176-
InstructionAccount::readonly(accounts.payer.to_account_view().address()),
180+
InstructionAccount::writable_signer(accounts.payer.to_account_view().address()),
177181
InstructionAccount::writable(accounts.mint_account.to_account_view().address()),
178-
InstructionAccount::readonly_signer(accounts.payer.to_account_view().address()),
182+
InstructionAccount::writable_signer(accounts.payer.to_account_view().address()),
183+
InstructionAccount::writable_signer(accounts.payer.to_account_view().address()),
184+
InstructionAccount::readonly(accounts.system_program.to_account_view().address()),
179185
],
180186
[
181187
accounts.mint_account.to_account_view(),
182188
accounts.payer.to_account_view(),
183189
accounts.mint_account.to_account_view(),
184190
accounts.payer.to_account_view(),
191+
accounts.payer.to_account_view(),
192+
accounts.system_program.to_account_view(),
185193
],
186194
buf,
187195
pos,

0 commit comments

Comments
 (0)