From e324816ee417895b3405ade258c92f6ee2d840b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wei=C3=9Fer=20Hase?= Date: Wed, 25 Sep 2024 15:57:05 +0200 Subject: [PATCH] feat: deprecate destination (in favour of source) (#8) The original codebase corresponds to a Vesting Contract between A and B, in which A gives tokens to B in a scheduled way. The intended behaviour of this proposal is for A to lock tokens, that only A can withdraw. Following that intended behaviour, we deprecate the concept of "destination" from every call (as it will be same as the source). --- program/src/instruction.rs | 17 ++--------------- program/src/processor.rs | 5 +---- program/tests/functional.rs | 15 +-------------- 3 files changed, 4 insertions(+), 33 deletions(-) diff --git a/program/src/instruction.rs b/program/src/instruction.rs index 115b8c0..8aa5055 100644 --- a/program/src/instruction.rs +++ b/program/src/instruction.rs @@ -86,7 +86,6 @@ pub enum VestingInstruction { Create { seeds: [u8; 32], mint_address: Pubkey, - destination_token_address: Pubkey, schedules: Vec, }, /// Unlocks a simple vesting contract (SVC) - can only be invoked by the program itself @@ -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 = 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) @@ -159,7 +153,6 @@ impl VestingInstruction { Self::Create { seeds, mint_address, - destination_token_address, schedules, } } @@ -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()); @@ -248,7 +239,6 @@ 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, seeds: [u8; 32], @@ -256,7 +246,6 @@ pub fn create( let data = VestingInstruction::Create { mint_address: *mint_address, seeds, - destination_token_address: *destination_token_account_key, schedules, } .pack(); @@ -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], @@ -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(); diff --git a/program/src/processor.rs b/program/src/processor.rs index 4d83ee5..3d87a3c 100644 --- a/program/src/processor.rs +++ b/program/src/processor.rs @@ -74,7 +74,6 @@ impl Processor { accounts: &[AccountInfo], seeds: [u8; 32], mint_address: &Pubkey, - destination_token_address: &Pubkey, schedules: Vec, ) -> ProgramResult { let accounts_iter = &mut accounts.iter(); @@ -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, }; @@ -290,7 +289,6 @@ impl Processor { VestingInstruction::Create { seeds, mint_address, - destination_token_address, schedules, } => { msg!("Instruction: Create Schedule"); @@ -299,7 +297,6 @@ impl Processor { accounts, seeds, &mint_address, - &destination_token_address, schedules, ) } diff --git a/program/tests/functional.rs b/program/tests/functional.rs index 5ab03e3..8d8b038 100644 --- a/program/tests/functional.rs +++ b/program/tests/functional.rs @@ -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; @@ -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 @@ -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() @@ -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() ];