-
Notifications
You must be signed in to change notification settings - Fork 4
feat: Add close validator vault #71
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 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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,25 @@ | ||
use solana_program::instruction::Instruction; | ||
use solana_program::{instruction::AccountMeta, pubkey::Pubkey}; | ||
|
||
use crate::discriminator::DlpDiscriminator; | ||
use crate::pda::validator_fees_vault_pda_from_validator; | ||
|
||
/// Close a validator fees vault PDA. | ||
/// See [crate::processor::process_close_validator_fees_vault] for docs. | ||
pub fn close_validator_fees_vault( | ||
payer: Pubkey, | ||
admin: Pubkey, | ||
validator_identity: Pubkey, | ||
) -> Instruction { | ||
let validator_fees_vault_pda = validator_fees_vault_pda_from_validator(&validator_identity); | ||
Instruction { | ||
program_id: crate::id(), | ||
accounts: vec![ | ||
AccountMeta::new(payer, true), | ||
AccountMeta::new(admin, true), | ||
AccountMeta::new(validator_identity, false), | ||
AccountMeta::new(validator_fees_vault_pda, false), | ||
], | ||
data: DlpDiscriminator::CloseValidatorFeesVault.to_vec(), | ||
} | ||
} |
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,63 @@ | ||
use solana_program::msg; | ||
use solana_program::program_error::ProgramError; | ||
use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, pubkey::Pubkey}; | ||
|
||
use crate::consts::ADMIN_PUBKEY; | ||
use crate::error::DlpError::Unauthorized; | ||
use crate::processor::utils::loaders::{load_initialized_pda, load_signer}; | ||
use crate::processor::utils::pda::close_pda; | ||
use crate::validator_fees_vault_seeds_from_validator; | ||
|
||
/// Process the close of the validator fees vault | ||
/// | ||
/// Accounts: | ||
/// | ||
/// 0; `[signer]` payer | ||
/// 1; `[signer]` admin that controls the vault | ||
/// 2; `[]` validator_identity | ||
/// 3; `[]` validator_fees_vault_pda | ||
/// | ||
/// Requirements: | ||
/// | ||
/// - validator admin need to be signer since the existence of the validator fees vault | ||
/// is used as proof later that the validator is whitelisted | ||
/// - validator fees vault is closed | ||
/// | ||
/// 1. Close the validator fees vault PDA | ||
pub fn process_close_validator_fees_vault( | ||
_program_id: &Pubkey, | ||
accounts: &[AccountInfo], | ||
_data: &[u8], | ||
) -> ProgramResult { | ||
// Load Accounts | ||
let [payer, admin, validator_identity, validator_fees_vault] = accounts else { | ||
return Err(ProgramError::NotEnoughAccountKeys); | ||
}; | ||
GabrielePicco marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Check if the payer and admin are signers | ||
load_signer(payer, "payer")?; | ||
load_signer(admin, "admin")?; | ||
|
||
// Check if the admin is the correct one | ||
if !admin.key.eq(&ADMIN_PUBKEY) { | ||
msg!( | ||
"Expected admin pubkey: {} but got {}", | ||
ADMIN_PUBKEY, | ||
admin.key | ||
); | ||
return Err(Unauthorized.into()); | ||
} | ||
|
||
load_initialized_pda( | ||
validator_fees_vault, | ||
validator_fees_vault_seeds_from_validator!(validator_identity.key), | ||
&crate::id(), | ||
true, | ||
"validator fees vault", | ||
)?; | ||
|
||
// Close the fees vault PDA | ||
close_pda(validator_fees_vault, validator_identity)?; | ||
|
||
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
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,67 @@ | ||
use crate::fixtures::TEST_AUTHORITY; | ||
use dlp::pda::validator_fees_vault_pda_from_validator; | ||
use solana_program::{hash::Hash, native_token::LAMPORTS_PER_SOL, system_program}; | ||
use solana_program_test::{processor, BanksClient, ProgramTest}; | ||
use solana_sdk::{ | ||
account::Account, | ||
signature::{Keypair, Signer}, | ||
transaction::Transaction, | ||
}; | ||
|
||
mod fixtures; | ||
|
||
#[tokio::test] | ||
async fn test_close_validator_fees_vault() { | ||
// Setup | ||
let (banks, admin, validator, blockhash) = setup_program_test_env().await; | ||
|
||
let validator_fees_vault_pda = validator_fees_vault_pda_from_validator(&validator.pubkey()); | ||
|
||
// Submit the close vault tx | ||
let ix = dlp::instruction_builder::close_validator_fees_vault( | ||
admin.pubkey(), | ||
admin.pubkey(), | ||
validator.pubkey(), | ||
); | ||
GabrielePicco marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let tx = Transaction::new_signed_with_payer(&[ix], Some(&admin.pubkey()), &[&admin], blockhash); | ||
let res = banks.process_transaction(tx).await; | ||
assert!(res.is_ok()); | ||
|
||
// Assert the validator fees vault now has been closed | ||
let validator_fees_vault_account = banks.get_account(validator_fees_vault_pda).await.unwrap(); | ||
assert!(validator_fees_vault_account.is_none()); | ||
} | ||
|
||
async fn setup_program_test_env() -> (BanksClient, Keypair, Keypair, Hash) { | ||
let mut program_test = ProgramTest::new("dlp", dlp::ID, processor!(dlp::process_instruction)); | ||
program_test.prefer_bpf(true); | ||
|
||
let admin_keypair = Keypair::from_bytes(&TEST_AUTHORITY).unwrap(); | ||
let validator = Keypair::new(); | ||
|
||
program_test.add_account( | ||
admin_keypair.pubkey(), | ||
Account { | ||
lamports: LAMPORTS_PER_SOL, | ||
data: vec![], | ||
owner: system_program::id(), | ||
executable: false, | ||
rent_epoch: 0, | ||
}, | ||
); | ||
|
||
// Setup the validator fees vault | ||
program_test.add_account( | ||
validator_fees_vault_pda_from_validator(&validator.pubkey()), | ||
Account { | ||
lamports: LAMPORTS_PER_SOL, | ||
data: vec![], | ||
owner: dlp::id(), | ||
executable: false, | ||
rent_epoch: 0, | ||
}, | ||
); | ||
|
||
let (banks, _, blockhash) = program_test.start().await; | ||
(banks, admin_keypair, validator, blockhash) | ||
} |
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.