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

LPv2: ForeignInvestments changes #1895

Merged
merged 36 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
43f851d
add uts (#1905)
lemunozm Jul 11, 2024
18e3753
main changes for FI
lemunozm Jul 1, 2024
38d5ae7
fix correlation precission
lemunozm Jul 1, 2024
d1d2ed6
minor renames
lemunozm Jul 1, 2024
ed80c3e
update investment UTs
lemunozm Jul 3, 2024
6324d10
update redemption UTs
lemunozm Jul 3, 2024
d410946
miscelaneous UTs
lemunozm Jul 3, 2024
ce7069b
minor renames
lemunozm Jul 4, 2024
9455501
simplify correlation and embed to the only needed place
lemunozm Jul 4, 2024
4ca7d7e
doc change
lemunozm Jul 4, 2024
f05b3fd
remove unused bound
lemunozm Jul 4, 2024
7ad4692
swapping calls into entities.rs file
lemunozm Jul 8, 2024
58ff813
merge SwapDone methods into FulfilledSwapHook
lemunozm Jul 8, 2024
51f279a
fix events
lemunozm Jul 8, 2024
fb3b061
working without pallet-swaps
lemunozm Jul 8, 2024
e4df219
remove boilerplate for removing entries
lemunozm Jul 8, 2024
d71e68c
minor msg change
lemunozm Jul 8, 2024
10f7f2a
minor simplification
lemunozm Jul 8, 2024
3645949
correct fulfilled sum after last collect
lemunozm Jul 8, 2024
63d9839
check OrderIdToSwapId storage
lemunozm Jul 9, 2024
56af82a
sending the message inside Info closure is not really a problem
lemunozm Jul 9, 2024
261d56e
send msgs from the entities
lemunozm Jul 9, 2024
ec637de
remove same currency check in impl.rs
lemunozm Jul 9, 2024
6d57a1a
unify hooks
lemunozm Jul 9, 2024
2c7aec5
remove pallet-swaps
lemunozm Jul 9, 2024
3c5a227
minor fmt
lemunozm Jul 9, 2024
8194284
add docs
lemunozm Jul 9, 2024
cd2199e
add architecture diagram
lemunozm Jul 9, 2024
483f946
return cancelled foreign amount from FI interface
lemunozm Jul 10, 2024
56f82c9
update liquidity-pools
lemunozm Jul 10, 2024
7e17f24
add messages to diagram
lemunozm Jul 10, 2024
3fa240a
implement hooks
lemunozm Jul 10, 2024
8778d91
fix runtimes
lemunozm Jul 10, 2024
847cedc
adapt integration-tests
lemunozm Jul 10, 2024
67d74f7
fix docs
lemunozm Jul 11, 2024
bd3a48e
fix clippy
lemunozm Jul 12, 2024
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 Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ members = [
"pallets/restricted-tokens",
"pallets/restricted-xtokens",
"pallets/rewards",
"pallets/swaps",
"pallets/token-mux",
"pallets/transfer-allowlist",
"runtime/altair",
Expand Down Expand Up @@ -249,7 +248,6 @@ pallet-pool-system = { path = "pallets/pool-system", default-features = false }
pallet-restricted-tokens = { path = "pallets/restricted-tokens", default-features = false }
pallet-restricted-xtokens = { path = "pallets/restricted-xtokens", default-features = false }
pallet-rewards = { path = "pallets/rewards", default-features = false }
pallet-swaps = { path = "pallets/swaps", default-features = false }
pallet-token-mux = { path = "pallets/token-mux", default-features = false }
pallet-transfer-allowlist = { path = "pallets/transfer-allowlist", default-features = false }

Expand Down
80 changes: 10 additions & 70 deletions libs/mocks/src/foreign_investment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ pub mod pallet {
register_call!(move |(a, b, c, d)| f(a, b, c, d));
}

pub fn mock_decrease_foreign_investment(
f: impl Fn(&T::AccountId, T::InvestmentId, T::Amount, T::CurrencyId) -> DispatchResult
+ 'static,
pub fn mock_cancel_foreign_investment(
f: impl Fn(&T::AccountId, T::InvestmentId, T::CurrencyId) -> DispatchResult + 'static,
) {
register_call!(move |(a, b, c, d)| f(a, b, c, d));
register_call!(move |(a, b, c)| f(a, b, c));
}

pub fn mock_increase_foreign_redemption(
Expand All @@ -45,48 +44,21 @@ pub mod pallet {
register_call!(move |(a, b, c, d)| f(a, b, c, d));
}

pub fn mock_decrease_foreign_redemption(
pub fn mock_cancel_foreign_redemption(
f: impl Fn(
&T::AccountId,
T::InvestmentId,
T::TrancheAmount,
T::CurrencyId,
) -> DispatchResult
) -> Result<T::TrancheAmount, DispatchError>
+ 'static,
) {
register_call!(move |(a, b, c, d)| f(a, b, c, d));
}

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

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

pub fn mock_investment(
f: impl Fn(&T::AccountId, T::InvestmentId) -> Result<T::Amount, DispatchError> + '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,
) {
register_call!(move |(a, b)| f(a, b));
}
}

impl<T: Config> ForeignInvestment<T::AccountId> for Pallet<T> {
type Amount = T::Amount;
type CurrencyId = T::CurrencyId;
type Error = DispatchError;
type InvestmentId = T::InvestmentId;
type TrancheAmount = T::TrancheAmount;

Expand All @@ -99,13 +71,12 @@ pub mod pallet {
execute_call!((a, b, c, d))
}

fn decrease_foreign_investment(
fn cancel_foreign_investment(
a: &T::AccountId,
b: Self::InvestmentId,
c: Self::Amount,
d: Self::CurrencyId,
c: Self::CurrencyId,
) -> DispatchResult {
execute_call!((a, b, c, d))
execute_call!((a, b, c))
}

fn increase_foreign_redemption(
Expand All @@ -117,43 +88,12 @@ pub mod pallet {
execute_call!((a, b, c, d))
}

fn decrease_foreign_redemption(
a: &T::AccountId,
b: Self::InvestmentId,
c: Self::TrancheAmount,
d: Self::CurrencyId,
) -> DispatchResult {
execute_call!((a, b, c, d))
}

fn collect_foreign_investment(
a: &T::AccountId,
b: Self::InvestmentId,
c: Self::CurrencyId,
) -> DispatchResult {
execute_call!((a, b, c))
}

fn collect_foreign_redemption(
fn cancel_foreign_redemption(
a: &T::AccountId,
b: Self::InvestmentId,
c: Self::CurrencyId,
) -> DispatchResult {
) -> Result<T::TrancheAmount, DispatchError> {
execute_call!((a, b, c))
}

fn investment(
a: &T::AccountId,
b: Self::InvestmentId,
) -> Result<Self::Amount, DispatchError> {
execute_call!((a, b))
}

fn redemption(
a: &T::AccountId,
b: Self::InvestmentId,
) -> Result<Self::TrancheAmount, DispatchError> {
execute_call!((a, b))
}
}
}
101 changes: 101 additions & 0 deletions libs/mocks/src/foreign_investment_hooks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#[frame_support::pallet(dev_mode)]
pub mod pallet {
use cfg_traits::investments::ForeignInvestmentHooks;
use frame_support::pallet_prelude::*;
use mock_builder::{execute_call, register_call};

#[pallet::config]
pub trait Config: frame_system::Config {
type Amount;
type TrancheAmount;
type CurrencyId;
type InvestmentId;
}

#[pallet::pallet]
pub struct Pallet<T>(_);

#[pallet::storage]
type CallIds<T: Config> = StorageMap<_, _, String, mock_builder::CallId>;

impl<T: Config> Pallet<T> {
pub fn mock_fulfill_cancel_investment(
f: impl Fn(
&T::AccountId,
T::InvestmentId,
T::CurrencyId,
T::Amount,
T::Amount,
) -> DispatchResult
+ 'static,
) {
register_call!(move |(a, b, c, d, e)| f(a, b, c, d, e));
}

pub fn mock_fulfill_collect_investment(
f: impl Fn(
&T::AccountId,
T::InvestmentId,
T::CurrencyId,
T::Amount,
T::TrancheAmount,
) -> DispatchResult
+ 'static,
) {
register_call!(move |(a, b, c, d, e)| f(a, b, c, d, e));
}

pub fn mock_fulfill_collect_redemption(
f: impl Fn(
&T::AccountId,
T::InvestmentId,
T::CurrencyId,
T::TrancheAmount,
T::Amount,
) -> DispatchResult
+ 'static,
) {
register_call!(move |(a, b, c, d, e)| f(a, b, c, d, e));
}
}

impl<T: Config> ForeignInvestmentHooks<T::AccountId> for Pallet<T> {
type Amount = T::Amount;
type CurrencyId = T::CurrencyId;
type InvestmentId = T::InvestmentId;
type TrancheAmount = T::TrancheAmount;

/// An async cancellation has been done
fn fulfill_cancel_investment(
a: &T::AccountId,
b: Self::InvestmentId,
c: Self::CurrencyId,
d: Self::Amount,
e: Self::Amount,
) -> DispatchResult {
execute_call!((a, b, c, d, e))
}

/// An async investment collection has been done
fn fulfill_collect_investment(
a: &T::AccountId,
b: Self::InvestmentId,
c: Self::CurrencyId,
d: Self::Amount,
e: Self::TrancheAmount,
) -> DispatchResult {
execute_call!((a, b, c, d, e))
}

/// An async redemption collection has been done
fn fulfill_collect_redemption(
a: &T::AccountId,
b: Self::InvestmentId,
c: Self::CurrencyId,
d: Self::TrancheAmount,
e: Self::Amount,
) -> DispatchResult {
execute_call!((a, b, c, d, e))
}
}
}
1 change: 1 addition & 0 deletions libs/mocks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub mod currency_conversion;
pub mod data;
pub mod fees;
pub mod foreign_investment;
pub mod foreign_investment_hooks;
pub mod investment;
pub mod liquidity_pools;
pub mod liquidity_pools_gateway_routers;
Expand Down
Loading
Loading