From bb4c3f85ea5697e4ef75c8251f06eb0612aa208a Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Mon, 20 Dec 2021 11:01:23 +0100 Subject: [PATCH] Remove separate clawback_authority (#15) Just use the realm authority instead. --- programs/voter-stake-registry/src/instructions/clawback.rs | 4 ++-- .../src/instructions/create_deposit_entry.rs | 2 +- .../src/instructions/create_registrar.rs | 5 ----- programs/voter-stake-registry/src/state/registrar.rs | 4 ++-- programs/voter-stake-registry/tests/program_test/addin.rs | 7 +++---- programs/voter-stake-registry/tests/test_clawback.rs | 2 +- 6 files changed, 9 insertions(+), 15 deletions(-) diff --git a/programs/voter-stake-registry/src/instructions/clawback.rs b/programs/voter-stake-registry/src/instructions/clawback.rs index e8cea2b..036fbc0 100644 --- a/programs/voter-stake-registry/src/instructions/clawback.rs +++ b/programs/voter-stake-registry/src/instructions/clawback.rs @@ -6,9 +6,9 @@ use anchor_spl::token::{Token, TokenAccount}; #[derive(Accounts)] pub struct Clawback<'info> { - #[account(has_one = clawback_authority)] + #[account(has_one = realm_authority)] pub registrar: AccountLoader<'info, Registrar>, - pub clawback_authority: Signer<'info>, + pub realm_authority: Signer<'info>, // checking the PDA address it just an extra precaution, // the other constraints must be exhaustive diff --git a/programs/voter-stake-registry/src/instructions/create_deposit_entry.rs b/programs/voter-stake-registry/src/instructions/create_deposit_entry.rs index a715b2c..dac28a8 100644 --- a/programs/voter-stake-registry/src/instructions/create_deposit_entry.rs +++ b/programs/voter-stake-registry/src/instructions/create_deposit_entry.rs @@ -54,7 +54,7 @@ pub struct CreateDepositEntry<'info> { /// the vesting start time and the anchor for the periods computation. /// /// - `periods`: How long to lock up, depending on `kind`. See LockupKind::period_secs() -/// - `allow_clawback`: When enabled, the the clawback_authority is allowed to +/// - `allow_clawback`: When enabled, the the realm_authority is allowed to /// unilaterally claim locked tokens. pub fn create_deposit_entry( ctx: Context, diff --git a/programs/voter-stake-registry/src/instructions/create_registrar.rs b/programs/voter-stake-registry/src/instructions/create_registrar.rs index 93efbae..878081e 100644 --- a/programs/voter-stake-registry/src/instructions/create_registrar.rs +++ b/programs/voter-stake-registry/src/instructions/create_registrar.rs @@ -33,10 +33,6 @@ pub struct CreateRegistrar<'info> { pub realm_governing_token_mint: Account<'info, Mint>, pub realm_authority: Signer<'info>, - /// The authority that may use the clawback() instruction - // TODO: Just use the realm_authority? - pub clawback_authority: UncheckedAccount<'info>, - #[account(mut)] pub payer: Signer<'info>, @@ -58,7 +54,6 @@ pub fn create_registrar(ctx: Context, registrar_bump: u8) -> Re registrar.realm = ctx.accounts.realm.key(); registrar.realm_governing_token_mint = ctx.accounts.realm_governing_token_mint.key(); registrar.realm_authority = ctx.accounts.realm_authority.key(); - registrar.clawback_authority = ctx.accounts.clawback_authority.key(); registrar.time_offset = 0; // Verify that "realm_authority" is the expected authority on "realm" diff --git a/programs/voter-stake-registry/src/state/registrar.rs b/programs/voter-stake-registry/src/state/registrar.rs index 188043e..a21e649 100644 --- a/programs/voter-stake-registry/src/state/registrar.rs +++ b/programs/voter-stake-registry/src/state/registrar.rs @@ -11,7 +11,7 @@ pub struct Registrar { pub realm: Pubkey, pub realm_governing_token_mint: Pubkey, pub realm_authority: Pubkey, - pub clawback_authority: Pubkey, + pub padding1: [u8; 32], /// Storage for voting mints and their configuration. /// The length should be adjusted for one's use case. @@ -20,7 +20,7 @@ pub struct Registrar { /// Debug only: time offset, to allow tests to move forward in time. pub time_offset: i64, pub bump: u8, - pub padding: [u8; 31], + pub padding2: [u8; 31], } const_assert!(std::mem::size_of::() == 5 * 32 + 4 * 120 + 8 + 1 + 31); diff --git a/programs/voter-stake-registry/tests/program_test/addin.rs b/programs/voter-stake-registry/tests/program_test/addin.rs index 267dfce..461cea8 100644 --- a/programs/voter-stake-registry/tests/program_test/addin.rs +++ b/programs/voter-stake-registry/tests/program_test/addin.rs @@ -60,7 +60,6 @@ impl AddinCookie { registrar, governance_program_id: realm.governance.program_id, realm: realm.realm, - clawback_authority: realm.authority, realm_governing_token_mint: community_token_mint, realm_authority: realm.authority, payer: payer.pubkey(), @@ -404,7 +403,7 @@ impl AddinCookie { registrar: &RegistrarCookie, voter: &VoterCookie, voting_mint: &VotingMintConfigCookie, - clawback_authority: &Keypair, + realm_authority: &Keypair, token_address: Pubkey, deposit_entry_index: u8, ) -> std::result::Result<(), TransportError> { @@ -422,7 +421,7 @@ impl AddinCookie { token_owner_record: voter.token_owner_record, vault, destination: token_address, - clawback_authority: clawback_authority.pubkey(), + realm_authority: realm_authority.pubkey(), token_program: spl_token::id(), }, None, @@ -435,7 +434,7 @@ impl AddinCookie { }]; // clone the secrets - let signer = Keypair::from_base58_string(&clawback_authority.to_base58_string()); + let signer = Keypair::from_base58_string(&realm_authority.to_base58_string()); self.solana .process_transaction(&instructions, Some(&[&signer])) diff --git a/programs/voter-stake-registry/tests/test_clawback.rs b/programs/voter-stake-registry/tests/test_clawback.rs index b7d33e8..8d2dc1a 100644 --- a/programs/voter-stake-registry/tests/test_clawback.rs +++ b/programs/voter-stake-registry/tests/test_clawback.rs @@ -167,7 +167,7 @@ async fn test_clawback() -> Result<(), TransportError> { 0, ) .await - .expect_err("fails because clawback_authority is invalid"); + .expect_err("fails because realm_authority is invalid"); println!("clawback"); context