Closed mclyk closed 2 years ago
Q1: what if in one era, user unstake through both of RelayChain/MatchingPool
Q2: if user unstake through MatchingPool, shoud add more Storage type?
Q3: if add new storage type, how to deal it with current Unlockings/UnlockChunk
, how to deal with it if currently era, total_stake_amount < total_unstake_amount
pub enum UnstakeProvider {
RelayChain = 0,
Loans = 1,
MatchingPool = 2,
}
/// MatchingPool fast unstake fee
#[pallet::constant]
type MatchingPoolFastUnstakeFee: Get<Rate>;
pub fn fast_match_unstake(origin: OriginFor<T>, redeemer_list: Vec<T::AccountId>)-> DispatchResult {
let _ = ensure_signed(origin)?;
for redeemer in redeemer_list {
Self::do_fast_match_unstake(&redeemer)?;
}
Ok(())
}
fn do_fast_match_unstake(redeemer: &T::AccountId){
//TODO: check MatchingPool, total_stake_amount and total_unstake_amount
//TODO: decrease storage `FastUnstakeRequests`
//TODO: decrease storage `Unlockings`
//TODO: charge fee and transfer to redeemer
}
// storage the total fast unstake amount and its accountId
#[pallet::storage]
#[pallet::getter(fn fast_unstake_requests)]
pub type FastUnstakeRequests<T: Config> = StorageMap<_, Blake2_128Concat, T::AccountId,BalanceOf<T>>;
unstake
(MatchingPool)
store unstake amount in Unlockings
(no change), besides, store it into FastUnstakeRequests
fast_match_unstake
offchain client listening storage FastUnstakeRequests
, calculate and using its accounts calling fast_match_unstake
user.Unlocking.UnlockingChunks
user.FastUnstakeRequests.amount
FastUnstakeRequests
Once advance new era, clear FastUnstakeRequests
storage, only deal with fast unstake requests in one era. user call unstake(MatchingPool)
FastUnstakeRequests
(in liquid currency), no other storage change(Unlocking/Matching pool).offchain call fast_match_unstake
on-chain logic:
FastUnstakeRequests
user.FastUnstakeRequests.amount
clear FastUnstakeRequests
Currently, instant unstake fee based on
Loans
charged high, now design instant unstake based on matching pool charged less, and not instantly. called itfast unstake