Skip to content

Commit c756622

Browse files
mikemaccanaclaude
andcommitted
Fix metadata: use 4-account TokenMetadataInitialize CPI matching spl-token-metadata-interface spec
Match the Anchor/spl-token-metadata-interface::instruction::initialize account layout: 0: metadata (= mint, writable) 1: update_authority (= payer, readonly) 2: mint (= mint, readonly, dup of 0) 3: mint_authority (= payer, writable+signer, dup of 1) The mint is pre-funded with lamports for the full size in create_account, so no explicit payer/system_program accounts are needed for the realloc. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 3be9824 commit c756622

1 file changed

Lines changed: 9 additions & 14 deletions

File tree

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

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

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,13 @@ 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 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.
149+
// Accounts match spl-token-metadata-interface::instruction::initialize layout:
150+
// 0: metadata (= mint, writable) — where TLV data is written and realloc happens
151+
// 1: update_authority (= payer, readonly) — stored in metadata
152+
// 2: mint (= mint, readonly, dup of 0) — read for mint_authority validation
153+
// 3: mint_authority (= payer, writable+signer, dup of 1) — must sign
154+
// No explicit payer/system_program needed: the mint was pre-funded in create_account
155+
// with sufficient lamports for the full post-realloc size (mint_size_full).
157156
const MAX_META_IX: usize = 512;
158157
let mut buf = [0u8; MAX_META_IX];
159158
let mut pos = 0usize;
@@ -177,19 +176,15 @@ pub fn handle_initialize(
177176
accounts.token_program.to_account_view().address(),
178177
[
179178
InstructionAccount::writable(accounts.mint_account.to_account_view().address()),
179+
InstructionAccount::readonly(accounts.payer.to_account_view().address()),
180+
InstructionAccount::readonly(accounts.mint_account.to_account_view().address()),
180181
InstructionAccount::writable_signer(accounts.payer.to_account_view().address()),
181-
InstructionAccount::writable(accounts.mint_account.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()),
185182
],
186183
[
187184
accounts.mint_account.to_account_view(),
188185
accounts.payer.to_account_view(),
189186
accounts.mint_account.to_account_view(),
190187
accounts.payer.to_account_view(),
191-
accounts.payer.to_account_view(),
192-
accounts.system_program.to_account_view(),
193188
],
194189
buf,
195190
pos,

0 commit comments

Comments
 (0)