forked from project-serum/governance-registry
-
Notifications
You must be signed in to change notification settings - Fork 24
Add accelerated vesting (#1) #60
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
Open
tomjohn1028
wants to merge
1
commit into
blockworks-foundation:master
Choose a base branch
from
mithraiclabs:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
Large diffs are not rendered by default.
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
51 changes: 51 additions & 0 deletions
51
programs/voter-stake-registry/src/instructions/unlock_deposit.rs
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,51 @@ | ||
| use crate::error::*; | ||
| use crate::state::*; | ||
| use anchor_lang::prelude::*; | ||
|
|
||
| #[derive(Accounts)] | ||
| pub struct UnlockDeposit<'info> { | ||
| pub registrar: AccountLoader<'info, Registrar>, | ||
| // checking the PDA address it just an extra precaution, | ||
| // the other constraints must be exhaustive | ||
| #[account( | ||
| mut, | ||
| seeds = [registrar.key().as_ref(), b"voter".as_ref(), voter_authority.key().as_ref()], | ||
| bump = voter.load()?.voter_bump, | ||
| has_one = voter_authority, | ||
| has_one = registrar)] | ||
| pub voter: AccountLoader<'info, Voter>, | ||
| pub voter_authority: Signer<'info>, | ||
| /// Authority for making a grant to this voter account | ||
| /// | ||
| /// Instruction validates grant_authority is the VotingMintConfig.grant_authority or | ||
| /// Registrar.realm_authority. | ||
| pub grant_authority: Signer<'info>, | ||
| } | ||
|
|
||
| pub fn unlock_deposit(ctx: Context<UnlockDeposit>, deposit_entry_index: u8) -> Result<()> { | ||
| // Load accounts. | ||
| let registrar = &ctx.accounts.registrar.load()?; | ||
| let voter = &mut ctx.accounts.voter.load_mut()?; | ||
|
|
||
| let deposit_entry = voter.active_deposit_mut(deposit_entry_index)?; | ||
| // Get the grant_authority for the DepositEntry | ||
| let mint_idx = deposit_entry.voting_mint_config_idx; | ||
| let mint_config: &VotingMintConfig = ®istrar.voting_mints[mint_idx as usize]; | ||
| let grant_authority = ctx.accounts.grant_authority.key(); | ||
|
|
||
| // Validate the VotingMintConfig was initialized and is in use | ||
| require!(mint_config.in_use(), VsrError::MintConfigNotUsed); | ||
|
|
||
| // Validate grant_authority is appropriate to unlock deposit | ||
| require!( | ||
| (grant_authority == registrar.realm_authority | ||
| || grant_authority == mint_config.grant_authority) | ||
| && grant_authority != Pubkey::default(), | ||
| VsrError::BadUnlockDepositAuthority | ||
| ); | ||
|
|
||
| // Change the DepositEntry to unlock all unvested tokens | ||
| deposit_entry.unlock_deposit(); | ||
|
|
||
| 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
Binary file modified
BIN
-188 KB
(78%)
programs/voter-stake-registry/tests/fixtures/spl_governance.so
Binary file not shown.
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needs to be checked out in relation to the warning above - likely all gov deployments have updated, but need to double check