Skip to content

Commit ea76766

Browse files
authored
fix: intercase leverage fix (#1800)
## Description closes: #XXXX --- ### Author Checklist _All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues._ I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] added appropriate labels to the PR - [ ] targeted the correct branch (see [PR Targeting](https://github.com/umee-network/umee/blob/main/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist _All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items._ I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
1 parent b48dc1a commit ea76766

File tree

7 files changed

+166
-93
lines changed

7 files changed

+166
-93
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
4949
### Fixes
5050

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

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

proto/umee/leverage/v1/query.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ message QueryMarketSummaryResponse {
187187
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
188188
(gogoproto.nullable) = true
189189
];
190+
string errors = 20;
190191
}
191192

192193
// QueryAccountBalances defines the request structure for the AccountBalances gRPC service handler.

swagger/swagger.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,8 @@ paths:
455455
price is used if required medians is zero. Price is nil when
456456
the oracle is down or insufficient historic medians are
457457
available.
458+
errors:
459+
type: string
458460
description: >-
459461
QueryMarketSummaryResponse defines the response structure for the
460462
MarketSummary gRPC service handler.
@@ -2229,6 +2231,8 @@ definitions:
22292231
the leverage registry. Current price is used if required medians is
22302232
zero. Price is nil when the oracle is down or insufficient historic
22312233
medians are available.
2234+
errors:
2235+
type: string
22322236
description: >-
22332237
QueryMarketSummaryResponse defines the response structure for the
22342238
MarketSummary gRPC service handler.

x/leverage/keeper/grpc_query.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,17 @@ func (q Querier) MarketSummary(
135135
}
136136

137137
// Oracle prices in response will be nil if it is unavailable
138-
if oraclePrice, _, oracleErr := q.Keeper.TokenPrice(ctx, req.Denom, types.PriceModeSpot); oracleErr == nil {
138+
oraclePrice, _, oracleErr := q.Keeper.TokenPrice(ctx, req.Denom, types.PriceModeSpot)
139+
if oracleErr == nil {
139140
resp.OraclePrice = &oraclePrice
141+
} else {
142+
resp.Errors += oracleErr.Error()
140143
}
141-
if historicPrice, _, historicErr := q.Keeper.TokenPrice(ctx, req.Denom, types.PriceModeHistoric); historicErr == nil {
144+
historicPrice, _, historicErr := q.Keeper.TokenPrice(ctx, req.Denom, types.PriceModeHistoric)
145+
if historicErr == nil {
142146
resp.OracleHistoricPrice = &historicPrice
147+
} else {
148+
resp.Errors += historicErr.Error()
143149
}
144150

145151
return &resp, nil

x/leverage/keeper/oracle.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package keeper
22

33
import (
4+
"strings"
5+
46
"cosmossdk.io/errors"
57
sdk "github.com/cosmos/cosmos-sdk/types"
68

@@ -40,7 +42,7 @@ func (k Keeper) TokenPrice(ctx sdk.Context, baseDenom string, mode types.PriceMo
4042
// historic price is required for modes other than spot
4143
var numStamps uint32
4244
historicPrice, numStamps, err = k.oracleKeeper.MedianOfHistoricMedians(
43-
ctx, t.SymbolDenom, uint64(t.HistoricMedians))
45+
ctx, strings.ToUpper(t.SymbolDenom), uint64(t.HistoricMedians))
4446
if err != nil {
4547
return sdk.ZeroDec(), t.Exponent, errors.Wrap(err, "oracle")
4648
}

x/leverage/keeper/oracle_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package keeper_test
22

33
import (
44
"fmt"
5+
"strings"
56

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

@@ -155,6 +156,12 @@ func (s *IntegrationTestSuite) TestOracle_TokenPrice() {
155156
require.NoError(err)
156157
require.Equal(sdk.MustNewDecFromStr("0.50"), p)
157158
require.Equal(uint32(6), e)
159+
160+
// Lowercase must be converted to uppercase symbol denom ("DUMP" from "dump")
161+
p, e, err = app.LeverageKeeper.TokenPrice(ctx, strings.ToLower(dumpDenom), types.PriceModeLow)
162+
require.NoError(err)
163+
require.Equal(sdk.MustNewDecFromStr("0.50"), p)
164+
require.Equal(uint32(6), e)
158165
}
159166

160167
func (s *IntegrationTestSuite) TestOracle_TokenValue() {
@@ -221,6 +228,11 @@ func (s *IntegrationTestSuite) TestOracle_TokenValue() {
221228
v, err = app.LeverageKeeper.TokenValue(ctx, coin.New(pumpDenom, 2_400000), types.PriceModeLow)
222229
require.NoError(err)
223230
require.Equal(sdk.MustNewDecFromStr("2.4"), v)
231+
232+
// lowercase 2.4 PUMP * $1.00
233+
v, err = app.LeverageKeeper.TokenValue(ctx, coin.New(strings.ToLower(pumpDenom), 2_400000), types.PriceModeLow)
234+
require.NoError(err)
235+
require.Equal(sdk.MustNewDecFromStr("2.4"), v)
224236
}
225237

226238
func (s *IntegrationTestSuite) TestOracle_TotalTokenValue() {

0 commit comments

Comments
 (0)