Skip to content

Commit

Permalink
fix: intercase leverage fix (#1800)
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
adamewozniak authored and mergify[bot] committed Feb 9, 2023
1 parent d4865a5 commit 3909d43
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 93 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [Unreleased]

<<<<<<< HEAD
=======
### 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

>>>>>>> ea76766 (fix: intercase leverage fix (#1800))
### API Breaking

- [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.
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 @@ -454,6 +454,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 @@ -2228,6 +2230,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
8 changes: 7 additions & 1 deletion x/leverage/keeper/oracle.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package keeper

import (
<<<<<<< HEAD
=======
"strings"

"cosmossdk.io/errors"
>>>>>>> ea76766 (fix: intercase leverage fix (#1800))
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

Expand Down Expand Up @@ -40,7 +46,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, sdkerrors.Wrap(err, "oracle")
}