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: stop LPs without refund addresses for both assets from creating orders in a pool (PRO-896) #4099

Merged
merged 3 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 13 additions & 0 deletions state-chain/pallets/cf-lp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,19 @@ pub mod pallet {
impl<T: Config> LpBalanceApi for Pallet<T> {
type AccountId = <T as frame_system::Config>::AccountId;

fn ensure_has_refund_address_for_pair(
who: &Self::AccountId,
base_asset: Asset,
pair_asset: Asset,
) -> DispatchResult {
ensure!(
LiquidityRefundAddress::<T>::contains_key(who, ForeignChain::from(base_asset)) &&
LiquidityRefundAddress::<T>::contains_key(who, ForeignChain::from(pair_asset)),
Error::<T>::NoLiquidityRefundAddressRegistered
);
Ok(())
}

fn try_credit_account(
account_id: &Self::AccountId,
asset: Asset,
Expand Down
4 changes: 4 additions & 0 deletions state-chain/pallets/cf-pools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ pub mod pallet {
Error::<T>::UpdatingRangeOrdersDisabled
);
let lp = T::AccountRoleRegistry::ensure_liquidity_provider(origin)?;
T::LpBalance::ensure_has_refund_address_for_pair(&lp, base_asset, pair_asset)?;
Self::try_mutate_enabled_pool(base_asset, pair_asset, |asset_pair, pool| {
let tick_range = match (
pool.range_orders
Expand Down Expand Up @@ -742,6 +743,7 @@ pub mod pallet {
Error::<T>::UpdatingRangeOrdersDisabled
);
let lp = T::AccountRoleRegistry::ensure_liquidity_provider(origin)?;
T::LpBalance::ensure_has_refund_address_for_pair(&lp, base_asset, pair_asset)?;
Self::try_mutate_enabled_pool(base_asset, pair_asset, |asset_pair, pool| {
let tick_range = match (
pool.range_orders
Expand Down Expand Up @@ -814,6 +816,7 @@ pub mod pallet {
Error::<T>::UpdatingLimitOrdersDisabled
);
let lp = T::AccountRoleRegistry::ensure_liquidity_provider(origin)?;
T::LpBalance::ensure_has_refund_address_for_pair(&lp, sell_asset, buy_asset)?;
Self::try_mutate_enabled_pool(sell_asset, buy_asset, |asset_pair, pool| {
let tick = match (
pool.limit_orders[asset_pair.base_side]
Expand Down Expand Up @@ -889,6 +892,7 @@ pub mod pallet {
Error::<T>::UpdatingLimitOrdersDisabled
);
let lp = T::AccountRoleRegistry::ensure_liquidity_provider(origin)?;
T::LpBalance::ensure_has_refund_address_for_pair(&lp, sell_asset, buy_asset)?;
Self::try_mutate_enabled_pool(sell_asset, buy_asset, |asset_pair, pool| {
let tick = match (
pool.limit_orders[asset_pair.base_side]
Expand Down
15 changes: 15 additions & 0 deletions state-chain/traits/src/liquidity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ pub trait SwapDepositHandler {
pub trait LpBalanceApi {
type AccountId;

fn ensure_has_refund_address_for_pair(
who: &Self::AccountId,
base_asset: Asset,
pair_asset: Asset,
) -> DispatchResult;

/// Attempt to credit the account with the given asset and amount.
fn try_credit_account(
who: &Self::AccountId,
Expand Down Expand Up @@ -67,6 +73,15 @@ impl<T: frame_system::Config> SwappingApi for T {
impl<T: frame_system::Config> LpBalanceApi for T {
type AccountId = T::AccountId;

fn ensure_has_refund_address_for_pair(
_who: &Self::AccountId,
_base_asset: Asset,
_pair_asset: Asset,
) -> DispatchResult {
// TODO
Ok(())
}

fn try_credit_account(
_who: &Self::AccountId,
_asset: Asset,
Expand Down
Loading