Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@ fn read_favorites(svm: &LiteSVM, pda: &Pubkey) -> FavoritesData {
offset += color_len;

// Vec<String> hobbies (4-byte vec length + each string)
let hobbies_count =
u32::from_le_bytes(data[offset..offset + 4].try_into().unwrap()) as usize;
let hobbies_count = u32::from_le_bytes(data[offset..offset + 4].try_into().unwrap()) as usize;
offset += 4;
let mut hobbies = Vec::with_capacity(hobbies_count);
for _ in 0..hobbies_count {
let hobby_len =
u32::from_le_bytes(data[offset..offset + 4].try_into().unwrap()) as usize;
let hobby_len = u32::from_le_bytes(data[offset..offset + 4].try_into().unwrap()) as usize;
offset += 4;
let hobby = String::from_utf8(data[offset..offset + hobby_len].to_vec()).unwrap();
offset += hobby_len;
Expand Down
7 changes: 5 additions & 2 deletions basics/pyth/anchor-v1/programs/pythexample/tests/test_pyth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,12 @@ fn setup_with_price_account(
(svm, payer, price_update_key)
}

fn read_price_instruction(price_update: anchor_lang::solana_program::pubkey::Pubkey) -> Instruction {
fn read_price_instruction(
price_update: anchor_lang::solana_program::pubkey::Pubkey,
) -> Instruction {
let ix_data = pythexample::instruction::ReadPrice {}.data();
let accounts = pythexample::accounts::ReadPriceAccountConstraints { price_update }.to_account_metas(None);
let accounts =
pythexample::accounts::ReadPriceAccountConstraints { price_update }.to_account_metas(None);
Instruction::new_with_bytes(pythexample::id(), &ix_data, accounts)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use anchor_lang::solana_program::{
};
use borsh::BorshSerialize;

use crate::{MPL_BUBBLEGUM_ID, SPLCompression};
use crate::{SPLCompression, MPL_BUBBLEGUM_ID};

/// Burn instruction discriminator from mpl-bubblegum
const BURN_DISCRIMINATOR: [u8; 8] = [116, 110, 29, 56, 107, 219, 42, 93];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ pub mod cnft_burn {
nonce: u64,
index: u32,
) -> Result<()> {
instructions::burn_cnft::handle_burn_cnft(context, root, data_hash, creator_hash, nonce, index)
instructions::burn_cnft::handle_burn_cnft(
context,
root,
data_hash,
creator_hash,
nonce,
index,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -476,11 +476,7 @@ fn create_tree_with_vault_cnft(context: &mut VaultTestContext) -> TreeWithVaultC
let proof = [empty_node(0), empty_node(1), empty_node(2)];

// Read the current root from the onchain tree account.
let tree_data = context
.svm
.get_account(&merkle_tree.pubkey())
.unwrap()
.data;
let tree_data = context.svm.get_account(&merkle_tree.pubkey()).unwrap().data;
let root = read_current_root(&tree_data);

TreeWithVaultCnft {
Expand Down Expand Up @@ -608,12 +604,8 @@ fn test_withdraw_cnft_by_authority() {
let recipient = Keypair::new();
let authority = context.authority.insecure_clone();

let withdraw_ix = build_withdraw_cnft_instruction(
&context,
authority.pubkey(),
&tree,
recipient.pubkey(),
);
let withdraw_ix =
build_withdraw_cnft_instruction(&context, authority.pubkey(), &tree, recipient.pubkey());

// The stored authority signs, so the withdraw succeeds (the vault PDA
// signs the Bubblegum CPI via invoke_signed inside the program).
Expand Down Expand Up @@ -692,12 +684,8 @@ fn test_withdraw_two_cnfts_by_authority() {

// Both trees' roots moved, so both cNFTs left the vault: replaying the
// single-tree withdraw against either tree with the cached roots fails.
let replay1 = build_withdraw_cnft_instruction(
&context,
authority.pubkey(),
&tree1,
recipient.pubkey(),
);
let replay1 =
build_withdraw_cnft_instruction(&context, authority.pubkey(), &tree1, recipient.pubkey());
let replay = send(&mut context.svm, vec![replay1], &authority, &[&authority]);
assert!(
replay.is_err(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ pub struct AddOutcomeAccountConstraints<'info> {
pub system_program: Program<'info, System>,
}

pub fn handle_add_outcome(context: Context<AddOutcomeAccountConstraints>, label: String) -> Result<()> {
pub fn handle_add_outcome(
context: Context<AddOutcomeAccountConstraints>,
label: String,
) -> Result<()> {
require!(label.len() <= MAX_LABEL_LEN, BettingError::LabelTooLong);
// Outcomes can only be added to a draft. Once `open_betting` runs, the
// field of choices is final before the first bet can land.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ pub mod cancel_event;
pub mod claim_refund;
pub mod claim_winnings;
pub mod close_losing_bet;
pub mod initialize_config;
pub mod initialize_event;
pub mod open_betting;
pub mod initialize_config;
pub mod place_bet;
pub mod settle_event;
pub mod shared;
Expand All @@ -15,9 +15,9 @@ pub use cancel_event::*;
pub use claim_refund::*;
pub use claim_winnings::*;
pub use close_losing_bet::*;
pub use initialize_config::*;
pub use initialize_event::*;
pub use open_betting::*;
pub use initialize_config::*;
pub use place_bet::*;
pub use settle_event::*;
pub use shared::*;
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ pub fn handle_settle_event(

// Winners always get their own stake back; the fee is only ever charged on
// the losing side, so a winner can never receive less than they staked.
let fee = (losing_pool as u128 * context.accounts.event.fee_bps as u128 / BPS_DENOMINATOR) as u64;
let fee =
(losing_pool as u128 * context.accounts.event.fee_bps as u128 / BPS_DENOMINATOR) as u64;
let distributable_losing_pool = losing_pool - fee;

if fee > 0 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ pub fn transfer_tokens_from_vault<'info>(
to: to.to_account_info(),
authority: event.clone(),
};
let cpi_context = CpiContext::new_with_signer(
token_program.key(),
transfer_accounts,
&signer_seeds,
);
let cpi_context =
CpiContext::new_with_signer(token_program.key(), transfer_accounts, &signer_seeds);
transfer_checked(cpi_context, amount, mint.decimals)
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ pub mod betting_market {
}

// Admin adds a possible result. Only allowed while the event is a draft.
pub fn add_outcome(context: Context<AddOutcomeAccountConstraints>, label: String) -> Result<()> {
pub fn add_outcome(
context: Context<AddOutcomeAccountConstraints>,
label: String,
) -> Result<()> {
instructions::add_outcome::handle_add_outcome(context, label)
}

Expand All @@ -63,7 +66,10 @@ pub mod betting_market {

// Admin resolves the market once betting has closed: takes the fee from the losing pool and records
// the figures winners need to claim their share.
pub fn settle_event(context: Context<SettleEventAccountConstraints>, winning_outcome_index: u8) -> Result<()> {
pub fn settle_event(
context: Context<SettleEventAccountConstraints>,
winning_outcome_index: u8,
) -> Result<()> {
instructions::settle_event::handle_settle_event(context, winning_outcome_index)
}

Expand Down
Loading
Loading