Skip to content

Commit 8627e64

Browse files
mikemaccanaclaude
andcommitted
Fix TokenMetadataInitialize realloc: pre-allocate full mint size
Create the mint account at the full required size (base + metadata TLV) upfront so that TokenMetadataInitialize can write TLV data without calling account_info.realloc(). Account data direct mapping prevents realloc within nested CPIs when the account was created in the same transaction, so pre-allocating avoids the InvalidRealloc error. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent c756622 commit 8627e64

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

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

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,16 @@ 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 base size; TokenMetadataInitialize will realloc to mint_size_full.
92-
// Lamports are pre-funded for the full size so the realloc has sufficient rent.
91+
// Create at full size so TokenMetadataInitialize can write TLV data without realloc.
92+
// Account data direct mapping prevents realloc within nested CPIs when the account
93+
// was created in the same transaction.
9394
accounts
9495
.system_program
9596
.create_account(
9697
accounts.payer,
9798
accounts.mint_account,
9899
lamports,
99-
mint_size_base as u64,
100+
mint_size_full as u64,
100101
accounts.token_program.to_account_view().address(),
101102
)
102103
.invoke()?;

0 commit comments

Comments
 (0)