Skip to content

Commit

Permalink
remove cpps and cdts
Browse files Browse the repository at this point in the history
  • Loading branch information
rbajollari committed Oct 18, 2023
1 parent abaea63 commit debd18c
Show file tree
Hide file tree
Showing 9 changed files with 1,779 additions and 86 deletions.
66 changes: 66 additions & 0 deletions proto/ojo/oracle/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ service Msg {
rpc GovAddDenoms(MsgGovAddDenoms)
returns (MsgGovAddDenomsResponse);

// GovRemoveCurrencyPairProviders updates the oracle parameters to remove a list of
// currency pair providers.
rpc GovRemoveCurrencyPairProviders(MsgGovRemoveCurrencyPairProviders)
returns (MsgGovRemoveCurrencyPairProvidersResponse);

// GovRemoveCurrencyDeviationThresholds updates the oracle parameters to remove a list
// of currency deviation thresholds.
rpc GovRemoveCurrencyDeviationThresholds(MsgGovRemoveCurrencyDeviationThresholds)
returns (MsgGovRemoveCurrencyDeviationThresholdsResponse);

// GovCancelUpdateParams cancels a plan to update the oracle parameters.
rpc GovCancelUpdateParams(MsgGovCancelUpdateParams)
returns (MsgGovCancelUpdateParamsResponse);
Expand Down Expand Up @@ -168,6 +178,62 @@ message MsgGovAddDenoms {
// MsgGovAddDenomResponse defines the Msg/GovAddDenomResponse response type.
message MsgGovAddDenomsResponse {}

// MsgGovRemoveCurrencyPairProviders defines the Msg/GovRemoveCurrencyPairProviders request type.
message MsgGovRemoveCurrencyPairProviders {
option (gogoproto.equal) = true;
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;
option (cosmos.msg.v1.signer) = "authority";

// authority is the address of the governance account.
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// title of the proposal
string title = 2;

// description of the proposal
string description = 3;

// height at which the param update must be performed
int64 height = 4;

// currency_pair_providers to remove from the current CurrencyPairProvidersList
repeated CurrencyPairProviders currency_pair_providers = 5 [
(gogoproto.moretags) = "yaml:\"currency_pair_providers\"",
(gogoproto.castrepeated) = "CurrencyPairProvidersList",
(gogoproto.nullable) = false
];
}

// MsgGovRemoveCurrencyPairProvidersResponse defines the Msg/GovRemoveCurrencyPairProvidersResponse response type.
message MsgGovRemoveCurrencyPairProvidersResponse {}

// MsgGovRemoveCurrencyDeviationThresholds defines the Msg/GovRemoveCurrencyDeviationThresholds request type.
message MsgGovRemoveCurrencyDeviationThresholds {
option (gogoproto.equal) = true;
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;
option (cosmos.msg.v1.signer) = "authority";

// authority is the address of the governance account.
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// title of the proposal
string title = 2;

// description of the proposal
string description = 3;

// height at which the param update must be performed
int64 height = 4;

// currencies to remove from the current CurrencyDeviationThresholdsList
repeated string currencies = 5;
}

// MsgGovRemoveCurrencyDeviationThresholdsResponse defines the Msg/GovRemoveCurrencyDeviationThresholdsResponse response type.
message MsgGovRemoveCurrencyDeviationThresholdsResponse {}

// MsgGovCancelUpdateParams defines the Msg/GovCancelUpdateParams request type.
message MsgGovCancelUpdateParams {
option (gogoproto.equal) = true;
Expand Down
87 changes: 87 additions & 0 deletions x/oracle/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"context"
"strings"

"cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -259,6 +260,92 @@ func (ms msgServer) GovAddDenoms(
return &types.MsgGovAddDenomsResponse{}, nil
}

// GovRemoveCurrencyPairProviders removes the specified currency pair
// providers in MsgGovRemoveCurrencyPairProviders if they exist in
// the current CurrencyPairProviders list.
func (ms msgServer) GovRemoveCurrencyPairProviders(
goCtx context.Context,
msg *types.MsgGovRemoveCurrencyPairProviders,
) (*types.MsgGovRemoveCurrencyPairProvidersResponse, error) {
if msg.Authority != ms.authority {
err := errors.Wrapf(
types.ErrNoGovAuthority,
"invalid authority; expected %s, got %s",
ms.authority,
msg.Authority,
)
return nil, err
}
ctx := sdk.UnwrapSDKContext(goCtx)
params := ms.GetParams(ctx)

plan := types.ParamUpdatePlan{
Keys: []string{string(types.KeyCurrencyPairProviders)},
Height: msg.Height,
Changes: params,
}

for _, cpp := range msg.CurrencyPairProviders {
plan.Changes.CurrencyPairProviders = plan.Changes.CurrencyPairProviders.RemovePair(cpp)
}

// validate plan construction before scheduling
err := plan.ValidateBasic()
if err != nil {
return nil, err
}

err = ms.ScheduleParamUpdatePlan(ctx, plan)
if err != nil {
return nil, err
}

return &types.MsgGovRemoveCurrencyPairProvidersResponse{}, nil
}

// GovRemoveCurrencyDeviationThresholds removes the specified currency
// deviation thresholds in MsgGovRemoveCurrencyDeviationThresholdsResponse
// if they exist in the current CurrencyDeviationThresholds list.
func (ms msgServer) GovRemoveCurrencyDeviationThresholds(
goCtx context.Context,
msg *types.MsgGovRemoveCurrencyDeviationThresholds,
) (*types.MsgGovRemoveCurrencyDeviationThresholdsResponse, error) {
if msg.Authority != ms.authority {
err := errors.Wrapf(
types.ErrNoGovAuthority,
"invalid authority; expected %s, got %s",
ms.authority,
msg.Authority,
)
return nil, err
}
ctx := sdk.UnwrapSDKContext(goCtx)
params := ms.GetParams(ctx)

plan := types.ParamUpdatePlan{
Keys: []string{string(types.KeyCurrencyDeviationThresholds)},
Height: msg.Height,
Changes: params,
}

for _, curr := range msg.Currencies {
plan.Changes.CurrencyDeviationThresholds = plan.Changes.CurrencyDeviationThresholds.RemovePair(strings.ToUpper(curr))
}

// validate plan construction before scheduling
err := plan.ValidateBasic()
if err != nil {
return nil, err
}

err = ms.ScheduleParamUpdatePlan(ctx, plan)
if err != nil {
return nil, err
}

return &types.MsgGovRemoveCurrencyDeviationThresholdsResponse{}, nil
}

func (ms msgServer) GovCancelUpdateParams(
goCtx context.Context,
msg *types.MsgGovCancelUpdateParams,
Expand Down
Loading

0 comments on commit debd18c

Please sign in to comment.