Skip to content

Commit

Permalink
anchor: match mainnet stack issue
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0ece committed Oct 3, 2024
1 parent 48396af commit f51ee51
Show file tree
Hide file tree
Showing 13 changed files with 160 additions and 190 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/post_commit_anchor_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ jobs:
run: pnpm install

- name: Build
run: pnpm run anchor-test
run: cd anchor ; anchor test -- --tools-version v1.43
1 change: 1 addition & 0 deletions anchor/Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ ledger = ".anchor/test-ledger"
rpc_port = 8899
slots_per_epoch = "32"
url = "https://api.devnet.solana.com"
deactivate_feature = ["EenyoWx9UMXYKpR8mW5Jmfmy2fRjzUtM7NduYMY8bx33"]

#
# Pricing
Expand Down
28 changes: 14 additions & 14 deletions anchor/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion anchor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ codegen-units = 1
[workspace.dependencies]
anchor-lang = { version = "0.30.1", features = ["init-if-needed", "interface-instructions"] }
anchor-spl = { version = "0.30.1", features = ["stake"] }
solana-program = "=1.18.22"
solana-program = "=1.18.23"

spl-transfer-hook-interface = "0.6.5"
spl-tlv-account-resolution = "0.6.5"
Expand Down
1 change: 1 addition & 0 deletions anchor/programs/glam/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ solana-program = { workspace = true }
spl-transfer-hook-interface = { workspace = true }
spl-tlv-account-resolution = { workspace = true }
spl-stake-pool = { workspace = true }

pyth-sdk-solana = { workspace = true }
strum = { workspace = true }
phf = { workspace = true }
Expand Down
44 changes: 28 additions & 16 deletions anchor/programs/glam/src/instructions/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ use crate::{
};
use anchor_lang::{prelude::*, system_program};
use anchor_spl::{
token_2022,
token_2022::spl_token_2022,
token_2022::spl_token_2022::{extension::ExtensionType, state::Mint as StateMint},
token_2022::{
self,
spl_token_2022::{self, extension::ExtensionType, state::Mint as StateMint},
},
token_2022_extensions::spl_token_metadata_interface,
token_interface::{Mint, Token2022},
};
Expand Down Expand Up @@ -137,7 +138,7 @@ pub struct AddShareClass<'info> {
pub manager: Signer<'info>,

pub system_program: Program<'info, System>,
pub token_program: Program<'info, Token2022>,
pub token_2022_program: Program<'info, Token2022>,
}

pub fn add_share_class_handler<'c: 'info, 'info>(
Expand Down Expand Up @@ -194,7 +195,7 @@ pub fn add_share_class_handler<'c: 'info, 'info>(
},
});
raw_openfunds.lock_up_period_in_days =
Some((share_class_metadata.lock_up_period_in_seconds / 24 * 60 * 60).to_string())
Some((1 + share_class_metadata.lock_up_period_in_seconds / 24 * 60 * 60).to_string())
} else {
raw_openfunds.lock_up_period_in_days = None;
raw_openfunds.lock_up_comment = None;
Expand Down Expand Up @@ -255,7 +256,7 @@ pub fn add_share_class_handler<'c: 'info, 'info>(
// Create mint account
system_program::create_account(
CpiContext::new_with_signer(
ctx.accounts.token_program.to_account_info(),
ctx.accounts.token_2022_program.to_account_info(),
system_program::CreateAccount {
from: ctx.accounts.manager.to_account_info(),
to: share_mint.clone(),
Expand All @@ -264,7 +265,7 @@ pub fn add_share_class_handler<'c: 'info, 'info>(
),
lamports_required,
space as u64,
&ctx.accounts.token_program.key(),
&ctx.accounts.token_2022_program.key(),
)?;

// Initialize all the extensions before calling mint2
Expand Down Expand Up @@ -319,7 +320,7 @@ pub fn add_share_class_handler<'c: 'info, 'info>(
// Invoke mint2
token_2022::initialize_mint2(
CpiContext::new(
ctx.accounts.token_program.to_account_info(),
ctx.accounts.token_2022_program.to_account_info(),
token_2022::InitializeMint2 {
mint: share_mint.clone(),
},
Expand Down Expand Up @@ -600,18 +601,21 @@ pub struct CloseShareClass<'info> {
&[share_class_id],
fund.key().as_ref()
],
bump, mint::authority = share_class, mint::token_program = token_2022_program
bump, mint::authority = share_class_mint, mint::token_program = token_2022_program
)]
share_class: InterfaceAccount<'info, Mint>,
share_class_mint: InterfaceAccount<'info, Mint>,

/// CHECK: Token2022 Transfer Hook, we manually close it
#[account(
mut,
seeds = [b"extra-account-metas", share_class.key().as_ref()],
seeds = [b"extra-account-metas", share_class_mint.key().as_ref()],
bump,
)]
pub extra_account_meta_list: UncheckedAccount<'info>,

#[account(mut)]
pub openfunds: Box<Account<'info, FundMetadataAccount>>,

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

Expand All @@ -627,7 +631,7 @@ pub fn close_share_class_handler(ctx: Context<CloseShareClass>, share_class_id:
// Note: this is redundant because close_account should check that supply == 0
// but better safe than sorry
require!(
ctx.accounts.share_class.supply == 0,
ctx.accounts.share_class_mint.supply == 0,
FundError::ShareClassNotEmpty
);

Expand All @@ -636,15 +640,15 @@ pub fn close_share_class_handler(ctx: Context<CloseShareClass>, share_class_id:
"share".as_bytes(),
&[share_class_id],
fund_key.as_ref(),
&[ctx.bumps.share_class],
&[ctx.bumps.share_class_mint],
];
let signer_seeds = &[&seeds[..]];
token_2022::close_account(CpiContext::new_with_signer(
ctx.accounts.token_2022_program.to_account_info(),
token_2022::CloseAccount {
account: ctx.accounts.share_class.to_account_info(),
account: ctx.accounts.share_class_mint.to_account_info(),
destination: ctx.accounts.manager.to_account_info(),
authority: ctx.accounts.share_class.to_account_info(),
authority: ctx.accounts.share_class_mint.to_account_info(),
},
signer_seeds,
))?;
Expand All @@ -654,11 +658,19 @@ pub fn close_share_class_handler(ctx: Context<CloseShareClass>, share_class_id:
.share_classes
.remove(share_class_id as usize);

ctx.accounts
.openfunds
.share_classes
.remove(share_class_id as usize);

close_account_info(
ctx.accounts.extra_account_meta_list.to_account_info(),
ctx.accounts.manager.to_account_info(),
)?;

msg!("Share class closed: {}", ctx.accounts.share_class.key());
msg!(
"Share class closed: {}",
ctx.accounts.share_class_mint.key()
);
Ok(())
}
Loading

0 comments on commit f51ee51

Please sign in to comment.