-
Notifications
You must be signed in to change notification settings - Fork 0
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
revoke whitelist logic #188
Changes from 4 commits
0b708af
edf77e9
6d7ead3
aed180e
e24d001
91ba418
e258fb8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,13 @@ use std::mem; | |
|
||
#[derive(Accounts)] | ||
#[instruction( | ||
expected_whitelist_size: u16 | ||
length: u8 | ||
)] | ||
pub struct CreateWhitelistAccounts<'info> { | ||
#[account( | ||
init_if_needed, | ||
payer = creator, | ||
space = 8 + mem::size_of::<Whitelist>() + (expected_whitelist_size as usize) | ||
space = get_whitelist_size_from_length(length), | ||
)] | ||
pub whitelist_account: Box<Account<'info, Whitelist>>, | ||
#[account(mut)] | ||
|
@@ -20,11 +20,9 @@ pub struct CreateWhitelistAccounts<'info> { | |
|
||
pub fn create_whitelist_instruction( | ||
ctx: Context<CreateWhitelistAccounts>, | ||
expected_whitelist_size: u16, | ||
whitelist_to_add: Vec<Pubkey>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you're passing it in one ix, you already have a length in this vector, no need to pass it as a parameter There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. resolved |
||
) -> Result<()> { | ||
let expected_whitelist_capacity = calculate_expected_capacity(expected_whitelist_size); | ||
validate_whitelist_inputs(expected_whitelist_capacity, &whitelist_to_add)?; | ||
validate_whitelist_inputs(whitelist_to_add.len())?; | ||
let CreateWhitelistAccounts { | ||
creator, | ||
whitelist_account, | ||
|
@@ -33,26 +31,21 @@ pub fn create_whitelist_instruction( | |
|
||
whitelist_account.set_inner(Whitelist { | ||
creator: creator.key(), | ||
associated_rfq: Pubkey::default(), | ||
whitelist: whitelist_to_add, | ||
capacity: expected_whitelist_capacity, | ||
}); | ||
|
||
Ok(()) | ||
} | ||
|
||
fn validate_whitelist_inputs( | ||
expected_whitelist_capacity: u8, | ||
whitelist_to_add: &Vec<Pubkey>, | ||
) -> Result<()> { | ||
fn validate_whitelist_inputs(length: usize) -> Result<()> { | ||
require!( | ||
whitelist_to_add.len() <= (expected_whitelist_capacity as usize), | ||
length <= Whitelist::MAX_WHITELIST_SIZE as usize, | ||
ProtocolError::WhitelistMaximumCapacityReached | ||
); | ||
|
||
Ok(()) | ||
} | ||
|
||
fn calculate_expected_capacity(expected_whitelist_size: u16) -> u8 { | ||
let pubkey_size = 32; | ||
(expected_whitelist_size / pubkey_size) as u8 | ||
fn get_whitelist_size_from_length(length: u8) -> usize { | ||
8 + mem::size_of::<Whitelist>() + length as usize * 32 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
pub mod add_address_to_whitelist; | ||
pub mod cleanup_whitelist; | ||
pub mod create_whitelist; | ||
pub mod remove_address_from_whitelist; |
This file was deleted.
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.
You can accidentally pass a None case if the rfq address exists and it wouldn't be cleaned up
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.
I think it makes sense to reuse the logic of "check whitelist account passed" used in response to rfq
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.
resolved