-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlib.rs
More file actions
128 lines (118 loc) · 4.85 KB
/
lib.rs
File metadata and controls
128 lines (118 loc) · 4.85 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#![allow(unexpected_cfgs, deprecated)]
use anchor_lang::prelude::*;
use light_token::instruction::{
CreateMintCpi, CreateMintParams, SystemAccountInfos, DEFAULT_RENT_PAYMENT, DEFAULT_WRITE_TOP_UP,
};
use light_token::{CompressedProof, ExtensionInstructionData, TokenMetadataInstructionData};
declare_id!("A1rJEoepgKYWZYZ8KVFpxgeeRGwBrU7xk8S39srjVkUX");
/// Token metadata parameters for creating a mint with metadata.
#[derive(AnchorSerialize, AnchorDeserialize, Clone)]
pub struct TokenMetadataParams {
pub name: Vec<u8>,
pub symbol: Vec<u8>,
pub uri: Vec<u8>,
pub update_authority: Option<Pubkey>,
}
#[program]
pub mod light_token_anchor_create_mint {
use super::*;
pub fn create_mint(
ctx: Context<CreateMintAccounts>,
decimals: u8,
address_merkle_tree_root_index: u16,
compression_address: [u8; 32],
proof: CompressedProof,
freeze_authority: Option<Pubkey>,
bump: u8,
rent_payment: Option<u8>,
write_top_up: Option<u32>,
metadata: Option<TokenMetadataParams>,
) -> Result<()> {
let mint = light_token::instruction::find_mint_address(ctx.accounts.mint_seed.key).0;
let extensions = metadata.map(|m| {
vec![ExtensionInstructionData::TokenMetadata(
TokenMetadataInstructionData {
update_authority: m
.update_authority
.map(|p| p.to_bytes().into()),
name: m.name,
symbol: m.symbol,
uri: m.uri,
additional_metadata: None,
},
)]
});
let params = CreateMintParams {
decimals,
address_merkle_tree_root_index,
mint_authority: *ctx.accounts.authority.key,
proof,
compression_address,
mint,
bump,
freeze_authority,
extensions,
rent_payment: rent_payment.unwrap_or(DEFAULT_RENT_PAYMENT),
write_top_up: write_top_up.unwrap_or(DEFAULT_WRITE_TOP_UP),
};
let system_accounts = SystemAccountInfos {
light_system_program: ctx.accounts.light_system_program.to_account_info(),
cpi_authority_pda: ctx.accounts.cpi_authority_pda.to_account_info(),
registered_program_pda: ctx.accounts.registered_program_pda.to_account_info(),
account_compression_authority: ctx.accounts.account_compression_authority.to_account_info(),
account_compression_program: ctx.accounts.account_compression_program.to_account_info(),
system_program: ctx.accounts.system_program.to_account_info(),
};
CreateMintCpi {
mint_seed: ctx.accounts.mint_seed.to_account_info(),
authority: ctx.accounts.authority.to_account_info(),
payer: ctx.accounts.payer.to_account_info(),
address_tree: ctx.accounts.address_tree.to_account_info(),
output_queue: ctx.accounts.output_queue.to_account_info(),
compressible_config: ctx.accounts.compressible_config.to_account_info(),
mint: ctx.accounts.mint.to_account_info(),
rent_sponsor: ctx.accounts.rent_sponsor.to_account_info(),
system_accounts,
cpi_context: None,
cpi_context_account: None,
params,
}
.invoke()?;
Ok(())
}
}
#[derive(Accounts)]
pub struct CreateMintAccounts<'info> {
/// CHECK: Light token program for CPI
pub light_token_program: AccountInfo<'info>,
pub mint_seed: Signer<'info>,
/// CHECK: Validated by light-token CPI
pub authority: AccountInfo<'info>,
#[account(mut)]
pub payer: Signer<'info>,
/// CHECK: Validated by light-token CPI
#[account(mut)]
pub address_tree: AccountInfo<'info>,
/// CHECK: Validated by light-token CPI
#[account(mut)]
pub output_queue: AccountInfo<'info>,
/// CHECK: Validated by light-token CPI
pub light_system_program: AccountInfo<'info>,
/// CHECK: Validated by light-token CPI
pub cpi_authority_pda: AccountInfo<'info>,
/// CHECK: Validated by light-token CPI
pub registered_program_pda: AccountInfo<'info>,
/// CHECK: Validated by light-token CPI
pub account_compression_authority: AccountInfo<'info>,
/// CHECK: Validated by light-token CPI
pub account_compression_program: AccountInfo<'info>,
pub system_program: Program<'info, System>,
/// CHECK: Validated by light-token CPI - use light_token::token::config_pda()
pub compressible_config: AccountInfo<'info>,
/// CHECK: Validated by light-token CPI - derived from find_mint_address(mint_seed)
#[account(mut)]
pub mint: AccountInfo<'info>,
/// CHECK: Validated by light-token CPI - use light_token::token::rent_sponsor_pda()
#[account(mut)]
pub rent_sponsor: AccountInfo<'info>,
}