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

Evm part 2 #1349

Merged
merged 21 commits into from
May 24, 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
31 changes: 20 additions & 11 deletions Cargo.lock

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

7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ fc-mapping-sync = { git = "https://github.com/PureStake/frontier", default-featu
fc-rpc = { git = "https://github.com/PureStake/frontier", default-features = false, branch = "moonbeam-polkadot-v0.9.37" }
fc-rpc-core = { git = "https://github.com/PureStake/frontier", default-features = false, branch = "moonbeam-polkadot-v0.9.37" }
fp-consensus = { git = "https://github.com/PureStake/frontier", default-features = false, branch = "moonbeam-polkadot-v0.9.37" }
fp-dynamic-fee = { git = "https://github.com/PureStake/frontier", default-features = false, branch = "moonbeam-polkadot-v0.9.37" }
fp-rpc = { git = "https://github.com/PureStake/frontier", default-features = false, branch = "moonbeam-polkadot-v0.9.37" }
fp-storage = { git = "https://github.com/PureStake/frontier", default-features = false, branch = "moonbeam-polkadot-v0.9.37" }

Expand Down Expand Up @@ -189,7 +188,10 @@ std = [
"cumulus-primitives-core/std",
"cumulus-primitives-parachain-inherent/std",
"development-runtime/std",
"fp-dynamic-fee/std",
"fp-consensus/std",
"fp-rpc/std",
"fp-storage/std",
"futures/std",
"frame-benchmarking/std",
"log/std",
"pallet-anchors/std",
Expand All @@ -203,6 +205,7 @@ std = [
"sp-block-builder/std",
"sp-consensus-aura/std",
"sp-core/std",
"sp-io/std",
"sp-keystore/std",
"sp-offchain/std",
"sp-runtime/std",
Expand Down
4 changes: 0 additions & 4 deletions libs/types/src/domain_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,3 @@ impl DomainAddress {
self.clone().into()
}
}

impl TypeId for DomainAddress {
const TYPE_ID: [u8; 4] = *b"dadr";
}
40 changes: 11 additions & 29 deletions pallets/connectors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ use orml_traits::asset_registry::{self, Inspect as _};
pub use pallet::*;
use scale_info::TypeInfo;
use sp_core::U256;
use sp_runtime::{traits::AtLeast32BitUnsigned, FixedPointNumber};
use sp_runtime::{
traits::{AtLeast32BitUnsigned, Convert},
FixedPointNumber,
};
use sp_std::{convert::TryInto, vec, vec::Vec};
pub mod weights;

Expand Down Expand Up @@ -179,6 +182,9 @@ pub mod pallet {
Error = DispatchError,
>;

/// The converter from a DomainAddress to a Substrate AccountId
type AccountConverter: Convert<DomainAddress, Self::AccountId>;

/// The prefix for currencies added via Connectors.
#[pallet::constant]
type GeneralCurrencyPrefix: Get<[u8; 12]>;
Expand Down Expand Up @@ -395,12 +401,12 @@ pub mod pallet {
// be retried.
if !T::Permission::has(
PermissionScope::Pool(pool_id),
domain_address.into_account_truncating(),
T::AccountConverter::convert(domain_address.clone()),
Role::PoolRole(PoolRole::TrancheInvestor(tranche_id, valid_until)),
) {
T::Permission::add(
PermissionScope::Pool(pool_id),
domain_address.into_account_truncating(),
T::AccountConverter::convert(domain_address.clone()),
Role::PoolRole(PoolRole::TrancheInvestor(tranche_id, valid_until)),
)?;
}
Expand Down Expand Up @@ -436,11 +442,12 @@ pub mod pallet {
domain_address.domain() != Domain::Centrifuge,
Error::<T>::InvalidTransferDomain
);

// Check that the destination is a member of this tranche token
ensure!(
T::Permission::has(
PermissionScope::Pool(pool_id),
domain_address.into_account_truncating(),
T::AccountConverter::convert(domain_address.clone()),
Role::PoolRole(PoolRole::TrancheInvestor(tranche_id, Self::now()))
),
Error::<T>::UnauthorizedTransfer
Expand Down Expand Up @@ -614,11 +621,8 @@ pub mod pallet {

#[cfg(test)]
mod tests {
use cfg_primitives::AccountId;
use codec::{Decode, Encode};
use sp_runtime::traits::AccountIdConversion;

use super::DomainAddress;
use crate::Domain;

#[test]
Expand All @@ -635,26 +639,4 @@ mod tests {

assert_eq!(domain, decoded);
}

#[test]
fn domain_address_account_derivation() {
assert_eq!(
account_from(DomainAddress::EVM(1284, [9; 20])),
account_from(DomainAddress::EVM(1284, [9; 20])),
);

assert_ne!(
account_from(DomainAddress::EVM(1284, [42; 20])),
account_from(DomainAddress::EVM(1284, [24; 20])),
);

assert_ne!(
account_from(DomainAddress::EVM(1284, [9; 20])),
account_from(DomainAddress::EVM(1285, [9; 20])),
);
}

fn account_from(domain_address: DomainAddress) -> AccountId {
domain_address.into_account_truncating()
}
}
25 changes: 25 additions & 0 deletions runtime/altair/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ orml-xcm = { git = "https://github.com/open-web3-stack/open-runtime-module-libra
orml-xcm-support = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, branch = "polkadot-v0.9.37" }
orml-xtokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, branch = "polkadot-v0.9.37" }

# frontier pallets
fp-rpc = { git = "https://github.com/PureStake/frontier", default-features = false, branch = "moonbeam-polkadot-v0.9.37" }
fp-self-contained = { git = "https://github.com/PureStake/frontier", default-features = false, branch = "moonbeam-polkadot-v0.9.37" }
pallet-base-fee = { git = "https://github.com/PureStake/frontier", default-features = false, branch = "moonbeam-polkadot-v0.9.37" }
pallet-ethereum = { git = "https://github.com/PureStake/frontier", default-features = false, branch = "moonbeam-polkadot-v0.9.37" }
pallet-evm = { git = "https://github.com/PureStake/frontier", default-features = false, branch = "moonbeam-polkadot-v0.9.37" }
pallet-evm-chain-id = { git = "https://github.com/PureStake/frontier", default-features = false, branch = "moonbeam-polkadot-v0.9.37" }
pallet-evm-precompile-dispatch = { git = "https://github.com/PureStake/frontier", default-features = false, branch = "moonbeam-polkadot-v0.9.37" }

# our custom pallets
cfg-primitives = { path = "../../libs/primitives", default-features = false }
cfg-traits = { path = "../../libs/traits", default-features = false }
Expand Down Expand Up @@ -126,6 +135,8 @@ std = [
"cumulus-pallet-xcm/std",
"cumulus-pallet-xcmp-queue/std",
"cumulus-primitives-timestamp/std",
"fp-rpc/std",
"fp-self-contained/std",
"frame-executive/std",
"frame-support/std",
"frame-system-rpc-runtime-api/std",
Expand All @@ -142,6 +153,7 @@ std = [
"pallet-aura/std",
"pallet-authorship/std",
"pallet-balances/std",
"pallet-base-fee/std",
"pallet-block-rewards/std",
"pallet-collator-allowlist/std",
"pallet-collator-selection/std",
Expand All @@ -150,6 +162,10 @@ std = [
"pallet-crowdloan-reward/std",
"pallet-democracy/std",
"pallet-elections-phragmen/std",
"pallet-ethereum/std",
"pallet-evm/std",
"pallet-evm-precompile-dispatch/std",
"pallet-evm-chain-id/std",
"pallet-fees/std",
"pallet-identity/std",
"pallet-interest-accrual/std",
Expand Down Expand Up @@ -220,6 +236,8 @@ runtime-benchmarks = [
"pallet-crowdloan-reward/runtime-benchmarks",
"pallet-democracy/runtime-benchmarks",
"pallet-elections-phragmen/runtime-benchmarks",
"pallet-ethereum/runtime-benchmarks",
"pallet-evm/runtime-benchmarks",
"pallet-fees/runtime-benchmarks",
"pallet-identity/runtime-benchmarks",
"pallet-interest-accrual/runtime-benchmarks",
Expand Down Expand Up @@ -254,6 +272,7 @@ runtime-benchmarks = [
"polkadot-runtime-common/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"xcm-executor/runtime-benchmarks",
"pallet-evm/runtime-benchmarks",
]

try-runtime = [
Expand All @@ -268,6 +287,7 @@ try-runtime = [
"cumulus-pallet-parachain-system/try-runtime",
"cumulus-pallet-xcm/try-runtime",
"cumulus-pallet-xcmp-queue/try-runtime",
"fp-self-contained/try-runtime",
"frame-executive/try-runtime",
"frame-support/try-runtime",
"frame-system/try-runtime",
Expand All @@ -280,6 +300,7 @@ try-runtime = [
"pallet-aura/try-runtime",
"pallet-authorship/try-runtime",
"pallet-balances/try-runtime",
"pallet-base-fee/try-runtime",
"pallet-block-rewards/try-runtime",
"pallet-collator-allowlist/try-runtime",
"pallet-collator-selection/try-runtime",
Expand All @@ -288,6 +309,9 @@ try-runtime = [
"pallet-crowdloan-reward/try-runtime",
"pallet-democracy/try-runtime",
"pallet-elections-phragmen/try-runtime",
"pallet-ethereum/try-runtime",
"pallet-evm/try-runtime",
"pallet-evm-chain-id/try-runtime",
"pallet-fees/try-runtime",
"pallet-identity/try-runtime",
"pallet-interest-accrual/try-runtime",
Expand Down Expand Up @@ -316,6 +340,7 @@ try-runtime = [
"pallet-xcm/try-runtime",
"parachain-info/try-runtime",
"runtime-common/try-runtime",
"sp-runtime/try-runtime",
]

# A feature that should be enabled when the runtime should be build for on-chain
Expand Down
Loading