Skip to content
This repository was archived by the owner on May 21, 2024. It is now read-only.
Open
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
1,384 changes: 217 additions & 1,167 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ pallet-utility = { version = "25.0.0", default-features = false }
pallet-treasury = { version = "24.0.0", default-features = false }
pallet-safe-mode = { version = "6.0.0", default-features = false }
pallet-tx-pause = { version = "6.0.0", default-features = false }
pallet-asset-conversion = { version = "7.0.0", default-features = false }

# Cumulus client dependencies
cumulus-client-cli = "0.4.0"
Expand Down
4 changes: 3 additions & 1 deletion node/src/chain_spec/stout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ use sc_service::ChainType;
use sp_core::sr25519;
use stout_runtime::{
constants::currency::EXISTENTIAL_DEPOSIT, AccountId, AssetsConfig, AuraId, BalancesConfig,
CouncilConfig, RuntimeGenesisConfig, SessionConfig, SessionKeys, SudoConfig, SystemConfig,
CouncilConfig, PoolAssetsConfig, RuntimeGenesisConfig, SessionConfig, SessionKeys, SudoConfig,
SystemConfig,
};

const DEFAULT_PROTOCOL_ID: &str = "stout";
Expand Down Expand Up @@ -156,5 +157,6 @@ pub fn testnet_genesis(
members: invulnerables.into_iter().map(|x| x.0).collect::<Vec<_>>(),
phantom: Default::default(),
},
pool_assets: PoolAssetsConfig { assets: vec![], accounts: vec![], metadata: vec![] },
}
}
5 changes: 4 additions & 1 deletion node/src/chain_spec/trappist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ use sc_service::ChainType;
use sp_core::{crypto::UncheckedInto, sr25519};
use trappist_runtime::{
constants::currency::EXISTENTIAL_DEPOSIT, AccountId, AssetsConfig, AuraId, BalancesConfig,
CouncilConfig, RuntimeGenesisConfig, SessionConfig, SessionKeys, SudoConfig, SystemConfig,
CouncilConfig, PoolAssetsConfig, RuntimeGenesisConfig, SessionConfig, SessionKeys, SudoConfig,
SystemConfig,
};

const DEFAULT_PROTOCOL_ID: &str = "hop";
Expand Down Expand Up @@ -214,6 +215,7 @@ pub fn testnet_genesis(
treasury: Default::default(),
safe_mode: Default::default(),
tx_pause: Default::default(),
pool_assets: PoolAssetsConfig { assets: vec![], accounts: vec![], metadata: vec![] },
transaction_payment: Default::default(),
}
}
Expand Down Expand Up @@ -331,6 +333,7 @@ fn trappist_live_genesis(
treasury: Default::default(),
safe_mode: Default::default(),
tx_pause: Default::default(),
pool_assets: PoolAssetsConfig { assets: vec![], accounts: vec![], metadata: vec![] },
transaction_payment: Default::default(),
}
}
6 changes: 6 additions & 0 deletions runtime/stout/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ frame-system-benchmarking = { workspace = true, optional = true }
frame-system-rpc-runtime-api = { workspace = true }

## Substrate Pallet Dependencies
pallet-asset-conversion = { workspace = true }
pallet-assets = { workspace = true }
pallet-asset-tx-payment = { workspace = true }
pallet-aura = { workspace = true }
Expand All @@ -68,6 +69,7 @@ pallet-uniques = { workspace = true }
pallet-utility = { workspace = true }

# Cumulus dependencies
assets-common = { workspace = true }
cumulus-pallet-aura-ext = { workspace = true }
cumulus-pallet-dmp-queue = { workspace = true }
cumulus-pallet-parachain-system = { workspace = true }
Expand Down Expand Up @@ -121,6 +123,7 @@ std = [
"frame-system-rpc-runtime-api/std",
"frame-system-benchmarking?/std",
"pallet-assets/std",
"pallet-asset-conversion/std",
"pallet-asset-tx-payment/std",
"pallet-aura/std",
"pallet-authorship/std",
Expand All @@ -141,6 +144,7 @@ std = [
"pallet-uniques/std",
"pallet-utility/std",
"pallet-xcm/std",
"assets-common/std",
"cumulus-pallet-aura-ext/std",
"cumulus-pallet-parachain-system/std",
"cumulus-pallet-xcm/std",
Expand All @@ -166,6 +170,7 @@ runtime-benchmarks = [
"frame-system-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-asset-conversion/runtime-benchmarks",
"pallet-assets/runtime-benchmarks",
"pallet-asset-registry/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
Expand All @@ -182,6 +187,7 @@ runtime-benchmarks = [
"cumulus-pallet-session-benchmarking/runtime-benchmarks",
"cumulus-pallet-xcmp-queue/runtime-benchmarks",
"cumulus-pallet-parachain-system/runtime-benchmarks",
"assets-common/runtime-benchmarks",
]
parameterized-consensus-hook = [
"cumulus-pallet-parachain-system/parameterized-consensus-hook",
Expand Down
152 changes: 122 additions & 30 deletions runtime/stout/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,28 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![recursion_limit = "256"]

// Make the WASM binary available.
#[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));

pub mod constants;
mod contracts;
pub mod xcm_config;
#[cfg(feature = "runtime-benchmarks")]
#[macro_use]
extern crate frame_benchmarking;

use common::AssetIdForTrustBackedAssets;
use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases;
use sp_api::impl_runtime_apis;
use sp_core::{crypto::KeyTypeId, ConstBool, ConstU8, OpaqueMetadata};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, ConvertInto},
traits::{AccountIdConversion, AccountIdLookup, BlakeTwo256, Block as BlockT, ConvertInto},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, Perbill,
ApplyExtrinsicResult, Perbill, Permill,
};

use constants::{currency::*, fee::WeightToFee};
use frame_support::instances::{Instance1, Instance2};
use frame_support::traits::fungibles::{Balanced, Credit};
use frame_support::{
construct_runtime,
dispatch::DispatchClass,
parameter_types,
ord_parameter_types, parameter_types,
traits::{
AsEnsureOriginWithArg, ConstU128, ConstU16, ConstU32, ConstU64, EitherOfDiverse,
EqualPrivilegeOnly, Everything,
Expand All @@ -52,34 +50,39 @@ use frame_support::{
},
PalletId,
};
pub use frame_system::Call as SystemCall;
use frame_system::{
limits::{BlockLength, BlockWeights},
EnsureRoot, EnsureSigned,
EnsureRoot, EnsureSigned, EnsureSignedBy,
};

use pallet_asset_conversion::{NativeOrAssetId, NativeOrAssetIdConverter};
use pallet_asset_tx_payment::HandleCredit;
use pallet_identity::simple::IdentityInfo;
use pallet_xcm::{EnsureXcm, IsMajorityOfBody};
pub use parachains_common as common;
pub use parachains_common::{
impls::{AssetsToBlockAuthor, DealWithFees},
opaque, AccountId, AuraId, Balance, BlockNumber, Hash, Header, Signature,
AVERAGE_ON_INITIALIZE_RATIO, HOURS, MAXIMUM_BLOCK_WEIGHT, MINUTES, NORMAL_DISPATCH_RATIO,
SLOT_DURATION,
};
pub use polkadot_runtime_common::BlockHashCount;
use polkadot_runtime_common::SlowAdjustingFeeUpdate;
use sp_std::prelude::*;
#[cfg(feature = "std")]
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;
use xcm::latest::prelude::BodyId;

use xcm_config::{CollatorSelectionUpdateOrigin, RelayLocation};

pub use frame_system::Call as SystemCall;
use pallet_identity::simple::IdentityInfo;
#[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage;
// Make the WASM binary available.
#[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));

// Polkadot imports
use pallet_xcm::{EnsureXcm, IsMajorityOfBody};
pub use polkadot_runtime_common::BlockHashCount;
use polkadot_runtime_common::SlowAdjustingFeeUpdate;
use xcm::latest::prelude::BodyId;
pub mod constants;
mod contracts;
pub mod xcm_config;

pub const MICROUNIT: Balance = 1_000_000;

Expand Down Expand Up @@ -249,12 +252,24 @@ impl pallet_transaction_payment::Config for Runtime {
type FeeMultiplierUpdate = SlowAdjustingFeeUpdate<Self>;
}

/// A `HandleCredit` implementation that naively transfers the fees to the block author.
/// Will drop and burn the assets in case the transfer fails.
pub struct CreditToBlockAuthor;
impl HandleCredit<AccountId, Assets> for CreditToBlockAuthor {
fn handle_credit(credit: Credit<AccountId, Assets>) {
if let Some(author) = pallet_authorship::Pallet::<Runtime>::author() {
// Drop the result which will trigger the `OnDrop` of the imbalance in case of error.
let _ = Assets::resolve(&author, credit);
}
}
}

impl pallet_asset_tx_payment::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Fungibles = Assets;
type OnChargeAssetTransaction = pallet_asset_tx_payment::FungiblesAdapter<
pallet_assets::BalanceToAssetBalance<Balances, Runtime, ConvertInto>,
AssetsToBlockAuthor<Runtime, ()>,
pallet_assets::BalanceToAssetBalance<Balances, Runtime, ConvertInto, Instance1>,
CreditToBlockAuthor,
>;
}

Expand Down Expand Up @@ -387,12 +402,12 @@ pub type AssetsForceOrigin =

pub type AssetBalance = Balance;

impl pallet_assets::Config for Runtime {
impl pallet_assets::Config<Instance1> for Runtime {
type RuntimeEvent = RuntimeEvent;
type Balance = AssetBalance;
type RemoveItemsLimit = ConstU32<1000>;
type AssetId = AssetIdForTrustBackedAssets;
type AssetIdParameter = parity_scale_codec::Compact<u32>;
type AssetIdParameter = parity_scale_codec::Compact<AssetIdForTrustBackedAssets>;
type Currency = Balances;
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<AccountId>>;
type ForceOrigin = AssetsForceOrigin;
Expand All @@ -410,6 +425,33 @@ impl pallet_assets::Config for Runtime {
type BenchmarkHelper = ();
}

ord_parameter_types! {
pub const AssetConversionOrigin: AccountId = AccountIdConversion::<AccountId>::into_account_truncating(&AssetConversionPalletId::get());
}

impl pallet_assets::Config<Instance2> for Runtime {
type RuntimeEvent = RuntimeEvent;
type Balance = AssetBalance;
type RemoveItemsLimit = ConstU32<1000>;
type AssetId = AssetIdForTrustBackedAssets;
type AssetIdParameter = parity_scale_codec::Compact<AssetIdForTrustBackedAssets>;
type Currency = Balances;
type CreateOrigin = AsEnsureOriginWithArg<EnsureSignedBy<AssetConversionOrigin, AccountId>>;
type ForceOrigin = AssetsForceOrigin;
type AssetDeposit = ConstU128<{ UNITS }>;
type AssetAccountDeposit = ConstU128<{ UNITS }>;
type MetadataDepositBase = ConstU128<{ UNITS }>;
type MetadataDepositPerByte = ConstU128<{ 10 * CENTS }>;
type ApprovalDeposit = ConstU128<{ 10 * CENTS }>;
type StringLimit = ConstU32<50>;
type Freezer = ();
type Extra = ();
type CallbackHandle = ();
type WeightInfo = pallet_assets::weights::SubstrateWeight<Runtime>;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
}

parameter_types! {
pub MaxProposalWeight: Weight = Perbill::from_percent(50) * RuntimeBlockWeights::get().max_block;
}
Expand Down Expand Up @@ -548,6 +590,45 @@ impl pallet_asset_registry::Config for Runtime {
type BenchmarkHelper = AssetRegistryBenchmarkHelper;
}

parameter_types! {
pub const AssetDeposit: Balance = UNITS;
pub const AssetAccountDeposit: Balance = deposit(1, 16);
pub const ApprovalDeposit: Balance = EXISTENTIAL_DEPOSIT;
pub const AssetsStringLimit: u32 = 50;
pub const MetadataDepositBase: Balance = deposit(1, 68);
pub const MetadataDepositPerByte: Balance = deposit(0, 1);
pub const AssetConversionPalletId: PalletId = PalletId(*b"py/ascon");
pub AllowMultiAssetPools: bool = true;
pub const PoolSetupFee: Balance = EXISTENTIAL_DEPOSIT; // should be more or equal to the existential deposit
pub const MintMinLiquidity: Balance = 100; // 100 is good enough when the main currency has 10-12 decimals.
pub const LiquidityWithdrawalFee: Permill = Permill::from_percent(0); // should be non-zero if AllowMultiAssetPools is true, otherwise can be zero.
}

impl pallet_asset_conversion::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type AssetBalance = Balance;
type HigherPrecisionBalance = u128;
type Assets = Assets;
type Balance = Balance;
type PoolAssets = PoolAssets;
type AssetId = <Self as pallet_assets::Config<Instance1>>::AssetId;
type MultiAssetId = NativeOrAssetId<u32>;
type PoolAssetId = <Self as pallet_assets::Config<Instance2>>::AssetId;
type PalletId = AssetConversionPalletId;
type LPFee = ConstU32<3>; // means 0.3%
type PoolSetupFee = PoolSetupFee;
type PoolSetupFeeReceiver = AssetConversionOrigin;
type LiquidityWithdrawalFee = LiquidityWithdrawalFee;
type WeightInfo = pallet_asset_conversion::weights::SubstrateWeight<Runtime>;
type AllowMultiAssetPools = AllowMultiAssetPools;
type MaxSwapPathLength = ConstU32<4>;
type MintMinLiquidity = MintMinLiquidity;
type MultiAssetIdConverter = NativeOrAssetIdConverter<u32>;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
}

// Create the runtime by composing the FRAME pallets that were previously configured.
construct_runtime!(
pub struct Runtime {
Expand Down Expand Up @@ -582,23 +663,22 @@ construct_runtime!(
Sudo: pallet_sudo = 40,
Contracts: pallet_contracts = 41,
Council: pallet_collective::<Instance1> = 42,
Assets: pallet_assets = 43,
Assets: pallet_assets::<Instance1> = 43,
Identity: pallet_identity = 44,
Uniques: pallet_uniques = 45,
Scheduler: pallet_scheduler = 46,
Utility: pallet_utility = 47,
Preimage: pallet_preimage = 48,
Multisig: pallet_multisig = 49,
// 50 was the old pallet-dex
AssetConversion: pallet_asset_conversion = 51,

Spambot: cumulus_ping::{Pallet, Call, Storage, Event<T>} = 99,
AssetRegistry: pallet_asset_registry::{Pallet, Call, Storage, Event<T>} = 111,
PoolAssets: pallet_assets::<Instance2> = 112,
}
);

#[cfg(feature = "runtime-benchmarks")]
#[macro_use]
extern crate frame_benchmarking;

#[cfg(feature = "runtime-benchmarks")]
mod benches {
define_benchmarks!(
Expand All @@ -610,6 +690,7 @@ mod benches {
[pallet_contracts, Contracts]
[pallet_collective, Council]
[pallet_assets, Assets]
[pallet_asset_conversion, AssetConversion]
[pallet_identity, Identity]
[pallet_multisig, Multisig]
[pallet_uniques, Uniques]
Expand Down Expand Up @@ -744,6 +825,17 @@ impl_runtime_apis! {
}
}

impl pallet_asset_conversion::AssetConversionApi<Block, Balance, u128, NativeOrAssetId<u32>> for Runtime {
fn quote_price_exact_tokens_for_tokens(asset1: NativeOrAssetId<u32>, asset2: NativeOrAssetId<u32>, amount: u128, include_fee: bool) -> Option<Balance> {
AssetConversion::quote_price_exact_tokens_for_tokens(asset1, asset2, amount, include_fee)
}
fn quote_price_tokens_for_exact_tokens(asset1: NativeOrAssetId<u32>, asset2: NativeOrAssetId<u32>, amount: u128, include_fee: bool) -> Option<Balance> {
AssetConversion::quote_price_tokens_for_exact_tokens(asset1, asset2, amount, include_fee)
}
fn get_reserves(asset1: NativeOrAssetId<u32>, asset2: NativeOrAssetId<u32>) -> Option<(Balance, Balance)> {
AssetConversion::get_reserves(&asset1, &asset2).ok()
}
}

impl pallet_contracts::ContractsApi<Block, AccountId, Balance, BlockNumber, Hash, EventRecord> for Runtime {
fn call(
Expand Down
Loading