Skip to content

Commit

Permalink
format & lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mschneider committed Nov 6, 2024
1 parent ead541e commit 429df0e
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 44 deletions.
15 changes: 7 additions & 8 deletions bin/autobahn-router/src/edge_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,17 +382,16 @@ impl EdgeUpdater {
return true;
}
match &self.dex.subscription_mode {
DexSubscriptionMode::Accounts(accounts) => {
return accounts.contains(pk)
},
DexSubscriptionMode::Disabled => {
false
},
DexSubscriptionMode::Accounts(accounts) => return accounts.contains(pk),
DexSubscriptionMode::Disabled => false,
DexSubscriptionMode::Programs(programs) => {
programs.contains(pk) || programs.contains(owner)
},
}
DexSubscriptionMode::Mixed(m) => {
m.accounts.contains(pk) || m.token_accounts_for_owner.contains(pk) || m.programs.contains(pk) || m.programs.contains(owner)
m.accounts.contains(pk)
|| m.token_accounts_for_owner.contains(pk)
|| m.programs.contains(pk)
|| m.programs.contains(owner)
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions bin/autobahn-router/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ async fn main() -> anyhow::Result<()> {
config.invariant.take_all_mints,
config.invariant.add_mango_tokens,
&config.invariant.mints
)
),
]
.into_iter()
.flatten()
Expand Down Expand Up @@ -688,7 +688,11 @@ fn handle_updated_account(
}

// ignore failing sends when there are no receivers
let _err = account_update_sender.send((account_write.pubkey, account_write.owner, account_write.slot));
let _err = account_update_sender.send((
account_write.pubkey,
account_write.owner,
account_write.slot,
));
}

match update {
Expand Down
1 change: 0 additions & 1 deletion lib/dex-invariant/src/internal/invariant-types/src/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,6 @@ pub fn cross_tick_no_fee_growth_update(tick: &Tick, pool: &mut Pool) -> Result<(
Ok(())
}


pub fn get_max_tick(tick_spacing: u16) -> TrackableResult<i32> {
let limit_by_space = TICK_LIMIT
.checked_sub(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl std::fmt::Display for TrackableError {
}
impl std::error::Error for TrackableError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
None
None
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/dex-invariant/src/internal/tickmap_slice.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

13 changes: 8 additions & 5 deletions lib/dex-invariant/src/invariant_dex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use std::{
};

use anchor_lang::{AnchorDeserialize, Id};

Check warning on line 6 in lib/dex-invariant/src/invariant_dex.rs

View workflow job for this annotation

GitHub Actions / Router full build

unused import: `Id`

Check warning on line 6 in lib/dex-invariant/src/invariant_dex.rs

View workflow job for this annotation

GitHub Actions / Router full build

unused import: `Id`

Check warning on line 6 in lib/dex-invariant/src/invariant_dex.rs

View workflow job for this annotation

GitHub Actions / Router full build

unused import: `Id`

Check warning on line 6 in lib/dex-invariant/src/invariant_dex.rs

View workflow job for this annotation

GitHub Actions / Router full build

unused import: `Id`
use anchor_spl::{token::spl_token::{self, state::AccountState}, token_2022::Token2022};
use anchor_spl::{
token::spl_token::{self, state::AccountState},
token_2022::Token2022,

Check warning on line 9 in lib/dex-invariant/src/invariant_dex.rs

View workflow job for this annotation

GitHub Actions / Router full build

unused import: `token_2022::Token2022`

Check warning on line 9 in lib/dex-invariant/src/invariant_dex.rs

View workflow job for this annotation

GitHub Actions / Router full build

unused import: `token_2022::Token2022`

Check warning on line 9 in lib/dex-invariant/src/invariant_dex.rs

View workflow job for this annotation

GitHub Actions / Router full build

unused import: `token_2022::Token2022`

Check warning on line 9 in lib/dex-invariant/src/invariant_dex.rs

View workflow job for this annotation

GitHub Actions / Router full build

unused import: `token_2022::Token2022`
};
use anyhow::{Context, Ok};
use async_trait::async_trait;
use invariant_types::{
Expand Down Expand Up @@ -243,10 +246,10 @@ impl DexInterface for InvariantDex {
let banned_reserves = vaults
.iter()
.filter(|(_, reserve)| {
spl_token::state::Account::unpack(reserve.data())
.unwrap()
.state
== AccountState::Frozen
spl_token::state::Account::unpack(reserve.data())
.unwrap()
.state
== AccountState::Frozen
})
.map(|(pk, _)| pk)
.collect::<HashSet<_>>();
Expand Down
6 changes: 5 additions & 1 deletion lib/dex-invariant/src/invariant_ix_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ pub fn build_swap_ix(
let destination_owner = dest_acc.owner();
let (source_account, destination_account) = (
get_associated_token_address_with_program_id(wallet_pk, &source_mint, &source_owner),
get_associated_token_address_with_program_id(wallet_pk, &destination_mint, &destination_owner)
get_associated_token_address_with_program_id(
wallet_pk,
&destination_mint,
&destination_owner,
),
);

let sqrt_price_limit = if id.x_to_y {
Expand Down
4 changes: 1 addition & 3 deletions lib/dex-orca/src/orca_dex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,7 @@ impl OrcaDex {
// TODO: actually need to dynamically adjust subscriptions based on the tick?
let tick_arrays = filtered_pools
.iter()
.map(|(pk, wp)| {
whirlpool_tick_array_pks(wp, pk, program_id)
})
.map(|(pk, wp)| whirlpool_tick_array_pks(wp, pk, program_id))
.collect_vec();

let edge_pairs = filtered_pools
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ pub fn execute_swap_v3(
}

emit_stack(SwapEvent {
input_mint: input_mint,
input_amount: input_amount,
output_mint: output_mint,
output_amount: output_amount,
input_mint,
input_amount,
output_mint,
output_amount,
})?;

if in_amount < min_out_amount {
Expand Down
3 changes: 2 additions & 1 deletion programs/autobahn-executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ pub mod token;
pub mod utils;

use instructions::{
execute_charge_fees, execute_charge_fees_v2, execute_create_referral, execute_openbook_v2_swap, execute_swap_v2, execute_swap_v3, execute_withdraw_referral_fees
execute_charge_fees, execute_charge_fees_v2, execute_create_referral, execute_openbook_v2_swap,
execute_swap_v2, execute_swap_v3, execute_withdraw_referral_fees,
};
use solana_program::declare_id;
use solana_program::entrypoint::ProgramResult;
Expand Down
35 changes: 17 additions & 18 deletions programs/autobahn-executor/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ use spl_token_2022::extension::{BaseStateWithExtensions, ExtensionType, StateWit
use crate::create_pda::create_pda_account;

pub fn get_balance(account: &AccountInfo) -> Result<u64, ProgramError> {
match account.owner {
&spl_token::ID => {
match *account.owner {
spl_token::ID => {
let token = spl_token::state::Account::unpack(&account.try_borrow_data()?)?;
Ok(token.amount)
}
&spl_token_2022::ID => {
spl_token_2022::ID => {
let token = spl_token_2022::state::Account::unpack(&account.try_borrow_data()?)?;
Ok(token.amount)
}
Expand All @@ -24,12 +24,12 @@ pub fn get_balance(account: &AccountInfo) -> Result<u64, ProgramError> {
}

pub fn get_mint(account: &AccountInfo) -> Result<Pubkey, ProgramError> {
match account.owner {
&spl_token::ID => {
match *account.owner {
spl_token::ID => {
let token = spl_token::state::Account::unpack(&account.try_borrow_data()?)?;
Ok(token.mint)
}
&spl_token_2022::ID => {
spl_token_2022::ID => {
let token: spl_token_2022::state::Account =
spl_token_2022::state::Account::unpack(&account.try_borrow_data()?)?;
Ok(token.mint)
Expand All @@ -39,12 +39,12 @@ pub fn get_mint(account: &AccountInfo) -> Result<Pubkey, ProgramError> {
}

pub fn get_owner(account: &AccountInfo) -> Result<Pubkey, ProgramError> {
match account.owner {
&spl_token::ID => {
match *account.owner {
spl_token::ID => {
let token = spl_token::state::Account::unpack(&account.try_borrow_data()?)?;
Ok(token.owner)
}
&spl_token_2022::ID => {
spl_token_2022::ID => {
let token: spl_token_2022::state::Account =
spl_token_2022::state::Account::unpack(&account.try_borrow_data()?)?;
Ok(token.owner)
Expand All @@ -61,9 +61,9 @@ pub fn intialize<'a>(
account: &AccountInfo<'a>,
seeds: &[&[u8]],
) -> Result<(), ProgramError> {
let space = match account.owner {
&spl_token::ID => Ok(spl_token::state::Account::LEN),
&spl_token_2022::ID => {
let space = match *account.owner {
spl_token::ID => Ok(spl_token::state::Account::LEN),
spl_token_2022::ID => {
let mint_data = mint.data.borrow();
let mint_with_extension =
StateWithExtensions::<spl_token_2022::state::Mint>::unpack(&mint_data).unwrap();
Expand Down Expand Up @@ -127,9 +127,8 @@ pub fn transfer<'a>(
}
spl_token_2022::ID => {
let mint_data = mint.try_borrow_data()?;
let mint_parsed = StateWithExtensions::<
spl_token_2022::state::Mint,
>::unpack(&mint_data)?;
let mint_parsed =
StateWithExtensions::<spl_token_2022::state::Mint>::unpack(&mint_data)?;
let transfer_ix = spl_token_2022::instruction::transfer_checked(
program.key,
source.key,
Expand All @@ -153,8 +152,8 @@ pub fn transfer<'a>(

pub fn verify_program_id(address: &Pubkey) -> Result<(), ProgramError> {
if spl_token::ID.eq(address) || spl_token_2022::ID.eq(address) {
return Ok(());
Ok(())
} else {
return Err(ProgramError::IncorrectProgramId);
Err(ProgramError::IncorrectProgramId)
}
}
}

0 comments on commit 429df0e

Please sign in to comment.