Skip to content

Commit d1557a3

Browse files
mikemaccanaclaude
andcommitted
Fix metadata: revert to base-size account, mark mint writable in CPI
- Revert account creation to 234 bytes (base + MetadataPointer space) so InitializeMint2 passes its extension-size validation - Mark mint as writable (not readonly) at position 2 in the TokenMetadataInitialize CPI to allow the internal realloc to succeed (Solana runtime rejects realloc when the account is also aliased readonly) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 3c72bbd commit d1557a3

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

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

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,15 @@ pub fn handle_initialize(
8888
let mint_size_full = mint_size_base + 4 + metadata_data_len;
8989
let lamports = Rent::get()?.try_minimum_balance(mint_size_full)?;
9090

91-
// Create at full size upfront: token-2022 cannot realloc an account inside CPI.
91+
// Create at base size; TokenMetadataInitialize will realloc to mint_size_full.
92+
// Lamports are pre-funded for the full size so the realloc has sufficient rent.
9293
accounts
9394
.system_program
9495
.create_account(
9596
accounts.payer,
9697
accounts.mint_account,
9798
lamports,
98-
mint_size_full as u64,
99+
mint_size_base as u64,
99100
accounts.token_program.to_account_view().address(),
100101
)
101102
.invoke()?;
@@ -146,7 +147,9 @@ pub fn handle_initialize(
146147
// uri_len(u32 LE), uri]
147148
// (update_authority and mint are passed as accounts, not instruction data)
148149
// Accounts: [metadata(=mint, writable), update_authority(readonly),
149-
// mint(readonly), mint_authority(signer)]
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.
150153
const MAX_META_IX: usize = 512;
151154
let mut buf = [0u8; MAX_META_IX];
152155
let mut pos = 0usize;
@@ -171,7 +174,7 @@ pub fn handle_initialize(
171174
[
172175
InstructionAccount::writable(accounts.mint_account.to_account_view().address()),
173176
InstructionAccount::readonly(accounts.payer.to_account_view().address()),
174-
InstructionAccount::readonly(accounts.mint_account.to_account_view().address()),
177+
InstructionAccount::writable(accounts.mint_account.to_account_view().address()),
175178
InstructionAccount::readonly_signer(accounts.payer.to_account_view().address()),
176179
],
177180
[

0 commit comments

Comments
 (0)