diff --git a/artifacts/checksums.txt b/artifacts/checksums.txt index ab72c48..499ec07 100644 --- a/artifacts/checksums.txt +++ b/artifacts/checksums.txt @@ -1,2 +1,2 @@ -98e7c175d92fb0c9791886af183f65a21c88e85ead116c8eac50a68d1595776a hydro.wasm +f8a0ea2d42c8439742497b6f0f86a0b2b427a82f949fd3a639bf19706ba32319 hydro.wasm 83f12ed4aa3b4900588096c639a9abec78080a4c91720442b47cba1b8059e63a tribute.wasm diff --git a/artifacts/hydro.wasm b/artifacts/hydro.wasm index ab9775f..af2c39f 100644 Binary files a/artifacts/hydro.wasm and b/artifacts/hydro.wasm differ diff --git a/contracts/hydro/src/contract.rs b/contracts/hydro/src/contract.rs index dfded0c..2b1f7fd 100644 --- a/contracts/hydro/src/contract.rs +++ b/contracts/hydro/src/contract.rs @@ -289,8 +289,8 @@ fn lock_tokens( let funds = info.funds[0].clone(); - let validator = - validate_denom(deps.as_ref(), current_round, &constants, funds.denom).map_err(|err| { + let validator = validate_denom(&deps.as_ref(), current_round, &constants, funds.denom) + .map_err(|err| { ContractError::Std(StdError::generic_err(format!("validating denom: {}", err))) })?; @@ -306,7 +306,7 @@ fn lock_tokens( )?; // validate that the user does not have too many locks - if get_lock_count(deps.as_ref(), info.sender.clone()) >= MAX_LOCK_ENTRIES { + if get_lock_count(&deps.as_ref(), info.sender.clone()) >= MAX_LOCK_ENTRIES { return Err(ContractError::Std(StdError::generic_err(format!( "User has too many locks, only {} locks allowed", MAX_LOCK_ENTRIES @@ -453,7 +453,7 @@ fn refresh_lock_duration( } fn refresh_single_lock( - deps: &mut DepsMut<'_, NeutronQuery>, + deps: &mut DepsMut, info: &MessageInfo, env: &Env, constants: &Constants, @@ -479,7 +479,7 @@ fn refresh_single_lock( env.block.height, )?; let validator_result = validate_denom( - deps.as_ref(), + &deps.as_ref(), current_round_id, constants, lock_entry.funds.denom.clone(), @@ -666,7 +666,7 @@ fn unlock_tokens( fn validate_previous_round_vote( deps: &DepsMut, env: &Env, - sender: Addr, + sender: &Addr, ) -> Result<(), ContractError> { let constants = load_current_constants(&deps.as_ref(), env)?; let current_round_id = compute_current_round_id(env, &constants)?; @@ -907,7 +907,7 @@ fn vote( // save the new power into the proposal let total_power = get_total_power_for_proposal(deps.as_ref().storage, vote.prop_id)?; - proposal.power = total_power.to_uint_ceil(); // TODO: decide whether we need to round or represent as decimals + proposal.power = total_power.to_uint_ceil(); // Save the proposal PROPOSAL_MAP.save( @@ -979,7 +979,7 @@ fn vote( // get the validator from the denom let validator = match validate_denom( - deps.as_ref(), + &deps.as_ref(), round_id, &constants, lock_entry.clone().funds.denom, @@ -1002,7 +1002,7 @@ fn vote( get_lock_time_weighted_shares( &constants.round_lock_power_schedule, round_end, - lock_entry.clone(), + &lock_entry, lock_epoch_length, ), Uint128::one(), @@ -1077,7 +1077,7 @@ fn vote( pub fn get_lock_time_weighted_shares( round_lock_power_schedule: &RoundLockPowerSchedule, round_end: Timestamp, - lock_entry: LockEntry, + lock_entry: &LockEntry, lock_epoch_length: u64, ) -> Uint128 { if round_end.nanos() > lock_entry.lock_end.nanos() { @@ -1427,7 +1427,7 @@ fn create_icqs_for_validators( // Validates that enough funds were sent to create ICQs for the given validator addresses. fn validate_icq_deposit_funds_sent( - deps: DepsMut<'_, NeutronQuery>, + deps: DepsMut, info: &MessageInfo, num_created_icqs: u64, ) -> Result<(), ContractError> { @@ -1694,27 +1694,27 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult to_json_binary(&query_all_user_lockups( - deps, env, address, start_from, limit, + &deps, &env, address, start_from, limit, )?), - QueryMsg::SpecificUserLockups { address, lock_ids } => { - to_json_binary(&query_specific_user_lockups(deps, env, address, lock_ids)?) - } + QueryMsg::SpecificUserLockups { address, lock_ids } => to_json_binary( + &query_specific_user_lockups(&deps, &env, address, lock_ids)?, + ), QueryMsg::AllUserLockupsWithTrancheInfos { address, start_from, limit, } => to_json_binary(&query_all_user_lockups_with_tranche_infos( - deps, env, address, start_from, limit, + &deps, &env, address, start_from, limit, )?), QueryMsg::SpecificUserLockupsWithTrancheInfos { address, lock_ids } => to_json_binary( - &query_specific_user_lockups_with_tranche_infos(deps, env, address, lock_ids)?, + &query_specific_user_lockups_with_tranche_infos(&deps, &env, address, lock_ids)?, ), QueryMsg::ExpiredUserLockups { address, start_from, limit, } => to_json_binary(&query_expired_user_lockups( - deps, env, address, start_from, limit, + &deps, &env, address, start_from, limit, )?), QueryMsg::UserVotingPower { address } => { to_json_binary(&query_user_voting_power(deps, env, address)?) @@ -1824,9 +1824,9 @@ pub fn query_round_total_power( deps: Deps, round_id: u64, ) -> StdResult { - let total_round_power = get_total_power_for_round(deps, round_id)?; + let total_round_power = get_total_power_for_round(&deps, round_id)?; Ok(RoundTotalVotingPowerResponse { - total_voting_power: total_round_power.to_uint_ceil(), // TODO: decide on rounding + total_voting_power: total_round_power.to_uint_ceil(), }) } @@ -1837,8 +1837,8 @@ pub fn query_constants(deps: Deps, env: Env) -> StdResult, - env: Env, + deps: &Deps, + env: &Env, address: String, predicate: impl FnMut(&LockEntry) -> bool, start_from: u32, @@ -1848,8 +1848,8 @@ fn get_user_lockups_with_predicate( let raw_lockups = query_user_lockups(deps, addr, predicate, start_from, limit); - let constants = load_current_constants(&deps, &env)?; - let current_round_id = compute_current_round_id(&env, &constants)?; + let constants = load_current_constants(deps, env)?; + let current_round_id = compute_current_round_id(env, &constants)?; let round_end = compute_round_end(&constants, current_round_id)?; // enrich the lockups by computing the voting power for each lockup @@ -1864,8 +1864,8 @@ fn get_user_lockups_with_predicate( } pub fn query_all_user_lockups( - deps: Deps, - env: Env, + deps: &Deps, + env: &Env, address: String, start_from: u32, limit: u32, @@ -1875,8 +1875,8 @@ pub fn query_all_user_lockups( } pub fn query_specific_user_lockups( - deps: Deps, - env: Env, + deps: &Deps, + env: &Env, address: String, lock_ids: Vec, ) -> StdResult { @@ -1896,8 +1896,8 @@ pub fn query_specific_user_lockups( // Helper function to handle the common logic for both query functions fn enrich_lockups_with_tranche_infos( - deps: Deps, - env: Env, + deps: &Deps, + env: &Env, address: String, lockups: Vec, ) -> StdResult> { @@ -1908,8 +1908,8 @@ fn enrich_lockups_with_tranche_infos( .map(|tranche| tranche.unwrap().1.id) .collect::>(); - let constants = load_current_constants(&deps, &env)?; - let current_round_id = compute_current_round_id(&env, &constants)?; + let constants = load_current_constants(deps, env)?; + let current_round_id = compute_current_round_id(env, &constants)?; // enrich lockups with some info per tranche let lockups_with_per_tranche_info: Vec = lockups @@ -1984,13 +1984,13 @@ fn enrich_lockups_with_tranche_infos( } pub fn query_all_user_lockups_with_tranche_infos( - deps: Deps, - env: Env, + deps: &Deps, + env: &Env, address: String, start_from: u32, limit: u32, ) -> StdResult { - let lockups = query_all_user_lockups(deps, env.clone(), address.clone(), start_from, limit)?; + let lockups = query_all_user_lockups(deps, env, address.clone(), start_from, limit)?; let enriched_lockups = enrich_lockups_with_tranche_infos(deps, env, address, lockups.lockups)?; Ok(AllUserLockupsWithTrancheInfosResponse { lockups_with_per_tranche_infos: enriched_lockups, @@ -1998,12 +1998,12 @@ pub fn query_all_user_lockups_with_tranche_infos( } pub fn query_specific_user_lockups_with_tranche_infos( - deps: Deps, - env: Env, + deps: &Deps, + env: &Env, address: String, lock_ids: Vec, ) -> StdResult { - let lockups = query_specific_user_lockups(deps, env.clone(), address.clone(), lock_ids)?; + let lockups = query_specific_user_lockups(deps, env, address.clone(), lock_ids)?; let enriched_lockups = enrich_lockups_with_tranche_infos(deps, env, address, lockups.lockups)?; Ok(SpecificUserLockupsWithTrancheInfosResponse { @@ -2012,8 +2012,8 @@ pub fn query_specific_user_lockups_with_tranche_infos( } pub fn query_expired_user_lockups( - deps: Deps, - env: Env, + deps: &Deps, + env: &Env, address: String, start_from: u32, limit: u32, @@ -2133,7 +2133,7 @@ pub fn get_user_voting_power_for_past_round( } }) .map(|lockup| { - to_lockup_with_power(*deps, constants, round_id, round_end, lockup) + to_lockup_with_power(deps, constants, round_id, round_end, lockup) .current_voting_power .u128() }) @@ -2156,7 +2156,7 @@ where .range(deps.storage, None, None, Order::Ascending) .filter_map(filter) .map(|lockup| { - to_lockup_with_power(*deps, constants, round_id, round_end, lockup) + to_lockup_with_power(deps, constants, round_id, round_end, lockup) .current_voting_power .u128() }) @@ -2306,7 +2306,7 @@ pub fn query_top_n_proposals( } // get total voting power for the round - let total_voting_power = get_total_power_for_round(deps, round_id)?.to_uint_ceil(); // TODO: decide on rounding + let total_voting_power = get_total_power_for_round(&deps, round_id)?.to_uint_ceil(); let top_proposals = top_props .into_iter() @@ -2338,7 +2338,7 @@ pub fn query_tranches(deps: Deps) -> StdResult { } fn query_user_lockups( - deps: Deps, + deps: &Deps, user_address: Addr, predicate: impl FnMut(&LockEntry) -> bool, start_from: u32, @@ -2489,14 +2489,14 @@ fn update_voting_power_on_proposals( Some(lock_entry) => get_lock_time_weighted_shares( &constants.round_lock_power_schedule, round_end, - lock_entry.clone(), + lock_entry, lock_epoch_length, ), }; let new_scaled_shares = get_lock_time_weighted_shares( &constants.round_lock_power_schedule, round_end, - new_lock_entry.clone(), + &new_lock_entry, lock_epoch_length, ); @@ -2779,7 +2779,7 @@ where } // Returns the number of locks for a given user -fn get_lock_count(deps: Deps, user_address: Addr) -> usize { +fn get_lock_count(deps: &Deps, user_address: Addr) -> usize { LOCKS_MAP .prefix(user_address) .range(deps.storage, None, None, Order::Ascending) @@ -2787,7 +2787,7 @@ fn get_lock_count(deps: Deps, user_address: Addr) -> usize { } fn to_lockup_with_power( - deps: Deps, + deps: &Deps, constants: &Constants, round_id: u64, round_end: Timestamp, @@ -2819,7 +2819,7 @@ fn to_lockup_with_power( let time_weighted_shares = get_lock_time_weighted_shares( &constants.round_lock_power_schedule, round_end, - lock_entry.clone(), + &lock_entry, constants.lock_epoch_length, ); diff --git a/contracts/hydro/src/lsm_integration.rs b/contracts/hydro/src/lsm_integration.rs index a4de774..32a657b 100644 --- a/contracts/hydro/src/lsm_integration.rs +++ b/contracts/hydro/src/lsm_integration.rs @@ -24,12 +24,12 @@ pub const COSMOS_VALIDATOR_ADDR_LENGTH: usize = 52; // e.g. cosmosvaloper15w6ra6 // of a validator that is also among the top max_validators validators // for the given round, and returns the address of that validator. pub fn validate_denom( - deps: Deps, + deps: &Deps, round_id: u64, constants: &Constants, denom: String, ) -> StdResult { - let validator = resolve_validator_from_denom(&deps, constants, denom)?; + let validator = resolve_validator_from_denom(deps, constants, denom)?; let max_validators = constants.max_validator_shares_participating; if is_active_round_validator(deps.storage, round_id, &validator) { @@ -85,7 +85,7 @@ pub fn is_active_round_validator(storage: &dyn Storage, round_id: u64, validator } // Gets the current list of active validators for the given round -pub fn get_round_validators(deps: Deps, round_id: u64) -> Vec { +pub fn get_round_validators(deps: &Deps, round_id: u64) -> Vec { VALIDATORS_INFO .prefix(round_id) .range(deps.storage, None, None, Order::Ascending) @@ -292,7 +292,7 @@ pub fn update_total_power_due_to_power_ratio_change( Ok(()) } -pub fn get_total_power_for_round(deps: Deps, round_id: u64) -> StdResult { +pub fn get_total_power_for_round(deps: &Deps, round_id: u64) -> StdResult { Ok( match TOTAL_VOTING_POWER_PER_ROUND.may_load(deps.storage, round_id)? { None => Decimal::zero(), diff --git a/contracts/hydro/src/score_keeper.rs b/contracts/hydro/src/score_keeper.rs index d10a0bf..ac55746 100644 --- a/contracts/hydro/src/score_keeper.rs +++ b/contracts/hydro/src/score_keeper.rs @@ -249,7 +249,7 @@ mod tests { let deps = mock_dependencies(no_op_grpc_query_mock()); let index_key = 5; - let total_power = get_total_power_for_round(deps.as_ref(), index_key).unwrap(); + let total_power = get_total_power_for_round(&deps.as_ref(), index_key).unwrap(); assert_eq!(total_power, Decimal::zero()); let total_power = get_total_power_for_proposal(deps.as_ref().storage, index_key).unwrap(); diff --git a/contracts/hydro/src/testing.rs b/contracts/hydro/src/testing.rs index 4472264..f594694 100644 --- a/contracts/hydro/src/testing.rs +++ b/contracts/hydro/src/testing.rs @@ -205,7 +205,7 @@ fn lock_tokens_basic_test() { let res = execute(deps.as_mut(), env.clone(), info2.clone(), msg); assert!(res.is_ok()); - let res = query_all_user_lockups(deps.as_ref(), env.clone(), info.sender.to_string(), 0, 2000); + let res = query_all_user_lockups(&deps.as_ref(), &env, info.sender.to_string(), 0, 2000); assert!(res.is_ok()); let res = res.unwrap(); assert_eq!(2, res.lockups.len()); @@ -3190,8 +3190,8 @@ fn test_refresh_multiple_locks() { // Verify the new lock durations for (sender, expected_durations) in &case.expected_new_lock_durations { let lockups = query_all_user_lockups( - deps.as_ref(), - env.clone(), + &deps.as_ref(), + &env, get_address_as_str(&deps.api, sender), 0, 100, diff --git a/contracts/hydro/src/testing_compounder_cap.rs b/contracts/hydro/src/testing_compounder_cap.rs index 36817a2..7e822d2 100644 --- a/contracts/hydro/src/testing_compounder_cap.rs +++ b/contracts/hydro/src/testing_compounder_cap.rs @@ -157,7 +157,7 @@ fn test_compounder_cap() { (12, 0), ]; for expected_round_power in expected_round_powers { - let res = get_total_power_for_round(deps.as_ref(), expected_round_power.0); + let res = get_total_power_for_round(&deps.as_ref(), expected_round_power.0); assert!(res.is_ok()); assert_eq!(res.unwrap().to_uint_ceil().u128(), expected_round_power.1); } @@ -279,7 +279,7 @@ fn test_compounder_cap() { ]; for expected_round_power in expected_round_powers { - let res = get_total_power_for_round(deps.as_ref(), expected_round_power.0); + let res = get_total_power_for_round(&deps.as_ref(), expected_round_power.0); assert!(res.is_ok()); assert_eq!(res.unwrap().to_uint_ceil().u128(), expected_round_power.1); } diff --git a/contracts/hydro/src/testing_lsm_integration.rs b/contracts/hydro/src/testing_lsm_integration.rs index 94bb1ae..52310fa 100644 --- a/contracts/hydro/src/testing_lsm_integration.rs +++ b/contracts/hydro/src/testing_lsm_integration.rs @@ -326,7 +326,7 @@ fn test_validate_denom() { (test_case.setup)(&mut deps.storage, &mut env); let result = validate_denom( - deps.as_ref(), + &deps.as_ref(), compute_current_round_id(&env, &constants).unwrap(), &constants, test_case.denom.clone(), @@ -729,7 +729,7 @@ fn lock_tokens_multiple_validators_and_vote() { // check the total round power { - let total_power = get_total_power_for_round(deps.as_ref(), 0); + let total_power = get_total_power_for_round(&deps.as_ref(), 0); assert!(total_power.is_ok()); assert_eq!(Uint128::new(4700), total_power.unwrap().to_uint_floor()); } @@ -766,7 +766,7 @@ fn lock_tokens_multiple_validators_and_vote() { // check the new total power { - let total_power = get_total_power_for_round(deps.as_ref(), 0); + let total_power = get_total_power_for_round(&deps.as_ref(), 0); assert!(total_power.is_ok()); assert_eq!(Uint128::new(4200), total_power.unwrap().to_uint_floor()); } diff --git a/contracts/hydro/src/testing_queries.rs b/contracts/hydro/src/testing_queries.rs index eeeb301..688fa2f 100644 --- a/contracts/hydro/src/testing_queries.rs +++ b/contracts/hydro/src/testing_queries.rs @@ -85,8 +85,8 @@ fn query_user_lockups_test() { // Query specific lockup by ID using query_specific_user_lockups let res = query_specific_user_lockups( - deps.as_ref(), - env.clone(), + &deps.as_ref(), + &env, info.sender.to_string(), vec![0], // Query only the first lockup ); @@ -101,8 +101,8 @@ fn query_user_lockups_test() { // Query for a non-existent lockup ID let res = query_specific_user_lockups( - deps.as_ref(), - env.clone(), + &deps.as_ref(), + &env, info.sender.to_string(), vec![999], // Non-existent lockup ID ); @@ -160,8 +160,8 @@ fn query_user_lockups_test() { // but they should have 2 lockups let res = query_all_user_lockups_with_tranche_infos( - deps.as_ref(), - env.clone(), + &deps.as_ref(), + &env, info.sender.to_string(), 0, 2000, @@ -222,8 +222,8 @@ fn query_user_lockups_test() { // Query specific lockup by ID using query_specific_user_lockups_with_tranche_infos let res = query_specific_user_lockups_with_tranche_infos( - deps.as_ref(), - env.clone(), + &deps.as_ref(), + &env, info.sender.to_string(), vec![1], // Query only the second lockup ); @@ -248,8 +248,8 @@ fn query_user_lockups_test() { ); let res = query_specific_user_lockups_with_tranche_infos( - deps.as_ref(), - env.clone(), + &deps.as_ref(), + &env, info.sender.to_string(), vec![999], // Non-existent lockup ID ); @@ -274,8 +274,8 @@ fn query_user_lockups_test() { ); let all_lockups = query_all_user_lockups_with_tranche_infos( - deps.as_ref(), - env.clone(), + &deps.as_ref(), + &env, info.sender.to_string(), 0, 2000, @@ -362,8 +362,8 @@ fn query_user_lockups_test() { assert_eq!(second_lockup_amount, expired_lockups[1].funds.amount.u128()); let all_lockups = query_all_user_lockups_with_tranche_infos( - deps.as_ref(), - env.clone(), + &deps.as_ref(), + &env, info.sender.to_string(), 0, 2000, @@ -417,7 +417,7 @@ fn query_user_lockups_test() { assert_eq!(0, expired_lockups.len()); let all_lockups = - query_all_user_lockups(deps.as_ref(), env.clone(), info.sender.to_string(), 0, 2000); + query_all_user_lockups(&deps.as_ref(), &env, info.sender.to_string(), 0, 2000); assert!(all_lockups.is_ok()); let all_lockups = all_lockups.unwrap(); @@ -852,13 +852,7 @@ fn get_expired_user_lockups( env: Env, user_address: String, ) -> Vec { - let res = query_expired_user_lockups( - deps.as_ref(), - env.clone(), - user_address.to_string(), - 0, - 2000, - ); + let res = query_expired_user_lockups(&deps.as_ref(), &env, user_address.to_string(), 0, 2000); assert!(res.is_ok()); let res = res.unwrap(); diff --git a/contracts/hydro/src/utils.rs b/contracts/hydro/src/utils.rs index d01dd3e..e57a236 100644 --- a/contracts/hydro/src/utils.rs +++ b/contracts/hydro/src/utils.rs @@ -102,7 +102,7 @@ pub fn validate_locked_tokens_caps( // If there is still room in known_users_cap, then check if this // is a user that should be allowed to use the known_users_cap. can_user_lock_in_known_users_cap( - deps, + &deps.as_ref(), constants, current_round, sender, @@ -126,7 +126,13 @@ pub fn validate_locked_tokens_caps( // If there is still room in known_users_cap, then check if this // is a user that should be allowed to use the known_users_cap. - can_user_lock_in_known_users_cap(deps, constants, current_round, sender, amount_to_lock)?; + can_user_lock_in_known_users_cap( + &deps.as_ref(), + constants, + current_round, + sender, + amount_to_lock, + )?; Ok(LockingInfo { lock_in_public_cap: None, @@ -135,7 +141,7 @@ pub fn validate_locked_tokens_caps( } fn can_user_lock_in_known_users_cap( - deps: &DepsMut, + deps: &Deps, constants: &Constants, current_round: u64, sender: &Addr, @@ -164,15 +170,10 @@ fn can_user_lock_in_known_users_cap( // Calculate user's voting power share in the total voting power let users_voting_power = Decimal::from_ratio( - get_user_voting_power_for_past_round( - &deps.as_ref(), - constants, - sender.clone(), - round_to_check, - )?, + get_user_voting_power_for_past_round(deps, constants, sender.clone(), round_to_check)?, Uint128::one(), ); - let total_voting_power = get_total_power_for_round(deps.as_ref(), round_to_check)?; + let total_voting_power = get_total_power_for_round(deps, round_to_check)?; // Prevent division by zero or break early in case user had no voting power in previous round. if total_voting_power == Decimal::zero() || users_voting_power == Decimal::zero() {