Skip to content

Commit

Permalink
Fix: crowdloan claim for users after expired (#1945)
Browse files Browse the repository at this point in the history
* add force arg to do_claim_for

* add force_claim_for
  • Loading branch information
mclyk authored Jul 19, 2023
1 parent 3bc7647 commit 9cd3cbc
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions pallets/crowdloans/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ pub mod pallet {
lease_end: LeasePeriod,
) -> DispatchResult {
let who = ensure_signed(origin)?;
Self::do_claim_for(who, crowdloan, lease_start, lease_end)
Self::do_claim_for(who, crowdloan, lease_start, lease_end, false)
}

/// If a `crowdloan` succeeded, claim the liquid derivatives of the
Expand All @@ -826,7 +826,7 @@ pub mod pallet {
) -> DispatchResult {
let _ = ensure_signed(origin)?;
let who = T::Lookup::lookup(dest)?;
Self::do_claim_for(who, crowdloan, lease_start, lease_end)
Self::do_claim_for(who, crowdloan, lease_start, lease_end, false)
}

/// If a `crowdloan` failed, withdraw the contributed assets
Expand Down Expand Up @@ -1220,6 +1220,23 @@ pub mod pallet {
));
Ok(())
}

/// If a `crowdloan` expired, force claim the liquid derivatives for users
/// who didn't claim it during succeed phase
#[pallet::call_index(22)]
#[pallet::weight(<T as Config>::WeightInfo::claim())]
#[transactional]
pub fn force_claim_for(
origin: OriginFor<T>,
dest: <T::Lookup as StaticLookup>::Source,
crowdloan: ParaId,
lease_start: LeasePeriod,
lease_end: LeasePeriod,
) -> DispatchResult {
ensure_origin!(SlotExpiredOrigin, origin)?;
let who = T::Lookup::lookup(dest)?;
Self::do_claim_for(who, crowdloan, lease_start, lease_end, true)
}
}

impl<T: Config> Pallet<T> {
Expand Down Expand Up @@ -1642,16 +1659,19 @@ pub mod pallet {
crowdloan: ParaId,
lease_start: LeasePeriod,
lease_end: LeasePeriod,
force: bool,
) -> DispatchResult {
let ctoken = Self::ctoken_of((&lease_start, &lease_end))
.ok_or(Error::<T>::CTokenDoesNotExist)?;
let vault = Self::vaults((&crowdloan, &lease_start, &lease_end))
.ok_or(Error::<T>::VaultDoesNotExist)?;

ensure!(
vault.phase == VaultPhase::Succeeded,
Error::<T>::IncorrectVaultPhase
);
if !force {
ensure!(
vault.phase == VaultPhase::Succeeded,
Error::<T>::IncorrectVaultPhase
);
}

let (amount, _) =
Self::contribution_get(vault.trie_index, &who, ChildStorageKind::Contributed);
Expand Down

0 comments on commit 9cd3cbc

Please sign in to comment.