diff --git a/Cargo.lock b/Cargo.lock index ccbe2af5b..2435f4575 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3421,11 +3421,10 @@ dependencies = [ [[package]] name = "half" -version = "2.3.1" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc52e53916c08643f1b56ec082790d1e86a32e58dc5268f897f313fbae7b4872" +checksum = "02b4af3693f1b705df946e9fe5631932443781d0aabb423b62fcd4d73f6d2fd0" dependencies = [ - "cfg-if", "crunchy", ] diff --git a/node/src/rpc.rs b/node/src/rpc.rs index 6146ff56f..70a90d0dc 100644 --- a/node/src/rpc.rs +++ b/node/src/rpc.rs @@ -62,8 +62,8 @@ where { use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer}; use substrate_frame_rpc_system::{System, SystemApiServer}; - use zrml_swaps_rpc::{Swaps, SwapsApiServer}; use sygma_rpc::{SygmaBridgeRpcServer, SygmaBridgeStorage}; + use zrml_swaps_rpc::{Swaps, SwapsApiServer}; let mut io = RpcModule::new(()); let FullDeps { client, pool, deny_unsafe } = deps; diff --git a/runtime/battery-station/Cargo.toml b/runtime/battery-station/Cargo.toml index a7610a068..44f304d9d 100644 --- a/runtime/battery-station/Cargo.toml +++ b/runtime/battery-station/Cargo.toml @@ -48,12 +48,12 @@ sp-version = { workspace = true } substrate-fixed = { workspace = true, features = ["serde"] } # Sygma Bridge -sygma-traits = { workspace = true } -sygma-basic-feehandler = { workspace = true } -sygma-bridge = { workspace = true } -sygma-access-segregator = { workspace = true } -sygma-fee-handler-router = { workspace = true } -sygma-runtime-api = { workspace = true } +sygma-traits = { workspace = true, optional = true } +sygma-basic-feehandler = { workspace = true, optional = true } +sygma-bridge = { workspace = true, optional = true } +sygma-access-segregator = { workspace = true, optional = true } +sygma-fee-handler-router = { workspace = true, optional = true } +sygma-runtime-api = { workspace = true, optional = true } # Try-Runtime @@ -138,6 +138,16 @@ xcm-emulator = { workspace = true } default = ["std"] parachain = [ "zrml-prediction-markets/parachain", + + # Sygma + + "sygma-traits", + "sygma-basic-feehandler", + "sygma-bridge", + "sygma-access-segregator", + "sygma-fee-handler-router", + "sygma-runtime-api", + # Cumulus "cumulus-pallet-dmp-queue", @@ -269,12 +279,12 @@ std = [ "substrate-fixed/std", # Sygma Bridge - "sygma-basic-feehandler/std", - "sygma-traits/std", - "sygma-bridge/std", - "sygma-access-segregator/std", - "sygma-fee-handler-router/std", - "sygma-runtime-api/std", + "sygma-basic-feehandler?/std", + "sygma-traits?/std", + "sygma-bridge?/std", + "sygma-access-segregator?/std", + "sygma-fee-handler-router?/std", + "sygma-runtime-api?/std", # Try-Runtime "frame-try-runtime/std", @@ -385,7 +395,7 @@ try-runtime = [ "orml-xtokens?/try-runtime", # Sygma Bridge - "sygma-bridge/try-runtime", + "sygma-bridge?/try-runtime", # Zeitgeist runtime pallets "zrml-authorized/try-runtime", diff --git a/runtime/battery-station/src/lib.rs b/runtime/battery-station/src/lib.rs index bc5e531dd..b59158187 100644 --- a/runtime/battery-station/src/lib.rs +++ b/runtime/battery-station/src/lib.rs @@ -54,6 +54,8 @@ use sp_runtime::{ }; #[cfg(feature = "std")] use sp_version::NativeVersion; +#[cfg(feature = "parachain")] +use substrate_fixed::types::extra::U16; use substrate_fixed::{types::extra::U33, FixedI128, FixedU128}; use zeitgeist_primitives::{constants::*, types::*}; use zrml_prediction_markets::Call::{ diff --git a/runtime/battery-station/src/parachain_params.rs b/runtime/battery-station/src/parachain_params.rs index 04d5ace4f..ffbdcb001 100644 --- a/runtime/battery-station/src/parachain_params.rs +++ b/runtime/battery-station/src/parachain_params.rs @@ -26,17 +26,16 @@ extern crate alloc; -use alloc::vec::Vec; -use frame_support::PalletId; use super::{parameters::MAXIMUM_BLOCK_WEIGHT, ParachainInfo, RuntimeOrigin}; -use frame_support::{parameter_types, weights::Weight}; +use alloc::vec::Vec; +use frame_support::{parameter_types, weights::Weight, PalletId}; use orml_traits::parameter_type_with_key; -use sp_runtime::{Perbill, Percent}; -use sygma_types::{ChainID as SygmaChainID, VerifyingContractAddress}; +use sp_runtime::{traits::AccountIdConversion, Perbill, Percent}; +use sygma_traits::{ChainID, VerifyingContractAddress}; use xcm::latest::{prelude::X1, Junction::Parachain, MultiLocation, NetworkId}; use zeitgeist_primitives::{ constants::{BASE, BLOCKS_PER_MINUTE}, - types::{Balance, AccountId}, + types::{AccountId, Balance}, }; // This address is defined in the substrate E2E test of sygma-relayer @@ -105,7 +104,7 @@ parameter_types! { // Sygma bridge pub NativeAssetLocation: MultiLocation = MultiLocation::here(); // TODO this is the resource id of Phala currently - pub NativeAssetSygmaResourceId: [u8; 32] = hex_literal::hex!("0000000000000000000000000000000000000000000000000000000000000001"); + pub NativeAssetSygmaResourceId: [u8; 32] = hex_literal::hex!("0000000000000000000000000000000000000000000000000000000000000001"); // Make sure put same value with `construct_runtime` pub const SygmaAccessSegregatorPalletIndex: u8 = 140; pub const SygmaBasicFeeHandlerPalletIndex: u8 = 141; @@ -138,11 +137,11 @@ parameter_types! { pub SygmaBridgeAdminAccount: AccountId = SygmaBridgeAdminAccountKey::get().into(); // TODO: How should the EIP712Chain id look like? Is it controlled by Zeitgeist? // EIP712ChainID is the chainID that pallet is assigned with, used in EIP712 typed data domain - pub EIP712ChainID: SygmaChainID = sp_core::U256::from(5233); + pub EIP712ChainID: ChainID = sp_core::U256::from(5233); // DestVerifyingContractAddress is a H160 address that is used in proposal signature verification, specifically EIP712 typed data // When relayers signing, this address will be included in the EIP712Domain // As long as the relayer and pallet configured with the same address, EIP712Domain should be recognized properly. - pub DestVerifyingContractAddress: VerifyingContractAddress = primitive_types::H160::from_slice(hex::decode(DEST_VERIFYING_CONTRACT_ADDRESS).ok().unwrap().as_slice()); + pub DestVerifyingContractAddress: VerifyingContractAddress = sp_core::H160::from_slice(hex::decode(DEST_VERIFYING_CONTRACT_ADDRESS).ok().unwrap().as_slice()); } parameter_type_with_key! { diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index 516cccd81..6b68d2e49 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -1193,10 +1193,23 @@ macro_rules! impl_config_traits { } #[cfg(feature = "parachain")] - pub struct SygmaAdminMembers; + use { + frame_support::traits::SortedMembers, + xcm::latest::{AssetId as XcmAssetId, Fungibility}, + sygma_traits::ResourceId as SygmaResourceId, + sp_runtime::traits::Get, + xcm::latest::{MultiAsset, MultiLocation}, + sygma_traits::{ExtractDestinationData, DomainID}, + sygma_traits::DecimalConverter, + orml_xcm_support::MultiNativeAsset, + orml_traits::location::AbsoluteReserveProvider, + frame_system::EnsureSignedBy, + xcm::opaque::latest::{Junctions, Junction::{GeneralKey, GeneralIndex}}, + }; #[cfg(feature = "parachain")] - use frame_support::traits::SortedMembers; + pub struct SygmaAdminMembers; + #[cfg(feature = "parachain")] impl SortedMembers for SygmaAdminMembers { fn sorted_members() -> Vec { @@ -1210,39 +1223,32 @@ macro_rules! impl_config_traits { type BridgeCommitteeOrigin = EnsureSignedBy; type PalletIndex = SygmaAccessSegregatorPalletIndex; type Extrinsics = RegisteredExtrinsics; - type WeightInfo = sygma_access_segregator::weights::SygmaWeightInfo; } #[cfg(feature = "parachain")] impl sygma_basic_feehandler::Config for Runtime { type RuntimeEvent = RuntimeEvent; + type BridgeCommitteeOrigin = EnsureSignedBy; type PalletIndex = SygmaBasicFeeHandlerPalletIndex; - type WeightInfo = sygma_basic_feehandler::weights::SygmaWeightInfo; } #[cfg(feature = "parachain")] impl sygma_fee_handler_router::Config for Runtime { type RuntimeEvent = RuntimeEvent; + type BridgeCommitteeOrigin = EnsureSignedBy; type BasicFeeHandler = SygmaBasicFeeHandler; type DynamicFeeHandler = (); type PalletIndex = SygmaFeeHandlerRouterPalletIndex; - type WeightInfo = sygma_fee_handler_router::weights::SygmaWeightInfo; } - #[cfg(feature = "parachain")] - use xcm::latest::AssetId as XcmAssetId; - #[cfg(feature = "parachain")] - use sygma_traits::ResourceId as SygmaResourceId; - #[cfg(feature = "parachain")] - use sp_runtime::traits::Get; #[cfg(feature = "parachain")] struct SygmaResourcePairs; #[cfg(feature = "parachain")] - impl Get> for SygmaResourcePairs { + impl Get> for SygmaResourcePairs { fn get() -> Vec<(XcmAssetId, SygmaResourceId)> { let mut pairs: Vec<(XcmAssetId, SygmaResourceId)> = vec![( - Concrete(T::NativeAssetLocation::get()).into(), - T::NativeAssetSygmaResourceId::get(), + XcmAssetId::Concrete(NativeAssetLocation::get()), + NativeAssetSygmaResourceId::get(), )]; // TODO add USDC as it is ready on the sygma side @@ -1252,10 +1258,6 @@ macro_rules! impl_config_traits { } } - #[cfg(feature = "parachain")] - use xcm::latest::{MultiAsset, MultiLocation}; - #[cfg(feature = "parachain")] - use sygma_traits::{ExtractDestinationData, DomainID}; /// const used to indicate sygma bridge path. str "sygma" #[cfg(feature = "parachain")] pub const SYGMA_PATH_KEY: &[u8] = &[0x73, 0x79, 0x67, 0x6d, 0x61]; @@ -1263,8 +1265,6 @@ macro_rules! impl_config_traits { #[cfg(feature = "parachain")] struct SygmaDestination; #[cfg(feature = "parachain")] - use xcm::opaque::latest::{Junctions, Junction::{GeneralKey, GeneralIndex}}; - #[cfg(feature = "parachain")] impl ExtractDestinationData for SygmaDestination { fn extract_dest(dest: &MultiLocation) -> Option<(Vec, DomainID)> { match (dest.parents, &dest.interior) { @@ -1277,7 +1277,7 @@ macro_rules! impl_config_traits { ), ) => { if sygma_path.clone().into_inner() == SYGMA_PATH_KEY.to_vec() { - return Some((recipient.to_vec(), dest_domain_id.as_u8())); + return Some((recipient.to_vec(), *dest_domain_id as u8)); } None } @@ -1286,20 +1286,15 @@ macro_rules! impl_config_traits { } } - #[cfg(feature = "parachain")] - use sygma_traits::DecimalConverter; - // TODO is an implementation for this even needed? because we saved all XCM incoming assets already in orml_tokens with a base of the native currency (base ten) + // TODO is an implementation for this even needed? because we saved all XCM incoming assets already in orml_tokens with a base of the native currency (base ten) #[cfg(feature = "parachain")] struct SygmaDecimalConverter; - #[cfg(feature = "parachain")] - use fixed::{types::extra::U16, FixedU128}; - #[cfg(feature = "parachain")] impl DecimalConverter for SygmaDecimalConverter { fn convert_to(asset: &MultiAsset) -> Option { match (&asset.fun, &asset.id) { - (Fungible(amount), XcmAssetId::Concrete(location)) => { + (Fungibility::Fungible(amount), XcmAssetId::Concrete(location)) => { let metadata = as orml_traits::asset_registry::Inspect>::metadata_by_location(location)?; let decimals = metadata.decimals; @@ -1328,7 +1323,7 @@ macro_rules! impl_config_traits { // Max is 5192296858534827628530496329220095 // if source asset decimal is 12, the max amount sending to sygma // relayer is 5192296858534827.628530496329 - if *amount > U112F16::MAX { + if *amount > U112F16::max_value() { return None; } let a = U112F16::from_num( @@ -1344,7 +1339,7 @@ macro_rules! impl_config_traits { fn convert_from(asset: &MultiAsset) -> Option { match (&asset.fun, &asset.id) { - (Fungible(amount), XcmAssetId::Concrete(location)) => { + (Fungibility::Fungible(amount), XcmAssetId::Concrete(location)) => { let metadata = as orml_traits::asset_registry::Inspect>::metadata_by_location(location)?; let decimals = metadata.decimals; let native_decimals: u32 = BalanceFractionalDecimals::get().into(); @@ -1359,7 +1354,7 @@ macro_rules! impl_config_traits { // Max is 5192296858534827628530496329220095 // if dest asset decimal is 24, the max amount coming from sygma // relayer is 5192296858.534827628530496329 - if *amount > U112F16::MAX { + if *amount > U112F16::max_value() { return None; } let a = U112F16::from_num( @@ -1386,16 +1381,10 @@ macro_rules! impl_config_traits { } } - #[cfg(feature = "parachain")] - use orml_xcm_support::MultiNativeAsset; - #[cfg(feature = "parachain")] - use orml_traits::location::AbsoluteReserveProvider; - #[cfg(feature = "parachain")] - use frame_system::EnsureSignedBy; - #[cfg(feature = "parachain")] impl sygma_bridge::Config for Runtime { type RuntimeEvent = RuntimeEvent; + type BridgeCommitteeOrigin = EnsureSignedBy; type TransferReserveAccount = SygmaBridgeAccount; type FeeReserveAccount = SygmaBridgeFeeAccount; type EIP712ChainID = EIP712ChainID; @@ -1408,7 +1397,6 @@ macro_rules! impl_config_traits { type PalletId = SygmaBridgePalletId; type PalletIndex = SygmaBridgePalletIndex; type DecimalConverter = SygmaDecimalConverter; - type WeightInfo = sygma_bridge::weights::SygmaWeightInfo; } } } diff --git a/runtime/zeitgeist/Cargo.toml b/runtime/zeitgeist/Cargo.toml index 8f8b5dced..f5efd5785 100644 --- a/runtime/zeitgeist/Cargo.toml +++ b/runtime/zeitgeist/Cargo.toml @@ -46,12 +46,12 @@ sp-version = { workspace = true } substrate-fixed = { workspace = true, features = ["serde"] } # Sygma Bridge -sygma-traits = { workspace = true } -sygma-basic-feehandler = { workspace = true } -sygma-bridge = { workspace = true } -sygma-access-segregator = { workspace = true } -sygma-fee-handler-router = { workspace = true } -sygma-runtime-api = { workspace = true } +sygma-traits = { workspace = true, optional = true } +sygma-basic-feehandler = { workspace = true, optional = true } +sygma-bridge = { workspace = true, optional = true } +sygma-access-segregator = { workspace = true, optional = true } +sygma-fee-handler-router = { workspace = true, optional = true } +sygma-runtime-api = { workspace = true, optional = true } # Try-Runtime @@ -266,12 +266,12 @@ std = [ "substrate-fixed/std", # Sygma Bridge - "sygma-basic-feehandler/std", - "sygma-traits/std", - "sygma-bridge/std", - "sygma-access-segregator/std", - "sygma-fee-handler-router/std", - "sygma-runtime-api/std", + "sygma-basic-feehandler?/std", + "sygma-traits?/std", + "sygma-bridge?/std", + "sygma-access-segregator?/std", + "sygma-fee-handler-router?/std", + "sygma-runtime-api?/std", # Benchmark @@ -374,7 +374,7 @@ try-runtime = [ "orml-xtokens?/try-runtime", # Sygma Bridge - "sygma-bridge/try-runtime", + "sygma-bridge?/try-runtime", # Zeitgeist runtime pallets "zrml-authorized/try-runtime", diff --git a/runtime/zeitgeist/src/lib.rs b/runtime/zeitgeist/src/lib.rs index f93350959..ec99b6a91 100644 --- a/runtime/zeitgeist/src/lib.rs +++ b/runtime/zeitgeist/src/lib.rs @@ -52,7 +52,12 @@ use sp_runtime::{ }; #[cfg(feature = "std")] use sp_version::NativeVersion; -use substrate_fixed::{types::extra::U33, FixedI128, FixedU128}; +#[cfg(feature = "parachain")] +use substrate_fixed::types::extra::U16; +use substrate_fixed::{ + types::extra::{U33}, + FixedI128, FixedU128, +}; use zeitgeist_primitives::{constants::*, types::*}; use zrml_rikiddo::types::{EmaMarketVolume, FeeSigmoid, RikiddoSigmoidMV}; #[cfg(feature = "parachain")] diff --git a/runtime/zeitgeist/src/parachain_params.rs b/runtime/zeitgeist/src/parachain_params.rs index 0b7125dce..4e0fed9d3 100644 --- a/runtime/zeitgeist/src/parachain_params.rs +++ b/runtime/zeitgeist/src/parachain_params.rs @@ -24,11 +24,14 @@ )] #![cfg(feature = "parachain")] -use super::{parameters::MAXIMUM_BLOCK_WEIGHT, ParachainInfo, RuntimeOrigin}; -use frame_support::{parameter_types, weights::Weight}; +extern crate alloc; + +use super::{parameters::MAXIMUM_BLOCK_WEIGHT, AccountId, ParachainInfo, RuntimeOrigin}; +use alloc::vec::Vec; +use frame_support::{parameter_types, weights::Weight, PalletId}; use orml_traits::parameter_type_with_key; -use sp_runtime::{Perbill, Percent}; -use sygma_types::{ChainID as SygmaChainID, VerifyingContractAddress}; +use sp_runtime::{traits::AccountIdConversion, Perbill, Percent}; +use sygma_traits::{ChainID, VerifyingContractAddress}; use xcm::latest::{prelude::X1, Junction::Parachain, MultiLocation, NetworkId}; use zeitgeist_primitives::{ constants::{BASE, BLOCKS_PER_MINUTE}, @@ -101,7 +104,7 @@ parameter_types! { // Sygma bridge pub NativeAssetLocation: MultiLocation = MultiLocation::here(); // TODO this is the resource id of Phala currently - pub NativeAssetSygmaResourceId: [u8; 32] = hex_literal::hex!("0000000000000000000000000000000000000000000000000000000000000001"); + pub NativeAssetSygmaResourceId: [u8; 32] = hex_literal::hex!("0000000000000000000000000000000000000000000000000000000000000001"); // Make sure put same value with `construct_runtime` pub const SygmaAccessSegregatorPalletIndex: u8 = 140; pub const SygmaBasicFeeHandlerPalletIndex: u8 = 141; @@ -134,11 +137,11 @@ parameter_types! { pub SygmaBridgeAdminAccount: AccountId = SygmaBridgeAdminAccountKey::get().into(); // TODO: How should the EIP712Chain id look like? Is it controlled by Zeitgeist? // EIP712ChainID is the chainID that pallet is assigned with, used in EIP712 typed data domain - pub EIP712ChainID: SygmaChainID = U256::from(5233); + pub EIP712ChainID: ChainID = sp_core::U256::from(5233); // DestVerifyingContractAddress is a H160 address that is used in proposal signature verification, specifically EIP712 typed data // When relayers signing, this address will be included in the EIP712Domain // As long as the relayer and pallet configured with the same address, EIP712Domain should be recognized properly. - pub DestVerifyingContractAddress: VerifyingContractAddress = primitive_types::H160::from_slice(hex::decode(DEST_VERIFYING_CONTRACT_ADDRESS).ok().unwrap().as_slice()); + pub DestVerifyingContractAddress: VerifyingContractAddress = sp_core::H160::from_slice(hex::decode(DEST_VERIFYING_CONTRACT_ADDRESS).ok().unwrap().as_slice()); } parameter_type_with_key! {