Skip to main content

spl_feature_proposal/
lib.rs

1//! Feature Proposal program
2#![deny(missing_docs)]
3#![forbid(unsafe_code)]
4
5pub mod borsh_utils;
6mod entrypoint;
7pub mod instruction;
8pub mod processor;
9pub mod state;
10
11// Export current SDK types for downstream users building with a different SDK version
12pub use solana_program;
13use solana_program::{program_pack::Pack, pubkey::Pubkey};
14
15solana_program::declare_id!("Feat1YXHhH6t1juaWF74WLcfv4XoNocjXA6sPWHNgAse");
16
17pub(crate) fn get_mint_address_with_seed(feature_proposal_address: &Pubkey) -> (Pubkey, u8) {
18    Pubkey::find_program_address(&[&feature_proposal_address.to_bytes(), br"mint"], &id())
19}
20
21pub(crate) fn get_distributor_token_address_with_seed(
22    feature_proposal_address: &Pubkey,
23) -> (Pubkey, u8) {
24    Pubkey::find_program_address(
25        &[&feature_proposal_address.to_bytes(), br"distributor"],
26        &id(),
27    )
28}
29
30pub(crate) fn get_acceptance_token_address_with_seed(
31    feature_proposal_address: &Pubkey,
32) -> (Pubkey, u8) {
33    Pubkey::find_program_address(
34        &[&feature_proposal_address.to_bytes(), br"acceptance"],
35        &id(),
36    )
37}
38
39pub(crate) fn get_feature_id_address_with_seed(feature_proposal_address: &Pubkey) -> (Pubkey, u8) {
40    Pubkey::find_program_address(
41        &[&feature_proposal_address.to_bytes(), br"feature-id"],
42        &id(),
43    )
44}
45
46/// Derive the SPL Token mint address associated with a feature proposal
47pub fn get_mint_address(feature_proposal_address: &Pubkey) -> Pubkey {
48    get_mint_address_with_seed(feature_proposal_address).0
49}
50
51/// Derive the SPL Token token address associated with a feature proposal that receives the initial
52/// minted tokens
53pub fn get_distributor_token_address(feature_proposal_address: &Pubkey) -> Pubkey {
54    get_distributor_token_address_with_seed(feature_proposal_address).0
55}
56
57/// Derive the SPL Token token address associated with a feature proposal that users send their
58/// tokens to accept the proposal
59pub fn get_acceptance_token_address(feature_proposal_address: &Pubkey) -> Pubkey {
60    get_acceptance_token_address_with_seed(feature_proposal_address).0
61}
62
63/// Derive the feature id address associated with the feature proposal
64pub fn get_feature_id_address(feature_proposal_address: &Pubkey) -> Pubkey {
65    get_feature_id_address_with_seed(feature_proposal_address).0
66}
67
68/// Convert the UI representation of a token amount (using the decimals field defined in its mint)
69/// to the raw amount
70pub fn ui_amount_to_amount(ui_amount: f64) -> u64 {
71    (ui_amount * 10_usize.pow(spl_token::native_mint::DECIMALS as u32) as f64) as u64
72}
73
74/// Convert a raw amount to its UI representation (using the decimals field defined in its mint)
75pub fn amount_to_ui_amount(amount: u64) -> f64 {
76    amount as f64 / 10_usize.pow(spl_token::native_mint::DECIMALS as u32) as f64
77}