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

Pangolin ahUSDT #1236

Merged
merged 22 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from 13 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
72 changes: 72 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 @@ -50,6 +50,7 @@ parachain-info = { git = "https://github.com/paritytech/c
# darwinia
crab-runtime = { path = "runtime/crab" }
darwinia-account-migration = { path = "pallet/account-migration", default-features = false }
darwinia-asset-limit = { path = "pallet/asset-limit", default-features = false}
darwinia-common-runtime = { path = "runtime/common", default-features = false }
darwinia-deposit = { path = "pallet/deposit", default-features = false }
darwinia-ecdsa-authority = { path = "pallet/ecdsa-authority", default-features = false }
Expand Down Expand Up @@ -108,10 +109,15 @@ moonbeam-primitives-ext = { git = "https://github.com/darwinia-network/moo
moonbeam-rpc-debug = { git = "https://github.com/darwinia-network/moonbeam", branch = "polkadot-v0.9.43" }
moonbeam-rpc-primitives-debug = { git = "https://github.com/darwinia-network/moonbeam", branch = "polkadot-v0.9.43", default-features = false }
moonbeam-rpc-trace = { git = "https://github.com/darwinia-network/moonbeam", branch = "polkadot-v0.9.43" }
pallet-asset-manager = { git = "https://github.com/darwinia-network/moonbeam", branch = "polkadot-v0.9.43", default-features = false }
pallet-ethereum-xcm = { git = "https://github.com/darwinia-network/moonbeam", branch = "polkadot-v0.9.43", default-features = false }
precompile-utils = { git = "https://github.com/darwinia-network/moonbeam", branch = "polkadot-v0.9.43", default-features = false }
xcm-primitives = { git = "https://github.com/darwinia-network/moonbeam", branch = "polkadot-v0.9.43", default-features = false }

# open-web3-stack
orml-xcm-support = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v0.9.43", default-features = false }
orml-xtokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v0.9.43", default-features = false }

# polkadot
pallet-xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.43", default-features = false }
polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.43" }
Expand Down
41 changes: 41 additions & 0 deletions pallet/asset-limit/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[package]
authors.workspace = true
description = "Darwinia asset limit implementation."
edition.workspace = true
name = "darwinia-asset-limit"
readme = "README.md"
version.workspace = true

[dependencies]
# crates.io
codec = { workspace = true, package = "parity-scale-codec" }
scale-info = { workspace = true }

# moonbeam
pallet-asset-manager = { workspace = true }

# substrate
frame-support = { workspace = true }
frame-system = { workspace = true }

[features]
default = ["std"]

std = [
# crates.io
"codec/std",
"scale-info/std",
# moonbeam
"pallet-asset-manager/std",
# substrate
"frame-support/std",
"frame-system/std",
]

try-runtime = [
# moonbeam
"pallet-asset-manager/try-runtime",
# substrate
"frame-support/try-runtime",
"frame-system/try-runtime",
]
92 changes: 92 additions & 0 deletions pallet/asset-limit/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// This file is part of Darwinia.
//
// Copyright (C) 2018-2023 Darwinia Network
// SPDX-License-Identifier: GPL-3.0
//
// Darwinia 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.
//
// Darwinia 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 Darwinia. If not, see <https://www.gnu.org/licenses/>.

//! # Darwinia asset limit pallet
//! Please note that this pallet is only for foreign assets.
//! This pallet only stores the asset limit and does not actually prevent asset deposits.
//! Currently, we use the app to limit excessive amounts of deposits.

#![cfg_attr(not(feature = "std"), no_std)]
#![deny(missing_docs)]
#![deny(unused_crate_dependencies)]

pub use pallet::*;

#[frame_support::pallet]
pub mod pallet {
// substrate
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;

#[pallet::pallet]
#[pallet::without_storage_info]
pub struct Pallet<T>(PhantomData<T>);

#[pallet::config]
pub trait Config: frame_system::Config + pallet_asset_manager::Config {
/// Override the [`frame_system::Config::RuntimeEvent`].
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;

/// Origin that is allowed to create and modify asset information for local assets
type LimitModifierOrigin: EnsureOrigin<Self::RuntimeOrigin>;
jiguantong marked this conversation as resolved.
Show resolved Hide resolved
}

#[allow(missing_docs)]
aurexav marked this conversation as resolved.
Show resolved Hide resolved
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// New limit is set or old limit is updated.
AssetLimitChanged { asset_location: T::ForeignAssetType, units_limit: u128 },
jiguantong marked this conversation as resolved.
Show resolved Hide resolved
}

#[allow(missing_docs)]
aurexav marked this conversation as resolved.
Show resolved Hide resolved
#[pallet::error]
pub enum Error<T> {
AssetDoesNotExist,
boundless-forest marked this conversation as resolved.
Show resolved Hide resolved
}

/// Stores the asset limit for foreign assets.
#[pallet::storage]
#[pallet::getter(fn foreign_asset_limit)]
pub type ForeignAssetLimit<T: Config> =
StorageMap<_, Blake2_128Concat, T::ForeignAssetType, u128>;
jiguantong marked this conversation as resolved.
Show resolved Hide resolved

#[pallet::call]
impl<T: Config> Pallet<T> {
/// Change the asset limit for a given asset location.
jiguantong marked this conversation as resolved.
Show resolved Hide resolved
#[pallet::call_index(0)]
#[pallet::weight(T::DbWeight::get().reads_writes(1, 1))]
pub fn set_foreign_asset_limit(
origin: OriginFor<T>,
asset_location: T::ForeignAssetType,
jiguantong marked this conversation as resolved.
Show resolved Hide resolved
units_limit: u128,
) -> DispatchResult {
T::LimitModifierOrigin::ensure_origin(origin)?;
jiguantong marked this conversation as resolved.
Show resolved Hide resolved

ensure!(
pallet_asset_manager::AssetTypeId::<T>::get(&asset_location).is_some(),
Error::<T>::AssetDoesNotExist
);

ForeignAssetLimit::<T>::insert(&asset_location, &units_limit);

Self::deposit_event(Event::AssetLimitChanged { asset_location, units_limit });
Ok(())
}
}
}
7 changes: 5 additions & 2 deletions runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ version.workspace = true

[dependencies]
# crates.io
codec = { workspace = true, package = "parity-scale-codec" }
smallvec = { version = "1.10" }
codec = { workspace = true, package = "parity-scale-codec" }
scale-info = { workspace = true }
smallvec = { version = "1.10" }


# darwinia
darwinia-precompile-assets = { workspace = true }
Expand Down Expand Up @@ -44,6 +46,7 @@ default = ["std"]
std = [
# crates.io
"codec/std",
"scale-info/std",

# darwinia
"darwinia-precompile-assets/std",
Expand Down
60 changes: 60 additions & 0 deletions runtime/common/src/xcm_configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,63 @@ impl<
OnUnbalanced::on_unbalanced(Currency::issue(self.1));
}
}

use frame_support::pallet_prelude::*;
use sp_std::prelude::*;
#[derive(Clone, Default, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)]
pub struct AssetRegistrarMetadata {
pub name: Vec<u8>,
pub symbol: Vec<u8>,
pub decimals: u8,
pub is_frozen: bool,
}

// Our AssetType. For now we only handle Xcm Assets
#[derive(Clone, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)]
pub enum AssetType {
Xcm(MultiLocation),
}
jiguantong marked this conversation as resolved.
Show resolved Hide resolved
impl Default for AssetType {
fn default() -> Self {
Self::Xcm(MultiLocation::here())
}
}

impl From<MultiLocation> for AssetType {
fn from(location: MultiLocation) -> Self {
Self::Xcm(location)
}
}
impl Into<Option<MultiLocation>> for AssetType {
fn into(self) -> Option<MultiLocation> {
match self {
Self::Xcm(location) => Some(location),
}
}
}

frame_support::parameter_types! {
pub UsdtLocation: MultiLocation = MultiLocation::new(
1,
X3(Parachain(1000), PalletInstance(50), GeneralIndex(1984))
);
}

use sp_runtime::traits::Hash;
jiguantong marked this conversation as resolved.
Show resolved Hide resolved
// Implementation on how to retrieve the AssetId from an AssetType
// We simply hash the AssetType and take the lowest 128 bits
impl From<AssetType> for crate::AssetId {
fn from(asset: AssetType) -> crate::AssetId {
match asset {
AssetType::Xcm(id) =>
if id == UsdtLocation::get() {
jiguantong marked this conversation as resolved.
Show resolved Hide resolved
1027
} else {
let mut result: [u8; 8] = [0u8; 8];
let hash: sp_core::H256 = id.using_encoded(dc_primitives::Hashing::hash);
result.copy_from_slice(&hash.as_fixed_bytes()[0..8]);
u64::from_le_bytes(result)
},
}
}
}
Loading