diff --git a/state-chain/chains/src/lib.rs b/state-chain/chains/src/lib.rs
index b4a99eab59..1d03874c44 100644
--- a/state-chain/chains/src/lib.rs
+++ b/state-chain/chains/src/lib.rs
@@ -12,8 +12,8 @@ use crate::{
};
pub use address::ForeignChainAddress;
use address::{
- AddressDerivationApi, AddressDerivationError, EncodedAddress, IntoForeignChainAddress,
- ToHumanreadableAddress,
+ AddressConverter, AddressDerivationApi, AddressDerivationError, EncodedAddress,
+ IntoForeignChainAddress, ToHumanreadableAddress,
};
use cf_primitives::{
AssetAmount, BroadcastId, ChannelId, EgressId, EthAmount, Price, TransactionHash,
@@ -628,12 +628,25 @@ pub struct CcmChannelMetadata {
}
#[derive(Clone, Debug, PartialEq, Eq, Encode, Decode, TypeInfo, Serialize, Deserialize)]
-pub struct CcmDepositMetadata {
+pub struct CcmDepositMetadataGeneric
{
pub source_chain: ForeignChain,
- pub source_address: Option,
+ pub source_address: Option,
pub channel_metadata: CcmChannelMetadata,
}
+pub type CcmDepositMetadata = CcmDepositMetadataGeneric;
+pub type CcmDepositMetadataEncoded = CcmDepositMetadataGeneric;
+
+impl CcmDepositMetadata {
+ pub fn to_encoded(self) -> CcmDepositMetadataEncoded {
+ CcmDepositMetadataEncoded {
+ source_chain: self.source_chain,
+ source_address: self.source_address.map(Converter::to_encoded_address),
+ channel_metadata: self.channel_metadata,
+ }
+ }
+}
+
#[derive(
PartialEqNoBound,
EqNoBound,
diff --git a/state-chain/pallets/cf-swapping/src/lib.rs b/state-chain/pallets/cf-swapping/src/lib.rs
index 057803ea99..2d4968cd62 100644
--- a/state-chain/pallets/cf-swapping/src/lib.rs
+++ b/state-chain/pallets/cf-swapping/src/lib.rs
@@ -7,7 +7,7 @@ use cf_amm::common::Side;
use cf_chains::{
address::{AddressConverter, ForeignChainAddress},
ccm_checker::CcmValidityCheck,
- CcmChannelMetadata, CcmDepositMetadata, ChannelRefundParameters,
+ CcmChannelMetadata, CcmDepositMetadata, CcmDepositMetadataEncoded, ChannelRefundParameters,
ChannelRefundParametersEncoded, SwapOrigin, SwapRefundParameters,
};
use cf_primitives::{
@@ -536,6 +536,8 @@ pub mod pallet {
output_asset: Asset,
origin: SwapOrigin,
request_type: SwapRequestTypeEncoded,
+ refund_parameters: Option,
+ dca_parameters: Option,
},
SwapRequestCompleted {
swap_request_id: SwapRequestId,
@@ -615,7 +617,7 @@ pub mod pallet {
CcmFailed {
reason: CcmFailReason,
destination_address: EncodedAddress,
- deposit_metadata: CcmDepositMetadata,
+ deposit_metadata: CcmDepositMetadataEncoded,
origin: SwapOrigin,
},
MaximumSwapAmountSet {
@@ -2091,10 +2093,16 @@ pub mod pallet {
output_address: T::AddressConverter::to_encoded_address(
output_address.clone(),
),
- ccm_deposit_metadata: ccm_deposit_metadata.clone(),
+ ccm_deposit_metadata: ccm_deposit_metadata
+ .clone()
+ .to_encoded::(),
},
},
origin: origin.clone(),
+ refund_parameters: refund_params
+ .clone()
+ .map(|params| params.map_address(T::AddressConverter::to_encoded_address)),
+ dca_parameters: dca_params.clone(),
});
match request_type {
@@ -2200,7 +2208,9 @@ pub mod pallet {
Self::deposit_event(Event::::CcmFailed {
reason,
destination_address: encoded_destination_address,
- deposit_metadata: ccm_deposit_metadata.clone(),
+ deposit_metadata: ccm_deposit_metadata
+ .clone()
+ .to_encoded::(),
origin: origin.clone(),
});
diff --git a/state-chain/pallets/cf-swapping/src/tests.rs b/state-chain/pallets/cf-swapping/src/tests.rs
index b08ebb6935..f6447433fd 100644
--- a/state-chain/pallets/cf-swapping/src/tests.rs
+++ b/state-chain/pallets/cf-swapping/src/tests.rs
@@ -209,7 +209,7 @@ fn assert_failed_ccm(
destination_address: ref address_in_event,
deposit_metadata: ref metadata_in_event,
..
- }) if reason_in_event == &reason && address_in_event == &MockAddressConverter::to_encoded_address(destination_address) && metadata_in_event == &ccm,
+ }) if reason_in_event == &reason && address_in_event == &MockAddressConverter::to_encoded_address(destination_address) && metadata_in_event == &ccm.to_encoded::<::AddressConverter>(),
RuntimeEvent::Swapping(Event::SwapRequestCompleted { .. }),
);
}
@@ -731,9 +731,12 @@ mod ccm {
output_asset,
input_amount,
request_type: SwapRequestTypeEncoded::Ccm {
- ccm_deposit_metadata,
+ ccm_deposit_metadata: ccm_deposit_metadata
+ .to_encoded::<::AddressConverter>(),
output_address: encoded_output_address,
},
+ dca_parameters: None,
+ refund_parameters: None,
origin,
}));
}
@@ -1112,6 +1115,8 @@ fn swap_by_witnesser_happy_path() {
request_type: SwapRequestTypeEncoded::Regular {
output_address: encoded_output_address,
},
+ refund_parameters: None,
+ dca_parameters: None,
origin: ORIGIN,
}));
@@ -2365,6 +2370,8 @@ fn network_fee_swap_gets_burnt() {
input_amount: AMOUNT,
output_asset: OUTPUT_ASSET,
request_type: SwapRequestTypeEncoded::NetworkFee,
+ refund_parameters: None,
+ dca_parameters: None,
origin: SwapOrigin::Internal,
}));
assert_has_matching_event!(Test, RuntimeEvent::Swapping(Event::SwapScheduled { .. }),);
@@ -2405,6 +2412,8 @@ fn transaction_fees_are_collected() {
input_amount: AMOUNT,
output_asset: OUTPUT_ASSET,
request_type: SwapRequestTypeEncoded::IngressEgressFee,
+ refund_parameters: None,
+ dca_parameters: None,
origin: SwapOrigin::Internal,
}));
diff --git a/state-chain/pallets/cf-swapping/src/tests/dca.rs b/state-chain/pallets/cf-swapping/src/tests/dca.rs
index 6c9cb5ab28..cb8ab5c538 100644
--- a/state-chain/pallets/cf-swapping/src/tests/dca.rs
+++ b/state-chain/pallets/cf-swapping/src/tests/dca.rs
@@ -44,17 +44,17 @@ fn dca_happy_path() {
.execute_with(|| {
assert_eq!(System::block_number(), INIT_BLOCK);
- insert_swaps(&[params(
- Some(DcaParameters { number_of_chunks: 2, chunk_interval: CHUNK_INTERVAL }),
- None,
- false,
- )]);
+ const DCA_PARAMS: DcaParameters =
+ DcaParameters { number_of_chunks: 2, chunk_interval: CHUNK_INTERVAL };
+
+ insert_swaps(&[params(Some(DCA_PARAMS), None, false)]);
assert_has_matching_event!(
Test,
RuntimeEvent::Swapping(Event::SwapRequested {
swap_request_id: SWAP_REQUEST_ID,
input_amount: INPUT_AMOUNT,
+ dca_parameters: Some(DCA_PARAMS),
..
})
);
diff --git a/state-chain/pallets/cf-swapping/src/tests/fill_or_kill.rs b/state-chain/pallets/cf-swapping/src/tests/fill_or_kill.rs
index b176519067..fdd9948ce1 100644
--- a/state-chain/pallets/cf-swapping/src/tests/fill_or_kill.rs
+++ b/state-chain/pallets/cf-swapping/src/tests/fill_or_kill.rs
@@ -34,13 +34,26 @@ fn both_fok_and_regular_swaps_succeed_first_try() {
.execute_with(|| {
assert_eq!(System::block_number(), INIT_BLOCK);
- insert_swaps(&[
- fok_swap(None),
- fok_swap(Some(TestRefundParams {
- retry_duration: DEFAULT_SWAP_RETRY_DELAY_BLOCKS,
- min_output: (INPUT_AMOUNT - BROKER_FEE) * DEFAULT_SWAP_RATE,
- })),
- ]);
+ const REFUND_PARAMS: TestRefundParams = TestRefundParams {
+ retry_duration: DEFAULT_SWAP_RETRY_DELAY_BLOCKS,
+ min_output: (INPUT_AMOUNT - BROKER_FEE) * DEFAULT_SWAP_RATE,
+ };
+
+ let refund_parameters_encoded =
+ REFUND_PARAMS.into_channel_params(INPUT_AMOUNT).map_address(|refund_address| {
+ MockAddressConverter::to_encoded_address(refund_address)
+ });
+
+ insert_swaps(&vec![fok_swap(None), fok_swap(Some(REFUND_PARAMS))]);
+
+ assert_has_matching_event!(
+ Test,
+ RuntimeEvent::Swapping(Event::SwapRequested {
+ swap_request_id: FOK_REQUEST_ID,
+ refund_parameters,
+ ..
+ }) if refund_parameters.as_ref() == Some(&refund_parameters_encoded),
+ );
assert_swaps_scheduled_for_block(
&[REGULAR_SWAP_ID, FOK_SWAP_ID],
diff --git a/state-chain/traits/src/swapping.rs b/state-chain/traits/src/swapping.rs
index 40796ef07e..248e58e051 100644
--- a/state-chain/traits/src/swapping.rs
+++ b/state-chain/traits/src/swapping.rs
@@ -1,4 +1,6 @@
-use cf_chains::{CcmDepositMetadata, ChannelRefundParameters, ForeignChainAddress, SwapOrigin};
+use cf_chains::{
+ CcmDepositMetadataGeneric, ChannelRefundParameters, ForeignChainAddress, SwapOrigin,
+};
use cf_primitives::{Asset, AssetAmount, Beneficiaries, DcaParameters, SwapRequestId};
use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::sp_runtime::DispatchError;
@@ -18,7 +20,7 @@ pub enum SwapRequestTypeGeneric {
NetworkFee,
IngressEgressFee,
Regular { output_address: Address },
- Ccm { output_address: Address, ccm_deposit_metadata: CcmDepositMetadata },
+ Ccm { output_address: Address, ccm_deposit_metadata: CcmDepositMetadataGeneric },
}
pub type SwapRequestType = SwapRequestTypeGeneric;