Skip to content

Commit

Permalink
[Tokenomics] feat: add mint_allocation_application param to tokenom…
Browse files Browse the repository at this point in the history
…ics module (#917)

## 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 <r3d0ne@gmail.com>
  • Loading branch information
bryanchriswhite and red-0ne authored Nov 13, 2024
1 parent afb2308 commit 9ce532b
Show file tree
Hide file tree
Showing 12 changed files with 251 additions and 43 deletions.
93 changes: 76 additions & 17 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 @@ -283,6 +283,7 @@ genesis:
mint_allocation_proposer: 0.05
mint_allocation_supplier: 0.7
mint_allocation_source_owner: 0.15
mint_allocation_application: 0.0
shared:
params:
num_blocks_per_session: 10
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 @@ -24,6 +24,9 @@ message Params {
// 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\""];
// mint_allocation_application is the percentage of the minted tokens which are sent
// to the application account address during claim settlement.
double mint_allocation_application = 5 [(gogoproto.jsontag) = "mint_allocation_application", (gogoproto.moretags) = "yaml:\"mint_allocation_application\""];

// 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
1 change: 1 addition & 0 deletions testutil/integration/suites/param_configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ var (
MintAllocationProposer: tokenomicstypes.DefaultMintAllocationProposer,
MintAllocationSupplier: tokenomicstypes.DefaultMintAllocationSupplier,
MintAllocationSourceOwner: tokenomicstypes.DefaultMintAllocationSourceOwner,
MintAllocationApplication: tokenomicstypes.DefaultMintAllocationApplication,
},
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 @@ -8,7 +8,8 @@
"mint_allocation_dao": 0.1,
"mint_allocation_proposer": 0.05,
"mint_allocation_supplier": 0.7,
"mint_allocation_source_owner": 0.15
"mint_allocation_source_owner": 0.15,
"mint_allocation_application": 0.0
}
}
]
Expand Down
12 changes: 12 additions & 0 deletions tools/scripts/params/tokenomics_mint_allocation_application.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_application",
"as_double": 0.0
}
]
}
}
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 @@ -44,6 +44,9 @@ func (k msgServer) UpdateParam(
case tokenomicstypes.ParamMintAllocationSourceOwner:
logger = logger.With("param_value", msg.GetAsFloat())
params.MintAllocationSourceOwner = msg.GetAsFloat()
case tokenomicstypes.ParamMintAllocationApplication:
logger = logger.With("param_value", msg.GetAsFloat())
params.MintAllocationApplication = 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 @@ -110,3 +110,28 @@ func TestMsgUpdateParam_UpdateMintAllocationSourceOwnerOnly(t *testing.T) {
// Ensure the other parameters are unchanged
testkeeper.AssertDefaultParamsEqualExceptFields(t, &defaultParams, res.Params, string(tokenomicstypes.KeyMintAllocationSourceOwner))
}

func TestMsgUpdateParam_UpdateMintAllocationApplicationOnly(t *testing.T) {
var expectedMintAllocationApplication 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, expectedMintAllocationApplication, defaultParams.MintAllocationApplication)

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

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

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

for _, test := range tests {
t.Run(test.desc, func(t *testing.T) {
err := tokenomicstypes.ValidateMintAllocationApplication(test.mintAllocatioApplication)
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 @@ -61,6 +61,11 @@ func (msg *MsgUpdateParam) ValidateBasic() error {
return err
}
return ValidateMintAllocationSourceOwner(msg.GetAsFloat())
case ParamMintAllocationApplication:
if err := msg.paramTypeIsFloat(); err != nil {
return err
}
return ValidateMintAllocationApplication(msg.GetAsFloat())
default:
return ErrTokenomicsParamNameInvalid.Wrapf("unsupported param %q", msg.Name)
}
Expand Down
Loading

0 comments on commit 9ce532b

Please sign in to comment.