diff --git a/contracts/alliance-lp-hub/src/contract.rs b/contracts/alliance-lp-hub/src/contract.rs index 70f7c5c..bfab3b0 100644 --- a/contracts/alliance-lp-hub/src/contract.rs +++ b/contracts/alliance-lp-hub/src/contract.rs @@ -68,9 +68,9 @@ pub fn instantiate( let config = Config { governance: governance_address, controller: controller_address, - fee_collector_addr: fee_collector_addr, + fee_collector_addr, - astro_incentives_addr: astro_incentives_addr, + astro_incentives_addr, astro_reward_denom: msg.astro_reward_denom, alliance_token_denom: "".to_string(), @@ -398,7 +398,7 @@ fn unstake( let astro_rewards = _claim_astro_rewards( deps.storage, sender.clone(), - AssetInfoKey::from(deposit_asset.clone()), + deposit_asset.clone(), astro_reward_token.clone(), )?; @@ -414,7 +414,7 @@ fn unstake( let withdraw_msg: CosmosMsg = CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: config.astro_incentives_addr.to_string(), msg: to_json_binary(&ExecuteAstroMsg::Withdraw { - lp_token: lp_token, + lp_token, amount: asset.amount, })?, funds: vec![], @@ -565,7 +565,7 @@ fn claim_rewards( astro_reward_token, ), ); - res = res.add_attribute("astro_reward_amount", &final_astro_rewards.to_string()); + res = res.add_attribute("astro_reward_amount", final_astro_rewards.to_string()); if !final_astro_rewards.is_zero() { let info = match deps.api.addr_validate(&config.astro_reward_denom) { Ok(addr) => AssetInfo::Cw20(addr), @@ -573,7 +573,7 @@ fn claim_rewards( }; let rewards_asset = Asset { - info: info, + info, amount: final_astro_rewards, }; res = res.add_message(rewards_asset.transfer_msg(&user)?) @@ -760,7 +760,8 @@ fn _update_astro_rewards( let (asset_info, _) = f?; let asset_info = asset_info.check(deps.api, None)?; let asset_string = asset_info.to_string(); - let asset_denom = asset_string.split(":").collect::>()[1].to_string(); + let splitter = char::from_str(":").unwrap(); + let asset_denom = asset_string.split(splitter).collect::>()[1].to_string(); whitelist.push(asset_denom); } diff --git a/contracts/alliance-lp-hub/src/models.rs b/contracts/alliance-lp-hub/src/models.rs index 3cfe77c..2e822cc 100644 --- a/contracts/alliance-lp-hub/src/models.rs +++ b/contracts/alliance-lp-hub/src/models.rs @@ -34,7 +34,7 @@ pub struct InstantiateMsg { pub astro_reward_denom: String, pub astro_incentives_addr: String, - + pub alliance_reward_denom: String, } diff --git a/contracts/alliance-lp-hub/src/state.rs b/contracts/alliance-lp-hub/src/state.rs index 8040a28..01d18e4 100644 --- a/contracts/alliance-lp-hub/src/state.rs +++ b/contracts/alliance-lp-hub/src/state.rs @@ -38,7 +38,8 @@ pub const USER_ASSET_REWARD_RATE: Map<(Addr, AssetInfoKey, AssetInfoKey), Decima // - AssetInfoKey: is the asset that is being deposited, // - AssetInfoKey: is the asset that is being rewarded, // - Decimal: is the reward rate, -pub const UNCLAIMED_REWARDS: Map<(Addr, AssetInfoKey, AssetInfoKey), Uint128> = Map::new("unclaimed_rewards"); +pub const UNCLAIMED_REWARDS: Map<(Addr, AssetInfoKey, AssetInfoKey), Uint128> = + Map::new("unclaimed_rewards"); pub const TEMP_BALANCE: Map = Map::new("temp_balance"); diff --git a/contracts/alliance-lp-hub/src/tests/helpers.rs b/contracts/alliance-lp-hub/src/tests/helpers.rs index 6acdcc5..1b86c01 100644 --- a/contracts/alliance-lp-hub/src/tests/helpers.rs +++ b/contracts/alliance-lp-hub/src/tests/helpers.rs @@ -45,7 +45,10 @@ pub fn set_alliance_asset(deps: DepsMut) { .unwrap(); } -pub fn modify_asset(deps: DepsMut, assets: Vec) -> Result { +pub fn modify_asset( + deps: DepsMut, + assets: Vec, +) -> Result { let info = mock_info("gov", &[]); let env = mock_env(); @@ -53,14 +56,24 @@ pub fn modify_asset(deps: DepsMut, assets: Vec) -> Result Result { +pub fn stake( + deps: DepsMut, + user: &str, + amount: u128, + denom: &str, +) -> Result { let info = mock_info(user, &[coin(amount, denom)]); let env = mock_env(); let msg = ExecuteMsg::Stake {}; execute(deps, env, info, msg) } -pub fn stake_cw20(deps: DepsMut, user: &str, amount: u128, denom: &str) -> Result { +pub fn stake_cw20( + deps: DepsMut, + user: &str, + amount: u128, + denom: &str, +) -> Result { let mut info = mock_info(user, &[]); let env = mock_env(); let msg = ExecuteMsg::Receive(Cw20ReceiveMsg { @@ -79,10 +92,15 @@ pub fn unstake(deps: DepsMut, user: &str, asset: Asset) -> Result Result { +pub fn unstake_callback( + deps: DepsMut, + sender: &str, + user: &str, + asset: Asset, +) -> Result { let info = mock_info(sender, &[]); let env = mock_env(); - let msg = ExecuteMsg::UnstakeCallback(asset,Addr::unchecked(user)); + let msg = ExecuteMsg::UnstakeCallback(asset, Addr::unchecked(user)); execute(deps, env, info, msg) } diff --git a/contracts/alliance-lp-hub/src/tests/mock_querier.rs b/contracts/alliance-lp-hub/src/tests/mock_querier.rs index 4ff4879..a2ba04a 100644 --- a/contracts/alliance-lp-hub/src/tests/mock_querier.rs +++ b/contracts/alliance-lp-hub/src/tests/mock_querier.rs @@ -16,13 +16,10 @@ pub fn mock_dependencies( ) -> OwnedDeps { let custom_querier: WasmMockQuerier = match balance { Some(b) => { - let balances = vec![ - (ASTRO_MOCK_CONTRACT_ADDR, b), - (MOCK_CONTRACT_ADDR, b) - ]; - + let balances = vec![(ASTRO_MOCK_CONTRACT_ADDR, b), (MOCK_CONTRACT_ADDR, b)]; + WasmMockQuerier::new(MockQuerier::new(&balances)) - }, + } None => WasmMockQuerier::new(MockQuerier::new(&[(ASTRO_MOCK_CONTRACT_ADDR, &[])])), }; // MockQuerier::default() @@ -74,7 +71,7 @@ impl WasmMockQuerier { return SystemResult::Ok(to_json_binary(&msg).into()); } let msg: Vec = vec![]; - return SystemResult::Ok(to_json_binary(&msg).into()); + SystemResult::Ok(to_json_binary(&msg).into()) } QueryAstroMsg::PendingRewards { lp_token, user: _ } => { if lp_token == "factory/astro_native" { @@ -95,7 +92,7 @@ impl WasmMockQuerier { info: AssetInfoBase::cw20(Addr::unchecked(lp_token.to_string())), amount: Uint128::zero(), }]; - return SystemResult::Ok(to_json_binary(&msg).into()); + SystemResult::Ok(to_json_binary(&msg).into()) } QueryAstroMsg::Deposit { lp_token, user: _ } => { if lp_token == "factory/astro_native" { @@ -103,7 +100,7 @@ impl WasmMockQuerier { } else if lp_token == "terra_astro_cw20" { return SystemResult::Ok(to_json_binary(&Uint128::new(50)).into()); } - return SystemResult::Ok(to_json_binary(&Uint128::zero()).into()); + SystemResult::Ok(to_json_binary(&Uint128::zero()).into()) } }, _ => self.base.handle_query(request), diff --git a/contracts/alliance-lp-hub/src/tests/mod.rs b/contracts/alliance-lp-hub/src/tests/mod.rs index eeddb74..bece28e 100644 --- a/contracts/alliance-lp-hub/src/tests/mod.rs +++ b/contracts/alliance-lp-hub/src/tests/mod.rs @@ -2,6 +2,6 @@ mod alliance; mod helpers; mod instantiate; mod mock_querier; +mod modify_asset; mod rewards; mod stake_unstake; -mod modify_asset; \ No newline at end of file diff --git a/contracts/alliance-lp-hub/src/tests/modify_asset.rs b/contracts/alliance-lp-hub/src/tests/modify_asset.rs index f5d9018..3307d7d 100644 --- a/contracts/alliance-lp-hub/src/tests/modify_asset.rs +++ b/contracts/alliance-lp-hub/src/tests/modify_asset.rs @@ -1,7 +1,7 @@ use crate::models::ModifyAssetPair; use crate::tests::helpers::{modify_asset, setup_contract, stake}; use alliance_protocol::error::ContractError; -use cosmwasm_std::{Response, testing::mock_dependencies}; +use cosmwasm_std::{testing::mock_dependencies, Response}; use cw_asset::AssetInfo; #[test] diff --git a/contracts/alliance-lp-hub/src/tests/stake_unstake.rs b/contracts/alliance-lp-hub/src/tests/stake_unstake.rs index e2bac17..552934c 100644 --- a/contracts/alliance-lp-hub/src/tests/stake_unstake.rs +++ b/contracts/alliance-lp-hub/src/tests/stake_unstake.rs @@ -9,7 +9,9 @@ use crate::tests::helpers::{ use crate::tests::mock_querier::mock_dependencies; use alliance_protocol::error::ContractError; use cosmwasm_std::testing::{mock_env, mock_info}; -use cosmwasm_std::{coin, to_json_binary, Addr, Coin, CosmosMsg, Response, Uint128, WasmMsg}; +use cosmwasm_std::{ + coin, coins, to_json_binary, Addr, Coin, CosmosMsg, Response, Uint128, WasmMsg, +}; use cw20::{Cw20ExecuteMsg, Cw20ReceiveMsg}; use cw_asset::{Asset, AssetInfo, AssetInfoKey}; @@ -377,7 +379,7 @@ fn test_unstake() { #[test] fn test_unstake_cw20_from_astro() { - let mut deps = mock_dependencies(Some(&vec![coin(100, "terra_astro_cw20")])); + let mut deps = mock_dependencies(Some(&coins(100, "terra_astro_cw20"))); setup_contract(deps.as_mut()); modify_asset( @@ -474,9 +476,7 @@ fn test_unstake_cw20_from_astro() { res.unwrap(), Response::new() .add_message(asset_info.transfer_msg(Addr::unchecked("user1")).unwrap()) - .add_attributes(vec![ - ("action", "unstake_alliance_lp_callback"), - ]) + .add_attributes(vec![("action", "unstake_alliance_lp_callback"),]) ); let balance = BALANCES