pub mod assertions;
pub mod constants;
pub mod errors;
pub mod instructions;
pub mod state;
use {anchor_lang::prelude::*, instructions::*, state::ProfileIdentity};
declare_id!("HiveXxaWodSx7aQgKuEyhv6QnWgx4BN4Vc1ZCoFGHV6B");
#[program]
pub mod hpl_hive_control {
use super::*;
pub fn init_public_info(ctx: Context<InitPublicInfo>, env: String) -> Result<()> {
assertions::assert_program_authority(
ctx.accounts.program.to_account_info(),
ctx.accounts.program_data.to_account_info(),
ctx.accounts.authority.key,
)?;
instructions::init_public_info(ctx, env)
}
pub fn set_public_info(
ctx: Context<SetPublicInfo>,
env: String,
args: SetPublicInfoArgs,
) -> Result<()> {
assertions::assert_program_authority(
ctx.accounts.program.to_account_info(),
ctx.accounts.program_data.to_account_info(),
ctx.accounts.authority.key,
)?;
instructions::set_public_info(ctx, env, args)
}
pub fn set_auth_driver(
ctx: Context<SetAuthDriver>,
env: String,
args: SetAuthDriverArgs,
) -> Result<()> {
assertions::assert_program_authority(
ctx.accounts.program.to_account_info(),
ctx.accounts.program_data.to_account_info(),
ctx.accounts.authority.key,
)?;
instructions::set_auth_driver(ctx, env, args)
}
pub fn create_project(ctx: Context<CreateProject>, args: CreateProjectArgs) -> Result<()> {
instructions::platform_gate_fn(
constants::ACTIONS.project_create,
None,
&ctx.accounts.project,
ctx.accounts.authority.key(),
ctx.accounts.payer.to_account_info(),
ctx.accounts.vault.to_account_info(),
&None,
ctx.accounts.system_program.to_account_info(),
)?;
instructions::create_project(ctx, args)
}
pub fn change_driver(ctx: Context<ChangeDriver>) -> Result<()> {
instructions::platform_gate_fn(
constants::ACTIONS.manage_delegate_authority,
None,
&ctx.accounts.project,
ctx.accounts.authority.key(),
ctx.accounts.payer.to_account_info(),
ctx.accounts.vault.to_account_info(),
&ctx.accounts.delegate_authority,
ctx.accounts.system_program.to_account_info(),
)?;
instructions::change_driver(ctx)
}
pub fn add_remove_criteria(
ctx: Context<AddRemoveCriteria>,
args: AddRemoveCriteriaArgs,
) -> Result<()> {
instructions::platform_gate_fn(
constants::ACTIONS.manage_criterias,
None,
&ctx.accounts.project,
ctx.accounts.authority.key(),
ctx.accounts.payer.to_account_info(),
ctx.accounts.vault.to_account_info(),
&ctx.accounts.delegate_authority,
ctx.accounts.system_program.to_account_info(),
)?;
instructions::add_remove_criteria(ctx, args)
}
pub fn add_remove_service(
ctx: Context<AddRemoveService>,
args: AddRemoveServiceArgs,
) -> Result<()> {
instructions::platform_gate_fn(
if args.remove.unwrap_or(false) {
constants::ACTIONS.remove_service
} else {
constants::ACTIONS.add_service
},
None,
&ctx.accounts.project,
ctx.accounts.authority.key(),
ctx.accounts.payer.to_account_info(),
ctx.accounts.vault.to_account_info(),
&ctx.accounts.delegate_authority,
ctx.accounts.system_program.to_account_info(),
)?;
instructions::add_remove_service(ctx, args)
}
pub fn add_remove_profile_data_config(
ctx: Context<AddRemoveProfileDataConfig>,
args: AddRemoveProfileDataConfigArgs,
) -> Result<()> {
instructions::platform_gate_fn(
constants::ACTIONS.manage_profiles,
None,
&ctx.accounts.project,
ctx.accounts.authority.key(),
ctx.accounts.payer.to_account_info(),
ctx.accounts.vault.to_account_info(),
&ctx.accounts.delegate_authority,
ctx.accounts.system_program.to_account_info(),
)?;
instructions::add_remove_profile_data_config(ctx, args)
}
pub fn add_address_container_to_project(
ctx: Context<AddAddressContainerToProject>,
args: AddAddressContainerToProjectArgs,
) -> Result<()> {
instructions::platform_gate_fn(
constants::ACTIONS.manage_indexing,
None,
&ctx.accounts.project,
ctx.accounts.authority.key(),
ctx.accounts.payer.to_account_info(),
ctx.accounts.vault.to_account_info(),
&ctx.accounts.delegate_authority,
ctx.accounts.system_program.to_account_info(),
)?;
instructions::add_address_container_to_project(ctx, args)
}
pub fn add_mint_addresses_to_address_container(
ctx: Context<AddMintAddressesToAddressContainer>,
args: AddMintAddressesToAddressContainerArgs,
) -> Result<()> {
instructions::add_mint_addresses_to_address_container(ctx, args)
}
pub fn create_delegate_authority(
ctx: Context<CreateDelegateAuthority>,
args: CreateDelegateAuthorityArgs,
) -> Result<()> {
instructions::platform_gate_fn(
constants::ACTIONS.manage_delegate_authority,
None,
&ctx.accounts.project,
ctx.accounts.authority.key(),
ctx.accounts.payer.to_account_info(),
ctx.accounts.vault.to_account_info(),
&None,
ctx.accounts.system_program.to_account_info(),
)?;
instructions::create_delegate_authority(ctx, args)
}
pub fn add_remove_delegation(
ctx: Context<ModifyDelegate>,
args: AddRemoveDelegationArgs,
) -> Result<()> {
instructions::platform_gate_fn(
constants::ACTIONS.manage_delegate_authority,
None,
&ctx.accounts.project,
ctx.accounts.authority.key(),
ctx.accounts.payer.to_account_info(),
ctx.accounts.vault.to_account_info(),
&None,
ctx.accounts.system_program.to_account_info(),
)?;
instructions::add_remove_delegation(ctx, args)
}
pub fn initialize_user(ctx: Context<InitializeUser>, args: InitializeUserArgs) -> Result<()> {
instructions::initialize_user(ctx, args)
}
pub fn close_user(ctx: Context<CloseUser>) -> Result<()> {
instructions::close_user(ctx)
}
pub fn update_user(ctx: Context<UpdateUser>, env: String, args: UpdateUserArgs) -> Result<()> {
let assert_user = assertions::assert_user(&ctx.accounts.user, ctx.accounts.authority.key());
if assert_user.is_err() {
assertions::assert_auth_driver(&ctx.accounts.public_info, &ctx.accounts.authority)?;
}
instructions::update_user(ctx, env, args)
}
pub fn add_wallet(ctx: Context<AddWallet>, env: String) -> Result<()> {
let assert_user = assertions::assert_user(&ctx.accounts.user, ctx.accounts.authority.key());
if assert_user.is_err() {
assertions::assert_auth_driver(&ctx.accounts.public_info, &ctx.accounts.authority)?;
}
instructions::add_wallet(ctx, env)
}
pub fn delete_wallet(ctx: Context<DeleteWallet>, env: String) -> Result<()> {
let assert_user = assertions::assert_user(&ctx.accounts.user, ctx.accounts.authority.key());
if assert_user.is_err() {
assertions::assert_auth_driver(&ctx.accounts.public_info, &ctx.accounts.authority)?;
}
instructions::delete_wallet(ctx, env)
}
pub fn create_profile(ctx: Context<CreateProfile>, args: CreateProfileArgs) -> Result<()> {
instructions::platform_gate_fn(
constants::ACTIONS.public_low,
None,
&ctx.accounts.project,
ctx.accounts.wallet.key(),
ctx.accounts.wallet.to_account_info(),
ctx.accounts.vault.to_account_info(),
&None,
ctx.accounts.system_program.to_account_info(),
)?;
instructions::create_profile(ctx, args)
}
pub fn delete_profile(ctx: Context<DeleteProfile>) -> Result<()> {
instructions::platform_gate_fn(
constants::ACTIONS.public_low,
None,
&ctx.accounts.project,
ctx.accounts.wallet.key(),
ctx.accounts.wallet.to_account_info(),
ctx.accounts.vault.to_account_info(),
&None,
ctx.accounts.system_program.to_account_info(),
)?;
instructions::delete_profile(ctx)
}
pub fn add_profile_data(
ctx: Context<ManageProfileData>,
args: AddProfileDataArgs,
) -> Result<()> {
let ix_program_key =
anchor_lang::solana_program::sysvar::instructions::get_instruction_relative(
0,
&ctx.accounts.instructions_sysvar,
)
.unwrap()
.program_id;
if !(!ix_program_key.eq(&ID)
&& ctx.accounts.profile.identity
== ProfileIdentity::Wallet {
key: ctx.accounts.authority.key(),
})
{
if args.value.is_some() {
let known_programs_vec = constants::known_programs();
let found = known_programs_vec
.iter()
.find(|p| p.key().eq(&ix_program_key));
if found.is_none() {
return Err(errors::ErrorCode::Unauthorized.into());
}
}
} else {
instructions::platform_gate_fn(
constants::ACTIONS.driver_action,
Some((0, Pubkey::default())),
&ctx.accounts.project,
ctx.accounts.authority.key(),
ctx.accounts.payer.to_account_info(),
ctx.accounts.vault.to_account_info(),
&ctx.accounts.delegate_authority,
ctx.accounts.system_program.to_account_info(),
)?;
}
instructions::add_profile_data(ctx, args)
}
pub fn modify_profile_data(
ctx: Context<ManageProfileData>,
args: ModifyProfileDataArgs,
) -> Result<()> {
let ix_program_key =
anchor_lang::solana_program::sysvar::instructions::get_instruction_relative(
0,
&ctx.accounts.instructions_sysvar,
)
.unwrap()
.program_id;
if !(!ix_program_key.eq(&ID)
&& ctx.accounts.profile.identity
== ProfileIdentity::Wallet {
key: ctx.accounts.authority.key(),
})
{
let known_programs_vec = constants::known_programs();
let found = known_programs_vec
.iter()
.find(|p| p.key().eq(&ix_program_key));
if found.is_none() {
return Err(errors::ErrorCode::Unauthorized.into());
}
} else {
instructions::platform_gate_fn(
constants::ACTIONS.driver_action,
Some((0, Pubkey::default())),
&ctx.accounts.project,
ctx.accounts.authority.key(),
ctx.accounts.payer.to_account_info(),
ctx.accounts.vault.to_account_info(),
&ctx.accounts.delegate_authority,
ctx.accounts.system_program.to_account_info(),
)?;
}
instructions::modify_profile_data(ctx, args)
}
pub fn remove_profile_data(
ctx: Context<ManageProfileData>,
args: RemoveProfileDataArgs,
) -> Result<()> {
let ix_program_key =
anchor_lang::solana_program::sysvar::instructions::get_instruction_relative(
0,
&ctx.accounts.instructions_sysvar,
)
.unwrap()
.program_id;
if !(!ix_program_key.eq(&ID)
&& ctx.accounts.profile.identity
== ProfileIdentity::Wallet {
key: ctx.accounts.authority.key(),
})
{
let known_programs_vec = constants::known_programs();
let found = known_programs_vec
.iter()
.find(|p| p.key().eq(&ix_program_key));
if found.is_none() {
return Err(errors::ErrorCode::Unauthorized.into());
}
} else {
instructions::platform_gate_fn(
constants::ACTIONS.driver_action,
Some((0, Pubkey::default())),
&ctx.accounts.project,
ctx.accounts.authority.key(),
ctx.accounts.payer.to_account_info(),
ctx.accounts.vault.to_account_info(),
&ctx.accounts.delegate_authority,
ctx.accounts.system_program.to_account_info(),
)?;
}
instructions::remove_profile_data(ctx, args)
}
pub fn verify_profile_entity_data(
ctx: Context<ManageProfileData>,
args: VerifyProfileEntityDataArgs,
) -> Result<()> {
instructions::platform_gate_fn(
constants::ACTIONS.public_high,
None,
&ctx.accounts.project,
ctx.accounts.authority.key(),
ctx.accounts.payer.to_account_info(),
ctx.accounts.vault.to_account_info(),
&ctx.accounts.delegate_authority,
ctx.accounts.system_program.to_account_info(),
)?;
instructions::verify_profile_entity_data(ctx, args)
}
}