Skip to content

Commit 3909d43

Browse files
adamewozniakmergify[bot]
authored andcommitted
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) (cherry picked from commit ea76766) # Conflicts: # CHANGELOG.md # x/leverage/keeper/oracle.go
1 parent d4865a5 commit 3909d43

File tree

7 files changed

+179
-93
lines changed

7 files changed

+179
-93
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ Ref: https://keepachangelog.com/en/1.0.0/
4646

4747
## [Unreleased]
4848

49+
<<<<<<< HEAD
50+
=======
51+
### Fixes
52+
53+
- [1736](https://github.com/umee-network/umee/pull/1736) Blacklisted tokens no longer add themselves back to the oracle accept list.
54+
- [1800](https://github.com/umee-network/umee/pull/1800) Handle non-capitalized assets when calling the historacle data.
55+
56+
## [v4.0.0](https://github.com/umee-network/umee/releases/tag/v4.0.0) - 2023-01-20
57+
58+
>>>>>>> ea76766 (fix: intercase leverage fix (#1800))
4959
### API Breaking
5060

5161
- [1683](https://github.com/umee-network/umee/pull/1683) MaxWithdraw query now returns `sdk.Coins`, not `sdk.Coin` and will be empty (not zero coin) when returning a zero amount. Denom field in query is now optional.

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
@@ -454,6 +454,8 @@ paths:
454454
price is used if required medians is zero. Price is nil when
455455
the oracle is down or insufficient historic medians are
456456
available.
457+
errors:
458+
type: string
457459
description: >-
458460
QueryMarketSummaryResponse defines the response structure for the
459461
MarketSummary gRPC service handler.
@@ -2228,6 +2230,8 @@ definitions:
22282230
the leverage registry. Current price is used if required medians is
22292231
zero. Price is nil when the oracle is down or insufficient historic
22302232
medians are available.
2233+
errors:
2234+
type: string
22312235
description: >-
22322236
QueryMarketSummaryResponse defines the response structure for the
22332237
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: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
package keeper
22

33
import (
4+
<<<<<<< HEAD
5+
=======
6+
"strings"
7+
8+
"cosmossdk.io/errors"
9+
>>>>>>> ea76766 (fix: intercase leverage fix (#1800))
410
sdk "github.com/cosmos/cosmos-sdk/types"
511
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
612

@@ -40,7 +46,7 @@ func (k Keeper) TokenPrice(ctx sdk.Context, baseDenom string, mode types.PriceMo
4046
// historic price is required for modes other than spot
4147
var numStamps uint32
4248
historicPrice, numStamps, err = k.oracleKeeper.MedianOfHistoricMedians(
43-
ctx, t.SymbolDenom, uint64(t.HistoricMedians))
49+
ctx, strings.ToUpper(t.SymbolDenom), uint64(t.HistoricMedians))
4450
if err != nil {
4551
return sdk.ZeroDec(), t.Exponent, sdkerrors.Wrap(err, "oracle")
4652
}

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

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

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

225237
func (s *IntegrationTestSuite) TestOracle_TotalTokenValue() {

0 commit comments

Comments
 (0)