From 6bc9b630bc5cabcd4d0f0be24158a8db421997df Mon Sep 17 00:00:00 2001 From: Florian Franzen Date: Wed, 26 Feb 2025 16:29:38 +0100 Subject: [PATCH] launch: deploy stage 28 to 30 (#1602) --- pallets/launch/src/allocation.rs | 5 -- pallets/launch/src/application.rs | 44 ++++++++++++++ pallets/launch/src/benchmarks.rs | 11 ++-- pallets/launch/src/data/mod.rs | 1 + pallets/launch/src/data/v30.rs | 6 ++ pallets/launch/src/lib.rs | 60 ++++++++++++++------ pallets/launch/src/tests.rs | 1 - runtime/src/weights/mainnet/pallet_launch.rs | 2 +- 8 files changed, 100 insertions(+), 30 deletions(-) create mode 100644 pallets/launch/src/application.rs create mode 100644 pallets/launch/src/data/v30.rs diff --git a/pallets/launch/src/allocation.rs b/pallets/launch/src/allocation.rs index 3099689f6..135ea7b1e 100644 --- a/pallets/launch/src/allocation.rs +++ b/pallets/launch/src/allocation.rs @@ -30,7 +30,6 @@ pub enum Allocation { Airdrop, Initiatives, Ecosystem, - Bridged, #[allow(clippy::upper_case_acronyms)] SIZE, } @@ -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, } } @@ -85,7 +83,6 @@ impl Allocation { Airdrop => b"airdrop", Initiatives => b"initiatives", Ecosystem => b"ecosystem", - Bridged => b"bridged-erc20", } } @@ -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, } } @@ -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, } } diff --git a/pallets/launch/src/application.rs b/pallets/launch/src/application.rs new file mode 100644 index 000000000..aab75ccdd --- /dev/null +++ b/pallets/launch/src/application.rs @@ -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(&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", + } + } +} diff --git a/pallets/launch/src/benchmarks.rs b/pallets/launch/src/benchmarks.rs index 0ee3f1b69..c4c1bb446 100644 --- a/pallets/launch/src/benchmarks.rs +++ b/pallets/launch/src/benchmarks.rs @@ -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::*; @@ -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::(); + fn lock_operational() { + let bridge_account = Application::Bridging.account_id::(); let bridge_issuance = BalanceOf::::from(TARGET_ISSUANCE); let _ = CurrencyOf::::deposit_creating(&bridge_account, bridge_issuance); #[extrinsic_call] - _(RawOrigin::Root, bridge_issuance); - - //assert_eq!(pallet_balances::Pallet::::balance_locked(*b"bridged0", &bridge_account),bridge_issuance); + _(RawOrigin::Root, Application::Bridging, bridge_issuance); } } diff --git a/pallets/launch/src/data/mod.rs b/pallets/launch/src/data/mod.rs index e74e148f2..0a4800170 100644 --- a/pallets/launch/src/data/mod.rs +++ b/pallets/launch/src/data/mod.rs @@ -1,3 +1,4 @@ // Include data files here pub mod v28; pub mod v29; +pub mod v30; diff --git a/pallets/launch/src/data/v30.rs b/pallets/launch/src/data/v30.rs new file mode 100644 index 000000000..2098f3f3b --- /dev/null +++ b/pallets/launch/src/data/v30.rs @@ -0,0 +1,6 @@ +use crate::airdrops::RawAirdropMintStage; + +use time_primitives::ANLOG; + +pub const AIRDROPS_VALIDATORS_MISSED: RawAirdropMintStage = + &[("an8ZYQStoJTWVqnmnsuSQwzugcxdUX9vBVSdzuCRE9LydDW9U", 160_086 * ANLOG, None)]; diff --git a/pallets/launch/src/lib.rs b/pallets/launch/src/lib.rs index 64152cdcd..e410dce9e 100644 --- a/pallets/launch/src/lib.rs +++ b/pallets/launch/src/lib.rs @@ -25,6 +25,7 @@ mod benchmarks; mod airdrops; mod allocation; +mod application; mod deposits; mod ledger; mod stage; @@ -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, @@ -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); @@ -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: @@ -226,13 +235,32 @@ pub mod pallet { TransferFromVirtual { source: Vec, target: T::AccountId, amount: BalanceOf }, } + /// 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 Hooks> for Pallet where T::AccountId: From, Balance: From> + From>, + BalanceOf: From, { fn on_runtime_upgrade() -> frame_support::weights::Weight { + if let Err(error) = CurrencyOf::::transfer( + &T::AccountId::from(OLD_BRIDGED_WALLET), + &Application::Bridging.account_id::(), + (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) => { @@ -250,25 +278,25 @@ pub mod pallet { #[pallet::call] impl Pallet { - /// 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(::WeightInfo::set_bridged_issuance())] - pub fn set_bridged_issuance(origin: OriginFor, amount: BalanceOf) -> DispatchResult { + #[pallet::weight(::WeightInfo::lock_operational())] + pub fn lock_operational( + origin: OriginFor, + target: Application, + amount: BalanceOf, + ) -> DispatchResult { T::LaunchAdmin::ensure_origin(origin)?; - let bridge_account = Allocation::Bridged.account_id::(); + let account = target.account_id::(); ensure!( - CurrencyOf::::total_balance(&bridge_account) >= amount, + CurrencyOf::::total_balance(&account) >= amount, TokenError::FundsUnavailable ); - CurrencyOf::::set_lock( - *b"bridged0", - &bridge_account, - amount, - WithdrawReasons::all(), - ); + CurrencyOf::::set_lock(target.lock_id(), &account, amount, WithdrawReasons::all()); Ok(()) } diff --git a/pallets/launch/src/tests.rs b/pallets/launch/src/tests.rs index 64de30765..903e6c362 100644 --- a/pallets/launch/src/tests.rs +++ b/pallets/launch/src/tests.rs @@ -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; diff --git a/runtime/src/weights/mainnet/pallet_launch.rs b/runtime/src/weights/mainnet/pallet_launch.rs index 42845befa..d8e2b3677 100644 --- a/runtime/src/weights/mainnet/pallet_launch.rs +++ b/runtime/src/weights/mainnet/pallet_launch.rs @@ -41,7 +41,7 @@ impl pallet_launch::WeightInfo for WeightInfo { /// 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`