-
Notifications
You must be signed in to change notification settings - Fork 95
feat(displays): commands to display vault and config transactions #181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ded2b52
feat(displays): commands to display vault and config transactions
sean-sqds 47d2488
feat(display): change command names
sean-sqds a33a5c2
feat(docs): update readme for new commands
sean-sqds caffaa6
feat(semver): version bump
sean-sqds 2e3bf3b
feat(display): show missing account data message
sean-sqds a38ffaa
feat(display): use exported b58
sean-sqds File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,4 +16,6 @@ lib | |
| .env.* | ||
| .env | ||
|
|
||
| cli/*.sh | ||
| cli/*.sh | ||
|
|
||
| .idea | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,180 @@ | ||
| use clap::Args; | ||
| use colored::Colorize; | ||
| use solana_sdk::pubkey::Pubkey; | ||
| use squads_multisig::anchor_lang::AccountDeserialize; | ||
| use squads_multisig::solana_rpc_client::nonblocking::rpc_client::RpcClient; | ||
| use squads_multisig::squads_multisig_program::state::ConfigTransaction; | ||
| use squads_multisig::state::{ConfigAction, Period, Permission, Permissions}; | ||
| use std::str::FromStr; | ||
|
|
||
| /// Fetch a config transaction account and display its decoded actions (add/remove member, change threshold, etc.). | ||
| #[derive(Args)] | ||
| pub struct DisplayConfigTransaction { | ||
| /// RPC URL (default: https://api.mainnet-beta.solana.com) | ||
| #[arg(long)] | ||
| rpc_url: Option<String>, | ||
|
|
||
| /// The ConfigTransaction account address to inspect | ||
| #[arg(long)] | ||
| transaction_address: String, | ||
| } | ||
|
|
||
| fn format_permissions(permissions: Permissions) -> String { | ||
| let mut parts = Vec::new(); | ||
| if permissions.has(Permission::Initiate) { | ||
| parts.push("Proposer"); | ||
| } | ||
| if permissions.has(Permission::Vote) { | ||
| parts.push("Voter"); | ||
| } | ||
| if permissions.has(Permission::Execute) { | ||
| parts.push("Executor"); | ||
| } | ||
| if parts.is_empty() { | ||
| "None".to_string() | ||
| } else { | ||
| parts.join(", ") | ||
| } | ||
| } | ||
|
|
||
| fn format_period(period: Period) -> &'static str { | ||
| match period { | ||
| Period::OneTime => "One-time", | ||
| Period::Day => "Daily", | ||
| Period::Week => "Weekly", | ||
| Period::Month => "Monthly", | ||
| } | ||
| } | ||
|
|
||
| impl DisplayConfigTransaction { | ||
| pub async fn execute(self) -> eyre::Result<()> { | ||
| let rpc_url = self | ||
| .rpc_url | ||
| .unwrap_or_else(|| "https://api.mainnet-beta.solana.com".to_string()); | ||
| let transaction_address = Pubkey::from_str(&self.transaction_address)?; | ||
|
|
||
| let rpc_client = RpcClient::new(rpc_url); | ||
|
|
||
| let account_data = match rpc_client.get_account(&transaction_address).await { | ||
| Ok(account) => account.data, | ||
| Err(_) => { | ||
| println!("Account closed or not found."); | ||
| return Ok(()); | ||
| } | ||
| }; | ||
|
|
||
| let config_tx = | ||
| ConfigTransaction::try_deserialize(&mut account_data.as_slice())?; | ||
|
|
||
| println!(); | ||
| println!("{}", "Config Transaction Details".bold()); | ||
| println!(" Address: {}", transaction_address); | ||
| println!(" Multisig: {}", config_tx.multisig); | ||
| println!(" Creator: {}", config_tx.creator); | ||
| println!(" Index: {}", config_tx.index); | ||
| println!(); | ||
|
|
||
| println!( | ||
| "{}", | ||
| format!("Actions ({})", config_tx.actions.len()).bold() | ||
| ); | ||
| println!(); | ||
|
|
||
| for (i, action) in config_tx.actions.iter().enumerate() { | ||
| match action { | ||
| ConfigAction::AddMember { new_member } => { | ||
| println!("{}", format!("Action {}: Add Member", i + 1).yellow().bold()); | ||
| println!(" Key: {}", new_member.key); | ||
| println!( | ||
| " Permissions: {}", | ||
| format_permissions(new_member.permissions) | ||
| ); | ||
| } | ||
| ConfigAction::RemoveMember { old_member } => { | ||
| println!( | ||
| "{}", | ||
| format!("Action {}: Remove Member", i + 1).yellow().bold() | ||
| ); | ||
| println!(" Key: {}", old_member); | ||
| } | ||
| ConfigAction::ChangeThreshold { new_threshold } => { | ||
| println!( | ||
| "{}", | ||
| format!("Action {}: Change Threshold", i + 1).yellow().bold() | ||
| ); | ||
| println!(" New Threshold: {}", new_threshold); | ||
| } | ||
| ConfigAction::SetTimeLock { new_time_lock } => { | ||
| println!( | ||
| "{}", | ||
| format!("Action {}: Set Time Lock", i + 1).yellow().bold() | ||
| ); | ||
| println!(" New Time Lock: {} seconds", new_time_lock); | ||
| } | ||
| ConfigAction::AddSpendingLimit { | ||
| create_key, | ||
| vault_index, | ||
| mint, | ||
| amount, | ||
| period, | ||
| members, | ||
| destinations, | ||
| } => { | ||
| println!( | ||
| "{}", | ||
| format!("Action {}: Add Spending Limit", i + 1).yellow().bold() | ||
| ); | ||
| println!(" Create Key: {}", create_key); | ||
| println!(" Vault Index: {}", vault_index); | ||
| println!(" Mint: {}", mint); | ||
| println!(" Amount: {}", amount); | ||
| println!(" Period: {}", format_period(*period)); | ||
| if members.is_empty() { | ||
| println!(" Members: (all)"); | ||
| } else { | ||
| println!(" Members:"); | ||
| for m in members { | ||
| println!(" {}", m); | ||
| } | ||
| } | ||
| if destinations.is_empty() { | ||
| println!(" Destinations: (any)"); | ||
| } else { | ||
| println!(" Destinations:"); | ||
| for d in destinations { | ||
| println!(" {}", d); | ||
| } | ||
| } | ||
| } | ||
| ConfigAction::RemoveSpendingLimit { spending_limit } => { | ||
| println!( | ||
| "{}", | ||
| format!("Action {}: Remove Spending Limit", i + 1).yellow().bold() | ||
| ); | ||
| println!(" Spending Limit: {}", spending_limit); | ||
| } | ||
| ConfigAction::SetRentCollector { new_rent_collector } => { | ||
| println!( | ||
| "{}", | ||
| format!("Action {}: Set Rent Collector", i + 1).yellow().bold() | ||
| ); | ||
| match new_rent_collector { | ||
| Some(key) => println!(" New Rent Collector: {}", key), | ||
| None => println!(" New Rent Collector: (disabled)"), | ||
| } | ||
| } | ||
| _ => { | ||
| println!( | ||
| "{}", | ||
| format!("Action {}: (unknown action type)", i + 1) | ||
| .yellow() | ||
| .bold() | ||
| ); | ||
| } | ||
| } | ||
| println!(); | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.