Skip to content

Commit

Permalink
fix: astro rewards linting and fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
emidev98 committed Feb 5, 2024
1 parent 1b5ce68 commit 8b1f084
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 30 deletions.
15 changes: 8 additions & 7 deletions contracts/alliance-lp-hub/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
)?;

Expand All @@ -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![],
Expand Down Expand Up @@ -565,15 +565,15 @@ 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),
Err(_) => AssetInfo::Native(config.astro_reward_denom.clone()),
};

let rewards_asset = Asset {
info: info,
info,
amount: final_astro_rewards,
};
res = res.add_message(rewards_asset.transfer_msg(&user)?)
Expand Down Expand Up @@ -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::<Vec<&str>>()[1].to_string();
let splitter = char::from_str(":").unwrap();
let asset_denom = asset_string.split(splitter).collect::<Vec<&str>>()[1].to_string();

whitelist.push(asset_denom);
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/alliance-lp-hub/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub struct InstantiateMsg {

pub astro_reward_denom: String,
pub astro_incentives_addr: String,

pub alliance_reward_denom: String,
}

Expand Down
3 changes: 2 additions & 1 deletion contracts/alliance-lp-hub/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AssetInfoKey, Uint128> = Map::new("temp_balance");

Expand Down
28 changes: 23 additions & 5 deletions contracts/alliance-lp-hub/src/tests/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,35 @@ pub fn set_alliance_asset(deps: DepsMut) {
.unwrap();
}

pub fn modify_asset(deps: DepsMut, assets: Vec<ModifyAssetPair>) -> Result<Response, ContractError> {
pub fn modify_asset(
deps: DepsMut,
assets: Vec<ModifyAssetPair>,
) -> Result<Response, ContractError> {
let info = mock_info("gov", &[]);
let env = mock_env();

let msg = ExecuteMsg::ModifyAssetPairs(assets);
execute(deps, env, info, msg)
}

pub fn stake(deps: DepsMut, user: &str, amount: u128, denom: &str) -> Result<Response, ContractError> {
pub fn stake(
deps: DepsMut,
user: &str,
amount: u128,
denom: &str,
) -> Result<Response, ContractError> {
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<Response, ContractError> {
pub fn stake_cw20(
deps: DepsMut,
user: &str,
amount: u128,
denom: &str,
) -> Result<Response, ContractError> {
let mut info = mock_info(user, &[]);
let env = mock_env();
let msg = ExecuteMsg::Receive(Cw20ReceiveMsg {
Expand All @@ -79,10 +92,15 @@ pub fn unstake(deps: DepsMut, user: &str, asset: Asset) -> Result<Response, Cont
execute(deps, env, info, msg)
}

pub fn unstake_callback(deps: DepsMut, sender:&str, user: &str, asset: Asset) -> Result<Response, ContractError> {
pub fn unstake_callback(
deps: DepsMut,
sender: &str,
user: &str,
asset: Asset,
) -> Result<Response, ContractError> {
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)
}

Expand Down
15 changes: 6 additions & 9 deletions contracts/alliance-lp-hub/src/tests/mock_querier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@ pub fn mock_dependencies(
) -> OwnedDeps<MockStorage, MockApi, WasmMockQuerier> {
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()
Expand Down Expand Up @@ -74,7 +71,7 @@ impl WasmMockQuerier {
return SystemResult::Ok(to_json_binary(&msg).into());
}
let msg: Vec<RewardInfo> = 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" {
Expand All @@ -95,15 +92,15 @@ 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" {
return SystemResult::Ok(to_json_binary(&Uint128::one()).into());
} 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),
Expand Down
2 changes: 1 addition & 1 deletion contracts/alliance-lp-hub/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ mod alliance;
mod helpers;
mod instantiate;
mod mock_querier;
mod modify_asset;
mod rewards;
mod stake_unstake;
mod modify_asset;
2 changes: 1 addition & 1 deletion contracts/alliance-lp-hub/src/tests/modify_asset.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
10 changes: 5 additions & 5 deletions contracts/alliance-lp-hub/src/tests/stake_unstake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8b1f084

Please sign in to comment.