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

Pools: use Rate represented as 18 decimals #1520

Merged
merged 12 commits into from Sep 4, 2023
Merged

Conversation

lemunozm
Copy link
Contributor

@lemunozm lemunozm commented Aug 30, 2023

Description

This PR changes the internal Rate representation for pool_system (and derivatives)

Changes and Descriptions

  • Update Rate by Ratio or Quantity where it should be used.
  • Rate of pool_system split into BalanceRatio (18 decimals for prices) and Rate (27 decimals for interest rates).
  • Add official StorageVersion for pool_system and investments and update the value to 1.
  • Nuke pool_system storages for altair & centrifuge runtimes.
  • Nuke investments storages for altair & centrifuge runtimes.

--> IMPORTANT: Should we nuke also liquidity_pools and liquidity_pools_gateway? It seems the storage is not still used.

Testing

algol

Comand:

RUST_LOG=runtime=trace,try-runtime::cli=trace,executor=trace cargo run --release --features try-runtime try-runtime --runtime target/release/wbuild/altair-runtime/altair_runtime.wasm --chain centrifuge on-runtime-upgrade live --uri wss://fullnode.algol.cntrfg.com:443

Output:

Nuke-PoolSystem: nuking pallet...
Nuke-PoolSystem: storage cleared successful
Nuke-PoolSystem: iteration result. backend: 7 unique: 7 loops: 7  
Nuke-Investments: nuking pallet...
Nuke-Investments: storage cleared successful
Nuke-Investments: iteration result. backend: 1 unique: 1 loops: 1 

altair

Comand:

RUST_LOG=runtime=trace,try-runtime::cli=trace,executor=trace cargo run --release --features try-runtime try-runtime --runtime target/release/wbuild/altair-runtime/altair_runtime.wasm --chain centrifuge on-runtime-upgrade live --uri wss://fullnode.altair.centrifuge.io:443

Output:

Nuke-PoolSystem: nuking pallet...
Nuke-PoolSystem: storage cleared successful
Nuke-PoolSystem: iteration result. backend: 4 unique: 4 loops: 4  
Nuke-Investments: nuking pallet...
Nuke-Investments: storage cleared successful
Nuke-Investments: iteration result. backend: 0 unique: 0 loops: 0 

catalyst

Command:

RUST_LOG=runtime=trace,try-runtime::cli=trace,executor=trace cargo run --release --features try-runtime try-runtime --runtime target/release/wbuild/centrifuge-runtime/centrifuge_runtime.wasm --chain centrifuge on-runtime-upgrade live --uri wss://fullnode.catalyst.cntrfg.com:443

Output:

Nuke-PoolSystem: nuking pallet...
Nuke-PoolSystem: storage cleared successful
Nuke-PoolSystem: iteration result. backend: 3 unique: 3 loops: 3  
Nuke-Investments: nuking pallet...
Nuke-Investments: storage cleared successful
Nuke-Investments: iteration result. backend: 7 unique: 7 loops: 7 

centrifuge

Command:

RUST_LOG=runtime=trace,try-runtime::cli=trace,executor=trace cargo run --release --features try-runtime try-runtime --runtime target/release/wbuild/centrifuge-runtime/centrifuge_runtime.wasm --chain centrifuge on-runtime-upgrade live --uri wss://fullnode.centrifuge.io:443

Output:

Nuke-PoolSystem: nuking pallet...
Nuke-PoolSystem: storage cleared successful
Nuke-PoolSystem: iteration result. backend: 0 unique: 0 loops: 0  
Nuke-Investments: nuking pallet...
Nuke-Investments: storage cleared successful
Nuke-Investments: iteration result. backend: 0 unique: 0 loops: 0 

@lemunozm lemunozm added I3-annoyance The code behaves as expected, but "expected" is an issue. I9-release A specific release. P7-asap Issue should be addressed in the next days. labels Aug 30, 2023
@lemunozm lemunozm self-assigned this Aug 30, 2023
Comment on lines +728 to 736
assert_eq!(pool.reserve.total, 758968368969420653250);
assert_eq!(
pool.tranches.residual_top_slice()[SENIOR_TRANCHE_INDEX as usize].reserve,
251031631030579346631
251031631030579346511
);
assert_eq!(
pool.reserve.total + senior_price.saturating_mul_int(250 * CURRENCY),
1010 * CURRENCY + 1 // TODO: Fix rounding issue with FixedPointNumberExtension
1009999999999999999750 // TODO: Fix rounding issue with FixedPointNumberExtension
);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

After separating the pool rate into 18 and 27 decimals, I found these tests magic values has changed. I do not know where they come from (probably from calculating prices in tranches), but I'm not able to answer why they change in that way.

It changes in the last decimals, so it probably is an accumulated rounding issue with some pow() or similar.

@@ -1032,6 +1032,7 @@ parameter_types! {
impl pallet_pool_system::Config for Runtime {
type AssetRegistry = OrmlAssetRegistry;
type Balance = Balance;
type BalanceRatio = Quantity;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I named it as BalanceRatio because it is how the generic is called in some places in pool_system. But I do not feel well with any naming 😆, neither Quantity or Ratio. Probably we should refactor this with better naming in another PR.

Copy link
Contributor

@wischli wischli left a comment

Choose a reason for hiding this comment

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

The current changes LGTM.

I was wondering about pool_registry::Config::Rate which is still set to Rate but does not seem to be used apart from the ModifyPoolMock?! Maybe we can remove it.

@@ -1166,33 +1167,6 @@ impl PoolUpdateGuard for UpdateGuard {
}
}

pub struct CurrencyPriceSource;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not used

@lemunozm
Copy link
Contributor Author

I was wondering about pool_registry::Config::Rate which is still set to Rate but does not seem to be used apart from the ModifyPoolMock?! Maybe we can remove it.

Yeah, I also notice that. Probably, it can be removed, but not sure if it's there for a pending future change (?) @mustermeiszer

mustermeiszer
mustermeiszer previously approved these changes Aug 30, 2023
Copy link
Collaborator

@mustermeiszer mustermeiszer left a comment

Choose a reason for hiding this comment

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

Changes look good. The test magic values. I do not know...

@@ -55,13 +54,13 @@ impl<T: Config> PoolInspect<T::AccountId, T::CurrencyId> for Pallet<T> {
impl<T: Config> TrancheTokenPrice<T::AccountId, T::CurrencyId> for Pallet<T> {
type Moment = Moment;
type PoolId = T::PoolId;
type Rate = T::Rate;
type Rate = T::BalanceRatio;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would also rename taht

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@mustermeiszer
Copy link
Collaborator

Yeah, I also notice that. Probably, it can be removed, but not sure if it's there for a pending future change (?) @mustermeiszer

Artifact from the refactor with Bastian I guess. We are not planing on havin Rate values in the registry IIRC.

@lemunozm
Copy link
Contributor Author

Ok, if compiles with all features, I think it's ready

Copy link
Contributor

@wischli wischli left a comment

Choose a reason for hiding this comment

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

Reapproving

@wischli wischli enabled auto-merge (squash) September 4, 2023 09:35
@wischli wischli merged commit 442e0aa into main Sep 4, 2023
11 checks passed
@mustermeiszer mustermeiszer added the D5-breaks-api Pull request changes public api. Document changes publicly. label Sep 4, 2023
@lemunozm lemunozm deleted the pools/rate-18-decimals branch September 10, 2023 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
D5-breaks-api Pull request changes public api. Document changes publicly. I3-annoyance The code behaves as expected, but "expected" is an issue. I9-release A specific release. P7-asap Issue should be addressed in the next days.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants