Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Chralt98 committed Aug 8, 2023
1 parent a40b13f commit defb1f9
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 86 deletions.
5 changes: 2 additions & 3 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
36 changes: 23 additions & 13 deletions runtime/battery-station/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions runtime/battery-station/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
17 changes: 8 additions & 9 deletions runtime/battery-station/src/parachain_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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! {
Expand Down
66 changes: 27 additions & 39 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AccountId> for SygmaAdminMembers {
fn sorted_members() -> Vec<AccountId> {
Expand All @@ -1210,39 +1223,32 @@ macro_rules! impl_config_traits {
type BridgeCommitteeOrigin = EnsureSignedBy<SygmaAdminMembers, AccountId>;
type PalletIndex = SygmaAccessSegregatorPalletIndex;
type Extrinsics = RegisteredExtrinsics;
type WeightInfo = sygma_access_segregator::weights::SygmaWeightInfo<Runtime>;
}

#[cfg(feature = "parachain")]
impl sygma_basic_feehandler::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type BridgeCommitteeOrigin = EnsureSignedBy<SygmaAdminMembers, AccountId>;
type PalletIndex = SygmaBasicFeeHandlerPalletIndex;
type WeightInfo = sygma_basic_feehandler::weights::SygmaWeightInfo<Runtime>;
}

#[cfg(feature = "parachain")]
impl sygma_fee_handler_router::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type BridgeCommitteeOrigin = EnsureSignedBy<SygmaAdminMembers, AccountId>;
type BasicFeeHandler = SygmaBasicFeeHandler;
type DynamicFeeHandler = ();
type PalletIndex = SygmaFeeHandlerRouterPalletIndex;
type WeightInfo = sygma_fee_handler_router::weights::SygmaWeightInfo<Runtime>;
}

#[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<T: Config> Get<Vec<(XcmAssetId, SygmaResourceId)>> for SygmaResourcePairs {
impl Get<Vec<(XcmAssetId, SygmaResourceId)>> 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
Expand All @@ -1252,19 +1258,13 @@ 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];

#[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<u8>, DomainID)> {
match (dest.parents, &dest.interior) {
Expand All @@ -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
}
Expand All @@ -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<u128> {
match (&asset.fun, &asset.id) {
(Fungible(amount), XcmAssetId::Concrete(location)) => {
(Fungibility::Fungible(amount), XcmAssetId::Concrete(location)) => {
let metadata = <orml_asset_registry::Pallet<Runtime> as orml_traits::asset_registry::Inspect>::metadata_by_location(location)?;
let decimals = metadata.decimals;

Expand Down Expand Up @@ -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(
Expand All @@ -1344,7 +1339,7 @@ macro_rules! impl_config_traits {

fn convert_from(asset: &MultiAsset) -> Option<MultiAsset> {
match (&asset.fun, &asset.id) {
(Fungible(amount), XcmAssetId::Concrete(location)) => {
(Fungibility::Fungible(amount), XcmAssetId::Concrete(location)) => {
let metadata = <orml_asset_registry::Pallet<Runtime> as orml_traits::asset_registry::Inspect>::metadata_by_location(location)?;
let decimals = metadata.decimals;
let native_decimals: u32 = BalanceFractionalDecimals::get().into();
Expand All @@ -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(
Expand All @@ -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<SygmaAdminMembers, AccountId>;
type TransferReserveAccount = SygmaBridgeAccount;
type FeeReserveAccount = SygmaBridgeFeeAccount;
type EIP712ChainID = EIP712ChainID;
Expand All @@ -1408,7 +1397,6 @@ macro_rules! impl_config_traits {
type PalletId = SygmaBridgePalletId;
type PalletIndex = SygmaBridgePalletIndex;
type DecimalConverter = SygmaDecimalConverter;
type WeightInfo = sygma_bridge::weights::SygmaWeightInfo<Runtime>;
}
}
}
Expand Down
26 changes: 13 additions & 13 deletions runtime/zeitgeist/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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",
Expand Down
7 changes: 6 additions & 1 deletion runtime/zeitgeist/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
Loading

0 comments on commit defb1f9

Please sign in to comment.