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

Rc/v3.0.1.5 #972

Draft
wants to merge 16 commits into
base: rc/v3.0.1
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 13 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
9 changes: 9 additions & 0 deletions Cargo.lock

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

12 changes: 12 additions & 0 deletions common/modules/disable-add-liq/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "disable-add-liq"
version = "0.0.0"
authors = ["Dorin Iancu <dorin.iancu@multiversx.com>"]
edition = "2021"

[lib]
path = "src/lib.rs"

[dependencies.multiversx-sc]
version = "=0.53.2"
features = ["esdt-token-payment-legacy-decode"]
32 changes: 32 additions & 0 deletions common/modules/disable-add-liq/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#![no_std]

multiversx_sc::imports!();

pub const ADD_LIQ_ENABLED: bool = false;
pub const ADD_LIQ_DISABLED: bool = true;

#[multiversx_sc::module]
pub trait DisableAddLiqModule {
#[only_owner]
#[endpoint(enableAddLiq)]
fn enable_add_liq(&self) {
self.add_liq_disabled().set(ADD_LIQ_ENABLED);
}

#[only_owner]
#[endpoint(disableAddLiq)]
fn disable_add_liq(&self) {
self.add_liq_disabled().set(ADD_LIQ_DISABLED);
}

fn require_add_liq_enabled(&self) {
require!(
self.add_liq_disabled().get() == ADD_LIQ_ENABLED,
"Add Liquidity is disabled"
);
}

#[view(isAddLiqDisabled)]
#[storage_mapper("addLiqDisabled")]
fn add_liq_disabled(&self) -> SingleValueMapper<bool>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though we want to have it disabled, we shouldn't name the storage in a negative manner. I would suggest add_liq_enabled -> and set it to false. It is more clear this way. Also, this way the default would still be disabled, if the storage is empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright then. Currently working on something else, will do after.

}
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.

Loading
Loading