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 Fungibles Runtime API - PLMC-606 #415

Merged
merged 1 commit into from
Oct 11, 2024
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
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ pallet-message-queue = { version = "38.0.0", default-features = false }
sp-weights = { version = "31.0.0", default-features = false }

# FRAME
assets-common = { version = "0.14.0", default-features = false }
pallet-aura = { version = "34.0.0", default-features = false }
pallet-balances = { version = "36.0.0", default-features = false }
pallet-assets = { version = "36.0.0", default-features = false }
Expand Down
3 changes: 3 additions & 0 deletions runtimes/polimec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ on-slash-vesting.workspace = true
pallet-proxy-bonding.workspace = true

# Substrate
assets-common.workspace = true
frame-benchmarking = { workspace = true, optional = true }
frame-executive.workspace = true
frame-support.workspace = true
Expand Down Expand Up @@ -117,6 +118,7 @@ default = [ "std" ]
fast-mode = [ "shared-configuration/fast-mode" ]
instant-mode = [ "shared-configuration/instant-mode" ]
std = [
"assets-common/std",
"cumulus-pallet-aura-ext/std",
"cumulus-pallet-parachain-system/std",
"cumulus-pallet-session-benchmarking/std",
Expand Down Expand Up @@ -194,6 +196,7 @@ std = [
]

runtime-benchmarks = [
"assets-common/runtime-benchmarks",
"cumulus-pallet-parachain-system/runtime-benchmarks",
"cumulus-pallet-session-benchmarking/runtime-benchmarks",
"cumulus-pallet-xcmp-queue/runtime-benchmarks",
Expand Down
91 changes: 0 additions & 91 deletions runtimes/polimec/src/custom_migrations/funding_holds.rs

This file was deleted.

4 changes: 1 addition & 3 deletions runtimes/polimec/src/custom_migrations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

// the generated files do not pass clippy
// The generated files do not pass clippy.
#![allow(clippy::all)]

pub mod funding_holds;
37 changes: 29 additions & 8 deletions runtimes/polimec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));

use assets_common::fungible_conversion::{convert, convert_balance};
use core::ops::RangeInclusive;
use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases;
use cumulus_primitives_core::{AggregateMessageOrigin, ParaId};
Expand Down Expand Up @@ -1131,14 +1132,6 @@ ord_parameter_types! {
pub const DispenserAdminAccount: AccountId = AccountId::from(hex_literal::hex!("d85a4f58eb7dba17bc436b16f394b242271237021f7880e1ccaf36cd9a616c99"));
}

// #[test]
// fn ensure_admin_account_is_correct() {
// use frame_support::traits::SortedMembers;
// use sp_core::crypto::Ss58Codec;
// let acc = AccountId::from_ss58check("5BAimacvMnhBEoc2g7PaiuEhJwmMZejq6j1ZMCpDZMHGAogz").unwrap();
// assert_eq!(acc, DispenserAdminAccount::sorted_members()[0]);
// }

impl pallet_dispenser::Config for Runtime {
type AdminOrigin = EnsureSignedBy<DispenserAdminAccount, AccountId>;
type BlockNumberToBalance = ConvertInto;
Expand Down Expand Up @@ -1308,6 +1301,34 @@ mod benches {
}

impl_runtime_apis! {
impl assets_common::runtime_api::FungiblesApi<Block,AccountId,> for Runtime{
fn query_account_balances(account: AccountId) -> Result<xcm::VersionedAssets, assets_common::runtime_api::FungiblesAccessError> {
Ok([
// collect pallet_balance
{
let balance = Balances::balance(&account);
if balance > 0 {
vec![convert_balance::<xcm_config::HereLocation, Balance>(balance)?]
} else {
vec![]
}
},
// collect pallet_assets (ContributionTokens)
convert::<_, _, _, _, xcm_config::ContributionTokensConvertedConcreteId>(
ContributionTokens::account_balances(account.clone())
.iter()
.filter(|(_, balance)| balance > &0)
)?,
// collect pallet_assets (ForeignAssets)
convert::<_, _, _, _, xcm_config::ForeignAssetsConvertedConcreteId>(
ForeignAssets::account_balances(account)
.iter()
.filter(|(_, balance)| balance > &0)
)?,
].concat().into())
}
}

impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
fn slot_duration() -> sp_consensus_aura::SlotDuration {
sp_consensus_aura::SlotDuration::from_millis(parachains_common::SLOT_DURATION)
Expand Down
23 changes: 19 additions & 4 deletions runtimes/polimec/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use super::{
AccountId, AllPalletsWithSystem, AssetId as AssetIdPalletAssets, Balance, Balances, EnsureRoot, ForeignAssets,
Funding, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin,
ToTreasury, TreasuryAccount, Vec, WeightToFee,
AccountId, AllPalletsWithSystem, AssetId as AssetIdPalletAssets, Balance, Balances, ContributionTokens, EnsureRoot,
ForeignAssets, Funding, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent,
RuntimeOrigin, ToTreasury, TreasuryAccount, Vec, WeightToFee,
};
use core::marker::PhantomData;
use cumulus_primitives_core::ParaId;
use frame_support::{
ensure, parameter_types,
ensure,
pallet_prelude::*,
parameter_types,
traits::{ConstU32, Contains, ContainsPair, Everything, Nothing, ProcessMessageError},
weights::Weight,
};
Expand Down Expand Up @@ -74,6 +76,11 @@ parameter_types! {
/// The check account that is allowed to mint assets locally. Used for PLMC teleport
/// checking once enabled.
pub LocalCheckAccount: (AccountId, MintLocation) = (CheckAccount::get(), MintLocation::Local);
pub ForeignAssetsPalletIndex: u8 = <ForeignAssets as PalletInfoAccess>::index() as u8;
pub ForeignAssetsPalletLocation: Location = PalletInstance(ForeignAssetsPalletIndex::get()).into();

pub ContributionTokensPalletIndex: u8 = <ContributionTokens as PalletInfoAccess>::index() as u8;
pub ContributionTokensPalletLocation: Location = PalletInstance(ContributionTokensPalletIndex::get()).into();

pub DotLocation: Location = RelayLocation::get();
pub UsdtLocation: Location = Location::new(1, [Parachain(1000), PalletInstance(50), GeneralIndex(1984)]);
Expand Down Expand Up @@ -109,6 +116,14 @@ pub type FungibleTransactor = FungibleAdapter<
LocalCheckAccount,
>;

/// `AssetId`/`Balance` converter for `ForeignAssets`.
pub type ForeignAssetsConvertedConcreteId =
assets_common::TrustBackedAssetsConvertedConcreteId<ForeignAssetsPalletLocation, Balance>;

/// `AssetId`/`Balance` converter for `ContributionTokens`.
pub type ContributionTokensConvertedConcreteId =
assets_common::TrustBackedAssetsConvertedConcreteId<ContributionTokensPalletLocation, Balance>;

// The `AssetIdPalletAssets` ids that are supported by this chain.
// Currently, we only support DOT (10), USDT (1984) and USDC (1337).
pub struct SupportedAssets;
Expand Down