Skip to content

Commit

Permalink
Added amount parameter to farming pallet for deposit extrinsic (#3581)
Browse files Browse the repository at this point in the history
This PR introduced additional parameter `amount` to allow user `deposit`
to specify any amount of LP tokens.

- upgrade runtime
- no node update

@kkast
  • Loading branch information
RustNinja committed May 10, 2023
1 parent 422847c commit 7cd9235
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion code/parachain/frame/farming/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ fn deposit_lp_tokens<T: Config>(
assert_ok!(Farming::<T>::deposit(
RawOrigin::Signed(account_id.clone()).into(),
pool_currency_id.into(),
amount
));
}

Expand Down Expand Up @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions code/parachain/frame/farming/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,13 @@ pub mod pallet {
#[pallet::call_index(2)]
#[pallet::weight(T::WeightInfo::deposit())]
#[transactional]
pub fn deposit(origin: OriginFor<T>, pool_currency_id: AssetIdOf<T>) -> DispatchResult {
pub fn deposit(
origin: OriginFor<T>,
pool_currency_id: AssetIdOf<T>,
amount: BalanceOf<T>,
) -> 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
Expand Down
2 changes: 1 addition & 1 deletion code/parachain/frame/farming/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 7cd9235

Please sign in to comment.