Skip to content
Open
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
67 changes: 8 additions & 59 deletions programs/vault-stake/src/account_structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,6 @@ pub struct Pause<'info> {
pub signer: Signer<'info>,
}

#[derive(Accounts)]
pub struct UpdateConfig<'info> {
#[account(
mut,
seeds = [b"stake_config"],
bump = stake_config.bump
)]
pub stake_config: Account<'info, StakeConfig>,

/// CHECK: This is the program data account that contains the update authority
#[account(
constraint = program_data.key() == get_program_data_address(&crate::id()) @ CustomErrorCode::InvalidProgramData
)]
pub program_data: UncheckedAccount<'info>,

pub signer: Signer<'info>,
}

#[derive(Accounts)]
pub struct Deposit<'info> {
#[account(
Expand Down Expand Up @@ -172,46 +154,10 @@ pub struct Deposit<'info> {
pub token_program: Program<'info, Token>,
}

#[derive(Accounts)]
pub struct Unbond<'info> {
#[account(
seeds = [b"stake_config"],
bump = stake_config.bump
)]
pub stake_config: Account<'info, StakeConfig>,

#[account(mut)]
pub signer: Signer<'info>,

#[account(
constraint = mint.key() == stake_config.mint @ CustomErrorCode::InvalidMint
)]
pub mint: Account<'info, Mint>,

#[account(
token::mint = stake_config.mint,
constraint = user_mint_token_account.mint == stake_config.mint @ CustomErrorCode::InvalidMint,
constraint = user_mint_token_account.owner == signer.key() @ CustomErrorCode::InvalidMintAuthority

)]
pub user_mint_token_account: Account<'info, TokenAccount>,

#[account(
init,
payer = signer,
space = UnbondingTicket::LEN,
seeds = [b"ticket", signer.key().as_ref()],
bump
)]
pub ticket: Account<'info, UnbondingTicket>,

pub system_program: Program<'info, System>,
}

#[derive(Accounts)]
pub struct Redeem<'info> {
#[account(
seeds = [b"stake_config"],
seeds = [b"stake_config"],
bump = stake_config.bump
)]
pub stake_config: Account<'info, StakeConfig>,
Expand Down Expand Up @@ -245,27 +191,30 @@ pub struct Redeem<'info> {
#[account(mut)]
pub signer: Signer<'info>,

/// Optional legacy unbonding ticket from the old two-step flow.
/// If present (pass the ticket PDA address), it will be closed and rent returned to signer.
/// If no ticket exists, pass the program's own ID — Anchor 0.31 treats it as None and skips all constraints.
#[account(
mut,
close = signer, // return rent to user when done
close = signer,
seeds = [b"ticket", signer.key().as_ref()],
bump,
)]
pub ticket: Account<'info, UnbondingTicket>,
pub ticket: Option<Account<'info, UnbondingTicket>>,

#[account(
mut,
token::mint = stake_config.vault,
constraint = user_vault_token_account.mint == stake_config.vault @ CustomErrorCode::InvalidVaultMint,
constraint = user_vault_token_account.owner == signer.key() @ CustomErrorCode::InvalidTicketOwner
constraint = user_vault_token_account.owner == signer.key() @ CustomErrorCode::InvalidTokenOwner
)]
pub user_vault_token_account: Account<'info, TokenAccount>,

#[account(
mut,
token::mint = stake_config.mint,
constraint = user_mint_token_account.mint == stake_config.mint @ CustomErrorCode::InvalidMint,
constraint = user_mint_token_account.owner == signer.key() @ CustomErrorCode::InvalidTicketOwner
constraint = user_mint_token_account.owner == signer.key() @ CustomErrorCode::InvalidTokenOwner
)]
pub user_mint_token_account: Account<'info, TokenAccount>,

Expand Down
10 changes: 0 additions & 10 deletions programs/vault-stake/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,11 @@ pub enum CustomErrorCode {
InvalidAuthority = 4,
#[msg("Insufficient balance")]
InsufficientBalance = 5,
#[msg("Unbonding period not elapsed")]
UnbondingPeriodNotElapsed = 6,
#[msg("Insufficient unbonding balance")]
InsufficientUnbondingBalance = 7,
#[msg("Unbonding is currently in progress")]
UnbondingInProgress = 8,

#[msg("Invalid mint provided")]
InvalidMint = 9,
#[msg("Invalid vault mint provided")]
InvalidVaultMint = 10,
#[msg("Invalid ticket owner")]
InvalidTicketOwner = 11,

#[msg("Invalid mint authority")]
InvalidMintAuthority = 12,
Expand Down Expand Up @@ -52,8 +44,6 @@ pub enum CustomErrorCode {
VaultAndMintCannotBeSame = 26,
#[msg("Protocol is paused")]
ProtocolPaused = 27,
#[msg("Invalid bonding period")]
InvalidBondingPeriod = 28,
#[msg("Invalid token owner")]
InvalidTokenOwner = 29,
#[msg("Invalid mint program owner")]
Expand Down
17 changes: 0 additions & 17 deletions programs/vault-stake/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ pub struct DepositEvent {
pub totals_last_update_slot: u64,
}

#[event]
pub struct UnbondEvent {
pub user: Pubkey,
pub amount: u64,
pub mint: Pubkey,
pub vault: Pubkey,
}

#[event]
pub struct RedeemEvent {
pub user: Pubkey,
Expand All @@ -37,15 +29,6 @@ pub struct RedeemEvent {
pub totals_last_update_slot: u64,
}

#[event]
pub struct UnbondingPeriodUpdated {
pub admin: Pubkey,
pub old_period: i64,
pub new_period: i64,
pub mint: Pubkey,
pub vault: Pubkey,
}

#[event]
pub struct RewardsPublished {
pub admin: Pubkey,
Expand Down
52 changes: 15 additions & 37 deletions programs/vault-stake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub mod account_structs;
///
/// 1. Initial Setup:
/// - Admin creates two token types: Vault (wYLDS), Stake (PRIME)
/// - Admin initializes program with token addresses and unbonding period
/// - Admin initializes program with token addresses
/// - Admin configures vault token account to hold deposited tokens
///
/// 2. User Staking Flow:
Expand All @@ -15,22 +15,15 @@ pub mod account_structs;
/// - User receives stake tokens (PRIME) based on their wYLDS pool share
///
/// 3. Withdrawal Flow:
/// a. Unbonding Initiation:
/// - User initiates withdrawal by burning stake tokens (PRIME)
/// - System creates an unbonding ticket attached to the user
/// - Unbonding period timer starts
///
/// b. Waiting Period:
/// - User holds an unbonding ticket during lock period
/// - Can query remaining time via status check
///
/// c. Redemption:
/// - After the unbonding period expires, the user can redeem
/// - Vault tokens (wYLDS) returned to user based on their minted PRIME share
/// - Unbonding ticket is invalidated
/// - User calls redeem(amount) with the amount of PRIME to burn
/// - Program computes wYLDS owed using virtual shares formula
/// - PRIME is burned; wYLDS is transferred to user immediately
/// - Any legacy unbonding ticket from v1 is automatically closed (rent returned)
/// when the optional ticket account is provided
///
/// 4. Administrative Functions:
/// - Update token configurations if needed
/// - Pause/unpause protocol operations
/// - Update freeze and rewards administrators
/// - Monitor vault token accounts
///
/// Security is maintained through PDAs (Program Derived Addresses) and strict
Expand All @@ -54,16 +47,13 @@ pub mod vault_stake {
/// Initializes the vault program with the required token configurations:
/// - vault_mint: The token that users deposit (e.g., wYLDS)
/// - stake_mint: The token users receive when staking (e.g., PRIME)
/// - unbonding_period: Time in seconds users must wait before redeeming
pub fn initialize(
ctx: Context<Initialize>,
unbonding_period: i64,
freeze_administrators: Vec<Pubkey>,
rewards_administrators: Vec<Pubkey>,
) -> Result<()> {
processor::initialize(
ctx,
unbonding_period,
freeze_administrators,
rewards_administrators,
)
Expand All @@ -74,12 +64,6 @@ pub mod vault_stake {
pub fn pause(ctx: Context<Pause>, pause: bool) -> Result<()> {
processor::pause(ctx, pause)
}

/// Updates the program configuration with new token addresses:
/// - new_unbonding_period: New unbonding period in seconds
pub fn update_config(ctx: Context<UpdateConfig>, new_unbonding_period: i64) -> Result<()> {
processor::update_config(ctx, new_unbonding_period)
}

/// Handles user deposits of vault tokens (e.g., wYLDS):
/// - Transfers vault tokens to program vault account
Expand All @@ -88,18 +72,12 @@ pub mod vault_stake {
processor::deposit(ctx, amount)
}

/// Initiates the unbonding process:
/// - Burns user's stake tokens (e.g., PRIME)
/// - Starts unbonding period timer via user ticket
pub fn unbond(ctx: Context<Unbond>, amount: u64) -> Result<()> {
processor::unbond(ctx, amount)
}

/// Completes the unbonding process after the period expires:
/// - Burns unbonding tokens (e.g., uwYLDS)
/// - Returns vault tokens (e.g., wYLDS) to user
pub fn redeem(ctx: Context<Redeem>) -> Result<()> {
processor::redeem(ctx)
/// Redeems stake tokens (PRIME) for vault tokens (wYLDS):
/// - Burns the specified amount of PRIME from the user's account
/// - Transfers the proportional wYLDS from the vault to the user immediately
/// - Optionally closes a legacy unbonding ticket (from v1) and returns rent to user
pub fn redeem(ctx: Context<Redeem>, amount: u64) -> Result<()> {
processor::redeem(ctx, amount)
}

pub fn update_freeze_administrators(
Expand Down Expand Up @@ -140,7 +118,7 @@ pub mod vault_stake {
}

pub fn exchange_rate(ctx: Context<ConversionView>) -> Result<u64> {
processor::exchange_rate(ctx)
processor::exchange_rate(ctx)
}

}
Loading