From c06f61e35a7b8406b5687ac478815990f8f33ecc Mon Sep 17 00:00:00 2001 From: kenta-elys Date: Tue, 19 Sep 2023 08:01:31 +0000 Subject: [PATCH] chore: manage eden boost burning from elys unstake and eden uncommitted --- proto/elys/incentive/elys_staked.proto | 17 + proto/elys/incentive/query.proto | 1 - x/amm/types/query.pb.gw.go | 19 +- x/commitment/keeper/hooks.go | 15 + .../keeper/msg_server_uncommit_tokens.go | 6 + x/commitment/types/interfaces.go | 3 + x/incentive/keeper/abci.go | 57 +++ x/incentive/keeper/elys_staked.go | 63 +++ x/incentive/keeper/hooks_commitment.go | 10 + x/incentive/keeper/hooks_staking.go | 6 +- x/incentive/keeper/keeper_burn_edenB.go | 78 ++++ x/incentive/module.go | 4 +- x/incentive/types/elys_staked.pb.go | 396 ++++++++++++++++++ x/incentive/types/expected_keepers.go | 2 + x/incentive/types/keys.go | 15 + 15 files changed, 686 insertions(+), 6 deletions(-) create mode 100644 proto/elys/incentive/elys_staked.proto create mode 100644 x/incentive/keeper/abci.go create mode 100644 x/incentive/keeper/elys_staked.go create mode 100644 x/incentive/keeper/keeper_burn_edenB.go create mode 100644 x/incentive/types/elys_staked.pb.go diff --git a/proto/elys/incentive/elys_staked.proto b/proto/elys/incentive/elys_staked.proto new file mode 100644 index 000000000..d48647966 --- /dev/null +++ b/proto/elys/incentive/elys_staked.proto @@ -0,0 +1,17 @@ +syntax = "proto3"; +package elys.incentive; + +option go_package = "github.com/elys-network/elys/x/incentive/types"; +option (gogoproto.equal_all) = true; + +import "gogoproto/gogo.proto"; + +// Elys staked +message ElysStaked { + string address = 1; + string amount = 2 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.nullable) = false + ]; + } + \ No newline at end of file diff --git a/proto/elys/incentive/query.proto b/proto/elys/incentive/query.proto index 33217a4bf..191b8fc20 100644 --- a/proto/elys/incentive/query.proto +++ b/proto/elys/incentive/query.proto @@ -25,7 +25,6 @@ service Query { option (google.api.http).get = "/elys-network/elys/incentive/community_pool"; } - } // QueryParamsRequest is request type for the Query/Params RPC method. message QueryParamsRequest {} diff --git a/x/amm/types/query.pb.gw.go b/x/amm/types/query.pb.gw.go index 2babba22a..3b891ece9 100644 --- a/x/amm/types/query.pb.gw.go +++ b/x/amm/types/query.pb.gw.go @@ -20,6 +20,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" "google.golang.org/grpc/status" ) @@ -30,6 +31,7 @@ var _ status.Status var _ = runtime.String var _ = utilities.NewDoubleArray var _ = descriptor.ForMessage +var _ = metadata.Join func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq QueryParamsRequest @@ -232,12 +234,14 @@ func local_request_Query_DenomLiquidityAll_0(ctx context.Context, marshaler runt // RegisterQueryHandlerServer registers the http handlers for service Query to "mux". // UnaryRPC :call QueryServer directly. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. -// Note that using this registration option will cause many gRPC library features (such as grpc.SendHeader, etc) to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -245,6 +249,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_Params_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -258,6 +263,8 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv mux.Handle("GET", pattern_Query_Pool_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -265,6 +272,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_Pool_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -278,6 +286,8 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv mux.Handle("GET", pattern_Query_PoolAll_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -285,6 +295,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_PoolAll_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -298,6 +309,8 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv mux.Handle("GET", pattern_Query_DenomLiquidity_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -305,6 +318,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_DenomLiquidity_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -318,6 +332,8 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv mux.Handle("GET", pattern_Query_DenomLiquidityAll_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -325,6 +341,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_DenomLiquidityAll_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) diff --git a/x/commitment/keeper/hooks.go b/x/commitment/keeper/hooks.go index 86b8ae763..55b216868 100644 --- a/x/commitment/keeper/hooks.go +++ b/x/commitment/keeper/hooks.go @@ -21,6 +21,13 @@ func (mh MultiCommitmentHooks) CommitmentChanged(ctx sdk.Context, creator string } } +// Committed is called when staker committed his token +func (mh MultiCommitmentHooks) EdenUncommitted(ctx sdk.Context, creator string, amount sdk.Coin) { + for i := range mh { + mh[i].EdenUncommitted(ctx, creator, amount) + } +} + // Committed executes the indicated for committed hook func (k Keeper) AfterCommitmentChange(ctx sdk.Context, creator string, amount sdk.Coin) { if k.hooks == nil { @@ -28,3 +35,11 @@ func (k Keeper) AfterCommitmentChange(ctx sdk.Context, creator string, amount sd } k.hooks.CommitmentChanged(ctx, creator, amount) } + +// Committed executes the indicated for committed hook +func (k Keeper) EdenUncommitted(ctx sdk.Context, creator string, amount sdk.Coin) { + if k.hooks == nil { + return + } + k.hooks.EdenUncommitted(ctx, creator, amount) +} diff --git a/x/commitment/keeper/msg_server_uncommit_tokens.go b/x/commitment/keeper/msg_server_uncommit_tokens.go index 5c4e00e74..53023c630 100644 --- a/x/commitment/keeper/msg_server_uncommit_tokens.go +++ b/x/commitment/keeper/msg_server_uncommit_tokens.go @@ -7,6 +7,7 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" aptypes "github.com/elys-network/elys/x/assetprofile/types" "github.com/elys-network/elys/x/commitment/types" + ptypes "github.com/elys-network/elys/x/parameter/types" ) func (k msgServer) UncommitTokens(goCtx context.Context, msg *types.MsgUncommitTokens) (*types.MsgUncommitTokensResponse, error) { @@ -58,6 +59,11 @@ func (k msgServer) UncommitTokens(goCtx context.Context, msg *types.MsgUncommitT // Emit Hook commitment changed k.AfterCommitmentChange(ctx, msg.Creator, sdk.NewCoin(msg.Denom, msg.Amount)) + // Emit Hook if Eden is uncommitted + if msg.Denom == ptypes.Eden { + k.EdenUncommitted(ctx, msg.Creator, sdk.NewCoin(msg.Denom, msg.Amount)) + } + // Emit blockchain event ctx.EventManager().EmitEvent( sdk.NewEvent( diff --git a/x/commitment/types/interfaces.go b/x/commitment/types/interfaces.go index f0ef60a5d..9247e744c 100644 --- a/x/commitment/types/interfaces.go +++ b/x/commitment/types/interfaces.go @@ -6,4 +6,7 @@ import sdk "github.com/cosmos/cosmos-sdk/types" type CommitmentHooks interface { // Token commitment changed CommitmentChanged(ctx sdk.Context, creator string, amount sdk.Coin) + + // Eden uncommitted + EdenUncommitted(ctx sdk.Context, creator string, amount sdk.Coin) } diff --git a/x/incentive/keeper/abci.go b/x/incentive/keeper/abci.go new file mode 100644 index 000000000..8aa538757 --- /dev/null +++ b/x/incentive/keeper/abci.go @@ -0,0 +1,57 @@ +// Copyright 2022 Evmos Foundation +// This file is part of the Evmos Network packages. +// +// Evmos is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// The Evmos packages are distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with the Evmos packages. If not, see https://github.com/evmos/evmos/blob/main/LICENSE + +package keeper + +import ( + "time" + + "github.com/cosmos/cosmos-sdk/telemetry" + sdk "github.com/cosmos/cosmos-sdk/types" + + ctypes "github.com/elys-network/elys/x/commitment/types" + "github.com/elys-network/elys/x/incentive/types" +) + +// EndBlocker of incentive module +func (k Keeper) EndBlocker(ctx sdk.Context) { + defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker) + // Track the amount of Elys staked + k.cmk.IterateCommitments( + ctx, func(commitments ctypes.Commitments) bool { + // Commitment owner + creator := commitments.Creator + _, err := sdk.AccAddressFromBech32(creator) + if err != nil { + // This could be validator address + return false + } + + // Calculate delegated amount per delegator + delegatedAmt := k.CalculateDelegatedAmount(ctx, creator) + + elysStaked := types.ElysStaked{ + Address: creator, + Amount: delegatedAmt, + } + + // Set Elys staked amount + k.SetElysStaked(ctx, elysStaked) + + return false + }, + ) +} diff --git a/x/incentive/keeper/elys_staked.go b/x/incentive/keeper/elys_staked.go new file mode 100644 index 000000000..575322c31 --- /dev/null +++ b/x/incentive/keeper/elys_staked.go @@ -0,0 +1,63 @@ +package keeper + +import ( + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/elys-network/elys/x/incentive/types" +) + +// SetSuperAdmin set a specific superAdmin in the store from its index +func (k Keeper) SetElysStaked(ctx sdk.Context, elysStaked types.ElysStaked) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.ElysStakedKeyPrefix)) + b := k.cdc.MustMarshal(&elysStaked) + store.Set(types.ElysStakedKey( + elysStaked.Address, + ), b) +} + +// GetSuperAdmin returns a superAdmin from its index +func (k Keeper) GetElysStaked( + ctx sdk.Context, + address string, + +) (val types.ElysStaked, found bool) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.ElysStakedKeyPrefix)) + + b := store.Get(types.ElysStakedKey( + address, + )) + if b == nil { + return val, false + } + + k.cdc.MustUnmarshal(b, &val) + return val, true +} + +// RemoveSuperAdmin removes a superAdmin from the store +func (k Keeper) RemoveElysStaked( + ctx sdk.Context, + address string, + +) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.ElysStakedKeyPrefix)) + store.Delete(types.ElysStakedKey( + address, + )) +} + +// GetAllSuperAdmin returns all superAdmin +func (k Keeper) GetAllElysStaked(ctx sdk.Context) (list []types.ElysStaked) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.ElysStakedKeyPrefix)) + iterator := sdk.KVStorePrefixIterator(store, []byte{}) + + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var val types.ElysStaked + k.cdc.MustUnmarshal(iterator.Value(), &val) + list = append(list, val) + } + + return +} diff --git a/x/incentive/keeper/hooks_commitment.go b/x/incentive/keeper/hooks_commitment.go index 278b34afd..638b18500 100644 --- a/x/incentive/keeper/hooks_commitment.go +++ b/x/incentive/keeper/hooks_commitment.go @@ -9,6 +9,11 @@ import ( func (k Keeper) CommitmentChanged(ctx sdk.Context, creator string, amount sdk.Coin) { } +// Process eden uncommitted hook +func (k Keeper) EdenUncommitted(ctx sdk.Context, creator string, amount sdk.Coin) { + k.BurnEdenBFromEdenUncommitted(ctx, creator, amount.Amount) +} + // ___________________________________________________________________________________________________ // Hooks wrapper struct for incentive keeper @@ -27,3 +32,8 @@ func (k Keeper) CommitmentHooks() CommitmentHooks { func (h CommitmentHooks) CommitmentChanged(ctx sdk.Context, creator string, amount sdk.Coin) { h.k.CommitmentChanged(ctx, creator, amount) } + +// EdenUncommitted implements EdenUncommitted +func (h CommitmentHooks) EdenUncommitted(ctx sdk.Context, creator string, amount sdk.Coin) { + h.k.EdenUncommitted(ctx, creator, amount) +} diff --git a/x/incentive/keeper/hooks_staking.go b/x/incentive/keeper/hooks_staking.go index 3099077ce..abd2c0b79 100644 --- a/x/incentive/keeper/hooks_staking.go +++ b/x/incentive/keeper/hooks_staking.go @@ -22,15 +22,15 @@ func (k Keeper) BeforeDelegationCreated(ctx sdk.Context, delAddr sdk.AccAddress, // Updating commitments on delegation changes func (k Keeper) AfterDelegationModified(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error { - return nil + return k.BurnEdenBFromElysUnstaking(ctx, delAddr) } func (k Keeper) BeforeDelegationRemoved(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error { - return nil + return k.BurnEdenBFromElysUnstaking(ctx, delAddr) } func (k Keeper) BeforeDelegationSharesModified(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error { - return nil + return k.BurnEdenBFromElysUnstaking(ctx, delAddr) } // ________________________________________________________________________________________ diff --git a/x/incentive/keeper/keeper_burn_edenB.go b/x/incentive/keeper/keeper_burn_edenB.go new file mode 100644 index 000000000..b313d3d29 --- /dev/null +++ b/x/incentive/keeper/keeper_burn_edenB.go @@ -0,0 +1,78 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + ptypes "github.com/elys-network/elys/x/parameter/types" +) + +// Burn EdenBoost from Elys unstaked +func (k Keeper) BurnEdenBFromElysUnstaking(ctx sdk.Context, delegator sdk.AccAddress) error { + delAddr := delegator.String() + // Get commitments + commitments, found := k.cmk.GetCommitments(ctx, delAddr) + if !found { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid address %s", delegator.String()) + } + + // Get previous amount + prevElysStaked, found := k.GetElysStaked(ctx, delAddr) + if !found { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid address %s", delegator.String()) + } + + // Calculate current delegated amount of delegator + delegatedAmt := k.CalculateDelegatedAmount(ctx, delAddr) + + // If not unstaked, + if delegatedAmt.GTE(prevElysStaked.Amount) { + return nil + } + + edenCommitted := commitments.GetCommittedAmountForDenom(ptypes.Eden) + + //Total EdenB amount + edenBCommitted := commitments.GetCommittedAmountForDenom(ptypes.EdenB) + edenBUncommitted := commitments.GetUncommittedAmountForDenom(ptypes.EdenB) + + // Total EdenB amount + totalEdenB := edenBCommitted.Add(edenBUncommitted) + + // Unstaked + unstakedElys := prevElysStaked.Amount.Sub(delegatedAmt) + + edenBToBurn := unstakedElys.Quo(edenCommitted.Add(prevElysStaked.Amount)).Mul(totalEdenB) + + // Burn EdenB ( Deduction EdenB in commitment module) + _, err := k.cmk.DeductCommitments(ctx, delAddr, ptypes.EdenB, edenBToBurn) + return err +} + +// Burn EdenBoost from Eden uncommitted +func (k Keeper) BurnEdenBFromEdenUncommitted(ctx sdk.Context, delegator string, uncommittedAmt sdk.Int) error { + // Get elys staked amount + elysStaked, found := k.GetElysStaked(ctx, delegator) + if !found { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid address %s", delegator) + } + + commitments, found := k.cmk.GetCommitments(ctx, delegator) + if !found { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid address %s", delegator) + } + + edenCommitted := commitments.GetCommittedAmountForDenom(ptypes.Eden) + + //Total EdenB amount + edenBCommitted := commitments.GetCommittedAmountForDenom(ptypes.EdenB) + edenBUncommitted := commitments.GetUncommittedAmountForDenom(ptypes.EdenB) + + // Total EdenB amount + totalEdenB := edenBCommitted.Add(edenBUncommitted) + + edenBToBurn := uncommittedAmt.Quo(edenCommitted.Add(elysStaked.Amount)).Mul(totalEdenB) + + // Burn EdenB ( Deduction EdenB in commitment module) + _, err := k.cmk.DeductCommitments(ctx, delegator, ptypes.EdenB, edenBToBurn) + return err +} diff --git a/x/incentive/module.go b/x/incentive/module.go index a38da13e8..d8103b813 100644 --- a/x/incentive/module.go +++ b/x/incentive/module.go @@ -143,6 +143,8 @@ func (AppModule) ConsensusVersion() uint64 { return 3 } 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 { +func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { + am.keeper.EndBlocker(ctx) + return []abci.ValidatorUpdate{} } diff --git a/x/incentive/types/elys_staked.pb.go b/x/incentive/types/elys_staked.pb.go new file mode 100644 index 000000000..cbaa038dd --- /dev/null +++ b/x/incentive/types/elys_staked.pb.go @@ -0,0 +1,396 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: elys/incentive/elys_staked.proto + +package types + +import ( + fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// Elys staked +type ElysStaked struct { + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + Amount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,2,opt,name=amount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"amount"` +} + +func (m *ElysStaked) Reset() { *m = ElysStaked{} } +func (m *ElysStaked) String() string { return proto.CompactTextString(m) } +func (*ElysStaked) ProtoMessage() {} +func (*ElysStaked) Descriptor() ([]byte, []int) { + return fileDescriptor_ebe5e1add8f72d5c, []int{0} +} +func (m *ElysStaked) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ElysStaked) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ElysStaked.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ElysStaked) XXX_Merge(src proto.Message) { + xxx_messageInfo_ElysStaked.Merge(m, src) +} +func (m *ElysStaked) XXX_Size() int { + return m.Size() +} +func (m *ElysStaked) XXX_DiscardUnknown() { + xxx_messageInfo_ElysStaked.DiscardUnknown(m) +} + +var xxx_messageInfo_ElysStaked proto.InternalMessageInfo + +func (m *ElysStaked) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + +func init() { + proto.RegisterType((*ElysStaked)(nil), "elys.incentive.ElysStaked") +} + +func init() { proto.RegisterFile("elys/incentive/elys_staked.proto", fileDescriptor_ebe5e1add8f72d5c) } + +var fileDescriptor_ebe5e1add8f72d5c = []byte{ + // 226 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x48, 0xcd, 0xa9, 0x2c, + 0xd6, 0xcf, 0xcc, 0x4b, 0x4e, 0xcd, 0x2b, 0xc9, 0x2c, 0x4b, 0xd5, 0x07, 0x71, 0xe3, 0x8b, 0x4b, + 0x12, 0xb3, 0x53, 0x53, 0xf4, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x85, 0xf8, 0x40, 0x42, 0x7a, 0x70, + 0x15, 0x52, 0x22, 0xe9, 0xf9, 0xe9, 0xf9, 0x60, 0x29, 0x7d, 0x10, 0x0b, 0xa2, 0x4a, 0x29, 0x8f, + 0x8b, 0xcb, 0x35, 0xa7, 0xb2, 0x38, 0x18, 0xac, 0x53, 0x48, 0x82, 0x8b, 0x3d, 0x31, 0x25, 0xa5, + 0x28, 0xb5, 0xb8, 0x58, 0x82, 0x51, 0x81, 0x51, 0x83, 0x33, 0x08, 0xc6, 0x15, 0x72, 0xe3, 0x62, + 0x4b, 0xcc, 0xcd, 0x2f, 0xcd, 0x2b, 0x91, 0x60, 0x02, 0x49, 0x38, 0xe9, 0x9d, 0xb8, 0x27, 0xcf, + 0x70, 0xeb, 0x9e, 0xbc, 0x5a, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x7e, + 0x72, 0x7e, 0x71, 0x6e, 0x7e, 0x31, 0x94, 0xd2, 0x2d, 0x4e, 0xc9, 0xd6, 0x2f, 0xa9, 0x2c, 0x48, + 0x2d, 0xd6, 0xf3, 0xcc, 0x2b, 0x09, 0x82, 0xea, 0x76, 0xf2, 0x59, 0xf1, 0x48, 0x8e, 0xf1, 0xc4, + 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, + 0xc2, 0x63, 0x39, 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0xf4, 0x90, 0x4c, 0x03, 0x39, 0x5f, 0x37, + 0x2f, 0xb5, 0xa4, 0x3c, 0xbf, 0x28, 0x1b, 0xcc, 0xd1, 0xaf, 0x40, 0xf2, 0x2f, 0xd8, 0xe4, 0x24, + 0x36, 0xb0, 0x27, 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0xb5, 0xe0, 0x1a, 0xce, 0x0e, 0x01, + 0x00, 0x00, +} + +func (this *ElysStaked) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*ElysStaked) + if !ok { + that2, ok := that.(ElysStaked) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.Address != that1.Address { + return false + } + if !this.Amount.Equal(that1.Amount) { + return false + } + return true +} +func (m *ElysStaked) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ElysStaked) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ElysStaked) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.Amount.Size() + i -= size + if _, err := m.Amount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintElysStaked(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintElysStaked(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintElysStaked(dAtA []byte, offset int, v uint64) int { + offset -= sovElysStaked(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *ElysStaked) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Address) + if l > 0 { + n += 1 + l + sovElysStaked(uint64(l)) + } + l = m.Amount.Size() + n += 1 + l + sovElysStaked(uint64(l)) + return n +} + +func sovElysStaked(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozElysStaked(x uint64) (n int) { + return sovElysStaked(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *ElysStaked) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowElysStaked + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ElysStaked: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ElysStaked: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowElysStaked + } + 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 ErrInvalidLengthElysStaked + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthElysStaked + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowElysStaked + } + 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 ErrInvalidLengthElysStaked + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthElysStaked + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipElysStaked(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthElysStaked + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipElysStaked(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowElysStaked + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowElysStaked + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowElysStaked + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthElysStaked + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupElysStaked + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthElysStaked + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthElysStaked = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowElysStaked = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupElysStaked = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/incentive/types/expected_keepers.go b/x/incentive/types/expected_keepers.go index cf4ebe9c4..7aa398c80 100644 --- a/x/incentive/types/expected_keepers.go +++ b/x/incentive/types/expected_keepers.go @@ -25,6 +25,8 @@ type CommitmentKeeper interface { ProcessWithdrawValidatorCommission(sdk.Context, string, string, string, sdk.Int) error // Withdraw tokens - only USDC ProcessWithdrawUSDC(ctx sdk.Context, creator string, denom string, amount sdk.Int) error + // Deduct commitments + DeductCommitments(ctx sdk.Context, creator string, denom string, amount sdk.Int) (ctypes.Commitments, error) } // Staking keeper diff --git a/x/incentive/types/keys.go b/x/incentive/types/keys.go index e33d4f316..73b72db6a 100644 --- a/x/incentive/types/keys.go +++ b/x/incentive/types/keys.go @@ -12,6 +12,8 @@ const ( // MemStoreKey defines the in-memory store key MemStoreKey = "mem_incentive" + + ElysStakedKeyPrefix = "ElysStaked/value/" ) func KeyPrefix(p string) []byte { @@ -21,3 +23,16 @@ func KeyPrefix(p string) []byte { var ( FeePoolKey = []byte{0x00} // key for global distribution state ) + +// ElysStakedKey returns the store key to retrieve a ElysStaked from the address fields +func ElysStakedKey( + address string, +) []byte { + var key []byte + + addressBytes := []byte(address) + key = append(key, addressBytes...) + key = append(key, []byte("/")...) + + return key +}