Skip to content

Commit

Permalink
[Tokenomics] feat: add mint_allocation_source_owner param to tokeno…
Browse files Browse the repository at this point in the history
…mics module (#915)

## Summary

Add `mint_allocation_supplier` param to the tokenomics module.

## Issue

- `TODO_BETA`

## Type of change

Select one or more from the following:

- [x] New feature, functionality or library
- [ ] Consensus breaking; add the `consensus-breaking` label if so. See
#791 for details
- [ ] Bug fix
- [ ] Code health or cleanup
- [ ] Documentation
- [ ] Other (specify)

## Testing

- [ ] **Documentation**: `make docusaurus_start`; only needed if you
make doc changes
- [x] **Unit Tests**: `make go_develop_and_test`
- [ ] **LocalNet E2E Tests**: `make test_e2e`
- [x] **DevNet E2E Tests**: Add the `devnet-test-e2e` label to the PR.

## Sanity Checklist

- [x] I have tested my changes using the available tooling
- [ ] I have commented my code
- [x] I have performed a self-review of my own code; both comments &
source code
- [ ] I create and reference any new tickets, if applicable
- [ ] I have left TODOs throughout the codebase, if applicable

---------

Co-authored-by: Redouane Lakrache <[email protected]>
  • Loading branch information
bryanchriswhite and red-0ne authored Nov 13, 2024
1 parent ed04927 commit 40942d2
Show file tree
Hide file tree
Showing 13 changed files with 273 additions and 59 deletions.
102 changes: 81 additions & 21 deletions api/poktroll/tokenomics/params.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ genesis:
mint_allocation_dao: 0.1
mint_allocation_proposer: 0.05
mint_allocation_supplier: 0.7
mint_allocation_source_owner: 0.15
shared:
params:
num_blocks_per_session: 10
Expand Down
4 changes: 4 additions & 0 deletions makefiles/params.mk
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ params_update_tokenomics_mint_allocation_proposer: ## Update the tokenomics modu
params_update_tokenomics_mint_allocation_supplier: ## Update the tokenomics module mint_allocation_supplier param
poktrolld tx authz exec ./tools/scripts/params/tokenomics_mint_allocation_supplier.json $(PARAM_FLAGS)

.PHONY: params_update_tokenomics_mint_allocation_source_owner
params_update_tokenomics_mint_allocation_source_owner: ## Update the tokenomics module mint_allocation_source_owner param
poktrolld tx authz exec ./tools/scripts/params/tokenomics_mint_allocation_source_owner.json $(PARAM_FLAGS)

### Service Module Params ###
.PHONY: params_get_service
params_get_service: ## Get the service module params
Expand Down
3 changes: 3 additions & 0 deletions proto/poktroll/tokenomics/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ message Params {
// mint_allocation_supplier is the percentage of the minted tokens which are sent
// to the block supplier account address during claim settlement.
double mint_allocation_supplier = 3 [(gogoproto.jsontag) = "mint_allocation_supplier", (gogoproto.moretags) = "yaml:\"mint_allocation_supplier\""];
// mint_allocation_source_owner is the percentage of the minted tokens which are sent
// to the service source owner account address during claim settlement.
double mint_allocation_source_owner = 4 [(gogoproto.jsontag) = "mint_allocation_source_owner", (gogoproto.moretags) = "yaml:\"mint_allocation_source_owner\""];

// IMPORTANT: Make sure to update all related files if you're modifying or adding a new parameter.
// Try the following grep to find all related places: `grep -r compute_units_to_tokens_multiplier`
Expand Down
7 changes: 4 additions & 3 deletions testutil/integration/suites/param_configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,10 @@ var (
QueryParamsResponse: tokenomicstypes.QueryParamsResponse{},
},
ValidParams: tokenomicstypes.Params{
MintAllocationDao: tokenomicstypes.DefaultMintAllocationDao,
MintAllocationProposer: tokenomicstypes.DefaultMintAllocationProposer,
MintAllocationSupplier: tokenomicstypes.DefaultMintAllocationSupplier,
MintAllocationDao: tokenomicstypes.DefaultMintAllocationDao,
MintAllocationProposer: tokenomicstypes.DefaultMintAllocationProposer,
MintAllocationSupplier: tokenomicstypes.DefaultMintAllocationSupplier,
MintAllocationSourceOwner: tokenomicstypes.DefaultMintAllocationSourceOwner,
},
ParamTypes: map[ParamType]any{
ParamTypeFloat64: tokenomicstypes.MsgUpdateParam_AsFloat{},
Expand Down
3 changes: 2 additions & 1 deletion tools/scripts/params/tokenomics_all.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"params": {
"mint_allocation_dao": 0.1,
"mint_allocation_proposer": 0.05,
"mint_allocation_supplier": 0.7
"mint_allocation_supplier": 0.7,
"mint_allocation_source_owner": 0.15
}
}
]
Expand Down
12 changes: 12 additions & 0 deletions tools/scripts/params/tokenomics_mint_allocation_source_owner.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"body": {
"messages": [
{
"@type": "/poktroll.tokenomics.MsgUpdateParam",
"authority": "pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t",
"name": "mint_allocation_source_owner",
"as_float": 0.15
}
]
}
}
3 changes: 3 additions & 0 deletions x/tokenomics/keeper/msg_server_update_param.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ func (k msgServer) UpdateParam(
case tokenomicstypes.ParamMintAllocationSupplier:
logger = logger.With("param_value", msg.GetAsFloat())
params.MintAllocationSupplier = msg.GetAsFloat()
case tokenomicstypes.ParamMintAllocationSourceOwner:
logger = logger.With("param_value", msg.GetAsFloat())
params.MintAllocationSourceOwner = msg.GetAsFloat()
default:
return nil, status.Error(
codes.InvalidArgument,
Expand Down
25 changes: 25 additions & 0 deletions x/tokenomics/keeper/msg_server_update_param_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,28 @@ func TestMsgUpdateParam_UpdateMintAllocationSupplierOnly(t *testing.T) {
// Ensure the other parameters are unchanged
testkeeper.AssertDefaultParamsEqualExceptFields(t, &defaultParams, res.Params, string(tokenomicstypes.KeyMintAllocationSupplier))
}

func TestMsgUpdateParam_UpdateMintAllocationSourceOwnerOnly(t *testing.T) {
var expectedMintAllocationSourceOwner float64 = 3.14159

// Set the parameters to their default values
k, msgSrv, ctx := setupMsgServer(t)
defaultParams := tokenomicstypes.DefaultParams()
require.NoError(t, k.SetParams(ctx, defaultParams))

// Ensure the default values are different from the new values we want to set
require.NotEqual(t, expectedMintAllocationSourceOwner, defaultParams.MintAllocationSourceOwner)

// Update the new parameter
updateParamMsg := &tokenomicstypes.MsgUpdateParam{
Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(),
Name: tokenomicstypes.ParamMintAllocationSourceOwner,
AsType: &tokenomicstypes.MsgUpdateParam_AsFloat{AsFloat: expectedMintAllocationSourceOwner},
}
res, err := msgSrv.UpdateParam(ctx, updateParamMsg)
require.NoError(t, err)
require.Equal(t, expectedMintAllocationSourceOwner, res.Params.MintAllocationSourceOwner)

// Ensure the other parameters are unchanged
testkeeper.AssertDefaultParamsEqualExceptFields(t, &defaultParams, res.Params, string(tokenomicstypes.KeyMintAllocationSourceOwner))
}
34 changes: 34 additions & 0 deletions x/tokenomics/keeper/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,37 @@ func TestParams_ValidateMintAllocationSupplier(t *testing.T) {
})
}
}

func TestParams_ValidateMintAllocationSourceOwner(t *testing.T) {
tests := []struct {
desc string
mintAllocatioSourceOwner any
expectedErr error
}{
{
desc: "invalid type",
mintAllocatioSourceOwner: "0",
expectedErr: tokenomicstypes.ErrTokenomicsParamInvalid.Wrap("invalid parameter type: string"),
},
{
desc: "invalid MintAllocationSourceOwner (<0)",
mintAllocatioSourceOwner: -0.1,
expectedErr: tokenomicstypes.ErrTokenomicsParamInvalid.Wrapf("mint allocation to source owner must be greater than or equal to 0: got %f", -0.1),
},
{
desc: "valid MintAllocationSourceOwner",
mintAllocatioSourceOwner: tokenomicstypes.DefaultMintAllocationSourceOwner,
},
}

for _, test := range tests {
t.Run(test.desc, func(t *testing.T) {
err := tokenomicstypes.ValidateMintAllocationSourceOwner(test.mintAllocatioSourceOwner)
if test.expectedErr != nil {
require.ErrorContains(t, err, test.expectedErr.Error())
} else {
require.NoError(t, err)
}
})
}
}
5 changes: 5 additions & 0 deletions x/tokenomics/types/message_update_param.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ func (msg *MsgUpdateParam) ValidateBasic() error {
return err
}
return ValidateMintAllocationSupplier(msg.GetAsFloat())
case ParamMintAllocationSourceOwner:
if err := msg.paramTypeIsFloat(); err != nil {
return err
}
return ValidateMintAllocationSourceOwner(msg.GetAsFloat())
default:
return ErrTokenomicsParamNameInvalid.Wrapf("unsupported param %q", msg.Name)
}
Expand Down
Loading

0 comments on commit 40942d2

Please sign in to comment.