-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlib.rs
More file actions
57 lines (51 loc) · 1.98 KB
/
lib.rs
File metadata and controls
57 lines (51 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#![allow(unexpected_cfgs, deprecated)]
use anchor_lang::prelude::*;
use light_token::instruction::CreateAssociatedAccountCpi;
declare_id!("35MukgdfpNUbPMhTmEk63ECV8vjgpNVFRH9nP8ovMN58");
#[program]
pub mod light_token_anchor_create_associated_token_account {
use super::*;
pub fn create_associated_token_account(ctx: Context<CreateAssociatedTokenAccountAccounts>, idempotent: bool) -> Result<()> {
let cpi = CreateAssociatedAccountCpi {
payer: ctx.accounts.payer.to_account_info(),
owner: ctx.accounts.owner.to_account_info(),
mint: ctx.accounts.mint.to_account_info(),
ata: ctx.accounts.associated_token_account.to_account_info(),
};
if idempotent {
cpi.idempotent().rent_free(
ctx.accounts.compressible_config.to_account_info(),
ctx.accounts.rent_sponsor.to_account_info(),
ctx.accounts.system_program.to_account_info(),
)
} else {
cpi.rent_free(
ctx.accounts.compressible_config.to_account_info(),
ctx.accounts.rent_sponsor.to_account_info(),
ctx.accounts.system_program.to_account_info(),
)
}
.invoke()?;
Ok(())
}
}
#[derive(Accounts)]
pub struct CreateAssociatedTokenAccountAccounts<'info> {
/// CHECK: Light token program for CPI
pub light_token_program: AccountInfo<'info>,
/// CHECK: Validated by light-token CPI
pub owner: AccountInfo<'info>,
/// CHECK: Validated by light-token CPI
pub mint: AccountInfo<'info>,
#[account(mut)]
pub payer: Signer<'info>,
/// CHECK: Validated by light-token CPI
#[account(mut)]
pub associated_token_account: AccountInfo<'info>,
pub system_program: Program<'info, System>,
/// CHECK: Validated by light-token CPI
pub compressible_config: AccountInfo<'info>,
/// CHECK: Validated by light-token CPI
#[account(mut)]
pub rent_sponsor: AccountInfo<'info>,
}