From 2f153ed77302c94dbe8a4b2cd995abb0fef070e2 Mon Sep 17 00:00:00 2001 From: f33r0 <95526886+f33r0@users.noreply.github.com> Date: Thu, 28 Mar 2024 08:45:20 +0300 Subject: [PATCH 01/19] Update build.sh --- housekeeping/build.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/housekeeping/build.sh b/housekeeping/build.sh index 7eea755394..a5f56640bc 100755 --- a/housekeeping/build.sh +++ b/housekeeping/build.sh @@ -43,9 +43,6 @@ build() { elif [[ -n ${TAG_NAME} && ${TAG_NAME} != 'predev' ]]; then featureList='include-real-files' sudoCheckStatus="101" - elif [[ $buildTag == 'latest' ]]; then - featureList='include-real-files' - sudoCheckStatus="101" elif [[ -n $buildTag ]]; then featureList='private-net include-real-files reduced-pswap-reward-periods wip ready-to-test' fi From 437deb49f4c7bad6dec332b7318f78d6a023168a Mon Sep 17 00:00:00 2001 From: f33r0 <95526886+f33r0@users.noreply.github.com> Date: Thu, 28 Mar 2024 12:43:21 +0300 Subject: [PATCH 02/19] Update build.sh --- housekeeping/build.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/housekeeping/build.sh b/housekeeping/build.sh index a5f56640bc..eb64645eb1 100755 --- a/housekeeping/build.sh +++ b/housekeeping/build.sh @@ -7,7 +7,7 @@ wasmReportFile='subwasm_report.json' PACKAGE='framenode-runtime' RUSTFLAGS='-Dwarnings' RUNTIME_DIR='runtime' -allfeatures='private-net,ready-to-test' +allfeatures="$featureList" # build func test() { @@ -21,7 +21,7 @@ test() { export LLVM_PROFILE_FILE="sora2-%p-%m.profraw" rm -rf ~/.cargo/.package-cache cargo fmt -- --check > /dev/null - cargo test --features $allfeatures -- --test-threads=1 + cargo test --features $allfeatures -- --test-threads=2 fi if [[ $prBranch = 'master' ]]; then printf "⚡️ This is "$prbranch" Running tests and migrations %s\n" From 18acce7f99a6611f1bd9bdd6b2f8323ef4c21b90 Mon Sep 17 00:00:00 2001 From: f33r0 <95526886+f33r0@users.noreply.github.com> Date: Thu, 28 Mar 2024 14:51:52 +0300 Subject: [PATCH 03/19] Update build.sh --- housekeeping/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/housekeeping/build.sh b/housekeeping/build.sh index eb64645eb1..a210eadf0c 100755 --- a/housekeeping/build.sh +++ b/housekeeping/build.sh @@ -21,7 +21,7 @@ test() { export LLVM_PROFILE_FILE="sora2-%p-%m.profraw" rm -rf ~/.cargo/.package-cache cargo fmt -- --check > /dev/null - cargo test --features $allfeatures -- --test-threads=2 + cargo test --features "$allfeatures" -- --test-threads=2 fi if [[ $prBranch = 'master' ]]; then printf "⚡️ This is "$prbranch" Running tests and migrations %s\n" From a41219087b66983ed8f407dcfbe003045b171595 Mon Sep 17 00:00:00 2001 From: f33r0 <95526886+f33r0@users.noreply.github.com> Date: Fri, 29 Mar 2024 17:46:15 +0300 Subject: [PATCH 04/19] Update build.sh --- housekeeping/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/housekeeping/build.sh b/housekeeping/build.sh index a210eadf0c..047f5f050a 100755 --- a/housekeeping/build.sh +++ b/housekeeping/build.sh @@ -42,7 +42,7 @@ build() { featureList='private-net include-real-files reduced-pswap-reward-periods ready-to-test' elif [[ -n ${TAG_NAME} && ${TAG_NAME} != 'predev' ]]; then featureList='include-real-files' - sudoCheckStatus="101" + sudoCheckStatus=101 elif [[ -n $buildTag ]]; then featureList='private-net include-real-files reduced-pswap-reward-periods wip ready-to-test' fi From 8bcbd085020c3750d1888532bc384471ea6f2cf3 Mon Sep 17 00:00:00 2001 From: f33r0 <95526886+f33r0@users.noreply.github.com> Date: Fri, 29 Mar 2024 17:55:19 +0300 Subject: [PATCH 05/19] Update build.sh --- housekeeping/build.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/housekeeping/build.sh b/housekeeping/build.sh index 047f5f050a..a65f61ab5e 100755 --- a/housekeeping/build.sh +++ b/housekeeping/build.sh @@ -43,8 +43,6 @@ build() { elif [[ -n ${TAG_NAME} && ${TAG_NAME} != 'predev' ]]; then featureList='include-real-files' sudoCheckStatus=101 - elif [[ -n $buildTag ]]; then - featureList='private-net include-real-files reduced-pswap-reward-periods wip ready-to-test' fi printf "⚡️ Building with features: %s\n" "$featureList" printf "⚡️ Checking sudo pallet: %s\n" "$sudoCheckStatus" From 79b4bdccd7948ba51ed28ba4012813041313527b Mon Sep 17 00:00:00 2001 From: Nikita Zaporozhets Date: Fri, 29 Mar 2024 20:15:08 +0300 Subject: [PATCH 06/19] set 0 as int Signed-off-by: Nikita Zaporozhets --- housekeeping/build.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/housekeeping/build.sh b/housekeeping/build.sh index a65f61ab5e..1a72d64b69 100755 --- a/housekeeping/build.sh +++ b/housekeeping/build.sh @@ -13,7 +13,7 @@ allfeatures="$featureList" test() { if [[ -n ${TAG_NAME} ]]; then printf "⚡️ Testing with features: private-net runtime-benchmarks\n" - cargo test --release --features "private-net runtime-benchmarks" + cargo test --release --features "private-net runtime-benchmarks" -- --test-threads=2 elif [[ -n $buildTag || $pr = true ]]; then printf "⚡️ Running Tests for code coverage only\n" export RUSTFLAGS="-Cinstrument-coverage" @@ -21,7 +21,7 @@ test() { export LLVM_PROFILE_FILE="sora2-%p-%m.profraw" rm -rf ~/.cargo/.package-cache cargo fmt -- --check > /dev/null - cargo test --features "$allfeatures" -- --test-threads=2 + cargo test --features "$allfeatures" -- --test-threads=2 fi if [[ $prBranch = 'master' ]]; then printf "⚡️ This is "$prbranch" Running tests and migrations %s\n" @@ -33,7 +33,7 @@ test() { build() { printf "Tag is %s\n" ${TAG_NAME} printf "BuildTag is %s\n" ${buildTag} - sudoCheckStatus="0" + sudoCheckStatus=0 if [[ ${TAG_NAME} =~ 'benchmarking'* ]]; then featureList='private-net runtime-benchmarks' elif [[ ${TAG_NAME} =~ 'stage'* ]]; then From 97fdd7110066675881a34728b5fdde405c47b738 Mon Sep 17 00:00:00 2001 From: Nikita Zaporozhets Date: Fri, 29 Mar 2024 20:19:22 +0300 Subject: [PATCH 07/19] set threads Signed-off-by: Nikita Zaporozhets --- housekeeping/build.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/housekeeping/build.sh b/housekeeping/build.sh index 1a72d64b69..6a2c6a7750 100755 --- a/housekeeping/build.sh +++ b/housekeeping/build.sh @@ -21,7 +21,7 @@ test() { export LLVM_PROFILE_FILE="sora2-%p-%m.profraw" rm -rf ~/.cargo/.package-cache cargo fmt -- --check > /dev/null - cargo test --features "$allfeatures" -- --test-threads=2 + cargo test --features "$allfeatures" -- --test-threads=2 fi if [[ $prBranch = 'master' ]]; then printf "⚡️ This is "$prbranch" Running tests and migrations %s\n" @@ -33,7 +33,7 @@ test() { build() { printf "Tag is %s\n" ${TAG_NAME} printf "BuildTag is %s\n" ${buildTag} - sudoCheckStatus=0 + sudoCheckStatus="0" if [[ ${TAG_NAME} =~ 'benchmarking'* ]]; then featureList='private-net runtime-benchmarks' elif [[ ${TAG_NAME} =~ 'stage'* ]]; then From df283dd19b9b8b0c2f7ef74a4aa42ec08eda9647 Mon Sep 17 00:00:00 2001 From: f33r0 <95526886+f33r0@users.noreply.github.com> Date: Fri, 29 Mar 2024 20:22:49 +0300 Subject: [PATCH 08/19] Update build.sh --- housekeeping/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/housekeeping/build.sh b/housekeeping/build.sh index 6a2c6a7750..fe6d43d357 100755 --- a/housekeeping/build.sh +++ b/housekeeping/build.sh @@ -33,7 +33,7 @@ test() { build() { printf "Tag is %s\n" ${TAG_NAME} printf "BuildTag is %s\n" ${buildTag} - sudoCheckStatus="0" + sudoCheckStatus=0 if [[ ${TAG_NAME} =~ 'benchmarking'* ]]; then featureList='private-net runtime-benchmarks' elif [[ ${TAG_NAME} =~ 'stage'* ]]; then From ced7e9c545118ae2d5200fc716d06073361548eb Mon Sep 17 00:00:00 2001 From: Nikita Zaporozhets Date: Sat, 30 Mar 2024 00:11:13 +0300 Subject: [PATCH 09/19] update sudo status check (new subwasm) Signed-off-by: Nikita Zaporozhets --- housekeeping/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/housekeeping/build.sh b/housekeeping/build.sh index fe6d43d357..a21d49b49d 100755 --- a/housekeeping/build.sh +++ b/housekeeping/build.sh @@ -42,7 +42,7 @@ build() { featureList='private-net include-real-files reduced-pswap-reward-periods ready-to-test' elif [[ -n ${TAG_NAME} && ${TAG_NAME} != 'predev' ]]; then featureList='include-real-files' - sudoCheckStatus=101 + sudoCheckStatus=1 fi printf "⚡️ Building with features: %s\n" "$featureList" printf "⚡️ Checking sudo pallet: %s\n" "$sudoCheckStatus" From 045c5bd2d991b77637585a33e2bc0f99b856fc9a Mon Sep 17 00:00:00 2001 From: Haidar Jbeily Date: Mon, 1 Apr 2024 12:43:36 +0300 Subject: [PATCH 10/19] feat(farming): add storage value to constrain lp bonus reward --- pallets/farming/src/lib.rs | 35 ++++++++++++++++++++++++++++++++++- pallets/farming/src/mock.rs | 3 ++- runtime/src/lib.rs | 3 ++- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/pallets/farming/src/lib.rs b/pallets/farming/src/lib.rs index 641dd62fbc..13e11222fc 100644 --- a/pallets/farming/src/lib.rs +++ b/pallets/farming/src/lib.rs @@ -185,7 +185,7 @@ impl Pallet { .try_into_balance() .unwrap_or(0); - if base_asset_amt < balance!(1) { + if base_asset_amt < Self::lp_min_xor_for_bonus_reward() { return 0; } @@ -316,6 +316,7 @@ pub mod pallet { use frame_support::pallet_prelude::*; use frame_support::traits::schedule::Anon; use frame_support::traits::StorageVersion; + use frame_system::{ensure_root, pallet_prelude::*}; use sp_runtime::traits::Zero; use sp_runtime::AccountId32; @@ -331,6 +332,7 @@ pub mod pallet { + pool_xyk::Config + vested_rewards::Config { + type RuntimeEvent: From> + IsType<::RuntimeEvent>; const PSWAP_PER_DAY: Balance; const REFRESH_FREQUENCY: BlockNumberFor; const VESTING_COEFF: u32; @@ -379,6 +381,14 @@ pub mod pallet { IncRefError, } + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event { + LpMinXorForBonusRewardUpdated { + lp_min_xor_for_bonus_reward: Balance, + }, + } + /// Pools whose farmers are refreshed at the specific block. Block => Pools #[pallet::storage] pub type Pools = @@ -388,6 +398,29 @@ pub mod pallet { #[pallet::storage] pub type PoolFarmers = StorageMap<_, Identity, T::AccountId, Vec>, ValueQuery>; + + #[pallet::storage] + #[pallet::getter(fn lp_min_xor_for_bonus_reward)] + pub type LpMinXorForBonusReward = StorageValue<_, Balance, ValueQuery>; + + #[pallet::call] + impl Pallet { + #[pallet::call_index(0)] + #[pallet::weight(::WeightInfo::set_lp_min_xor_for_bonus_reward())] + pub fn set_lp_min_xor_for_bonus_reward( + origin: OriginFor, + new_lp_min_xor_for_bonus_reward: Balance, + ) -> DispatchResult { + ensure_root(origin)?; + LpMinXorForBonusReward::::mutate(|lp_min_xor_for_bonus_reward| { + *lp_min_xor_for_bonus_reward = new_lp_min_xor_for_bonus_reward; + }); + Self::deposit_event(Event::LpMinXorForBonusRewardUpdated { + lp_min_xor_for_bonus_reward: new_lp_min_xor_for_bonus_reward, + }); + Ok(()) + } + } } pub mod rpc { diff --git a/pallets/farming/src/mock.rs b/pallets/farming/src/mock.rs index d5682514e8..931f50c74f 100644 --- a/pallets/farming/src/mock.rs +++ b/pallets/farming/src/mock.rs @@ -147,7 +147,7 @@ construct_runtime! { MBCPool: multicollateral_bonding_curve_pool::{Pallet, Call, Storage, Event}, VestedRewards: vested_rewards::{Pallet, Storage, Event}, Scheduler: pallet_scheduler::{Pallet, Call, Storage, Event}, - Farming: farming::{Pallet, Storage}, + Farming: farming::{Pallet, Storage, Event}, CeresLiquidityLocker: ceres_liquidity_locker::{Pallet, Call, Storage, Event}, DemeterFarmingPlatform: demeter_farming_platform::{Pallet, Call, Storage, Event}, } @@ -398,6 +398,7 @@ impl Config for Runtime { type RewardDoublingAssets = RewardDoublingAssets; type TradingPairSourceManager = trading_pair::Pallet; type WeightInfo = (); + type RuntimeEvent = RuntimeEvent; } pub struct ExtBuilder { diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index b68f7572b2..156aca65af 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -1589,6 +1589,7 @@ impl farming::Config for Runtime { type RewardDoublingAssets = FarmingRewardDoublingAssets; type TradingPairSourceManager = trading_pair::Pallet; type WeightInfo = (); + type RuntimeEvent = RuntimeEvent; } impl pswap_distribution::Config for Runtime { @@ -2410,7 +2411,7 @@ construct_runtime! { ElectionsPhragmen: pallet_elections_phragmen::{Pallet, Call, Storage, Event, Config} = 39, VestedRewards: vested_rewards::{Pallet, Call, Storage, Event} = 40, Identity: pallet_identity::{Pallet, Call, Storage, Event} = 41, - Farming: farming::{Pallet, Storage} = 42, + Farming: farming::{Pallet, Storage, Event} = 42, XSTPool: xst::{Pallet, Call, Storage, Config, Event} = 43, PriceTools: price_tools::{Pallet, Storage, Event} = 44, CeresStaking: ceres_staking::{Pallet, Call, Storage, Event} = 45, From 7839e18cf824787b44cf3ebeca891de683364545 Mon Sep 17 00:00:00 2001 From: Haidar Jbeily Date: Mon, 1 Apr 2024 15:14:03 +0300 Subject: [PATCH 11/19] feat(farming): support new functionality with tests --- pallets/farming/src/tests.rs | 36 ++++++++++++++++++++++++++++++++-- pallets/farming/src/weights.rs | 11 +++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/pallets/farming/src/tests.rs b/pallets/farming/src/tests.rs index d17e79ad46..54d0005880 100644 --- a/pallets/farming/src/tests.rs +++ b/pallets/farming/src/tests.rs @@ -28,18 +28,20 @@ // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -use frame_support::assert_ok; +use frame_support::{assert_noop, assert_ok}; use common::{balance, RewardReason, DOT, PSWAP, VAL, XOR, XSTUSD}; use frame_support::log::debug; +use frame_system::RawOrigin; use pool_xyk::Properties; +use sp_runtime::traits::BadOrigin; use vested_rewards::Rewards; use crate::mock::{ self, run_to_block, AssetId, DEXId, ExtBuilder, Runtime, RuntimeOrigin, ALICE, BOB, CHARLIE, DAVE, DEX_A_ID, DEX_B_ID, EVE, REFRESH_FREQUENCY, VESTING_FREQUENCY, }; -use crate::{PoolFarmer, PoolFarmers}; +use crate::{Pallet, PoolFarmer, PoolFarmers}; fn init_pool(dex_id: DEXId, base_asset: AssetId, other_asset: AssetId) { assert_ok!(trading_pair::Pallet::::register( @@ -63,6 +65,10 @@ fn init_pool(dex_id: DEXId, base_asset: AssetId, other_asset: AssetId) { fn test() { let dex_id = DEX_A_ID; ExtBuilder::default().build().execute_with(|| { + assert_ok!(Pallet::::set_lp_min_xor_for_bonus_reward( + RawOrigin::Root.into(), + balance!(1) + )); init_pool(DEX_A_ID, XOR, DOT); init_pool(DEX_A_ID, XOR, PSWAP); init_pool(DEX_A_ID, XOR, XSTUSD); @@ -406,3 +412,29 @@ fn test() { assert_eq!(eve_reward, balance!(375576.575413164636883116)); }); } + +#[test] +fn set_lp_min_xor_for_bonus_reward_should_forbid_for_non_root_call() { + ExtBuilder::default().build().execute_with(|| { + assert_noop!( + Pallet::::set_lp_min_xor_for_bonus_reward( + RuntimeOrigin::signed(ALICE()), + balance!(100000) + ), + BadOrigin + ); + assert!(Pallet::::lp_min_xor_for_bonus_reward() == balance!(0)); + }); +} + +#[test] +fn set_lp_min_xor_for_bonus_reward_should_work() { + ExtBuilder::default().build().execute_with(|| { + let modified_min_xor = balance!(3 * (10_i32.pow(6))); + assert_ok!(Pallet::::set_lp_min_xor_for_bonus_reward( + RawOrigin::Root.into(), + modified_min_xor + )); + assert!(Pallet::::lp_min_xor_for_bonus_reward() == modified_min_xor); + }); +} diff --git a/pallets/farming/src/weights.rs b/pallets/farming/src/weights.rs index bed2a46244..ecb7047a5d 100644 --- a/pallets/farming/src/weights.rs +++ b/pallets/farming/src/weights.rs @@ -63,6 +63,7 @@ pub trait WeightInfo { fn refresh_pool(a: u32, ) -> Weight; fn prepare_accounts_for_vesting(a: u32, b: u32, ) -> Weight; fn vest_account_rewards(a: u32, ) -> Weight; + fn set_lp_min_xor_for_bonus_reward() -> Weight; } /// Weights for farming using the Substrate node and recommended hardware. @@ -132,6 +133,11 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().writes((2_u64).saturating_mul(a.into()))) .saturating_add(Weight::from_parts(0, 5468).saturating_mul(a.into())) } + + fn set_lp_min_xor_for_bonus_reward() -> Weight{ + Weight::from_parts(5_967_353, 631) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } } // For backwards compatibility and tests @@ -200,4 +206,9 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().writes((2_u64).saturating_mul(a.into()))) .saturating_add(Weight::from_parts(0, 5468).saturating_mul(a.into())) } + + fn set_lp_min_xor_for_bonus_reward() -> Weight{ + Weight::from_parts(5_967_353, 631) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } } From 277b882432ad994db9f5142e842119487773b1ed Mon Sep 17 00:00:00 2001 From: Haidar Jbeily Date: Tue, 2 Apr 2024 10:29:50 +0300 Subject: [PATCH 12/19] revert build.sh from merge --- housekeeping/build.sh | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/housekeeping/build.sh b/housekeeping/build.sh index a21d49b49d..147acf1eb9 100755 --- a/housekeeping/build.sh +++ b/housekeeping/build.sh @@ -7,13 +7,13 @@ wasmReportFile='subwasm_report.json' PACKAGE='framenode-runtime' RUSTFLAGS='-Dwarnings' RUNTIME_DIR='runtime' -allfeatures="$featureList" +allfeatures='private-net,ready-to-test' # build func test() { if [[ -n ${TAG_NAME} ]]; then printf "⚡️ Testing with features: private-net runtime-benchmarks\n" - cargo test --release --features "private-net runtime-benchmarks" -- --test-threads=2 + cargo test --release --features "private-net runtime-benchmarks" elif [[ -n $buildTag || $pr = true ]]; then printf "⚡️ Running Tests for code coverage only\n" export RUSTFLAGS="-Cinstrument-coverage" @@ -21,7 +21,7 @@ test() { export LLVM_PROFILE_FILE="sora2-%p-%m.profraw" rm -rf ~/.cargo/.package-cache cargo fmt -- --check > /dev/null - cargo test --features "$allfeatures" -- --test-threads=2 + cargo test --features "$allfeatures" -- --test-threads=1 fi if [[ $prBranch = 'master' ]]; then printf "⚡️ This is "$prbranch" Running tests and migrations %s\n" @@ -33,7 +33,7 @@ test() { build() { printf "Tag is %s\n" ${TAG_NAME} printf "BuildTag is %s\n" ${buildTag} - sudoCheckStatus=0 + sudoCheckStatus="0" if [[ ${TAG_NAME} =~ 'benchmarking'* ]]; then featureList='private-net runtime-benchmarks' elif [[ ${TAG_NAME} =~ 'stage'* ]]; then @@ -42,7 +42,12 @@ build() { featureList='private-net include-real-files reduced-pswap-reward-periods ready-to-test' elif [[ -n ${TAG_NAME} && ${TAG_NAME} != 'predev' ]]; then featureList='include-real-files' - sudoCheckStatus=1 + sudoCheckStatus="101" + elif [[ $buildTag == 'latest' ]]; then + featureList='include-real-files' + sudoCheckStatus="101" + elif [[ -n $buildTag ]]; then + featureList='private-net include-real-files reduced-pswap-reward-periods wip ready-to-test' fi printf "⚡️ Building with features: %s\n" "$featureList" printf "⚡️ Checking sudo pallet: %s\n" "$sudoCheckStatus" From 99ce09c58a9fec61bb920e8bd6ed3763b0b9fcb4 Mon Sep 17 00:00:00 2001 From: Haidar Jbeily Date: Tue, 2 Apr 2024 10:32:29 +0300 Subject: [PATCH 13/19] revert build.sh from merge --- housekeeping/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/housekeeping/build.sh b/housekeeping/build.sh index 147acf1eb9..7eea755394 100755 --- a/housekeeping/build.sh +++ b/housekeeping/build.sh @@ -21,7 +21,7 @@ test() { export LLVM_PROFILE_FILE="sora2-%p-%m.profraw" rm -rf ~/.cargo/.package-cache cargo fmt -- --check > /dev/null - cargo test --features "$allfeatures" -- --test-threads=1 + cargo test --features $allfeatures -- --test-threads=1 fi if [[ $prBranch = 'master' ]]; then printf "⚡️ This is "$prbranch" Running tests and migrations %s\n" From e580718e6868b9bda4250bec8e43756c05a24483 Mon Sep 17 00:00:00 2001 From: Haidar Jbeily Date: Tue, 2 Apr 2024 11:21:40 +0300 Subject: [PATCH 14/19] feat(farming): handle error and add default value --- pallets/farming/src/lib.rs | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/pallets/farming/src/lib.rs b/pallets/farming/src/lib.rs index 13e11222fc..02720abbe4 100644 --- a/pallets/farming/src/lib.rs +++ b/pallets/farming/src/lib.rs @@ -379,16 +379,25 @@ pub mod pallet { pub enum Error { /// Increment account reference error. IncRefError, + /// Invalid New xor Min amount for Liquidity Provider Bonus Reward. + InvalidNewLpMinXorForBonusRewardError, } #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event { + /// When Minimum XOR amount for Liquidity Provider Bonus Reward is updated LpMinXorForBonusRewardUpdated { - lp_min_xor_for_bonus_reward: Balance, + new_lp_min_xor_for_bonus_reward: Balance, + old_lp_min_xor_for_bonus_reward: Balance, }, } + #[pallet::type_value] + pub fn DefaultLpMinXorForBonusReward() -> Balance { + balance!(1) + } + /// Pools whose farmers are refreshed at the specific block. Block => Pools #[pallet::storage] pub type Pools = @@ -401,7 +410,8 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn lp_min_xor_for_bonus_reward)] - pub type LpMinXorForBonusReward = StorageValue<_, Balance, ValueQuery>; + pub type LpMinXorForBonusReward = + StorageValue<_, Balance, ValueQuery, DefaultLpMinXorForBonusReward>; #[pallet::call] impl Pallet { @@ -412,11 +422,15 @@ pub mod pallet { new_lp_min_xor_for_bonus_reward: Balance, ) -> DispatchResult { ensure_root(origin)?; - LpMinXorForBonusReward::::mutate(|lp_min_xor_for_bonus_reward| { - *lp_min_xor_for_bonus_reward = new_lp_min_xor_for_bonus_reward; - }); + ensure!( + new_lp_min_xor_for_bonus_reward >= balance!(1), + >::InvalidNewLpMinXorForBonusRewardError + ); + let old_lp_min_xor_for_bonus_reward = >::get(); + >::put(new_lp_min_xor_for_bonus_reward); Self::deposit_event(Event::LpMinXorForBonusRewardUpdated { - lp_min_xor_for_bonus_reward: new_lp_min_xor_for_bonus_reward, + new_lp_min_xor_for_bonus_reward, + old_lp_min_xor_for_bonus_reward, }); Ok(()) } From e57d4b6d973fedfddbe5eb1f5465458b33791878 Mon Sep 17 00:00:00 2001 From: Haidar Jbeily Date: Tue, 2 Apr 2024 12:24:02 +0300 Subject: [PATCH 15/19] feat(farming): change default value and rollback added check --- pallets/farming/src/lib.rs | 10 ++-------- pallets/farming/src/tests.rs | 7 ++----- runtime/src/lib.rs | 4 ++-- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/pallets/farming/src/lib.rs b/pallets/farming/src/lib.rs index 02720abbe4..d256ec9173 100644 --- a/pallets/farming/src/lib.rs +++ b/pallets/farming/src/lib.rs @@ -41,7 +41,7 @@ mod mock; mod tests; #[cfg(feature = "runtime-benchmarks")] mod utils; -mod weights; +pub mod weights; use assets::AssetIdOf; use codec::{Decode, Encode}; @@ -379,8 +379,6 @@ pub mod pallet { pub enum Error { /// Increment account reference error. IncRefError, - /// Invalid New xor Min amount for Liquidity Provider Bonus Reward. - InvalidNewLpMinXorForBonusRewardError, } #[pallet::event] @@ -395,7 +393,7 @@ pub mod pallet { #[pallet::type_value] pub fn DefaultLpMinXorForBonusReward() -> Balance { - balance!(1) + balance!(3000000) } /// Pools whose farmers are refreshed at the specific block. Block => Pools @@ -422,10 +420,6 @@ pub mod pallet { new_lp_min_xor_for_bonus_reward: Balance, ) -> DispatchResult { ensure_root(origin)?; - ensure!( - new_lp_min_xor_for_bonus_reward >= balance!(1), - >::InvalidNewLpMinXorForBonusRewardError - ); let old_lp_min_xor_for_bonus_reward = >::get(); >::put(new_lp_min_xor_for_bonus_reward); Self::deposit_event(Event::LpMinXorForBonusRewardUpdated { diff --git a/pallets/farming/src/tests.rs b/pallets/farming/src/tests.rs index 54d0005880..b23ca36fb7 100644 --- a/pallets/farming/src/tests.rs +++ b/pallets/farming/src/tests.rs @@ -65,10 +65,8 @@ fn init_pool(dex_id: DEXId, base_asset: AssetId, other_asset: AssetId) { fn test() { let dex_id = DEX_A_ID; ExtBuilder::default().build().execute_with(|| { - assert_ok!(Pallet::::set_lp_min_xor_for_bonus_reward( - RawOrigin::Root.into(), - balance!(1) - )); + let _ = + >::set_lp_min_xor_for_bonus_reward(RawOrigin::Root.into(), balance!(1)); init_pool(DEX_A_ID, XOR, DOT); init_pool(DEX_A_ID, XOR, PSWAP); init_pool(DEX_A_ID, XOR, XSTUSD); @@ -423,7 +421,6 @@ fn set_lp_min_xor_for_bonus_reward_should_forbid_for_non_root_call() { ), BadOrigin ); - assert!(Pallet::::lp_min_xor_for_bonus_reward() == balance!(0)); }); } diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index a61a18995d..2bcdcb445b 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -1588,7 +1588,7 @@ impl farming::Config for Runtime { type Scheduler = Scheduler; type RewardDoublingAssets = FarmingRewardDoublingAssets; type TradingPairSourceManager = trading_pair::Pallet; - type WeightInfo = (); + type WeightInfo = farming::weights::SubstrateWeight; type RuntimeEvent = RuntimeEvent; } @@ -2411,7 +2411,7 @@ construct_runtime! { ElectionsPhragmen: pallet_elections_phragmen::{Pallet, Call, Storage, Event, Config} = 39, VestedRewards: vested_rewards::{Pallet, Call, Storage, Event} = 40, Identity: pallet_identity::{Pallet, Call, Storage, Event} = 41, - Farming: farming::{Pallet, Storage, Event} = 42, + Farming: farming::{Pallet, Call, Storage, Event} = 42, XSTPool: xst::{Pallet, Call, Storage, Config, Event} = 43, PriceTools: price_tools::{Pallet, Storage, Event} = 44, CeresStaking: ceres_staking::{Pallet, Call, Storage, Event} = 45, From 6c5f65a8ce848b7890aee57f3981c8a0b43cb37c Mon Sep 17 00:00:00 2001 From: Haidar Jbeily Date: Tue, 2 Apr 2024 13:23:52 +0300 Subject: [PATCH 16/19] feat(farming): update weights aligned with benchmarking --- pallets/farming/src/benchmarking.rs | 9 +++++++++ pallets/farming/src/weights.rs | 26 ++++++++++++++++++++------ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/pallets/farming/src/benchmarking.rs b/pallets/farming/src/benchmarking.rs index fab86afd42..37e5a0847f 100644 --- a/pallets/farming/src/benchmarking.rs +++ b/pallets/farming/src/benchmarking.rs @@ -160,6 +160,14 @@ benchmarks! { }: { Pallet::::vest_account_rewards(accounts); } + + set_lp_min_xor_for_bonus_reward{ + let root = RawOrigin::Root; + let balance = balance!(10000000); + }: { + let _ = Pallet::::set_lp_min_xor_for_bonus_reward(root.into(), balance); + } + } #[cfg(test)] @@ -176,6 +184,7 @@ mod tests { assert_ok!(Pallet::::test_benchmark_refresh_pool()); assert_ok!(Pallet::::test_benchmark_prepare_accounts_for_vesting()); assert_ok!(Pallet::::test_benchmark_vest_account_rewards()); + assert_ok!(Pallet::::test_benchmark_set_lp_min_xor_for_bonus_reward()); }); } } diff --git a/pallets/farming/src/weights.rs b/pallets/farming/src/weights.rs index ecb7047a5d..8e5490fc8b 100644 --- a/pallets/farming/src/weights.rs +++ b/pallets/farming/src/weights.rs @@ -134,9 +134,16 @@ impl WeightInfo for SubstrateWeight { .saturating_add(Weight::from_parts(0, 5468).saturating_mul(a.into())) } - fn set_lp_min_xor_for_bonus_reward() -> Weight{ - Weight::from_parts(5_967_353, 631) - .saturating_add(T::DbWeight::get().writes(1_u64)) + /// Storage: Farming LpMinXorForBonusReward (r:1 w:1) + /// Proof Skipped: Farming LpMinXorForBonusReward (max_values: Some(1), max_size: None, mode: Measured) + fn set_lp_min_xor_for_bonus_reward() -> Weight { + // Proof Size summary in bytes: + // Measured: `109` + // Estimated: `604` + // Minimum execution time: 8_000 nanoseconds. + Weight::from_parts(9_000_000, 604) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } } @@ -207,8 +214,15 @@ impl WeightInfo for () { .saturating_add(Weight::from_parts(0, 5468).saturating_mul(a.into())) } - fn set_lp_min_xor_for_bonus_reward() -> Weight{ - Weight::from_parts(5_967_353, 631) - .saturating_add(RocksDbWeight::get().writes(1_u64)) + /// Storage: Farming LpMinXorForBonusReward (r:1 w:1) + /// Proof Skipped: Farming LpMinXorForBonusReward (max_values: Some(1), max_size: None, mode: Measured) + fn set_lp_min_xor_for_bonus_reward() -> Weight { + // Proof Size summary in bytes: + // Measured: `109` + // Estimated: `604` + // Minimum execution time: 8_000 nanoseconds. + Weight::from_parts(9_000_000, 604) + .saturating_add(RocksDbWeight::get().reads(1)) + .saturating_add(RocksDbWeight::get().writes(1)) } } From 0575d1dfd2622fb8d749daaa27780420c90b7deb Mon Sep 17 00:00:00 2001 From: Haidar Jbeily Date: Tue, 2 Apr 2024 13:27:43 +0300 Subject: [PATCH 17/19] feat(farming): add `Call` to mock --- pallets/farming/src/mock.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/farming/src/mock.rs b/pallets/farming/src/mock.rs index 931f50c74f..3aa8bc710c 100644 --- a/pallets/farming/src/mock.rs +++ b/pallets/farming/src/mock.rs @@ -147,7 +147,7 @@ construct_runtime! { MBCPool: multicollateral_bonding_curve_pool::{Pallet, Call, Storage, Event}, VestedRewards: vested_rewards::{Pallet, Storage, Event}, Scheduler: pallet_scheduler::{Pallet, Call, Storage, Event}, - Farming: farming::{Pallet, Storage, Event}, + Farming: farming::{Pallet, Call, Storage, Event}, CeresLiquidityLocker: ceres_liquidity_locker::{Pallet, Call, Storage, Event}, DemeterFarmingPlatform: demeter_farming_platform::{Pallet, Call, Storage, Event}, } From d98e332d783af289c8c4f5b6ee0bccc7cd99647e Mon Sep 17 00:00:00 2001 From: Haidar Jbeily Date: Tue, 2 Apr 2024 14:01:43 +0300 Subject: [PATCH 18/19] feat(farming): unwrap in tests --- pallets/farming/src/benchmarking.rs | 2 +- pallets/farming/src/tests.rs | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/pallets/farming/src/benchmarking.rs b/pallets/farming/src/benchmarking.rs index 37e5a0847f..683fa66bc9 100644 --- a/pallets/farming/src/benchmarking.rs +++ b/pallets/farming/src/benchmarking.rs @@ -165,7 +165,7 @@ benchmarks! { let root = RawOrigin::Root; let balance = balance!(10000000); }: { - let _ = Pallet::::set_lp_min_xor_for_bonus_reward(root.into(), balance); + Pallet::::set_lp_min_xor_for_bonus_reward(root.into(), balance).unwrap(); } } diff --git a/pallets/farming/src/tests.rs b/pallets/farming/src/tests.rs index b23ca36fb7..d233dbd562 100644 --- a/pallets/farming/src/tests.rs +++ b/pallets/farming/src/tests.rs @@ -65,8 +65,21 @@ fn init_pool(dex_id: DEXId, base_asset: AssetId, other_asset: AssetId) { fn test() { let dex_id = DEX_A_ID; ExtBuilder::default().build().execute_with(|| { - let _ = - >::set_lp_min_xor_for_bonus_reward(RawOrigin::Root.into(), balance!(1)); + // Check default value for lp_min_xor_for_bonus_reward + assert_eq!( + >::lp_min_xor_for_bonus_reward(), + balance!(3000000) + ); + // Update lp_min_xor_for_bonus_reward + >::set_lp_min_xor_for_bonus_reward(RawOrigin::Root.into(), balance!(1)) + .unwrap(); + + // Check lp_min_xor_for_bonus_reward updated + assert_eq!( + >::lp_min_xor_for_bonus_reward(), + balance!(1) + ); + init_pool(DEX_A_ID, XOR, DOT); init_pool(DEX_A_ID, XOR, PSWAP); init_pool(DEX_A_ID, XOR, XSTUSD); From 0d1ac66f2c179c651da872cf08e6cdb206ccd5f8 Mon Sep 17 00:00:00 2001 From: Haidar Jbeily Date: Wed, 3 Apr 2024 22:23:10 +0300 Subject: [PATCH 19/19] feat(farming): add asset_has_event on test --- pallets/farming/src/tests.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/pallets/farming/src/tests.rs b/pallets/farming/src/tests.rs index d233dbd562..fa85ec5f02 100644 --- a/pallets/farming/src/tests.rs +++ b/pallets/farming/src/tests.rs @@ -32,6 +32,7 @@ use frame_support::{assert_noop, assert_ok}; use common::{balance, RewardReason, DOT, PSWAP, VAL, XOR, XSTUSD}; use frame_support::log::debug; +use frame_system; use frame_system::RawOrigin; use pool_xyk::Properties; use sp_runtime::traits::BadOrigin; @@ -41,7 +42,9 @@ use crate::mock::{ self, run_to_block, AssetId, DEXId, ExtBuilder, Runtime, RuntimeOrigin, ALICE, BOB, CHARLIE, DAVE, DEX_A_ID, DEX_B_ID, EVE, REFRESH_FREQUENCY, VESTING_FREQUENCY, }; -use crate::{Pallet, PoolFarmer, PoolFarmers}; +use crate::{Event, Pallet, PoolFarmer, PoolFarmers}; + +type System = frame_system::Pallet; fn init_pool(dex_id: DEXId, base_asset: AssetId, other_asset: AssetId) { assert_ok!(trading_pair::Pallet::::register( @@ -440,11 +443,21 @@ fn set_lp_min_xor_for_bonus_reward_should_forbid_for_non_root_call() { #[test] fn set_lp_min_xor_for_bonus_reward_should_work() { ExtBuilder::default().build().execute_with(|| { + System::set_block_number(1); let modified_min_xor = balance!(3 * (10_i32.pow(6))); + let old_lp_min_xor_for_bonus_reward = Pallet::::lp_min_xor_for_bonus_reward(); assert_ok!(Pallet::::set_lp_min_xor_for_bonus_reward( RawOrigin::Root.into(), modified_min_xor )); - assert!(Pallet::::lp_min_xor_for_bonus_reward() == modified_min_xor); + let new_lp_min_xor_for_bonus_reward = Pallet::::lp_min_xor_for_bonus_reward(); + assert_eq!(new_lp_min_xor_for_bonus_reward, modified_min_xor); + System::assert_has_event( + Event::LpMinXorForBonusRewardUpdated { + new_lp_min_xor_for_bonus_reward, + old_lp_min_xor_for_bonus_reward, + } + .into(), + ); }); }