Skip to content

Commit

Permalink
Merge pull request #58 from multiversx/extra-views
Browse files Browse the repository at this point in the history
extra views
  • Loading branch information
dorin-iancu authored Feb 14, 2024
2 parents eefb927 + 4b4c0e7 commit 6b385a9
Show file tree
Hide file tree
Showing 7 changed files with 280 additions and 5 deletions.
119 changes: 118 additions & 1 deletion growth-program/output/growth-program.abi.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"contractCrate": {
"name": "growth-program",
"version": "0.0.0",
"gitVersion": "v1.0.2-136-g99c9bec"
"gitVersion": "v1.0.2-141-gb83ee58"
},
"framework": {
"name": "multiversx-sc",
Expand Down Expand Up @@ -289,6 +289,49 @@
}
]
},
{
"name": "getExemptedParticipants",
"mutability": "readonly",
"inputs": [
{
"name": "project_id",
"type": "u32"
},
{
"name": "week",
"type": "u32"
}
],
"outputs": [
{
"type": "variadic<Address>",
"multi_result": true
}
]
},
{
"name": "getUserClaimed",
"mutability": "readonly",
"inputs": [
{
"name": "user_address",
"type": "Address"
},
{
"name": "project_id",
"type": "u32"
},
{
"name": "week",
"type": "u32"
}
],
"outputs": [
{
"type": "bool"
}
]
},
{
"name": "updateRewards",
"mutability": "mutable",
Expand All @@ -305,6 +348,59 @@
],
"outputs": []
},
{
"name": "getRewardsInfo",
"mutability": "readonly",
"inputs": [
{
"name": "project_id",
"type": "u32"
}
],
"outputs": [
{
"type": "RewardsInfo"
}
]
},
{
"name": "getRewardsTotalAmount",
"mutability": "readonly",
"inputs": [
{
"name": "project_id",
"type": "u32"
},
{
"name": "week",
"type": "u32"
}
],
"outputs": [
{
"type": "BigUint"
}
]
},
{
"name": "getRewardsRemainingAmount",
"mutability": "readonly",
"inputs": [
{
"name": "project_id",
"type": "u32"
},
{
"name": "week",
"type": "u32"
}
],
"outputs": [
{
"type": "BigUint"
}
]
},
{
"name": "changeSigner",
"onlyOwner": true,
Expand Down Expand Up @@ -423,6 +519,27 @@
"discriminant": 2
}
]
},
"RewardsInfo": {
"type": "struct",
"fields": [
{
"name": "reward_token_id",
"type": "TokenIdentifier"
},
{
"name": "undistributed_rewards",
"type": "BigUint"
},
{
"name": "start_week",
"type": "u32"
},
{
"name": "end_week",
"type": "u32"
}
]
}
}
}
1 change: 1 addition & 0 deletions growth-program/output/growth-program.imports.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"bigIntAbs",
"bigIntAdd",
"bigIntCmp",
"bigIntFinishUnsigned",
"bigIntGetUnsignedArgument",
"bigIntMul",
"bigIntPow",
Expand Down
121 changes: 119 additions & 2 deletions growth-program/output/growth-program.mxsc.json

Large diffs are not rendered by default.

Binary file modified growth-program/output/growth-program.wasm
Binary file not shown.
32 changes: 32 additions & 0 deletions growth-program/src/rewards/claim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,38 @@ pub trait ClaimRewardsModule:
OptionalValue::Some(output_payment)
}

#[view(getExemptedParticipants)]
fn get_exempted_participants(
&self,
project_id: ProjectId,
week: Week,
) -> MultiValueEncoded<ManagedAddress> {
let id_mapper = self.user_ids();
let mut results = MultiValueEncoded::new();
for user_id in self.exempted_participants(project_id, week).iter() {
let opt_user_address = id_mapper.get_address(user_id);
let user_address = unsafe { opt_user_address.unwrap_unchecked() };
results.push(user_address);
}

results
}

#[view(getUserClaimed)]
fn get_user_claimed(
&self,
user_address: ManagedAddress,
project_id: ProjectId,
week: Week,
) -> bool {
let user_id = self.user_ids().get_id(&user_address);
if user_id == NULL_ID {
return false;
}

self.user_claimed(project_id, week).contains(&user_id)
}

fn adjust_energy_to_lock_option(&self, amount: BigUint, lock_option: LockOption) -> BigUint {
match lock_option {
LockOption::None => amount * NONE_PERCENTAGE / MAX_PERCENTAGE,
Expand Down
3 changes: 3 additions & 0 deletions growth-program/src/rewards/common_rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,16 @@ pub trait CommonRewardsModule: week_timekeeping::WeekTimekeepingModule {
#[storage_mapper("minWeeklyRewardsValue")]
fn min_weekly_rewards_value(&self) -> SingleValueMapper<BigUint>;

#[view(getRewardsInfo)]
#[storage_mapper("rewardsInfo")]
fn rewards_info(&self, project_id: ProjectId) -> SingleValueMapper<RewardsInfo<Self::Api>>;

#[view(getRewardsTotalAmount)]
#[storage_mapper("rewardsTotalAmount")]
fn rewards_total_amount(&self, project_id: ProjectId, week: Week)
-> SingleValueMapper<BigUint>;

#[view(getRewardsRemainingAmount)]
#[storage_mapper("rewardsRemainingAmount")]
fn rewards_remaining_amount(
&self,
Expand Down
9 changes: 7 additions & 2 deletions growth-program/wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
////////////////////////////////////////////////////

// Init: 1
// Endpoints: 23
// Endpoints: 28
// Async Callback (empty): 1
// Total number of exported functions: 25
// Total number of exported functions: 30

#![no_std]
#![allow(internal_features)]
Expand All @@ -34,7 +34,12 @@ multiversx_sc_wasm_adapter::endpoints! {
setAlpha => set_alpha
setBeta => set_beta
claimRewards => claim_rewards
getExemptedParticipants => get_exempted_participants
getUserClaimed => get_user_claimed
updateRewards => update_rewards_endpoint
getRewardsInfo => rewards_info
getRewardsTotalAmount => rewards_total_amount
getRewardsRemainingAmount => rewards_remaining_amount
changeSigner => change_signer
getCurrentWeek => get_current_week
getFirstWeekStartEpoch => first_week_start_epoch
Expand Down

0 comments on commit 6b385a9

Please sign in to comment.