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

[NonPoolSuperfluid] Queries #8320

Merged
merged 60 commits into from
Jun 5, 2024
Merged

[NonPoolSuperfluid] Queries #8320

merged 60 commits into from
Jun 5, 2024

Conversation

nicolaslara
Copy link
Contributor

What is the purpose of the change

Queries now take non-pool assets into account

Testing and Verifying

Updated necessary tests

Documentation and Release Note

  • Does this pull request introduce a new feature or user-facing behavior changes?
  • Changelog entry added to Unreleased section of CHANGELOG.md?

Where is the change documented?

  • Specification (x/{module}/README.md)
  • Osmosis documentation site
  • Code comments?
  • N/A

@nicolaslara nicolaslara changed the base branch from main to nicolas/superfluid-btc-multiple-pools May 27, 2024 14:04
Copy link
Contributor

coderabbitai bot commented May 27, 2024

Walkthrough

This update enhances the Osmosis protocol by adding support for non-pool assets in superfluid staking. Key changes include modifying protobuf definitions to include new fields, updating various keeper functions and tests to handle the new asset types, and introducing new methods for calculating and validating non-native assets. The overall goal is to improve the flexibility and functionality of superfluid staking.

Changes

Files/Paths Change Summary
proto/osmosis/superfluid/query.proto Added total_equivalent_non_osmo_staked_amount field to response messages.
proto/osmosis/superfluid/superfluid.proto Imported new proto file and replaced price_pool_id with price_route in SuperfluidAsset.
x/poolmanager/types/routes.go Added a new Equal method to SwapAmountInRoute struct.
x/superfluid/README.md Updated documentation for custom Risk Factor, asset types, and introduced MsgSetRiskFactor and SuperfluidAssetType enum.
x/superfluid/keeper/epoch.go Removed osmomath import, adjusted TWAP price calculation, and updated SetOsmoEquivalentMultiplier.
x/superfluid/keeper/epoch_test.go Added poolmanagertypes import and updated test logic for native token Osmo equivalent.
x/superfluid/keeper/gov.go Updated handling of superfluid assets proposals with changes in validation and comparison logic.
x/superfluid/keeper/gov_test.go Included PriceRoute in nativeAsset in TestHandleSetSuperfluidAssetsProposal function.
x/superfluid/keeper/grpc_query.go Added TotalEquivalentNonOsmoStakedAmount and adjusted related calculations.
x/superfluid/keeper/grpc_query_test.go Renamed function to reflect handling of non-native assets.
x/superfluid/keeper/integration_test.go Added new tests and modified existing ones for superfluid delegations, reward distribution, voting, and native functionality.
x/superfluid/keeper/stake.go Introduced ValidateNativeAsset function for validating native assets.
x/superfluid/keeper/stake_test.go Updated imports and test logic to handle new PriceRoute field and native asset validation.
x/superfluid/keeper/twap_price.go Renamed and added functions to handle non-native assets and refactored existing functions.
x/superfluid/keeper/twap_price_test.go Updated test functions to use new function names reflecting non-native asset handling.
x/superfluid/types/expected_keepers.go Modified TwapKeeper interface method signature to GetMultiPoolArithmeticTwapToNow.
x/twap/api.go Added new function for multi-pool arithmetic TWAP calculation and new package imports.

Possibly related issues

  • osmo-labs/osmosis#8240: The changes address the need for enhanced functionality and flexibility in asset handling, which is part of the broader goals mentioned in the issue.

Poem

In the land where tokens flow,
Superfluid staking starts to grow.
Non-pool assets join the dance,
Enhancing Osmosis, seizing the chance.
With routes and risks all set anew,
The future's bright, the sky so blue. 🌟


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1e6747d and edbda36.

Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • x/superfluid/keeper/integration_test.go (3 hunks)
  • x/superfluid/keeper/stake_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • x/superfluid/keeper/integration_test.go
  • x/superfluid/keeper/stake_test.go
Additional context used
Markdownlint
CHANGELOG.md

1070-1070: Expected: h3; Actual: h4 (MD001, heading-increment)
Heading levels should only increment by one level at a time


1082-1082: Expected: h3; Actual: h4 (MD001, heading-increment)
Heading levels should only increment by one level at a time


1091-1091: Expected: h3; Actual: h4 (MD001, heading-increment)
Heading levels should only increment by one level at a time


1096-1096: Expected: h3; Actual: h4 (MD001, heading-increment)
Heading levels should only increment by one level at a time


1148-1148: Expected: h3; Actual: h4 (MD001, heading-increment)
Heading levels should only increment by one level at a time


409-409: Punctuation: '.' (MD026, no-trailing-punctuation)
Trailing punctuation in heading


672-672: null (MD034, no-bare-urls)
Bare URL used


730-730: null (MD034, no-bare-urls)
Bare URL used


1311-1311: null (MD042, no-empty-links)
No empty links


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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@nicolaslara nicolaslara added the V:state/compatible/no_backport State machine compatible PR, depends on prior breaks label May 27, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Outside diff range and nitpick comments (10)
x/superfluid/keeper/twap_price.go (1)

60-60: Clarify the logic for excluding native tokens in getSuperfluidOSMOTokens.

Consider adding a comment explaining why native tokens are excluded in some scenarios.

CHANGELOG.md (9)

Line range hint 1058-1058: Correct the heading level to maintain a logical order.

- #### [v6.4.0](https://github.com/osmosis-labs/osmosis/releases/tag/v6.4.0)
+ ### [v6.4.0](https://github.com/osmosis-labs/osmosis/releases/tag/v6.4.0)

Line range hint 1070-1070: Correct the heading level to maintain a logical order.

- #### [v6.3.1](https://github.com/osmosis-labs/osmosis/releases/tag/v6.3.1)
+ ### [v6.3.1](https://github.com/osmosis-labs/osmosis/releases/tag/v6.3.1)

Line range hint 1079-1079: Correct the heading level to maintain a logical order.

- #### [v6.3.0](https://github.com/osmosis-labs/osmosis/releases/tag/v6.3.0)
+ ### [v6.3.0](https://github.com/osmosis-labs/osmosis/releases/tag/v6.3.0)

Line range hint 1084-1084: Correct the heading level to maintain a logical order.

- #### [v6.2.0](https://github.com/osmosis-labs/osmosis/releases/tag/v6.2.0)
+ ### [v6.2.0](https://github.com/osmosis-labs/osmosis/releases/tag/v6.2.0)

Line range hint 1136-1136: Correct the heading level to maintain a logical order.

- #### [v6.0.0](https://github.com/osmosis-labs/osmosis/releases/tag/v6.0.0)
+ ### [v6.0.0](https://github.com/osmosis-labs/osmosis/releases/tag/v6.0.0)

Line range hint 397-397: Remove trailing punctuation from the heading.

- ## [v4.0.0]
+ ## [v4.0.0]

Line range hint 660-660: Replace bare URL with a markdown link.

- See: [SDK v0.43.0 Release Notes](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.43.0) For more details
+ See: [SDK v0.43.0 Release Notes](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.43.0) for more details.

Line range hint 718-718: Replace bare URL with a markdown link.

- [wasmd-v.022.0-osmo-v7.2](https://github.com/osmosis-labs/wasmd/releases/tag/v0.22.0-osmo-v7.2) Upgrade SDK and IAVL dependencies to use fast storage
+ [wasmd-v.022.0-osmo-v7.2](https://github.com/osmosis-labs/wasmd/releases/tag/v0.22.0-osmo-v7.2) Upgrade SDK and IAVL dependencies to use fast storage.

Line range hint 1299-1299: Ensure all links are properly formatted and not empty.

- * [Patch](https://github.com/osmosis-labs/osmosis/commit/907001b08686ed980e0afa3d97a9c5e2f095b79f#diff-a172cedcae47474b615c54d510a5d84a8dea3032e958587430b413538be3f333) - Revert back to passing in the correct staking keeper into the IBC keeper constructor.
+ * [Patch](https://github.com/osmosis-labs/osmosis/commit/907001b08686ed980e0afa3d97a9c5e2f095b79f#diff-a172cedcae47474b615c54d510a5d84a8dea3032e958587430b413538be3f333) - Revert back to passing in the correct staking keeper into the IBC keeper constructor.

@@ -430,7 +435,7 @@ func (q Querier) SuperfluidDelegationsByValidatorDenom(goCtx context.Context, re
lockedCoins := sdk.NewCoin(req.Denom, lock.GetCoins().AmountOf(req.Denom))
baseDenom := lock.Coins.GetDenomByIndex(0)

equivalentAmount, err := q.Keeper.GetSuperfluidOSMOTokensExcludeNative(ctx, baseDenom, lockedCoins.Amount)
equivalentAmount, err := q.Keeper.GetSuperfluidOSMOTokens(ctx, baseDenom, lockedCoins.Amount)
Copy link
Member

@czarcas7ic czarcas7ic May 28, 2024

Choose a reason for hiding this comment

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

Wont this include uosmo then? I think should be excluded in SF queries, but all other native SF assets make sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the idea is to include everything there. I added a separate field for the non-osmo ones. To get the old value, we can subtract them.

I thought of keeping this one as the one with only osmo and adding the field for non-osmo, but I think the query response names would become confusing: why would the field total_equivalent_staked_amount exclude some assets? I think "total" implies all.

I choose to change the value instead of the name here, but happy to change the api to make it more clear

Copy link
Member

@czarcas7ic czarcas7ic May 28, 2024

Choose a reason for hiding this comment

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

But this query is total SF assets delegated, not total assets delegated. So it would make sense to not include uosmo (as a native asset), since that would include uosmo staked to the validator by normal staking means.

Copy link
Member

Choose a reason for hiding this comment

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

In other words, with no other changes and just this query changed, we would go from showing the SF assets staked to a validator, to the SF assets staked to a validator plus the normal uosmo staked, which completely changes what the query means (and imo doesn't make sense to do it this way). If we only include SF assets, then the before and after of this query is the same, and will only change once a new native SF asset gets added.

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 gets the total SF staked. Neither the one before nor after include the staked uosmo. When I say non-pool assets here, I mean btc.

If we only include SF assets, then the before and after of this query is the same, and will only change once a new native SF asset gets added.

correct

Copy link
Member

@czarcas7ic czarcas7ic May 28, 2024

Choose a reason for hiding this comment

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

The "exclude native" really throws me off then, why it was ever named this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

lol
Notification_Center

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'd be happy to rename them to something with OsmoEquivalent to make it clearer. Just didn't want to change the existing name

Copy link
Member

Choose a reason for hiding this comment

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

The context in which the method is being called is what is confusing me.

All things equal, in SF if I see "ExcludeNative" in context of superfluid and this new feature, I think, lets get all the superfluid staked assets of a certain validator, but leave out any osmo or token factory tokens (in this case alloyed assets).

I think what is missing is a proper godoc here

func (k Keeper) getSuperfluidOSMOTokens(ctx sdk.Context, denom string, amount osmomath.Int, includeNative bool) (osmomath.Int, error) {
if !includeNative && !isNonNative(denom) {
return osmomath.ZeroInt(), nil
}
multiplier := k.GetOsmoEquivalentMultiplier(ctx, denom)
if multiplier.IsZero() {
return osmomath.ZeroInt(), nil
}
decAmt := multiplier.Mul(amount.ToLegacyDec())
_, err := k.GetSuperfluidAsset(ctx, denom)
if err != nil {
return osmomath.ZeroInt(), err
}
return k.GetRiskAdjustedOsmoValue(ctx, decAmt.RoundInt(), denom), nil
}
because the name could mean a variety of things

Copy link
Member

Choose a reason for hiding this comment

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

I fully onboarded and IMO, this clarifies the difference between the two methods abd9f3b

x/superfluid/keeper/grpc_query.go Show resolved Hide resolved
Base automatically changed from nicolas/superfluid-btc-multiple-pools to main June 5, 2024 08:43
* initial docs

* more docs

* Update x/superfluid/README.md

* lint

* clarify native vs non native calls

---------

Co-authored-by: Adam Tucker <[email protected]>
Co-authored-by: Adam Tucker <[email protected]>
@github-actions github-actions bot added the C:docs Improvements or additions to documentation label Jun 5, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 12

Outside diff range and nitpick comments (1)
x/superfluid/keeper/integration_test.go (1)

Line range hint 501-514: The test setup for reward distribution appears to have a potential issue with the setup of validator rewards. The comment on line 512 suggests a misunderstanding or a setup error in the test environment. It would be beneficial to clarify this in the test comments or revise the setup to avoid confusion.

- // Validators get stake and uosmo. I think this is an issue with test setup
+ // Ensure that validators receive the correct types of rewards. Adjust the test setup if necessary.

Comment on lines +406 to +420
### Set a custom Risk Factor for a denom

The risk factor is a multiplier that is applied to the Osmo Equivalent
Multiplier for a denom. It is used to adjust the staking power of a
denom. The risk factor is set by the governance module.

If not set, it defaults to params.minimum_risk_factor.

```{.go}
type MsgSetRiskFactor struct {
Sender string
Denom string
RiskFactor github.com_cosmos_cosmos_sdk_types.Dec
}
```
Copy link
Contributor

Choose a reason for hiding this comment

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

Clarify the default behavior for the risk factor if not set.

The documentation mentions that the risk factor defaults to params.minimum_risk_factor if not set. It would be beneficial to include this default behavior in the MsgSetRiskFactor struct documentation to ensure clarity for developers and users.

Comment on lines 164 to 168
price, err := k.twapk.GetMultiPoolArithmeticTwapToNow(ctx, asset.PriceRoute, asset.Denom, bondDenom, startTime)
if err != nil {
return sdkerrors.Wrap(err, "failed to get twap price")
}
k.SetOsmoEquivalentMultiplier(ctx, newEpochNumber, asset.Denom, osmomath.NewDec(1).Quo(price))
k.SetOsmoEquivalentMultiplier(ctx, newEpochNumber, asset.Denom, price)
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider handling the error from GetMultiPoolArithmeticTwapToNow more gracefully.

Currently, the function returns an error directly which could halt the execution of important logic if the TWAP calculation fails. It might be beneficial to log this error and continue with a default or previously calculated value to ensure the system's robustness.

Comment on lines 465 to 475
s.Require().Equal(appparams.BaseCoinUnit, res.SuperfluidDelegationRecords[0].EquivalentStakedAmount.Denom)
riskFactor := s.App.SuperfluidKeeper.CalculateRiskFactor(s.Ctx, btcDenom)
twapStartTime := s.Ctx.BlockTime().Add(-5 * time.Minute)
price, err := s.App.TwapKeeper.GetMultiPoolArithmeticTwapToNow(s.Ctx, []*poolmanagertypes.SwapAmountInRoute{{PoolId: nextPoolId, TokenOutDenom: bondDenom}}, btcDenom, bondDenom, twapStartTime)
equivalentAmount := riskFactor.Mul(osmomath.NewDec(btcStakeAmount.Int64())).Mul(price)
s.Require().NoError(err)
s.Require().Equal(equivalentAmount, osmomath.NewDec(res.SuperfluidDelegationRecords[0].EquivalentStakedAmount.Amount.Int64()))
s.Require().Equal(appparams.BaseCoinUnit, res.TotalEquivalentStakedAmount.Denom)
s.Require().Equal(equivalentAmount, osmomath.NewDec(res.TotalEquivalentStakedAmount.Amount.Int64()))
s.Require().Equal(appparams.BaseCoinUnit, res.TotalEquivalentNonOsmoStakedAmount.Denom)
s.Require().Equal(equivalentAmount, osmomath.NewDec(res.TotalEquivalentNonOsmoStakedAmount.Amount.Int64()))
Copy link
Contributor

Choose a reason for hiding this comment

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

The calculation of equivalent staked amounts using TWAP prices and risk factors is a significant addition. It's important to ensure that these calculations are accurate and reflect the true market conditions. Consider adding more detailed logging or debugging information to help trace these calculations in a production environment.

+ fmt.Println("Detailed TWAP calculation:", price)

Committable suggestion was skipped due to low confidence.

Comment on lines 154 to 162
func (k Keeper) ValidateNativeAsset(asset types.SuperfluidAsset) error {
if asset.AssetType == types.SuperfluidAssetTypeNative {
if len(asset.PriceRoute) == 0 ||
strings.TrimSpace(asset.PriceRoute[0].TokenOutDenom) == "" {
return errorsmod.Wrap(types.ErrNonSuperfluidAsset, "asset is not properly configured for superfluid staking: missing or empty price route")
}
}
return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure proper configuration for native superfluid assets.

The function ValidateNativeAsset checks if the asset type is native and then validates the PriceRoute. However, the error message could be more specific about what is exactly missing or misconfigured. Consider enhancing the error message to improve clarity and debugging efficiency.

- return errorsmod.Wrap(types.ErrNonSuperfluidAsset, "asset is not properly configured for superfluid staking: missing or empty price route")
+ return errorsmod.Wrap(types.ErrNonSuperfluidAsset, "asset is not properly configured for superfluid staking: missing or empty price route in the first element")
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
func (k Keeper) ValidateNativeAsset(asset types.SuperfluidAsset) error {
if asset.AssetType == types.SuperfluidAssetTypeNative {
if len(asset.PriceRoute) == 0 ||
strings.TrimSpace(asset.PriceRoute[0].TokenOutDenom) == "" {
return errorsmod.Wrap(types.ErrNonSuperfluidAsset, "asset is not properly configured for superfluid staking: missing or empty price route")
}
}
return nil
}
func (k Keeper) ValidateNativeAsset(asset types.SuperfluidAsset) error {
if asset.AssetType == types.SuperfluidAssetTypeNative {
if len(asset.PriceRoute) == 0 ||
strings.TrimSpace(asset.PriceRoute[0].TokenOutDenom) == "" {
return errorsmod.Wrap(types.ErrNonSuperfluidAsset, "asset is not properly configured for superfluid staking: missing or empty price route in the first element")
}
}
return nil
}

Comment on lines 163 to 164
params, _ := s.App.StakingKeeper.GetParams(s.Ctx)
bondDenom := params.BondDenom
Copy link
Contributor

Choose a reason for hiding this comment

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

The retrieval of bondDenom from staking parameters is repeated in multiple test cases. Consider refactoring this into a helper function to reduce code duplication.

- params, _ := s.App.StakingKeeper.GetParams(s.Ctx)
- bondDenom := params.BondDenom
+ bondDenom := s.getBondDenom()

And add a new method:

func (s *KeeperTestSuite) getBondDenom() string {
    params, _ := s.App.StakingKeeper.GetParams(s.Ctx)
    return params.BondDenom
}

@@ -246,7 +250,7 @@ func (s *KeeperTestSuite) TestValidateLockForSFDelegate() {
Duration: time.Hour * 24 * 21,
ID: 1,
},
superfluidAssetToSet: types.SuperfluidAsset{Denom: "foo", AssetType: types.SuperfluidAssetTypeNative, PricePoolId: 1},
superfluidAssetToSet: types.SuperfluidAsset{Denom: "foo", AssetType: types.SuperfluidAssetTypeNative, PriceRoute: []*poolmanagertypes.SwapAmountInRoute{{PoolId: 1, TokenOutDenom: bondDenom}}},
Copy link
Contributor

Choose a reason for hiding this comment

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

The test cases for "valid native lock" and "invalid native lock - asset not set" use the same superfluidAssetToSet setup. This redundancy could be streamlined by setting up the superfluidAssetToSet before the test cases if it does not change.

- superfluidAssetToSet: types.SuperfluidAsset{Denom: "foo", AssetType: types.SuperfluidAssetTypeNative, PriceRoute: []*poolmanagertypes.SwapAmountInRoute{{PoolId: 1, TokenOutDenom: bondDenom}}},
+ superfluidAssetToSet: commonAssetSetup

And define commonAssetSetup before the tests:

commonAssetSetup := types.SuperfluidAsset{Denom: "foo", AssetType: types.SuperfluidAssetTypeNative, PriceRoute: []*poolmanagertypes.SwapAmountInRoute{{PoolId: 1, TokenOutDenom: bondDenom}}}

Also applies to: 264-264

Comment on lines 52 to 54
Denom: "btc",
AssetType: types.SuperfluidAssetTypeNative,
PriceRoute: []*poolmanagertypes.SwapAmountInRoute{{PoolId: 1, TokenOutDenom: "stake"}},
Copy link
Contributor

Choose a reason for hiding this comment

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

Validate the PriceRoute field in SuperfluidAsset for native assets.

The PriceRoute field should not typically be set for native assets as their price is not derived from a pool. This could potentially introduce bugs or unexpected behavior. Consider adding validation logic to prevent or handle this scenario appropriately.

Comment on lines 90 to 93
params, _ := s.App.StakingKeeper.GetParams(s.Ctx)
params.BondDenom = appparams.BaseCoinUnit
err := s.App.StakingKeeper.SetParams(s.Ctx, params)
s.Require().NoError(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

The parameters for the staking keeper are being reset within each test case. Consider refactoring to avoid redundancy and potential side effects across tests.

- params, _ := s.App.StakingKeeper.GetParams(s.Ctx)
- params.BondDenom = appparams.BaseCoinUnit
- err := s.App.StakingKeeper.SetParams(s.Ctx, params)
- s.Require().NoError(err)
+ // Refactor to set parameters once in a setup method if applicable

Committable suggestion was skipped due to low confidence.

Comment on lines 25 to 26
if err := k.ValidateNativeAsset(asset); err != nil {
return fmt.Errorf("native asset (%s) must have a price route", asset.Denom)
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider enhancing the error message to include more context about the failure.

- return fmt.Errorf("native asset (%s) must have a price route", asset.Denom)
+ return fmt.Errorf("validation failed for native asset (%s): a price route is required", asset.Denom)
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if err := k.ValidateNativeAsset(asset); err != nil {
return fmt.Errorf("native asset (%s) must have a price route", asset.Denom)
if err := k.ValidateNativeAsset(asset); err != nil {
return fmt.Errorf("validation failed for native asset (%s): a price route is required", asset.Denom)

@@ -40,7 +40,7 @@ func HandleRemoveSuperfluidAssetsProposal(ctx sdk.Context, k keeper.Keeper, p *t
return err
}
dummyAsset := types.SuperfluidAsset{}
if asset == dummyAsset {
if asset.Equal(dummyAsset) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using a more direct method to check for asset existence instead of comparing to a dummy object.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range and nitpick comments (8)
CHANGELOG.md (8)

Line range hint 1070-1070: Consider adjusting the heading level from h4 to h3 for consistency.


Line range hint 1082-1082: Consider adjusting the heading level from h4 to h3 for consistency.


Line range hint 1091-1091: Consider adjusting the heading level from h4 to h3 for consistency.


Line range hint 1096-1096: Consider adjusting the heading level from h4 to h3 for consistency.


Line range hint 1148-1148: Consider adjusting the heading level from h4 to h3 for consistency.


Line range hint 409-409: Remove the trailing punctuation from the heading.


Line range hint 672-672: Avoid using bare URLs. Consider using markdown link syntax or providing additional context.

Also applies to: 730-730


Line range hint 1311-1311: Ensure that there are no empty links in the document.

@PaddyMc PaddyMc merged commit 344e59e into main Jun 5, 2024
1 check passed
@PaddyMc PaddyMc deleted the nicolas/superfluid-btc-queries branch June 5, 2024 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:docs Improvements or additions to documentation C:x/poolmanager C:x/superfluid C:x/twap Changes to the twap module V:state/compatible/no_backport State machine compatible PR, depends on prior breaks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants