Skip to content

Commit

Permalink
Addition FPS fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
blockiosaurus committed Sep 12, 2024
1 parent 2473b25 commit b59bcf5
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 24 deletions.
18 changes: 11 additions & 7 deletions fixed-price-sale/program/src/processor/claim_resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::{
};
use anchor_lang::{prelude::*, solana_program::program_pack::Pack, system_program::System};
use anchor_spl::token;
use mpl_token_metadata::state::TokenMetadataAccount;

impl<'info> ClaimResource<'info> {
pub fn process(&mut self, vault_owner_bump: u8) -> Result<()> {
Expand Down Expand Up @@ -69,12 +68,17 @@ impl<'info> ClaimResource<'info> {
]];

// Update primary sale flag
let data = &metadata.data.borrow_mut();
if data.is_empty() || data[0] != mpl_token_metadata::state::Key::MetadataV1 as u8 {
return Err(ErrorCode::InvalidMetadataAccount.into());
}
let metadata_state = mpl_token_metadata::state::Metadata::deserialize(&mut data.as_ref())?;
if !metadata_state.primary_sale_happened {
let primary_sale_happened = {
let data = &metadata.data.borrow_mut();
if data.is_empty() || data[0] != mpl_token_metadata::state::Key::MetadataV1 as u8 {
return Err(ErrorCode::InvalidMetadataAccount.into());
}
let metadata_state =
mpl_token_metadata::state::Metadata::deserialize(&mut data.as_ref())?;
metadata_state.primary_sale_happened
};

if !primary_sale_happened {
mpl_update_primary_sale_happened_via_token(
&metadata.to_account_info(),
&vault_owner.to_account_info(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::{error::ErrorCode, state::SellingResourceState, utils::*, InitSellingResource};
use anchor_lang::prelude::*;
use anchor_spl::token;
use mpl_token_metadata::state::TokenMetadataAccount;

impl<'info> InitSellingResource<'info> {
pub fn process(
Expand Down Expand Up @@ -62,8 +61,12 @@ impl<'info> InitSellingResource<'info> {
}
}

let data = &master_edition_info.data.borrow();
if data.is_empty() || data[0] != mpl_token_metadata::state::Key::MasterEditionV2 as u8 {
return Err(ErrorCode::InvalidMetadataAccount.into());
}
let master_edition =
mpl_token_metadata::state::MasterEditionV2::from_account_info(master_edition_info)?;
mpl_token_metadata::state::MasterEditionV2::deserialize(&mut data.as_ref())?;

let mut actual_max_supply = max_supply;

Expand Down
1 change: 0 additions & 1 deletion fixed-price-sale/program/src/processor/withdraw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use anchor_spl::{
associated_token::{self, get_associated_token_address},
token,
};
use mpl_token_metadata::state::TokenMetadataAccount;

impl<'info> Withdraw<'info> {
pub fn process(
Expand Down
12 changes: 5 additions & 7 deletions fixed-price-sale/program/tests/buy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ mod buy {
},
};
use anchor_lang::{
error::ERROR_CODE_OFFSET, AccountDeserialize, InstructionData, ToAccountMetas,
error::ERROR_CODE_OFFSET, AccountDeserialize, AnchorDeserialize, InstructionData,
ToAccountMetas,
};
use mpl_fixed_price_sale::{
accounts as mpl_fixed_price_sale_accounts,
Expand All @@ -26,10 +27,7 @@ mod buy {
find_vault_owner_address,
},
};
use mpl_token_metadata::{
instruction::burn_edition_nft,
state::{MasterEditionV2, TokenMetadataAccount},
};
use mpl_token_metadata::{instruction::burn_edition_nft, state::MasterEditionV2};
use solana_program::{clock::Clock, instruction::AccountMeta};
use solana_program_test::*;
use solana_sdk::{
Expand Down Expand Up @@ -4330,7 +4328,7 @@ mod buy {
.unwrap()
.unwrap();
let master_edition_struct =
MasterEditionV2::safe_deserialize(&master_edition_account.data).unwrap();
MasterEditionV2::deserialize(&mut master_edition_account.data.as_slice()).unwrap();

assert_eq!(master_edition_struct.supply, 1);

Expand Down Expand Up @@ -4365,7 +4363,7 @@ mod buy {
.unwrap()
.unwrap();
let master_edition_struct =
MasterEditionV2::safe_deserialize(&master_edition_account.data).unwrap();
MasterEditionV2::deserialize(&mut master_edition_account.data.as_slice()).unwrap();

assert_eq!(master_edition_struct.supply, 0);
/* BURN ENDED */
Expand Down
11 changes: 4 additions & 7 deletions fixed-price-sale/program/tests/buy_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mod buy_v2 {
setup_functions::{setup_selling_resource, setup_store},
},
};
use anchor_lang::{AccountDeserialize, InstructionData, ToAccountMetas};
use anchor_lang::{AccountDeserialize, AnchorDeserialize, InstructionData, ToAccountMetas};
use mpl_fixed_price_sale::{
accounts as mpl_fixed_price_sale_accounts, instruction as mpl_fixed_price_sale_instruction,
state::{SellingResource, TradeHistory},
Expand All @@ -21,10 +21,7 @@ mod buy_v2 {
find_vault_owner_address,
},
};
use mpl_token_metadata::{
instruction::burn_edition_nft,
state::{MasterEditionV2, TokenMetadataAccount},
};
use mpl_token_metadata::{instruction::burn_edition_nft, state::MasterEditionV2};
use solana_program::clock::Clock;
use solana_program_test::*;
use solana_sdk::{
Expand Down Expand Up @@ -315,7 +312,7 @@ mod buy_v2 {
.unwrap()
.unwrap();
let master_edition_struct =
MasterEditionV2::safe_deserialize(&master_edition_account.data).unwrap();
MasterEditionV2::deserialize(&mut master_edition_account.data.as_slice()).unwrap();

assert_eq!(master_edition_struct.supply, 1);

Expand Down Expand Up @@ -350,7 +347,7 @@ mod buy_v2 {
.unwrap()
.unwrap();
let master_edition_struct =
MasterEditionV2::safe_deserialize(&master_edition_account.data).unwrap();
MasterEditionV2::deserialize(&mut master_edition_account.data.as_slice()).unwrap();

assert_eq!(master_edition_struct.supply, 0); /* BURN ENDED */

Expand Down

0 comments on commit b59bcf5

Please sign in to comment.