Skip to content

Commit

Permalink
merge ron's work in
Browse files Browse the repository at this point in the history
  • Loading branch information
claravanstaden committed Oct 23, 2024
1 parent 1329923 commit 0b5e254
Show file tree
Hide file tree
Showing 12 changed files with 644 additions and 446 deletions.
1,028 changes: 586 additions & 442 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions bridges/snowbridge/pallets/inbound-queue-v2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ use xcm::{
prelude::{send_xcm, Junction::*, Location, SendError as XcmpSendError, SendXcm, Xcm},
VersionedXcm, MAX_XCM_DECODE_DEPTH,
};
use snowbridge_core::rewards::RewardLedger;

use snowbridge_core::{
inbound::{Message, VerificationError, Verifier},
Expand Down Expand Up @@ -98,6 +99,8 @@ pub mod pallet {

#[cfg(feature = "runtime-benchmarks")]
type Helper: BenchmarkHelper<Self>;
/// To keep track of relayer rewards.
type RewardLedger: RewardLedger<Self>;
}

#[pallet::hooks]
Expand Down
3 changes: 3 additions & 0 deletions bridges/snowbridge/pallets/outbound-queue-v2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ use sp_runtime::{
use sp_std::prelude::*;
pub use types::{CommittedMessage, FeeWithBlockNumber, ProcessMessageOriginOf};
pub use weights::WeightInfo;
use snowbridge_core::rewards::RewardLedger;

pub use pallet::*;

Expand Down Expand Up @@ -173,6 +174,8 @@ pub mod pallet {
/// Address of the Gateway contract
#[pallet::constant]
type GatewayAddress: Get<H160>;
/// To keep track of relayer rewards.
type RewardLedger: RewardLedger<Self>;
}

#[pallet::event]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ decl_test_parachains! {
EthereumSystem: bridge_hub_rococo_runtime::EthereumSystem,
EthereumInboundQueue: bridge_hub_rococo_runtime::EthereumInboundQueue,
EthereumOutboundQueue: bridge_hub_rococo_runtime::EthereumOutboundQueue,
EthereumRewards: bridge_hub_rococo_runtime::EthereumRewards,
}
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ decl_test_parachains! {
PolkadotXcm: bridge_hub_westend_runtime::PolkadotXcm,
Balances: bridge_hub_westend_runtime::Balances,
EthereumSystem: bridge_hub_westend_runtime::EthereumSystem,
EthereumRewards: bridge_hub_rococo_runtime::EthereumRewards,
}
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,5 @@ testnet-parachains-constants = { features = ["rococo", "westend"], workspace = t
snowbridge-core = { workspace = true }
snowbridge-router-primitives = { workspace = true }
snowbridge-pallet-system = { workspace = true }
snowbridge-pallet-rewards = { workspace = true }
snowbridge-pallet-outbound-queue = { workspace = true }
snowbridge-pallet-inbound-queue-fixtures = { workspace = true, default-features = true }
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ snowbridge-pallet-outbound-queue = { workspace = true }
snowbridge-pallet-inbound-queue = { workspace = true }
snowbridge-pallet-inbound-queue-fixtures = { workspace = true }
snowbridge-pallet-outbound-queue-v2 = { workspace = true }
snowbridge-pallet-rewards = { workspace = true }
Original file line number Diff line number Diff line change
Expand Up @@ -586,3 +586,29 @@ fn transfer_ah_token() {
);
});
}

#[test]
fn claim_rewards(
) {
BridgeHubWestend::execute_with(|| {
type RuntimeEvent = <BridgeHubWestend as Chain>::RuntimeEvent;

let relayer = BridgeHubWestendSender::get();
let reward_address = AssetHubWestendReceiver::get();
type EthereumRewards =
<BridgeHubWestend as BridgeHubWestendPallet>::EthereumRewards;
assert_ok!(EthereumRewards::deposit(relayer.into(), 2 * ETH));

// Check that the message was sent
assert_expected_events!(
BridgeHubWestend,
vec![
RuntimeEvent::EthereumRewards(snowbridge_pallet_rewards::Event::RewardDeposited { .. }) => {},
]
);

type EthereumInboundQueue =
<BridgeHubWestend as BridgeHubWestendPallet>::EthereumInboundQueue;
let message_id = H256::random();
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::XcmRouter;
use crate::{
xcm_config, xcm_config::UniversalLocation, Balances, EthereumInboundQueue,
EthereumOutboundQueue, EthereumSystem, MessageQueue, Runtime, RuntimeEvent, TransactionByteFee,
TreasuryAccount,
TreasuryAccount, EthereumRewards
};
use parachains_common::{AccountId, Balance};
use snowbridge_beacon_primitives::{Fork, ForkVersions};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ snowbridge-core = { workspace = true }
snowbridge-pallet-ethereum-client = { workspace = true }
snowbridge-pallet-inbound-queue = { workspace = true }
snowbridge-pallet-outbound-queue = { workspace = true }
snowbridge-pallet-rewards = { workspace = true }
snowbridge-outbound-queue-runtime-api = { workspace = true }
snowbridge-router-primitives = { workspace = true }
snowbridge-runtime-common = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{
xcm_config,
xcm_config::{TreasuryAccount, UniversalLocation},
Balances, EthereumInboundQueue, EthereumOutboundQueue, EthereumSystem, MessageQueue, Runtime,
RuntimeEvent, TransactionByteFee,
RuntimeEvent, TransactionByteFee, EthereumRewards,
};
use parachains_common::{AccountId, Balance};
use snowbridge_beacon_primitives::{Fork, ForkVersions};
Expand Down Expand Up @@ -121,6 +121,7 @@ impl snowbridge_pallet_inbound_queue_v2::Config for Runtime {
type GatewayAddress = EthereumGatewayAddress;
#[cfg(feature = "runtime-benchmarks")]
type Helper = Runtime;
type RewardLedger = EthereumRewards;
type WeightInfo = crate::weights::snowbridge_pallet_inbound_queue_v2::WeightInfo<Runtime>;
}

Expand Down Expand Up @@ -150,6 +151,7 @@ impl snowbridge_pallet_outbound_queue_v2::Config for Runtime {
type WeightToFee = WeightToFee;
type Verifier = snowbridge_pallet_ethereum_client::Pallet<Runtime>;
type GatewayAddress = EthereumGatewayAddress;
type RewardLedger = EthereumRewards;
type WeightInfo = crate::weights::snowbridge_pallet_outbound_queue_v2::WeightInfo<Runtime>;
}

Expand Down Expand Up @@ -228,6 +230,24 @@ impl snowbridge_pallet_system::Config for Runtime {
type EthereumLocation = EthereumLocation;
}

parameter_types! {
pub WethAddress: H160 = H160(hex_literal::hex!("fff9976782d46cc05630d1f6ebab18b2324d6b14"));
}

pub const ASSET_HUB_ID: u32 = westend_runtime_constants::system_parachain::ASSET_HUB_ID;

impl snowbridge_pallet_rewards::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type AssetHubParaId = ConstU32<ASSET_HUB_ID>;
type EthereumNetwork = EthereumNetwork;
type WethAddress = WethAddress;
#[cfg(not(feature = "runtime-benchmarks"))]
type XcmSender = XcmRouter;
#[cfg(feature = "runtime-benchmarks")]
type XcmSender = DoNothingRouter;
type WeightInfo = (); // TODO generate weights
}

#[cfg(feature = "runtime-benchmarks")]
pub mod benchmark_helpers {
use crate::{EthereumBeaconClient, Runtime, RuntimeOrigin};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ construct_runtime!(
EthereumSystem: snowbridge_pallet_system = 83,
EthereumInboundQueueV2: snowbridge_pallet_inbound_queue_v2 = 84,
EthereumOutboundQueueV2: snowbridge_pallet_outbound_queue_v2 = 85,
EthereumRewards: snowbridge_pallet_rewards = 86,

// Message Queue. Importantly, is registered last so that messages are processed after
// the `on_initialize` hooks of bridging pallets.
Expand Down

0 comments on commit 0b5e254

Please sign in to comment.