Skip to content

Commit 00bfb1e

Browse files
committed
fix: lints
1 parent a96f462 commit 00bfb1e

File tree

9 files changed

+57
-77
lines changed

9 files changed

+57
-77
lines changed

contract/vault/src/aux.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub enum ReturnStyle {
3333

3434
// TODO: use this
3535
impl ReturnStyle {
36-
pub fn serialize(
36+
#[must_use] pub fn serialize(
3737
&self,
3838
amount: templar_common::asset::FungibleAssetAmount<impl templar_common::asset::AssetClass>,
3939
) -> serde_json::Value {

contract/vault/src/impl_callbacks.rs

Lines changed: 28 additions & 34 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

@@ -503,7 +503,7 @@ impl Contract {
503503
index,
504504
remaining: U128(remaining),
505505
collected: U128(collected),
506-
reason: msg.map(|m| m.to_string()),
506+
reason: msg.map(std::string::ToString::to_string),
507507
}
508508
.emit();
509509
}
@@ -540,7 +540,7 @@ impl Contract {
540540
op_id: *op_id,
541541
receiver: receiver.clone(),
542542
amount: U128(*amount),
543-
reason: msg.map(|m| m.to_string()),
543+
reason: msg.map(std::string::ToString::to_string),
544544
}
545545
.emit();
546546
}
@@ -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: 4 additions & 4 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
};
@@ -146,7 +146,7 @@ impl Contract {
146146
/// - `fee_recipient`: account to receive performance fees.
147147
/// - `skim_recipient`: account to receive skimmed tokens.
148148
/// - `name`/`symbol`/`decimals`: metadata for the share token.
149-
pub fn new(configuration: VaultConfiguration) -> Self {
149+
#[must_use] pub fn new(configuration: VaultConfiguration) -> Self {
150150
let VaultConfiguration {
151151
owner,
152152
curator,
@@ -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();
Lines changed: 13 additions & 17 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};
@@ -12,52 +11,52 @@ use templar_common::vault::{storage_bytes_for_account_id, MarketConfiguration};
1211
pub const MAP_ENTRY_OVERHEAD: u64 = 64;
1312

1413
pub const VEC_ITEM_OVERHEAD: u64 = 16;
15-
pub fn storage_bytes_for_queue_account_id() -> u64 {
14+
#[must_use] pub fn storage_bytes_for_queue_account_id() -> u64 {
1615
VEC_ITEM_OVERHEAD + storage_bytes_for_account_id()
1716
}
1817

19-
pub fn storage_bytes_for_config_entry() -> u64 {
18+
#[must_use] pub fn storage_bytes_for_config_entry() -> u64 {
2019
let key = storage_bytes_for_account_id();
2120
MAP_ENTRY_OVERHEAD + key + MarketConfiguration::encoded_size() as u64
2221
}
2322

24-
pub fn storage_bytes_for_market_supply_entry() -> u64 {
23+
#[must_use] pub fn storage_bytes_for_market_supply_entry() -> u64 {
2524
let key = storage_bytes_for_account_id();
2625
// u128 principal
2726
let val = 16u64;
2827
MAP_ENTRY_OVERHEAD + key + val
2928
}
3029

31-
pub fn storage_bytes_for_pending_cap_entry() -> u64 {
30+
#[must_use] pub fn storage_bytes_for_pending_cap_entry() -> u64 {
3231
let key = storage_bytes_for_account_id();
3332
// PendingValue { value: u128, valid_at: u64 }
3433
let val = 16u64 + 8u64;
3534
MAP_ENTRY_OVERHEAD + key + val
3635
}
3736

38-
pub fn storage_bytes_for_pending_withdrawal() -> u64 {
37+
#[must_use] pub fn storage_bytes_for_pending_withdrawal() -> u64 {
3938
// Key is u64 id -> 8 bytes
4039
let key = 8u64;
4140
let val = PendingWithdrawal::encoded_size();
4241
MAP_ENTRY_OVERHEAD + key + val
4342
}
4443

45-
pub fn yocto_for_bytes(bytes: u64) -> u128 {
44+
#[must_use] pub fn yocto_for_bytes(bytes: u64) -> u128 {
4645
let price = env::storage_byte_cost().as_yoctonear();
4746
u128::from(bytes).saturating_mul(price)
4847
}
4948

50-
pub fn yocto_for_new_market() -> u128 {
49+
#[must_use] pub fn yocto_for_new_market() -> u128 {
5150
yocto_for_bytes(
5251
storage_bytes_for_config_entry().saturating_add(storage_bytes_for_market_supply_entry()),
5352
)
5453
}
5554

56-
pub fn yocto_for_pending_cap() -> u128 {
55+
#[must_use] pub fn yocto_for_pending_cap() -> u128 {
5756
yocto_for_bytes(storage_bytes_for_pending_cap_entry())
5857
}
5958

60-
pub fn yocto_for_queue_additions(current: &HashSet<AccountId>, new: &[AccountId]) -> u128 {
59+
#[must_use] pub fn yocto_for_queue_additions(current: &HashSet<AccountId>, new: &[AccountId]) -> u128 {
6160
new.iter().fold(0u128, |acc, id| {
6261
if current.contains(id) {
6362
acc
@@ -67,24 +66,21 @@ pub fn yocto_for_queue_additions(current: &HashSet<AccountId>, new: &[AccountId]
6766
})
6867
}
6968

70-
pub fn require_attached_at_least(required_yocto: u128, ctx: &str) -> u128 {
69+
#[must_use] 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
}
8177

82-
pub fn require_attached_for_bytes(bytes: u64, ctx: &str) -> u128 {
78+
#[must_use] pub fn require_attached_for_bytes(bytes: u64, ctx: &str) -> u128 {
8379
let req = yocto_for_bytes(bytes);
8480
require_attached_at_least(req, ctx)
8581
}
8682

87-
pub fn require_attached_for_pending_withdrawal() -> u128 {
83+
#[must_use] pub fn require_attached_for_pending_withdrawal() -> u128 {
8884
let bytes = storage_bytes_for_pending_withdrawal();
8985
require_attached_for_bytes(bytes, "withdrawal request")
9086
}

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/src/wad.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ pub const WAD: u128 = 1e18 as u128;
66

77
/// Multiplies two WAD-scaled values and floors the result: floor(x * y / WAD).
88
#[inline]
9-
pub fn mul_wad_floor(x: u128, y: u128) -> u128 {
9+
#[must_use] pub fn mul_wad_floor(x: u128, y: u128) -> u128 {
1010
mul_div_floor(x, y, WAD)
1111
}
1212

1313
/// Multiplies and divides with flooring: floor(x * y / denom).
1414
/// Uses 256-bit intermediate to avoid overflow; returns 0 if denom is 0.
1515
#[inline]
16-
pub fn mul_div_floor(x: u128, y: u128, denom: u128) -> u128 {
16+
#[must_use] pub fn mul_div_floor(x: u128, y: u128, denom: u128) -> u128 {
1717
if denom == 0 {
1818
return 0;
1919
}
@@ -25,7 +25,7 @@ pub fn mul_div_floor(x: u128, y: u128, denom: u128) -> u128 {
2525
/// Multiplies and divides with ceiling: ceil(x * y / denom).
2626
/// Uses 256-bit intermediate to avoid overflow; returns 0 if denom is 0.
2727
#[inline]
28-
pub fn mul_div_ceil(x: u128, y: u128, denom: u128) -> u128 {
28+
#[must_use] pub fn mul_div_ceil(x: u128, y: u128, denom: u128) -> u128 {
2929
if denom == 0 {
3030
return 0;
3131
}
@@ -43,7 +43,7 @@ pub fn mul_div_ceil(x: u128, y: u128, denom: u128) -> u128 {
4343
///
4444
/// Floors intermediate divisions; returns 0 when no profit, zero fee, or zero supply.
4545
#[inline]
46-
pub fn compute_fee_shares(
46+
#[must_use] pub fn compute_fee_shares(
4747
cur_total_assets: u128,
4848
last_total_assets: u128,
4949
performance_fee: u128,

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)