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: enable full foreign collect flow via extrinsic #1556

Merged
merged 13 commits into from
Sep 22, 2023
4 changes: 1 addition & 3 deletions libs/traits/src/investments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ pub trait ForeignInvestment<AccountId> {
type CurrencyId;
type Error: Debug;
type InvestmentId;
type CollectInvestResult;

/// Initiates the increment of a foreign investment amount in
/// `foreign_payment_currency` of who into the investment class
Expand Down Expand Up @@ -365,8 +364,7 @@ pub trait ForeignInvestment<AccountId> {
who: &AccountId,
investment_id: Self::InvestmentId,
foreign_currency: Self::CurrencyId,
pool_currency: Self::CurrencyId,
) -> Result<Self::CollectInvestResult, Self::Error>;
) -> Result<(), Self::Error>;

/// Collect the results of a user's foreign redeem orders for the given
/// investment. If any amounts are not fulfilled they are directly
Expand Down
43 changes: 21 additions & 22 deletions libs/types/src/investments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ pub struct Swap<
pub currency_in: Currency,
/// The outgoing currency, i.e. the one which should be replaced.
pub currency_out: Currency,
/// The amount of outgoing currency which shall be exchanged.
/// The amount of incoming currency which shall be bought.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See this comment for explanation.

pub amount: Balance,
}

Expand Down Expand Up @@ -237,30 +237,29 @@ pub struct ExecutedForeignDecreaseInvest<Balance, Currency> {
pub amount_remaining: Balance,
}

/// A representation of an executed collected investment.
/// A representation of an executed collected foreign investment or redemption.
#[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug, Default, TypeInfo, MaxEncodedLen)]

pub struct ExecutedForeignCollectInvest<Balance> {
/// The amount that was actually collected
pub amount_currency_payout: Balance,
/// The amount of tranche tokens received for the investment made
pub amount_tranche_tokens_payout: Balance,
/// The unprocessed plus processed but not yet collected investment amount
/// denominated in foreign currency
pub amount_remaining_invest: Balance,
}

/// A representation of an executed collected redemption.
#[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug, Default, TypeInfo, MaxEncodedLen)]

pub struct ExecutedForeignCollectRedeem<Balance, Currency> {
/// The foreign currency in which the payout takes place
pub struct ExecutedForeignCollect<Balance, Currency> {
/// The foreign currency in which ...
/// * If investment: the payment took place
/// * If redemption: the payout takes place
pub currency: Currency,
/// The amount of `currency` being paid out to the investor

/// The amount of `currency`...
/// * If investment: that was collected
/// * If redemption: paid out to the investor
pub amount_currency_payout: Balance,
/// How many tranche tokens were actually redeemed

/// The amount of tranche tokens...
/// * If investment: received for the investment made
/// * If redemption: which were actually redeemed
pub amount_tranche_tokens_payout: Balance,
/// The unprocessed plus processed but not yet collected redemption amount
/// of tranche tokens
pub amount_remaining_redeem: Balance,

/// The unprocessed ...
/// * If investment: investment amount of `currency` (denominated in foreign
/// currency)
/// * If redemption: redemption amount of tranche tokens (denominated in
/// pool currency)
pub amount_remaining: Balance,
}
19 changes: 12 additions & 7 deletions pallets/foreign-investments/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ pub enum InvestError {
CollectTransition,
/// The investment needs to be collected before it can be updated further.
CollectRequired,
/// The provided currency does not match the one stored when the first
/// investment increase was triggered.
///
/// NOTE: As long as the `InvestmentState` has not been cleared, the
/// payment currency cannot change from the initially provided one.
InvalidPaymentCurrency,
}

#[derive(Encode, Decode, TypeInfo, PalletError)]
Expand All @@ -41,13 +47,6 @@ pub enum RedeemError {
IncreaseTransition,
/// Failed to collect the redemption.
CollectTransition,
/// Failed to retrieve the foreign payout currency for a collected
/// redemption.
///
/// NOTE: This error can only occur, if a user tries to collect before
/// having increased their redemption as this would store the payout
/// currency.
CollectPayoutCurrencyNotFound,
/// The desired decreasing amount exceeds the max amount.
DecreaseAmountOverflow,
/// Failed to transition the state as a result of a decrease.
Expand All @@ -56,6 +55,12 @@ pub enum RedeemError {
FulfillSwapOrderTransition,
/// The redemption needs to be collected before it can be updated further.
CollectRequired,
/// The provided currency does not match the one stored when the first
/// redemption increase was triggered.
///
/// NOTE: As long as the `RedemptionState` has not been cleared, the
/// payout currency cannot change from the initially provided one.
InvalidPayoutCurrency,
}

impl<T: Config> From<InvestError> for Error<T> {
Expand Down
Loading
Loading