From d33ed15e24ac03b62ebac9597c61c59ad9740787 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Rios Date: Thu, 31 Oct 2024 10:36:30 +0100 Subject: [PATCH] WETH from assethub support --- Cargo.lock | 1 + integration-tests/src/constants.rs | 18 ++++- .../src/tests/ethereum_support.rs | 2 +- .../src/instantiator/chain_interactions.rs | 8 +++ pallets/funding/src/mock.rs | 9 +++ pallets/funding/src/tests/3_auction.rs | 26 ++++--- pallets/funding/src/tests/4_contribution.rs | 1 + pallets/funding/src/tests/misc.rs | 1 - pallets/funding/src/types.rs | 3 + pallets/oracle-ocw/src/mock.rs | 1 + pallets/oracle-ocw/src/types.rs | 3 + runtimes/polimec/Cargo.toml | 2 + runtimes/polimec/src/lib.rs | 8 +-- runtimes/polimec/src/xcm_config.rs | 67 ++++++++++++++----- runtimes/shared-configuration/src/currency.rs | 1 + 15 files changed, 120 insertions(+), 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4ad49cf80..0ebb8795f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8807,6 +8807,7 @@ dependencies = [ "frame-system-rpc-runtime-api", "frame-try-runtime", "hex-literal", + "lazy_static", "log", "orml-oracle", "pallet-asset-tx-payment", diff --git a/integration-tests/src/constants.rs b/integration-tests/src/constants.rs index 9e492d546..160e89c11 100644 --- a/integration-tests/src/constants.rs +++ b/integration-tests/src/constants.rs @@ -69,6 +69,7 @@ pub struct Prices { pub usdc: FixedU128, pub usdt: FixedU128, pub plmc: FixedU128, + pub weth: FixedU128, } // PricesBuilder for optional fields before building Prices @@ -78,12 +79,13 @@ pub struct PricesBuilder { usdc: Option, usdt: Option, plmc: Option, + weth: Option, } impl PricesBuilder { // Initialize a new builder with None for each field pub fn new() -> Self { - Self { dot: None, usdc: None, usdt: None, plmc: None } + Self { dot: None, usdc: None, usdt: None, plmc: None, weth: None } } pub fn default() -> Prices { @@ -92,6 +94,7 @@ impl PricesBuilder { usdc: FixedU128::from_rational(1, 1), usdt: FixedU128::from_rational(1, 1), plmc: FixedU128::from_rational(840, 100), + weth: FixedU128::from_rational(3620, 1), } } @@ -116,6 +119,11 @@ impl PricesBuilder { self } + pub fn weth(&mut self, price: FixedU128) -> &mut Self { + self.weth = Some(price); + self + } + // Build Prices using provided values or default values pub fn build(self) -> Prices { Prices { @@ -123,6 +131,7 @@ impl PricesBuilder { usdc: self.usdc.unwrap_or(FixedU128::from_rational(1, 1)), // Default USDC price usdt: self.usdt.unwrap_or(FixedU128::from_rational(1, 1)), // Default USDT price plmc: self.plmc.unwrap_or(FixedU128::from_rational(840, 100)), // Default PLMC price + weth: self.weth.unwrap_or(FixedU128::from_rational(3620, 1)), // Default WETH price } } } @@ -446,9 +455,10 @@ pub mod polimec { let usdc = (AcceptedFundingAsset::USDC.id(), prices.usdc); let usdt = (AcceptedFundingAsset::USDT.id(), prices.usdt); let plmc = (polimec_common::PLMC_FOREIGN_ID, prices.plmc); + let weth = (AcceptedFundingAsset::WETH.id(), prices.weth); let values: BoundedVec<(u32, FixedU128), ::MaxFeedValues> = - vec![dot, usdc, usdt, plmc].try_into().expect("benchmarks can panic"); + vec![dot, usdc, usdt, plmc, weth].try_into().expect("benchmarks can panic"); let alice: [u8; 32] = [ 212, 53, 147, 199, 21, 253, 211, 28, 97, 20, 26, 189, 4, 169, 159, 214, 130, 44, 133, 88, 133, 76, 205, 227, 154, 86, 132, 231, 165, 109, 162, 125, @@ -483,6 +493,8 @@ pub mod polimec { let dot_asset_id = AcceptedFundingAsset::DOT.id(); let usdt_asset_id = AcceptedFundingAsset::USDT.id(); let usdc_asset_id = AcceptedFundingAsset::USDC.id(); + let weth_asset_id = AcceptedFundingAsset::WETH.id(); + let mut funded_accounts = vec![ ( PolimecNet::sovereign_account_id_of((Parent, xcm::prelude::Parachain(penpal::PARA_ID)).into()), @@ -515,11 +527,13 @@ pub mod polimec { (dot_asset_id, alice_account.clone(), true, 100_000_000), (usdt_asset_id, alice_account.clone(), true, 70_000), (usdc_asset_id, alice_account.clone(), true, 70_000), + (weth_asset_id, alice_account.clone(), true, 0_000_041_000_000_000_000), ], metadata: vec![ (dot_asset_id, "Local DOT".as_bytes().to_vec(), "DOT".as_bytes().to_vec(), 10), (usdt_asset_id, "Local USDT".as_bytes().to_vec(), "USDT".as_bytes().to_vec(), 6), (usdc_asset_id, "Local USDC".as_bytes().to_vec(), "USDC".as_bytes().to_vec(), 6), + (usdc_asset_id, "Local WETH".as_bytes().to_vec(), "WETH".as_bytes().to_vec(), 18), ], accounts: vec![], }, diff --git a/integration-tests/src/tests/ethereum_support.rs b/integration-tests/src/tests/ethereum_support.rs index 28b43edf2..37c5c838c 100644 --- a/integration-tests/src/tests/ethereum_support.rs +++ b/integration-tests/src/tests/ethereum_support.rs @@ -10,7 +10,7 @@ fn test_hardcoded_signatures() { let project_id = 1; // Values generated with `https://github.com/lrazovic/ethsigner` - let polimec_account_ss58 = polimec_runtime::SS58Converter::convert(polimec_account.clone()); + let _polimec_account_ss58 = polimec_runtime::SS58Converter::convert(polimec_account.clone()); let ethereum_account: [u8; 20] = hex!("796afe7b8933ee8cf337f17887e5c19b657f9ab8"); let signature: [u8; 65] = hex!("952e312ac892fefc7c69051521e78a3bc2727fbb495585bdb5fb77e662b8a3de2b1254058d824e85034710e338c2590e2f92d74ce3c60292ed25c7537d94ed621b"); diff --git a/pallets/funding/src/instantiator/chain_interactions.rs b/pallets/funding/src/instantiator/chain_interactions.rs index 2fd3411d4..646f3b72d 100644 --- a/pallets/funding/src/instantiator/chain_interactions.rs +++ b/pallets/funding/src/instantiator/chain_interactions.rs @@ -545,12 +545,14 @@ impl< let mut total_expected_dot: Balance = Zero::zero(); let mut total_expected_usdt: Balance = Zero::zero(); let mut total_expected_usdc: Balance = Zero::zero(); + let mut total_expected_weth: Balance = Zero::zero(); for bid in bids { match bid.funding_asset { AcceptedFundingAsset::DOT => total_expected_dot += bid.funding_asset_amount_locked, AcceptedFundingAsset::USDT => total_expected_usdt += bid.funding_asset_amount_locked, AcceptedFundingAsset::USDC => total_expected_usdc += bid.funding_asset_amount_locked, + AcceptedFundingAsset::WETH => total_expected_weth += bid.funding_asset_amount_locked, } } @@ -559,6 +561,7 @@ impl< AcceptedFundingAsset::DOT => total_expected_dot += contribution.funding_asset_amount, AcceptedFundingAsset::USDT => total_expected_usdt += contribution.funding_asset_amount, AcceptedFundingAsset::USDC => total_expected_usdc += contribution.funding_asset_amount, + AcceptedFundingAsset::WETH => total_expected_weth += contribution.funding_asset_amount, } } @@ -572,12 +575,17 @@ impl< ); let total_stored_usdc = self.get_free_funding_asset_balance_for( AcceptedFundingAsset::USDC.id(), + project_metadata.funding_destination_account.clone(), + ); + let total_stored_weth = self.get_free_funding_asset_balance_for( + AcceptedFundingAsset::WETH.id(), project_metadata.funding_destination_account, ); assert_eq!(total_expected_dot, total_stored_dot, "DOT amount is incorrect"); assert_eq!(total_expected_usdt, total_stored_usdt, "USDT amount is incorrect"); assert_eq!(total_expected_usdc, total_stored_usdc, "USDC amount is incorrect"); + assert_eq!(total_expected_weth, total_stored_weth, "WETH amount is incorrect"); } // Used to check if all evaluations are settled correctly. We cannot check amount of diff --git a/pallets/funding/src/mock.rs b/pallets/funding/src/mock.rs index 41b4a61a0..c133bea69 100644 --- a/pallets/funding/src/mock.rs +++ b/pallets/funding/src/mock.rs @@ -362,6 +362,7 @@ thread_local! { (AcceptedFundingAsset::DOT.id(), FixedU128::from_float(69f64)), // DOT (AcceptedFundingAsset::USDC.id(), FixedU128::from_float(0.97f64)), // USDC (AcceptedFundingAsset::USDT.id(), FixedU128::from_float(1.0f64)), // USDT + (AcceptedFundingAsset::WETH.id(), FixedU128::from_float(3619.451f64)), // WETH (PLMC_FOREIGN_ID, FixedU128::from_float(8.4f64)), // PLMC ])); } @@ -511,11 +512,19 @@ pub fn new_test_ext() -> sp_io::TestExternalities { true, 100_000_000, ), + ( + AcceptedFundingAsset::WETH.id(), + ::PalletId::get().into_account_truncating(), + true, + // 0.07 USD = .000041WETH at this moment + 0_000_041_000_000_000_000, + ), ], metadata: vec![ (AcceptedFundingAsset::USDT.id(), "USDT".as_bytes().to_vec(), "USDT".as_bytes().to_vec(), 6), (AcceptedFundingAsset::USDC.id(), "USDC".as_bytes().to_vec(), "USDC".as_bytes().to_vec(), 6), (AcceptedFundingAsset::DOT.id(), "DOT".as_bytes().to_vec(), "DOT".as_bytes().to_vec(), 10), + (AcceptedFundingAsset::WETH.id(), "WETH".as_bytes().to_vec(), "WETH".as_bytes().to_vec(), 18), ], accounts: vec![], }, diff --git a/pallets/funding/src/tests/3_auction.rs b/pallets/funding/src/tests/3_auction.rs index dd208cc93..9e2aa7965 100644 --- a/pallets/funding/src/tests/3_auction.rs +++ b/pallets/funding/src/tests/3_auction.rs @@ -147,6 +147,7 @@ mod round_flow { AcceptedFundingAsset::USDT => usdt_price, AcceptedFundingAsset::USDC => usdc_price, AcceptedFundingAsset::DOT => dot_price, + AcceptedFundingAsset::WETH => todo!(), }; let mut project_metadata = default_project_metadata.clone(); @@ -2269,8 +2270,12 @@ mod end_auction_extrinsic { let accounts = [ADAM, TOM, SOFIA, FRED, ANNA, DAMIAN]; let mut project_metadata = default_project_metadata(ISSUER_1); project_metadata.total_allocation_size = 100_000 * CT_UNIT; - project_metadata.participation_currencies = - bounded_vec![AcceptedFundingAsset::USDT, AcceptedFundingAsset::USDC, AcceptedFundingAsset::DOT,]; + project_metadata.participation_currencies = bounded_vec![ + AcceptedFundingAsset::USDT, + AcceptedFundingAsset::USDC, + AcceptedFundingAsset::DOT, + AcceptedFundingAsset::WETH + ]; // overfund with plmc let plmc_fundings = accounts @@ -2278,11 +2283,16 @@ mod end_auction_extrinsic { .map(|acc| UserToPLMCBalance { account: *acc, plmc_amount: PLMC * 1_000_000 }) .collect_vec(); - let fundings = [AcceptedFundingAsset::USDT, AcceptedFundingAsset::USDC, AcceptedFundingAsset::DOT]; + let fundings = [ + AcceptedFundingAsset::USDT, + AcceptedFundingAsset::USDC, + AcceptedFundingAsset::DOT, + AcceptedFundingAsset::WETH, + ]; assert_eq!(fundings.len(), AcceptedFundingAsset::VARIANT_COUNT); let mut fundings = fundings.into_iter().cycle(); - let usdt_fundings = accounts + let funding_asset_mints = accounts .iter() .map(|acc| { let accepted_asset = fundings.next().unwrap(); @@ -2293,7 +2303,7 @@ mod end_auction_extrinsic { }) .collect_vec(); inst.mint_plmc_to(plmc_fundings); - inst.mint_funding_asset_to(usdt_fundings); + inst.mint_funding_asset_to(funding_asset_mints); let project_id = inst.create_auctioning_project(project_metadata, ISSUER_1, None, default_evaluations()); @@ -2301,9 +2311,9 @@ mod end_auction_extrinsic { (ADAM, 10_000 * CT_UNIT, ParticipationMode::Classic(1), AcceptedFundingAsset::USDT).into(), (TOM, 20_000 * CT_UNIT, ParticipationMode::Classic(1), AcceptedFundingAsset::USDC).into(), (SOFIA, 20_000 * CT_UNIT, ParticipationMode::Classic(1), AcceptedFundingAsset::DOT).into(), - (FRED, 10_000 * CT_UNIT, ParticipationMode::Classic(1), AcceptedFundingAsset::USDT).into(), - (ANNA, 5_000 * CT_UNIT, ParticipationMode::Classic(1), AcceptedFundingAsset::USDC).into(), - (DAMIAN, 5_000 * CT_UNIT, ParticipationMode::Classic(1), AcceptedFundingAsset::DOT).into(), + (FRED, 10_000 * CT_UNIT, ParticipationMode::Classic(1), AcceptedFundingAsset::WETH).into(), + (ANNA, 5_000 * CT_UNIT, ParticipationMode::Classic(1), AcceptedFundingAsset::USDT).into(), + (DAMIAN, 5_000 * CT_UNIT, ParticipationMode::Classic(1), AcceptedFundingAsset::USDC).into(), ]; inst.bid_for_users(project_id, bids).unwrap(); diff --git a/pallets/funding/src/tests/4_contribution.rs b/pallets/funding/src/tests/4_contribution.rs index fb0f0275b..f76b698f3 100644 --- a/pallets/funding/src/tests/4_contribution.rs +++ b/pallets/funding/src/tests/4_contribution.rs @@ -210,6 +210,7 @@ mod round_flow { AcceptedFundingAsset::USDT => usdt_price, AcceptedFundingAsset::USDC => usdc_price, AcceptedFundingAsset::DOT => dot_price, + AcceptedFundingAsset::WETH => todo!(), }; let mut project_metadata = default_project_metadata.clone(); diff --git a/pallets/funding/src/tests/misc.rs b/pallets/funding/src/tests/misc.rs index 0b9e5ff43..8c32056e0 100644 --- a/pallets/funding/src/tests/misc.rs +++ b/pallets/funding/src/tests/misc.rs @@ -4,7 +4,6 @@ use super::*; mod helper_functions { use super::*; use polimec_common::USD_DECIMALS; - use sp_core::{ecdsa, hexdisplay::AsBytesRef, keccak_256, sr25519, Pair}; #[test] fn test_usd_price_decimal_aware() { diff --git a/pallets/funding/src/types.rs b/pallets/funding/src/types.rs index 240d6dfc2..2091ce136 100644 --- a/pallets/funding/src/types.rs +++ b/pallets/funding/src/types.rs @@ -652,6 +652,8 @@ pub mod inner { USDC, #[codec(index = 2)] DOT, + #[codec(index = 3)] + WETH, } impl AcceptedFundingAsset { pub const fn id(&self) -> u32 { @@ -659,6 +661,7 @@ pub mod inner { AcceptedFundingAsset::USDT => 1984, AcceptedFundingAsset::DOT => 10, AcceptedFundingAsset::USDC => 1337, + AcceptedFundingAsset::WETH => 10_000, } } } diff --git a/pallets/oracle-ocw/src/mock.rs b/pallets/oracle-ocw/src/mock.rs index 658b5b318..c5694f36b 100644 --- a/pallets/oracle-ocw/src/mock.rs +++ b/pallets/oracle-ocw/src/mock.rs @@ -105,6 +105,7 @@ impl Convert<(AssetName, FixedU128), (OracleKey, OracleValue)> for AssetPriceCon AssetName::USDC => (1337, price), AssetName::USDT => (1984, price), AssetName::PLMC => (3344, price), + AssetName::WETH => (10_000, price), } } } diff --git a/pallets/oracle-ocw/src/types.rs b/pallets/oracle-ocw/src/types.rs index dba09f69d..ec70c9377 100644 --- a/pallets/oracle-ocw/src/types.rs +++ b/pallets/oracle-ocw/src/types.rs @@ -30,6 +30,7 @@ pub enum AssetName { USDC, DOT, PLMC, + WETH, } #[derive(Debug, Clone, Copy)] @@ -131,6 +132,7 @@ impl FetchPrice for KrakenFetcher { AssetName::DOT => "https://api.kraken.com/0/public/OHLC?pair=DOTUSD&interval=1", AssetName::USDC => "https://api.kraken.com/0/public/OHLC?pair=USDCUSD&interval=1", AssetName::PLMC => "", + AssetName::WETH => "", } } } @@ -224,6 +226,7 @@ impl FetchPrice for BitStampFetcher { AssetName::DOT => "https://www.bitstamp.net/api/v2/ohlc/dotusd/?step=60&limit=15", AssetName::USDC => "https://www.bitstamp.net/api/v2/ohlc/usdcusd/?step=60&limit=15", AssetName::PLMC => "", + AssetName::WETH => "", } } } diff --git a/runtimes/polimec/Cargo.toml b/runtimes/polimec/Cargo.toml index d5318a6bd..3cd09ac8b 100644 --- a/runtimes/polimec/Cargo.toml +++ b/runtimes/polimec/Cargo.toml @@ -25,6 +25,8 @@ scale-info = { workspace= true, default-features = false, features = [ "derive", ] } +lazy_static = "1.5.0" + # Uncomment this and the std feature below to see variables instead of in the console output #sp-debug-derive = { workspace = true, features = ["force-debug"]} diff --git a/runtimes/polimec/src/lib.rs b/runtimes/polimec/src/lib.rs index 2107ee7ce..5d8cdeaff 100644 --- a/runtimes/polimec/src/lib.rs +++ b/runtimes/polimec/src/lib.rs @@ -837,7 +837,7 @@ parameter_types! { pub const ExpiresIn: Moment = 1000 * 60; // 1 mins pub const MaxHasDispatchedSize: u32 = 20; pub RootOperatorAccountId: AccountId = AccountId::from([0xffu8; 32]); - pub const MaxFeedValues: u32 = 4; // max 4 values allowd to feed in one call (USDT, USDC, DOT, PLMC). + pub const MaxFeedValues: u32 = AcceptedFundingAsset::VARIANT_COUNT as u32 + 1; // Funding asset prices + PLMC } impl orml_oracle::Config for Runtime { @@ -1708,9 +1708,9 @@ impl_runtime_apis! { fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result, XcmPaymentApiError> { let acceptable_assets = vec![ xcm_config::HereLocation::get().into(), - xcm_config::DotLocation::get().into(), - xcm_config::UsdtLocation::get().into(), - xcm_config::UsdcLocation::get().into() + xcm_config::DOTLocation::get().into(), + xcm_config::USDTLocation::get().into(), + xcm_config::USDCLocation::get().into() ]; PolkadotXcm::query_acceptable_payment_assets(xcm_version, acceptable_assets) diff --git a/runtimes/polimec/src/xcm_config.rs b/runtimes/polimec/src/xcm_config.rs index 7ba11a84f..8be691602 100644 --- a/runtimes/polimec/src/xcm_config.rs +++ b/runtimes/polimec/src/xcm_config.rs @@ -13,6 +13,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +extern crate alloc; use super::{ AccountId, AllPalletsWithSystem, AssetId as AssetIdPalletAssets, Balance, Balances, ContributionTokens, EnsureRoot, @@ -55,12 +56,12 @@ const DOT_PER_MB_PROOF: u128 = 0_2_000_000_000; // 0.0000001 DOT per Megabyte of // USDT from Polkadot Asset Hub const USDT_PER_SECOND_EXECUTION: u128 = 1_000_000; // 1 USDT per second of execution time const USDT_PER_MB_PROOF: u128 = 1_000_000; // 1 USDT per Megabyte of proof size -pub const USDT_JUNCTION: &[Junction] = &[Parachain(1000), PalletInstance(50), GeneralIndex(1984)]; // USDC from Polkadot Asset Hub const USDC_PER_SECOND_EXECUTION: u128 = 1_000_000; // 1 USDC per second of execution time const USDC_PER_MB_PROOF: u128 = 1_000_000; // 1 USDC per Megabyte of proof size -pub const USDC_JUNCTION: &[Junction] = &[Parachain(1000), PalletInstance(50), GeneralIndex(1337)]; + +pub const WETH_ADDRESS: [u8; 20] = hex_literal::hex!("c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"); parameter_types! { pub const RelayLocation: Location = Location::parent(); @@ -82,14 +83,33 @@ parameter_types! { pub ContributionTokensPalletIndex: u8 = ::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)]); - pub UsdcLocation: Location = Location::new(1, [Parachain(1000), PalletInstance(50), GeneralIndex(1337)]); - pub DotTraderParams: (AssetId, u128, u128) = (DotLocation::get().into(), DOT_PER_SECOND_EXECUTION, DOT_PER_MB_PROOF); - pub UsdtTraderParams: (AssetId, u128, u128) = (UsdtLocation::get().into(), USDT_PER_SECOND_EXECUTION, USDT_PER_MB_PROOF); - pub UsdcTraderParams: (AssetId, u128, u128) = (UsdcLocation::get().into(), USDC_PER_SECOND_EXECUTION, USDC_PER_MB_PROOF); + pub DOTLocation: Location = Location::new(DOT_PARENTS, DOT_JUNCTIONS); + pub USDTLocation: Location = Location::new(USDT_PARENTS, USDT_JUNCTIONS); + pub USDCLocation: Location = Location::new(USDC_PARENTS, USDC_JUNCTIONS); + pub WETHLocation: Location = Location::new(WETH_PARENTS, WETH_JUNCTIONS); + + pub DotTraderParams: (AssetId, u128, u128) = (DOTLocation::get().into(), DOT_PER_SECOND_EXECUTION, DOT_PER_MB_PROOF); + pub UsdtTraderParams: (AssetId, u128, u128) = (USDTLocation::get().into(), USDT_PER_SECOND_EXECUTION, USDT_PER_MB_PROOF); + pub UsdcTraderParams: (AssetId, u128, u128) = (USDCLocation::get().into(), USDC_PER_SECOND_EXECUTION, USDC_PER_MB_PROOF); } +const DOT_PARENTS: u8 = 1; +const DOT_JUNCTIONS: [Junction; 0] = []; +const DOT_UNPACKED: (u8, &[Junction]) = (DOT_PARENTS, &DOT_JUNCTIONS); + +const USDT_PARENTS: u8 = 1; +const USDT_JUNCTIONS: [Junction; 3] = [Parachain(1000), PalletInstance(50), GeneralIndex(1984)]; +const USDT_UNPACKED: (u8, &[Junction]) = (USDT_PARENTS, &USDT_JUNCTIONS); + +const USDC_PARENTS: u8 = 1; +const USDC_JUNCTIONS: [Junction; 3] = [Parachain(1000), PalletInstance(50), GeneralIndex(1337)]; +const USDC_UNPACKED: (u8, &[Junction]) = (USDC_PARENTS, &USDC_JUNCTIONS); + +const WETH_PARENTS: u8 = 2; +const WETH_JUNCTIONS: [Junction; 2] = + [GlobalConsensus(Ethereum { chain_id: 1 }), AccountKey20 { network: None, key: WETH_ADDRESS }]; +const WETH_UNPACKED: (u8, &[Junction]) = (WETH_PARENTS, &WETH_JUNCTIONS); + /// Type for specifying how a `Location` can be converted into an `AccountId`. This is used /// when determining ownership of accounts for asset transacting and when attempting to use XCM /// `Transact` in order to determine the dispatch Origin. @@ -129,25 +149,28 @@ pub type ContributionTokensConvertedConcreteId = pub struct SupportedAssets; impl frame_support::traits::Contains for SupportedAssets { fn contains(l: &Location) -> bool { - matches!(l.unpack(), (1, []) | (1, USDC_JUNCTION) | (1, USDT_JUNCTION)) + let funding_assets = [DOTLocation::get(), USDTLocation::get(), USDCLocation::get(), WETHLocation::get()]; + funding_assets.contains(l) } } impl MaybeEquivalence for SupportedAssets { fn convert(asset_id: &Location) -> Option { match asset_id.unpack() { - (1, []) => Some(10), - (1, USDC_JUNCTION) => Some(1337), - (1, USDT_JUNCTION) => Some(1984), + DOT_UNPACKED => Some(10), + USDT_UNPACKED => Some(1984), + USDC_UNPACKED => Some(1337), + WETH_UNPACKED => Some(10_000), _ => None, } } fn convert_back(asset_id: &AssetIdPalletAssets) -> Option { match asset_id { - 10 => Some(DotLocation::get()), - 1337 => Some(UsdcLocation::get()), - 1984 => Some(UsdtLocation::get()), + 10 => Some(DOTLocation::get()), + 1337 => Some(USDCLocation::get()), + 1984 => Some(USDTLocation::get()), + 10_000 => Some(WETHLocation::get()), _ => None, } } @@ -190,6 +213,20 @@ impl Contains<(Location, Vec)> for AssetHubAssetsAsReserve { } } +/// Matches foreign assets from a given origin. +/// Foreign assets are assets bridged from other consensus systems. i.e parents > 1. +pub struct IsBridgedAssetFrom(PhantomData); +impl ContainsPair for IsBridgedAssetFrom +where + Origin: Get, +{ + fn contains(asset: &Asset, origin: &Location) -> bool { + let loc = Origin::get(); + &loc == origin && + matches!(asset, Asset { id: AssetId(Location { parents: 2, .. }), fun: Fungibility::Fungible(_) },) + } +} + /// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance, /// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can /// biases the kind of local `Origin` it will become. diff --git a/runtimes/shared-configuration/src/currency.rs b/runtimes/shared-configuration/src/currency.rs index a8379e918..4d45defbf 100644 --- a/runtimes/shared-configuration/src/currency.rs +++ b/runtimes/shared-configuration/src/currency.rs @@ -90,6 +90,7 @@ impl Convert<(AssetName, FixedU128), (AssetId, Price)> for AssetPriceConverter { AssetName::USDC => (AcceptedFundingAsset::USDC.id(), price), AssetName::USDT => (AcceptedFundingAsset::USDT.id(), price), AssetName::PLMC => (PLMC_FOREIGN_ID, price), + AssetName::WETH => (AcceptedFundingAsset::WETH.id(), price), } } }