Skip to content

Commit

Permalink
Add improved homa lite redeem match (#1626)
Browse files Browse the repository at this point in the history
* Added a new mock that costs no fees. This can be used to test economic model more easily for HomaLite
Added basic unit tests using the feeless mock.

* Fixed a bug where total_staking is not changed when redeeming from available-staking-balances
Added more tests and modified existing tests

* Added one more test

* Updated comments

* Added one more test

* Updated homalite redeem logic so if redeemer doesn't enough reserve balance, mint/adjust_available_staking_balance will not fail, and will skip the request instead
Added corresponding unit test.

* Fixed a clippy errot

* Added function that iterates redeem request from a starting element. Starting element is read from storage
Added unit test to test that function

* Replaced redeem logic to iterate from the "Next" item
When updating redeem requests, remember the "next" item
Added unit tests to test the new logic

* Improved the way iterator from next element

* Changed the storage of NextRedeemRequestToMatch to store the last redeem request key
Iteration now start from and exclude the key
Update tests.

* Improved how "first element" is handled
iterate_from_next_redeem_request now also updates storage

* Improved coding structure for homalite redeem
Modification and removal of redeem requests storage now happens within the same function

* Refactored the way functions are structured in HomaLite
Removed the use of closures
Storage mutation and deletion now all happens within the same function and synchronously.
`redeem_from_previous_redeem_request` now iterates and redeem requests depending on input parameter.

* Fixed a benchmarking test

* refactor

* Fixed unit tests

* Tidied up how events are asserted in HomaLite unit tests

* Tidied up how events are asserted

* minor comments update

* Added System::reset_events to make event assert clearer

* Fixed clippy
Fixed benchmarking tests

* Update modules/homa-lite/src/lib.rs

Co-authored-by: Roy Yang <[email protected]>
Co-authored-by: Bryan Chen <[email protected]>
  • Loading branch information
3 people authored Nov 24, 2021
1 parent d96f82e commit f9c6754
Show file tree
Hide file tree
Showing 7 changed files with 714 additions and 399 deletions.
5 changes: 4 additions & 1 deletion modules/homa-lite/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ primitives = { package = "acala-primitives", path = "../../primitives", default-
orml-traits = { path = "../../orml/traits", default-features = false }
module-support = { path = "../../modules/support", default-features = false }

# TODO: move this to dev-dependencies when https://github.com/paritytech/polkadot/pull/4355 is available
xcm-executor = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.12", default-features = false }

[dev-dependencies]
sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.12" }
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.12" }
module-currencies = { path = "../../modules/currencies" }
orml-tokens = { path = "../../orml/tokens" }
xcm-executor = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.12" }
cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.12" }
module-relaychain = { path = "../relaychain", features = ["kusama"] }

Expand All @@ -48,6 +50,7 @@ std = [
"primitives/std",
"orml-traits/std",
"module-support/std",
"xcm-executor/std",
]
runtime-benchmarks = [
"frame-benchmarking",
Expand Down
4 changes: 2 additions & 2 deletions modules/homa-lite/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ benchmarks! {
let caller: T::AccountId = account("caller", 0, SEED);
<T as module::Config>::Currency::deposit(T::LiquidCurrencyId::get(), &caller, amount)?;
let _ = crate::Pallet::<T>::adjust_available_staking_balance(RawOrigin::Root.into(), AmountOf::<T>::max_value(), 1);
let _ = crate::Pallet::<T>::request_redeem(RawOrigin::Signed(caller).into(), amount, Permill::default());
let _ = crate::Pallet::<T>::request_redeem(RawOrigin::Signed(caller.clone()).into(), amount, Permill::default());
}: {
let _ = crate::Pallet::<T>::process_redeem_requests_with_available_staking_balance(1);
let _ = crate::Pallet::<T>::process_redeem_requests_with_available_staking_balance(&caller);
}

xcm_unbond {}: {
Expand Down
Loading

0 comments on commit f9c6754

Please sign in to comment.