Skip to content

Commit edaa8eb

Browse files
committed
fix: lints
1 parent a96f462 commit edaa8eb

File tree

7 files changed

+37
-57
lines changed

7 files changed

+37
-57
lines changed

contract/vault/src/impl_callbacks.rs

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::fmt::Display;
33
use crate::{ext_self, near, Contract, ContractExt, Error, Nep141Controller, OpState};
44
use near_contract_standards::fungible_token::core::ext_ft_core;
55
use near_sdk::{
6-
env, json_types::U128, serde_json, AccountId, Gas, NearToken, Promise, PromiseError,
6+
env, json_types::U128, AccountId, NearToken, PromiseError,
77
PromiseOrValue,
88
};
99
use near_sdk_contract_tools::ft::nep141::GAS_FOR_FT_TRANSFER_CALL;
@@ -30,7 +30,7 @@ impl Contract {
3030
attempted: U128,
3131
) -> PromiseOrValue<()> {
3232
// Invariant: Index drift or stale op_id results in a graceful stop
33-
let _ = if let Err(e) = self.ctx_allocating(op_id) {
33+
let () = if let Err(e) = self.ctx_allocating(op_id) {
3434
return self.stop_and_exit(Some(&e));
3535
};
3636

@@ -670,16 +670,16 @@ mod tests {
670670
use std::u128;
671671

672672
use crate::test_utils::*;
673-
use crate::Contract;
673+
674674
use near_sdk::json_types::U128;
675-
use near_sdk::test_utils::{accounts, VMContextBuilder};
676-
use near_sdk::{test_utils::testing_env_with_promise_results, AccountId, PromiseOrValue};
677-
use near_sdk::{test_vm_config, testing_env, PromiseResult, RuntimeFeesConfig};
675+
use near_sdk::test_utils::accounts;
676+
use near_sdk::PromiseOrValue;
677+
use near_sdk::PromiseResult;
678678
use rstest::rstest;
679-
use templar_common::asset::{BorrowAsset, FungibleAsset};
679+
680680
use templar_common::vault::Error;
681-
use templar_common::vault::{AllocationMode, OpState, VaultConfiguration};
682-
use test_utils::vault_configuration;
681+
use templar_common::vault::OpState;
682+
683683

684684
#[test]
685685
fn after_supply_1_check_allocating_not_allocating() {
@@ -834,7 +834,7 @@ mod tests {
834834
OpState::Payout { amount, .. } => {
835835
assert_eq!(*amount, 70, "Payout amount must match collected + credited");
836836
}
837-
other => panic!("Unexpected state after read: {:?}", other),
837+
other => panic!("Unexpected state after read: {other:?}"),
838838
}
839839
}
840840

@@ -952,9 +952,9 @@ mod tests {
952952

953953
match &c.op_state {
954954
OpState::Payout { amount, .. } => {
955-
assert_eq!(*amount, collected, "Payout amount must equal collected")
955+
assert_eq!(*amount, collected, "Payout amount must equal collected");
956956
}
957-
other => panic!("Unexpected state: {:?}", other),
957+
other => panic!("Unexpected state: {other:?}"),
958958
}
959959
}
960960

@@ -1009,9 +1009,9 @@ mod tests {
10091009

10101010
match &c.op_state {
10111011
OpState::Payout { amount, .. } => {
1012-
assert_eq!(*amount, collected, "Payout amount must equal collected")
1012+
assert_eq!(*amount, collected, "Payout amount must equal collected");
10131013
}
1014-
other => panic!("Unexpected state: {:?}", other),
1014+
other => panic!("Unexpected state: {other:?}"),
10151015
}
10161016
}
10171017

@@ -1046,24 +1046,18 @@ mod tests {
10461046
let call_idx = if pass_index { real_idx } else { real_idx + 1 };
10471047

10481048
let r = c.after_exec_withdraw_read(Ok(None), call_op, call_idx, U128(10), U128(1));
1049-
match (pass_op, pass_index) {
1050-
(true, true) => {
1051-
assert!(
1052-
!matches!(c.op_state, OpState::Idle),
1053-
"Valid callback should not immediately stop"
1054-
);
1055-
}
1056-
_ => {
1057-
// Any mismatch should stop and go Idle
1058-
match r {
1059-
PromiseOrValue::Value(()) => {}
1060-
_ => {}
1061-
}
1062-
assert!(
1063-
matches!(c.op_state, OpState::Idle),
1064-
"Mismatched callback must stop and go Idle"
1065-
);
1066-
}
1049+
if let (true, true) = (pass_op, pass_index) {
1050+
assert!(
1051+
!matches!(c.op_state, OpState::Idle),
1052+
"Valid callback should not immediately stop"
1053+
);
1054+
} else {
1055+
// Any mismatch should stop and go Idle
1056+
if let PromiseOrValue::Value(()) = r {}
1057+
assert!(
1058+
matches!(c.op_state, OpState::Idle),
1059+
"Mismatched callback must stop and go Idle"
1060+
);
10671061
}
10681062
}
10691063

contract/vault/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use near_contract_standards::fungible_token::core::ext_ft_core;
44
use near_sdk::{
55
env,
66
json_types::U128,
7-
near, require, serde_json,
7+
near, serde_json,
88
store::{IterableMap, LookupMap, Vector},
99
AccountId, BorshStorageKey, IntoStorageKey, PanicOnDefault, Promise, PromiseOrValue,
1010
};
@@ -1054,9 +1054,9 @@ impl Contract {
10541054
.emit();
10551055
}
10561056

1057-
/// Computes fee-aware effective totals for conversions, mimicking MetaMorpho:
1057+
/// Computes fee-aware effective totals for conversions, mimicking `MetaMorpho`:
10581058
/// - Include fee shares that would be minted if fees accrued now.
1059-
/// - Apply virtual offsets: +virtual_shares to supply and +virtual_assets to assets.
1059+
/// - Apply virtual offsets: +`virtual_shares` to supply and +`virtual_assets` to assets.
10601060
fn effective_totals_fee_aware(&self) -> (u128, u128) {
10611061
let cur = self.get_total_assets().0;
10621062
let ts = self.total_supply();

contract/vault/src/storage_management.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::PendingWithdrawal;
2-
use near_sdk::borsh::{self, BorshSerialize};
32
use near_sdk::{env, AccountId};
43
use std::collections::HashSet;
54
use templar_common::vault::{storage_bytes_for_account_id, MarketConfiguration};
@@ -71,10 +70,7 @@ pub fn require_attached_at_least(required_yocto: u128, ctx: &str) -> u128 {
7170
let attached = env::attached_deposit().as_yoctonear();
7271
assert!(
7372
attached >= required_yocto,
74-
"Insufficient storage deposit for {}: required {}, attached {}",
75-
ctx,
76-
required_yocto,
77-
attached
73+
"Insufficient storage deposit for {ctx}: required {required_yocto}, attached {attached}"
7874
);
7975
required_yocto
8076
}

contract/vault/src/test_utils.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ pub use near_sdk::{
55
test_vm_config, testing_env, AccountId, PromiseResult, RuntimeFeesConfig,
66
};
77
use near_sdk_contract_tools::ft::Nep141Controller as _;
8-
use rstest::rstest;
9-
use templar_common::vault::{AllocationMode, OpState, VaultConfiguration};
108
use test_utils::vault_configuration;
119

1210
pub fn mk(n: u32) -> AccountId {

contract/vault/src/tests.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
1-
use crate::storage_management;
2-
use crate::storage_management::storage_bytes_for_pending_cap_entry;
31
use crate::storage_management::storage_bytes_for_queue_account_id;
42
use crate::storage_management::yocto_for_bytes;
53
use crate::storage_management::yocto_for_new_market;
64
use crate::test_utils::*;
75
use crate::Contract;
86
use near_sdk::env;
97
use near_sdk::test_utils::accounts;
10-
use near_sdk::{json_types::U128, AccountId, RuntimeFeesConfig};
11-
use near_sdk::{test_vm_config, testing_env};
8+
use near_sdk::{json_types::U128, AccountId};
129
use near_sdk_contract_tools::ft::Nep141Controller as _;
1310
use near_sdk_contract_tools::owner::OwnerExternal;
1411
use rstest::rstest;
15-
use templar_common::asset::{BorrowAsset, FungibleAsset};
1612
use templar_common::vault::MarketConfiguration;
1713
use templar_common::vault::OpState;
18-
use templar_common::vault::{AllocationMode, VaultConfiguration};
1914

2015
#[rstest(len => [2usize, 3, 5])]
2116
#[should_panic = "Duplicate market"]
@@ -142,8 +137,8 @@ fn execute_next_withdrawal_request_skips_holes() {
142137
let owner = c.own_get_owner().unwrap();
143138
setup_env(&vault_id, &owner, vec![]);
144139

145-
println!("vault_id: {}", vault_id);
146-
println!("owner: {}", owner);
140+
println!("vault_id: {vault_id}");
141+
println!("owner: {owner}");
147142

148143
// Bob gets 20 shares
149144
c.deposit_unchecked(&owner, 20).unwrap();
@@ -722,7 +717,7 @@ fn clamp_allocation_total_matches_min_bounds_cases(
722717
c.supply_queue.push(m.clone());
723718
c.idle_balance = idle;
724719

725-
let room = if cap > cur { cap - cur } else { 0 };
720+
let room = cap.saturating_sub(cur);
726721
let requested = req.unwrap_or(c.idle_balance);
727722
let expect = requested.min(c.idle_balance).min(room);
728723

contract/vault/tests/happy_path.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use near_sdk::{json_types::U128, AccountId};
1+
use near_sdk::json_types::U128;
22
use templar_common::{interest_rate_strategy::InterestRateStrategy, number::Decimal};
33
use test_utils::{
4-
controller::vault::UnifiedVaultController, setup_test, ContractController, MarketController,
4+
controller::vault::UnifiedVaultController, setup_test, ContractController,
55
UnifiedMarketController,
66
};
77

contract/vault/tests/invariants.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
use near_sdk::{json_types::U128, AccountId};
2-
use templar_common::{interest_rate_strategy::InterestRateStrategy, number::Decimal};
31
use test_utils::{
4-
controller::vault::UnifiedVaultController, setup_test, ContractController, MarketController,
5-
UnifiedMarketController,
2+
setup_test, ContractController,
63
};
74

85
// TODO(unit?): on allocation-failure, reconcile to idle

0 commit comments

Comments
 (0)