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

add Primitive types #961

Merged
merged 22 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
206 changes: 105 additions & 101 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ members = [
"pallets/*",
"precompiles/*",

"primitives",

"chain-extensions/dapps-staking",
"chain-extensions/pallet-assets",
"chain-extensions/xvm",
Expand Down Expand Up @@ -272,7 +274,7 @@ pallet-xc-asset-config = { path = "./pallets/xc-asset-config", default-features
pallet-xvm = { path = "./pallets/pallet-xvm", default-features = false }
pallet-xcm = { path = "./pallets/pallet-xcm", default-features = false }

xcm-primitives = { path = "./primitives/xcm", default-features = false }
astar-primitives = { path = "./primitives", default-features = false }

pallet-evm-precompile-assets-erc20 = { path = "./precompiles/assets-erc20", default-features = false }
pallet-evm-precompile-sr25519 = { path = "./precompiles/sr25519", default-features = false }
Expand Down
2 changes: 2 additions & 0 deletions bin/collator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ shibuya-runtime = { workspace = true, features = ["std"] }
shiden-runtime = { workspace = true, features = ["std"] }

# astar pallets dependencies
astar-primitives = { workspace = true }
pallet-block-reward = { workspace = true }

# frame dependencies
Expand Down Expand Up @@ -161,6 +162,7 @@ runtime-benchmarks = [
"sp-keyring",
"cumulus-test-relay-sproof-builder",
"polkadot-runtime-common",
"astar-primitives/runtime-benchmarks",
]
cli = ["try-runtime-cli"]
try-runtime = ["local-runtime/try-runtime", "try-runtime-cli/try-runtime"]
Expand Down
2 changes: 1 addition & 1 deletion bin/collator/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// You should have received a copy of the GNU General Public License
// along with Astar. If not, see <http://www.gnu.org/licenses/>.

use crate::primitives::{AccountId, Balance, Block};
use astar_primitives::{AccountId, Balance, Block};
use cumulus_primitives_core::PersistedValidationData;
use cumulus_primitives_parachain_inherent::{ParachainInherentData, INHERENT_IDENTIFIER};
use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder;
Expand Down
2 changes: 1 addition & 1 deletion bin/collator/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ use crate::{
self, astar, chain_spec, service::AdditionalConfig, shibuya, shiden, start_astar_node,
start_shibuya_node, start_shiden_node,
},
primitives::Block,
};
use astar_primitives::*;
use cumulus_client_cli::generate_genesis_block;
use cumulus_primitives_core::ParaId;
use log::{error, info};
Expand Down
1 change: 0 additions & 1 deletion bin/collator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ mod benchmarking;
mod cli;
mod command;
mod evm_tracing_types;
mod primitives;
mod rpc;

pub use cli::*;
Expand Down
2 changes: 1 addition & 1 deletion bin/collator/src/local/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use std::{collections::BTreeMap, sync::Arc, time::Duration};

pub use local_runtime::RuntimeApi;

use crate::primitives::*;
use astar_primitives::*;

/// Local runtime native executor.
pub struct Executor;
Expand Down
2 changes: 1 addition & 1 deletion bin/collator/src/parachain/chain_spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use sc_chain_spec::ChainSpecExtension;
use serde::{Deserialize, Serialize};
use sp_core::{Pair, Public};

use crate::primitives::Block;
use astar_primitives::Block;

pub mod astar;
pub mod shibuya;
Expand Down
3 changes: 2 additions & 1 deletion bin/collator/src/parachain/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
// along with Astar. If not, see <http://www.gnu.org/licenses/>.

//! Parachain Service and ServiceFactory implementation.

use astar_primitives::*;
use cumulus_client_cli::CollatorOptions;
use cumulus_client_consensus_aura::{AuraConsensus, BuildAuraConsensusParams, SlotProportion};
use cumulus_client_consensus_common::{ParachainBlockImport, ParachainConsensus};
Expand Down Expand Up @@ -51,7 +53,6 @@ use super::shell_upgrade::*;
#[cfg(feature = "evm-tracing")]
use crate::evm_tracing_types::{EthApi as EthApiCmd, EvmTracingConfig};

use crate::primitives::*;
#[cfg(feature = "evm-tracing")]
use crate::rpc::tracing;

Expand Down
3 changes: 1 addition & 2 deletions bin/collator/src/parachain/shell_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

///! Special [`ParachainConsensus`] implementation that waits for the upgrade from
///! shell to a parachain runtime that implements Aura.
use astar_primitives::*;
use cumulus_client_consensus_common::{ParachainCandidate, ParachainConsensus};
use cumulus_primitives_core::relay_chain::{Hash as PHash, PersistedValidationData};
use futures::lock::Mutex;
Expand All @@ -28,8 +29,6 @@ use sp_consensus_aura::{sr25519::AuthorityId as AuraId, AuraApi};
use sp_runtime::traits::Header as HeaderT;
use std::sync::Arc;

use crate::primitives::*;

pub enum BuildOnAccess<R> {
Uninitialized(Option<Box<dyn FnOnce() -> R + Send + Sync>>),
Initialized(R),
Expand Down
40 changes: 0 additions & 40 deletions bin/collator/src/primitives.rs

This file was deleted.

2 changes: 1 addition & 1 deletion bin/collator/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ use moonbeam_rpc_trace::{Trace, TraceServer};
#[cfg(feature = "evm-tracing")]
use moonbeam_rpc_txpool::{TxPool, TxPoolServer};

use crate::primitives::*;
use astar_primitives::*;

#[cfg(feature = "evm-tracing")]
pub mod tracing;
Expand Down
5 changes: 1 addition & 4 deletions chain-extensions/dapps-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
// along with Astar. If not, see <http://www.gnu.org/licenses/>.

#![cfg_attr(not(feature = "std"), no_std)]
use sp_runtime::{
traits::{Saturating, Zero},
DispatchError,
};
use sp_runtime::{traits::Zero, DispatchError};

use dapps_staking_chain_extension_types::{
DSError, DappsStakingAccountInput, DappsStakingEraInput, DappsStakingNominationInput,
Expand Down
3 changes: 3 additions & 0 deletions pallets/block-reward/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ repository.workspace = true
parity-scale-codec = { workspace = true }
serde = { workspace = true }

astar-primitives = { workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
scale-info = { workspace = true }
Expand All @@ -38,11 +39,13 @@ std = [
"frame-system/std",
"pallet-timestamp/std",
"pallet-balances/std",
"astar-primitives/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"]
11 changes: 4 additions & 7 deletions pallets/block-reward/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@

pub use pallet::*;

use astar_primitives::Balance;
use frame_support::pallet_prelude::*;
use frame_support::{
log,
Expand Down Expand Up @@ -107,10 +108,6 @@ pub mod pallet {
#[pallet::pallet]
pub struct Pallet<T>(PhantomData<T>);

/// The balance type of this pallet.
pub(crate) type BalanceOf<T> =
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;

// Negative imbalance type of this pallet.
pub(crate) type NegativeImbalanceOf<T> = <<T as Config>::Currency as Currency<
<T as frame_system::Config>::AccountId,
Expand All @@ -119,17 +116,17 @@ pub mod pallet {
#[pallet::config]
pub trait Config: frame_system::Config {
/// The currency trait.
type Currency: Currency<Self::AccountId>;
type Currency: Currency<Self::AccountId, Balance = Balance>;

/// Provides information about how much value is locked by dapps staking
type DappsStakingTvlProvider: Get<BalanceOf<Self>>;
type DappsStakingTvlProvider: Get<Balance>;

/// Used to payout rewards
type BeneficiaryPayout: BeneficiaryPayout<NegativeImbalanceOf<Self>>;

/// The amount of issuance for each block.
#[pallet::constant]
type RewardAmount: Get<BalanceOf<Self>>;
type RewardAmount: Get<Balance>;

/// The overarching event type.
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
Expand Down
2 changes: 1 addition & 1 deletion pallets/block-reward/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use super::{pallet::Error, Event, *};
use frame_support::{assert_noop, assert_ok, traits::OnTimestampSet};
use mock::*;
use mock::{Balance, *};
shaunxw marked this conversation as resolved.
Show resolved Hide resolved
use sp_runtime::{
traits::{AccountIdConversion, BadOrigin, Zero},
Perbill,
Expand Down
3 changes: 3 additions & 0 deletions pallets/dapps-staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ frame-system = { workspace = true }
num-traits = { workspace = true }
parity-scale-codec = { workspace = true }

astar-primitives = { workspace = true }
scale-info = { workspace = true }
serde = { workspace = true, optional = true }
sp-arithmetic = { workspace = true }
Expand Down Expand Up @@ -48,11 +49,13 @@ std = [
"pallet-timestamp/std",
"sp-staking/std",
"frame-benchmarking?/std",
"astar-primitives/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"]
24 changes: 12 additions & 12 deletions pallets/dapps-staking/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::Pallet as DappsStaking;
use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller};
use frame_support::traits::{Get, OnFinalize, OnInitialize};
use frame_system::{Pallet as System, RawOrigin};
use sp_runtime::traits::{Bounded, One, TrailingZeroInput};
use sp_runtime::traits::{One, TrailingZeroInput};

const SEED: u32 = 9000;
const STAKER_BLOCK_REWARD: u32 = 1234u32;
Expand Down Expand Up @@ -94,7 +94,7 @@ fn register_contract<T: Config>(
) -> Result<(T::AccountId, T::SmartContract), &'static str> {
let developer: T::AccountId = account("developer", index.into(), SEED);
let smart_contract = smart_contract::<T>(index);
T::Currency::make_free_balance_be(&developer, BalanceOf::<T>::max_value());
T::Currency::make_free_balance_be(&developer, Balance::max_value());
DappsStaking::<T>::register(
RawOrigin::Root.into(),
developer.clone(),
Expand All @@ -119,7 +119,7 @@ fn prepare_bond_and_stake<T: Config>(
for id in 0..number_of_stakers {
let staker_acc: T::AccountId = account("pre_staker", id, seed);
stakers.push(staker_acc.clone());
T::Currency::make_free_balance_be(&staker_acc, BalanceOf::<T>::max_value());
T::Currency::make_free_balance_be(&staker_acc, Balance::max_value());

DappsStaking::<T>::bond_and_stake(
RawOrigin::Signed(staker_acc).into(),
Expand All @@ -137,7 +137,7 @@ benchmarks! {
initialize::<T>();
let developer_id = whitelisted_caller();
let contract_id = T::SmartContract::default();
T::Currency::make_free_balance_be(&developer_id, BalanceOf::<T>::max_value());
T::Currency::make_free_balance_be(&developer_id, Balance::max_value());
}: _(RawOrigin::Root, developer_id.clone(), contract_id.clone())
verify {
assert_last_event::<T>(Event::<T>::NewContract(developer_id, contract_id).into());
Expand All @@ -158,7 +158,7 @@ benchmarks! {
let (developer, contract_id) = register_contract::<T>(1)?;
let stakers = prepare_bond_and_stake::<T>(1, &contract_id, SEED)?;
let staker = stakers[0].clone();
let stake_amount = BalanceOf::<T>::max_value() / 2u32.into();
let stake_amount = Balance::max_value() / 2u128;

DappsStaking::<T>::bond_and_stake(RawOrigin::Signed(staker.clone()).into(), contract_id.clone(), stake_amount)?;
DappsStaking::<T>::unregister(RawOrigin::Root.into(), contract_id.clone())?;
Expand All @@ -174,8 +174,8 @@ benchmarks! {
let (_, contract_id) = register_contract::<T>(1)?;

let staker = whitelisted_caller();
let _ = T::Currency::make_free_balance_be(&staker, BalanceOf::<T>::max_value());
let amount = BalanceOf::<T>::max_value() / 2u32.into();
let _ = T::Currency::make_free_balance_be(&staker, Balance::max_value());
let amount = Balance::max_value() / 2u128;

}: _(RawOrigin::Signed(staker.clone()), contract_id.clone(), amount)
verify {
Expand All @@ -188,8 +188,8 @@ benchmarks! {
let (_, contract_id) = register_contract::<T>(1)?;

let staker = whitelisted_caller();
let _ = T::Currency::make_free_balance_be(&staker, BalanceOf::<T>::max_value());
let amount = BalanceOf::<T>::max_value() / 2u32.into();
let _ = T::Currency::make_free_balance_be(&staker, Balance::max_value());
let amount = Balance::max_value() / 2u128;

DappsStaking::<T>::bond_and_stake(RawOrigin::Signed(staker.clone()).into(), contract_id.clone(), amount)?;

Expand All @@ -204,9 +204,9 @@ benchmarks! {
let (_, contract_id) = register_contract::<T>(1)?;

let staker = whitelisted_caller();
let _ = T::Currency::make_free_balance_be(&staker, BalanceOf::<T>::max_value());
let stake_amount = BalanceOf::<T>::max_value() / 2u32.into();
let unstake_amount = stake_amount / 2u32.into();
let _ = T::Currency::make_free_balance_be(&staker, Balance::max_value());
let stake_amount = Balance::max_value() / 2u128;
let unstake_amount = stake_amount / 2u128;

DappsStaking::<T>::bond_and_stake(RawOrigin::Signed(staker.clone()).into(), contract_id.clone(), stake_amount)?;
DappsStaking::<T>::unbond_and_unstake(RawOrigin::Signed(staker.clone()).into(), contract_id, unstake_amount)?;
Expand Down
Loading