-
Notifications
You must be signed in to change notification settings - Fork 7
make getprice work just like our usual price calc incl decimals #143
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
base: main
Are you sure you want to change the base?
Conversation
|
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.
Pull request overview
This PR refactors the getPrice method in SundaeUtils to properly account for decimal differences between assets and introduces price inversion for exotic (non-ADA) pairs. Previously, the method returned a simple ratio of reserves without decimal adjustment. The new implementation uses AssetAmount to normalize values by their decimals, ensuring accurate price calculations across assets with different decimal places.
Changes:
- Updated
SundaeUtils.getPrice()to use decimal-awareAssetAmountcalculations for constant product pools - Added price inversion logic for exotic pairs (non-ADA pairs return assetB/assetA instead of assetA/assetB)
- Refactored CLI code to use the centralized
SundaeUtils.getPrice()method instead of duplicating price calculation logic - Added comprehensive test coverage for various pool types including v1, v3, exotic pairs, same-decimal assets, and stableswap pools
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/core/src/Utilities/SundaeUtils.class.ts | Core implementation: adds decimal-aware price calculation using AssetAmount and introduces price inversion for exotic pairs |
| packages/core/src/Utilities/tests/SundaeUtils.class.test.ts | Comprehensive test suite covering ADA pairs, exotic pairs, same-decimal assets, and stableswap pools with various scenarios |
| packages/cli/src/menus/pool.ts | Refactored to use centralized SundaeUtils.getPrice() method, removing duplicate price calculation logic and StableSwapsPool import |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Create AssetAmounts to handle decimal normalization | ||
| const assetAmountA = new AssetAmount<IAssetAmountMetadata>( | ||
| pool.liquidity.aReserve, | ||
| pool.assetA, | ||
| ); | ||
| const assetAmountB = new AssetAmount<IAssetAmountMetadata>( | ||
| pool.liquidity.bReserve, | ||
| pool.assetB, | ||
| ); |
Copilot
AI
Jan 24, 2026
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.
The AssetAmount instances are created at the beginning of the function but are not used when processing stableswap pools. Consider moving the AssetAmount creation into the constant product pool branch to avoid unnecessary object instantiation for stableswap pools.
No description provided.