light_token_interface/instructions/mint_action/
builder.rs1use light_compressed_account::instruction_data::{
2 compressed_proof::CompressedProof,
3 traits::{InstructionDiscriminator, LightInstructionData},
4};
5
6use crate::instructions::mint_action::{
7 Action, CompressAndCloseMintAction, CpiContext, CreateMint, DecompressMintAction,
8 MintActionCompressedInstructionData, MintInstructionData, MintToAction, MintToCompressedAction,
9 MintWithContext, RemoveMetadataKeyAction, UpdateAuthority, UpdateMetadataAuthorityAction,
10 UpdateMetadataFieldAction,
11};
12
13pub const MINT_ACTION_DISCRIMINATOR: u8 = 103;
15
16impl InstructionDiscriminator for MintActionCompressedInstructionData {
17 fn discriminator(&self) -> &'static [u8] {
18 &[MINT_ACTION_DISCRIMINATOR]
19 }
20}
21
22impl LightInstructionData for MintActionCompressedInstructionData {}
23
24impl MintActionCompressedInstructionData {
25 pub fn new(mint_with_context: MintWithContext, proof: Option<CompressedProof>) -> Self {
27 Self {
28 leaf_index: mint_with_context.leaf_index,
29 prove_by_index: mint_with_context.prove_by_index,
30 root_index: mint_with_context.root_index,
31 max_top_up: 0, create_mint: None,
33 actions: Vec::new(),
34 proof,
35 cpi_context: None,
36 mint: mint_with_context.mint,
37 }
38 }
39
40 pub fn new_mint(
42 address_merkle_tree_root_index: u16,
43 proof: CompressedProof,
44 mint: MintInstructionData,
45 ) -> Self {
46 Self {
47 leaf_index: 0, prove_by_index: false, root_index: address_merkle_tree_root_index,
50 max_top_up: 0, create_mint: Some(CreateMint::default()),
52 actions: Vec::new(),
53 proof: Some(proof),
54 cpi_context: None,
55 mint: Some(mint),
56 }
57 }
58
59 pub fn new_mint_write_to_cpi_context(
61 address_merkle_tree_root_index: u16,
62 mint: MintInstructionData,
63 cpi_context: CpiContext,
64 ) -> Self {
65 Self {
66 leaf_index: 0, prove_by_index: false, root_index: address_merkle_tree_root_index,
69 max_top_up: 0, create_mint: Some(CreateMint::default()),
71 actions: Vec::new(),
72 proof: None, cpi_context: Some(cpi_context),
74 mint: Some(mint),
75 }
76 }
77
78 #[must_use = "with_mint_to_compressed returns a new value"]
79 pub fn with_mint_to_compressed(mut self, action: MintToCompressedAction) -> Self {
80 self.actions.push(Action::MintToCompressed(action));
81 self
82 }
83
84 #[must_use = "with_mint_to returns a new value"]
85 pub fn with_mint_to(mut self, action: MintToAction) -> Self {
86 self.actions.push(Action::MintTo(action));
87 self
88 }
89
90 #[must_use = "with_update_mint_authority returns a new value"]
91 pub fn with_update_mint_authority(mut self, authority: UpdateAuthority) -> Self {
92 self.actions.push(Action::UpdateMintAuthority(authority));
93 self
94 }
95
96 #[must_use = "with_update_freeze_authority returns a new value"]
97 pub fn with_update_freeze_authority(mut self, authority: UpdateAuthority) -> Self {
98 self.actions.push(Action::UpdateFreezeAuthority(authority));
99 self
100 }
101
102 #[must_use = "with_update_metadata_field returns a new value"]
103 pub fn with_update_metadata_field(mut self, action: UpdateMetadataFieldAction) -> Self {
104 self.actions.push(Action::UpdateMetadataField(action));
105 self
106 }
107
108 #[must_use = "with_update_metadata_authority returns a new value"]
109 pub fn with_update_metadata_authority(mut self, action: UpdateMetadataAuthorityAction) -> Self {
110 self.actions.push(Action::UpdateMetadataAuthority(action));
111 self
112 }
113
114 #[must_use = "with_remove_metadata_key returns a new value"]
115 pub fn with_remove_metadata_key(mut self, action: RemoveMetadataKeyAction) -> Self {
116 self.actions.push(Action::RemoveMetadataKey(action));
117 self
118 }
119
120 #[must_use = "with_decompress_mint returns a new value"]
121 pub fn with_decompress_mint(mut self, action: DecompressMintAction) -> Self {
122 self.actions.push(Action::DecompressMint(action));
123 self
124 }
125
126 #[must_use = "with_compress_and_close_mint returns a new value"]
127 pub fn with_compress_and_close_mint(mut self, action: CompressAndCloseMintAction) -> Self {
128 self.actions.push(Action::CompressAndCloseMint(action));
129 self
130 }
131
132 #[must_use = "with_cpi_context returns a new value"]
133 pub fn with_cpi_context(mut self, cpi_context: CpiContext) -> Self {
134 self.cpi_context = Some(cpi_context);
135 self
136 }
137
138 #[must_use = "with_max_top_up returns a new value"]
139 pub fn with_max_top_up(mut self, max_top_up: u16) -> Self {
140 self.max_top_up = max_top_up;
141 self
142 }
143
144 #[must_use = "write_to_cpi_context_first returns a new value"]
145 pub fn write_to_cpi_context_first(mut self) -> Self {
146 if let Some(ref mut ctx) = self.cpi_context {
147 ctx.first_set_context = true;
148 ctx.set_context = false;
149 } else {
150 self.cpi_context = Some(CpiContext {
151 first_set_context: true,
152 ..Default::default()
153 });
154 }
155 self
156 }
157
158 #[must_use = "write_to_cpi_context_set returns a new value"]
159 pub fn write_to_cpi_context_set(mut self) -> Self {
160 if let Some(ref mut ctx) = self.cpi_context {
161 ctx.set_context = true;
162 ctx.first_set_context = false;
163 } else {
164 self.cpi_context = Some(CpiContext {
165 set_context: true,
166 ..Default::default()
167 });
168 }
169 self
170 }
171}