diff --git a/programs/libreplex_fair_launch/src/instructions/mod.rs b/programs/libreplex_fair_launch/src/instructions/mod.rs index 6840985..6212cb8 100644 --- a/programs/libreplex_fair_launch/src/instructions/mod.rs +++ b/programs/libreplex_fair_launch/src/instructions/mod.rs @@ -41,6 +41,9 @@ pub use v2::*; pub mod raw; pub use raw::*; +pub mod toggle_freeze; +pub use toggle_freeze::*; + pub const COMPRESSED_DEPLOYMENT_TYPE: u8 = 2; pub const STANDARD_DEPLOYMENT_TYPE: u8 = 0; diff --git a/programs/libreplex_fair_launch/src/instructions/toggle_freeze.rs b/programs/libreplex_fair_launch/src/instructions/toggle_freeze.rs new file mode 100644 index 0000000..1b520b0 --- /dev/null +++ b/programs/libreplex_fair_launch/src/instructions/toggle_freeze.rs @@ -0,0 +1,69 @@ +use anchor_lang::{prelude::*, system_program}; +use anchor_spl::token_interface::{Mint, TokenAccount}; + +use crate::Deployment; + +#[derive(Accounts)] +pub struct ToggleFreeze<'info> { + #[account(seeds = ["deployment".as_ref(), deployment.ticker.as_ref()], bump)] + pub deployment: Box>, + + #[account(mint::freeze_authority = deployment)] + pub mint: Box>, + + #[account(token::mint = mint, + constraint = token_account.amount == 1)] + pub token_account: Box>, + + pub delegate: Signer<'info>, + + /// CHECK: Checked by addy + #[account(constraint = + token_program.key == &anchor_spl::token::ID || + token_program.key == &anchor_spl::token_2022::ID)] + pub token_program: UncheckedAccount<'info>, + + pub system_program: Program<'info, System>, +} + +pub fn toggle_freeze(ctx: Context) -> Result<()> { + let token_account = ctx.accounts.token_account.as_ref(); + let delegate = &ctx.accounts.delegate; + let deployment = ctx.accounts.deployment.as_ref(); + + if token_account.delegate.is_none() || token_account.delegated_amount != 1 || + token_account.delegate.as_ref().unwrap() != delegate.key { + panic!("Not delegated"); + } + + + let authority_seeds = &[ + "deployment".as_bytes(), + deployment.ticker.as_ref(), + &[ctx.bumps.deployment], + ]; + + if token_account.is_frozen() { + anchor_spl::token_interface::thaw_account( + CpiContext::new_with_signer(ctx.accounts.token_account.to_account_info(), + anchor_spl::token_interface::ThawAccount { + account: ctx.accounts.token_account.to_account_info(), + mint: ctx.accounts.mint.to_account_info(), + authority: deployment.to_account_info(), + }, + &[authority_seeds]) + )?; + } else { + anchor_spl::token_interface::freeze_account( + CpiContext::new_with_signer(ctx.accounts.token_account.to_account_info(), + anchor_spl::token_interface::FreezeAccount { + account: ctx.accounts.token_account.to_account_info(), + mint: ctx.accounts.mint.to_account_info(), + authority: deployment.to_account_info(), + }, + &[authority_seeds]) + )?; + } + + Ok(()) +} \ No newline at end of file diff --git a/programs/libreplex_fair_launch/src/lib.rs b/programs/libreplex_fair_launch/src/lib.rs index 32846eb..9824267 100644 --- a/programs/libreplex_fair_launch/src/lib.rs +++ b/programs/libreplex_fair_launch/src/lib.rs @@ -32,6 +32,10 @@ pub mod libreplex_fair_launch { instructions::deploy_token_2022(ctx) } + pub fn toggle_freeze(ctx: Context) -> Result<()> { + instructions::toggle_freeze(ctx) + } + // deploy hybrid - it's like token 2022 but with an extra metaplex // metadata for the FUNGIBLE mint only pub fn deployhybrid(ctx: Context) -> Result<()> { diff --git a/target/types/libreplex_fair_launch.ts b/target/types/libreplex_fair_launch.ts index 88587b3..489c729 100644 --- a/target/types/libreplex_fair_launch.ts +++ b/target/types/libreplex_fair_launch.ts @@ -1,5 +1,5 @@ export type LibreplexFairLaunch = { - "version": "0.3.0", + "version": "0.3.1", "name": "libreplex_fair_launch", "instructions": [ { @@ -170,6 +170,42 @@ export type LibreplexFairLaunch = { ], "args": [] }, + { + "name": "toggleFreeze", + "accounts": [ + { + "name": "deployment", + "isMut": false, + "isSigner": false + }, + { + "name": "mint", + "isMut": false, + "isSigner": false + }, + { + "name": "tokenAccount", + "isMut": false, + "isSigner": false + }, + { + "name": "delegate", + "isMut": false, + "isSigner": true + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [] + }, { "name": "deployhybrid", "accounts": [ @@ -1009,22 +1045,6 @@ export type LibreplexFairLaunch = { } ] }, - { - "name": "allowCreatorToClaimTransferFee", - "accounts": [ - { - "name": "deploymentConfig", - "isMut": true, - "isSigner": false - }, - { - "name": "payer", - "isMut": true, - "isSigner": true - } - ], - "args": [] - }, { "name": "migrateToHashlist", "accounts": [ @@ -2150,7 +2170,7 @@ export type LibreplexFairLaunch = { }; export const IDL: LibreplexFairLaunch = { - "version": "0.3.0", + "version": "0.3.1", "name": "libreplex_fair_launch", "instructions": [ { @@ -2321,6 +2341,42 @@ export const IDL: LibreplexFairLaunch = { ], "args": [] }, + { + "name": "toggleFreeze", + "accounts": [ + { + "name": "deployment", + "isMut": false, + "isSigner": false + }, + { + "name": "mint", + "isMut": false, + "isSigner": false + }, + { + "name": "tokenAccount", + "isMut": false, + "isSigner": false + }, + { + "name": "delegate", + "isMut": false, + "isSigner": true + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [] + }, { "name": "deployhybrid", "accounts": [ @@ -3160,22 +3216,6 @@ export const IDL: LibreplexFairLaunch = { } ] }, - { - "name": "allowCreatorToClaimTransferFee", - "accounts": [ - { - "name": "deploymentConfig", - "isMut": true, - "isSigner": false - }, - { - "name": "payer", - "isMut": true, - "isSigner": true - } - ], - "args": [] - }, { "name": "migrateToHashlist", "accounts": [