Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement incentive msg interface #1653

Merged
merged 5 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion proto/umee/incentive/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ message GenesisState {
];
repeated Bond bonds = 8 [(gogoproto.nullable) = false];
repeated PendingReward pending_rewards = 9 [(gogoproto.nullable) = false];
repeated RewardTracker reward_bases = 10 [(gogoproto.nullable) = false];
repeated RewardTracker reward_trackers = 10 [(gogoproto.nullable) = false];
repeated RewardAccumulator reward_accumulators = 11 [(gogoproto.nullable) = false];
repeated Unbonding unbondings = 12 [(gogoproto.nullable) = false];
}
Expand Down
2 changes: 1 addition & 1 deletion proto/umee/oracle/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ message GenesisState {
[(gogoproto.nullable) = false];
repeated AggregateExchangeRateVote aggregate_exchange_rate_votes = 6
[(gogoproto.nullable) = false];
repeated Price historic_prices = 8 [(gogoproto.nullable) = false];
repeated Price medians = 7 [(gogoproto.nullable) = false];
repeated Price historic_prices = 8 [(gogoproto.nullable) = false];
repeated Price medianDeviations = 9 [(gogoproto.nullable) = false];
}

Expand Down
143 changes: 53 additions & 90 deletions swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1233,54 +1233,41 @@ paths:
format: uint64
min_valid_per_window:
type: string
stamp_period:
historic_stamp_period:
toteki marked this conversation as resolved.
Show resolved Hide resolved
type: string
format: uint64
description: >-
Stamp Period represents the amount of blocks the
historacle module
Historic Stamp Period represents the amount of blocks the
oracle

waits before recording a set of prices from the oracle.
prune_period:
module waits before recording a new historic price.
median_stamp_period:
type: string
format: uint64
description: >-
Prune Period represents the maximum amount of blocks which
we want
Median Stamp Period represents the amount blocks the
oracle module

to keep a record of our set of exchange rates.
median_period:
waits between calculating and stamping a new median and
standard

deviation of that median.
maximum_price_stamps:
type: string
format: uint64
description: >-
Median Period represents the amount blocks we will wait
between

calculating the median and standard deviation of the
median of
Maximum Price Stamps represents the maximum amount of
historic prices

historic prices in the last Prune Period.
historic_accept_list:
type: array
items:
type: object
properties:
base_denom:
type: string
symbol_denom:
type: string
exponent:
type: integer
format: int64
title: Denom - the object to hold configurations of each denom
the oracle module will store before pruning via FIFO.
maximum_median_stamps:
type: string
format: uint64
description: >-
Historic Asset List is a list of assets which will use the
historic

price stamping protection methodology (mainly
manipulatable assets).
Maximum Median Stamps represents the maximum amount of
medians the

Any assets not on this list will not be stamped.
oracle module will store before pruning via FIFO.
description: >-
QueryParamsResponse is the response type for the Query/Params RPC
method.
Expand Down Expand Up @@ -2716,42 +2703,31 @@ definitions:
format: uint64
min_valid_per_window:
type: string
stamp_period:
historic_stamp_period:
type: string
format: uint64
description: |-
Stamp Period represents the amount of blocks the historacle module
waits before recording a set of prices from the oracle.
prune_period:
Historic Stamp Period represents the amount of blocks the oracle
module waits before recording a new historic price.
median_stamp_period:
type: string
format: uint64
description: |-
Prune Period represents the maximum amount of blocks which we want
to keep a record of our set of exchange rates.
median_period:
Median Stamp Period represents the amount blocks the oracle module
waits between calculating and stamping a new median and standard
deviation of that median.
maximum_price_stamps:
type: string
format: uint64
description: |-
Median Period represents the amount blocks we will wait between
calculating the median and standard deviation of the median of
historic prices in the last Prune Period.
historic_accept_list:
type: array
items:
type: object
properties:
base_denom:
type: string
symbol_denom:
type: string
exponent:
type: integer
format: int64
title: Denom - the object to hold configurations of each denom
Maximum Price Stamps represents the maximum amount of historic prices
the oracle module will store before pruning via FIFO.
maximum_median_stamps:
type: string
format: uint64
description: |-
Historic Asset List is a list of assets which will use the historic
price stamping protection methodology (mainly manipulatable assets).
Any assets not on this list will not be stamped.
Maximum Median Stamps represents the maximum amount of medians the
oracle module will store before pruning via FIFO.
description: Params defines the parameters for the oracle module.
umee.oracle.v1.QueryActiveExchangeRatesResponse:
type: object
Expand Down Expand Up @@ -3016,46 +2992,33 @@ definitions:
format: uint64
min_valid_per_window:
type: string
stamp_period:
historic_stamp_period:
type: string
format: uint64
description: |-
Stamp Period represents the amount of blocks the historacle module
waits before recording a set of prices from the oracle.
prune_period:
Historic Stamp Period represents the amount of blocks the oracle
module waits before recording a new historic price.
median_stamp_period:
type: string
format: uint64
description: |-
Prune Period represents the maximum amount of blocks which we want
to keep a record of our set of exchange rates.
median_period:
Median Stamp Period represents the amount blocks the oracle module
waits between calculating and stamping a new median and standard
deviation of that median.
maximum_price_stamps:
type: string
format: uint64
description: |-
Median Period represents the amount blocks we will wait between
calculating the median and standard deviation of the median of
historic prices in the last Prune Period.
historic_accept_list:
type: array
items:
type: object
properties:
base_denom:
type: string
symbol_denom:
type: string
exponent:
type: integer
format: int64
title: Denom - the object to hold configurations of each denom
description: >-
Historic Asset List is a list of assets which will use the
historic

price stamping protection methodology (mainly manipulatable
assets).
Maximum Price Stamps represents the maximum amount of historic
prices

Any assets not on this list will not be stamped.
the oracle module will store before pruning via FIFO.
maximum_median_stamps:
type: string
format: uint64
description: |-
Maximum Median Stamps represents the maximum amount of medians the
oracle module will store before pruning via FIFO.
description: QueryParamsResponse is the response type for the Query/Params RPC method.
umee.oracle.v1.QuerySlashWindowResponse:
type: object
Expand Down
37 changes: 37 additions & 0 deletions util/checkers/proposal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package checkers

import (
"errors"
"fmt"
"strings"

sdk "github.com/cosmos/cosmos-sdk/types"
gov1b1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
)

// ValidateProposal checks the format of the title, description, and authority of a gov message.
func ValidateProposal(title, description, authority string) error {
toteki marked this conversation as resolved.
Show resolved Hide resolved
_, err := sdk.AccAddressFromBech32(authority)
if err != nil {
return err
}

if len(strings.TrimSpace(title)) == 0 {
return errors.New("proposal title cannot be blank")
}
if len(title) > gov1b1.MaxTitleLength {
return fmt.Errorf("proposal title is longer than max length of %d", gov1b1.MaxTitleLength)
}

if len(description) == 0 {
return errors.New("proposal description cannot be blank")
}
if len(description) > gov1b1.MaxDescriptionLength {
return fmt.Errorf(
"proposal description is longer than max length of %d",
gov1b1.MaxDescriptionLength,
)
}

return nil
}
44 changes: 44 additions & 0 deletions x/incentive/codec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package incentive

import (
"github.com/cosmos/cosmos-sdk/codec"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
)

var (
amino = codec.NewLegacyAmino()
ModuleCdc = codec.NewAminoCodec(amino)
)

func init() {
RegisterLegacyAminoCodec(amino)
cryptocodec.RegisterCrypto(amino)
amino.Seal()
}

// RegisterLegacyAminoCodec registers the necessary x/leverage interfaces and
// concrete types on the provided LegacyAmino codec. These types are used for
// Amino JSON serialization.
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&MsgClaim{}, "umee/incentive/MsgClaim", nil)
cdc.RegisterConcrete(&MsgBond{}, "umee/incentive/MsgBond", nil)
cdc.RegisterConcrete(&MsgBeginUnbonding{}, "umee/incentive/MsgBeginUnbonding", nil)
cdc.RegisterConcrete(&MsgSponsor{}, "umee/incentive/MsgSponsor", nil)
cdc.RegisterConcrete(&MsgGovCreateProgram{}, "umee/incentive/MsgGovCreateProgram", nil)
}

func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
registry.RegisterImplementations(
(*sdk.Msg)(nil),
&MsgClaim{},
&MsgBond{},
&MsgBeginUnbonding{},
&MsgSponsor{},
&MsgGovCreateProgram{},
)

msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
}
26 changes: 26 additions & 0 deletions x/incentive/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package incentive

// DONTCOVER

import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

var (
// 0 = TODO
ErrNotImplemented = sdkerrors.Register(ModuleName, 0, "not implemented")

// 1XX = General
ErrInvalidProgramID = sdkerrors.Register(ModuleName, 100, "invalid program ID")
ErrNilAsset = sdkerrors.Register(ModuleName, 101, "nil asset")
ErrInvalidTier = sdkerrors.Register(ModuleName, 102, "invalid unbonding tier")
ErrEmptyAddress = sdkerrors.Register(ModuleName, 103, "empty address")

// 2XX = Params
ErrUnbondingTierOrder = sdkerrors.Register(ModuleName, 200, "unbonding tier lock durations out of order")
ErrUnbondingWeightOrder = sdkerrors.Register(ModuleName, 201, "unbonding tier weights out of order")

// 3XX = Gov Proposal
ErrNonzeroRemainingRewards = sdkerrors.Register(ModuleName, 300, "remaining rewards must be zero in proposal")
ErrNonzeroFundedRewards = sdkerrors.Register(ModuleName, 301, "funded rewards must be zero in proposal")
)
Loading