Created
May 28, 2021 10:49
-
-
Save petscheit/46552eda8ebd6bfb3f8535d5ba3ca3ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use anchor_lang::prelude::*; | |
// use borsh::{BorshDeserialize, BorshSerialize}; | |
#[program] | |
pub mod drop { | |
use super::*; | |
pub fn initialize_mint(ctx: Context<CreateMint>, supply: u64, decimals: u8, authority: Pubkey) -> ProgramResult { | |
let mint = &mut ctx.accounts.mint; | |
mint.supply = supply; | |
mint.decimals = decimals; | |
mint.mint_authority = Some(authority); | |
mint.freeze_authority = Some(authority); | |
mint.is_initialized = true; | |
Ok(()) | |
} | |
pub fn create_account(ctx: Context<CreateAccount>) -> ProgramResult { | |
let account = &mut ctx.accounts.account; | |
account.amount = 0; | |
account.owner = *ctx.accounts.owner.key; | |
account.mint = *ctx.accounts.mint.to_account_info().key; | |
// account.state = AccountState::Initialized; | |
account.delegated_amount = 0; | |
Ok(()) | |
} | |
} | |
#[derive(Accounts)] | |
pub struct CreateMint<'info> { | |
#[account(init)] | |
mint: ProgramAccount<'info, Mint>, | |
rent: Sysvar<'info, Rent>, | |
} | |
#[account] | |
pub struct Mint { | |
/// Optional authority used to mint new tokens. The mint authority may only be provided during | |
/// mint creation. If no mint authority is present then the mint has a fixed supply and no | |
/// further tokens may be minted. | |
pub mint_authority: Option<Pubkey>, | |
/// Total supply of tokens. | |
pub supply: u64, | |
/// Number of base 10 digits to the right of the decimal place. | |
pub decimals: u8, | |
/// Is `true` if this structure has been initialized | |
pub is_initialized: bool, | |
/// Optional authority to freeze token accounts. | |
pub freeze_authority: Option<Pubkey>, | |
} | |
#[derive(Accounts)] | |
pub struct CreateAccount<'info> { | |
#[account(init, associated = owner, with = mint)] | |
account: ProgramAccount<'info, Account>, | |
mint: ProgramAccount<'info, Mint>, | |
owner: AccountInfo<'info>, | |
rent: Sysvar<'info, Rent>, | |
system_program: AccountInfo<'info>, | |
} | |
#[associated] | |
pub struct Account { | |
/// The mint associated with this account | |
pub mint: Pubkey, | |
/// The owner of this account. | |
pub owner: Pubkey, | |
/// The amount of tokens this account holds. | |
pub amount: u64, | |
/// If `delegate` is `Some` then `delegated_amount` represents | |
/// the amount authorized by the delegate | |
pub delegate: Option<Pubkey>, | |
/// The account's state | |
// pub state: AccountState, | |
/// If is_some, this is a native token, and the value logs the rent-exempt reserve. An Account | |
/// is required to be rent-exempt, so the value is used by the Processor to ensure that wrapped | |
/// SOL accounts do not drop below this threshold. | |
pub is_native: Option<u64>, | |
/// The amount delegated | |
pub delegated_amount: u64, | |
/// Optional authority to close the account. | |
pub close_authority: Option<Pubkey>, | |
} | |
// #endregion code | |
// #[repr(u8)] | |
// #[derive(Clone, Copy, Debug, PartialEq, BorshSerialize, BorshDeserialize)] | |
// pub enum AccountState { | |
// /// Account is not yet initialized | |
// Uninitialized, | |
// /// Account is initialized; the account owner and/or delegate may perform permitted operations | |
// /// on this account | |
// Initialized, | |
// /// Account has been frozen by the mint freeze authority. Neither the account owner nor | |
// /// the delegate are able to perform operations on this account. | |
// Frozen, | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment