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

lp: Add compute_at to UpdateTrancheTokenPrice #1598

Merged
merged 2 commits into from
Oct 24, 2023

Conversation

NunoAlexandre
Copy link
Contributor

After a discussion within the MultiChain team, we agreed that we need to include the timestamp at which a tranche token price was calculated in the UpdateTrancheToken message.

Given that we add this new field at the end of the message, no migrations or special handing is necessary since this will make this messages backwards and forwards compatible.

@NunoAlexandre NunoAlexandre self-assigned this Oct 24, 2023
@@ -193,6 +193,7 @@ pub mod pallet {
BalanceRatio = Self::BalanceRatio,
PoolId = Self::PoolId,
TrancheId = Self::TrancheId,
Moment = Seconds,
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 needed to set this restriction here so that we can have the PriceValue.last_updated field bound to Seconds and therefore bound to the computed_at field of UpdateTrancheTokenPrice.

AFAIK this should be an acceptable bound but please let me know if I am overseeing anything here.

Copy link
Contributor

@lemunozm lemunozm Oct 24, 2023

Choose a reason for hiding this comment

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

Maybe it can be handled also by creating a MomentOf<T> type and passing to the Message struct.

Having it as Seconds type (which is an u64) could lead to mixing them with other time precisions as milliseconds (also u64). But having it through the associated type is not.

Copy link
Contributor

@lemunozm lemunozm Oct 24, 2023

Choose a reason for hiding this comment

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

In the future Seconds and Millis should have wrappers around u64 with math support to avoid mixing them

Copy link
Contributor

Choose a reason for hiding this comment

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

But not super strong opinion, I have pallet_loans populated with Seconds right now 😆

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah we definitly should have strong typing around those two different units of time 👍

is your suggestion adding a Moment type to the Config of liquidity pools and bound the PriceValue<Moment = T::Moment>? I want to keep the type at the message level concrete and not abstract since messages are type-fixed or else they will break; but we can have a Into<u64> or Into<Seconds> trait bound for this Moment type.

what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

I want to keep the type at the message level concrete and not abstract since messages are type-fixed or else they will break

But yes, if you want to have more control over the type used, T::moment will work for sure!

Copy link
Contributor

Choose a reason for hiding this comment

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

Wondering now, if the encoding dictates everything in this pallet, maybe allowing the user to choose i.e the PoolId or the TrancheId they want is not the safer way.

Should these associated types actually be types?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah exactly, I didn't want to do that because we then need to bound it to u64 to match the expected type in the message. Of course than in a normal scenario that's not what we want so that the pallet is actually generic over these types but for liquidity-pools, a multi-chain system, being type generic over the messages' fields is not desired.

So we can:

  1. Keep thing as are with a strict bound on PriceValue<Moment = which is the least invasive

  2. Add a Moment type to the pallet' Config and have PriceValue<Moment bound to this type AND have the type implement ToSeconds or Into<u64>.

I am cool with the second but maybe we could keep things as are now and implement the latter change once we introduce strong typing for Seconds and Millis. wdyt @lemunozm ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, being the message who dictates here, I think leaving this as they're now is ok 👍🏻
As you say, the mixing issue will be fixed with strong typing in Seconds.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hit the merge button! 🚀

Copy link
Contributor

@hieronx hieronx left a comment

Choose a reason for hiding this comment

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

🚀

@NunoAlexandre NunoAlexandre merged commit 90d3cf9 into main Oct 24, 2023
10 checks passed
@NunoAlexandre NunoAlexandre deleted the lp/token-price-computed branch October 24, 2023 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants