-
Notifications
You must be signed in to change notification settings - Fork 124
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
Update pow10 functions #1622
Update pow10 functions #1622
Conversation
WalkthroughThe recent updates primarily focus on enhancing the precision and efficiency of mathematical operations involving powers of 10 across various components. This includes refactoring functions for exponentiation and multiplication, adjusting test cases, and simplifying conversion logic between different numerical representations. The changes aim to improve accuracy and performance, particularly in financial calculations and asset conversions. Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
Outside diff range and nitpick comments (3)
protocol/x/clob/keeper/liquidations.go (3)
Line range hint
35-35
: Resolve the undefined reference toKeeper
.It appears that the
Keeper
struct is not defined within this file or imported from another package. This could be a result of an incomplete code snippet or a missing import statement. Please ensure that theKeeper
struct is correctly defined or imported to resolve this issue.
Line range hint
164-164
: Ensure consistency in the definition or import ofKeeper
.Similar to the previous comment, the
Keeper
struct is referenced multiple times in the file but seems to be undefined or not imported. This issue needs to be addressed to ensure the file compiles without errors.Also applies to: 197-197
Line range hint
692-692
: Address the undefined functiongetFillQuoteQuantums
.The function
getFillQuoteQuantums
is called but not defined or imported in this file. This could lead to runtime errors. Please define this function or ensure it is correctly imported from the appropriate module.
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (16)
- protocol/daemons/pricefeed/client/price_function/util.go (1 hunks)
- protocol/daemons/pricefeed/client/price_function/util_test.go (1 hunks)
- protocol/lib/big_math.go (1 hunks)
- protocol/lib/big_math_test.go (1 hunks)
- protocol/lib/quantums.go (2 hunks)
- protocol/testutil/big/big.go (1 hunks)
- protocol/testutil/perpetuals/perpetuals.go (2 hunks)
- protocol/testutil/perpetuals/perpetuals_test.go (1 hunks)
- protocol/testutil/prices/market_param_price.go (2 hunks)
- protocol/testutil/prices/market_param_price_test.go (1 hunks)
- protocol/x/assets/keeper/asset.go (1 hunks)
- protocol/x/clob/keeper/liquidations.go (1 hunks)
- protocol/x/clob/types/price_to_subticks.go (2 hunks)
- protocol/x/clob/types/quantums.go (2 hunks)
- protocol/x/prices/keeper/market_price.go (1 hunks)
- protocol/x/ratelimit/types/params.go (1 hunks)
Files skipped from review due to trivial changes (1)
- protocol/testutil/prices/market_param_price_test.go
Additional context used
golangci-lint
protocol/x/ratelimit/types/params.go
28-28: undefined: Limiter
34-34: undefined: Limiter
41-41: undefined: LimitParams
52-52: undefined: LimitParams
42-42: undefined: LimitParams
44-44: undefined: Limiter
59-59: undefined: ErrInvalidRateLimitPeriod
63-63: undefined: ErrInvalidBaselineMinimum
67-67: undefined: ErrInvalidBaselineTvlPpm
protocol/x/clob/types/quantums.go
29-29: undefined: Subticks
protocol/x/clob/types/price_to_subticks.go
28-28: undefined: ClobPair
66-66: undefined: Subticks
68-68: undefined: ClobPair
protocol/x/prices/keeper/market_price.go
25-25: undefined: Keeper
30-30: undefined: Keeper
118-118: undefined: Keeper
102-102: undefined: GenerateMarketPriceUpdateIndexerEvents
protocol/daemons/pricefeed/client/price_function/util.go
16-16: undefined: validator
62-62: undefined: validator
72-72: undefined: validator
protocol/x/clob/keeper/liquidations.go
35-35: undefined: Keeper
164-164: undefined: Keeper
197-197: undefined: Keeper
692-692: undefined: getFillQuoteQuantums
Additional comments not posted (44)
protocol/testutil/perpetuals/perpetuals_test.go (1)
20-21
: The new test cases enhance coverage for edge cases.The added test cases for
MustHumanSizeToBaseQuantums
are well-formed and improve the robustness of the testing suite.protocol/testutil/prices/market_param_price.go (1)
91-107
: The updated function enhances clarity and maintainability.The changes to
MustHumanPriceToMarketPrice
correctly utilize the newBigIntMulPow10
function, improving the clarity and maintainability of the code.protocol/lib/quantums.go (2)
43-48
: Refactored to useBigPow10
for exponentiation, simplifying the logic and improving readability.
78-82
: Successfully refactored to utilizeBigPow10
for handling exponentiation, enhancing code clarity and maintainability.protocol/testutil/perpetuals/perpetuals.go (1)
100-109
: Refactored to useBigIntMulPow10
for converting human-readable size to quantums, simplifying the logic and ensuring consistency with the main application code.protocol/x/prices/keeper/market_price.go (1)
68-75
: Refactored to useBigPow10
for handling exponentiation during market price updates, aligning with the new standard for handling powers of ten across the codebase.protocol/x/assets/keeper/asset.go (1)
302-312
: Successfully refactored to useBigPow10
for exponentiation in asset-to-coin conversion, enhancing the clarity and maintainability of the code.protocol/daemons/pricefeed/client/price_function/util.go (1)
147-157
: Refactored to useBigPow10
for handling exponentiation in the reversal of big float slices, aligning with the new standard for handling powers of ten across the codebase.protocol/lib/big_math.go (1)
35-67
: ImplementedBigPow10
andBigIntMulPow10
using generics to handle exponentiation and multiplication by powers of ten flexibly across different integer types. This central change supports the simplification efforts seen throughout the codebase.protocol/daemons/pricefeed/client/price_function/util_test.go (9)
Line range hint
1-1
: Ensure the package and imports are correctly defined and necessary.
Line range hint
14-14
: Validate the constant definitions for accuracy and relevance to the tests.
Line range hint
20-20
: Check the error message for clarity and correctness inpositiveTagValidationError
.
Line range hint
22-22
: Review the test functionTestIsExchangeError_Mixed
for logic and correctness.
Line range hint
42-42
: Examine the test functionTestGetApiResponseValidator_validatePositiveNumericString_Mixed
for proper validation logic and error handling.
Line range hint
64-64
: Assess the test functionTestGetOnlyTickerAndExponent
for correct handling of different scenarios and error conditions.
Line range hint
86-86
: Evaluate the test functionTestGetUint64MedianFromShiftedBigFloatValues
for correct median calculation and error handling.
Line range hint
108-108
: Review the test functionTestReverseShiftBigFloatSlice
for correct functionality and precision handling.
Line range hint
130-130
: Check the test functionTestConvertFloat64ToString
for correct string conversion and formatting.protocol/lib/big_math_test.go (25)
Line range hint
1-1
: Ensure the package and imports are correctly defined and necessary.
Line range hint
10-10
: Review the benchmark functionBenchmarkBigI
for correct functionality and performance testing.
Line range hint
18-18
: Evaluate the benchmark functionBenchmarkBigU
for correct functionality and performance testing.
Line range hint
26-26
: Check the test functionTestBigI
for correct integer conversion.
Line range hint
34-34
: Assess the test functionTestBigU
for correct unsigned integer conversion.
Line range hint
42-42
: Review the benchmark functionBenchmarkBigMulPpm_RoundDown
for correct functionality and performance testing.
Line range hint
50-50
: Evaluate the benchmark functionBenchmarkBigMulPpm_RoundUp
for correct functionality and performance testing.
Line range hint
58-58
: Check the test functionTestBigMulPpm
for correct multiplication and rounding behavior.
149-171
: Review the test functionTestBigPow10
for correct power calculation and inverse flag behavior.
179-194
: Evaluate the test functionsTestBigPow10AllValuesInMemo
andTestBigPow10AllValueNotInMemo
for correct memoization and power calculation.
Line range hint
202-202
: Assess the test functionTestBigIntMulPpm
for correct multiplication and precision handling.
Line range hint
230-230
: Check the test functionsTestBigMin
andTestBigMax
for correct minimum and maximum calculations.
Line range hint
258-258
: Review the test functionTestBigRatMulPpm
for correct rational number multiplication and precision handling.
Line range hint
286-286
: Evaluate the benchmark functionBenchmarkBigRatMulPpm
for correct functionality and performance testing.
Line range hint
294-294
: Check the test functionTestBigRatClamp
for correct clamping behavior.
Line range hint
322-322
: Assess the test functionTestBigIntClamp
for correct clamping behavior.
Line range hint
350-350
: Evaluate the benchmark functionBenchmarkBigDivCeil
for correct functionality and performance testing.
Line range hint
358-358
: Check the test functionTestBigDivCeil
for correct division and ceiling behavior.
Line range hint
386-386
: Review the test functionTestBigRatRound
for correct rounding behavior.
Line range hint
414-414
: Evaluate the test functionTestBigIntRoundToMultiple
for correct rounding to multiple behavior.
Line range hint
442-442
: Assess the test functionsTestBigInt0
,TestBigFloat0
,TestBigFloatMaxUint64
,TestBigRat0
, andTestBigRat1
for correct zero and one value initializations.
Line range hint
460-460
: Check the test functionTestBigUint64Clamp
for correct clamping behavior.
Line range hint
488-488
: Evaluate the test functionTestBigInt32Clamp
for correct clamping behavior.
Line range hint
516-516
: Review the test functionTestMustConvertBigIntToInt32
for correct conversion and error handling.
Line range hint
544-544
: Assess the test functionTestBigRatRoundToNearestMultiple
for correct rounding to nearest multiple behavior.protocol/x/clob/keeper/liquidations.go (1)
1057-1070
: RefactorConvertFillablePriceToSubticks
to use the newBigPow10
function.The refactoring of
ConvertFillablePriceToSubticks
to use the newBigPow10
function fromlib
is a good improvement. It simplifies the handling of exponentiation and makes the code more readable and maintainable. Ensure that the new function behaves as expected in all edge cases, especially with negative or zero exponents.
power10Exponent := BigPow10(uint64(AbsInt32(exponent))) | ||
if exponent > 0 { | ||
result.Quo(result, power10Exponent) | ||
p10, inverse := BigPow10(exponent) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason you aren't using BigIntMulPow10 here?
Changelist
func BigMulPow10(val *big.Int, exponent int32) *big.Rat
andfunc BigPow10(exponent uint64) *big.Int
withBigPow10(int exponent) (*big.Int, bool)
andBigIntMulPow10(input *big.Int, exponent int, roundUp bool) *big.Int
Test Plan
Summary by CodeRabbit
Refactor
Tests
New Features