Skip to content

Commit

Permalink
refactor: update x/foundation params (#704)
Browse files Browse the repository at this point in the history
* Update params proto

* Update params related logics

* Remove unused logics

* Add OutsourcingDecisionPolicy into proto

* Implement OutsourcingDecisionPolicy

* Use more specific method of require

* Increase coverage

* Revisit genesis proto

* Revisit genesis logic

* Use MustAccAddressFromBech32()

* Lint

* Update CHANGELOG.md

* Make sure operator is a module account

* Stop providing generated members

* Stop providing CreateValidatorAuthorizations

* Add more validations on proposals in x/foundation genesis

* Revisit validation of FoundationInfo

* Increase coverage

* Apply suggestions from code review

* Revert "Apply suggestions from code review"

This reverts commit ded8679.

* Update unit test on UpdateFoundationParamsProposal

* Apply feedback

Add "is" in front of the variable `outsourcing`.

* Increase coverage

* Use snake_case
  • Loading branch information
0Tech committed Oct 18, 2022
1 parent 502bfd7 commit 15168bf
Show file tree
Hide file tree
Showing 54 changed files with 1,823 additions and 1,509 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (cli) [\#708](https://github.com/line/lbm-sdk/pull/708) In CLI, allow 1 SIGN_MODE_DIRECT signer in transactions with multiple signers.
* (x/modules) [\#722](https://github.com/line/lbm-sdk/pull/722) Check error for `RegisterQueryHandlerClient` in all modules `RegisterGRPCGatewayRoutes`
* (x/bank) [\#716](https://github.com/line/lbm-sdk/pull/716) remove useless DenomMetadata key function

* (x/foundation) [\#704](https://github.com/line/lbm-sdk/pull/704) update x/foundation params

### Bug Fixes
* (x/wasm) [\#453](https://github.com/line/lbm-sdk/pull/453) modify wasm grpc query api path
Expand Down
2 changes: 1 addition & 1 deletion baseapp/block_gas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func TestBaseApp_BlockGas(t *testing.T) {
txBuilder.SetFeeAmount(feeAmount)
txBuilder.SetGasLimit(txtypes.MaxGasWanted) // tx validation checks that gasLimit can't be bigger than this

privs, accNums, accSeqs := []cryptotypes.PrivKey{priv1}, []uint64{8}, []uint64{0}
privs, accNums, accSeqs := []cryptotypes.PrivKey{priv1}, []uint64{7}, []uint64{0}
_, txBytes, err := createTestTx(encCfg.TxConfig, txBuilder, privs, accNums, accSeqs, ctx.ChainID())
require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion client/docs/statik/statik.go

Large diffs are not rendered by default.

21 changes: 12 additions & 9 deletions client/docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35088,11 +35088,12 @@ paths:
params:
type: object
properties:
enabled:
type: boolean
format: boolean
foundation_tax:
type: string
censored_msg_type_urls:
type: array
items:
type: string
description: Params defines the parameters for the foundation module.
description: >-
QueryParamsResponse is the response type for the Query/Params RPC
Expand Down Expand Up @@ -68794,11 +68795,12 @@ definitions:
lbm.foundation.v1.Params:
type: object
properties:
enabled:
type: boolean
format: boolean
foundation_tax:
type: string
censored_msg_type_urls:
type: array
items:
type: string
description: Params defines the parameters for the foundation module.
lbm.foundation.v1.Proposal:
type: object
Expand Down Expand Up @@ -69462,11 +69464,12 @@ definitions:
params:
type: object
properties:
enabled:
type: boolean
format: boolean
foundation_tax:
type: string
censored_msg_type_urls:
type: array
items:
type: string
description: Params defines the parameters for the foundation module.
description: QueryParamsResponse is the response type for the Query/Params RPC method.
lbm.foundation.v1.QueryProposalResponse:
Expand Down
23 changes: 21 additions & 2 deletions docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,7 @@
- [FoundationInfo](#lbm.foundation.v1.FoundationInfo)
- [Member](#lbm.foundation.v1.Member)
- [MemberRequest](#lbm.foundation.v1.MemberRequest)
- [OutsourcingDecisionPolicy](#lbm.foundation.v1.OutsourcingDecisionPolicy)
- [Params](#lbm.foundation.v1.Params)
- [PercentageDecisionPolicy](#lbm.foundation.v1.PercentageDecisionPolicy)
- [Pool](#lbm.foundation.v1.Pool)
Expand Down Expand Up @@ -16851,6 +16852,22 @@ since this field cannot be set as part of requests.



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

### OutsourcingDecisionPolicy
OutsourcingDecisionPolicy is a dummy decision policy which is set after
the operator has been updated into x/group's group policy.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `description` | [string](#string) | | |






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

### Params
Expand All @@ -16859,8 +16876,8 @@ Params defines the parameters for the foundation module.

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `enabled` | [bool](#bool) | | |
| `foundation_tax` | [string](#string) | | |
| `censored_msg_type_urls` | [string](#string) | repeated | |



Expand Down Expand Up @@ -16979,7 +16996,9 @@ UpdateFoundationParamsProposal details a proposal to update params of foundation
| ----- | ---- | ----- | ----------- |
| `title` | [string](#string) | | |
| `description` | [string](#string) | | |
| `params` | [Params](#lbm.foundation.v1.Params) | | |
| `params` | [Params](#lbm.foundation.v1.Params) | | params defines the x/foundation parameters to update.

Note: All parameters must be supplied. |



Expand Down
2 changes: 1 addition & 1 deletion proto/lbm/foundation/v1/event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import "lbm/foundation/v1/foundation.proto";

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

// EventFundTreasury is an event emitted when one funds the treasury.
Expand Down
18 changes: 15 additions & 3 deletions proto/lbm/foundation/v1/foundation.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import "cosmos_proto/cosmos.proto";

// Params defines the parameters for the foundation module.
message Params {
bool enabled = 1;
string foundation_tax = 2
string foundation_tax = 1
[(gogoproto.customtype) = "github.com/line/lbm-sdk/types.Dec", (gogoproto.nullable) = false];
repeated string censored_msg_type_urls = 2;
}

// UpdateFoundationParamsProposal details a proposal to update params of foundation module.
Expand All @@ -26,7 +26,11 @@ message UpdateFoundationParamsProposal {

string title = 1;
string description = 2;
Params params = 3;

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

// Member represents a foundation member with an account address and metadata.
Expand Down Expand Up @@ -107,6 +111,14 @@ message DecisionPolicyWindows {
google.protobuf.Duration min_execution_period = 2 [(gogoproto.stdduration) = true, (gogoproto.nullable) = false];
}

// OutsourcingDecisionPolicy is a dummy decision policy which is set after
// the operator has been updated into x/group's group policy.
message OutsourcingDecisionPolicy {
option (cosmos_proto.implements_interface) = "DecisionPolicy";

string description = 1;
}

// VoteOption enumerates the valid vote options for a given proposal.
enum VoteOption {
option (gogoproto.goproto_enum_prefix) = false;
Expand Down
4 changes: 2 additions & 2 deletions proto/lbm/foundation/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ message GenesisState {
option (gogoproto.goproto_getters) = false;

// params defines the module parameters at genesis.
Params params = 1;
Params params = 1 [(gogoproto.nullable) = false];

// foundation is the foundation info.
FoundationInfo foundation = 2;
FoundationInfo foundation = 2 [(gogoproto.nullable) = false];

// members is the list of the foundation members.
repeated Member members = 3 [(gogoproto.nullable) = false];
Expand Down
2 changes: 1 addition & 1 deletion proto/lbm/foundation/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ message QueryParamsRequest {}

// QueryParamsResponse is the response type for the Query/Params RPC method.
message QueryParamsResponse {
Params params = 1;
Params params = 1 [(gogoproto.nullable) = false];
}

// QueryTreasuryRequest is the request type for the
Expand Down
6 changes: 3 additions & 3 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ var (
authtypes.FeeCollectorName: nil,
distrtypes.ModuleName: nil,
foundation.TreasuryName: nil,
foundation.AdministratorName: nil,
foundation.DefaultOperatorName: nil,
foundation.GovMinterName: {authtypes.Minter},
minttypes.ModuleName: {authtypes.Minter},
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
Expand Down Expand Up @@ -378,7 +378,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, stakingKeeper, authtypes.FeeCollectorName, foundationConfig)
app.FoundationKeeper = foundationkeeper.NewKeeper(appCodec, keys[foundation.StoreKey], app.BaseApp.MsgServiceRouter(), app.AccountKeeper, app.BankKeeper, authtypes.FeeCollectorName, foundationConfig)

classKeeper := classkeeper.NewKeeper(appCodec, keys[class.StoreKey])
app.TokenKeeper = tokenkeeper.NewKeeper(appCodec, keys[token.StoreKey], app.AccountKeeper, classKeeper)
Expand Down Expand Up @@ -521,7 +521,7 @@ func NewSimApp(
capability.NewAppModule(appCodec, *app.CapabilityKeeper),
crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants),
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
foundationmodule.NewAppModule(appCodec, app.FoundationKeeper, app.StakingKeeper),
foundationmodule.NewAppModule(appCodec, app.FoundationKeeper),
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper),
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper),
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
Expand Down
2 changes: 1 addition & 1 deletion x/auth/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ func (suite *AnteTestSuite) TestAnteHandlerFees() {
{
"signer as enough funds, should pass",
func() {
accNums = []uint64{8}
accNums = []uint64{7}
modAcc := suite.app.AccountKeeper.GetModuleAccount(suite.ctx, types.FeeCollectorName)

suite.Require().True(suite.app.BankKeeper.GetAllBalances(suite.ctx, modAcc.GetAddress()).Empty())
Expand Down
44 changes: 26 additions & 18 deletions x/foundation/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"strconv"
"strings"

"github.com/spf13/cobra"

Expand All @@ -13,21 +12,26 @@ import (
"github.com/line/lbm-sdk/client/tx"
"github.com/line/lbm-sdk/codec"
sdk "github.com/line/lbm-sdk/types"
"github.com/line/lbm-sdk/version"
"github.com/line/lbm-sdk/x/foundation"
"github.com/line/lbm-sdk/x/gov/client/cli"
govtypes "github.com/line/lbm-sdk/x/gov/types"
)

// Proposal flags
const (
FlagAllowedValidatorAdd = "add"
FlagAllowedValidatorDelete = "delete"

FlagExec = "exec"
ExecTry = "try"
)

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 @@ -146,19 +150,21 @@ func NewTxCmd() *cobra.Command {
// NewProposalCmdUpdateFoundationParams implements the command to submit an update-foundation-params proposal
func NewProposalCmdUpdateFoundationParams() *cobra.Command {
cmd := &cobra.Command{
Use: "update-foundation-params",
Args: cobra.NoArgs,
Use: "update-foundation-params [params-json]",
Args: cobra.ExactArgs(1),
Short: "Submit an update foundation params proposal",
Long: strings.TrimSpace(
fmt.Sprintf(`Submit an update foundation params proposal.
For now, you have no other options, so we make the corresponding params json file for you.
Long: `Submit an update foundation params proposal.
Example:
$ %s tx gov submit-proposal update-foundation-params [flags]
Example of the content of params-json:
{
"foundation_tax": "0.1",
"censored_msg_type_urls": [
"/cosmos.staking.v1beta1.MsgCreateValidator",
"/lbm.foundation.v1.MsgWithdrawFromTreasury"
]
}
`,
version.AppName,
),
),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
Expand Down Expand Up @@ -186,10 +192,12 @@ $ %s tx gov submit-proposal update-foundation-params [flags]
return err
}

params := &foundation.Params{
Enabled: false,
params, err := parseParams(clientCtx.Codec, args[0])
if err != nil {
return err
}
content := foundation.NewUpdateFoundationParamsProposal(title, description, params)

content := foundation.NewUpdateFoundationParamsProposal(title, description, *params)
msg, err := govtypes.NewMsgSubmitProposal(content, deposit, from)
if err != nil {
return err
Expand Down
8 changes: 6 additions & 2 deletions x/foundation/client/testutil/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

sdk "github.com/line/lbm-sdk/types"
"github.com/line/lbm-sdk/x/foundation"
stakingtypes "github.com/line/lbm-sdk/x/staking/types"
)

func (s *IntegrationTestSuite) TestGRPCParams() {
Expand All @@ -27,9 +28,12 @@ func (s *IntegrationTestSuite) TestGRPCParams() {
false,
&foundation.QueryParamsResponse{},
&foundation.QueryParamsResponse{
Params: &foundation.Params{
Enabled: true,
Params: foundation.Params{
FoundationTax: sdk.MustNewDecFromStr("0.2"),
CensoredMsgTypeUrls: []string{
sdk.MsgTypeURL((*stakingtypes.MsgCreateValidator)(nil)),
sdk.MsgTypeURL((*foundation.MsgWithdrawFromTreasury)(nil)),
},
},
},
},
Expand Down
Loading

0 comments on commit 15168bf

Please sign in to comment.