Skip to content

Commit

Permalink
feat!: Add medians param to Token struct (#1685)
Browse files Browse the repository at this point in the history
* add and use HistoricMedians field in Token

* make proto-all

* cl++

* finish updating param

* typo--
  • Loading branch information
toteki committed Jan 6, 2023
1 parent c864727 commit deb4dc4
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 64 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -62,6 +62,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
- [1588](https://github.com/umee-network/umee/pull/1588) Historacle proto.
- [1653](https://github.com/umee-network/umee/pull/1653) Incentive Msg Server interface implementation.
- [1654](https://github.com/umee-network/umee/pull/1654) Leverage historacle integration.
- [1685](https://github.com/umee-network/umee/pull/1685) Add medians param to Token registry.
- [1683](https://github.com/umee-network/umee/pull/1683) Add MaxBorrow query and allow returning all denoms from MaxWithdraw.

## [v3.3.0](https://github.com/umee-network/umee/releases/tag/v3.3.0) - 2022-12-20
Expand Down
10 changes: 10 additions & 0 deletions proto/umee/leverage/v1/leverage.proto
Expand Up @@ -230,4 +230,14 @@ message Token {
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"max_supply\""
];

// Historic Medians is the number of median historic prices to request from
// the oracle module when evaluating new borrow positions containing this token.
// All MsgBorrow, MsgWithdraw, and MsgDecollateralize must result in healthy
// borrow positions under both current and historic prices. The default value of
// zero for this field causes current price to be used in those calculations
// for the affected Token.
uint32 historic_medians = 19 [
(gogoproto.moretags) = "yaml:\"historic_medians\""
];
}
60 changes: 60 additions & 0 deletions swagger/swagger.yaml
Expand Up @@ -981,6 +981,26 @@ paths:
To mark a token as not valid for supply, `msg_supply`
must be set to false.
historic_medians:
type: integer
format: int64
description: >-
Historic Medians is the number of median historic prices
to request from
the oracle module when evaluating new borrow positions
containing this token.
All MsgBorrow, MsgWithdraw, and MsgDecollateralize must
result in healthy
borrow positions under both current and historic prices.
The default value of
zero for this field causes current price to be used in
those calculations
for the affected Token.
description: >-
Token defines a token, along with its metadata and
parameters, in the Umee
Expand Down Expand Up @@ -2517,6 +2537,26 @@ definitions:
To mark a token as not valid for supply, `msg_supply` must be
set to false.
historic_medians:
type: integer
format: int64
description: >-
Historic Medians is the number of median historic prices to
request from
the oracle module when evaluating new borrow positions
containing this token.
All MsgBorrow, MsgWithdraw, and MsgDecollateralize must result
in healthy
borrow positions under both current and historic prices. The
default value of
zero for this field causes current price to be used in those
calculations
for the affected Token.
description: >-
Token defines a token, along with its metadata and parameters, in
the Umee
Expand Down Expand Up @@ -2702,6 +2742,26 @@ definitions:
To mark a token as not valid for supply, `msg_supply` must be set to
false.
historic_medians:
type: integer
format: int64
description: >-
Historic Medians is the number of median historic prices to request
from
the oracle module when evaluating new borrow positions containing this
token.
All MsgBorrow, MsgWithdraw, and MsgDecollateralize must result in
healthy
borrow positions under both current and historic prices. The default
value of
zero for this field causes current price to be used in those
calculations
for the affected Token.
description: >-
Token defines a token, along with its metadata and parameters, in the Umee
Expand Down
1 change: 1 addition & 0 deletions x/leverage/fixtures/token.go
Expand Up @@ -34,5 +34,6 @@ func Token(base, symbol string, exponent uint32) types.Token {
MaxSupplyUtilization: sdk.MustNewDecFromStr("0.9"),
MinCollateralLiquidity: sdk.MustNewDecFromStr("0"),
MaxSupply: sdk.NewInt(100_000_000000),
HistoricMedians: 24,
}
}
13 changes: 4 additions & 9 deletions x/leverage/keeper/oracle.go
Expand Up @@ -11,11 +11,6 @@ import (

var ten = sdk.MustNewDecFromStr("10")

// TODO: Parameterize and move this
const (
minHistoracleStamps = uint64(24)
)

// TokenBasePrice returns the USD value of a base token. Note, the token's denomination
// must be the base denomination, e.g. uumee. The x/oracle module must know of
// the base and display/symbol denominations for each exchange pair. E.g. it must
Expand Down Expand Up @@ -59,14 +54,14 @@ func (k Keeper) TokenDefaultDenomPrice(ctx sdk.Context, baseDenom string, histor

var price sdk.Dec

if historic && minHistoracleStamps > 0 {
if historic && t.HistoricMedians > 0 {
// historic price
var numStamps uint32
price, numStamps, err = k.oracleKeeper.MedianOfHistoricMedians(ctx, t.SymbolDenom, minHistoracleStamps)
if err == nil && numStamps < uint32(minHistoracleStamps) {
price, numStamps, err = k.oracleKeeper.MedianOfHistoricMedians(ctx, t.SymbolDenom, uint64(t.HistoricMedians))
if err == nil && numStamps < t.HistoricMedians {
return sdk.ZeroDec(), t.Exponent, types.ErrNoHistoricMedians.Wrapf(
"requested %d, got %d",
minHistoracleStamps,
t.HistoricMedians,
numStamps,
)
}
Expand Down
2 changes: 2 additions & 0 deletions x/leverage/keeper/token_test.go
Expand Up @@ -24,4 +24,6 @@ func (s *IntegrationTestSuite) TestGetToken() {
require.NoError(t.AssertBorrowEnabled())
require.NoError(t.AssertSupplyEnabled())
require.NoError(t.AssertNotBlacklisted())

require.Equal(uint32(24), t.HistoricMedians)
}
151 changes: 96 additions & 55 deletions x/leverage/types/leverage.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions x/leverage/types/token_test.go
Expand Up @@ -59,6 +59,7 @@ func validToken() types.Token {
MaxSupplyUtilization: sdk.MustNewDecFromStr("1"),
MinCollateralLiquidity: sdk.MustNewDecFromStr("1"),
MaxSupply: sdk.NewInt(1000),
HistoricMedians: 24,
}
}

Expand Down Expand Up @@ -93,6 +94,7 @@ addtokens:
max_supply_utilization: "1.000000000000000000"
min_collateral_liquidity: "1.000000000000000000"
max_supply: "1000"
historic_medians: 24
updatetokens: []
`
require.Equal(t, expected, p.String())
Expand Down

0 comments on commit deb4dc4

Please sign in to comment.