Skip to content

Commit

Permalink
feat: params upgrade message + new min_funding_multiple param
Browse files Browse the repository at this point in the history
  • Loading branch information
mbreithecker committed Oct 27, 2023
1 parent 07dd3b9 commit 2866707
Show file tree
Hide file tree
Showing 11 changed files with 1,324 additions and 77 deletions.
11 changes: 11 additions & 0 deletions docs/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4518,6 +4518,17 @@ paths:
type: string
format: uint64
description: Minimum amount of tokens that can be funded per bundle.
min_funding_multiple:
type: string
format: uint64
description: >-
Minimum ratio between the funded amount and the
amount_per_bundle.
In other words this param ensures, that a funder provides
at least funding for
`min_funding_multiple` bundles.
description: QueryParamsResponse ...
default:
description: An unexpected error response.
Expand Down
15 changes: 13 additions & 2 deletions proto/kyve/funders/v1beta1/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@ syntax = "proto3";

package kyve.funders.v1beta1;

//import "gogoproto/gogo.proto";
//import "kyve/funders/v1beta1/params.proto";
import "gogoproto/gogo.proto";
import "kyve/funders/v1beta1/params.proto";

option go_package = "github.com/KYVENetwork/chain/x/funders/types";

// EventUpdateParams is an event emitted when the module parameters are updated.
// emitted_by: MsgUpdateParams
message EventUpdateParams {
// old_params is the module's old parameters.
Params old_params = 1 [(gogoproto.nullable) = false];
// new_params is the module's new parameters.
Params new_params = 2 [(gogoproto.nullable) = false];
// payload is the parameter updates that were performed.
string payload = 3;
}

// EventCreateFunder is an event emitted when a funder is created.
// emitted_by: MsgCreateFunder
message EventCreateFunder {
Expand Down
4 changes: 4 additions & 0 deletions proto/kyve/funders/v1beta1/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ message Params {
uint64 min_funding_amount = 1;
// Minimum amount of tokens that can be funded per bundle.
uint64 min_funding_amount_per_bundle = 2;
// Minimum ratio between the funded amount and the amount_per_bundle.
// In other words this param ensures, that a funder provides at least funding for
// `min_funding_multiple` bundles.
uint64 min_funding_multiple = 3;
}
18 changes: 18 additions & 0 deletions proto/kyve/funders/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ syntax = "proto3";

package kyve.funders.v1beta1;

import "cosmos_proto/cosmos.proto";

option go_package = "github.com/KYVENetwork/chain/x/funders/types";

// Msg defines the Msg service.
Expand All @@ -14,6 +16,10 @@ service Msg {
rpc FundPool(MsgFundPool) returns (MsgFundPoolResponse);
// DefundPool ...
rpc DefundPool(MsgDefundPool) returns (MsgDefundPoolResponse);

// UpdateParams defines a governance operation for updating the x/delegation module
// parameters. The authority is hard-coded to the x/gov module account.
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
}

// MsgCreateFunder defines a SDK message for creating a funder.
Expand Down Expand Up @@ -81,3 +87,15 @@ message MsgDefundPool {

// MsgDefundPoolResponse defines the Msg/DefundPool response type.
message MsgDefundPoolResponse {}

// MsgUpdateParams defines a SDK message for updating the module parameters.
message MsgUpdateParams {
// authority is the address of the governance account.
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// payload defines the x/delegation parameters to update.
string payload = 2;
}

// MsgUpdateParamsResponse defines the Msg/UpdateParams response type.
message MsgUpdateParamsResponse {}
35 changes: 35 additions & 0 deletions x/funders/keeper/msg_server_update_params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package keeper

import (
"context"
"encoding/json"

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

// Delegation
"github.com/KYVENetwork/chain/x/funders/types"
// Gov
govTypes "github.com/cosmos/cosmos-sdk/x/gov/types"
)

func (k msgServer) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) {
if k.authority != msg.Authority {
return nil, errors.Wrapf(govTypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.authority, msg.Authority)
}

ctx := sdk.UnwrapSDKContext(goCtx)
oldParams := k.GetParams(ctx)

newParams := oldParams
_ = json.Unmarshal([]byte(msg.Payload), &newParams)
k.SetParams(ctx, newParams)

_ = ctx.EventManager().EmitTypedEvent(&types.EventUpdateParams{
OldParams: oldParams,
NewParams: newParams,
Payload: msg.Payload,
})

return &types.MsgUpdateParamsResponse{}, nil
}
Loading

0 comments on commit 2866707

Please sign in to comment.