-
Notifications
You must be signed in to change notification settings - Fork 856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pallet assets-vesting
#7404
base: master
Are you sure you want to change the base?
Pallet assets-vesting
#7404
Conversation
…et-vesting` Next steps: finish migrating tests / add tests for multiple assets
…enchmarking` to prevent unused imports
45f5e13
to
e04b76c
Compare
4dee538
to
178e20f
Compare
… AH Westend and AH Rococo
178e20f
to
66e3103
Compare
@@ -0,0 +1,16 @@ | |||
title: Bridges small nits/improvements |
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.
title: Bridges small nits/improvements | |
title: "Introduce `pallet-assets-vesting`" |
|
||
/// A vesting schedule over a fungible asset class. This allows a particular currency to have | ||
/// vesting limits applied to it. | ||
pub trait VestingSchedule<AccountId> { |
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 don't see anything wrong in the trait itself, but it is very different from how other fungibles features are implemented.
fungibles is defined with Inspect
and Mutate
, then fungibles freeze and holds have their own Inspect
and Mutate
.
Here we have VestingSchedule
and VestingTransfer
.
I think we can merge both schedule and transfer, and then split it again but into Inspect
and Mutate
.
Inspect
trait will bound fungibles::Inspect
so that AssetId
, Balance
are defined their and not duplicated
Mutate
will bound Inspect
probably fungibles::Mutate
.
Then the trait can have many method already implemented similarly to other traits like in hold. But I don't mind also no default implementation.
WDYT?
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.
So, it'd be something like fungible/fungibles::vesting::Inspect
and fungible/fungibles::vesting::Mutate
? Then, include the methods from VestingSchedule
and VestingTransfer
inside.
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.
Yes I think so
#[derive(DefaultNoBound)] | ||
pub struct GenesisConfig<T: Config<I>, I: 'static = ()> { | ||
pub vesting: | ||
Vec<(Vec<u8>, T::AccountId, BlockNumberFor<T>, BlockNumberFor<T>, BalanceOf<T, I>)>, |
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.
Maybe we can have a more precise type rather than a tuple?
// Total genesis `balance` minus `liquid` equals assets frozen for vesting | ||
let frozen = balance.saturating_sub(liquid); | ||
let length_as_balance = T::BlockNumberToBalance::convert(length); | ||
let per_block = frozen / length_as_balance.max(One::one()); |
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.
If per_block
is zero here it will trigger vesting info invalid. Maybe
let per_block = frozen / length_as_balance.max(One::one()); | |
let per_block = (frozen / length_as_balance.max(One::one())).max(One::one()); |
let vesting_info = VestingInfo::new(frozen, per_block, begin); | ||
if !vesting_info.is_valid() { | ||
panic!("Invalid VestingInfo params at genesis") | ||
}; | ||
|
||
Vesting::<T, I>::try_append(asset.clone(), who, vesting_info) | ||
.expect("Too many vesting schedules at genesis."); | ||
|
||
T::Freezer::set_freeze(asset, &FreezeReason::<I>::Vesting.into(), who, frozen) | ||
.expect("Too many freezes at genesis"); |
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.
out of curiosity, would add_versing_schedule
work? it would be simpler than manually adding the schedule.
/// - `starting_block`: `MAX(schedule1.starting_block, scheduled2.starting_block, | ||
/// current_block)`. | ||
/// - `ending_block`: `MAX(schedule1.ending_block, schedule2.ending_block)`. | ||
/// - `locked`: `schedule1.locked_at(current_block) + schedule2.locked_at(current_block)`. |
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.
isn't it disadvantageous to merge if 1 or 2 schedule are future?
all the unlock from the earlier to the later is postponed to after later?
Hmm something seems wrong, if I have 2 identical vesting schedule, and I merge them I get a new vesting schedule that double the frozen amount.
AFAICT it is never advantageous to merge schedules, in any circumstances no? Do I miss something, why do have this feature to merge schedules?
EDIT: maybe we don't need this merge, we can just have vesting without merging vesting schedules.
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.
Hmm… good question! It was already in the Currency
version (pallet-vesting
), so I just moved it here to keep compatibility. Maybe we don't really need it, but there might be use cases that already take advantage from it. Not sure whether those assumptions would hold.
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.
Ok, let's keep it as it is, but let's add in the doc of the call that the resulting vesting is always disadvantageous to the caller, and the only advantage is to reduce the number of vesting schedule in storage.
Fixes #4090.
Description
The
pallet-assets-vesting
is a pallet that supports handling vesting of an instances ofpallet-assets
through freezingfungibles
.The behaviour is analog to what already exists with
pallet-vesting
, with small differences (like adding anasset
parameter where theAssetId
goes on every call). Also,WithdrawalReasons
are no longer used, since they're related toCurrency
.Integration
This pallet can be integrated into any runtime that already has an instance of
pallet-assets
andpallet-assets-freezer
.The instance must be the same as the one that pallets mentioned above use.
Checklist
T
required)