-
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 1 commit
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub const MAX_WHITELIST_SIZE: u8 = 20; | ||
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
use crate::{errors::ProtocolError, state::whitelist::Whitelist}; | ||
|
||
use crate::{errors::ProtocolError, state::whitelist::Whitelist,constants::MAX_WHITELIST_SIZE}; | ||
use anchor_lang::prelude::*; | ||
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 +21,10 @@ pub struct CreateWhitelistAccounts<'info> { | |
|
||
pub fn create_whitelist_instruction( | ||
ctx: Context<CreateWhitelistAccounts>, | ||
expected_whitelist_size: u16, | ||
length:u8, | ||
whitelist_to_add: Vec<Pubkey>, | ||
) -> Result<()> { | ||
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 |
||
let expected_whitelist_capacity = calculate_expected_capacity(expected_whitelist_size); | ||
validate_whitelist_inputs(expected_whitelist_capacity, &whitelist_to_add)?; | ||
validate_whitelist_inputs(length)?; | ||
let CreateWhitelistAccounts { | ||
creator, | ||
whitelist_account, | ||
|
@@ -34,25 +34,23 @@ pub fn create_whitelist_instruction( | |
whitelist_account.set_inner(Whitelist { | ||
creator: creator.key(), | ||
whitelist: whitelist_to_add, | ||
capacity: expected_whitelist_capacity, | ||
}); | ||
|
||
Ok(()) | ||
} | ||
|
||
fn validate_whitelist_inputs( | ||
expected_whitelist_capacity: u8, | ||
whitelist_to_add: &Vec<Pubkey>, | ||
length:u8, | ||
) -> Result<()> { | ||
require!( | ||
whitelist_to_add.len() <= (expected_whitelist_capacity as usize), | ||
length <= MAX_WHITELIST_SIZE , | ||
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 u64 * 32 as u64) as usize | ||
} | ||
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.
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 |
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.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ use anchor_lang::prelude::*; | |
#[account] | ||
pub struct Whitelist { | ||
pub creator: Pubkey, | ||
pub capacity: u8, | ||
pub whitelist: 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. Let's add an associated rfq field, which would work as follows:
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 |
||
|
||
|
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.
We're storing constants in state files, you can check other types for examples
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 , added to state