Skip to content

Commit

Permalink
launch: deploy stage 28 to 30 (#1602)
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianFranzen authored Feb 26, 2025
1 parent a4eb757 commit 6bc9b63
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 30 deletions.
5 changes: 0 additions & 5 deletions pallets/launch/src/allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ pub enum Allocation {
Airdrop,
Initiatives,
Ecosystem,
Bridged,
#[allow(clippy::upper_case_acronyms)]
SIZE,
}
Expand All @@ -57,7 +56,6 @@ impl Allocation {
i if i == Airdrop as usize => Airdrop,
i if i == Initiatives as usize => Initiatives,
i if i == Ecosystem as usize => Ecosystem,
i if i == Bridged as usize => Bridged,
_ => Ignore,
}
}
Expand Down Expand Up @@ -85,7 +83,6 @@ impl Allocation {
Airdrop => b"airdrop",
Initiatives => b"initiatives",
Ecosystem => b"ecosystem",
Bridged => b"bridged-erc20",
}
}

Expand All @@ -111,7 +108,6 @@ impl Allocation {
Airdrop => 452_898_550_000 * mANLOG,
Initiatives => 1_811_594_200_000 * mANLOG,
Ecosystem => 1_359_106_343_190 * mANLOG,
Bridged => 0,
}
}

Expand All @@ -132,7 +128,6 @@ impl Allocation {
Airdrop => None,
Initiatives => Some((1_086_956_520_000 * mANLOG, 68_745 * mANLOG, 633_270)),
Ecosystem => Some((679_553_171_595 * mANLOG, 32_234 * mANLOG, 633_270)),
Bridged => None,
}
}

Expand Down
44 changes: 44 additions & 0 deletions pallets/launch/src/application.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use crate::Config;

use scale_codec::{Decode, Encode};

use polkadot_sdk::*;

use frame_support::traits::LockIdentifier;
use sp_core::Get;
use sp_runtime::traits::AccountIdConversion;
use sp_runtime::RuntimeDebug;

#[derive(Clone, Encode, Decode, PartialEq, RuntimeDebug, scale_info::TypeInfo)]
#[repr(u8)]
pub enum Application {
Bridging,
OverTheCounter,
}

impl Application {
/// Retrieve sub id used in virtual wallet generation
pub fn sub_id(&self) -> &'static [u8] {
use Application::*;

match self {
Bridging => b"bridged-erc20",
OverTheCounter => b"over-the-counter",
}
}

/// Compute account id of virtual wallet tracking issuance
pub fn account_id<T: Config>(&self) -> T::AccountId {
T::PalletId::get().into_sub_account_truncating(self.sub_id())
}

/// Current identifier under which to lock tokens
pub fn lock_id(&self) -> LockIdentifier {
use Application::*;

match self {
Bridging => *b"bridged0",
OverTheCounter => *b"otclock0",
}
}
}
11 changes: 4 additions & 7 deletions pallets/launch/src/benchmarks.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![cfg(feature = "runtime-benchmarks")]
use crate::{allocation::Allocation, BalanceOf, Call, Config, CurrencyOf, Pallet};
use crate::{application::Application, BalanceOf, Call, Config, CurrencyOf, Pallet};

//use super::mock_helpers::*;
use polkadot_sdk::*;
Expand All @@ -16,18 +16,15 @@ use time_primitives::{Balance, TARGET_ISSUANCE};
mod benchmarks {
use super::*;

//use polkadot_sdk::pallet_balances;
use polkadot_sdk::frame_support::traits::Currency;

#[benchmark]
fn set_bridged_issuance() {
let bridge_account = Allocation::Bridged.account_id::<T>();
fn lock_operational() {
let bridge_account = Application::Bridging.account_id::<T>();
let bridge_issuance = BalanceOf::<T>::from(TARGET_ISSUANCE);
let _ = CurrencyOf::<T>::deposit_creating(&bridge_account, bridge_issuance);

#[extrinsic_call]
_(RawOrigin::Root, bridge_issuance);

//assert_eq!(pallet_balances::Pallet::<T>::balance_locked(*b"bridged0", &bridge_account),bridge_issuance);
_(RawOrigin::Root, Application::Bridging, bridge_issuance);
}
}
1 change: 1 addition & 0 deletions pallets/launch/src/data/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Include data files here
pub mod v28;
pub mod v29;
pub mod v30;
6 changes: 6 additions & 0 deletions pallets/launch/src/data/v30.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use crate::airdrops::RawAirdropMintStage;

use time_primitives::ANLOG;

pub const AIRDROPS_VALIDATORS_MISSED: RawAirdropMintStage =
&[("an8ZYQStoJTWVqnmnsuSQwzugcxdUX9vBVSdzuCRE9LydDW9U", 160_086 * ANLOG, None)];
60 changes: 44 additions & 16 deletions pallets/launch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ mod benchmarks;

mod airdrops;
mod allocation;
mod application;
mod deposits;
mod ledger;
mod stage;
Expand All @@ -46,6 +47,7 @@ pub mod pallet {
// Import various useful types required by all FRAME pallets.
use super::*;
use allocation::Allocation;
use application::Application;
use frame_support::pallet_prelude::*;
use frame_support::traits::{
Currency, ExistenceRequirement, LockableCurrency, StorageVersion, WithdrawReasons,
Expand All @@ -56,18 +58,18 @@ pub mod pallet {
use sp_std::{vec, vec::Vec};

pub trait WeightInfo {
fn set_bridged_issuance() -> Weight;
fn lock_operational() -> Weight;
}

pub struct TestWeightInfo;
impl WeightInfo for TestWeightInfo {
fn set_bridged_issuance() -> Weight {
fn lock_operational() -> Weight {
Weight::zero()
}
}

/// Updating this number will automatically execute the next launch stages on update
pub const LAUNCH_VERSION: u16 = 27;
pub const LAUNCH_VERSION: u16 = 30;
/// Wrapped version to support substrate interface as well
pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(LAUNCH_VERSION);

Expand Down Expand Up @@ -137,6 +139,13 @@ pub mod pallet {
),
// Airdrop Move 3
(29, Allocation::Airdrop, 0, Stage::AirdropTransfer(data::v29::AIRDROP_MOVE_3)),
// Validator Airdrop (missed)
(
30,
Allocation::Ecosystem,
160_086 * ANLOG,
Stage::AirdropFromUnlocked(data::v30::AIRDROPS_VALIDATORS_MISSED),
),
];

/// TODO: Difference that was actually minted for airdrops:
Expand Down Expand Up @@ -226,13 +235,32 @@ pub mod pallet {
TransferFromVirtual { source: Vec<u8>, target: T::AccountId, amount: BalanceOf<T> },
}

/// Old bridged token wallet from which to migrate
const OLD_BRIDGED_WALLET: AccountId = AccountId::new([
109, 111, 100, 108, 116, 101, 115, 116, 108, 110, 99, 104, 52, 98, 114, 105, 100, 103, 101,
100, 45, 101, 114, 99, 50, 48, 0, 0, 0, 0, 0, 0,
]);

#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T>
where
T::AccountId: From<AccountId>,
Balance: From<BalanceOf<T>> + From<AirdropBalanceOf<T>>,
BalanceOf<T>: From<u128>,
{
fn on_runtime_upgrade() -> frame_support::weights::Weight {
if let Err(error) = CurrencyOf::<T>::transfer(
&T::AccountId::from(OLD_BRIDGED_WALLET),
&Application::Bridging.account_id::<T>(),
(103_579_710 * ANLOG).into(),
ExistenceRequirement::AllowDeath,
) {
log::warn!(
target: LOG_TARGET,
"🤔 Unable to migrate old bridging funds: {:?}", error
);
}

match LaunchLedger::compile(LAUNCH_LEDGER) {
Ok(plan) => return plan.run(),
Err(error) => {
Expand All @@ -250,25 +278,25 @@ pub mod pallet {

#[pallet::call]
impl<T: Config> Pallet<T> {
/// Update total amount of tokens that are locked in the [`Allocation::Bridged`]
/// account as preparation for miniting or as a result of burning wrapped
/// tokens on another chain.
/// Update total amount of tokens that are locked in one of the operational wallets.
///
/// This is used as a preparation for miniting, as a result of burning wrapped
/// tokens on another chain or other tokenomics reasons.
#[pallet::call_index(0)]
#[pallet::weight(<T as Config>::WeightInfo::set_bridged_issuance())]
pub fn set_bridged_issuance(origin: OriginFor<T>, amount: BalanceOf<T>) -> DispatchResult {
#[pallet::weight(<T as Config>::WeightInfo::lock_operational())]
pub fn lock_operational(
origin: OriginFor<T>,
target: Application,
amount: BalanceOf<T>,
) -> DispatchResult {
T::LaunchAdmin::ensure_origin(origin)?;

let bridge_account = Allocation::Bridged.account_id::<T>();
let account = target.account_id::<T>();
ensure!(
CurrencyOf::<T>::total_balance(&bridge_account) >= amount,
CurrencyOf::<T>::total_balance(&account) >= amount,
TokenError::FundsUnavailable
);
CurrencyOf::<T>::set_lock(
*b"bridged0",
&bridge_account,
amount,
WithdrawReasons::all(),
);
CurrencyOf::<T>::set_lock(target.lock_id(), &account, amount, WithdrawReasons::all());

Ok(())
}
Expand Down
1 change: 0 additions & 1 deletion pallets/launch/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::{ledger::LaunchLedger, Event, Pallet, LAUNCH_LEDGER, LAUNCH_VERSION,
use polkadot_sdk::*;

use frame_support::traits::{Currency, StorageVersion, VestingSchedule};
//use sp_runtime::traits::CheckedConversion;

use time_primitives::MILLIANLOG as mANLOG;

Expand Down
2 changes: 1 addition & 1 deletion runtime/src/weights/mainnet/pallet_launch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl<T: frame_system::Config> pallet_launch::WeightInfo for WeightInfo<T> {
/// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1299), added: 3774, mode: `MaxEncodedLen`)
/// Storage: `Balances::Freezes` (r:1 w:0)
/// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(67), added: 2542, mode: `MaxEncodedLen`)
fn set_bridged_issuance() -> Weight {
fn lock_operational() -> Weight {
// Proof Size summary in bytes:
// Measured: `165`
// Estimated: `4764`
Expand Down

0 comments on commit 6bc9b63

Please sign in to comment.