Skip to content

Commit

Permalink
upgraded runtime-common
Browse files Browse the repository at this point in the history
  • Loading branch information
lemunozm committed May 17, 2024
1 parent 45b3f11 commit a783c9f
Show file tree
Hide file tree
Showing 15 changed files with 822 additions and 257 deletions.
643 changes: 626 additions & 17 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ members = [
#"runtime/altair",
#"runtime/centrifuge",
#"runtime/development",
#"runtime/common",
"runtime/common",
#"runtime/integration-tests",
#"runtime/integration-tests/procedural",
]
Expand Down
19 changes: 11 additions & 8 deletions libs/types/src/locations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use staging_xcm::VersionedLocation;
use crate::domain_address::DomainAddress;
/// Location types for destinations that can receive restricted transfers
#[derive(Clone, RuntimeDebugNoBound, Encode, Decode, Eq, PartialEq, MaxEncodedLen, TypeInfo)]
pub enum Location {
pub enum CfgLocation {
/// Local chain account sending destination.
Local(AccountId),
/// XCM MultiLocation sending destinations.
Expand All @@ -33,21 +33,24 @@ pub enum Location {
Address(DomainAddress),
}

impl From<AccountId32> for Location {
impl From<AccountId32> for CfgLocation {
fn from(value: AccountId32) -> Self {
Self::Local(value)
}
}

impl From<VersionedLocation> for Location {
impl From<VersionedLocation> for CfgLocation {
fn from(vml: VersionedLocation) -> Self {
// using hash here as multilocation is significantly larger than any other enum
// type here -- 592 bytes, vs 40 bytes for domain address (next largest)
Self::XCM(BlakeTwo256::hash(&vml.encode()))

// TODO-1.7: I'm afraid of locations translated from v3 to v4 will generate a different hash here.
// How this affect our current chain state?
}
}

impl From<DomainAddress> for Location {
impl From<DomainAddress> for CfgLocation {
fn from(da: DomainAddress) -> Self {
Self::Address(da)
}
Expand All @@ -65,10 +68,10 @@ mod test {
fn from_xcm_versioned_address_works() {
// TODO-1.7: Must be changed to V4?
let xa = VersionedLocation::V3(MultiLocation::default());
let l = Location::from(xa.clone());
let l = CfgLocation::from(xa.clone());
assert_eq!(
l,
Location::XCM(sp_core::H256(
CfgLocation::XCM(sp_core::H256(
<[u8; 32]>::from_hex(
"a943e30c855a123a9506e69e678dc65ae9f5b70149cb6b26eb2ed58a59b4bf77"
)
Expand All @@ -83,8 +86,8 @@ mod test {
1284,
<[u8; 20]>::from_hex("1231231231231231231231231231231231231231").unwrap(),
);
let l = Location::from(da.clone());
let l = CfgLocation::from(da.clone());

assert_eq!(l, Location::Address(da))
assert_eq!(l, CfgLocation::Address(da))
}
}
1 change: 0 additions & 1 deletion pallets/fees/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ impl pallet_authorship::Config for Runtime {
parameter_types! {
pub const TreasuryPalletId: PalletId = PalletId(*b"treasury");
pub TreasuryAccount: u64 = Treasury::account_id();
pub TreasuryInstance1Account: u64 = Treasury::account_id();
}

impl pallet_treasury::Config for Runtime {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub(crate) fn get_axelar_encoded_msg(
},
],
outputs: vec![],
constant: false,
constant: Some(false),
state_mutability: Default::default(),
}],
)]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub(crate) fn get_xcm_router_contract() -> Contract {
internal_type: None,
}],
outputs: vec![],
constant: false,
constant: Some(false),
state_mutability: Default::default(),
}],
);
Expand Down
1 change: 0 additions & 1 deletion pallets/oracle-feed/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use frame_benchmarking::{v2::*, whitelisted_caller};
use frame_support::traits::OriginTrait;
use frame_system::RawOrigin;
use parity_scale_codec::Decode;
use sp_std::vec; // required for #[benchmarks]

use crate::pallet::{Call, Config, Pallet};

Expand Down
2 changes: 1 addition & 1 deletion runtime/altair/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2324,7 +2324,7 @@ impl_runtime_apis! {
// Investment Runtime APIs
impl runtime_common::apis::InvestmentsApi<Block, AccountId, TrancheCurrency, InvestmentPortfolio<Balance, CurrencyId>> for Runtime {
fn investment_portfolio(account_id: AccountId) -> Vec<(TrancheCurrency, InvestmentPortfolio<Balance, CurrencyId>)> {
runtime_common::investment_portfolios::get_account_portfolio::<Runtime, PoolSystem>(account_id)
runtime_common::investment_portfolios::get_account_portfolio::<Runtime>(account_id)
}
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/centrifuge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2371,7 +2371,7 @@ impl_runtime_apis! {
// Investment Runtime APIs
impl runtime_common::apis::InvestmentsApi<Block, AccountId, TrancheCurrency, InvestmentPortfolio<Balance, CurrencyId>> for Runtime {
fn investment_portfolio(account_id: AccountId) -> Vec<(TrancheCurrency, InvestmentPortfolio<Balance, CurrencyId>)> {
runtime_common::investment_portfolios::get_account_portfolio::<Runtime, PoolSystem>(account_id)
runtime_common::investment_portfolios::get_account_portfolio::<Runtime>(account_id)
}
}

Expand Down
21 changes: 10 additions & 11 deletions runtime/common/src/account_conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use cfg_types::domain_address::{Domain, DomainAddress};
use pallet_evm::AddressMapping;
use sp_core::{Get, H160};
use sp_runtime::traits::Convert;
use staging_xcm::v3;
use staging_xcm::v4::{Junction::AccountKey20, Location, NetworkId::Ethereum};
use staging_xcm_executor::traits::ConvertLocation;

/// Common converter code for translating accounts across different
Expand All @@ -40,22 +40,21 @@ impl AccountConverter {
}

pub fn location_to_account<XcmConverter: ConvertLocation<AccountId>>(
location: v3::MultiLocation,
location: Location,
) -> Option<AccountId> {
// Try xcm logic first
match XcmConverter::convert_location(&location) {
Some(acc) => Some(acc),
None => {
// match EVM logic
match location {
v3::MultiLocation {
parents: 0,
interior:
v3::Junctions::X1(v3::Junction::AccountKey20 {
network: Some(v3::NetworkId::Ethereum { chain_id }),
key,
}),
} => Some(Self::convert_evm_address(chain_id, key)),
match location.unpack() {
(
0,
[AccountKey20 {
network: Some(Ethereum { chain_id }),
key,
}],
) => Some(Self::convert_evm_address(*chain_id, *key)),
_ => None,
}
}
Expand Down
10 changes: 10 additions & 0 deletions runtime/common/src/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ mod test {
use cfg_types::ids::TREASURY_PALLET_ID;
use frame_support::{
derive_impl, parameter_types,
traits::tokens::{PayFromAccount, UnityAssetBalanceConversion},
traits::{Currency, FindAuthor},
PalletId,
};
Expand Down Expand Up @@ -185,6 +186,7 @@ mod test {

parameter_types! {
pub const TreasuryPalletId: PalletId = TREASURY_PALLET_ID;
pub TreasuryAccount: AccountId = Treasury::account_id();
pub const MaxApprovals: u32 = 100;
}

Expand All @@ -205,6 +207,14 @@ mod test {
type SpendOrigin = frame_support::traits::NeverEnsureOrigin<u64>;
type SpendPeriod = ();
type WeightInfo = ();
type AssetKind = ();
type Beneficiary = Self::AccountId;
type BeneficiaryLookup = IdentityLookup<Self::Beneficiary>;
type Paymaster = PayFromAccount<Balances, TreasuryAccount>;
type BalanceConverter = UnityAssetBalanceConversion;
type PayoutPeriod = ConstU64<10>;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
}

pub struct OneAuthor;
Expand Down
Loading

0 comments on commit a783c9f

Please sign in to comment.