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
use anchor_lang::prelude::*;

pub mod errors;
pub mod instructions;
pub mod states;

use instructions::*;

declare_id!("7cJdKSjPtZqiGV4CFAGtbhhpf5CsYjbkbEkLKcXfHLYd");
hpl_macros::platform_gate!();

#[program]
pub mod hpl_asset_manager {
    use super::*;

    pub fn create_asset_manager(ctx: Context<CreateAssetManager>) -> Result<()> {
        hpl_macros::add_service!(hpl_hive_control::state::Service::AssetManager {
            asset_manager_id: ctx.accounts.asset_manager.key(),
        });

        instructions::create_asset_manager(ctx)
    }

    pub fn create_asset(
        ctx: Context<CreateAsset>,
        args: CreateAssetArgs,
        proof_index: u8,
    ) -> Result<()> {
        platform_gate_cpi(
            hpl_hive_control::state::SerializableActions::ManageAssets,
            Some((proof_index, ctx.accounts.asset_manager.key())),
            ctx.accounts.project.to_account_info(),
            ctx.accounts.authority.to_account_info(),
            ctx.accounts.payer.to_account_info(),
            ctx.accounts.vault.to_account_info(),
            &ctx.accounts.delegate_authority,
            ctx.accounts.system_program.to_account_info(),
            ctx.accounts.hive_control.to_account_info(),
            ctx.accounts.instructions_sysvar.to_account_info(),
        )?;

        instructions::create_asset(ctx, args)
    }

    pub fn mint_asset(ctx: Context<MintAsset>, amount: u64) -> Result<()> {
        platform_gate_cpi(
            hpl_hive_control::state::SerializableActions::PublicHigh,
            None,
            ctx.accounts.project.to_account_info(),
            ctx.accounts.wallet.to_account_info(),
            ctx.accounts.wallet.to_account_info(),
            ctx.accounts.vault.to_account_info(),
            &ctx.accounts.delegate_authority,
            ctx.accounts.system_program.to_account_info(),
            ctx.accounts.hive_control.to_account_info(),
            ctx.accounts.instructions_sysvar.to_account_info(),
        )?;

        instructions::mint_asset(ctx, amount)
    }
}