Skip to content
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

feat: deprecate destination (in favour of source) #8

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 2 additions & 15 deletions program/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ pub enum VestingInstruction {
Create {
seeds: [u8; 32],
mint_address: Pubkey,
destination_token_address: Pubkey,
schedules: Vec<Schedule>,
},
/// Unlocks a simple vesting contract (SVC) - can only be invoked by the program itself
Expand Down Expand Up @@ -131,14 +130,9 @@ impl VestingInstruction {
.and_then(|slice| slice.try_into().ok())
.map(Pubkey::new_from_array)
.ok_or(InvalidInstruction)?;
let destination_token_address = rest
.get(64..96)
.and_then(|slice| slice.try_into().ok())
.map(Pubkey::new_from_array)
.ok_or(InvalidInstruction)?;
let number_of_schedules = rest[96..].len() / SCHEDULE_SIZE;
let number_of_schedules = rest[64..].len() / SCHEDULE_SIZE;
let mut schedules: Vec<Schedule> = Vec::with_capacity(number_of_schedules);
let mut offset = 96;
let mut offset = 64;
for _ in 0..number_of_schedules {
let release_time = rest
.get(offset..offset + 8)
Expand All @@ -159,7 +153,6 @@ impl VestingInstruction {
Self::Create {
seeds,
mint_address,
destination_token_address,
schedules,
}
}
Expand Down Expand Up @@ -191,13 +184,11 @@ impl VestingInstruction {
Self::Create {
seeds,
mint_address,
destination_token_address,
schedules,
} => {
buf.push(1);
buf.extend_from_slice(seeds);
buf.extend_from_slice(&mint_address.to_bytes());
buf.extend_from_slice(&destination_token_address.to_bytes());
for s in schedules.iter() {
buf.extend_from_slice(&s.release_time.to_le_bytes());
buf.extend_from_slice(&s.amount.to_le_bytes());
Expand Down Expand Up @@ -248,15 +239,13 @@ pub fn create(
vesting_token_account_key: &Pubkey,
source_token_account_owner_key: &Pubkey,
source_token_account_key: &Pubkey,
destination_token_account_key: &Pubkey,
mint_address: &Pubkey,
schedules: Vec<Schedule>,
seeds: [u8; 32],
) -> Result<Instruction, ProgramError> {
let data = VestingInstruction::Create {
mint_address: *mint_address,
seeds,
destination_token_address: *destination_token_account_key,
schedules,
}
.pack();
Expand Down Expand Up @@ -306,7 +295,6 @@ mod test {
#[test]
fn test_instruction_packing() {
let mint_address = Pubkey::new_unique();
let destination_token_address = Pubkey::new_unique();

let original_create = VestingInstruction::Create {
seeds: [50u8; 32],
Expand All @@ -315,7 +303,6 @@ mod test {
release_time: 250,
}],
mint_address: mint_address.clone(),
destination_token_address,
};
let packed_create = original_create.pack();
let unpacked_create = VestingInstruction::unpack(&packed_create).unwrap();
Expand Down
5 changes: 1 addition & 4 deletions program/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ impl Processor {
accounts: &[AccountInfo],
seeds: [u8; 32],
mint_address: &Pubkey,
destination_token_address: &Pubkey,
schedules: Vec<Schedule>,
) -> ProgramResult {
let accounts_iter = &mut accounts.iter();
Expand Down Expand Up @@ -128,7 +127,7 @@ impl Processor {
}

let state_header = VestingScheduleHeader {
destination_address: *destination_token_address,
destination_address: *source_token_account.key,
mint_address: *mint_address,
is_initialized: true,
};
Expand Down Expand Up @@ -290,7 +289,6 @@ impl Processor {
VestingInstruction::Create {
seeds,
mint_address,
destination_token_address,
schedules,
} => {
msg!("Instruction: Create Schedule");
Expand All @@ -299,7 +297,6 @@ impl Processor {
accounts,
seeds,
&mint_address,
&destination_token_address,
schedules,
)
}
Expand Down
15 changes: 1 addition & 14 deletions program/tests/functional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ async fn test_token_vesting() {
let source_account = Keypair::new();
let source_token_account = Keypair::new();

let destination_account = Keypair::new();
let destination_token_account = Keypair::new();

let new_destination_account = Keypair::new();
let new_destination_token_account = Keypair::new();

let mut seeds = [42u8; 32];
let (vesting_account_key, bump) = Pubkey::find_program_address(&[&seeds[..31]], &program_id);
seeds[31] = bump;
Expand Down Expand Up @@ -89,12 +83,6 @@ async fn test_token_vesting() {
banks_client.process_transaction(
create_token_account(&payer, &mint, recent_blockhash, &vesting_token_account, &vesting_account_key)
).await.unwrap();
banks_client.process_transaction(
create_token_account(&payer, &mint, recent_blockhash, &destination_token_account, &destination_account.pubkey())
).await.unwrap();
banks_client.process_transaction(
create_token_account(&payer, &mint, recent_blockhash, &new_destination_token_account, &new_destination_account.pubkey())
).await.unwrap();


// Create and process the vesting transactions
Expand Down Expand Up @@ -123,7 +111,6 @@ async fn test_token_vesting() {
&vesting_token_account.pubkey(),
&source_account.pubkey(),
&source_token_account.pubkey(),
&destination_token_account.pubkey(),
&mint.pubkey(),
schedules,
seeds.clone()
Expand All @@ -134,7 +121,7 @@ async fn test_token_vesting() {
&sysvar::clock::id(),
&vesting_account_key,
&vesting_token_account.pubkey(),
&destination_token_account.pubkey(),
&source_token_account.pubkey(),
seeds.clone()
).unwrap()
];
Expand Down
Loading