Skip to content

Commit

Permalink
style: satisfy clippy
Browse files Browse the repository at this point in the history
* ran `just lint`
* ran `cargo clippy --tests --all -- -D warnings`
  • Loading branch information
kaimen-sano committed Apr 14, 2024
1 parent 62a82ed commit 16c42b0
Show file tree
Hide file tree
Showing 15 changed files with 212 additions and 115 deletions.
2 changes: 2 additions & 0 deletions contracts/liquidity_hub/epoch-manager/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use white_whale_std::epoch_manager::epoch_manager::{
};

/// Mocks contract instantiation.
#[allow(dead_code)]
pub(crate) fn mock_instantiation(
deps: DepsMut,
info: MessageInfo,
Expand All @@ -28,6 +29,7 @@ pub(crate) fn mock_instantiation(
}

/// Mocks hook addition.
#[allow(dead_code)]
pub(crate) fn mock_add_hook(deps: DepsMut, info: MessageInfo) -> Result<Response, ContractError> {
let msg = ExecuteMsg::AddHook {
contract_addr: "hook_contract_1".to_string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ impl TestingSuite {
.unwrap();
}

#[allow(clippy::inconsistent_digit_grouping)]
fn create_epoch_manager(&mut self) {
let epoch_manager_contract = self.app.store_code(epoch_manager_contract());

Expand Down Expand Up @@ -197,6 +198,7 @@ impl TestingSuite {
}

#[track_caller]
#[allow(clippy::too_many_arguments)]
pub(crate) fn instantiate(
&mut self,
whale_lair_addr: String,
Expand Down Expand Up @@ -239,6 +241,7 @@ impl TestingSuite {
}

#[track_caller]
#[allow(clippy::too_many_arguments)]
pub(crate) fn instantiate_err(
&mut self,
whale_lair_addr: String,
Expand Down Expand Up @@ -300,6 +303,7 @@ impl TestingSuite {
}

#[track_caller]
#[allow(clippy::too_many_arguments)]
pub(crate) fn update_config(
&mut self,
sender: Addr,
Expand Down Expand Up @@ -555,7 +559,7 @@ impl TestingSuite {

result(
self.app
.execute_contract(sender, self.epoch_manager_addr.clone(), &msg, &vec![]),
.execute_contract(sender, self.epoch_manager_addr.clone(), &msg, &[]),
);

self
Expand Down Expand Up @@ -584,7 +588,7 @@ impl TestingSuite {
#[track_caller]
pub(crate) fn query_current_epoch(
&mut self,
result: impl Fn(StdResult<EpochResponse>),
mut result: impl FnMut(StdResult<EpochResponse>),
) -> &mut Self {
let current_epoch_response: StdResult<EpochResponse> = self.app.wrap().query_wasm_smart(
&self.epoch_manager_addr,
Expand Down
46 changes: 23 additions & 23 deletions contracts/liquidity_hub/incentive-manager/tests/integration.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
extern crate core;

use std::cell::RefCell;

use cosmwasm_std::{coin, Addr, Coin, Decimal, Uint128};

use incentive_manager::ContractError;
use white_whale_std::incentive_manager::{
Config, Curve, EpochId, Incentive, IncentiveAction, IncentiveParams, IncentivesBy,
LpWeightResponse, Position, PositionAction, RewardsResponse,
Config, Curve, Incentive, IncentiveAction, IncentiveParams, IncentivesBy, LpWeightResponse,
Position, PositionAction, RewardsResponse,
};

use crate::common::suite::TestingSuite;
Expand Down Expand Up @@ -707,6 +705,7 @@ fn expand_incentives() {
}

#[test]
#[allow(clippy::inconsistent_digit_grouping)]
fn close_incentives() {
let lp_denom = "factory/pool/uLP".to_string();

Expand Down Expand Up @@ -790,7 +789,7 @@ fn close_incentives() {
},
)
.query_balance("ulab".to_string(), other.clone(), |balance| {
assert_eq!(balance, Uint128::new(99_999_6000));
assert_eq!(balance, Uint128::new(999_996_000));
})
.manage_incentive(
other.clone(),
Expand All @@ -803,7 +802,7 @@ fn close_incentives() {
},
)
.query_balance("ulab".to_string(), other.clone(), |balance| {
assert_eq!(balance, Uint128::new(100_000_0000));
assert_eq!(balance, Uint128::new(1000_000_000));
});

suite
Expand All @@ -829,7 +828,7 @@ fn close_incentives() {
},
)
.query_balance("ulab".to_string(), other.clone(), |balance| {
assert_eq!(balance, Uint128::new(99_999_6000));
assert_eq!(balance, Uint128::new(999_996_000));
})
// the owner of the contract can also close incentives
.manage_incentive(
Expand All @@ -843,7 +842,7 @@ fn close_incentives() {
},
)
.query_balance("ulab".to_string(), other.clone(), |balance| {
assert_eq!(balance, Uint128::new(100_000_0000));
assert_eq!(balance, Uint128::new(1000_000_000));
});
}

Expand Down Expand Up @@ -1115,15 +1114,16 @@ pub fn update_config() {
}

#[test]
#[allow(clippy::inconsistent_digit_grouping)]
pub fn test_manage_position() {
let lp_denom = "factory/pool/uLP".to_string();

let mut suite = TestingSuite::default_with_balances(vec![
coin(1_000_000_000u128, "uwhale".to_string()),
coin(1_000_000_000u128, "ulab".to_string()),
coin(1_000_000_000u128, "uosmo".to_string()),
coin(1_000_000_000u128, "uwhale"),
coin(1_000_000_000u128, "ulab"),
coin(1_000_000_000u128, "uosmo"),
coin(1_000_000_000u128, lp_denom.clone()),
coin(1_000_000_000u128, "invalid_lp".clone()),
coin(1_000_000_000u128, "invalid_lp"),
]);

let creator = suite.creator();
Expand Down Expand Up @@ -1990,11 +1990,11 @@ fn claim_expired_incentive_returns_nothing() {
let lp_denom = "factory/pool/uLP".to_string();

let mut suite = TestingSuite::default_with_balances(vec![
coin(1_000_000_000u128, "uwhale".to_string()),
coin(1_000_000_000u128, "ulab".to_string()),
coin(1_000_000_000u128, "uosmo".to_string()),
coin(1_000_000_000u128, "uwhale"),
coin(1_000_000_000u128, "ulab"),
coin(1_000_000_000u128, "uosmo"),
coin(1_000_000_000u128, lp_denom.clone()),
coin(1_000_000_000u128, "invalid_lp".clone()),
coin(1_000_000_000u128, "invalid_lp"),
]);

let creator = suite.creator();
Expand Down Expand Up @@ -2136,11 +2136,11 @@ fn test_close_expired_incentives() {
let lp_denom = "factory/pool/uLP".to_string();

let mut suite = TestingSuite::default_with_balances(vec![
coin(1_000_000_000u128, "uwhale".to_string()),
coin(1_000_000_000u128, "ulab".to_string()),
coin(1_000_000_000u128, "uosmo".to_string()),
coin(1_000_000_000u128, "uwhale"),
coin(1_000_000_000u128, "ulab"),
coin(1_000_000_000u128, "uosmo"),
coin(1_000_000_000u128, lp_denom.clone()),
coin(1_000_000_000u128, "invalid_lp".clone()),
coin(1_000_000_000u128, "invalid_lp"),
]);

let creator = suite.creator();
Expand Down Expand Up @@ -2182,18 +2182,18 @@ fn test_close_expired_incentives() {
});
}

let current_id: RefCell<EpochId> = RefCell::new(0u64);
let mut current_id = 0;

// try opening another incentive for the same lp denom, the expired incentive should get closed
suite
.query_current_epoch(|result| {
let epoch_response = result.unwrap();
*current_id.borrow_mut() = epoch_response.epoch.id;
current_id = epoch_response.epoch.id;
})
.query_incentives(None, None, None, |result| {
let incentives_response = result.unwrap();
assert_eq!(incentives_response.incentives.len(), 1);
assert!(incentives_response.incentives[0].is_expired(current_id.borrow().clone()));
assert!(incentives_response.incentives[0].is_expired(current_id));
})
.manage_incentive(
other.clone(),
Expand Down
62 changes: 54 additions & 8 deletions contracts/liquidity_hub/pool-manager/schema/pool-manager.json
Original file line number Diff line number Diff line change
Expand Up @@ -489,22 +489,45 @@
]
},
"PoolFee": {
"description": "Fees used by the pools on the pool network",
"description": "Represents the fee structure for transactions within a pool.\n\n# Fields - `protocol_fee`: The fee percentage charged by the protocol on each transaction to support operational and developmental needs. - `swap_fee`: The fee percentage allocated to liquidity providers as a reward for supplying liquidity to the pool, incentivizing participation and ensuring pool health. - `burn_fee`: A fee percentage that is burned on each transaction, helping manage the token economy by reducing supply over time, potentially increasing token value. - `osmosis_fee` (optional): Specific to the Osmosis feature, this fee is charged on each transaction when the Osmosis feature is enabled, supporting specific ecosystem requirements. - `extra_fees`: A vector of custom fees allowing for extensible and adaptable fee structures to meet diverse and evolving needs. Validation ensures that the total of all fees does not exceed 100%, maintaining fairness and avoiding overcharging.\n\n# Features - `osmosis`: Enables the `osmosis_fee` field, integrating specific fee requirements for the Osmosis protocol within the pool's fee structure.",
"type": "object",
"required": [
"burn_fee",
"extra_fees",
"protocol_fee",
"swap_fee"
],
"properties": {
"burn_fee": {
"$ref": "#/definitions/Fee"
"description": "Fee percentage that is burned on each transaction. Burning a portion of the transaction fee helps in reducing the overall token supply.",
"allOf": [
{
"$ref": "#/definitions/Fee"
}
]
},
"extra_fees": {
"description": "A list of custom, additional fees that can be defined for specific use cases or additional functionalities. This vector enables the flexibility to introduce new fees without altering the core fee structure. Total of all fees, including custom ones, is validated to not exceed 100%, ensuring a balanced and fair fee distribution.",
"type": "array",
"items": {
"$ref": "#/definitions/Fee"
}
},
"protocol_fee": {
"$ref": "#/definitions/Fee"
"description": "Fee percentage charged on each transaction for the protocol's benefit.",
"allOf": [
{
"$ref": "#/definitions/Fee"
}
]
},
"swap_fee": {
"$ref": "#/definitions/Fee"
"description": "Fee percentage allocated to liquidity providers on each swap.",
"allOf": [
{
"$ref": "#/definitions/Fee"
}
]
}
},
"additionalProperties": false
Expand Down Expand Up @@ -998,22 +1021,45 @@
]
},
"PoolFee": {
"description": "Fees used by the pools on the pool network",
"description": "Represents the fee structure for transactions within a pool.\n\n# Fields - `protocol_fee`: The fee percentage charged by the protocol on each transaction to support operational and developmental needs. - `swap_fee`: The fee percentage allocated to liquidity providers as a reward for supplying liquidity to the pool, incentivizing participation and ensuring pool health. - `burn_fee`: A fee percentage that is burned on each transaction, helping manage the token economy by reducing supply over time, potentially increasing token value. - `osmosis_fee` (optional): Specific to the Osmosis feature, this fee is charged on each transaction when the Osmosis feature is enabled, supporting specific ecosystem requirements. - `extra_fees`: A vector of custom fees allowing for extensible and adaptable fee structures to meet diverse and evolving needs. Validation ensures that the total of all fees does not exceed 100%, maintaining fairness and avoiding overcharging.\n\n# Features - `osmosis`: Enables the `osmosis_fee` field, integrating specific fee requirements for the Osmosis protocol within the pool's fee structure.",
"type": "object",
"required": [
"burn_fee",
"extra_fees",
"protocol_fee",
"swap_fee"
],
"properties": {
"burn_fee": {
"$ref": "#/definitions/Fee"
"description": "Fee percentage that is burned on each transaction. Burning a portion of the transaction fee helps in reducing the overall token supply.",
"allOf": [
{
"$ref": "#/definitions/Fee"
}
]
},
"extra_fees": {
"description": "A list of custom, additional fees that can be defined for specific use cases or additional functionalities. This vector enables the flexibility to introduce new fees without altering the core fee structure. Total of all fees, including custom ones, is validated to not exceed 100%, ensuring a balanced and fair fee distribution.",
"type": "array",
"items": {
"$ref": "#/definitions/Fee"
}
},
"protocol_fee": {
"$ref": "#/definitions/Fee"
"description": "Fee percentage charged on each transaction for the protocol's benefit.",
"allOf": [
{
"$ref": "#/definitions/Fee"
}
]
},
"swap_fee": {
"$ref": "#/definitions/Fee"
"description": "Fee percentage allocated to liquidity providers on each swap.",
"allOf": [
{
"$ref": "#/definitions/Fee"
}
]
}
},
"additionalProperties": false
Expand Down
31 changes: 27 additions & 4 deletions contracts/liquidity_hub/pool-manager/schema/raw/execute.json
Original file line number Diff line number Diff line change
Expand Up @@ -442,22 +442,45 @@
]
},
"PoolFee": {
"description": "Fees used by the pools on the pool network",
"description": "Represents the fee structure for transactions within a pool.\n\n# Fields - `protocol_fee`: The fee percentage charged by the protocol on each transaction to support operational and developmental needs. - `swap_fee`: The fee percentage allocated to liquidity providers as a reward for supplying liquidity to the pool, incentivizing participation and ensuring pool health. - `burn_fee`: A fee percentage that is burned on each transaction, helping manage the token economy by reducing supply over time, potentially increasing token value. - `osmosis_fee` (optional): Specific to the Osmosis feature, this fee is charged on each transaction when the Osmosis feature is enabled, supporting specific ecosystem requirements. - `extra_fees`: A vector of custom fees allowing for extensible and adaptable fee structures to meet diverse and evolving needs. Validation ensures that the total of all fees does not exceed 100%, maintaining fairness and avoiding overcharging.\n\n# Features - `osmosis`: Enables the `osmosis_fee` field, integrating specific fee requirements for the Osmosis protocol within the pool's fee structure.",
"type": "object",
"required": [
"burn_fee",
"extra_fees",
"protocol_fee",
"swap_fee"
],
"properties": {
"burn_fee": {
"$ref": "#/definitions/Fee"
"description": "Fee percentage that is burned on each transaction. Burning a portion of the transaction fee helps in reducing the overall token supply.",
"allOf": [
{
"$ref": "#/definitions/Fee"
}
]
},
"extra_fees": {
"description": "A list of custom, additional fees that can be defined for specific use cases or additional functionalities. This vector enables the flexibility to introduce new fees without altering the core fee structure. Total of all fees, including custom ones, is validated to not exceed 100%, ensuring a balanced and fair fee distribution.",
"type": "array",
"items": {
"$ref": "#/definitions/Fee"
}
},
"protocol_fee": {
"$ref": "#/definitions/Fee"
"description": "Fee percentage charged on each transaction for the protocol's benefit.",
"allOf": [
{
"$ref": "#/definitions/Fee"
}
]
},
"swap_fee": {
"$ref": "#/definitions/Fee"
"description": "Fee percentage allocated to liquidity providers on each swap.",
"allOf": [
{
"$ref": "#/definitions/Fee"
}
]
}
},
"additionalProperties": false
Expand Down
Loading

0 comments on commit 16c42b0

Please sign in to comment.