Skip to content

Commit

Permalink
Merge branch 'main' into code-coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
gpmayorga authored Feb 28, 2024
2 parents 4d06bac + 91f26f9 commit 37e6d77
Show file tree
Hide file tree
Showing 18 changed files with 428 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
run: >
docker run --rm --user root --platform=linux/amd64
-e PACKAGE=${{ matrix.package }} -v /home/runner/.cargo:/cargo-home
-v ${{ github.workspace }}:/build paritytech/srtool:1.73.0-0.12.0
-v ${{ github.workspace }}:/build paritytech/srtool:1.75.0-0.14.0
/srtool/build --app
# Alternative way of running SRTool that allows for "script-like" execution,
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

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

5 changes: 4 additions & 1 deletion libs/types/src/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,10 @@ pub mod usdc {
pub const CURRENCY_ID_LP_ETH_GOERLI: CurrencyId = CurrencyId::ForeignAsset(100_001);
pub const CURRENCY_ID_LP_BASE: CurrencyId = CurrencyId::ForeignAsset(100_002);
pub const CURRENCY_ID_LP_ARB: CurrencyId = CurrencyId::ForeignAsset(100_003);
pub const CURRENCY_ID_LP_CELO: CurrencyId = CurrencyId::ForeignAsset(100_004);

pub const CURRENCY_ID_LP_CELO_WORMHOLE: CurrencyId = CurrencyId::ForeignAsset(100_004);
pub const CURRENCY_ID_LP_CELO: CurrencyId = CurrencyId::ForeignAsset(100_006);

pub const LOCAL_ASSET_ID: LocalAssetId = LocalAssetId(1u32);
pub const CURRENCY_ID_LOCAL: CurrencyId = CurrencyId::LocalAsset(LOCAL_ASSET_ID);

Expand Down
7 changes: 4 additions & 3 deletions runtime/altair/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,16 +251,17 @@ impl Contains<RuntimeCall> for BaseCallFilter {
RuntimeCall::PolkadotXcm(method) => match method {
// Block these calls when called by a signed extrinsic.
// Root will still be able to execute these.
pallet_xcm::Call::send { .. }
| pallet_xcm::Call::execute { .. }
pallet_xcm::Call::execute { .. }
| pallet_xcm::Call::teleport_assets { .. }
| pallet_xcm::Call::reserve_transfer_assets { .. }
| pallet_xcm::Call::limited_reserve_transfer_assets { .. }
| pallet_xcm::Call::limited_teleport_assets { .. } => false,
pallet_xcm::Call::__Ignore { .. } => {
unimplemented!()
}
pallet_xcm::Call::force_xcm_version { .. }
// Allow all these calls. Only send(..) is callable by signed the rest needs root.
pallet_xcm::Call::send { .. }
| pallet_xcm::Call::force_xcm_version { .. }
| pallet_xcm::Call::force_suspension { .. }
| pallet_xcm::Call::force_default_xcm_version { .. }
| pallet_xcm::Call::force_subscribe_version_notify { .. }
Expand Down
12 changes: 5 additions & 7 deletions runtime/altair/src/xcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ use pallet_xcm::XcmPassthrough;
use runtime_common::{
transfer_filter::PreXcmTransfer,
xcm::{
general_key, AccountIdToMultiLocation, Barrier, FixedConversionRateProvider, ToTreasury,
general_key, AccountIdToMultiLocation, Barrier, FixedConversionRateProvider,
LocalOriginToLocation, ToTreasury,
},
xcm_fees::native_per_second,
};
Expand All @@ -39,7 +40,7 @@ use xcm::{
use xcm_builder::{
ConvertedConcreteId, EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, FungiblesAdapter,
NoChecking, RelayChainAsNative, SiblingParachainAsNative, SignedAccountId32AsNative,
SignedToAccountId32, SovereignSignedViaLocation,
SovereignSignedViaLocation,
};
use xcm_executor::{traits::JustTry, XcmExecutor};

Expand Down Expand Up @@ -170,7 +171,7 @@ impl pallet_xcm::Config for Runtime {
type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
type Currency = crate::Balances;
type CurrencyMatcher = ();
type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation<Runtime>>;
type MaxLockers = ConstU32<8>;
type MaxRemoteLockConsumers = ConstU32<0>;
#[cfg(feature = "runtime-benchmarks")]
Expand All @@ -179,7 +180,7 @@ impl pallet_xcm::Config for Runtime {
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type RuntimeOrigin = RuntimeOrigin;
type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation<Runtime>>;
type SovereignAccountOf = LocationToAccountId;
type TrustedLockers = ();
type UniversalLocation = UniversalLocation;
Expand All @@ -204,9 +205,6 @@ parameter_types! {
pub type CurrencyIdConvert = runtime_common::xcm::CurrencyIdConvert<Runtime>;
pub type LocationToAccountId = runtime_common::xcm::LocationToAccountId<RelayNetwork>;

/// No local origins on this chain are allowed to dispatch XCM sends/executions.
pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>;

/// The means for routing XCM messages which are not for local execution
/// into the right message queues.
pub type XcmRouter = (
Expand Down
9 changes: 5 additions & 4 deletions runtime/centrifuge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,16 +254,17 @@ impl Contains<RuntimeCall> for BaseCallFilter {
RuntimeCall::PolkadotXcm(method) => match method {
// Block these calls when called by a signed extrinsic.
// Root will still be able to execute these.
pallet_xcm::Call::send { .. }
| pallet_xcm::Call::execute { .. }
pallet_xcm::Call::execute { .. }
| pallet_xcm::Call::teleport_assets { .. }
| pallet_xcm::Call::reserve_transfer_assets { .. }
| pallet_xcm::Call::limited_reserve_transfer_assets { .. }
| pallet_xcm::Call::limited_teleport_assets { .. } => false,
pallet_xcm::Call::__Ignore { .. } => {
unimplemented!()
}
pallet_xcm::Call::force_xcm_version { .. }
// Allow all these calls. Only send(..) is callable by signed the rest needs root.
pallet_xcm::Call::send { .. }
| pallet_xcm::Call::force_xcm_version { .. }
| pallet_xcm::Call::force_suspension { .. }
| pallet_xcm::Call::force_default_xcm_version { .. }
| pallet_xcm::Call::force_subscribe_version_notify { .. }
Expand Down Expand Up @@ -1802,7 +1803,7 @@ parameter_types! {
}

impl pallet_order_book::Config for Runtime {
type AdminOrigin = EnsureRoot<AccountId>;
type AdminOrigin = EnsureAccountOrRootOr<LpAdminAccount, TwoThirdOfCouncil>;
type AssetRegistry = OrmlAssetRegistry;
type BalanceIn = Balance;
type BalanceOut = Balance;
Expand Down
6 changes: 5 additions & 1 deletion runtime/centrifuge/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ use cfg_primitives::{Balance, PoolId};
use cfg_types::tokens::{
usdc::{
CURRENCY_ID_AXELAR, CURRENCY_ID_DOT_NATIVE, CURRENCY_ID_LOCAL, CURRENCY_ID_LP_ARB,
CURRENCY_ID_LP_BASE, CURRENCY_ID_LP_CELO, CURRENCY_ID_LP_ETH, LOCAL_ASSET_ID,
CURRENCY_ID_LP_BASE, CURRENCY_ID_LP_CELO, CURRENCY_ID_LP_CELO_WORMHOLE, CURRENCY_ID_LP_ETH,
LOCAL_ASSET_ID,
},
CurrencyId, LocalAssetId,
};
Expand All @@ -31,6 +32,7 @@ frame_support::parameter_types! {
pub const UsdcEth: CurrencyId = CURRENCY_ID_LP_ETH;
pub const UsdcBase: CurrencyId = CURRENCY_ID_LP_BASE;
pub const UsdcArb: CurrencyId = CURRENCY_ID_LP_ARB;
pub const UsdcCeloWormhole: CurrencyId = CURRENCY_ID_LP_CELO_WORMHOLE;
pub const UsdcCelo: CurrencyId = CURRENCY_ID_LP_CELO;
pub const MinOrderAmount: Balance = 10u128.pow(6);
pub const AnnualTreasuryInflationPercent: u32 = 3;
Expand All @@ -51,6 +53,8 @@ pub type UpgradeCentrifuge1025 = (
super::Runtime,
LocalCurrencyIdUsdc,
>,
// Register new canonical USDC on Celo
runtime_common::migrations::update_celo_usdcs::Migration<super::Runtime>,
// Init local representation for all assets
runtime_common::migrations::local_currency::translate_metadata::Migration<
super::Runtime,
Expand Down
11 changes: 4 additions & 7 deletions runtime/centrifuge/src/xcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use runtime_common::{
transfer_filter::PreXcmTransfer,
xcm::{
general_key, AccountIdToMultiLocation, Barrier, FixedConversionRateProvider,
LpInstanceRelayer, ToTreasury,
LocalOriginToLocation, LpInstanceRelayer, ToTreasury,
},
xcm_fees::native_per_second,
};
Expand All @@ -41,7 +41,7 @@ use xcm::{
use xcm_builder::{
ConvertedConcreteId, EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, FungiblesAdapter,
NoChecking, RelayChainAsNative, SiblingParachainAsNative, SignedAccountId32AsNative,
SignedToAccountId32, SovereignSignedViaLocation,
SovereignSignedViaLocation,
};
use xcm_executor::{traits::JustTry, XcmExecutor};

Expand Down Expand Up @@ -172,7 +172,7 @@ impl pallet_xcm::Config for Runtime {
type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
type Currency = crate::Balances;
type CurrencyMatcher = ();
type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation<Runtime>>;
type MaxLockers = ConstU32<8>;
type MaxRemoteLockConsumers = ConstU32<0>;
#[cfg(feature = "runtime-benchmarks")]
Expand All @@ -181,7 +181,7 @@ impl pallet_xcm::Config for Runtime {
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type RuntimeOrigin = RuntimeOrigin;
type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation<Runtime>>;
type SovereignAccountOf = LocationToAccountId;
type TrustedLockers = ();
type UniversalLocation = UniversalLocation;
Expand All @@ -206,9 +206,6 @@ parameter_types! {
pub type CurrencyIdConvert = runtime_common::xcm::CurrencyIdConvert<Runtime>;
pub type LocationToAccountId = runtime_common::xcm::LocationToAccountId<RelayNetwork>;

/// No local origins on this chain are allowed to dispatch XCM sends/executions.
pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>;

/// The means for routing XCM messages which are not for local execution
/// into the right message queues.
pub type XcmRouter = (
Expand Down
116 changes: 116 additions & 0 deletions runtime/common/src/migrations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,119 @@ pub mod nuke;
pub mod orml_tokens;
pub mod precompile_account_codes;
pub mod transfer_allowlist_currency;

pub mod update_celo_usdcs {
use cfg_primitives::Balance;
#[cfg(feature = "try-runtime")]
use cfg_types::tokens::LocalAssetId;
use cfg_types::tokens::{
usdc::{CURRENCY_ID_LP_CELO, CURRENCY_ID_LP_CELO_WORMHOLE},
CrossChainTransferability, CurrencyId, CustomMetadata,
};
use frame_support::{traits::OnRuntimeUpgrade, weights::Weight};
use hex_literal::hex;
use orml_traits::asset_registry::{AssetMetadata, Mutate};
use sp_runtime::traits::Get;
#[cfg(feature = "try-runtime")]
use sp_std::{vec, vec::Vec};
use xcm::v3::{
Junction::{AccountKey20, GlobalConsensus, PalletInstance},
Junctions::X3,
NetworkId::Ethereum,
};

const LOG_PREFIX: &str = "UpdateCeloUsdcs";

pub struct Migration<T>(sp_std::marker::PhantomData<T>);

impl<T> OnRuntimeUpgrade for Migration<T>
where
T: orml_asset_registry::Config<
CustomMetadata = CustomMetadata,
AssetId = CurrencyId,
Balance = Balance,
>,
{
fn on_runtime_upgrade() -> Weight {
<orml_asset_registry::Pallet<T> as Mutate>::register_asset(
Some(CURRENCY_ID_LP_CELO),
AssetMetadata {
decimals: 6,
name: "LP Celo Wrapped USDC ".as_bytes().to_vec(),
symbol: "LpCeloUSDC".as_bytes().to_vec(),
existential_deposit: 1000u128,
location: Some(
X3(
PalletInstance(103),
GlobalConsensus(Ethereum { chain_id: 42220 }),
AccountKey20 {
// https://www.circle.com/blog/usdc-now-available-on-celo
key: hex!("cebA9300f2b948710d2653dD7B07f33A8B32118C"),
network: None,
},
)
.into(),
),
additional: CustomMetadata {
transferability: CrossChainTransferability::LiquidityPools,
mintable: false,
permissioned: false,
pool_currency: true,
local_representation: None,
},
},
)
.map_err(|e| {
log::error!(
"{LOG_PREFIX} Failed to register new canonical Celo USDC due to error {:?}",
e
);
})
.ok();

log::info!("{LOG_PREFIX} Done registering new canonical Celo USDC currency");

<orml_asset_registry::Pallet<T> as Mutate>::update_asset(
CURRENCY_ID_LP_CELO_WORMHOLE,
None,
Some("LP Celo Wrapped Wormhole USDC ".as_bytes().to_vec()),
Some("LpCeloWormUSDC ".as_bytes().to_vec()),
None,
None,
None,
)
.map_err(|e| {
log::error!(
"{LOG_PREFIX} Failed to update wormhole Celo USDC due to error {:?}",
e
);
})
.ok();

log::info!("{LOG_PREFIX} Done updating wormhole Celo USDC currency");

T::DbWeight::get().writes(2)
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, sp_runtime::DispatchError> {
assert!(!orml_asset_registry::Metadata::<T>::contains_key(
CURRENCY_ID_LP_CELO
));

log::info!("{LOG_PREFIX} PRE UPGRADE: Finished");

Ok(vec![])
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(_: Vec<u8>) -> Result<(), sp_runtime::DispatchError> {
assert!(orml_asset_registry::Metadata::<T>::contains_key(
CURRENCY_ID_LP_CELO
));

log::info!("{LOG_PREFIX} POST UPGRADE: Finished");
Ok(())
}
}
}
31 changes: 26 additions & 5 deletions runtime/common/src/xcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ use cfg_types::{
};
use frame_support::{
sp_std::marker::PhantomData,
traits::{fungibles::Mutate, Everything},
traits::{fungibles::Mutate, Everything, Get},
};
use polkadot_parachain::primitives::Sibling;
use sp_runtime::traits::{AccountIdConversion, Convert};
use sp_runtime::traits::{AccountIdConversion, Convert, Zero};
use xcm::v3::{
prelude::*,
Junction::{AccountId32, AccountKey20, GeneralKey, Parachain},
Junctions::{X1, X2},
MultiAsset, MultiLocation, OriginKind,
MultiAsset, MultiLocation, NetworkId, OriginKind,
};
use xcm_builder::{
AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom,
AllowTopLevelPaidExecutionFrom, ParentIsPreset, SiblingParachainConvertsVia, TakeRevenue,
TakeWeightCredit,
AllowTopLevelPaidExecutionFrom, ParentIsPreset, SiblingParachainConvertsVia,
SignedToAccountId32, TakeRevenue, TakeWeightCredit,
};

use crate::xcm_fees::default_per_second;
Expand Down Expand Up @@ -130,6 +130,27 @@ where
}
}

/// No local origins on this chain are allowed to dispatch XCM sends/executions.
pub type LocalOriginToLocation<R> = SignedToAccountId32<
<R as frame_system::Config>::RuntimeOrigin,
AccountId,
NetworkIdByGenesis<R>,
>;

pub struct NetworkIdByGenesis<T>(sp_std::marker::PhantomData<T>);

impl<T: frame_system::Config> Get<Option<NetworkId>> for NetworkIdByGenesis<T>
where
<T as frame_system::Config>::Hash: Into<[u8; 32]>,
{
fn get() -> Option<NetworkId> {
Some(NetworkId::ByGenesis(
frame_system::BlockHash::<T>::get(<T as frame_system::Config>::BlockNumber::zero())
.into(),
))
}
}

/// CurrencyIdConvert
/// This type implements conversions from our `CurrencyId` type into
/// `MultiLocation` and vice-versa. A currency locally is identified with a
Expand Down
2 changes: 1 addition & 1 deletion runtime/development/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "development-runtime"
version = "0.10.41"
version = "0.10.42"
build = "build.rs"
authors.workspace = true
edition.workspace = true
Expand Down
Loading

0 comments on commit 37e6d77

Please sign in to comment.