You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// Additional fee that is paid for every byte of the outbound message.
112
+
/// See `calculate_fees` for more details.
112
113
typeByteFee:Get<u128>;
113
-
/// Asset that is used to paid bridge fee.
114
-
typeFeeAsset:Get<AssetId>;
114
+
/// Asset used to pay the `ByteFee`.
115
+
/// If not specified, the `ByteFee` is ignored.
116
+
/// See `calculate_fees` for more details.
117
+
typeFeeAsset:Get<Option<AssetId>>;
115
118
}
116
119
117
120
#[pallet::pallet]
@@ -216,6 +219,36 @@ pub mod pallet {
216
219
*f
217
220
});
218
221
}
222
+
223
+
/// Calculates final fees based on the configuration, supporting two optional features:
224
+
///
225
+
/// 1. Adds an (optional) fee for message size based on `T::ByteFee` and `T::FeeAsset`.
226
+
/// 2. Applies a dynamic fee factor `Self::delivery_fee_factor` to the `actual_cost` (useful for congestion handling).
227
+
///
228
+
/// Parameters:
229
+
/// - `message_size`
230
+
/// - `actual_cost`: the fee for sending a message from this chain to a child, sibling, or local bridge hub, determined by `Config::ToBridgeHubSender`.
if bridge_hub_location.eq(&T::SiblingBridgeHubLocation::get()) =>
268
-
(bridge_hub_location, maybe_payment),
269
-
_ => {
270
-
log::trace!(
271
-
target:LOG_TARGET,
272
-
"Router configured with bridged_network_id {:?} and sibling_bridge_hub_location: {:?} does not support bridging to network {:?} and remote_location {:?}!",
273
-
T::BridgedNetworkId::get(),
274
-
T::SiblingBridgeHubLocation::get(),
275
-
network,
276
-
remote_location,
277
-
);
278
-
returnNone
279
-
},
280
-
};
281
-
282
-
// take `base_fee` from `T::Brides`, but it has to be the same `T::FeeAsset`
283
-
let base_fee = match maybe_payment {
284
-
Some(payment) => match payment {
285
-
Asset{fun:Fungible(amount), id }if id.eq(&T::FeeAsset::get()) => amount,
286
-
invalid_asset => {
287
-
log::error!(
288
-
target:LOG_TARGET,
289
-
"Router with bridged_network_id {:?} is configured for `T::FeeAsset` {:?} \
290
-
which is not compatible with {:?} for bridge_hub_location: {:?} for bridging to {:?}/{:?}!",
291
-
T::BridgedNetworkId::get(),
292
-
T::FeeAsset::get(),
293
-
invalid_asset,
294
-
bridge_hub_location,
295
-
network,
296
-
remote_location,
297
-
);
298
-
returnNone
299
-
},
300
-
},
301
-
None => 0,
302
-
};
303
-
304
-
// compute fee amount. Keep in mind that this is only the bridge fee. The fee for sending
305
-
// message from this chain to child/sibling bridge hub is determined by the
306
-
// `Config::ToBridgeHubSender`
307
-
let message_size = message.encoded_size();
308
-
let message_fee = (message_size asu128).saturating_mul(T::ByteFee::get());
309
-
let fee_sum = base_fee.saturating_add(message_fee);
310
-
311
-
let fee_factor = Self::delivery_fee_factor();
312
-
let fee = fee_factor.saturating_mul_int(fee_sum);
313
-
let fee = if fee > 0{Some((T::FeeAsset::get(), fee).into())}else{None};
314
-
315
-
log::info!(
316
-
target:LOG_TARGET,
317
-
"Going to send message to {:?} ({} bytes) over bridge. Computed bridge fee {:?} using fee factor {}",
318
-
(network, remote_location),
319
-
message_size,
320
-
fee,
321
-
fee_factor,
322
-
);
323
-
324
-
Some((bridge_hub_location, fee))
325
-
}
326
-
}
327
-
328
270
// This pallet acts as the `SendXcm` to the sibling/child bridge hub instead of regular
329
271
// XCMP/DMP transport. This allows injecting dynamic message fees into XCM programs that
0 commit comments