Skip to content

Commit

Permalink
Freeze (#100)
Browse files Browse the repository at this point in the history
* Toggle freeze

* Freeze endpoint
  • Loading branch information
FallingHazard authored May 10, 2024
1 parent 3c4aecd commit 937b757
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 34 deletions.
3 changes: 3 additions & 0 deletions programs/libreplex_fair_launch/src/instructions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
69 changes: 69 additions & 0 deletions programs/libreplex_fair_launch/src/instructions/toggle_freeze.rs
Original file line number Diff line number Diff line change
@@ -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<'info, Deployment>>,

#[account(mint::freeze_authority = deployment)]
pub mint: Box<InterfaceAccount<'info, Mint>>,

#[account(token::mint = mint,
constraint = token_account.amount == 1)]
pub token_account: Box<InterfaceAccount<'info, TokenAccount>>,

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<ToggleFreeze>) -> 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(())
}
4 changes: 4 additions & 0 deletions programs/libreplex_fair_launch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ pub mod libreplex_fair_launch {
instructions::deploy_token_2022(ctx)
}

pub fn toggle_freeze(ctx: Context<ToggleFreeze>) -> 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<DeployHybridCtx>) -> Result<()> {
Expand Down
108 changes: 74 additions & 34 deletions target/types/libreplex_fair_launch.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export type LibreplexFairLaunch = {
"version": "0.3.0",
"version": "0.3.1",
"name": "libreplex_fair_launch",
"instructions": [
{
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -2150,7 +2170,7 @@ export type LibreplexFairLaunch = {
};

export const IDL: LibreplexFairLaunch = {
"version": "0.3.0",
"version": "0.3.1",
"name": "libreplex_fair_launch",
"instructions": [
{
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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": [
Expand Down

0 comments on commit 937b757

Please sign in to comment.