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

dapp staking v3 - Oracle solution #1197

Merged
merged 28 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
806a3b4
Init commit
Dinonard Feb 29, 2024
e92ca10
Progress on the implementation
Dinonard Mar 6, 2024
5c87071
Merge remote-tracking branch 'origin/master' into feat/dapp-staking-v…
Dinonard Mar 7, 2024
c5171d0
More functionality
Dinonard Mar 7, 2024
b214af6
Price type updates, docs, functionality implementation
Dinonard Mar 7, 2024
8c29007
Tests, minor updates
Dinonard Mar 7, 2024
ea68a06
More test & some fixes
Dinonard Mar 7, 2024
5cd43e2
Tests & minor fixes
Dinonard Mar 8, 2024
49aab3c
Finished implementation
Dinonard Mar 8, 2024
bf41b25
Docs
Dinonard Mar 8, 2024
4b06736
Year change to make license check happy
Dinonard Mar 8, 2024
91edee9
Full integration - init version
Dinonard Mar 15, 2024
4593ebc
genesis
Dinonard Mar 15, 2024
7dded29
Move dummy combiner to primitives
Dinonard Mar 15, 2024
d4ef459
Changes
Dinonard Mar 15, 2024
de558a2
orml oracle benchmarks dummy pallet
Dinonard Mar 15, 2024
7a29817
Temporary benchmarks
Dinonard Mar 18, 2024
994ca0d
Comment
Dinonard Mar 18, 2024
1cbc702
Resolve TODOs
Dinonard Mar 18, 2024
fb7d0a5
Price aggregator weights
Dinonard Mar 18, 2024
3ff442a
Merge remote-tracking branch 'origin/master' into feat/dapp-staking-v…
Dinonard Mar 18, 2024
22c3f90
Post merge adjustments
Dinonard Mar 18, 2024
af84b55
Weights update
Dinonard Mar 18, 2024
08ecdd7
Integration tests
Dinonard Mar 18, 2024
3b1048c
Remove comment
Dinonard Mar 18, 2024
f793b81
Fix UT
Dinonard Mar 18, 2024
f4e7885
dApp staking v3 update
Dinonard Mar 20, 2024
d761f6e
Comments
Dinonard Mar 26, 2024
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
67 changes: 67 additions & 0 deletions Cargo.lock

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

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ pallet-scheduler = { git = "https://github.com/paritytech/polkadot-sdk", branch
pallet-treasury = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
pallet-grandpa = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
pallet-message-queue = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
pallet-membership = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }

# EVM & Ethereum
# (wasm)
Expand Down Expand Up @@ -266,6 +267,7 @@ polkadot-service = { git = "https://github.com/paritytech/polkadot-sdk", branch
orml-xtokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v1.1.0", default-features = false }
orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v1.1.0", default-features = false }
orml-xcm-support = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v1.1.0", default-features = false }
orml-oracle = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v1.1.0", default-features = false }

# Astar pallets & modules
# (wasm)
Expand All @@ -282,6 +284,10 @@ pallet-dynamic-evm-base-fee = { path = "./pallets/dynamic-evm-base-fee", default
pallet-unified-accounts = { path = "./pallets/unified-accounts", default-features = false }
astar-xcm-benchmarks = { path = "./pallets/astar-xcm-benchmarks", default-features = false }
pallet-static-price-provider = { path = "./pallets/static-price-provider", default-features = false }
pallet-price-aggregator = { path = "./pallets/price-aggregator", default-features = false }

# Get rid of this once orml-oracle has been updated with benchmarks
oracle-benchmarks = { path = "./pallets/oracle-benchmarks", default-features = false }

dapp-staking-v3-runtime-api = { path = "./pallets/dapp-staking-v3/rpc/runtime-api", default-features = false }

Expand Down
22 changes: 19 additions & 3 deletions bin/collator/src/parachain/chain_spec/shibuya.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ use sc_service::ChainType;
use shibuya_runtime::{
wasm_binary_unwrap, AccountId, AuraConfig, AuraId, Balance, BalancesConfig,
CollatorSelectionConfig, CouncilConfig, DappStakingConfig, DemocracyConfig, EVMChainIdConfig,
EVMConfig, InflationConfig, InflationParameters, ParachainInfoConfig, Precompiles,
RuntimeGenesisConfig, SessionConfig, SessionKeys, Signature, SudoConfig, SystemConfig,
TechnicalCommitteeConfig, TierThreshold, TreasuryConfig, VestingConfig, SBY,
EVMConfig, InflationConfig, InflationParameters, OracleMembershipConfig, ParachainInfoConfig,
Precompiles, PriceAggregatorConfig, RuntimeGenesisConfig, SessionConfig, SessionKeys,
Signature, SudoConfig, SystemConfig, TechnicalCommitteeConfig, TierThreshold, TreasuryConfig,
VestingConfig, SBY,
};
use sp_core::{sr25519, Pair, Public};

use astar_primitives::oracle::CurrencyAmount;
use sp_runtime::{
traits::{IdentifyAccount, Verify},
Permill,
Expand Down Expand Up @@ -206,6 +208,20 @@ fn make_genesis(
params: InflationParameters::default(),
..Default::default()
},
oracle_membership: OracleMembershipConfig {
members: vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
]
.try_into()
.expect("Assumption is that at least two members will be allowed."),
..Default::default()
},
price_aggregator: PriceAggregatorConfig {
circular_buffer: vec![CurrencyAmount::from_rational(5, 10)]
.try_into()
.expect("Must work since buffer should have at least a single value."),
},
}
}

Expand Down
6 changes: 3 additions & 3 deletions pallets/dapp-staking-v3/src/test/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use frame_support::{
traits::{fungible::Mutate as FunMutate, ConstU128, ConstU32},
weights::Weight,
};
use sp_arithmetic::fixed_point::FixedU64;
use sp_arithmetic::fixed_point::FixedU128;
use sp_core::H256;
use sp_io::TestExternalities;
use sp_runtime::{
Expand Down Expand Up @@ -106,8 +106,8 @@ impl pallet_balances::Config for Test {

pub struct DummyPriceProvider;
impl PriceProvider for DummyPriceProvider {
fn average_price() -> FixedU64 {
FixedU64::from_rational(1, 10)
fn average_price() -> FixedU128 {
FixedU128::from_rational(1, 10)
}
}

Expand Down
6 changes: 3 additions & 3 deletions pallets/dapp-staking-v3/src/test/tests_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use astar_primitives::{dapp_staking::StandardTierSlots, Balance};
use frame_support::assert_ok;
use sp_arithmetic::fixed_point::FixedU64;
use sp_arithmetic::fixed_point::FixedU128;
use sp_runtime::Permill;

use crate::*;
Expand Down Expand Up @@ -2887,11 +2887,11 @@ fn tier_configuration_basic_tests() {
assert!(init_config.is_valid(), "Init config must be valid!");

// Create a new config, based on a new price
let high_price = FixedU64::from_rational(20, 100); // in production will be expressed in USD
let high_price = FixedU128::from_rational(20, 100); // in production will be expressed in USD
let new_config = init_config.calculate_new(high_price, &params);
assert!(new_config.is_valid());

let low_price = FixedU64::from_rational(1, 100); // in production will be expressed in USD
let low_price = FixedU128::from_rational(1, 100); // in production will be expressed in USD
let new_config = init_config.calculate_new(low_price, &params);
assert!(new_config.is_valid());

Expand Down
8 changes: 4 additions & 4 deletions pallets/dapp-staking-v3/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
use frame_support::{pallet_prelude::*, BoundedBTreeMap, BoundedVec};
use parity_scale_codec::{Decode, Encode};
use serde::{Deserialize, Serialize};
use sp_arithmetic::fixed_point::FixedU64;
use sp_arithmetic::fixed_point::FixedU128;
use sp_runtime::{
traits::{CheckedAdd, UniqueSaturatedInto, Zero},
FixedPointNumber, Permill, Saturating,
Expand Down Expand Up @@ -1629,7 +1629,7 @@ impl<NT: Get<u32>, T: TierSlotsFunc> TiersConfiguration<NT, T> {
}

/// Calculate new `TiersConfiguration`, based on the old settings, current native currency price and tier configuration.
pub fn calculate_new(&self, native_price: FixedU64, params: &TierParameters<NT>) -> Self {
pub fn calculate_new(&self, native_price: FixedU128, params: &TierParameters<NT>) -> Self {
// It must always be at least 1 slot.
let new_number_of_slots = T::number_of_slots(native_price).max(1);

Expand Down Expand Up @@ -1671,7 +1671,7 @@ impl<NT: Get<u32>, T: TierSlotsFunc> TiersConfiguration<NT, T> {
// new_threshold = old_threshold * (1 + %_threshold)
//
let new_tier_thresholds = if new_number_of_slots > self.number_of_slots {
let delta_threshold_decrease = FixedU64::from_rational(
let delta_threshold_decrease = FixedU128::from_rational(
(new_number_of_slots - self.number_of_slots).into(),
new_number_of_slots.into(),
);
Expand All @@ -1693,7 +1693,7 @@ impl<NT: Get<u32>, T: TierSlotsFunc> TiersConfiguration<NT, T> {

new_tier_thresholds
} else if new_number_of_slots < self.number_of_slots {
let delta_threshold_increase = FixedU64::from_rational(
let delta_threshold_increase = FixedU128::from_rational(
(self.number_of_slots - new_number_of_slots).into(),
new_number_of_slots.into(),
);
Expand Down
52 changes: 52 additions & 0 deletions pallets/oracle-benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[package]
name = "oracle-benchmarks"
version = "0.1.0"
license = "GPL-3.0-or-later"
description = "Temporary pallet to benchmark orml-oracle. Should be handled by orml-oracle itself in the future."
authors.workspace = true
edition.workspace = true
homepage.workspace = true
repository.workspace = true

[dependencies]
log = { workspace = true }
parity-scale-codec = { workspace = true }
serde = { workspace = true }

frame-support = { workspace = true }
frame-system = { workspace = true }
scale-info = { workspace = true }
sp-arithmetic = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }

orml-oracle = { workspace = true }
orml-traits = { workspace = true }

astar-primitives = { workspace = true }

frame-benchmarking = { workspace = true, optional = true }

[features]
default = ["std"]
std = [
"parity-scale-codec/std",
"log/std",
"scale-info/std",
"serde/std",
"sp-std/std",
"frame-support/std",
"frame-system/std",
"astar-primitives/std",
"sp-arithmetic/std",
"orml-traits/std",
"orml-oracle/std",
]
runtime-benchmarks = [
"frame-benchmarking",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"astar-primitives/runtime-benchmarks",
]
try-runtime = ["frame-support/try-runtime"]
69 changes: 69 additions & 0 deletions pallets/oracle-benchmarks/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// This file is part of Astar.

// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later

// Astar is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Astar is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Astar. If not, see <http://www.gnu.org/licenses/>.

#![cfg(feature = "runtime-benchmarks")]

use super::*;
use frame_benchmarking::v2::*;
use frame_support::{
assert_ok,
traits::{Get, OnFinalize},
BoundedVec,
};
use frame_system::RawOrigin;
use sp_std::vec;

#[benchmarks]
mod benchmarks {
use super::*;

#[benchmark]
fn feed_values(x: Linear<1, { <T as orml_oracle::Config>::MaxFeedValues::get() }>) {
// Prepare account and add it as member
let account: T::AccountId = whitelisted_caller();
T::AddMember::add_member(account.clone());

// Get base feed value
let currency_id_price_pair = T::BenchmarkCurrencyIdValuePair::get();

// Prepare feed values vector
let mut key_value_pairs =
BoundedVec::<_, <T as orml_oracle::Config>::MaxFeedValues>::default();
for _ in 0..x {
key_value_pairs
.try_push(currency_id_price_pair.clone())
.unwrap();
}

#[block]
{
assert_ok!(orml_oracle::Pallet::<T>::feed_values(
RawOrigin::Signed(account.clone()).into(),
key_value_pairs
));
}
}

#[benchmark]
fn on_finalize() {
#[block]
{
orml_oracle::Pallet::<T>::on_finalize(1_u32.into());
}
}
}
Loading
Loading