Skip to content

Commit

Permalink
Addressed PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanfrey committed Jun 28, 2023
1 parent 7b9d4ec commit 9764c27
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
7 changes: 4 additions & 3 deletions contracts/provider/external-staking/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -823,10 +823,11 @@ impl ExternalStakingContract<'_> {
.may_load(ctx.deps.storage, &validator)?
.unwrap_or_default();
let amount = Self::calculate_reward(stake, &distribution)?;
Ok::<_, ContractError>(ValidatorPendingReward {
Ok::<_, ContractError>(ValidatorPendingReward::new(
validator,
amount: coin(amount.u128(), &config.rewards_denom),
})
amount.u128(),
&config.rewards_denom,
))
})
.collect::<Result<_, _>>()?;

Expand Down
6 changes: 3 additions & 3 deletions contracts/provider/external-staking/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,20 @@ pub struct PendingRewards {
pub amount: Coin,
}

/// Response for pending rewards query on one validator
/// Response for pending rewards query on all validator
#[cw_serde]
pub struct AllPendingRewards {
pub rewards: Vec<ValidatorPendingReward>,
}

#[cw_serde]
pub struct ValidatorPendingReward {
pub amount: Coin,
pub validator: String,
pub amount: Coin,
}

impl ValidatorPendingReward {
pub fn new(amount: u128, denom: impl Into<String>, validator: impl Into<String>) -> Self {
pub fn new(validator: impl Into<String>, amount: u128, denom: impl Into<String>) -> Self {
Self {
amount: coin(amount, denom),
validator: validator.into(),
Expand Down
14 changes: 7 additions & 7 deletions contracts/provider/external-staking/src/multitest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -787,15 +787,15 @@ fn distribution() {
.all_pending_rewards(users[0].to_owned(), None, None)
.unwrap();
let expected = vec![
ValidatorPendingReward::new(20, STAR, validators[0]),
ValidatorPendingReward::new(30, STAR, validators[1]),
ValidatorPendingReward::new(validators[0], 20, STAR),
ValidatorPendingReward::new(validators[1], 30, STAR),
];
assert_eq!(all_rewards.rewards, expected);

let all_rewards = contract
.all_pending_rewards(users[1].to_owned(), None, None)
.unwrap();
let expected = vec![ValidatorPendingReward::new(30, STAR, validators[0])];
let expected = vec![ValidatorPendingReward::new(validators[0], 30, STAR)];
assert_eq!(all_rewards.rewards, expected);

// Distributed funds should be on the staking contract
Expand Down Expand Up @@ -1223,17 +1223,17 @@ fn distribution() {
.all_pending_rewards(users[0].to_owned(), None, None)
.unwrap();
let expected = vec![
ValidatorPendingReward::new(6, STAR, validators[0]),
ValidatorPendingReward::new(2, STAR, validators[1]),
ValidatorPendingReward::new(validators[0], 6, STAR),
ValidatorPendingReward::new(validators[1], 2, STAR),
];
assert_eq!(all_rewards.rewards, expected);

let all_rewards = contract
.all_pending_rewards(users[1].to_owned(), None, None)
.unwrap();
let expected = vec![
ValidatorPendingReward::new(33, STAR, validators[0]),
ValidatorPendingReward::new(37, STAR, validators[1]),
ValidatorPendingReward::new(validators[0], 33, STAR),
ValidatorPendingReward::new(validators[1], 37, STAR),
];
assert_eq!(all_rewards.rewards, expected);

Expand Down

0 comments on commit 9764c27

Please sign in to comment.