Skip to content

Commit

Permalink
chore: fix PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kerber0x committed May 20, 2024
1 parent c26315d commit 2bee41f
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"additionalProperties": false
},
{
"description": "Sends withdrawable unbonded tokens to the user.",
"description": "Sends withdrawable assets of the given denom to the user. An asset becomes withdrawable after it has been unbonded and the unbonding period has passed.",
"type": "object",
"required": [
"withdraw"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"additionalProperties": false
},
{
"description": "Sends withdrawable unbonded tokens to the user.",
"description": "Sends withdrawable assets of the given denom to the user. An asset becomes withdrawable after it has been unbonded and the unbonding period has passed.",
"type": "object",
"required": [
"withdraw"
Expand Down
13 changes: 6 additions & 7 deletions contracts/liquidity_hub/bonding-manager/src/bonding/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ pub(crate) fn bond(

GLOBAL.save(deps.storage, &global_index)?;

// first time the user bonds it shouldn't be able to claim rewards until the next epoch. This is
// why we save the last claimed epoch as the current epoch.
// In case the user has already bonded before, it won't be able to bond again without first
// claiming the pending rewards, in which case the last claimed epoch will be updated to the
// current epoch anyway.
LAST_CLAIMED_EPOCH.save(deps.storage, &info.sender, &current_epoch.epoch.id)?;

Ok(Response::default().add_attributes(vec![
Expand Down Expand Up @@ -125,12 +130,6 @@ pub(crate) fn unbond(
if bonds_by_receiver.is_empty() {
Err(ContractError::NothingToUnbond)
} else {
// sanity check
ensure!(
bonds_by_receiver.len() == 1usize,
ContractError::AssetMismatch
);

let mut unbond = bonds_by_receiver[0].clone();

// check if the address has enough bond
Expand Down Expand Up @@ -192,7 +191,7 @@ pub(crate) fn unbond(
}
}

/// Withdraws the rewards for the provided address
/// Withdraws the unbonded asset of the given denom for the provided address
pub(crate) fn withdraw(
deps: DepsMut,
address: Addr,
Expand Down
4 changes: 2 additions & 2 deletions contracts/liquidity_hub/bonding-manager/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ pub fn swap_coins_to_main_token(
coins: Vec<Coin>,
deps: &DepsMut,
config: Config,
to_be_distribution_asset: &mut Coin,
distribution_asset: &mut Coin,
distribution_denom: &String,
messages: &mut Vec<CosmosMsg>,
) -> Result<(), ContractError> {
Expand Down Expand Up @@ -233,7 +233,7 @@ pub fn swap_coins_to_main_token(

// Add the simulate amount received to the distribution_denom amount, if the swap fails this should
// also be rolled back
to_be_distribution_asset.amount = to_be_distribution_asset
distribution_asset.amount = distribution_asset
.amount
.checked_add(simulate_swap_operations_response.amount)?;

Expand Down
19 changes: 8 additions & 11 deletions contracts/liquidity_hub/bonding-manager/src/rewards/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,16 @@ pub(crate) fn on_epoch_created(
ContractError::Unauthorized
);

let global = GLOBAL.may_load(deps.storage)?;
// This happens only on the very first epoch where Global has not been initialised yet
if global.is_none() {
let initial_global_index = GlobalIndex {
let mut global_index = GLOBAL.load(deps.storage).unwrap_or(
// This happens only on the very first epoch where Global has not been initialised yet
GlobalIndex {
epoch_id: current_epoch.id,
last_updated: current_epoch.id,
..Default::default()
};
GLOBAL.save(deps.storage, &initial_global_index)?;
}
},
);

// Update the global index epoch id
let mut global_index = GLOBAL.load(deps.storage)?;
global_index.epoch_id = current_epoch.id;

if global_index.bonded_amount == Uint128::zero() {
Expand Down Expand Up @@ -100,7 +97,7 @@ pub(crate) fn fill_rewards(
let mut submessages: Vec<SubMsg> = vec![];
// swap non-whale to whale

let mut distribution_denom_in_tx = info
let mut distribution_asset_in_tx = info
.funds
.iter()
.find(|coin| coin.denom.eq(distribution_denom.as_str()))
Expand All @@ -126,7 +123,7 @@ pub(crate) fn fill_rewards(
remnant_coins,
&deps,
config,
&mut distribution_denom_in_tx,
&mut distribution_asset_in_tx,
&distribution_denom,
&mut messages,
)?;
Expand All @@ -136,7 +133,7 @@ pub(crate) fn fill_rewards(
// Because we are using minimum receive, it is possible the contract can accumulate micro amounts of whale if we get more than what the swap query returned
// If this became an issue we could look at replies instead of the query
// The lp_tokens being withdrawn are handled in the reply entry point
fill_upcoming_reward_bucket(deps, distribution_denom_in_tx.clone())?;
fill_upcoming_reward_bucket(deps, distribution_asset_in_tx.clone())?;

Ok(Response::default()
.add_messages(messages)
Expand Down
2 changes: 1 addition & 1 deletion contracts/liquidity_hub/bonding-manager/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub const BONDING_ASSETS_LIMIT: usize = 2;
pub const CONFIG: Item<Config> = Item::new("config");

/// A monotonically increasing counter to generate unique bond ids.
pub const BOND_COUNTER: Item<u64> = Item::new("bond_id_counter");
pub const BOND_COUNTER: Item<u64> = Item::new("bond_counter");
pub const BONDS: IndexedMap<u64, Bond, BondIndexes> = IndexedMap::new(
"bonds",
BondIndexes {
Expand Down
35 changes: 18 additions & 17 deletions contracts/liquidity_hub/epoch-manager/tests/epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use cosmwasm_std::from_json;
use cosmwasm_std::testing::{mock_env, mock_info};

use epoch_manager::contract::{execute, query};
use epoch_manager::ContractError;
use white_whale_std::epoch_manager::epoch_manager::{Epoch, EpochResponse, ExecuteMsg, QueryMsg};
use white_whale_std::epoch_manager::hooks::EpochChangedHookMsg;
use white_whale_std::pool_network::mock_querier::mock_dependencies;
Expand Down Expand Up @@ -61,20 +62,20 @@ fn create_new_epoch_successfully() {
);
}

// #[test]
// fn create_new_epoch_unsuccessfully() {
// let mut deps = mock_dependencies(&[]);
// let info = mock_info("owner", &[]);
// let mut env = mock_env();
// mock_instantiation(deps.as_mut(), info.clone()).unwrap();

// // move time ahead but not enough so the epoch creation fails
// env.block.time = env.block.time.plus_nanos(86300);

// let msg = ExecuteMsg::CreateEpoch;
// let err = execute(deps.as_mut(), env, info, msg).unwrap_err();
// match err {
// ContractError::CurrentEpochNotExpired => {}
// _ => panic!("should return ContractError::CurrentEpochNotExpired"),
// }
// }
#[test]
fn create_new_epoch_unsuccessfully() {
let mut deps = mock_dependencies(&[]);
let info = mock_info("owner", &[]);
let mut env = mock_env();
mock_instantiation(deps.as_mut(), info.clone()).unwrap();

// move time ahead but not enough so the epoch creation fails
env.block.time = env.block.time.plus_nanos(86300);

let msg = ExecuteMsg::CreateEpoch;
let err = execute(deps.as_mut(), env, info, msg).unwrap_err();
match err {
ContractError::CurrentEpochNotExpired => {}
_ => panic!("should return ContractError::CurrentEpochNotExpired"),
}
}
3 changes: 1 addition & 2 deletions contracts/liquidity_hub/incentive-manager/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ pub const LAST_CLAIMED_EPOCH: Map<&Addr, EpochId> = Map::new("last_claimed_epoch
/// The lp weight history for addresses, including the contract. i.e. how much lp weight an address
/// or contract has at a given epoch.
/// Key is a tuple of (address, lp_denom, epoch_id), value is the lp weight.
pub const LP_WEIGHT_HISTORY: Map<(&Addr, &str, EpochId), Uint128> =
Map::new("address_lp_weight_history");
pub const LP_WEIGHT_HISTORY: Map<(&Addr, &str, EpochId), Uint128> = Map::new("lp_weight_history");

/// A monotonically increasing counter to generate unique incentive identifiers.
pub const INCENTIVE_COUNTER: Item<u64> = Item::new("incentive_counter");
Expand Down
3 changes: 2 additions & 1 deletion packages/white-whale-std/src/bonding_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ pub enum ExecuteMsg {
/// The asset to unbond.
asset: Coin,
},
/// Sends withdrawable unbonded tokens to the user.
/// Sends withdrawable assets of the given denom to the user. An asset becomes withdrawable after
/// it has been unbonded and the unbonding period has passed.
Withdraw {
/// The denom to withdraw.
denom: String,
Expand Down

0 comments on commit 2bee41f

Please sign in to comment.