Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use encoded address for refund_address in events #5135

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions api/lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChannelRefundParameters>,
pub refund_parameters: Option<ChannelRefundParameters<AddressString>>,
}

#[derive(Serialize, Deserialize, Debug)]
Expand Down Expand Up @@ -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");
Expand Down
14 changes: 12 additions & 2 deletions state-chain/chains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,8 +677,18 @@ pub struct SwapRefundParameters {
#[derive(
Clone, Debug, PartialEq, Eq, Encode, Decode, TypeInfo, MaxEncodedLen, Serialize, Deserialize,
)]
pub struct ChannelRefundParameters {
pub struct ChannelRefundParameters<A> {
pub retry_duration: cf_primitives::BlockNumber,
pub refund_address: ForeignChainAddress,
pub refund_address: A,
pub min_price: Price,
}

impl<A: Clone> ChannelRefundParameters<A> {
pub fn map_address<B, F: FnOnce(A) -> B>(&self, f: F) -> ChannelRefundParameters<B> {
ChannelRefundParameters {
retry_duration: self.retry_duration,
refund_address: f(self.refund_address.clone()),
min_price: self.min_price,
}
}
}
6 changes: 3 additions & 3 deletions state-chain/pallets/cf-ingress-egress/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ pub mod pallet {
destination_asset: Asset,
destination_address: ForeignChainAddress,
broker_fees: Beneficiaries<AccountId>,
refund_params: Option<ChannelRefundParameters>,
refund_params: Option<ChannelRefundParameters<ForeignChainAddress>>,
},
LiquidityProvision {
lp_account: AccountId,
Expand All @@ -337,7 +337,7 @@ pub mod pallet {
destination_address: ForeignChainAddress,
broker_fees: Beneficiaries<AccountId>,
channel_metadata: CcmChannelMetadata,
refund_params: Option<ChannelRefundParameters>,
refund_params: Option<ChannelRefundParameters<ForeignChainAddress>>,
},
}

Expand Down Expand Up @@ -2071,7 +2071,7 @@ impl<T: Config<I>, I: 'static> DepositApi<T::TargetChain> for Pallet<T, I> {
broker_id: T::AccountId,
channel_metadata: Option<CcmChannelMetadata>,
boost_fee: BasisPoints,
refund_params: Option<ChannelRefundParameters>,
refund_params: Option<ChannelRefundParameters<ForeignChainAddress>>,
) -> Result<
(ChannelId, ForeignChainAddress, <T::TargetChain as Chain>::ChainBlockNumber, Self::Amount),
DispatchError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub(super) mod old {
destination_asset: Asset,
destination_address: ForeignChainAddress,
broker_fees: Beneficiaries<AccountId>,
refund_params: Option<ChannelRefundParameters>,
refund_params: Option<ChannelRefundParameters<ForeignChainAddress>>,
},
LiquidityProvision {
lp_account: AccountId,
Expand All @@ -20,7 +20,7 @@ pub(super) mod old {
destination_asset: Asset,
destination_address: ForeignChainAddress,
channel_metadata: CcmChannelMetadata,
refund_params: Option<ChannelRefundParameters>,
refund_params: Option<ChannelRefundParameters<ForeignChainAddress>>,
},
}

Expand Down
11 changes: 6 additions & 5 deletions state-chain/pallets/cf-swapping/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ pub mod pallet {
boost_fee: BasisPoints,
channel_opening_fee: T::Amount,
affiliate_fees: Affiliates<T::AccountId>,
refund_parameters: Option<ChannelRefundParameters>,
refund_parameters: Option<ChannelRefundParameters<EncodedAddress>>,
},
/// A swap is scheduled for the first time
SwapScheduled {
Expand Down Expand Up @@ -953,7 +953,7 @@ pub mod pallet {
channel_metadata: Option<CcmChannelMetadata>,
boost_fee: BasisPoints,
affiliate_fees: Affiliates<T::AccountId>,
refund_parameters: Option<ChannelRefundParameters>,
refund_parameters: Option<ChannelRefundParameters<ForeignChainAddress>>,
) -> DispatchResult {
let broker = T::AccountRoleRegistry::ensure_broker(origin)?;
let (beneficiaries, total_bps) = {
Expand Down Expand Up @@ -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(())
Expand Down Expand Up @@ -1501,7 +1502,7 @@ pub mod pallet {
amount: AssetAmount,
destination_address: ForeignChainAddress,
broker_commission: Beneficiaries<Self::AccountId>,
refund_params: Option<ChannelRefundParameters>,
refund_params: Option<ChannelRefundParameters<ForeignChainAddress>>,
channel_id: ChannelId,
) -> SwapId {
// Permill maxes out at 100% so this is safe.
Expand Down Expand Up @@ -1584,7 +1585,7 @@ pub mod pallet {
deposit_metadata: CcmDepositMetadata,
origin: SwapOrigin,
// TODO: CCM should use refund params
_refund_params: Option<ChannelRefundParameters>,
_refund_params: Option<ChannelRefundParameters<ForeignChainAddress>>,
) -> Result<CcmSwapIds, ()> {
let encoded_destination_address =
T::AddressConverter::to_encoded_address(destination_address.clone());
Expand Down
2 changes: 1 addition & 1 deletion state-chain/pallets/cf-swapping/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
});
}
Expand Down
2 changes: 1 addition & 1 deletion state-chain/runtime/src/chainflip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ macro_rules! impl_deposit_api_for_anychain {
broker_id: Self::AccountId,
channel_metadata: Option<CcmChannelMetadata>,
boost_fee: BasisPoints,
refund_parameters: Option<ChannelRefundParameters>,
refund_parameters: Option<ChannelRefundParameters<ForeignChainAddress>>,
) -> Result<(ChannelId, ForeignChainAddress, <AnyChain as cf_chains::Chain>::ChainBlockNumber, FlipBalance), DispatchError> {
match source_asset.into() {
$(
Expand Down
6 changes: 3 additions & 3 deletions state-chain/traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ pub trait DepositApi<C: Chain> {
broker_id: Self::AccountId,
channel_metadata: Option<CcmChannelMetadata>,
boost_fee: BasisPoints,
refund_params: Option<ChannelRefundParameters>,
refund_params: Option<ChannelRefundParameters<ForeignChainAddress>>,
) -> Result<(ChannelId, ForeignChainAddress, C::ChainBlockNumber, Self::Amount), DispatchError>;
}

Expand Down Expand Up @@ -903,7 +903,7 @@ pub trait CcmHandler {
broker_commission: Beneficiaries<Self::AccountId>,
deposit_metadata: CcmDepositMetadata,
origin: SwapOrigin,
refund_params: Option<ChannelRefundParameters>,
refund_params: Option<ChannelRefundParameters<ForeignChainAddress>>,
) -> Result<CcmSwapIds, ()>;
}

Expand All @@ -917,7 +917,7 @@ impl CcmHandler for () {
_broker_commission: Beneficiaries<Self::AccountId>,
_deposit_metadata: CcmDepositMetadata,
_origin: SwapOrigin,
_refund_params: Option<ChannelRefundParameters>,
_refund_params: Option<ChannelRefundParameters<ForeignChainAddress>>,
) -> Result<CcmSwapIds, ()> {
Err(())
}
Expand Down
2 changes: 1 addition & 1 deletion state-chain/traits/src/liquidity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub trait SwapDepositHandler {
amount: AssetAmount,
destination_address: ForeignChainAddress,
broker_commission: Beneficiaries<Self::AccountId>,
refund_params: Option<ChannelRefundParameters>,
refund_params: Option<ChannelRefundParameters<ForeignChainAddress>>,
channel_id: ChannelId,
) -> SwapId;
}
Expand Down
2 changes: 1 addition & 1 deletion state-chain/traits/src/mocks/ccm_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl CcmHandler for MockCcmHandler {
_broker_commission: Beneficiaries<Self::AccountId>,
deposit_metadata: CcmDepositMetadata,
origin: SwapOrigin,
_refund_params: Option<ChannelRefundParameters>,
_refund_params: Option<ChannelRefundParameters<ForeignChainAddress>>,
) -> Result<CcmSwapIds, ()> {
<Self as MockPalletStorage>::mutate_value(CCM_HANDLER_PREFIX, |ccm_requests| {
if ccm_requests.is_none() {
Expand Down
2 changes: 1 addition & 1 deletion state-chain/traits/src/mocks/deposit_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl<C: Chain, T: Chainflip> DepositApi<C> for MockDepositHandler<C, T> {
broker_id: Self::AccountId,
channel_metadata: Option<CcmChannelMetadata>,
boost_fee: BasisPoints,
_refund_params: Option<ChannelRefundParameters>,
_refund_params: Option<ChannelRefundParameters<ForeignChainAddress>>,
) -> Result<
(cf_primitives::ChannelId, ForeignChainAddress, C::ChainBlockNumber, Self::Amount),
DispatchError,
Expand Down
2 changes: 1 addition & 1 deletion state-chain/traits/src/mocks/swap_deposit_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ where
amount: AssetAmount,
destination_address: ForeignChainAddress,
_broker_commission: Beneficiaries<Self::AccountId>,
_refund_params: Option<ChannelRefundParameters>,
_refund_params: Option<ChannelRefundParameters<ForeignChainAddress>>,
_channel_id: ChannelId,
) -> SwapId {
let _ = E::schedule_egress(
Expand Down
Loading