From 390e88c0a389bdc034860a976352794e99b3136f Mon Sep 17 00:00:00 2001 From: shreyasbhat0 Date: Fri, 13 Sep 2024 09:08:18 +0530 Subject: [PATCH 01/24] feat: update params proto --- app/app.go | 1 - proto/arkeo/arkeo/params.proto | 9 ++++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/app.go b/app/app.go index 1f1a43e0..eeb8260a 100644 --- a/app/app.go +++ b/app/app.go @@ -213,7 +213,6 @@ var ( arkeomoduletypes.ReserveName: {}, arkeomoduletypes.ProviderName: {}, arkeomoduletypes.ContractName: {}, - // this line is used by starport scaffolding # stargate/app/maccPerms } ) diff --git a/proto/arkeo/arkeo/params.proto b/proto/arkeo/arkeo/params.proto index ac5f2ed6..fa704a5e 100644 --- a/proto/arkeo/arkeo/params.proto +++ b/proto/arkeo/arkeo/params.proto @@ -2,8 +2,15 @@ syntax = "proto3"; package arkeo.arkeo; import "gogoproto/gogo.proto"; +import "cosmos/base/v1beta1/coin.proto"; +import "cosmos_proto/cosmos.proto"; option go_package = "github.com/arkeonetwork/arkeo/x/arkeo/types"; // Params defines the parameters for the module. -message Params { option (gogoproto.goproto_stringer) = false; } +message Params { + option (gogoproto.goproto_stringer) = false; + string CommunityPoolPercentage= 1 [(cosmos_proto.scalar) = "cosmos.LegacyDec", (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", (gogoproto.nullable) = false]; + string DevFundPercentage= 2 [(cosmos_proto.scalar) = "cosmos.LegacyDec", (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", (gogoproto.nullable) = false]; + string ValidatorRewardsPercentage= 3 [(cosmos_proto.scalar) = "cosmos.LegacyDec", (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", (gogoproto.nullable) = false]; +} From 263ff0649155a761a1ed36c55dd057a417e847e6 Mon Sep 17 00:00:00 2001 From: shreyasbhat0 Date: Fri, 13 Sep 2024 09:08:37 +0530 Subject: [PATCH 02/24] chore: update arkeo module --- x/arkeo/keeper/keeper.go | 7 ++ x/arkeo/keeper/manager.go | 2 + x/arkeo/module.go | 1 + x/arkeo/types/expected_keepers.go | 1 + x/arkeo/types/params.go | 7 +- x/arkeo/types/params.pb.go | 169 ++++++++++++++++++++++++++++-- x/arkeo/types/query.pb.gw.go | 2 - x/claim/types/query.pb.gw.go | 2 - x/claim/types/tx.pb.go | 76 +++++++------- 9 files changed, 217 insertions(+), 50 deletions(-) diff --git a/x/arkeo/keeper/keeper.go b/x/arkeo/keeper/keeper.go index d7fd6896..1d692f09 100644 --- a/x/arkeo/keeper/keeper.go +++ b/x/arkeo/keeper/keeper.go @@ -126,6 +126,13 @@ func NewKVStore( storeKey, memKey storetypes.StoreKey, ps paramtypes.Subspace, + + /* + accountKeeper keeper.AccountKeeper + bankKeeper keeper.Keeper + distributionKeeper distkeeper.Keeper + stakingKeeper stakingkeeper.Keeper + */ coinKeeper bankkeeper.Keeper, accountKeeper authkeeper.AccountKeeper, stakingKeeper stakingkeeper.Keeper, diff --git a/x/arkeo/keeper/manager.go b/x/arkeo/keeper/manager.go index 9281f7d4..79db2df9 100644 --- a/x/arkeo/keeper/manager.go +++ b/x/arkeo/keeper/manager.go @@ -6,6 +6,7 @@ import ( "cosmossdk.io/errors" abci "github.com/cometbft/cometbft/abci/types" cmptm "github.com/cometbft/cometbft/proto/tendermint/types" + mintTypes "github.com/cosmos/cosmos-sdk/x/mint/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" "github.com/arkeonetwork/arkeo/common" @@ -17,6 +18,7 @@ import ( type Manager struct { keeper Keeper sk stakingkeeper.Keeper + mk mintTypes.BankKeeper } func NewManager(k Keeper, sk stakingkeeper.Keeper) Manager { diff --git a/x/arkeo/module.go b/x/arkeo/module.go index 72a08f6c..100e29cb 100644 --- a/x/arkeo/module.go +++ b/x/arkeo/module.go @@ -103,6 +103,7 @@ type AppModule struct { stakingKeeper stakingkeeper.Keeper } + func NewAppModule( cdc codec.Codec, keeper keeper.Keeper, diff --git a/x/arkeo/types/expected_keepers.go b/x/arkeo/types/expected_keepers.go index bf166837..d017c0e7 100644 --- a/x/arkeo/types/expected_keepers.go +++ b/x/arkeo/types/expected_keepers.go @@ -9,6 +9,7 @@ import ( // AccountKeeper defines the expected account keeper used for simulations (noalias) type AccountKeeper interface { GetAccount(ctx context.Context, addr sdk.AccAddress) sdk.AccountI + GetModuleAccount(ctx context.Context, name string) sdk.ModuleAccountI // Methods imported from account should be defined here } diff --git a/x/arkeo/types/params.go b/x/arkeo/types/params.go index 357196ad..981b7a15 100644 --- a/x/arkeo/types/params.go +++ b/x/arkeo/types/params.go @@ -1,6 +1,7 @@ package types import ( + "cosmossdk.io/math" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "gopkg.in/yaml.v2" ) @@ -14,7 +15,11 @@ func ParamKeyTable() paramtypes.KeyTable { // NewParams creates a new Params instance func NewParams() Params { - return Params{} + return Params{ + CommunityPoolPercentage: math.LegacyNewDecWithPrec(10, 1), + DevFundPercentage: math.LegacyNewDecWithPrec(10, 1), + ValidatorRewardsPercentage: math.LegacyNewDecWithPrec(10, 1), + } } // DefaultParams returns a default set of parameters diff --git a/x/arkeo/types/params.pb.go b/x/arkeo/types/params.pb.go index 20b07c81..a38f6b53 100644 --- a/x/arkeo/types/params.pb.go +++ b/x/arkeo/types/params.pb.go @@ -5,7 +5,10 @@ package types import ( + cosmossdk_io_math "cosmossdk.io/math" fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + _ "github.com/cosmos/cosmos-sdk/types" _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/cosmos/gogoproto/proto" io "io" @@ -26,6 +29,9 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Params defines the parameters for the module. type Params struct { + CommunityPoolPercentage cosmossdk_io_math.LegacyDec `protobuf:"bytes,1,opt,name=CommunityPoolPercentage,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"CommunityPoolPercentage"` + DevFundPercentage cosmossdk_io_math.LegacyDec `protobuf:"bytes,2,opt,name=DevFundPercentage,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"DevFundPercentage"` + ValidatorRewardsPercentage cosmossdk_io_math.LegacyDec `protobuf:"bytes,3,opt,name=ValidatorRewardsPercentage,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"ValidatorRewardsPercentage"` } func (m *Params) Reset() { *m = Params{} } @@ -67,16 +73,27 @@ func init() { func init() { proto.RegisterFile("arkeo/arkeo/params.proto", fileDescriptor_47c871f4fc73dfc5) } var fileDescriptor_47c871f4fc73dfc5 = []byte{ - // 142 bytes of a gzipped FileDescriptorProto + // 306 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x48, 0x2c, 0xca, 0x4e, 0xcd, 0xd7, 0x87, 0x90, 0x05, 0x89, 0x45, 0x89, 0xb9, 0xc5, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0xdc, 0x60, 0x31, 0x3d, 0x30, 0x29, 0x25, 0x92, 0x9e, 0x9f, 0x9e, 0x0f, 0x16, 0xd7, 0x07, - 0xb1, 0x20, 0x4a, 0x94, 0xf8, 0xb8, 0xd8, 0x02, 0xc0, 0x5a, 0xac, 0x58, 0x66, 0x2c, 0x90, 0x67, - 0x70, 0x72, 0x3d, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, - 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0xed, 0xf4, 0xcc, - 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0x88, 0x5d, 0x79, 0xa9, 0x25, 0xe5, 0xf9, 0x45, - 0xd9, 0x50, 0x8b, 0x2b, 0xa0, 0x74, 0x49, 0x65, 0x41, 0x6a, 0x71, 0x12, 0x1b, 0xd8, 0x74, 0x63, - 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x93, 0xe1, 0x2d, 0xa8, 0x9c, 0x00, 0x00, 0x00, + 0xb1, 0x20, 0x4a, 0xa4, 0xe4, 0x92, 0xf3, 0x8b, 0x73, 0xf3, 0x8b, 0xf5, 0x93, 0x12, 0x8b, 0x53, + 0xf5, 0xcb, 0x0c, 0x93, 0x52, 0x4b, 0x12, 0x0d, 0xf5, 0x93, 0xf3, 0x33, 0xf3, 0xa0, 0xf2, 0x92, + 0x10, 0xf9, 0x78, 0x88, 0x46, 0x08, 0x07, 0x22, 0xa5, 0xf4, 0x90, 0x89, 0x8b, 0x2d, 0x00, 0x6c, + 0x9d, 0x50, 0x21, 0x97, 0xb8, 0x73, 0x7e, 0x6e, 0x6e, 0x69, 0x5e, 0x66, 0x49, 0x65, 0x40, 0x7e, + 0x7e, 0x4e, 0x40, 0x6a, 0x51, 0x72, 0x6a, 0x5e, 0x49, 0x62, 0x7a, 0xaa, 0x04, 0xa3, 0x02, 0xa3, + 0x06, 0xa7, 0x93, 0xf9, 0x89, 0x7b, 0xf2, 0x0c, 0xb7, 0xee, 0xc9, 0x4b, 0x43, 0x4c, 0x28, 0x4e, + 0xc9, 0xd6, 0xcb, 0xcc, 0xd7, 0xcf, 0x4d, 0x2c, 0xc9, 0xd0, 0xf3, 0x49, 0x4d, 0x4f, 0x4c, 0xae, + 0x74, 0x49, 0x4d, 0xbe, 0xb4, 0x45, 0x57, 0x00, 0x6a, 0x01, 0x5c, 0x2c, 0x08, 0x97, 0xb9, 0x42, + 0xa9, 0x5c, 0x82, 0x2e, 0xa9, 0x65, 0x6e, 0xa5, 0x79, 0x29, 0x48, 0x96, 0x31, 0x51, 0x66, 0x19, + 0xa6, 0x89, 0x42, 0xe5, 0x5c, 0x52, 0x61, 0x89, 0x39, 0x99, 0x29, 0x89, 0x25, 0xf9, 0x45, 0x41, + 0xa9, 0xe5, 0x89, 0x45, 0x29, 0xc5, 0x48, 0xf6, 0x31, 0x53, 0x66, 0x1f, 0x1e, 0xa3, 0xad, 0x58, + 0x66, 0x2c, 0x90, 0x67, 0x70, 0x72, 0x3d, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, + 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, + 0x28, 0xed, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0x48, 0xd4, 0xe7, 0xa5, + 0x96, 0x94, 0xe7, 0x17, 0x65, 0x43, 0xd3, 0x41, 0x05, 0x94, 0x2e, 0xa9, 0x2c, 0x48, 0x2d, 0x4e, + 0x62, 0x03, 0xc7, 0x98, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0xb9, 0xcb, 0x73, 0x48, 0x2b, 0x02, + 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -99,6 +116,36 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + { + size := m.ValidatorRewardsPercentage.Size() + i -= size + if _, err := m.ValidatorRewardsPercentage.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + { + size := m.DevFundPercentage.Size() + i -= size + if _, err := m.DevFundPercentage.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + { + size := m.CommunityPoolPercentage.Size() + i -= size + if _, err := m.CommunityPoolPercentage.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa return len(dAtA) - i, nil } @@ -119,6 +166,12 @@ func (m *Params) Size() (n int) { } var l int _ = l + l = m.CommunityPoolPercentage.Size() + n += 1 + l + sovParams(uint64(l)) + l = m.DevFundPercentage.Size() + n += 1 + l + sovParams(uint64(l)) + l = m.ValidatorRewardsPercentage.Size() + n += 1 + l + sovParams(uint64(l)) return n } @@ -157,6 +210,108 @@ func (m *Params) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CommunityPoolPercentage", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.CommunityPoolPercentage.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DevFundPercentage", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.DevFundPercentage.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorRewardsPercentage", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.ValidatorRewardsPercentage.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipParams(dAtA[iNdEx:]) diff --git a/x/arkeo/types/query.pb.gw.go b/x/arkeo/types/query.pb.gw.go index fc8cce66..747f7ebe 100644 --- a/x/arkeo/types/query.pb.gw.go +++ b/x/arkeo/types/query.pb.gw.go @@ -1,6 +1,4 @@ // DONTCOVER -// DONTCOVER -// DONTCOVER // Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. // source: arkeo/arkeo/query.proto diff --git a/x/claim/types/query.pb.gw.go b/x/claim/types/query.pb.gw.go index 33cf14da..95ff1fc6 100644 --- a/x/claim/types/query.pb.gw.go +++ b/x/claim/types/query.pb.gw.go @@ -1,6 +1,4 @@ // DONTCOVER -// DONTCOVER -// DONTCOVER // Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. // source: arkeo/claim/query.proto diff --git a/x/claim/types/tx.pb.go b/x/claim/types/tx.pb.go index 59b8408d..ee63e8ac 100644 --- a/x/claim/types/tx.pb.go +++ b/x/claim/types/tx.pb.go @@ -512,45 +512,45 @@ func init() { func init() { proto.RegisterFile("arkeo/claim/tx.proto", fileDescriptor_6a4ddac60cb43154) } var fileDescriptor_6a4ddac60cb43154 = []byte{ - // 602 bytes of a gzipped FileDescriptorProto + // 607 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x54, 0xbf, 0x6f, 0xd3, 0x40, - 0x14, 0xae, 0x09, 0xfd, 0xf5, 0xd2, 0x56, 0xd4, 0xb4, 0xd4, 0x71, 0xa9, 0x09, 0x96, 0x40, 0x51, - 0x80, 0x58, 0x04, 0x89, 0x21, 0x5b, 0x5a, 0xb5, 0x13, 0x59, 0x42, 0x91, 0x10, 0x4b, 0xe4, 0x3a, - 0x57, 0xdb, 0x2a, 0xf6, 0x85, 0xbb, 0x0b, 0x94, 0x0d, 0x31, 0x32, 0xb1, 0x31, 0xf0, 0x2f, 0x20, - 0x91, 0x81, 0x3f, 0x02, 0xb6, 0x8a, 0x89, 0x11, 0x25, 0x43, 0xfe, 0x0d, 0xe4, 0x3b, 0x9f, 0x6b, - 0x3b, 0x69, 0x84, 0xb2, 0x5c, 0xf2, 0xbe, 0xef, 0xbd, 0x97, 0xef, 0xbb, 0x7b, 0x2f, 0xb0, 0x65, - 0x93, 0x33, 0x84, 0x2d, 0xe7, 0xb5, 0xed, 0x07, 0x16, 0x3b, 0xaf, 0xf5, 0x08, 0x66, 0x58, 0x2d, - 0x72, 0xb4, 0xc6, 0x51, 0xbd, 0xe4, 0x60, 0x1a, 0x60, 0xda, 0xe1, 0x94, 0x25, 0x02, 0x91, 0xa7, - 0x1b, 0xe9, 0x6a, 0x7e, 0x76, 0x08, 0x72, 0x30, 0xe9, 0xc6, 0xfc, 0x96, 0x8b, 0x5d, 0x2c, 0xea, - 0xa2, 0x6f, 0x31, 0xba, 0x23, 0x7a, 0x58, 0x01, 0x75, 0xad, 0xb7, 0x8f, 0xa3, 0x8f, 0x98, 0xd8, - 0xb4, 0x03, 0x3f, 0xc4, 0x16, 0x3f, 0x05, 0x64, 0x7e, 0x53, 0xa0, 0xd8, 0xa2, 0xee, 0x41, 0xd4, - 0xfb, 0x90, 0x79, 0x6a, 0x1d, 0x96, 0x1d, 0x82, 0x6c, 0x86, 0x89, 0xa6, 0x94, 0x95, 0xca, 0xea, - 0xbe, 0xf6, 0xfb, 0xc7, 0xa3, 0xad, 0x58, 0x54, 0xb3, 0xdb, 0x25, 0x88, 0xd2, 0xe7, 0x8c, 0xf8, - 0xa1, 0xdb, 0x96, 0x89, 0xea, 0x1d, 0x28, 0x22, 0xe6, 0x75, 0x6c, 0xc1, 0x6a, 0xd7, 0xa2, 0xba, - 0x36, 0x20, 0xe6, 0xc5, 0xf9, 0xea, 0x6d, 0x58, 0xa5, 0xbe, 0x1b, 0xda, 0xac, 0x4f, 0x90, 0x56, - 0xe0, 0xf4, 0x25, 0xd0, 0xa8, 0x7e, 0x1c, 0x0f, 0xaa, 0xb2, 0xd9, 0xa7, 0xf1, 0xa0, 0x5a, 0x12, - 0xae, 0xcf, 0x63, 0xdf, 0x29, 0x79, 0xe6, 0x36, 0xdc, 0x4c, 0x85, 0x6d, 0x44, 0x7b, 0x38, 0xa4, - 0xc8, 0x7c, 0x03, 0xeb, 0x12, 0x6e, 0x46, 0xb5, 0xf3, 0xd8, 0x68, 0x3c, 0xcc, 0xeb, 0xd8, 0x9d, - 0xae, 0x83, 0xff, 0x82, 0xb9, 0x03, 0xdb, 0x19, 0x20, 0xd1, 0xf2, 0x5d, 0x81, 0x1b, 0x2d, 0xea, - 0x1e, 0x13, 0x3b, 0xa4, 0xa7, 0x88, 0xf0, 0x8c, 0xb9, 0xae, 0xf5, 0x29, 0xac, 0x32, 0xdc, 0x4c, - 0x5f, 0xea, 0x8c, 0xaa, 0xcb, 0xd4, 0x86, 0x95, 0xf7, 0x61, 0x4c, 0xf8, 0xc8, 0x88, 0x33, 0x75, - 0xd0, 0xf2, 0x58, 0xe2, 0xe6, 0x97, 0x98, 0x8f, 0x66, 0xb7, 0x3b, 0xbf, 0x91, 0x0a, 0x2c, 0x3a, - 0x9e, 0xed, 0x87, 0xdc, 0xc4, 0x46, 0x5d, 0xad, 0xa5, 0xa6, 0xbf, 0x76, 0x10, 0x31, 0x6d, 0x91, - 0xa0, 0x6a, 0xb0, 0x2c, 0xa7, 0x48, 0x8c, 0x89, 0x0c, 0xd5, 0x5b, 0xb0, 0x64, 0x07, 0xb8, 0x1f, - 0x32, 0xed, 0x7a, 0x59, 0xa9, 0x14, 0xda, 0x71, 0xf4, 0x3f, 0xc3, 0x23, 0xb5, 0xc7, 0xc3, 0x23, - 0xc3, 0xc4, 0xe2, 0x17, 0x05, 0x36, 0xe5, 0x53, 0x1e, 0x7b, 0x98, 0x08, 0x29, 0xf3, 0x18, 0xbd, - 0x0b, 0x6b, 0xa7, 0x04, 0x07, 0xb9, 0x4d, 0x28, 0x46, 0x98, 0x5c, 0x85, 0x3d, 0x00, 0x86, 0x3b, - 0x59, 0x93, 0xa9, 0xb7, 0x5b, 0x4b, 0xdb, 0x31, 0x77, 0xa1, 0x34, 0x21, 0x4c, 0xca, 0xae, 0x7f, - 0x2d, 0x40, 0xa1, 0x45, 0x5d, 0xf5, 0x08, 0x56, 0x92, 0xed, 0xd5, 0x32, 0x57, 0x9b, 0xda, 0x14, - 0xbd, 0x7c, 0x15, 0x23, 0xfb, 0xa9, 0xcf, 0x00, 0x52, 0x0b, 0xa4, 0x4f, 0xcd, 0xe7, 0x9c, 0x6e, - 0x5e, 0xcd, 0x25, 0xdd, 0x5e, 0xc0, 0x7a, 0x76, 0x03, 0xf6, 0xf2, 0x45, 0x19, 0x5a, 0xbf, 0x37, - 0x93, 0x4e, 0xda, 0x1e, 0xc1, 0x4a, 0x32, 0x8a, 0x13, 0x66, 0x25, 0x33, 0x69, 0x36, 0xff, 0xe6, - 0xea, 0x4b, 0xd8, 0xc8, 0xbd, 0xb7, 0x31, 0xd5, 0x54, 0xc2, 0xeb, 0xf7, 0x67, 0xf3, 0xb2, 0xb3, - 0xbe, 0xf8, 0x61, 0x3c, 0xa8, 0x2a, 0xfb, 0x87, 0x3f, 0x87, 0x86, 0x72, 0x31, 0x34, 0x94, 0xbf, - 0x43, 0x43, 0xf9, 0x3c, 0x32, 0x16, 0x2e, 0x46, 0xc6, 0xc2, 0x9f, 0x91, 0xb1, 0xf0, 0xea, 0x81, - 0xeb, 0x33, 0xaf, 0x7f, 0x52, 0x73, 0x70, 0x60, 0xf1, 0x96, 0x21, 0x62, 0xef, 0x30, 0x39, 0xb3, - 0xb2, 0x83, 0xcb, 0xde, 0xf7, 0x10, 0x3d, 0x59, 0xe2, 0xff, 0xd2, 0x4f, 0xfe, 0x05, 0x00, 0x00, - 0xff, 0xff, 0x10, 0xa2, 0x81, 0xc3, 0x47, 0x06, 0x00, 0x00, + 0x14, 0x8e, 0x09, 0xfd, 0x91, 0x17, 0x5a, 0x51, 0x93, 0x52, 0xc7, 0xa5, 0x6e, 0xb0, 0x04, 0x8a, + 0x02, 0xc4, 0x10, 0x24, 0x86, 0x6c, 0x69, 0xd5, 0x4e, 0x64, 0x09, 0x45, 0x42, 0x2c, 0x91, 0xeb, + 0x5c, 0x6d, 0xab, 0xd8, 0x17, 0xee, 0x2e, 0x50, 0x36, 0xc4, 0xc8, 0xc4, 0xce, 0xbf, 0x80, 0x44, + 0x06, 0x36, 0xfe, 0x01, 0xd8, 0x2a, 0x26, 0x46, 0x94, 0x0c, 0xf9, 0x37, 0x90, 0xcf, 0x3e, 0xd7, + 0x76, 0xd2, 0xa8, 0xca, 0xe2, 0xe4, 0xbe, 0xef, 0xbd, 0x97, 0xef, 0x3b, 0x7f, 0x2f, 0x50, 0x32, + 0xc9, 0x29, 0xc2, 0x86, 0xf5, 0xc6, 0x74, 0x3d, 0x83, 0x9d, 0xd5, 0xfb, 0x04, 0x33, 0x2c, 0x17, + 0x39, 0x5a, 0xe7, 0xa8, 0x5a, 0xb6, 0x30, 0xf5, 0x30, 0xed, 0x72, 0xca, 0x08, 0x0f, 0x61, 0x9d, + 0xaa, 0x25, 0xbb, 0xf9, 0xb3, 0x4b, 0x90, 0x85, 0x49, 0x2f, 0xe2, 0x4b, 0x36, 0xb6, 0x71, 0xd8, + 0x17, 0x7c, 0x8b, 0xd0, 0xad, 0x70, 0x86, 0xe1, 0x51, 0xdb, 0x78, 0xf7, 0x24, 0xf8, 0x88, 0x88, + 0x0d, 0xd3, 0x73, 0x7d, 0x6c, 0xf0, 0x67, 0x08, 0xe9, 0xdf, 0x24, 0x28, 0xb6, 0xa9, 0xbd, 0x1f, + 0xcc, 0x3e, 0x60, 0x8e, 0xdc, 0x80, 0x15, 0x8b, 0x20, 0x93, 0x61, 0xa2, 0x48, 0x15, 0xa9, 0x5a, + 0xd8, 0x53, 0xfe, 0xfc, 0x78, 0x54, 0x8a, 0x44, 0xb5, 0x7a, 0x3d, 0x82, 0x28, 0x7d, 0xc1, 0x88, + 0xeb, 0xdb, 0x1d, 0x51, 0x28, 0xef, 0x42, 0x11, 0x31, 0xa7, 0x6b, 0x86, 0xac, 0x72, 0x2d, 0xe8, + 0xeb, 0x00, 0x62, 0x4e, 0x54, 0x2f, 0xdf, 0x81, 0x02, 0x75, 0x6d, 0xdf, 0x64, 0x03, 0x82, 0x94, + 0x3c, 0xa7, 0x2f, 0x80, 0x66, 0xed, 0xd3, 0x64, 0x58, 0x13, 0xc3, 0x3e, 0x4f, 0x86, 0xb5, 0x72, + 0xe8, 0xfa, 0x2c, 0xf2, 0x9d, 0x90, 0xa7, 0x6f, 0xc2, 0xad, 0xc4, 0xb1, 0x83, 0x68, 0x1f, 0xfb, + 0x14, 0xe9, 0x6f, 0x61, 0x4d, 0xc0, 0xad, 0xa0, 0x77, 0x11, 0x1b, 0xcd, 0x87, 0x59, 0x1d, 0xdb, + 0xb3, 0x75, 0xf0, 0x5f, 0xd0, 0xb7, 0x60, 0x33, 0x05, 0xc4, 0x5a, 0xbe, 0x4b, 0x70, 0xb3, 0x4d, + 0xed, 0x23, 0x62, 0xfa, 0xf4, 0x04, 0x11, 0x5e, 0xb1, 0xd0, 0xb5, 0x3e, 0x83, 0x02, 0xc3, 0xad, + 0xe4, 0xa5, 0xce, 0xe9, 0xba, 0x28, 0x6d, 0x1a, 0x59, 0x1f, 0xda, 0x94, 0x8f, 0x94, 0x38, 0x5d, + 0x05, 0x25, 0x8b, 0xc5, 0x6e, 0x7e, 0x87, 0xf9, 0x68, 0xf5, 0x7a, 0x8b, 0x1b, 0xa9, 0xc2, 0x92, + 0xe5, 0x98, 0xae, 0xcf, 0x4d, 0xac, 0x37, 0xe4, 0x7a, 0x22, 0xfd, 0xf5, 0xfd, 0x80, 0xe9, 0x84, + 0x05, 0xb2, 0x02, 0x2b, 0x22, 0x45, 0x61, 0x4c, 0xc4, 0x51, 0xbe, 0x0d, 0xcb, 0xa6, 0x87, 0x07, + 0x3e, 0x53, 0xae, 0x57, 0xa4, 0x6a, 0xbe, 0x13, 0x9d, 0xae, 0x12, 0x1e, 0xa1, 0x3d, 0x0a, 0x8f, + 0x38, 0xc6, 0x16, 0x7f, 0x4a, 0xb0, 0x21, 0x5e, 0xe5, 0x91, 0x83, 0x49, 0x28, 0x65, 0x11, 0xa3, + 0x77, 0xe1, 0xc6, 0x09, 0xc1, 0x5e, 0x66, 0x13, 0x8a, 0x01, 0x26, 0x56, 0x61, 0x07, 0x80, 0xe1, + 0x6e, 0xda, 0x64, 0xe2, 0xdd, 0x3d, 0xce, 0xda, 0xd9, 0x9d, 0x9d, 0xc1, 0x58, 0xa7, 0xbe, 0x0d, + 0xe5, 0x29, 0x50, 0x58, 0x6b, 0x7c, 0xcd, 0x43, 0xbe, 0x4d, 0x6d, 0xf9, 0x10, 0x56, 0xe3, 0x0d, + 0x57, 0x52, 0xd7, 0x9f, 0xd8, 0x26, 0xb5, 0x72, 0x19, 0x23, 0xe6, 0xc9, 0xcf, 0x01, 0x12, 0x4b, + 0xa6, 0xce, 0xac, 0xe7, 0x9c, 0xaa, 0x5f, 0xce, 0xc5, 0xd3, 0x5e, 0xc2, 0x5a, 0x7a, 0x4b, 0x76, + 0xb2, 0x4d, 0x29, 0x5a, 0xbd, 0x37, 0x97, 0x8e, 0xc7, 0x1e, 0xc2, 0x6a, 0x1c, 0xd7, 0x29, 0xb3, + 0x82, 0x99, 0x36, 0x9b, 0xcd, 0x85, 0xfc, 0x0a, 0xd6, 0x33, 0x99, 0xd0, 0x66, 0x9a, 0x8a, 0x79, + 0xf5, 0xfe, 0x7c, 0x5e, 0x4c, 0x56, 0x97, 0x3e, 0x4e, 0x86, 0x35, 0x69, 0xef, 0xe0, 0xd7, 0x48, + 0x93, 0xce, 0x47, 0x9a, 0xf4, 0x6f, 0xa4, 0x49, 0x5f, 0xc6, 0x5a, 0xee, 0x7c, 0xac, 0xe5, 0xfe, + 0x8e, 0xb5, 0xdc, 0xeb, 0x07, 0xb6, 0xcb, 0x9c, 0xc1, 0x71, 0xdd, 0xc2, 0x9e, 0xc1, 0x47, 0xfa, + 0x88, 0xbd, 0xc7, 0xe4, 0xd4, 0x48, 0xa7, 0x81, 0x7d, 0xe8, 0x23, 0x7a, 0xbc, 0xcc, 0xff, 0xc9, + 0x9f, 0xfe, 0x0f, 0x00, 0x00, 0xff, 0xff, 0xb3, 0xa2, 0x0a, 0xf6, 0x6b, 0x06, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. From c323a7da4d0cb2229e69b6fe48f0a4131705986b Mon Sep 17 00:00:00 2001 From: shreyasbhat0 Date: Fri, 13 Sep 2024 18:24:00 +0530 Subject: [PATCH 03/24] feat: add mint logic for distributing tokens --- x/arkeo/keeper/keeper.go | 55 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/x/arkeo/keeper/keeper.go b/x/arkeo/keeper/keeper.go index 1d692f09..880d1071 100644 --- a/x/arkeo/keeper/keeper.go +++ b/x/arkeo/keeper/keeper.go @@ -7,6 +7,7 @@ import ( "cosmossdk.io/errors" "cosmossdk.io/log" + "cosmossdk.io/math" storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" @@ -367,3 +368,57 @@ func (k KVStore) StakingSetParams(ctx cosmos.Context, params stakingtypes.Params func (k KVStore) GetAuthority() string { return k.authority } + +func (k KVStore) GetCirculatingSupply(ctx cosmos.Context, denom string) cosmos.Coin { + + // Get the total token supply of the given token + totalSupply := k.coinKeeper.GetSupply(ctx, denom) + + // Module Address for which the circulating supply should be exempted + + exemptModules := []string{"FoundationPool", "DevFund", "CommunityPool"} + exemptBalance := cosmos.NewInt(0) + + // range over the module and create exempt balances + for _, moduleName := range exemptModules { + moduleAddr := k.accountKeeper.GetModuleAddress(moduleName) + moduleBalance := k.coinKeeper.GetBalance(ctx, moduleAddr, denom) + exemptBalance = exemptBalance.Add(moduleBalance.Amount) + } + + // get the circulating supply + circulatingSupply := totalSupply.Amount.Sub(exemptBalance) + + return cosmos.NewCoin(denom, circulatingSupply) +} + +func (k KVStore) MintAndDistributeTokens(ctx cosmos.Context, newlyMinted cosmos.Coin) (math.Int, error) { + if err := k.MintToModule(ctx, types.ModuleName, newlyMinted); err != nil { + return math.NewInt(0), fmt.Errorf("failed to mint to module %s : error : %s", types.ModuleName, err) + } + + params := k.GetParams(ctx) + + devFundAmount := newlyMinted.Amount.MulRaw(params.DevFundPercentage.RoundInt64()).QuoRaw(100) + communityPoolAmount := newlyMinted.Amount.MulRaw(params.CommunityPoolPercentage.RoundInt64()).QuoRaw(100) + + validatorRewardAmount := newlyMinted.Amount.Sub(devFundAmount).Sub(communityPoolAmount) + + devFundAddr := k.accountKeeper.GetModuleAddress("DevFund") + if err := k.SendFromModuleToAccount(ctx, types.ModuleName, devFundAddr, cosmos.NewCoins(cosmos.NewCoin(newlyMinted.Denom, devFundAmount))); err != nil { + return math.NewInt(0), fmt.Errorf("error sending amount to module %s", err) + } + + communityPoolAddr := k.accountKeeper.GetModuleAddress("CommunityPool") + if err := k.SendFromModuleToAccount(ctx, types.ModuleName, communityPoolAddr, cosmos.NewCoins(cosmos.NewCoin(newlyMinted.Denom, devFundAmount))); err != nil { + return math.NewInt(0), fmt.Errorf("error sending amount to module %s", err) + } + + return validatorRewardAmount, nil + +} + +func (k KVStore) DistributeValidatorRewards(ctx cosmos.Context, denom string, amount cosmos.Int, validator stakingtypes.Validator) error { + // TODO: Add Logic Here + return nil +} From 34e78976d3005f626fa9444fad9369a52e12f742 Mon Sep 17 00:00:00 2001 From: toshiSat <10103480+toshiSat@users.noreply.github.com> Date: Sat, 14 Sep 2024 13:06:09 -0600 Subject: [PATCH 04/24] Increase claim timeout --- scripts/genesis.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/genesis.sh b/scripts/genesis.sh index f4e43d8f..fa8c5178 100755 --- a/scripts/genesis.sh +++ b/scripts/genesis.sh @@ -96,7 +96,7 @@ if [ ! -f ~/.arkeo/config/genesis.json ]; then # Thorchain derived test addresses add_account "tarkeo1dllfyp57l4xj5umqfcqy6c2l3xfk0qk6zpc3t7" $TOKEN 1000000000000000 # bob, 10m - add_claim_records "ARKEO" "ch" 1000 1000 1000 true + add_claim_records "ARKEO" "tarkeo1dllfyp57l4xj5umqfcqy6c2l3xfk0qk6zpc3t7" 1000 1000 1000 true add_account "tarkeo1xrz7z3zwtpc45xm72tpnevuf3wn53re8q4u4nr" $TOKEN 1000000000000000 add_claim_records "ARKEO" "tarkeo1xrz7z3zwtpc45xm72tpnevuf3wn53re8q4u4nr" 1000 1000 1000 true @@ -106,13 +106,13 @@ if [ ! -f ~/.arkeo/config/genesis.json ]; then # add_claim_records "ETHEREUM" "{YOUR ETH ADDRESS}" 500000 600000 700000 true add_claim_records "ETHEREUM" "0x92E14917A0508Eb56C90C90619f5F9Adbf49f47d" 500000 600000 700000 true - # enable CORs on testnet/localnet sed -i 's/enabled-unsafe-cors = false/enabled-unsafe-cors = true/g' ~/.arkeo/config/app.toml sed -i 's/cors_allowed_origins = \[\]/cors_allowed_origins = \["*"\]/g' ~/.arkeo/config/config.toml fi sed -i 's/"stake"/"uarkeo"/g' ~/.arkeo/config/genesis.json + sed -i '/"duration_until_decay"\|"duration_of_decay"/s/"3600s"/"7884000s"/' ~/.arkeo/config/genesis.json sed -i 's/enable = false/enable = true/g' ~/.arkeo/config/app.toml sed -i 's/127.0.0.1:26657/0.0.0.0:26657/g' ~/.arkeo/config/config.toml sed -i 's/address = "tcp:\/\/localhost:1317"/address = "tcp:\/\/0.0.0.0:1317"/g' ~/.arkeo/config/app.toml From 841a0cd366c2e2fe4ed953aff7074524ab36fcbb Mon Sep 17 00:00:00 2001 From: toshiSat <10103480+toshiSat@users.noreply.github.com> Date: Sat, 14 Sep 2024 13:14:50 -0600 Subject: [PATCH 05/24] Fix claim timeout --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 30af6cb6..a3188fce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,7 +42,8 @@ Contains all the PRs that improved the code without changing the behaviors. - Fixed Consumer in Directory Service - Fixed Regression Export - Fixed localnet docker -- updated the genesis file +- updated the genesis file +- claim timeout # v1.0.0-Prerelease From 58d561e41d53e15a1feebacd7a787a5bbe715ebe Mon Sep 17 00:00:00 2001 From: shreyasbhat0 Date: Mon, 16 Sep 2024 19:57:34 +0530 Subject: [PATCH 06/24] feat: add new module accounts --- app/app.go | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/app/app.go b/app/app.go index eeb8260a..5f788c4e 100644 --- a/app/app.go +++ b/app/app.go @@ -200,19 +200,22 @@ var ( // module account permissions maccPerms = map[string][]string{ - authtypes.FeeCollectorName: nil, - distrtypes.ModuleName: nil, - icatypes.ModuleName: nil, - minttypes.ModuleName: {authtypes.Minter}, - stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, - stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, - govtypes.ModuleName: {authtypes.Burner}, - ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, - claimmoduletypes.ModuleName: {authtypes.Minter}, - arkeomoduletypes.ModuleName: {}, - arkeomoduletypes.ReserveName: {}, - arkeomoduletypes.ProviderName: {}, - arkeomoduletypes.ContractName: {}, + authtypes.FeeCollectorName: nil, + distrtypes.ModuleName: nil, + icatypes.ModuleName: nil, + minttypes.ModuleName: {authtypes.Minter}, + stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, + stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, + govtypes.ModuleName: {authtypes.Burner}, + ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, + claimmoduletypes.ModuleName: {authtypes.Minter}, + arkeomoduletypes.ModuleName: {}, + arkeomoduletypes.ReserveName: {}, + arkeomoduletypes.ProviderName: {}, + arkeomoduletypes.ContractName: {}, + arkeomoduletypes.DevFundPool: {authtypes.Minter, authtypes.Burner}, + arkeomoduletypes.CommunityPool: {authtypes.Minter, authtypes.Burner}, + arkeomoduletypes.ValidatorRewardPool: {authtypes.Minter, authtypes.Burner}, } ) From 195ea70760289d1e97098866a75e814feed779bf Mon Sep 17 00:00:00 2001 From: shreyasbhat0 Date: Mon, 16 Sep 2024 19:58:04 +0530 Subject: [PATCH 07/24] feat: update validator payout --- x/arkeo/keeper/keeper.go | 47 +++--- x/arkeo/keeper/keeper_test.go | 3 + x/arkeo/keeper/manager.go | 166 +++++++++++--------- x/arkeo/keeper/manager_test.go | 277 ++++++++++++++++++--------------- 4 files changed, 268 insertions(+), 225 deletions(-) diff --git a/x/arkeo/keeper/keeper.go b/x/arkeo/keeper/keeper.go index 880d1071..a41ae688 100644 --- a/x/arkeo/keeper/keeper.go +++ b/x/arkeo/keeper/keeper.go @@ -7,8 +7,12 @@ import ( "cosmossdk.io/errors" "cosmossdk.io/log" - "cosmossdk.io/math" + sdkmath "cosmossdk.io/math" storetypes "cosmossdk.io/store/types" + "github.com/arkeonetwork/arkeo/common" + "github.com/arkeonetwork/arkeo/common/cosmos" + "github.com/arkeonetwork/arkeo/x/arkeo/configs" + "github.com/arkeonetwork/arkeo/x/arkeo/types" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -17,11 +21,6 @@ import ( paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - - "github.com/arkeonetwork/arkeo/common" - "github.com/arkeonetwork/arkeo/common/cosmos" - "github.com/arkeonetwork/arkeo/x/arkeo/configs" - "github.com/arkeonetwork/arkeo/x/arkeo/types" ) type dbPrefix string @@ -59,6 +58,8 @@ type Keeper interface { GetActiveValidators(ctx cosmos.Context) ([]stakingtypes.Validator, error) GetAccount(ctx cosmos.Context, addr cosmos.AccAddress) cosmos.Account StakingSetParams(ctx cosmos.Context, params stakingtypes.Params) error + MintAndDistributeTokens(ctx cosmos.Context, newlyMinted cosmos.Coin) error + GetCirculatingSupply(ctx cosmos.Context, denom string) cosmos.Coin // Query Params(c context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) @@ -375,8 +376,7 @@ func (k KVStore) GetCirculatingSupply(ctx cosmos.Context, denom string) cosmos.C totalSupply := k.coinKeeper.GetSupply(ctx, denom) // Module Address for which the circulating supply should be exempted - - exemptModules := []string{"FoundationPool", "DevFund", "CommunityPool"} + exemptModules := []string{types.ValidatorRewardPool, types.CommunityPool, types.DevFundPool} exemptBalance := cosmos.NewInt(0) // range over the module and create exempt balances @@ -392,33 +392,28 @@ func (k KVStore) GetCirculatingSupply(ctx cosmos.Context, denom string) cosmos.C return cosmos.NewCoin(denom, circulatingSupply) } -func (k KVStore) MintAndDistributeTokens(ctx cosmos.Context, newlyMinted cosmos.Coin) (math.Int, error) { - if err := k.MintToModule(ctx, types.ModuleName, newlyMinted); err != nil { - return math.NewInt(0), fmt.Errorf("failed to mint to module %s : error : %s", types.ModuleName, err) - } +func (k KVStore) MintAndDistributeTokens(ctx cosmos.Context, newlyMinted cosmos.Coin) error { params := k.GetParams(ctx) - devFundAmount := newlyMinted.Amount.MulRaw(params.DevFundPercentage.RoundInt64()).QuoRaw(100) - communityPoolAmount := newlyMinted.Amount.MulRaw(params.CommunityPoolPercentage.RoundInt64()).QuoRaw(100) + newlyMintedDec := sdkmath.LegacyNewDecFromInt(newlyMinted.Amount) - validatorRewardAmount := newlyMinted.Amount.Sub(devFundAmount).Sub(communityPoolAmount) + devFundAmount := newlyMintedDec.Mul(params.DevFundPercentage).TruncateInt() + communityPoolAmount := newlyMintedDec.Mul(params.CommunityPoolPercentage).TruncateInt() + validatorRewardAmount := newlyMintedDec.Mul(params.ValidatorRewardsPercentage).TruncateInt() - devFundAddr := k.accountKeeper.GetModuleAddress("DevFund") - if err := k.SendFromModuleToAccount(ctx, types.ModuleName, devFundAddr, cosmos.NewCoins(cosmos.NewCoin(newlyMinted.Denom, devFundAmount))); err != nil { - return math.NewInt(0), fmt.Errorf("error sending amount to module %s", err) + if err := k.MintToModule(ctx, types.DevFundPool, cosmos.NewCoin(newlyMinted.Denom, devFundAmount)); err != nil { + return fmt.Errorf("error sending amount to module %s", err) } - communityPoolAddr := k.accountKeeper.GetModuleAddress("CommunityPool") - if err := k.SendFromModuleToAccount(ctx, types.ModuleName, communityPoolAddr, cosmos.NewCoins(cosmos.NewCoin(newlyMinted.Denom, devFundAmount))); err != nil { - return math.NewInt(0), fmt.Errorf("error sending amount to module %s", err) + if err := k.MintToModule(ctx, types.CommunityPool, cosmos.NewCoin(newlyMinted.Denom, communityPoolAmount)); err != nil { + return fmt.Errorf("error sending amount to module %s", err) } - return validatorRewardAmount, nil - -} + if err := k.MintToModule(ctx, types.ValidatorRewardPool, cosmos.NewCoin(newlyMinted.Denom, validatorRewardAmount)); err != nil { + return fmt.Errorf("error sending amount to module %s", err) + } -func (k KVStore) DistributeValidatorRewards(ctx cosmos.Context, denom string, amount cosmos.Int, validator stakingtypes.Validator) error { - // TODO: Add Logic Here return nil + } diff --git a/x/arkeo/keeper/keeper_test.go b/x/arkeo/keeper/keeper_test.go index 92b53213..f8d00325 100644 --- a/x/arkeo/keeper/keeper_test.go +++ b/x/arkeo/keeper/keeper_test.go @@ -198,6 +198,9 @@ func SetupKeeperWithStaking(t testing.TB) (cosmos.Context, Keeper, stakingkeeper types.ProviderName: {}, types.ContractName: {}, govtypes.ModuleName: {authtypes.Minter, authtypes.Burner}, + types.DevFundPool: {authtypes.Minter, authtypes.Burner}, + types.ValidatorRewardPool: {authtypes.Minter, authtypes.Burner}, + types.CommunityPool: {authtypes.Minter, authtypes.Burner}, }, authcodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()), sdk.Bech32PrefixAccAddr, diff --git a/x/arkeo/keeper/manager.go b/x/arkeo/keeper/manager.go index 79db2df9..9d2ee149 100644 --- a/x/arkeo/keeper/manager.go +++ b/x/arkeo/keeper/manager.go @@ -193,105 +193,125 @@ func (mgr Manager) ValidatorPayout(ctx cosmos.Context, votes []abci.VoteInfo) er if valCycle == 0 || ctx.BlockHeight()%valCycle != 0 { return nil } + + circulatingSupply := mgr.keeper.GetCirculatingSupply(ctx, configs.Denom) + emissionCurve := mgr.FetchConfig(ctx, configs.EmissionCurve) blocksPerYear := mgr.FetchConfig(ctx, configs.BlocksPerYear) - reserveBal := mgr.keeper.GetBalance(ctx, mgr.keeper.GetModuleAccAddress(types.ReserveName)) - for _, bal := range reserveBal { - reserve := bal.Amount - blockReward := mgr.calcBlockReward(reserve.Int64(), emissionCurve, (blocksPerYear / valCycle)) + blockRewards := mgr.calcBlockReward(circulatingSupply.Amount.Int64(), emissionCurve, (blocksPerYear / valCycle)) + + if blockRewards.IsZero() { + return nil + } + + newlyMintedCoins := cosmos.NewCoin(configs.Denom, blockRewards) - if blockReward.IsZero() { + if err := mgr.keeper.MintAndDistributeTokens(ctx, newlyMintedCoins); err != nil { + ctx.Logger().Error("failed to mint and distribute tokens", "error", err) + return err + } + + validatorRewardPoolAddr := mgr.keeper.GetModuleAccAddress(types.ValidatorRewardPool) + validatorRewards := mgr.keeper.GetBalance(ctx, validatorRewardPoolAddr) + validatorRewardAmount := validatorRewards.AmountOf(configs.Denom) + + totalShares := cosmos.ZeroInt() + + for _, vote := range votes { + val, err := mgr.sk.ValidatorByConsAddr(ctx, vote.Validator.Address) + + if err != nil { + ctx.Logger().Info("unable to find validator", "validator", string(vote.Validator.Address)) continue } - // sum tokens - total := cosmos.ZeroInt() - for _, vote := range votes { - val, err := mgr.sk.ValidatorByConsAddr(ctx, vote.Validator.Address) - if err != nil { - ctx.Logger().Info("unable to find validator", "validator", string(vote.Validator.Address)) - continue - } - if !val.IsBonded() || val.IsJailed() { - continue - } - total = total.Add(val.GetDelegatorShares().RoundInt()) + if !val.IsBonded() || val.IsJailed() { + continue } - if total.IsZero() { - return nil + + totalShares = totalShares.Add(val.GetDelegatorShares().RoundInt()) + } + + if totalShares.IsZero() { + return nil + } + + for _, vote := range votes { + + if vote.BlockIdFlag.String() != "BLOCK_ID_FLAG_COMMIT" { + ctx.Logger().Info("validator rewards skipped due to lack of signature", "validator", string(vote.Validator.Address)) + continue } - for _, vote := range votes { + val, err := mgr.sk.ValidatorByConsAddr(ctx, vote.Validator.Address) + if err != nil { + ctx.Logger().Info("unable to find validator", "validator", string(vote.Validator.Address)) + continue + } + if !val.IsBonded() || val.IsJailed() { + ctx.Logger().Info("validator rewards skipped due to status or jailed", string(val.GetOperator())) + continue + } - if vote.BlockIdFlag.String() == "BLOCK_ID_FLAG_ABSENT" { - ctx.Logger().Info("validator rewards skipped due to lack of signature", "validator", string(vote.Validator.Address)) - continue - } + valBz, err := mgr.sk.ValidatorAddressCodec().StringToBytes(val.GetOperator()) + if err != nil { + ctx.Logger().Error("failed to decode validator address", "validator", string(val.GetOperator()), "error", err) + continue + } - val, err := mgr.sk.ValidatorByConsAddr(ctx, vote.Validator.Address) - if err != nil { - ctx.Logger().Info("unable to find validator", "validator", string(vote.Validator.Address)) - continue - } - if !val.IsBonded() || val.IsJailed() { - ctx.Logger().Info("validator rewards skipped due to status or jailed", "validator", val.GetOperator()) - continue - } + valVersion := mgr.keeper.GetVersionForAddress(ctx, valBz) + curVersion := mgr.keeper.GetVersion(ctx) + if valVersion < curVersion { + continue + } + acc := cosmos.AccAddress(val.GetOperator()) - valBz, err := mgr.sk.ValidatorAddressCodec().StringToBytes(val.GetOperator()) - if err != nil { - panic(err) - } + totalReward := common.GetSafeShare(val.GetDelegatorShares().RoundInt(), totalShares, validatorRewardAmount) + validatorReward := cosmos.ZeroInt() + rateBasisPts := val.GetCommission().MulInt64(100).RoundInt() - valVersion := mgr.keeper.GetVersionForAddress(ctx, valBz) - curVersion := mgr.keeper.GetVersion(ctx) - if valVersion < curVersion { - continue - } - acc := cosmos.AccAddress(val.GetOperator()) + delegates, err := mgr.sk.GetValidatorDelegations(ctx, valBz) + + if err != nil { + ctx.Logger().Error("unable to fetch delegations for validator", "validator", val.GetOperator(), "error", err) + continue + } - totalReward := common.GetSafeShare(val.GetDelegatorShares().RoundInt(), total, blockReward) - validatorReward := cosmos.ZeroInt() - rateBasisPts := val.GetCommission().MulInt64(100).RoundInt() + for _, delegate := range delegates { - delegates, err := mgr.sk.GetValidatorDelegations(ctx, valBz) + delegateAcc, err := cosmos.AccAddressFromBech32(delegate.DelegatorAddress) if err != nil { - panic(err) + ctx.Logger().Error("unable to fetch delegate address", "delegate", delegate.DelegatorAddress, "error", err) + continue } + delegateReward := common.GetSafeShare(delegate.GetShares().RoundInt(), val.GetDelegatorShares().RoundInt(), totalReward) + if acc.String() != delegate.DelegatorAddress { + valFee := common.GetSafeShare(rateBasisPts, cosmos.NewInt(configs.MaxBasisPoints), delegateReward) + delegateReward = delegateReward.Sub(valFee) + validatorReward = validatorReward.Add(valFee) - for _, delegate := range delegates { - delegateAcc, err := cosmos.AccAddressFromBech32(delegate.DelegatorAddress) - if err != nil { - ctx.Logger().Error("unable to fetch delegate address", "delegate", delegate.DelegatorAddress, "error", err) - continue - } - delegateReward := common.GetSafeShare(delegate.GetShares().RoundInt(), val.GetDelegatorShares().RoundInt(), totalReward) - if acc.String() != delegate.DelegatorAddress { - valFee := common.GetSafeShare(rateBasisPts, cosmos.NewInt(configs.MaxBasisPoints), delegateReward) - delegateReward = delegateReward.Sub(valFee) - validatorReward = validatorReward.Add(valFee) - } - if err := mgr.keeper.SendFromModuleToAccount(ctx, types.ReserveName, delegateAcc, cosmos.NewCoins(cosmos.NewCoin(bal.Denom, delegateReward))); err != nil { - ctx.Logger().Error("unable to pay rewards to delegate", "delegate", delegate.DelegatorAddress, "error", err) - } - ctx.Logger().Info("delegate rewarded", "delegate", delegateAcc.String(), "amount", delegateReward) } - if !validatorReward.IsZero() { - if err := mgr.keeper.SendFromModuleToAccount(ctx, types.ReserveName, acc, cosmos.NewCoins(cosmos.NewCoin(bal.Denom, validatorReward))); err != nil { - ctx.Logger().Error("unable to pay rewards to validator", "validator", val.GetOperator(), "error", err) - continue - } - ctx.Logger().Info("validator additional rewards", "validator", acc.String(), "amount", validatorReward) + if err := mgr.keeper.SendFromModuleToAccount(ctx, types.ValidatorRewardPool, delegateAcc, cosmos.NewCoins(cosmos.NewCoin(configs.Denom, delegateReward))); err != nil { + ctx.Logger().Error("unable to pay rewards to delegate", "delegate", delegate.DelegatorAddress, "error", err) } - if err := mgr.EmitValidatorPayoutEvent(ctx, acc, validatorReward); err != nil { - ctx.Logger().Error("unable to emit validator payout event", "validator", acc.String(), "error", err) + ctx.Logger().Info("delegate rewarded", "delegate", delegateAcc.String(), "amount", delegateReward) + } + + if !validatorReward.IsZero() { + if err := mgr.keeper.SendFromModuleToAccount(ctx, types.ValidatorRewardPool, acc, cosmos.NewCoins(cosmos.NewCoin(configs.Denom, validatorReward))); err != nil { + ctx.Logger().Error("unable to pay rewards to validator", "validator", val.GetOperator(), "error", err) + continue } + ctx.Logger().Info("validator additional rewards", "validator", acc.String(), "amount", validatorReward) } - } + if err := mgr.EmitValidatorPayoutEvent(ctx, acc, validatorReward); err != nil { + ctx.Logger().Error("unable to emit validator payout event", "validator", acc.String(), "error", err) + } + } return nil } diff --git a/x/arkeo/keeper/manager_test.go b/x/arkeo/keeper/manager_test.go index 90d4faf8..da6bda59 100644 --- a/x/arkeo/keeper/manager_test.go +++ b/x/arkeo/keeper/manager_test.go @@ -1,10 +1,13 @@ package keeper import ( + "fmt" "testing" "github.com/stretchr/testify/require" + "cosmossdk.io/math" + sdkmath "cosmossdk.io/math" "github.com/arkeonetwork/arkeo/common" "github.com/arkeonetwork/arkeo/common/cosmos" "github.com/arkeonetwork/arkeo/x/arkeo/configs" @@ -15,132 +18,6 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) -func TestValidatorPayout(t *testing.T) { - ctx, k, sk := SetupKeeperWithStaking(t) - - pks := simtestutil.CreateTestPubKeys(3) - pk1, err := common.NewPubKeyFromCrypto(pks[0]) - require.NoError(t, err) - acc1, err := pk1.GetMyAddress() - require.NoError(t, err) - pk2, err := common.NewPubKeyFromCrypto(pks[1]) - require.NoError(t, err) - acc2, err := pk2.GetMyAddress() - require.NoError(t, err) - pk3, err := common.NewPubKeyFromCrypto(pks[2]) - require.NoError(t, err) - acc3, err := pk3.GetMyAddress() - require.NoError(t, err) - - valAddrs := simtestutil.ConvertAddrsToValAddrs([]cosmos.AccAddress{acc1, acc2, acc3}) - - val1, err := stakingtypes.NewValidator(valAddrs[0].String(), pks[0], stakingtypes.Description{}) - require.NoError(t, err) - val1.Tokens = cosmos.NewInt(100) - val1.DelegatorShares = cosmos.NewDec(100 + 10 + 20) - val1.Status = stakingtypes.Bonded - val1.Commission = stakingtypes.NewCommission(cosmos.NewDecWithPrec(1, 1), cosmos.ZeroDec(), cosmos.ZeroDec()) - - val2, err := stakingtypes.NewValidator(valAddrs[1].String(), pks[1], stakingtypes.Description{}) - require.NoError(t, err) - val2.Tokens = cosmos.NewInt(200) - val2.DelegatorShares = cosmos.NewDec(200 + 20) - val2.Status = stakingtypes.Bonded - val2.Commission = stakingtypes.NewCommission(cosmos.NewDecWithPrec(2, 1), cosmos.ZeroDec(), cosmos.ZeroDec()) - - val3, err := stakingtypes.NewValidator(valAddrs[2].String(), pks[2], stakingtypes.Description{}) - require.NoError(t, err) - val3.Tokens = cosmos.NewInt(500) - val3.DelegatorShares = cosmos.NewDec(500) - val3.Status = stakingtypes.Bonded - val3.Commission = stakingtypes.NewCommission(cosmos.NewDecWithPrec(5, 1), cosmos.ZeroDec(), cosmos.ZeroDec()) - - vals := []stakingtypes.Validator{val1, val2, val3} - for _, val := range vals { - require.NoError(t, sk.SetValidator(ctx, val)) - require.NoError(t, sk.SetValidatorByConsAddr(ctx, val)) - require.NoError(t, sk.SetNewValidatorByPowerIndex(ctx, val)) - } - - delAcc1 := types.GetRandomBech32Addr() - delAcc2 := types.GetRandomBech32Addr() - delAcc3 := types.GetRandomBech32Addr() - - require.NoError(t, sk.SetDelegation(ctx, stakingtypes.NewDelegation(acc1.String(), valAddrs[0].String(), cosmos.NewDec(100)))) - require.NoError(t, sk.SetDelegation(ctx, stakingtypes.NewDelegation(acc2.String(), valAddrs[1].String(), cosmos.NewDec(200)))) - require.NoError(t, sk.SetDelegation(ctx, stakingtypes.NewDelegation(acc3.String(), valAddrs[2].String(), cosmos.NewDec(500)))) - - del1 := stakingtypes.NewDelegation(delAcc1.String(), valAddrs[0].String(), cosmos.NewDec(10)) - del2 := stakingtypes.NewDelegation(delAcc2.String(), valAddrs[1].String(), cosmos.NewDec(20)) - del3 := stakingtypes.NewDelegation(delAcc3.String(), valAddrs[2].String(), cosmos.NewDec(20)) - require.NoError(t, sk.SetDelegation(ctx, del1)) - require.NoError(t, sk.SetDelegation(ctx, del2)) - require.NoError(t, sk.SetDelegation(ctx, del3)) - - // mint token1 - require.NoError(t, k.MintToModule(ctx, types.ModuleName, getCoin(common.Tokens(50000)))) - require.NoError(t, k.SendFromModuleToModule(ctx, types.ModuleName, types.ReserveName, getCoins(common.Tokens(50000)))) - // mint token2 - coins := cosmos.NewCoins(cosmos.NewInt64Coin("tokkie", 50000*1e8)) - require.NoError(t, k.MintToModule(ctx, types.ModuleName, coins[0])) - require.NoError(t, k.SendFromModuleToModule(ctx, types.ModuleName, types.ReserveName, coins)) - - mgr := NewManager(k, sk) - ctx = ctx.WithBlockHeight(mgr.FetchConfig(ctx, configs.ValidatorPayoutCycle)) - - votes := make([]abci.VoteInfo, len(vals)) - for i, val := range vals { - consAddr, err := val.GetConsAddr() - require.NoError(t, err) - votes[i] = abci.VoteInfo{ - Validator: abci.Validator{ - Address: consAddr, - Power: val.Tokens.Int64(), - }, - } - } - - blockReward := int64(158529) - require.NoError(t, mgr.ValidatorPayout(ctx, votes)) - require.Equal(t, k.GetBalanceOfModule(ctx, types.ReserveName, configs.Denom).Int64(), 5000000000000-blockReward) - - // check validator balances - totalBal := cosmos.ZeroInt() - bal := k.GetBalance(ctx, acc1) - require.Equal(t, bal.AmountOf(configs.Denom).Int64(), int64(18632)) - totalBal = totalBal.Add(bal.AmountOf(configs.Denom)) - require.Equal(t, bal.AmountOf("tokkie").Int64(), int64(18632)) - - bal = k.GetBalance(ctx, acc2) - require.Equal(t, bal.AmountOf(configs.Denom).Int64(), int64(37226)) - totalBal = totalBal.Add(bal.AmountOf(configs.Denom)) - require.Equal(t, bal.AmountOf("tokkie").Int64(), int64(37226)) - - bal = k.GetBalance(ctx, acc3) - require.Equal(t, bal.AmountOf(configs.Denom).Int64(), int64(92786)) - totalBal = totalBal.Add(bal.AmountOf(configs.Denom)) - require.Equal(t, bal.AmountOf("tokkie").Int64(), int64(92786)) - - // check delegate balances - bal = k.GetBalance(ctx, delAcc1) - require.Equal(t, bal.AmountOf(configs.Denom).Int64(), int64(1863)) - totalBal = totalBal.Add(bal.AmountOf(configs.Denom)) - require.Equal(t, bal.AmountOf("tokkie").Int64(), int64(1863)) - - bal = k.GetBalance(ctx, delAcc2) - require.Equal(t, bal.AmountOf(configs.Denom).Int64(), int64(3723)) - totalBal = totalBal.Add(bal.AmountOf(configs.Denom)) - require.Equal(t, bal.AmountOf("tokkie").Int64(), int64(3723)) - - bal = k.GetBalance(ctx, delAcc3) - require.Equal(t, bal.AmountOf(configs.Denom).Int64(), int64(3711)) - _ = totalBal.Add(bal.AmountOf(configs.Denom)) - require.Equal(t, bal.AmountOf("tokkie").Int64(), int64(3711)) - - // ensure block reward is equal to total rewarded to validators and delegates - require.Equal(t, blockReward, int64(158529)) -} - func TestContractEndBlock(t *testing.T) { ctx, k, sk := SetupKeeperWithStaking(t) ctx = ctx.WithBlockHeight(10) @@ -404,3 +281,151 @@ func TestInvariantMaxSupply(t *testing.T) { require.NoError(t, k.MintToModule(ctx, types.ModuleName, getCoin(200_000_000*1e8))) require.ErrorIs(t, mgr.invariantMaxSupply(ctx), types.ErrInvariantMaxSupply) } + +func TestParamsRewardsPercentage(t *testing.T) { + ctx, k, _ := SetupKeeperWithStaking(t) + + params := k.GetParams(ctx) + + require.Equal(t, params.CommunityPoolPercentage, math.LegacyNewDecWithPrec(10, 2)) + +} + +func TestValidatorPayouts(t *testing.T) { + ctx, k, sk := SetupKeeperWithStaking(t) + + pks := simtestutil.CreateTestPubKeys(3) + pk1, err := common.NewPubKeyFromCrypto(pks[0]) + require.NoError(t, err) + acc1, err := pk1.GetMyAddress() + require.NoError(t, err) + pk2, err := common.NewPubKeyFromCrypto(pks[1]) + require.NoError(t, err) + acc2, err := pk2.GetMyAddress() + require.NoError(t, err) + pk3, err := common.NewPubKeyFromCrypto(pks[2]) + require.NoError(t, err) + acc3, err := pk3.GetMyAddress() + require.NoError(t, err) + + valAddrs := simtestutil.ConvertAddrsToValAddrs([]cosmos.AccAddress{acc1, acc2, acc3}) + + val1, err := stakingtypes.NewValidator(valAddrs[0].String(), pks[0], stakingtypes.Description{}) + require.NoError(t, err) + val1.Tokens = cosmos.NewInt(100) + val1.DelegatorShares = cosmos.NewDec(130) // Validator + Delegations + val1.Status = stakingtypes.Bonded + val1.Commission = stakingtypes.NewCommission(cosmos.NewDecWithPrec(1, 1), cosmos.ZeroDec(), cosmos.ZeroDec()) + + val2, err := stakingtypes.NewValidator(valAddrs[1].String(), pks[1], stakingtypes.Description{}) + require.NoError(t, err) + val2.Tokens = cosmos.NewInt(200) + val2.DelegatorShares = cosmos.NewDec(220) + val2.Status = stakingtypes.Bonded + val2.Commission = stakingtypes.NewCommission(cosmos.NewDecWithPrec(2, 1), cosmos.ZeroDec(), cosmos.ZeroDec()) + + val3, err := stakingtypes.NewValidator(valAddrs[2].String(), pks[2], stakingtypes.Description{}) + require.NoError(t, err) + val3.Tokens = cosmos.NewInt(500) + val3.DelegatorShares = cosmos.NewDec(500) + val3.Status = stakingtypes.Bonded + val3.Commission = stakingtypes.NewCommission(cosmos.NewDecWithPrec(5, 1), cosmos.ZeroDec(), cosmos.ZeroDec()) + + vals := []stakingtypes.Validator{val1, val2, val3} + for _, val := range vals { + require.NoError(t, sk.SetValidator(ctx, val)) + require.NoError(t, sk.SetValidatorByConsAddr(ctx, val)) + require.NoError(t, sk.SetNewValidatorByPowerIndex(ctx, val)) + } + + delAcc1 := types.GetRandomBech32Addr() + delAcc2 := types.GetRandomBech32Addr() + delAcc3 := types.GetRandomBech32Addr() + + require.NoError(t, sk.SetDelegation(ctx, stakingtypes.NewDelegation(acc1.String(), valAddrs[0].String(), cosmos.NewDec(100)))) + require.NoError(t, sk.SetDelegation(ctx, stakingtypes.NewDelegation(acc2.String(), valAddrs[1].String(), cosmos.NewDec(200)))) + require.NoError(t, sk.SetDelegation(ctx, stakingtypes.NewDelegation(acc3.String(), valAddrs[2].String(), cosmos.NewDec(500)))) + + del1 := stakingtypes.NewDelegation(delAcc1.String(), valAddrs[0].String(), cosmos.NewDec(10)) + del2 := stakingtypes.NewDelegation(delAcc2.String(), valAddrs[1].String(), cosmos.NewDec(20)) + del3 := stakingtypes.NewDelegation(delAcc3.String(), valAddrs[2].String(), cosmos.NewDec(20)) + require.NoError(t, sk.SetDelegation(ctx, del1)) + require.NoError(t, sk.SetDelegation(ctx, del2)) + require.NoError(t, sk.SetDelegation(ctx, del3)) + + // Mint initial funds to the reserve + require.NoError(t, k.MintToModule(ctx, types.ModuleName, getCoin(common.Tokens(50000)))) + require.NoError(t, k.SendFromModuleToModule(ctx, types.ModuleName, types.ReserveName, getCoins(common.Tokens(50000)))) + + // Set parameters for payouts + params := types.DefaultParams() + params.DevFundPercentage = sdkmath.LegacyNewDecWithPrec(20, 2) // 20% + params.CommunityPoolPercentage = sdkmath.LegacyNewDecWithPrec(10, 2) // 10% + params.ValidatorRewardsPercentage = sdkmath.LegacyNewDecWithPrec(70, 2) // 70% + k.SetParams(ctx, params) + + // Instantiate manager with keeper and staking keeper + mgr := NewManager(k, sk) + ctx = ctx.WithBlockHeight(mgr.FetchConfig(ctx, configs.ValidatorPayoutCycle)) + + // Create VoteInfo for each validator + votes := make([]abci.VoteInfo, len(vals)) + for i, val := range vals { + consAddr, err := val.GetConsAddr() + require.NoError(t, err) + votes[i] = abci.VoteInfo{ + Validator: abci.Validator{ + Address: consAddr, + Power: val.Tokens.Int64(), + }, + BlockIdFlag: 2, + } + } + + blockReward := int64(158529) + newlyMintedDec := sdkmath.LegacyNewDecFromInt(sdkmath.NewInt(blockReward)) + + _ = newlyMintedDec.Mul(params.DevFundPercentage).TruncateInt() + _ = newlyMintedDec.Mul(params.CommunityPoolPercentage).TruncateInt() + validatorRewardAmount := newlyMintedDec.Mul(params.ValidatorRewardsPercentage).TruncateInt() + + // Expected block reward calculation + + validatorRewardPoolAddr := mgr.keeper.GetModuleAccAddress(types.ValidatorRewardPool) + fmt.Println(k.GetBalance(ctx, validatorRewardPoolAddr)) + + require.NoError(t, mgr.ValidatorPayout(ctx, votes)) + + validatorRewardPoolAddr = mgr.keeper.GetModuleAccAddress(types.ValidatorRewardPool) + fmt.Println(k.GetBalance(ctx, validatorRewardPoolAddr).AmountOf(configs.Denom)) + + // Verify the remaining balance after distribution + expectedRemaining := 5000000000000 - k.GetBalance(ctx, validatorRewardPoolAddr).AmountOf(configs.Denom).Int64() + require.Equal(t, k.GetBalanceOfModule(ctx, types.ReserveName, configs.Denom).Int64(), expectedRemaining) + + totalBal := cosmos.ZeroInt() + + // Check balances of validators 7 + checkBalance(ctx, t, k, acc1, configs.Denom, 13042, &totalBal) + checkBalance(ctx, t, k, acc2, configs.Denom, 26059, &totalBal) + checkBalance(ctx, t, k, acc3, configs.Denom, 64950, &totalBal) + + // Check balances of delegates + checkBalance(ctx, t, k, delAcc1, configs.Denom, 1305, &totalBal) + checkBalance(ctx, t, k, delAcc2, configs.Denom, 2606, &totalBal) + checkBalance(ctx, t, k, delAcc3, configs.Denom, 2598, &totalBal) + + fmt.Println(sdkmath.NewInt(110970).Sub(totalBal)) + + validatorRewardPoolAddr = mgr.keeper.GetModuleAccAddress(types.ValidatorRewardPool) + fmt.Println("Val", k.GetBalance(ctx, validatorRewardPoolAddr).AmountOf(configs.Denom)) + + // Ensure the total block reward equals the sum of all payouts + require.Equal(t, validatorRewardAmount.Int64(), int64(110970)) +} + +func checkBalance(ctx cosmos.Context, t *testing.T, k Keeper, acc cosmos.AccAddress, denom string, expectedAmt int64, total *sdkmath.Int) { + bal := k.GetBalance(ctx, acc) + *total = total.Add(bal.AmountOf(denom)) + require.Equal(t, bal.AmountOf(denom).Int64(), expectedAmt) +} From bc765a50d5b11e4112ee7505f80fdc8074746b02 Mon Sep 17 00:00:00 2001 From: shreyasbhat0 Date: Mon, 16 Sep 2024 19:58:56 +0530 Subject: [PATCH 08/24] feat: add module keys and update params --- x/arkeo/types/keys.go | 11 +++++++---- x/arkeo/types/params.go | 6 +++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/x/arkeo/types/keys.go b/x/arkeo/types/keys.go index 0854c3a7..21cd9c7e 100644 --- a/x/arkeo/types/keys.go +++ b/x/arkeo/types/keys.go @@ -2,10 +2,13 @@ package types const ( // ModuleName defines the module name - ModuleName = "arkeo" - ReserveName = "arkeo-reserve" - ProviderName = "providers" - ContractName = "contracts" + ModuleName = "arkeo" + ReserveName = "arkeo-reserve" + ProviderName = "providers" + ContractName = "contracts" + DevFundPool = "dev-fund" + CommunityPool = "community-fund" + ValidatorRewardPool = "validator-fund" // StoreKey defines the primary module store key StoreKey = ModuleName diff --git a/x/arkeo/types/params.go b/x/arkeo/types/params.go index 981b7a15..499a395c 100644 --- a/x/arkeo/types/params.go +++ b/x/arkeo/types/params.go @@ -16,9 +16,9 @@ func ParamKeyTable() paramtypes.KeyTable { // NewParams creates a new Params instance func NewParams() Params { return Params{ - CommunityPoolPercentage: math.LegacyNewDecWithPrec(10, 1), - DevFundPercentage: math.LegacyNewDecWithPrec(10, 1), - ValidatorRewardsPercentage: math.LegacyNewDecWithPrec(10, 1), + CommunityPoolPercentage: math.LegacyNewDecWithPrec(10, 2), + DevFundPercentage: math.LegacyNewDecWithPrec(20, 2), + ValidatorRewardsPercentage: math.LegacyNewDecWithPrec(70, 2), } } From a4fa05412923c9bee4a0f4a039c7cdb93243bea7 Mon Sep 17 00:00:00 2001 From: shreyasbhat0 Date: Mon, 16 Sep 2024 20:00:09 +0530 Subject: [PATCH 09/24] chore: update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 673fd1d1..542b8ba1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,8 @@ Contains all the PRs that improved the code without changing the behaviors. - Thorchain Claims Proto Updates - Documentation of Testnet Setup using local build and Cosmovisor - Documentation update and addition of validator setup documentation +- New Module accounts to handle rewards +- New Params to Arkeo Module ## Fixed - Testnet binary generation using go build @@ -41,6 +43,7 @@ Contains all the PRs that improved the code without changing the behaviors. - Updated Docs - Fixed Consumer in Directory Service - Fixed Regression Export +- Updated Tests on arkeo module keeper # v1.0.0-Prerelease From 051443a085114802c2e65dec4137956c0162995d Mon Sep 17 00:00:00 2001 From: shreyasbhat0 Date: Tue, 17 Sep 2024 13:50:10 +0530 Subject: [PATCH 10/24] fix: module genesis init --- app/app.go | 12 ++++------ app/export.go | 5 ++-- config.yml | 61 +++++++++++++++++++++++++++++++++++++++++++++++ x/arkeo/module.go | 20 ++++++++-------- x/claim/module.go | 20 +++++++--------- 5 files changed, 87 insertions(+), 31 deletions(-) diff --git a/app/app.go b/app/app.go index 1f1a43e0..405d9b24 100644 --- a/app/app.go +++ b/app/app.go @@ -486,7 +486,6 @@ func NewArkeoApp( app.GetSubspace(claimmoduletypes.ModuleName), logger, ) - claimModule := claimmodule.NewAppModule(appCodec, app.Keepers.ClaimKeeper, app.Keepers.AccountKeeper, app.Keepers.BankKeeper) // register the staking hooks // NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks @@ -597,7 +596,6 @@ func NewArkeoApp( govModuleAddr, logger, ) - arkeoModule := arkeomodule.NewAppModule(appCodec, app.Keepers.ArkeoKeeper, app.Keepers.AccountKeeper, app.Keepers.BankKeeper, *app.Keepers.StakingKeeper) /**** Module Options ****/ @@ -610,7 +608,7 @@ func NewArkeoApp( app.mm = module.NewManager( genutil.NewAppModule( - app.Keepers.AccountKeeper, app.Keepers.StakingKeeper, app, + app.Keepers.AccountKeeper, app.Keepers.StakingKeeper, app.BaseApp, encodingConfig.TxConfig, ), auth.NewAppModule(appCodec, app.Keepers.AccountKeeper, nil, app.GetSubspace(authtypes.ModuleName)), @@ -632,8 +630,8 @@ func NewArkeoApp( params.NewAppModule(app.Keepers.ParamsKeeper), transferModule, icaModule, - arkeoModule, - claimModule, + arkeomodule.NewAppModule(appCodec, app.Keepers.ArkeoKeeper, app.Keepers.AccountKeeper, app.Keepers.BankKeeper, *app.Keepers.StakingKeeper), + claimmodule.NewAppModule(appCodec, app.Keepers.ClaimKeeper, app.Keepers.AccountKeeper, app.Keepers.BankKeeper), // this line is used by starport scaffolding # stargate/app/appModule ) @@ -771,8 +769,8 @@ func NewArkeoApp( evidence.NewAppModule(app.Keepers.EvidenceKeeper), ibc.NewAppModule(app.Keepers.IBCKeeper), transferModule, - arkeoModule, - claimModule, + arkeomodule.NewAppModule(appCodec, app.Keepers.ArkeoKeeper, app.Keepers.AccountKeeper, app.Keepers.BankKeeper, *app.Keepers.StakingKeeper), + claimmodule.NewAppModule(appCodec, app.Keepers.ClaimKeeper, app.Keepers.AccountKeeper, app.Keepers.BankKeeper), // this line is used by starport scaffolding # stargate/app/appModule ) app.sm.RegisterStoreDecoders() diff --git a/app/export.go b/app/export.go index 57f841ba..bd305ba2 100644 --- a/app/export.go +++ b/app/export.go @@ -243,7 +243,7 @@ func (app *ArkeoApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs /* Handle slashing state. */ // reset start height on signing infos - err = app.Keepers.SlashingKeeper.IterateValidatorSigningInfos( + if err := app.Keepers.SlashingKeeper.IterateValidatorSigningInfos( ctx, func(addr sdk.ConsAddress, info slashingtypes.ValidatorSigningInfo) (stop bool) { info.StartHeight = 0 @@ -253,8 +253,7 @@ func (app *ArkeoApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs } return false }, - ) - if err != nil { + ); err != nil { panic(err) } } diff --git a/config.yml b/config.yml index 368ee46a..b1f706cd 100644 --- a/config.yml +++ b/config.yml @@ -12,6 +12,67 @@ genesis: staking: params: bond_denom: "uarkeo" + claimarkeo: + module_account_balance: + denom: '' + amount: '0' + params: + airdrop_start_time: '2024-08-27T04:35:10.833785853Z' + duration_until_decay: 7884000s + duration_of_decay: 7884000s + claim_denom: uarkeo + initial_gas_amount: + claim_records: + - chain: ARKEO + address: tarkeo19358z26jwh3e4rd6psxqf8q6f3pe6f8s7v0x2a + amount_claim: + denom: uarkeo + amount: '1000' + amount_vote: + denom: uarkeo + amount: '1000' + amount_delegate: + denom: uarkeo + amount: '1000' + is_transferable: true + - chain: ARKEO + address: tarkeo1dllfyp57l4xj5umqfcqy6c2l3xfk0qk6zpc3t7 + amount_claim: + denom: uarkeo + amount: '1000' + amount_vote: + denom: uarkeo + amount: '1000' + amount_delegate: + denom: uarkeo + amount: '1000' + is_transferable: true + - chain: ARKEO + address: tarkeo1xrz7z3zwtpc45xm72tpnevuf3wn53re8q4u4nr + amount_claim: + denom: uarkeo + amount: '1000' + amount_vote: + denom: uarkeo + amount: '1000' + amount_delegate: + denom: uarkeo + amount: '1000' + is_transferable: true + - chain: ETHEREUM + address: '0x92E14917A0508Eb56C90C90619f5F9Adbf49f47d' + amount_claim: + denom: uarkeo + amount: '500000' + amount_vote: + denom: uarkeo + amount: '600000' + amount_delegate: + denom: uarkeo + amount: '700000' + is_transferable: true + + accounts: - name: reserve coins: diff --git a/x/arkeo/module.go b/x/arkeo/module.go index 72a08f6c..24735f37 100644 --- a/x/arkeo/module.go +++ b/x/arkeo/module.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" - "github.com/arkeonetwork/arkeo/common/cosmos" "github.com/arkeonetwork/arkeo/x/arkeo/client/cli" "github.com/arkeonetwork/arkeo/x/arkeo/keeper" "github.com/arkeonetwork/arkeo/x/arkeo/types" @@ -26,8 +25,10 @@ import ( ) var ( - _ module.AppModule = AppModule{} - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} + _ module.HasABCIEndBlock = AppModule{} + _ module.HasGenesis = AppModule{} ) // ---------------------------------------------------------------------------- @@ -128,15 +129,13 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { // RegisterInvariants registers the invariants of the module. If an invariant deviates from its predicted value, the InvariantRegistry triggers appropriate logic (most often the chain will be halted) func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} -// InitGenesis performs the module's genesis initialization. It returns no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) []abci.ValidatorUpdate { +// InitGenesis performs the module's genesis initialization. +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) { var genState types.GenesisState // Initialize global index to index in genesis state cdc.MustUnmarshalJSON(gs, &genState) InitGenesis(ctx, am.keeper, genState) - - return []abci.ValidatorUpdate{} } // ExportGenesis returns the module's exported genesis state as raw JSON bytes. @@ -157,10 +156,11 @@ func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestFinalizeBlock) { } // EndBlock contains the logic that is automatically triggered at the end of each block -func (am AppModule) EndBlock(ctx cosmos.Context) ([]abci.ValidatorUpdate, error) { +func (am AppModule) EndBlock(ctx context.Context) ([]abci.ValidatorUpdate, error) { mgr := keeper.NewManager(am.keeper, am.stakingKeeper) - if err := mgr.EndBlock(ctx); err != nil { - ctx.Logger().Error("manager endblock error ", "error", err) + context := sdk.UnwrapSDKContext(ctx) + if err := mgr.EndBlock(context); err != nil { + context.Logger().Error("manager endblock error ", "error", err) } return []abci.ValidatorUpdate{}, nil } diff --git a/x/claim/module.go b/x/claim/module.go index 74fd5085..d04895ee 100644 --- a/x/claim/module.go +++ b/x/claim/module.go @@ -10,7 +10,7 @@ import ( "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" - abci "github.com/tendermint/tendermint/abci/types" + abci "github.com/cometbft/cometbft/abci/types" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" @@ -24,8 +24,10 @@ import ( ) var ( - _ module.AppModule = AppModule{} - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} + _ module.HasABCIEndBlock = AppModule{} + _ module.HasGenesis = AppModule{} ) // ---------------------------------------------------------------------------- @@ -135,14 +137,13 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} // InitGenesis performs the module's genesis initialization. It returns no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) []abci.ValidatorUpdate { +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) { var genState types.GenesisState // Initialize global index to index in genesis state + cdc.MustUnmarshalJSON(gs, &genState) InitGenesis(ctx, am.keeper, genState) - - return []abci.ValidatorUpdate{} } // ExportGenesis returns the module's exported genesis state as raw JSON bytes. @@ -154,12 +155,9 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw // ConsensusVersion is a sequence number for state-breaking change of the module. It should be incremented on each consensus-breaking change introduced by the module. To avoid wrong/empty versions, the initial version should be set to 1 func (AppModule) ConsensusVersion() uint64 { return 1 } -// BeginBlock contains the logic that is automatically triggered at the beginning of each block -func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} - // EndBlock contains the logic that is automatically triggered at the end of each block -func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - return []abci.ValidatorUpdate{} +func (am AppModule) EndBlock(_ context.Context) ([]abci.ValidatorUpdate, error) { + return []abci.ValidatorUpdate{}, nil } func (am AppModule) IsAppModule() {} From 652f72c55c291768dc256adb29a3b040f175ad65 Mon Sep 17 00:00:00 2001 From: shreyasbhat0 Date: Tue, 17 Sep 2024 14:38:19 +0530 Subject: [PATCH 11/24] fix: update regression tests --- directory/indexer/consumer.go | 3 ++ .../suites_contracts_pay-as-you-go.json | 39 ++++++++--------- .../suites_contracts_subscription.json | 43 ++++++++----------- .../mnt/exports/suites_core_send.json | 15 ++++++- .../mnt/exports/suites_initialize.json | 15 ++++++- .../exports/suites_providers_providers.json | 13 ++++++ .../suites_sentinel_contract_config.json | 13 ++++++ .../mnt/exports/suites_sentinel_sentinel.json | 13 ++++++ .../suites/contracts/pay-as-you-go.yaml | 6 +-- .../suites/contracts/subscription.yaml | 12 +++--- 10 files changed, 115 insertions(+), 57 deletions(-) diff --git a/directory/indexer/consumer.go b/directory/indexer/consumer.go index df336430..29ca6a75 100644 --- a/directory/indexer/consumer.go +++ b/directory/indexer/consumer.go @@ -238,6 +238,9 @@ func convertEventToMap(event abcitypes.Event) (map[string]any, error) { if attr.Key == "msg_index" { continue } + if attr.Key == "mode" { + continue + } switch attrValue[0] { case '{': var nest any diff --git a/test/regression/mnt/exports/suites_contracts_pay-as-you-go.json b/test/regression/mnt/exports/suites_contracts_pay-as-you-go.json index 1a57e5e5..d5acf54d 100644 --- a/test/regression/mnt/exports/suites_contracts_pay-as-you-go.json +++ b/test/regression/mnt/exports/suites_contracts_pay-as-you-go.json @@ -26,7 +26,7 @@ "authorization": "STRICT", "client": "tarkeopub1addwnpepq2res6tu0m73ulk5sepgp6g3y37schfgymxy8z6l3lc78k7ju9u45yajwem", "delegate": "", - "deposit": "100", + "deposit": "3", "duration": "10", "height": "2", "id": "1", @@ -40,7 +40,7 @@ }, "service": 1, "settlement_duration": "11", - "settlement_height": "0", + "settlement_height": "15", "type": "PAY_AS_YOU_GO" } ], @@ -72,16 +72,7 @@ ] } ], - "user_contract_sets": [ - { - "contract_set": { - "contract_ids": [ - "1" - ] - }, - "user": "tarkeopub1addwnpepq2res6tu0m73ulk5sepgp6g3y37schfgymxy8z6l3lc78k7ju9u45yajwem" - } - ], + "user_contract_sets": [], "version": "0" }, "auth": { @@ -273,20 +264,11 @@ } ] }, - { - "address": "tarkeo1kz2dkl8zlxwte008astc5e65htrxdcse6x3h3h", - "coins": [ - { - "amount": "97", - "denom": "uarkeo" - } - ] - }, { "address": "tarkeo1uhapc6jjq6ns0ydnk7zld5x7f5kl2ukemjw5fg", "coins": [ { - "amount": "999999899999900", + "amount": "999999899999997", "denom": "uarkeo" } ] @@ -340,6 +322,19 @@ } ] }, + "claimarkeo": { + "claim_records": [], + "module_account_balance": { + "amount": "0", + "denom": "uarkeo" + }, + "params": { + "claim_denom": "uarkeo", + "duration_of_decay": "3600s", + "duration_until_decay": "3600s", + "initial_gas_amount": null + } + }, "crisis": { "constant_fee": { "amount": "1000", diff --git a/test/regression/mnt/exports/suites_contracts_subscription.json b/test/regression/mnt/exports/suites_contracts_subscription.json index 95f8d34c..aa0f984e 100644 --- a/test/regression/mnt/exports/suites_contracts_subscription.json +++ b/test/regression/mnt/exports/suites_contracts_subscription.json @@ -31,7 +31,7 @@ "height": "2", "id": "1", "nonce": "0", - "paid": "0", + "paid": "100", "provider": "tarkeopub1addwnpepqtsg8syrpcn60t2nnvnhtk6psr8qxlrtwjk8rmpkhxk9vy9wkd8ewmqv7rh", "queries_per_minute": "1", "rate": { @@ -40,7 +40,7 @@ }, "service": 1, "settlement_duration": "11", - "settlement_height": "0", + "settlement_height": "12", "type": "SUBSCRIPTION" }, { @@ -93,16 +93,7 @@ ] } ], - "user_contract_sets": [ - { - "contract_set": { - "contract_ids": [ - "1" - ] - }, - "user": "tarkeopub1addwnpepq2res6tu0m73ulk5sepgp6g3y37schfgymxy8z6l3lc78k7ju9u45yajwem" - } - ], + "user_contract_sets": [], "version": "0" }, "auth": { @@ -268,7 +259,7 @@ "address": "tarkeo1v0n7wer498vqq6yddkr4clg3lck7kaw9lstp4k", "coins": [ { - "amount": "1000000000000018", + "amount": "1000000000000108", "denom": "uarkeo" } ] @@ -277,7 +268,7 @@ "address": "tarkeo1d0m97ywk2y4vq58ud6q5e0r3q9khj9e3unfe4t", "coins": [ { - "amount": "200000002", + "amount": "200000012", "denom": "uarkeo" } ] @@ -291,15 +282,6 @@ } ] }, - { - "address": "tarkeo1kz2dkl8zlxwte008astc5e65htrxdcse6x3h3h", - "coins": [ - { - "amount": "100", - "denom": "uarkeo" - } - ] - }, { "address": "tarkeo1uhapc6jjq6ns0ydnk7zld5x7f5kl2ukemjw5fg", "coins": [ @@ -358,6 +340,19 @@ } ] }, + "claimarkeo": { + "claim_records": [], + "module_account_balance": { + "amount": "0", + "denom": "uarkeo" + }, + "params": { + "claim_denom": "uarkeo", + "duration_of_decay": "3600s", + "duration_until_decay": "3600s", + "initial_gas_amount": null + } + }, "crisis": { "constant_fee": { "amount": "1000", @@ -708,7 +703,7 @@ "upgrade": {}, "vesting": {} }, - "app_version": "v1.0.0-prerelease", + "app_version": "v1.0.0-prerelease", "chain_id": "arkeo", "consensus": { "params": { diff --git a/test/regression/mnt/exports/suites_core_send.json b/test/regression/mnt/exports/suites_core_send.json index af064192..70b02506 100644 --- a/test/regression/mnt/exports/suites_core_send.json +++ b/test/regression/mnt/exports/suites_core_send.json @@ -215,6 +215,19 @@ } ] }, + "claimarkeo": { + "claim_records": [], + "module_account_balance": { + "amount": "0", + "denom": "uarkeo" + }, + "params": { + "claim_denom": "uarkeo", + "duration_of_decay": "3600s", + "duration_until_decay": "3600s", + "initial_gas_amount": null + } + }, "crisis": { "constant_fee": { "amount": "1000", @@ -565,7 +578,7 @@ "upgrade": {}, "vesting": {} }, - "app_version": "v1.0.0-prerelease", + "app_version": "v1.0.0-prerelease", "chain_id": "arkeo", "consensus": { "params": { diff --git a/test/regression/mnt/exports/suites_initialize.json b/test/regression/mnt/exports/suites_initialize.json index 013486d4..62ebbcdf 100644 --- a/test/regression/mnt/exports/suites_initialize.json +++ b/test/regression/mnt/exports/suites_initialize.json @@ -212,6 +212,19 @@ } ] }, + "claimarkeo": { + "claim_records": [], + "module_account_balance": { + "amount": "0", + "denom": "uarkeo" + }, + "params": { + "claim_denom": "uarkeo", + "duration_of_decay": "3600s", + "duration_until_decay": "3600s", + "initial_gas_amount": null + } + }, "crisis": { "constant_fee": { "amount": "1000", @@ -562,7 +575,7 @@ "upgrade": {}, "vesting": {} }, - "app_version": "v1.0.0-prerelease", + "app_version": "v1.0.0-prerelease", "chain_id": "arkeo", "consensus": { "params": { diff --git a/test/regression/mnt/exports/suites_providers_providers.json b/test/regression/mnt/exports/suites_providers_providers.json index 281dce64..134dcd76 100644 --- a/test/regression/mnt/exports/suites_providers_providers.json +++ b/test/regression/mnt/exports/suites_providers_providers.json @@ -226,6 +226,19 @@ } ] }, + "claimarkeo": { + "claim_records": [], + "module_account_balance": { + "amount": "0", + "denom": "uarkeo" + }, + "params": { + "claim_denom": "uarkeo", + "duration_of_decay": "3600s", + "duration_until_decay": "3600s", + "initial_gas_amount": null + } + }, "crisis": { "constant_fee": { "amount": "1000", diff --git a/test/regression/mnt/exports/suites_sentinel_contract_config.json b/test/regression/mnt/exports/suites_sentinel_contract_config.json index bd9dc320..5f4d7d96 100644 --- a/test/regression/mnt/exports/suites_sentinel_contract_config.json +++ b/test/regression/mnt/exports/suites_sentinel_contract_config.json @@ -319,6 +319,19 @@ } ] }, + "claimarkeo": { + "claim_records": [], + "module_account_balance": { + "amount": "0", + "denom": "uarkeo" + }, + "params": { + "claim_denom": "uarkeo", + "duration_of_decay": "3600s", + "duration_until_decay": "3600s", + "initial_gas_amount": null + } + }, "crisis": { "constant_fee": { "amount": "1000", diff --git a/test/regression/mnt/exports/suites_sentinel_sentinel.json b/test/regression/mnt/exports/suites_sentinel_sentinel.json index afcde25e..87936117 100644 --- a/test/regression/mnt/exports/suites_sentinel_sentinel.json +++ b/test/regression/mnt/exports/suites_sentinel_sentinel.json @@ -212,6 +212,19 @@ } ] }, + "claimarkeo": { + "claim_records": [], + "module_account_balance": { + "amount": "0", + "denom": "uarkeo" + }, + "params": { + "claim_denom": "uarkeo", + "duration_of_decay": "3600s", + "duration_until_decay": "3600s", + "initial_gas_amount": null + } + }, "crisis": { "constant_fee": { "amount": "1000", diff --git a/test/regression/suites/contracts/pay-as-you-go.yaml b/test/regression/suites/contracts/pay-as-you-go.yaml index 060f745b..1f42f3eb 100644 --- a/test/regression/suites/contracts/pay-as-you-go.yaml +++ b/test/regression/suites/contracts/pay-as-you-go.yaml @@ -236,12 +236,12 @@ description: cat account balance should increase endpoint: http://localhost:1317/cosmos/bank/v1beta1/balances/{{ addr_cat }} asserts: - .balances|length == 1 - - .balances[]|select(.denom == "uarkeo")|.amount|tonumber == 999999899999900 + - .balances[]|select(.denom == "uarkeo")|.amount|tonumber == 999999899999997 --- type: check description: ensure contract is closed endpoint: http://localhost:1317/arkeo/contract/1 asserts: - .contract.paid == "3" - - .contract.deposit == "100" ---- + - .contract.deposit == "3" +--- \ No newline at end of file diff --git a/test/regression/suites/contracts/subscription.yaml b/test/regression/suites/contracts/subscription.yaml index d90e9222..ac5c0d62 100644 --- a/test/regression/suites/contracts/subscription.yaml +++ b/test/regression/suites/contracts/subscription.yaml @@ -94,14 +94,14 @@ type: check description: ensure contract is closed endpoint: http://localhost:1317/arkeo/contract/1 asserts: - - .contract.paid == "0" + - .contract.paid == "100" --- type: check description: fox account balance should increase endpoint: http://localhost:1317/cosmos/bank/v1beta1/balances/{{ addr_fox }} asserts: - .balances|length == 1 - - .balances[]|select(.denom == "uarkeo")|.amount|tonumber == 1000000000000000 # fox gets 90 due to 10% tax to reserve + - .balances[]|select(.denom == "uarkeo")|.amount|tonumber == 1000000000000090 # fox gets 90 due to 10% tax to reserve --- type: check description: check that contract is in directory service @@ -111,8 +111,8 @@ asserts: - .client_pubkey == "tarkeopub1addwnpepq2res6tu0m73ulk5sepgp6g3y37schfgymxy8z6l3lc78k7ju9u45yajwem" - .contract_type == "SUBSCRIPTION" - .settlement_duration == 11 - - .paid == 0 - - .reserve_contrib_asset == 0 + - .paid == 100 + - .reserve_contrib_asset == 10 # - .reserve_contrib_usd == 10 # TODO --- ######################################################################################## @@ -209,7 +209,7 @@ description: fox account balance should increase endpoint: http://localhost:1317/cosmos/bank/v1beta1/balances/{{ addr_fox }} asserts: - .balances|length == 1 - - .balances[]|select(.denom == "uarkeo")|.amount|tonumber == 1000000000000018 + - .balances[]|select(.denom == "uarkeo")|.amount|tonumber == 1000000000000108 --- type: check description: ensure contract is closed @@ -225,4 +225,4 @@ asserts: - .paid == 20 - .reserve_contrib_asset == 2 # - .reserve_contrib_usd == 10 # TODO - - .settlement_duration == 11 + - .settlement_duration == 11 \ No newline at end of file From 27db8c31fced13c906bd1d04c9fa1058ba8b2f07 Mon Sep 17 00:00:00 2001 From: shreyasbhat0 Date: Tue, 17 Sep 2024 19:37:33 +0530 Subject: [PATCH 12/24] feat: update inflation handling and block reward --- api/arkeo/arkeo/params.pulsar.go | 269 +++++++++++++++++++++++++++++-- app/app.go | 33 ++-- x/arkeo/keeper/keeper.go | 57 ++++--- x/arkeo/keeper/keeper_test.go | 28 +++- x/arkeo/keeper/manager.go | 99 ++++++------ x/arkeo/keeper/manager_test.go | 25 +-- x/arkeo/types/keys.go | 14 +- 7 files changed, 412 insertions(+), 113 deletions(-) diff --git a/api/arkeo/arkeo/params.pulsar.go b/api/arkeo/arkeo/params.pulsar.go index ea521687..1a3b1573 100644 --- a/api/arkeo/arkeo/params.pulsar.go +++ b/api/arkeo/arkeo/params.pulsar.go @@ -2,7 +2,9 @@ package arkeo import ( + _ "cosmossdk.io/api/cosmos/base/v1beta1" fmt "fmt" + _ "github.com/cosmos/cosmos-proto" runtime "github.com/cosmos/cosmos-proto/runtime" _ "github.com/cosmos/gogoproto/gogoproto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" @@ -14,12 +16,18 @@ import ( ) var ( - md_Params protoreflect.MessageDescriptor + md_Params protoreflect.MessageDescriptor + fd_Params_CommunityPoolPercentage protoreflect.FieldDescriptor + fd_Params_DevFundPercentage protoreflect.FieldDescriptor + fd_Params_ValidatorRewardsPercentage protoreflect.FieldDescriptor ) func init() { file_arkeo_arkeo_params_proto_init() md_Params = File_arkeo_arkeo_params_proto.Messages().ByName("Params") + fd_Params_CommunityPoolPercentage = md_Params.Fields().ByName("CommunityPoolPercentage") + fd_Params_DevFundPercentage = md_Params.Fields().ByName("DevFundPercentage") + fd_Params_ValidatorRewardsPercentage = md_Params.Fields().ByName("ValidatorRewardsPercentage") } var _ protoreflect.Message = (*fastReflection_Params)(nil) @@ -87,6 +95,24 @@ func (x *fastReflection_Params) Interface() protoreflect.ProtoMessage { // While iterating, mutating operations may only be performed // on the current field descriptor. func (x *fastReflection_Params) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { + if x.CommunityPoolPercentage != "" { + value := protoreflect.ValueOfString(x.CommunityPoolPercentage) + if !f(fd_Params_CommunityPoolPercentage, value) { + return + } + } + if x.DevFundPercentage != "" { + value := protoreflect.ValueOfString(x.DevFundPercentage) + if !f(fd_Params_DevFundPercentage, value) { + return + } + } + if x.ValidatorRewardsPercentage != "" { + value := protoreflect.ValueOfString(x.ValidatorRewardsPercentage) + if !f(fd_Params_ValidatorRewardsPercentage, value) { + return + } + } } // Has reports whether a field is populated. @@ -102,6 +128,12 @@ func (x *fastReflection_Params) Range(f func(protoreflect.FieldDescriptor, proto // a repeated field is populated if it is non-empty. func (x *fastReflection_Params) Has(fd protoreflect.FieldDescriptor) bool { switch fd.FullName() { + case "arkeo.arkeo.Params.CommunityPoolPercentage": + return x.CommunityPoolPercentage != "" + case "arkeo.arkeo.Params.DevFundPercentage": + return x.DevFundPercentage != "" + case "arkeo.arkeo.Params.ValidatorRewardsPercentage": + return x.ValidatorRewardsPercentage != "" default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: arkeo.arkeo.Params")) @@ -118,6 +150,12 @@ func (x *fastReflection_Params) Has(fd protoreflect.FieldDescriptor) bool { // Clear is a mutating operation and unsafe for concurrent use. func (x *fastReflection_Params) Clear(fd protoreflect.FieldDescriptor) { switch fd.FullName() { + case "arkeo.arkeo.Params.CommunityPoolPercentage": + x.CommunityPoolPercentage = "" + case "arkeo.arkeo.Params.DevFundPercentage": + x.DevFundPercentage = "" + case "arkeo.arkeo.Params.ValidatorRewardsPercentage": + x.ValidatorRewardsPercentage = "" default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: arkeo.arkeo.Params")) @@ -134,6 +172,15 @@ func (x *fastReflection_Params) Clear(fd protoreflect.FieldDescriptor) { // of the value; to obtain a mutable reference, use Mutable. func (x *fastReflection_Params) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { switch descriptor.FullName() { + case "arkeo.arkeo.Params.CommunityPoolPercentage": + value := x.CommunityPoolPercentage + return protoreflect.ValueOfString(value) + case "arkeo.arkeo.Params.DevFundPercentage": + value := x.DevFundPercentage + return protoreflect.ValueOfString(value) + case "arkeo.arkeo.Params.ValidatorRewardsPercentage": + value := x.ValidatorRewardsPercentage + return protoreflect.ValueOfString(value) default: if descriptor.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: arkeo.arkeo.Params")) @@ -154,6 +201,12 @@ func (x *fastReflection_Params) Get(descriptor protoreflect.FieldDescriptor) pro // Set is a mutating operation and unsafe for concurrent use. func (x *fastReflection_Params) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { switch fd.FullName() { + case "arkeo.arkeo.Params.CommunityPoolPercentage": + x.CommunityPoolPercentage = value.Interface().(string) + case "arkeo.arkeo.Params.DevFundPercentage": + x.DevFundPercentage = value.Interface().(string) + case "arkeo.arkeo.Params.ValidatorRewardsPercentage": + x.ValidatorRewardsPercentage = value.Interface().(string) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: arkeo.arkeo.Params")) @@ -174,6 +227,12 @@ func (x *fastReflection_Params) Set(fd protoreflect.FieldDescriptor, value proto // Mutable is a mutating operation and unsafe for concurrent use. func (x *fastReflection_Params) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { switch fd.FullName() { + case "arkeo.arkeo.Params.CommunityPoolPercentage": + panic(fmt.Errorf("field CommunityPoolPercentage of message arkeo.arkeo.Params is not mutable")) + case "arkeo.arkeo.Params.DevFundPercentage": + panic(fmt.Errorf("field DevFundPercentage of message arkeo.arkeo.Params is not mutable")) + case "arkeo.arkeo.Params.ValidatorRewardsPercentage": + panic(fmt.Errorf("field ValidatorRewardsPercentage of message arkeo.arkeo.Params is not mutable")) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: arkeo.arkeo.Params")) @@ -187,6 +246,12 @@ func (x *fastReflection_Params) Mutable(fd protoreflect.FieldDescriptor) protore // For lists, maps, and messages, this returns a new, empty, mutable value. func (x *fastReflection_Params) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { switch fd.FullName() { + case "arkeo.arkeo.Params.CommunityPoolPercentage": + return protoreflect.ValueOfString("") + case "arkeo.arkeo.Params.DevFundPercentage": + return protoreflect.ValueOfString("") + case "arkeo.arkeo.Params.ValidatorRewardsPercentage": + return protoreflect.ValueOfString("") default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: arkeo.arkeo.Params")) @@ -256,6 +321,18 @@ func (x *fastReflection_Params) ProtoMethods() *protoiface.Methods { var n int var l int _ = l + l = len(x.CommunityPoolPercentage) + if l > 0 { + n += 1 + l + runtime.Sov(uint64(l)) + } + l = len(x.DevFundPercentage) + if l > 0 { + n += 1 + l + runtime.Sov(uint64(l)) + } + l = len(x.ValidatorRewardsPercentage) + if l > 0 { + n += 1 + l + runtime.Sov(uint64(l)) + } if x.unknownFields != nil { n += len(x.unknownFields) } @@ -285,6 +362,27 @@ func (x *fastReflection_Params) ProtoMethods() *protoiface.Methods { i -= len(x.unknownFields) copy(dAtA[i:], x.unknownFields) } + if len(x.ValidatorRewardsPercentage) > 0 { + i -= len(x.ValidatorRewardsPercentage) + copy(dAtA[i:], x.ValidatorRewardsPercentage) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.ValidatorRewardsPercentage))) + i-- + dAtA[i] = 0x1a + } + if len(x.DevFundPercentage) > 0 { + i -= len(x.DevFundPercentage) + copy(dAtA[i:], x.DevFundPercentage) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.DevFundPercentage))) + i-- + dAtA[i] = 0x12 + } + if len(x.CommunityPoolPercentage) > 0 { + i -= len(x.CommunityPoolPercentage) + copy(dAtA[i:], x.CommunityPoolPercentage) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.CommunityPoolPercentage))) + i-- + dAtA[i] = 0xa + } if input.Buf != nil { input.Buf = append(input.Buf, dAtA...) } else { @@ -334,6 +432,102 @@ func (x *fastReflection_Params) ProtoMethods() *protoiface.Methods { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { + case 1: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field CommunityPoolPercentage", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.CommunityPoolPercentage = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field DevFundPercentage", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.DevFundPercentage = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field ValidatorRewardsPercentage", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.ValidatorRewardsPercentage = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := runtime.Skip(dAtA[iNdEx:]) @@ -387,6 +581,10 @@ type Params struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields + + CommunityPoolPercentage string `protobuf:"bytes,1,opt,name=CommunityPoolPercentage,proto3" json:"CommunityPoolPercentage,omitempty"` + DevFundPercentage string `protobuf:"bytes,2,opt,name=DevFundPercentage,proto3" json:"DevFundPercentage,omitempty"` + ValidatorRewardsPercentage string `protobuf:"bytes,3,opt,name=ValidatorRewardsPercentage,proto3" json:"ValidatorRewardsPercentage,omitempty"` } func (x *Params) Reset() { @@ -409,24 +607,69 @@ func (*Params) Descriptor() ([]byte, []int) { return file_arkeo_arkeo_params_proto_rawDescGZIP(), []int{0} } +func (x *Params) GetCommunityPoolPercentage() string { + if x != nil { + return x.CommunityPoolPercentage + } + return "" +} + +func (x *Params) GetDevFundPercentage() string { + if x != nil { + return x.DevFundPercentage + } + return "" +} + +func (x *Params) GetValidatorRewardsPercentage() string { + if x != nil { + return x.ValidatorRewardsPercentage + } + return "" +} + var File_arkeo_arkeo_params_proto protoreflect.FileDescriptor var file_arkeo_arkeo_params_proto_rawDesc = []byte{ 0x0a, 0x18, 0x61, 0x72, 0x6b, 0x65, 0x6f, 0x2f, 0x61, 0x72, 0x6b, 0x65, 0x6f, 0x2f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0b, 0x61, 0x72, 0x6b, 0x65, 0x6f, 0x2e, 0x61, 0x72, 0x6b, 0x65, 0x6f, 0x1a, 0x14, 0x67, 0x6f, 0x67, 0x6f, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x2f, 0x67, 0x6f, 0x67, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x0e, 0x0a, - 0x06, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x3a, 0x04, 0x98, 0xa0, 0x1f, 0x00, 0x42, 0x89, 0x01, - 0x0a, 0x0f, 0x63, 0x6f, 0x6d, 0x2e, 0x61, 0x72, 0x6b, 0x65, 0x6f, 0x2e, 0x61, 0x72, 0x6b, 0x65, - 0x6f, 0x42, 0x0b, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, - 0x5a, 0x1c, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, - 0x70, 0x69, 0x2f, 0x61, 0x72, 0x6b, 0x65, 0x6f, 0x2f, 0x61, 0x72, 0x6b, 0x65, 0x6f, 0xa2, 0x02, - 0x03, 0x41, 0x41, 0x58, 0xaa, 0x02, 0x0b, 0x41, 0x72, 0x6b, 0x65, 0x6f, 0x2e, 0x41, 0x72, 0x6b, - 0x65, 0x6f, 0xca, 0x02, 0x0b, 0x41, 0x72, 0x6b, 0x65, 0x6f, 0x5c, 0x41, 0x72, 0x6b, 0x65, 0x6f, - 0xe2, 0x02, 0x17, 0x41, 0x72, 0x6b, 0x65, 0x6f, 0x5c, 0x41, 0x72, 0x6b, 0x65, 0x6f, 0x5c, 0x47, - 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x0c, 0x41, 0x72, 0x6b, - 0x65, 0x6f, 0x3a, 0x3a, 0x41, 0x72, 0x6b, 0x65, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x33, + 0x74, 0x6f, 0x2f, 0x67, 0x6f, 0x67, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1e, 0x63, + 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x62, 0x61, 0x73, 0x65, 0x2f, 0x76, 0x31, 0x62, 0x65, 0x74, + 0x61, 0x31, 0x2f, 0x63, 0x6f, 0x69, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x19, 0x63, + 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x63, 0x6f, 0x73, 0x6d, + 0x6f, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xe1, 0x02, 0x0a, 0x06, 0x50, 0x61, 0x72, + 0x61, 0x6d, 0x73, 0x12, 0x71, 0x0a, 0x17, 0x43, 0x6f, 0x6d, 0x6d, 0x75, 0x6e, 0x69, 0x74, 0x79, + 0x50, 0x6f, 0x6f, 0x6c, 0x50, 0x65, 0x72, 0x63, 0x65, 0x6e, 0x74, 0x61, 0x67, 0x65, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x42, 0x37, 0xc8, 0xde, 0x1f, 0x00, 0xda, 0xde, 0x1f, 0x1b, 0x63, 0x6f, + 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x6d, 0x61, 0x74, 0x68, 0x2e, + 0x4c, 0x65, 0x67, 0x61, 0x63, 0x79, 0x44, 0x65, 0x63, 0xd2, 0xb4, 0x2d, 0x10, 0x63, 0x6f, 0x73, + 0x6d, 0x6f, 0x73, 0x2e, 0x4c, 0x65, 0x67, 0x61, 0x63, 0x79, 0x44, 0x65, 0x63, 0x52, 0x17, 0x43, + 0x6f, 0x6d, 0x6d, 0x75, 0x6e, 0x69, 0x74, 0x79, 0x50, 0x6f, 0x6f, 0x6c, 0x50, 0x65, 0x72, 0x63, + 0x65, 0x6e, 0x74, 0x61, 0x67, 0x65, 0x12, 0x65, 0x0a, 0x11, 0x44, 0x65, 0x76, 0x46, 0x75, 0x6e, + 0x64, 0x50, 0x65, 0x72, 0x63, 0x65, 0x6e, 0x74, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x09, 0x42, 0x37, 0xc8, 0xde, 0x1f, 0x00, 0xda, 0xde, 0x1f, 0x1b, 0x63, 0x6f, 0x73, 0x6d, 0x6f, + 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x6d, 0x61, 0x74, 0x68, 0x2e, 0x4c, 0x65, 0x67, + 0x61, 0x63, 0x79, 0x44, 0x65, 0x63, 0xd2, 0xb4, 0x2d, 0x10, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, + 0x2e, 0x4c, 0x65, 0x67, 0x61, 0x63, 0x79, 0x44, 0x65, 0x63, 0x52, 0x11, 0x44, 0x65, 0x76, 0x46, + 0x75, 0x6e, 0x64, 0x50, 0x65, 0x72, 0x63, 0x65, 0x6e, 0x74, 0x61, 0x67, 0x65, 0x12, 0x77, 0x0a, + 0x1a, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x52, 0x65, 0x77, 0x61, 0x72, 0x64, + 0x73, 0x50, 0x65, 0x72, 0x63, 0x65, 0x6e, 0x74, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x09, 0x42, 0x37, 0xc8, 0xde, 0x1f, 0x00, 0xda, 0xde, 0x1f, 0x1b, 0x63, 0x6f, 0x73, 0x6d, 0x6f, + 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x6d, 0x61, 0x74, 0x68, 0x2e, 0x4c, 0x65, 0x67, + 0x61, 0x63, 0x79, 0x44, 0x65, 0x63, 0xd2, 0xb4, 0x2d, 0x10, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, + 0x2e, 0x4c, 0x65, 0x67, 0x61, 0x63, 0x79, 0x44, 0x65, 0x63, 0x52, 0x1a, 0x56, 0x61, 0x6c, 0x69, + 0x64, 0x61, 0x74, 0x6f, 0x72, 0x52, 0x65, 0x77, 0x61, 0x72, 0x64, 0x73, 0x50, 0x65, 0x72, 0x63, + 0x65, 0x6e, 0x74, 0x61, 0x67, 0x65, 0x3a, 0x04, 0x98, 0xa0, 0x1f, 0x00, 0x42, 0x89, 0x01, 0x0a, + 0x0f, 0x63, 0x6f, 0x6d, 0x2e, 0x61, 0x72, 0x6b, 0x65, 0x6f, 0x2e, 0x61, 0x72, 0x6b, 0x65, 0x6f, + 0x42, 0x0b, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, + 0x1c, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, + 0x69, 0x2f, 0x61, 0x72, 0x6b, 0x65, 0x6f, 0x2f, 0x61, 0x72, 0x6b, 0x65, 0x6f, 0xa2, 0x02, 0x03, + 0x41, 0x41, 0x58, 0xaa, 0x02, 0x0b, 0x41, 0x72, 0x6b, 0x65, 0x6f, 0x2e, 0x41, 0x72, 0x6b, 0x65, + 0x6f, 0xca, 0x02, 0x0b, 0x41, 0x72, 0x6b, 0x65, 0x6f, 0x5c, 0x41, 0x72, 0x6b, 0x65, 0x6f, 0xe2, + 0x02, 0x17, 0x41, 0x72, 0x6b, 0x65, 0x6f, 0x5c, 0x41, 0x72, 0x6b, 0x65, 0x6f, 0x5c, 0x47, 0x50, + 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x0c, 0x41, 0x72, 0x6b, 0x65, + 0x6f, 0x3a, 0x3a, 0x41, 0x72, 0x6b, 0x65, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/app/app.go b/app/app.go index 0f5de57d..b7579ccb 100644 --- a/app/app.go +++ b/app/app.go @@ -200,22 +200,22 @@ var ( // module account permissions maccPerms = map[string][]string{ - authtypes.FeeCollectorName: nil, - distrtypes.ModuleName: nil, - icatypes.ModuleName: nil, - minttypes.ModuleName: {authtypes.Minter}, - stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, - stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, - govtypes.ModuleName: {authtypes.Burner}, - ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, - claimmoduletypes.ModuleName: {authtypes.Minter}, - arkeomoduletypes.ModuleName: {}, - arkeomoduletypes.ReserveName: {}, - arkeomoduletypes.ProviderName: {}, - arkeomoduletypes.ContractName: {}, - arkeomoduletypes.DevFundPool: {authtypes.Minter, authtypes.Burner}, - arkeomoduletypes.CommunityPool: {authtypes.Minter, authtypes.Burner}, - arkeomoduletypes.ValidatorRewardPool: {authtypes.Minter, authtypes.Burner}, + authtypes.FeeCollectorName: nil, + distrtypes.ModuleName: nil, + icatypes.ModuleName: nil, + minttypes.ModuleName: {authtypes.Minter}, + stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, + stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, + govtypes.ModuleName: {authtypes.Burner}, + ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, + claimmoduletypes.ModuleName: {authtypes.Minter}, + arkeomoduletypes.ModuleName: {}, + arkeomoduletypes.ReserveName: {}, + arkeomoduletypes.ProviderName: {}, + arkeomoduletypes.ContractName: {}, + arkeomoduletypes.DevFundPool: {authtypes.Minter}, + arkeomoduletypes.CommunityPool: {authtypes.Minter}, + arkeomoduletypes.GrantPool: {authtypes.Minter}, } ) @@ -597,6 +597,7 @@ func NewArkeoApp( *app.Keepers.StakingKeeper, govModuleAddr, logger, + app.Keepers.MintKeeper, ) /**** Module Options ****/ diff --git a/x/arkeo/keeper/keeper.go b/x/arkeo/keeper/keeper.go index a41ae688..1ff0295d 100644 --- a/x/arkeo/keeper/keeper.go +++ b/x/arkeo/keeper/keeper.go @@ -7,6 +7,7 @@ import ( "cosmossdk.io/errors" "cosmossdk.io/log" + "cosmossdk.io/math" sdkmath "cosmossdk.io/math" storetypes "cosmossdk.io/store/types" "github.com/arkeonetwork/arkeo/common" @@ -18,6 +19,8 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + minttypes "github.com/cosmos/cosmos-sdk/x/mint/keeper" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -58,8 +61,9 @@ type Keeper interface { GetActiveValidators(ctx cosmos.Context) ([]stakingtypes.Validator, error) GetAccount(ctx cosmos.Context, addr cosmos.AccAddress) cosmos.Account StakingSetParams(ctx cosmos.Context, params stakingtypes.Params) error - MintAndDistributeTokens(ctx cosmos.Context, newlyMinted cosmos.Coin) error - GetCirculatingSupply(ctx cosmos.Context, denom string) cosmos.Coin + MintAndDistributeTokens(ctx cosmos.Context, newlyMinted cosmos.Coin) (cosmos.Coin, error) + GetCirculatingSupply(ctx cosmos.Context, denom string) (cosmos.Coin, error) + GetInflationRate(ctx cosmos.Context) (math.LegacyDec, error) // Query Params(c context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) @@ -121,6 +125,7 @@ type KVStore struct { stakingKeeper stakingkeeper.Keeper authority string logger log.Logger + mintKeeper minttypes.Keeper } func NewKVStore( @@ -140,6 +145,7 @@ func NewKVStore( stakingKeeper stakingkeeper.Keeper, authority string, logger log.Logger, + mintKeeper minttypes.Keeper, ) *KVStore { // set KeyTable if it has not already been set if !ps.HasKeyTable() { @@ -156,6 +162,7 @@ func NewKVStore( stakingKeeper: stakingKeeper, authority: authority, logger: logger, + mintKeeper: mintKeeper, } } @@ -370,29 +377,37 @@ func (k KVStore) GetAuthority() string { return k.authority } -func (k KVStore) GetCirculatingSupply(ctx cosmos.Context, denom string) cosmos.Coin { +func (k KVStore) GetCirculatingSupply(ctx cosmos.Context, denom string) (cosmos.Coin, error) { - // Get the total token supply of the given token - totalSupply := k.coinKeeper.GetSupply(ctx, denom) + sdkContext := sdk.UnwrapSDKContext(ctx) + + // Get Total Supply + fullTokenSupply, err := k.coinKeeper.TotalSupply(ctx, &banktypes.QueryTotalSupplyRequest{}) + if err != nil { + sdkContext.Logger().Error("Failed to get full token supply data", err) + return cosmos.NewCoin(denom, sdkmath.NewInt(0)), err + } + totalSupply := fullTokenSupply.Supply.AmountOf(configs.Denom) + sdkContext.Logger().Error("Current supply of token with denom :", denom, "supply:", totalSupply) // Module Address for which the circulating supply should be exempted - exemptModules := []string{types.ValidatorRewardPool, types.CommunityPool, types.DevFundPool} + modulesToExempt := []string{types.GrantPool, types.CommunityPool, types.DevFundPool} exemptBalance := cosmos.NewInt(0) // range over the module and create exempt balances - for _, moduleName := range exemptModules { + for _, moduleName := range modulesToExempt { moduleAddr := k.accountKeeper.GetModuleAddress(moduleName) moduleBalance := k.coinKeeper.GetBalance(ctx, moduleAddr, denom) exemptBalance = exemptBalance.Add(moduleBalance.Amount) } - // get the circulating supply - circulatingSupply := totalSupply.Amount.Sub(exemptBalance) + // total supply without balances of exempted module + circulatingSupply := totalSupply.Sub(exemptBalance) - return cosmos.NewCoin(denom, circulatingSupply) + return cosmos.NewCoin(denom, circulatingSupply), nil } -func (k KVStore) MintAndDistributeTokens(ctx cosmos.Context, newlyMinted cosmos.Coin) error { +func (k KVStore) MintAndDistributeTokens(ctx cosmos.Context, newlyMinted cosmos.Coin) (cosmos.Coin, error) { params := k.GetParams(ctx) @@ -400,20 +415,26 @@ func (k KVStore) MintAndDistributeTokens(ctx cosmos.Context, newlyMinted cosmos. devFundAmount := newlyMintedDec.Mul(params.DevFundPercentage).TruncateInt() communityPoolAmount := newlyMintedDec.Mul(params.CommunityPoolPercentage).TruncateInt() - validatorRewardAmount := newlyMintedDec.Mul(params.ValidatorRewardsPercentage).TruncateInt() + // validatorRewardAmount := newlyMintedDec.Mul(params.ValidatorRewardsPercentage).TruncateInt() if err := k.MintToModule(ctx, types.DevFundPool, cosmos.NewCoin(newlyMinted.Denom, devFundAmount)); err != nil { - return fmt.Errorf("error sending amount to module %s", err) + return cosmos.NewCoin(configs.Denom, sdkmath.NewInt(0)), fmt.Errorf("error sending amount to module %s", err) } if err := k.MintToModule(ctx, types.CommunityPool, cosmos.NewCoin(newlyMinted.Denom, communityPoolAmount)); err != nil { - return fmt.Errorf("error sending amount to module %s", err) + return cosmos.NewCoin(configs.Denom, sdkmath.NewInt(0)), fmt.Errorf("error sending amount to module %s", err) } + balance := newlyMintedDec.Sub(sdkmath.LegacyDec(devFundAmount)).Sub(sdkmath.LegacyDec(communityPoolAmount)) - if err := k.MintToModule(ctx, types.ValidatorRewardPool, cosmos.NewCoin(newlyMinted.Denom, validatorRewardAmount)); err != nil { - return fmt.Errorf("error sending amount to module %s", err) - } + return cosmos.NewCoin(configs.Denom, balance.RoundInt()), nil - return nil +} + +func (k KVStore) GetInflationRate(ctx cosmos.Context) (math.LegacyDec, error) { + minter, err := k.mintKeeper.Minter.Get(ctx) + if err != nil { + return math.LegacyNewDec(0), err + } + return minter.Inflation, nil } diff --git a/x/arkeo/keeper/keeper_test.go b/x/arkeo/keeper/keeper_test.go index f8d00325..d7ee0f31 100644 --- a/x/arkeo/keeper/keeper_test.go +++ b/x/arkeo/keeper/keeper_test.go @@ -25,6 +25,8 @@ import ( bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper" + minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" typesparams "github.com/cosmos/cosmos-sdk/x/params/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" @@ -51,6 +53,7 @@ func SetupKeeper(t testing.TB) (cosmos.Context, Keeper) { keyBank := cosmos.NewKVStoreKey(banktypes.StoreKey) keyStake := cosmos.NewKVStoreKey(stakingtypes.StoreKey) keyParams := cosmos.NewKVStoreKey(typesparams.StoreKey) + keyMint := cosmos.NewKVStoreKey(minttypes.StoreKey) tkeyParams := cosmos.NewTransientStoreKey(typesparams.TStoreKey) memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey) @@ -124,6 +127,16 @@ func SetupKeeper(t testing.TB) (cosmos.Context, Keeper) { authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()), ) + mk := mintkeeper.NewKeeper( + cdc, + runtime.NewKVStoreService(keyMint), + sk, + ak, + bk, + authtypes.FeeCollectorName, + govModuleAddr, + ) + k := NewKVStore( cdc, storeKey, @@ -134,6 +147,7 @@ func SetupKeeper(t testing.TB) (cosmos.Context, Keeper) { *sk, govModuleAddr, logger, + mk, ) k.SetVersion(ctx, common.GetCurrentVersion()) @@ -147,6 +161,7 @@ func SetupKeeperWithStaking(t testing.TB) (cosmos.Context, Keeper, stakingkeeper storeKey := storetypes.NewKVStoreKey(types.StoreKey) keyAcc := cosmos.NewKVStoreKey(authtypes.StoreKey) keyBank := cosmos.NewKVStoreKey(banktypes.StoreKey) + keyMint := cosmos.NewKVStoreKey(minttypes.StoreKey) keyStake := cosmos.NewKVStoreKey(stakingtypes.StoreKey) keyParams := cosmos.NewKVStoreKey(typesparams.StoreKey) tkeyParams := cosmos.NewTransientStoreKey(typesparams.TStoreKey) @@ -199,7 +214,7 @@ func SetupKeeperWithStaking(t testing.TB) (cosmos.Context, Keeper, stakingkeeper types.ContractName: {}, govtypes.ModuleName: {authtypes.Minter, authtypes.Burner}, types.DevFundPool: {authtypes.Minter, authtypes.Burner}, - types.ValidatorRewardPool: {authtypes.Minter, authtypes.Burner}, + types.GrantPool: {authtypes.Minter, authtypes.Burner}, types.CommunityPool: {authtypes.Minter, authtypes.Burner}, }, authcodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()), @@ -227,6 +242,16 @@ func SetupKeeperWithStaking(t testing.TB) (cosmos.Context, Keeper, stakingkeeper authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()), ) + mk := mintkeeper.NewKeeper( + cdc, + runtime.NewKVStoreService(keyMint), + sk, + ak, + bk, + authtypes.FeeCollectorName, + govModuleAddr, + ) + k := NewKVStore( cdc, storeKey, @@ -237,6 +262,7 @@ func SetupKeeperWithStaking(t testing.TB) (cosmos.Context, Keeper, stakingkeeper *sk, govModuleAddr, logger, + mk, ) k.SetVersion(ctx, common.GetCurrentVersion()) diff --git a/x/arkeo/keeper/manager.go b/x/arkeo/keeper/manager.go index 9d2ee149..2b0b65f1 100644 --- a/x/arkeo/keeper/manager.go +++ b/x/arkeo/keeper/manager.go @@ -4,9 +4,9 @@ import ( "fmt" "cosmossdk.io/errors" + sdkmath "cosmossdk.io/math" abci "github.com/cometbft/cometbft/abci/types" cmptm "github.com/cometbft/cometbft/proto/tendermint/types" - mintTypes "github.com/cosmos/cosmos-sdk/x/mint/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" "github.com/arkeonetwork/arkeo/common" @@ -18,7 +18,6 @@ import ( type Manager struct { keeper Keeper sk stakingkeeper.Keeper - mk mintTypes.BankKeeper } func NewManager(k Keeper, sk stakingkeeper.Keeper) Manager { @@ -54,7 +53,20 @@ func (mgr *Manager) BeginBlock(ctx cosmos.Context) error { } votes = append(votes, abciVote) } - if err := mgr.ValidatorPayout(ctx, votes); err != nil { + + // Get the circulating supply after calculating inflation + circSupply, err := mgr.circulatingSupplyAfterInflationCalc(ctx) + if err != nil { + ctx.Logger().Error("unable to get supply with inflation calculation", "error", err) + } + + // Calculate Block Rewards + blockReward := mgr.calcBlockReward(ctx, circSupply.Amount.Int64()) + + // Distribute Minted To Pools + afterDistribution, err := mgr.keeper.MintAndDistributeTokens(ctx, blockReward) + + if err := mgr.ValidatorPayout(ctx, votes, afterDistribution); err != nil { ctx.Logger().Error("unable to settle contracts", "error", err) } return nil @@ -188,52 +200,30 @@ func (mgr Manager) ContractEndBlock(ctx cosmos.Context) error { // units = U / (T / t) // Since the development goal at the moment is to get this chain up and // running, we can save this optimization for another day. -func (mgr Manager) ValidatorPayout(ctx cosmos.Context, votes []abci.VoteInfo) error { +func (mgr Manager) ValidatorPayout(ctx cosmos.Context, votes []abci.VoteInfo, blockReward cosmos.Coin) error { valCycle := mgr.FetchConfig(ctx, configs.ValidatorPayoutCycle) if valCycle == 0 || ctx.BlockHeight()%valCycle != 0 { return nil } - circulatingSupply := mgr.keeper.GetCirculatingSupply(ctx, configs.Denom) - - emissionCurve := mgr.FetchConfig(ctx, configs.EmissionCurve) - blocksPerYear := mgr.FetchConfig(ctx, configs.BlocksPerYear) - - blockRewards := mgr.calcBlockReward(circulatingSupply.Amount.Int64(), emissionCurve, (blocksPerYear / valCycle)) - - if blockRewards.IsZero() { + if blockReward.IsZero() { return nil } - newlyMintedCoins := cosmos.NewCoin(configs.Denom, blockRewards) - - if err := mgr.keeper.MintAndDistributeTokens(ctx, newlyMintedCoins); err != nil { - ctx.Logger().Error("failed to mint and distribute tokens", "error", err) - return err - } - - validatorRewardPoolAddr := mgr.keeper.GetModuleAccAddress(types.ValidatorRewardPool) - validatorRewards := mgr.keeper.GetBalance(ctx, validatorRewardPoolAddr) - validatorRewardAmount := validatorRewards.AmountOf(configs.Denom) - - totalShares := cosmos.ZeroInt() - + // sum tokens + total := cosmos.ZeroInt() for _, vote := range votes { val, err := mgr.sk.ValidatorByConsAddr(ctx, vote.Validator.Address) - if err != nil { ctx.Logger().Info("unable to find validator", "validator", string(vote.Validator.Address)) continue } - if !val.IsBonded() || val.IsJailed() { continue } - - totalShares = totalShares.Add(val.GetDelegatorShares().RoundInt()) + total = total.Add(val.GetDelegatorShares().RoundInt()) } - - if totalShares.IsZero() { + if total.IsZero() { return nil } @@ -250,14 +240,13 @@ func (mgr Manager) ValidatorPayout(ctx cosmos.Context, votes []abci.VoteInfo) er continue } if !val.IsBonded() || val.IsJailed() { - ctx.Logger().Info("validator rewards skipped due to status or jailed", string(val.GetOperator())) + ctx.Logger().Info("validator rewards skipped due to status or jailed", "validator", val.GetOperator()) continue } valBz, err := mgr.sk.ValidatorAddressCodec().StringToBytes(val.GetOperator()) if err != nil { - ctx.Logger().Error("failed to decode validator address", "validator", string(val.GetOperator()), "error", err) - continue + panic(err) } valVersion := mgr.keeper.GetVersionForAddress(ctx, valBz) @@ -267,19 +256,16 @@ func (mgr Manager) ValidatorPayout(ctx cosmos.Context, votes []abci.VoteInfo) er } acc := cosmos.AccAddress(val.GetOperator()) - totalReward := common.GetSafeShare(val.GetDelegatorShares().RoundInt(), totalShares, validatorRewardAmount) + totalReward := common.GetSafeShare(val.GetDelegatorShares().RoundInt(), total, blockReward.Amount) validatorReward := cosmos.ZeroInt() rateBasisPts := val.GetCommission().MulInt64(100).RoundInt() delegates, err := mgr.sk.GetValidatorDelegations(ctx, valBz) - if err != nil { - ctx.Logger().Error("unable to fetch delegations for validator", "validator", val.GetOperator(), "error", err) - continue + panic(err) } for _, delegate := range delegates { - delegateAcc, err := cosmos.AccAddressFromBech32(delegate.DelegatorAddress) if err != nil { ctx.Logger().Error("unable to fetch delegate address", "delegate", delegate.DelegatorAddress, "error", err) @@ -290,18 +276,15 @@ func (mgr Manager) ValidatorPayout(ctx cosmos.Context, votes []abci.VoteInfo) er valFee := common.GetSafeShare(rateBasisPts, cosmos.NewInt(configs.MaxBasisPoints), delegateReward) delegateReward = delegateReward.Sub(valFee) validatorReward = validatorReward.Add(valFee) - } - - if err := mgr.keeper.SendFromModuleToAccount(ctx, types.ValidatorRewardPool, delegateAcc, cosmos.NewCoins(cosmos.NewCoin(configs.Denom, delegateReward))); err != nil { + if err := mgr.keeper.SendFromModuleToAccount(ctx, types.ReserveName, delegateAcc, cosmos.NewCoins(cosmos.NewCoin(blockReward.Denom, delegateReward))); err != nil { ctx.Logger().Error("unable to pay rewards to delegate", "delegate", delegate.DelegatorAddress, "error", err) } - ctx.Logger().Info("delegate rewarded", "delegate", delegateAcc.String(), "amount", delegateReward) } if !validatorReward.IsZero() { - if err := mgr.keeper.SendFromModuleToAccount(ctx, types.ValidatorRewardPool, acc, cosmos.NewCoins(cosmos.NewCoin(configs.Denom, validatorReward))); err != nil { + if err := mgr.keeper.SendFromModuleToAccount(ctx, types.ReserveName, acc, cosmos.NewCoins(cosmos.NewCoin(blockReward.Denom, validatorReward))); err != nil { ctx.Logger().Error("unable to pay rewards to validator", "validator", val.GetOperator(), "error", err) continue } @@ -312,19 +295,24 @@ func (mgr Manager) ValidatorPayout(ctx cosmos.Context, votes []abci.VoteInfo) er ctx.Logger().Error("unable to emit validator payout event", "validator", acc.String(), "error", err) } } + return nil } -func (mgr Manager) calcBlockReward(totalReserve, emissionCurve, blocksPerYear int64) cosmos.Int { +func (mgr Manager) calcBlockReward(ctx cosmos.Context, totalReserve int64) cosmos.Coin { + + emissionCurve := mgr.FetchConfig(ctx, configs.EmissionCurve) // Emission curve factor + blocksPerYear := mgr.FetchConfig(ctx, configs.BlocksPerYear) + // Block Rewards will take the latest reserve, divide it by the emission // curve factor, then divide by blocks per year if emissionCurve == 0 || blocksPerYear == 0 { - return cosmos.ZeroInt() + return cosmos.NewCoin(configs.Denom, sdkmath.NewInt(0)) } trD := cosmos.NewDec(totalReserve) ecD := cosmos.NewDec(emissionCurve) bpyD := cosmos.NewDec(blocksPerYear) - return trD.Quo(ecD).Quo(bpyD).RoundInt() + return cosmos.NewCoin(configs.Denom, trD.Quo(ecD).Quo(bpyD).RoundInt()) } func (mgr Manager) FetchConfig(ctx cosmos.Context, name configs.ConfigName) int64 { @@ -420,3 +408,20 @@ func (mgr Manager) contractDebt(ctx cosmos.Context, contract types.Contract) (co return debt, nil } + +func (mgr Manager) circulatingSupplyAfterInflationCalc(ctx cosmos.Context) (cosmos.Coin, error) { + + circulatingSupply, err := mgr.keeper.GetCirculatingSupply(ctx, configs.Denom) + + if err != nil { + return cosmos.NewCoin(configs.Denom, sdkmath.NewInt(0)), err + } + inflationRate, err := mgr.keeper.GetInflationRate(ctx) + if err != nil { + return cosmos.NewCoin(configs.Denom, sdkmath.NewInt(0)), err + } + + newTokenAmountMinted := circulatingSupply.Amount.ToLegacyDec().Mul(sdkmath.LegacyDec(inflationRate.TruncateInt())) + + return cosmos.NewCoin(configs.Denom, newTokenAmountMinted.RoundInt()), nil +} diff --git a/x/arkeo/keeper/manager_test.go b/x/arkeo/keeper/manager_test.go index da6bda59..eaa810d4 100644 --- a/x/arkeo/keeper/manager_test.go +++ b/x/arkeo/keeper/manager_test.go @@ -354,8 +354,11 @@ func TestValidatorPayouts(t *testing.T) { require.NoError(t, sk.SetDelegation(ctx, del3)) // Mint initial funds to the reserve - require.NoError(t, k.MintToModule(ctx, types.ModuleName, getCoin(common.Tokens(50000)))) - require.NoError(t, k.SendFromModuleToModule(ctx, types.ModuleName, types.ReserveName, getCoins(common.Tokens(50000)))) + require.NoError(t, k.MintToModule(ctx, types.ModuleName, getCoin(common.Tokens(200000)))) + exemptModules := []string{types.GrantPool, types.CommunityPool, types.DevFundPool} + for _, modules := range exemptModules { + require.NoError(t, k.SendFromModuleToModule(ctx, types.ModuleName, modules, getCoins(common.Tokens(50000)))) + } // Set parameters for payouts params := types.DefaultParams() @@ -391,17 +394,17 @@ func TestValidatorPayouts(t *testing.T) { // Expected block reward calculation - validatorRewardPoolAddr := mgr.keeper.GetModuleAccAddress(types.ValidatorRewardPool) - fmt.Println(k.GetBalance(ctx, validatorRewardPoolAddr)) + // validatorRewardPoolAddr := mgr.keeper.GetModuleAccAddress(types.ValidatorRewardPool) + // fmt.Println(k.GetBalance(ctx, validatorRewardPoolAddr)) - require.NoError(t, mgr.ValidatorPayout(ctx, votes)) + // require.NoError(t, mgr.ValidatorPayout(ctx, votes,)) - validatorRewardPoolAddr = mgr.keeper.GetModuleAccAddress(types.ValidatorRewardPool) - fmt.Println(k.GetBalance(ctx, validatorRewardPoolAddr).AmountOf(configs.Denom)) + // validatorRewardPoolAddr = mgr.keeper.GetModuleAccAddress(types.ValidatorRewardPool) + // fmt.Println(k.GetBalance(ctx, validatorRewardPoolAddr).AmountOf(configs.Denom)) // Verify the remaining balance after distribution - expectedRemaining := 5000000000000 - k.GetBalance(ctx, validatorRewardPoolAddr).AmountOf(configs.Denom).Int64() - require.Equal(t, k.GetBalanceOfModule(ctx, types.ReserveName, configs.Denom).Int64(), expectedRemaining) + // expectedRemaining := 5000000000000 - k.GetBalance(ctx, validatorRewardPoolAddr).AmountOf(configs.Denom).Int64() + // require.Equal(t, k.GetBalanceOfModule(ctx, types.ReserveName, configs.Denom).Int64(), expectedRemaining) totalBal := cosmos.ZeroInt() @@ -417,8 +420,8 @@ func TestValidatorPayouts(t *testing.T) { fmt.Println(sdkmath.NewInt(110970).Sub(totalBal)) - validatorRewardPoolAddr = mgr.keeper.GetModuleAccAddress(types.ValidatorRewardPool) - fmt.Println("Val", k.GetBalance(ctx, validatorRewardPoolAddr).AmountOf(configs.Denom)) + // validatorRewardPoolAddr = mgr.keeper.GetModuleAccAddress(types.ValidatorRewardPool) + // fmt.Println("Val", k.GetBalance(ctx, validatorRewardPoolAddr).AmountOf(configs.Denom)) // Ensure the total block reward equals the sum of all payouts require.Equal(t, validatorRewardAmount.Int64(), int64(110970)) diff --git a/x/arkeo/types/keys.go b/x/arkeo/types/keys.go index 21cd9c7e..a2d97c97 100644 --- a/x/arkeo/types/keys.go +++ b/x/arkeo/types/keys.go @@ -2,13 +2,13 @@ package types const ( // ModuleName defines the module name - ModuleName = "arkeo" - ReserveName = "arkeo-reserve" - ProviderName = "providers" - ContractName = "contracts" - DevFundPool = "dev-fund" - CommunityPool = "community-fund" - ValidatorRewardPool = "validator-fund" + ModuleName = "arkeo" + ReserveName = "arkeo-reserve" + ProviderName = "providers" + ContractName = "contracts" + DevFundPool = "devpool" + CommunityPool = "communitypool" + GrantPool = "grantpool" // StoreKey defines the primary module store key StoreKey = ModuleName From 0f4b4674b78ec2e266817890cb7be8685cbd3d80 Mon Sep 17 00:00:00 2001 From: shreyasbhat0 Date: Tue, 17 Sep 2024 19:45:00 +0530 Subject: [PATCH 13/24] fix: regression testing --- app/app_regtest.go | 1 + .../mnt/exports/suites_contracts_pay-as-you-go.json | 6 +++++- .../mnt/exports/suites_contracts_subscription.json | 6 +++++- test/regression/mnt/exports/suites_core_send.json | 6 +++++- test/regression/mnt/exports/suites_initialize.json | 6 +++++- test/regression/mnt/exports/suites_providers_providers.json | 6 +++++- .../mnt/exports/suites_sentinel_contract_config.json | 6 +++++- test/regression/mnt/exports/suites_sentinel_sentinel.json | 6 +++++- 8 files changed, 36 insertions(+), 7 deletions(-) diff --git a/app/app_regtest.go b/app/app_regtest.go index 99c122c1..73a73d8c 100644 --- a/app/app_regtest.go +++ b/app/app_regtest.go @@ -602,6 +602,7 @@ func NewArkeoApp( *app.Keepers.StakingKeeper, govModuleAddr, logger, + app.Keepers.MintKeeper, ) arkeoModule := arkeomodule.NewAppModule(appCodec, app.ArkeoKeeper, app.Keepers.AccountKeeper, app.Keepers.BankKeeper, *app.Keepers.StakingKeeper) diff --git a/test/regression/mnt/exports/suites_contracts_pay-as-you-go.json b/test/regression/mnt/exports/suites_contracts_pay-as-you-go.json index d5acf54d..c12f212c 100644 --- a/test/regression/mnt/exports/suites_contracts_pay-as-you-go.json +++ b/test/regression/mnt/exports/suites_contracts_pay-as-you-go.json @@ -45,7 +45,11 @@ } ], "next_contract_id": "2", - "params": {}, + "params": { + "CommunityPoolPercentage": "0.100000000000000000", + "DevFundPercentage": "0.200000000000000000", + "ValidatorRewardsPercentage": "0.700000000000000000" + }, "providers": [ { "bond": "1000000000000", diff --git a/test/regression/mnt/exports/suites_contracts_subscription.json b/test/regression/mnt/exports/suites_contracts_subscription.json index aa0f984e..311396e8 100644 --- a/test/regression/mnt/exports/suites_contracts_subscription.json +++ b/test/regression/mnt/exports/suites_contracts_subscription.json @@ -66,7 +66,11 @@ } ], "next_contract_id": "3", - "params": {}, + "params": { + "CommunityPoolPercentage": "0.100000000000000000", + "DevFundPercentage": "0.200000000000000000", + "ValidatorRewardsPercentage": "0.700000000000000000" + }, "providers": [ { "bond": "1000000000000", diff --git a/test/regression/mnt/exports/suites_core_send.json b/test/regression/mnt/exports/suites_core_send.json index 70b02506..36c0933d 100644 --- a/test/regression/mnt/exports/suites_core_send.json +++ b/test/regression/mnt/exports/suites_core_send.json @@ -6,7 +6,11 @@ "contract_expiration_sets": [], "contracts": [], "next_contract_id": "1", - "params": {}, + "params": { + "CommunityPoolPercentage": "0.100000000000000000", + "DevFundPercentage": "0.200000000000000000", + "ValidatorRewardsPercentage": "0.700000000000000000" + }, "providers": [], "user_contract_sets": [], "version": "0" diff --git a/test/regression/mnt/exports/suites_initialize.json b/test/regression/mnt/exports/suites_initialize.json index 62ebbcdf..d4e65ad6 100644 --- a/test/regression/mnt/exports/suites_initialize.json +++ b/test/regression/mnt/exports/suites_initialize.json @@ -6,7 +6,11 @@ "contract_expiration_sets": [], "contracts": [], "next_contract_id": "1", - "params": {}, + "params": { + "CommunityPoolPercentage": "0.100000000000000000", + "DevFundPercentage": "0.200000000000000000", + "ValidatorRewardsPercentage": "0.700000000000000000" + }, "providers": [], "user_contract_sets": [], "version": "0" diff --git a/test/regression/mnt/exports/suites_providers_providers.json b/test/regression/mnt/exports/suites_providers_providers.json index 134dcd76..125546e8 100644 --- a/test/regression/mnt/exports/suites_providers_providers.json +++ b/test/regression/mnt/exports/suites_providers_providers.json @@ -6,7 +6,11 @@ "contract_expiration_sets": [], "contracts": [], "next_contract_id": "1", - "params": {}, + "params": { + "CommunityPoolPercentage": "0.100000000000000000", + "DevFundPercentage": "0.200000000000000000", + "ValidatorRewardsPercentage": "0.700000000000000000" + }, "providers": [], "user_contract_sets": [], "version": "0" diff --git a/test/regression/mnt/exports/suites_sentinel_contract_config.json b/test/regression/mnt/exports/suites_sentinel_contract_config.json index 5f4d7d96..12dae5ba 100644 --- a/test/regression/mnt/exports/suites_sentinel_contract_config.json +++ b/test/regression/mnt/exports/suites_sentinel_contract_config.json @@ -70,7 +70,11 @@ } ], "next_contract_id": "1", - "params": {}, + "params": { + "CommunityPoolPercentage": "0.100000000000000000", + "DevFundPercentage": "0.200000000000000000", + "ValidatorRewardsPercentage": "0.700000000000000000" + }, "providers": [ { "bond": "1000000000000", diff --git a/test/regression/mnt/exports/suites_sentinel_sentinel.json b/test/regression/mnt/exports/suites_sentinel_sentinel.json index 87936117..5dd2d1c6 100644 --- a/test/regression/mnt/exports/suites_sentinel_sentinel.json +++ b/test/regression/mnt/exports/suites_sentinel_sentinel.json @@ -6,7 +6,11 @@ "contract_expiration_sets": [], "contracts": [], "next_contract_id": "1", - "params": {}, + "params": { + "CommunityPoolPercentage": "0.100000000000000000", + "DevFundPercentage": "0.200000000000000000", + "ValidatorRewardsPercentage": "0.700000000000000000" + }, "providers": [], "user_contract_sets": [], "version": "0" From 3bb1867d022cd28296c39682a07c3b0c12db1569 Mon Sep 17 00:00:00 2001 From: shreyasbhat0 Date: Tue, 17 Sep 2024 20:00:11 +0530 Subject: [PATCH 14/24] fix: test imports --- testutil/keeper/arkeo.go | 16 ++ x/arkeo/keeper/keeper_test.go | 2 + x/arkeo/keeper/manager_test.go | 275 ++++++++++++++++----------------- 3 files changed, 153 insertions(+), 140 deletions(-) diff --git a/testutil/keeper/arkeo.go b/testutil/keeper/arkeo.go index 3b975de8..8a558a96 100644 --- a/testutil/keeper/arkeo.go +++ b/testutil/keeper/arkeo.go @@ -27,6 +27,8 @@ import ( bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper" + minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" typesparams "github.com/cosmos/cosmos-sdk/x/params/types" @@ -43,6 +45,7 @@ func ArkeoKeeper(t testing.TB) (cosmos.Context, keeper.Keeper) { keyParams := cosmos.NewKVStoreKey(paramstypes.StoreKey) tkeyParams := cosmos.NewTransientStoreKey(paramstypes.TStoreKey) memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey) + keyMint := cosmos.NewKVStoreKey(minttypes.StoreKey) logger := log.NewNopLogger() db := tmdb.NewMemDB() @@ -76,6 +79,7 @@ func ArkeoKeeper(t testing.TB) (cosmos.Context, keeper.Keeper) { types.ReserveName: {}, types.ProviderName: {}, types.ContractName: {}, + minttypes.ModuleName: {authtypes.Minter}, }, authcodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()), sdk.Bech32PrefixAccAddr, @@ -100,6 +104,17 @@ func ArkeoKeeper(t testing.TB) (cosmos.Context, keeper.Keeper) { authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()), authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()), ) + + mk := mintkeeper.NewKeeper( + cdc, + runtime.NewKVStoreService(keyMint), + sk, + ak, + bk, + authtypes.FeeCollectorName, + govModuleAddr, + ) + k := keeper.NewKVStore( cdc, storeKey, @@ -110,6 +125,7 @@ func ArkeoKeeper(t testing.TB) (cosmos.Context, keeper.Keeper) { *sk, govModuleAddr, logger, + mk, ) ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger()) diff --git a/x/arkeo/keeper/keeper_test.go b/x/arkeo/keeper/keeper_test.go index d7ee0f31..98e72e69 100644 --- a/x/arkeo/keeper/keeper_test.go +++ b/x/arkeo/keeper/keeper_test.go @@ -101,6 +101,7 @@ func SetupKeeper(t testing.TB) (cosmos.Context, Keeper) { types.ReserveName: {}, types.ProviderName: {}, types.ContractName: {}, + minttypes.ModuleName: {authtypes.Minter}, }, authcodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()), sdk.Bech32PrefixAccAddr, @@ -216,6 +217,7 @@ func SetupKeeperWithStaking(t testing.TB) (cosmos.Context, Keeper, stakingkeeper types.DevFundPool: {authtypes.Minter, authtypes.Burner}, types.GrantPool: {authtypes.Minter, authtypes.Burner}, types.CommunityPool: {authtypes.Minter, authtypes.Burner}, + minttypes.ModuleName: {authtypes.Minter}, }, authcodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()), sdk.Bech32PrefixAccAddr, diff --git a/x/arkeo/keeper/manager_test.go b/x/arkeo/keeper/manager_test.go index eaa810d4..e781aa12 100644 --- a/x/arkeo/keeper/manager_test.go +++ b/x/arkeo/keeper/manager_test.go @@ -1,7 +1,6 @@ package keeper import ( - "fmt" "testing" "github.com/stretchr/testify/require" @@ -12,10 +11,6 @@ import ( "github.com/arkeonetwork/arkeo/common/cosmos" "github.com/arkeonetwork/arkeo/x/arkeo/configs" "github.com/arkeonetwork/arkeo/x/arkeo/types" - - abci "github.com/cometbft/cometbft/abci/types" - simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) func TestContractEndBlock(t *testing.T) { @@ -291,141 +286,141 @@ func TestParamsRewardsPercentage(t *testing.T) { } -func TestValidatorPayouts(t *testing.T) { - ctx, k, sk := SetupKeeperWithStaking(t) - - pks := simtestutil.CreateTestPubKeys(3) - pk1, err := common.NewPubKeyFromCrypto(pks[0]) - require.NoError(t, err) - acc1, err := pk1.GetMyAddress() - require.NoError(t, err) - pk2, err := common.NewPubKeyFromCrypto(pks[1]) - require.NoError(t, err) - acc2, err := pk2.GetMyAddress() - require.NoError(t, err) - pk3, err := common.NewPubKeyFromCrypto(pks[2]) - require.NoError(t, err) - acc3, err := pk3.GetMyAddress() - require.NoError(t, err) - - valAddrs := simtestutil.ConvertAddrsToValAddrs([]cosmos.AccAddress{acc1, acc2, acc3}) - - val1, err := stakingtypes.NewValidator(valAddrs[0].String(), pks[0], stakingtypes.Description{}) - require.NoError(t, err) - val1.Tokens = cosmos.NewInt(100) - val1.DelegatorShares = cosmos.NewDec(130) // Validator + Delegations - val1.Status = stakingtypes.Bonded - val1.Commission = stakingtypes.NewCommission(cosmos.NewDecWithPrec(1, 1), cosmos.ZeroDec(), cosmos.ZeroDec()) - - val2, err := stakingtypes.NewValidator(valAddrs[1].String(), pks[1], stakingtypes.Description{}) - require.NoError(t, err) - val2.Tokens = cosmos.NewInt(200) - val2.DelegatorShares = cosmos.NewDec(220) - val2.Status = stakingtypes.Bonded - val2.Commission = stakingtypes.NewCommission(cosmos.NewDecWithPrec(2, 1), cosmos.ZeroDec(), cosmos.ZeroDec()) - - val3, err := stakingtypes.NewValidator(valAddrs[2].String(), pks[2], stakingtypes.Description{}) - require.NoError(t, err) - val3.Tokens = cosmos.NewInt(500) - val3.DelegatorShares = cosmos.NewDec(500) - val3.Status = stakingtypes.Bonded - val3.Commission = stakingtypes.NewCommission(cosmos.NewDecWithPrec(5, 1), cosmos.ZeroDec(), cosmos.ZeroDec()) - - vals := []stakingtypes.Validator{val1, val2, val3} - for _, val := range vals { - require.NoError(t, sk.SetValidator(ctx, val)) - require.NoError(t, sk.SetValidatorByConsAddr(ctx, val)) - require.NoError(t, sk.SetNewValidatorByPowerIndex(ctx, val)) - } - - delAcc1 := types.GetRandomBech32Addr() - delAcc2 := types.GetRandomBech32Addr() - delAcc3 := types.GetRandomBech32Addr() - - require.NoError(t, sk.SetDelegation(ctx, stakingtypes.NewDelegation(acc1.String(), valAddrs[0].String(), cosmos.NewDec(100)))) - require.NoError(t, sk.SetDelegation(ctx, stakingtypes.NewDelegation(acc2.String(), valAddrs[1].String(), cosmos.NewDec(200)))) - require.NoError(t, sk.SetDelegation(ctx, stakingtypes.NewDelegation(acc3.String(), valAddrs[2].String(), cosmos.NewDec(500)))) - - del1 := stakingtypes.NewDelegation(delAcc1.String(), valAddrs[0].String(), cosmos.NewDec(10)) - del2 := stakingtypes.NewDelegation(delAcc2.String(), valAddrs[1].String(), cosmos.NewDec(20)) - del3 := stakingtypes.NewDelegation(delAcc3.String(), valAddrs[2].String(), cosmos.NewDec(20)) - require.NoError(t, sk.SetDelegation(ctx, del1)) - require.NoError(t, sk.SetDelegation(ctx, del2)) - require.NoError(t, sk.SetDelegation(ctx, del3)) - - // Mint initial funds to the reserve - require.NoError(t, k.MintToModule(ctx, types.ModuleName, getCoin(common.Tokens(200000)))) - exemptModules := []string{types.GrantPool, types.CommunityPool, types.DevFundPool} - for _, modules := range exemptModules { - require.NoError(t, k.SendFromModuleToModule(ctx, types.ModuleName, modules, getCoins(common.Tokens(50000)))) - } - - // Set parameters for payouts - params := types.DefaultParams() - params.DevFundPercentage = sdkmath.LegacyNewDecWithPrec(20, 2) // 20% - params.CommunityPoolPercentage = sdkmath.LegacyNewDecWithPrec(10, 2) // 10% - params.ValidatorRewardsPercentage = sdkmath.LegacyNewDecWithPrec(70, 2) // 70% - k.SetParams(ctx, params) - - // Instantiate manager with keeper and staking keeper - mgr := NewManager(k, sk) - ctx = ctx.WithBlockHeight(mgr.FetchConfig(ctx, configs.ValidatorPayoutCycle)) - - // Create VoteInfo for each validator - votes := make([]abci.VoteInfo, len(vals)) - for i, val := range vals { - consAddr, err := val.GetConsAddr() - require.NoError(t, err) - votes[i] = abci.VoteInfo{ - Validator: abci.Validator{ - Address: consAddr, - Power: val.Tokens.Int64(), - }, - BlockIdFlag: 2, - } - } - - blockReward := int64(158529) - newlyMintedDec := sdkmath.LegacyNewDecFromInt(sdkmath.NewInt(blockReward)) - - _ = newlyMintedDec.Mul(params.DevFundPercentage).TruncateInt() - _ = newlyMintedDec.Mul(params.CommunityPoolPercentage).TruncateInt() - validatorRewardAmount := newlyMintedDec.Mul(params.ValidatorRewardsPercentage).TruncateInt() - - // Expected block reward calculation - - // validatorRewardPoolAddr := mgr.keeper.GetModuleAccAddress(types.ValidatorRewardPool) - // fmt.Println(k.GetBalance(ctx, validatorRewardPoolAddr)) - - // require.NoError(t, mgr.ValidatorPayout(ctx, votes,)) - - // validatorRewardPoolAddr = mgr.keeper.GetModuleAccAddress(types.ValidatorRewardPool) - // fmt.Println(k.GetBalance(ctx, validatorRewardPoolAddr).AmountOf(configs.Denom)) - - // Verify the remaining balance after distribution - // expectedRemaining := 5000000000000 - k.GetBalance(ctx, validatorRewardPoolAddr).AmountOf(configs.Denom).Int64() - // require.Equal(t, k.GetBalanceOfModule(ctx, types.ReserveName, configs.Denom).Int64(), expectedRemaining) - - totalBal := cosmos.ZeroInt() - - // Check balances of validators 7 - checkBalance(ctx, t, k, acc1, configs.Denom, 13042, &totalBal) - checkBalance(ctx, t, k, acc2, configs.Denom, 26059, &totalBal) - checkBalance(ctx, t, k, acc3, configs.Denom, 64950, &totalBal) - - // Check balances of delegates - checkBalance(ctx, t, k, delAcc1, configs.Denom, 1305, &totalBal) - checkBalance(ctx, t, k, delAcc2, configs.Denom, 2606, &totalBal) - checkBalance(ctx, t, k, delAcc3, configs.Denom, 2598, &totalBal) - - fmt.Println(sdkmath.NewInt(110970).Sub(totalBal)) - - // validatorRewardPoolAddr = mgr.keeper.GetModuleAccAddress(types.ValidatorRewardPool) - // fmt.Println("Val", k.GetBalance(ctx, validatorRewardPoolAddr).AmountOf(configs.Denom)) - - // Ensure the total block reward equals the sum of all payouts - require.Equal(t, validatorRewardAmount.Int64(), int64(110970)) -} +// func TestValidatorPayouts(t *testing.T) { +// ctx, k, sk := SetupKeeperWithStaking(t) + +// pks := simtestutil.CreateTestPubKeys(3) +// pk1, err := common.NewPubKeyFromCrypto(pks[0]) +// require.NoError(t, err) +// acc1, err := pk1.GetMyAddress() +// require.NoError(t, err) +// pk2, err := common.NewPubKeyFromCrypto(pks[1]) +// require.NoError(t, err) +// acc2, err := pk2.GetMyAddress() +// require.NoError(t, err) +// pk3, err := common.NewPubKeyFromCrypto(pks[2]) +// require.NoError(t, err) +// acc3, err := pk3.GetMyAddress() +// require.NoError(t, err) + +// valAddrs := simtestutil.ConvertAddrsToValAddrs([]cosmos.AccAddress{acc1, acc2, acc3}) + +// val1, err := stakingtypes.NewValidator(valAddrs[0].String(), pks[0], stakingtypes.Description{}) +// require.NoError(t, err) +// val1.Tokens = cosmos.NewInt(100) +// val1.DelegatorShares = cosmos.NewDec(130) // Validator + Delegations +// val1.Status = stakingtypes.Bonded +// val1.Commission = stakingtypes.NewCommission(cosmos.NewDecWithPrec(1, 1), cosmos.ZeroDec(), cosmos.ZeroDec()) + +// val2, err := stakingtypes.NewValidator(valAddrs[1].String(), pks[1], stakingtypes.Description{}) +// require.NoError(t, err) +// val2.Tokens = cosmos.NewInt(200) +// val2.DelegatorShares = cosmos.NewDec(220) +// val2.Status = stakingtypes.Bonded +// val2.Commission = stakingtypes.NewCommission(cosmos.NewDecWithPrec(2, 1), cosmos.ZeroDec(), cosmos.ZeroDec()) + +// val3, err := stakingtypes.NewValidator(valAddrs[2].String(), pks[2], stakingtypes.Description{}) +// require.NoError(t, err) +// val3.Tokens = cosmos.NewInt(500) +// val3.DelegatorShares = cosmos.NewDec(500) +// val3.Status = stakingtypes.Bonded +// val3.Commission = stakingtypes.NewCommission(cosmos.NewDecWithPrec(5, 1), cosmos.ZeroDec(), cosmos.ZeroDec()) + +// vals := []stakingtypes.Validator{val1, val2, val3} +// for _, val := range vals { +// require.NoError(t, sk.SetValidator(ctx, val)) +// require.NoError(t, sk.SetValidatorByConsAddr(ctx, val)) +// require.NoError(t, sk.SetNewValidatorByPowerIndex(ctx, val)) +// } + +// delAcc1 := types.GetRandomBech32Addr() +// delAcc2 := types.GetRandomBech32Addr() +// delAcc3 := types.GetRandomBech32Addr() + +// require.NoError(t, sk.SetDelegation(ctx, stakingtypes.NewDelegation(acc1.String(), valAddrs[0].String(), cosmos.NewDec(100)))) +// require.NoError(t, sk.SetDelegation(ctx, stakingtypes.NewDelegation(acc2.String(), valAddrs[1].String(), cosmos.NewDec(200)))) +// require.NoError(t, sk.SetDelegation(ctx, stakingtypes.NewDelegation(acc3.String(), valAddrs[2].String(), cosmos.NewDec(500)))) + +// del1 := stakingtypes.NewDelegation(delAcc1.String(), valAddrs[0].String(), cosmos.NewDec(10)) +// del2 := stakingtypes.NewDelegation(delAcc2.String(), valAddrs[1].String(), cosmos.NewDec(20)) +// del3 := stakingtypes.NewDelegation(delAcc3.String(), valAddrs[2].String(), cosmos.NewDec(20)) +// require.NoError(t, sk.SetDelegation(ctx, del1)) +// require.NoError(t, sk.SetDelegation(ctx, del2)) +// require.NoError(t, sk.SetDelegation(ctx, del3)) + +// // Mint initial funds to the reserve +// require.NoError(t, k.MintToModule(ctx, types.ModuleName, getCoin(common.Tokens(200000)))) +// exemptModules := []string{types.GrantPool, types.CommunityPool, types.DevFundPool} +// for _, modules := range exemptModules { +// require.NoError(t, k.SendFromModuleToModule(ctx, types.ModuleName, modules, getCoins(common.Tokens(50000)))) +// } + +// // Set parameters for payouts +// params := types.DefaultParams() +// params.DevFundPercentage = sdkmath.LegacyNewDecWithPrec(20, 2) // 20% +// params.CommunityPoolPercentage = sdkmath.LegacyNewDecWithPrec(10, 2) // 10% +// params.ValidatorRewardsPercentage = sdkmath.LegacyNewDecWithPrec(70, 2) // 70% +// k.SetParams(ctx, params) + +// // Instantiate manager with keeper and staking keeper +// mgr := NewManager(k, sk) +// ctx = ctx.WithBlockHeight(mgr.FetchConfig(ctx, configs.ValidatorPayoutCycle)) + +// // Create VoteInfo for each validator +// votes := make([]abci.VoteInfo, len(vals)) +// for i, val := range vals { +// consAddr, err := val.GetConsAddr() +// require.NoError(t, err) +// votes[i] = abci.VoteInfo{ +// Validator: abci.Validator{ +// Address: consAddr, +// Power: val.Tokens.Int64(), +// }, +// BlockIdFlag: 2, +// } +// } + +// blockReward := int64(158529) +// newlyMintedDec := sdkmath.LegacyNewDecFromInt(sdkmath.NewInt(blockReward)) + +// _ = newlyMintedDec.Mul(params.DevFundPercentage).TruncateInt() +// _ = newlyMintedDec.Mul(params.CommunityPoolPercentage).TruncateInt() +// validatorRewardAmount := newlyMintedDec.Mul(params.ValidatorRewardsPercentage).TruncateInt() + +// // Expected block reward calculation + +// // validatorRewardPoolAddr := mgr.keeper.GetModuleAccAddress(types.ValidatorRewardPool) +// // fmt.Println(k.GetBalance(ctx, validatorRewardPoolAddr)) + +// // require.NoError(t, mgr.ValidatorPayout(ctx, votes,)) + +// // validatorRewardPoolAddr = mgr.keeper.GetModuleAccAddress(types.ValidatorRewardPool) +// // fmt.Println(k.GetBalance(ctx, validatorRewardPoolAddr).AmountOf(configs.Denom)) + +// // Verify the remaining balance after distribution +// // expectedRemaining := 5000000000000 - k.GetBalance(ctx, validatorRewardPoolAddr).AmountOf(configs.Denom).Int64() +// // require.Equal(t, k.GetBalanceOfModule(ctx, types.ReserveName, configs.Denom).Int64(), expectedRemaining) + +// totalBal := cosmos.ZeroInt() + +// // Check balances of validators 7 +// checkBalance(ctx, t, k, acc1, configs.Denom, 13042, &totalBal) +// checkBalance(ctx, t, k, acc2, configs.Denom, 26059, &totalBal) +// checkBalance(ctx, t, k, acc3, configs.Denom, 64950, &totalBal) + +// // Check balances of delegates +// checkBalance(ctx, t, k, delAcc1, configs.Denom, 1305, &totalBal) +// checkBalance(ctx, t, k, delAcc2, configs.Denom, 2606, &totalBal) +// checkBalance(ctx, t, k, delAcc3, configs.Denom, 2598, &totalBal) + +// fmt.Println(sdkmath.NewInt(110970).Sub(totalBal)) + +// // validatorRewardPoolAddr = mgr.keeper.GetModuleAccAddress(types.ValidatorRewardPool) +// // fmt.Println("Val", k.GetBalance(ctx, validatorRewardPoolAddr).AmountOf(configs.Denom)) + +// // Ensure the total block reward equals the sum of all payouts +// require.Equal(t, validatorRewardAmount.Int64(), int64(110970)) +// } func checkBalance(ctx cosmos.Context, t *testing.T, k Keeper, acc cosmos.AccAddress, denom string, expectedAmt int64, total *sdkmath.Int) { bal := k.GetBalance(ctx, acc) From e4ffd8af612b45af399f5bfeb16f6275306be76f Mon Sep 17 00:00:00 2001 From: shreyasbhat0 Date: Wed, 18 Sep 2024 19:20:38 +0530 Subject: [PATCH 15/24] feat: update params --- proto/arkeo/arkeo/params.proto | 4 ++-- x/arkeo/types/params.go | 6 +++--- x/arkeo/types/params.pb.go | 35 +++++++++++++++++----------------- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/proto/arkeo/arkeo/params.proto b/proto/arkeo/arkeo/params.proto index fa704a5e..84e8139f 100644 --- a/proto/arkeo/arkeo/params.proto +++ b/proto/arkeo/arkeo/params.proto @@ -10,7 +10,7 @@ option go_package = "github.com/arkeonetwork/arkeo/x/arkeo/types"; // Params defines the parameters for the module. message Params { option (gogoproto.goproto_stringer) = false; - string CommunityPoolPercentage= 1 [(cosmos_proto.scalar) = "cosmos.LegacyDec", (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", (gogoproto.nullable) = false]; + string CommunityPoolPercentage= 1 [(cosmos_proto.scalar) = "cosmos.LegacyDec", (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", (gogoproto.nullable) = false]; string DevFundPercentage= 2 [(cosmos_proto.scalar) = "cosmos.LegacyDec", (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", (gogoproto.nullable) = false]; - string ValidatorRewardsPercentage= 3 [(cosmos_proto.scalar) = "cosmos.LegacyDec", (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", (gogoproto.nullable) = false]; + string GrantFundPercentage= 3 [(cosmos_proto.scalar) = "cosmos.LegacyDec", (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", (gogoproto.nullable) = false]; } diff --git a/x/arkeo/types/params.go b/x/arkeo/types/params.go index 499a395c..c6173925 100644 --- a/x/arkeo/types/params.go +++ b/x/arkeo/types/params.go @@ -16,9 +16,9 @@ func ParamKeyTable() paramtypes.KeyTable { // NewParams creates a new Params instance func NewParams() Params { return Params{ - CommunityPoolPercentage: math.LegacyNewDecWithPrec(10, 2), - DevFundPercentage: math.LegacyNewDecWithPrec(20, 2), - ValidatorRewardsPercentage: math.LegacyNewDecWithPrec(70, 2), + CommunityPoolPercentage: math.LegacyNewDecWithPrec(10, 2), + DevFundPercentage: math.LegacyNewDecWithPrec(20, 2), + GrantFundPercentage: math.LegacyNewDecWithPrec(20, 2), } } diff --git a/x/arkeo/types/params.pb.go b/x/arkeo/types/params.pb.go index a38f6b53..aa8771ef 100644 --- a/x/arkeo/types/params.pb.go +++ b/x/arkeo/types/params.pb.go @@ -29,9 +29,9 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Params defines the parameters for the module. type Params struct { - CommunityPoolPercentage cosmossdk_io_math.LegacyDec `protobuf:"bytes,1,opt,name=CommunityPoolPercentage,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"CommunityPoolPercentage"` - DevFundPercentage cosmossdk_io_math.LegacyDec `protobuf:"bytes,2,opt,name=DevFundPercentage,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"DevFundPercentage"` - ValidatorRewardsPercentage cosmossdk_io_math.LegacyDec `protobuf:"bytes,3,opt,name=ValidatorRewardsPercentage,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"ValidatorRewardsPercentage"` + CommunityPoolPercentage cosmossdk_io_math.LegacyDec `protobuf:"bytes,1,opt,name=CommunityPoolPercentage,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"CommunityPoolPercentage"` + DevFundPercentage cosmossdk_io_math.LegacyDec `protobuf:"bytes,2,opt,name=DevFundPercentage,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"DevFundPercentage"` + GrantFundPercentage cosmossdk_io_math.LegacyDec `protobuf:"bytes,3,opt,name=GrantFundPercentage,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"GrantFundPercentage"` } func (m *Params) Reset() { *m = Params{} } @@ -73,27 +73,26 @@ func init() { func init() { proto.RegisterFile("arkeo/arkeo/params.proto", fileDescriptor_47c871f4fc73dfc5) } var fileDescriptor_47c871f4fc73dfc5 = []byte{ - // 306 bytes of a gzipped FileDescriptorProto + // 295 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x48, 0x2c, 0xca, 0x4e, 0xcd, 0xd7, 0x87, 0x90, 0x05, 0x89, 0x45, 0x89, 0xb9, 0xc5, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0xdc, 0x60, 0x31, 0x3d, 0x30, 0x29, 0x25, 0x92, 0x9e, 0x9f, 0x9e, 0x0f, 0x16, 0xd7, 0x07, 0xb1, 0x20, 0x4a, 0xa4, 0xe4, 0x92, 0xf3, 0x8b, 0x73, 0xf3, 0x8b, 0xf5, 0x93, 0x12, 0x8b, 0x53, 0xf5, 0xcb, 0x0c, 0x93, 0x52, 0x4b, 0x12, 0x0d, 0xf5, 0x93, 0xf3, 0x33, 0xf3, 0xa0, 0xf2, 0x92, - 0x10, 0xf9, 0x78, 0x88, 0x46, 0x08, 0x07, 0x22, 0xa5, 0xf4, 0x90, 0x89, 0x8b, 0x2d, 0x00, 0x6c, + 0x10, 0xf9, 0x78, 0x88, 0x46, 0x08, 0x07, 0x22, 0xa5, 0x74, 0x99, 0x89, 0x8b, 0x2d, 0x00, 0x6c, 0x9d, 0x50, 0x21, 0x97, 0xb8, 0x73, 0x7e, 0x6e, 0x6e, 0x69, 0x5e, 0x66, 0x49, 0x65, 0x40, 0x7e, 0x7e, 0x4e, 0x40, 0x6a, 0x51, 0x72, 0x6a, 0x5e, 0x49, 0x62, 0x7a, 0xaa, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0xa7, 0x93, 0xf9, 0x89, 0x7b, 0xf2, 0x0c, 0xb7, 0xee, 0xc9, 0x4b, 0x43, 0x4c, 0x28, 0x4e, 0xc9, 0xd6, 0xcb, 0xcc, 0xd7, 0xcf, 0x4d, 0x2c, 0xc9, 0xd0, 0xf3, 0x49, 0x4d, 0x4f, 0x4c, 0xae, 0x74, 0x49, 0x4d, 0xbe, 0xb4, 0x45, 0x57, 0x00, 0x6a, 0x01, 0x5c, 0x2c, 0x08, 0x97, 0xb9, 0x42, 0xa9, 0x5c, 0x82, 0x2e, 0xa9, 0x65, 0x6e, 0xa5, 0x79, 0x29, 0x48, 0x96, 0x31, 0x51, 0x66, 0x19, - 0xa6, 0x89, 0x42, 0xe5, 0x5c, 0x52, 0x61, 0x89, 0x39, 0x99, 0x29, 0x89, 0x25, 0xf9, 0x45, 0x41, - 0xa9, 0xe5, 0x89, 0x45, 0x29, 0xc5, 0x48, 0xf6, 0x31, 0x53, 0x66, 0x1f, 0x1e, 0xa3, 0xad, 0x58, - 0x66, 0x2c, 0x90, 0x67, 0x70, 0x72, 0x3d, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, - 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, - 0x28, 0xed, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0x48, 0xd4, 0xe7, 0xa5, - 0x96, 0x94, 0xe7, 0x17, 0x65, 0x43, 0xd3, 0x41, 0x05, 0x94, 0x2e, 0xa9, 0x2c, 0x48, 0x2d, 0x4e, - 0x62, 0x03, 0xc7, 0x98, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0xb9, 0xcb, 0x73, 0x48, 0x2b, 0x02, - 0x00, 0x00, + 0xa6, 0x89, 0x42, 0x99, 0x5c, 0xc2, 0xee, 0x45, 0x89, 0x79, 0x25, 0x68, 0x16, 0x31, 0x53, 0x66, + 0x11, 0x36, 0x33, 0xad, 0x58, 0x66, 0x2c, 0x90, 0x67, 0x70, 0x72, 0x3d, 0xf1, 0x48, 0x8e, 0xf1, + 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, 0x8e, + 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0xed, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, + 0x5c, 0x48, 0x64, 0xe7, 0xa5, 0x96, 0x94, 0xe7, 0x17, 0x65, 0x43, 0x63, 0xbe, 0x02, 0x4a, 0x97, + 0x54, 0x16, 0xa4, 0x16, 0x27, 0xb1, 0x81, 0xe3, 0xc8, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x47, + 0x53, 0xda, 0x44, 0x1d, 0x02, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -117,9 +116,9 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { var l int _ = l { - size := m.ValidatorRewardsPercentage.Size() + size := m.GrantFundPercentage.Size() i -= size - if _, err := m.ValidatorRewardsPercentage.MarshalTo(dAtA[i:]); err != nil { + if _, err := m.GrantFundPercentage.MarshalTo(dAtA[i:]); err != nil { return 0, err } i = encodeVarintParams(dAtA, i, uint64(size)) @@ -170,7 +169,7 @@ func (m *Params) Size() (n int) { n += 1 + l + sovParams(uint64(l)) l = m.DevFundPercentage.Size() n += 1 + l + sovParams(uint64(l)) - l = m.ValidatorRewardsPercentage.Size() + l = m.GrantFundPercentage.Size() n += 1 + l + sovParams(uint64(l)) return n } @@ -280,7 +279,7 @@ func (m *Params) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ValidatorRewardsPercentage", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field GrantFundPercentage", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -308,7 +307,7 @@ func (m *Params) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.ValidatorRewardsPercentage.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.GrantFundPercentage.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex From 8f4954f033e83103259951a680e8fe6799b8d866 Mon Sep 17 00:00:00 2001 From: shreyasbhat0 Date: Wed, 18 Sep 2024 19:21:57 +0530 Subject: [PATCH 16/24] feat: update foundational accounts for handling tokens --- app/app.go | 33 ++++----- scripts/genesis.sh | 3 + testutil/keeper/arkeo.go | 14 ++++ x/arkeo/keeper/keeper.go | 132 +++++++++++++++++++++++----------- x/arkeo/keeper/keeper_test.go | 46 +++++++++--- x/arkeo/keeper/manager.go | 12 +++- x/arkeo/types/keys.go | 18 +++-- 7 files changed, 182 insertions(+), 76 deletions(-) diff --git a/app/app.go b/app/app.go index b7579ccb..c93c5d86 100644 --- a/app/app.go +++ b/app/app.go @@ -200,22 +200,22 @@ var ( // module account permissions maccPerms = map[string][]string{ - authtypes.FeeCollectorName: nil, - distrtypes.ModuleName: nil, - icatypes.ModuleName: nil, - minttypes.ModuleName: {authtypes.Minter}, - stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, - stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, - govtypes.ModuleName: {authtypes.Burner}, - ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, - claimmoduletypes.ModuleName: {authtypes.Minter}, - arkeomoduletypes.ModuleName: {}, - arkeomoduletypes.ReserveName: {}, - arkeomoduletypes.ProviderName: {}, - arkeomoduletypes.ContractName: {}, - arkeomoduletypes.DevFundPool: {authtypes.Minter}, - arkeomoduletypes.CommunityPool: {authtypes.Minter}, - arkeomoduletypes.GrantPool: {authtypes.Minter}, + authtypes.FeeCollectorName: nil, + distrtypes.ModuleName: nil, + icatypes.ModuleName: nil, + minttypes.ModuleName: {authtypes.Minter}, + stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, + stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, + govtypes.ModuleName: {authtypes.Burner}, + ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, + claimmoduletypes.ModuleName: {authtypes.Minter}, + arkeomoduletypes.ModuleName: {}, + arkeomoduletypes.ReserveName: {}, + arkeomoduletypes.ProviderName: {}, + arkeomoduletypes.ContractName: {}, + arkeomoduletypes.FoundationDevAccount: {authtypes.Minter}, + arkeomoduletypes.FoundationGrantsAccount: {authtypes.Minter}, + arkeomoduletypes.FoundationCommunityAccount: {authtypes.Minter}, } ) @@ -598,6 +598,7 @@ func NewArkeoApp( govModuleAddr, logger, app.Keepers.MintKeeper, + app.Keepers.DistrKeeper, ) /**** Module Options ****/ diff --git a/scripts/genesis.sh b/scripts/genesis.sh index fa8c5178..82185630 100755 --- a/scripts/genesis.sh +++ b/scripts/genesis.sh @@ -84,6 +84,9 @@ if [ ! -f ~/.arkeo/config/genesis.json ]; then if [ "$NET" = "mocknet" ] || [ "$NET" = "testnet" ]; then add_module tarkeo1d0m97ywk2y4vq58ud6q5e0r3q9khj9e3unfe4t $TOKEN 10000000000000000 'arkeo-reserve' # reserve, 10m add_module tarkeo14tmx70mvve3u7hfmd45vle49kvylk6s2wllxny $TOKEN 10000000000000000 'claimarkeo' + add_module tarkeo10sav33v67743s6cl2cvjmmua7c5arysw3txz9r $TOKEN 10000000000000000 'devpool' + add_module tarkeo1v50hrsxx0mxar4653aujcnqyjft07w0npcxrjx $TOKEN 10000000000000000 'communitypool' + add_module tarkeo16k3k0erkwaanqnup20dxxenpd6wh058nh4pgup $TOKEN 10000000000000000 'grantspool' echo "shoulder heavy loyal save patient deposit crew bag pull club escape eyebrow hip verify border into wire start pact faint fame festival solve shop" | arkeod keys add alice --keyring-backend test --recover ALICE=$(arkeod keys show alice -a --keyring-backend test) diff --git a/testutil/keeper/arkeo.go b/testutil/keeper/arkeo.go index 8a558a96..3a411938 100644 --- a/testutil/keeper/arkeo.go +++ b/testutil/keeper/arkeo.go @@ -8,6 +8,8 @@ import ( storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/runtime" authcodec "github.com/cosmos/cosmos-sdk/x/auth/codec" + distkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" + disttypes "github.com/cosmos/cosmos-sdk/x/distribution/types" "github.com/arkeonetwork/arkeo/common" "github.com/arkeonetwork/arkeo/common/cosmos" @@ -46,6 +48,7 @@ func ArkeoKeeper(t testing.TB) (cosmos.Context, keeper.Keeper) { tkeyParams := cosmos.NewTransientStoreKey(paramstypes.TStoreKey) memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey) keyMint := cosmos.NewKVStoreKey(minttypes.StoreKey) + keydist := cosmos.NewKVStoreKey(disttypes.StoreKey) logger := log.NewNopLogger() db := tmdb.NewMemDB() @@ -105,6 +108,16 @@ func ArkeoKeeper(t testing.TB) (cosmos.Context, keeper.Keeper) { authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()), ) + dk := distkeeper.NewKeeper( + cdc, + runtime.NewKVStoreService(keydist), + ak, + bk, + sk, + authtypes.FeeCollectorName, + govModuleAddr, + ) + mk := mintkeeper.NewKeeper( cdc, runtime.NewKVStoreService(keyMint), @@ -126,6 +139,7 @@ func ArkeoKeeper(t testing.TB) (cosmos.Context, keeper.Keeper) { govModuleAddr, logger, mk, + dk, ) ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger()) diff --git a/x/arkeo/keeper/keeper.go b/x/arkeo/keeper/keeper.go index 1ff0295d..2dc24b39 100644 --- a/x/arkeo/keeper/keeper.go +++ b/x/arkeo/keeper/keeper.go @@ -20,6 +20,7 @@ import ( authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + distkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" minttypes "github.com/cosmos/cosmos-sdk/x/mint/keeper" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" @@ -64,6 +65,7 @@ type Keeper interface { MintAndDistributeTokens(ctx cosmos.Context, newlyMinted cosmos.Coin) (cosmos.Coin, error) GetCirculatingSupply(ctx cosmos.Context, denom string) (cosmos.Coin, error) GetInflationRate(ctx cosmos.Context) (math.LegacyDec, error) + MoveTokensFromDistributionToFoundationPoolAccount(ctx cosmos.Context) error // Query Params(c context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) @@ -116,16 +118,17 @@ const ( ) type KVStore struct { - cdc codec.BinaryCodec - storeKey storetypes.StoreKey - memKey storetypes.StoreKey - paramstore paramtypes.Subspace - coinKeeper bankkeeper.Keeper - accountKeeper authkeeper.AccountKeeper - stakingKeeper stakingkeeper.Keeper - authority string - logger log.Logger - mintKeeper minttypes.Keeper + cdc codec.BinaryCodec + storeKey storetypes.StoreKey + memKey storetypes.StoreKey + paramstore paramtypes.Subspace + coinKeeper bankkeeper.Keeper + accountKeeper authkeeper.AccountKeeper + stakingKeeper stakingkeeper.Keeper + authority string + logger log.Logger + mintKeeper minttypes.Keeper + distributionKeeper distkeeper.Keeper } func NewKVStore( @@ -133,19 +136,13 @@ func NewKVStore( storeKey, memKey storetypes.StoreKey, ps paramtypes.Subspace, - - /* - accountKeeper keeper.AccountKeeper - bankKeeper keeper.Keeper - distributionKeeper distkeeper.Keeper - stakingKeeper stakingkeeper.Keeper - */ coinKeeper bankkeeper.Keeper, accountKeeper authkeeper.AccountKeeper, stakingKeeper stakingkeeper.Keeper, authority string, logger log.Logger, mintKeeper minttypes.Keeper, + distributionKeeper distkeeper.Keeper, ) *KVStore { // set KeyTable if it has not already been set if !ps.HasKeyTable() { @@ -153,16 +150,17 @@ func NewKVStore( } return &KVStore{ - cdc: cdc, - storeKey: storeKey, - memKey: memKey, - paramstore: ps, - coinKeeper: coinKeeper, - accountKeeper: accountKeeper, - stakingKeeper: stakingKeeper, - authority: authority, - logger: logger, - mintKeeper: mintKeeper, + cdc: cdc, + storeKey: storeKey, + memKey: memKey, + paramstore: ps, + coinKeeper: coinKeeper, + accountKeeper: accountKeeper, + stakingKeeper: stakingKeeper, + authority: authority, + logger: logger, + mintKeeper: mintKeeper, + distributionKeeper: distributionKeeper, } } @@ -390,14 +388,25 @@ func (k KVStore) GetCirculatingSupply(ctx cosmos.Context, denom string) (cosmos. totalSupply := fullTokenSupply.Supply.AmountOf(configs.Denom) sdkContext.Logger().Error("Current supply of token with denom :", denom, "supply:", totalSupply) + // Get the account addresses whose balances need to be exempted + devAccountAddress := k.getFoundationDevAccountAddress() + + communityAccountAddress := k.getFoundationCommunityAccountAddress() + + grantAccountAddress := k.getFoundationGrantsAccountAddress() + // Module Address for which the circulating supply should be exempted - modulesToExempt := []string{types.GrantPool, types.CommunityPool, types.DevFundPool} + moduleAddressToExempt := []sdk.AccAddress{ + devAccountAddress, + communityAccountAddress, + grantAccountAddress, + } + exemptBalance := cosmos.NewInt(0) // range over the module and create exempt balances - for _, moduleName := range modulesToExempt { - moduleAddr := k.accountKeeper.GetModuleAddress(moduleName) - moduleBalance := k.coinKeeper.GetBalance(ctx, moduleAddr, denom) + for _, moduleAddress := range moduleAddressToExempt { + moduleBalance := k.coinKeeper.GetBalance(ctx, moduleAddress, denom) exemptBalance = exemptBalance.Add(moduleBalance.Amount) } @@ -407,26 +416,35 @@ func (k KVStore) GetCirculatingSupply(ctx cosmos.Context, denom string) (cosmos. return cosmos.NewCoin(denom, circulatingSupply), nil } -func (k KVStore) MintAndDistributeTokens(ctx cosmos.Context, newlyMinted cosmos.Coin) (cosmos.Coin, error) { +func (k KVStore) MintAndDistributeTokens(ctx cosmos.Context, newlyMinted cosmos.Coin) (sdk.Coin, error) { params := k.GetParams(ctx) - newlyMintedDec := sdkmath.LegacyNewDecFromInt(newlyMinted.Amount) + // mint newly added tokens to reserve + if err := k.MintToModule(ctx, types.ReserveName, newlyMinted); err != nil { + return cosmos.NewCoin(newlyMinted.Denom, sdkmath.NewInt(0)), err + } + devFundAmount := newlyMintedDec.Mul(params.DevFundPercentage).TruncateInt() communityPoolAmount := newlyMintedDec.Mul(params.CommunityPoolPercentage).TruncateInt() - // validatorRewardAmount := newlyMintedDec.Mul(params.ValidatorRewardsPercentage).TruncateInt() + grantFundAmount := newlyMintedDec.Mul(params.GrantFundPercentage).TruncateInt() + + if err := k.SendFromModuleToModule(ctx, types.ReserveName, types.FoundationDevAccount, cosmos.NewCoins(cosmos.NewCoin(newlyMinted.Denom, devFundAmount))); err != nil { + return cosmos.NewCoin(newlyMinted.Denom, sdkmath.NewInt(0)), fmt.Errorf("error sending amount to module %s", err) + } - if err := k.MintToModule(ctx, types.DevFundPool, cosmos.NewCoin(newlyMinted.Denom, devFundAmount)); err != nil { - return cosmos.NewCoin(configs.Denom, sdkmath.NewInt(0)), fmt.Errorf("error sending amount to module %s", err) + if err := k.SendFromModuleToModule(ctx, types.ReserveName, types.FoundationCommunityAccount, cosmos.NewCoins(cosmos.NewCoin(newlyMinted.Denom, communityPoolAmount))); err != nil { + return cosmos.NewCoin(newlyMinted.Denom, sdkmath.NewInt(0)), fmt.Errorf("error sending amount to module %s", err) } - if err := k.MintToModule(ctx, types.CommunityPool, cosmos.NewCoin(newlyMinted.Denom, communityPoolAmount)); err != nil { - return cosmos.NewCoin(configs.Denom, sdkmath.NewInt(0)), fmt.Errorf("error sending amount to module %s", err) + if err := k.SendFromModuleToModule(ctx, types.ReserveName, types.FoundationGrantsAccount, cosmos.NewCoins(cosmos.NewCoin(newlyMinted.Denom, grantFundAmount))); err != nil { + return cosmos.NewCoin(newlyMinted.Denom, sdkmath.NewInt(0)), fmt.Errorf("error sending amount to module %s", err) } - balance := newlyMintedDec.Sub(sdkmath.LegacyDec(devFundAmount)).Sub(sdkmath.LegacyDec(communityPoolAmount)) - return cosmos.NewCoin(configs.Denom, balance.RoundInt()), nil + balance := newlyMintedDec.Sub(sdkmath.LegacyDec(devFundAmount)).Sub(sdkmath.LegacyDec(communityPoolAmount)).Sub(sdkmath.LegacyDec(grantFundAmount)) + + return cosmos.NewCoin(newlyMinted.Denom, sdkmath.NewInt(balance.RoundInt64())), nil } @@ -438,3 +456,37 @@ func (k KVStore) GetInflationRate(ctx cosmos.Context) (math.LegacyDec, error) { return minter.Inflation, nil } + +// transfer tokens form the Distribution to Foundation Community Pool +func (k KVStore) MoveTokensFromDistributionToFoundationPoolAccount(ctx cosmos.Context) error { + + // get pool balance + pool, err := k.distributionKeeper.FeePool.Get(ctx) + if err != nil { + return err + } + amount := pool.CommunityPool.AmountOf(configs.Denom) + + communityAccountAddress := k.getFoundationCommunityAccountAddress() + + if amount.RoundInt64() > 0 { + err = k.distributionKeeper.DistributeFromFeePool(ctx, cosmos.NewCoins(cosmos.NewCoin(configs.Denom, amount.RoundInt())), communityAccountAddress) + if err != nil { + return err + } + + } + return err +} + +func (k KVStore) getFoundationDevAccountAddress() cosmos.AccAddress { + return k.GetModuleAccAddress(types.FoundationDevAccount) +} + +func (k KVStore) getFoundationCommunityAccountAddress() cosmos.AccAddress { + return k.GetModuleAccAddress(types.FoundationCommunityAccount) +} + +func (k KVStore) getFoundationGrantsAccountAddress() cosmos.AccAddress { + return k.GetModuleAccAddress(types.FoundationGrantsAccount) +} diff --git a/x/arkeo/keeper/keeper_test.go b/x/arkeo/keeper/keeper_test.go index 98e72e69..1bb95e58 100644 --- a/x/arkeo/keeper/keeper_test.go +++ b/x/arkeo/keeper/keeper_test.go @@ -24,6 +24,8 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + distkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" + disttypes "github.com/cosmos/cosmos-sdk/x/distribution/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" @@ -56,6 +58,7 @@ func SetupKeeper(t testing.TB) (cosmos.Context, Keeper) { keyMint := cosmos.NewKVStoreKey(minttypes.StoreKey) tkeyParams := cosmos.NewTransientStoreKey(typesparams.TStoreKey) memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey) + keydist := cosmos.NewKVStoreKey(disttypes.StoreKey) cfg := sdk.GetConfig() @@ -127,6 +130,15 @@ func SetupKeeper(t testing.TB) (cosmos.Context, Keeper) { authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()), authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()), ) + dk := distkeeper.NewKeeper( + cdc, + runtime.NewKVStoreService(keydist), + ak, + bk, + sk, + authtypes.FeeCollectorName, + govModuleAddr, + ) mk := mintkeeper.NewKeeper( cdc, @@ -149,6 +161,7 @@ func SetupKeeper(t testing.TB) (cosmos.Context, Keeper) { govModuleAddr, logger, mk, + dk, ) k.SetVersion(ctx, common.GetCurrentVersion()) @@ -167,6 +180,7 @@ func SetupKeeperWithStaking(t testing.TB) (cosmos.Context, Keeper, stakingkeeper keyParams := cosmos.NewKVStoreKey(typesparams.StoreKey) tkeyParams := cosmos.NewTransientStoreKey(typesparams.TStoreKey) memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey) + keydist := cosmos.NewKVStoreKey(disttypes.StoreKey) cfg := sdk.GetConfig() @@ -207,17 +221,17 @@ func SetupKeeperWithStaking(t testing.TB) (cosmos.Context, Keeper, stakingkeeper runtime.NewKVStoreService(keyAcc), authtypes.ProtoBaseAccount, map[string][]string{ - stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, - stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, - types.ModuleName: {authtypes.Minter, authtypes.Burner}, - types.ReserveName: {}, - types.ProviderName: {}, - types.ContractName: {}, - govtypes.ModuleName: {authtypes.Minter, authtypes.Burner}, - types.DevFundPool: {authtypes.Minter, authtypes.Burner}, - types.GrantPool: {authtypes.Minter, authtypes.Burner}, - types.CommunityPool: {authtypes.Minter, authtypes.Burner}, - minttypes.ModuleName: {authtypes.Minter}, + stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, + stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, + types.ModuleName: {authtypes.Minter, authtypes.Burner}, + types.ReserveName: {}, + types.ProviderName: {}, + types.ContractName: {}, + govtypes.ModuleName: {authtypes.Minter, authtypes.Burner}, + types.FoundationDevAccount: {authtypes.Minter, authtypes.Burner}, + types.FoundationGrantsAccount: {authtypes.Minter, authtypes.Burner}, + types.FoundationCommunityAccount: {authtypes.Minter, authtypes.Burner}, + minttypes.ModuleName: {authtypes.Minter}, }, authcodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()), sdk.Bech32PrefixAccAddr, @@ -253,6 +267,15 @@ func SetupKeeperWithStaking(t testing.TB) (cosmos.Context, Keeper, stakingkeeper authtypes.FeeCollectorName, govModuleAddr, ) + dk := distkeeper.NewKeeper( + cdc, + runtime.NewKVStoreService(keydist), + ak, + bk, + sk, + authtypes.FeeCollectorName, + govModuleAddr, + ) k := NewKVStore( cdc, @@ -265,6 +288,7 @@ func SetupKeeperWithStaking(t testing.TB) (cosmos.Context, Keeper, stakingkeeper govModuleAddr, logger, mk, + dk, ) k.SetVersion(ctx, common.GetCurrentVersion()) diff --git a/x/arkeo/keeper/manager.go b/x/arkeo/keeper/manager.go index 2b0b65f1..07a26b4d 100644 --- a/x/arkeo/keeper/manager.go +++ b/x/arkeo/keeper/manager.go @@ -60,13 +60,21 @@ func (mgr *Manager) BeginBlock(ctx cosmos.Context) error { ctx.Logger().Error("unable to get supply with inflation calculation", "error", err) } + err = mgr.keeper.MoveTokensFromDistributionToFoundationPoolAccount(ctx) + if err != nil { + ctx.Logger().Error("unable to send tokens from distribution to pool account", "error", err) + } + // Calculate Block Rewards blockReward := mgr.calcBlockReward(ctx, circSupply.Amount.Int64()) // Distribute Minted To Pools - afterDistribution, err := mgr.keeper.MintAndDistributeTokens(ctx, blockReward) + balanceDistribution, err := mgr.keeper.MintAndDistributeTokens(ctx, blockReward) + if err != nil { + ctx.Logger().Error("unable to mint and distribute tokens", "error", err) + } - if err := mgr.ValidatorPayout(ctx, votes, afterDistribution); err != nil { + if err := mgr.ValidatorPayout(ctx, votes, balanceDistribution); err != nil { ctx.Logger().Error("unable to settle contracts", "error", err) } return nil diff --git a/x/arkeo/types/keys.go b/x/arkeo/types/keys.go index a2d97c97..2838d20b 100644 --- a/x/arkeo/types/keys.go +++ b/x/arkeo/types/keys.go @@ -2,13 +2,10 @@ package types const ( // ModuleName defines the module name - ModuleName = "arkeo" - ReserveName = "arkeo-reserve" - ProviderName = "providers" - ContractName = "contracts" - DevFundPool = "devpool" - CommunityPool = "communitypool" - GrantPool = "grantpool" + ModuleName = "arkeo" + ReserveName = "arkeo-reserve" + ProviderName = "providers" + ContractName = "contracts" // StoreKey defines the primary module store key StoreKey = ModuleName @@ -23,3 +20,10 @@ const ( func KeyPrefix(p string) []byte { return []byte(p) } + +// Foundational Accounts +const ( + FoundationDevAccount = "devpool" + FoundationCommunityAccount = "communitypool" + FoundationGrantsAccount = "grantspool" +) From 31d1238a03806469317669bf7b47bc143685e51c Mon Sep 17 00:00:00 2001 From: shreyasbhat0 Date: Wed, 18 Sep 2024 19:23:59 +0530 Subject: [PATCH 17/24] fix: update regression test --- app/app_regtest.go | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/app/app_regtest.go b/app/app_regtest.go index 73a73d8c..952022ea 100644 --- a/app/app_regtest.go +++ b/app/app_regtest.go @@ -219,18 +219,21 @@ var ( // module account permissions maccPerms = map[string][]string{ - authtypes.FeeCollectorName: nil, - distrtypes.ModuleName: nil, - icatypes.ModuleName: nil, - minttypes.ModuleName: {authtypes.Minter}, - stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, - stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, - govtypes.ModuleName: {authtypes.Burner}, - ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, - arkeomoduletypes.ModuleName: {}, - arkeomoduletypes.ReserveName: {}, - arkeomoduletypes.ProviderName: {}, - arkeomoduletypes.ContractName: {}, + authtypes.FeeCollectorName: nil, + distrtypes.ModuleName: nil, + icatypes.ModuleName: nil, + minttypes.ModuleName: {authtypes.Minter}, + stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, + stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, + govtypes.ModuleName: {authtypes.Burner}, + ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, + arkeomoduletypes.ModuleName: {}, + arkeomoduletypes.ReserveName: {}, + arkeomoduletypes.ProviderName: {}, + arkeomoduletypes.ContractName: {}, + arkeomoduletypes.FoundationDevAccount: {authtypes.Minter}, + arkeomoduletypes.FoundationGrantsAccount: {authtypes.Minter}, + arkeomoduletypes.FoundationCommunityAccount: {authtypes.Minter}, // this line is used by starport scaffolding # stargate/app/maccPerms } ) @@ -603,6 +606,7 @@ func NewArkeoApp( govModuleAddr, logger, app.Keepers.MintKeeper, + app.Keepers.DistrKeeper, ) arkeoModule := arkeomodule.NewAppModule(appCodec, app.ArkeoKeeper, app.Keepers.AccountKeeper, app.Keepers.BankKeeper, *app.Keepers.StakingKeeper) From 38ffd86324eb29480a2990b1dbe55d2e64d06632 Mon Sep 17 00:00:00 2001 From: shreyasbhat0 Date: Thu, 19 Sep 2024 19:26:44 +0530 Subject: [PATCH 18/24] feat: update param proto --- proto/arkeo/arkeo/params.proto | 6 +++--- x/arkeo/types/keys.go | 6 +++--- x/arkeo/types/params.go | 6 +++--- x/arkeo/types/params.pb.go | 34 +++++++++++++++++----------------- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/proto/arkeo/arkeo/params.proto b/proto/arkeo/arkeo/params.proto index 84e8139f..b7a7de5f 100644 --- a/proto/arkeo/arkeo/params.proto +++ b/proto/arkeo/arkeo/params.proto @@ -10,7 +10,7 @@ option go_package = "github.com/arkeonetwork/arkeo/x/arkeo/types"; // Params defines the parameters for the module. message Params { option (gogoproto.goproto_stringer) = false; - string CommunityPoolPercentage= 1 [(cosmos_proto.scalar) = "cosmos.LegacyDec", (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", (gogoproto.nullable) = false]; - string DevFundPercentage= 2 [(cosmos_proto.scalar) = "cosmos.LegacyDec", (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", (gogoproto.nullable) = false]; - string GrantFundPercentage= 3 [(cosmos_proto.scalar) = "cosmos.LegacyDec", (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", (gogoproto.nullable) = false]; + string CommunityPoolPercentage= 1 [(cosmos_proto.scalar) = "cosmos.Int", (gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false]; + string DevFundPercentage= 2 [(cosmos_proto.scalar) = "cosmos.Int", (gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false]; + string GrantFundPercentage= 3 [(cosmos_proto.scalar) = "cosmos.Int", (gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false]; } diff --git a/x/arkeo/types/keys.go b/x/arkeo/types/keys.go index 2838d20b..019d4064 100644 --- a/x/arkeo/types/keys.go +++ b/x/arkeo/types/keys.go @@ -23,7 +23,7 @@ func KeyPrefix(p string) []byte { // Foundational Accounts const ( - FoundationDevAccount = "devpool" - FoundationCommunityAccount = "communitypool" - FoundationGrantsAccount = "grantspool" + FoundationDevAccount = "tarkeo10sav33v67743s6cl2cvjmmua7c5arysw3txz9r" + FoundationCommunityAccount = "tarkeo1v50hrsxx0mxar4653aujcnqyjft07w0npcxrjx" + FoundationGrantsAccount = "tarkeo16k3k0erkwaanqnup20dxxenpd6wh058nh4pgup" ) diff --git a/x/arkeo/types/params.go b/x/arkeo/types/params.go index c6173925..ebfb1a91 100644 --- a/x/arkeo/types/params.go +++ b/x/arkeo/types/params.go @@ -16,9 +16,9 @@ func ParamKeyTable() paramtypes.KeyTable { // NewParams creates a new Params instance func NewParams() Params { return Params{ - CommunityPoolPercentage: math.LegacyNewDecWithPrec(10, 2), - DevFundPercentage: math.LegacyNewDecWithPrec(20, 2), - GrantFundPercentage: math.LegacyNewDecWithPrec(20, 2), + CommunityPoolPercentage: math.NewInt(10), + DevFundPercentage: math.NewInt(20), + GrantFundPercentage: math.NewInt(20), } } diff --git a/x/arkeo/types/params.pb.go b/x/arkeo/types/params.pb.go index aa8771ef..7bff56db 100644 --- a/x/arkeo/types/params.pb.go +++ b/x/arkeo/types/params.pb.go @@ -29,9 +29,9 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Params defines the parameters for the module. type Params struct { - CommunityPoolPercentage cosmossdk_io_math.LegacyDec `protobuf:"bytes,1,opt,name=CommunityPoolPercentage,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"CommunityPoolPercentage"` - DevFundPercentage cosmossdk_io_math.LegacyDec `protobuf:"bytes,2,opt,name=DevFundPercentage,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"DevFundPercentage"` - GrantFundPercentage cosmossdk_io_math.LegacyDec `protobuf:"bytes,3,opt,name=GrantFundPercentage,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"GrantFundPercentage"` + CommunityPoolPercentage cosmossdk_io_math.Int `protobuf:"bytes,1,opt,name=CommunityPoolPercentage,proto3,customtype=cosmossdk.io/math.Int" json:"CommunityPoolPercentage"` + DevFundPercentage cosmossdk_io_math.Int `protobuf:"bytes,2,opt,name=DevFundPercentage,proto3,customtype=cosmossdk.io/math.Int" json:"DevFundPercentage"` + GrantFundPercentage cosmossdk_io_math.Int `protobuf:"bytes,3,opt,name=GrantFundPercentage,proto3,customtype=cosmossdk.io/math.Int" json:"GrantFundPercentage"` } func (m *Params) Reset() { *m = Params{} } @@ -73,26 +73,26 @@ func init() { func init() { proto.RegisterFile("arkeo/arkeo/params.proto", fileDescriptor_47c871f4fc73dfc5) } var fileDescriptor_47c871f4fc73dfc5 = []byte{ - // 295 bytes of a gzipped FileDescriptorProto + // 290 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x48, 0x2c, 0xca, 0x4e, 0xcd, 0xd7, 0x87, 0x90, 0x05, 0x89, 0x45, 0x89, 0xb9, 0xc5, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0xdc, 0x60, 0x31, 0x3d, 0x30, 0x29, 0x25, 0x92, 0x9e, 0x9f, 0x9e, 0x0f, 0x16, 0xd7, 0x07, 0xb1, 0x20, 0x4a, 0xa4, 0xe4, 0x92, 0xf3, 0x8b, 0x73, 0xf3, 0x8b, 0xf5, 0x93, 0x12, 0x8b, 0x53, 0xf5, 0xcb, 0x0c, 0x93, 0x52, 0x4b, 0x12, 0x0d, 0xf5, 0x93, 0xf3, 0x33, 0xf3, 0xa0, 0xf2, 0x92, - 0x10, 0xf9, 0x78, 0x88, 0x46, 0x08, 0x07, 0x22, 0xa5, 0x74, 0x99, 0x89, 0x8b, 0x2d, 0x00, 0x6c, - 0x9d, 0x50, 0x21, 0x97, 0xb8, 0x73, 0x7e, 0x6e, 0x6e, 0x69, 0x5e, 0x66, 0x49, 0x65, 0x40, 0x7e, + 0x10, 0xf9, 0x78, 0x88, 0x46, 0x08, 0x07, 0x22, 0xa5, 0xb4, 0x9e, 0x89, 0x8b, 0x2d, 0x00, 0x6c, + 0x9d, 0x50, 0x2a, 0x97, 0xb8, 0x73, 0x7e, 0x6e, 0x6e, 0x69, 0x5e, 0x66, 0x49, 0x65, 0x40, 0x7e, 0x7e, 0x4e, 0x40, 0x6a, 0x51, 0x72, 0x6a, 0x5e, 0x49, 0x62, 0x7a, 0xaa, 0x04, 0xa3, 0x02, 0xa3, - 0x06, 0xa7, 0x93, 0xf9, 0x89, 0x7b, 0xf2, 0x0c, 0xb7, 0xee, 0xc9, 0x4b, 0x43, 0x4c, 0x28, 0x4e, - 0xc9, 0xd6, 0xcb, 0xcc, 0xd7, 0xcf, 0x4d, 0x2c, 0xc9, 0xd0, 0xf3, 0x49, 0x4d, 0x4f, 0x4c, 0xae, - 0x74, 0x49, 0x4d, 0xbe, 0xb4, 0x45, 0x57, 0x00, 0x6a, 0x01, 0x5c, 0x2c, 0x08, 0x97, 0xb9, 0x42, - 0xa9, 0x5c, 0x82, 0x2e, 0xa9, 0x65, 0x6e, 0xa5, 0x79, 0x29, 0x48, 0x96, 0x31, 0x51, 0x66, 0x19, - 0xa6, 0x89, 0x42, 0x99, 0x5c, 0xc2, 0xee, 0x45, 0x89, 0x79, 0x25, 0x68, 0x16, 0x31, 0x53, 0x66, - 0x11, 0x36, 0x33, 0xad, 0x58, 0x66, 0x2c, 0x90, 0x67, 0x70, 0x72, 0x3d, 0xf1, 0x48, 0x8e, 0xf1, - 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, 0x8e, - 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0xed, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, - 0x5c, 0x48, 0x64, 0xe7, 0xa5, 0x96, 0x94, 0xe7, 0x17, 0x65, 0x43, 0x63, 0xbe, 0x02, 0x4a, 0x97, - 0x54, 0x16, 0xa4, 0x16, 0x27, 0xb1, 0x81, 0xe3, 0xc8, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x47, - 0x53, 0xda, 0x44, 0x1d, 0x02, 0x00, 0x00, + 0x06, 0xa7, 0x93, 0xf6, 0x89, 0x7b, 0xf2, 0x0c, 0xb7, 0xee, 0xc9, 0x8b, 0x42, 0x4c, 0x28, 0x4e, + 0xc9, 0xd6, 0xcb, 0xcc, 0xd7, 0xcf, 0x4d, 0x2c, 0xc9, 0xd0, 0xf3, 0xcc, 0x2b, 0xb9, 0xb4, 0x45, + 0x97, 0x0b, 0x6a, 0xb4, 0x67, 0x5e, 0x49, 0x10, 0x2e, 0xb3, 0x84, 0x22, 0xb9, 0x04, 0x5d, 0x52, + 0xcb, 0xdc, 0x4a, 0xf3, 0x52, 0x90, 0x2c, 0x60, 0x22, 0xdd, 0x02, 0x4c, 0x53, 0x84, 0x62, 0xb9, + 0x84, 0xdd, 0x8b, 0x12, 0xf3, 0x4a, 0xd0, 0x0c, 0x67, 0x26, 0xdd, 0x70, 0x6c, 0xe6, 0x58, 0xb1, + 0xcc, 0x58, 0x20, 0xcf, 0xe0, 0xe4, 0x7a, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, + 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, + 0x51, 0xda, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0x90, 0x88, 0xcc, 0x4b, + 0x2d, 0x29, 0xcf, 0x2f, 0xca, 0x86, 0xc6, 0x6a, 0x05, 0x94, 0x2e, 0xa9, 0x2c, 0x48, 0x2d, 0x4e, + 0x62, 0x03, 0x87, 0xbf, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0xdb, 0xf8, 0x23, 0xd7, 0xf9, 0x01, + 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { From f7031a95e2c9ed9a5312c485c9b6a4e352822009 Mon Sep 17 00:00:00 2001 From: shreyasbhat0 Date: Thu, 19 Sep 2024 19:27:22 +0530 Subject: [PATCH 19/24] fix: regression testing --- app/app.go | 29 ++--- app/app_regtest.go | 27 ++-- .../suites_contracts_pay-as-you-go.json | 121 ++++++++++++++++-- .../suites_contracts_subscription.json | 121 ++++++++++++++++-- .../mnt/exports/suites_core_send.json | 117 +++++++++++++++-- .../mnt/exports/suites_initialize.json | 119 +++++++++++++++-- .../exports/suites_providers_providers.json | 119 +++++++++++++++-- .../suites_sentinel_contract_config.json | 78 ++++++++++- .../mnt/exports/suites_sentinel_sentinel.json | 78 ++++++++++- .../suites/contracts/subscription.yaml | 4 +- 10 files changed, 711 insertions(+), 102 deletions(-) diff --git a/app/app.go b/app/app.go index c93c5d86..9bf01528 100644 --- a/app/app.go +++ b/app/app.go @@ -200,22 +200,19 @@ var ( // module account permissions maccPerms = map[string][]string{ - authtypes.FeeCollectorName: nil, - distrtypes.ModuleName: nil, - icatypes.ModuleName: nil, - minttypes.ModuleName: {authtypes.Minter}, - stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, - stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, - govtypes.ModuleName: {authtypes.Burner}, - ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, - claimmoduletypes.ModuleName: {authtypes.Minter}, - arkeomoduletypes.ModuleName: {}, - arkeomoduletypes.ReserveName: {}, - arkeomoduletypes.ProviderName: {}, - arkeomoduletypes.ContractName: {}, - arkeomoduletypes.FoundationDevAccount: {authtypes.Minter}, - arkeomoduletypes.FoundationGrantsAccount: {authtypes.Minter}, - arkeomoduletypes.FoundationCommunityAccount: {authtypes.Minter}, + authtypes.FeeCollectorName: nil, + distrtypes.ModuleName: {authtypes.Minter}, + icatypes.ModuleName: nil, + minttypes.ModuleName: {authtypes.Minter}, + stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, + stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, + govtypes.ModuleName: {authtypes.Burner}, + ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, + claimmoduletypes.ModuleName: {authtypes.Minter}, + arkeomoduletypes.ModuleName: {authtypes.Minter}, + arkeomoduletypes.ReserveName: {}, + arkeomoduletypes.ProviderName: {}, + arkeomoduletypes.ContractName: {}, } ) diff --git a/app/app_regtest.go b/app/app_regtest.go index 952022ea..3918b8bb 100644 --- a/app/app_regtest.go +++ b/app/app_regtest.go @@ -219,21 +219,18 @@ var ( // module account permissions maccPerms = map[string][]string{ - authtypes.FeeCollectorName: nil, - distrtypes.ModuleName: nil, - icatypes.ModuleName: nil, - minttypes.ModuleName: {authtypes.Minter}, - stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, - stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, - govtypes.ModuleName: {authtypes.Burner}, - ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, - arkeomoduletypes.ModuleName: {}, - arkeomoduletypes.ReserveName: {}, - arkeomoduletypes.ProviderName: {}, - arkeomoduletypes.ContractName: {}, - arkeomoduletypes.FoundationDevAccount: {authtypes.Minter}, - arkeomoduletypes.FoundationGrantsAccount: {authtypes.Minter}, - arkeomoduletypes.FoundationCommunityAccount: {authtypes.Minter}, + authtypes.FeeCollectorName: nil, + distrtypes.ModuleName: nil, + icatypes.ModuleName: nil, + minttypes.ModuleName: {authtypes.Minter}, + stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, + stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, + govtypes.ModuleName: {authtypes.Burner}, + ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, + arkeomoduletypes.ModuleName: {authtypes.Minter}, + arkeomoduletypes.ReserveName: {}, + arkeomoduletypes.ProviderName: {}, + arkeomoduletypes.ContractName: {}, // this line is used by starport scaffolding # stargate/app/maccPerms } ) diff --git a/test/regression/mnt/exports/suites_contracts_pay-as-you-go.json b/test/regression/mnt/exports/suites_contracts_pay-as-you-go.json index c12f212c..c3b4b5a5 100644 --- a/test/regression/mnt/exports/suites_contracts_pay-as-you-go.json +++ b/test/regression/mnt/exports/suites_contracts_pay-as-you-go.json @@ -46,9 +46,9 @@ ], "next_contract_id": "2", "params": { - "CommunityPoolPercentage": "0.100000000000000000", - "DevFundPercentage": "0.200000000000000000", - "ValidatorRewardsPercentage": "0.700000000000000000" + "CommunityPoolPercentage": "10", + "DevFundPercentage": "20", + "GrantFundPercentage": "20" }, "providers": [ { @@ -119,10 +119,17 @@ }, "sequence": "2" }, + { + "@type": "/cosmos.auth.v1beta1.BaseAccount", + "account_number": "11", + "address": "tarkeo1v50hrsxx0mxar4653aujcnqyjft07w0npcxrjx", + "pub_key": null, + "sequence": "0" + }, { "@type": "/cosmos.auth.v1beta1.ModuleAccount", "base_account": { - "account_number": "9", + "account_number": "14", "address": "tarkeo1d0m97ywk2y4vq58ud6q5e0r3q9khj9e3unfe4t", "pub_key": null, "sequence": "0" @@ -130,6 +137,13 @@ "name": "arkeo-reserve", "permissions": [] }, + { + "@type": "/cosmos.auth.v1beta1.BaseAccount", + "account_number": "13", + "address": "tarkeo1w3shy6m9damxzmr0wpjhyvtgdeuhjdr8wq6hgempwfcxwvmcw5m8wdtrwu685umewp58svnv09nxudf5wd5qsks9jp", + "pub_key": null, + "sequence": "0" + }, { "@type": "/cosmos.auth.v1beta1.ModuleAccount", "base_account": { @@ -143,6 +157,13 @@ "burner" ] }, + { + "@type": "/cosmos.auth.v1beta1.BaseAccount", + "account_number": "10", + "address": "tarkeo10sav33v67743s6cl2cvjmmua7c5arysw3txz9r", + "pub_key": null, + "sequence": "0" + }, { "@type": "/cosmos.auth.v1beta1.ModuleAccount", "base_account": { @@ -157,7 +178,7 @@ { "@type": "/cosmos.auth.v1beta1.ModuleAccount", "base_account": { - "account_number": "10", + "account_number": "15", "address": "tarkeo1kz2dkl8zlxwte008astc5e65htrxdcse6x3h3h", "pub_key": null, "sequence": "0" @@ -165,6 +186,19 @@ "name": "contracts", "permissions": [] }, + { + "@type": "/cosmos.auth.v1beta1.ModuleAccount", + "base_account": { + "account_number": "9", + "address": "tarkeo1k8925g52vwe5jgfp4nqr7ljuhs7nzu2f8g0za5", + "pub_key": null, + "sequence": "0" + }, + "name": "arkeo", + "permissions": [ + "minter" + ] + }, { "@type": "/cosmos.auth.v1beta1.BaseAccount", "account_number": "0", @@ -175,6 +209,13 @@ }, "sequence": "1" }, + { + "@type": "/cosmos.auth.v1beta1.BaseAccount", + "account_number": "12", + "address": "tarkeo16k3k0erkwaanqnup20dxxenpd6wh058nh4pgup", + "pub_key": null, + "sequence": "0" + }, { "@type": "/cosmos.auth.v1beta1.ModuleAccount", "base_account": { @@ -250,6 +291,15 @@ } ] }, + { + "address": "tarkeo1v50hrsxx0mxar4653aujcnqyjft07w0npcxrjx", + "coins": [ + { + "amount": "621404328", + "denom": "uarkeo" + } + ] + }, { "address": "tarkeo1d0m97ywk2y4vq58ud6q5e0r3q9khj9e3unfe4t", "coins": [ @@ -259,11 +309,47 @@ } ] }, + { + "address": "tarkeo10sav33v67743s6cl2cvjmmua7c5arysw3txz9r", + "coins": [ + { + "amount": "643005225", + "denom": "uarkeo" + } + ] + }, { "address": "tarkeo1jv65s3grqf6v6jl3dp4t6c9t9rk99cd8t6gr9e", "coins": [ { - "amount": "16066162928", + "amount": "15766261669", + "denom": "uarkeo" + } + ] + }, + { + "address": "tarkeo1k8925g52vwe5jgfp4nqr7ljuhs7nzu2f8g0za5", + "coins": [ + { + "amount": "107167575", + "denom": "uarkeo" + } + ] + }, + { + "address": "tarkeo1hnyy4gp5tgarpg3xu6w5cw4zsyphx2lyvls9rz", + "coins": [ + { + "amount": "1498845173", + "denom": "uarkeo" + } + ] + }, + { + "address": "tarkeo16k3k0erkwaanqnup20dxxenpd6wh058nh4pgup", + "coins": [ + { + "amount": "643005225", "denom": "uarkeo" } ] @@ -276,6 +362,15 @@ "denom": "uarkeo" } ] + }, + { + "address": "tarkeo1w3shy6m9damxzmr0wpjhyvtgdeuhjdr8wq6hgempwfcxwvmcw5m8wdtrwu685umewp58svnv09nxudf5wd5qsks9jp", + "coins": [ + { + "amount": "1500352", + "denom": "uarkeo" + } + ] } ], "denom_metadata": [], @@ -286,7 +381,7 @@ "send_enabled": [], "supply": [ { - "amount": "52001016066162928", + "amount": "52001019281189547", "denom": "uarkeo" } ] @@ -361,7 +456,7 @@ "fee_pool": { "community_pool": [ { - "amount": "321323258.560000000000000000", + "amount": "21421544.840000000000000000", "denom": "uarkeo" } ] @@ -370,7 +465,7 @@ { "outstanding_rewards": [ { - "amount": "15744839669.440000000000000000", + "amount": "15744840124.160000000000000000", "denom": "uarkeo" } ], @@ -389,7 +484,7 @@ "accumulated": { "commission": [ { - "amount": "1574483966.944000000000000000", + "amount": "1574484012.416000000000000000", "denom": "uarkeo" } ] @@ -403,7 +498,7 @@ "period": "2", "rewards": [ { - "amount": "14170355702.496000000000000000", + "amount": "14170356111.744000000000000000", "denom": "uarkeo" } ] @@ -578,8 +673,8 @@ }, "mint": { "minter": { - "annual_provisions": "6760124958900879.440734825593079684", - "inflation": "0.129999865570695682" + "annual_provisions": "6760125348991042.808880506171119200", + "inflation": "0.129999865570708475" }, "params": { "blocks_per_year": "6311520", diff --git a/test/regression/mnt/exports/suites_contracts_subscription.json b/test/regression/mnt/exports/suites_contracts_subscription.json index 311396e8..57899793 100644 --- a/test/regression/mnt/exports/suites_contracts_subscription.json +++ b/test/regression/mnt/exports/suites_contracts_subscription.json @@ -67,9 +67,9 @@ ], "next_contract_id": "3", "params": { - "CommunityPoolPercentage": "0.100000000000000000", - "DevFundPercentage": "0.200000000000000000", - "ValidatorRewardsPercentage": "0.700000000000000000" + "CommunityPoolPercentage": "10", + "DevFundPercentage": "20", + "GrantFundPercentage": "20" }, "providers": [ { @@ -137,10 +137,17 @@ "pub_key": null, "sequence": "0" }, + { + "@type": "/cosmos.auth.v1beta1.BaseAccount", + "account_number": "11", + "address": "tarkeo1v50hrsxx0mxar4653aujcnqyjft07w0npcxrjx", + "pub_key": null, + "sequence": "0" + }, { "@type": "/cosmos.auth.v1beta1.ModuleAccount", "base_account": { - "account_number": "9", + "account_number": "14", "address": "tarkeo1d0m97ywk2y4vq58ud6q5e0r3q9khj9e3unfe4t", "pub_key": null, "sequence": "0" @@ -148,6 +155,13 @@ "name": "arkeo-reserve", "permissions": [] }, + { + "@type": "/cosmos.auth.v1beta1.BaseAccount", + "account_number": "13", + "address": "tarkeo1w3shy6m9damxzmr0wpjhyvtgdeuhjdr8wq6hgempwfcxwvmcw5m8wdtrwu685umewp58svnv09nxudf5wd5qsks9jp", + "pub_key": null, + "sequence": "0" + }, { "@type": "/cosmos.auth.v1beta1.ModuleAccount", "base_account": { @@ -161,6 +175,13 @@ "burner" ] }, + { + "@type": "/cosmos.auth.v1beta1.BaseAccount", + "account_number": "10", + "address": "tarkeo10sav33v67743s6cl2cvjmmua7c5arysw3txz9r", + "pub_key": null, + "sequence": "0" + }, { "@type": "/cosmos.auth.v1beta1.ModuleAccount", "base_account": { @@ -175,7 +196,7 @@ { "@type": "/cosmos.auth.v1beta1.ModuleAccount", "base_account": { - "account_number": "10", + "account_number": "15", "address": "tarkeo1kz2dkl8zlxwte008astc5e65htrxdcse6x3h3h", "pub_key": null, "sequence": "0" @@ -183,6 +204,19 @@ "name": "contracts", "permissions": [] }, + { + "@type": "/cosmos.auth.v1beta1.ModuleAccount", + "base_account": { + "account_number": "9", + "address": "tarkeo1k8925g52vwe5jgfp4nqr7ljuhs7nzu2f8g0za5", + "pub_key": null, + "sequence": "0" + }, + "name": "arkeo", + "permissions": [ + "minter" + ] + }, { "@type": "/cosmos.auth.v1beta1.BaseAccount", "account_number": "0", @@ -193,6 +227,13 @@ }, "sequence": "2" }, + { + "@type": "/cosmos.auth.v1beta1.BaseAccount", + "account_number": "12", + "address": "tarkeo16k3k0erkwaanqnup20dxxenpd6wh058nh4pgup", + "pub_key": null, + "sequence": "0" + }, { "@type": "/cosmos.auth.v1beta1.ModuleAccount", "base_account": { @@ -268,6 +309,15 @@ } ] }, + { + "address": "tarkeo1v50hrsxx0mxar4653aujcnqyjft07w0npcxrjx", + "coins": [ + { + "amount": "749969453", + "denom": "uarkeo" + } + ] + }, { "address": "tarkeo1d0m97ywk2y4vq58ud6q5e0r3q9khj9e3unfe4t", "coins": [ @@ -277,11 +327,47 @@ } ] }, + { + "address": "tarkeo10sav33v67743s6cl2cvjmmua7c5arysw3txz9r", + "coins": [ + { + "amount": "771606216", + "denom": "uarkeo" + } + ] + }, { "address": "tarkeo1jv65s3grqf6v6jl3dp4t6c9t9rk99cd8t6gr9e", "coins": [ { - "amount": "19279394116", + "amount": "18915228438", + "denom": "uarkeo" + } + ] + }, + { + "address": "tarkeo1k8925g52vwe5jgfp4nqr7ljuhs7nzu2f8g0za5", + "coins": [ + { + "amount": "107167575", + "denom": "uarkeo" + } + ] + }, + { + "address": "tarkeo1hnyy4gp5tgarpg3xu6w5cw4zsyphx2lyvls9rz", + "coins": [ + { + "amount": "1820026156", + "denom": "uarkeo" + } + ] + }, + { + "address": "tarkeo16k3k0erkwaanqnup20dxxenpd6wh058nh4pgup", + "coins": [ + { + "amount": "771606216", "denom": "uarkeo" } ] @@ -294,6 +380,15 @@ "denom": "uarkeo" } ] + }, + { + "address": "tarkeo1w3shy6m9damxzmr0wpjhyvtgdeuhjdr8wq6hgempwfcxwvmcw5m8wdtrwu685umewp58svnv09nxudf5wd5qsks9jp", + "coins": [ + { + "amount": "1821854", + "denom": "uarkeo" + } + ] } ], "denom_metadata": [], @@ -304,7 +399,7 @@ "send_enabled": [], "supply": [ { - "amount": "52001019279394116", + "amount": "52001023137425908", "denom": "uarkeo" } ] @@ -379,7 +474,7 @@ "fee_pool": { "community_pool": [ { - "amount": "385587882.320000000000000000", + "amount": "21421541.840000000000000000", "denom": "uarkeo" } ] @@ -388,7 +483,7 @@ { "outstanding_rewards": [ { - "amount": "18893806233.680000000000000000", + "amount": "18893806896.160000000000000000", "denom": "uarkeo" } ], @@ -407,7 +502,7 @@ "accumulated": { "commission": [ { - "amount": "1889380623.368000000000000000", + "amount": "1889380689.616000000000000000", "denom": "uarkeo" } ] @@ -421,7 +516,7 @@ "period": "2", "rewards": [ { - "amount": "17004425610.312000000000000000", + "amount": "17004426206.544000000000000000", "denom": "uarkeo" } ] @@ -596,8 +691,8 @@ }, "mint": { "minter": { - "annual_provisions": "6760123978529236.587874847213850985", - "inflation": "0.129999838684851257" + "annual_provisions": "6760124452210194.355441603119737810", + "inflation": "0.129999838684869898" }, "params": { "blocks_per_year": "6311520", diff --git a/test/regression/mnt/exports/suites_core_send.json b/test/regression/mnt/exports/suites_core_send.json index 36c0933d..71e1bdc1 100644 --- a/test/regression/mnt/exports/suites_core_send.json +++ b/test/regression/mnt/exports/suites_core_send.json @@ -7,9 +7,9 @@ "contracts": [], "next_contract_id": "1", "params": { - "CommunityPoolPercentage": "0.100000000000000000", - "DevFundPercentage": "0.200000000000000000", - "ValidatorRewardsPercentage": "0.700000000000000000" + "CommunityPoolPercentage": "10", + "DevFundPercentage": "20", + "GrantFundPercentage": "20" }, "providers": [], "user_contract_sets": [], @@ -52,6 +52,20 @@ "pub_key": null, "sequence": "0" }, + { + "@type": "/cosmos.auth.v1beta1.BaseAccount", + "account_number": "11", + "address": "tarkeo1v50hrsxx0mxar4653aujcnqyjft07w0npcxrjx", + "pub_key": null, + "sequence": "0" + }, + { + "@type": "/cosmos.auth.v1beta1.BaseAccount", + "account_number": "13", + "address": "tarkeo1w3shy6m9damxzmr0wpjhyvtgdeuhjdr8wq6hgempwfcxwvmcw5m8wdtrwu685umewp58svnv09nxudf5wd5qsks9jp", + "pub_key": null, + "sequence": "0" + }, { "@type": "/cosmos.auth.v1beta1.ModuleAccount", "base_account": { @@ -65,6 +79,13 @@ "burner" ] }, + { + "@type": "/cosmos.auth.v1beta1.BaseAccount", + "account_number": "10", + "address": "tarkeo10sav33v67743s6cl2cvjmmua7c5arysw3txz9r", + "pub_key": null, + "sequence": "0" + }, { "@type": "/cosmos.auth.v1beta1.ModuleAccount", "base_account": { @@ -76,6 +97,19 @@ "name": "distribution", "permissions": [] }, + { + "@type": "/cosmos.auth.v1beta1.ModuleAccount", + "base_account": { + "account_number": "9", + "address": "tarkeo1k8925g52vwe5jgfp4nqr7ljuhs7nzu2f8g0za5", + "pub_key": null, + "sequence": "0" + }, + "name": "arkeo", + "permissions": [ + "minter" + ] + }, { "@type": "/cosmos.auth.v1beta1.BaseAccount", "account_number": "0", @@ -86,6 +120,13 @@ }, "sequence": "1" }, + { + "@type": "/cosmos.auth.v1beta1.BaseAccount", + "account_number": "12", + "address": "tarkeo16k3k0erkwaanqnup20dxxenpd6wh058nh4pgup", + "pub_key": null, + "sequence": "0" + }, { "@type": "/cosmos.auth.v1beta1.ModuleAccount", "base_account": { @@ -152,11 +193,56 @@ } ] }, + { + "address": "tarkeo1v50hrsxx0mxar4653aujcnqyjft07w0npcxrjx", + "coins": [ + { + "amount": "64299303", + "denom": "uarkeo" + } + ] + }, + { + "address": "tarkeo10sav33v67743s6cl2cvjmmua7c5arysw3txz9r", + "coins": [ + { + "amount": "128598609", + "denom": "uarkeo" + } + ] + }, { "address": "tarkeo1jv65s3grqf6v6jl3dp4t6c9t9rk99cd8t6gr9e", "coins": [ { - "amount": "3213171726", + "amount": "3213171739", + "denom": "uarkeo" + } + ] + }, + { + "address": "tarkeo1k8925g52vwe5jgfp4nqr7ljuhs7nzu2f8g0za5", + "coins": [ + { + "amount": "107165513", + "denom": "uarkeo" + } + ] + }, + { + "address": "tarkeo1hnyy4gp5tgarpg3xu6w5cw4zsyphx2lyvls9rz", + "coins": [ + { + "amount": "214116679", + "denom": "uarkeo" + } + ] + }, + { + "address": "tarkeo16k3k0erkwaanqnup20dxxenpd6wh058nh4pgup", + "coins": [ + { + "amount": "128598609", "denom": "uarkeo" } ] @@ -169,6 +255,15 @@ "denom": "uarkeo" } ] + }, + { + "address": "tarkeo1w3shy6m9damxzmr0wpjhyvtgdeuhjdr8wq6hgempwfcxwvmcw5m8wdtrwu685umewp58svnv09nxudf5wd5qsks9jp", + "coins": [ + { + "amount": "214332", + "denom": "uarkeo" + } + ] } ], "denom_metadata": [], @@ -179,7 +274,7 @@ "send_enabled": [], "supply": [ { - "amount": "52000003213171726", + "amount": "52000003856164784", "denom": "uarkeo" } ] @@ -254,7 +349,7 @@ "fee_pool": { "community_pool": [ { - "amount": "64263434.520000000000000000", + "amount": "64263434.780000000000000000", "denom": "uarkeo" } ] @@ -263,7 +358,7 @@ { "outstanding_rewards": [ { - "amount": "3148908291.480000000000000000", + "amount": "3148908304.220000000000000000", "denom": "uarkeo" } ], @@ -282,7 +377,7 @@ "accumulated": { "commission": [ { - "amount": "314890829.148000000000000000", + "amount": "314890830.422000000000000000", "denom": "uarkeo" } ] @@ -296,7 +391,7 @@ "period": "2", "rewards": [ { - "amount": "2834017462.332000000000000000", + "amount": "2834017473.798000000000000000", "denom": "uarkeo" } ] @@ -471,8 +566,8 @@ }, "mint": { "minter": { - "annual_provisions": "6759998880320819.659730123458173168", - "inflation": "0.129999973112422838" + "annual_provisions": "6759998936046892.886047279891762320", + "inflation": "0.129999973112423204" }, "params": { "blocks_per_year": "6311520", diff --git a/test/regression/mnt/exports/suites_initialize.json b/test/regression/mnt/exports/suites_initialize.json index d4e65ad6..fd9fa130 100644 --- a/test/regression/mnt/exports/suites_initialize.json +++ b/test/regression/mnt/exports/suites_initialize.json @@ -7,9 +7,9 @@ "contracts": [], "next_contract_id": "1", "params": { - "CommunityPoolPercentage": "0.100000000000000000", - "DevFundPercentage": "0.200000000000000000", - "ValidatorRewardsPercentage": "0.700000000000000000" + "CommunityPoolPercentage": "10", + "DevFundPercentage": "20", + "GrantFundPercentage": "20" }, "providers": [], "user_contract_sets": [], @@ -52,6 +52,20 @@ "pub_key": null, "sequence": "0" }, + { + "@type": "/cosmos.auth.v1beta1.BaseAccount", + "account_number": "11", + "address": "tarkeo1v50hrsxx0mxar4653aujcnqyjft07w0npcxrjx", + "pub_key": null, + "sequence": "0" + }, + { + "@type": "/cosmos.auth.v1beta1.BaseAccount", + "account_number": "13", + "address": "tarkeo1w3shy6m9damxzmr0wpjhyvtgdeuhjdr8wq6hgempwfcxwvmcw5m8wdtrwu685umewp58svnv09nxudf5wd5qsks9jp", + "pub_key": null, + "sequence": "0" + }, { "@type": "/cosmos.auth.v1beta1.ModuleAccount", "base_account": { @@ -65,6 +79,13 @@ "burner" ] }, + { + "@type": "/cosmos.auth.v1beta1.BaseAccount", + "account_number": "10", + "address": "tarkeo10sav33v67743s6cl2cvjmmua7c5arysw3txz9r", + "pub_key": null, + "sequence": "0" + }, { "@type": "/cosmos.auth.v1beta1.ModuleAccount", "base_account": { @@ -76,6 +97,19 @@ "name": "distribution", "permissions": [] }, + { + "@type": "/cosmos.auth.v1beta1.ModuleAccount", + "base_account": { + "account_number": "9", + "address": "tarkeo1k8925g52vwe5jgfp4nqr7ljuhs7nzu2f8g0za5", + "pub_key": null, + "sequence": "0" + }, + "name": "arkeo", + "permissions": [ + "minter" + ] + }, { "@type": "/cosmos.auth.v1beta1.BaseAccount", "account_number": "0", @@ -86,6 +120,13 @@ }, "sequence": "2" }, + { + "@type": "/cosmos.auth.v1beta1.BaseAccount", + "account_number": "12", + "address": "tarkeo16k3k0erkwaanqnup20dxxenpd6wh058nh4pgup", + "pub_key": null, + "sequence": "0" + }, { "@type": "/cosmos.auth.v1beta1.ModuleAccount", "base_account": { @@ -144,7 +185,25 @@ "address": "tarkeo1v0n7wer498vqq6yddkr4clg3lck7kaw9lstp4k", "coins": [ { - "amount": "1000000000000000", + "amount": "1000000001000000", + "denom": "uarkeo" + } + ] + }, + { + "address": "tarkeo1v50hrsxx0mxar4653aujcnqyjft07w0npcxrjx", + "coins": [ + { + "amount": "42866203", + "denom": "uarkeo" + } + ] + }, + { + "address": "tarkeo10sav33v67743s6cl2cvjmmua7c5arysw3txz9r", + "coins": [ + { + "amount": "85732408", "denom": "uarkeo" } ] @@ -153,7 +212,34 @@ "address": "tarkeo1jv65s3grqf6v6jl3dp4t6c9t9rk99cd8t6gr9e", "coins": [ { - "amount": "2142114536", + "amount": "2142114540", + "denom": "uarkeo" + } + ] + }, + { + "address": "tarkeo1k8925g52vwe5jgfp4nqr7ljuhs7nzu2f8g0za5", + "coins": [ + { + "amount": "107165513", + "denom": "uarkeo" + } + ] + }, + { + "address": "tarkeo1hnyy4gp5tgarpg3xu6w5cw4zsyphx2lyvls9rz", + "coins": [ + { + "amount": "106058342", + "denom": "uarkeo" + } + ] + }, + { + "address": "tarkeo16k3k0erkwaanqnup20dxxenpd6wh058nh4pgup", + "coins": [ + { + "amount": "85732408", "denom": "uarkeo" } ] @@ -166,6 +252,15 @@ "denom": "uarkeo" } ] + }, + { + "address": "tarkeo1w3shy6m9damxzmr0wpjhyvtgdeuhjdr8wq6hgempwfcxwvmcw5m8wdtrwu685umewp58svnv09nxudf5wd5qsks9jp", + "coins": [ + { + "amount": "107166", + "denom": "uarkeo" + } + ] } ], "denom_metadata": [], @@ -176,7 +271,7 @@ "send_enabled": [], "supply": [ { - "amount": "52000002142114536", + "amount": "52000002570776580", "denom": "uarkeo" } ] @@ -251,7 +346,7 @@ "fee_pool": { "community_pool": [ { - "amount": "42842290.720000000000000000", + "amount": "42842290.800000000000000000", "denom": "uarkeo" } ] @@ -260,7 +355,7 @@ { "outstanding_rewards": [ { - "amount": "2099272245.280000000000000000", + "amount": "2099272249.200000000000000000", "denom": "uarkeo" } ], @@ -279,7 +374,7 @@ "accumulated": { "commission": [ { - "amount": "209927224.528000000000000000", + "amount": "209927224.920000000000000000", "denom": "uarkeo" } ] @@ -293,7 +388,7 @@ "period": "2", "rewards": [ { - "amount": "1889345020.752000000000000000", + "amount": "1889345024.280000000000000000", "denom": "uarkeo" } ] @@ -468,8 +563,8 @@ }, "mint": { "minter": { - "annual_provisions": "6759999207134722.421242256517847300", - "inflation": "0.129999982074947950" + "annual_provisions": "6759999234997758.173347634280370968", + "inflation": "0.129999982074948072" }, "params": { "blocks_per_year": "6311520", diff --git a/test/regression/mnt/exports/suites_providers_providers.json b/test/regression/mnt/exports/suites_providers_providers.json index 125546e8..f224271a 100644 --- a/test/regression/mnt/exports/suites_providers_providers.json +++ b/test/regression/mnt/exports/suites_providers_providers.json @@ -7,9 +7,9 @@ "contracts": [], "next_contract_id": "1", "params": { - "CommunityPoolPercentage": "0.100000000000000000", - "DevFundPercentage": "0.200000000000000000", - "ValidatorRewardsPercentage": "0.700000000000000000" + "CommunityPoolPercentage": "10", + "DevFundPercentage": "20", + "GrantFundPercentage": "20" }, "providers": [], "user_contract_sets": [], @@ -20,7 +20,7 @@ { "@type": "/cosmos.auth.v1beta1.ModuleAccount", "base_account": { - "account_number": "9", + "account_number": "14", "address": "tarkeo1rcvm4v5mcepj53fh2526uve0tly4grdsx5yw7k", "pub_key": null, "sequence": "0" @@ -66,6 +66,20 @@ }, "sequence": "5" }, + { + "@type": "/cosmos.auth.v1beta1.BaseAccount", + "account_number": "11", + "address": "tarkeo1v50hrsxx0mxar4653aujcnqyjft07w0npcxrjx", + "pub_key": null, + "sequence": "0" + }, + { + "@type": "/cosmos.auth.v1beta1.BaseAccount", + "account_number": "13", + "address": "tarkeo1w3shy6m9damxzmr0wpjhyvtgdeuhjdr8wq6hgempwfcxwvmcw5m8wdtrwu685umewp58svnv09nxudf5wd5qsks9jp", + "pub_key": null, + "sequence": "0" + }, { "@type": "/cosmos.auth.v1beta1.ModuleAccount", "base_account": { @@ -79,6 +93,13 @@ "burner" ] }, + { + "@type": "/cosmos.auth.v1beta1.BaseAccount", + "account_number": "10", + "address": "tarkeo10sav33v67743s6cl2cvjmmua7c5arysw3txz9r", + "pub_key": null, + "sequence": "0" + }, { "@type": "/cosmos.auth.v1beta1.ModuleAccount", "base_account": { @@ -90,6 +111,19 @@ "name": "distribution", "permissions": [] }, + { + "@type": "/cosmos.auth.v1beta1.ModuleAccount", + "base_account": { + "account_number": "9", + "address": "tarkeo1k8925g52vwe5jgfp4nqr7ljuhs7nzu2f8g0za5", + "pub_key": null, + "sequence": "0" + }, + "name": "arkeo", + "permissions": [ + "minter" + ] + }, { "@type": "/cosmos.auth.v1beta1.BaseAccount", "account_number": "0", @@ -100,6 +134,13 @@ }, "sequence": "1" }, + { + "@type": "/cosmos.auth.v1beta1.BaseAccount", + "account_number": "12", + "address": "tarkeo16k3k0erkwaanqnup20dxxenpd6wh058nh4pgup", + "pub_key": null, + "sequence": "0" + }, { "@type": "/cosmos.auth.v1beta1.ModuleAccount", "base_account": { @@ -163,11 +204,56 @@ } ] }, + { + "address": "tarkeo1v50hrsxx0mxar4653aujcnqyjft07w0npcxrjx", + "coins": [ + { + "amount": "257125458", + "denom": "uarkeo" + } + ] + }, + { + "address": "tarkeo10sav33v67743s6cl2cvjmmua7c5arysw3txz9r", + "coins": [ + { + "amount": "257197200", + "denom": "uarkeo" + } + ] + }, { "address": "tarkeo1jv65s3grqf6v6jl3dp4t6c9t9rk99cd8t6gr9e", "coins": [ { - "amount": "6426342986", + "amount": "6297816191", + "denom": "uarkeo" + } + ] + }, + { + "address": "tarkeo1k8925g52vwe5jgfp4nqr7ljuhs7nzu2f8g0za5", + "coins": [ + { + "amount": "107165513", + "denom": "uarkeo" + } + ] + }, + { + "address": "tarkeo1hnyy4gp5tgarpg3xu6w5cw4zsyphx2lyvls9rz", + "coins": [ + { + "amount": "535291663", + "denom": "uarkeo" + } + ] + }, + { + "address": "tarkeo16k3k0erkwaanqnup20dxxenpd6wh058nh4pgup", + "coins": [ + { + "amount": "257197200", "denom": "uarkeo" } ] @@ -180,6 +266,15 @@ "denom": "uarkeo" } ] + }, + { + "address": "tarkeo1w3shy6m9damxzmr0wpjhyvtgdeuhjdr8wq6hgempwfcxwvmcw5m8wdtrwu685umewp58svnv09nxudf5wd5qsks9jp", + "coins": [ + { + "amount": "535827", + "denom": "uarkeo" + } + ] } ], "denom_metadata": [], @@ -190,7 +285,7 @@ "send_enabled": [], "supply": [ { - "amount": "52000006426342986", + "amount": "52000007712329052", "denom": "uarkeo" } ] @@ -265,7 +360,7 @@ "fee_pool": { "community_pool": [ { - "amount": "128526859.720000000000000000", + "amount": "0.040000000000000000", "denom": "uarkeo" } ] @@ -274,7 +369,7 @@ { "outstanding_rewards": [ { - "amount": "6297816126.280000000000000000", + "amount": "6297816190.960000000000000000", "denom": "uarkeo" } ], @@ -293,7 +388,7 @@ "accumulated": { "commission": [ { - "amount": "629781612.628000000000000000", + "amount": "629781619.096000000000000000", "denom": "uarkeo" } ] @@ -307,7 +402,7 @@ "period": "2", "rewards": [ { - "amount": "5668034513.652000000000000000", + "amount": "5668034571.864000000000000000", "denom": "uarkeo" } ] @@ -482,8 +577,8 @@ }, "mint": { "minter": { - "annual_provisions": "6759997899879145.760700882792909356", - "inflation": "0.129999946224851156" + "annual_provisions": "6759998039194342.158301786339003680", + "inflation": "0.129999946224852984" }, "params": { "blocks_per_year": "6311520", diff --git a/test/regression/mnt/exports/suites_sentinel_contract_config.json b/test/regression/mnt/exports/suites_sentinel_contract_config.json index 12dae5ba..e40b16de 100644 --- a/test/regression/mnt/exports/suites_sentinel_contract_config.json +++ b/test/regression/mnt/exports/suites_sentinel_contract_config.json @@ -71,9 +71,9 @@ ], "next_contract_id": "1", "params": { - "CommunityPoolPercentage": "0.100000000000000000", - "DevFundPercentage": "0.200000000000000000", - "ValidatorRewardsPercentage": "0.700000000000000000" + "CommunityPoolPercentage": "10", + "DevFundPercentage": "20", + "GrantFundPercentage": "20" }, "providers": [ { @@ -141,6 +141,13 @@ "pub_key": null, "sequence": "0" }, + { + "@type": "/cosmos.auth.v1beta1.BaseAccount", + "account_number": "11", + "address": "tarkeo1v50hrsxx0mxar4653aujcnqyjft07w0npcxrjx", + "pub_key": null, + "sequence": "0" + }, { "@type": "/cosmos.auth.v1beta1.ModuleAccount", "base_account": { @@ -154,6 +161,13 @@ "burner" ] }, + { + "@type": "/cosmos.auth.v1beta1.BaseAccount", + "account_number": "10", + "address": "tarkeo10sav33v67743s6cl2cvjmmua7c5arysw3txz9r", + "pub_key": null, + "sequence": "0" + }, { "@type": "/cosmos.auth.v1beta1.ModuleAccount", "base_account": { @@ -165,6 +179,19 @@ "name": "distribution", "permissions": [] }, + { + "@type": "/cosmos.auth.v1beta1.ModuleAccount", + "base_account": { + "account_number": "9", + "address": "tarkeo1k8925g52vwe5jgfp4nqr7ljuhs7nzu2f8g0za5", + "pub_key": null, + "sequence": "0" + }, + "name": "arkeo", + "permissions": [ + "minter" + ] + }, { "@type": "/cosmos.auth.v1beta1.BaseAccount", "account_number": "0", @@ -175,6 +202,13 @@ }, "sequence": "1" }, + { + "@type": "/cosmos.auth.v1beta1.BaseAccount", + "account_number": "12", + "address": "tarkeo16k3k0erkwaanqnup20dxxenpd6wh058nh4pgup", + "pub_key": null, + "sequence": "0" + }, { "@type": "/cosmos.auth.v1beta1.ModuleAccount", "base_account": { @@ -247,6 +281,24 @@ } ] }, + { + "address": "tarkeo1v50hrsxx0mxar4653aujcnqyjft07w0npcxrjx", + "coins": [ + { + "amount": "21433514", + "denom": "uarkeo" + } + ] + }, + { + "address": "tarkeo10sav33v67743s6cl2cvjmmua7c5arysw3txz9r", + "coins": [ + { + "amount": "42867029", + "denom": "uarkeo" + } + ] + }, { "address": "tarkeo1kz2dkl8zlxwte008astc5e65htrxdcse6x3h3h", "coins": [ @@ -256,6 +308,24 @@ } ] }, + { + "address": "tarkeo1k8925g52vwe5jgfp4nqr7ljuhs7nzu2f8g0za5", + "coins": [ + { + "amount": "107167575", + "denom": "uarkeo" + } + ] + }, + { + "address": "tarkeo16k3k0erkwaanqnup20dxxenpd6wh058nh4pgup", + "coins": [ + { + "amount": "42867029", + "denom": "uarkeo" + } + ] + }, { "address": "tarkeo1uhapc6jjq6ns0ydnk7zld5x7f5kl2ukemjw5fg", "coins": [ @@ -283,7 +353,7 @@ "send_enabled": [], "supply": [ { - "amount": "52001001071078191", + "amount": "52001001285413338", "denom": "uarkeo" } ] diff --git a/test/regression/mnt/exports/suites_sentinel_sentinel.json b/test/regression/mnt/exports/suites_sentinel_sentinel.json index 5dd2d1c6..f9c739a1 100644 --- a/test/regression/mnt/exports/suites_sentinel_sentinel.json +++ b/test/regression/mnt/exports/suites_sentinel_sentinel.json @@ -7,9 +7,9 @@ "contracts": [], "next_contract_id": "1", "params": { - "CommunityPoolPercentage": "0.100000000000000000", - "DevFundPercentage": "0.200000000000000000", - "ValidatorRewardsPercentage": "0.700000000000000000" + "CommunityPoolPercentage": "10", + "DevFundPercentage": "20", + "GrantFundPercentage": "20" }, "providers": [], "user_contract_sets": [], @@ -52,6 +52,13 @@ "pub_key": null, "sequence": "0" }, + { + "@type": "/cosmos.auth.v1beta1.BaseAccount", + "account_number": "11", + "address": "tarkeo1v50hrsxx0mxar4653aujcnqyjft07w0npcxrjx", + "pub_key": null, + "sequence": "0" + }, { "@type": "/cosmos.auth.v1beta1.ModuleAccount", "base_account": { @@ -65,6 +72,13 @@ "burner" ] }, + { + "@type": "/cosmos.auth.v1beta1.BaseAccount", + "account_number": "10", + "address": "tarkeo10sav33v67743s6cl2cvjmmua7c5arysw3txz9r", + "pub_key": null, + "sequence": "0" + }, { "@type": "/cosmos.auth.v1beta1.ModuleAccount", "base_account": { @@ -76,6 +90,19 @@ "name": "distribution", "permissions": [] }, + { + "@type": "/cosmos.auth.v1beta1.ModuleAccount", + "base_account": { + "account_number": "9", + "address": "tarkeo1k8925g52vwe5jgfp4nqr7ljuhs7nzu2f8g0za5", + "pub_key": null, + "sequence": "0" + }, + "name": "arkeo", + "permissions": [ + "minter" + ] + }, { "@type": "/cosmos.auth.v1beta1.BaseAccount", "account_number": "0", @@ -86,6 +113,13 @@ }, "sequence": "1" }, + { + "@type": "/cosmos.auth.v1beta1.BaseAccount", + "account_number": "12", + "address": "tarkeo16k3k0erkwaanqnup20dxxenpd6wh058nh4pgup", + "pub_key": null, + "sequence": "0" + }, { "@type": "/cosmos.auth.v1beta1.ModuleAccount", "base_account": { @@ -149,6 +183,42 @@ } ] }, + { + "address": "tarkeo1v50hrsxx0mxar4653aujcnqyjft07w0npcxrjx", + "coins": [ + { + "amount": "21433102", + "denom": "uarkeo" + } + ] + }, + { + "address": "tarkeo10sav33v67743s6cl2cvjmmua7c5arysw3txz9r", + "coins": [ + { + "amount": "42866205", + "denom": "uarkeo" + } + ] + }, + { + "address": "tarkeo1k8925g52vwe5jgfp4nqr7ljuhs7nzu2f8g0za5", + "coins": [ + { + "amount": "107165513", + "denom": "uarkeo" + } + ] + }, + { + "address": "tarkeo16k3k0erkwaanqnup20dxxenpd6wh058nh4pgup", + "coins": [ + { + "amount": "42866205", + "denom": "uarkeo" + } + ] + }, { "address": "tarkeo1uhapc6jjq6ns0ydnk7zld5x7f5kl2ukemjw5fg", "coins": [ @@ -176,7 +246,7 @@ "send_enabled": [], "supply": [ { - "amount": "52000001071057294", + "amount": "52000001285388319", "denom": "uarkeo" } ] diff --git a/test/regression/suites/contracts/subscription.yaml b/test/regression/suites/contracts/subscription.yaml index ac5c0d62..875db64c 100644 --- a/test/regression/suites/contracts/subscription.yaml +++ b/test/regression/suites/contracts/subscription.yaml @@ -111,8 +111,8 @@ asserts: - .client_pubkey == "tarkeopub1addwnpepq2res6tu0m73ulk5sepgp6g3y37schfgymxy8z6l3lc78k7ju9u45yajwem" - .contract_type == "SUBSCRIPTION" - .settlement_duration == 11 - - .paid == 100 - - .reserve_contrib_asset == 10 + - .paid == 0 + - .reserve_contrib_asset == 0 # - .reserve_contrib_usd == 10 # TODO --- ######################################################################################## From 73e535e14adb296c1b54245956059779ba5a5cae Mon Sep 17 00:00:00 2001 From: shreyasbhat0 Date: Thu, 19 Sep 2024 19:28:00 +0530 Subject: [PATCH 20/24] feat: update inflation and payout --- x/arkeo/keeper/keeper.go | 95 +++++++--- x/arkeo/keeper/keeper_test.go | 10 +- x/arkeo/keeper/manager.go | 67 +++++-- x/arkeo/keeper/manager_test.go | 319 +++++++++++++++++++-------------- x/arkeo/module.go | 12 +- 5 files changed, 319 insertions(+), 184 deletions(-) diff --git a/x/arkeo/keeper/keeper.go b/x/arkeo/keeper/keeper.go index 2dc24b39..afade9f4 100644 --- a/x/arkeo/keeper/keeper.go +++ b/x/arkeo/keeper/keeper.go @@ -386,14 +386,23 @@ func (k KVStore) GetCirculatingSupply(ctx cosmos.Context, denom string) (cosmos. return cosmos.NewCoin(denom, sdkmath.NewInt(0)), err } totalSupply := fullTokenSupply.Supply.AmountOf(configs.Denom) - sdkContext.Logger().Error("Current supply of token with denom :", denom, "supply:", totalSupply) + sdkContext.Logger().Info(fmt.Sprintf("current supply of token with denom :%s : supply : %d", denom, totalSupply.Int64())) // Get the account addresses whose balances need to be exempted - devAccountAddress := k.getFoundationDevAccountAddress() + devAccountAddress, err := k.getFoundationDevAccountAddress() + if err != nil { + return cosmos.NewCoin(denom, sdkmath.NewInt(0)), fmt.Errorf("failed to fetch foundational account %s", err) + } - communityAccountAddress := k.getFoundationCommunityAccountAddress() + communityAccountAddress, err := k.getFoundationCommunityAccountAddress() + if err != nil { + return cosmos.NewCoin(denom, sdkmath.NewInt(0)), fmt.Errorf("failed to fetch foundational account %s", err) + } - grantAccountAddress := k.getFoundationGrantsAccountAddress() + grantAccountAddress, err := k.getFoundationGrantsAccountAddress() + if err != nil { + return cosmos.NewCoin(denom, sdkmath.NewInt(0)), fmt.Errorf("failed to fetch foundational account %s", err) + } // Module Address for which the circulating supply should be exempted moduleAddressToExempt := []sdk.AccAddress{ @@ -417,34 +426,59 @@ func (k KVStore) GetCirculatingSupply(ctx cosmos.Context, denom string) (cosmos. } func (k KVStore) MintAndDistributeTokens(ctx cosmos.Context, newlyMinted cosmos.Coin) (sdk.Coin, error) { - + sdkContext := sdk.UnwrapSDKContext(ctx) params := k.GetParams(ctx) - newlyMintedDec := sdkmath.LegacyNewDecFromInt(newlyMinted.Amount) + + sdkContext.Logger().Info(fmt.Sprintf("newly minted token %v", newlyMinted)) + newlyMintedAmount := newlyMinted.Amount // mint newly added tokens to reserve - if err := k.MintToModule(ctx, types.ReserveName, newlyMinted); err != nil { + if err := k.MintToModule(ctx, types.ModuleName, newlyMinted); err != nil { + sdkContext.Logger().Error(fmt.Sprintf("failed to mint %s", err)) return cosmos.NewCoin(newlyMinted.Denom, sdkmath.NewInt(0)), err } - devFundAmount := newlyMintedDec.Mul(params.DevFundPercentage).TruncateInt() - communityPoolAmount := newlyMintedDec.Mul(params.CommunityPoolPercentage).TruncateInt() - grantFundAmount := newlyMintedDec.Mul(params.GrantFundPercentage).TruncateInt() + devFundAmount := newlyMintedAmount.Mul(params.DevFundPercentage).Quo(sdkmath.NewInt(100)) + communityPoolAmount := newlyMintedAmount.Mul(params.CommunityPoolPercentage).Quo(sdkmath.NewInt(100)) + grantFundAmount := newlyMintedAmount.Mul(params.GrantFundPercentage).Quo(sdkmath.NewInt(100)) + + devAccountAddress, err := k.getFoundationDevAccountAddress() + if err != nil { + sdkContext.Logger().Error(fmt.Sprintf("failed to fetch foundational account %s", err)) + return cosmos.NewCoin(newlyMinted.Denom, sdkmath.NewInt(0)), fmt.Errorf("failed to fetch foundational account %s", err) + } + + communityAccountAddress, err := k.getFoundationCommunityAccountAddress() + if err != nil { + sdkContext.Logger().Error(fmt.Sprintf("failed to fetch foundational account %s", err)) + return cosmos.NewCoin(newlyMinted.Denom, sdkmath.NewInt(0)), fmt.Errorf("failed to fetch foundational account %s", err) + } - if err := k.SendFromModuleToModule(ctx, types.ReserveName, types.FoundationDevAccount, cosmos.NewCoins(cosmos.NewCoin(newlyMinted.Denom, devFundAmount))); err != nil { + grantAccountAddress, err := k.getFoundationGrantsAccountAddress() + if err != nil { + sdkContext.Logger().Error(fmt.Sprintf("failed to fetch foundational account %s", err)) + return cosmos.NewCoin(newlyMinted.Denom, sdkmath.NewInt(0)), fmt.Errorf("failed to fetch foundational account %s", err) + } + + if err := k.SendFromModuleToAccount(ctx, types.ModuleName, devAccountAddress, cosmos.NewCoins(cosmos.NewCoin(newlyMinted.Denom, devFundAmount))); err != nil { + sdkContext.Logger().Error(fmt.Sprintf("failed to send amount to Dev foundational account %s", err)) return cosmos.NewCoin(newlyMinted.Denom, sdkmath.NewInt(0)), fmt.Errorf("error sending amount to module %s", err) } - if err := k.SendFromModuleToModule(ctx, types.ReserveName, types.FoundationCommunityAccount, cosmos.NewCoins(cosmos.NewCoin(newlyMinted.Denom, communityPoolAmount))); err != nil { + if err := k.SendFromModuleToAccount(ctx, types.ModuleName, communityAccountAddress, cosmos.NewCoins(cosmos.NewCoin(newlyMinted.Denom, communityPoolAmount))); err != nil { + sdkContext.Logger().Error(fmt.Sprintf("failed to send amount to Community foundational account %s", err)) return cosmos.NewCoin(newlyMinted.Denom, sdkmath.NewInt(0)), fmt.Errorf("error sending amount to module %s", err) } - if err := k.SendFromModuleToModule(ctx, types.ReserveName, types.FoundationGrantsAccount, cosmos.NewCoins(cosmos.NewCoin(newlyMinted.Denom, grantFundAmount))); err != nil { + if err := k.SendFromModuleToAccount(ctx, types.ModuleName, grantAccountAddress, cosmos.NewCoins(cosmos.NewCoin(newlyMinted.Denom, grantFundAmount))); err != nil { + sdkContext.Logger().Error(fmt.Sprintf("failed to send amount to Grant foundational account %s", err)) return cosmos.NewCoin(newlyMinted.Denom, sdkmath.NewInt(0)), fmt.Errorf("error sending amount to module %s", err) } - balance := newlyMintedDec.Sub(sdkmath.LegacyDec(devFundAmount)).Sub(sdkmath.LegacyDec(communityPoolAmount)).Sub(sdkmath.LegacyDec(grantFundAmount)) + balance := newlyMintedAmount.Sub(devFundAmount).Sub(communityPoolAmount).Sub(grantFundAmount) + // newlyMintedAmount.Sub(sdkmath.LegacyDec(devFundAmount)).Sub(sdkmath.LegacyDec(communityPoolAmount)).Sub(sdkmath.LegacyDec(grantFundAmount)) - return cosmos.NewCoin(newlyMinted.Denom, sdkmath.NewInt(balance.RoundInt64())), nil + return cosmos.NewCoin(newlyMinted.Denom, balance), nil } @@ -467,26 +501,33 @@ func (k KVStore) MoveTokensFromDistributionToFoundationPoolAccount(ctx cosmos.Co } amount := pool.CommunityPool.AmountOf(configs.Denom) - communityAccountAddress := k.getFoundationCommunityAccountAddress() + communityAccountAddress, err := k.getFoundationCommunityAccountAddress() + if err != nil { + return fmt.Errorf("failed to fetch foundational account %s", err) + } if amount.RoundInt64() > 0 { - err = k.distributionKeeper.DistributeFromFeePool(ctx, cosmos.NewCoins(cosmos.NewCoin(configs.Denom, amount.RoundInt())), communityAccountAddress) - if err != nil { - return err + if err := k.distributionKeeper.DistributeFromFeePool(ctx, cosmos.NewCoins(cosmos.NewCoin(configs.Denom, amount.RoundInt())), communityAccountAddress); err != nil { + if err.Error() == "community pool does not have sufficient coins to distribute" { + ctx.Logger().Info(fmt.Sprintf("%s", err)) + return nil + } else { + ctx.Logger().Error(fmt.Sprintf("failed to distribute from community pool %s", err)) + return err + } } - } - return err + return nil } -func (k KVStore) getFoundationDevAccountAddress() cosmos.AccAddress { - return k.GetModuleAccAddress(types.FoundationDevAccount) +func (k KVStore) getFoundationDevAccountAddress() (cosmos.AccAddress, error) { + return sdk.AccAddressFromBech32(types.FoundationDevAccount) } -func (k KVStore) getFoundationCommunityAccountAddress() cosmos.AccAddress { - return k.GetModuleAccAddress(types.FoundationCommunityAccount) +func (k KVStore) getFoundationCommunityAccountAddress() (cosmos.AccAddress, error) { + return sdk.AccAddressFromBech32(types.FoundationCommunityAccount) } -func (k KVStore) getFoundationGrantsAccountAddress() cosmos.AccAddress { - return k.GetModuleAccAddress(types.FoundationGrantsAccount) +func (k KVStore) getFoundationGrantsAccountAddress() (cosmos.AccAddress, error) { + return sdk.AccAddressFromBech32(types.FoundationGrantsAccount) } diff --git a/x/arkeo/keeper/keeper_test.go b/x/arkeo/keeper/keeper_test.go index 1bb95e58..a09764ae 100644 --- a/x/arkeo/keeper/keeper_test.go +++ b/x/arkeo/keeper/keeper_test.go @@ -3,6 +3,7 @@ package keeper import ( "testing" + math "cosmossdk.io/math" storemetrics "cosmossdk.io/store/metrics" "github.com/cosmos/cosmos-sdk/runtime" "github.com/stretchr/testify/require" @@ -11,6 +12,7 @@ import ( "github.com/arkeonetwork/arkeo/common" "github.com/arkeonetwork/arkeo/common/cosmos" "github.com/arkeonetwork/arkeo/testutil/utils" + "github.com/arkeonetwork/arkeo/x/arkeo/configs" "github.com/arkeonetwork/arkeo/x/arkeo/types" "cosmossdk.io/log" @@ -25,6 +27,7 @@ import ( bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" distkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" + distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" disttypes "github.com/cosmos/cosmos-sdk/x/distribution/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper" @@ -36,7 +39,7 @@ import ( ) const ( - bech32Prefix = "arkeo" + bech32Prefix = "tarkeo" ) var ( @@ -198,6 +201,7 @@ func SetupKeeperWithStaking(t testing.TB) (cosmos.Context, Keeper, stakingkeeper stateStore.MountStoreWithDB(keyParams, storetypes.StoreTypeIAVL, db) stateStore.MountStoreWithDB(tkeyParams, storetypes.StoreTypeIAVL, db) stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil) + stateStore.MountStoreWithDB(keydist, storetypes.StoreTypeIAVL, db) require.NoError(t, stateStore.LoadLatestVersion()) encodingConfig := arekoappParams.MakeEncodingConfig() @@ -214,13 +218,14 @@ func SetupKeeperWithStaking(t testing.TB) (cosmos.Context, Keeper, stakingkeeper ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger()) - govModuleAddr := "arkeo12jurap3ypfmwzghj9d0t4wanc9gne2cktxh2y2" + govModuleAddr := "tarkeo1krj9ywwmqcellgunxg66kjw5dtt402kq0uf6pu" _ = paramskeeper.NewKeeper(cdc, amino, keyParams, tkeyParams) ak := authkeeper.NewAccountKeeper( cdc, runtime.NewKVStoreService(keyAcc), authtypes.ProtoBaseAccount, map[string][]string{ + distrtypes.ModuleName: {authtypes.Minter}, stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, types.ModuleName: {authtypes.Minter, authtypes.Burner}, @@ -276,6 +281,7 @@ func SetupKeeperWithStaking(t testing.TB) (cosmos.Context, Keeper, stakingkeeper authtypes.FeeCollectorName, govModuleAddr, ) + dk.FeePool.Set(ctx, disttypes.FeePool{CommunityPool: []sdk.DecCoin{sdk.NewDecCoin(configs.Denom, math.NewInt(10000))}}) k := NewKVStore( cdc, diff --git a/x/arkeo/keeper/manager.go b/x/arkeo/keeper/manager.go index 07a26b4d..9d97cd23 100644 --- a/x/arkeo/keeper/manager.go +++ b/x/arkeo/keeper/manager.go @@ -7,6 +7,7 @@ import ( sdkmath "cosmossdk.io/math" abci "github.com/cometbft/cometbft/abci/types" cmptm "github.com/cometbft/cometbft/proto/tendermint/types" + sdk "github.com/cosmos/cosmos-sdk/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" "github.com/arkeonetwork/arkeo/common" @@ -58,6 +59,7 @@ func (mgr *Manager) BeginBlock(ctx cosmos.Context) error { circSupply, err := mgr.circulatingSupplyAfterInflationCalc(ctx) if err != nil { ctx.Logger().Error("unable to get supply with inflation calculation", "error", err) + return err } err = mgr.keeper.MoveTokensFromDistributionToFoundationPoolAccount(ctx) @@ -65,8 +67,14 @@ func (mgr *Manager) BeginBlock(ctx cosmos.Context) error { ctx.Logger().Error("unable to send tokens from distribution to pool account", "error", err) } + validatorPayoutCycle := mgr.FetchConfig(ctx, configs.ValidatorPayoutCycle) + + emissionCurve := mgr.FetchConfig(ctx, configs.EmissionCurve) // Emission curve factor + blocksPerYear := mgr.FetchConfig(ctx, configs.BlocksPerYear) + // Calculate Block Rewards - blockReward := mgr.calcBlockReward(ctx, circSupply.Amount.Int64()) + blockReward := mgr.calcBlockReward(ctx, circSupply.Amount.ToLegacyDec().RoundInt64(), emissionCurve, blocksPerYear, validatorPayoutCycle) + ctx.Logger().Info(fmt.Sprintf("Block Reward %v", blockReward)) // Distribute Minted To Pools balanceDistribution, err := mgr.keeper.MintAndDistributeTokens(ctx, blockReward) @@ -209,10 +217,6 @@ func (mgr Manager) ContractEndBlock(ctx cosmos.Context) error { // Since the development goal at the moment is to get this chain up and // running, we can save this optimization for another day. func (mgr Manager) ValidatorPayout(ctx cosmos.Context, votes []abci.VoteInfo, blockReward cosmos.Coin) error { - valCycle := mgr.FetchConfig(ctx, configs.ValidatorPayoutCycle) - if valCycle == 0 || ctx.BlockHeight()%valCycle != 0 { - return nil - } if blockReward.IsZero() { return nil @@ -285,14 +289,15 @@ func (mgr Manager) ValidatorPayout(ctx cosmos.Context, votes []abci.VoteInfo, bl delegateReward = delegateReward.Sub(valFee) validatorReward = validatorReward.Add(valFee) } - if err := mgr.keeper.SendFromModuleToAccount(ctx, types.ReserveName, delegateAcc, cosmos.NewCoins(cosmos.NewCoin(blockReward.Denom, delegateReward))); err != nil { + if err := mgr.keeper.SendFromModuleToAccount(ctx, types.ModuleName, delegateAcc, cosmos.NewCoins(cosmos.NewCoin(blockReward.Denom, delegateReward))); err != nil { ctx.Logger().Error("unable to pay rewards to delegate", "delegate", delegate.DelegatorAddress, "error", err) + continue } ctx.Logger().Info("delegate rewarded", "delegate", delegateAcc.String(), "amount", delegateReward) } if !validatorReward.IsZero() { - if err := mgr.keeper.SendFromModuleToAccount(ctx, types.ReserveName, acc, cosmos.NewCoins(cosmos.NewCoin(blockReward.Denom, validatorReward))); err != nil { + if err := mgr.keeper.SendFromModuleToAccount(ctx, types.ModuleName, acc, cosmos.NewCoins(cosmos.NewCoin(blockReward.Denom, validatorReward))); err != nil { ctx.Logger().Error("unable to pay rewards to validator", "validator", val.GetOperator(), "error", err) continue } @@ -307,20 +312,31 @@ func (mgr Manager) ValidatorPayout(ctx cosmos.Context, votes []abci.VoteInfo, bl return nil } -func (mgr Manager) calcBlockReward(ctx cosmos.Context, totalReserve int64) cosmos.Coin { - - emissionCurve := mgr.FetchConfig(ctx, configs.EmissionCurve) // Emission curve factor - blocksPerYear := mgr.FetchConfig(ctx, configs.BlocksPerYear) +func (mgr Manager) calcBlockReward(ctx cosmos.Context, totalReserve, emissionCurve, blocksPerYear, validatorPayoutCycle int64) cosmos.Coin { + sdkContext := sdk.UnwrapSDKContext(ctx) // Block Rewards will take the latest reserve, divide it by the emission // curve factor, then divide by blocks per year if emissionCurve == 0 || blocksPerYear == 0 { + sdkContext.Logger().Info("block and emission-curve cannot be zero") return cosmos.NewCoin(configs.Denom, sdkmath.NewInt(0)) + } + + if validatorPayoutCycle == 0 || sdkContext.BlockHeight()%validatorPayoutCycle != 0 { + sdkContext.Logger().Info("validator payout cycle cannot be zero") + return cosmos.NewCoin(configs.Denom, sdkmath.NewInt(0)) + } + trD := cosmos.NewDec(totalReserve) ecD := cosmos.NewDec(emissionCurve) - bpyD := cosmos.NewDec(blocksPerYear) - return cosmos.NewCoin(configs.Denom, trD.Quo(ecD).Quo(bpyD).RoundInt()) + bpyD := cosmos.NewDec((blocksPerYear / validatorPayoutCycle)) + + blockReward := trD.Quo(ecD).Quo(bpyD).RoundInt() + + sdkContext.Logger().Info(fmt.Sprintf("block reward %d ", trD.Quo(ecD).Quo(bpyD).TruncateInt64())) + + return cosmos.NewCoin(configs.Denom, blockReward) } func (mgr Manager) FetchConfig(ctx cosmos.Context, name configs.ConfigName) int64 { @@ -419,17 +435,36 @@ func (mgr Manager) contractDebt(ctx cosmos.Context, contract types.Contract) (co func (mgr Manager) circulatingSupplyAfterInflationCalc(ctx cosmos.Context) (cosmos.Coin, error) { - circulatingSupply, err := mgr.keeper.GetCirculatingSupply(ctx, configs.Denom) + sdkContext := sdk.UnwrapSDKContext(ctx) + // Get the circulating supply + circulatingSupply, err := mgr.keeper.GetCirculatingSupply(ctx, configs.Denom) if err != nil { + sdkContext.Logger().Error(fmt.Sprintf("failed to get circulating supply %s", err)) return cosmos.NewCoin(configs.Denom, sdkmath.NewInt(0)), err } + + sdkContext.Logger().Info(fmt.Sprintf("Circulating supply: %v", circulatingSupply)) + + // Get the inflation rate inflationRate, err := mgr.keeper.GetInflationRate(ctx) if err != nil { + sdkContext.Logger().Error(fmt.Sprintf("failed to get inflation rate: %s", err)) return cosmos.NewCoin(configs.Denom, sdkmath.NewInt(0)), err } - newTokenAmountMinted := circulatingSupply.Amount.ToLegacyDec().Mul(sdkmath.LegacyDec(inflationRate.TruncateInt())) + sdkContext.Logger().Info(fmt.Sprintf("Inflation rate: %v", inflationRate)) + + // Convert circulating supply to decimal for precise calculation + circulatingSupplyDec := sdkmath.LegacyNewDec(circulatingSupply.Amount.Int64()) + + // Multiply circulating supply by inflation rate to get the newly minted token amount + newTokenAmountMintedDec := circulatingSupplyDec.Mul(inflationRate) + + // Convert the result back to integer and truncate any decimals + newTokenAmountMinted := newTokenAmountMintedDec.TruncateInt() + + sdkContext.Logger().Info(fmt.Sprintf("Newly minted token amount: %v", newTokenAmountMinted)) - return cosmos.NewCoin(configs.Denom, newTokenAmountMinted.RoundInt()), nil + return cosmos.NewCoin(configs.Denom, newTokenAmountMinted), nil } diff --git a/x/arkeo/keeper/manager_test.go b/x/arkeo/keeper/manager_test.go index e781aa12..67015d70 100644 --- a/x/arkeo/keeper/manager_test.go +++ b/x/arkeo/keeper/manager_test.go @@ -3,6 +3,11 @@ package keeper import ( "testing" + abci "github.com/cometbft/cometbft/abci/types" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" + sdk "github.com/cosmos/cosmos-sdk/types" + disttypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/stretchr/testify/require" "cosmossdk.io/math" @@ -285,143 +290,187 @@ func TestParamsRewardsPercentage(t *testing.T) { require.Equal(t, params.CommunityPoolPercentage, math.LegacyNewDecWithPrec(10, 2)) } +func TestCommunityPoolDistributionToFoundationCommunityPool(t *testing.T) { -// func TestValidatorPayouts(t *testing.T) { -// ctx, k, sk := SetupKeeperWithStaking(t) - -// pks := simtestutil.CreateTestPubKeys(3) -// pk1, err := common.NewPubKeyFromCrypto(pks[0]) -// require.NoError(t, err) -// acc1, err := pk1.GetMyAddress() -// require.NoError(t, err) -// pk2, err := common.NewPubKeyFromCrypto(pks[1]) -// require.NoError(t, err) -// acc2, err := pk2.GetMyAddress() -// require.NoError(t, err) -// pk3, err := common.NewPubKeyFromCrypto(pks[2]) -// require.NoError(t, err) -// acc3, err := pk3.GetMyAddress() -// require.NoError(t, err) - -// valAddrs := simtestutil.ConvertAddrsToValAddrs([]cosmos.AccAddress{acc1, acc2, acc3}) - -// val1, err := stakingtypes.NewValidator(valAddrs[0].String(), pks[0], stakingtypes.Description{}) -// require.NoError(t, err) -// val1.Tokens = cosmos.NewInt(100) -// val1.DelegatorShares = cosmos.NewDec(130) // Validator + Delegations -// val1.Status = stakingtypes.Bonded -// val1.Commission = stakingtypes.NewCommission(cosmos.NewDecWithPrec(1, 1), cosmos.ZeroDec(), cosmos.ZeroDec()) - -// val2, err := stakingtypes.NewValidator(valAddrs[1].String(), pks[1], stakingtypes.Description{}) -// require.NoError(t, err) -// val2.Tokens = cosmos.NewInt(200) -// val2.DelegatorShares = cosmos.NewDec(220) -// val2.Status = stakingtypes.Bonded -// val2.Commission = stakingtypes.NewCommission(cosmos.NewDecWithPrec(2, 1), cosmos.ZeroDec(), cosmos.ZeroDec()) - -// val3, err := stakingtypes.NewValidator(valAddrs[2].String(), pks[2], stakingtypes.Description{}) -// require.NoError(t, err) -// val3.Tokens = cosmos.NewInt(500) -// val3.DelegatorShares = cosmos.NewDec(500) -// val3.Status = stakingtypes.Bonded -// val3.Commission = stakingtypes.NewCommission(cosmos.NewDecWithPrec(5, 1), cosmos.ZeroDec(), cosmos.ZeroDec()) - -// vals := []stakingtypes.Validator{val1, val2, val3} -// for _, val := range vals { -// require.NoError(t, sk.SetValidator(ctx, val)) -// require.NoError(t, sk.SetValidatorByConsAddr(ctx, val)) -// require.NoError(t, sk.SetNewValidatorByPowerIndex(ctx, val)) -// } - -// delAcc1 := types.GetRandomBech32Addr() -// delAcc2 := types.GetRandomBech32Addr() -// delAcc3 := types.GetRandomBech32Addr() - -// require.NoError(t, sk.SetDelegation(ctx, stakingtypes.NewDelegation(acc1.String(), valAddrs[0].String(), cosmos.NewDec(100)))) -// require.NoError(t, sk.SetDelegation(ctx, stakingtypes.NewDelegation(acc2.String(), valAddrs[1].String(), cosmos.NewDec(200)))) -// require.NoError(t, sk.SetDelegation(ctx, stakingtypes.NewDelegation(acc3.String(), valAddrs[2].String(), cosmos.NewDec(500)))) - -// del1 := stakingtypes.NewDelegation(delAcc1.String(), valAddrs[0].String(), cosmos.NewDec(10)) -// del2 := stakingtypes.NewDelegation(delAcc2.String(), valAddrs[1].String(), cosmos.NewDec(20)) -// del3 := stakingtypes.NewDelegation(delAcc3.String(), valAddrs[2].String(), cosmos.NewDec(20)) -// require.NoError(t, sk.SetDelegation(ctx, del1)) -// require.NoError(t, sk.SetDelegation(ctx, del2)) -// require.NoError(t, sk.SetDelegation(ctx, del3)) - -// // Mint initial funds to the reserve -// require.NoError(t, k.MintToModule(ctx, types.ModuleName, getCoin(common.Tokens(200000)))) -// exemptModules := []string{types.GrantPool, types.CommunityPool, types.DevFundPool} -// for _, modules := range exemptModules { -// require.NoError(t, k.SendFromModuleToModule(ctx, types.ModuleName, modules, getCoins(common.Tokens(50000)))) -// } - -// // Set parameters for payouts -// params := types.DefaultParams() -// params.DevFundPercentage = sdkmath.LegacyNewDecWithPrec(20, 2) // 20% -// params.CommunityPoolPercentage = sdkmath.LegacyNewDecWithPrec(10, 2) // 10% -// params.ValidatorRewardsPercentage = sdkmath.LegacyNewDecWithPrec(70, 2) // 70% -// k.SetParams(ctx, params) - -// // Instantiate manager with keeper and staking keeper -// mgr := NewManager(k, sk) -// ctx = ctx.WithBlockHeight(mgr.FetchConfig(ctx, configs.ValidatorPayoutCycle)) - -// // Create VoteInfo for each validator -// votes := make([]abci.VoteInfo, len(vals)) -// for i, val := range vals { -// consAddr, err := val.GetConsAddr() -// require.NoError(t, err) -// votes[i] = abci.VoteInfo{ -// Validator: abci.Validator{ -// Address: consAddr, -// Power: val.Tokens.Int64(), -// }, -// BlockIdFlag: 2, -// } -// } - -// blockReward := int64(158529) -// newlyMintedDec := sdkmath.LegacyNewDecFromInt(sdkmath.NewInt(blockReward)) - -// _ = newlyMintedDec.Mul(params.DevFundPercentage).TruncateInt() -// _ = newlyMintedDec.Mul(params.CommunityPoolPercentage).TruncateInt() -// validatorRewardAmount := newlyMintedDec.Mul(params.ValidatorRewardsPercentage).TruncateInt() - -// // Expected block reward calculation - -// // validatorRewardPoolAddr := mgr.keeper.GetModuleAccAddress(types.ValidatorRewardPool) -// // fmt.Println(k.GetBalance(ctx, validatorRewardPoolAddr)) - -// // require.NoError(t, mgr.ValidatorPayout(ctx, votes,)) - -// // validatorRewardPoolAddr = mgr.keeper.GetModuleAccAddress(types.ValidatorRewardPool) -// // fmt.Println(k.GetBalance(ctx, validatorRewardPoolAddr).AmountOf(configs.Denom)) - -// // Verify the remaining balance after distribution -// // expectedRemaining := 5000000000000 - k.GetBalance(ctx, validatorRewardPoolAddr).AmountOf(configs.Denom).Int64() -// // require.Equal(t, k.GetBalanceOfModule(ctx, types.ReserveName, configs.Denom).Int64(), expectedRemaining) - -// totalBal := cosmos.ZeroInt() - -// // Check balances of validators 7 -// checkBalance(ctx, t, k, acc1, configs.Denom, 13042, &totalBal) -// checkBalance(ctx, t, k, acc2, configs.Denom, 26059, &totalBal) -// checkBalance(ctx, t, k, acc3, configs.Denom, 64950, &totalBal) - -// // Check balances of delegates -// checkBalance(ctx, t, k, delAcc1, configs.Denom, 1305, &totalBal) -// checkBalance(ctx, t, k, delAcc2, configs.Denom, 2606, &totalBal) -// checkBalance(ctx, t, k, delAcc3, configs.Denom, 2598, &totalBal) - -// fmt.Println(sdkmath.NewInt(110970).Sub(totalBal)) - -// // validatorRewardPoolAddr = mgr.keeper.GetModuleAccAddress(types.ValidatorRewardPool) -// // fmt.Println("Val", k.GetBalance(ctx, validatorRewardPoolAddr).AmountOf(configs.Denom)) - -// // Ensure the total block reward equals the sum of all payouts -// require.Equal(t, validatorRewardAmount.Int64(), int64(110970)) -// } + ctx, k, sk := SetupKeeperWithStaking(t) + mgr := NewManager(k, sk) + + require.NoError(t, k.MintToModule(ctx, disttypes.ModuleName, getCoin(common.Tokens(200000)))) + + err := mgr.keeper.MoveTokensFromDistributionToFoundationPoolAccount(ctx) + require.NoError(t, err) + + address, err := sdk.AccAddressFromBech32(types.FoundationCommunityAccount) + require.NoError(t, err) + + bal := mgr.keeper.GetBalance(ctx, address).AmountOf(configs.Denom) + + require.Equal(t, bal, sdkmath.NewInt(10000)) +} + +func TestBlockRewardCalculation(t *testing.T) { + ctx, k, sk := SetupKeeperWithStaking(t) + mgr := NewManager(k, sk) + + // BlockPer Year -> 5000 + // Emission Curve -> 10 + // Total Reserve -> 100000000 + // validator cycle -> 100 + // reward = (totalReserve / emissionCurve) / (blocksPerYear / valCycle)) -> 2000 + valCycle := int64(100) + emissionCurve := int64(10) + blocksPerYear := int64(5000) + totalReserve := int64(1000000) + + reward := mgr.calcBlockReward(ctx, totalReserve, emissionCurve, blocksPerYear, valCycle) + + require.Equal(t, reward.Amount.Int64(), int64(2000)) + + valCycle = int64(10) + emissionCurve = int64(5) + blocksPerYear = int64(200) + totalReserve = int64(999999) + + reward = mgr.calcBlockReward(ctx, totalReserve, emissionCurve, blocksPerYear, valCycle) + + require.Equal(t, reward.Amount.Int64(), int64(10000)) // its 9999.99 rounded to 10000 +} + +func TestValidatorPayouts(t *testing.T) { + ctx, k, sk := SetupKeeperWithStaking(t) + mgr := NewManager(k, sk) + + valCycle := int64(100) + emissionCurve := int64(10) + blocksPerYear := int64(5000) + totalReserve := int64(1000000000) + + blockReward := mgr.calcBlockReward(ctx, totalReserve, emissionCurve, blocksPerYear, valCycle) + + require.Equal(t, blockReward.Amount.Int64(), int64(2000000)) + + pks := simtestutil.CreateTestPubKeys(3) + pk1, err := common.NewPubKeyFromCrypto(pks[0]) + require.NoError(t, err) + acc1, err := pk1.GetMyAddress() + require.NoError(t, err) + pk2, err := common.NewPubKeyFromCrypto(pks[1]) + require.NoError(t, err) + acc2, err := pk2.GetMyAddress() + require.NoError(t, err) + pk3, err := common.NewPubKeyFromCrypto(pks[2]) + require.NoError(t, err) + acc3, err := pk3.GetMyAddress() + require.NoError(t, err) + + valAddrs := simtestutil.ConvertAddrsToValAddrs([]cosmos.AccAddress{acc1, acc2, acc3}) + + val1, err := stakingtypes.NewValidator(valAddrs[0].String(), pks[0], stakingtypes.Description{}) + require.NoError(t, err) + val1.Tokens = cosmos.NewInt(100) + val1.DelegatorShares = cosmos.NewDec(130) // Validator + Delegations + val1.Status = stakingtypes.Bonded + val1.Commission = stakingtypes.NewCommission(cosmos.NewDecWithPrec(1, 1), cosmos.ZeroDec(), cosmos.ZeroDec()) + + val2, err := stakingtypes.NewValidator(valAddrs[1].String(), pks[1], stakingtypes.Description{}) + require.NoError(t, err) + val2.Tokens = cosmos.NewInt(200) + val2.DelegatorShares = cosmos.NewDec(220) + val2.Status = stakingtypes.Bonded + val2.Commission = stakingtypes.NewCommission(cosmos.NewDecWithPrec(2, 1), cosmos.ZeroDec(), cosmos.ZeroDec()) + + val3, err := stakingtypes.NewValidator(valAddrs[2].String(), pks[2], stakingtypes.Description{}) + require.NoError(t, err) + val3.Tokens = cosmos.NewInt(500) + val3.DelegatorShares = cosmos.NewDec(500) + val3.Status = stakingtypes.Bonded + val3.Commission = stakingtypes.NewCommission(cosmos.NewDecWithPrec(5, 1), cosmos.ZeroDec(), cosmos.ZeroDec()) + + vals := []stakingtypes.Validator{val1, val2, val3} + for _, val := range vals { + require.NoError(t, sk.SetValidator(ctx, val)) + require.NoError(t, sk.SetValidatorByConsAddr(ctx, val)) + require.NoError(t, sk.SetNewValidatorByPowerIndex(ctx, val)) + } + + delAcc1 := types.GetRandomBech32Addr() + delAcc2 := types.GetRandomBech32Addr() + delAcc3 := types.GetRandomBech32Addr() + + require.NoError(t, sk.SetDelegation(ctx, stakingtypes.NewDelegation(acc1.String(), valAddrs[0].String(), cosmos.NewDec(100)))) + require.NoError(t, sk.SetDelegation(ctx, stakingtypes.NewDelegation(acc2.String(), valAddrs[1].String(), cosmos.NewDec(200)))) + require.NoError(t, sk.SetDelegation(ctx, stakingtypes.NewDelegation(acc3.String(), valAddrs[2].String(), cosmos.NewDec(500)))) + + del1 := stakingtypes.NewDelegation(delAcc1.String(), valAddrs[0].String(), cosmos.NewDec(10)) + del2 := stakingtypes.NewDelegation(delAcc2.String(), valAddrs[1].String(), cosmos.NewDec(20)) + del3 := stakingtypes.NewDelegation(delAcc3.String(), valAddrs[2].String(), cosmos.NewDec(20)) + require.NoError(t, sk.SetDelegation(ctx, del1)) + require.NoError(t, sk.SetDelegation(ctx, del2)) + require.NoError(t, sk.SetDelegation(ctx, del3)) + + // Mint initial funds to the reserve + require.NoError(t, k.MintToModule(ctx, types.ModuleName, getCoin(common.Tokens(200000)))) + + ctx = ctx.WithBlockHeight(mgr.FetchConfig(ctx, configs.ValidatorPayoutCycle)) + + // Create VoteInfo for each validator + votes := make([]abci.VoteInfo, len(vals)) + for i, val := range vals { + consAddr, err := val.GetConsAddr() + require.NoError(t, err) + votes[i] = abci.VoteInfo{ + Validator: abci.Validator{ + Address: consAddr, + Power: val.Tokens.Int64(), + }, + BlockIdFlag: 2, + } + } + balanceDistribution, err := mgr.keeper.MintAndDistributeTokens(ctx, blockReward) + if err != nil { + ctx.Logger().Error("unable to mint and distribute tokens", "error", err) + } + devAccountAddress, err := sdk.AccAddressFromBech32(types.FoundationDevAccount) + require.NoError(t, err) + grantAccountAddress, err := sdk.AccAddressFromBech32(types.FoundationGrantsAccount) + require.NoError(t, err) + + communityAccountAddress, err := sdk.AccAddressFromBech32(types.FoundationCommunityAccount) + require.NoError(t, err) + + devAccountBal := k.GetBalance(ctx, devAccountAddress).AmountOf(configs.Denom) + require.Equal(t, devAccountBal, sdkmath.NewInt(400000)) + + grantAccountBal := k.GetBalance(ctx, grantAccountAddress).AmountOf(configs.Denom) + require.Equal(t, grantAccountBal, sdkmath.NewInt(400000)) + + communityAccountBal := k.GetBalance(ctx, communityAccountAddress).AmountOf(configs.Denom) + require.Equal(t, communityAccountBal, sdkmath.NewInt(200000)) + + moduleBalance := k.GetBalanceOfModule(ctx, types.ModuleName, configs.Denom) + require.Equal(t, moduleBalance.Int64(), int64(20000001000000)) + + require.NoError(t, mgr.ValidatorPayout(ctx, votes, balanceDistribution)) + + totalBal := cosmos.ZeroInt() + + // Check balances of validators 7 + checkBalance(ctx, t, k, acc1, configs.Denom, 117529, &totalBal) + checkBalance(ctx, t, k, acc2, configs.Denom, 234824, &totalBal) + checkBalance(ctx, t, k, acc3, configs.Denom, 585294, &totalBal) + + // Check balances of delegates + checkBalance(ctx, t, k, delAcc1, configs.Denom, 11753, &totalBal) + checkBalance(ctx, t, k, delAcc2, configs.Denom, 23482, &totalBal) + checkBalance(ctx, t, k, delAcc3, configs.Denom, 23411, &totalBal) + + require.Equal(t, totalBal.ToLegacyDec(), sdkmath.LegacyNewDec(996293)) + + moduleBalance = k.GetBalanceOfModule(ctx, types.ModuleName, configs.Denom) + require.Equal(t, moduleBalance.Int64(), int64(20000000000000)) + +} func checkBalance(ctx cosmos.Context, t *testing.T, k Keeper, acc cosmos.AccAddress, denom string, expectedAmt int64, total *sdkmath.Int) { bal := k.GetBalance(ctx, acc) *total = total.Add(bal.AmountOf(denom)) diff --git a/x/arkeo/module.go b/x/arkeo/module.go index f1c3df12..534d659f 100644 --- a/x/arkeo/module.go +++ b/x/arkeo/module.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" + "cosmossdk.io/core/appmodule" "github.com/arkeonetwork/arkeo/x/arkeo/client/cli" "github.com/arkeonetwork/arkeo/x/arkeo/keeper" "github.com/arkeonetwork/arkeo/x/arkeo/types" @@ -29,6 +30,7 @@ var ( _ module.AppModuleBasic = AppModuleBasic{} _ module.HasABCIEndBlock = AppModule{} _ module.HasGenesis = AppModule{} + _ appmodule.AppModule = AppModule{} ) // ---------------------------------------------------------------------------- @@ -104,7 +106,6 @@ type AppModule struct { stakingKeeper stakingkeeper.Keeper } - func NewAppModule( cdc codec.Codec, keeper keeper.Keeper, @@ -149,11 +150,14 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw func (am AppModule) ConsensusVersion() uint64 { return 1 } // BeginBlock contains the logic that is automatically triggered at the beginning of each block -func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestFinalizeBlock) { +func (am AppModule) BeginBlock(ctx context.Context) error { + context := sdk.UnwrapSDKContext(ctx) mgr := keeper.NewManager(am.keeper, am.stakingKeeper) - if err := mgr.BeginBlock(ctx); err != nil { - ctx.Logger().Error("manager beginblock error ", "error", err) + if err := mgr.BeginBlock(context); err != nil { + context.Logger().Error("manager beginblock error ", "error", err) + return err } + return nil } // EndBlock contains the logic that is automatically triggered at the end of each block From 3b0e5ead3f110a68dffdd0e26385703aaff6a67c Mon Sep 17 00:00:00 2001 From: shreyasbhat0 Date: Thu, 19 Sep 2024 19:32:10 +0530 Subject: [PATCH 21/24] chore: update genesis file --- scripts/genesis.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/scripts/genesis.sh b/scripts/genesis.sh index 82185630..0fd001ca 100755 --- a/scripts/genesis.sh +++ b/scripts/genesis.sh @@ -84,9 +84,6 @@ if [ ! -f ~/.arkeo/config/genesis.json ]; then if [ "$NET" = "mocknet" ] || [ "$NET" = "testnet" ]; then add_module tarkeo1d0m97ywk2y4vq58ud6q5e0r3q9khj9e3unfe4t $TOKEN 10000000000000000 'arkeo-reserve' # reserve, 10m add_module tarkeo14tmx70mvve3u7hfmd45vle49kvylk6s2wllxny $TOKEN 10000000000000000 'claimarkeo' - add_module tarkeo10sav33v67743s6cl2cvjmmua7c5arysw3txz9r $TOKEN 10000000000000000 'devpool' - add_module tarkeo1v50hrsxx0mxar4653aujcnqyjft07w0npcxrjx $TOKEN 10000000000000000 'communitypool' - add_module tarkeo16k3k0erkwaanqnup20dxxenpd6wh058nh4pgup $TOKEN 10000000000000000 'grantspool' echo "shoulder heavy loyal save patient deposit crew bag pull club escape eyebrow hip verify border into wire start pact faint fame festival solve shop" | arkeod keys add alice --keyring-backend test --recover ALICE=$(arkeod keys show alice -a --keyring-backend test) @@ -97,6 +94,15 @@ if [ ! -f ~/.arkeo/config/genesis.json ]; then add_account "$BOB" $TOKEN 1000000000000000 # bob, 1m add_claim_records "ARKEO" "$BOB" 1000 1000 1000 true + # Add Foundational Accounts + # FoundationCommunityAccount = "tarkeo1v50hrsxx0mxar4653aujcnqyjft07w0npcxrjx" + add_account "tarkeo1v50hrsxx0mxar4653aujcnqyjft07w0npcxrjx" $TOKEN 10000 + # FoundationDevAccount = "tarkeo10sav33v67743s6cl2cvjmmua7c5arysw3txz9r" + add_account "tarkeo10sav33v67743s6cl2cvjmmua7c5arysw3txz9r" $TOKEN 10000 + # FoundationGrantsAccount = "tarkeo16k3k0erkwaanqnup20dxxenpd6wh058nh4pgup" + add_account "tarkeo16k3k0erkwaanqnup20dxxenpd6wh058nh4pgup" $TOKEN 10000 + + # Thorchain derived test addresses add_account "tarkeo1dllfyp57l4xj5umqfcqy6c2l3xfk0qk6zpc3t7" $TOKEN 1000000000000000 # bob, 10m add_claim_records "ARKEO" "tarkeo1dllfyp57l4xj5umqfcqy6c2l3xfk0qk6zpc3t7" 1000 1000 1000 true From db0013d9011f577a5252a7cc9d70276b292c6acb Mon Sep 17 00:00:00 2001 From: shreyasbhat0 Date: Thu, 19 Sep 2024 19:35:03 +0530 Subject: [PATCH 22/24] fix: logging in modules --- x/arkeo/keeper/keeper.go | 5 +---- x/arkeo/keeper/manager.go | 4 ---- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/x/arkeo/keeper/keeper.go b/x/arkeo/keeper/keeper.go index afade9f4..689cc479 100644 --- a/x/arkeo/keeper/keeper.go +++ b/x/arkeo/keeper/keeper.go @@ -427,9 +427,8 @@ func (k KVStore) GetCirculatingSupply(ctx cosmos.Context, denom string) (cosmos. func (k KVStore) MintAndDistributeTokens(ctx cosmos.Context, newlyMinted cosmos.Coin) (sdk.Coin, error) { sdkContext := sdk.UnwrapSDKContext(ctx) - params := k.GetParams(ctx) - sdkContext.Logger().Info(fmt.Sprintf("newly minted token %v", newlyMinted)) + params := k.GetParams(ctx) newlyMintedAmount := newlyMinted.Amount // mint newly added tokens to reserve @@ -476,8 +475,6 @@ func (k KVStore) MintAndDistributeTokens(ctx cosmos.Context, newlyMinted cosmos. } balance := newlyMintedAmount.Sub(devFundAmount).Sub(communityPoolAmount).Sub(grantFundAmount) - // newlyMintedAmount.Sub(sdkmath.LegacyDec(devFundAmount)).Sub(sdkmath.LegacyDec(communityPoolAmount)).Sub(sdkmath.LegacyDec(grantFundAmount)) - return cosmos.NewCoin(newlyMinted.Denom, balance), nil } diff --git a/x/arkeo/keeper/manager.go b/x/arkeo/keeper/manager.go index 9d97cd23..f5fb762c 100644 --- a/x/arkeo/keeper/manager.go +++ b/x/arkeo/keeper/manager.go @@ -444,8 +444,6 @@ func (mgr Manager) circulatingSupplyAfterInflationCalc(ctx cosmos.Context) (cosm return cosmos.NewCoin(configs.Denom, sdkmath.NewInt(0)), err } - sdkContext.Logger().Info(fmt.Sprintf("Circulating supply: %v", circulatingSupply)) - // Get the inflation rate inflationRate, err := mgr.keeper.GetInflationRate(ctx) if err != nil { @@ -464,7 +462,5 @@ func (mgr Manager) circulatingSupplyAfterInflationCalc(ctx cosmos.Context) (cosm // Convert the result back to integer and truncate any decimals newTokenAmountMinted := newTokenAmountMintedDec.TruncateInt() - sdkContext.Logger().Info(fmt.Sprintf("Newly minted token amount: %v", newTokenAmountMinted)) - return cosmos.NewCoin(configs.Denom, newTokenAmountMinted), nil } From 1dd0b993ccb23b8b49d425f5bb852c15edadd557 Mon Sep 17 00:00:00 2001 From: shreyasbhat0 Date: Thu, 19 Sep 2024 19:54:50 +0530 Subject: [PATCH 23/24] fix: regression tests --- test/regression/suites/contracts/subscription.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/regression/suites/contracts/subscription.yaml b/test/regression/suites/contracts/subscription.yaml index ac5c0d62..875db64c 100644 --- a/test/regression/suites/contracts/subscription.yaml +++ b/test/regression/suites/contracts/subscription.yaml @@ -111,8 +111,8 @@ asserts: - .client_pubkey == "tarkeopub1addwnpepq2res6tu0m73ulk5sepgp6g3y37schfgymxy8z6l3lc78k7ju9u45yajwem" - .contract_type == "SUBSCRIPTION" - .settlement_duration == 11 - - .paid == 100 - - .reserve_contrib_asset == 10 + - .paid == 0 + - .reserve_contrib_asset == 0 # - .reserve_contrib_usd == 10 # TODO --- ######################################################################################## From 87cd7e9d32d3970638c1e2e93897bea7535bc0ef Mon Sep 17 00:00:00 2001 From: shreyasbhat0 Date: Thu, 19 Sep 2024 20:09:35 +0530 Subject: [PATCH 24/24] fix: go lint --- app/app_regtest.go | 2 +- .../mnt/exports/suites_contracts_pay-as-you-go.json | 4 +++- .../mnt/exports/suites_contracts_subscription.json | 4 +++- test/regression/mnt/exports/suites_core_send.json | 4 +++- test/regression/mnt/exports/suites_initialize.json | 4 +++- .../mnt/exports/suites_providers_providers.json | 4 +++- .../mnt/exports/suites_sentinel_contract_config.json | 4 +++- .../mnt/exports/suites_sentinel_sentinel.json | 4 +++- testutil/keeper/arkeo.go | 1 + x/arkeo/keeper/keeper.go | 12 +++++------- x/arkeo/keeper/keeper_test.go | 3 ++- x/arkeo/keeper/manager.go | 4 ---- x/arkeo/keeper/manager_test.go | 7 ++----- x/arkeo/module.go | 1 + 14 files changed, 33 insertions(+), 25 deletions(-) diff --git a/app/app_regtest.go b/app/app_regtest.go index 3918b8bb..d8f23413 100644 --- a/app/app_regtest.go +++ b/app/app_regtest.go @@ -220,7 +220,7 @@ var ( // module account permissions maccPerms = map[string][]string{ authtypes.FeeCollectorName: nil, - distrtypes.ModuleName: nil, + distrtypes.ModuleName: {authtypes.Minter}, icatypes.ModuleName: nil, minttypes.ModuleName: {authtypes.Minter}, stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, diff --git a/test/regression/mnt/exports/suites_contracts_pay-as-you-go.json b/test/regression/mnt/exports/suites_contracts_pay-as-you-go.json index c3b4b5a5..78d5cb9d 100644 --- a/test/regression/mnt/exports/suites_contracts_pay-as-you-go.json +++ b/test/regression/mnt/exports/suites_contracts_pay-as-you-go.json @@ -173,7 +173,9 @@ "sequence": "0" }, "name": "distribution", - "permissions": [] + "permissions": [ + "minter" + ] }, { "@type": "/cosmos.auth.v1beta1.ModuleAccount", diff --git a/test/regression/mnt/exports/suites_contracts_subscription.json b/test/regression/mnt/exports/suites_contracts_subscription.json index 57899793..0811cce4 100644 --- a/test/regression/mnt/exports/suites_contracts_subscription.json +++ b/test/regression/mnt/exports/suites_contracts_subscription.json @@ -191,7 +191,9 @@ "sequence": "0" }, "name": "distribution", - "permissions": [] + "permissions": [ + "minter" + ] }, { "@type": "/cosmos.auth.v1beta1.ModuleAccount", diff --git a/test/regression/mnt/exports/suites_core_send.json b/test/regression/mnt/exports/suites_core_send.json index 71e1bdc1..39ae93ec 100644 --- a/test/regression/mnt/exports/suites_core_send.json +++ b/test/regression/mnt/exports/suites_core_send.json @@ -95,7 +95,9 @@ "sequence": "0" }, "name": "distribution", - "permissions": [] + "permissions": [ + "minter" + ] }, { "@type": "/cosmos.auth.v1beta1.ModuleAccount", diff --git a/test/regression/mnt/exports/suites_initialize.json b/test/regression/mnt/exports/suites_initialize.json index fd9fa130..8faee0d3 100644 --- a/test/regression/mnt/exports/suites_initialize.json +++ b/test/regression/mnt/exports/suites_initialize.json @@ -95,7 +95,9 @@ "sequence": "0" }, "name": "distribution", - "permissions": [] + "permissions": [ + "minter" + ] }, { "@type": "/cosmos.auth.v1beta1.ModuleAccount", diff --git a/test/regression/mnt/exports/suites_providers_providers.json b/test/regression/mnt/exports/suites_providers_providers.json index f224271a..4b1a06b9 100644 --- a/test/regression/mnt/exports/suites_providers_providers.json +++ b/test/regression/mnt/exports/suites_providers_providers.json @@ -109,7 +109,9 @@ "sequence": "0" }, "name": "distribution", - "permissions": [] + "permissions": [ + "minter" + ] }, { "@type": "/cosmos.auth.v1beta1.ModuleAccount", diff --git a/test/regression/mnt/exports/suites_sentinel_contract_config.json b/test/regression/mnt/exports/suites_sentinel_contract_config.json index e40b16de..b3e3034f 100644 --- a/test/regression/mnt/exports/suites_sentinel_contract_config.json +++ b/test/regression/mnt/exports/suites_sentinel_contract_config.json @@ -177,7 +177,9 @@ "sequence": "0" }, "name": "distribution", - "permissions": [] + "permissions": [ + "minter" + ] }, { "@type": "/cosmos.auth.v1beta1.ModuleAccount", diff --git a/test/regression/mnt/exports/suites_sentinel_sentinel.json b/test/regression/mnt/exports/suites_sentinel_sentinel.json index f9c739a1..4ce43644 100644 --- a/test/regression/mnt/exports/suites_sentinel_sentinel.json +++ b/test/regression/mnt/exports/suites_sentinel_sentinel.json @@ -88,7 +88,9 @@ "sequence": "0" }, "name": "distribution", - "permissions": [] + "permissions": [ + "minter" + ] }, { "@type": "/cosmos.auth.v1beta1.ModuleAccount", diff --git a/testutil/keeper/arkeo.go b/testutil/keeper/arkeo.go index 3a411938..05f7b8d7 100644 --- a/testutil/keeper/arkeo.go +++ b/testutil/keeper/arkeo.go @@ -76,6 +76,7 @@ func ArkeoKeeper(t testing.TB) (cosmos.Context, keeper.Keeper) { runtime.NewKVStoreService(keyAcc), authtypes.ProtoBaseAccount, map[string][]string{ + disttypes.ModuleName: {authtypes.Minter}, stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, types.ModuleName: {authtypes.Minter, authtypes.Burner}, diff --git a/x/arkeo/keeper/keeper.go b/x/arkeo/keeper/keeper.go index 689cc479..a1900d1e 100644 --- a/x/arkeo/keeper/keeper.go +++ b/x/arkeo/keeper/keeper.go @@ -10,10 +10,6 @@ import ( "cosmossdk.io/math" sdkmath "cosmossdk.io/math" storetypes "cosmossdk.io/store/types" - "github.com/arkeonetwork/arkeo/common" - "github.com/arkeonetwork/arkeo/common/cosmos" - "github.com/arkeonetwork/arkeo/x/arkeo/configs" - "github.com/arkeonetwork/arkeo/x/arkeo/types" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -25,6 +21,11 @@ import ( paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + + "github.com/arkeonetwork/arkeo/common" + "github.com/arkeonetwork/arkeo/common/cosmos" + "github.com/arkeonetwork/arkeo/x/arkeo/configs" + "github.com/arkeonetwork/arkeo/x/arkeo/types" ) type dbPrefix string @@ -376,7 +377,6 @@ func (k KVStore) GetAuthority() string { } func (k KVStore) GetCirculatingSupply(ctx cosmos.Context, denom string) (cosmos.Coin, error) { - sdkContext := sdk.UnwrapSDKContext(ctx) // Get Total Supply @@ -476,7 +476,6 @@ func (k KVStore) MintAndDistributeTokens(ctx cosmos.Context, newlyMinted cosmos. balance := newlyMintedAmount.Sub(devFundAmount).Sub(communityPoolAmount).Sub(grantFundAmount) return cosmos.NewCoin(newlyMinted.Denom, balance), nil - } func (k KVStore) GetInflationRate(ctx cosmos.Context) (math.LegacyDec, error) { @@ -490,7 +489,6 @@ func (k KVStore) GetInflationRate(ctx cosmos.Context) (math.LegacyDec, error) { // transfer tokens form the Distribution to Foundation Community Pool func (k KVStore) MoveTokensFromDistributionToFoundationPoolAccount(ctx cosmos.Context) error { - // get pool balance pool, err := k.distributionKeeper.FeePool.Get(ctx) if err != nil { diff --git a/x/arkeo/keeper/keeper_test.go b/x/arkeo/keeper/keeper_test.go index a09764ae..e30fe16b 100644 --- a/x/arkeo/keeper/keeper_test.go +++ b/x/arkeo/keeper/keeper_test.go @@ -101,6 +101,7 @@ func SetupKeeper(t testing.TB) (cosmos.Context, Keeper) { runtime.NewKVStoreService(keyAcc), authtypes.ProtoBaseAccount, map[string][]string{ + distrtypes.ModuleName: {authtypes.Minter}, stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, types.ModuleName: {authtypes.Minter, authtypes.Burner}, @@ -281,7 +282,7 @@ func SetupKeeperWithStaking(t testing.TB) (cosmos.Context, Keeper, stakingkeeper authtypes.FeeCollectorName, govModuleAddr, ) - dk.FeePool.Set(ctx, disttypes.FeePool{CommunityPool: []sdk.DecCoin{sdk.NewDecCoin(configs.Denom, math.NewInt(10000))}}) + _ = dk.FeePool.Set(ctx, disttypes.FeePool{CommunityPool: []sdk.DecCoin{sdk.NewDecCoin(configs.Denom, math.NewInt(10000))}}) k := NewKVStore( cdc, diff --git a/x/arkeo/keeper/manager.go b/x/arkeo/keeper/manager.go index f5fb762c..080ce0c0 100644 --- a/x/arkeo/keeper/manager.go +++ b/x/arkeo/keeper/manager.go @@ -217,7 +217,6 @@ func (mgr Manager) ContractEndBlock(ctx cosmos.Context) error { // Since the development goal at the moment is to get this chain up and // running, we can save this optimization for another day. func (mgr Manager) ValidatorPayout(ctx cosmos.Context, votes []abci.VoteInfo, blockReward cosmos.Coin) error { - if blockReward.IsZero() { return nil } @@ -240,7 +239,6 @@ func (mgr Manager) ValidatorPayout(ctx cosmos.Context, votes []abci.VoteInfo, bl } for _, vote := range votes { - if vote.BlockIdFlag.String() != "BLOCK_ID_FLAG_COMMIT" { ctx.Logger().Info("validator rewards skipped due to lack of signature", "validator", string(vote.Validator.Address)) continue @@ -320,7 +318,6 @@ func (mgr Manager) calcBlockReward(ctx cosmos.Context, totalReserve, emissionCur if emissionCurve == 0 || blocksPerYear == 0 { sdkContext.Logger().Info("block and emission-curve cannot be zero") return cosmos.NewCoin(configs.Denom, sdkmath.NewInt(0)) - } if validatorPayoutCycle == 0 || sdkContext.BlockHeight()%validatorPayoutCycle != 0 { @@ -434,7 +431,6 @@ func (mgr Manager) contractDebt(ctx cosmos.Context, contract types.Contract) (co } func (mgr Manager) circulatingSupplyAfterInflationCalc(ctx cosmos.Context) (cosmos.Coin, error) { - sdkContext := sdk.UnwrapSDKContext(ctx) // Get the circulating supply diff --git a/x/arkeo/keeper/manager_test.go b/x/arkeo/keeper/manager_test.go index 67015d70..a1da1d70 100644 --- a/x/arkeo/keeper/manager_test.go +++ b/x/arkeo/keeper/manager_test.go @@ -10,8 +10,8 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/stretchr/testify/require" - "cosmossdk.io/math" sdkmath "cosmossdk.io/math" + "github.com/arkeonetwork/arkeo/common" "github.com/arkeonetwork/arkeo/common/cosmos" "github.com/arkeonetwork/arkeo/x/arkeo/configs" @@ -287,11 +287,9 @@ func TestParamsRewardsPercentage(t *testing.T) { params := k.GetParams(ctx) - require.Equal(t, params.CommunityPoolPercentage, math.LegacyNewDecWithPrec(10, 2)) - + require.Equal(t, params.CommunityPoolPercentage.Int64(), int64(10)) } func TestCommunityPoolDistributionToFoundationCommunityPool(t *testing.T) { - ctx, k, sk := SetupKeeperWithStaking(t) mgr := NewManager(k, sk) @@ -469,7 +467,6 @@ func TestValidatorPayouts(t *testing.T) { moduleBalance = k.GetBalanceOfModule(ctx, types.ModuleName, configs.Denom) require.Equal(t, moduleBalance.Int64(), int64(20000000000000)) - } func checkBalance(ctx cosmos.Context, t *testing.T, k Keeper, acc cosmos.AccAddress, denom string, expectedAmt int64, total *sdkmath.Int) { bal := k.GetBalance(ctx, acc) diff --git a/x/arkeo/module.go b/x/arkeo/module.go index 534d659f..23c46751 100644 --- a/x/arkeo/module.go +++ b/x/arkeo/module.go @@ -6,6 +6,7 @@ import ( "fmt" "cosmossdk.io/core/appmodule" + "github.com/arkeonetwork/arkeo/x/arkeo/client/cli" "github.com/arkeonetwork/arkeo/x/arkeo/keeper" "github.com/arkeonetwork/arkeo/x/arkeo/types"