Skip to content

Commit

Permalink
Oracle Solution Integration - Astar&Shiden (#1231)
Browse files Browse the repository at this point in the history
* Oracle Solution Integration - Astar&Shiden

* Review comments
  • Loading branch information
Dinonard authored May 2, 2024
1 parent 19b60fa commit 9f5e4dd
Show file tree
Hide file tree
Showing 11 changed files with 238 additions and 53 deletions.
11 changes: 8 additions & 3 deletions Cargo.lock

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

19 changes: 17 additions & 2 deletions bin/collator/src/parachain/chain_spec/astar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@

//! Astar chain specifications.
use astar_primitives::oracle::CurrencyAmount;
use astar_runtime::{
wasm_binary_unwrap, AccountId, AuraId, Balance, DappStakingConfig, EVMConfig, InflationConfig,
InflationParameters, ParachainInfoConfig, Precompiles, Signature, SystemConfig, TierThreshold,
ASTR,
InflationParameters, OracleMembershipConfig, ParachainInfoConfig, Precompiles,
PriceAggregatorConfig, Signature, SystemConfig, TierThreshold, ASTR,
};
use cumulus_primitives_core::ParaId;
use sc_service::ChainType;
Expand Down Expand Up @@ -192,6 +193,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
19 changes: 17 additions & 2 deletions bin/collator/src/parachain/chain_spec/shiden.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ use cumulus_primitives_core::ParaId;
use sc_service::ChainType;
use shiden_runtime::{
wasm_binary_unwrap, AccountId, AuraId, Balance, DappStakingConfig, EVMConfig, InflationConfig,
InflationParameters, ParachainInfoConfig, Precompiles, Signature, SystemConfig, TierThreshold,
SDN,
InflationParameters, OracleMembershipConfig, ParachainInfoConfig, Precompiles,
PriceAggregatorConfig, Signature, SystemConfig, TierThreshold, SDN,
};
use sp_core::{sr25519, Pair, Public};

use astar_primitives::oracle::CurrencyAmount;
use sp_runtime::{
traits::{IdentifyAccount, Verify},
Permill,
Expand Down Expand Up @@ -191,6 +192,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
19 changes: 16 additions & 3 deletions runtime/astar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pallet-evm-precompile-modexp = { workspace = true }
pallet-evm-precompile-sha3fips = { workspace = true }
pallet-evm-precompile-simple = { workspace = true }
pallet-identity = { workspace = true }
pallet-membership = { workspace = true }
pallet-multisig = { workspace = true }
pallet-proxy = { workspace = true }
pallet-session = { workspace = true, features = ["historical"] }
Expand Down Expand Up @@ -88,6 +89,7 @@ xcm-builder = { workspace = true }
xcm-executor = { workspace = true }

# orml dependencies
orml-oracle = { workspace = true }
orml-xcm-support = { workspace = true }
orml-xtokens = { workspace = true }

Expand All @@ -112,10 +114,13 @@ pallet-evm-precompile-sr25519 = { workspace = true }
pallet-evm-precompile-substrate-ecdsa = { workspace = true }
pallet-evm-precompile-xcm = { workspace = true }
pallet-inflation = { workspace = true }
pallet-static-price-provider = { workspace = true }
pallet-price-aggregator = { workspace = true }
pallet-xc-asset-config = { workspace = true }
pallet-xcm = { workspace = true }

# Get rid of this after uplifting to high enough version of ORML so we get access to benchmark support for the pallet
oracle-benchmarks = { workspace = true }

dapp-staking-v3-runtime-api = { workspace = true }

# Moonbeam tracing
Expand All @@ -140,6 +145,10 @@ std = [
"sp-std/std",
"sp-api/std",
"sp-core/std",
"oracle-benchmarks/std",
"pallet-membership/std",
"pallet-price-aggregator/std",
"orml-oracle/std",
"sp-consensus-aura/std",
"sp-arithmetic/std",
"sp-io/std",
Expand All @@ -159,7 +168,6 @@ std = [
"pallet-aura/std",
"pallet-balances/std",
"pallet-proxy/std",
"pallet-static-price-provider/std",
"pallet-dapp-staking-v3/std",
"pallet-dapp-staking-migration/std",
"dapp-staking-v3-runtime-api/std",
Expand Down Expand Up @@ -233,7 +241,9 @@ runtime-benchmarks = [
"pallet-ethereum/runtime-benchmarks",
"pallet-dapp-staking-v3/runtime-benchmarks",
"pallet-dapp-staking-migration/runtime-benchmarks",
"pallet-price-aggregator/runtime-benchmarks",
"pallet-inflation/runtime-benchmarks",
"pallet-membership/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
"pallet-xc-asset-config/runtime-benchmarks",
Expand Down Expand Up @@ -263,10 +273,13 @@ try-runtime = [
"pallet-timestamp/try-runtime",
"pallet-transaction-payment/try-runtime",
"pallet-utility/try-runtime",
"pallet-static-price-provider/try-runtime",
"pallet-vesting/try-runtime",
"pallet-xc-asset-config/try-runtime",
"pallet-ethereum/try-runtime",
"orml-oracle/try-runtime",
"pallet-price-aggregator/try-runtime",
"pallet-membership/try-runtime",
"oracle-benchmarks/try-runtime",
"pallet-assets/try-runtime",
"pallet-authorship/try-runtime",
"pallet-collator-selection/try-runtime",
Expand Down
91 changes: 80 additions & 11 deletions runtime/astar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ use astar_primitives::{
PeriodNumber, SmartContract, StandardTierSlots, TierId,
},
evm::EvmRevertCodeHandler,
oracle::{CurrencyAmount, CurrencyId, DummyCombineData},
xcm::AssetLocationIdConverter,
Address, AssetId, BlockNumber, Hash, Header, Nonce,
};
Expand Down Expand Up @@ -327,10 +328,6 @@ parameter_types! {
pub const MinimumStakingAmount: Balance = 500 * ASTR;
}

impl pallet_static_price_provider::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
}

#[cfg(feature = "runtime-benchmarks")]
pub struct BenchmarkHelper<SC, ACC>(sp_std::marker::PhantomData<(SC, ACC)>);
#[cfg(feature = "runtime-benchmarks")]
Expand Down Expand Up @@ -365,7 +362,7 @@ impl pallet_dapp_staking_v3::Config for Runtime {
type Currency = Balances;
type SmartContract = SmartContract<AccountId>;
type ManagerOrigin = frame_system::EnsureRoot<AccountId>;
type NativePriceProvider = StaticPriceProvider;
type NativePriceProvider = PriceAggregator;
type StakingRewardHandler = Inflation;
type CycleConfiguration = InflationCycleConfig;
type Observers = Inflation;
Expand Down Expand Up @@ -1033,6 +1030,60 @@ impl pallet_proxy::Config for Runtime {
type AnnouncementDepositFactor = AnnouncementDepositFactor;
}

parameter_types! {
pub const NativeCurrencyId: CurrencyId = CurrencyId::ASTR;
// Aggregate values for one day.
pub const AggregationDuration: BlockNumber = 7200;
}

impl pallet_price_aggregator::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type MaxValuesPerBlock = ConstU32<8>;
type ProcessBlockValues = pallet_price_aggregator::MedianBlockValue;
type NativeCurrencyId = NativeCurrencyId;
// 7 days
type CircularBufferLength = ConstU32<7>;
type AggregationDuration = AggregationDuration;
type WeightInfo = pallet_price_aggregator::weights::SubstrateWeight<Runtime>;
}

parameter_types! {
// Cannot specify `Root` so need to do it like this, unfortunately.
pub RootOperatorAccountId: AccountId = AccountId::from([0xffu8; 32]);
}

impl orml_oracle::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type OnNewData = PriceAggregator;
type CombineData = DummyCombineData<Runtime>;
type Time = Timestamp;
type OracleKey = CurrencyId;
type OracleValue = CurrencyAmount;
type RootOperatorAccountId = RootOperatorAccountId;
type Members = OracleMembership;
type MaxHasDispatchedSize = ConstU32<8>;
type WeightInfo = oracle_benchmarks::weights::SubstrateWeight<Runtime>;
#[cfg(feature = "runtime-benchmarks")]
type MaxFeedValues = ConstU32<2>;
#[cfg(not(feature = "runtime-benchmarks"))]
type MaxFeedValues = ConstU32<1>;
}

pub type OracleMembershipInstance = pallet_membership::Instance1;
impl pallet_membership::Config<OracleMembershipInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type AddOrigin = EnsureRoot<AccountId>;
type RemoveOrigin = EnsureRoot<AccountId>;
type SwapOrigin = EnsureRoot<AccountId>;
type ResetOrigin = EnsureRoot<AccountId>;
type PrimeOrigin = EnsureRoot<AccountId>;

type MembershipInitialized = ();
type MembershipChanged = ();
type MaxMembers = ConstU32<16>;
type WeightInfo = pallet_membership::weights::SubstrateWeight<Runtime>;
}

construct_runtime!(
pub struct Runtime
{
Expand All @@ -1056,6 +1107,9 @@ construct_runtime!(
Inflation: pallet_inflation = 33,
DappStaking: pallet_dapp_staking_v3 = 34,
Assets: pallet_assets = 36,
PriceAggregator: pallet_price_aggregator = 37,
Oracle: orml_oracle = 38,
OracleMembership: pallet_membership::<Instance1> = 39,

Authorship: pallet_authorship = 40,
CollatorSelection: pallet_collator_selection = 41,
Expand All @@ -1077,9 +1131,6 @@ construct_runtime!(
Contracts: pallet_contracts = 70,

Sudo: pallet_sudo = 99,

// To be removed & cleaned up once proper oracle is implemented
StaticPriceProvider: pallet_static_price_provider = 253,
}
);

Expand Down Expand Up @@ -1118,20 +1169,38 @@ pub type Executive = frame_executive::Executive<
>;

parameter_types! {
pub const DappStakingMigrationName: &'static str = "DappStakingMigration";

pub const StaticPriceProviderName: &'static str = "StaticPriceProvider";
// 0.18 $
pub const InitPrice: CurrencyAmount = CurrencyAmount::from_rational(18, 100);
}

/// All migrations that will run on the next runtime upgrade.
///
/// Once done, migrations should be removed from the tuple.
pub type Migrations = (
frame_support::migrations::RemovePallet<
DappStakingMigrationName,
StaticPriceProviderName,
<Runtime as frame_system::Config>::DbWeight,
>,
OracleIntegrationLogic,
pallet_price_aggregator::PriceAggregatorInitializer<Runtime, InitPrice>,
);

use frame_support::traits::OnRuntimeUpgrade;
pub struct OracleIntegrationLogic;
impl OnRuntimeUpgrade for OracleIntegrationLogic {
fn on_runtime_upgrade() -> Weight {
// 1. Set initial storage versions for the membership pallet
use frame_support::traits::StorageVersion;
StorageVersion::new(4)
.put::<pallet_membership::Pallet<Runtime, OracleMembershipInstance>>();

// No storage version for the `orml_oracle` pallet, it's essentially 0

<Runtime as frame_system::Config>::DbWeight::get().writes(1)
}
}

type EventRecord = frame_system::EventRecord<
<Runtime as frame_system::Config>::RuntimeEvent,
<Runtime as frame_system::Config>::Hash,
Expand Down
3 changes: 0 additions & 3 deletions runtime/shibuya/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ pallet-evm-precompile-xcm = { workspace = true }
pallet-evm-precompile-xvm = { workspace = true }
pallet-inflation = { workspace = true }
pallet-price-aggregator = { workspace = true }
pallet-static-price-provider = { workspace = true }
pallet-unified-accounts = { workspace = true }
pallet-xc-asset-config = { workspace = true }
pallet-xcm = { workspace = true }
Expand Down Expand Up @@ -204,7 +203,6 @@ std = [
"orml-oracle/std",
"dapp-staking-v3-runtime-api/std",
"pallet-inflation/std",
"pallet-static-price-provider/std",
"pallet-price-aggregator/std",
"pallet-identity/std",
"pallet-multisig/std",
Expand Down Expand Up @@ -293,7 +291,6 @@ try-runtime = [
"pallet-balances/try-runtime",
"pallet-dapp-staking-v3/try-runtime",
"pallet-inflation/try-runtime",
"pallet-static-price-provider/try-runtime",
"pallet-sudo/try-runtime",
"pallet-timestamp/try-runtime",
"pallet-transaction-payment/try-runtime",
Expand Down
6 changes: 0 additions & 6 deletions runtime/shibuya/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,6 @@ impl pallet_preimage::Config for Runtime {
>;
}

impl pallet_static_price_provider::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
}

#[cfg(feature = "runtime-benchmarks")]
pub struct BenchmarkHelper<SC, ACC>(sp_std::marker::PhantomData<(SC, ACC)>);
#[cfg(feature = "runtime-benchmarks")]
Expand Down Expand Up @@ -1259,8 +1255,6 @@ construct_runtime!(

// Remove after benchmarks are available in orml_oracle
OracleBenchmarks: oracle_benchmarks = 251,
// To be removed & cleaned up once proper oracle is implemented
StaticPriceProvider: pallet_static_price_provider = 253,
}
);

Expand Down
Loading

0 comments on commit 9f5e4dd

Please sign in to comment.