use cfg_primitives::OrderId;
use frame_support::pallet_prelude::RuntimeDebug;
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
use sp_runtime::{
traits::{EnsureAddAssign, Zero},
DispatchResult,
};
use sp_std::cmp::PartialEq;
use crate::orders::Order;
#[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug, TypeInfo)]
pub struct InvestmentAccount<InvestmentId> {
pub investment_id: InvestmentId,
}
#[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug, Default, TypeInfo)]
pub struct InvestmentInfo<AccountId, Currency, InvestmentId> {
pub owner: AccountId,
pub id: InvestmentId,
pub payment_currency: Currency,
}
#[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug, TypeInfo)]
pub struct InvestCollection<Balance> {
pub payout_investment_invest: Balance,
pub remaining_investment_invest: Balance,
}
impl<Balance: Zero> Default for InvestCollection<Balance> {
fn default() -> Self {
InvestCollection {
payout_investment_invest: Zero::zero(),
remaining_investment_invest: Zero::zero(),
}
}
}
impl<Balance: Zero + Copy> InvestCollection<Balance> {
pub fn from_order(order: &Order<Balance, OrderId>) -> Self {
InvestCollection {
payout_investment_invest: Zero::zero(),
remaining_investment_invest: order.amount(),
}
}
}
#[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug, TypeInfo)]
pub struct RedeemCollection<Balance> {
pub payout_investment_redeem: Balance,
pub remaining_investment_redeem: Balance,
}
impl<Balance: Zero> Default for RedeemCollection<Balance> {
fn default() -> Self {
RedeemCollection {
payout_investment_redeem: Zero::zero(),
remaining_investment_redeem: Zero::zero(),
}
}
}
impl<Balance: Zero + Copy> RedeemCollection<Balance> {
pub fn from_order(order: &Order<Balance, OrderId>) -> Self {
RedeemCollection {
payout_investment_redeem: Zero::zero(),
remaining_investment_redeem: order.amount(),
}
}
}
#[derive(Encode, Default, Decode, Clone, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
pub struct CollectedAmount<Collected, Payment> {
pub amount_collected: Collected,
pub amount_payment: Payment,
}
impl<Collected: EnsureAddAssign + Copy, Payment: EnsureAddAssign + Copy>
CollectedAmount<Collected, Payment>
{
pub fn increase(&mut self, other: &Self) -> DispatchResult {
self.amount_collected
.ensure_add_assign(other.amount_collected)?;
self.amount_payment
.ensure_add_assign(other.amount_payment)?;
Ok(())
}
}
#[derive(Encode, Decode, Default, Clone, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
pub struct InvestmentPortfolio<Balance, CurrencyId> {
pub pool_currency_id: CurrencyId,
pub pending_invest_currency: Balance,
pub claimable_tranche_tokens: Balance,
pub free_tranche_tokens: Balance,
pub reserved_tranche_tokens: Balance,
pub pending_redeem_tranche_tokens: Balance,
pub claimable_currency: Balance,
}
impl<Balance: Default, CurrencyId> InvestmentPortfolio<Balance, CurrencyId> {
pub fn new(pool_currency_id: CurrencyId) -> Self {
Self {
pool_currency_id,
pending_invest_currency: Balance::default(),
claimable_tranche_tokens: Balance::default(),
free_tranche_tokens: Balance::default(),
reserved_tranche_tokens: Balance::default(),
pending_redeem_tranche_tokens: Balance::default(),
claimable_currency: Balance::default(),
}
}
pub fn with_pending_invest_currency(mut self, amount: Balance) -> Self {
self.pending_invest_currency = amount;
self
}
pub fn with_free_tranche_tokens(mut self, amount: Balance) -> Self {
self.free_tranche_tokens = amount;
self
}
pub fn with_reserved_tranche_tokens(mut self, amount: Balance) -> Self {
self.reserved_tranche_tokens = amount;
self
}
pub fn with_claimable_tranche_tokens(mut self, amount: Balance) -> Self {
self.claimable_tranche_tokens = amount;
self
}
pub fn with_pending_redeem_tranche_tokens(mut self, amount: Balance) -> Self {
self.pending_redeem_tranche_tokens = amount;
self
}
pub fn with_claimable_currency(mut self, amount: Balance) -> Self {
self.claimable_currency = amount;
self
}
}