From ad5a2377134aa13d7d76575b95613cf8ed12d1e4 Mon Sep 17 00:00:00 2001 From: Adam Wozniak <29418299+adamewozniak@users.noreply.github.com> Date: Wed, 15 Feb 2023 07:31:49 -0800 Subject: [PATCH] feat: individual reward bands per denom (#98) --- proto/ojo/oracle/v1/oracle.proto | 19 +- x/oracle/README.md | 4 +- x/oracle/abci.go | 9 +- x/oracle/abci_test.go | 2 +- x/oracle/keeper/params.go | 5 +- x/oracle/keeper/slash_test.go | 2 - x/oracle/simulations/genesis.go | 28 ++- x/oracle/simulations/params.go | 2 +- x/oracle/types/errors.go | 1 + x/oracle/types/genesis_test.go | 4 +- x/oracle/types/oracle.pb.go | 387 +++++++++++++++++++++++------ x/oracle/types/params.go | 58 ++++- x/oracle/types/params_test.go | 2 +- x/oracle/types/reward_band.go | 46 ++++ x/oracle/types/reward_band_test.go | 63 +++++ 15 files changed, 521 insertions(+), 111 deletions(-) create mode 100644 x/oracle/types/reward_band.go create mode 100644 x/oracle/types/reward_band_test.go diff --git a/proto/ojo/oracle/v1/oracle.proto b/proto/ojo/oracle/v1/oracle.proto index 70ed22a0..ba33521d 100644 --- a/proto/ojo/oracle/v1/oracle.proto +++ b/proto/ojo/oracle/v1/oracle.proto @@ -19,9 +19,9 @@ message Params { (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false ]; - string reward_band = 3 [ - (gogoproto.moretags) = "yaml:\"reward_band\"", - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + repeated RewardBand reward_bands = 3 [ + (gogoproto.moretags) = "yaml:\"reward_bands\"", + (gogoproto.castrepeated) = "RewardBandList", (gogoproto.nullable) = false ]; uint64 reward_distribution_window = 4 @@ -73,6 +73,19 @@ message Denom { uint32 exponent = 3 [ (gogoproto.moretags) = "yaml:\"exponent\"" ]; } +// RewardBand - the object to hold the reward band configuration for a given denom. +message RewardBand { + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + option (gogoproto.goproto_stringer) = false; + string symbol_denom = 1 [ (gogoproto.moretags) = "yaml:\"symbol_denom\"" ]; + string reward_band = 2 [ + (gogoproto.moretags) = "yaml:\"reward_band\"", + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; +} + // AggregateExchangeRatePrevote - // struct for aggregate prevoting on the ExchangeRateVote. // The purpose of aggregate prevote is to hide vote exchange rates with hash diff --git a/x/oracle/README.md b/x/oracle/README.md index f490bebc..613e20e5 100644 --- a/x/oracle/README.md +++ b/x/oracle/README.md @@ -62,7 +62,9 @@ Validators must first pre-commit to a set of exchange rates, then in the subsequ ### Reward Band -Let `M` be the median, `𝜎` be the standard deviation of the votes in the ballot, and `R` be the RewardBand parameter. The band around the median is set to be `𝜀 = max(𝜎, R/2)`. All valid (i.e. bonded and non-jailed) validators that submitted an exchange rate vote in the interval `[M - 𝜀, M + 𝜀]` should be included in the set of winners. +Each asset has a unique RewardBand when it's being added to the Oracle Parameters. For some assets this needs to be smaller or larger in order to account for expected price flux / stability. + +Let `M` be the median, `𝜎` be the standard deviation of the votes in the ballot, and `R` be the RewardBand for a given asset. The band around the median is set to be `𝜀 = max(𝜎, R/2)`. All valid (i.e. bonded and non-jailed) validators that submitted an exchange rate vote in the interval `[M - 𝜀, M + 𝜀]` should be included in the set of winners. ### Reward Pool diff --git a/x/oracle/abci.go b/x/oracle/abci.go index 73dff49d..4e6d0e7a 100644 --- a/x/oracle/abci.go +++ b/x/oracle/abci.go @@ -62,8 +62,15 @@ func CalcPrices(ctx sdk.Context, params types.Params, k keeper.Keeper) error { // Increment Mandatory Win count if Denom in Mandatory list incrementWin := params.MandatoryList.Contains(ballotDenom.Denom) + + // Get the current denom's reward band + rewardBand, err := params.RewardBands.GetBandFromDenom(ballotDenom.Denom) + if err != nil { + return err + } + // Get median of exchange rates - exchangeRate, err := Tally(ballotDenom.Ballot, params.RewardBand, validatorClaimMap, incrementWin) + exchangeRate, err := Tally(ballotDenom.Ballot, rewardBand, validatorClaimMap, incrementWin) if err != nil { return err } diff --git a/x/oracle/abci_test.go b/x/oracle/abci_test.go index 9e3897d9..992f9348 100644 --- a/x/oracle/abci_test.go +++ b/x/oracle/abci_test.go @@ -387,7 +387,7 @@ func (s *IntegrationTestSuite) TestEndblockerHistoracle() { blockHeight += historicStampPeriod ctx = ctx.WithBlockHeight(blockHeight) - var decCoins = sdk.DecCoins{} + decCoins := sdk.DecCoins{} for denom, prices := range exchangeRates { decCoins = append(decCoins, sdk.DecCoin{ Denom: denom, diff --git a/x/oracle/keeper/params.go b/x/oracle/keeper/params.go index 926d3675..20c6e565 100644 --- a/x/oracle/keeper/params.go +++ b/x/oracle/keeper/params.go @@ -22,7 +22,7 @@ func (k Keeper) VoteThreshold(ctx sdk.Context) (res sdk.Dec) { // RewardBand returns the ratio of allowable exchange rate error that a validator // can be rewarded. func (k Keeper) RewardBand(ctx sdk.Context) (res sdk.Dec) { - k.paramSpace.Get(ctx, types.KeyRewardBand, &res) + k.paramSpace.Get(ctx, types.KeyRewardBands, &res) return } @@ -54,7 +54,8 @@ func (k Keeper) MandatoryList(ctx sdk.Context) (res types.DenomList) { // SetMandatoryList updates the mandatory list of assets supported by the x/oracle // module. func (k Keeper) SetMandatoryList(ctx sdk.Context, - mandatoryList types.DenomList) { + mandatoryList types.DenomList, +) { k.paramSpace.Set(ctx, types.KeyMandatoryList, mandatoryList) } diff --git a/x/oracle/keeper/slash_test.go b/x/oracle/keeper/slash_test.go index f1008c4d..b5d3fa47 100644 --- a/x/oracle/keeper/slash_test.go +++ b/x/oracle/keeper/slash_test.go @@ -81,7 +81,6 @@ func (s *IntegrationTestSuite) TestSlashAndResetMissCounters() { s.Require().Equal(tc.jailedAfter, validator.Jailed) }) } - } func (s *IntegrationTestSuite) TestPossibleWinsPerSlashWindow() { @@ -129,5 +128,4 @@ func (s *IntegrationTestSuite) TestPossibleWinsPerSlashWindow() { s.Require().Equal(tc.possibleWinsPerSlashWindow, actual) }) } - } diff --git a/x/oracle/simulations/genesis.go b/x/oracle/simulations/genesis.go index 84be7a00..d30262ea 100644 --- a/x/oracle/simulations/genesis.go +++ b/x/oracle/simulations/genesis.go @@ -15,7 +15,7 @@ import ( const ( votePeriodKey = "vote_period" voteThresholdKey = "vote_threshold" - rewardBandKey = "reward_band" + rewardBandsKey = "reward_bands" rewardDistributionWindowKey = "reward_distribution_window" slashFractionKey = "slash_fraction" slashWindowKey = "slash_window" @@ -83,6 +83,8 @@ func GenMaximumMedianStamps(r *rand.Rand) uint64 { // RandomizedGenState generates a random GenesisState for oracle func RandomizedGenState(simState *module.SimulationState) { + oracleGenesis := types.DefaultGenesisState() + var votePeriod uint64 simState.AppParams.GetOrGenerate( simState.Cdc, votePeriodKey, &votePeriod, simState.Rand, @@ -95,10 +97,25 @@ func RandomizedGenState(simState *module.SimulationState) { func(r *rand.Rand) { voteThreshold = GenVoteThreshold(r) }, ) - var rewardBand sdk.Dec + var rewardBands types.RewardBandList simState.AppParams.GetOrGenerate( - simState.Cdc, rewardBandKey, &rewardBand, simState.Rand, - func(r *rand.Rand) { rewardBand = GenRewardBand(r) }, + simState.Cdc, rewardBandsKey, &rewardBands, simState.Rand, + func(r *rand.Rand) { + for _, denom := range oracleGenesis.Params.MandatoryList { + rb := types.RewardBand{ + RewardBand: GenRewardBand(r), + SymbolDenom: denom.SymbolDenom, + } + rewardBands = append(rewardBands, rb) + } + for _, denom := range oracleGenesis.Params.AcceptList { + rb := types.RewardBand{ + RewardBand: GenRewardBand(r), + SymbolDenom: denom.SymbolDenom, + } + rewardBands = append(rewardBands, rb) + } + }, ) var rewardDistributionWindow uint64 @@ -149,11 +166,10 @@ func RandomizedGenState(simState *module.SimulationState) { func(r *rand.Rand) { maximumMedianStamps = GenMaximumMedianStamps(r) }, ) - oracleGenesis := types.DefaultGenesisState() oracleGenesis.Params = types.Params{ VotePeriod: votePeriod, VoteThreshold: voteThreshold, - RewardBand: rewardBand, + RewardBands: rewardBands, RewardDistributionWindow: rewardDistributionWindow, AcceptList: types.DenomList{ {SymbolDenom: types.OjoSymbol, BaseDenom: types.OjoDenom}, diff --git a/x/oracle/simulations/params.go b/x/oracle/simulations/params.go index 1a681158..0d3c41bc 100644 --- a/x/oracle/simulations/params.go +++ b/x/oracle/simulations/params.go @@ -24,7 +24,7 @@ func ParamChanges(_ *rand.Rand) []simtypes.ParamChange { return fmt.Sprintf("\"%s\"", GenVoteThreshold(r)) }, ), - simulation.NewSimParamChange(types.ModuleName, string(types.KeyRewardBand), + simulation.NewSimParamChange(types.ModuleName, string(types.KeyRewardBands), func(r *rand.Rand) string { return fmt.Sprintf("\"%s\"", GenRewardBand(r)) }, diff --git a/x/oracle/types/errors.go b/x/oracle/types/errors.go index 3dd1d220..9c81e459 100644 --- a/x/oracle/types/errors.go +++ b/x/oracle/types/errors.go @@ -29,4 +29,5 @@ var ( ErrNoHistoricPrice = errors.Register(ModuleName, 19, "no historic price for this denom at this block") ErrNoMedian = errors.Register(ModuleName, 20, "no median for this denom at this block") ErrNoMedianDeviation = errors.Register(ModuleName, 21, "no median deviation for this denom at this block") + ErrNoRewardBand = errors.Register(ModuleName, 22, "unable to find the reward band the given asset") ) diff --git a/x/oracle/types/genesis_test.go b/x/oracle/types/genesis_test.go index dca5dbdb..ace1992c 100644 --- a/x/oracle/types/genesis_test.go +++ b/x/oracle/types/genesis_test.go @@ -24,9 +24,9 @@ func TestGenesisValidation(t *testing.T) { // Invalid Rewardband genState = DefaultGenesisState() - genState.Params.RewardBand = sdk.NewDec(2) + genState.Params.RewardBands[0].RewardBand = sdk.NewDec(2) require.Error(t, ValidateGenesis(genState)) - genState.Params.RewardBand = sdk.NewDec(-1) + genState.Params.RewardBands[0].RewardBand = sdk.NewDec(-1) require.Error(t, ValidateGenesis(genState)) // Invalid RewardDistributionWindow diff --git a/x/oracle/types/oracle.pb.go b/x/oracle/types/oracle.pb.go index 78386825..3eae689a 100644 --- a/x/oracle/types/oracle.pb.go +++ b/x/oracle/types/oracle.pb.go @@ -29,7 +29,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type Params struct { VotePeriod uint64 `protobuf:"varint,1,opt,name=vote_period,json=votePeriod,proto3" json:"vote_period,omitempty" yaml:"vote_period"` VoteThreshold github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=vote_threshold,json=voteThreshold,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"vote_threshold" yaml:"vote_threshold"` - RewardBand github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=reward_band,json=rewardBand,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"reward_band" yaml:"reward_band"` + RewardBands RewardBandList `protobuf:"bytes,3,rep,name=reward_bands,json=rewardBands,proto3,castrepeated=RewardBandList" json:"reward_bands" yaml:"reward_bands"` RewardDistributionWindow uint64 `protobuf:"varint,4,opt,name=reward_distribution_window,json=rewardDistributionWindow,proto3" json:"reward_distribution_window,omitempty" yaml:"reward_distribution_window"` AcceptList DenomList `protobuf:"bytes,5,rep,name=accept_list,json=acceptList,proto3,castrepeated=DenomList" json:"accept_list" yaml:"accept_list"` SlashFraction github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,6,opt,name=slash_fraction,json=slashFraction,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"slash_fraction" yaml:"slash_fraction"` @@ -122,6 +122,43 @@ func (m *Denom) XXX_DiscardUnknown() { var xxx_messageInfo_Denom proto.InternalMessageInfo +type RewardBand struct { + SymbolDenom string `protobuf:"bytes,1,opt,name=symbol_denom,json=symbolDenom,proto3" json:"symbol_denom,omitempty" yaml:"symbol_denom"` + RewardBand github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=reward_band,json=rewardBand,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"reward_band" yaml:"reward_band"` +} + +func (m *RewardBand) Reset() { *m = RewardBand{} } +func (*RewardBand) ProtoMessage() {} +func (*RewardBand) Descriptor() ([]byte, []int) { + return fileDescriptor_e2b9fb194216b28f, []int{2} +} +func (m *RewardBand) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *RewardBand) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_RewardBand.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *RewardBand) XXX_Merge(src proto.Message) { + xxx_messageInfo_RewardBand.Merge(m, src) +} +func (m *RewardBand) XXX_Size() int { + return m.Size() +} +func (m *RewardBand) XXX_DiscardUnknown() { + xxx_messageInfo_RewardBand.DiscardUnknown(m) +} + +var xxx_messageInfo_RewardBand proto.InternalMessageInfo + // AggregateExchangeRatePrevote - // struct for aggregate prevoting on the ExchangeRateVote. // The purpose of aggregate prevote is to hide vote exchange rates with hash @@ -136,7 +173,7 @@ type AggregateExchangeRatePrevote struct { func (m *AggregateExchangeRatePrevote) Reset() { *m = AggregateExchangeRatePrevote{} } func (*AggregateExchangeRatePrevote) ProtoMessage() {} func (*AggregateExchangeRatePrevote) Descriptor() ([]byte, []int) { - return fileDescriptor_e2b9fb194216b28f, []int{2} + return fileDescriptor_e2b9fb194216b28f, []int{3} } func (m *AggregateExchangeRatePrevote) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -175,7 +212,7 @@ type AggregateExchangeRateVote struct { func (m *AggregateExchangeRateVote) Reset() { *m = AggregateExchangeRateVote{} } func (*AggregateExchangeRateVote) ProtoMessage() {} func (*AggregateExchangeRateVote) Descriptor() ([]byte, []int) { - return fileDescriptor_e2b9fb194216b28f, []int{3} + return fileDescriptor_e2b9fb194216b28f, []int{4} } func (m *AggregateExchangeRateVote) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -204,6 +241,8 @@ func (m *AggregateExchangeRateVote) XXX_DiscardUnknown() { var xxx_messageInfo_AggregateExchangeRateVote proto.InternalMessageInfo +// PriceStamp defines a stamp of a denom's exchange rate +// at the block number it was calculated in. type PriceStamp struct { ExchangeRate *types.DecCoin `protobuf:"bytes,1,opt,name=exchange_rate,json=exchangeRate,proto3" json:"exchange_rate,omitempty"` BlockNum uint64 `protobuf:"varint,2,opt,name=block_num,json=blockNum,proto3" json:"block_num,omitempty"` @@ -213,7 +252,7 @@ func (m *PriceStamp) Reset() { *m = PriceStamp{} } func (m *PriceStamp) String() string { return proto.CompactTextString(m) } func (*PriceStamp) ProtoMessage() {} func (*PriceStamp) Descriptor() ([]byte, []int) { - return fileDescriptor_e2b9fb194216b28f, []int{4} + return fileDescriptor_e2b9fb194216b28f, []int{5} } func (m *PriceStamp) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -245,6 +284,7 @@ var xxx_messageInfo_PriceStamp proto.InternalMessageInfo func init() { proto.RegisterType((*Params)(nil), "ojo.oracle.v1.Params") proto.RegisterType((*Denom)(nil), "ojo.oracle.v1.Denom") + proto.RegisterType((*RewardBand)(nil), "ojo.oracle.v1.RewardBand") proto.RegisterType((*AggregateExchangeRatePrevote)(nil), "ojo.oracle.v1.AggregateExchangeRatePrevote") proto.RegisterType((*AggregateExchangeRateVote)(nil), "ojo.oracle.v1.AggregateExchangeRateVote") proto.RegisterType((*PriceStamp)(nil), "ojo.oracle.v1.PriceStamp") @@ -253,64 +293,67 @@ func init() { func init() { proto.RegisterFile("ojo/oracle/v1/oracle.proto", fileDescriptor_e2b9fb194216b28f) } var fileDescriptor_e2b9fb194216b28f = []byte{ - // 909 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x55, 0xcf, 0x6f, 0xe3, 0x44, - 0x14, 0x8e, 0xd9, 0xb6, 0x24, 0x93, 0xa4, 0x4b, 0xdd, 0x16, 0x4c, 0x77, 0x15, 0x17, 0x23, 0x96, - 0x02, 0x5a, 0x9b, 0xee, 0x22, 0x21, 0xf5, 0xb6, 0xa6, 0xb0, 0x17, 0x16, 0x45, 0x06, 0x2d, 0x12, - 0x07, 0xac, 0xb1, 0x3d, 0x24, 0xd3, 0x7a, 0x66, 0xa2, 0x99, 0x49, 0x9b, 0x5e, 0x38, 0x73, 0xe4, - 0xc8, 0xb1, 0xe7, 0xbd, 0x23, 0xf1, 0x17, 0xa0, 0x4a, 0x5c, 0xf6, 0x88, 0x38, 0x78, 0xa1, 0xbd, - 0x70, 0xce, 0x5f, 0x80, 0xe6, 0x47, 0x1a, 0xa7, 0xaa, 0x60, 0x2b, 0x4e, 0x9e, 0x37, 0xdf, 0x7c, - 0xef, 0x7d, 0xef, 0xc7, 0x8c, 0xc1, 0x16, 0x3b, 0x60, 0x11, 0xe3, 0x30, 0x2f, 0x51, 0x74, 0xb4, - 0x6b, 0x57, 0xe1, 0x88, 0x33, 0xc9, 0xdc, 0x2e, 0x3b, 0x60, 0xa1, 0xdd, 0x39, 0xda, 0xdd, 0xda, - 0x18, 0xb0, 0x01, 0xd3, 0x48, 0xa4, 0x56, 0xe6, 0xd0, 0x56, 0x2f, 0x67, 0x82, 0x30, 0x11, 0x65, - 0x50, 0x28, 0x0f, 0x19, 0x92, 0x70, 0x37, 0xca, 0x19, 0xa6, 0x06, 0x0f, 0x7e, 0x6d, 0x82, 0x95, - 0x3e, 0xe4, 0x90, 0x08, 0xf7, 0x63, 0xd0, 0x3e, 0x62, 0x12, 0xa5, 0x23, 0xc4, 0x31, 0x2b, 0x3c, - 0x67, 0xdb, 0xd9, 0x59, 0x8a, 0x5f, 0x9f, 0x56, 0xbe, 0x7b, 0x02, 0x49, 0xb9, 0x17, 0xd4, 0xc0, - 0x20, 0x01, 0xca, 0xea, 0x6b, 0xc3, 0xa5, 0x60, 0x55, 0x63, 0x72, 0xc8, 0x91, 0x18, 0xb2, 0xb2, - 0xf0, 0x5e, 0xd9,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xa5, 0x1c, 0x4a, 0x24, 0x3c, 0x47, 0x4f, 0xf3, 0xdd, 0xd0, - 0x5c, 0x97, 0x50, 0xd5, 0x3e, 0xb4, 0xbf, 0x04, 0x75, 0x63, 0x3e, 0x61, 0x98, 0xc6, 0x0f, 0xd5, - 0x54, 0x3f, 0x7b, 0xe1, 0x7f, 0xf0, 0x72, 0xb7, 0x4c, 0x71, 0x44, 0xd2, 0x45, 0xb5, 0xe0, 0xe2, - 0x65, 0x2b, 0x71, 0x25, 0x9b, 0x12, 0x80, 0xf9, 0x34, 0xba, 0x8f, 0x40, 0x77, 0x41, 0xbd, 0xae, - 0xfd, 0x7f, 0x88, 0x4f, 0x3a, 0x75, 0x1d, 0xee, 0x1d, 0xd0, 0xd2, 0x35, 0x4c, 0xe9, 0xd8, 0x8c, - 0xd3, 0x52, 0xd2, 0xd4, 0x1b, 0x5f, 0x8c, 0x49, 0xfc, 0xf8, 0xec, 0xaf, 0x5e, 0xe3, 0xec, 0xbc, - 0xe7, 0x3c, 0x3f, 0xef, 0x39, 0x7f, 0x9e, 0xf7, 0x9c, 0x1f, 0x2f, 0x7a, 0x8d, 0xe7, 0x17, 0xbd, - 0xc6, 0xef, 0x17, 0xbd, 0xc6, 0x37, 0xef, 0xd5, 0xb2, 0x67, 0x07, 0xec, 0x3e, 0x45, 0xf2, 0x98, - 0xf1, 0x43, 0xb5, 0x8e, 0x26, 0xb3, 0xff, 0xb1, 0x2e, 0x42, 0xb6, 0xa2, 0xff, 0xa3, 0x0f, 0xff, - 0x09, 0x00, 0x00, 0xff, 0xff, 0xdd, 0xe3, 0xe0, 0x22, 0xaa, 0x07, 0x00, 0x00, + // 960 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x56, 0xbf, 0x6f, 0x23, 0x45, + 0x14, 0xf6, 0x92, 0x1f, 0xd8, 0x63, 0x3b, 0x47, 0x36, 0x09, 0xec, 0xe5, 0x4e, 0xde, 0xb0, 0x88, + 0x23, 0x80, 0xb2, 0x4b, 0xee, 0x90, 0x90, 0xd2, 0xdd, 0x12, 0xb8, 0x86, 0x43, 0xd6, 0x80, 0x0e, + 0x89, 0x82, 0xd5, 0xec, 0xee, 0x60, 0x4f, 0xb2, 0xbb, 0x63, 0xcd, 0x8c, 0x13, 0xa7, 0xa1, 0xa6, + 0xa4, 0xa4, 0x4c, 0x7d, 0x3d, 0x12, 0x0d, 0x7d, 0x24, 0x28, 0xae, 0x44, 0x14, 0x7b, 0x90, 0x34, + 0xd4, 0xfe, 0x0b, 0xd0, 0xfc, 0xb0, 0xbd, 0xf6, 0x45, 0x70, 0x11, 0x95, 0xe7, 0xcd, 0xf7, 0xde, + 0xbc, 0xef, 0x7d, 0x6f, 0xe6, 0x79, 0xc1, 0x36, 0x3d, 0xa2, 0x01, 0x65, 0x28, 0xc9, 0x70, 0x70, + 0xb2, 0x6f, 0x56, 0xfe, 0x80, 0x51, 0x41, 0xed, 0x36, 0x3d, 0xa2, 0xbe, 0xd9, 0x39, 0xd9, 0xdf, + 0xde, 0xec, 0xd1, 0x1e, 0x55, 0x48, 0x20, 0x57, 0xda, 0x69, 0xbb, 0x93, 0x50, 0x9e, 0x53, 0x1e, + 0xc4, 0x88, 0xcb, 0x13, 0x62, 0x2c, 0xd0, 0x7e, 0x90, 0x50, 0x52, 0x68, 0xdc, 0xfb, 0xad, 0x0e, + 0x56, 0xbb, 0x88, 0xa1, 0x9c, 0xdb, 0x1f, 0x81, 0xe6, 0x09, 0x15, 0x38, 0x1a, 0x60, 0x46, 0x68, + 0xea, 0x58, 0x3b, 0xd6, 0xee, 0x72, 0xf8, 0xfa, 0xb8, 0x74, 0xed, 0x33, 0x94, 0x67, 0x07, 0x5e, + 0x05, 0xf4, 0x20, 0x90, 0x56, 0x57, 0x19, 0x76, 0x01, 0xd6, 0x14, 0x26, 0xfa, 0x0c, 0xf3, 0x3e, + 0xcd, 0x52, 0xe7, 0x95,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xaf, 0xaa, 0xaf, + 0x81, 0x07, 0xff, 0x04, 0x00, 0x00, 0xff, 0xff, 0xfa, 0x52, 0x13, 0x5a, 0x70, 0x08, 0x00, 0x00, } func (this *Params) Equal(that interface{}) bool { @@ -338,9 +381,14 @@ func (this *Params) Equal(that interface{}) bool { if !this.VoteThreshold.Equal(that1.VoteThreshold) { return false } - if !this.RewardBand.Equal(that1.RewardBand) { + if len(this.RewardBands) != len(that1.RewardBands) { return false } + for i := range this.RewardBands { + if !this.RewardBands[i].Equal(&that1.RewardBands[i]) { + return false + } + } if this.RewardDistributionWindow != that1.RewardDistributionWindow { return false } @@ -481,16 +529,20 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x20 } - { - size := m.RewardBand.Size() - i -= size - if _, err := m.RewardBand.MarshalTo(dAtA[i:]); err != nil { - return 0, err + if len(m.RewardBands) > 0 { + for iNdEx := len(m.RewardBands) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.RewardBands[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintOracle(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a } - i = encodeVarintOracle(dAtA, i, uint64(size)) } - i-- - dAtA[i] = 0x1a { size := m.VoteThreshold.Size() i -= size @@ -551,6 +603,46 @@ func (m *Denom) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *RewardBand) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *RewardBand) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *RewardBand) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.RewardBand.Size() + i -= size + if _, err := m.RewardBand.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintOracle(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.SymbolDenom) > 0 { + i -= len(m.SymbolDenom) + copy(dAtA[i:], m.SymbolDenom) + i = encodeVarintOracle(dAtA, i, uint64(len(m.SymbolDenom))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func (m *AggregateExchangeRatePrevote) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -699,8 +791,12 @@ func (m *Params) Size() (n int) { } l = m.VoteThreshold.Size() n += 1 + l + sovOracle(uint64(l)) - l = m.RewardBand.Size() - n += 1 + l + sovOracle(uint64(l)) + if len(m.RewardBands) > 0 { + for _, e := range m.RewardBands { + l = e.Size() + n += 1 + l + sovOracle(uint64(l)) + } + } if m.RewardDistributionWindow != 0 { n += 1 + sovOracle(uint64(m.RewardDistributionWindow)) } @@ -758,6 +854,21 @@ func (m *Denom) Size() (n int) { return n } +func (m *RewardBand) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.SymbolDenom) + if l > 0 { + n += 1 + l + sovOracle(uint64(l)) + } + l = m.RewardBand.Size() + n += 1 + l + sovOracle(uint64(l)) + return n +} + func (m *AggregateExchangeRatePrevote) Size() (n int) { if m == nil { return 0 @@ -903,9 +1014,9 @@ func (m *Params) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RewardBand", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field RewardBands", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowOracle @@ -915,23 +1026,23 @@ func (m *Params) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthOracle } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthOracle } if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.RewardBand.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.RewardBands = append(m.RewardBands, RewardBand{}) + if err := m.RewardBands[len(m.RewardBands)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -1339,6 +1450,122 @@ func (m *Denom) Unmarshal(dAtA []byte) error { } return nil } +func (m *RewardBand) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowOracle + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: RewardBand: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: RewardBand: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SymbolDenom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowOracle + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthOracle + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthOracle + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SymbolDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RewardBand", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowOracle + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthOracle + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthOracle + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.RewardBand.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipOracle(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthOracle + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *AggregateExchangeRatePrevote) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/x/oracle/types/params.go b/x/oracle/types/params.go index de362503..beaabfa3 100644 --- a/x/oracle/types/params.go +++ b/x/oracle/types/params.go @@ -12,7 +12,7 @@ import ( var ( KeyVotePeriod = []byte("VotePeriod") KeyVoteThreshold = []byte("VoteThreshold") - KeyRewardBand = []byte("RewardBand") + KeyRewardBands = []byte("RewardBands") KeyRewardDistributionWindow = []byte("RewardDistributionWindow") KeyAcceptList = []byte("AcceptList") KeyMandatoryList = []byte("MandatoryList") @@ -39,8 +39,8 @@ const ( // Default parameter values var ( DefaultVoteThreshold = sdk.NewDecWithPrec(50, 2) // 50% - DefaultRewardBand = sdk.NewDecWithPrec(2, 2) // 2% (-1, 1) - DefaultAcceptList = DenomList{ + + DefaultAcceptList = DenomList{ { BaseDenom: OjoDenom, SymbolDenom: OjoSymbol, @@ -65,12 +65,29 @@ var ( var _ paramstypes.ParamSet = &Params{} +// DefaultRewardBands returns a new default RewardBandList object. +// +// This function is necessary because we cannot use a constant, +// and the reward band list is manipulated in our unit tests. +func DefaultRewardBands() RewardBandList { + defaultRewardBand := sdk.NewDecWithPrec(2, 2) // 0.02 + return RewardBandList{ + { + SymbolDenom: OjoSymbol, + RewardBand: defaultRewardBand, + }, + { + SymbolDenom: AtomSymbol, + RewardBand: defaultRewardBand, + }, + } +} + // DefaultParams creates default oracle module parameters func DefaultParams() Params { return Params{ VotePeriod: DefaultVotePeriod, VoteThreshold: DefaultVoteThreshold, - RewardBand: DefaultRewardBand, RewardDistributionWindow: DefaultRewardDistributionWindow, AcceptList: DefaultAcceptList, MandatoryList: DefaultMandatoryList, @@ -81,6 +98,7 @@ func DefaultParams() Params { MedianStampPeriod: DefaultMedianStampPeriod, MaximumPriceStamps: DefaultMaximumPriceStamps, MaximumMedianStamps: DefaultMaximumMedianStamps, + RewardBands: DefaultRewardBands(), } } @@ -104,9 +122,9 @@ func (p *Params) ParamSetPairs() paramstypes.ParamSetPairs { validateVoteThreshold, ), paramstypes.NewParamSetPair( - KeyRewardBand, - &p.RewardBand, - validateRewardBand, + KeyRewardBands, + &p.RewardBands, + validateRewardBands, ), paramstypes.NewParamSetPair( KeyRewardDistributionWindow, @@ -176,10 +194,6 @@ func (p Params) Validate() error { return fmt.Errorf("oracle parameter VoteThreshold must be greater than 33 percent") } - if p.RewardBand.GT(sdk.OneDec()) || p.RewardBand.IsNegative() { - return fmt.Errorf("oracle parameter RewardBand must be between [0, 1]") - } - if p.RewardDistributionWindow < p.VotePeriod { return fmt.Errorf("oracle parameter RewardDistributionWindow must be greater than or equal with VotePeriod") } @@ -212,7 +226,11 @@ func (p Params) Validate() error { if len(denom.SymbolDenom) == 0 { return fmt.Errorf("oracle parameter MandatoryList Denom must have SymbolDenom") } + } + err := validateRewardBands(p.RewardBands) + if err != nil { + return err } // all denoms in mandatory list must be in accept list @@ -301,6 +319,24 @@ func validateDenomList(i interface{}) error { return nil } +func validateRewardBands(i interface{}) error { + v, ok := i.(RewardBandList) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + for _, d := range v { + if err := validateRewardBand(d.RewardBand); err != nil { + return err + } + if len(d.SymbolDenom) == 0 { + return fmt.Errorf("oracle parameter RewardBand must have SymbolDenom") + } + } + + return nil +} + func validateSlashFraction(i interface{}) error { v, ok := i.(sdk.Dec) if !ok { diff --git a/x/oracle/types/params_test.go b/x/oracle/types/params_test.go index f5879c17..f39ded51 100644 --- a/x/oracle/types/params_test.go +++ b/x/oracle/types/params_test.go @@ -139,7 +139,7 @@ func TestParamsEqual(t *testing.T) { // negative reward band p3 := DefaultParams() - p3.RewardBand = sdk.NewDecWithPrec(-1, 2) + p3.RewardBands[0].RewardBand = sdk.NewDecWithPrec(-1, 2) err = p3.Validate() require.Error(t, err) diff --git a/x/oracle/types/reward_band.go b/x/oracle/types/reward_band.go new file mode 100644 index 00000000..01362a35 --- /dev/null +++ b/x/oracle/types/reward_band.go @@ -0,0 +1,46 @@ +package types + +import ( + "strings" + + sdk "github.com/cosmos/cosmos-sdk/types" + "gopkg.in/yaml.v3" +) + +// String implements fmt.Stringer interface +func (rb RewardBand) String() string { + out, _ := yaml.Marshal(rb) + return string(out) +} + +func (rb RewardBand) Equal(rb2 *RewardBand) bool { + if !strings.EqualFold(rb.SymbolDenom, rb2.SymbolDenom) { + return false + } + if !rb.RewardBand.Equal(rb2.RewardBand) { + return false + } + return true +} + +// RewardBandList is array of RewardBand +type RewardBandList []RewardBand + +func (rbl RewardBandList) String() (out string) { + for _, d := range rbl { + out += d.String() + "\n" + } + + return strings.TrimSpace(out) +} + +// GetRewardBand returns the reward band of a given Denom. +// It will return an error if it can not find it. +func (rbl RewardBandList) GetBandFromDenom(denom string) (sdk.Dec, error) { + for _, rb := range rbl { + if strings.EqualFold(denom, rb.SymbolDenom) { + return rb.RewardBand, nil + } + } + return sdk.ZeroDec(), ErrNoRewardBand +} diff --git a/x/oracle/types/reward_band_test.go b/x/oracle/types/reward_band_test.go new file mode 100644 index 00000000..5bf0355f --- /dev/null +++ b/x/oracle/types/reward_band_test.go @@ -0,0 +1,63 @@ +package types + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" +) + +func TestRewardBandString(t *testing.T) { + rb := RewardBand{ + SymbolDenom: "ojo", + RewardBand: sdk.OneDec(), + } + require.Equal(t, rb.String(), "symbol_denom: ojo\nreward_band: \"1.000000000000000000\"\n") + + rbl := RewardBandList{rb} + require.Equal(t, rbl.String(), "symbol_denom: ojo\nreward_band: \"1.000000000000000000\"") +} + +func TestRewardBandEqual(t *testing.T) { + rb := RewardBand{ + SymbolDenom: "ojo", + RewardBand: sdk.OneDec(), + } + rb2 := RewardBand{ + SymbolDenom: "ojo", + RewardBand: sdk.OneDec(), + } + rb3 := RewardBand{ + SymbolDenom: "inequal", + RewardBand: sdk.OneDec(), + } + + require.True(t, rb.Equal(&rb2)) + require.False(t, rb.Equal(&rb3)) + require.False(t, rb2.Equal(&rb3)) +} + +func TestRewardBandDenomFinder(t *testing.T) { + rbl := RewardBandList{ + { + SymbolDenom: "foo", + RewardBand: sdk.OneDec(), + }, + { + SymbolDenom: "bar", + RewardBand: sdk.ZeroDec(), + }, + } + + band, err := rbl.GetBandFromDenom("foo") + require.NoError(t, err) + require.Equal(t, band, sdk.OneDec()) + + band, err = rbl.GetBandFromDenom("bar") + require.NoError(t, err) + require.Equal(t, band, sdk.ZeroDec()) + + band, err = rbl.GetBandFromDenom("baz") + require.Error(t, err) + require.Equal(t, band, sdk.ZeroDec()) +}