-
Notifications
You must be signed in to change notification settings - Fork 38
[Pending] Rebond unlocking chunks #97
base: polkadot-v0.9.29
Are you sure you want to change the base?
Conversation
compilation started to fail after pushing small commit 852fb39. Why, will check |
rebond_and_stake { | ||
initialize::<T>(); | ||
|
||
let (_, contract_id) = register_contract::<T>(1)?; | ||
prepare_bond_and_stake::<T>(T::MaxNumberOfStakersPerContract::get() - 1, &contract_id, SEED)?; | ||
|
||
let staker = whitelisted_caller(); | ||
let _ = T::Currency::make_free_balance_be(&staker, BalanceOf::<T>::max_value()); | ||
let stake_amount = BalanceOf::<T>::max_value() / 2u32.into(); | ||
let unstake_amount = stake_amount / 2u32.into(); | ||
|
||
DappsStaking::<T>::bond_and_stake(RawOrigin::Signed(staker.clone()).into(), contract_id.clone(), stake_amount)?; | ||
DappsStaking::<T>::unbond_and_unstake(RawOrigin::Signed(staker.clone()).into(), contract_id.clone(), unstake_amount)?; | ||
}: _(RawOrigin::Signed(staker.clone()), contract_id.clone()) | ||
verify { | ||
assert_last_event::<T>(Event::<T>::RebondAndStake(staker, contract_id, unstake_amount).into()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I'd like to have some comments describing what is actually happening.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM aside of small nits
let base_weight = | ||
<T as pallet_dapps_staking::Config>::WeightInfo::rebond_and_stake(); | ||
env.charge_weight(base_weight)?; | ||
|
||
let caller = env.ext().address().clone(); | ||
let call_result = pallet_dapps_staking::Pallet::<T>::rebond_and_stake( | ||
RawOrigin::Signed(caller).into(), | ||
contract, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was kinda confused since rebond_and_stake
is called twice in a row. I do understand that these are two different calls, but still this is a bit confusing. Maybe we should add couple of comments to reduce overall WTF/minute.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be said for other functions too. it's a more universal topic.
I thought it's very clear they are different and what they do because they are different methods, one is WeightInfo
's and another is Pallet
's.
@@ -120,27 +123,29 @@ pub enum Contract<Account> { | |||
Wasm(Account), | |||
} | |||
|
|||
pub type ContractBytes = [u8; 32]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this type is in public it would be a good idea to add some explanatory comment. What is this type, why it 32 bytes long, what is the purpose of that type, etc.
Minimum allowed line rate is |
@Dinonard I also added chain extension and precompiles, but I started to think they should be separately released (in a different PR) after this function become stable. What do you think? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this!
About your precompile/chain-extension questions, I think we should keep them out of this PR. And maybe we shouldn't add them at all.
Your comment about feature being stable makes sense and I'd also add the point that we'll be redesigning dapps-staking very soon. It's not necessarily true that this function will be compatible with new version so I'd wait until then with it. That way we reduce number of incompatible legacy functions.
/// | ||
/// All unbonding chunks will be used and staked to the specified contract. | ||
/// | ||
/// The dispatch origin for this call must be _Signed_ by the staker's account. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also check top of lib.rs file and update comments there if needed.
GeneralEraInfo::<T>::mutate(¤t_era, |value| { | ||
if let Some(x) = value { | ||
x.staked = x.staked.saturating_add(value_to_stake); | ||
x.locked = x.locked.saturating_add(value_to_stake); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is incorrect - TVL doesn't increase after this since unbonding chunks are still considered to be locked.
UT should be updated to catch this.
assert_eq!( | ||
final_state.era_info.locked, | ||
init_state.era_info.locked + expected_stake_amount | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is incorrect, see my comment above.
); | ||
}) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest also covering the error cases with InsufficientValue or TooManyEraStakeValues.
Not mandatory, just a suggestion.
That makes sense. |
I'm not sure how feasible is that, tbh. We don't know if this will even be applicable then. I don't see an issue with this being merged now but we should avoid precompiles/chain-extensions. Also, not sure how much it makes sense to ask UI team to do this since it will most likely be changed soon. Anyhow, |
Solves #63
Pull Request Summary
Added feature
rebond_and_stake
unlocking chunks to contracts.Once stakers start the unbonding, their unbonded funds will remain locked during the
unbonding period
. During this period, these funds neither generate any rewards nor can they be used for payment, transfer, etc.One functionality we could provide is for stakers to re-bond their unbonding chunks. They could select unbonding chunks as a source when staking on a contract from UI, similar as they do for nomination_transfer. This will result in unbonding chunks being consumed and (re)staked on some contract.
Check list