Skip to content

Commit

Permalink
Revamp salp with fund continue flow (#480)
Browse files Browse the repository at this point in the history
* Revamp salp with fund continue flow

- add continue failed fund
- revamp refund & redeem accordingly
- some other refactor remove deprecated codes

* Fix breaking benchmarks
  • Loading branch information
yrong authored Jan 24, 2022
1 parent bd26461 commit ae851ea
Show file tree
Hide file tree
Showing 10 changed files with 431 additions and 530 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 0 additions & 2 deletions node/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ bifrost-liquidity-mining-rpc-runtime-api = { path = "../../pallets/liquidity-min
default = [ "std" ]
std = []
runtime-benchmarks = [
"asgard-runtime/runtime-benchmarks",
"bifrost-kusama-runtime/runtime-benchmarks",
"bifrost-polkadot-runtime/runtime-benchmarks",
]
with-asgard-runtime = [
"asgard-runtime",
Expand Down
25 changes: 11 additions & 14 deletions pallets/salp-lite/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ fn create_fund<T: Config>(id: u32) -> ParaId {
#[allow(dead_code)]
fn contribute_fund<T: Config>(who: &T::AccountId, index: ParaId) {
let value = T::MinContribution::get();
assert_ok!(Salp::<T>::issue(RawOrigin::Root.into(), who.clone(), index, value, [0; 32]));
let confirmer: T::Origin = RawOrigin::Signed(Salp::<T>::multisig_confirm_account()).into();
assert_ok!(Salp::<T>::issue(confirmer, who.clone(), index, value, [0; 32]));
}

benchmarks! {

redeem {
let fund_index = create_fund::<T>(1);
let caller: T::AccountId = whitelisted_caller();
Expand All @@ -70,22 +70,19 @@ benchmarks! {
assert_last_event::<T>(Event::<T>::Redeemed(caller.clone(), fund_index, (0 as u32).into(),(7 as u32).into(),contribution).into())
}

batch_migrate {
let k in 1 .. T::BatchKeysLimit::get();
refund {
let fund_index = create_fund::<T>(1);
let caller: T::AccountId = whitelisted_caller();
let caller_origin: T::Origin = RawOrigin::Signed(caller.clone()).into();
let contribution = T::MinContribution::get();
let mut caller: T::AccountId = whitelisted_caller();
for i in 0 .. k {
caller = account("contributor", i, 0);
contribute_fund::<T>(&caller,fund_index);
}
contribute_fund::<T>(&caller,fund_index);
assert_ok!(Salp::<T>::fund_fail(RawOrigin::Root.into(), fund_index));
}: _(RawOrigin::Signed(caller.clone()), fund_index)
assert_ok!(Salp::<T>::withdraw(RawOrigin::Root.into(), fund_index));
assert_eq!(Salp::<T>::redeem_pool(), T::MinContribution::get());
}: _(RawOrigin::Signed(caller.clone()), fund_index,(0 as u32).into(),(7 as u32).into(),contribution)
verify {
let fund = Salp::<T>::funds(fund_index).unwrap();
let (_, status) = Salp::<T>::contribution(fund.trie_index, &caller);
assert_eq!(status, ContributionStatus::Unlocked);
assert_last_event::<T>(Event::<T>::AllUnlocked(fund_index).into());
assert_eq!(Salp::<T>::redeem_pool(), 0_u32.saturated_into());
assert_last_event::<T>(Event::<T>::Refunded(caller.clone(), fund_index, (0 as u32).into(),(7 as u32).into(),contribution).into())
}
}

Expand Down
5 changes: 4 additions & 1 deletion pallets/salp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkad
orml-tokens = "0.4.1-dev"
orml-currencies = "0.4.1-dev"
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }
pallet-collective = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }
bifrost-bancor = { path = "../../pallets/bancor" }
bifrost-runtime-common = { path = "../../runtime/common" }
bifrost-kusama-runtime = { path = "../../runtime/bifrost-kusama" }

[features]
default = ["std"]
Expand All @@ -57,4 +57,7 @@ runtime-benchmarks = [
"frame-benchmarking",
"sp-runtime/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-collective/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
]
18 changes: 11 additions & 7 deletions pallets/salp/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ benchmarks! {
let caller_origin: T::Origin = RawOrigin::Signed(caller.clone()).into();
let contribution = T::MinContribution::get();
contribute_fund::<T>(&caller,fund_index);
let confirmer: T::Origin = RawOrigin::Signed(Salp::<T>::multisig_confirm_account()).into();
assert_ok!(Salp::<T>::confirm_contribute(
RawOrigin::Root.into(),
confirmer,
caller.clone(),
fund_index,
true,
Expand All @@ -84,11 +85,11 @@ benchmarks! {
let fund = Salp::<T>::funds(fund_index).unwrap();
let (_, status) = Salp::<T>::contribution(fund.trie_index, &caller);
assert_eq!(status, ContributionStatus::Idle);
}: _(RawOrigin::Signed(caller.clone()), fund_index)
}: _(RawOrigin::Signed(caller.clone()), fund_index,(0 as u32).into(),(7 as u32).into(),contribution)
verify {
let (_, status) = Salp::<T>::contribution(fund.trie_index, &caller);
assert_eq!(status, ContributionStatus::Refunded);
assert_last_event::<T>(Event::<T>::Refunded(caller.clone(), fund_index, contribution).into())
assert_eq!(status, ContributionStatus::Idle);
assert_last_event::<T>(Event::<T>::Refunded(caller.clone(), fund_index, (0 as u32).into(),(7 as u32).into(),contribution).into())
}

unlock {
Expand All @@ -97,8 +98,9 @@ benchmarks! {
let caller_origin: T::Origin = RawOrigin::Signed(caller.clone()).into();
let contribution = T::MinContribution::get();
contribute_fund::<T>(&caller,fund_index);
let confirmer: T::Origin = RawOrigin::Signed(Salp::<T>::multisig_confirm_account()).into();
assert_ok!(Salp::<T>::confirm_contribute(
RawOrigin::Root.into(),
confirmer,
caller.clone(),
fund_index,
true,
Expand All @@ -117,11 +119,12 @@ benchmarks! {
let fund_index = create_fund::<T>(1);
let contribution = T::MinContribution::get();
let mut caller: T::AccountId = whitelisted_caller();
let confirmer: T::Origin = RawOrigin::Signed(Salp::<T>::multisig_confirm_account()).into();
for i in 0 .. k {
caller = account("contributor", i, 0);
contribute_fund::<T>(&caller,fund_index);
let _ = Salp::<T>::confirm_contribute(
RawOrigin::Root.into(),
confirmer.clone(),
caller.clone(),
fund_index,
true,
Expand All @@ -143,8 +146,9 @@ benchmarks! {
let caller_origin: T::Origin = RawOrigin::Signed(caller.clone()).into();
let contribution = T::MinContribution::get();
contribute_fund::<T>(&caller,fund_index);
let confirmer: T::Origin = RawOrigin::Signed(Salp::<T>::multisig_confirm_account()).into();
assert_ok!(Salp::<T>::confirm_contribute(
RawOrigin::Root.into(),
confirmer,
caller.clone(),
fund_index,
true,
Expand Down
Loading

0 comments on commit ae851ea

Please sign in to comment.