Skip to content
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
3 changes: 3 additions & 0 deletions programs/wewe-token-launch-pad/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,7 @@ pub enum ProposalError {

#[msg("Liquidity cannot be zero. Ensure base_amount and quote_amount are non-zero and sqrt_price is within valid range.")]
LiquidityCannotBeZero,

#[msg("Insufficient funds in vault to cover proposal requirements")]
InsufficientFunds,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
use anchor_lang::prelude::*;
use anchor_spl::token_interface::{TokenAccount, TokenInterface};
use anchor_spl::token::{Mint, Token};

use crate::{
constant::{
seeds::{TOKEN_VAULT, VAULT_AUTHORITY},
wsol_pubkey,
MINT_DECIMALS,
},
errors::ProposalError,
state::proposal::Proposal,
};

#[derive(Accounts)]
pub struct ResetPoolLaunch<'info> {
pub authority: Signer<'info>,

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

#[account(mut)]
pub proposal: Account<'info, Proposal>,

/// CHECK: vault authority
#[account(
mut,
seeds = [VAULT_AUTHORITY.as_ref()],
bump,
)]
pub vault_authority: SystemAccount<'info>,

#[account(
mut,
seeds = [TOKEN_VAULT, vault_authority.key().as_ref(), wsol_pubkey::ID.as_ref()],
bump,
token::mint = quote_mint,
token::authority = vault_authority,
)]
pub wsol_vault: Box<InterfaceAccount<'info, TokenAccount>>,

/// CHECK: quote token mint (WSOL)
#[account(
address = wsol_pubkey::ID @ ProposalError::IncorrectAccount
)]
pub quote_mint: UncheckedAccount<'info>,

#[account(
init,
payer = payer,
mint::decimals = MINT_DECIMALS,
mint::authority = proposal.key(),
mint::freeze_authority = proposal.key(),
)]
pub mint_account: Account<'info, Mint>,

#[account(
init,
seeds = [TOKEN_VAULT, vault_authority.key().as_ref(), mint_account.key().as_ref()],
payer = payer,
token::mint = mint_account,
token::authority = vault_authority,
token::token_program = token_program,
bump,
)]
pub token_vault: Box<InterfaceAccount<'info, TokenAccount>>,

pub token_program: Interface<'info, TokenInterface>,
pub system_program: Program<'info, System>,
}

impl<'info> ResetPoolLaunch<'info> {
pub fn handle_reset_pool_launch(&mut self) -> Result<()> {

// Check that pool is currently launched
require!(
self.proposal.is_pool_launched,
ProposalError::PoolNotInitialized
);

// Check that WSOL vault has enough funds to cover the proposal's total_backing
require!(
self.wsol_vault.amount >= self.proposal.total_backing,
ProposalError::InsufficientFunds
);

// Reset the pool launch flag
self.proposal.is_pool_launched = false;

// Update the mint account (use the initialized mint account's key)
self.proposal.mint_account = self.mint_account.key();

// Optionally reset launch_timestamp (set to None)
self.proposal.launch_timestamp = None;

Ok(())
}
}

4 changes: 3 additions & 1 deletion programs/wewe-token-launch-pad/src/instructions/admin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub mod ix_start_milestone;
pub mod ix_end_milestone;
pub mod ix_set_config;
pub mod ix_emergency_unlock;
pub mod ix_reset_pool_launch;

pub use ix_reject_proposal::*;
pub use ix_snapshot::*;
Expand All @@ -14,4 +15,5 @@ pub use ix_collect_pool_fees::*;
pub use ix_start_milestone::*;
pub use ix_end_milestone::*;
pub use ix_set_config::*;
pub use ix_emergency_unlock::*;
pub use ix_emergency_unlock::*;
pub use ix_reset_pool_launch::*;
19 changes: 19 additions & 0 deletions programs/wewe-token-launch-pad/src/instructions/ix_launch_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,25 @@ impl<'info> DammV2<'info> {
},
)?;

// Permanent lock position before initializing pool
// Note: This requires the position to exist, which is created by initialize_pool_with_dynamic_config
// If the position doesn't exist yet, this will fail. Consider moving this call after initialize_pool_with_dynamic_config
damm_v2_cpi::cpi::permanent_lock_position(
CpiContext::new_with_signer(
self.amm_program.to_account_info(),
damm_v2_cpi::cpi::accounts::PermanentLockPositionCtx {
pool: self.pool.to_account_info(),
position: self.position.to_account_info(),
position_nft_account: self.position_nft_account.to_account_info(),
owner: self.vault_authority.to_account_info(),
event_authority: self.damm_event_authority.to_account_info(),
program: self.amm_program.to_account_info(),
},
signer_seeds,
),
liquidity,
)?;

// Reload accounts after CPI to get updated balances for validation
self.token_vault.reload()?;
self.wsol_vault.reload()?;
Expand Down
5 changes: 5 additions & 0 deletions programs/wewe-token-launch-pad/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,9 @@ pub mod wewe_token_launch_pad {
ctx.accounts.handle_end_milestone()
}

#[access_control(check(&ctx.accounts.authority))]
pub fn reset_pool_launch(ctx: Context<ResetPoolLaunch>) -> Result<()> {
ctx.accounts.handle_reset_pool_launch()
}

}
Loading
Loading