Skip to content

Commit

Permalink
Merge pull request #286 from Phala-Network/khala-phala-sygma
Browse files Browse the repository at this point in the history
Enable sygma bridge in khala&phala
  • Loading branch information
jasl committed Jun 19, 2023
2 parents 32ebbb0 + 61dabc8 commit 40d99b5
Show file tree
Hide file tree
Showing 6 changed files with 288 additions and 16 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

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

21 changes: 19 additions & 2 deletions runtime/khala/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ serde = { version = "1.0.132", optional = true, features = ["derive"] }
smallvec = "1.6.1"
static_assertions = "1.1.0"

primitive-types = { version = "0.12", default-features = false, features = ["scale-info", "serde_no_std"] }
hex = { version = "0.4.3", default-features = false }

phala-types = { path = "../../crates/phala-types", default-features = false }
parachains-common = { path = "../../parachains-common", default-features = false }

Expand Down Expand Up @@ -92,8 +95,12 @@ pallet-rmrk-market = { git = "https://github.com/Phala-Network/rmrk-substrate",
rmrk-traits = { git = "https://github.com/Phala-Network/rmrk-substrate", branch = "polkadot-v0.9.42", default-features = false }
pallet-rmrk-rpc-runtime-api = { git = "https://github.com/Phala-Network/rmrk-substrate", branch = "polkadot-v0.9.42", default-features = false }

# Sygma
# Sygma dependencies
sygma-traits = { git = "https://github.com/sygmaprotocol/sygma-substrate-pallets", branch = "polkadot-v0.9.42", default-features = false }
sygma-basic-feehandler = { git = "https://github.com/sygmaprotocol/sygma-substrate-pallets", branch = "polkadot-v0.9.42", default-features = false }
sygma-bridge = { git = "https://github.com/sygmaprotocol/sygma-substrate-pallets", branch = "polkadot-v0.9.42", default-features = false }
sygma-access-segregator = { git = "https://github.com/sygmaprotocol/sygma-substrate-pallets", branch = "polkadot-v0.9.42", default-features = false }
sygma-fee-handler-router = { git = "https://github.com/sygmaprotocol/sygma-substrate-pallets", branch = "polkadot-v0.9.42", default-features = false }
sygma-runtime-api = { git = "https://github.com/sygmaprotocol/sygma-substrate-pallets", branch = "polkadot-v0.9.42", default-features = false }

# Local dependencies
Expand Down Expand Up @@ -219,8 +226,14 @@ std = [
"rmrk-traits/std",
"pallet-rmrk-rpc-runtime-api/std",
"pallet-phala-world/std",
"sygma-runtime-api/std",
"pallet-index/std",
"sygma-basic-feehandler/std",
"sygma-traits/std",
"sygma-bridge/std",
"sygma-access-segregator/std",
"sygma-fee-handler-router/std",
"sygma-runtime-api/std",
"primitive-types/std",
]

try-runtime = [
Expand Down Expand Up @@ -270,6 +283,10 @@ try-runtime = [
"assets-registry/try-runtime",
"phala-pallets/try-runtime",
"pallet-index/try-runtime",
"sygma-basic-feehandler/try-runtime",
"sygma-bridge/try-runtime",
"sygma-access-segregator/try-runtime",
"sygma-fee-handler-router/try-runtime",
]

# A feature that should be enabled when the runtime should be build for on-chain
Expand Down
118 changes: 113 additions & 5 deletions runtime/khala/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ mod msg_routing;

use codec::{Decode, Encode, MaxEncodedLen};
use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases;
use primitive_types::U256;
use sp_api::impl_runtime_apis;
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
use sp_runtime::{
Expand Down Expand Up @@ -132,9 +133,9 @@ pub use phala_pallets::{
pub use sp_runtime::BuildStorage;
pub use subbridge_pallets::{
chainbridge, dynamic_trader::DynamicWeightTrader, fungible_adapter::XTransferAdapter, helper,
xcmbridge, xtransfer,
sygma_wrapper, xcmbridge, xtransfer,
};
use sygma_traits::{DepositNonce, DomainID};
use sygma_traits::{ChainID as SygmaChainID, DepositNonce, DomainID, VerifyingContractAddress};

/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know
/// the specifics of the runtime. They can then be made to be agnostic over specific formats
Expand Down Expand Up @@ -309,7 +310,12 @@ construct_runtime! {
PWIncubation: pallet_pw_incubation::{Pallet, Call, Storage, Event<T>} = 106,
PWMarketplace: pallet_pw_marketplace::{Pallet, Call, Event<T>} = 107,

// 11x kept for Sygma bridge
// Sygma bridge
SygmaAccessSegregator: sygma_access_segregator::{Pallet, Call, Storage, Event<T>} = 111,
SygmaBasicFeeHandler: sygma_basic_feehandler::{Pallet, Call, Storage, Event<T>} = 112,
SygmaBridge: sygma_bridge::{Pallet, Call, Storage, Event<T>} = 113,
SygmaFeeHandlerRouter: sygma_fee_handler_router::{Pallet, Call, Storage, Event<T>} = 114,
SygmaWrapper: sygma_wrapper::{Pallet, Storage, Event<T>} = 115,

// inDEX
PalletIndex: pallet_index::{Pallet, Call, Storage, Event<T>} = 121,
Expand Down Expand Up @@ -390,6 +396,10 @@ impl Contains<RuntimeCall> for BaseCallFilter {
// Monetary
RuntimeCall::Balances { .. } |
RuntimeCall::ChainBridge { .. } |
RuntimeCall::SygmaAccessSegregator { .. } |
RuntimeCall::SygmaBasicFeeHandler { .. } |
RuntimeCall::SygmaFeeHandlerRouter { .. } |
RuntimeCall::SygmaBridge { .. } |
RuntimeCall::XTransfer { .. } |
// Collator
RuntimeCall::CollatorSelection(_) | RuntimeCall::Session(_) |
Expand Down Expand Up @@ -1589,9 +1599,108 @@ impl chainbridge::Config for Runtime {
type ResourceIdGenerationSalt = ResourceIdGenerationSalt;
}

// This address is provided by Sygma bridge
const DEST_VERIFYING_CONTRACT_ADDRESS: &str = "6CdE2Cd82a4F8B74693Ff5e194c19CA08c2d1c68";
parameter_types! {
// Make sure put same value with `construct_runtime`
pub const SygmaAccessSegregatorPalletIndex: u8 = 111;
pub const SygmaBasicFeeHandlerPalletIndex: u8 = 112;
pub const SygmaBridgePalletIndex: u8 = 113;
pub const SygmaFeeHandlerRouterPalletIndex: u8 = 114;
// RegisteredExtrinsics here registers all valid (pallet index, extrinsic_name) paris
// make sure to update this when adding new access control extrinsic
pub RegisteredExtrinsics: Vec<(u8, Vec<u8>)> = [
(SygmaAccessSegregatorPalletIndex::get(), b"grant_access".to_vec()),
(SygmaBasicFeeHandlerPalletIndex::get(), b"set_fee".to_vec()),
(SygmaBridgePalletIndex::get(), b"set_mpc_address".to_vec()),
(SygmaBridgePalletIndex::get(), b"pause_bridge".to_vec()),
(SygmaBridgePalletIndex::get(), b"unpause_bridge".to_vec()),
(SygmaBridgePalletIndex::get(), b"register_domain".to_vec()),
(SygmaBridgePalletIndex::get(), b"unregister_domain".to_vec()),
(SygmaBridgePalletIndex::get(), b"retry".to_vec()),
(SygmaFeeHandlerRouterPalletIndex::get(), b"set_fee_handler".to_vec()),
].to_vec();
pub const SygmaBridgePalletId: PalletId = PalletId(*b"sygma/01");
// SygmaBridgeAccount is an account for holding transferred asset collection
// SygmaBridgeAccount address: 5EYCAe5jLbHcAAMKvLFSXgCTbPrLgBJusvPwfKcaKzuf5X5e
pub SygmaBridgeAccount: AccountId = SygmaBridgePalletId::get().into_account_truncating();
// SygmaBridgeFeeAccountKey Address: 44bdQyeqk5oJzxbZH9xMcovmj3oAxqzSjKujaVhHaZxZuTBH
pub SygmaBridgeFeeAccountKey: [u8; 32] = hex_literal::hex!("b00e3e4afb5a9c54036ec6c1775881031fb26b72427a10724c4d8b91099ee889");
pub SygmaBridgeFeeAccount: AccountId = SygmaBridgeFeeAccountKey::get().into();
// SygmaBridgeAdminAccountKey Address: 44bdQyeqk5oJzxbZH9xMcovmj3oAxqzSjKujaVhHaZxZuTBH
pub SygmaBridgeAdminAccountKey: [u8; 32] = hex_literal::hex!("b00e3e4afb5a9c54036ec6c1775881031fb26b72427a10724c4d8b91099ee889");
pub SygmaBridgeAdminAccount: AccountId = SygmaBridgeAdminAccountKey::get().into();
// EIP712ChainID is the chainID that pallet is assigned with, used in EIP712 typed data domain
pub EIP712ChainID: SygmaChainID = U256::from(5232);
// 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 struct SygmaAdminMembers;
impl SortedMembers<AccountId> for SygmaAdminMembers {
fn sorted_members() -> Vec<AccountId> {
[SygmaBridgeAdminAccount::get()].to_vec()
}
}

impl sygma_access_segregator::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type BridgeCommitteeOrigin = EnsureSignedBy<SygmaAdminMembers, AccountId>;
type PalletIndex = SygmaAccessSegregatorPalletIndex;
type Extrinsics = RegisteredExtrinsics;
type WeightInfo = sygma_access_segregator::weights::SygmaWeightInfo<Runtime>;
}

impl sygma_basic_feehandler::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type PalletIndex = SygmaBasicFeeHandlerPalletIndex;
type WeightInfo = sygma_basic_feehandler::weights::SygmaWeightInfo<Runtime>;
}

impl sygma_fee_handler_router::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type BasicFeeHandler = SygmaBasicFeeHandler;
type DynamicFeeHandler = ();
type PalletIndex = SygmaFeeHandlerRouterPalletIndex;
type WeightInfo = sygma_fee_handler_router::weights::SygmaWeightInfo<Runtime>;
}

impl sygma_bridge::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type TransferReserveAccount = SygmaBridgeAccount;
type FeeReserveAccount = SygmaBridgeFeeAccount;
type EIP712ChainID = EIP712ChainID;
type DestVerifyingContractAddress = DestVerifyingContractAddress;
type FeeHandler = SygmaFeeHandlerRouter;
type AssetTransactor = XTransferAdapter<
CurrencyTransactor,
FungiblesTransactor,
XTransfer,
assets_registry::NativeAssetFilter<ParachainInfo>,
assets_registry::ReserveAssetFilter<
ParachainInfo,
assets_registry::NativeAssetFilter<ParachainInfo>,
>,
>;
type ResourcePairs = AssetsRegistry;
type IsReserve = assets_registry::SygmaAssetReserveChecker<ParachainInfo>;
type ExtractDestData = SygmaWrapper;
type PalletId = SygmaBridgePalletId;
type PalletIndex = SygmaBridgePalletIndex;
type DecimalConverter = assets_registry::SygmaDecimalConverter<AssetsRegistry>;
type WeightInfo = sygma_bridge::weights::SygmaWeightInfo<Runtime>;
}

impl sygma_wrapper::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
}

impl xtransfer::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Bridge = (
sygma_wrapper::BridgeTransactImpl<Runtime>,
xcmbridge::BridgeTransactImpl<Runtime>,
chainbridge::BridgeTransactImpl<Runtime>,
);
Expand Down Expand Up @@ -2012,8 +2121,7 @@ impl_runtime_apis! {

impl sygma_runtime_api::SygmaBridgeApi<Block> for Runtime {
fn is_proposal_executed(nonce: DepositNonce, domain_id: DomainID) -> bool {
// TODO: enable Sygma
false
SygmaBridge::is_proposal_executed(nonce, domain_id)
}
}

Expand Down
21 changes: 19 additions & 2 deletions runtime/phala/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ hex-literal = "0.4.1"
smallvec = "1.6.1"
static_assertions = "1.1.0"

primitive-types = { version = "0.12", default-features = false, features = ["scale-info", "serde_no_std"] }
hex = { version = "0.4.3", default-features = false }

phala-types = { path = "../../crates/phala-types", default-features = false }
parachains-common = { path = "../../parachains-common", default-features = false }

Expand Down Expand Up @@ -92,8 +95,12 @@ pallet-rmrk-market = { git = "https://github.com/Phala-Network/rmrk-substrate",
rmrk-traits = { git = "https://github.com/Phala-Network/rmrk-substrate", branch = "polkadot-v0.9.42", default-features = false }
pallet-rmrk-rpc-runtime-api = { git = "https://github.com/Phala-Network/rmrk-substrate", branch = "polkadot-v0.9.42", default-features = false }

# Sygma
# Sygma dependencies
sygma-traits = { git = "https://github.com/sygmaprotocol/sygma-substrate-pallets", branch = "polkadot-v0.9.42", default-features = false }
sygma-basic-feehandler = { git = "https://github.com/sygmaprotocol/sygma-substrate-pallets", branch = "polkadot-v0.9.42", default-features = false }
sygma-bridge = { git = "https://github.com/sygmaprotocol/sygma-substrate-pallets", branch = "polkadot-v0.9.42", default-features = false }
sygma-access-segregator = { git = "https://github.com/sygmaprotocol/sygma-substrate-pallets", branch = "polkadot-v0.9.42", default-features = false }
sygma-fee-handler-router = { git = "https://github.com/sygmaprotocol/sygma-substrate-pallets", branch = "polkadot-v0.9.42", default-features = false }
sygma-runtime-api = { git = "https://github.com/sygmaprotocol/sygma-substrate-pallets", branch = "polkadot-v0.9.42", default-features = false }

# Local dependencies
Expand Down Expand Up @@ -212,13 +219,19 @@ std = [
"pallet-mq-runtime-api/std",
"assets-registry/std",
"subbridge-pallets/std",
"sygma-runtime-api/std",
"pallet-rmrk-core/std",
"pallet-rmrk-market/std",
"pallet-rmrk-equip/std",
"rmrk-traits/std",
"pallet-rmrk-rpc-runtime-api/std",
"pallet-index/std",
"sygma-basic-feehandler/std",
"sygma-traits/std",
"sygma-bridge/std",
"sygma-access-segregator/std",
"sygma-fee-handler-router/std",
"sygma-runtime-api/std",
"primitive-types/std",
]

try-runtime = [
Expand Down Expand Up @@ -267,6 +280,10 @@ try-runtime = [
"assets-registry/try-runtime",
"phala-pallets/try-runtime",
"pallet-index/try-runtime",
"sygma-basic-feehandler/try-runtime",
"sygma-bridge/try-runtime",
"sygma-access-segregator/try-runtime",
"sygma-fee-handler-router/try-runtime",
]

# A feature that should be enabled when the runtime should be build for on-chain
Expand Down
Loading

0 comments on commit 40d99b5

Please sign in to comment.