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(vpool): sqrt of liquidity depth tracked on pool #1243

Merged
merged 20 commits into from
Mar 31, 2023

Conversation

Unique-Divine
Copy link
Member

@Unique-Divine Unique-Divine commented Mar 28, 2023

Summary

Location Description
x/common Added functions for computing the square root of sdk.Dec and big.Int values and corresponding tests. The exact square root is computed using the underlying big integer for the decimal and preserves precision more than root solving.
proto/vpool Added SqrtDepth as a field of the Vpool type. This is part of an iterative change toward using the base reserves, peg multiplier, and bias for pricing swaps.
x/vpool Integrates changes to the protos, adds validation checks to Vpool.Validate, and uses the new square root functions in EditSwapInvariantProposal
modules like spot, oracle, perp, etc. Renames or other no-opp refactors

Notes to self (ignore)

  • fix types tests
  • fix keeper tests
  • fix damage dealt to other modules
  • fix integration tests
  • perform self-review
  • write review guide

@Unique-Divine Unique-Divine marked this pull request as ready for review March 29, 2023 03:29
@Unique-Divine Unique-Divine requested a review from a team as a code owner March 29, 2023 03:29
x/common/dec_test.go Show resolved Hide resolved
x/common/dec.go Outdated Show resolved Hide resolved
x/common/dec.go Outdated Show resolved Hide resolved
@Unique-Divine Unique-Divine enabled auto-merge (squash) March 29, 2023 07:22
@jgimeno
Copy link
Contributor

jgimeno commented Mar 29, 2023

I lack some context on why this change. Is there any doc?

@@ -3,5 +3,5 @@ package common
const (
TreasuryPoolModuleAccount = "treasury_pool"
// Precision for int representation in sdk.Int objects
Precision = int64(1_000_000)
MICRO = int64(1_000_000)
Copy link
Member

Choose a reason for hiding this comment

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

MICRO or MEGA? Also what's wrong with Precision?

In my mind,
micro ==> multiply by 10^-6
mega ==> multiply by 10^6

Copy link
Member Author

@Unique-Divine Unique-Divine Mar 30, 2023

Choose a reason for hiding this comment

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

If you have 2 dollars, you have 2 million micro dollars. The semantics here would be 2$ * MICRO = 2_000_000, so I'm using MICRO to express a unit conversion.

I think an even clearer name would be TO_MICRO, just to emphasize how to use it. 5 * TO_MICRO = 5_000_000 is probably easier to follow.

Precision is vague, and someone wouldn't know what it means by looking at it. In our case, we're not really using this value as a precision. It's just a simple multiplier into micro units.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, TO_MICRO or AS_MICRO would be more clear.

@Unique-Divine Unique-Divine requested a review from a team March 30, 2023 21:36
Copy link
Member

@k-yang k-yang left a comment

Choose a reason for hiding this comment

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

A couple of nits, but overall LGTM


// Bias refers to the net long-short bias of the market. The bias of a pool
// is equivalent to the sum of all base reserve changes since its creation.
// string bias = 5 [
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to include these commented-out fields in this PR?

BaseAssetReserve: sdk.NewDec(5 * common.Precision),
QuoteAssetReserve: sdk.NewDec(10 * common.TO_MICRO),
BaseAssetReserve: sdk.NewDec(5 * common.TO_MICRO),
SqrtDepth: common.MustSqrtDec(sdk.NewDec(5 * 10 * common.TO_MICRO * common.TO_MICRO)),
Copy link
Member

Choose a reason for hiding this comment

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

In this case, I would put in the literal number we expect rather than rely on a utility function to calculate it for us, because the utility function is also used in the class's code path to calculate this value. If something changes in the utility function, this test case would still pass even though the final value isn't what we expect for this vpool entity.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added a simplified constructor for this. I'll add a ticket to convert over most of the vpooltypes.Vpool initializations to use vpooltypes.NewVpool(types.ArgsNewVpool(...)) to accomplish this more directly.

Context: A Slack discussion

image

@k-yang k-yang disabled auto-merge March 31, 2023 14:20
@Unique-Divine Unique-Divine merged commit b7149d1 into master Mar 31, 2023
@Unique-Divine Unique-Divine deleted the realu/sqrt-depth branch March 31, 2023 22:00
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.

feat(vpool): store sqrt_depth on the vpool struct and use it for computations.
3 participants