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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
use {
crate::state::{Assembler, AssemblingAction, Creator, TokenStandard},
anchor_lang::{prelude::*, solana_program},
anchor_spl::token::{self, Mint, Token},
hpl_hive_control::{
program::HplHiveControl,
state::{DelegateAuthority, Project},
},
hpl_utils::create_nft,
mpl_token_metadata::state::AssetData,
};
#[derive(Accounts)]
pub struct CreateAssembler<'info> {
#[account(
init,
payer = payer,
mint::decimals = 0,
mint::authority = assembler,
mint::freeze_authority = assembler,
)]
pub collection_mint: Account<'info, Mint>,
#[account(mut)]
pub collection_metadata: AccountInfo<'info>,
#[account(mut)]
pub collection_master_edition: AccountInfo<'info>,
#[account(
init, payer = payer,
space = Assembler::LEN ,
seeds = [
b"assembler".as_ref(),
collection_mint.key().as_ref(),
],
bump,
)]
pub assembler: Account<'info, Assembler>,
pub authority: AccountInfo<'info>,
#[account(mut)]
pub payer: Signer<'info>,
pub system_program: Program<'info, System>,
#[account(address = token::ID)]
pub token_program: Program<'info, Token>,
pub token_metadata_program: AccountInfo<'info>,
pub rent: Sysvar<'info, Rent>,
#[account(address = solana_program::sysvar::instructions::ID)]
pub sysvar_instructions: AccountInfo<'info>,
#[account(mut)]
pub project: Box<Account<'info, Project>>,
#[account(has_one = authority)]
pub delegate_authority: Option<Account<'info, DelegateAuthority>>,
#[account(mut)]
pub vault: AccountInfo<'info>,
pub hive_control: Program<'info, HplHiveControl>,
}
#[derive(AnchorSerialize, AnchorDeserialize, Clone)]
pub struct CreateAssemblerArgs {
assembling_action: AssemblingAction,
collection_name: String,
collection_symbol: String,
collection_uri: String,
collection_description: String,
nft_base_uri: String,
allow_duplicates: Option<bool>,
default_royalty: Option<u16>,
token_standard: Option<TokenStandard>,
rule_set: Option<Pubkey>,
default_creators: Vec<Creator>,
}
pub fn create_assembler(ctx: Context<CreateAssembler>, args: CreateAssemblerArgs) -> Result<()> {
let assembler = &mut ctx.accounts.assembler;
assembler.bump = ctx.bumps["assembler"];
assembler.project = ctx.accounts.project.key();
assembler.collection = ctx.accounts.collection_mint.key();
assembler.collection_name = args.collection_name;
assembler.collection_symbol = args.collection_symbol;
assembler.collection_description = args.collection_description;
assembler.nft_base_uri = args.nft_base_uri;
assembler.assembling_action = args.assembling_action;
assembler.nfts = 0;
assembler.allow_duplicates = args.allow_duplicates.unwrap_or(false);
assembler.default_royalty = args.default_royalty.unwrap_or(0);
assembler.token_standard = args
.token_standard
.unwrap_or(crate::state::TokenStandard::NonFungible);
assembler.rule_set = args.rule_set;
assembler.default_creators = args.default_creators;
let assembler_seeds = &[
b"assembler".as_ref(),
assembler.collection.as_ref(),
&[assembler.bump],
];
let assembler_signer = &[&assembler_seeds[..]];
create_nft(
AssetData {
name: assembler.collection_name.clone(),
symbol: assembler.collection_symbol.clone(),
uri: args.collection_uri,
seller_fee_basis_points: assembler.default_royalty,
creators: Some(
[
vec![mpl_token_metadata::state::Creator {
address: assembler.key(),
verified: true,
share: 0,
}],
assembler
.default_creators
.clone()
.iter()
.map(|c| mpl_token_metadata::state::Creator {
address: c.address,
verified: false,
share: c.share,
})
.collect(),
]
.concat(),
),
primary_sale_happened: false,
is_mutable: true,
token_standard: mpl_token_metadata::state::TokenStandard::NonFungible,
collection: None,
uses: None,
collection_details: None,
rule_set: assembler.rule_set,
},
false,
true,
ctx.accounts.collection_metadata.to_account_info(),
ctx.accounts.collection_master_edition.to_account_info(),
ctx.accounts.collection_mint.to_account_info(),
assembler.to_account_info(),
ctx.accounts.payer.to_account_info(),
assembler.to_account_info(),
ctx.accounts.system_program.to_account_info(),
ctx.accounts.sysvar_instructions.to_account_info(),
ctx.accounts.token_program.to_account_info(),
Some(assembler_signer),
)?;
Ok(())
}
#[derive(Accounts)]
pub struct UpdateAssembler<'info> {
#[account(mut, has_one = project)]
pub assembler: Account<'info, Assembler>,
pub authority: Signer<'info>,
pub payer: Signer<'info>,
pub system_program: Program<'info, System>,
#[account()]
pub project: Box<Account<'info, Project>>,
#[account(has_one = authority)]
pub delegate_authority: Option<Account<'info, DelegateAuthority>>,
#[account(mut)]
pub vault: AccountInfo<'info>,
}
#[derive(AnchorSerialize, AnchorDeserialize, Clone)]
pub struct UpdateAssemblerArgs {
assembling_action: AssemblingAction,
nft_base_uri: String,
allow_duplicates: Option<bool>,
default_royalty: Option<u16>,
}
pub fn update_assembler(ctx: Context<UpdateAssembler>, args: UpdateAssemblerArgs) -> Result<()> {
let assembler = &mut ctx.accounts.assembler;
assembler.nft_base_uri = args.nft_base_uri;
assembler.assembling_action = args.assembling_action;
assembler.allow_duplicates = args.allow_duplicates.unwrap_or(assembler.allow_duplicates);
assembler.default_royalty = args.default_royalty.unwrap_or(assembler.default_royalty);
Ok(())
}