Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change undistributed rewards code #971

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions dex/farm-with-locked-rewards/wasm/Cargo.lock

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

5 changes: 2 additions & 3 deletions dex/farm-with-locked-rewards/wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

// Init: 1
// Upgrade: 1
// Endpoints: 66
// Endpoints: 65
// Async Callback: 1
// Total number of exported functions: 69
// Total number of exported functions: 68

#![no_std]

Expand Down Expand Up @@ -71,7 +71,6 @@ multiversx_sc_wasm_adapter::endpoints! {
getAccumulatedRewardsForWeek => accumulated_rewards_for_week
getFarmSupplyForWeek => farm_supply_for_week
getRemainingBoostedRewardsToDistribute => remaining_boosted_rewards_to_distribute
getUndistributedBoostedRewards => undistributed_boosted_rewards
setBoostedYieldsFactors => set_boosted_yields_factors
getBoostedYieldsFactors => get_boosted_yields_factors
getCurrentWeek => get_current_week
Expand Down
8 changes: 5 additions & 3 deletions dex/farm/tests/farm_multi_user_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,12 +690,14 @@ fn farm_multiple_claim_weeks_with_collect_undistributed_rewards_test() {

farm_setup.check_error_collect_undistributed_boosted_rewards(
"Current week must be higher than the week offset",
1,
4,
);

// advance to week 6
farm_setup.b_mock.set_block_epoch(36);

farm_setup.collect_undistributed_boosted_rewards();
farm_setup.collect_undistributed_boosted_rewards(1, 1);
farm_setup.check_undistributed_boosted_rewards(1);
farm_setup.check_remaining_boosted_rewards_to_distribute(1, 0);
farm_setup.check_remaining_boosted_rewards_to_distribute(2, 1);
Expand All @@ -704,7 +706,7 @@ fn farm_multiple_claim_weeks_with_collect_undistributed_rewards_test() {
// advance to week 8
farm_setup.b_mock.set_block_epoch(50);

farm_setup.collect_undistributed_boosted_rewards();
farm_setup.collect_undistributed_boosted_rewards(1, 3);
farm_setup.check_undistributed_boosted_rewards(3);

farm_setup.check_remaining_boosted_rewards_to_distribute(1, 0);
Expand Down Expand Up @@ -966,7 +968,7 @@ fn farm_claim_with_minimum_tokens() {
let remaining_boosted_yields_rewards =
total_boosted_yields_rewards - first_boosted_amt - second_boosted_amt;
farm_setup.check_undistributed_boosted_rewards(0);
farm_setup.collect_undistributed_boosted_rewards();
farm_setup.collect_undistributed_boosted_rewards(1, 1);
farm_setup.check_undistributed_boosted_rewards(remaining_boosted_yields_rewards);
farm_setup.check_remaining_boosted_rewards_to_distribute(1, 0);
farm_setup.check_remaining_boosted_rewards_to_distribute(2, 0);
Expand Down
55 changes: 44 additions & 11 deletions dex/farm/tests/farm_setup/multi_user_farm_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ use farm_boosted_yields::FarmBoostedYieldsModule;
use farm_token::FarmTokenModule;
use pausable::{PausableModule, State};
use sc_whitelist_module::SCWhitelistModule;
use week_timekeeping::Epoch;
use week_timekeeping::{Epoch, Week};
use weekly_rewards_splitting::update_claim_progress_energy::UpdateClaimProgressEnergyModule;

use super::single_user_farm_setup::MEX_TOKEN_ID;

pub static REWARD_TOKEN_ID: &[u8] = b"REW-123456";
pub static FARMING_TOKEN_ID: &[u8] = b"LPTOK-123456";
pub static FARM_TOKEN_ID: &[u8] = b"FARM-123456";
Expand Down Expand Up @@ -65,6 +67,7 @@ where
pub first_user: Address,
pub second_user: Address,
pub third_user: Address,
pub undistributed_rew_dest: Address,
pub last_farm_token_nonce: u64,
pub farm_wrapper: ContractObjWrapper<farm::ContractObj<DebugApi>, FarmObjBuilder>,
pub energy_factory_wrapper:
Expand All @@ -91,6 +94,7 @@ where
let first_user = b_mock.create_user_account(&rust_zero);
let second_user = b_mock.create_user_account(&rust_zero);
let third_user = b_mock.create_user_account(&rust_zero);
let undistributed_rew_dest = b_mock.create_user_account(&rust_zero);
let farm_wrapper =
b_mock.create_sc_account(&rust_zero, Some(&owner), farm_builder, "farm.wasm");
let energy_factory_wrapper = b_mock.create_sc_account(
Expand All @@ -102,6 +106,20 @@ where
let eu_wrapper =
b_mock.create_sc_account(&rust_zero, Some(&owner), eu_builder, "energy update mock");

b_mock
.execute_tx(&owner, &energy_factory_wrapper, &rust_zero, |sc| {
sc.init();
sc.base_asset_token_id()
.set(managed_token_id!(MEX_TOKEN_ID));
})
.assert_ok();

b_mock.set_esdt_local_roles(
energy_factory_wrapper.address_ref(),
MEX_TOKEN_ID,
&[EsdtLocalRole::Mint],
);

b_mock
.execute_tx(&owner, &eu_wrapper, &rust_zero, |sc| {
sc.init();
Expand Down Expand Up @@ -185,6 +203,7 @@ where
first_user,
second_user,
third_user,
undistributed_rew_dest,
last_farm_token_nonce: 0,
farm_wrapper,
energy_factory_wrapper,
Expand Down Expand Up @@ -651,18 +670,33 @@ where
.assert_ok();
}

pub fn check_error_collect_undistributed_boosted_rewards(&mut self, expected_message: &str) {
pub fn check_error_collect_undistributed_boosted_rewards(
&mut self,
expected_message: &str,
start_week: Week,
end_week: Week,
) {
let dest_address = self.undistributed_rew_dest.clone();
self.b_mock
.execute_tx(&self.owner, &self.farm_wrapper, &rust_biguint!(0), |sc| {
sc.collect_undistributed_boosted_rewards();
sc.collect_undistributed_boosted_rewards(
start_week,
end_week,
managed_address!(&dest_address),
);
})
.assert_error(4, expected_message)
}

pub fn collect_undistributed_boosted_rewards(&mut self) {
pub fn collect_undistributed_boosted_rewards(&mut self, start_week: Week, end_week: Week) {
let dest_address = self.undistributed_rew_dest.clone();
self.b_mock
.execute_tx(&self.owner, &self.farm_wrapper, &rust_biguint!(0), |sc| {
sc.collect_undistributed_boosted_rewards();
sc.collect_undistributed_boosted_rewards(
start_week,
end_week,
managed_address!(&dest_address),
);
})
.assert_ok();
}
Expand All @@ -683,12 +717,11 @@ where
}

pub fn check_undistributed_boosted_rewards(&mut self, expected_amount: u64) {
self.b_mock
.execute_query(&self.farm_wrapper, |sc| {
let result_managed = sc.undistributed_boosted_rewards().get();
assert_eq!(result_managed, managed_biguint!(expected_amount));
})
.assert_ok();
self.b_mock.check_esdt_balance(
&self.undistributed_rew_dest,
MEX_TOKEN_ID,
&rust_biguint!(expected_amount),
);
}

pub fn check_farm_token_supply(&mut self, expected_farm_token_supply: u64) {
Expand Down
8 changes: 8 additions & 0 deletions dex/farm/wasm/Cargo.lock

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

5 changes: 2 additions & 3 deletions dex/farm/wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

// Init: 1
// Upgrade: 1
// Endpoints: 63
// Endpoints: 62
// Async Callback: 1
// Total number of exported functions: 66
// Total number of exported functions: 65

#![no_std]

Expand Down Expand Up @@ -68,7 +68,6 @@ multiversx_sc_wasm_adapter::endpoints! {
getAccumulatedRewardsForWeek => accumulated_rewards_for_week
getFarmSupplyForWeek => farm_supply_for_week
getRemainingBoostedRewardsToDistribute => remaining_boosted_rewards_to_distribute
getUndistributedBoostedRewards => undistributed_boosted_rewards
setBoostedYieldsFactors => set_boosted_yields_factors
getBoostedYieldsFactors => get_boosted_yields_factors
getCurrentWeek => get_current_week
Expand Down
8 changes: 8 additions & 0 deletions dex/pair/wasm-pair-full/Cargo.lock

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

8 changes: 8 additions & 0 deletions dex/pair/wasm-safe-price-view/Cargo.lock

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

8 changes: 8 additions & 0 deletions dex/pair/wasm/Cargo.lock

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

8 changes: 8 additions & 0 deletions dex/price-discovery/wasm/Cargo.lock

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

8 changes: 8 additions & 0 deletions dex/proxy-deployer/wasm/Cargo.lock

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

8 changes: 8 additions & 0 deletions dex/router/wasm/Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
multiversx_sc::imports!();
multiversx_sc::derive_imports!();

pub const USER_MAX_CLAIM_WEEKS: usize = 4;
pub const USER_MAX_CLAIM_WEEKS: Week = 4;

pub mod base_impl;
pub mod events;
Expand Down
14 changes: 14 additions & 0 deletions energy-integration/energy-factory-mock/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,23 @@ pub trait EnergyFactoryMock {
self.user_energy(&user).set(&energy);
}

#[endpoint(transferUnlockedToken)]
fn transfer_unlocked_token(&self, dest: ManagedAddress, amount: BigUint) {
require!(amount != 0, "Invalid amount");

let base_asset_token_id = self.base_asset_token_id().get();
self.send()
.esdt_local_mint(&base_asset_token_id, 0, &amount);
self.send()
.direct_esdt(&dest, &base_asset_token_id, 0, &amount);
}

#[storage_mapper("userEnergy")]
fn user_energy(&self, user: &ManagedAddress) -> SingleValueMapper<Energy<Self::Api>>;

#[storage_mapper("lockedTokenId")]
fn locked_token(&self) -> NonFungibleTokenMapper;

#[storage_mapper("baseAssetTokenId")]
fn base_asset_token_id(&self) -> SingleValueMapper<TokenIdentifier>;
}
Loading
Loading