Skip to content

Commit 6049b57

Browse files
mikemaccanaclaude
andcommitted
Fix metadata MetadataPointerInstruction encoding: use PodCOption (4-byte flags)
The MetadataPointerInstruction::Initialize uses PodCOption<Pubkey> which encodes with a 4-byte LE flag ([1,0,0,0] for Some) + 32-byte pubkey, making each field 36 bytes. Total instruction: 74 bytes. Previous attempts used 1-byte COption flags (66 and 68 bytes), which caused InvalidInstructionData because the validator requires exactly [1,0,0,0] or [0,0,0,0] for the 4-byte option field. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 1ede0be commit 6049b57

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

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

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,17 @@ pub fn handle_initialize(
9999
.invoke()?;
100100

101101
// InitializeMetadataPointer: opcode 39, sub-opcode 0.
102-
// Layout: [39, 0, COption_flag(1), authority(32), COption_flag(1), metadata_address(32)]
103-
let mut mp_data = [0u8; 68];
102+
// Uses PodCOption<Pubkey> encoding: 4-byte LE flag + 32-byte pubkey = 36 bytes each.
103+
// Layout: [39, 0, 1,0,0,0, authority(32), 1,0,0,0, metadata_address(32)] = 74 bytes
104+
let mut mp_data = [0u8; 74];
104105
mp_data[0] = 39;
105106
mp_data[1] = 0;
106-
mp_data[2] = 1; // COption::Some for authority
107-
mp_data[3..35].copy_from_slice(accounts.payer.to_account_view().address().as_ref());
108-
mp_data[35] = 1; // COption::Some for metadata_address
109-
mp_data[36..68]
107+
mp_data[2] = 1; // PodCOption::Some flag (4-byte LE: [1,0,0,0])
108+
// mp_data[3..6] already zero
109+
mp_data[6..38].copy_from_slice(accounts.payer.to_account_view().address().as_ref());
110+
mp_data[38] = 1; // PodCOption::Some flag (4-byte LE: [1,0,0,0])
111+
// mp_data[39..42] already zero
112+
mp_data[42..74]
110113
.copy_from_slice(accounts.mint_account.to_account_view().address().as_ref());
111114

112115
CpiCall::new(

0 commit comments

Comments
 (0)