Skip to content

Commit

Permalink
fix: make clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
0xFable committed May 2, 2024
1 parent 92aa39b commit 0f77427
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 38 deletions.
7 changes: 1 addition & 6 deletions contracts/liquidity_hub/bonding-manager/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ pub(crate) fn bond(
Ok(bucket)
},
)?;
println!("Bonded asset: {:?}", global_index);

Ok(Response::default().add_attributes(vec![
("action", "bond".to_string()),
Expand Down Expand Up @@ -239,7 +238,6 @@ pub fn claim(deps: DepsMut, _env: Env, info: MessageInfo) -> Result<Response, Co
!claimable_epochs.is_empty(),
ContractError::NothingToClaim {}

Check warning on line 239 in contracts/liquidity_hub/bonding-manager/src/commands.rs

View check run for this annotation

Codecov / codecov/patch

contracts/liquidity_hub/bonding-manager/src/commands.rs#L239

Added line #L239 was not covered by tests
);
print!("Claimable epochs: {:?}", claimable_epochs);
let _global = GLOBAL.load(deps.storage)?;
let mut claimable_fees = vec![];
for mut epoch in claimable_epochs.clone() {
Expand All @@ -249,11 +247,8 @@ pub fn claim(deps: DepsMut, _env: Env, info: MessageInfo) -> Result<Response, Co
info.sender.to_string(),
Some(epoch.global_index.clone()),
)?;
println!("Bonding weight response: {:?}", bonding_weight_response);
println!("Epoch: {:?}", epoch);
for fee in epoch.total.iter() {
println!("Fee: {:?}", fee);

for fee in epoch.total.iter() {
let reward = fee.amount * bonding_weight_response.share;

if reward.is_zero() {
Expand Down
21 changes: 2 additions & 19 deletions contracts/liquidity_hub/bonding-manager/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,7 @@ pub fn execute(
match msg {
ExecuteMsg::Bond {} => {
let asset_to_bond = helpers::validate_funds(&deps, &info)?;
commands::bond(
deps,
env.block.time,
info.clone(),
env,
asset_to_bond.to_owned(),
)
commands::bond(deps, env.block.time, info, env, asset_to_bond)
}
ExecuteMsg::Unbond { asset } => {
cw_utils::nonpayable(&info)?;
Expand Down Expand Up @@ -117,10 +111,7 @@ pub fn execute(
// Epoch has been updated, update rewards bucket
// and forward the expiring epoch
// Store epoch manager and verify the sender is him
println!("New epoch created: {:?}", current_epoch);
// let config = CONFIG.load(deps.storage)?;
let global = GLOBAL.may_load(deps.storage)?;
println!("Global: {:?}", global);
// This happens only on the first epoch where Global has not been initialised yet
if global.is_none() {
let default_global = GlobalIndex {
Expand Down Expand Up @@ -155,11 +146,10 @@ pub fn execute(
&Epoch {
id: next_epoch_id.into(),
start_time: current_epoch.start_time.plus_days(1),
global_index: global.clone(),
global_index: global,
..Epoch::default()
},
)?;
println!("Nexts epoch created: {}", next_epoch_id);
// // Return early if the epoch is the first one
// if new_epoch_id == 1 {
// // Creates a new bucket for the rewards flowing from this time on, i.e. to be distributed in the next epoch. Also, forwards the expiring epoch (only 21 epochs are live at a given moment)
Expand All @@ -180,13 +170,11 @@ pub fn execute(

// forward fees from the expiring epoch to the new one.
let mut expiring_epoch = get_expiring_epoch(deps.as_ref())?;
println!("Expiring epoch: {:?}", expiring_epoch);
if let Some(expiring_epoch) = expiring_epoch.as_mut() {
// Load all the available assets from the expiring epoch
let amount_to_be_forwarded = EPOCHS
.load(deps.storage, &expiring_epoch.id.to_be_bytes())?
.available;
println!("Amount to be forwarded: {:?}", amount_to_be_forwarded);
EPOCHS.update(
deps.storage,
&new_epoch_id.to_be_bytes(),
Expand Down Expand Up @@ -271,8 +259,6 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
// Reply entrypoint handling LP withdraws from fill_rewards
#[entry_point]
pub fn reply(deps: DepsMut, _env: Env, msg: Reply) -> Result<Response, ContractError> {
println!("Reply from fill_rewards: {:?}", msg.clone());

match msg.id {
LP_WITHDRAWAL_REPLY_ID => {
// Read the epoch sent by the fee collector through the ForwardFeesResponse
Expand All @@ -282,7 +268,6 @@ pub fn reply(deps: DepsMut, _env: Env, msg: Reply) -> Result<Response, ContractE
.ok_or(ContractError::Unauthorized {})?;

let coins: Vec<Coin> = from_json(data.as_slice())?;
println!("Coins: {:?}", coins);
let config = CONFIG.load(deps.storage)?;
let distribution_denom = config.distribution_denom.clone();
let mut messages = vec![];
Expand Down Expand Up @@ -333,8 +318,6 @@ pub fn reply(deps: DepsMut, _env: Env, msg: Reply) -> Result<Response, ContractE
Some(epoch_id) => epoch_id?,
None => return Err(ContractError::Unauthorized {}),

Check warning on line 319 in contracts/liquidity_hub/bonding-manager/src/contract.rs

View check run for this annotation

Codecov / codecov/patch

contracts/liquidity_hub/bonding-manager/src/contract.rs#L319

Added line #L319 was not covered by tests
};
let epoch_to_log = EPOCHS.load(deps.storage, &next_epoch_id)?;
println!("Most recent epoch: {:?}", epoch_to_log);
EPOCHS.update(deps.storage, &next_epoch_id, |bucket| -> StdResult<_> {
let mut bucket = bucket.unwrap_or_default();
bucket.available = asset::aggregate_coins(bucket.available, vec![whale.clone()])?;
Expand Down
3 changes: 0 additions & 3 deletions contracts/liquidity_hub/bonding-manager/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ pub fn validate_funds(deps: &DepsMut, info: &MessageInfo) -> Result<Coin, Contra
pub fn validate_claimed(deps: &DepsMut, _info: &MessageInfo) -> Result<(), ContractError> {
// Do a smart query for Claimable
let claimable_rewards: ClaimableEpochsResponse = get_claimable_epochs(deps.as_ref()).unwrap();
println!("Claimable rewards: {:?}", claimable_rewards);
// If epochs is greater than none
if !claimable_rewards.epochs.is_empty() {
return Err(ContractError::UnclaimedRewards {});

Check warning on line 60 in contracts/liquidity_hub/bonding-manager/src/helpers.rs

View check run for this annotation

Codecov / codecov/patch

contracts/liquidity_hub/bonding-manager/src/helpers.rs#L60

Added line #L60 was not covered by tests
Expand Down Expand Up @@ -108,11 +107,9 @@ pub fn calculate_epoch(

let elapsed_time =
Uint64::new(timestamp.nanos()).checked_sub(genesis_epoch_config.genesis_epoch)?;
println!("Elapsed time: {:?}", elapsed_time);
let epoch = elapsed_time
.checked_div(epoch_duration)?

Check warning on line 111 in contracts/liquidity_hub/bonding-manager/src/helpers.rs

View check run for this annotation

Codecov / codecov/patch

contracts/liquidity_hub/bonding-manager/src/helpers.rs#L111

Added line #L111 was not covered by tests
.checked_add(Uint64::one())?;
println!("Epoch: {:?}", epoch);

Ok(epoch)
}
Expand Down
7 changes: 0 additions & 7 deletions contracts/liquidity_hub/bonding-manager/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ pub(crate) fn query_bonded(deps: Deps, address: String) -> StdResult<BondedRespo
Ok(bond)
})
.collect::<StdResult<Vec<Bond>>>()?;
println!("bonds is empty : {:?}", bonds.is_empty());

// if it doesn't have bonded, return empty response
if bonds.is_empty() {
Expand All @@ -47,7 +46,6 @@ pub(crate) fn query_bonded(deps: Deps, address: String) -> StdResult<BondedRespo
first_bonded_epoch_id: Uint64::zero(),

Check warning on line 46 in contracts/liquidity_hub/bonding-manager/src/queries.rs

View check run for this annotation

Codecov / codecov/patch

contracts/liquidity_hub/bonding-manager/src/queries.rs#L43-L46

Added lines #L43 - L46 were not covered by tests
});
}
println!("bonds: {:?}", bonds);

let mut total_bonded = Uint128::zero();
let mut bonded_assets = vec![];
Expand Down Expand Up @@ -105,7 +103,6 @@ pub(crate) fn query_unbonding(
Ok(bond)
})
.collect::<StdResult<Vec<Bond>>>()?;
println!("unbonding: {:?}", unbonding);
// aggregate all the amounts in unbonding vec and return uint128
let unbonding_amount = unbonding.iter().try_fold(Uint128::zero(), |acc, bond| {
acc.checked_add(bond.asset.amount)
Expand Down Expand Up @@ -182,7 +179,6 @@ pub(crate) fn query_weight(
config.growth_rate,
bond.timestamp,
)?;
println!("bond: {:?}", bond);

if !unique_denoms.contains(&bond.asset.denom) {
unique_denoms.insert(bond.asset.denom.clone());
Expand All @@ -200,7 +196,6 @@ pub(crate) fn query_weight(
.unwrap_or_else(|_| Some(GlobalIndex::default()))
.ok_or_else(|| StdError::generic_err("Global index not found"))?

Check warning on line 197 in contracts/liquidity_hub/bonding-manager/src/queries.rs

View check run for this annotation

Codecov / codecov/patch

contracts/liquidity_hub/bonding-manager/src/queries.rs#L196-L197

Added lines #L196 - L197 were not covered by tests
};
println!("unique_denoms: {:?}", global_index);

// If a global weight from an Epoch was passed, use that to get the weight, otherwise use the current global index weight
global_index.weight = get_weight(
Expand All @@ -210,7 +205,6 @@ pub(crate) fn query_weight(
config.growth_rate,
global_index.timestamp,
)?;
println!("unique_denoms: {:?}", global_index);

// Represents the share of the global weight that the address has
// If global_index.weight is zero no one has bonded yet so the share is
Expand Down Expand Up @@ -338,7 +332,6 @@ pub fn query_claimable(deps: Deps, address: &Addr) -> StdResult<ClaimableEpochsR
claimable_epochs.retain(|epoch| epoch.id > bonded_response.first_bonded_epoch_id);
}
};
println!("claimable_epochs: {:?}", claimable_epochs);
// filter out epochs that have no available fees. This would only happen in case the grace period
// gets increased after epochs have expired, which would lead to make them available for claiming
// again without any available rewards, as those were forwarded to newer epochs.
Expand Down
3 changes: 0 additions & 3 deletions contracts/liquidity_hub/bonding-manager/src/tests/claim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ fn test_claimable_epochs() {
.add_epochs_to_state(epochs)
.query_claimable_epochs(None, |res| {
let (_, epochs) = res.unwrap();
println!("{:?}", epochs);
assert_eq!(epochs.len(), claimable_epochs.len());
for (e, a) in epochs.iter().zip(claimable_epochs.iter()) {
assert_eq!(e, *a);
Expand Down Expand Up @@ -244,7 +243,6 @@ fn test_claim_successfully() {

robot.claim(sender, |res| {
let result = res.unwrap();
println!("{:?}", result);
assert!(result.events.iter().any(|event| {
event
.attributes
Expand All @@ -255,7 +253,6 @@ fn test_claim_successfully() {

robot.claim(another_sender, |res| {
let result = res.unwrap();
println!("{:?}", result);
assert!(result.events.iter().any(|event| {
event
.attributes
Expand Down

0 comments on commit 0f77427

Please sign in to comment.