diff --git a/pallets/system_tables/src/lib.rs b/pallets/system_tables/src/lib.rs index 626eb12e..53e2cfa0 100644 --- a/pallets/system_tables/src/lib.rs +++ b/pallets/system_tables/src/lib.rs @@ -359,45 +359,21 @@ pub mod pallet { let staker_id = sxt_core::utils::eth_address_to_substrate_account_id::(&staker)?; - // Make sure they're staked - let Some(old_staking_ledger) = pallet_staking::Ledger::::get(&staker_id) - else { - return Err(Error::::AccountNotStaked.into()); - }; - - // Make sure they're in an unbonding state - if !(pallet_staking::Pallet::::is_unbonding(&staker_id)?) { - return Err(Error::::AccountNotUnbonding.into()); - } - let staker_signer: OriginFor = RawOrigin::Signed(staker_id.clone()).into(); - // The struct that represents when a particular batch of funds will unlock - // has all fields private to the staking crate. For now the - // best we can do is to call the withdraw function and see if there are any - // balance changes. + let old_total = pallet_staking::Ledger::::get(&staker_id) + .map(|ledger| ledger.total) + .unwrap_or(0); + pallet_staking::Pallet::::withdraw_unbonded(staker_signer.clone(), 0u32) .map_err(|e| e.error)?; - // Check if the user still has entries in the staking ledger - let maybe_new_staking_ledger = pallet_staking::Ledger::::get(&staker_id); - - if maybe_new_staking_ledger.is_some() { - // If this was a partial unlock we need to actually check if the locks - // were removed by the withdrawal call. If they weren't the claim is - // unsuccessful and we return an error. Otherwise we emit the event - if pallet_staking::Pallet::::is_unbonding(&staker_id)? { - // The user's unstaked funds are still locked - return Err(Error::::FundsLocked.into()); - } - } - - let new_total = maybe_new_staking_ledger + let new_total = pallet_staking::Ledger::::get(&staker_id) .map(|ledger| ledger.total) .unwrap_or(0); - let amount_withdrawn = old_staking_ledger.total.saturating_sub(new_total); + let amount_withdrawn = old_total.saturating_sub(new_total); ClaimedUnstakes::::insert( &staker_id,