gpl_feature_proposal/
lib.rs

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