Skip to content
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

1st Runtime Upgrade on Rollup Prod Alphanet: Issuance Edits #876

Merged
merged 8 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pallets/bootstrap/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ parameter_types! {


pub const TotalCrowdloanAllocation: Balance = 200_000_000;
pub const IssuanceCap: Balance = 4_000_000_000;
pub const IssuanceAmount: Balance = 4_000_000_000;
pub const LinearIssuanceBlocks: u32 = 22_222u32;
pub const LiquidityMiningSplit: Perbill = Perbill::from_parts(555555556);
pub const StakingSplit: Perbill = Perbill::from_parts(344444444);
Expand All @@ -247,7 +247,7 @@ impl pallet_issuance::Config for Test {
type LiquidityMiningIssuanceVault = LiquidityMiningIssuanceVault;
type StakingIssuanceVault = StakingIssuanceVault;
type TotalCrowdloanAllocation = TotalCrowdloanAllocation;
type IssuanceCap = IssuanceCap;
type IssuanceAmount = IssuanceAmount;
type LinearIssuanceBlocks = LinearIssuanceBlocks;
type LiquidityMiningSplit = LiquidityMiningSplit;
type StakingSplit = StakingSplit;
Expand Down
47 changes: 5 additions & 42 deletions pallets/issuance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ mod benchmarking;
#[derive(Encode, Decode, Clone, Default, RuntimeDebug, PartialEq, Eq, TypeInfo)]
pub struct IssuanceInfo<Balance> {
// Max number of MGA to target
pub cap: Balance,
pub issuance_amount: Balance,
// MGA created at token generation event
// We aasume that there is only one tge
pub issuance_at_init: Balance,
Expand Down Expand Up @@ -134,7 +134,7 @@ pub mod pallet {
type ImmediateTGEReleasePercent: Get<Percent>;
#[pallet::constant]
/// The maximum amount of Mangata tokens
type IssuanceCap: Get<BalanceOf<Self>>;
type IssuanceAmount: Get<BalanceOf<Self>>;
#[pallet::constant]
/// The number of blocks the issuance is linear
type LinearIssuanceBlocks: Get<u32>;
Expand Down Expand Up @@ -352,7 +352,7 @@ impl<T: Config> Pallet<T> {
ensure!(IsTGEFinalized::<T>::get(), Error::<T>::TGENotFinalized);

let issuance_config: IssuanceInfo<BalanceOf<T>> = IssuanceInfo {
cap: T::IssuanceCap::get(),
issuance_amount: T::IssuanceAmount::get(),
issuance_at_init: T::Tokens::total_issuance(T::NativeCurrencyId::get().into()),
linear_issuance_blocks: T::LinearIssuanceBlocks::get(),
liquidity_mining_split: T::LiquidityMiningSplit::get(),
Expand All @@ -379,14 +379,6 @@ impl<T: Config> Pallet<T> {
Perbill::from_percent(100),
Error::<T>::IssuanceConfigInvalid
);
ensure!(
issuance_config.cap >=
issuance_config
.issuance_at_init
.checked_add(&issuance_config.total_crowdloan_allocation)
.ok_or(Error::<T>::IssuanceConfigInvalid)?,
Error::<T>::IssuanceConfigInvalid
);
ensure!(
issuance_config.linear_issuance_blocks != u32::zero(),
Error::<T>::IssuanceConfigInvalid
Expand All @@ -403,12 +395,7 @@ impl<T: Config> Pallet<T> {
pub fn calculate_and_store_round_issuance(current_round: u32) -> DispatchResult {
let issuance_config =
IssuanceConfigStore::<T>::get().ok_or(Error::<T>::IssuanceConfigNotInitialized)?;
let to_be_issued: BalanceOf<T> = issuance_config
.cap
.checked_sub(&issuance_config.issuance_at_init)
.ok_or(Error::<T>::MathError)?
.checked_sub(&issuance_config.total_crowdloan_allocation)
.ok_or(Error::<T>::MathError)?;
let to_be_issued: BalanceOf<T> = issuance_config.issuance_amount;
let linear_issuance_sessions: u32 = issuance_config
.linear_issuance_blocks
.checked_div(T::BlocksPerRound::get())
Expand All @@ -417,31 +404,7 @@ impl<T: Config> Pallet<T> {
.checked_div(&linear_issuance_sessions.into())
.ok_or(Error::<T>::MathError)?;

let current_round_issuance: BalanceOf<T>;
// We do not want issuance to overshoot
// Sessions begin from 0 and linear_issuance_sessions is the total number of linear sessions including 0
// So we stop before that
if current_round < linear_issuance_sessions {
current_round_issuance = linear_issuance_per_session;
} else {
let current_mga_total_issuance: BalanceOf<T> =
T::Tokens::total_issuance(T::NativeCurrencyId::get().into());
if issuance_config.cap > current_mga_total_issuance {
// TODO
// Here we assume that the crowdloan ends before linear issuance period ends
// We could get the amount that the crowdloan rewards still need to mint and account for that
// But that largely depends on on how the next crowdloan will be implemented
// Not very useful for the first crowdloan, as we know that it will end before linear issuance period ends and we check for this
current_round_issuance = linear_issuance_per_session.min(
issuance_config
.cap
.checked_sub(&current_mga_total_issuance)
.ok_or(Error::<T>::MathError)?,
)
} else {
current_round_issuance = Zero::zero();
}
}
let current_round_issuance: BalanceOf<T> = linear_issuance_per_session;

let liquidity_mining_issuance =
issuance_config.liquidity_mining_split * current_round_issuance;
Expand Down
4 changes: 2 additions & 2 deletions pallets/issuance/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ parameter_types! {


pub const TotalCrowdloanAllocation: Balance = 200_000_000;
pub const IssuanceCap: Balance = 4_000_000_000;
pub const IssuanceAmount: Balance = 4_000_000_000;
pub const LinearIssuanceBlocks: u32 = 22_222u32;
pub const LiquidityMiningSplit: Perbill = Perbill::from_parts(555555556);
pub const StakingSplit: Perbill = Perbill::from_parts(222222222);
Expand Down Expand Up @@ -126,7 +126,7 @@ impl pallet_issuance::Config for Test {
type StakingIssuanceVault = StakingIssuanceVault;
type SequencersIssuanceVault = SequencersIssuanceVault;
type TotalCrowdloanAllocation = TotalCrowdloanAllocation;
type IssuanceCap = IssuanceCap;
type IssuanceAmount = IssuanceAmount;
type LinearIssuanceBlocks = LinearIssuanceBlocks;
type LiquidityMiningSplit = LiquidityMiningSplit;
type StakingSplit = StakingSplit;
Expand Down
4 changes: 2 additions & 2 deletions pallets/issuance/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn init_issuance_config_works() {
assert_eq!(
Issuance::get_issuance_config(),
Some(IssuanceInfo {
cap: 4_000_000_000u128,
issuance_amount: 4_000_000_000u128,
issuance_at_init: current_issuance,
linear_issuance_blocks: 22_222u32,
liquidity_mining_split: Perbill::from_parts(555555556),
Expand Down Expand Up @@ -71,7 +71,7 @@ fn cannot_init_issuance_config_when_already_init() {
assert_eq!(
Issuance::get_issuance_config(),
Some(IssuanceInfo {
cap: 4_000_000_000u128,
issuance_amount: 4_000_000_000u128,
issuance_at_init: current_issuance,
linear_issuance_blocks: 22_222u32,
liquidity_mining_split: Perbill::from_parts(555555556),
Expand Down
4 changes: 2 additions & 2 deletions pallets/parachain-staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ parameter_types! {
pub StakingIssuanceVault: AccountId = StakingIssuanceVaultId::get().into_account_truncating();

pub const TotalCrowdloanAllocation: Balance = 200_000_000;
pub const IssuanceCap: Balance = 4_000_000_000;
pub const IssuanceAmount: Balance = 4_000_000_000;
pub const LinearIssuanceBlocks: u32 = 13_140_000u32; // 5 years
pub const LiquidityMiningSplit: Perbill = Perbill::from_parts(555555556);
pub const StakingSplit: Perbill = Perbill::from_parts(444444444);
Expand Down Expand Up @@ -109,7 +109,7 @@ impl GetIssuance<Balance> for MockIssuance {
}
fn get_staking_issuance(_n: u32) -> Option<Balance> {
let to_be_issued: Balance =
IssuanceCap::get() - TargetTge::get() - TotalCrowdloanAllocation::get();
IssuanceAmount::get() - TargetTge::get() - TotalCrowdloanAllocation::get();
let linear_issuance_sessions: u32 = LinearIssuanceBlocks::get() / BlocksPerRound::get();
let linear_issuance_per_session = to_be_issued / linear_issuance_sessions as Balance;
let staking_issuance = StakingSplit::get() * linear_issuance_per_session;
Expand Down
4 changes: 2 additions & 2 deletions pallets/proof-of-stake/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl pallet_issuance::Config for Test {
type StakingIssuanceVault = StakingIssuanceVault;
type SequencersIssuanceVault = SequencerIssuanceVault;
type TotalCrowdloanAllocation = TotalCrowdloanAllocation;
type IssuanceCap = IssuanceCap;
type IssuanceAmount = IssuanceAmount;
type LinearIssuanceBlocks = LinearIssuanceBlocks;
type LiquidityMiningSplit = LiquidityMiningSplit;
type StakingSplit = StakingSplit;
Expand Down Expand Up @@ -140,7 +140,7 @@ parameter_types! {


pub const TotalCrowdloanAllocation: Balance = 200_000_000;
pub const IssuanceCap: Balance = 4_000_000_000;
pub const IssuanceAmount: Balance = 4_000_000_000;
pub const LinearIssuanceBlocks: u32 = 22_222u32;
pub const LiquidityMiningSplit: Perbill = Perbill::from_parts(555555556);
pub const StakingSplit: Perbill = Perbill::from_parts(344444444);
Expand Down
4 changes: 2 additions & 2 deletions pallets/sequencer-staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ parameter_types! {
pub SequencerIssuanceVault: AccountId = SequencerIssuanceVaultId::get().into_account_truncating();

pub const TotalCrowdloanAllocation: Balance = 0;
pub const IssuanceCap: Balance = 4_000_000_000;
pub const IssuanceAmount: Balance = 4_000_000_000;
pub const LinearIssuanceBlocks: u32 = 10_000u32;
pub const LiquidityMiningSplit: Perbill = Perbill::from_parts(555555556);
pub const StakingSplit: Perbill = Perbill::from_parts(344444444);
Expand Down Expand Up @@ -96,7 +96,7 @@ impl GetIssuance<Balance> for MockIssuance {
}
fn get_sequencer_issuance(_n: u32) -> Option<Balance> {
let to_be_issued: Balance =
IssuanceCap::get() - TargetTge::get() - TotalCrowdloanAllocation::get();
IssuanceAmount::get() - TargetTge::get() - TotalCrowdloanAllocation::get();
let linear_issuance_sessions: u32 = LinearIssuanceBlocks::get() / BlocksPerRound::get();
let linear_issuance_per_session = to_be_issued / linear_issuance_sessions as Balance;
let issuance = SequencerSplit::get() * linear_issuance_per_session;
Expand Down
6 changes: 3 additions & 3 deletions pallets/xyk/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ parameter_types! {


pub const TotalCrowdloanAllocation: Balance = 200_000_000;
pub const IssuanceCap: Balance = 100_000_000_000_000_000;
pub const IssuanceAmount: Balance = 100_000_000_000_000_000;
pub const LinearIssuanceBlocks: u32 = 22_222u32;
pub const LiquidityMiningSplit: Perbill = Perbill::from_parts(555555556);
pub const StakingSplit: Perbill = Perbill::from_parts(344444444);
Expand All @@ -137,7 +137,7 @@ parameter_types! {
// type LiquidityMiningIssuanceVault = LiquidityMiningIssuanceVault;
// type StakingIssuanceVault = StakingIssuanceVault;
// type TotalCrowdloanAllocation = TotalCrowdloanAllocation;
// type IssuanceCap = IssuanceCap;
// type IssuanceAmount = IssuanceAmount;
// type LinearIssuanceBlocks = LinearIssuanceBlocks;
// type LiquidityMiningSplit = LiquidityMiningSplit;
// type StakingSplit = StakingSplit;
Expand All @@ -158,7 +158,7 @@ impl pallet_issuance::Config for Test {
type StakingIssuanceVault = StakingIssuanceVault;
type SequencersIssuanceVault = SequencerIssuanceVault;
type TotalCrowdloanAllocation = TotalCrowdloanAllocation;
type IssuanceCap = IssuanceCap;
type IssuanceAmount = IssuanceAmount;
type LinearIssuanceBlocks = LinearIssuanceBlocks;
type LiquidityMiningSplit = LiquidityMiningSplit;
type StakingSplit = StakingSplit;
Expand Down
2 changes: 1 addition & 1 deletion rollup/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ impl pallet_issuance::Config for Runtime {
type StakingIssuanceVault = cfg::pallet_issuance::StakingIssuanceVault;
type SequencersIssuanceVault = cfg::pallet_issuance::SequencerIssuanceVault;
type TotalCrowdloanAllocation = cfg::pallet_issuance::TotalCrowdloanAllocation;
type IssuanceCap = cfg::pallet_issuance::IssuanceCap;
type IssuanceAmount = cfg::pallet_issuance::IssuanceAmount;
type LinearIssuanceBlocks = cfg::pallet_issuance::LinearIssuanceBlocks;
type LiquidityMiningSplit = cfg::pallet_issuance::LiquidityMiningSplit;
type StakingSplit = cfg::pallet_issuance::StakingSplit;
Expand Down
10 changes: 5 additions & 5 deletions rollup/runtime/src/runtime_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1000,11 +1000,11 @@ pub mod config {
pub SequencerIssuanceVault: AccountId = SequencerIssuanceVaultId::get().into_account_truncating();

pub const TotalCrowdloanAllocation: Balance = 0 * DOLLARS;
pub const IssuanceCap: Balance = 25_400_000 * DOLLARS;
pub const LinearIssuanceBlocks: u32 = 10_512_000u32; // 5 years
pub const LiquidityMiningSplit: Perbill = Perbill::from_parts(647050000); // 13'199'820
pub const StakingSplit: Perbill = Perbill::from_parts(235300000); // 4'800'120
pub const SequencerSplit: Perbill = Perbill::from_parts(117650000); // 2'400'060
pub const IssuanceAmount: Balance = 10_200_000 * DOLLARS; // IssuanceAmount is the value that is issued over the LinearIssuanceBlocks
pub const LinearIssuanceBlocks: u32 = 10_512_000u32; // 2 years
pub const LiquidityMiningSplit: Perbill = Perbill::from_parts(686000000); // 6_997_200
pub const StakingSplit: Perbill = Perbill::from_parts(314000000); // 3_202_800
pub const SequencerSplit: Perbill = Perbill::from_parts(0); // 0
pub const ImmediateTGEReleasePercent: Percent = Percent::from_percent(100);
// Just some safe values to avoid zero diision etc
// TGE happens on L1 either way
Expand Down
Loading