Skip to content

Commit 4926032

Browse files
authored
fix(macros): Provide full import paths in light_accounts macro (#1063)
* fix(macros): Provide full import paths in `light_accounts` macro Before this change, using `#[light_accounts]` macro required adding necessary imports manually, e.g. ```rust use account_compression::program::AccountCompression; use light_system_program::program::LightSystemProgram; ``` Which might've been annoying for developers. This change uses full paths for all foregin types used inside macros, so no additional imports are needed. * fix(macros): Provide full import paths in `LightTraits` (#1069) Before this change, using `#[derive(LightTraits)]` macro required adding necessary imports manually, e.g. ```rust use light_sdk::traits::{InvokeAccounts, SignerAccounts}; ``` Which might've been annoying for developers. This change uses full paths for all foreign types used inside macros, so no additional imports are needed. * style: Use all avaiable light macros in token-escrow Also, remove unnecessary imports. * style: Use `AccountInfo` instead of `UncheckedAccount`
1 parent 183b79a commit 4926032

File tree

12 files changed

+66
-61
lines changed

12 files changed

+66
-61
lines changed

examples/token-escrow/programs/token-escrow/src/escrow_with_compressed_pda/escrow.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::{create_change_output_compressed_token_account, program::TokenEscrow, EscrowTimeLock};
2-
use account_compression::{program::AccountCompression, RegisteredProgram};
32
use anchor_lang::prelude::*;
43
use light_compressed_token::{
54
process_transfer::{
@@ -15,7 +14,6 @@ use light_sdk::{
1514
use light_system_program::{
1615
invoke::processor::CompressedProof,
1716
invoke_cpi::account::CpiContextAccount,
18-
program::LightSystemProgram,
1917
sdk::{
2018
address::derive_address,
2119
compressed_account::{CompressedAccount, CompressedAccountData, PackedMerkleContext},
@@ -24,8 +22,6 @@ use light_system_program::{
2422
NewAddressParamsPacked, OutputCompressedAccountWithPackedContext,
2523
};
2624

27-
use light_sdk::traits::*;
28-
2925
#[light_accounts]
3026
#[derive(Accounts, LightTraits)]
3127
pub struct EscrowCompressedTokensWithCompressedPda<'info> {

examples/token-escrow/programs/token-escrow/src/escrow_with_pda/escrow.rs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::create_change_output_compressed_token_account;
2-
use account_compression::{program::AccountCompression, RegisteredProgram};
32
use anchor_lang::prelude::*;
43
use light_compressed_token::{
54
process_transfer::{
@@ -8,13 +7,10 @@ use light_compressed_token::{
87
},
98
program::LightCompressedToken,
109
};
11-
use light_sdk::traits::*;
12-
use light_sdk::LightTraits;
13-
use light_system_program::{
14-
invoke::processor::CompressedProof, invoke_cpi::account::CpiContextAccount,
15-
program::LightSystemProgram,
16-
};
10+
use light_sdk::{light_accounts, LightTraits};
11+
use light_system_program::invoke::processor::CompressedProof;
1712

13+
#[light_accounts]
1814
#[derive(Accounts, LightTraits)]
1915
pub struct EscrowCompressedTokensWithPda<'info> {
2016
#[account(mut)]
@@ -26,19 +22,10 @@ pub struct EscrowCompressedTokensWithPda<'info> {
2622
pub token_owner_pda: AccountInfo<'info>,
2723
#[self_program]
2824
pub compressed_token_program: Program<'info, LightCompressedToken>,
29-
pub light_system_program: Program<'info, LightSystemProgram>,
30-
pub account_compression_program: Program<'info, AccountCompression>,
31-
/// CHECK:
32-
pub account_compression_authority: AccountInfo<'info>,
3325
/// CHECK:
3426
pub compressed_token_cpi_authority_pda: AccountInfo<'info>,
35-
/// CHECK:
36-
pub registered_program_pda: Account<'info, RegisteredProgram>,
37-
/// CHECK:
38-
pub noop_program: AccountInfo<'info>,
3927
#[account(init_if_needed, seeds = [b"timelock".as_slice(), signer.key.to_bytes().as_slice()],bump, payer = signer, space = 8 + 8)]
4028
pub timelock_pda: Account<'info, EscrowTimeLock>,
41-
pub system_program: Program<'info, System>,
4229
}
4330

4431
#[derive(Debug)]

macros/light/src/accounts.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,20 @@ pub(crate) fn process_light_accounts(input: DeriveInput) -> Result<TokenStream>
88
if let Data::Struct(ref mut data_struct) = output.data {
99
if let Fields::Named(ref mut fields) = data_struct.fields {
1010
let fields_to_add = [
11-
("light_system_program", "Program<'info, LightSystemProgram>"),
11+
(
12+
"light_system_program",
13+
"Program<'info, ::light_system_program::program::LightSystemProgram>",
14+
),
1215
("system_program", "Program<'info, System>"),
1316
(
1417
"account_compression_program",
15-
"Program<'info, AccountCompression>",
18+
"Program<'info, ::account_compression::program::AccountCompression>",
1619
),
1720
];
1821
let fields_to_add_check = [
1922
(
2023
"registered_program_pda",
21-
"Account<'info, RegisteredProgram>",
24+
"Account<'info, ::account_compression::RegisteredProgram>",
2225
),
2326
("noop_program", "AccountInfo<'info>"),
2427
("account_compression_authority", "AccountInfo<'info>"),

macros/light/src/traits.rs

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -198,46 +198,55 @@ fn process_fields_and_attributes(name: &Ident, fields: FieldsNamed) -> TokenStre
198198
}
199199
} else {
200200
let base_impls = quote! {
201-
impl<'info> InvokeCpiAccounts<'info> for #name<'info> {
201+
impl<'info> ::light_sdk::traits::InvokeCpiAccounts<'info> for #name<'info> {
202202
fn get_invoking_program(&self) -> &AccountInfo<'info> {
203203
&self.#self_program_field
204204
}
205205
}
206-
impl<'info> SignerAccounts<'info> for #name<'info> {
207-
fn get_fee_payer(&self) -> &Signer<'info> {
206+
impl<'info> ::light_sdk::traits::SignerAccounts<'info> for #name<'info> {
207+
fn get_fee_payer(&self) -> &::anchor_lang::prelude::Signer<'info> {
208208
&self.#fee_payer_field
209209
}
210-
fn get_authority(&self) -> &AccountInfo<'info> {
210+
fn get_authority(&self) -> &::anchor_lang::prelude::AccountInfo<'info> {
211211
&self.#authority_field
212212
}
213213
}
214-
impl<'info> LightSystemAccount<'info> for #name<'info> {
215-
fn get_light_system_program(&self) -> &Program<'info, LightSystemProgram> {
214+
impl<'info> ::light_sdk::traits::LightSystemAccount<'info> for #name<'info> {
215+
fn get_light_system_program(&self) -> &::anchor_lang::prelude::Program<
216+
'info,
217+
::light_system_program::program::LightSystemProgram
218+
> {
216219
&self.#light_system_program_field
217220
}
218221
}
219222
};
220223
let invoke_accounts_impl = quote! {
221-
impl<'info> InvokeAccounts<'info> for #name<'info> {
222-
fn get_registered_program_pda(&self) -> &Account<'info, RegisteredProgram> {
224+
impl<'info> ::light_sdk::traits::InvokeAccounts<'info> for #name<'info> {
225+
fn get_registered_program_pda(&self) -> &::anchor_lang::prelude::Account<
226+
'info,
227+
::account_compression::RegisteredProgram
228+
> {
223229
&self.#registered_program_pda_field
224230
}
225-
fn get_noop_program(&self) -> &AccountInfo<'info> {
231+
fn get_noop_program(&self) -> &::anchor_lang::prelude::AccountInfo<'info> {
226232
&self.#noop_program_field
227233
}
228-
fn get_account_compression_authority(&self) -> &AccountInfo<'info> {
234+
fn get_account_compression_authority(&self) -> &::anchor_lang::prelude::AccountInfo<'info> {
229235
&self.#account_compression_authority_field
230236
}
231-
fn get_account_compression_program(&self) -> &Program<'info, AccountCompression> {
237+
fn get_account_compression_program(&self) -> &::anchor_lang::prelude::Program<
238+
'info,
239+
::account_compression::program::AccountCompression
240+
> {
232241
&self.#account_compression_program_field
233242
}
234-
fn get_system_program(&self) -> &Program<'info, System> {
243+
fn get_system_program(&self) -> &::anchor_lang::prelude::Program<'info, System> {
235244
&self.#system_program_field
236245
}
237-
fn get_compressed_sol_pda(&self) -> Option<&UncheckedAccount<'info>> {
246+
fn get_compressed_sol_pda(&self) -> Option<&::anchor_lang::prelude::AccountInfo<'info>> {
238247
#compressed_sol_pda_field
239248
}
240-
fn get_compression_recipient(&self) -> Option<&UncheckedAccount<'info>> {
249+
fn get_compression_recipient(&self) -> Option<&::anchor_lang::prelude::AccountInfo<'info>> {
241250
#compression_recipient_field
242251
}
243252
}
@@ -246,8 +255,13 @@ fn process_fields_and_attributes(name: &Ident, fields: FieldsNamed) -> TokenStre
246255
quote! {
247256
#base_impls
248257
#invoke_accounts_impl
249-
impl<'info> InvokeCpiContextAccount<'info> for #name<'info> {
250-
fn get_cpi_context_account(&self) -> Option<&Account<'info, CpiContextAccount>> {
258+
impl<'info> ::light_sdk::traits::InvokeCpiContextAccount<'info> for #name<'info> {
259+
fn get_cpi_context_account(&self) -> Option<
260+
&::anchor_lang::prelude::Account<
261+
'info,
262+
::light_system_program::invoke_cpi::account::CpiContextAccount
263+
>
264+
> {
251265
None
252266
}
253267
}
@@ -256,8 +270,13 @@ fn process_fields_and_attributes(name: &Ident, fields: FieldsNamed) -> TokenStre
256270
quote! {
257271
#base_impls
258272
#invoke_accounts_impl
259-
impl<'info> InvokeCpiContextAccount<'info> for #name<'info> {
260-
fn get_cpi_context_account(&self) -> Option<&Account<'info, CpiContextAccount>> {
273+
impl<'info> ::light_sdk::traits::InvokeCpiContextAccount<'info> for #name<'info> {
274+
fn get_cpi_context_account(&self) -> Option<
275+
&::anchor_lang::prelude::Account<
276+
'info,
277+
::light_system_program::invoke_cpi::account::CpiContextAccount
278+
>
279+
> {
261280
Some(&self.#cpi_context_account_field)
262281
}
263282
}

programs/compressed-token/src/instructions/burn.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ impl<'info> InvokeAccounts<'info> for BurnInstruction<'info> {
6060
&self.system_program
6161
}
6262

63-
fn get_sol_pool_pda(&self) -> Option<&UncheckedAccount<'info>> {
63+
fn get_sol_pool_pda(&self) -> Option<&AccountInfo<'info>> {
6464
None
6565
}
6666

67-
fn get_decompression_recipient(&self) -> Option<&UncheckedAccount<'info>> {
67+
fn get_decompression_recipient(&self) -> Option<&AccountInfo<'info>> {
6868
None
6969
}
7070
}

programs/compressed-token/src/instructions/freeze.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ impl<'info> InvokeAccounts<'info> for FreezeInstruction<'info> {
5252
&self.system_program
5353
}
5454

55-
fn get_sol_pool_pda(&self) -> Option<&UncheckedAccount<'info>> {
55+
fn get_sol_pool_pda(&self) -> Option<&AccountInfo<'info>> {
5656
None
5757
}
5858

59-
fn get_decompression_recipient(&self) -> Option<&UncheckedAccount<'info>> {
59+
fn get_decompression_recipient(&self) -> Option<&AccountInfo<'info>> {
6060
None
6161
}
6262
}

programs/compressed-token/src/instructions/generic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ impl<'info> InvokeAccounts<'info> for GenericInstruction<'info> {
5151
&self.system_program
5252
}
5353

54-
fn get_sol_pool_pda(&self) -> Option<&UncheckedAccount<'info>> {
54+
fn get_sol_pool_pda(&self) -> Option<&AccountInfo<'info>> {
5555
None
5656
}
5757

58-
fn get_decompression_recipient(&self) -> Option<&UncheckedAccount<'info>> {
58+
fn get_decompression_recipient(&self) -> Option<&AccountInfo<'info>> {
5959
None
6060
}
6161
}

programs/compressed-token/src/instructions/transfer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ impl<'info> InvokeAccounts<'info> for TransferInstruction<'info> {
6161
&self.system_program
6262
}
6363

64-
fn get_sol_pool_pda(&self) -> Option<&UncheckedAccount<'info>> {
64+
fn get_sol_pool_pda(&self) -> Option<&AccountInfo<'info>> {
6565
None
6666
}
6767

68-
fn get_decompression_recipient(&self) -> Option<&UncheckedAccount<'info>> {
68+
fn get_decompression_recipient(&self) -> Option<&AccountInfo<'info>> {
6969
None
7070
}
7171
}

programs/system/src/invoke/instruction.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ pub struct InvokeInstruction<'info> {
3939
mut,
4040
seeds = [SOL_POOL_PDA_SEED], bump
4141
)]
42-
pub sol_pool_pda: Option<UncheckedAccount<'info>>,
42+
pub sol_pool_pda: Option<AccountInfo<'info>>,
4343
/// Only needs to be provided for decompression as a recipient for the
4444
/// decompressed sol.
4545
/// Compressed sol originate from authority.
4646
#[account(mut)]
47-
pub decompression_recipient: Option<UncheckedAccount<'info>>,
47+
pub decompression_recipient: Option<AccountInfo<'info>>,
4848
pub system_program: Program<'info, System>,
4949
}
5050

@@ -79,11 +79,11 @@ impl<'info> InvokeAccounts<'info> for InvokeInstruction<'info> {
7979
&self.system_program
8080
}
8181

82-
fn get_sol_pool_pda(&self) -> Option<&UncheckedAccount<'info>> {
82+
fn get_sol_pool_pda(&self) -> Option<&AccountInfo<'info>> {
8383
self.sol_pool_pda.as_ref()
8484
}
8585

86-
fn get_decompression_recipient(&self) -> Option<&UncheckedAccount<'info>> {
86+
fn get_decompression_recipient(&self) -> Option<&AccountInfo<'info>> {
8787
self.decompression_recipient.as_ref()
8888
}
8989
}

programs/system/src/invoke_cpi/instruction.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ pub struct InvokeCpiInstruction<'info> {
3939
mut,
4040
seeds = [SOL_POOL_PDA_SEED], bump
4141
)]
42-
pub sol_pool_pda: Option<UncheckedAccount<'info>>,
42+
pub sol_pool_pda: Option<AccountInfo<'info>>,
4343
#[account(mut)]
44-
pub decompression_recipient: Option<UncheckedAccount<'info>>,
44+
pub decompression_recipient: Option<AccountInfo<'info>>,
4545
pub system_program: Program<'info, System>,
4646
#[account(mut)]
4747
pub cpi_context_account: Option<Account<'info, CpiContextAccount>>,
@@ -74,11 +74,11 @@ impl<'info> InvokeAccounts<'info> for InvokeCpiInstruction<'info> {
7474
&self.account_compression_program
7575
}
7676

77-
fn get_sol_pool_pda(&self) -> Option<&UncheckedAccount<'info>> {
77+
fn get_sol_pool_pda(&self) -> Option<&AccountInfo<'info>> {
7878
self.sol_pool_pda.as_ref()
7979
}
8080

81-
fn get_decompression_recipient(&self) -> Option<&UncheckedAccount<'info>> {
81+
fn get_decompression_recipient(&self) -> Option<&AccountInfo<'info>> {
8282
self.decompression_recipient.as_ref()
8383
}
8484

0 commit comments

Comments
 (0)