-
Notifications
You must be signed in to change notification settings - Fork 1
Feat/update share and remove user #16
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
bangyro
wants to merge
17
commits into
release_0.1.2
Choose a base branch
from
feat/update_share
base: release_0.1.2
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
Show all changes
17 commits
Select commit
Hold shift + click to select a range
b84bbbb
chore: add toolchain
bangyro a8a46db
feat: update user share logic
bangyro 3ef93aa
feat: create/close operator account on a fee vault level
bangyro 3be39f2
feat: update changelog
bangyro 2561964
feat: change from operator_account to address
bangyro 3cf2cd7
feat: mutable fee_vault and remove user feature
bangyro e63211b
feat: update tooling and config
bangyro e9fffc7
feat: add fail case
bangyro bf5760a
docs: update changelog
bangyro 0f963eb
fix: validate mutable_flag param
bangyro ab2aeb9
feat: add more test
bangyro 1a05433
feat: refactor baseKp
bangyro 92ee278
feat: add more test assertions
bangyro 1f70893
docs: document mutable_flag field
bangyro a3cc414
feat: address comments
bangyro 9b24620
feat: address comments and change update user share behaviour
bangyro 681d89c
feat: add user and add update operator event
bangyro 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 |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| [toolchain] | ||
| anchor_version = "0.31.1" | ||
| solana_version = "2.3.13" | ||
| package_manager = "yarn" | ||
|
|
||
| [features] | ||
|
|
||
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
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
85 changes: 85 additions & 0 deletions
85
programs/dynamic-fee-sharing/src/instructions/ix_claim_removed_user_fee.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,85 @@ | ||
| use crate::const_pda; | ||
| use crate::constants::seeds::REMOVED_USER_TOKEN_VAULT; | ||
| use crate::event::EvtClaimRemovedUserFee; | ||
| use crate::state::FeeVault; | ||
| use crate::utils::token::transfer_from_fee_vault; | ||
| use anchor_lang::prelude::*; | ||
| use anchor_spl::token_interface::{ | ||
| close_account, CloseAccount, Mint, TokenAccount, TokenInterface, | ||
| }; | ||
|
|
||
| #[event_cpi] | ||
| #[derive(Accounts)] | ||
| pub struct ClaimRemovedUserFeeCtx<'info> { | ||
| #[account(has_one = token_mint, has_one = owner)] | ||
| pub fee_vault: AccountLoader<'info, FeeVault>, | ||
|
|
||
| /// CHECK: fee vault authority | ||
| #[account(address = const_pda::fee_vault_authority::ID)] | ||
| pub fee_vault_authority: UncheckedAccount<'info>, | ||
|
|
||
| pub token_mint: Box<InterfaceAccount<'info, Mint>>, | ||
|
|
||
| #[account( | ||
| mut, | ||
| seeds = [ | ||
| REMOVED_USER_TOKEN_VAULT, | ||
| fee_vault.key().as_ref(), | ||
| token_mint.key().as_ref(), | ||
| user.key().as_ref(), | ||
| ], | ||
| bump, | ||
| token::mint = token_mint, | ||
| token::authority = fee_vault_authority, | ||
| )] | ||
| pub removed_user_token_vault: Box<InterfaceAccount<'info, TokenAccount>>, | ||
|
|
||
| #[account( | ||
| mut, | ||
| token::authority = user, | ||
| token::mint = token_mint, | ||
| )] | ||
| pub user_token_vault: Box<InterfaceAccount<'info, TokenAccount>>, | ||
|
|
||
| /// CHECK: fee vault owner, receives rent from closed account | ||
| #[account(mut)] | ||
| pub owner: UncheckedAccount<'info>, | ||
|
|
||
| pub user: Signer<'info>, | ||
|
|
||
| pub token_program: Interface<'info, TokenInterface>, | ||
| } | ||
|
|
||
| pub fn handle_claim_removed_user_fee(ctx: Context<ClaimRemovedUserFeeCtx>) -> Result<()> { | ||
| let fee_being_claimed = ctx.accounts.removed_user_token_vault.amount; | ||
|
|
||
| if fee_being_claimed > 0 { | ||
| transfer_from_fee_vault( | ||
| ctx.accounts.fee_vault_authority.to_account_info(), | ||
| &ctx.accounts.token_mint, | ||
| &ctx.accounts.removed_user_token_vault, | ||
| &ctx.accounts.user_token_vault, | ||
| &ctx.accounts.token_program, | ||
| fee_being_claimed, | ||
| )?; | ||
| } | ||
|
|
||
| let signer_seeds = fee_vault_authority_seeds!(); | ||
| close_account(CpiContext::new_with_signer( | ||
| ctx.accounts.token_program.to_account_info(), | ||
| CloseAccount { | ||
| account: ctx.accounts.removed_user_token_vault.to_account_info(), | ||
| destination: ctx.accounts.owner.to_account_info(), | ||
| authority: ctx.accounts.fee_vault_authority.to_account_info(), | ||
| }, | ||
| &[&signer_seeds[..]], | ||
| ))?; | ||
|
|
||
| emit_cpi!(EvtClaimRemovedUserFee { | ||
| fee_vault: ctx.accounts.fee_vault.key(), | ||
| user: ctx.accounts.user.key(), | ||
| claimed_fee: fee_being_claimed, | ||
| }); | ||
|
|
||
| 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
29 changes: 29 additions & 0 deletions
29
programs/dynamic-fee-sharing/src/instructions/operator/ix_add_user.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,29 @@ | ||
| use crate::event::EvtAddUser; | ||
| use crate::state::FeeVault; | ||
| use anchor_lang::prelude::*; | ||
|
|
||
| #[event_cpi] | ||
| #[derive(Accounts)] | ||
| pub struct AddUserCtx<'info> { | ||
| #[account(mut)] | ||
| pub fee_vault: AccountLoader<'info, FeeVault>, | ||
|
|
||
| /// CHECK: the user being added | ||
| pub user: UncheckedAccount<'info>, | ||
|
|
||
| pub signer: Signer<'info>, | ||
| } | ||
|
|
||
| pub fn handle_add_user(ctx: Context<AddUserCtx>, share: u32) -> Result<()> { | ||
| let mut fee_vault = ctx.accounts.fee_vault.load_mut()?; | ||
| let user = ctx.accounts.user.key(); | ||
| fee_vault.validate_and_add_user(&user, share)?; | ||
|
|
||
| emit_cpi!(EvtAddUser { | ||
| fee_vault: ctx.accounts.fee_vault.key(), | ||
| user, | ||
| share, | ||
| }); | ||
|
|
||
| Ok(()) | ||
| } |
Oops, something went wrong.
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.
Changing the error name here since. This error is also used when the number of user is less than the minimum amount (2)