Skip to content

Commit

Permalink
feat(sdk-rs): add pda module
Browse files Browse the repository at this point in the history
  • Loading branch information
vovacodes committed Sep 11, 2023
1 parent e5dfcee commit b06e6b1
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "squads-multisig"
version = "0.0.4"
version = "0.0.5"
description = "An SDK for building automated programs on Solana"
edition = "2021"
license = "AGPL-3.0-or-later"
Expand Down
2 changes: 2 additions & 0 deletions sdk/rs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pub mod pda;

// Re-export dependencies for convenience
pub use solana_client;

Expand Down
76 changes: 76 additions & 0 deletions sdk/rs/src/pda.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
use crate::solana_program::pubkey::Pubkey;
use squads_multisig_program::{
SEED_MULTISIG, SEED_PREFIX, SEED_PROPOSAL, SEED_SPENDING_LIMIT, SEED_TRANSACTION, SEED_VAULT,
};

pub fn get_multisig_pda(create_key: &Pubkey, program_id: Option<&Pubkey>) -> (Pubkey, u8) {
Pubkey::find_program_address(
&[SEED_PREFIX, SEED_MULTISIG, create_key.to_bytes().as_ref()],
program_id.unwrap_or(&squads_multisig_program::ID),
)
}

pub fn get_vault_pda(
multisig_pda: &Pubkey,
index: u8,
program_id: Option<&Pubkey>,
) -> (Pubkey, u8) {
Pubkey::find_program_address(
&[
SEED_PREFIX,
multisig_pda.to_bytes().as_ref(),
SEED_VAULT,
&[index],
],
program_id.unwrap_or(&squads_multisig_program::ID),
)
}

pub fn get_transaction_pda(
multisig_pda: &Pubkey,
index: u8,
program_id: Option<&Pubkey>,
) -> (Pubkey, u8) {
Pubkey::find_program_address(
&[
SEED_PREFIX,
multisig_pda.to_bytes().as_ref(),
SEED_TRANSACTION,
&[index],
],
program_id.unwrap_or(&squads_multisig_program::ID),
)
}

pub fn get_proposal_pda(
multisig_pda: &Pubkey,
transaction_index: u64,
program_id: Option<&Pubkey>,
) -> (Pubkey, u8) {
Pubkey::find_program_address(
&[
SEED_PREFIX,
multisig_pda.to_bytes().as_ref(),
SEED_TRANSACTION,
&transaction_index.to_le_bytes(),
SEED_PROPOSAL,
],
program_id.unwrap_or(&squads_multisig_program::ID),
)
}

pub fn get_spending_limit_pda(
multisig_pda: &Pubkey,
create_key: &Pubkey,
program_id: Option<&Pubkey>,
) -> (Pubkey, u8) {
Pubkey::find_program_address(
&[
SEED_PREFIX,
multisig_pda.to_bytes().as_ref(),
SEED_SPENDING_LIMIT,
create_key.to_bytes().as_ref(),
],
program_id.unwrap_or(&squads_multisig_program::ID),
)
}

0 comments on commit b06e6b1

Please sign in to comment.