#account #solana #order #shank #idl #annotate #extract

macro shank_macro

Provides macros used to annotate Solana Rust programs in order to extract an IDL with the shank CLI

22 releases (4 breaking)

0.4.2 Feb 29, 2024
0.3.1-alpha.5 Jan 30, 2024
0.3.0 Oct 31, 2023
0.2.1 Jul 29, 2023
0.0.1 Mar 22, 2022

#7 in #annotate

Download history 11547/week @ 2024-07-21 11428/week @ 2024-07-28 11091/week @ 2024-08-04 10457/week @ 2024-08-11 9146/week @ 2024-08-18 10883/week @ 2024-08-25 9240/week @ 2024-09-01 8896/week @ 2024-09-08 5441/week @ 2024-09-15 7736/week @ 2024-09-22 8085/week @ 2024-09-29 8158/week @ 2024-10-06 10256/week @ 2024-10-13 10941/week @ 2024-10-20 13087/week @ 2024-10-27 11958/week @ 2024-11-03

46,879 downloads per month
Used in 139 crates (via shank)

Apache-2.0

275KB
7K SLoC

shank_macro

Provides macros used to annotate Solana Rust programs in order to extract an IDL with the shank CLI.

ShankAccount

Annotates a struct that shank will consider an account containing de/serializable data.

use shank::ShankAccount;
use borsh::{BorshDeserialize, BorshSerialize};

#[derive(Clone, BorshSerialize, BorshDeserialize, ShankAccount)]
pub struct Metadata {
    pub update_authority: Pubkey,
    pub mint: Pubkey,
    pub primary_sale_happened: bool,
}

Note

The fields of a ShankAccount struct can reference other types as long as they are annotated with BorshSerialize or BorshDeserialize.

ShankInstruction

Annotates the program Instruction Enum in order to include #[account] attributes.

The #[account] attributes indicate for each instruction variant which accounts it expects and how they should be configured.

#[account] attribute

This attribute allows you to configure each account that is provided to the particular instruction. These annotations need to follow the order in which the accounts are provided. They take the following general form:

#[account(index?, (writable|signer)?, name="<account_name>", desc?="optional description")]
  • index: optionally provides the account index in the provided accounts array which needs to match its position of #[account] attributes
  • signer | sign | sig: indicates that the account is signer
  • writable | write | writ | mut: indicates that the account is writable which means it may be mutated as part of processing the particular instruction
  • name: (required) provides the name for the account
  • desc | description: allows to provide a description of the account

Known Accounts

If an account name matches either of the a known accounts indicated below then solita generated SDK code won't require providing it as the program id is known.

  • token_program uses TOKEN_PROGRAM_ID
  • ata_program uses ASSOCIATED_TOKEN_PROGRAM_ID
  • system_program uses SystemProgram.programId
  • rent uses SYSVAR_RENT_PUBKEY
use borsh::{BorshDeserialize, BorshSerialize};
use shank::ShankInstruction;
#[derive(Debug, Clone, ShankInstruction, BorshSerialize, BorshDeserialize)]
#[rustfmt::skip]
pub enum VaultInstruction {
    /// Initialize a token vault, starts inactivate. Add tokens in subsequent instructions, then activate.
    #[account(0, writable, name="fraction_mint",
              desc="Initialized fractional share mint with 0 tokens in supply, authority on mint must be pda of program with seed [prefix, programid]")]
    #[account(1, writable, name="redeem_treasury",
            desc = "Initialized redeem treasury token account with 0 tokens in supply, owner of account must be pda of program like above")]
    #[account(2, writable, name="fraction_treasury",
            desc = "Initialized fraction treasury token account with 0 tokens in supply, owner of account must be pda of program like above")]
    #[account(3, writable, name="vault",
            desc = "Uninitialized vault account")]
    #[account(4, name="authority",
            desc = "Authority on the vault")]
    #[account(5, name="pricing_lookup_address",
            desc = "Pricing Lookup Address")]
    #[account(6, name="token_program",
            desc = "Token program")]
    #[account(7, name="rent",
            desc = "Rent sysvar")]
    InitVault(InitVaultArgs),

    /// Activates the vault, distributing initial shares into the fraction treasury.
    /// Tokens can no longer be removed in this state until Combination.
    #[account(0, writable, name="vault", desc = "Initialized inactivated fractionalized token vault")]
    #[account(1, writable, name="fraction_mint", desc = "Fraction mint")]
    #[account(2, writable, name="fraction_treasury", desc = "Fraction treasury")]
    #[account(3, name="fraction_mint_authority", desc = "Fraction mint authority for the program - seed of [PREFIX, program_id]")]
    #[account(4, signer, name="vault_authority", desc = "Authority on the vault")]
    #[account(5, name="token_program", desc = "Token program")]
    ActivateVault(NumberOfShareArgs)
}

LICENSE

Apache-2.0

Dependencies

~0.5–1MB
~24K SLoC