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
20 changes: 16 additions & 4 deletions packages/program/programs/autofun/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ pub enum PumpfunError {

#[msg("Incorrect team wallet address")]
IncorrectTeamWallet,

#[msg("Curve is not completed")]
CurveNotCompleted,

#[msg("Can not swap after the curve is completed")]
CurveAlreadyCompleted,

#[msg("Mint authority should be revoked")]
MintAuthorityEnabled,

#[msg("Freeze authority should be revoked")]
FreezeAuthorityEnabled,

Expand All @@ -48,4 +48,16 @@ pub enum PumpfunError {

#[msg("Decimal overflow")]
DecimalOverflow,

#[msg("Exceeds Max Sell Amount")]
ExceedsMaxSellAMount,

#[msg("Exceeds Max Buy Amount")]
ExceedsMaxBuyAmount,

#[msg("Trade Too Early")]
TradeTooEarly,

#[msg("Over Set Time")]
OverSetTime,
}
16 changes: 15 additions & 1 deletion packages/program/programs/autofun/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,18 @@ pub struct CompleteEvent {
pub user: Pubkey,
pub mint: Pubkey,
pub bonding_curve: Pubkey,
}
}

#[event]
pub struct InstantModeSwitched {
pub instant_trade: bool,
}

#[event]
pub struct MaxAmountsSet {
pub bonding_curve: Pubkey,
pub creator: Pubkey,
pub modified_time: i64,
pub max_buy_amount: u64,
pub max_sell_amount: u64,
}
61 changes: 28 additions & 33 deletions packages/program/programs/autofun/src/instructions/configure.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
use crate::{
constants::{CONFIG, GLOBAL},
constants::{ CONFIG, GLOBAL },
errors::*,
state::{Config, AmountConfig},
state::{ Config, AmountConfig },
utils::sol_transfer_from_user,
};
use anchor_lang::{prelude::*, system_program, Discriminator};
use anchor_spl::{
associated_token::AssociatedToken,
token::{Mint, Token, TokenAccount},
};
use anchor_lang::{ prelude::*, system_program, Discriminator };
use anchor_spl::{ associated_token::AssociatedToken, token::{ Mint, Token, TokenAccount } };
use borsh::BorshDeserialize;

#[derive(Accounts)]
Expand Down Expand Up @@ -40,9 +37,7 @@ pub struct Configure<'info> {
)]
global_wsol_account: Box<Account<'info, TokenAccount>>,

#[account(
address = spl_token::native_mint::ID
)]
#[account(address = spl_token::native_mint::ID)]
native_mint: Box<Account<'info, Mint>>,

#[account(address = system_program::ID)]
Expand All @@ -55,8 +50,10 @@ pub struct Configure<'info> {

impl<'info> Configure<'info> {
pub fn process(&mut self, new_config: Config, config_bump: u8) -> Result<()> {
let serialized_config =
[&Config::DISCRIMINATOR, new_config.try_to_vec()?.as_slice()].concat();
let serialized_config = [
&Config::DISCRIMINATOR,
new_config.try_to_vec()?.as_slice(),
].concat();
let serialized_config_len = serialized_config.len();
let config_cost = Rent::get()?.minimum_balance(serialized_config_len);

Expand All @@ -75,72 +72,70 @@ impl<'info> Configure<'info> {
}
}
}

// Init config pda if needed
if self.config.owner != &crate::ID {
let cpi_context = CpiContext::new(
self.system_program.to_account_info(),
system_program::CreateAccount {
from: self.payer.to_account_info(),
to: self.config.to_account_info(),
},
}
);

system_program::create_account(
cpi_context.with_signer(&[&[CONFIG.as_bytes(), &[config_bump]]]),
config_cost,
serialized_config_len as u64,
&crate::ID,
&crate::ID
)?;
} else {
let data = self.config.try_borrow_data()?;
if data.len() < 8 || data[0..8] != Config::DISCRIMINATOR {
return err!(PumpfunError::IncorrectConfigAccount);
}
let config = Config::deserialize(&mut &data[8..])?;

if config.authority != self.payer.key() {
return err!(PumpfunError::IncorrectAuthority);
}

// Prevent changing authority through configure instruction
if config.authority != new_config.authority {
return err!(PumpfunError::IncorrectAuthority);
}
}

let lamport_delta = (config_cost as i64) - (self.config.lamports() as i64);
if lamport_delta > 0 {
system_program::transfer(
CpiContext::new(
self.system_program.to_account_info(),
system_program::Transfer {
from: self.payer.to_account_info(),
to: self.config.to_account_info(),
},
),
lamport_delta as u64,
CpiContext::new(self.system_program.to_account_info(), system_program::Transfer {
from: self.payer.to_account_info(),
to: self.config.to_account_info(),
}),
lamport_delta as u64
)?;
}

// Always check and realloc if needed, regardless of lamport balance
if serialized_config_len > self.config.data_len() {
self.config.realloc(serialized_config_len, false)?;
}

(self.config.try_borrow_mut_data()?[..serialized_config_len])
.copy_from_slice(serialized_config.as_slice());


self.config
.try_borrow_mut_data()?
[..serialized_config_len].copy_from_slice(serialized_config.as_slice());

// Initialize global vault if needed
if self.global_vault.lamports() == 0 {
sol_transfer_from_user(
&self.payer,
self.global_vault.clone(),
&self.system_program,
890880,
890880
)?;
}

Ok(())
}
}
Loading
Loading