Skip to content

Commit d661690

Browse files
committed
vault-strategy: cargo fmt
Apply rustfmt to the deposit handler and the tests; the CI Rustfmt check runs `cargo fmt --check`. No behavior change.
1 parent 9fb03be commit d661690

2 files changed

Lines changed: 48 additions & 15 deletions

File tree

finance/vault-strategy/anchor/programs/vault-strategy/src/instructions/deposit.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,20 @@ pub fn handle_deposit<'info>(
129129
let feed_account = &remaining[index * 5 + 4];
130130

131131
let config = AssetConfig::load_checked(config_account)?;
132-
require_keys_eq!(config.strategy, strategy_key, VaultError::InvalidAssetAccount);
133-
require!(config.index as usize == index, VaultError::InvalidAssetAccount);
134-
require_keys_eq!(vault_account.key(), config.vault, VaultError::InvalidAssetAccount);
132+
require_keys_eq!(
133+
config.strategy,
134+
strategy_key,
135+
VaultError::InvalidAssetAccount
136+
);
137+
require!(
138+
config.index as usize == index,
139+
VaultError::InvalidAssetAccount
140+
);
141+
require_keys_eq!(
142+
vault_account.key(),
143+
config.vault,
144+
VaultError::InvalidAssetAccount
145+
);
135146

136147
let price = load_price(feed_account, &config.price_feed, now)?;
137148
let amount = read_token_amount(vault_account)?;
@@ -151,7 +162,10 @@ pub fn handle_deposit<'info>(
151162
.ok_or(VaultError::MathOverflow)? as u64
152163
};
153164

154-
require!(shares_to_mint >= minimum_shares, VaultError::SlippageTooHigh);
165+
require!(
166+
shares_to_mint >= minimum_shares,
167+
VaultError::SlippageTooHigh
168+
);
155169

156170
context.accounts.strategy.total_shares = total_shares
157171
.checked_add(shares_to_mint)
@@ -182,7 +196,11 @@ pub fn handle_deposit<'info>(
182196
let feed_account = &remaining[index * 5 + 4];
183197

184198
let config = AssetConfig::load_checked(config_account)?;
185-
require_keys_eq!(mint_account.key(), config.mint, VaultError::InvalidAssetAccount);
199+
require_keys_eq!(
200+
mint_account.key(),
201+
config.mint,
202+
VaultError::InvalidAssetAccount
203+
);
186204

187205
if config.weight_bps == 0 {
188206
continue;

finance/vault-strategy/anchor/programs/vault-strategy/tests/vault_strategy.rs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,11 @@ fn set_nvda_price(ctx: &mut TestContext, price: i64, rate: u64) {
552552
set_router_rate(ctx, nvda_mint, rate, nvda_rate_pda);
553553
}
554554

555-
fn set_weight(ctx: &mut TestContext, index: u8, weight_bps: u16) -> Result<(), solana_kite::SolanaKiteError> {
555+
fn set_weight(
556+
ctx: &mut TestContext,
557+
index: u8,
558+
weight_bps: u16,
559+
) -> Result<(), solana_kite::SolanaKiteError> {
556560
let ix = Instruction::new_with_bytes(
557561
ctx.vault_program_id,
558562
&vault_strategy::instruction::SetWeight { weight_bps }.data(),
@@ -563,7 +567,12 @@ fn set_weight(ctx: &mut TestContext, index: u8, weight_bps: u16) -> Result<(), s
563567
}
564568
.to_account_metas(None),
565569
);
566-
send_transaction_from_instructions(&mut ctx.svm, vec![ix], &[&ctx.manager], &ctx.manager.pubkey())
570+
send_transaction_from_instructions(
571+
&mut ctx.svm,
572+
vec![ix],
573+
&[&ctx.manager],
574+
&ctx.manager.pubkey(),
575+
)
567576
}
568577

569578
/// init strategy + add only TSLAx at 40%, so total weight is 4000: the strategy is
@@ -614,7 +623,8 @@ fn do_rebalance(
614623
sell_amount: u64,
615624
usdc_to_invest: u64,
616625
) {
617-
let (sell_mint, sell_config, sell_feed, vault_sell, sell_rate) = asset_accounts(ctx, sell_index);
626+
let (sell_mint, sell_config, sell_feed, vault_sell, sell_rate) =
627+
asset_accounts(ctx, sell_index);
618628
let (buy_mint, buy_config, buy_feed, vault_buy, buy_rate) = asset_accounts(ctx, buy_index);
619629
let ix = Instruction::new_with_bytes(
620630
ctx.vault_program_id,
@@ -648,8 +658,13 @@ fn do_rebalance(
648658
}
649659
.to_account_metas(None),
650660
);
651-
send_transaction_from_instructions(&mut ctx.svm, vec![ix], &[&ctx.manager], &ctx.manager.pubkey())
652-
.unwrap();
661+
send_transaction_from_instructions(
662+
&mut ctx.svm,
663+
vec![ix],
664+
&[&ctx.manager],
665+
&ctx.manager.pubkey(),
666+
)
667+
.unwrap();
653668
}
654669

655670
fn advance_one_year(ctx: &mut TestContext) {
@@ -1121,10 +1136,7 @@ fn test_withdraw() {
11211136
send_transaction_from_instructions(&mut ctx.svm, vec![ix], &[&user], &user.pubkey()).unwrap();
11221137

11231138
// Sole holder withdraws everything in kind: all 16000 TSLAx + 33333 NVDAx, no USDC.
1124-
assert_eq!(
1125-
get_token_account_balance(&ctx.svm, &user_usdc).unwrap(),
1126-
0
1127-
);
1139+
assert_eq!(get_token_account_balance(&ctx.svm, &user_usdc).unwrap(), 0);
11281140
assert_eq!(
11291141
get_token_account_balance(&ctx.svm, &derive_ata(&user.pubkey(), &ctx.tsla_mint)).unwrap(),
11301142
16_000
@@ -1274,7 +1286,10 @@ fn test_set_weight_rejects_overflow() {
12741286
standard_strategy(&mut ctx);
12751287
// TSLAx 4000 + NVDAx 6000 = 10000. Raising TSLAx to 6000 would total 12000.
12761288
let r = set_weight(&mut ctx, 0, 6000);
1277-
assert!(r.is_err(), "weight change pushing total over 10000 must revert");
1289+
assert!(
1290+
r.is_err(),
1291+
"weight change pushing total over 10000 must revert"
1292+
);
12781293
}
12791294

12801295
#[test]

0 commit comments

Comments
 (0)