From 9ce532be8880ff375bbbc84563d588ada127cd7c Mon Sep 17 00:00:00 2001 From: Bryan White Date: Wed, 13 Nov 2024 19:25:52 +0100 Subject: [PATCH] [Tokenomics] feat: add `mint_allocation_application` param to tokenomics 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 --- api/poktroll/tokenomics/params.pulsar.go | 93 +++++++++++++++---- config.yml | 1 + proto/poktroll/tokenomics/params.proto | 3 + testutil/integration/suites/param_configs.go | 1 + tools/scripts/params/tokenomics_all.json | 3 +- ...okenomics_mint_allocation_application.json | 12 +++ .../keeper/msg_server_update_param.go | 3 + .../keeper/msg_server_update_param_test.go | 25 +++++ x/tokenomics/keeper/params_test.go | 34 +++++++ x/tokenomics/types/message_update_param.go | 5 + x/tokenomics/types/params.go | 31 ++++++- x/tokenomics/types/params.pb.go | 83 ++++++++++++----- 12 files changed, 251 insertions(+), 43 deletions(-) create mode 100644 tools/scripts/params/tokenomics_mint_allocation_application.json diff --git a/api/poktroll/tokenomics/params.pulsar.go b/api/poktroll/tokenomics/params.pulsar.go index 10529181b..f31b520e6 100644 --- a/api/poktroll/tokenomics/params.pulsar.go +++ b/api/poktroll/tokenomics/params.pulsar.go @@ -22,6 +22,7 @@ var ( fd_Params_mint_allocation_proposer protoreflect.FieldDescriptor fd_Params_mint_allocation_supplier protoreflect.FieldDescriptor fd_Params_mint_allocation_source_owner protoreflect.FieldDescriptor + fd_Params_mint_allocation_application protoreflect.FieldDescriptor ) func init() { @@ -31,6 +32,7 @@ func init() { fd_Params_mint_allocation_proposer = md_Params.Fields().ByName("mint_allocation_proposer") fd_Params_mint_allocation_supplier = md_Params.Fields().ByName("mint_allocation_supplier") fd_Params_mint_allocation_source_owner = md_Params.Fields().ByName("mint_allocation_source_owner") + fd_Params_mint_allocation_application = md_Params.Fields().ByName("mint_allocation_application") } var _ protoreflect.Message = (*fastReflection_Params)(nil) @@ -122,6 +124,12 @@ func (x *fastReflection_Params) Range(f func(protoreflect.FieldDescriptor, proto return } } + if x.MintAllocationApplication != float64(0) || math.Signbit(x.MintAllocationApplication) { + value := protoreflect.ValueOfFloat64(x.MintAllocationApplication) + if !f(fd_Params_mint_allocation_application, value) { + return + } + } } // Has reports whether a field is populated. @@ -145,6 +153,8 @@ func (x *fastReflection_Params) Has(fd protoreflect.FieldDescriptor) bool { return x.MintAllocationSupplier != float64(0) || math.Signbit(x.MintAllocationSupplier) case "poktroll.tokenomics.Params.mint_allocation_source_owner": return x.MintAllocationSourceOwner != float64(0) || math.Signbit(x.MintAllocationSourceOwner) + case "poktroll.tokenomics.Params.mint_allocation_application": + return x.MintAllocationApplication != float64(0) || math.Signbit(x.MintAllocationApplication) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.tokenomics.Params")) @@ -169,6 +179,8 @@ func (x *fastReflection_Params) Clear(fd protoreflect.FieldDescriptor) { x.MintAllocationSupplier = float64(0) case "poktroll.tokenomics.Params.mint_allocation_source_owner": x.MintAllocationSourceOwner = float64(0) + case "poktroll.tokenomics.Params.mint_allocation_application": + x.MintAllocationApplication = float64(0) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.tokenomics.Params")) @@ -197,6 +209,9 @@ func (x *fastReflection_Params) Get(descriptor protoreflect.FieldDescriptor) pro case "poktroll.tokenomics.Params.mint_allocation_source_owner": value := x.MintAllocationSourceOwner return protoreflect.ValueOfFloat64(value) + case "poktroll.tokenomics.Params.mint_allocation_application": + value := x.MintAllocationApplication + return protoreflect.ValueOfFloat64(value) default: if descriptor.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.tokenomics.Params")) @@ -225,6 +240,8 @@ func (x *fastReflection_Params) Set(fd protoreflect.FieldDescriptor, value proto x.MintAllocationSupplier = value.Float() case "poktroll.tokenomics.Params.mint_allocation_source_owner": x.MintAllocationSourceOwner = value.Float() + case "poktroll.tokenomics.Params.mint_allocation_application": + x.MintAllocationApplication = value.Float() default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.tokenomics.Params")) @@ -253,6 +270,8 @@ func (x *fastReflection_Params) Mutable(fd protoreflect.FieldDescriptor) protore panic(fmt.Errorf("field mint_allocation_supplier of message poktroll.tokenomics.Params is not mutable")) case "poktroll.tokenomics.Params.mint_allocation_source_owner": panic(fmt.Errorf("field mint_allocation_source_owner of message poktroll.tokenomics.Params is not mutable")) + case "poktroll.tokenomics.Params.mint_allocation_application": + panic(fmt.Errorf("field mint_allocation_application of message poktroll.tokenomics.Params is not mutable")) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.tokenomics.Params")) @@ -274,6 +293,8 @@ func (x *fastReflection_Params) NewField(fd protoreflect.FieldDescriptor) protor return protoreflect.ValueOfFloat64(float64(0)) case "poktroll.tokenomics.Params.mint_allocation_source_owner": return protoreflect.ValueOfFloat64(float64(0)) + case "poktroll.tokenomics.Params.mint_allocation_application": + return protoreflect.ValueOfFloat64(float64(0)) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.tokenomics.Params")) @@ -355,6 +376,9 @@ func (x *fastReflection_Params) ProtoMethods() *protoiface.Methods { if x.MintAllocationSourceOwner != 0 || math.Signbit(x.MintAllocationSourceOwner) { n += 9 } + if x.MintAllocationApplication != 0 || math.Signbit(x.MintAllocationApplication) { + n += 9 + } if x.unknownFields != nil { n += len(x.unknownFields) } @@ -384,6 +408,12 @@ func (x *fastReflection_Params) ProtoMethods() *protoiface.Methods { i -= len(x.unknownFields) copy(dAtA[i:], x.unknownFields) } + if x.MintAllocationApplication != 0 || math.Signbit(x.MintAllocationApplication) { + i -= 8 + binary.LittleEndian.PutUint64(dAtA[i:], uint64(math.Float64bits(float64(x.MintAllocationApplication)))) + i-- + dAtA[i] = 0x29 + } if x.MintAllocationSourceOwner != 0 || math.Signbit(x.MintAllocationSourceOwner) { i -= 8 binary.LittleEndian.PutUint64(dAtA[i:], uint64(math.Float64bits(float64(x.MintAllocationSourceOwner)))) @@ -501,6 +531,17 @@ func (x *fastReflection_Params) ProtoMethods() *protoiface.Methods { v = uint64(binary.LittleEndian.Uint64(dAtA[iNdEx:])) iNdEx += 8 x.MintAllocationSourceOwner = float64(math.Float64frombits(v)) + case 5: + if wireType != 1 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field MintAllocationApplication", wireType) + } + var v uint64 + if (iNdEx + 8) > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + v = uint64(binary.LittleEndian.Uint64(dAtA[iNdEx:])) + iNdEx += 8 + x.MintAllocationApplication = float64(math.Float64frombits(v)) default: iNdEx = preIndex skippy, err := runtime.Skip(dAtA[iNdEx:]) @@ -567,6 +608,9 @@ type Params struct { // mint_allocation_source_owner is the percentage of the minted tokens which are sent // to the service source owner account address during claim settlement. MintAllocationSourceOwner float64 `protobuf:"fixed64,4,opt,name=mint_allocation_source_owner,json=mintAllocationSourceOwner,proto3" json:"mint_allocation_source_owner,omitempty"` + // mint_allocation_application is the percentage of the minted tokens which are sent + // to the service source owner account address during claim settlement. + MintAllocationApplication float64 `protobuf:"fixed64,5,opt,name=mint_allocation_application,json=mintAllocationApplication,proto3" json:"mint_allocation_application,omitempty"` } func (x *Params) Reset() { @@ -617,6 +661,13 @@ func (x *Params) GetMintAllocationSourceOwner() float64 { return 0 } +func (x *Params) GetMintAllocationApplication() float64 { + if x != nil { + return x.MintAllocationApplication + } + return 0 +} + var File_poktroll_tokenomics_params_proto protoreflect.FileDescriptor var file_poktroll_tokenomics_params_proto_rawDesc = []byte{ @@ -626,7 +677,7 @@ var file_poktroll_tokenomics_params_proto_rawDesc = []byte{ 0x65, 0x6e, 0x6f, 0x6d, 0x69, 0x63, 0x73, 0x1a, 0x11, 0x61, 0x6d, 0x69, 0x6e, 0x6f, 0x2f, 0x61, 0x6d, 0x69, 0x6e, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x14, 0x67, 0x6f, 0x67, 0x6f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x6f, 0x67, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x22, 0x97, 0x04, 0x0a, 0x06, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x65, 0x0a, 0x13, 0x6d, + 0x22, 0x9f, 0x05, 0x0a, 0x06, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x65, 0x0a, 0x13, 0x6d, 0x69, 0x6e, 0x74, 0x5f, 0x61, 0x6c, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x64, 0x61, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x01, 0x42, 0x35, 0xea, 0xde, 0x1f, 0x13, 0x6d, 0x69, 0x6e, 0x74, 0x5f, 0x61, 0x6c, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x64, 0x61, @@ -657,22 +708,30 @@ var file_poktroll_tokenomics_params_proto_rawDesc = []byte{ 0x61, 0x6c, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x5f, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x22, 0x52, 0x19, 0x6d, 0x69, 0x6e, 0x74, 0x41, 0x6c, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x4f, 0x77, - 0x6e, 0x65, 0x72, 0x3a, 0x25, 0xe8, 0xa0, 0x1f, 0x01, 0x8a, 0xe7, 0xb0, 0x2a, 0x1c, 0x70, 0x6f, - 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, 0x78, 0x2f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x6f, 0x6d, - 0x69, 0x63, 0x73, 0x2f, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x42, 0xbd, 0x01, 0xd8, 0xe2, 0x1e, - 0x01, 0x0a, 0x17, 0x63, 0x6f, 0x6d, 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, - 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x6f, 0x6d, 0x69, 0x63, 0x73, 0x42, 0x0b, 0x50, 0x61, 0x72, 0x61, - 0x6d, 0x73, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x24, 0x63, 0x6f, 0x73, 0x6d, 0x6f, - 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x70, 0x6f, 0x6b, 0x74, - 0x72, 0x6f, 0x6c, 0x6c, 0x2f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x6f, 0x6d, 0x69, 0x63, 0x73, 0xa2, - 0x02, 0x03, 0x50, 0x54, 0x58, 0xaa, 0x02, 0x13, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, - 0x2e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x6f, 0x6d, 0x69, 0x63, 0x73, 0xca, 0x02, 0x13, 0x50, 0x6f, - 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x5c, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x6f, 0x6d, 0x69, 0x63, - 0x73, 0xe2, 0x02, 0x1f, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x5c, 0x54, 0x6f, 0x6b, - 0x65, 0x6e, 0x6f, 0x6d, 0x69, 0x63, 0x73, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, - 0x61, 0x74, 0x61, 0xea, 0x02, 0x14, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x3a, 0x3a, - 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x6f, 0x6d, 0x69, 0x63, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x33, + 0x6e, 0x65, 0x72, 0x12, 0x85, 0x01, 0x0a, 0x1b, 0x6d, 0x69, 0x6e, 0x74, 0x5f, 0x61, 0x6c, 0x6c, + 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x18, 0x05, 0x20, 0x01, 0x28, 0x01, 0x42, 0x45, 0xea, 0xde, 0x1f, 0x1b, 0x6d, + 0x69, 0x6e, 0x74, 0x5f, 0x61, 0x6c, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x61, + 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0xf2, 0xde, 0x1f, 0x22, 0x79, 0x61, + 0x6d, 0x6c, 0x3a, 0x22, 0x6d, 0x69, 0x6e, 0x74, 0x5f, 0x61, 0x6c, 0x6c, 0x6f, 0x63, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x5f, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, + 0x52, 0x19, 0x6d, 0x69, 0x6e, 0x74, 0x41, 0x6c, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x25, 0xe8, 0xa0, 0x1f, + 0x01, 0x8a, 0xe7, 0xb0, 0x2a, 0x1c, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, 0x78, + 0x2f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x6f, 0x6d, 0x69, 0x63, 0x73, 0x2f, 0x50, 0x61, 0x72, 0x61, + 0x6d, 0x73, 0x42, 0xbd, 0x01, 0xd8, 0xe2, 0x1e, 0x01, 0x0a, 0x17, 0x63, 0x6f, 0x6d, 0x2e, 0x70, + 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x6f, 0x6d, 0x69, + 0x63, 0x73, 0x42, 0x0b, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, + 0x01, 0x5a, 0x24, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, + 0x61, 0x70, 0x69, 0x2f, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, 0x74, 0x6f, 0x6b, + 0x65, 0x6e, 0x6f, 0x6d, 0x69, 0x63, 0x73, 0xa2, 0x02, 0x03, 0x50, 0x54, 0x58, 0xaa, 0x02, 0x13, + 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x6f, 0x6d, + 0x69, 0x63, 0x73, 0xca, 0x02, 0x13, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x5c, 0x54, + 0x6f, 0x6b, 0x65, 0x6e, 0x6f, 0x6d, 0x69, 0x63, 0x73, 0xe2, 0x02, 0x1f, 0x50, 0x6f, 0x6b, 0x74, + 0x72, 0x6f, 0x6c, 0x6c, 0x5c, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x6f, 0x6d, 0x69, 0x63, 0x73, 0x5c, + 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x14, 0x50, 0x6f, + 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x3a, 0x3a, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x6f, 0x6d, 0x69, + 0x63, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/config.yml b/config.yml index 9aafa823c..5f8046a5a 100644 --- a/config.yml +++ b/config.yml @@ -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 diff --git a/proto/poktroll/tokenomics/params.proto b/proto/poktroll/tokenomics/params.proto index 78d663d59..62971780f 100644 --- a/proto/poktroll/tokenomics/params.proto +++ b/proto/poktroll/tokenomics/params.proto @@ -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` diff --git a/testutil/integration/suites/param_configs.go b/testutil/integration/suites/param_configs.go index 286647ebf..27f72ac4d 100644 --- a/testutil/integration/suites/param_configs.go +++ b/testutil/integration/suites/param_configs.go @@ -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{}, diff --git a/tools/scripts/params/tokenomics_all.json b/tools/scripts/params/tokenomics_all.json index 0e9eb9ef8..1b27a34c6 100644 --- a/tools/scripts/params/tokenomics_all.json +++ b/tools/scripts/params/tokenomics_all.json @@ -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 } } ] diff --git a/tools/scripts/params/tokenomics_mint_allocation_application.json b/tools/scripts/params/tokenomics_mint_allocation_application.json new file mode 100644 index 000000000..5f94c64de --- /dev/null +++ b/tools/scripts/params/tokenomics_mint_allocation_application.json @@ -0,0 +1,12 @@ +{ + "body": { + "messages": [ + { + "@type": "/poktroll.tokenomics.MsgUpdateParam", + "authority": "pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t", + "name": "mint_allocation_application", + "as_double": 0.0 + } + ] + } +} diff --git a/x/tokenomics/keeper/msg_server_update_param.go b/x/tokenomics/keeper/msg_server_update_param.go index 2f3fc1cbf..a7cc7269b 100644 --- a/x/tokenomics/keeper/msg_server_update_param.go +++ b/x/tokenomics/keeper/msg_server_update_param.go @@ -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, diff --git a/x/tokenomics/keeper/msg_server_update_param_test.go b/x/tokenomics/keeper/msg_server_update_param_test.go index d7d731f02..36751a95c 100644 --- a/x/tokenomics/keeper/msg_server_update_param_test.go +++ b/x/tokenomics/keeper/msg_server_update_param_test.go @@ -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)) +} diff --git a/x/tokenomics/keeper/params_test.go b/x/tokenomics/keeper/params_test.go index 5df00d7aa..cdcca60a7 100644 --- a/x/tokenomics/keeper/params_test.go +++ b/x/tokenomics/keeper/params_test.go @@ -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) + } + }) + } +} diff --git a/x/tokenomics/types/message_update_param.go b/x/tokenomics/types/message_update_param.go index 071fd8da7..1ff96a105 100644 --- a/x/tokenomics/types/message_update_param.go +++ b/x/tokenomics/types/message_update_param.go @@ -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) } diff --git a/x/tokenomics/types/params.go b/x/tokenomics/types/params.go index a6c9231e0..cb4f5f082 100644 --- a/x/tokenomics/types/params.go +++ b/x/tokenomics/types/params.go @@ -17,6 +17,9 @@ var ( KeyMintAllocationSourceOwner = []byte("MintAllocationSourceOwner") ParamMintAllocationSourceOwner = "mint_allocation_source_owner" DefaultMintAllocationSourceOwner float64 = 0.15 + KeyMintAllocationApplication = []byte("MintAllocationApplication") + ParamMintAllocationApplication = "mint_allocation_application" + DefaultMintAllocationApplication float64 = 0.0 _ paramtypes.ParamSet = (*Params)(nil) ) @@ -31,13 +34,15 @@ func NewParams( mintAllocationDao, mintAllocationProposer, mintAllocationSupplier, - mintAllocationSourceOwner float64, + mintAllocationSourceOwner, + mintAllocationApplication float64, ) Params { return Params{ MintAllocationDao: mintAllocationDao, MintAllocationProposer: mintAllocationProposer, MintAllocationSupplier: mintAllocationSupplier, MintAllocationSourceOwner: mintAllocationSourceOwner, + MintAllocationApplication: mintAllocationApplication, } } @@ -48,6 +53,7 @@ func DefaultParams() Params { DefaultMintAllocationProposer, DefaultMintAllocationSupplier, DefaultMintAllocationSourceOwner, + DefaultMintAllocationApplication, ) } @@ -74,6 +80,11 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { &p.MintAllocationSourceOwner, ValidateMintAllocationSourceOwner, ), + paramtypes.NewParamSetPair( + KeyMintAllocationApplication, + &p.MintAllocationApplication, + ValidateMintAllocationApplication, + ), } } @@ -95,6 +106,10 @@ func (params *Params) ValidateBasic() error { return err } + if err := ValidateMintAllocationApplication(params.MintAllocationApplication); err != nil { + return err + } + return nil } @@ -153,3 +168,17 @@ func ValidateMintAllocationSourceOwner(mintAllocationSourceOwner any) error { return nil } + +// ValidateMintAllocationApplication validates the MintAllocationApplication param. +func ValidateMintAllocationApplication(mintAllocationApplication any) error { + mintAllocationApplicationFloat, ok := mintAllocationApplication.(float64) + if !ok { + return ErrTokenomicsParamInvalid.Wrapf("invalid parameter type: %T", mintAllocationApplication) + } + + if mintAllocationApplicationFloat < 0 { + return ErrTokenomicsParamInvalid.Wrapf("mint allocation to application must be greater than or equal to 0: got %f", mintAllocationApplicationFloat) + } + + return nil +} diff --git a/x/tokenomics/types/params.pb.go b/x/tokenomics/types/params.pb.go index 45d881ff0..26eeca14d 100644 --- a/x/tokenomics/types/params.pb.go +++ b/x/tokenomics/types/params.pb.go @@ -39,6 +39,9 @@ type Params struct { // mint_allocation_source_owner is the percentage of the minted tokens which are sent // to the service source owner account address during claim settlement. MintAllocationSourceOwner float64 `protobuf:"fixed64,4,opt,name=mint_allocation_source_owner,json=mintAllocationSourceOwner,proto3" json:"mint_allocation_source_owner" yaml:"mint_allocation_source_owner"` + // mint_allocation_application is the percentage of the minted tokens which are sent + // to the service source owner account address during claim settlement. + MintAllocationApplication float64 `protobuf:"fixed64,5,opt,name=mint_allocation_application,json=mintAllocationApplication,proto3" json:"mint_allocation_application" yaml:"mint_allocation_application"` } func (m *Params) Reset() { *m = Params{} } @@ -98,6 +101,13 @@ func (m *Params) GetMintAllocationSourceOwner() float64 { return 0 } +func (m *Params) GetMintAllocationApplication() float64 { + if m != nil { + return m.MintAllocationApplication + } + return 0 +} + func init() { proto.RegisterType((*Params)(nil), "poktroll.tokenomics.Params") } @@ -105,30 +115,32 @@ func init() { func init() { proto.RegisterFile("poktroll/tokenomics/params.proto", fileDescriptor_df10a06914fc6eee) } var fileDescriptor_df10a06914fc6eee = []byte{ - // 359 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x92, 0xb1, 0x4e, 0xc2, 0x40, - 0x18, 0xc7, 0x39, 0x25, 0x0c, 0xdd, 0x28, 0xc6, 0x54, 0x42, 0xee, 0x48, 0x8d, 0x89, 0x31, 0x91, - 0x0e, 0xc4, 0x85, 0xc5, 0x48, 0x4c, 0x1c, 0x45, 0xdc, 0x5c, 0xc8, 0x51, 0x2f, 0xd8, 0xd0, 0xf6, - 0xbb, 0x5c, 0x8f, 0x20, 0x6f, 0x60, 0x9c, 0xdc, 0x5c, 0x7d, 0x04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0xb6, 0xfe, 0x82, 0x81, 0xb0, 0x59, 0x07, 0x86, 0x3e, 0x13, 0x46, 0x5e, 0xf9, 0xaf, 0x66, 0x21, - 0xf9, 0x97, 0x9b, 0x87, 0xe4, 0x30, 0xe3, 0x86, 0x35, 0xca, 0x6c, 0x1f, 0x6c, 0xdc, 0xa1, 0xc2, - 0xeb, 0x38, 0x6b, 0x1c, 0x7d, 0xbf, 0x11, 0xf4, 0xfc, 0xf5, 0x7e, 0x52, 0x59, 0x75, 0xeb, 0x71, - 0xbd, 0x5d, 0x8b, 0x3a, 0x34, 0x6f, 0x3e, 0x22, 0x8c, 0xc6, 0x11, 0x46, 0x93, 0x08, 0xa3, 0xcf, - 0x08, 0xa3, 0x97, 0x29, 0xce, 0x8d, 0xa7, 0x38, 0x37, 0x99, 0xe2, 0xdc, 0x5d, 0xbd, 0xe7, 0xc8, - 0x87, 0x41, 0xb7, 0x66, 0x83, 0x67, 0xc5, 0x6b, 0x4e, 0x7d, 0x26, 0x87, 0x20, 0xfa, 0x56, 0xfa, - 0x4e, 0x39, 0xe2, 0x2c, 0xe8, 0x16, 0x54, 0xe7, 0xea, 0x3f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x18, - 0x57, 0xdf, 0x97, 0xd5, 0x02, 0x00, 0x00, + // 397 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x92, 0x31, 0x8e, 0xda, 0x40, + 0x14, 0x86, 0x99, 0x24, 0x50, 0xb8, 0xc3, 0x44, 0x91, 0x43, 0x90, 0x07, 0x39, 0x8a, 0x14, 0x45, + 0x0a, 0x2e, 0x50, 0x1a, 0x9a, 0x08, 0x94, 0x28, 0x65, 0x08, 0xe9, 0xd2, 0xa0, 0xc1, 0x19, 0x11, + 0x0b, 0xdb, 0x6f, 0x34, 0x1e, 0x44, 0x38, 0x40, 0xa4, 0x68, 0xab, 0xbd, 0xc1, 0xee, 0x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0xff, 0x91, 0xd6, 0x3a, 0xf9, 0x05, 0x73, 0xee, 0xd0, 0x31, 0x2c, 0x02, 0xca, + 0x8d, 0x17, 0xca, 0xff, 0x5b, 0x2c, 0xf1, 0x59, 0x2e, 0x91, 0xf8, 0x6d, 0x49, 0x86, 0x03, 0xca, + 0x1a, 0xbd, 0x3e, 0xca, 0xa1, 0xc4, 0xef, 0xa9, 0xa6, 0xff, 0x43, 0xda, 0x9b, 0xe3, 0xcf, 0x24, + 0x8d, 0x99, 0xcd, 0x46, 0x55, 0x25, 0xf9, 0x1a, 0x4b, 0x7c, 0x0e, 0x4b, 0x24, 0xb6, 0x8a, 0x83, + 0x1c, 0x40, 0x27, 0x39, 0xfa, 0x7b, 0xad, 0xf7, 0xee, 0xe1, 0x1a, 0xa3, 0x8b, 0xfb, 0x9b, 0x0f, + 0xad, 0x5d, 0xc7, 0xff, 0x1e, 0xb6, 0x3c, 0xab, 0xe5, 0xe0, 0xc7, 0x6d, 0x64, 0xa2, 0x55, 0x64, + 0xa2, 0x75, 0x64, 0xa2, 0xbb, 0xc8, 0x44, 0x97, 0x1b, 0xb3, 0xb2, 0xda, 0x98, 0x95, 0xf5, 0xc6, + 0xac, 0xfc, 0xea, 0x4e, 0x5d, 0xf1, 0x67, 0x3e, 0xe9, 0x38, 0xe0, 0xdb, 0xe9, 0x99, 0x8f, 0x01, + 0x15, 0x0b, 0xe0, 0x33, 0xbb, 0xf8, 0xa6, 0x58, 0x32, 0x1a, 0x4e, 0x6a, 0xaa, 0xfb, 0xdd, 0xc7, + 0x00, 0x00, 0x00, 0xff, 0xff, 0x0f, 0x45, 0x21, 0xe2, 0x5d, 0x03, 0x00, 0x00, } func (this *Params) Equal(that interface{}) bool { @@ -162,6 +174,9 @@ func (this *Params) Equal(that interface{}) bool { if this.MintAllocationSourceOwner != that1.MintAllocationSourceOwner { return false } + if this.MintAllocationApplication != that1.MintAllocationApplication { + return false + } return true } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -184,6 +199,12 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.MintAllocationApplication != 0 { + i -= 8 + encoding_binary.LittleEndian.PutUint64(dAtA[i:], uint64(math.Float64bits(float64(m.MintAllocationApplication)))) + i-- + dAtA[i] = 0x29 + } if m.MintAllocationSourceOwner != 0 { i -= 8 encoding_binary.LittleEndian.PutUint64(dAtA[i:], uint64(math.Float64bits(float64(m.MintAllocationSourceOwner)))) @@ -240,6 +261,9 @@ func (m *Params) Size() (n int) { if m.MintAllocationSourceOwner != 0 { n += 9 } + if m.MintAllocationApplication != 0 { + n += 9 + } return n } @@ -322,6 +346,17 @@ func (m *Params) Unmarshal(dAtA []byte) error { v = uint64(encoding_binary.LittleEndian.Uint64(dAtA[iNdEx:])) iNdEx += 8 m.MintAllocationSourceOwner = float64(math.Float64frombits(v)) + case 5: + if wireType != 1 { + return fmt.Errorf("proto: wrong wireType = %d for field MintAllocationApplication", wireType) + } + var v uint64 + if (iNdEx + 8) > l { + return io.ErrUnexpectedEOF + } + v = uint64(encoding_binary.LittleEndian.Uint64(dAtA[iNdEx:])) + iNdEx += 8 + m.MintAllocationApplication = float64(math.Float64frombits(v)) default: iNdEx = preIndex skippy, err := skipParams(dAtA[iNdEx:])