Skip to content

Commit

Permalink
Merge pull request #59 from multiversx/more-and-more-changes
Browse files Browse the repository at this point in the history
More and more changes
  • Loading branch information
dorin-iancu authored Mar 8, 2024
2 parents 6b385a9 + 50e6b6b commit 7575712
Show file tree
Hide file tree
Showing 20 changed files with 476 additions and 150 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions growth-program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ rev = "0c7f45e"
git = "https://github.com/multiversx/mx-exchange-sc"
rev = "0c7f45e"

[dependencies.week-timekeeping]
git = "https://github.com/multiversx/mx-exchange-sc"
rev = "0c7f45e"

[dependencies.energy-query]
git = "https://github.com/multiversx/mx-exchange-sc"
rev = "0c7f45e"
Expand Down
102 changes: 92 additions & 10 deletions 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-141-gb83ee58"
"gitVersion": "v1.0.2-154-g37b183a"
},
"framework": {
"name": "multiversx-sc",
Expand All @@ -21,14 +21,14 @@
"constructor": {
"docs": [
"Arguments:",
"min_energy_per_reward_dollar: Scaled to PRECISION const.",
"min_reward_dollars_per_energy: Scaled to PRECISION const.",
"alpha: Percentage, scaled to MAX_PERCENTAGE const.",
"beta: Percentage, scaled to MAX_PERCENTAGE const.",
"signer: Public key of the signer, used to verify user claims"
],
"inputs": [
{
"name": "min_energy_per_reward_dollar",
"name": "min_reward_dollars_per_energy",
"type": "BigUint"
},
{
Expand Down Expand Up @@ -153,7 +153,7 @@
"type": "u32"
},
{
"name": "initial_energy_per_rew_dollar",
"name": "initial_rewards_dollar_per_energy",
"type": "BigUint"
}
],
Expand Down Expand Up @@ -209,7 +209,7 @@
"outputs": []
},
{
"name": "setMinEnergyPerRewardDollar",
"name": "setMinRewardDollarsPerEnergy",
"onlyOwner": true,
"mutability": "mutable",
"inputs": [
Expand All @@ -221,7 +221,7 @@
"outputs": []
},
{
"name": "setEnergyPerRewardDollarForWeek",
"name": "setNextWeekRewardDollarsPerEnergy",
"onlyOwner": true,
"mutability": "mutable",
"inputs": [
Expand Down Expand Up @@ -260,6 +260,33 @@
],
"outputs": []
},
{
"name": "setTotalEnergyForCurrentWeek",
"mutability": "mutable",
"inputs": [
{
"name": "project_ids",
"type": "variadic<u32>",
"multi_arg": true
}
],
"outputs": []
},
{
"name": "getTotalEnergyForCurrentWeek",
"mutability": "readonly",
"inputs": [
{
"name": "project_id",
"type": "u32"
}
],
"outputs": [
{
"type": "BigUint"
}
]
},
{
"name": "claimRewards",
"mutability": "mutable",
Expand All @@ -277,9 +304,8 @@
"type": "array64<u8>"
},
{
"name": "opt_lock_option",
"type": "optional<LockOption>",
"multi_arg": true
"name": "claim_type",
"type": "ClaimType"
}
],
"outputs": [
Expand Down Expand Up @@ -427,7 +453,7 @@
]
},
{
"name": "getFirstWeekStartEpoch",
"name": "getFirstWeekStartTimestamp",
"mutability": "readonly",
"inputs": [],
"outputs": [
Expand Down Expand Up @@ -483,9 +509,61 @@
]
}
],
"events": [
{
"identifier": "claimRewardsEvent",
"inputs": [
{
"name": "caller",
"type": "Address",
"indexed": true
},
{
"name": "claim_data",
"type": "ClaimRewardsEventData"
}
]
}
],
"esdtAttributes": [],
"hasCallback": false,
"types": {
"ClaimRewardsEventData": {
"type": "struct",
"fields": [
{
"name": "project_id",
"type": "u32"
},
{
"name": "amount",
"type": "BigUint"
},
{
"name": "claim_type",
"type": "ClaimType"
}
]
},
"ClaimType": {
"type": "enum",
"variants": [
{
"name": "Exemption",
"discriminant": 0
},
{
"name": "Rewards",
"discriminant": 1,
"fields": [
{
"name": "0",
"type": "LockOption"
}
]
}
]
},
"EsdtTokenPayment": {
"type": "struct",
"fields": [
Expand Down Expand Up @@ -535,6 +613,10 @@
"name": "start_week",
"type": "u32"
},
{
"name": "last_update_week",
"type": "u32"
},
{
"name": "end_week",
"type": "u32"
Expand Down
2 changes: 2 additions & 0 deletions growth-program/output/growth-program.imports.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"cleanReturnData",
"getArgumentLength",
"getBlockEpoch",
"getBlockTimestamp",
"getGasLeft",
"getNumArguments",
"isSmartContract",
Expand Down Expand Up @@ -43,6 +44,7 @@
"managedSCAddress",
"managedSignalError",
"managedVerifyEd25519",
"managedWriteLog",
"signalError",
"smallIntFinishSigned",
"smallIntFinishUnsigned",
Expand Down
104 changes: 93 additions & 11 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.
36 changes: 36 additions & 0 deletions growth-program/src/events.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use crate::{project::ProjectId, rewards::claim::ClaimType};

multiversx_sc::imports!();
multiversx_sc::derive_imports!();

#[derive(TypeAbi, TopEncode, TopDecode, NestedEncode, NestedDecode)]
pub struct ClaimRewardsEventData<M: ManagedTypeApi> {
pub project_id: ProjectId,
pub amount: BigUint<M>,
pub claim_type: ClaimType,
}

#[multiversx_sc::module]
pub trait EventsModule {
fn emit_claim_rewards_event(
&self,
caller: &ManagedAddress,
project_id: ProjectId,
rewards_amount: BigUint,
claim_type: ClaimType,
) {
let claim_data = ClaimRewardsEventData {
amount: rewards_amount,
project_id,
claim_type,
};
self.claim_rewards_event(caller, &claim_data);
}

#[event("claimRewardsEvent")]
fn claim_rewards_event(
&self,
#[indexed] caller: &ManagedAddress,
claim_data: &ClaimRewardsEventData<Self::Api>,
);
}
21 changes: 14 additions & 7 deletions growth-program/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#![no_std]

use week_timekeeping::Week;
use rewards::week_timekeeping::{Week, MONDAY_19_02_2024_GMT_TIMESTAMP};

multiversx_sc::imports!();

pub mod events;
pub mod price_query;
pub mod project;
pub mod rewards;
Expand All @@ -12,6 +13,7 @@ pub mod validation;
pub type Timestamp = u64;

pub const MAX_PERCENTAGE: u32 = 100_000;
pub const HOUR_IN_SECONDS: Timestamp = 60 * 60;
pub const DAY_IN_SECONDS: Timestamp = 24 * 60 * 60;
pub const WEEK_IN_SECONDS: Timestamp = 7 * DAY_IN_SECONDS;
pub const PRECISION: u64 = 1_000_000_000_000_000_000;
Expand All @@ -30,20 +32,21 @@ pub trait GrowthProgram:
+ rewards::common_rewards::CommonRewardsModule
+ price_query::PriceQueryModule
+ validation::ValidationModule
+ week_timekeeping::WeekTimekeepingModule
+ rewards::week_timekeeping::WeekTimekeepingModule
+ events::EventsModule
+ utils::UtilsModule
+ energy_query::EnergyQueryModule
+ multiversx_sc_modules::pause::PauseModule
{
/// Arguments:
/// min_energy_per_reward_dollar: Scaled to PRECISION const.
/// min_reward_dollars_per_energy: Scaled to PRECISION const.
/// alpha: Percentage, scaled to MAX_PERCENTAGE const.
/// beta: Percentage, scaled to MAX_PERCENTAGE const.
/// signer: Public key of the signer, used to verify user claims
#[init]
fn init(
&self,
min_energy_per_reward_dollar: BigUint,
min_reward_dollars_per_energy: BigUint,
alpha: BigUint,
beta: BigUint,
signer: ManagedAddress,
Expand All @@ -67,7 +70,7 @@ pub trait GrowthProgram:
self.wegld_token_id().set(wegld_token_id);

self.set_energy_factory_address(energy_factory_address);
self.set_min_energy_per_reward_dollar(min_energy_per_reward_dollar);
self.set_min_reward_dollars_per_energy(min_reward_dollars_per_energy);
self.set_alpha(alpha);
self.set_beta(beta);
self.change_signer(signer);
Expand All @@ -80,8 +83,12 @@ pub trait GrowthProgram:
self.min_weekly_rewards_value()
.set(default_min_weekly_rewards_value);

let current_epoch = self.blockchain().get_block_epoch();
self.first_week_start_epoch().set(current_epoch);
let current_timestamp = self.blockchain().get_block_timestamp();
let first_week_start_timestamp = MONDAY_19_02_2024_GMT_TIMESTAMP
+ (current_timestamp - MONDAY_19_02_2024_GMT_TIMESTAMP) / WEEK_IN_SECONDS
* WEEK_IN_SECONDS;
self.first_week_start_timestamp()
.set(first_week_start_timestamp);

self.set_paused(true);
}
Expand Down
Loading

0 comments on commit 7575712

Please sign in to comment.