Remove separate clawback_authority (#15)
Just use the realm authority instead.
This commit is contained in:
parent
0e45b0d8a4
commit
bb4c3f85ea
|
@ -6,9 +6,9 @@ use anchor_spl::token::{Token, TokenAccount};
|
||||||
|
|
||||||
#[derive(Accounts)]
|
#[derive(Accounts)]
|
||||||
pub struct Clawback<'info> {
|
pub struct Clawback<'info> {
|
||||||
#[account(has_one = clawback_authority)]
|
#[account(has_one = realm_authority)]
|
||||||
pub registrar: AccountLoader<'info, Registrar>,
|
pub registrar: AccountLoader<'info, Registrar>,
|
||||||
pub clawback_authority: Signer<'info>,
|
pub realm_authority: Signer<'info>,
|
||||||
|
|
||||||
// checking the PDA address it just an extra precaution,
|
// checking the PDA address it just an extra precaution,
|
||||||
// the other constraints must be exhaustive
|
// the other constraints must be exhaustive
|
||||||
|
|
|
@ -54,7 +54,7 @@ pub struct CreateDepositEntry<'info> {
|
||||||
/// the vesting start time and the anchor for the periods computation.
|
/// the vesting start time and the anchor for the periods computation.
|
||||||
///
|
///
|
||||||
/// - `periods`: How long to lock up, depending on `kind`. See LockupKind::period_secs()
|
/// - `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.
|
/// unilaterally claim locked tokens.
|
||||||
pub fn create_deposit_entry(
|
pub fn create_deposit_entry(
|
||||||
ctx: Context<CreateDepositEntry>,
|
ctx: Context<CreateDepositEntry>,
|
||||||
|
|
|
@ -33,10 +33,6 @@ pub struct CreateRegistrar<'info> {
|
||||||
pub realm_governing_token_mint: Account<'info, Mint>,
|
pub realm_governing_token_mint: Account<'info, Mint>,
|
||||||
pub realm_authority: Signer<'info>,
|
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)]
|
#[account(mut)]
|
||||||
pub payer: Signer<'info>,
|
pub payer: Signer<'info>,
|
||||||
|
|
||||||
|
@ -58,7 +54,6 @@ pub fn create_registrar(ctx: Context<CreateRegistrar>, registrar_bump: u8) -> Re
|
||||||
registrar.realm = ctx.accounts.realm.key();
|
registrar.realm = ctx.accounts.realm.key();
|
||||||
registrar.realm_governing_token_mint = ctx.accounts.realm_governing_token_mint.key();
|
registrar.realm_governing_token_mint = ctx.accounts.realm_governing_token_mint.key();
|
||||||
registrar.realm_authority = ctx.accounts.realm_authority.key();
|
registrar.realm_authority = ctx.accounts.realm_authority.key();
|
||||||
registrar.clawback_authority = ctx.accounts.clawback_authority.key();
|
|
||||||
registrar.time_offset = 0;
|
registrar.time_offset = 0;
|
||||||
|
|
||||||
// Verify that "realm_authority" is the expected authority on "realm"
|
// Verify that "realm_authority" is the expected authority on "realm"
|
||||||
|
|
|
@ -11,7 +11,7 @@ pub struct Registrar {
|
||||||
pub realm: Pubkey,
|
pub realm: Pubkey,
|
||||||
pub realm_governing_token_mint: Pubkey,
|
pub realm_governing_token_mint: Pubkey,
|
||||||
pub realm_authority: Pubkey,
|
pub realm_authority: Pubkey,
|
||||||
pub clawback_authority: Pubkey,
|
pub padding1: [u8; 32],
|
||||||
|
|
||||||
/// Storage for voting mints and their configuration.
|
/// Storage for voting mints and their configuration.
|
||||||
/// The length should be adjusted for one's use case.
|
/// 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.
|
/// Debug only: time offset, to allow tests to move forward in time.
|
||||||
pub time_offset: i64,
|
pub time_offset: i64,
|
||||||
pub bump: u8,
|
pub bump: u8,
|
||||||
pub padding: [u8; 31],
|
pub padding2: [u8; 31],
|
||||||
}
|
}
|
||||||
const_assert!(std::mem::size_of::<Registrar>() == 5 * 32 + 4 * 120 + 8 + 1 + 31);
|
const_assert!(std::mem::size_of::<Registrar>() == 5 * 32 + 4 * 120 + 8 + 1 + 31);
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,6 @@ impl AddinCookie {
|
||||||
registrar,
|
registrar,
|
||||||
governance_program_id: realm.governance.program_id,
|
governance_program_id: realm.governance.program_id,
|
||||||
realm: realm.realm,
|
realm: realm.realm,
|
||||||
clawback_authority: realm.authority,
|
|
||||||
realm_governing_token_mint: community_token_mint,
|
realm_governing_token_mint: community_token_mint,
|
||||||
realm_authority: realm.authority,
|
realm_authority: realm.authority,
|
||||||
payer: payer.pubkey(),
|
payer: payer.pubkey(),
|
||||||
|
@ -404,7 +403,7 @@ impl AddinCookie {
|
||||||
registrar: &RegistrarCookie,
|
registrar: &RegistrarCookie,
|
||||||
voter: &VoterCookie,
|
voter: &VoterCookie,
|
||||||
voting_mint: &VotingMintConfigCookie,
|
voting_mint: &VotingMintConfigCookie,
|
||||||
clawback_authority: &Keypair,
|
realm_authority: &Keypair,
|
||||||
token_address: Pubkey,
|
token_address: Pubkey,
|
||||||
deposit_entry_index: u8,
|
deposit_entry_index: u8,
|
||||||
) -> std::result::Result<(), TransportError> {
|
) -> std::result::Result<(), TransportError> {
|
||||||
|
@ -422,7 +421,7 @@ impl AddinCookie {
|
||||||
token_owner_record: voter.token_owner_record,
|
token_owner_record: voter.token_owner_record,
|
||||||
vault,
|
vault,
|
||||||
destination: token_address,
|
destination: token_address,
|
||||||
clawback_authority: clawback_authority.pubkey(),
|
realm_authority: realm_authority.pubkey(),
|
||||||
token_program: spl_token::id(),
|
token_program: spl_token::id(),
|
||||||
},
|
},
|
||||||
None,
|
None,
|
||||||
|
@ -435,7 +434,7 @@ impl AddinCookie {
|
||||||
}];
|
}];
|
||||||
|
|
||||||
// clone the secrets
|
// 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
|
self.solana
|
||||||
.process_transaction(&instructions, Some(&[&signer]))
|
.process_transaction(&instructions, Some(&[&signer]))
|
||||||
|
|
|
@ -167,7 +167,7 @@ async fn test_clawback() -> Result<(), TransportError> {
|
||||||
0,
|
0,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.expect_err("fails because clawback_authority is invalid");
|
.expect_err("fails because realm_authority is invalid");
|
||||||
|
|
||||||
println!("clawback");
|
println!("clawback");
|
||||||
context
|
context
|
||||||
|
|
Loading…
Reference in New Issue