Skip to content

Commit cde31d3

Browse files
authored
Merge pull request #783 from UniqueNetwork/release-v930034-1
Release v930034 1
2 parents b30515b + fab5061 commit cde31d3

59 files changed

Lines changed: 1572 additions & 2783 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.docker/xcm-config/launch-config-xcm-quartz.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@
102102
"id": "2000",
103103
"chain": "karura-dev",
104104
"balance": "1000000000000000000000",
105+
"chainInitializer": [
106+
"chainql",
107+
"-e",
108+
"(import '${spec}') {id+: '-local'}"
109+
],
105110
"nodes": [
106111
{
107112
"wsPort": 9946,

.env

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ POLKADOT_MAINNET_BRANCH=release-v0.9.30
55
STATEMINT_BUILD_BRANCH=release-parachains-v9320
66
ACALA_BUILD_BRANCH=2.10.1
77
MOONBEAM_BUILD_BRANCH=runtime-1901
8-
UNIQUE_MAINNET_BRANCH=v924013
8+
UNIQUE_MAINNET_BRANCH=v930033-node-only-fix
99
UNIQUE_REPLICA_FROM=wss://eu-ws.unique.network:443
1010

11-
KUSAMA_MAINNET_BRANCH=release-v0.9.32
11+
KUSAMA_MAINNET_BRANCH=release-v0.9.34
1212
STATEMINE_BUILD_BRANCH=release-parachains-v9320
1313
KARURA_BUILD_BRANCH=release-karura-2.10.0
1414
MOONRIVER_BUILD_BRANCH=runtime-1901
15-
QUARTZ_MAINNET_BRANCH=v930032
15+
QUARTZ_MAINNET_BRANCH=v930033-node-only-fix
1616
QUARTZ_REPLICA_FROM=wss://eu-ws-quartz.unique.network:443
1717

1818
UNQWND_MAINNET_BRANCH=release-v0.9.30
1919
WESTMINT_BUILD_BRANCH=parachains-v9330
20-
OPAL_MAINNET_BRANCH=v930032
20+
OPAL_MAINNET_BRANCH=v930032-node-only-fix
2121
OPAL_REPLICA_FROM=wss://eu-ws-opal.unique.network:443
2222

2323
POLKADOT_LAUNCH_BRANCH=unique-network

.github/workflows/ci-master.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ concurrency:
1616
# List of a jobs included into Workflow.
1717
jobs:
1818

19+
yarn-dev:
20+
uses: ./.github/workflows/yarn-dev.yml
21+
1922
unit-test:
2023
uses: ./.github/workflows/unit-test.yml
2124

Cargo.lock

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node/rpc/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ where
176176
};
177177
use uc_rpc::{UniqueApiServer, Unique};
178178

179-
#[cfg(not(any(feature = "unique-runtime", feature = "quartz-runtime")))]
179+
#[cfg(not(feature = "unique-runtime"))]
180180
use uc_rpc::{AppPromotionApiServer, AppPromotion};
181181

182182
#[cfg(not(feature = "unique-runtime"))]
@@ -236,7 +236,7 @@ where
236236

237237
io.merge(Unique::new(client.clone()).into_rpc())?;
238238

239-
#[cfg(not(any(feature = "unique-runtime", feature = "quartz-runtime")))]
239+
#[cfg(not(feature = "unique-runtime"))]
240240
io.merge(AppPromotion::new(client.clone()).into_rpc())?;
241241

242242
#[cfg(not(feature = "unique-runtime"))]

pallets/app-promotion/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Change Log
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
<!-- bureaucrate goes here -->
6+
7+
## [0.1.1] - 2022-12-13
8+
9+
### Added
10+
11+
- The ability to configure pallet `app-promotion` via the `configuration` pallet.

pallets/app-promotion/Cargo.toml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ homepage = 'https://unique.network'
99
license = 'GPLv3'
1010
name = 'pallet-app-promotion'
1111
repository = 'https://github.com/UniqueNetwork/unique-chain'
12-
version = '0.1.0'
12+
version = '0.1.1'
1313

1414
[package.metadata.docs.rs]
1515
targets = ['x86_64-unknown-linux-gnu']
@@ -64,11 +64,12 @@ serde = { default-features = false, features = ['derive'], version = '1.0.130' }
6464
################################################################################
6565
# local dependencies
6666

67-
up-data-structs ={ default-features = false, path = "../../primitives/data-structs" }
68-
pallet-common ={ default-features = false, path = "../common" }
69-
pallet-unique ={ default-features = false, path = "../unique" }
70-
pallet-evm-contract-helpers ={ default-features = false, path = "../evm-contract-helpers" }
71-
pallet-evm-migration ={ default-features = false, path = "../evm-migration" }
67+
up-data-structs = { default-features = false, path = "../../primitives/data-structs" }
68+
pallet-common = { default-features = false, path = "../common" }
69+
pallet-configuration = { default-features = false, path = "../configuration" }
70+
pallet-unique = { default-features = false, path = "../unique" }
71+
pallet-evm-contract-helpers = { default-features = false, path = "../evm-contract-helpers" }
72+
pallet-evm-migration = { default-features = false, path = "../evm-migration" }
7273

7374
# [dev-dependencies]
7475

pallets/app-promotion/src/lib.rs

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ pub mod pallet {
102102
use frame_system::pallet_prelude::*;
103103

104104
#[pallet::config]
105-
pub trait Config: frame_system::Config + pallet_evm::account::Config {
105+
pub trait Config:
106+
frame_system::Config + pallet_evm::account::Config + pallet_configuration::Config
107+
{
106108
/// Type to interact with the native token
107109
type Currency: ExtendedLockableCurrency<Self::AccountId>
108110
+ ReservableCurrency<Self::AccountId>;
@@ -253,11 +255,11 @@ pub mod pallet {
253255
ValueQuery,
254256
>;
255257

256-
/// Stores a key for record for which the next revenue recalculation would be performed.
258+
/// Stores a key for record for which the revenue recalculation was performed.
257259
/// If `None`, then recalculation has not yet been performed or calculations have been completed for all stakers.
258260
#[pallet::storage]
259261
#[pallet::getter(fn get_next_calculated_record)]
260-
pub type NextCalculatedRecord<T: Config> =
262+
pub type PreviousCalculatedRecord<T: Config> =
261263
StorageValue<Value = (T::AccountId, T::BlockNumber), QueryKind = OptionQuery>;
262264

263265
#[pallet::hooks]
@@ -328,6 +330,7 @@ pub mod pallet {
328330
amount >= <BalanceOf<T>>::from(100u128) * T::Nominal::get(),
329331
ArithmeticError::Underflow
330332
);
333+
let config = <PalletConfiguration<T>>::get();
331334

332335
let balance =
333336
<<T as Config>::Currency as Currency<T::AccountId>>::free_balance(&staker_id);
@@ -349,17 +352,17 @@ pub mod pallet {
349352
// Calculation of the number of recalculation periods,
350353
// after how much the first interest calculation should be performed for the stake
351354
let recalculate_after_interval: T::BlockNumber =
352-
if block_number % T::RecalculationInterval::get() == 0u32.into() {
355+
if block_number % config.recalculation_interval == 0u32.into() {
353356
1u32.into()
354357
} else {
355358
2u32.into()
356359
};
357360

358361
// Сalculation of the number of the relay block
359362
// in which it is necessary to accrue remuneration for the stake.
360-
let recalc_block = (block_number / T::RecalculationInterval::get()
363+
let recalc_block = (block_number / config.recalculation_interval
361364
+ recalculate_after_interval)
362-
* T::RecalculationInterval::get();
365+
* config.recalculation_interval;
363366

364367
<Staked<T>>::insert((&staker_id, block_number), {
365368
let mut balance_and_recalc_block = <Staked<T>>::get((&staker_id, block_number));
@@ -391,9 +394,10 @@ pub mod pallet {
391394
#[pallet::weight(T::WeightInfo::unstake())]
392395
pub fn unstake(staker: OriginFor<T>) -> DispatchResultWithPostInfo {
393396
let staker_id = ensure_signed(staker)?;
397+
let config = <PalletConfiguration<T>>::get();
394398

395399
// calculate block number where the sum would be free
396-
let block = <frame_system::Pallet<T>>::block_number() + T::PendingInterval::get();
400+
let block = <frame_system::Pallet<T>>::block_number() + config.pending_interval;
397401

398402
let mut pendings = <PendingUnstake<T>>::get(block);
399403

@@ -555,31 +559,40 @@ pub mod pallet {
555559
/// # Arguments
556560
///
557561
/// * `stakers_number`: the number of stakers for which recalculation will be performed
558-
#[pallet::weight(T::WeightInfo::payout_stakers(stakers_number.unwrap_or(20) as u32))]
562+
#[pallet::weight(T::WeightInfo::payout_stakers(stakers_number.unwrap_or(DEFAULT_NUMBER_PAYOUTS) as u32))]
559563
pub fn payout_stakers(admin: OriginFor<T>, stakers_number: Option<u8>) -> DispatchResult {
560564
let admin_id = ensure_signed(admin)?;
561565

562566
ensure!(
563567
admin_id == Admin::<T>::get().ok_or(Error::<T>::AdminNotSet)?,
564568
Error::<T>::NoPermission
565569
);
570+
let config = <PalletConfiguration<T>>::get();
571+
572+
let mut stakers_number = stakers_number.unwrap_or(DEFAULT_NUMBER_PAYOUTS);
573+
574+
ensure!(
575+
stakers_number <= config.max_stakers_per_calculation && stakers_number != 0,
576+
Error::<T>::NoPermission
577+
);
566578

567579
// calculate the number of the current recalculation block,
568580
// this is necessary in order to understand which stakers we should calculate interest
569-
let current_recalc_block =
570-
Self::get_current_recalc_block(T::RelayBlockNumberProvider::current_block_number());
581+
let current_recalc_block = Self::get_current_recalc_block(
582+
T::RelayBlockNumberProvider::current_block_number(),
583+
&config,
584+
);
571585

572586
// calculate the number of the next recalculation block,
573587
// this value is set for the stakers to whom the recalculation will be performed
574-
let next_recalc_block = current_recalc_block + T::RecalculationInterval::get();
588+
let next_recalc_block = current_recalc_block + config.recalculation_interval;
575589

576590
let mut storage_iterator = Self::get_next_calculated_key()
577591
.map_or(Staked::<T>::iter(), |key| Staked::<T>::iter_from(key));
578592

579-
NextCalculatedRecord::<T>::set(None);
593+
PreviousCalculatedRecord::<T>::set(None);
580594

581595
{
582-
let mut stakers_number = stakers_number.unwrap_or(20);
583596
let last_id = RefCell::new(None);
584597
let income_acc = RefCell::new(BalanceOf::<T>::default());
585598
let amount_acc = RefCell::new(BalanceOf::<T>::default());
@@ -622,10 +635,6 @@ pub mod pallet {
622635
(amount, next_recalc_block_for_stake),
623636
)) = storage_iterator.next()
624637
{
625-
if stakers_number == 0 {
626-
NextCalculatedRecord::<T>::set(Some((current_id, staked_block)));
627-
break;
628-
}
629638
if last_id.borrow().as_ref() != Some(&current_id) {
630639
flush_stake()?;
631640
*last_id.borrow_mut() = Some(current_id.clone());
@@ -639,11 +648,18 @@ pub mod pallet {
639648
next_recalc_block,
640649
amount,
641650
((current_recalc_block - next_recalc_block_for_stake)
642-
/ T::RecalculationInterval::get())
643-
.into() + 1,
651+
/ config.recalculation_interval)
652+
.into() + 1,
644653
&mut *income_acc.borrow_mut(),
645654
);
646655
}
656+
657+
if stakers_number == 0 {
658+
if storage_iterator.next().is_some() {
659+
PreviousCalculatedRecord::<T>::set(Some((current_id, staked_block)));
660+
}
661+
break;
662+
}
647663
}
648664
flush_stake()?;
649665
}
@@ -802,15 +818,19 @@ impl<T: Config> Pallet<T> {
802818
where
803819
I: EncodeLike<BalanceOf<T>> + Balance,
804820
{
821+
let config = <PalletConfiguration<T>>::get();
805822
let mut income = base;
806823

807-
(0..iters).for_each(|_| income += T::IntervalIncome::get() * income);
824+
(0..iters).for_each(|_| income += config.interval_income * income);
808825

809826
income - base
810827
}
811828

812-
fn get_current_recalc_block(current_relay_block: T::BlockNumber) -> T::BlockNumber {
813-
(current_relay_block / T::RecalculationInterval::get()) * T::RecalculationInterval::get()
829+
fn get_current_recalc_block(
830+
current_relay_block: T::BlockNumber,
831+
config: &PalletConfiguration<T>,
832+
) -> T::BlockNumber {
833+
(current_relay_block / config.recalculation_interval) * config.recalculation_interval
814834
}
815835

816836
fn get_next_calculated_key() -> Option<Vec<u8>> {

pallets/app-promotion/src/types.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@ use frame_support::{traits::LockableCurrency, WeakBoundedVec, Parameter, dispatc
44
use pallet_balances::{BalanceLock, Config as BalancesConfig, Pallet as PalletBalances};
55
use pallet_common::CollectionHandle;
66

7-
use sp_runtime::DispatchError;
7+
use sp_runtime::{DispatchError, Perbill};
88
use up_data_structs::{CollectionId};
99
use sp_std::borrow::ToOwned;
1010
use pallet_evm_contract_helpers::{Pallet as EvmHelpersPallet, Config as EvmHelpersConfig};
11+
use pallet_configuration::{AppPromomotionConfigurationOverride};
12+
use sp_core::Get;
13+
14+
const MAX_NUMBER_PAYOUTS: u8 = 100;
15+
pub(crate) const DEFAULT_NUMBER_PAYOUTS: u8 = 20;
1116

1217
/// This trait was defined because `LockableCurrency`
1318
/// has no way to know the state of the lock for an account.
@@ -128,3 +133,32 @@ impl<T: EvmHelpersConfig> ContractHandler for EvmHelpersPallet<T> {
128133
Ok(Self::get_sponsor(contract_address))
129134
}
130135
}
136+
pub(crate) struct PalletConfiguration<T: crate::Config> {
137+
/// In relay blocks.
138+
pub recalculation_interval: T::BlockNumber,
139+
/// In parachain blocks.
140+
pub pending_interval: T::BlockNumber,
141+
/// Value for `RecalculationInterval` based on 0.05% per 24h.
142+
pub interval_income: Perbill,
143+
/// Maximum allowable number of stakers calculated per call of the `app-promotion::PayoutStakers` extrinsic.
144+
pub max_stakers_per_calculation: u8,
145+
}
146+
impl<T: crate::Config> PalletConfiguration<T> {
147+
pub fn get() -> Self {
148+
let config = <AppPromomotionConfigurationOverride<T>>::get();
149+
Self {
150+
recalculation_interval: config
151+
.recalculation_interval
152+
.unwrap_or_else(|| T::RecalculationInterval::get()),
153+
pending_interval: config
154+
.pending_interval
155+
.unwrap_or_else(|| T::PendingInterval::get()),
156+
interval_income: config
157+
.interval_income
158+
.unwrap_or_else(|| T::IntervalIncome::get()),
159+
max_stakers_per_calculation: config
160+
.max_stakers_per_calculation
161+
.unwrap_or_else(|| MAX_NUMBER_PAYOUTS),
162+
}
163+
}
164+
}

pallets/common/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,6 +1518,9 @@ pub trait CommonWeightInfo<CrossAccountId> {
15181518

15191519
/// The price of retrieving token owner
15201520
fn token_owner() -> Weight;
1521+
1522+
/// The price of repairing an item.
1523+
fn repair_item() -> Weight;
15211524
}
15221525

15231526
/// Weight info extension trait for refungible pallet.
@@ -1825,6 +1828,9 @@ pub trait CommonCollectionOperations<T: Config> {
18251828

18261829
/// Get extension for RFT collection.
18271830
fn refungible_extensions(&self) -> Option<&dyn RefungibleExtensions<T>>;
1831+
1832+
/// Repairs a possibly broken item.
1833+
fn repair_item(&self, token: TokenId) -> DispatchResultWithPostInfo;
18281834
}
18291835

18301836
/// Extension for RFT collection.

0 commit comments

Comments
 (0)