-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: init blank pool fees pallet * chore: apply workspace #1609 to pool-fees dummy * fix: docker-compose * feat: add changeguard pool fees support * wip: prepare payment logic * refactor: use reserve instead of nav * chore: add extrinsics * feat: prep + pay disbursements * refactor: Apply fees ChangeGuard to #1637 * feat: add pool fees to all runtimes * feat: add fees pool registration * fix: existing pool unit tests * fix: existing integration tests * docs: add pool fee types * wip: init fees unit tests * tests: extrinsics wip * chore: add events * tests: add pool fees unit tests * fix: support retroactive disbursements * refactor: add epoch transition hook * refactor: add pool fee prefix to types * refactor: remove redundand trait bounds * wip: pool system integration tests * refactor: move portfolio valuation from loans to cfg-types * chore: add pool fee account id * wip: pool fee nav * wip: fix uts * wip: fix apply review by @lemunozm * fix: issues after rebase * tests: add saturated_proration * refactor: simplify pool fee amounts * chore: aum + fix fees UTs * chore: apply AUM to pool-system * fix: remove AUM coupling in PoolFees * fix: transfer on close, unit tests * fix: use total nav * fix: taplo * fix: fee calc on nav closing * feat: impl TimeAsSecs for timestamp mock * fix: test on_closing instead of update_active_fees * fix: clippy * tests: fix + add missing pool fees * refactor: make update fees result instead of void * tests: add insufficient resource in p-system * bench: add pool fees, apply to system + registry * fix: tests * refactor: explicitly use Seconds in FeeAmountProration impl * docs: add PoolFeeAmount and NAV update * refactor: update NAV, total assets after review from @mustermeiszer * fix: clippy * refactor: Add PoolFeePayable * fix: clippy * fix: correct epoch execution with fees (#1695) * fix: correct epoch execution with fees * refactor: use new nav syntax * tests: fix auto epoch closing * feat: epoch execution migration * chore: add epoch migration to altair --------- Co-authored-by: William Freudenberger <[email protected]> --------- Co-authored-by: Guillermo Perez <[email protected]> Co-authored-by: Frederik Gartenmeister <[email protected]>
- Loading branch information
1 parent
ca18a90
commit 0426f76
Showing
58 changed files
with
4,876 additions
and
216 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright 2023 Centrifuge Foundation (centrifuge.io). | ||
|
||
// Centrifuge is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version (see http://www.gnu.org/licenses). | ||
|
||
// Centrifuge is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
use frame_support::dispatch::{Decode, Encode, MaxEncodedLen, TypeInfo}; | ||
use sp_runtime::DispatchResult; | ||
use strum::{EnumCount, EnumIter}; | ||
|
||
/// The priority segregation of pool fees | ||
/// | ||
/// NOTE: Whenever a new variant is added, must bump | ||
/// [cfg_primitives::MAX_FEES_PER_POOL]. | ||
#[derive( | ||
Debug, Encode, Decode, EnumIter, EnumCount, TypeInfo, MaxEncodedLen, PartialEq, Eq, Clone, Copy, | ||
)] | ||
pub enum PoolFeeBucket { | ||
/// Fees that are charged first, before any redemptions, investments, | ||
/// repayments or originations | ||
Top, | ||
// Future: AfterTranche(TrancheId) | ||
} | ||
|
||
/// Trait to add fees to a pool | ||
pub trait PoolFees { | ||
type PoolId; | ||
type FeeInfo; | ||
|
||
/// Add a new fee to the pool and bucket. | ||
/// | ||
/// NOTE: Assumes call permissions are separately checked beforehand. | ||
fn add_fee(pool_id: Self::PoolId, bucket: PoolFeeBucket, fee: Self::FeeInfo) -> DispatchResult; | ||
|
||
/// Returns the maximum number of pool fees per bucket required for accurate | ||
/// weights | ||
fn get_max_fees_per_bucket() -> u32; | ||
|
||
/// Returns the current amount of active fees for the given pool and bucket | ||
/// pair | ||
fn get_pool_fee_bucket_count(pool: Self::PoolId, bucket: PoolFeeBucket) -> u32; | ||
} | ||
|
||
/// Trait to prorate a fee amount to a rate or amount | ||
pub trait FeeAmountProration<Balance, Rate, Time> { | ||
/// Returns the prorated amount based on the NAV passed time period. | ||
fn saturated_prorated_amount(&self, portfolio_valuation: Balance, period: Time) -> Balance; | ||
|
||
/// Returns the proratio rate based on the NAV and passed time period. | ||
fn saturated_prorated_rate(&self, portfolio_valuation: Balance, period: Time) -> Rate; | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use strum::IntoEnumIterator; | ||
|
||
use super::*; | ||
|
||
#[test] | ||
fn max_fees_per_pool() { | ||
assert!( | ||
cfg_primitives::MAX_POOL_FEES_PER_BUCKET | ||
<= (cfg_primitives::MAX_FEES_PER_POOL * PoolFeeBucket::iter().count() as u32), | ||
"Need to bump MAX_FEES_PER_POOL after adding variant(s) to PoolFeeBuckets" | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.