diff --git a/api/lib/src/lib.rs b/api/lib/src/lib.rs index ce8dea308ab..e6865b7d970 100644 --- a/api/lib/src/lib.rs +++ b/api/lib/src/lib.rs @@ -347,7 +347,7 @@ pub struct SwapDepositAddress { pub channel_id: ChannelId, pub source_chain_expiry_block: NumberOrHex, pub channel_opening_fee: U256, - pub refund_parameters: Option, + pub refund_parameters: Option>, } #[derive(Serialize, Deserialize, Debug)] @@ -454,7 +454,11 @@ pub trait BrokerApi: SignedExtrinsicApi + StorageApi + Sized + Send + Sync + 'st channel_id: *channel_id, source_chain_expiry_block: (*source_chain_expiry_block).into(), channel_opening_fee: (*channel_opening_fee).into(), - refund_parameters: refund_parameters.clone(), + refund_parameters: refund_parameters.as_ref().map(|params| { + params.map_address(|refund_address| { + AddressString::from_encoded_address(&refund_address) + }) + }), }) } else { bail!("No SwapDepositAddressReady event was found"); diff --git a/state-chain/chains/src/lib.rs b/state-chain/chains/src/lib.rs index 10bb424b4f2..e617b671bf7 100644 --- a/state-chain/chains/src/lib.rs +++ b/state-chain/chains/src/lib.rs @@ -677,8 +677,18 @@ pub struct SwapRefundParameters { #[derive( Clone, Debug, PartialEq, Eq, Encode, Decode, TypeInfo, MaxEncodedLen, Serialize, Deserialize, )] -pub struct ChannelRefundParameters { +pub struct ChannelRefundParameters { pub retry_duration: cf_primitives::BlockNumber, - pub refund_address: ForeignChainAddress, + pub refund_address: A, pub min_price: Price, } + +impl ChannelRefundParameters { + pub fn map_address B>(&self, f: F) -> ChannelRefundParameters { + ChannelRefundParameters { + retry_duration: self.retry_duration, + refund_address: f(self.refund_address.clone()), + min_price: self.min_price, + } + } +} diff --git a/state-chain/pallets/cf-ingress-egress/src/lib.rs b/state-chain/pallets/cf-ingress-egress/src/lib.rs index 4f44e7a431a..b6cd595545f 100644 --- a/state-chain/pallets/cf-ingress-egress/src/lib.rs +++ b/state-chain/pallets/cf-ingress-egress/src/lib.rs @@ -327,7 +327,7 @@ pub mod pallet { destination_asset: Asset, destination_address: ForeignChainAddress, broker_fees: Beneficiaries, - refund_params: Option, + refund_params: Option>, }, LiquidityProvision { lp_account: AccountId, @@ -337,7 +337,7 @@ pub mod pallet { destination_address: ForeignChainAddress, broker_fees: Beneficiaries, channel_metadata: CcmChannelMetadata, - refund_params: Option, + refund_params: Option>, }, } @@ -2071,7 +2071,7 @@ impl, I: 'static> DepositApi for Pallet { broker_id: T::AccountId, channel_metadata: Option, boost_fee: BasisPoints, - refund_params: Option, + refund_params: Option>, ) -> Result< (ChannelId, ForeignChainAddress, ::ChainBlockNumber, Self::Amount), DispatchError, diff --git a/state-chain/pallets/cf-ingress-egress/src/migrations/add_broker_fee_to_ccm.rs b/state-chain/pallets/cf-ingress-egress/src/migrations/add_broker_fee_to_ccm.rs index 3d678280fff..7fce8649b2a 100644 --- a/state-chain/pallets/cf-ingress-egress/src/migrations/add_broker_fee_to_ccm.rs +++ b/state-chain/pallets/cf-ingress-egress/src/migrations/add_broker_fee_to_ccm.rs @@ -11,7 +11,7 @@ pub(super) mod old { destination_asset: Asset, destination_address: ForeignChainAddress, broker_fees: Beneficiaries, - refund_params: Option, + refund_params: Option>, }, LiquidityProvision { lp_account: AccountId, @@ -20,7 +20,7 @@ pub(super) mod old { destination_asset: Asset, destination_address: ForeignChainAddress, channel_metadata: CcmChannelMetadata, - refund_params: Option, + refund_params: Option>, }, } diff --git a/state-chain/pallets/cf-swapping/src/lib.rs b/state-chain/pallets/cf-swapping/src/lib.rs index be4f16586b6..f84ac1b437c 100644 --- a/state-chain/pallets/cf-swapping/src/lib.rs +++ b/state-chain/pallets/cf-swapping/src/lib.rs @@ -379,7 +379,7 @@ pub mod pallet { boost_fee: BasisPoints, channel_opening_fee: T::Amount, affiliate_fees: Affiliates, - refund_parameters: Option, + refund_parameters: Option>, }, /// A swap is scheduled for the first time SwapScheduled { @@ -953,7 +953,7 @@ pub mod pallet { channel_metadata: Option, boost_fee: BasisPoints, affiliate_fees: Affiliates, - refund_parameters: Option, + refund_parameters: Option>, ) -> DispatchResult { let broker = T::AccountRoleRegistry::ensure_broker(origin)?; let (beneficiaries, total_bps) = { @@ -1017,7 +1017,8 @@ pub mod pallet { boost_fee, channel_opening_fee, affiliate_fees, - refund_parameters, + refund_parameters: refund_parameters + .map(|params| params.map_address(T::AddressConverter::to_encoded_address)), }); Ok(()) @@ -1501,7 +1502,7 @@ pub mod pallet { amount: AssetAmount, destination_address: ForeignChainAddress, broker_commission: Beneficiaries, - refund_params: Option, + refund_params: Option>, channel_id: ChannelId, ) -> SwapId { // Permill maxes out at 100% so this is safe. @@ -1584,7 +1585,7 @@ pub mod pallet { deposit_metadata: CcmDepositMetadata, origin: SwapOrigin, // TODO: CCM should use refund params - _refund_params: Option, + _refund_params: Option>, ) -> Result { let encoded_destination_address = T::AddressConverter::to_encoded_address(destination_address.clone()); diff --git a/state-chain/pallets/cf-swapping/src/tests.rs b/state-chain/pallets/cf-swapping/src/tests.rs index ac05ea692b7..91623aaa7b4 100644 --- a/state-chain/pallets/cf-swapping/src/tests.rs +++ b/state-chain/pallets/cf-swapping/src/tests.rs @@ -2269,7 +2269,7 @@ fn deposit_address_ready_event_contains_correct_parameters() { boost_fee: BOOST_FEE, refund_parameters: Some(ref refund_params_in_event), .. - }) if refund_params_in_event == &refund_parameters + }) if *refund_params_in_event == refund_parameters.map_address(MockAddressConverter::to_encoded_address) ); }); } diff --git a/state-chain/runtime/src/chainflip.rs b/state-chain/runtime/src/chainflip.rs index 9b421cd59b2..2a51d2aaab3 100644 --- a/state-chain/runtime/src/chainflip.rs +++ b/state-chain/runtime/src/chainflip.rs @@ -585,7 +585,7 @@ macro_rules! impl_deposit_api_for_anychain { broker_id: Self::AccountId, channel_metadata: Option, boost_fee: BasisPoints, - refund_parameters: Option, + refund_parameters: Option>, ) -> Result<(ChannelId, ForeignChainAddress, ::ChainBlockNumber, FlipBalance), DispatchError> { match source_asset.into() { $( diff --git a/state-chain/traits/src/lib.rs b/state-chain/traits/src/lib.rs index d2ce21686c2..1661030d95f 100644 --- a/state-chain/traits/src/lib.rs +++ b/state-chain/traits/src/lib.rs @@ -718,7 +718,7 @@ pub trait DepositApi { broker_id: Self::AccountId, channel_metadata: Option, boost_fee: BasisPoints, - refund_params: Option, + refund_params: Option>, ) -> Result<(ChannelId, ForeignChainAddress, C::ChainBlockNumber, Self::Amount), DispatchError>; } @@ -903,7 +903,7 @@ pub trait CcmHandler { broker_commission: Beneficiaries, deposit_metadata: CcmDepositMetadata, origin: SwapOrigin, - refund_params: Option, + refund_params: Option>, ) -> Result; } @@ -917,7 +917,7 @@ impl CcmHandler for () { _broker_commission: Beneficiaries, _deposit_metadata: CcmDepositMetadata, _origin: SwapOrigin, - _refund_params: Option, + _refund_params: Option>, ) -> Result { Err(()) } diff --git a/state-chain/traits/src/liquidity.rs b/state-chain/traits/src/liquidity.rs index 0c05be513c4..8167d6a680e 100644 --- a/state-chain/traits/src/liquidity.rs +++ b/state-chain/traits/src/liquidity.rs @@ -19,7 +19,7 @@ pub trait SwapDepositHandler { amount: AssetAmount, destination_address: ForeignChainAddress, broker_commission: Beneficiaries, - refund_params: Option, + refund_params: Option>, channel_id: ChannelId, ) -> SwapId; } diff --git a/state-chain/traits/src/mocks/ccm_handler.rs b/state-chain/traits/src/mocks/ccm_handler.rs index 2514e4cbe1c..605728450c9 100644 --- a/state-chain/traits/src/mocks/ccm_handler.rs +++ b/state-chain/traits/src/mocks/ccm_handler.rs @@ -41,7 +41,7 @@ impl CcmHandler for MockCcmHandler { _broker_commission: Beneficiaries, deposit_metadata: CcmDepositMetadata, origin: SwapOrigin, - _refund_params: Option, + _refund_params: Option>, ) -> Result { ::mutate_value(CCM_HANDLER_PREFIX, |ccm_requests| { if ccm_requests.is_none() { diff --git a/state-chain/traits/src/mocks/deposit_handler.rs b/state-chain/traits/src/mocks/deposit_handler.rs index 901aec01af7..a5c136035e2 100644 --- a/state-chain/traits/src/mocks/deposit_handler.rs +++ b/state-chain/traits/src/mocks/deposit_handler.rs @@ -124,7 +124,7 @@ impl DepositApi for MockDepositHandler { broker_id: Self::AccountId, channel_metadata: Option, boost_fee: BasisPoints, - _refund_params: Option, + _refund_params: Option>, ) -> Result< (cf_primitives::ChannelId, ForeignChainAddress, C::ChainBlockNumber, Self::Amount), DispatchError, diff --git a/state-chain/traits/src/mocks/swap_deposit_handler.rs b/state-chain/traits/src/mocks/swap_deposit_handler.rs index ddf9b34597f..246ba4c2641 100644 --- a/state-chain/traits/src/mocks/swap_deposit_handler.rs +++ b/state-chain/traits/src/mocks/swap_deposit_handler.rs @@ -19,7 +19,7 @@ where amount: AssetAmount, destination_address: ForeignChainAddress, _broker_commission: Beneficiaries, - _refund_params: Option, + _refund_params: Option>, _channel_id: ChannelId, ) -> SwapId { let _ = E::schedule_egress(