Skip to content

Commit

Permalink
Add deviation thresholds param
Browse files Browse the repository at this point in the history
  • Loading branch information
rbajollari committed Aug 30, 2023
1 parent 245a7ae commit 6826a91
Show file tree
Hide file tree
Showing 17 changed files with 1,339 additions and 217 deletions.
1 change: 1 addition & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func (app *App) registerUpgrade0_2_1(_ upgradetypes.Plan) {
ctx.Logger().Info("Upgrade handler execution", "name", planName)
upgrader := oraclekeeper.NewMigrator(&app.OracleKeeper)
upgrader.MigratePriceFeederCurrencyPairProviders(ctx)
upgrader.MigratePriceFeederCurrencyDeviationThresholds(ctx)
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
},
)
Expand Down
27 changes: 23 additions & 4 deletions proto/ojo/oracle/v1/oracle.proto
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ message Params {
(gogoproto.castrepeated) = "CurrencyPairProvidersList",
(gogoproto.nullable) = false
];
// Price Feeder Currency Deviation Thresholds defines the deviation
// thresholds for each base currency the price feeder uses upon start up.
repeated CurrencyDeviationThreshold price_feeder_currency_deviation_thresholds = 15 [
(gogoproto.moretags) = "yaml:\"price_feeder_currency_deviation_thresholds\"",
(gogoproto.castrepeated) = "CurrencyDeviationThresholdList",
(gogoproto.nullable) = false
];
}

// Denom - the object to hold configurations of each denom
Expand Down Expand Up @@ -143,9 +150,21 @@ message CurrencyPairProviders {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;

string base_denom = 1 [ (gogoproto.moretags) = "yaml:\"base_denom\"" ];
string quote_denom = 2 [ (gogoproto.moretags) = "yaml:\"quote_denom\"" ];

repeated string providers = 3 [ (gogoproto.moretags) = "yaml:\"providers\"" ];
string base_denom = 1 [ (gogoproto.moretags) = "yaml:\"base_denom\"" ];
string quote_denom = 2 [ (gogoproto.moretags) = "yaml:\"quote_denom\"" ];
string address = 3 [ (gogoproto.moretags) = "yaml:\"address\"" ];
string address_provider = 4 [ (gogoproto.moretags) = "yaml:\"address_provider\"" ];
repeated string providers = 5 [ (gogoproto.moretags) = "yaml:\"providers\"" ];
}

// CurrencyDeviationThreshold defines a deviation theshold for a
// base denom.
message CurrencyDeviationThreshold {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;

string base_denom = 1 [ (gogoproto.moretags) = "yaml:\"base_denom\"" ];
string threshold = 2 [ (gogoproto.moretags) = "yaml:\"threshold\"" ];
}
20 changes: 20 additions & 0 deletions proto/ojo/oracle/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ service Query {
option (google.api.http).get =
"/ojo/oracle/v1/valdiators/price_feeder_currency_pair_providers";
}

// PriceFeederCurrencyDeviationThresholds returns the deviation
// thresholds for each base currency the price feeder uses upon start up.
rpc PriceFeederCurrencyDeviationThresholds(QueryPriceFeederCurrencyDeviationThresholds)
returns (QueryPriceFeederCurrencyDeviationThresholdsResponse) {
option (google.api.http).get =
"/ojo/oracle/v1/valdiators/price_feeder_currency_deviation_thresholds";
}
}

// QueryExchangeRates is the request type for the Query/ExchangeRate RPC
Expand Down Expand Up @@ -311,3 +319,15 @@ message QueryPriceFeederCurrencyPairProvidersResponse {
(gogoproto.nullable) = false
];
}

// QueryPriceFeederCurrencyDeviationThresholds is the request type for the
// Query/PriceFeederCurrencyDeviationThresholds RPC method.
message QueryPriceFeederCurrencyDeviationThresholds {}

// QueryPriceFeederCurrencyDeviationThresholdsResponse is the response type
// for the Query/PriceFeederCurrencyDeviationThresholds RPC method.
message QueryPriceFeederCurrencyDeviationThresholdsResponse {
repeated CurrencyDeviationThreshold PriceFeederCurrencyDeviationThresholds = 1 [
(gogoproto.nullable) = false
];
}
19 changes: 19 additions & 0 deletions x/oracle/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,22 @@ func (q querier) PriceFeederCurrencyPairProviders(
PriceFeederCurrencyPairProviders: pfCurrencyPairProviderList,
}, nil
}

// PriceFeederCurrencyDeviationThresholds queries the Currency Deviation Thesholds
// the price feeder uses when starting up.
func (q querier) PriceFeederCurrencyDeviationThresholds(
goCtx context.Context,
req *types.QueryPriceFeederCurrencyDeviationThresholds,
) (*types.QueryPriceFeederCurrencyDeviationThresholdsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}

ctx := sdk.UnwrapSDKContext(goCtx)

pfCurrencyDeviationThresholdList := q.PriceFeederCurrencyDeviationThresholdList(ctx)

return &types.QueryPriceFeederCurrencyDeviationThresholdsResponse{
PriceFeederCurrencyDeviationThresholds: pfCurrencyDeviationThresholdList,
}, nil
}
32 changes: 28 additions & 4 deletions x/oracle/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,12 @@ func (s *IntegrationTestSuite) TestQuerier_PriceFeederCurrencyPairProviders() {
},
},
types.CurrencyPairProviders{
BaseDenom: "OJO",
QuoteDenom: "ATOM",
BaseDenom: "RETH",
QuoteDenom: "WETH",
Address: "address",
AddressProvider: "eth-uniswap",
Providers: []string{
"osmosis",
"mexc",
"eth-uniswap",
},
},
}
Expand All @@ -336,6 +337,29 @@ func (s *IntegrationTestSuite) TestQuerier_PriceFeederCurrencyPairProviders() {
s.Require().Equal(2, len(priceFeederCurrencyPairProvidersResp.PriceFeederCurrencyPairProviders))
}

func (s *IntegrationTestSuite) TestQuerier_PriceFeederCurrencyDeviationThresholds() {
app, ctx := s.app, s.ctx

pfCurrencyDeviationThresholdList := types.CurrencyDeviationThresholdList{
types.CurrencyDeviationThreshold{
BaseDenom: "OJO",
Threshold: "1.5",
},
types.CurrencyDeviationThreshold{
BaseDenom: "RETH",
Threshold: "2",
},
}
app.OracleKeeper.SetPriceFeederCurrencyDeviationThresholdList(ctx, pfCurrencyDeviationThresholdList)

priceFeederCurrencyDeviationThresholdsResp, err := s.queryClient.PriceFeederCurrencyDeviationThresholds(
ctx.Context(),
&types.QueryPriceFeederCurrencyDeviationThresholds{},
)
s.Require().NoError(err)
s.Require().Equal(2, len(priceFeederCurrencyDeviationThresholdsResp.PriceFeederCurrencyDeviationThresholds))
}

func (s *IntegrationTestSuite) TestEmptyRequest() {
q := keeper.NewQuerier(keeper.Keeper{})
const emptyRequestErrorMsg = "empty request"
Expand Down
130 changes: 124 additions & 6 deletions x/oracle/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,26 +316,144 @@ func (m Migrator) MigratePriceFeederCurrencyPairProviders(ctx sdk.Context) {
},
},
types.CurrencyPairProviders{
BaseDenom: "RETH",
QuoteDenom: "WETH",
BaseDenom: "RETH",
QuoteDenom: "WETH",
Address: "0xa4e0faA58465A2D369aa21B3e42d43374c6F9613",
AddressProvider: "eth-uniswap",
Providers: []string{
"eth-uniswap",
},
},
types.CurrencyPairProviders{
BaseDenom: "WETH",
QuoteDenom: "USDC",
BaseDenom: "WETH",
QuoteDenom: "USDC",
Address: "0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640",
AddressProvider: "eth-uniswap",
Providers: []string{
"eth-uniswap",
},
},
types.CurrencyPairProviders{
BaseDenom: "CBETH",
QuoteDenom: "WETH",
BaseDenom: "CBETH",
QuoteDenom: "WETH",
Address: "0x840deeef2f115cf50da625f7368c24af6fe74410",
AddressProvider: "eth-uniswap",
Providers: []string{
"eth-uniswap",
},
},
}
m.keeper.SetPriceFeederCurrencyPairProvidersList(ctx, priceFeederCurrencyPairProviders)
}

// MigratePriceFeederCurrencyDeviationThresholds adds the price feeder
// currency deviation threshold list.
func (m Migrator) MigratePriceFeederCurrencyDeviationThresholds(ctx sdk.Context) {
priceFeederCurrencyDeviationThresholds := types.CurrencyDeviationThresholdList{
types.CurrencyDeviationThreshold{
BaseDenom: "USDT",
Threshold: "1.5",
},
types.CurrencyDeviationThreshold{
BaseDenom: "ATOM",
Threshold: "1.5",
},
types.CurrencyDeviationThreshold{
BaseDenom: "ETH",
Threshold: "2",
},
types.CurrencyDeviationThreshold{
BaseDenom: "BTC",
Threshold: "2",
},
types.CurrencyDeviationThreshold{
BaseDenom: "OSMO",
Threshold: "2",
},
types.CurrencyDeviationThreshold{
BaseDenom: "stATOM",
Threshold: "2",
},
types.CurrencyDeviationThreshold{
BaseDenom: "stOSMO",
Threshold: "2",
},
types.CurrencyDeviationThreshold{
BaseDenom: "DAI",
Threshold: "2",
},
types.CurrencyDeviationThreshold{
BaseDenom: "JUNO",
Threshold: "2",
},
types.CurrencyDeviationThreshold{
BaseDenom: "stJUNO",
Threshold: "2",
},
types.CurrencyDeviationThreshold{
BaseDenom: "SCRT",
Threshold: "2",
},
types.CurrencyDeviationThreshold{
BaseDenom: "WBTC",
Threshold: "2",
},
types.CurrencyDeviationThreshold{
BaseDenom: "USDC",
Threshold: "1.5",
},
types.CurrencyDeviationThreshold{
BaseDenom: "IST",
Threshold: "2",
},
types.CurrencyDeviationThreshold{
BaseDenom: "BNB",
Threshold: "2",
},
types.CurrencyDeviationThreshold{
BaseDenom: "LUNA",
Threshold: "2",
},
types.CurrencyDeviationThreshold{
BaseDenom: "DOT",
Threshold: "2",
},
types.CurrencyDeviationThreshold{
BaseDenom: "AXL",
Threshold: "2",
},
types.CurrencyDeviationThreshold{
BaseDenom: "STARS",
Threshold: "2",
},
types.CurrencyDeviationThreshold{
BaseDenom: "XRP",
Threshold: "2",
},
types.CurrencyDeviationThreshold{
BaseDenom: "USK",
Threshold: "2",
},
types.CurrencyDeviationThreshold{
BaseDenom: "KUJI",
Threshold: "2",
},
types.CurrencyDeviationThreshold{
BaseDenom: "MNTA",
Threshold: "2",
},
types.CurrencyDeviationThreshold{
BaseDenom: "RETH",
Threshold: "2",
},
types.CurrencyDeviationThreshold{
BaseDenom: "WETH",
Threshold: "2",
},
types.CurrencyDeviationThreshold{
BaseDenom: "CBETH",
Threshold: "2",
},
}
m.keeper.SetPriceFeederCurrencyDeviationThresholdList(ctx, priceFeederCurrencyDeviationThresholds)
}
9 changes: 4 additions & 5 deletions x/oracle/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/hex"
"fmt"
"math/rand"
"strings"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -69,8 +68,8 @@ func (s *IntegrationTestSuite) TestMsgServer_AggregateExchangeRatePrevote() {
func (s *IntegrationTestSuite) TestMsgServer_AggregateExchangeRateVote() {
ctx := s.ctx

ratesStr := "ojo:123.2"
ratesStrInvalidCoin := "ojo:123.2,badcoin:234.5"
ratesStr := "OJO:123.2"
ratesStrInvalidCoin := "OJO:123.2,badcoin:234.5"
salt, err := GenerateSalt(32)
s.Require().NoError(err)
hash := oracletypes.GetAggregateVoteHash(salt, ratesStr, valAddr)
Expand Down Expand Up @@ -122,7 +121,7 @@ func (s *IntegrationTestSuite) TestMsgServer_AggregateExchangeRateVote() {
vote, err := s.app.OracleKeeper.GetAggregateExchangeRateVote(ctx, valAddr)
s.Require().Nil(err)
for _, v := range vote.ExchangeRates {
s.Require().Contains(acceptListFlat, strings.ToLower(v.Denom))
s.Require().Contains(acceptListFlat, v.Denom)
}

// Valid, but with an exchange rate which isn't in AcceptList
Expand All @@ -137,7 +136,7 @@ func (s *IntegrationTestSuite) TestMsgServer_AggregateExchangeRateVote() {
vote, err = s.app.OracleKeeper.GetAggregateExchangeRateVote(ctx, valAddr)
s.Require().NoError(err)
for _, v := range vote.ExchangeRates {
s.Require().Contains(acceptListFlat, strings.ToLower(v.Denom))
s.Require().Contains(acceptListFlat, v.Denom)
}
}

Expand Down
16 changes: 16 additions & 0 deletions x/oracle/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,19 @@ func (k Keeper) SetPriceFeederCurrencyPairProvidersList(
) {
k.paramSpace.Set(ctx, types.KeyPriceFeederCurrencyPairProviders, priceFeederCurrencyPairProviders)
}

// SetPriceFeederCurrencyDeviationThresholdList returns the current Currency Deviation Thesholds
// the price feeder will query when starting up.
func (k Keeper) PriceFeederCurrencyDeviationThresholdList(ctx sdk.Context) (res types.CurrencyDeviationThresholdList) {
k.paramSpace.Get(ctx, types.KeyPriceFeederCurrencyDeviationThresholds, &res)
return
}

// SetPriceFeederCurrencyDeviationThresholdList updates the current Currency Deviation Thesholds
// the price feeder will query when starting up.
func (k Keeper) SetPriceFeederCurrencyDeviationThresholdList(
ctx sdk.Context,
priceFeederCurrencyDeviationThresholds types.CurrencyDeviationThresholdList,
) {
k.paramSpace.Set(ctx, types.KeyPriceFeederCurrencyDeviationThresholds, priceFeederCurrencyDeviationThresholds)
}
4 changes: 2 additions & 2 deletions x/oracle/types/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (

const (
OjoDenom string = appparams.BondDenom
OjoSymbol string = "ojo"
OjoSymbol string = "OJO"
OjoExponent = uint32(6)
AtomDenom string = "ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9"
AtomSymbol string = "atom"
AtomSymbol string = "ATOM"
AtomExponent = uint32(6)
USDDenom string = "USD"
BlocksPerMinute = uint64(10)
Expand Down
Loading

0 comments on commit 6826a91

Please sign in to comment.