[solana] reclaim rent (#1266)

* Checkpoint

* Checkpoint

* Cleanup

* Checkpoint, debug

* Go

* Checkpoint

* Fix

* Add new error and test

* Cleanup

* Add another test

* Keep adding errors

* Another test

* Add comment

* More

* Do it

* Again

* Nice

* Ship it
This commit is contained in:
guibescos 2024-02-01 15:51:24 +00:00 committed by GitHub
parent f01d17e8ad
commit 7e65fd6597
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 70 additions and 1 deletions

View File

@ -217,6 +217,10 @@ pub mod pyth_solana_receiver {
Ok(())
}
pub fn reclaim_rent(_ctx: Context<ReclaimRent>) -> Result<()> {
Ok(())
}
}
pub const CONFIG_SEED: &str = "config";
@ -295,6 +299,14 @@ pub struct PostUpdatesAtomic<'info> {
pub system_program: Program<'info, System>,
}
#[derive(Accounts)]
pub struct ReclaimRent<'info> {
#[account(mut)]
pub payer: Signer<'info>,
#[account(mut, close = payer, constraint = price_update_account.write_authority == payer.key() @ ReceiverError::WrongWriteAuthority)]
pub price_update_account: Account<'info, PriceUpdateV1>,
}
#[derive(Debug, AnchorSerialize, AnchorDeserialize, Clone)]
pub struct PostUpdatesAtomicParams {
pub vaa: Vec<u8>,

View File

@ -88,6 +88,16 @@ impl accounts::AcceptGovernanceAuthorityTransfer {
}
}
impl accounts::ReclaimRent {
pub fn populate(payer: Pubkey, price_update_account: Pubkey) -> Self {
let _config = get_config_address();
accounts::ReclaimRent {
payer,
price_update_account,
}
}
}
impl instruction::Initialize {
pub fn populate(payer: &Pubkey, initial_config: Config) -> Instruction {
Instruction {
@ -229,6 +239,18 @@ impl instruction::AcceptGovernanceAuthorityTransfer {
}
}
impl instruction::ReclaimRent {
pub fn populate(payer: Pubkey, price_update_account: Pubkey) -> Instruction {
let governance_accounts =
accounts::ReclaimRent::populate(payer, price_update_account).to_account_metas(None);
Instruction {
program_id: ID,
accounts: governance_accounts,
data: instruction::ReclaimRent {}.data(),
}
}
}
pub fn get_treasury_address() -> Pubkey {
Pubkey::find_program_address(&[TREASURY_SEED.as_ref()], &ID).0

View File

@ -10,7 +10,10 @@ use {
program_simulator::into_transaction_error,
pyth_solana_receiver::{
error::ReceiverError,
instruction::PostUpdates,
instruction::{
PostUpdates,
ReclaimRent,
},
sdk::deserialize_accumulator_update_data,
state::price_update::{
PriceUpdateV1,
@ -120,6 +123,38 @@ async fn test_post_updates() {
Message::PriceFeedMessage(price_update_account.price_message),
feed_2
);
// This poster doesn't have the write authority
let poster_2 = program_simulator.get_funded_keypair().await.unwrap();
assert_eq!(
program_simulator
.process_ix_with_default_compute_limit(
ReclaimRent::populate(poster_2.pubkey(), price_update_keypair.pubkey()),
&vec![&poster_2],
None,
)
.await
.unwrap_err()
.unwrap(),
into_transaction_error(ReceiverError::WrongWriteAuthority)
);
program_simulator
.process_ix_with_default_compute_limit(
ReclaimRent::populate(poster.pubkey(), price_update_keypair.pubkey()),
&vec![&poster],
None,
)
.await
.unwrap();
assert_eq!(
program_simulator
.get_balance(price_update_keypair.pubkey())
.await
.unwrap(),
0
);
}
#[tokio::test]