From 7cd92357fe26acb75f1f21d72af9c2c0f92edcd2 Mon Sep 17 00:00:00 2001 From: Rust Ninja <102041955+RustNinja@users.noreply.github.com> Date: Wed, 10 May 2023 11:06:47 +0100 Subject: [PATCH] Added amount parameter to farming pallet for deposit extrinsic (#3581) This PR introduced additional parameter `amount` to allow user `deposit` to specify any amount of LP tokens. - upgrade runtime - no node update @kkast --- code/parachain/frame/farming/src/benchmarking.rs | 3 ++- code/parachain/frame/farming/src/lib.rs | 7 +++++-- code/parachain/frame/farming/src/tests.rs | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/code/parachain/frame/farming/src/benchmarking.rs b/code/parachain/frame/farming/src/benchmarking.rs index 768ce8104ae..3bd381fb79b 100644 --- a/code/parachain/frame/farming/src/benchmarking.rs +++ b/code/parachain/frame/farming/src/benchmarking.rs @@ -59,6 +59,7 @@ fn deposit_lp_tokens( assert_ok!(Farming::::deposit( RawOrigin::Signed(account_id.clone()).into(), pool_currency_id.into(), + amount )); } @@ -104,7 +105,7 @@ benchmarks! { 100u32.into(), )); - }: _(RawOrigin::Signed(origin), pool_currency_id.into()) + }: _(RawOrigin::Signed(origin), pool_currency_id.into(), 100u32.into()) withdraw { let origin: T::AccountId = account("Origin", 0, 0); diff --git a/code/parachain/frame/farming/src/lib.rs b/code/parachain/frame/farming/src/lib.rs index b12d1fac854..78e90dc2b71 100644 --- a/code/parachain/frame/farming/src/lib.rs +++ b/code/parachain/frame/farming/src/lib.rs @@ -323,10 +323,13 @@ pub mod pallet { #[pallet::call_index(2)] #[pallet::weight(T::WeightInfo::deposit())] #[transactional] - pub fn deposit(origin: OriginFor, pool_currency_id: AssetIdOf) -> DispatchResult { + pub fn deposit( + origin: OriginFor, + pool_currency_id: AssetIdOf, + amount: BalanceOf, + ) -> DispatchResult { let who = ensure_signed(origin)?; // reserve lp tokens to prevent spending - let amount = T::MultiCurrency::free_balance(pool_currency_id, &who); T::MultiCurrency::reserve(pool_currency_id, &who, amount)?; // deposit lp tokens as stake diff --git a/code/parachain/frame/farming/src/tests.rs b/code/parachain/frame/farming/src/tests.rs index 10cf67830ca..212ff8c43e3 100644 --- a/code/parachain/frame/farming/src/tests.rs +++ b/code/parachain/frame/farming/src/tests.rs @@ -128,7 +128,7 @@ fn should_overwrite_existing_schedule() { fn mint_and_deposit(account_id: AccountId, amount: Balance) { assert_ok!(Tokens::set_balance(RuntimeOrigin::root(), account_id, POOL_CURRENCY_ID, amount, 0)); - assert_ok!(Farming::deposit(RuntimeOrigin::signed(account_id), POOL_CURRENCY_ID,)); + assert_ok!(Farming::deposit(RuntimeOrigin::signed(account_id), POOL_CURRENCY_ID, amount)); } #[test]