@@ -108,6 +108,27 @@ pub enum TokenWrapInstruction {
108108 /// 4. `[]` Wrapped mint authority (PDA)
109109 /// 5. `[]` Token-2022 program
110110 CloseStuckEscrow ,
111+
112+ /// This instruction copies the metadata fields from an unwrapped mint to
113+ /// its wrapped mint `TokenMetadata` extension.
114+ ///
115+ /// Supports (unwrapped to wrapped):
116+ /// - Token-2022 to Token-2022
117+ /// - SPL-token to Token-2022 (still `TODO`)
118+ ///
119+ /// If the `TokenMetadata` extension on the wrapped mint if not present, it
120+ /// will initialize it. The client is responsible for funding the wrapped
121+ /// mint account with enough lamports to cover the rent for the
122+ /// additional space required by the `TokenMetadata` extension and/or
123+ /// metadata sync.
124+ ///
125+ /// Accounts expected by this instruction:
126+ ///
127+ /// 0. `[w]` Wrapped mint
128+ /// 1. `[]` Wrapped mint authority (PDA)
129+ /// 2. `[]` Unwrapped mint
130+ /// 3. `[]` Token-2022 program
131+ SyncMetadataToToken2022 ,
111132}
112133
113134impl TokenWrapInstruction {
@@ -132,6 +153,9 @@ impl TokenWrapInstruction {
132153 TokenWrapInstruction :: CloseStuckEscrow => {
133154 buf. push ( 3 ) ;
134155 }
156+ TokenWrapInstruction :: SyncMetadataToToken2022 => {
157+ buf. push ( 4 ) ;
158+ }
135159 }
136160 buf
137161 }
@@ -157,6 +181,7 @@ impl TokenWrapInstruction {
157181 Ok ( TokenWrapInstruction :: Unwrap { amount } )
158182 }
159183 Some ( ( & 3 , [ ] ) ) => Ok ( TokenWrapInstruction :: CloseStuckEscrow ) ,
184+ Some ( ( & 4 , [ ] ) ) => Ok ( TokenWrapInstruction :: SyncMetadataToToken2022 ) ,
160185 _ => Err ( ProgramError :: InvalidInstructionData ) ,
161186 }
162187 }
@@ -168,15 +193,13 @@ pub fn create_mint(
168193 wrapped_mint_address : & Pubkey ,
169194 wrapped_backpointer_address : & Pubkey ,
170195 unwrapped_mint_address : & Pubkey ,
171- wrapped_mint_authority_address : & Pubkey ,
172196 wrapped_token_program_id : & Pubkey ,
173197 idempotent : bool ,
174198) -> Instruction {
175199 let accounts = vec ! [
176200 AccountMeta :: new( * wrapped_mint_address, false ) ,
177201 AccountMeta :: new( * wrapped_backpointer_address, false ) ,
178202 AccountMeta :: new_readonly( * unwrapped_mint_address, false ) ,
179- AccountMeta :: new_readonly( * wrapped_mint_authority_address, false ) ,
180203 AccountMeta :: new_readonly( solana_system_interface:: program:: id( ) , false ) ,
181204 AccountMeta :: new_readonly( * wrapped_token_program_id, false ) ,
182205 ] ;
@@ -280,3 +303,20 @@ pub fn close_stuck_escrow(
280303 let data = TokenWrapInstruction :: CloseStuckEscrow . pack ( ) ;
281304 Instruction :: new_with_bytes ( * program_id, & data, accounts)
282305}
306+
307+ /// Creates `SyncMetadataToToken2022` instruction.
308+ pub fn sync_metadata_to_token_2022 (
309+ program_id : & Pubkey ,
310+ wrapped_mint : & Pubkey ,
311+ wrapped_mint_authority : & Pubkey ,
312+ unwrapped_mint : & Pubkey ,
313+ ) -> Instruction {
314+ let accounts = vec ! [
315+ AccountMeta :: new( * wrapped_mint, false ) ,
316+ AccountMeta :: new_readonly( * wrapped_mint_authority, false ) ,
317+ AccountMeta :: new_readonly( * unwrapped_mint, false ) ,
318+ AccountMeta :: new_readonly( spl_token_2022:: id( ) , false ) ,
319+ ] ;
320+ let data = TokenWrapInstruction :: SyncMetadataToToken2022 . pack ( ) ;
321+ Instruction :: new_with_bytes ( * program_id, & data, accounts)
322+ }
0 commit comments