Skip to content
This repository was archived by the owner on Dec 20, 2025. It is now read-only.

Commit e324816

Browse files
authored
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).
1 parent 5c50f7f commit e324816

3 files changed

Lines changed: 4 additions & 33 deletions

File tree

program/src/instruction.rs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ pub enum VestingInstruction {
8686
Create {
8787
seeds: [u8; 32],
8888
mint_address: Pubkey,
89-
destination_token_address: Pubkey,
9089
schedules: Vec<Schedule>,
9190
},
9291
/// Unlocks a simple vesting contract (SVC) - can only be invoked by the program itself
@@ -131,14 +130,9 @@ impl VestingInstruction {
131130
.and_then(|slice| slice.try_into().ok())
132131
.map(Pubkey::new_from_array)
133132
.ok_or(InvalidInstruction)?;
134-
let destination_token_address = rest
135-
.get(64..96)
136-
.and_then(|slice| slice.try_into().ok())
137-
.map(Pubkey::new_from_array)
138-
.ok_or(InvalidInstruction)?;
139-
let number_of_schedules = rest[96..].len() / SCHEDULE_SIZE;
133+
let number_of_schedules = rest[64..].len() / SCHEDULE_SIZE;
140134
let mut schedules: Vec<Schedule> = Vec::with_capacity(number_of_schedules);
141-
let mut offset = 96;
135+
let mut offset = 64;
142136
for _ in 0..number_of_schedules {
143137
let release_time = rest
144138
.get(offset..offset + 8)
@@ -159,7 +153,6 @@ impl VestingInstruction {
159153
Self::Create {
160154
seeds,
161155
mint_address,
162-
destination_token_address,
163156
schedules,
164157
}
165158
}
@@ -191,13 +184,11 @@ impl VestingInstruction {
191184
Self::Create {
192185
seeds,
193186
mint_address,
194-
destination_token_address,
195187
schedules,
196188
} => {
197189
buf.push(1);
198190
buf.extend_from_slice(seeds);
199191
buf.extend_from_slice(&mint_address.to_bytes());
200-
buf.extend_from_slice(&destination_token_address.to_bytes());
201192
for s in schedules.iter() {
202193
buf.extend_from_slice(&s.release_time.to_le_bytes());
203194
buf.extend_from_slice(&s.amount.to_le_bytes());
@@ -248,15 +239,13 @@ pub fn create(
248239
vesting_token_account_key: &Pubkey,
249240
source_token_account_owner_key: &Pubkey,
250241
source_token_account_key: &Pubkey,
251-
destination_token_account_key: &Pubkey,
252242
mint_address: &Pubkey,
253243
schedules: Vec<Schedule>,
254244
seeds: [u8; 32],
255245
) -> Result<Instruction, ProgramError> {
256246
let data = VestingInstruction::Create {
257247
mint_address: *mint_address,
258248
seeds,
259-
destination_token_address: *destination_token_account_key,
260249
schedules,
261250
}
262251
.pack();
@@ -306,7 +295,6 @@ mod test {
306295
#[test]
307296
fn test_instruction_packing() {
308297
let mint_address = Pubkey::new_unique();
309-
let destination_token_address = Pubkey::new_unique();
310298

311299
let original_create = VestingInstruction::Create {
312300
seeds: [50u8; 32],
@@ -315,7 +303,6 @@ mod test {
315303
release_time: 250,
316304
}],
317305
mint_address: mint_address.clone(),
318-
destination_token_address,
319306
};
320307
let packed_create = original_create.pack();
321308
let unpacked_create = VestingInstruction::unpack(&packed_create).unwrap();

program/src/processor.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ impl Processor {
7474
accounts: &[AccountInfo],
7575
seeds: [u8; 32],
7676
mint_address: &Pubkey,
77-
destination_token_address: &Pubkey,
7877
schedules: Vec<Schedule>,
7978
) -> ProgramResult {
8079
let accounts_iter = &mut accounts.iter();
@@ -128,7 +127,7 @@ impl Processor {
128127
}
129128

130129
let state_header = VestingScheduleHeader {
131-
destination_address: *destination_token_address,
130+
destination_address: *source_token_account.key,
132131
mint_address: *mint_address,
133132
is_initialized: true,
134133
};
@@ -290,7 +289,6 @@ impl Processor {
290289
VestingInstruction::Create {
291290
seeds,
292291
mint_address,
293-
destination_token_address,
294292
schedules,
295293
} => {
296294
msg!("Instruction: Create Schedule");
@@ -299,7 +297,6 @@ impl Processor {
299297
accounts,
300298
seeds,
301299
&mint_address,
302-
&destination_token_address,
303300
schedules,
304301
)
305302
}

program/tests/functional.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ async fn test_token_vesting() {
2424
let source_account = Keypair::new();
2525
let source_token_account = Keypair::new();
2626

27-
let destination_account = Keypair::new();
28-
let destination_token_account = Keypair::new();
29-
30-
let new_destination_account = Keypair::new();
31-
let new_destination_token_account = Keypair::new();
32-
3327
let mut seeds = [42u8; 32];
3428
let (vesting_account_key, bump) = Pubkey::find_program_address(&[&seeds[..31]], &program_id);
3529
seeds[31] = bump;
@@ -89,12 +83,6 @@ async fn test_token_vesting() {
8983
banks_client.process_transaction(
9084
create_token_account(&payer, &mint, recent_blockhash, &vesting_token_account, &vesting_account_key)
9185
).await.unwrap();
92-
banks_client.process_transaction(
93-
create_token_account(&payer, &mint, recent_blockhash, &destination_token_account, &destination_account.pubkey())
94-
).await.unwrap();
95-
banks_client.process_transaction(
96-
create_token_account(&payer, &mint, recent_blockhash, &new_destination_token_account, &new_destination_account.pubkey())
97-
).await.unwrap();
9886

9987

10088
// Create and process the vesting transactions
@@ -123,7 +111,6 @@ async fn test_token_vesting() {
123111
&vesting_token_account.pubkey(),
124112
&source_account.pubkey(),
125113
&source_token_account.pubkey(),
126-
&destination_token_account.pubkey(),
127114
&mint.pubkey(),
128115
schedules,
129116
seeds.clone()
@@ -134,7 +121,7 @@ async fn test_token_vesting() {
134121
&sysvar::clock::id(),
135122
&vesting_account_key,
136123
&vesting_token_account.pubkey(),
137-
&destination_token_account.pubkey(),
124+
&source_token_account.pubkey(),
138125
seeds.clone()
139126
).unwrap()
140127
];

0 commit comments

Comments
 (0)