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

fix: intercase leverage fix #1800

Merged
merged 9 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Fixes

- [1736](https://github.com/umee-network/umee/pull/1736) Blacklisted tokens no longer add themselves back to the oracle accept list.
- [1800](https://github.com/umee-network/umee/pull/1800) Handle non-capitalized assets when calling the historacle data.

## [v4.0.0](https://github.com/umee-network/umee/releases/tag/v4.0.0) - 2023-01-20

Expand Down
1 change: 1 addition & 0 deletions proto/umee/leverage/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ message QueryMarketSummaryResponse {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = true
];
string errors = 20;
}

// QueryAccountBalances defines the request structure for the AccountBalances gRPC service handler.
Expand Down
4 changes: 4 additions & 0 deletions swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,8 @@ paths:
price is used if required medians is zero. Price is nil when
the oracle is down or insufficient historic medians are
available.
errors:
type: string
description: >-
QueryMarketSummaryResponse defines the response structure for the
MarketSummary gRPC service handler.
Expand Down Expand Up @@ -2229,6 +2231,8 @@ definitions:
the leverage registry. Current price is used if required medians is
zero. Price is nil when the oracle is down or insufficient historic
medians are available.
errors:
type: string
description: >-
QueryMarketSummaryResponse defines the response structure for the
MarketSummary gRPC service handler.
Expand Down
10 changes: 8 additions & 2 deletions x/leverage/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,17 @@ func (q Querier) MarketSummary(
}

// Oracle prices in response will be nil if it is unavailable
if oraclePrice, _, oracleErr := q.Keeper.TokenPrice(ctx, req.Denom, types.PriceModeSpot); oracleErr == nil {
oraclePrice, _, oracleErr := q.Keeper.TokenPrice(ctx, req.Denom, types.PriceModeSpot)
if oracleErr == nil {
resp.OraclePrice = &oraclePrice
} else {
resp.Errors += oracleErr.Error()
}
if historicPrice, _, historicErr := q.Keeper.TokenPrice(ctx, req.Denom, types.PriceModeHistoric); historicErr == nil {
historicPrice, _, historicErr := q.Keeper.TokenPrice(ctx, req.Denom, types.PriceModeHistoric)
if historicErr == nil {
resp.OracleHistoricPrice = &historicPrice
} else {
resp.Errors += historicErr.Error()
}

return &resp, nil
Expand Down
4 changes: 3 additions & 1 deletion x/leverage/keeper/oracle.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package keeper

import (
"strings"

"cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"

Expand Down Expand Up @@ -40,7 +42,7 @@ func (k Keeper) TokenPrice(ctx sdk.Context, baseDenom string, mode types.PriceMo
// historic price is required for modes other than spot
var numStamps uint32
historicPrice, numStamps, err = k.oracleKeeper.MedianOfHistoricMedians(
ctx, t.SymbolDenom, uint64(t.HistoricMedians))
ctx, strings.ToUpper(t.SymbolDenom), uint64(t.HistoricMedians))
if err != nil {
return sdk.ZeroDec(), t.Exponent, errors.Wrap(err, "oracle")
}
Expand Down
12 changes: 12 additions & 0 deletions x/leverage/keeper/oracle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper_test

import (
"fmt"
"strings"

sdk "github.com/cosmos/cosmos-sdk/types"

Expand Down Expand Up @@ -155,6 +156,12 @@ func (s *IntegrationTestSuite) TestOracle_TokenPrice() {
require.NoError(err)
require.Equal(sdk.MustNewDecFromStr("0.50"), p)
require.Equal(uint32(6), e)

// Lowercase must be converted to uppercase symbol denom ("DUMP" from "dump")
p, e, err = app.LeverageKeeper.TokenPrice(ctx, strings.ToLower(dumpDenom), types.PriceModeLow)
require.NoError(err)
require.Equal(sdk.MustNewDecFromStr("0.50"), p)
require.Equal(uint32(6), e)
}

func (s *IntegrationTestSuite) TestOracle_TokenValue() {
Expand Down Expand Up @@ -221,6 +228,11 @@ func (s *IntegrationTestSuite) TestOracle_TokenValue() {
v, err = app.LeverageKeeper.TokenValue(ctx, coin.New(pumpDenom, 2_400000), types.PriceModeLow)
require.NoError(err)
require.Equal(sdk.MustNewDecFromStr("2.4"), v)

// lowercase 2.4 PUMP * $1.00
v, err = app.LeverageKeeper.TokenValue(ctx, coin.New(strings.ToLower(pumpDenom), 2_400000), types.PriceModeLow)
require.NoError(err)
require.Equal(sdk.MustNewDecFromStr("2.4"), v)
}

func (s *IntegrationTestSuite) TestOracle_TotalTokenValue() {
Expand Down
Loading