44 extensions:: MintExtension ,
55 mint_builder:: MintBuilder ,
66 } ,
7+ borsh:: BorshSerialize ,
78 mollusk_svm:: { result:: Check , Mollusk } ,
9+ mpl_token_metadata:: { accounts:: Metadata as MetaplexMetadata , types:: Key } ,
810 solana_account:: Account ,
911 solana_pubkey:: Pubkey ,
1012 spl_token_wrap:: {
11- get_wrapped_mint_address, get_wrapped_mint_authority,
13+ get_wrapped_mint_address, get_wrapped_mint_authority, id ,
1214 instruction:: sync_metadata_to_token_2022,
1315 } ,
1416} ;
1517
1618pub struct SyncMetadataResult {
17- pub unwrapped_mint : KeyedAccount ,
1819 pub wrapped_mint : KeyedAccount ,
1920 pub wrapped_mint_authority : KeyedAccount ,
2021}
@@ -25,6 +26,7 @@ pub struct SyncMetadataBuilder<'a> {
2526 unwrapped_mint : Option < KeyedAccount > ,
2627 wrapped_mint : Option < KeyedAccount > ,
2728 wrapped_mint_authority : Option < Pubkey > ,
29+ metaplex_metadata : Option < KeyedAccount > ,
2830}
2931
3032impl Default for SyncMetadataBuilder < ' _ > {
@@ -35,6 +37,7 @@ impl Default for SyncMetadataBuilder<'_> {
3537 unwrapped_mint : None ,
3638 wrapped_mint : None ,
3739 wrapped_mint_authority : None ,
40+ metaplex_metadata : None ,
3841 }
3942 }
4043}
@@ -59,6 +62,11 @@ impl<'a> SyncMetadataBuilder<'a> {
5962 self
6063 }
6164
65+ pub fn metaplex_metadata ( mut self , account : KeyedAccount ) -> Self {
66+ self . metaplex_metadata = Some ( account) ;
67+ self
68+ }
69+
6270 pub fn check ( mut self , check : Check < ' a > ) -> Self {
6371 self . checks . push ( check) ;
6472 self
@@ -93,33 +101,68 @@ impl<'a> SyncMetadataBuilder<'a> {
93101 . build ( )
94102 } ) ;
95103
104+ let metaplex_metadata: Option < KeyedAccount > = self . metaplex_metadata . or_else ( || {
105+ if unwrapped_mint. account . owner == spl_token:: id ( ) {
106+ let metadata = MetaplexMetadata {
107+ key : Key :: MetadataV1 ,
108+ update_authority : Default :: default ( ) ,
109+ mint : unwrapped_mint. key ,
110+ name : "x" . to_string ( ) ,
111+ symbol : "y" . to_string ( ) ,
112+ uri : "z" . to_string ( ) ,
113+ seller_fee_basis_points : 0 ,
114+ creators : None ,
115+ primary_sale_happened : false ,
116+ is_mutable : false ,
117+ edition_nonce : None ,
118+ token_standard : None ,
119+ collection : None ,
120+ uses : None ,
121+ collection_details : None ,
122+ programmable_config : None ,
123+ } ;
124+ Some ( KeyedAccount {
125+ key : MetaplexMetadata :: find_pda ( & unwrapped_mint. key ) . 0 ,
126+ account : Account {
127+ lamports : 1_000_000_000 ,
128+ data : metadata. try_to_vec ( ) . unwrap ( ) ,
129+ owner : mpl_token_metadata:: ID ,
130+ ..Default :: default ( )
131+ } ,
132+ } )
133+ } else {
134+ None
135+ }
136+ } ) ;
137+
96138 let instruction = sync_metadata_to_token_2022 (
97- & spl_token_wrap :: id ( ) ,
139+ & id ( ) ,
98140 & wrapped_mint. key ,
99141 & wrapped_mint_authority,
100142 & unwrapped_mint. key ,
143+ metaplex_metadata. as_ref ( ) . map ( |ka| & ka. key ) ,
101144 ) ;
102145
103- let accounts = & [
146+ let mut accounts = vec ! [
104147 wrapped_mint. pair( ) ,
105148 ( wrapped_mint_authority, Account :: default ( ) ) ,
106149 unwrapped_mint. pair( ) ,
107150 TokenProgram :: SplToken2022 . keyed_account( ) ,
108151 ] ;
109152
153+ if let Some ( metadata) = metaplex_metadata {
154+ accounts. push ( metadata. pair ( ) ) ;
155+ }
156+
110157 if self . checks . is_empty ( ) {
111158 self . checks . push ( Check :: success ( ) ) ;
112159 }
113160
114161 let result =
115162 self . mollusk
116- . process_and_validate_instruction ( & instruction, accounts, & self . checks ) ;
163+ . process_and_validate_instruction ( & instruction, & accounts, & self . checks ) ;
117164
118165 SyncMetadataResult {
119- unwrapped_mint : KeyedAccount {
120- key : unwrapped_mint. key ,
121- account : result. get_account ( & unwrapped_mint. key ) . unwrap ( ) . clone ( ) ,
122- } ,
123166 wrapped_mint : KeyedAccount {
124167 key : wrapped_mint. key ,
125168 account : result. get_account ( & wrapped_mint. key ) . unwrap ( ) . clone ( ) ,
0 commit comments