@@ -70,6 +70,7 @@ pub trait MessageBridge {
7070 /// Convert Bridged chain balance into This chain balance.
7171 fn bridged_balance_to_this_balance (
7272 bridged_balance : BalanceOf < BridgedChain < Self > > ,
73+ bridged_to_this_conversion_rate_override : Option < FixedU128 > ,
7374 ) -> BalanceOf < ThisChain < Self > > ;
7475}
7576
@@ -316,8 +317,11 @@ pub mod source {
316317 pallet_bridge_dispatch:: verify_message_origin ( submitter, payload)
317318 . map_err ( |_| BAD_ORIGIN ) ?;
318319
319- let minimal_fee_in_this_tokens =
320- estimate_message_dispatch_and_delivery_fee :: < B > ( payload, B :: RELAYER_FEE_PERCENT ) ?;
320+ let minimal_fee_in_this_tokens = estimate_message_dispatch_and_delivery_fee :: < B > (
321+ payload,
322+ B :: RELAYER_FEE_PERCENT ,
323+ None ,
324+ ) ?;
321325
322326 // compare with actual fee paid
323327 if * delivery_and_dispatch_fee < minimal_fee_in_this_tokens {
@@ -371,6 +375,7 @@ pub mod source {
371375 pub fn estimate_message_dispatch_and_delivery_fee < B : MessageBridge > (
372376 payload : & FromThisChainMessagePayload < B > ,
373377 relayer_fee_percent : u32 ,
378+ bridged_to_this_conversion_rate : Option < FixedU128 > ,
374379 ) -> Result < BalanceOf < ThisChain < B > > , & ' static str > {
375380 // the fee (in Bridged tokens) of all transactions that are made on the Bridged chain
376381 //
@@ -391,8 +396,11 @@ pub mod source {
391396 ThisChain :: < B > :: transaction_payment ( confirmation_transaction) ;
392397
393398 // minimal fee (in This tokens) is a sum of all required fees
394- let minimal_fee = B :: bridged_balance_to_this_balance ( delivery_transaction_fee)
395- . checked_add ( & confirmation_transaction_fee) ;
399+ let minimal_fee = B :: bridged_balance_to_this_balance (
400+ delivery_transaction_fee,
401+ bridged_to_this_conversion_rate,
402+ )
403+ . checked_add ( & confirmation_transaction_fee) ;
396404
397405 // before returning, add extra fee that is paid to the relayer (relayer interest)
398406 minimal_fee
@@ -798,8 +806,12 @@ mod tests {
798806
799807 fn bridged_balance_to_this_balance (
800808 bridged_balance : BridgedChainBalance ,
809+ bridged_to_this_conversion_rate_override : Option < FixedU128 > ,
801810 ) -> ThisChainBalance {
802- ThisChainBalance ( bridged_balance. 0 * BRIDGED_CHAIN_TO_THIS_CHAIN_BALANCE_RATE as u32 )
811+ let conversion_rate = bridged_to_this_conversion_rate_override
812+ . map ( |r| r. to_float ( ) as u32 )
813+ . unwrap_or ( BRIDGED_CHAIN_TO_THIS_CHAIN_BALANCE_RATE ) ;
814+ ThisChainBalance ( bridged_balance. 0 * conversion_rate)
803815 }
804816 }
805817
@@ -817,7 +829,10 @@ mod tests {
817829 type ThisChain = BridgedChain ;
818830 type BridgedChain = ThisChain ;
819831
820- fn bridged_balance_to_this_balance ( _this_balance : ThisChainBalance ) -> BridgedChainBalance {
832+ fn bridged_balance_to_this_balance (
833+ _this_balance : ThisChainBalance ,
834+ _bridged_to_this_conversion_rate_override : Option < FixedU128 > ,
835+ ) -> BridgedChainBalance {
821836 unreachable ! ( )
822837 }
823838 }
@@ -1095,6 +1110,7 @@ mod tests {
10951110 source:: estimate_message_dispatch_and_delivery_fee:: <OnThisChainBridge >(
10961111 & payload,
10971112 OnThisChainBridge :: RELAYER_FEE_PERCENT ,
1113+ None ,
10981114 ) ,
10991115 Ok ( ThisChainBalance ( EXPECTED_MINIMAL_FEE ) ) ,
11001116 ) ;
@@ -1106,6 +1122,7 @@ mod tests {
11061122 source:: estimate_message_dispatch_and_delivery_fee :: < OnThisChainBridge > (
11071123 & payload_with_pay_on_target,
11081124 OnThisChainBridge :: RELAYER_FEE_PERCENT ,
1125+ None ,
11091126 )
11101127 . expect (
11111128 "estimate_message_dispatch_and_delivery_fee failed for pay-at-target-chain message" ,
@@ -1572,4 +1589,21 @@ mod tests {
15721589 100 + 50 * 10 + 777 ,
15731590 ) ;
15741591 }
1592+
1593+ #[ test]
1594+ fn conversion_rate_override_works ( ) {
1595+ let payload = regular_outbound_message_payload ( ) ;
1596+ let regular_fee = source:: estimate_message_dispatch_and_delivery_fee :: < OnThisChainBridge > (
1597+ & payload,
1598+ OnThisChainBridge :: RELAYER_FEE_PERCENT ,
1599+ None ,
1600+ ) ;
1601+ let overrided_fee = source:: estimate_message_dispatch_and_delivery_fee :: < OnThisChainBridge > (
1602+ & payload,
1603+ OnThisChainBridge :: RELAYER_FEE_PERCENT ,
1604+ Some ( FixedU128 :: from_float ( ( BRIDGED_CHAIN_TO_THIS_CHAIN_BALANCE_RATE * 2 ) as f64 ) ) ,
1605+ ) ;
1606+
1607+ assert ! ( regular_fee < overrided_fee) ;
1608+ }
15751609}
0 commit comments