diff --git a/programs/mango-v4/src/error.rs b/programs/mango-v4/src/error.rs index 53b411399..65a216383 100644 --- a/programs/mango-v4/src/error.rs +++ b/programs/mango-v4/src/error.rs @@ -114,7 +114,7 @@ macro_rules! error_msg { macro_rules! require_msg { ($invariant:expr, $($arg:tt)*) => { if !($invariant) { - Err(error_msg!($($arg)*))?; + return Err(error_msg!($($arg)*)); } }; } diff --git a/programs/mango-v4/src/instructions/account_expand.rs b/programs/mango-v4/src/instructions/account_expand.rs index f7cb901b6..8492a0e9d 100644 --- a/programs/mango-v4/src/instructions/account_expand.rs +++ b/programs/mango-v4/src/instructions/account_expand.rs @@ -25,7 +25,7 @@ pub fn account_expand(ctx: Context) -> Result<()> { require_eq!(account_size, AccountSize::Small); - let new_space = MangoAccount::space(AccountSize::Large.try_into().unwrap()); + let new_space = MangoAccount::space(AccountSize::Large); let new_rent_minimum = Rent::get()?.minimum_balance(new_space); let realloc_account = ctx.accounts.account.as_ref(); @@ -52,7 +52,7 @@ pub fn account_expand(ctx: Context) -> Result<()> { // expand dynamic content, e.g. to grow token positions, we need to slide serum3orders further later, and so on.... let mut account = ctx.accounts.account.load_mut()?; - account.expand_dynamic_content(AccountSize::Large.try_into().unwrap())?; + account.expand_dynamic_content(AccountSize::Large)?; Ok(()) } diff --git a/programs/mango-v4/src/instructions/flash_loan.rs b/programs/mango-v4/src/instructions/flash_loan.rs index 5feec92a1..aea3321f1 100644 --- a/programs/mango-v4/src/instructions/flash_loan.rs +++ b/programs/mango-v4/src/instructions/flash_loan.rs @@ -224,7 +224,7 @@ pub fn flash_loan_end<'key, 'accounts, 'remaining, 'info>( vaults_with_banks[vault_index] = true; let token_account_ai = &token_accounts[vault_index]; - let token_account = Account::::try_from(&token_account_ai)?; + let token_account = Account::::try_from(token_account_ai)?; // Ensure this bank/vault combination was mentioned in the Begin instruction: // The Begin instruction only checks that End ends with the same vault accounts - diff --git a/programs/mango-v4/src/instructions/liq_token_bankruptcy.rs b/programs/mango-v4/src/instructions/liq_token_bankruptcy.rs index eee966613..f5f541da3 100644 --- a/programs/mango-v4/src/instructions/liq_token_bankruptcy.rs +++ b/programs/mango-v4/src/instructions/liq_token_bankruptcy.rs @@ -123,7 +123,7 @@ pub fn liq_token_bankruptcy( if insurance_transfer > 0 { // in the end, the liqee gets liab assets liqee_liab_active = liab_bank.deposit(liqee_liab, liab_transfer)?; - remaining_liab_loss = -liqee_liab.native(&liab_bank); + remaining_liab_loss = -liqee_liab.native(liab_bank); // move insurance assets into quote bank let group_seeds = group_seeds!(group); diff --git a/programs/mango-v4/src/instructions/liq_token_with_token.rs b/programs/mango-v4/src/instructions/liq_token_with_token.rs index 433829d8f..d912919bc 100644 --- a/programs/mango-v4/src/instructions/liq_token_with_token.rs +++ b/programs/mango-v4/src/instructions/liq_token_with_token.rs @@ -79,11 +79,11 @@ pub fn liq_token_with_token( // The main complication here is that we can't keep the liqee_asset_position and liqee_liab_position // borrows alive at the same time. Possibly adding get_mut_pair() would be helpful. let (liqee_asset_position, liqee_asset_raw_index) = liqee.token_get(asset_token_index)?; - let liqee_assets_native = liqee_asset_position.native(&asset_bank); + let liqee_assets_native = liqee_asset_position.native(asset_bank); require!(liqee_assets_native.is_positive(), MangoError::SomeError); let (liqee_liab_position, liqee_liab_raw_index) = liqee.token_get(liab_token_index)?; - let liqee_liab_native = liqee_liab_position.native(&liab_bank); + let liqee_liab_native = liqee_liab_position.native(liab_bank); require!(liqee_liab_native.is_negative(), MangoError::SomeError); // TODO why sum of both tokens liquidation fees? Add comment diff --git a/programs/mango-v4/src/instructions/perp_consume_events.rs b/programs/mango-v4/src/instructions/perp_consume_events.rs index 4bb7197f0..c55f598f4 100644 --- a/programs/mango-v4/src/instructions/perp_consume_events.rs +++ b/programs/mango-v4/src/instructions/perp_consume_events.rs @@ -48,7 +48,7 @@ pub fn perp_consume_events(ctx: Context, limit: usize) -> Res Some(ai) => { let mal: AccountLoaderDynamic = - AccountLoaderDynamic::try_from(&ai)?; + AccountLoaderDynamic::try_from(ai)?; let mut ma = mal.load_mut()?; ma.perp_execute_maker( perp_market.perp_market_index, @@ -64,7 +64,7 @@ pub fn perp_consume_events(ctx: Context, limit: usize) -> Res fill.maker, perp_market.perp_market_index as u64, fill.price, - &ma.perp_find_account(perp_market.perp_market_index).unwrap(), + ma.perp_find_account(perp_market.perp_market_index).unwrap(), &perp_market, ); } @@ -77,7 +77,7 @@ pub fn perp_consume_events(ctx: Context, limit: usize) -> Res } Some(ai) => { let mal: AccountLoaderDynamic = - AccountLoaderDynamic::try_from(&ai)?; + AccountLoaderDynamic::try_from(ai)?; let mut maker = mal.load_mut()?; match mango_account_ais.iter().find(|ai| ai.key == &fill.taker) { @@ -87,7 +87,7 @@ pub fn perp_consume_events(ctx: Context, limit: usize) -> Res } Some(ai) => { let mal: AccountLoaderDynamic = - AccountLoaderDynamic::try_from(&ai)?; + AccountLoaderDynamic::try_from(ai)?; let mut taker = mal.load_mut()?; maker.perp_execute_maker( @@ -104,7 +104,7 @@ pub fn perp_consume_events(ctx: Context, limit: usize) -> Res fill.maker, perp_market.perp_market_index as u64, fill.price, - &maker + maker .perp_find_account(perp_market.perp_market_index) .unwrap(), &perp_market, @@ -113,7 +113,7 @@ pub fn perp_consume_events(ctx: Context, limit: usize) -> Res fill.taker, perp_market.perp_market_index as u64, fill.price, - &taker + taker .perp_find_account(perp_market.perp_market_index) .unwrap(), &perp_market, @@ -155,7 +155,7 @@ pub fn perp_consume_events(ctx: Context, limit: usize) -> Res } Some(ai) => { let mal: AccountLoaderDynamic = - AccountLoaderDynamic::try_from(&ai)?; + AccountLoaderDynamic::try_from(ai)?; let mut ma = mal.load_mut()?; ma.perp_remove_order(out.owner_slot as usize, out.quantity)?; diff --git a/programs/mango-v4/src/instructions/serum3_settle_funds.rs b/programs/mango-v4/src/instructions/serum3_settle_funds.rs index 4941bf26e..a501bedac 100644 --- a/programs/mango-v4/src/instructions/serum3_settle_funds.rs +++ b/programs/mango-v4/src/instructions/serum3_settle_funds.rs @@ -187,7 +187,7 @@ pub fn charge_maybe_fees( // loan origination fees let coin_token_account = account.token_get_mut(coin_bank.token_index)?.0; - let coin_token_native = coin_token_account.native(&coin_bank); + let coin_token_native = coin_token_account.native(coin_bank); if coin_token_native.is_negative() { let actualized_loan = coin_token_native.abs().min(maybe_actualized_coin_loan); @@ -212,7 +212,7 @@ pub fn charge_maybe_fees( // loan origination fees let pc_token_account = account.token_get_mut(pc_bank.token_index)?.0; - let pc_token_native = pc_token_account.native(&pc_bank); + let pc_token_native = pc_token_account.native(pc_bank); if pc_token_native.is_negative() { let actualized_loan = pc_token_native.abs().min(maybe_actualized_pc_loan); diff --git a/programs/mango-v4/src/instructions/token_deposit.rs b/programs/mango-v4/src/instructions/token_deposit.rs index f35dceae5..5f7cc87fd 100644 --- a/programs/mango-v4/src/instructions/token_deposit.rs +++ b/programs/mango-v4/src/instructions/token_deposit.rs @@ -113,7 +113,7 @@ pub fn token_deposit(ctx: Context, amount: u64) -> Result<()> { emit!(DepositLog { mango_account: ctx.accounts.account.key(), signer: ctx.accounts.token_authority.key(), - token_index: token_index, + token_index, quantity: amount, price: oracle_price.to_bits(), }); diff --git a/programs/mango-v4/src/serum3_cpi.rs b/programs/mango-v4/src/serum3_cpi.rs index 45e84aebf..b8ef5baf6 100644 --- a/programs/mango-v4/src/serum3_cpi.rs +++ b/programs/mango-v4/src/serum3_cpi.rs @@ -11,7 +11,7 @@ use crate::error::*; use crate::state::*; /// Serum padding is "serum" + data + "padding" -fn strip_dex_padding<'a>(data: &[u8]) -> Result<&[u8]> { +fn strip_dex_padding(data: &[u8]) -> Result<&[u8]> { require!(data.len() >= 12, MangoError::SomeError); Ok(&data[5..data.len() - 7]) } @@ -117,7 +117,7 @@ pub fn load_open_orders_ref<'a>( Ok(Ref::map(strip_dex_padding_ref(acc)?, bytemuck::from_bytes)) } -pub fn load_open_orders<'a>(acc: &impl AccountReader) -> Result<&serum_dex::state::OpenOrders> { +pub fn load_open_orders(acc: &impl AccountReader) -> Result<&serum_dex::state::OpenOrders> { Ok(bytemuck::from_bytes(strip_dex_padding(acc.data())?)) } diff --git a/programs/mango-v4/src/state/bank.rs b/programs/mango-v4/src/state/bank.rs index 194a6cf08..73a0f9e33 100644 --- a/programs/mango-v4/src/state/bank.rs +++ b/programs/mango-v4/src/state/bank.rs @@ -97,7 +97,7 @@ pub struct Bank { } const_assert_eq!( size_of::(), - 32 + 16 + 32 * 3 + 16 + 16 * 6 + 8 * 2 + 16 * 16 + 8 * 2 + 2 + 1 * 2 + 4 + 256 + 32 + 16 + 32 * 3 + 16 + 16 * 6 + 8 * 2 + 16 * 16 + 8 * 2 + 2 + 1 + 1 + 4 + 256 ); const_assert_eq!(size_of::() % 8, 0); diff --git a/programs/mango-v4/src/state/dynamic_account.rs b/programs/mango-v4/src/state/dynamic_account.rs index 94fa3d0f5..d95860b91 100644 --- a/programs/mango-v4/src/state/dynamic_account.rs +++ b/programs/mango-v4/src/state/dynamic_account.rs @@ -64,7 +64,7 @@ impl DerefOrBorrow for &T { impl DerefOrBorrow<[T]> for Vec { fn deref_or_borrow(&self) -> &[T] { - &self + self } } @@ -76,13 +76,13 @@ impl DerefOrBorrow for &mut T { impl<'a, T: ?Sized> DerefOrBorrow for Ref<'a, T> { fn deref_or_borrow(&self) -> &T { - &self + self } } impl<'a, T: ?Sized> DerefOrBorrow for RefMut<'a, T> { fn deref_or_borrow(&self) -> &T { - &self + self } } @@ -153,7 +153,7 @@ impl<'info, D: DynamicAccountType> AccountLoaderDynamic<'info, D> { } /// Returns a Ref to the account data structure for reading. - pub fn load_fixed<'a>(&'a self) -> Result> { + pub fn load_fixed(&self) -> Result> { let data = self.acc_info.try_borrow_data()?; let fixed = Ref::map(data, |d| { bytemuck::from_bytes(&d[8..8 + size_of::()]) @@ -161,10 +161,9 @@ impl<'info, D: DynamicAccountType> AccountLoaderDynamic<'info, D> { Ok(fixed) } + #[allow(clippy::type_complexity)] /// Returns a Ref to the account data structure for reading. - pub fn load<'a>( - &'a self, - ) -> Result, Ref<'a, [u8]>>> { + pub fn load(&self) -> Result, Ref<[u8]>>> { let data = self.acc_info.try_borrow_data()?; let header = D::Header::from_bytes(&data[8 + size_of::()..])?; let (_, data) = Ref::map_split(data, |d| d.split_at(8)); @@ -176,9 +175,8 @@ impl<'info, D: DynamicAccountType> AccountLoaderDynamic<'info, D> { }) } - pub fn load_init<'a>( - &'a self, - ) -> Result, RefMut<'a, [u8]>>> { + #[allow(clippy::type_complexity)] + pub fn load_init(&self) -> Result, RefMut<[u8]>>> { if !self.acc_info.is_writable { return Err(ErrorCode::AccountNotMutable.into()); } @@ -202,9 +200,8 @@ impl<'info, D: DynamicAccountType> AccountLoaderDynamic<'info, D> { } /// Returns a Ref to the account data structure for reading. - pub fn load_mut<'a>( - &'a self, - ) -> Result, RefMut<'a, [u8]>>> { + #[allow(clippy::type_complexity)] + pub fn load_mut(&self) -> Result, RefMut<[u8]>>> { if !self.acc_info.is_writable { return Err(ErrorCode::AccountNotMutable.into()); } diff --git a/programs/mango-v4/src/state/group.rs b/programs/mango-v4/src/state/group.rs index 5fa039de9..f2091659f 100644 --- a/programs/mango-v4/src/state/group.rs +++ b/programs/mango-v4/src/state/group.rs @@ -35,7 +35,7 @@ pub struct Group { pub reserved: [u8; 256], } -const_assert_eq!(size_of::(), 32 * 5 + 4 + 4 + 1 * 2 + 6 + 256); +const_assert_eq!(size_of::(), 32 * 5 + 4 + 4 + 1 + 1 + 6 + 256); const_assert_eq!(size_of::() % 8, 0); impl Group { diff --git a/programs/mango-v4/src/state/health.rs b/programs/mango-v4/src/state/health.rs index fa753af5e..f28e20fe1 100644 --- a/programs/mango-v4/src/state/health.rs +++ b/programs/mango-v4/src/state/health.rs @@ -73,8 +73,8 @@ pub fn new_fixed_order_account_retriever<'a, 'info>( Ok(FixedOrderAccountRetriever { ais: ais - .into_iter() - .map(|ai| AccountInfoRef::borrow(ai)) + .iter() + .map(AccountInfoRef::borrow) .collect::>>()?, n_banks: active_token_len, begin_perp: cm!(active_token_len * 2), @@ -93,11 +93,7 @@ impl FixedOrderAccountRetriever { fn oracle_price(&self, account_index: usize, bank: &Bank) -> Result { let oracle = &self.ais[cm!(self.n_banks + account_index)]; require_keys_eq!(bank.oracle, *oracle.key()); - Ok(oracle_price( - oracle, - bank.oracle_config.conf_filter, - bank.mint_decimals, - )?) + oracle_price(oracle, bank.oracle_config.conf_filter, bank.mint_decimals) } } @@ -238,8 +234,8 @@ impl<'a, 'info> ScanningAccountRetriever<'a, 'info> { Ok(Self { ais: ais - .into_iter() - .map(|ai| AccountInfoRefMut::borrow(ai)) + .iter() + .map(AccountInfoRefMut::borrow) .collect::>>()?, token_index_map, perp_index_map, @@ -270,6 +266,7 @@ impl<'a, 'info> ScanningAccountRetriever<'a, 'info> { .ok_or_else(|| error_msg!("perp market index {} not found", perp_market_index))?) } + #[allow(clippy::type_complexity)] pub fn banks_mut_and_oracles( &mut self, token_index1: TokenIndex, @@ -393,8 +390,8 @@ pub fn compute_health_from_fixed_accounts( let retriever = FixedOrderAccountRetriever { ais: ais - .into_iter() - .map(|ai| AccountInfoRef::borrow(ai)) + .iter() + .map(AccountInfoRef::borrow) .collect::>>()?, n_banks: active_token_len, begin_perp: cm!(active_token_len * 2), @@ -799,7 +796,7 @@ pub fn new_health_cache( // converts the token value to the basis token value for health computations // TODO: health basis token == USDC? - let native = position.native(&bank); + let native = position.native(bank); token_infos.push(TokenInfo { token_index: bank.token_index, diff --git a/programs/mango-v4/src/state/mango_account.rs b/programs/mango-v4/src/state/mango_account.rs index c3cc654df..633488c76 100644 --- a/programs/mango-v4/src/state/mango_account.rs +++ b/programs/mango-v4/src/state/mango_account.rs @@ -209,7 +209,7 @@ fn test_dynamic_offsets() { .resize(8, PerpOpenOrders::default()); assert_eq!( 8 + AnchorSerialize::try_to_vec(&account).unwrap().len(), - MangoAccount::space(AccountSize::Large.try_into().unwrap()) + MangoAccount::space(AccountSize::Large) ); } @@ -392,7 +392,7 @@ impl MangoAccountValue { pub fn from_bytes(bytes: &[u8]) -> Result { let (fixed, dynamic) = bytes.split_at(size_of::()); Ok(Self { - fixed: *bytemuck::from_bytes(&fixed), + fixed: *bytemuck::from_bytes(fixed), header: MangoAccountDynamicHeader::from_bytes(dynamic)?, dynamic: dynamic.to_vec(), }) @@ -404,7 +404,7 @@ impl<'a> MangoAccountRefWithHeader<'a> { pub fn from_bytes(bytes: &'a [u8]) -> Result { let (fixed, dynamic) = bytes.split_at(size_of::()); Ok(Self { - fixed: bytemuck::from_bytes(&fixed), + fixed: bytemuck::from_bytes(fixed), header: MangoAccountDynamicHeader::from_bytes(dynamic)?, dynamic, }) @@ -550,7 +550,7 @@ impl< self.fixed().is_bankrupt() } - pub fn borrow<'b>(&'b self) -> DynamicAccountRef<'b, MangoAccount> { + pub fn borrow(&self) -> DynamicAccountRef { DynamicAccount { header: self.header(), fixed: self.fixed(), @@ -579,7 +579,7 @@ impl< self.dynamic.deref_or_borrow_mut() } - pub fn borrow_mut<'b>(&'b mut self) -> DynamicAccountRefMut<'b, MangoAccount> { + pub fn borrow_mut(&mut self) -> DynamicAccountRefMut { DynamicAccount { header: self.header.deref_or_borrow_mut(), fixed: self.fixed.deref_or_borrow_mut(),