Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewsource147 committed Jan 24, 2025
1 parent 9c41d62 commit 4a7982f
Show file tree
Hide file tree
Showing 45 changed files with 1,792 additions and 108 deletions.
10 changes: 9 additions & 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ incremental = false
codegen-units = 1

[workspace.dependencies]
anchor-lang = "0.30.1"
anchor-lang = { version = "0.30.1", features = ["init-if-needed"] }
anchor-spl = "0.30.1"
anchor-client = "0.30.1"
clap = { version = "3.2.25", features = ["derive", "env"] }
Expand Down
5 changes: 3 additions & 2 deletions programs/locker/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "locker"
version = "0.3.1"
version = "0.4.0"
description = "Created with Anchor"
edition = "2021"
authors = ["andrew <[email protected]>"]
Expand All @@ -20,13 +20,14 @@ staging = []
idl-build = ["anchor-lang/idl-build", "anchor-spl/idl-build"]

[dependencies]
anchor-lang = { workspace = true, features = ["event-cpi"] }
anchor-lang = { workspace = true, features = ["event-cpi", "init-if-needed"] }
anchor-spl = { workspace = true, features = ["memo"] }
spl-transfer-hook-interface = "0.5.0"
solana-program = {workspace = true}
bytemuck = { version = "1.13.1", features = ["derive", "min_const_generics"] }
static_assertions = "1.1.0"
num_enum = "0.7.1"
merkle-verify = { path = "../../verify" }

[dev-dependencies]
proptest = "1.2.0"
9 changes: 9 additions & 0 deletions programs/locker/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,13 @@ pub enum LockerError {

#[msg("Claiming is not finished")]
ClaimingIsNotFinished,

#[msg("Invalid merkle proof")]
InvalidMerkleProof,

#[msg("Escrow is not cancelled")]
EscrowNotCancelled,

#[msg("Amount is zero")]
AmountIsZero,
}
44 changes: 44 additions & 0 deletions programs/locker/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,36 @@ pub struct EventCreateVestingEscrow {
pub escrow: Pubkey,
}

#[event]
pub struct EventCreateRootEscrow {
pub root_escrow: Pubkey,
pub max_claim_amount: u64,
pub max_escrow: u64,
pub version: u64,
pub root: [u8; 32],
}

#[event]
pub struct EventClaim {
pub amount: u64,
pub current_ts: u64,
pub escrow: Pubkey,
}

#[event]
pub struct EventClaimV3 {
pub amount: u64,
pub current_ts: u64,
pub escrow: Pubkey,
pub vesting_start_time: u64,
pub cliff_time: u64,
pub frequency: u64,
pub cliff_unlock_amount: u64,
pub amount_per_period: u64,
pub number_of_period: u64,
pub recipient: Pubkey,
}

#[event]
pub struct EventUpdateVestingEscrowRecipient {
pub escrow: Pubkey,
Expand All @@ -38,7 +61,28 @@ pub struct EventCancelVestingEscrow {
pub cancelled_at: u64,
}

#[event]
pub struct EventCancelVestingEscrowV3 {
pub escrow: Pubkey,
pub signer: Pubkey,
pub remaining_amount: u64,
pub cancelled_at: u64,
}

#[event]
pub struct EventCloseVestingEscrow {
pub escrow: Pubkey,
}

#[event]
pub struct EventCloseClaimStatus {
pub escrow: Pubkey,
pub recipient: Pubkey,
pub rent_receiver: Pubkey,
}

#[event]
pub struct EventFundRootEscrow {
pub root_escrow: Pubkey,
pub funded_amount: u64,
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ use util::{
};

use crate::safe_math::SafeMath;
use crate::util::{transfer_to_user_v2, MemoTransferContext};
use crate::util::{transfer_to_user2, MemoTransferContext};
use crate::*;

/// Accounts for [locker::cancel_vesting_escrow].
#[derive(Accounts)]
#[event_cpi]
pub struct CancelVestingEscrow<'info> {
pub struct CancelVestingEscrowCtx<'info> {
/// Escrow.
#[account(
mut,
Expand Down Expand Up @@ -69,7 +69,7 @@ pub struct CancelVestingEscrow<'info> {
pub token_program: Interface<'info, TokenInterface>,
}

impl<'info> CancelVestingEscrow<'info> {
impl<'info> CancelVestingEscrowCtx<'info> {
fn close_escrow_token(&self) -> Result<()> {
let escrow = self.escrow.load()?;
let escrow_seeds = escrow_seeds!(escrow);
Expand All @@ -89,7 +89,7 @@ impl<'info> CancelVestingEscrow<'info> {
}

pub fn handle_cancel_vesting_escrow<'c: 'info, 'info>(
ctx: Context<'_, '_, 'c, 'info, CancelVestingEscrow<'info>>,
ctx: Context<'_, '_, 'c, 'info, CancelVestingEscrowCtx<'info>>,
remaining_accounts_info: Option<RemainingAccountsInfo>,
) -> Result<()> {
let mut escrow = ctx.accounts.escrow.load_mut()?;
Expand Down Expand Up @@ -119,7 +119,7 @@ pub fn handle_cancel_vesting_escrow<'c: 'info, 'info>(
};

// Transfer the claimable amount to the recipient
transfer_to_user_v2(
transfer_to_user2(
&ctx.accounts.escrow,
&ctx.accounts.token_mint,
&ctx.accounts.escrow_token.to_account_info(),
Expand All @@ -134,7 +134,7 @@ pub fn handle_cancel_vesting_escrow<'c: 'info, 'info>(
)?;

// Transfer the remaining amount to the creator
transfer_to_user_v2(
transfer_to_user2(
&ctx.accounts.escrow,
&ctx.accounts.token_mint,
&ctx.accounts.escrow_token.to_account_info(),
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::util::{transfer_to_user_v2, MemoTransferContext};
use crate::util::{transfer_to_user2, MemoTransferContext};
use crate::*;
use anchor_spl::memo::Memo;
use anchor_spl::token_interface::{Mint, TokenAccount, TokenInterface};
Expand All @@ -8,7 +8,7 @@ use util::{

#[event_cpi]
#[derive(Accounts)]
pub struct ClaimV2<'info> {
pub struct Claim2Ctx<'info> {
/// Escrow.
#[account(
mut,
Expand Down Expand Up @@ -48,8 +48,8 @@ pub struct ClaimV2<'info> {
pub token_program: Interface<'info, TokenInterface>,
}

pub fn handle_claim_v2<'c: 'info, 'info>(
ctx: Context<'_, '_, 'c, 'info, ClaimV2<'info>>,
pub fn handle_claim2<'c: 'info, 'info>(
ctx: Context<'_, '_, 'c, 'info, Claim2Ctx<'info>>,
max_amount: u64,
remaining_accounts_info: Option<RemainingAccountsInfo>,
) -> Result<()> {
Expand All @@ -69,7 +69,7 @@ pub fn handle_claim_v2<'c: 'info, 'info>(
None => ParsedRemainingAccounts::default(),
};

transfer_to_user_v2(
transfer_to_user2(
&ctx.accounts.escrow,
&ctx.accounts.token_mint,
&ctx.accounts.escrow_token.to_account_info(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use anchor_spl::{
token_interface::{close_account, CloseAccount, Mint, TokenAccount, TokenInterface},
};
use util::{
close, harvest_fees, is_closed, parse_remaining_accounts, transfer_to_user_v2, AccountsType,
close, harvest_fees, is_closed, parse_remaining_accounts, transfer_to_user2, AccountsType,
MemoTransferContext, ParsedRemainingAccounts, TRANSFER_MEMO_CLOSE_ESCROW,
};

/// Accounts for [locker::close_vesting_escrow].
#[derive(Accounts)]
#[event_cpi]
pub struct CloseVestingEscrow<'info> {
pub struct CloseVestingEscrowCtx<'info> {
/// Escrow.
#[account(
mut,
Expand Down Expand Up @@ -54,7 +54,7 @@ pub struct CloseVestingEscrow<'info> {
}

pub fn handle_close_vesting_escrow<'c: 'info, 'info>(
ctx: Context<'_, '_, 'c, 'info, CloseVestingEscrow<'info>>,
ctx: Context<'_, '_, 'c, 'info, CloseVestingEscrowCtx<'info>>,
remaining_accounts_info: Option<RemainingAccountsInfo>,
) -> Result<()> {
let escrow = ctx.accounts.escrow.load()?;
Expand Down Expand Up @@ -87,7 +87,7 @@ pub fn handle_close_vesting_escrow<'c: 'info, 'info>(
)?,
None => ParsedRemainingAccounts::default(),
};
transfer_to_user_v2(
transfer_to_user2(
&ctx.accounts.escrow,
&ctx.accounts.token_mint,
&ctx.accounts.escrow_token,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ impl CreateVestingEscrowParameters {
vesting_escrow: &AccountLoader<VestingEscrow>,
recipient: Pubkey,
token_mint: Pubkey,
sender: Pubkey,
creator: Pubkey,
base: Pubkey,
escrow_bump: u8,
token_program_flag: TokenProgramFlag,
token_program_flag: u8,
) -> Result<()> {
self.validate()?;

Expand All @@ -70,12 +70,12 @@ impl CreateVestingEscrowParameters {
self.number_of_period,
recipient,
token_mint,
sender,
creator,
base,
escrow_bump,
self.update_recipient_mode,
self.cancel_mode,
token_program_flag.into(),
token_program_flag,
);

Ok(())
Expand Down Expand Up @@ -139,7 +139,7 @@ pub fn handle_create_vesting_escrow(
ctx.accounts.sender.key(),
ctx.accounts.base.key(),
ctx.bumps.escrow,
UseSplToken,
UseSplToken.into(),
)?;

transfer_to_escrow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ use anchor_spl::token_2022::spl_token_2022;
use anchor_spl::token_interface::{Mint, TokenAccount, TokenInterface};

use crate::util::{
calculate_transfer_fee_included_amount, parse_remaining_accounts, transfer_to_escrow_v2,
calculate_transfer_fee_included_amount, parse_remaining_accounts, transfer_to_escrow2,
validate_mint, AccountsType, ParsedRemainingAccounts,
};
use crate::TokenProgramFlag::{UseSplToken, UseToken2022};
use crate::*;

#[event_cpi]
#[derive(Accounts)]
pub struct CreateVestingEscrowV2<'info> {
pub struct CreateVestingEscrow2Ctx<'info> {
/// Base.
#[account(mut)]
pub base: Signer<'info>,
Expand Down Expand Up @@ -59,13 +59,13 @@ pub struct CreateVestingEscrowV2<'info> {
pub system_program: Program<'info, System>,
}

pub fn handle_create_vesting_escrow_v2<'c: 'info, 'info>(
ctx: Context<'_, '_, 'c, 'info, CreateVestingEscrowV2<'info>>,
pub fn handle_create_vesting_escrow2<'c: 'info, 'info>(
ctx: Context<'_, '_, 'c, 'info, CreateVestingEscrow2Ctx<'info>>,
params: &CreateVestingEscrowParameters,
remaining_accounts_info: Option<RemainingAccountsInfo>,
) -> Result<()> {
// Validate if token_mint is supported
validate_mint(&ctx.accounts.token_mint)?;
validate_mint(&ctx.accounts.token_mint, true)?;

let token_mint_info = ctx.accounts.token_mint.to_account_info();
let token_program_flag = match *token_mint_info.owner {
Expand All @@ -81,7 +81,7 @@ pub fn handle_create_vesting_escrow_v2<'c: 'info, 'info>(
ctx.accounts.sender.key(),
ctx.accounts.base.key(),
ctx.bumps.escrow,
token_program_flag,
token_program_flag.into(),
)?;

// Process remaining accounts
Expand All @@ -95,7 +95,7 @@ pub fn handle_create_vesting_escrow_v2<'c: 'info, 'info>(
None => ParsedRemainingAccounts::default(),
};

transfer_to_escrow_v2(
transfer_to_escrow2(
&ctx.accounts.sender,
&ctx.accounts.token_mint,
&ctx.accounts.sender_token,
Expand Down
21 changes: 21 additions & 0 deletions programs/locker/src/instructions/escrow_instructions/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
pub mod claim;
pub use claim::*;

pub mod create_vesting_escrow;
pub use create_vesting_escrow::*;

pub use claim2::*;
pub use create_vesting_escrow2::*;

pub mod claim2;
pub mod create_vesting_escrow2;

pub mod cancel_vesting_escrow;
pub use cancel_vesting_escrow::*;

pub use create_vesting_escrow_metadata::*;
pub use update_vesting_escrow_recipient::*;
pub mod close_vesting_escrow;
pub mod create_vesting_escrow_metadata;
pub mod update_vesting_escrow_recipient;
pub use close_vesting_escrow::*;
16 changes: 4 additions & 12 deletions programs/locker/src/instructions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
pub use claim::*;
pub use create_vesting_escrow::*;
pub use create_vesting_escrow_metadata::*;
pub use update_vesting_escrow_recipient::*;
pub mod claim;
pub mod create_vesting_escrow;
pub mod create_vesting_escrow_metadata;
pub mod update_vesting_escrow_recipient;
pub mod v2;
pub use v2::*;
pub mod close_vesting_escrow;
pub use close_vesting_escrow::*;
pub mod escrow_instructions;
pub use escrow_instructions::*;
pub mod root_escrow_instructions;
pub use root_escrow_instructions::*;
Loading

0 comments on commit 4a7982f

Please sign in to comment.