Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fee manager #23

Merged
merged 22 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ hex-literal = "0.4.1"
sp-core = { path = "../../../../../../substrate/primitives/core", default-features = false}
frame-support = { path = "../../../../../../substrate/frame/support", default-features = false }
pallet-assets = { path = "../../../../../../substrate/frame/assets", default-features = false }
pallet-balances = { path = "../../../../../../substrate/frame/balances", default-features = false }

# Polkadot
polkadot-core-primitives = { path = "../../../../../../polkadot/core-primitives", default-features = false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::*;
use hex_literal::hex;
use integration_tests_common::{AssetHubRococoPallet, BridgeHubRococoPallet};
Expand All @@ -25,6 +24,8 @@ const CHAIN_ID: u64 = 15;
const DEST_PARA_ID: u32 = 1000;
const SNOWBRIDGE_SOVEREIGN: [u8; 32] =
hex!("da4d66c3651dc151264eee5460493210338e41a7bbfca91a520e438daf180bf5");
const TREASURY_ACCOUNT: [u8; 32] =
hex!("6d6f646c70792f74727372790000000000000000000000000000000000000000");
const WETH: [u8; 20] = hex!("87d1f7fdfEe7f651FaBc8bFCB6E086C278b77A7d");
const ASSETHUB_SOVEREIGN: [u8; 32] =
hex!("7369626ce8030000000000000000000000000000000000000000000000000000");
Expand Down Expand Up @@ -385,5 +386,24 @@ fn reserve_transfer_token() {
RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::Success { .. }) => {},
]
);
let events = BridgeHubRococo::events();
assert!(
events.iter().find(|&event| matches!(
event,
RuntimeEvent::Balances(pallet_balances::Event::Deposit{ who, amount })
if *who == TREASURY_ACCOUNT.into() && *amount == 16903333
))
.is_some(),
"Snowbridge sovereign takes local fee."
);
assert!(
events.iter().find(|&event| matches!(
event,
RuntimeEvent::Balances(pallet_balances::Event::Deposit{ who, amount })
if *who == ASSETHUB_SOVEREIGN.into() && *amount == 2200000000000
))
.is_some(),
"Assethub sovereign takes remote fee."
);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,16 @@ pallet-bridge-relayers = { path = "../../../../../bridges/modules/relayers", def
bridge-runtime-common = { path = "../../../../../bridges/bin/runtime-common", default-features = false }

# Ethereum Bridge (Snowbridge)
snowbridge-core = { path = "../../../../../../parachain/primitives/core", default-features = false }
snowbridge-beacon-primitives = { path = "../../../../../../parachain/primitives/beacon", default-features = false }
snowbridge-router-primitives = { path = "../../../../../../parachain/primitives/router", default-features = false }
snowbridge-control = { path = "../../../../../../parachain/pallets/control", default-features = false }
snowbridge-control-runtime-api = { path = "../../../../../../parachain/pallets/control/runtime-api", default-features = false }
snowbridge-core = { path = "../../../../../../parachain/primitives/core", default-features = false }
snowbridge-ethereum-beacon-client = { path = "../../../../../../parachain/pallets/ethereum-beacon-client", default-features = false }
snowbridge-inbound-queue = { path = "../../../../../../parachain/pallets/inbound-queue", default-features = false }
snowbridge-outbound-queue = { path = "../../../../../../parachain/pallets/outbound-queue", default-features = false }
snowbridge-outbound-queue-runtime-api = { path = "../../../../../../parachain/pallets/outbound-queue/runtime-api", default-features = false }
snowbridge-control = { path = "../../../../../../parachain/pallets/control", default-features = false }
snowbridge-control-runtime-api = { path = "../../../../../../parachain/pallets/control/runtime-api", default-features = false }
snowbridge-router-primitives = { path = "../../../../../../parachain/primitives/router", default-features = false }
snowbridge-runtime-common = { path = "../../../../../../parachain/primitives/runtime-common", default-features = false }

[dev-dependencies]
static_assertions = "1.1"
Expand Down Expand Up @@ -186,15 +187,16 @@ std = [
"xcm-builder/std",
"xcm-executor/std",
"xcm/std",
"snowbridge-core/std",
"snowbridge-router-primitives/std",
"snowbridge-beacon-primitives/std",
"snowbridge-control-runtime-api/std",
"snowbridge-control/std",
"snowbridge-core/std",
"snowbridge-ethereum-beacon-client/std",
"snowbridge-inbound-queue/std",
"snowbridge-outbound-queue/std",
"snowbridge-outbound-queue-runtime-api/std",
"snowbridge-control/std",
"snowbridge-control-runtime-api/std",
"snowbridge-outbound-queue/std",
"snowbridge-router-primitives/std",
"snowbridge-runtime-common/std",
"substrate-wasm-builder",
]

Expand Down Expand Up @@ -225,11 +227,12 @@ runtime-benchmarks = [
"sp-runtime/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
"xcm-executor/runtime-benchmarks",
"snowbridge-core/runtime-benchmarks",
"snowbridge-control/runtime-benchmarks",
"snowbridge-core/runtime-benchmarks",
"snowbridge-ethereum-beacon-client/runtime-benchmarks",
"snowbridge-inbound-queue/runtime-benchmarks",
"snowbridge-outbound-queue/runtime-benchmarks",
"snowbridge-ethereum-beacon-client/runtime-benchmarks"
"snowbridge-runtime-common/runtime-benchmarks",
]

try-runtime = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use sp_api::impl_runtime_apis;
use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H160};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{AccountIdConversion, AccountIdLookup, BlakeTwo256, Block as BlockT, Keccak256},
traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, Keccak256},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult,
};
Expand Down Expand Up @@ -86,7 +86,7 @@ use pallet_xcm::EnsureXcm;
pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
pub use sp_runtime::{MultiAddress, Perbill, Permill};
use xcm::VersionedMultiLocation;
use xcm_config::{XcmConfig, XcmOriginToTransactDispatchOrigin};
use xcm_config::{TreasuryAccount, XcmConfig, XcmOriginToTransactDispatchOrigin};

use bp_runtime::HeaderId;

Expand Down Expand Up @@ -604,10 +604,6 @@ parameter_types! {
pub const RelayNetwork: NetworkId = Rococo;
}

parameter_types! {
pub TreasuryAccount: AccountId = PalletId(*b"py/trsry").into_account_truncating();
}

#[cfg(feature = "runtime-benchmarks")]
impl snowbridge_control::BenchmarkHelper<RuntimeOrigin> for () {
fn make_xcm_origin(location: xcm::latest::MultiLocation) -> RuntimeOrigin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ use parachains_common::{
use polkadot_parachain_primitives::primitives::Sibling;
use polkadot_runtime_common::xcm_sender::ExponentialPrice;
use rococo_runtime_constants::system_parachain::SystemParachains;
use snowbridge_router_primitives::outbound::EthereumBlobExporter;
use snowbridge_router_primitives:: outbound::EthereumBlobExporter;
use snowbridge_runtime_common::XcmExportFeeToSnowbridge;
use sp_core::{Get, H256};
use sp_runtime::traits::AccountIdConversion;
use sp_std::marker::PhantomData;
Expand Down Expand Up @@ -82,7 +83,8 @@ parameter_types! {
pub RelayTreasuryLocation: MultiLocation = (Parent, PalletInstance(rococo_runtime_constants::TREASURY_PALLET_ID)).into();

// Network and location for the local Ethereum testnet.
pub const EthereumNetwork: NetworkId = NetworkId::Ethereum { chain_id: 15 };
pub const EthereumChainId: u64 = 15;
pub const EthereumNetwork: NetworkId = NetworkId::Ethereum { chain_id: EthereumChainId::get() };
}

/// Adapter for resolving `NetworkId` based on `pub storage Flavor: RuntimeFlavor`.
Expand Down Expand Up @@ -317,6 +319,12 @@ impl xcm_executor::Config for XcmConfig {
BridgeHubRococoChainId,
BridgeHubRococoMessagesLane,
>,
XcmExportFeeToSnowbridge<
TokenLocation,
EthereumNetwork,
Self::AssetTransactor,
crate::EthereumOutboundQueue,
>,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

XcmFeeToAccount<Self::AssetTransactor, AccountId, TreasuryAccount>,
),
>;
Expand Down Expand Up @@ -571,4 +579,4 @@ impl<

fee
}
}
}
Loading