Skip to content

Commit

Permalink
(fix) Synced proto definition with latest versions from injective-cor…
Browse files Browse the repository at this point in the history
…e and injective-indexer (v1.13 chain upgrade candidates)
  • Loading branch information
aarmoa committed Jul 17, 2024
1 parent 58aee14 commit fb8a8bf
Show file tree
Hide file tree
Showing 19 changed files with 2,571 additions and 2,441 deletions.
609 changes: 332 additions & 277 deletions chain/exchange/types/exchange.pb.go

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions chain/exchange/types/fee_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ func ValidateMakerWithTakerFee(makerFeeRate, takerFeeRate, relayerFeeShareRate,
return nil
}

// if makerFeeRate is negative, must hold: takerFeeRate * (1 - relayerFeeShareRate) + makerFeeRate > minimalProtocolFeeRate
if takerFeeRate.Mul(math.LegacyOneDec().Sub(relayerFeeShareRate)).Add(makerFeeRate).LT(minimalProtocolFeeRate) {
// if makerFeeRate is negative then takerFeeRate >= (minimalProtocolFeeRate - relayerFeeShareRate)/(1 - makerFeeRate)
numerator := minimalProtocolFeeRate.Sub(relayerFeeShareRate)
denominator := math.LegacyOneDec().Sub(makerFeeRate)
return errors.Wrap(ErrFeeRatesRelation, fmt.Sprintf("if maker_fee_rate is negative (%v), taker_fee_rate must be GTE than %v [ taker_fee_rate >= (minimum_protocol_fee_rate - maker_fee_rate)/(1 - relayer_fee_share_rate) ]", makerFeeRate.String(), numerator.Quo(denominator).String()))
errMsg := fmt.Sprintf("if makerFeeRate (%v) is negative, (takerFeeRate = %v) * (1 - relayerFeeShareRate = %v) + makerFeeRate < %v", makerFeeRate.String(), takerFeeRate.String(), relayerFeeShareRate.String(), minimalProtocolFeeRate.String())
return errors.Wrap(ErrFeeRatesRelation, errMsg)
}

return nil
Expand Down
34 changes: 30 additions & 4 deletions chain/exchange/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ const (
// funding is consistently applied on the hour for all perpetual markets.
DefaultFundingMultipleSeconds int64 = 3600

// SpotMarketInstantListingFee is 1000 INJ
SpotMarketInstantListingFee int64 = 1000
// SpotMarketInstantListingFee is 20 INJ
SpotMarketInstantListingFee int64 = 20

// DerivativeMarketInstantListingFee is 1000 INJ
DerivativeMarketInstantListingFee int64 = 1000
// DerivativeMarketInstantListingFee is 20 INJ
DerivativeMarketInstantListingFee int64 = 20

// BinaryOptionsMarketInstantListingFee is 100 INJ
BinaryOptionsMarketInstantListingFee int64 = 100
Expand Down Expand Up @@ -289,6 +289,9 @@ func (p Params) Validate() error {
if err := validatePostOnlyModeHeightThreshold(p.PostOnlyModeHeightThreshold); err != nil {
return fmt.Errorf("post_only_mode_height_threshold is incorrect: %w", err)
}
if err := validateAdmins(p.ExchangeAdmins); err != nil {
return fmt.Errorf("ExchangeAdmins is incorrect: %w", err)
}
return nil
}

Expand Down Expand Up @@ -524,6 +527,29 @@ func validatePostOnlyModeHeightThreshold(i interface{}) error {
return nil
}

func validateAdmins(i interface{}) error {
v, ok := i.([]string)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

admins := make(map[string]struct{})

for _, admin := range v {
adminAddr, err := sdk.AccAddressFromBech32(admin)
if err != nil {
return fmt.Errorf("invalid admin address: %s", admin)
}

if _, found := admins[adminAddr.String()]; found {
return fmt.Errorf("duplicate admin: %s", admin)
}
admins[adminAddr.String()] = struct{}{}
}

return nil
}

func validateFundingMultiple(i interface{}) error {
v, ok := i.(int64)
if !ok {
Expand Down
582 changes: 243 additions & 339 deletions chain/exchange/types/tx.pb.go

Large diffs are not rendered by default.

32 changes: 28 additions & 4 deletions chain/oracle/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,13 @@ func (msg MsgRelayStorkPrices) ValidateBasic() error {
oldestTimestamp := ^uint64(0) // max uint64
for i := range assetPair.SignedPrices {
p := assetPair.SignedPrices[i]
if p.Timestamp > newestTimestamp {
newestTimestamp = p.Timestamp
// convert timestamp to nanoseconds to validate conditions
timestamp := ConvertTimestampToNanoSecond(p.Timestamp)
if timestamp > newestTimestamp {
newestTimestamp = timestamp
}
if p.Timestamp < oldestTimestamp {
oldestTimestamp = p.Timestamp
if timestamp < oldestTimestamp {
oldestTimestamp = timestamp
}

price := new(big.Int).Quo(p.Price.BigInt(), sdkmath.LegacyOneDec().BigInt()).String()
Expand Down Expand Up @@ -376,3 +378,25 @@ func (msg MsgRelayStorkPrices) GetSigners() []sdk.AccAddress {
}
return []sdk.AccAddress{sender}
}

// ConvertTimestampToNanoSecond converts timestamp to nano seconds
// if timestamp > 1e18 => timestamp is in nanosecond format
// else if timestamp > 1e15 => timestamp is in microsecond format
// else if timestamp > 1e12 => timestamp is in millisecond format
// else the timestamp is in second format
func ConvertTimestampToNanoSecond(timestamp uint64) (nanoSeconds uint64) {
switch {
// nanosecond
case timestamp > 1e18:
return timestamp
// microsecond
case timestamp > 1e15:
return timestamp * 1_000
// millisecond
case timestamp > 1e12:
return timestamp * 1_000_000
// second
default:
return timestamp * 1_000_000_000
}
}
31 changes: 29 additions & 2 deletions chain/peggy/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (

"cosmossdk.io/errors"
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
)

// DefaultParamspace defines the default auth module parameter subspace
// DefaultParamspace defines the default peggy module parameter subspace
const (
// todo: implement oracle constants as params
DefaultParamspace = ModuleName
)

Expand All @@ -33,6 +33,7 @@ func DefaultParams() *Params {
CosmosCoinDenom: "inj",
UnbondSlashingValsetsWindow: 10000,
ClaimSlashingEnabled: false,
Admins: nil,
}
}

Expand Down Expand Up @@ -98,6 +99,9 @@ func (p Params) ValidateBasic() error {
if err := validateClaimSlashingEnabled(p.ClaimSlashingEnabled); err != nil {
return errors.Wrap(err, "claim slashing enabled")
}
if err := validateAdmins(p.Admins); err != nil {
return errors.Wrap(err, "admins")
}

return nil
}
Expand Down Expand Up @@ -293,3 +297,26 @@ func validateSlashFractionBadEthSignature(i interface{}) error {
func validateValsetReward(i interface{}) error {
return nil
}

func validateAdmins(i interface{}) error {
v, ok := i.([]string)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

admins := make(map[string]struct{})

for _, admin := range v {
adminAddr, err := sdk.AccAddressFromBech32(admin)
if err != nil {
return fmt.Errorf("invalid admin address: %s", admin)
}

if _, found := admins[adminAddr.String()]; found {
return fmt.Errorf("duplicate admin: %s", admin)
}
admins[adminAddr.String()] = struct{}{}
}

return nil
}
3 changes: 3 additions & 0 deletions chain/peggy/types/params_legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ var (
// to a relayer when they relay a valset
ParamStoreValsetRewardAmount = []byte("ValsetReward")

ParamStoreAdmins = []byte("Admins")

// Ensure that params implements the proper interface
_ paramtypes.ParamSet = &Params{}
)
Expand Down Expand Up @@ -101,5 +103,6 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
paramtypes.NewParamSetPair(ParamStoreClaimSlashingEnabled, &p.ClaimSlashingEnabled, validateClaimSlashingEnabled),
paramtypes.NewParamSetPair(ParamsStoreKeyBridgeContractStartHeight, &p.BridgeContractStartHeight, validateBridgeContractStartHeight),
paramtypes.NewParamSetPair(ParamStoreValsetRewardAmount, &p.ValsetReward, validateValsetReward),
paramtypes.NewParamSetPair(ParamStoreAdmins, &p.Admins, validateAdmins),
}
}
56 changes: 44 additions & 12 deletions chain/wasmx/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package types
import (
"fmt"

wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)

Expand All @@ -25,10 +27,11 @@ var (

// Parameter keys
var (
KeyIsExecutionEnabled = []byte("IsExecutionEnabled")
KeyMaxBeginBlockTotalGas = []byte("MaxBeginBlockTotalGas")
KeyMaxContractGasLimit = []byte("MaxContractGasLimit")
KeyMinGasPrice = []byte("MinGasPrice")
KeyIsExecutionEnabled = []byte("IsExecutionEnabled")
KeyMaxBeginBlockTotalGas = []byte("MaxBeginBlockTotalGas")
KeyMaxContractGasLimit = []byte("MaxContractGasLimit")
KeyMinGasPrice = []byte("MinGasPrice")
KeyRegisterContractAccess = []byte("RegisterContractAccess")
)

// ParamKeyTable returns the parameter key table.
Expand All @@ -42,12 +45,14 @@ func NewParams(
maxBeginBlockTotalGas uint64,
maxContractGasLimit uint64,
minGasPrice uint64,
registerContractAccess wasmtypes.AccessConfig,
) Params {
return Params{
IsExecutionEnabled: isExecutionEnabled,
MaxBeginBlockTotalGas: maxBeginBlockTotalGas,
MaxContractGasLimit: maxContractGasLimit,
MinGasPrice: minGasPrice,
IsExecutionEnabled: isExecutionEnabled,
MaxBeginBlockTotalGas: maxBeginBlockTotalGas,
MaxContractGasLimit: maxContractGasLimit,
MinGasPrice: minGasPrice,
RegisterContractAccess: registerContractAccess,
}
}

Expand All @@ -58,16 +63,18 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
paramtypes.NewParamSetPair(KeyIsExecutionEnabled, &p.IsExecutionEnabled, validateIsExecutionEnabled),
paramtypes.NewParamSetPair(KeyMaxBeginBlockTotalGas, &p.MaxBeginBlockTotalGas, validateMaxBeginBlockTotalGas),
paramtypes.NewParamSetPair(KeyMaxContractGasLimit, &p.MaxContractGasLimit, validateMaxContractGasLimit),
paramtypes.NewParamSetPair(KeyRegisterContractAccess, &p.RegisterContractAccess, validateAccessConfig),
}
}

// DefaultParams returns a default set of parameters.
func DefaultParams() Params {
return Params{
IsExecutionEnabled: DefaultIsExecutionEnabled,
MaxBeginBlockTotalGas: DefaultMaxBeginBlockTotalGas,
MaxContractGasLimit: DefaultMaxContractGasLimit,
MinGasPrice: DefaultMinGasPrice,
IsExecutionEnabled: DefaultIsExecutionEnabled,
MaxBeginBlockTotalGas: DefaultMaxBeginBlockTotalGas,
MaxContractGasLimit: DefaultMaxContractGasLimit,
MinGasPrice: DefaultMinGasPrice,
RegisterContractAccess: wasmtypes.AccessConfig{},
}
}

Expand All @@ -89,6 +96,9 @@ func (p Params) Validate() error {
return err
}

if err := validateAccessConfig(p.RegisterContractAccess); err != nil {
return err
}
return nil
}

Expand Down Expand Up @@ -137,3 +147,25 @@ func validateMinGasPrice(i interface{}) error {
}
return nil
}

func validateAccessConfig(i interface{}) error {
v, ok := i.(wasmtypes.AccessConfig)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

uploaders := make(map[string]struct{})

for _, addr := range v.Addresses {
address, err := sdk.AccAddressFromBech32(addr)
if err != nil {
return fmt.Errorf("invalid address: %s", addr)
}

if _, found := uploaders[address.String()]; found {
return fmt.Errorf("duplicate address: %s", addr)
}
uploaders[address.String()] = struct{}{}
}
return nil
}
7 changes: 2 additions & 5 deletions chain/wasmx/types/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ import (
)

func IsAllowed(accessConfig types.AccessConfig, actor types2.AccAddress) bool {
switch accessConfig.Permission {
case types.AccessTypeAnyOfAddresses:
if accessConfig.Permission == types.AccessTypeAnyOfAddresses {
for _, v := range accessConfig.Addresses {
if v == actor.String() {
return true
}
}
return false
default:
return false
}
return false
}
31 changes: 27 additions & 4 deletions client/chain/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ package chain
import (
"os"

"cosmossdk.io/x/tx/signing"
"github.com/cosmos/cosmos-sdk/codec/address"
"github.com/cosmos/gogoproto/proto"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
Expand Down Expand Up @@ -49,9 +53,28 @@ import (
ibctenderminttypes "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"
)

// NewInterfaceRegistry returns a new InterfaceRegistry
func NewInterfaceRegistry() types.InterfaceRegistry {
registry, err := types.NewInterfaceRegistryWithOptions(types.InterfaceRegistryOptions{
ProtoFiles: proto.HybridResolver,
SigningOptions: signing.Options{
AddressCodec: address.Bech32Codec{
Bech32Prefix: cosmostypes.GetConfig().GetBech32AccountAddrPrefix(),
},
ValidatorAddressCodec: address.Bech32Codec{
Bech32Prefix: cosmostypes.GetConfig().GetBech32ValidatorAddrPrefix(),
},
},
})
if err != nil {
panic(err)
}
return registry
}

// NewTxConfig initializes new Cosmos TxConfig with certain signModes enabled.
func NewTxConfig(signModes []signingtypes.SignMode) client.TxConfig {
interfaceRegistry := types.NewInterfaceRegistry()
interfaceRegistry := NewInterfaceRegistry()
keyscodec.RegisterInterfaces(interfaceRegistry)
std.RegisterInterfaces(interfaceRegistry)
exchange.RegisterInterfaces(interfaceRegistry)
Expand Down Expand Up @@ -98,7 +121,7 @@ func NewClientContext(
) (client.Context, error) {
clientCtx := client.Context{}

interfaceRegistry := types.NewInterfaceRegistry()
interfaceRegistry := NewInterfaceRegistry()
keyscodec.RegisterInterfaces(interfaceRegistry)
std.RegisterInterfaces(interfaceRegistry)
exchange.RegisterInterfaces(interfaceRegistry)
Expand Down Expand Up @@ -205,12 +228,12 @@ func newContext(
}

if keyInfo.PubKey != nil {
address, err := keyInfo.GetAddress()
keyInfoAddress, err := keyInfo.GetAddress()
if err != nil {
panic(err)
}
clientCtx = clientCtx.WithKeyring(kb)
clientCtx = clientCtx.WithFromAddress(address)
clientCtx = clientCtx.WithFromAddress(keyInfoAddress)
clientCtx = clientCtx.WithFromName(keyInfo.Name)
clientCtx = clientCtx.WithFrom(keyInfo.Name)
}
Expand Down
3 changes: 1 addition & 2 deletions client/chain/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"path/filepath"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
cosmcrypto "github.com/cosmos/cosmos-sdk/crypto"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
Expand Down Expand Up @@ -190,7 +189,7 @@ func (r *passReader) Read(p []byte) (n int, err error) {
}

func getCryptoCodec() *codec.ProtoCodec {
registry := types.NewInterfaceRegistry()
registry := NewInterfaceRegistry()
crypto_cdc.RegisterInterfaces(registry)
return codec.NewProtoCodec(registry)
}
Expand Down
Loading

0 comments on commit fb8a8bf

Please sign in to comment.