@@ -21,7 +21,24 @@ import V1ToV2MigrationPrompt from "/snippets/ai-prompts/v1-to-v2-migration.mdx";
2121
2222### Update Cargo.toml
2323
24- in 0.17.x onward, V2 is a recommended default feature.
24+ In 0.17.x onward, ` v2 ` is a default feature of ` light-sdk ` . Make sure it stays enabled.
25+
26+ <Info >
27+ When you specify ` features = [...] ` in Cargo.toml, Cargo ** disables default features** .
28+ If you need extra features like ` keccak ` or ` anchor ` , either keep defaults explicitly
29+ or add ` v2 ` to your features list:
30+
31+ ``` toml
32+ # This DISABLES v2 (default features are off):
33+ light-sdk = { version = " 0.17.1" , features = [" keccak" ] }
34+
35+ # Either of these keeps v2 enabled:
36+ light-sdk = { version = " 0.17.1" , features = [" keccak" , " v2" ] }
37+ light-sdk = { version = " 0.17.1" , default-features = true , features = [" keccak" ] }
38+ ```
39+
40+ Without ` v2 ` , ` add_system_accounts_v2 ` and ` cpi::v2 ` are not available.
41+ </Info >
2542
2643** On-chain program:**
2744
@@ -42,7 +59,7 @@ light-sdk = { version = "0.17.1", features = ["anchor"] }
4259
4360``` toml
4461[dependencies ]
45- light-client = " 0.17.2"
62+ light-client = { version = " 0.17.2" , features = [ " v2 " ] }
4663```
4764
4865
@@ -108,14 +125,75 @@ if address_tree_pubkey.to_bytes() != ADDRESS_TREE_V2 {
108125}
109126```
110127
128+ ### Update client-side account packing
129+
130+ ``` rust
131+ use light_sdk :: instruction :: {PackedAccounts , SystemAccountMetaConfig };
132+
133+ let config = SystemAccountMetaConfig :: new (YOUR_PROGRAM_ID );
134+ let mut packed = PackedAccounts :: default ();
135+ ```
136+
137+ ``` rust
138+ // v1
139+ packed . add_system_accounts (config )? ;
140+ ```
141+
142+ ``` rust
143+ // v2
144+ packed . add_system_accounts_v2 (config )? ;
145+ ```
146+
147+ ** Full v2 client example**
148+
149+ ``` rust
150+ use light_client :: rpc :: {LightClient , LightClientConfig , Rpc , Indexer };
151+ use light_sdk :: {
152+ address :: v2 :: derive_address,
153+ instruction :: {PackedAccounts , SystemAccountMetaConfig },
154+ };
155+
156+ // 1. Build PackedAccounts with v2 system accounts
157+ let config = SystemAccountMetaConfig :: new (YOUR_PROGRAM_ID );
158+ let mut packed = PackedAccounts :: default ();
159+ packed . add_system_accounts_v2 (config )? ;
160+
161+ // 2. Fetch validity proof
162+ let address_tree = rpc . get_address_tree_v2 ();
163+ let (address , _ ) = derive_address (& [b " my_seed" , & id ], & address_tree . tree, & YOUR_PROGRAM_ID );
164+
165+ let rpc_result = rpc
166+ . get_validity_proof (
167+ vec! [],
168+ vec! [AddressWithTree { address , tree : address_tree . tree }],
169+ None ,
170+ )
171+ . await ?
172+ . value;
173+
174+ // 3. Pack tree infos into remaining accounts
175+ let tree_infos = rpc_result . pack_tree_infos (& mut packed );
176+ let address_tree_info = tree_infos . address_trees[0 ];
177+
178+ // 4. Pack output state tree
179+ let state_tree = rpc . get_random_state_tree_info ()? ;
180+ let output_state_tree_index = state_tree . pack_output_tree_index (& mut packed )? ;
181+
182+ // 5. Convert to account metas for the instruction
183+ let (remaining_accounts , _system_offset , _packed_offset ) = packed . to_account_metas ();
184+ ```
185+
111186### Update client code (light-client)
112187
113188``` rust
114189use light_client :: rpc :: {LightClient , LightClientConfig , Rpc };
115190
116- let rpc = LightClient :: new (
117- LightClientConfig :: new (" https://mainnet.helius-rpc.com/?api-key=YOUR_KEY" )
118- ). await ? ;
191+ let rpc_url = " https://mainnet.helius-rpc.com/?api-key=YOUR_KEY" . to_string ();
192+ let photon_url = " https://mainnet.helius-rpc.com" . to_string ();
193+ let api_key = " YOUR_KEY" . to_string ();
194+
195+ let config = LightClientConfig :: new (rpc_url , Some (photon_url ), Some (api_key ));
196+ let mut rpc = LightClient :: new (config ). await ? ;
119197```
120198
121199** Tree info methods:**
0 commit comments