Skip to content

Commit

Permalink
feat!: migrate x/foundation FoundationTax into x/params (Finschia#999)
Browse files Browse the repository at this point in the history
* Remove relevant messages from proto

* Remove relevant logics from x/foundation

* Use x/param

* Add migration logic

* Update docs

* Update CHANGELOG.md

* Update x/foundation/foundation.go

Co-authored-by: zemyblue <[email protected]>

* Revert lint on protos

---------

Co-authored-by: zemyblue <[email protected]>
  • Loading branch information
0Tech and zemyblue authored May 17, 2023
1 parent 4f96389 commit e9fe906
Show file tree
Hide file tree
Showing 33 changed files with 383 additions and 1,170 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Removed

### Breaking Changes
* (x/foundation) [\#999](https://github.com/Finschia/finschia-sdk/pull/999) migrate x/foundation FoundationTax into x/params

### Build, CI

Expand Down
47 changes: 0 additions & 47 deletions docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,6 @@
- [EventUpdateCensorship](#lbm.foundation.v1.EventUpdateCensorship)
- [EventUpdateDecisionPolicy](#lbm.foundation.v1.EventUpdateDecisionPolicy)
- [EventUpdateMembers](#lbm.foundation.v1.EventUpdateMembers)
- [EventUpdateParams](#lbm.foundation.v1.EventUpdateParams)
- [EventVote](#lbm.foundation.v1.EventVote)
- [EventWithdrawFromTreasury](#lbm.foundation.v1.EventWithdrawFromTreasury)
- [EventWithdrawProposal](#lbm.foundation.v1.EventWithdrawProposal)
Expand Down Expand Up @@ -846,8 +845,6 @@
- [MsgUpdateDecisionPolicyResponse](#lbm.foundation.v1.MsgUpdateDecisionPolicyResponse)
- [MsgUpdateMembers](#lbm.foundation.v1.MsgUpdateMembers)
- [MsgUpdateMembersResponse](#lbm.foundation.v1.MsgUpdateMembersResponse)
- [MsgUpdateParams](#lbm.foundation.v1.MsgUpdateParams)
- [MsgUpdateParamsResponse](#lbm.foundation.v1.MsgUpdateParamsResponse)
- [MsgVote](#lbm.foundation.v1.MsgVote)
- [MsgVoteResponse](#lbm.foundation.v1.MsgVoteResponse)
- [MsgWithdrawFromTreasury](#lbm.foundation.v1.MsgWithdrawFromTreasury)
Expand Down Expand Up @@ -11827,21 +11824,6 @@ EventUpdateMembers is an event emitted when the members have been updated.



<a name="lbm.foundation.v1.EventUpdateParams"></a>

### EventUpdateParams
EventUpdateParams is emitted after updating foundation parameters.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `params` | [Params](#lbm.foundation.v1.Params) | | |






<a name="lbm.foundation.v1.EventVote"></a>

### EventVote
Expand Down Expand Up @@ -12595,34 +12577,6 @@ MsgUpdateMembersResponse is the Msg/UpdateMembers response type.



<a name="lbm.foundation.v1.MsgUpdateParams"></a>

### MsgUpdateParams
MsgUpdateParams is the Msg/UpdateParams request type.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `authority` | [string](#string) | | authority is the address of the privileged account. |
| `params` | [Params](#lbm.foundation.v1.Params) | | params defines the x/foundation parameters to update.

NOTE: All parameters must be supplied. |






<a name="lbm.foundation.v1.MsgUpdateParamsResponse"></a>

### MsgUpdateParamsResponse
MsgUpdateParamsResponse is the Msg/UpdateParams response type.






<a name="lbm.foundation.v1.MsgVote"></a>

### MsgVote
Expand Down Expand Up @@ -12730,7 +12684,6 @@ Msg defines the foundation Msg service.

| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint |
| ----------- | ------------ | ------------- | ------------| ------- | -------- |
| `UpdateParams` | [MsgUpdateParams](#lbm.foundation.v1.MsgUpdateParams) | [MsgUpdateParamsResponse](#lbm.foundation.v1.MsgUpdateParamsResponse) | UpdateParams defines an operation for updating the x/foundation module parameters. | |
| `FundTreasury` | [MsgFundTreasury](#lbm.foundation.v1.MsgFundTreasury) | [MsgFundTreasuryResponse](#lbm.foundation.v1.MsgFundTreasuryResponse) | FundTreasury defines a method to fund the treasury. | |
| `WithdrawFromTreasury` | [MsgWithdrawFromTreasury](#lbm.foundation.v1.MsgWithdrawFromTreasury) | [MsgWithdrawFromTreasuryResponse](#lbm.foundation.v1.MsgWithdrawFromTreasuryResponse) | WithdrawFromTreasury defines a method to withdraw coins from the treasury. | |
| `UpdateMembers` | [MsgUpdateMembers](#lbm.foundation.v1.MsgUpdateMembers) | [MsgUpdateMembersResponse](#lbm.foundation.v1.MsgUpdateMembersResponse) | UpdateMembers updates the foundation members. | |
Expand Down
5 changes: 0 additions & 5 deletions proto/lbm/foundation/v1/event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ import "cosmos_proto/cosmos.proto";
import "cosmos/base/v1beta1/coin.proto";
import "lbm/foundation/v1/foundation.proto";

// EventUpdateParams is emitted after updating foundation parameters.
message EventUpdateParams {
Params params = 1 [(gogoproto.nullable) = false];
}

// EventFundTreasury is an event emitted when one funds the treasury.
message EventFundTreasury {
string from = 1;
Expand Down
18 changes: 0 additions & 18 deletions proto/lbm/foundation/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ option (gogoproto.goproto_getters_all) = false;

// Msg defines the foundation Msg service.
service Msg {
// UpdateParams defines an operation for updating the x/foundation module
// parameters.
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);

// FundTreasury defines a method to fund the treasury.
rpc FundTreasury(MsgFundTreasury) returns (MsgFundTreasuryResponse);

Expand Down Expand Up @@ -59,20 +55,6 @@ service Msg {
rpc Revoke(MsgRevoke) returns (MsgRevokeResponse);
}

// MsgUpdateParams is the Msg/UpdateParams request type.
message MsgUpdateParams {
// authority is the address of the privileged account.
string authority = 1;

// params defines the x/foundation parameters to update.
//
// NOTE: All parameters must be supplied.
Params params = 2 [(gogoproto.nullable) = false];
}

// MsgUpdateParamsResponse is the Msg/UpdateParams response type.
message MsgUpdateParamsResponse {}

// MsgFundTreasury is the Msg/FundTreasury request type.
message MsgFundTreasury {
string from = 1;
Expand Down
3 changes: 2 additions & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ func NewSimApp(
app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath, app.BaseApp)

foundationConfig := foundation.DefaultConfig()
app.FoundationKeeper = foundationkeeper.NewKeeper(appCodec, keys[foundation.StoreKey], app.BaseApp.MsgServiceRouter(), app.AccountKeeper, app.BankKeeper, authtypes.FeeCollectorName, foundationConfig, foundation.DefaultAuthority().String())
app.FoundationKeeper = foundationkeeper.NewKeeper(appCodec, keys[foundation.StoreKey], app.BaseApp.MsgServiceRouter(), app.AccountKeeper, app.BankKeeper, authtypes.FeeCollectorName, foundationConfig, foundation.DefaultAuthority().String(), app.GetSubspace(foundation.ModuleName))

app.ClassKeeper = classkeeper.NewKeeper(appCodec, keys[class.StoreKey])
app.TokenKeeper = tokenkeeper.NewKeeper(appCodec, keys[token.StoreKey], app.ClassKeeper)
Expand Down Expand Up @@ -712,6 +712,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(slashingtypes.ModuleName)
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypes.ParamKeyTable())
paramsKeeper.Subspace(crisistypes.ModuleName)
paramsKeeper.Subspace(foundation.ModuleName)

return paramsKeeper
}
56 changes: 6 additions & 50 deletions x/foundation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ back these foundation-specific functionalities.
## Contents

* [Concepts](#concepts)
* [Parameters](#parameters)
* [State](#state)
* [Msg Service](#msg-service)
* [Msg/UpdateParams](#msgupdateparams)
* [Msg/UpdateDecisionPolicy](#msgupdatedecisionpolicy)
* [Msg/UpdateMembers](#msgupdatemembers)
* [Msg/LeaveFoundation](#msgleavefoundation)
Expand All @@ -33,7 +33,6 @@ back these foundation-specific functionalities.
* [Msg/FundTreasury](#msgfundtreasury)
* [Msg/WithdrawFromTreasury](#msgwithdrawfromtreasury)
* [Events](#events)
* [EventUpdateFoundationParams](#eventupdatefoundationparams)
* [EventUpdateDecisionPolicy](#eventupdatedecisionpolicy)
* [EventUpdateMembers](#eventupdatedmembers)
* [EventLeaveFoundation](#eventleavefoundation)
Expand Down Expand Up @@ -269,19 +268,15 @@ The foundation can withdraw coins from the treasury. The recipient must have
the corresponding authorization (`ReceiveFromTreasuryAuthorization`) prior to
sending the message `Msg/WithdrawFromTreasury`.

**Note:** After setting the tax rate to zero, you cannot set it to a non-zero
value again (irreversible), which means you must set it to a non-zero value in
the genesis to make it work.
# Parameters

# State

## Params
## FoundationTax

* Params: `0x00 -> PropocolBuffer(Params)`.
The value of `FoundationTax` is the foundation tax rate.

### FoundationTax
* FoundationTax: `sdk.Dec`

The value of `FoundationTax` is the foundation tax rate.
# State

## FoundationInfo

Expand Down Expand Up @@ -350,17 +345,6 @@ Authorization) tuple.

# Msg Service

## Msg/UpdateParams

The `MsgUpdateParams` can be used to update the parameters of `foundation`.

+++ https://github.com/Finschia/finschia-sdk/blob/f682f758268c19dd93958abbbaf697f51e6991b3/proto/lbm/foundation/v1/tx.proto#L62-L71

It's expected to fail if:

* the authority is not the module's authority.
* the parameters introduces any new foundation-specific features.

## Msg/UpdateDecisionPolicy

The `MsgUpdateDecisionPolicy` can be used to update the decision policy.
Expand Down Expand Up @@ -526,15 +510,6 @@ The message handling should fail if:

# Events

## EventUpdateFoundationParams

`EventUpdateFoundationParams` is an event emitted when the foundation
parameters have been updated.

| Attribute Key | Attribute Value |
|---------------|-----------------|
| params | {params} |

## EventUpdateDecisionPolicy

`EventUpdateDecisionPolicy` is an event emitted when the decision policy have
Expand Down Expand Up @@ -1010,25 +985,6 @@ simd tx foundation --help
you cannot broadcast the message directly. The use of those commands is to make
it easier to generate the messages by end users.

#### update-params

The `update-params` command allows users to update the foundation's parameters.

```bash
simd tx foundation update-params [authority] [params-json] [flags]
```

Example:

```bash
simd tx foundation update-params link1... \
'{
"foundation_tax": "0.1"
}'
```

**Note:** The signer MUST be the module's authority.

#### update-members

The `update-members` command allows users to update the foundation's members.
Expand Down
53 changes: 0 additions & 53 deletions x/foundation/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,6 @@ func validateGenerateOnly(cmd *cobra.Command) error {
return nil
}

func parseParams(codec codec.Codec, paramsJSON string) (*foundation.Params, error) {
var params foundation.Params
if err := codec.UnmarshalJSON([]byte(paramsJSON), &params); err != nil {
return nil, err
}

return &params, nil
}

func parseMemberRequests(codec codec.Codec, membersJSON string) ([]foundation.MemberRequest, error) {
var cliMembers []json.RawMessage
if err := json.Unmarshal([]byte(membersJSON), &cliMembers); err != nil {
Expand Down Expand Up @@ -141,7 +132,6 @@ func NewTxCmd() *cobra.Command {
}

txCmd.AddCommand(
NewTxCmdUpdateParams(),
NewTxCmdFundTreasury(),
NewTxCmdWithdrawFromTreasury(),
NewTxCmdUpdateMembers(),
Expand All @@ -158,49 +148,6 @@ func NewTxCmd() *cobra.Command {
return txCmd
}

func NewTxCmdUpdateParams() *cobra.Command {
cmd := &cobra.Command{
Use: "update-params [authority] [params-json]",
Args: cobra.ExactArgs(2),
Short: "Update params",
Long: `Update x/foundation parameters.
Example of the content of params-json:
{
"foundation_tax": "0.1"
}
`,
RunE: func(cmd *cobra.Command, args []string) error {
if err := validateGenerateOnly(cmd); err != nil {
return err
}

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

params, err := parseParams(clientCtx.Codec, args[1])
if err != nil {
return err
}

msg := foundation.MsgUpdateParams{
Authority: args[0],
Params: *params,
}
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
},
}

flags.AddTxFlagsToCmd(cmd)
return cmd
}

func NewTxCmdFundTreasury() *cobra.Command {
cmd := &cobra.Command{
Use: "fund-treasury [from] [amount]",
Expand Down
46 changes: 0 additions & 46 deletions x/foundation/client/testutil/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,52 +13,6 @@ import (
"github.com/Finschia/finschia-sdk/x/foundation/client/cli"
)

func (s *IntegrationTestSuite) TestNewTxCmdUpdateParams() {
val := s.network.Validators[0]

commonArgs := []string{
fmt.Sprintf("--%s", flags.FlagGenerateOnly),
}

testCases := map[string]struct {
args []string
valid bool
}{
"valid transaction": {
[]string{
s.authority.String(),
fmt.Sprintf(`{"foundation_tax": "%s"}`, sdk.ZeroDec()),
},
true,
},
"wrong number of args": {
[]string{
s.authority.String(),
fmt.Sprintf(`{"foundation_tax": "%s"}`, sdk.ZeroDec()),
"extra",
},
false,
},
}

for name, tc := range testCases {
tc := tc

s.Run(name, func() {
cmd := cli.NewTxCmdUpdateParams()
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...))
if !tc.valid {
s.Require().Error(err)
return
}
s.Require().NoError(err)

var res txtypes.Tx
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res), out)
})
}
}

func (s *IntegrationTestSuite) TestNewTxCmdFundTreasury() {
val := s.network.Validators[0]
commonArgs := []string{
Expand Down
2 changes: 0 additions & 2 deletions x/foundation/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
legacy.RegisterAminoMsg(cdc, &MsgWithdrawProposal{}, "lbm-sdk/MsgWithdrawProposal")

// proposal from foundation operator
legacy.RegisterAminoMsg(cdc, &MsgUpdateParams{}, "lbm-sdk/MsgUpdateParams")
legacy.RegisterAminoMsg(cdc, &MsgWithdrawFromTreasury{}, "lbm-sdk/MsgWithdrawFromTreasury")
legacy.RegisterAminoMsg(cdc, &MsgUpdateMembers{}, "lbm-sdk/MsgUpdateMembers")
legacy.RegisterAminoMsg(cdc, &MsgUpdateDecisionPolicy{}, "lbm-sdk/MsgUpdateDecisionPolicy")
Expand All @@ -41,7 +40,6 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {

func RegisterInterfaces(registry types.InterfaceRegistry) {
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgUpdateParams{},
&MsgFundTreasury{},
&MsgWithdrawFromTreasury{},
&MsgUpdateMembers{},
Expand Down
Loading

0 comments on commit e9fe906

Please sign in to comment.