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

Cleaning: Remove TradingPair #1741

Merged
merged 7 commits into from
Feb 23, 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
20 changes: 0 additions & 20 deletions libs/mocks/src/investment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ pub mod pallet {
register_call!(move |(a, b, c)| f(a, b, c));
}

pub fn mock_accepted_payment_currency(
f: impl Fn(T::InvestmentId, T::CurrencyId) -> bool + 'static,
) {
register_call!(move |(a, b)| f(a, b));
}

pub fn mock_investment(
f: impl Fn(&T::AccountId, T::InvestmentId) -> Result<T::Amount, DispatchError> + 'static,
) {
Expand All @@ -48,12 +42,6 @@ pub mod pallet {
register_call!(move |(a, b, c)| f(a, b, c));
}

pub fn mock_accepted_payout_currency(
f: impl Fn(T::InvestmentId, T::CurrencyId) -> bool + 'static,
) {
register_call!(move |(a, b)| f(a, b));
}

pub fn mock_redemption(
f: impl Fn(&T::AccountId, T::InvestmentId) -> Result<T::TrancheAmount, DispatchError>
+ 'static,
Expand Down Expand Up @@ -101,10 +89,6 @@ pub mod pallet {
execute_call!((a, b, c))
}

fn accepted_payment_currency(a: Self::InvestmentId, b: Self::CurrencyId) -> bool {
execute_call!((a, b))
}

fn investment(
a: &T::AccountId,
b: Self::InvestmentId,
Expand All @@ -120,10 +104,6 @@ pub mod pallet {
execute_call!((a, b, c))
}

fn accepted_payout_currency(a: Self::InvestmentId, b: Self::CurrencyId) -> bool {
execute_call!((a, b))
}

fn redemption(
a: &T::AccountId,
b: Self::InvestmentId,
Expand Down
26 changes: 0 additions & 26 deletions libs/mocks/src/token_swaps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ pub mod pallet {
register_call!(f);
}

pub fn mock_valid_pair(
f: impl Fn(T::CurrencyId, T::CurrencyId) -> DispatchResult + 'static,
) {
register_call!(move |(a, b)| f(a, b));
}

pub fn mock_get_order_details(
f: impl Fn(T::OrderId) -> Option<OrderInfo<T::BalanceOut, T::CurrencyId, T::Ratio>>
+ 'static,
Expand All @@ -81,13 +75,6 @@ pub mod pallet {
) {
register_call!(move |(a, b, c)| f(a, b, c))
}

#[cfg(feature = "runtime-benchmarks")]
pub fn mock_add_trading_pair(
f: impl Fn(T::CurrencyId, T::CurrencyId, T::BalanceOut) -> DispatchResult + 'static,
) {
register_call!(move |(a, b, c)| f(a, b, c))
}
}

impl<T: Config> TokenSwaps<T::AccountId> for Pallet<T> {
Expand Down Expand Up @@ -119,10 +106,6 @@ pub mod pallet {
execute_call!(a)
}

fn valid_pair(a: Self::CurrencyId, b: Self::CurrencyId) -> bool {
execute_call!((a, b))
}

fn get_order_details(
a: Self::OrderId,
) -> Option<OrderInfo<Self::BalanceOut, Self::CurrencyId, Self::Ratio>> {
Expand All @@ -140,14 +123,5 @@ pub mod pallet {
fn fill_order(a: T::AccountId, b: Self::OrderId, c: Self::BalanceOut) -> DispatchResult {
execute_call!((a, b, c))
}

#[cfg(feature = "runtime-benchmarks")]
fn add_trading_pair(
a: Self::CurrencyId,
b: Self::CurrencyId,
c: Self::BalanceOut,
) -> DispatchResult {
execute_call!((a, b, c))
}
}
}
26 changes: 0 additions & 26 deletions libs/traits/src/investments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ pub trait Investment<AccountId> {
amount: Self::Amount,
) -> Result<(), Self::Error>;

/// Checks whether a currency can be used for buying the given investment.
fn accepted_payment_currency(
investment_id: Self::InvestmentId,
currency: Self::CurrencyId,
) -> bool;

/// Returns, if possible, the currently unprocessed investment amount (in
/// pool currency) of who into the given investment class.
///
Expand All @@ -70,13 +64,6 @@ pub trait Investment<AccountId> {
amount: Self::TrancheAmount,
) -> Result<(), Self::Error>;

/// Checks whether a currency is accepted as a payout for the given
/// investment.
fn accepted_payout_currency(
investment_id: Self::InvestmentId,
currency: Self::CurrencyId,
) -> bool;

/// Returns, if possible, the currently unprocessed redemption amount (in
/// tranche tokens) of who into the given investment class.
///
Expand Down Expand Up @@ -329,17 +316,4 @@ pub trait ForeignInvestment<AccountId> {
who: &AccountId,
investment_id: Self::InvestmentId,
) -> Result<Self::TrancheAmount, Self::Error>;

/// Checks whether a currency can be used for buying the given investment.
fn accepted_payment_currency(
investment_id: Self::InvestmentId,
currency: Self::CurrencyId,
) -> bool;

/// Checks whether a currency is accepted as a payout for the given
/// investment.
fn accepted_payout_currency(
investment_id: Self::InvestmentId,
currency: Self::CurrencyId,
) -> bool;
}
16 changes: 0 additions & 16 deletions libs/traits/src/swaps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@ pub trait TokenSwaps<Account> {
amount: Self::BalanceOut,
) -> DispatchResult;

/// A sanity check that can be used for validating that a trading pair
/// is supported. Will also be checked when placing an order but might be
/// cheaper.
fn valid_pair(currency_in: Self::CurrencyId, currency_out: Self::CurrencyId) -> bool;

/// Cancel an already active order.
fn cancel_order(order: Self::OrderId) -> DispatchResult;

Expand All @@ -103,14 +98,6 @@ pub trait TokenSwaps<Account> {
currency_out: Self::CurrencyId,
amount_out: Self::BalanceOut,
) -> Result<Self::BalanceIn, DispatchError>;

#[cfg(feature = "runtime-benchmarks")]
/// Adds a valid trading pair.
fn add_trading_pair(
currency_in: Self::CurrencyId,
currency_out: Self::CurrencyId,
min_order: Self::BalanceOut,
) -> DispatchResult;
}

/// A representation of a currency swap in process.
Expand Down Expand Up @@ -172,9 +159,6 @@ pub trait Swaps<AccountId> {
from_currency: Self::CurrencyId,
) -> Result<Self::Amount, DispatchError>;

/// Check that validates that if swapping pair is supported.
fn valid_pair(currency_in: Self::CurrencyId, currency_out: Self::CurrencyId) -> bool;

/// Makes a conversion between 2 currencies using the market ratio between
/// them
// TODO: Should be removed after #1723
Expand Down
24 changes: 2 additions & 22 deletions pallets/foreign-investments/src/impls.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Trait implementations. Higher level file.

use cfg_traits::{
investments::{ForeignInvestment, Investment, InvestmentCollector, TrancheCurrency},
investments::{ForeignInvestment, Investment, InvestmentCollector},
swaps::{SwapState, Swaps},
PoolInspect, StatusNotificationHook,
StatusNotificationHook,
};
use cfg_types::investments::CollectedAmount;
use frame_support::pallet_prelude::*;
Expand Down Expand Up @@ -203,26 +203,6 @@ impl<T: Config> ForeignInvestment<T::AccountId> for Pallet<T> {
) -> Result<T::TrancheBalance, DispatchError> {
T::Investment::redemption(who, investment_id)
}

fn accepted_payment_currency(investment_id: T::InvestmentId, currency: T::CurrencyId) -> bool {
if T::Investment::accepted_payment_currency(investment_id, currency) {
true
} else {
T::PoolInspect::currency_for(investment_id.of_pool())
.map(|pool_currency| T::Swaps::valid_pair(pool_currency, currency))
.unwrap_or(false)
}
}

fn accepted_payout_currency(investment_id: T::InvestmentId, currency: T::CurrencyId) -> bool {
if T::Investment::accepted_payout_currency(investment_id, currency) {
true
} else {
T::PoolInspect::currency_for(investment_id.of_pool())
.map(|pool_currency| T::Swaps::valid_pair(currency, pool_currency))
.unwrap_or(false)
}
}
}

pub struct FulfilledSwapHook<T>(PhantomData<T>);
Expand Down
18 changes: 0 additions & 18 deletions pallets/investments/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1097,15 +1097,6 @@ impl<T: Config> Investment<T::AccountId> for Pallet<T> {
Pallet::<T>::do_update_investment(who.clone(), investment_id, amount)
}

fn accepted_payment_currency(
investment_id: Self::InvestmentId,
currency: Self::CurrencyId,
) -> bool {
T::Accountant::info(investment_id)
.map(|info| info.payment_currency == currency)
.unwrap_or(false)
}

fn investment(
who: &T::AccountId,
investment_id: Self::InvestmentId,
Expand All @@ -1122,15 +1113,6 @@ impl<T: Config> Investment<T::AccountId> for Pallet<T> {
Pallet::<T>::do_update_redemption(who.clone(), investment_id, amount)
}

fn accepted_payout_currency(
investment_id: Self::InvestmentId,
currency: Self::CurrencyId,
) -> bool {
T::Accountant::info(investment_id)
.map(|info| info.payment_currency == currency)
.unwrap_or(false)
}

fn redemption(
who: &T::AccountId,
investment_id: Self::InvestmentId,
Expand Down
15 changes: 6 additions & 9 deletions pallets/liquidity-pools/src/inbound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ where
amount: <T as Config>::Balance,
) -> DispatchResult {
let invest_id: T::TrancheCurrency = Self::derive_invest_id(pool_id, tranche_id)?;
let payment_currency = Self::try_get_payment_currency(invest_id.clone(), currency_index)?;
let payment_currency = Self::try_get_currency_id(currency_index)?;

// Mint additional amount of payment currency
T::Tokens::mint_into(payment_currency, &investor, amount)?;
Expand Down Expand Up @@ -134,10 +134,7 @@ where
amount: <T as Config>::Balance,
) -> DispatchResult {
let invest_id: T::TrancheCurrency = Self::derive_invest_id(pool_id, tranche_id)?;
// NOTE: Even though we can assume this currency to have been used as payment,
// the trading pair needs to be registered for the opposite direction as hin
// case a swap from pool to foreign results from updating the `InvestState`
let payout_currency = Self::try_get_payout_currency(invest_id.clone(), currency_index)?;
let payout_currency = Self::try_get_currency_id(currency_index)?;

T::ForeignInvestment::decrease_foreign_investment(
&investor,
Expand Down Expand Up @@ -187,7 +184,7 @@ where
sending_domain: DomainAddress,
) -> DispatchResult {
let invest_id: T::TrancheCurrency = Self::derive_invest_id(pool_id, tranche_id)?;
let payout_currency = Self::try_get_payout_currency(invest_id.clone(), currency_index)?;
let payout_currency = Self::try_get_currency_id(currency_index)?;

// Transfer tranche tokens from `DomainLocator` account of
// origination domain
Expand Down Expand Up @@ -227,7 +224,7 @@ where
) -> DispatchResult {
let invest_id: T::TrancheCurrency = Self::derive_invest_id(pool_id, tranche_id)?;
let currency_u128 = currency_index.index;
let payout_currency = Self::try_get_payout_currency(invest_id.clone(), currency_index)?;
let payout_currency = Self::try_get_currency_id(currency_index)?;

T::ForeignInvestment::decrease_foreign_redemption(
&investor,
Expand Down Expand Up @@ -304,7 +301,7 @@ where
currency_index: GeneralCurrencyIndexOf<T>,
) -> DispatchResult {
let invest_id: T::TrancheCurrency = Self::derive_invest_id(pool_id, tranche_id)?;
let payment_currency = Self::try_get_payment_currency(invest_id.clone(), currency_index)?;
let payment_currency = Self::try_get_currency_id(currency_index)?;

// NOTE: Dispatch of `ExecutedCollectInvest` is handled by
// `ExecutedCollectInvestHook`
Expand All @@ -331,7 +328,7 @@ where
currency_index: GeneralCurrencyIndexOf<T>,
) -> DispatchResult {
let invest_id: T::TrancheCurrency = Self::derive_invest_id(pool_id, tranche_id)?;
let payout_currency = Self::try_get_payout_currency(invest_id.clone(), currency_index)?;
let payout_currency = Self::try_get_currency_id(currency_index)?;

T::ForeignInvestment::collect_foreign_redemption(&investor, invest_id, payout_currency)?;

Expand Down
Loading
Loading