Skip to content

Commit

Permalink
Revamp salp with fund edit (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
yrong committed Sep 14, 2021
1 parent 3c7d7e7 commit cd49e91
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
43 changes: 43 additions & 0 deletions pallets/salp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ pub mod pallet {
Refunded(AccountIdOf<T>, ParaId, BalanceOf<T>),
/// redeem to account. [who, fund_index, first_slot, last_slot, value]
Redeemed(AccountIdOf<T>, ParaId, LeasePeriod, LeasePeriod, BalanceOf<T>),
/// Fund is edited. [fund_index]
Edited(ParaId),
/// Fund is dissolved. [fund_index]
Dissolved(ParaId),
/// The vsToken/vsBond was be unlocked. [who, fund_index, value]
Expand Down Expand Up @@ -382,6 +384,47 @@ pub mod pallet {
Ok(())
}

/// Edit the configuration for an in-progress crowdloan.
///
/// Can only be called by Root origin.
#[pallet::weight((
0,
DispatchClass::Normal,
Pays::No
))]
pub fn edit(
origin: OriginFor<T>,
#[pallet::compact] index: ParaId,
#[pallet::compact] cap: BalanceOf<T>,
#[pallet::compact] first_slot: LeasePeriod,
#[pallet::compact] last_slot: LeasePeriod,
fund_status: Option<FundStatus>,
) -> DispatchResult {
T::EnsureConfirmAsGovernance::ensure_origin(origin)?;

let fund = Self::funds(index).ok_or(Error::<T>::InvalidParaId)?;

let status = match fund_status {
None => fund.status,
Some(status) => status,
};

Funds::<T>::insert(
index,
Some(FundInfo {
cap,
first_slot,
last_slot,
status,
raised: fund.raised,
trie_index: fund.trie_index,
}),
);

Self::deposit_event(Event::<T>::Edited(index));
Ok(())
}

/// Unlock the reserved vsToken/vsBond after fund success
#[pallet::weight(T::WeightInfo::unlock())]
#[transactional]
Expand Down
30 changes: 30 additions & 0 deletions pallets/salp/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1364,3 +1364,33 @@ fn batch_unlock_should_work() {
assert_ok!(Salp::batch_unlock(Some(ALICE).into(), 3_000));
})
}

#[test]
fn edit_fund_should_work() {
new_test_ext().execute_with(|| {
assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get()));
assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100));
assert_ok!(Salp::confirm_contribute(
Some(ALICE).into(),
BRUCE,
3_000,
true,
CONTRIBUTON_INDEX
));
assert_ok!(Salp::fund_fail(Some(ALICE).into(), 3_000));
assert_ok!(Salp::edit(Some(ALICE).into(), 3_000, 1_000, 2, SlotLength::get() + 1, None));
let mut fund = Salp::funds(3_000).unwrap();
assert_eq!(fund.first_slot, 2);
assert_eq!(fund.status, FundStatus::Failed);
assert_ok!(Salp::edit(
Some(ALICE).into(),
3_000,
1_000,
2,
SlotLength::get() + 1,
Some(FundStatus::Ongoing),
));
fund = Salp::funds(3_000).unwrap();
assert_eq!(fund.status, FundStatus::Ongoing);
})
}

0 comments on commit cd49e91

Please sign in to comment.