Skip to content

Commit

Permalink
Merge pull request #783 from UniqueNetwork/release-v930034-1
Browse files Browse the repository at this point in the history
Release v930034 1
  • Loading branch information
kozyrevdev authored Dec 16, 2022
2 parents b30515b + fab5061 commit cde31d3
Show file tree
Hide file tree
Showing 59 changed files with 1,572 additions and 2,783 deletions.
5 changes: 5 additions & 0 deletions .docker/xcm-config/launch-config-xcm-quartz.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@
"id": "2000",
"chain": "karura-dev",
"balance": "1000000000000000000000",
"chainInitializer": [
"chainql",
"-e",
"(import '${spec}') {id+: '-local'}"
],
"nodes": [
{
"wsPort": 9946,
Expand Down
8 changes: 4 additions & 4 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ POLKADOT_MAINNET_BRANCH=release-v0.9.30
STATEMINT_BUILD_BRANCH=release-parachains-v9320
ACALA_BUILD_BRANCH=2.10.1
MOONBEAM_BUILD_BRANCH=runtime-1901
UNIQUE_MAINNET_BRANCH=v924013
UNIQUE_MAINNET_BRANCH=v930033-node-only-fix
UNIQUE_REPLICA_FROM=wss://eu-ws.unique.network:443

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

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

POLKADOT_LAUNCH_BRANCH=unique-network
3 changes: 3 additions & 0 deletions .github/workflows/ci-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ concurrency:
# List of a jobs included into Workflow.
jobs:

yarn-dev:
uses: ./.github/workflows/yarn-dev.yml

unit-test:
uses: ./.github/workflows/unit-test.yml

Expand Down
6 changes: 4 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions node/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ where
};
use uc_rpc::{UniqueApiServer, Unique};

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

#[cfg(not(feature = "unique-runtime"))]
Expand Down Expand Up @@ -236,7 +236,7 @@ where

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

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

#[cfg(not(feature = "unique-runtime"))]
Expand Down
11 changes: 11 additions & 0 deletions pallets/app-promotion/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Change Log

All notable changes to this project will be documented in this file.

<!-- bureaucrate goes here -->

## [0.1.1] - 2022-12-13

### Added

- The ability to configure pallet `app-promotion` via the `configuration` pallet.
13 changes: 7 additions & 6 deletions pallets/app-promotion/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ homepage = 'https://unique.network'
license = 'GPLv3'
name = 'pallet-app-promotion'
repository = 'https://github.com/UniqueNetwork/unique-chain'
version = '0.1.0'
version = '0.1.1'

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

up-data-structs ={ default-features = false, path = "../../primitives/data-structs" }
pallet-common ={ default-features = false, path = "../common" }
pallet-unique ={ default-features = false, path = "../unique" }
pallet-evm-contract-helpers ={ default-features = false, path = "../evm-contract-helpers" }
pallet-evm-migration ={ default-features = false, path = "../evm-migration" }
up-data-structs = { default-features = false, path = "../../primitives/data-structs" }
pallet-common = { default-features = false, path = "../common" }
pallet-configuration = { default-features = false, path = "../configuration" }
pallet-unique = { default-features = false, path = "../unique" }
pallet-evm-contract-helpers = { default-features = false, path = "../evm-contract-helpers" }
pallet-evm-migration = { default-features = false, path = "../evm-migration" }

# [dev-dependencies]

Expand Down
64 changes: 42 additions & 22 deletions pallets/app-promotion/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ pub mod pallet {
use frame_system::pallet_prelude::*;

#[pallet::config]
pub trait Config: frame_system::Config + pallet_evm::account::Config {
pub trait Config:
frame_system::Config + pallet_evm::account::Config + pallet_configuration::Config
{
/// Type to interact with the native token
type Currency: ExtendedLockableCurrency<Self::AccountId>
+ ReservableCurrency<Self::AccountId>;
Expand Down Expand Up @@ -253,11 +255,11 @@ pub mod pallet {
ValueQuery,
>;

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

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

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

// Сalculation of the number of the relay block
// in which it is necessary to accrue remuneration for the stake.
let recalc_block = (block_number / T::RecalculationInterval::get()
let recalc_block = (block_number / config.recalculation_interval
+ recalculate_after_interval)
* T::RecalculationInterval::get();
* config.recalculation_interval;

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

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

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

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

ensure!(
admin_id == Admin::<T>::get().ok_or(Error::<T>::AdminNotSet)?,
Error::<T>::NoPermission
);
let config = <PalletConfiguration<T>>::get();

let mut stakers_number = stakers_number.unwrap_or(DEFAULT_NUMBER_PAYOUTS);

ensure!(
stakers_number <= config.max_stakers_per_calculation && stakers_number != 0,
Error::<T>::NoPermission
);

// calculate the number of the current recalculation block,
// this is necessary in order to understand which stakers we should calculate interest
let current_recalc_block =
Self::get_current_recalc_block(T::RelayBlockNumberProvider::current_block_number());
let current_recalc_block = Self::get_current_recalc_block(
T::RelayBlockNumberProvider::current_block_number(),
&config,
);

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

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

NextCalculatedRecord::<T>::set(None);
PreviousCalculatedRecord::<T>::set(None);

{
let mut stakers_number = stakers_number.unwrap_or(20);
let last_id = RefCell::new(None);
let income_acc = RefCell::new(BalanceOf::<T>::default());
let amount_acc = RefCell::new(BalanceOf::<T>::default());
Expand Down Expand Up @@ -622,10 +635,6 @@ pub mod pallet {
(amount, next_recalc_block_for_stake),
)) = storage_iterator.next()
{
if stakers_number == 0 {
NextCalculatedRecord::<T>::set(Some((current_id, staked_block)));
break;
}
if last_id.borrow().as_ref() != Some(&current_id) {
flush_stake()?;
*last_id.borrow_mut() = Some(current_id.clone());
Expand All @@ -639,11 +648,18 @@ pub mod pallet {
next_recalc_block,
amount,
((current_recalc_block - next_recalc_block_for_stake)
/ T::RecalculationInterval::get())
.into() + 1,
/ config.recalculation_interval)
.into() + 1,
&mut *income_acc.borrow_mut(),
);
}

if stakers_number == 0 {
if storage_iterator.next().is_some() {
PreviousCalculatedRecord::<T>::set(Some((current_id, staked_block)));
}
break;
}
}
flush_stake()?;
}
Expand Down Expand Up @@ -802,15 +818,19 @@ impl<T: Config> Pallet<T> {
where
I: EncodeLike<BalanceOf<T>> + Balance,
{
let config = <PalletConfiguration<T>>::get();
let mut income = base;

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

income - base
}

fn get_current_recalc_block(current_relay_block: T::BlockNumber) -> T::BlockNumber {
(current_relay_block / T::RecalculationInterval::get()) * T::RecalculationInterval::get()
fn get_current_recalc_block(
current_relay_block: T::BlockNumber,
config: &PalletConfiguration<T>,
) -> T::BlockNumber {
(current_relay_block / config.recalculation_interval) * config.recalculation_interval
}

fn get_next_calculated_key() -> Option<Vec<u8>> {
Expand Down
36 changes: 35 additions & 1 deletion pallets/app-promotion/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ use frame_support::{traits::LockableCurrency, WeakBoundedVec, Parameter, dispatc
use pallet_balances::{BalanceLock, Config as BalancesConfig, Pallet as PalletBalances};
use pallet_common::CollectionHandle;

use sp_runtime::DispatchError;
use sp_runtime::{DispatchError, Perbill};
use up_data_structs::{CollectionId};
use sp_std::borrow::ToOwned;
use pallet_evm_contract_helpers::{Pallet as EvmHelpersPallet, Config as EvmHelpersConfig};
use pallet_configuration::{AppPromomotionConfigurationOverride};
use sp_core::Get;

const MAX_NUMBER_PAYOUTS: u8 = 100;
pub(crate) const DEFAULT_NUMBER_PAYOUTS: u8 = 20;

/// This trait was defined because `LockableCurrency`
/// has no way to know the state of the lock for an account.
Expand Down Expand Up @@ -128,3 +133,32 @@ impl<T: EvmHelpersConfig> ContractHandler for EvmHelpersPallet<T> {
Ok(Self::get_sponsor(contract_address))
}
}
pub(crate) struct PalletConfiguration<T: crate::Config> {
/// In relay blocks.
pub recalculation_interval: T::BlockNumber,
/// In parachain blocks.
pub pending_interval: T::BlockNumber,
/// Value for `RecalculationInterval` based on 0.05% per 24h.
pub interval_income: Perbill,
/// Maximum allowable number of stakers calculated per call of the `app-promotion::PayoutStakers` extrinsic.
pub max_stakers_per_calculation: u8,
}
impl<T: crate::Config> PalletConfiguration<T> {
pub fn get() -> Self {
let config = <AppPromomotionConfigurationOverride<T>>::get();
Self {
recalculation_interval: config
.recalculation_interval
.unwrap_or_else(|| T::RecalculationInterval::get()),
pending_interval: config
.pending_interval
.unwrap_or_else(|| T::PendingInterval::get()),
interval_income: config
.interval_income
.unwrap_or_else(|| T::IntervalIncome::get()),
max_stakers_per_calculation: config
.max_stakers_per_calculation
.unwrap_or_else(|| MAX_NUMBER_PAYOUTS),
}
}
}
6 changes: 6 additions & 0 deletions pallets/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1518,6 +1518,9 @@ pub trait CommonWeightInfo<CrossAccountId> {

/// The price of retrieving token owner
fn token_owner() -> Weight;

/// The price of repairing an item.
fn repair_item() -> Weight;
}

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

/// Get extension for RFT collection.
fn refungible_extensions(&self) -> Option<&dyn RefungibleExtensions<T>>;

/// Repairs a possibly broken item.
fn repair_item(&self, token: TokenId) -> DispatchResultWithPostInfo;
}

/// Extension for RFT collection.
Expand Down
6 changes: 6 additions & 0 deletions pallets/configuration/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<!-- bureaucrate goes here -->
## [0.1.2] - 2022-12-13

### Added

- The ability to configure pallet `app-promotion` via the `configuration` pallet.

## [v0.1.1] 2022-08-16

### Other changes
Expand Down
Loading

0 comments on commit cde31d3

Please sign in to comment.