Skip to content

Commit

Permalink
Add is_claimable flag to reward response
Browse files Browse the repository at this point in the history
  • Loading branch information
ismellike committed Feb 14, 2024
1 parent 30bfeab commit 2816beb
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -620,14 +620,18 @@
"type": "object",
"required": [
"amount",
"denom"
"denom",
"is_claimable"
],
"properties": {
"amount": {
"$ref": "#/definitions/Uint128"
},
"denom": {
"$ref": "#/definitions/CheckedDenom"
},
"is_claimable": {
"type": "boolean"
}
},
"additionalProperties": false,
Expand Down
1 change: 1 addition & 0 deletions contracts/external/dao-voting-incentives/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ pub enum MigrateMsg {
pub struct RewardResponse {
pub denom: CheckedDenom,
pub amount: Uint128,
pub is_claimable: bool,
}
2 changes: 2 additions & 0 deletions contracts/external/dao-voting-incentives/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub fn reward(deps: Deps, contract: &Addr, addr: &Addr) -> Result<RewardResponse
Ok(RewardResponse {
denom: config.denom,
amount: calculate_reward(config.total_votes, user_votes, balance)?,
is_claimable: true,
})
}
None => {
Expand All @@ -58,6 +59,7 @@ pub fn reward(deps: Deps, contract: &Addr, addr: &Addr) -> Result<RewardResponse
Ok(RewardResponse {
denom: config.denom,
amount: calculate_reward(config.total_votes, user_votes, balance)?,
is_claimable: false,
})
}
}
Expand Down
24 changes: 22 additions & 2 deletions contracts/external/dao-voting-incentives/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use cosmwasm_std::{
};

use cw20::{BalanceResponse, Cw20Coin, Cw20QueryMsg, Cw20ReceiveMsg};
use cw_denom::UncheckedDenom;
use cw_denom::{CheckedDenom, UncheckedDenom};
use cw_multi_test::{error::AnyResult, App, AppBuilder, AppResponse, Executor};
use cw_utils::Expiration;
use dao_testing::{
Expand All @@ -17,7 +17,7 @@ use dao_voting::{proposal::SingleChoiceProposeMsg, threshold::Threshold};

use crate::{
contract::{migrate, CONTRACT_NAME, CONTRACT_VERSION},
msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg},
msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg, RewardResponse},
state::Config,
};

Expand Down Expand Up @@ -492,6 +492,26 @@ pub fn test_hooks() {
);
assert!(result.is_err());

// Check rewards
let rewards: RewardResponse = context
.app
.wrap()
.query_wasm_smart(
dao_voting_incentives_addr.clone(),
&QueryMsg::Rewards {
address: ADDR1.to_string(),
},
)
.unwrap();
assert_eq!(
rewards,
RewardResponse {
denom: CheckedDenom::Native(DENOM.to_string()),
amount: Uint128::new(500),
is_claimable: true,
}
);

// User claims rewards
let result = context.app.execute_contract(
Addr::unchecked(ADDR1),
Expand Down

0 comments on commit 2816beb

Please sign in to comment.