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

rename cliff amount #8

Merged
merged 2 commits into from
Aug 7, 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion programs/locker/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "locker"
version = "0.2.1"
version = "0.2.2"
description = "Created with Anchor"
edition = "2021"
author = "[email protected]"
Expand Down
2 changes: 1 addition & 1 deletion programs/locker/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions programs/locker/src/instructions/create_vesting_escrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -16,7 +16,7 @@ pub struct CreateVestingEscrowParameters {
impl CreateVestingEscrowParameters {
pub fn get_total_deposit_amount(&self) -> Result<u64> {
let total_amount = self
.cliff_amount
.initial_unlock_amount
.safe_add(self.amount_per_period.safe_mul(self.number_of_period)?)?;
Ok(total_amount)
}
Expand Down Expand Up @@ -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,
Expand All @@ -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(),
Expand All @@ -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(),
Expand Down
24 changes: 12 additions & 12 deletions programs/locker/src/state/vesting_escrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -151,23 +151,23 @@ 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
.get_max_unlocked_amount(start_time + frequency * number_of_period)
.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
.get_max_unlocked_amount(start_time + frequency * number_of_period + 1)
.unwrap();
assert_eq!(
unlocked_amount,
cliff_amount + amount_per_period * number_of_period
initial_unlock_amount + amount_per_period * number_of_period
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/escrow_metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/locker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions tests/locker_utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ export interface CreateVestingPlanParams {
isAssertion: boolean,
startTime: BN,
frequency: BN,
cliffAmount: BN,
initialUnlockAmount: BN,
amountPerPeriod: BN,
numberOfPeriod: BN,
recipient: web3.PublicKey,
updateRecipientMode: number,
}

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();
Expand All @@ -87,7 +87,7 @@ export async function createVestingPlan(params: CreateVestingPlanParams) {
await program.methods.createVestingEscrow({
startTime,
frequency,
cliffAmount,
initialUnlockAmount,
amountPerPeriod,
numberOfPeriod,
updateRecipientMode,
Expand Down Expand Up @@ -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());
Expand Down
10 changes: 5 additions & 5 deletions tests/update_recipient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Loading