diff --git a/CHANGELOG.md b/CHANGELOG.md index 14a9d11..368db28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Breaking Changes +## Program [0.2.2] [PR #8](https://github.com/jup-ag/jup-lock/pull/8) + +### Breaking Changes +- Rename `cliff_amount` to `initial_unlock_amount` + + ## Program [0.2.1] [PR #4](https://github.com/jup-ag/jup-lock/pull/4) ### Fixed diff --git a/Cargo.lock b/Cargo.lock index 965144b..78147a3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1218,7 +1218,7 @@ dependencies = [ [[package]] name = "locker" -version = "0.2.1" +version = "0.2.2" dependencies = [ "anchor-lang", "anchor-spl", diff --git a/programs/locker/Cargo.toml b/programs/locker/Cargo.toml index b938eb3..ef1289a 100644 --- a/programs/locker/Cargo.toml +++ b/programs/locker/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "locker" -version = "0.2.1" +version = "0.2.2" description = "Created with Anchor" edition = "2021" author = "andrew@raccoons.dev" diff --git a/programs/locker/src/events.rs b/programs/locker/src/events.rs index e0ee428..5d8f456 100644 --- a/programs/locker/src/events.rs +++ b/programs/locker/src/events.rs @@ -4,7 +4,7 @@ use anchor_lang::prelude::*; pub struct EventCreateVestingEscrow { pub start_time: u64, pub frequency: u64, - pub cliff_amount: u64, + pub initial_unlock_amount: u64, pub amount_per_period: u64, pub number_of_period: u64, pub update_recipient_mode: u8, diff --git a/programs/locker/src/instructions/create_vesting_escrow.rs b/programs/locker/src/instructions/create_vesting_escrow.rs index 50634d5..b55796d 100644 --- a/programs/locker/src/instructions/create_vesting_escrow.rs +++ b/programs/locker/src/instructions/create_vesting_escrow.rs @@ -7,7 +7,7 @@ use anchor_spl::token::{Token, TokenAccount, Transfer}; pub struct CreateVestingEscrowParameters { pub start_time: u64, pub frequency: u64, - pub cliff_amount: u64, + pub initial_unlock_amount: u64, pub amount_per_period: u64, pub number_of_period: u64, pub update_recipient_mode: u8, @@ -16,7 +16,7 @@ pub struct CreateVestingEscrowParameters { impl CreateVestingEscrowParameters { pub fn get_total_deposit_amount(&self) -> Result { let total_amount = self - .cliff_amount + .initial_unlock_amount .safe_add(self.amount_per_period.safe_mul(self.number_of_period)?)?; Ok(total_amount) } @@ -66,7 +66,7 @@ pub fn handle_create_vesting_escrow( let &CreateVestingEscrowParameters { start_time, frequency, - cliff_amount, + initial_unlock_amount, amount_per_period, number_of_period, update_recipient_mode, @@ -93,7 +93,7 @@ pub fn handle_create_vesting_escrow( escrow.init( start_time, frequency, - cliff_amount, + initial_unlock_amount, amount_per_period, number_of_period, ctx.accounts.recipient.key(), @@ -119,7 +119,7 @@ pub fn handle_create_vesting_escrow( emit_cpi!(EventCreateVestingEscrow { start_time, frequency, - cliff_amount, + initial_unlock_amount, amount_per_period, number_of_period, recipient: ctx.accounts.recipient.key(), diff --git a/programs/locker/src/state/vesting_escrow.rs b/programs/locker/src/state/vesting_escrow.rs index 721aa78..277f5e5 100644 --- a/programs/locker/src/state/vesting_escrow.rs +++ b/programs/locker/src/state/vesting_escrow.rs @@ -34,8 +34,8 @@ pub struct VestingEscrow { pub start_time: u64, /// frequency pub frequency: u64, - /// cliff amount - pub cliff_amount: u64, + /// initial unlock amount + pub initial_unlock_amount: u64, /// amount per period pub amount_per_period: u64, /// number of period @@ -55,7 +55,7 @@ impl VestingEscrow { &mut self, start_time: u64, frequency: u64, - cliff_amount: u64, + initial_unlock_amount: u64, amount_per_period: u64, number_of_period: u64, recipient: Pubkey, @@ -67,7 +67,7 @@ impl VestingEscrow { ) { self.start_time = start_time; self.frequency = frequency; - self.cliff_amount = cliff_amount; + self.initial_unlock_amount = initial_unlock_amount; self.amount_per_period = amount_per_period; self.number_of_period = number_of_period; self.recipient = recipient; @@ -88,7 +88,7 @@ impl VestingEscrow { let period = period.min(self.number_of_period); let unlocked_amount = self - .cliff_amount + .initial_unlock_amount .safe_add(period.safe_mul(self.amount_per_period)?)?; Ok(unlocked_amount) @@ -121,26 +121,26 @@ mod escrow_test { start_time in 1..=u64::MAX/2, frequency in 1..2592000u64, number_of_period in 0..10000u64, - cliff_amount in 0..u64::MAX / 100, + initial_unlock_amount in 0..u64::MAX / 100, amount_per_period in 0..u64::MAX / 10000, ) { let mut escrow = VestingEscrow::default(); escrow.start_time = start_time; escrow.frequency = frequency; escrow.number_of_period = number_of_period; - escrow.cliff_amount = cliff_amount; + escrow.initial_unlock_amount = initial_unlock_amount; escrow.amount_per_period = amount_per_period; let unlocked_amount = escrow.get_max_unlocked_amount(start_time - 1).unwrap(); assert_eq!(unlocked_amount, 0); let unlocked_amount = escrow.get_max_unlocked_amount(start_time).unwrap(); - assert_eq!(unlocked_amount, cliff_amount); + assert_eq!(unlocked_amount, initial_unlock_amount); let unlocked_amount = escrow .get_max_unlocked_amount(start_time + frequency * 1) .unwrap(); - assert_eq!(unlocked_amount, cliff_amount + amount_per_period * 1); + assert_eq!(unlocked_amount, initial_unlock_amount + amount_per_period * 1); let unlocked_amount = escrow .get_max_unlocked_amount(start_time + frequency * number_of_period - 1) @@ -151,7 +151,7 @@ mod escrow_test { 0 ); } else { - assert_eq!(unlocked_amount, cliff_amount+ amount_per_period * (number_of_period-1)); + assert_eq!(unlocked_amount, initial_unlock_amount+ amount_per_period * (number_of_period-1)); } let unlocked_amount = escrow @@ -159,7 +159,7 @@ mod escrow_test { .unwrap(); assert_eq!( unlocked_amount, - cliff_amount + amount_per_period * number_of_period + initial_unlock_amount + amount_per_period * number_of_period ); let unlocked_amount = escrow @@ -167,7 +167,7 @@ mod escrow_test { .unwrap(); assert_eq!( unlocked_amount, - cliff_amount + amount_per_period * number_of_period + initial_unlock_amount + amount_per_period * number_of_period ); } } diff --git a/tests/escrow_metadata.ts b/tests/escrow_metadata.ts index 4751162..3ea2709 100644 --- a/tests/escrow_metadata.ts +++ b/tests/escrow_metadata.ts @@ -84,7 +84,7 @@ describe("Escrow metadata", () => { isAssertion: true, startTime, frequency: new BN(1), - cliffAmount: new BN(100_000), + initialUnlockAmount: new BN(100_000), amountPerPeriod: new BN(50_000), numberOfPeriod: new BN(2), recipient: ReceipentKP.publicKey, diff --git a/tests/locker.ts b/tests/locker.ts index 4540e6a..94c7703 100644 --- a/tests/locker.ts +++ b/tests/locker.ts @@ -102,7 +102,7 @@ describe("Full flow", () => { isAssertion: true, startTime, frequency: new BN(1), - cliffAmount: new BN(100_000), + initialUnlockAmount: new BN(100_000), amountPerPeriod: new BN(50_000), numberOfPeriod: new BN(2), recipient: ReceipentKP.publicKey, diff --git a/tests/locker_utils/index.ts b/tests/locker_utils/index.ts index 5abf821..2a7187a 100644 --- a/tests/locker_utils/index.ts +++ b/tests/locker_utils/index.ts @@ -54,7 +54,7 @@ export interface CreateVestingPlanParams { isAssertion: boolean, startTime: BN, frequency: BN, - cliffAmount: BN, + initialUnlockAmount: BN, amountPerPeriod: BN, numberOfPeriod: BN, recipient: web3.PublicKey, @@ -62,7 +62,7 @@ export interface CreateVestingPlanParams { } export async function createVestingPlan(params: CreateVestingPlanParams) { - let { isAssertion, tokenMint, ownerKeypair, startTime, frequency, cliffAmount, amountPerPeriod, numberOfPeriod, recipient, updateRecipientMode } = params; + let { isAssertion, tokenMint, ownerKeypair, startTime, frequency, initialUnlockAmount, amountPerPeriod, numberOfPeriod, recipient, updateRecipientMode } = params; const program = createLockerProgram(new Wallet(ownerKeypair)); const baseKP = web3.Keypair.generate(); @@ -87,7 +87,7 @@ export async function createVestingPlan(params: CreateVestingPlanParams) { await program.methods.createVestingEscrow({ startTime, frequency, - cliffAmount, + initialUnlockAmount, amountPerPeriod, numberOfPeriod, updateRecipientMode, @@ -117,7 +117,7 @@ export async function createVestingPlan(params: CreateVestingPlanParams) { const escrowState = await program.account.vestingEscrow.fetch(escrow); expect(escrowState.startTime.toString()).eq(startTime.toString()); expect(escrowState.frequency.toString()).eq(frequency.toString()); - expect(escrowState.cliffAmount.toString()).eq(cliffAmount.toString()); + expect(escrowState.initialUnlockAmount.toString()).eq(initialUnlockAmount.toString()); expect(escrowState.amountPerPeriod.toString()).eq(amountPerPeriod.toString()); expect(escrowState.numberOfPeriod.toString()).eq(numberOfPeriod.toString()); expect(escrowState.recipient.toString()).eq(recipient.toString()); diff --git a/tests/update_recipient.ts b/tests/update_recipient.ts index 16712d9..362cff6 100644 --- a/tests/update_recipient.ts +++ b/tests/update_recipient.ts @@ -85,7 +85,7 @@ describe("Update recipient", () => { isAssertion: true, startTime, frequency: new BN(1), - cliffAmount: new BN(100_000), + initialUnlockAmount: new BN(100_000), amountPerPeriod: new BN(50_000), numberOfPeriod: new BN(2), recipient: ReceipentKP.publicKey, @@ -125,7 +125,7 @@ describe("Update recipient", () => { isAssertion: true, startTime, frequency: new BN(1), - cliffAmount: new BN(100_000), + initialUnlockAmount: new BN(100_000), amountPerPeriod: new BN(50_000), numberOfPeriod: new BN(2), recipient: ReceipentKP.publicKey, @@ -164,7 +164,7 @@ describe("Update recipient", () => { isAssertion: true, startTime, frequency: new BN(1), - cliffAmount: new BN(100_000), + initialUnlockAmount: new BN(100_000), amountPerPeriod: new BN(50_000), numberOfPeriod: new BN(2), recipient: ReceipentKP.publicKey, @@ -202,7 +202,7 @@ describe("Update recipient", () => { isAssertion: true, startTime, frequency: new BN(1), - cliffAmount: new BN(100_000), + initialUnlockAmount: new BN(100_000), amountPerPeriod: new BN(50_000), numberOfPeriod: new BN(2), recipient: ReceipentKP.publicKey, @@ -238,7 +238,7 @@ describe("Update recipient", () => { isAssertion: true, startTime, frequency: new BN(1), - cliffAmount: new BN(100_000), + initialUnlockAmount: new BN(100_000), amountPerPeriod: new BN(50_000), numberOfPeriod: new BN(2), recipient: ReceipentKP.publicKey,