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

feat: add expiry block to liquidity channel event #4111

Merged
merged 1 commit into from
Oct 12, 2023
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
9 changes: 6 additions & 3 deletions state-chain/pallets/cf-ingress-egress/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -993,11 +993,14 @@ impl<T: Config<I>, I: 'static> DepositApi<T::TargetChain> for Pallet<T, I> {
fn request_liquidity_deposit_address(
lp_account: T::AccountId,
source_asset: TargetChainAsset<T, I>,
) -> Result<(ChannelId, ForeignChainAddress), DispatchError> {
let (channel_id, deposit_address, ..) =
) -> Result<
(ChannelId, ForeignChainAddress, <T::TargetChain as Chain>::ChainBlockNumber),
DispatchError,
> {
let (channel_id, deposit_address, expiry_block) =
Self::open_channel(source_asset, ChannelAction::LiquidityProvision { lp_account })?;

Ok((channel_id, deposit_address.into()))
Ok((channel_id, deposit_address.into(), expiry_block))
}

// This should only be callable by the broker.
Expand Down
2 changes: 1 addition & 1 deletion state-chain/pallets/cf-ingress-egress/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ impl<Ctx: Clone> RequestAddress for TestExternalities<Test, Ctx> {
.map(|request| match request {
DepositRequest::Liquidity { lp_account, asset } =>
IngressEgress::request_liquidity_deposit_address(lp_account, asset)
.map(|(id, addr)| {
.map(|(id, addr, ..)| {
(request, id, TestChainAccount::try_from(addr).unwrap())
})
.unwrap(),
Expand Down
2 changes: 1 addition & 1 deletion state-chain/pallets/cf-ingress-egress/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ fn request_address_and_deposit(
who: ChannelId,
asset: eth::Asset,
) -> (ChannelId, <Ethereum as Chain>::ChainAccount) {
let (id, address) = IngressEgress::request_liquidity_deposit_address(who, asset).unwrap();
let (id, address, ..) = IngressEgress::request_liquidity_deposit_address(who, asset).unwrap();
let address: <Ethereum as Chain>::ChainAccount = address.try_into().unwrap();
assert_ok!(IngressEgress::process_single_deposit(
address,
Expand Down
6 changes: 4 additions & 2 deletions state-chain/pallets/cf-lp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl_pallet_safe_mode!(PalletSafeMode; deposit_enabled, withdrawal_enabled);

#[frame_support::pallet]
pub mod pallet {
use cf_chains::address::EncodedAddress;
use cf_chains::{address::EncodedAddress, Chain};
use cf_primitives::{ChannelId, EgressId};

use super::*;
Expand Down Expand Up @@ -103,6 +103,7 @@ pub mod pallet {
deposit_address: EncodedAddress,
// account the funds will be credited to upon deposit
account_id: T::AccountId,
deposit_chain_expiry_block: <AnyChain as Chain>::ChainBlockNumber,
},
WithdrawalEgressScheduled {
egress_id: EgressId,
Expand Down Expand Up @@ -174,14 +175,15 @@ pub mod pallet {
Error::<T>::NoLiquidityRefundAddressRegistered
);

let (channel_id, deposit_address) =
let (channel_id, deposit_address, expiry_block) =
T::DepositHandler::request_liquidity_deposit_address(account_id.clone(), asset)?;

Self::deposit_event(Event::LiquidityDepositAddressReady {
channel_id,
asset,
deposit_address: T::AddressConverter::to_encoded_address(deposit_address),
account_id,
deposit_chain_expiry_block: expiry_block,
});

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions state-chain/runtime/src/chainflip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,14 +447,14 @@ macro_rules! impl_deposit_api_for_anychain {
fn request_liquidity_deposit_address(
lp_account: Self::AccountId,
source_asset: Asset,
) -> Result<(ChannelId, ForeignChainAddress), DispatchError> {
) -> Result<(ChannelId, ForeignChainAddress, <AnyChain as cf_chains::Chain>::ChainBlockNumber), DispatchError> {
match source_asset.into() {
$(
ForeignChain::$chain =>
$pallet::request_liquidity_deposit_address(
lp_account,
source_asset.try_into().unwrap(),
),
).map(|(channel, address, block_number)| (channel, address, block_number.into())),
)+
}
}
Expand Down
2 changes: 1 addition & 1 deletion state-chain/traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ pub trait DepositApi<C: Chain> {
fn request_liquidity_deposit_address(
lp_account: Self::AccountId,
source_asset: C::ChainAsset,
) -> Result<(ChannelId, ForeignChainAddress), DispatchError>;
) -> Result<(ChannelId, ForeignChainAddress, C::ChainBlockNumber), DispatchError>;

/// Issues a channel id and deposit address for a new swap.
fn request_swap_deposit_address(
Expand Down
7 changes: 5 additions & 2 deletions state-chain/traits/src/mocks/deposit_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ impl<C: Chain, T: Chainflip> DepositApi<C> for MockDepositHandler<C, T> {
fn request_liquidity_deposit_address(
lp_account: Self::AccountId,
source_asset: <C as cf_chains::Chain>::ChainAsset,
) -> Result<(cf_primitives::ChannelId, ForeignChainAddress), sp_runtime::DispatchError> {
) -> Result<
(cf_primitives::ChannelId, ForeignChainAddress, <C as cf_chains::Chain>::ChainBlockNumber),
sp_runtime::DispatchError,
> {
let (channel_id, deposit_address) =
Self::get_new_deposit_address(SwapOrLp::Lp, source_asset);
<Self as MockPalletStorage>::mutate_value(b"LP_INGRESS_CHANNELS", |lp_channels| {
Expand All @@ -96,7 +99,7 @@ impl<C: Chain, T: Chainflip> DepositApi<C> for MockDepositHandler<C, T> {
});
}
});
Ok((channel_id, deposit_address))
Ok((channel_id, deposit_address, 0u32.into()))
}

fn request_swap_deposit_address(
Expand Down