From dbaac510058bd0529128a632ff02093326ed443c Mon Sep 17 00:00:00 2001 From: Hanjun Kim Date: Wed, 1 Sep 2021 16:24:27 +0900 Subject: [PATCH 01/16] refactor!: remove unused fields --- .../tendermint/farming/v1beta1/farming.proto | 47 +- .../tendermint/farming/v1beta1/genesis.proto | 19 +- proto/tendermint/farming/v1beta1/query.proto | 18 - x/farming/types/farming.pb.go | 647 ++--------------- x/farming/types/genesis.pb.go | 241 +------ x/farming/types/query.pb.go | 670 ++---------------- x/farming/types/query.pb.gw.go | 80 --- 7 files changed, 164 insertions(+), 1558 deletions(-) diff --git a/proto/tendermint/farming/v1beta1/farming.proto b/proto/tendermint/farming/v1beta1/farming.proto index e96b7ab0..17006ae5 100644 --- a/proto/tendermint/farming/v1beta1/farming.proto +++ b/proto/tendermint/farming/v1beta1/farming.proto @@ -22,20 +22,12 @@ message Params { (gogoproto.nullable) = false ]; - // When a farmer creates new staking, the farmer needs to pay - // staking_creation_fee to prevent spam on the staking struct - repeated cosmos.base.v1beta1.Coin staking_creation_fee = 2 [ - (gogoproto.moretags) = "yaml:\"staking_creation_fee\"", - (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", - (gogoproto.nullable) = false - ]; - // The universal epoch length in number of days. Every process for staking and // reward distribution is executed with this epoch_days frequency - uint32 epoch_days = 3 [(gogoproto.moretags) = "yaml:\"epoch_days\""]; + uint32 epoch_days = 2 [(gogoproto.moretags) = "yaml:\"epoch_days\""]; // farming_fee_collector is the module account address to collect fees within the farming module - string farming_fee_collector = 4 [(gogoproto.moretags) = "yaml:\"farming_fee_collector\""]; + string farming_fee_collector = 3 [(gogoproto.moretags) = "yaml:\"farming_fee_collector\""]; } // BasePlan defines a base plan type. It contains all the necessary fields @@ -167,38 +159,3 @@ message Staking { (gogoproto.nullable) = false ]; } - -// Reward defines a record of farming rewards. -message Reward { - option (gogoproto.goproto_getters) = false; - option (gogoproto.goproto_stringer) = false; - - // farmer defines the bech32-encoded address of the farmer - string farmer = 1; - - // staking_coin_denom is denom of staked coin as a source of the reward - string staking_coin_denom = 2 [(gogoproto.moretags) = "yaml:\"staking_coin_denom\""]; - - // reward_coins specifies rewards amount at this point in time when farmers - // receive them from the farming plan - repeated cosmos.base.v1beta1.Coin reward_coins = 3 [ - (gogoproto.moretags) = "yaml:\"reward_coins\"", - (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", - (gogoproto.nullable) = false - ]; -} - -// RewardCoins represents reward coins for specific staking coin denom for a farmer. -// This is the actual struct that is stored in kvstore. -message RewardCoins { - option (gogoproto.goproto_getters) = false; - option (gogoproto.goproto_stringer) = false; - - // reward_coins specifies rewards amount at this point in time when farmers - // receive them from the farming plan - repeated cosmos.base.v1beta1.Coin reward_coins = 1 [ - (gogoproto.moretags) = "yaml:\"reward_coins\"", - (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", - (gogoproto.nullable) = false - ]; -} diff --git a/proto/tendermint/farming/v1beta1/genesis.proto b/proto/tendermint/farming/v1beta1/genesis.proto index bbcdf9c8..22c8672e 100644 --- a/proto/tendermint/farming/v1beta1/genesis.proto +++ b/proto/tendermint/farming/v1beta1/genesis.proto @@ -25,9 +25,6 @@ message GenesisState { // stakings defines the staking records used for genesis state repeated Staking stakings = 3 [(gogoproto.nullable) = false]; - - // rewards defines the reward records used for genesis state - repeated Reward rewards = 4 [(gogoproto.nullable) = false]; } // PlanRecord is used for import/export via genesis json. @@ -38,29 +35,17 @@ message PlanRecord { // plan specifies the plan interface; it can be FixedAmountPlan or RatioPlan google.protobuf.Any plan = 1 [(gogoproto.nullable) = false]; - // last_epoch_time specifies the last distributed epoch time of the plan - google.protobuf.Timestamp last_epoch_time = 2 - [(gogoproto.stdtime) = true, (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"last_epoch_time\""]; - // farming_pool_coins specifies balance of the farming pool for the plan // this param is needed for import/export validation - repeated cosmos.base.v1beta1.Coin farming_pool_coins = 3 [ + repeated cosmos.base.v1beta1.Coin farming_pool_coins = 2 [ (gogoproto.moretags) = "yaml:\"farming_pool_coins\"", (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", (gogoproto.nullable) = false ]; - // reward_pool_coins specifies balance of the reward pool to be distributed in - // the plan this param is needed for import/export validation - repeated cosmos.base.v1beta1.Coin reward_pool_coins = 4 [ - (gogoproto.moretags) = "yaml:\"reward_pool_coins\"", - (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", - (gogoproto.nullable) = false - ]; - // staking_reserve_coins specifies balance of the staking reserve pool staked // in the plan this param is needed for import/export validation - repeated cosmos.base.v1beta1.Coin staking_reserve_coins = 5 [ + repeated cosmos.base.v1beta1.Coin staking_reserve_coins = 3 [ (gogoproto.moretags) = "yaml:\"staking_reserve_coins\"", (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", (gogoproto.nullable) = false diff --git a/proto/tendermint/farming/v1beta1/query.proto b/proto/tendermint/farming/v1beta1/query.proto index 52f3d529..df32c141 100644 --- a/proto/tendermint/farming/v1beta1/query.proto +++ b/proto/tendermint/farming/v1beta1/query.proto @@ -37,11 +37,6 @@ service Query { rpc Staking(QueryStakingRequest) returns (QueryStakingResponse) { option (google.api.http).get = "/cosmos/farming/v1beta1/stakings/{staking_id}"; } - - // Rewards returns all rewards. - rpc Rewards(QueryRewardsRequest) returns (QueryRewardsResponse) { - option (google.api.http).get = "/cosmos/farming/v1beta1/rewards"; - } } // QueryParamsRequest is the request type for the Query/Params RPC method. @@ -100,16 +95,3 @@ message QueryStakingRequest { message QueryStakingResponse { Staking staking = 1 [(gogoproto.nullable) = false]; } - -// QueryRewardsRequest is the request type for the Query/Rewards RPC method. -message QueryRewardsRequest { - string farmer = 1; - string staking_coin_denom = 2 [(gogoproto.moretags) = "yaml:\"staking_coin_denom\""]; - cosmos.base.query.v1beta1.PageRequest pagination = 3; -} - -// QueryRewardsResponse is the response type for the Query/Rewards RPC method. -message QueryRewardsResponse { - repeated Reward rewards = 1 [(gogoproto.nullable) = false]; - cosmos.base.query.v1beta1.PageResponse pagination = 2; -} diff --git a/x/farming/types/farming.pb.go b/x/farming/types/farming.pb.go index 80b27913..b4616df1 100644 --- a/x/farming/types/farming.pb.go +++ b/x/farming/types/farming.pb.go @@ -67,14 +67,11 @@ type Params struct { // private_plan_creation_fee specifies the fee for plan creation // this fee prevents from spamming and it is collected in the community pool PrivatePlanCreationFee github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,1,rep,name=private_plan_creation_fee,json=privatePlanCreationFee,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"private_plan_creation_fee" yaml:"private_plan_creation_fee"` - // When a farmer creates new staking, the farmer needs to pay - // staking_creation_fee to prevent spam on the staking struct - StakingCreationFee github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,2,rep,name=staking_creation_fee,json=stakingCreationFee,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"staking_creation_fee" yaml:"staking_creation_fee"` // The universal epoch length in number of days. Every process for staking and // reward distribution is executed with this epoch_days frequency - EpochDays uint32 `protobuf:"varint,3,opt,name=epoch_days,json=epochDays,proto3" json:"epoch_days,omitempty" yaml:"epoch_days"` + EpochDays uint32 `protobuf:"varint,2,opt,name=epoch_days,json=epochDays,proto3" json:"epoch_days,omitempty" yaml:"epoch_days"` // farming_fee_collector is the module account address to collect fees within the farming module - FarmingFeeCollector string `protobuf:"bytes,4,opt,name=farming_fee_collector,json=farmingFeeCollector,proto3" json:"farming_fee_collector,omitempty" yaml:"farming_fee_collector"` + FarmingFeeCollector string `protobuf:"bytes,3,opt,name=farming_fee_collector,json=farmingFeeCollector,proto3" json:"farming_fee_collector,omitempty" yaml:"farming_fee_collector"` } func (m *Params) Reset() { *m = Params{} } @@ -299,89 +296,6 @@ func (m *Staking) XXX_DiscardUnknown() { var xxx_messageInfo_Staking proto.InternalMessageInfo -// Reward defines a record of farming rewards. -type Reward struct { - // farmer defines the bech32-encoded address of the farmer - Farmer string `protobuf:"bytes,1,opt,name=farmer,proto3" json:"farmer,omitempty"` - // staking_coin_denom is denom of staked coin as a source of the reward - StakingCoinDenom string `protobuf:"bytes,2,opt,name=staking_coin_denom,json=stakingCoinDenom,proto3" json:"staking_coin_denom,omitempty" yaml:"staking_coin_denom"` - // reward_coins specifies rewards amount at this point in time when farmers - // receive them from the farming plan - RewardCoins github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,3,rep,name=reward_coins,json=rewardCoins,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"reward_coins" yaml:"reward_coins"` -} - -func (m *Reward) Reset() { *m = Reward{} } -func (*Reward) ProtoMessage() {} -func (*Reward) Descriptor() ([]byte, []int) { - return fileDescriptor_5b657e0809d9de86, []int{5} -} -func (m *Reward) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *Reward) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_Reward.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 *Reward) XXX_Merge(src proto.Message) { - xxx_messageInfo_Reward.Merge(m, src) -} -func (m *Reward) XXX_Size() int { - return m.Size() -} -func (m *Reward) XXX_DiscardUnknown() { - xxx_messageInfo_Reward.DiscardUnknown(m) -} - -var xxx_messageInfo_Reward proto.InternalMessageInfo - -// RewardCoins represents reward coins for specific staking coin denom for a farmer. -// This is the actual struct that is stored in kvstore. -type RewardCoins struct { - // reward_coins specifies rewards amount at this point in time when farmers - // receive them from the farming plan - RewardCoins github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,1,rep,name=reward_coins,json=rewardCoins,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"reward_coins" yaml:"reward_coins"` -} - -func (m *RewardCoins) Reset() { *m = RewardCoins{} } -func (*RewardCoins) ProtoMessage() {} -func (*RewardCoins) Descriptor() ([]byte, []int) { - return fileDescriptor_5b657e0809d9de86, []int{6} -} -func (m *RewardCoins) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *RewardCoins) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_RewardCoins.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 *RewardCoins) XXX_Merge(src proto.Message) { - xxx_messageInfo_RewardCoins.Merge(m, src) -} -func (m *RewardCoins) XXX_Size() int { - return m.Size() -} -func (m *RewardCoins) XXX_DiscardUnknown() { - xxx_messageInfo_RewardCoins.DiscardUnknown(m) -} - -var xxx_messageInfo_RewardCoins proto.InternalMessageInfo - func init() { proto.RegisterEnum("cosmos.farming.v1beta1.PlanType", PlanType_name, PlanType_value) proto.RegisterType((*Params)(nil), "cosmos.farming.v1beta1.Params") @@ -389,8 +303,6 @@ func init() { proto.RegisterType((*FixedAmountPlan)(nil), "cosmos.farming.v1beta1.FixedAmountPlan") proto.RegisterType((*RatioPlan)(nil), "cosmos.farming.v1beta1.RatioPlan") proto.RegisterType((*Staking)(nil), "cosmos.farming.v1beta1.Staking") - proto.RegisterType((*Reward)(nil), "cosmos.farming.v1beta1.Reward") - proto.RegisterType((*RewardCoins)(nil), "cosmos.farming.v1beta1.RewardCoins") } func init() { @@ -398,77 +310,72 @@ func init() { } var fileDescriptor_5b657e0809d9de86 = []byte{ - // 1119 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x56, 0xcf, 0x6f, 0xe3, 0xc4, - 0x17, 0xcf, 0xb4, 0xd9, 0x36, 0x99, 0x7c, 0xbf, 0x6d, 0x3a, 0xfd, 0x21, 0x37, 0xbb, 0xb5, 0x2d, - 0x4b, 0x20, 0xab, 0xa8, 0x8e, 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0x06, 0xb8, 0xe9, 0xdf, 0x33, 0xf0, 0x2d, 0x80, 0x25, - 0xf3, 0xf2, 0xe6, 0x3a, 0x43, 0xf0, 0x1f, 0x33, 0x5c, 0xfd, 0x02, 0xc0, 0x42, 0xfa, 0x2a, 0x40, - 0xab, 0x70, 0xb1, 0xb1, 0xb7, 0xb9, 0x6f, 0x35, 0x3f, 0x69, 0x6c, 0x5b, 0x8f, 0xf6, 0x1f, 0x36, - 0xb6, 0xb7, 0x76, 0x77, 0x76, 0xb7, 0xeb, 0xe5, 0x5c, 0x65, 0xf6, 0xe4, 0x54, 0x2d, 0xa5, 0x8a, - 0xfb, 0x8e, 0x8b, 0x74, 0x58, 0xbe, 0xd4, 0x6d, 0x3c, 0xaa, 0xed, 0xed, 0x6e, 0x95, 0x41, 0x05, - 0x9d, 0x9c, 0xaa, 0x33, 0xa9, 0x5a, 0xa3, 0xd7, 0x72, 0x9d, 0x36, 0x5a, 0x85, 0x73, 0x19, 0x4d, - 0x73, 0xf7, 0xa3, 0xcd, 0xe6, 0x76, 0x79, 0xa2, 0x32, 0x7f, 0x72, 0xaa, 0xce, 0x0e, 0x54, 0xf9, - 0xe3, 0xb1, 0x92, 0x7f, 0xfe, 0xbd, 0x9c, 0xab, 0xdd, 0x7f, 0x7d, 0x2e, 0x83, 0xb3, 0x73, 0x19, - 0xfc, 0x76, 0x2e, 0x83, 0x17, 0x17, 0x72, 0xee, 0xec, 0x42, 0xce, 0xfd, 0x72, 0x21, 0xe7, 0x3e, - 0x5d, 0xcb, 0xc4, 0x3b, 0xe4, 0x11, 0xff, 0x6c, 0xf0, 0xc5, 0x42, 0x6f, 0x4d, 0xb1, 0x7f, 0xa8, - 0xf7, 0xff, 0x0a, 0x00, 0x00, 0xff, 0xff, 0x5b, 0x8a, 0x15, 0x9d, 0xf1, 0x0b, 0x00, 0x00, + // 1030 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0xcd, 0x6e, 0xdb, 0x46, + 0x10, 0xd6, 0xca, 0x8a, 0x2d, 0xad, 0x5a, 0x5b, 0x5e, 0xff, 0x80, 0x56, 0x12, 0x92, 0x20, 0xd0, + 0x42, 0x70, 0x61, 0x0a, 0x71, 0x73, 0xf2, 0xcd, 0xf2, 0x4f, 0x20, 0xc0, 0x70, 0x55, 0x46, 0x69, + 0xda, 0x5e, 0x88, 0x95, 0xb8, 0x96, 0x89, 0x50, 0x5c, 0x95, 0x4b, 0x25, 0xd1, 0x03, 0x14, 0x08, + 0x7c, 0x0a, 0x8a, 0x1e, 0x7a, 0x71, 0x11, 0xb4, 0xb7, 0x9c, 0xfb, 0x10, 0x01, 0x72, 0x31, 0x0a, + 0x14, 0x28, 0x7a, 0x60, 0x0a, 0xfb, 0x0d, 0x74, 0xee, 0xa1, 0xd8, 0x1f, 0x2a, 0x2c, 0xa2, 0xc0, + 0xd1, 0xa1, 0x27, 0xed, 0xce, 0x7e, 0xf3, 0xcd, 0x37, 0xbb, 0x33, 0x43, 0xc1, 0x5a, 0x4c, 0x42, + 0x8f, 0x44, 0x7d, 0x3f, 0x8c, 0xeb, 0x27, 0x98, 0xff, 0xf6, 0xea, 0x8f, 0xef, 0x74, 0x48, 0x8c, + 0xef, 0xa4, 0x7b, 0x7b, 0x10, 0xd1, 0x98, 0xa2, 0xf5, 0x2e, 0x65, 0x7d, 0xca, 0xec, 0xd4, 0xaa, + 0x50, 0xd5, 0xd5, 0x1e, 0xed, 0x51, 0x01, 0xa9, 0xf3, 0x95, 0x44, 0x57, 0x37, 0x24, 0xda, 0x95, + 0x07, 0xca, 0x55, 0x1e, 0xe9, 0x72, 0x57, 0xef, 0x60, 0x46, 0x26, 0xb1, 0xba, 0xd4, 0x0f, 0xd5, + 0xb9, 0xd1, 0xa3, 0xb4, 0x17, 0x90, 0xba, 0xd8, 0x75, 0x86, 0x27, 0xf5, 0xd8, 0xef, 0x13, 0x16, + 0xe3, 0xfe, 0x40, 0x02, 0xac, 0xd7, 0x79, 0x38, 0xdf, 0xc2, 0x11, 0xee, 0x33, 0xf4, 0x12, 0xc0, + 0x8d, 0x41, 0xe4, 0x3f, 0xc6, 0x31, 0x71, 0x07, 0x01, 0x0e, 0xdd, 0x6e, 0x44, 0x70, 0xec, 0xd3, + 0xd0, 0x3d, 0x21, 0x44, 0x03, 0xe6, 0x5c, 0xad, 0xbc, 0xbd, 0x61, 0xab, 0xf0, 0x3c, 0x60, 0x2a, + 0xdb, 0xde, 0xa3, 0x7e, 0xd8, 0x68, 0xbf, 0x4a, 0x8c, 0xdc, 0x38, 0x31, 0xcc, 0x11, 0xee, 0x07, + 0x3b, 0xd6, 0x7b, 0x99, 0xac, 0x97, 0x6f, 0x8c, 0x5a, 0xcf, 0x8f, 0x4f, 0x87, 0x1d, 0xbb, 0x4b, + 0xfb, 0x2a, 0x1f, 0xf5, 0xb3, 0xc5, 0xbc, 0x47, 0xf5, 0x78, 0x34, 0x20, 0x4c, 0x90, 0x32, 0x67, + 0x5d, 0xf1, 0xb4, 0x02, 0x1c, 0xee, 0x29, 0x96, 0x43, 0x42, 0xd0, 0x5d, 0x08, 0xc9, 0x80, 0x76, + 0x4f, 0x5d, 0x0f, 0x8f, 0x98, 0x96, 0x37, 0x41, 0xed, 0xe3, 0xc6, 0xda, 0x38, 0x31, 0x96, 0x65, + 0xf4, 0xb7, 0x67, 0x96, 0x53, 0x12, 0x9b, 0x7d, 0x3c, 0x62, 0xa8, 0x0d, 0xd7, 0xd4, 0x95, 0x73, + 0x25, 0x6e, 0x97, 0x06, 0x01, 0xe9, 0xc6, 0x34, 0xd2, 0xe6, 0x4c, 0x50, 0x2b, 0x35, 0xcc, 0x71, + 0x62, 0xdc, 0x92, 0x04, 0x53, 0x61, 0x96, 0xb3, 0xa2, 0xec, 0x87, 0x84, 0xec, 0xa5, 0xd6, 0x9d, + 0xe2, 0xb3, 0x17, 0x46, 0xee, 0xa7, 0x17, 0x46, 0xce, 0xfa, 0x79, 0x01, 0x16, 0x1b, 0x98, 0x09, + 0xb5, 0x68, 0x11, 0xe6, 0x7d, 0x4f, 0x03, 0x26, 0xa8, 0x15, 0x9c, 0xbc, 0xef, 0x21, 0x04, 0x0b, + 0x21, 0xee, 0x13, 0x21, 0xb6, 0xe4, 0x88, 0x35, 0xba, 0x0b, 0x0b, 0x3c, 0x5b, 0x11, 0x7f, 0x71, + 0xdb, 0xb4, 0xa7, 0xd7, 0x85, 0xcd, 0xf9, 0xda, 0xa3, 0x01, 0x71, 0x04, 0x1a, 0x7d, 0x09, 0x57, + 0x53, 0x7d, 0x03, 0x4a, 0x03, 0x17, 0x7b, 0x5e, 0x44, 0x18, 0xd3, 0x0a, 0x22, 0x0b, 0x63, 0x9c, + 0x18, 0x37, 0xff, 0x9b, 0x45, 0x16, 0x65, 0x39, 0x48, 0x99, 0x5b, 0x94, 0x06, 0xbb, 0xd2, 0x88, + 0xbe, 0x80, 0x2b, 0xb1, 0x28, 0x5d, 0xf9, 0x4e, 0x29, 0xe3, 0x0d, 0xc1, 0xa8, 0x8f, 0x13, 0xa3, + 0x2a, 0x19, 0xa7, 0x80, 0x2c, 0x07, 0x65, 0xac, 0x29, 0xe1, 0x2f, 0x00, 0xae, 0xb2, 0x18, 0x3f, + 0xe2, 0xe1, 0x79, 0x41, 0xba, 0x4f, 0x88, 0xdf, 0x3b, 0x8d, 0x99, 0x36, 0x2f, 0x0a, 0xe9, 0xd6, + 0xd4, 0x42, 0xda, 0x27, 0x5d, 0x51, 0x4b, 0x8e, 0xaa, 0x25, 0x95, 0xc6, 0x34, 0x1e, 0x5e, 0x46, + 0x9f, 0x7d, 0x40, 0x19, 0x29, 0x4a, 0xe6, 0x20, 0xc5, 0xc2, 0x77, 0x0f, 0x25, 0x07, 0xfa, 0x1a, + 0x42, 0x16, 0xe3, 0x28, 0x76, 0x79, 0x5b, 0x68, 0x0b, 0x26, 0xa8, 0x95, 0xb7, 0xab, 0xb6, 0xec, + 0x19, 0x3b, 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b, 0x6c, 0xeb, + 0x41, 0xe3, 0xa8, 0xb9, 0x57, 0x01, 0x55, 0x74, 0x76, 0x6e, 0x2e, 0xa6, 0xb0, 0xd6, 0xb0, 0x13, + 0xf8, 0x5d, 0xb4, 0x09, 0x97, 0x33, 0x48, 0xa7, 0xf9, 0xd5, 0x6e, 0xfb, 0xa0, 0x92, 0xaf, 0xae, + 0x9c, 0x9d, 0x9b, 0x4b, 0x13, 0xa8, 0xfc, 0xf2, 0x57, 0x0b, 0xcf, 0x7e, 0xd5, 0x73, 0x8d, 0x7b, + 0xaf, 0x2e, 0x75, 0x70, 0x71, 0xa9, 0x83, 0xbf, 0x2f, 0x75, 0xf0, 0xfc, 0x4a, 0xcf, 0x5d, 0x5c, + 0xe9, 0xb9, 0x3f, 0xaf, 0xf4, 0xdc, 0xb7, 0x5b, 0x99, 0x7c, 0xa7, 0xfc, 0x03, 0x7b, 0x3a, 0x59, + 0x89, 0xd4, 0x3b, 0xf3, 0x62, 0xfa, 0x7d, 0xfe, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7c, 0x80, + 0x4f, 0xb0, 0xae, 0x09, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -496,26 +403,12 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { copy(dAtA[i:], m.FarmingFeeCollector) i = encodeVarintFarming(dAtA, i, uint64(len(m.FarmingFeeCollector))) i-- - dAtA[i] = 0x22 + dAtA[i] = 0x1a } if m.EpochDays != 0 { i = encodeVarintFarming(dAtA, i, uint64(m.EpochDays)) i-- - dAtA[i] = 0x18 - } - if len(m.StakingCreationFee) > 0 { - for iNdEx := len(m.StakingCreationFee) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.StakingCreationFee[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintFarming(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } + dAtA[i] = 0x10 } if len(m.PrivatePlanCreationFee) > 0 { for iNdEx := len(m.PrivatePlanCreationFee) - 1; iNdEx >= 0; iNdEx-- { @@ -809,94 +702,6 @@ func (m *Staking) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *Reward) 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 *Reward) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Reward) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.RewardCoins) > 0 { - for iNdEx := len(m.RewardCoins) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.RewardCoins[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintFarming(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - } - } - if len(m.StakingCoinDenom) > 0 { - i -= len(m.StakingCoinDenom) - copy(dAtA[i:], m.StakingCoinDenom) - i = encodeVarintFarming(dAtA, i, uint64(len(m.StakingCoinDenom))) - i-- - dAtA[i] = 0x12 - } - if len(m.Farmer) > 0 { - i -= len(m.Farmer) - copy(dAtA[i:], m.Farmer) - i = encodeVarintFarming(dAtA, i, uint64(len(m.Farmer))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *RewardCoins) 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 *RewardCoins) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *RewardCoins) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.RewardCoins) > 0 { - for iNdEx := len(m.RewardCoins) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.RewardCoins[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintFarming(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - } - return len(dAtA) - i, nil -} - func encodeVarintFarming(dAtA []byte, offset int, v uint64) int { offset -= sovFarming(v) base := offset @@ -920,12 +725,6 @@ func (m *Params) Size() (n int) { n += 1 + l + sovFarming(uint64(l)) } } - if len(m.StakingCreationFee) > 0 { - for _, e := range m.StakingCreationFee { - l = e.Size() - n += 1 + l + sovFarming(uint64(l)) - } - } if m.EpochDays != 0 { n += 1 + sovFarming(uint64(m.EpochDays)) } @@ -1048,44 +847,6 @@ func (m *Staking) Size() (n int) { return n } -func (m *Reward) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Farmer) - if l > 0 { - n += 1 + l + sovFarming(uint64(l)) - } - l = len(m.StakingCoinDenom) - if l > 0 { - n += 1 + l + sovFarming(uint64(l)) - } - if len(m.RewardCoins) > 0 { - for _, e := range m.RewardCoins { - l = e.Size() - n += 1 + l + sovFarming(uint64(l)) - } - } - return n -} - -func (m *RewardCoins) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if len(m.RewardCoins) > 0 { - for _, e := range m.RewardCoins { - l = e.Size() - n += 1 + l + sovFarming(uint64(l)) - } - } - return n -} - func sovFarming(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -1156,40 +917,6 @@ func (m *Params) Unmarshal(dAtA []byte) error { } iNdEx = postIndex case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field StakingCreationFee", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowFarming - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthFarming - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthFarming - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.StakingCreationFee = append(m.StakingCreationFee, types.Coin{}) - if err := m.StakingCreationFee[len(m.StakingCreationFee)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 3: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field EpochDays", wireType) } @@ -1208,7 +935,7 @@ func (m *Params) Unmarshal(dAtA []byte) error { break } } - case 4: + case 3: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field FarmingFeeCollector", wireType) } @@ -2044,238 +1771,6 @@ func (m *Staking) Unmarshal(dAtA []byte) error { } return nil } -func (m *Reward) 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 ErrIntOverflowFarming - } - 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: Reward: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Reward: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Farmer", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowFarming - } - 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 ErrInvalidLengthFarming - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthFarming - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Farmer = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field StakingCoinDenom", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowFarming - } - 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 ErrInvalidLengthFarming - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthFarming - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.StakingCoinDenom = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RewardCoins", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowFarming - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthFarming - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthFarming - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.RewardCoins = append(m.RewardCoins, types.Coin{}) - if err := m.RewardCoins[len(m.RewardCoins)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipFarming(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthFarming - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *RewardCoins) 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 ErrIntOverflowFarming - } - 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: RewardCoins: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: RewardCoins: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RewardCoins", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowFarming - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthFarming - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthFarming - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.RewardCoins = append(m.RewardCoins, types.Coin{}) - if err := m.RewardCoins[len(m.RewardCoins)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipFarming(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthFarming - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func skipFarming(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/farming/types/genesis.pb.go b/x/farming/types/genesis.pb.go index 537ad138..6e678b6e 100644 --- a/x/farming/types/genesis.pb.go +++ b/x/farming/types/genesis.pb.go @@ -10,20 +10,17 @@ import ( types1 "github.com/cosmos/cosmos-sdk/types" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" - github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" _ "github.com/regen-network/cosmos-proto" _ "google.golang.org/protobuf/types/known/timestamppb" io "io" math "math" math_bits "math/bits" - time "time" ) // Reference imports to suppress errors if they are not otherwise used. var _ = proto.Marshal var _ = fmt.Errorf var _ = math.Inf -var _ = time.Kitchen // This is a compile-time assertion to ensure that this generated file // is compatible with the proto package it is being compiled against. @@ -39,8 +36,6 @@ type GenesisState struct { PlanRecords []PlanRecord `protobuf:"bytes,2,rep,name=plan_records,json=planRecords,proto3" json:"plan_records" yaml:"plan_records"` // stakings defines the staking records used for genesis state Stakings []Staking `protobuf:"bytes,3,rep,name=stakings,proto3" json:"stakings"` - // rewards defines the reward records used for genesis state - Rewards []Reward `protobuf:"bytes,4,rep,name=rewards,proto3" json:"rewards"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -80,17 +75,12 @@ var xxx_messageInfo_GenesisState proto.InternalMessageInfo type PlanRecord struct { // plan specifies the plan interface; it can be FixedAmountPlan or RatioPlan Plan types.Any `protobuf:"bytes,1,opt,name=plan,proto3" json:"plan"` - // last_epoch_time specifies the last distributed epoch time of the plan - LastEpochTime time.Time `protobuf:"bytes,2,opt,name=last_epoch_time,json=lastEpochTime,proto3,stdtime" json:"last_epoch_time" yaml:"last_epoch_time"` // farming_pool_coins specifies balance of the farming pool for the plan // this param is needed for import/export validation - FarmingPoolCoins github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,3,rep,name=farming_pool_coins,json=farmingPoolCoins,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"farming_pool_coins" yaml:"farming_pool_coins"` - // reward_pool_coins specifies balance of the reward pool to be distributed in - // the plan this param is needed for import/export validation - RewardPoolCoins github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,4,rep,name=reward_pool_coins,json=rewardPoolCoins,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"reward_pool_coins" yaml:"reward_pool_coins"` + FarmingPoolCoins github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,2,rep,name=farming_pool_coins,json=farmingPoolCoins,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"farming_pool_coins" yaml:"farming_pool_coins"` // staking_reserve_coins specifies balance of the staking reserve pool staked // in the plan this param is needed for import/export validation - StakingReserveCoins github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,5,rep,name=staking_reserve_coins,json=stakingReserveCoins,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"staking_reserve_coins" yaml:"staking_reserve_coins"` + StakingReserveCoins github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,3,rep,name=staking_reserve_coins,json=stakingReserveCoins,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"staking_reserve_coins" yaml:"staking_reserve_coins"` } func (m *PlanRecord) Reset() { *m = PlanRecord{} } @@ -136,44 +126,38 @@ func init() { } var fileDescriptor_c67612b66bcd2967 = []byte{ - // 580 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x94, 0x31, 0x6f, 0xd3, 0x40, - 0x14, 0xc7, 0xed, 0x34, 0x94, 0xea, 0x52, 0x54, 0x70, 0x4b, 0x95, 0x04, 0x64, 0x57, 0x9e, 0xb2, - 0xd4, 0x56, 0xcb, 0x56, 0x21, 0xa4, 0x06, 0x21, 0x06, 0x40, 0x8a, 0x5c, 0x26, 0x16, 0xeb, 0x9c, - 0x5c, 0x5c, 0xab, 0xf6, 0x9d, 0xe5, 0xbb, 0x16, 0xf2, 0x0d, 0x18, 0x2b, 0x21, 0xb1, 0xd2, 0x11, - 0xf1, 0x1d, 0xd8, 0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, - 0x39, 0xad, 0x38, 0x11, 0x87, 0xc7, 0x91, 0xd7, 0x65, 0x19, 0xec, 0x31, 0x7c, 0xb6, 0x79, 0xef, - 0xc8, 0x17, 0x83, 0x9c, 0x70, 0xe5, 0xc6, 0x83, 0x87, 0x60, 0xd0, 0x61, 0x2c, 0x55, 0x11, 0xeb, - 0x8b, 0x89, 0x1e, 0xe9, 0xa9, 0x4e, 0x73, 0x55, 0x6f, 0xe3, 0x7a, 0x0b, 0x5c, 0x75, 0xcd, 0x35, - 0xe3, 0x70, 0x37, 0xac, 0x35, 0x9d, 0x3f, 0xa1, 0xfa, 0x66, 0xa2, 0xc7, 0xb0, 0x2c, 0x61, 0x41, - 0x38, 0x29, 0x4e, 0x08, 0x90, 0xdd, 0xbb, 0x8d, 0xac, 0x03, 0x64, 0x4f, 0x35, 0xd9, 0x5c, 0x97, - 0xbb, 0xd1, 0xad, 0x83, 0x47, 0xa0, 0x2d, 0x54, 0x70, 0xb2, 0x81, 0xed, 0x37, 0xdf, 0x87, 0xb6, - 0x79, 0x3e, 0xb4, 0xcd, 0x8b, 0xa1, 0x6d, 0xfe, 0x1e, 0xda, 0xe6, 0xe9, 0xc8, 0x36, 0x2e, 0x46, - 0xb6, 0xf1, 0x6b, 0x64, 0x1b, 0x1f, 0xb6, 0xa7, 0xca, 0xcc, 0xf9, 0xd7, 0xf8, 0x34, 0x3e, 0xa9, - 0x8a, 0xd1, 0xb2, 0x5a, 0xb7, 0x67, 0xff, 0x03, 0x00, 0x00, 0xff, 0xff, 0x60, 0x99, 0x36, 0x07, - 0x10, 0x05, 0x00, 0x00, + // 483 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x92, 0xb1, 0x6f, 0xd4, 0x30, + 0x14, 0xc6, 0x63, 0xae, 0xaa, 0x2a, 0x5f, 0x07, 0x94, 0x16, 0x74, 0x57, 0x90, 0x53, 0x65, 0xba, + 0x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7d, 0x80, 0x71, 0x93, 0x5a, + 0x6a, 0x59, 0x9f, 0x4b, 0xf4, 0xd6, 0xfb, 0x97, 0xb7, 0x09, 0x7a, 0x7b, 0xec, 0xbc, 0xad, 0xa4, + 0xfc, 0x9f, 0xbd, 0x2d, 0x64, 0xc4, 0x0e, 0x61, 0x37, 0x6f, 0x66, 0x30, 0x7e, 0xf1, 0x69, 0xc1, + 0xc8, 0xe5, 0x82, 0x91, 0xab, 0x05, 0x23, 0xdf, 0x16, 0x8c, 0xbc, 0x5f, 0x32, 0xef, 0x6a, 0xc9, + 0xbc, 0x2f, 0x4b, 0xe6, 0xbd, 0xda, 0xbb, 0xd5, 0x66, 0xc5, 0xbb, 0x7f, 0xd3, 0xad, 0x6c, 0xc7, + 0x74, 0xdd, 0xce, 0xea, 0xc9, 0xaf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x71, 0x6a, 0x45, 0x2c, 0xd2, + 0x03, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -196,20 +180,6 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.Rewards) > 0 { - for iNdEx := len(m.Rewards) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Rewards[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintGenesis(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x22 - } - } if len(m.Stakings) > 0 { for iNdEx := len(m.Stakings) - 1; iNdEx >= 0; iNdEx-- { { @@ -282,21 +252,7 @@ func (m *PlanRecord) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintGenesis(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x2a - } - } - if len(m.RewardPoolCoins) > 0 { - for iNdEx := len(m.RewardPoolCoins) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.RewardPoolCoins[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintGenesis(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x22 + dAtA[i] = 0x1a } } if len(m.FarmingPoolCoins) > 0 { @@ -310,17 +266,9 @@ func (m *PlanRecord) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintGenesis(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x1a + dAtA[i] = 0x12 } } - n2, err2 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.LastEpochTime, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.LastEpochTime):]) - if err2 != nil { - return 0, err2 - } - i -= n2 - i = encodeVarintGenesis(dAtA, i, uint64(n2)) - i-- - dAtA[i] = 0x12 { size, err := m.Plan.MarshalToSizedBuffer(dAtA[:i]) if err != nil { @@ -365,12 +313,6 @@ func (m *GenesisState) Size() (n int) { n += 1 + l + sovGenesis(uint64(l)) } } - if len(m.Rewards) > 0 { - for _, e := range m.Rewards { - l = e.Size() - n += 1 + l + sovGenesis(uint64(l)) - } - } return n } @@ -382,20 +324,12 @@ func (m *PlanRecord) Size() (n int) { _ = l l = m.Plan.Size() n += 1 + l + sovGenesis(uint64(l)) - l = github_com_gogo_protobuf_types.SizeOfStdTime(m.LastEpochTime) - n += 1 + l + sovGenesis(uint64(l)) if len(m.FarmingPoolCoins) > 0 { for _, e := range m.FarmingPoolCoins { l = e.Size() n += 1 + l + sovGenesis(uint64(l)) } } - if len(m.RewardPoolCoins) > 0 { - for _, e := range m.RewardPoolCoins { - l = e.Size() - n += 1 + l + sovGenesis(uint64(l)) - } - } if len(m.StakingReserveCoins) > 0 { for _, e := range m.StakingReserveCoins { l = e.Size() @@ -541,40 +475,6 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Rewards", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Rewards = append(m.Rewards, Reward{}) - if err := m.Rewards[len(m.Rewards)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) @@ -659,39 +559,6 @@ func (m *PlanRecord) Unmarshal(dAtA []byte) error { } iNdEx = postIndex case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field LastEpochTime", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.LastEpochTime, dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 3: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field FarmingPoolCoins", wireType) } @@ -725,41 +592,7 @@ func (m *PlanRecord) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RewardPoolCoins", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.RewardPoolCoins = append(m.RewardPoolCoins, types1.Coin{}) - if err := m.RewardPoolCoins[len(m.RewardPoolCoins)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 5: + case 3: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field StakingReserveCoins", wireType) } diff --git a/x/farming/types/query.pb.go b/x/farming/types/query.pb.go index 70f7ca46..975ecd4d 100644 --- a/x/farming/types/query.pb.go +++ b/x/farming/types/query.pb.go @@ -546,120 +546,6 @@ func (m *QueryStakingResponse) GetStaking() Staking { return Staking{} } -// QueryRewardsRequest is the request type for the Query/Rewards RPC method. -type QueryRewardsRequest struct { - Farmer string `protobuf:"bytes,1,opt,name=farmer,proto3" json:"farmer,omitempty"` - StakingCoinDenom string `protobuf:"bytes,2,opt,name=staking_coin_denom,json=stakingCoinDenom,proto3" json:"staking_coin_denom,omitempty" yaml:"staking_coin_denom"` - Pagination *query.PageRequest `protobuf:"bytes,3,opt,name=pagination,proto3" json:"pagination,omitempty"` -} - -func (m *QueryRewardsRequest) Reset() { *m = QueryRewardsRequest{} } -func (m *QueryRewardsRequest) String() string { return proto.CompactTextString(m) } -func (*QueryRewardsRequest) ProtoMessage() {} -func (*QueryRewardsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_00c8db58c274b111, []int{10} -} -func (m *QueryRewardsRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryRewardsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryRewardsRequest.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 *QueryRewardsRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryRewardsRequest.Merge(m, src) -} -func (m *QueryRewardsRequest) XXX_Size() int { - return m.Size() -} -func (m *QueryRewardsRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryRewardsRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryRewardsRequest proto.InternalMessageInfo - -func (m *QueryRewardsRequest) GetFarmer() string { - if m != nil { - return m.Farmer - } - return "" -} - -func (m *QueryRewardsRequest) GetStakingCoinDenom() string { - if m != nil { - return m.StakingCoinDenom - } - return "" -} - -func (m *QueryRewardsRequest) GetPagination() *query.PageRequest { - if m != nil { - return m.Pagination - } - return nil -} - -// QueryRewardsResponse is the response type for the Query/Rewards RPC method. -type QueryRewardsResponse struct { - Rewards []Reward `protobuf:"bytes,1,rep,name=rewards,proto3" json:"rewards"` - Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` -} - -func (m *QueryRewardsResponse) Reset() { *m = QueryRewardsResponse{} } -func (m *QueryRewardsResponse) String() string { return proto.CompactTextString(m) } -func (*QueryRewardsResponse) ProtoMessage() {} -func (*QueryRewardsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_00c8db58c274b111, []int{11} -} -func (m *QueryRewardsResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryRewardsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryRewardsResponse.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 *QueryRewardsResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryRewardsResponse.Merge(m, src) -} -func (m *QueryRewardsResponse) XXX_Size() int { - return m.Size() -} -func (m *QueryRewardsResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryRewardsResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryRewardsResponse proto.InternalMessageInfo - -func (m *QueryRewardsResponse) GetRewards() []Reward { - if m != nil { - return m.Rewards - } - return nil -} - -func (m *QueryRewardsResponse) GetPagination() *query.PageResponse { - if m != nil { - return m.Pagination - } - return nil -} - func init() { proto.RegisterType((*QueryParamsRequest)(nil), "cosmos.farming.v1beta1.QueryParamsRequest") proto.RegisterType((*QueryParamsResponse)(nil), "cosmos.farming.v1beta1.QueryParamsResponse") @@ -671,8 +557,6 @@ func init() { proto.RegisterType((*QueryStakingsResponse)(nil), "cosmos.farming.v1beta1.QueryStakingsResponse") proto.RegisterType((*QueryStakingRequest)(nil), "cosmos.farming.v1beta1.QueryStakingRequest") proto.RegisterType((*QueryStakingResponse)(nil), "cosmos.farming.v1beta1.QueryStakingResponse") - proto.RegisterType((*QueryRewardsRequest)(nil), "cosmos.farming.v1beta1.QueryRewardsRequest") - proto.RegisterType((*QueryRewardsResponse)(nil), "cosmos.farming.v1beta1.QueryRewardsResponse") } func init() { @@ -680,62 +564,58 @@ func init() { } var fileDescriptor_00c8db58c274b111 = []byte{ - // 877 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x56, 0x3d, 0x6f, 0x2b, 0x45, - 0x14, 0xf5, 0x38, 0xfe, 0x48, 0x6e, 0x9a, 0x30, 0x31, 0xc1, 0xb1, 0xc8, 0xda, 0xac, 0x44, 0xe2, - 0x7c, 0x78, 0x97, 0x24, 0xa4, 0x41, 0x08, 0x14, 0x83, 0x08, 0x11, 0x4d, 0x70, 0x0a, 0x24, 0x1a, - 0x6b, 0x9d, 0x9d, 0x2c, 0x2b, 0xec, 0x9d, 0xcd, 0xee, 0x1a, 0xb0, 0xa2, 0x34, 0x48, 0x14, 0x48, - 0x20, 0x81, 0xa0, 0xa3, 0x00, 0x89, 0xbf, 0xc0, 0x2f, 0x80, 0x26, 0xa2, 0x8a, 0x44, 0x43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, 0xaa, 0xea, 0x20, 0xe9, 0xd1, 0x5c, 0xdf, 0x79, 0x92, 0x83, 0xac, 0x50, 0x48, - 0xbf, 0x25, 0x90, 0x93, 0x5d, 0x9b, 0x6e, 0x8c, 0x12, 0xf3, 0xf0, 0xa1, 0x28, 0x6d, 0x4e, 0x85, - 0x95, 0x99, 0xf5, 0xd5, 0xaf, 0xff, 0xf9, 0xff, 0xa7, 0x74, 0x85, 0x6a, 0xf8, 0x04, 0x3d, 0x78, - 0x30, 0xe5, 0x43, 0x41, 0xbf, 0x21, 0x20, 0xfa, 0x40, 0x48, 0xd7, 0xc7, 0x87, 0xef, 0x7b, 0x47, - 0x4a, 0x1b, 0xd3, 0x40, 0x51, 0xc8, 0xeb, 0x42, 0x48, 0x99, 0xae, 0x8c, 0x14, 0x22, 0xb2, 0x7f, - 0x47, 0x20, 0x13, 0x13, 0x69, 0x75, 0x62, 0x6c, 0xa5, 0x62, 0x7d, 0x0a, 0x24, 0x8a, 0x30, 0x85, - 0x88, 0x75, 0xba, 0x36, 0x56, 0x84, 0x79, 0x8e, 0x5d, 0xf6, 0x82, 0xfe, 0x48, 0x60, 0x56, 0xf5, - 0x10, 0xba, 0x35, 0x36, 0xd1, 0xbd, 0x86, 0x59, 0xaa, 0x4d, 0x89, 0x46, 0x69, 0x55, 0x21, 0x4d, - 0xa7, 0x95, 0x51, 0xd2, 0x92, 0xfe, 0xf3, 0x0b, 0x81, 0x3c, 0xd2, 0xe9, 0xe6, 0x34, 0x49, 0x94, - 0xa2, 0xad, 0xe9, 0xc0, 0x28, 0x68, 0x4f, 0x08, 0x32, 0x69, 0x6d, 0x92, 0x20, 0xf3, 0xfc, 0xae, - 0x5d, 0x5d, 0xd0, 0xef, 0x09, 0xe4, 0xf1, 0xee, 0x4d, 0x50, 0x37, 0xd8, 0x66, 0x26, 0xa8, 0xbb, - 0x77, 0x9d, 0xf5, 0x35, 0xa1, 0xee, 0x35, 0x5a, 0x1e, 0xa5, 0x0e, 0xef, 0x6d, 0xfd, 0xe0, 0xf2, - 0x46, 0x23, 0x57, 0x37, 0x1a, 0xf9, 0xef, 0x46, 0x23, 0x3f, 0xdc, 0x6a, 0xa9, 0xab, 0x5b, 0x2d, - 0xf5, 0xef, 0xad, 0x96, 0xfa, 0xb4, 0xe6, 0xb8, 0xd1, 0x67, 0xdd, 0x96, 0x71, 0xc2, 0x3b, 0xe6, - 0x90, 0x7f, 0x94, 0x5f, 0x25, 0x5f, 0xf1, 0xff, 0xa3, 0xb0, 0x95, 0x13, 0x0f, 0xe7, 0xee, 0xb3, - 0x00, 0x00, 0x00, 0xff, 0xff, 0xaa, 0x1b, 0x33, 0xd1, 0xbe, 0x0a, 0x00, 0x00, + // 807 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x56, 0x4f, 0x4f, 0x13, 0x4f, + 0x18, 0xee, 0x96, 0xb6, 0xc0, 0xcb, 0x85, 0xdf, 0xd0, 0x1f, 0x96, 0x46, 0xb6, 0xcd, 0x26, 0x42, + 0xf9, 0xd3, 0x5d, 0x01, 0xb9, 0x18, 0x13, 0x43, 0x35, 0x22, 0xf1, 0x82, 0xe5, 0x60, 0xe2, 0xa5, + 0xd9, 0xb2, 0xc3, 0xba, 0xb1, 0xdd, 0x59, 0xba, 0x5b, 0x63, 0x43, 0xb8, 0x98, 0x78, 0x30, 0xf1, + 0xa0, 0xd1, 0x9b, 0x17, 0x13, 0xbf, 0x82, 0xdf, 0xc0, 0x0b, 0xf1, 0x44, 0xe2, 0xc5, 0x83, 0x21, + 0x06, 0xfc, 0x04, 0x7e, 0x02, 0xb3, 0x33, 0xef, 0x2c, 0x2d, 0xf4, 0x5f, 0x8c, 0x27, 0x76, 0x66, + 0x9e, 0xf7, 0x79, 0x9f, 0x79, 0x9f, 0x77, 0x5e, 0x0a, 0x73, 0x01, 0x75, 0x2d, 0xda, 0xa8, 0x3b, + 0x6e, 0x60, 0xec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 0xfe, 0x5a, 0x81, 0x44, 0x18, 0x48, 0x0a, 0x03, 0xb9, 0xa5, 0x8a, 0x85, + 0x21, 0x90, 0x28, 0xc2, 0xe0, 0x22, 0x16, 0xc8, 0x7c, 0x5f, 0x11, 0xc6, 0x01, 0x3e, 0xff, 0x43, + 0xf2, 0x56, 0x81, 0x31, 0xd9, 0xdc, 0x64, 0xb9, 0x6f, 0xa2, 0x0b, 0x2f, 0x39, 0x5b, 0x1c, 0x12, + 0x8d, 0xd2, 0x0a, 0x5c, 0x9a, 0x46, 0xf2, 0xbd, 0xa4, 0x45, 0x0f, 0xe3, 0x83, 0x02, 0xa3, 0x18, + 0x4e, 0x96, 0x86, 0x49, 0x22, 0x15, 0x2d, 0x0f, 0x07, 0x46, 0x41, 0xeb, 0x5c, 0x90, 0x41, 0x8a, + 0x83, 0x04, 0x19, 0x07, 0xe7, 0xef, 0xe8, 0xb0, 0xb4, 0x79, 0x74, 0xaa, 0x2a, 0xc7, 0xa7, 0xaa, + 0xf2, 0xf3, 0x54, 0x55, 0xde, 0x9c, 0xa9, 0xb1, 0xe3, 0x33, 0x35, 0xf6, 0xfd, 0x4c, 0x8d, 0x3d, + 0x2e, 0xda, 0x4e, 0xf0, 0xa4, 0x59, 0xd5, 0x77, 0x59, 0xdd, 0xe8, 0xf2, 0xd3, 0xe2, 0x79, 0xf4, + 0x15, 0xfe, 0xa3, 0xf4, 0xab, 0x29, 0x3e, 0x41, 0xd7, 0xfe, 0x04, 0x00, 0x00, 0xff, 0xff, 0x8e, + 0xc7, 0xd1, 0xb8, 0xc7, 0x08, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -760,8 +640,6 @@ type QueryClient interface { Stakings(ctx context.Context, in *QueryStakingsRequest, opts ...grpc.CallOption) (*QueryStakingsResponse, error) // Staking returns a specific staking. Staking(ctx context.Context, in *QueryStakingRequest, opts ...grpc.CallOption) (*QueryStakingResponse, error) - // Rewards returns all rewards. - Rewards(ctx context.Context, in *QueryRewardsRequest, opts ...grpc.CallOption) (*QueryRewardsResponse, error) } type queryClient struct { @@ -817,15 +695,6 @@ func (c *queryClient) Staking(ctx context.Context, in *QueryStakingRequest, opts return out, nil } -func (c *queryClient) Rewards(ctx context.Context, in *QueryRewardsRequest, opts ...grpc.CallOption) (*QueryRewardsResponse, error) { - out := new(QueryRewardsResponse) - err := c.cc.Invoke(ctx, "/cosmos.farming.v1beta1.Query/Rewards", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - // QueryServer is the server API for Query service. type QueryServer interface { // Params returns parameters of the farming module. @@ -838,8 +707,6 @@ type QueryServer interface { Stakings(context.Context, *QueryStakingsRequest) (*QueryStakingsResponse, error) // Staking returns a specific staking. Staking(context.Context, *QueryStakingRequest) (*QueryStakingResponse, error) - // Rewards returns all rewards. - Rewards(context.Context, *QueryRewardsRequest) (*QueryRewardsResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. @@ -861,9 +728,6 @@ func (*UnimplementedQueryServer) Stakings(ctx context.Context, req *QueryStaking func (*UnimplementedQueryServer) Staking(ctx context.Context, req *QueryStakingRequest) (*QueryStakingResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Staking not implemented") } -func (*UnimplementedQueryServer) Rewards(ctx context.Context, req *QueryRewardsRequest) (*QueryRewardsResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Rewards not implemented") -} func RegisterQueryServer(s grpc1.Server, srv QueryServer) { s.RegisterService(&_Query_serviceDesc, srv) @@ -959,24 +823,6 @@ func _Query_Staking_Handler(srv interface{}, ctx context.Context, dec func(inter return interceptor(ctx, in, info, handler) } -func _Query_Rewards_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryRewardsRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(QueryServer).Rewards(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/cosmos.farming.v1beta1.Query/Rewards", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).Rewards(ctx, req.(*QueryRewardsRequest)) - } - return interceptor(ctx, in, info, handler) -} - var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "cosmos.farming.v1beta1.Query", HandlerType: (*QueryServer)(nil), @@ -1001,10 +847,6 @@ var _Query_serviceDesc = grpc.ServiceDesc{ MethodName: "Staking", Handler: _Query_Staking_Handler, }, - { - MethodName: "Rewards", - Handler: _Query_Rewards_Handler, - }, }, Streams: []grpc.StreamDesc{}, Metadata: "tendermint/farming/v1beta1/query.proto", @@ -1407,104 +1249,6 @@ func (m *QueryStakingResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *QueryRewardsRequest) 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 *QueryRewardsRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryRewardsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Pagination != nil { - { - size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - } - if len(m.StakingCoinDenom) > 0 { - i -= len(m.StakingCoinDenom) - copy(dAtA[i:], m.StakingCoinDenom) - i = encodeVarintQuery(dAtA, i, uint64(len(m.StakingCoinDenom))) - i-- - dAtA[i] = 0x12 - } - if len(m.Farmer) > 0 { - i -= len(m.Farmer) - copy(dAtA[i:], m.Farmer) - i = encodeVarintQuery(dAtA, i, uint64(len(m.Farmer))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *QueryRewardsResponse) 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 *QueryRewardsResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryRewardsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Pagination != nil { - { - size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - if len(m.Rewards) > 0 { - for iNdEx := len(m.Rewards) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Rewards[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - } - return len(dAtA) - i, nil -} - func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { offset -= sovQuery(v) base := offset @@ -1676,46 +1420,6 @@ func (m *QueryStakingResponse) Size() (n int) { return n } -func (m *QueryRewardsRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Farmer) - if l > 0 { - n += 1 + l + sovQuery(uint64(l)) - } - l = len(m.StakingCoinDenom) - if l > 0 { - n += 1 + l + sovQuery(uint64(l)) - } - if m.Pagination != nil { - l = m.Pagination.Size() - n += 1 + l + sovQuery(uint64(l)) - } - return n -} - -func (m *QueryRewardsResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if len(m.Rewards) > 0 { - for _, e := range m.Rewards { - l = e.Size() - n += 1 + l + sovQuery(uint64(l)) - } - } - if m.Pagination != nil { - l = m.Pagination.Size() - n += 1 + l + sovQuery(uint64(l)) - } - return n -} - func sovQuery(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -2798,276 +2502,6 @@ func (m *QueryStakingResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryRewardsRequest) 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 ErrIntOverflowQuery - } - 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: QueryRewardsRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryRewardsRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Farmer", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - 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 ErrInvalidLengthQuery - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Farmer = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field StakingCoinDenom", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - 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 ErrInvalidLengthQuery - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.StakingCoinDenom = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Pagination == nil { - m.Pagination = &query.PageRequest{} - } - if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryRewardsResponse) 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 ErrIntOverflowQuery - } - 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: QueryRewardsResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryRewardsResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Rewards", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Rewards = append(m.Rewards, Reward{}) - if err := m.Rewards[len(m.Rewards)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Pagination == nil { - m.Pagination = &query.PageResponse{} - } - if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func skipQuery(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/farming/types/query.pb.gw.go b/x/farming/types/query.pb.gw.go index ff008a74..36a5c276 100644 --- a/x/farming/types/query.pb.gw.go +++ b/x/farming/types/query.pb.gw.go @@ -229,42 +229,6 @@ func local_request_Query_Staking_0(ctx context.Context, marshaler runtime.Marsha } -var ( - filter_Query_Rewards_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} -) - -func request_Query_Rewards_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryRewardsRequest - var metadata runtime.ServerMetadata - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Rewards_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Rewards(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Query_Rewards_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryRewardsRequest - var metadata runtime.ServerMetadata - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Rewards_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.Rewards(ctx, &protoReq) - return msg, metadata, err - -} - // 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. @@ -371,26 +335,6 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) - mux.Handle("GET", pattern_Query_Rewards_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Query_Rewards_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_Rewards_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - return nil } @@ -532,26 +476,6 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) - mux.Handle("GET", pattern_Query_Rewards_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Query_Rewards_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_Rewards_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - return nil } @@ -565,8 +489,6 @@ var ( pattern_Query_Stakings_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "farming", "v1beta1", "stakings"}, "", runtime.AssumeColonVerbOpt(false))) pattern_Query_Staking_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"cosmos", "farming", "v1beta1", "stakings", "staking_id"}, "", runtime.AssumeColonVerbOpt(false))) - - pattern_Query_Rewards_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "farming", "v1beta1", "rewards"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( @@ -579,6 +501,4 @@ var ( forward_Query_Stakings_0 = runtime.ForwardResponseMessage forward_Query_Staking_0 = runtime.ForwardResponseMessage - - forward_Query_Rewards_0 = runtime.ForwardResponseMessage ) From 59cb86aec1e0d055672e022a8162063710781bb6 Mon Sep 17 00:00:00 2001 From: Hanjun Kim Date: Fri, 3 Sep 2021 16:35:45 +0900 Subject: [PATCH 02/16] refactor!: apply f1 distribution; WIP --- app/app.go | 2 +- .../tendermint/farming/v1beta1/farming.proto | 41 +- proto/tendermint/farming/v1beta1/query.proto | 33 - x/farming/abci.go | 5 +- x/farming/client/cli/query.go | 154 -- x/farming/handler_test.go | 1 - x/farming/keeper/epoch.go | 13 + x/farming/keeper/genesis.go | 2 +- x/farming/keeper/grpc_query.go | 164 -- x/farming/keeper/grpc_query_test.go | 346 ++--- x/farming/keeper/invariants.go | 93 +- x/farming/keeper/invariants_test.go | 193 ++- x/farming/keeper/keeper.go | 10 +- x/farming/keeper/keeper_test.go | 6 +- x/farming/keeper/msg_server.go | 4 +- x/farming/keeper/plan_test.go | 85 +- x/farming/keeper/reward.go | 323 ++-- x/farming/keeper/reward_test.go | 149 +- x/farming/keeper/simulation_test.go | 176 +++ x/farming/keeper/staking.go | 422 +++--- x/farming/keeper/staking_test.go | 434 +++--- x/farming/simulation/decoder.go | 5 - x/farming/types/events.go | 2 +- x/farming/types/expected_keepers.go | 16 - x/farming/types/farming.pb.go | 805 ++++++++-- x/farming/types/genesis.go | 33 +- x/farming/types/keys.go | 76 +- x/farming/types/msgs_test.go | 10 + x/farming/types/params.go | 22 - x/farming/types/params_test.go | 7 - x/farming/types/query.pb.go | 1316 +++-------------- x/farming/types/query.pb.gw.go | 178 --- x/farming/types/reward.go | 37 - x/farming/types/staking.go | 17 - 34 files changed, 2086 insertions(+), 3094 deletions(-) create mode 100644 x/farming/keeper/simulation_test.go diff --git a/app/app.go b/app/app.go index e9d8dedc..a8461225 100644 --- a/app/app.go +++ b/app/app.go @@ -284,7 +284,7 @@ func NewFarmingApp( app.FarmingKeeper = farmingkeeper.NewKeeper( appCodec, keys[farmingtypes.StoreKey], app.GetSubspace(farmingtypes.ModuleName), app.AccountKeeper, - app.BankKeeper, app.DistrKeeper, app.ModuleAccountAddrs(), + app.BankKeeper, app.ModuleAccountAddrs(), ) // todo: farming ordering diff --git a/proto/tendermint/farming/v1beta1/farming.proto b/proto/tendermint/farming/v1beta1/farming.proto index 17006ae5..2c63f29c 100644 --- a/proto/tendermint/farming/v1beta1/farming.proto +++ b/proto/tendermint/farming/v1beta1/farming.proto @@ -138,24 +138,35 @@ message Staking { option (gogoproto.goproto_getters) = false; option (gogoproto.goproto_stringer) = false; - // id specifies index of the staking - uint64 id = 1; + string amount = 1 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false]; - // farmer defines the bech32-encoded address of the staker for the plan - string farmer = 2; + uint64 starting_epoch = 2 [(gogoproto.moretags) = "yaml:\"starting_epoch\""]; +} - // staked_coins specifies the staking amount for the plan of farmer - repeated cosmos.base.v1beta1.Coin staked_coins = 3 [ - (gogoproto.moretags) = "yaml:\"staked_coins\"", - (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", - (gogoproto.nullable) = false - ]; +message QueuedStaking { + option (gogoproto.goproto_getters) = false; - // queued_coins specifies the coins on standby before current epoch passes and - // gets staked. - repeated cosmos.base.v1beta1.Coin queued_coins = 4 [ - (gogoproto.moretags) = "yaml:\"queued_coins\"", - (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", + string amount = 1 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false]; +} + +message TotalStaking { + option (gogoproto.goproto_getters) = false; + + string amount = 1 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false]; +} + +message HistoricalRewards { + option (gogoproto.goproto_getters) = false; + + repeated cosmos.base.v1beta1.DecCoin cumulative_unit_rewards = 1 [ + (gogoproto.moretags) = "yaml:\"cumulative_unit_rewards\"", + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins", (gogoproto.nullable) = false ]; } + +message CurrentRewards { + option (gogoproto.goproto_getters) = false; + + uint64 epoch = 1; +} \ No newline at end of file diff --git a/proto/tendermint/farming/v1beta1/query.proto b/proto/tendermint/farming/v1beta1/query.proto index df32c141..ba749fc3 100644 --- a/proto/tendermint/farming/v1beta1/query.proto +++ b/proto/tendermint/farming/v1beta1/query.proto @@ -27,16 +27,6 @@ service Query { rpc Plan(QueryPlanRequest) returns (QueryPlanResponse) { option (google.api.http).get = "/cosmos/farming/v1beta1/plans/{plan_id}"; } - - // Stakings returns all stakings. - rpc Stakings(QueryStakingsRequest) returns (QueryStakingsResponse) { - option (google.api.http).get = "/cosmos/farming/v1beta1/stakings"; - } - - // Staking returns a specific staking. - rpc Staking(QueryStakingRequest) returns (QueryStakingResponse) { - option (google.api.http).get = "/cosmos/farming/v1beta1/stakings/{staking_id}"; - } } // QueryParamsRequest is the request type for the Query/Params RPC method. @@ -72,26 +62,3 @@ message QueryPlanRequest { message QueryPlanResponse { google.protobuf.Any plan = 1 [(cosmos_proto.accepts_interface) = "PlanI"]; } - -// QueryStakingsRequest is the request type for the Query/Stakings RPC method. -message QueryStakingsRequest { - string farmer = 1; - string staking_coin_denom = 2 [(gogoproto.moretags) = "yaml:\"staking_coin_denom\""]; - cosmos.base.query.v1beta1.PageRequest pagination = 3; -} - -// QueryStakingsResponse is the response type for the Query/Stakings RPC method. -message QueryStakingsResponse { - repeated Staking stakings = 1 [(gogoproto.nullable) = false]; - cosmos.base.query.v1beta1.PageResponse pagination = 2; -} - -// QueryStakingRequest is the request type for the Query/Staking RPC method. -message QueryStakingRequest { - uint64 staking_id = 1; -} - -// QueryStakingResponse is the response type for the Query/Staking RPC method. -message QueryStakingResponse { - Staking staking = 1 [(gogoproto.nullable) = false]; -} diff --git a/x/farming/abci.go b/x/farming/abci.go index 12a84585..f67497df 100644 --- a/x/farming/abci.go +++ b/x/farming/abci.go @@ -30,12 +30,9 @@ func EndBlocker(ctx sdk.Context, k keeper.Keeper) { y, m, d := lastEpochTime.AddDate(0, 0, int(params.EpochDays)).Date() y2, m2, d2 := ctx.BlockTime().Date() if y == y2 && m == m2 && d == d2 { - if err := k.DistributeRewards(ctx); err != nil { + if err := k.AdvanceEpoch(ctx); err != nil { panic(err) } - k.ProcessQueuedCoins(ctx) - - k.SetLastEpochTime(ctx, ctx.BlockTime()) } } } diff --git a/x/farming/client/cli/query.go b/x/farming/client/cli/query.go index dc422d40..890f96ec 100644 --- a/x/farming/client/cli/query.go +++ b/x/farming/client/cli/query.go @@ -34,9 +34,6 @@ func GetQueryCmd() *cobra.Command { GetCmdQueryParams(), GetCmdQueryPlans(), GetCmdQueryPlan(), - GetCmdQueryStakings(), - GetCmdQueryStaking(), - GetCmdQueryRewards(), ) return farmingQueryCmd @@ -191,154 +188,3 @@ $ %s query %s plan return cmd } - -func GetCmdQueryStakings() *cobra.Command { - cmd := &cobra.Command{ - Use: "stakings [optional flags]", - Args: cobra.NoArgs, - Short: "Query for all stakings", - Long: strings.TrimSpace( - fmt.Sprintf(`Query details about all farming stakings on a network. - -Example: -$ %s query %s stakings -$ %s query %s stakings --farmer-addr %s1zaavvzxez0elundtn32qnk9lkm8kmcszzsv80v -$ %s query %s stakings --staking-coin-denom poolD35A0CC16EE598F90B044CE296A405BA9C381E38837599D96F2F70C2F02A23A4 -`, - version.AppName, types.ModuleName, - version.AppName, types.ModuleName, - version.AppName, types.ModuleName, sdk.Bech32MainPrefix, - ), - ), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - - farmerAddr, _ := cmd.Flags().GetString(FlagFarmerAddr) - stakingCoinDenom, _ := cmd.Flags().GetString(FlagStakingCoinDenom) - - queryClient := types.NewQueryClient(clientCtx) - pageReq, err := client.ReadPageRequest(cmd.Flags()) - if err != nil { - return err - } - - resp, err := queryClient.Stakings(cmd.Context(), &types.QueryStakingsRequest{ - Farmer: farmerAddr, - StakingCoinDenom: stakingCoinDenom, - Pagination: pageReq, - }) - if err != nil { - return err - } - - return clientCtx.PrintProto(resp) - }, - } - - cmd.Flags().AddFlagSet(flagSetStaking()) - flags.AddQueryFlagsToCmd(cmd) - flags.AddPaginationFlagsToCmd(cmd, "stakings") - - return cmd -} - -func GetCmdQueryStaking() *cobra.Command { - cmd := &cobra.Command{ - Use: "staking [staking-id]", - Args: cobra.ExactArgs(1), - Short: "Query a specific staking", - Long: strings.TrimSpace( - fmt.Sprintf(`Query details about a specific plan. - -Example: -$ %s query %s staking 1 -`, - version.AppName, types.ModuleName, - ), - ), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - - stakingId, err := strconv.ParseUint(args[0], 10, 64) - if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "staking-id %s is not valid", args[0]) - } - - queryClient := types.NewQueryClient(clientCtx) - - resp, err := queryClient.Staking(cmd.Context(), &types.QueryStakingRequest{ - StakingId: stakingId, - }) - if err != nil { - return err - } - - return clientCtx.PrintProto(resp) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} - -func GetCmdQueryRewards() *cobra.Command { - cmd := &cobra.Command{ - Use: "rewards [optional flags]", - Args: cobra.NoArgs, - Short: "Query for all rewards", - Long: strings.TrimSpace( - fmt.Sprintf(`Query rewards that are accumulated on a network. - -Example: -$ %s query %s rewards -$ %s query %s rewards --farmer-addr %s1zaavvzxez0elundtn32qnk9lkm8kmcszzsv80v -$ %s query %s rewards --staking-coin-denom uatom -$ %s query %s rewards --staking-coin-denom uatom --farmer-addr %s1zaavvzxez0elundtn32qnk9lkm8kmcszzsv80v -`, - version.AppName, types.ModuleName, - version.AppName, types.ModuleName, - version.AppName, types.ModuleName, sdk.Bech32MainPrefix, - version.AppName, types.ModuleName, sdk.Bech32MainPrefix, - ), - ), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - - farmerAddr, _ := cmd.Flags().GetString(FlagFarmerAddr) - stakingCoinDenom, _ := cmd.Flags().GetString(FlagStakingCoinDenom) - - queryClient := types.NewQueryClient(clientCtx) - pageReq, err := client.ReadPageRequest(cmd.Flags()) - if err != nil { - return err - } - - resp, err := queryClient.Rewards(cmd.Context(), &types.QueryRewardsRequest{ - Farmer: farmerAddr, - StakingCoinDenom: stakingCoinDenom, - Pagination: pageReq, - }) - if err != nil { - return err - } - - return clientCtx.PrintProto(resp) - }, - } - - cmd.Flags().AddFlagSet(flagSetRewards()) - flags.AddQueryFlagsToCmd(cmd) - flags.AddPaginationFlagsToCmd(cmd, "rewards") - - return cmd -} diff --git a/x/farming/handler_test.go b/x/farming/handler_test.go index 9aec164f..6eb3a3b3 100644 --- a/x/farming/handler_test.go +++ b/x/farming/handler_test.go @@ -28,7 +28,6 @@ func createTestInput() (*farmingapp.FarmingApp, sdk.Context, []sdk.AccAddress) { app.GetSubspace(types.ModuleName), app.AccountKeeper, app.BankKeeper, - app.DistrKeeper, map[string]bool{}, ) diff --git a/x/farming/keeper/epoch.go b/x/farming/keeper/epoch.go index 4672e54d..b3201348 100644 --- a/x/farming/keeper/epoch.go +++ b/x/farming/keeper/epoch.go @@ -1,6 +1,7 @@ package keeper import ( + "fmt" "time" gogotypes "github.com/gogo/protobuf/types" @@ -34,3 +35,15 @@ func (k Keeper) SetLastEpochTime(ctx sdk.Context, t time.Time) { bz := k.cdc.MustMarshal(ts) store.Set(types.GlobalLastEpochTimeKey, bz) } + +func (k Keeper) AdvanceEpoch(ctx sdk.Context) error { + fmt.Println(">>> AdvanceEpoch()") + if err := k.AllocateRewards(ctx); err != nil { + return err + } + k.ProcessQueuedCoins(ctx) + k.SetLastEpochTime(ctx, ctx.BlockTime()) + fmt.Println("<<< AdvanceEpoch()") + + return nil +} \ No newline at end of file diff --git a/x/farming/keeper/genesis.go b/x/farming/keeper/genesis.go index 9d161b39..e13d3cca 100644 --- a/x/farming/keeper/genesis.go +++ b/x/farming/keeper/genesis.go @@ -59,7 +59,7 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { // planRecords = []types.PlanRecord{} //} - return types.NewGenesisState(params, planRecords, nil, nil) + return types.NewGenesisState(params, planRecords, nil) } // ValidateGenesis validates the farming module's genesis state. diff --git a/x/farming/keeper/grpc_query.go b/x/farming/keeper/grpc_query.go index 52a62134..2ff053d0 100644 --- a/x/farming/keeper/grpc_query.go +++ b/x/farming/keeper/grpc_query.go @@ -2,7 +2,6 @@ package keeper import ( "context" - "fmt" "strconv" "google.golang.org/grpc/codes" @@ -146,166 +145,3 @@ func (k Querier) Plan(c context.Context, req *types.QueryPlanRequest) (*types.Qu return &types.QueryPlanResponse{Plan: any}, nil } - -// Stakings queries all stakings. -func (k Querier) Stakings(c context.Context, req *types.QueryStakingsRequest) (*types.QueryStakingsResponse, error) { - if req == nil { - return nil, status.Error(codes.InvalidArgument, "invalid request") - } - - if req.StakingCoinDenom != "" { - if err := sdk.ValidateDenom(req.StakingCoinDenom); err != nil { - return nil, err - } - } - - ctx := sdk.UnwrapSDKContext(c) - store := ctx.KVStore(k.storeKey) - var stakings []types.Staking - var pageRes *query.PageResponse - var err error - - if req.Farmer != "" { - farmerAcc, err := sdk.AccAddressFromBech32(req.Farmer) - if err != nil { - return nil, err - } - - staking, found := k.GetStakingByFarmer(ctx, farmerAcc) - if found { - found := false - - if req.StakingCoinDenom != "" { - for _, denom := range staking.StakingCoinDenoms() { - if denom == req.StakingCoinDenom { - found = true - break - } - } - } else { - found = true - } - - if found { - stakings = append(stakings, staking) - } - } - - pageRes = &query.PageResponse{ - NextKey: nil, - Total: uint64(len(stakings)), - } - } else { - if req.StakingCoinDenom != "" { - storePrefix := types.GetStakingsByStakingCoinDenomIndexKey(req.StakingCoinDenom) - indexStore := prefix.NewStore(store, storePrefix) - pageRes, err = query.Paginate(indexStore, req.Pagination, func(key, value []byte) error { - _, stakingID := types.ParseStakingsByStakingCoinDenomIndexKey(append(storePrefix, key...)) - staking, _ := k.GetStaking(ctx, stakingID) - stakings = append(stakings, staking) - return nil - }) - } else { - stakingStore := prefix.NewStore(store, types.StakingKeyPrefix) - pageRes, err = query.Paginate(stakingStore, req.Pagination, func(key, value []byte) error { - var staking types.Staking - k.cdc.MustUnmarshal(value, &staking) - stakings = append(stakings, staking) - return nil - }) - } - if err != nil { - return nil, status.Error(codes.Internal, err.Error()) - } - } - - return &types.QueryStakingsResponse{Stakings: stakings, Pagination: pageRes}, nil -} - -// Staking queries a specific staking. -func (k Querier) Staking(c context.Context, req *types.QueryStakingRequest) (*types.QueryStakingResponse, error) { - if req == nil { - return nil, status.Error(codes.InvalidArgument, "invalid request") - } - - ctx := sdk.UnwrapSDKContext(c) - staking, found := k.GetStaking(ctx, req.StakingId) - if !found { - return nil, status.Errorf(codes.NotFound, "staking %d not found", req.StakingId) - } - - return &types.QueryStakingResponse{Staking: staking}, nil -} - -// Rewards queries all rewards. -func (k Querier) Rewards(c context.Context, req *types.QueryRewardsRequest) (*types.QueryRewardsResponse, error) { - if req == nil { - return nil, status.Error(codes.InvalidArgument, "invalid request") - } - - if req.StakingCoinDenom != "" { - if err := sdk.ValidateDenom(req.StakingCoinDenom); err != nil { - return nil, err - } - } - - ctx := sdk.UnwrapSDKContext(c) - store := ctx.KVStore(k.storeKey) - var rewards []types.Reward - var pageRes *query.PageResponse - var err error - - if req.Farmer != "" { - var farmerAcc sdk.AccAddress - farmerAcc, err = sdk.AccAddressFromBech32(req.Farmer) - if err != nil { - return nil, err - } - - storePrefix := types.GetRewardsByFarmerIndexKey(farmerAcc) - indexStore := prefix.NewStore(store, storePrefix) - pageRes, err = query.FilteredPaginate(indexStore, req.Pagination, func(key, value []byte, accumulate bool) (bool, error) { - _, stakingCoinDenom := types.ParseRewardsByFarmerIndexKey(append(storePrefix, key...)) - if req.StakingCoinDenom != "" { - if stakingCoinDenom != req.StakingCoinDenom { - return false, nil - } - } - reward, found := k.GetReward(ctx, stakingCoinDenom, farmerAcc) - if !found { // TODO: remove this check - return false, fmt.Errorf("reward not found") - } - if accumulate { - rewards = append(rewards, reward) - } - return true, nil - }) - } else { - var storePrefix []byte - if req.StakingCoinDenom != "" { - storePrefix = types.GetRewardsByStakingCoinDenomKey(req.StakingCoinDenom) - } else { - storePrefix = types.RewardKeyPrefix - } - rewardStore := prefix.NewStore(store, storePrefix) - - pageRes, err = query.Paginate(rewardStore, req.Pagination, func(key, value []byte) error { - stakingCoinDenom, farmerAcc := types.ParseRewardKey(append(storePrefix, key...)) - rewardCoins, err := k.UnmarshalRewardCoins(value) - if err != nil { - return err - } - rewards = append(rewards, types.Reward{ - Farmer: farmerAcc.String(), - StakingCoinDenom: stakingCoinDenom, - RewardCoins: rewardCoins.RewardCoins, - }) - return nil - }) - } - if err != nil { - return nil, status.Error(codes.Internal, err.Error()) - } - - return &types.QueryRewardsResponse{Rewards: rewards, Pagination: pageRes}, nil -} diff --git a/x/farming/keeper/grpc_query_test.go b/x/farming/keeper/grpc_query_test.go index 2902f02b..b3fe8a1e 100644 --- a/x/farming/keeper/grpc_query_test.go +++ b/x/farming/keeper/grpc_query_test.go @@ -217,220 +217,132 @@ func (suite *KeeperTestSuite) TestGRPCPlan() { } } -func (suite *KeeperTestSuite) TestGRPCStakings() { - suite.Stake(suite.addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom1, 1000), sdk.NewInt64Coin(denom2, 1500))) - suite.Stake(suite.addrs[1], sdk.NewCoins(sdk.NewInt64Coin(denom1, 500))) - suite.Stake(suite.addrs[2], sdk.NewCoins(sdk.NewInt64Coin(denom2, 800))) - suite.keeper.ProcessQueuedCoins(suite.ctx) - - for _, tc := range []struct { - name string - req *types.QueryStakingsRequest - expectErr bool - postRun func(response *types.QueryStakingsResponse) - }{ - { - "nil request", - nil, - true, - nil, - }, - { - "query all", - &types.QueryStakingsRequest{}, - false, - func(resp *types.QueryStakingsResponse) { - suite.Require().Len(resp.Stakings, 3) - }, - }, - { - "query by farmer addr", - &types.QueryStakingsRequest{Farmer: suite.addrs[0].String()}, - false, - func(resp *types.QueryStakingsResponse) { - suite.Require().Len(resp.Stakings, 1) - suite.Require().Equal(suite.addrs[0], resp.Stakings[0].GetFarmer()) - }, - }, - { - "invalid farmer addr", - &types.QueryStakingsRequest{Farmer: "invalid"}, - true, - nil, - }, - { - "query by staking coin denom", - &types.QueryStakingsRequest{StakingCoinDenom: denom1}, - false, - func(resp *types.QueryStakingsResponse) { - suite.Require().Len(resp.Stakings, 2) - for _, staking := range resp.Stakings { - suite.Require().True(staking.StakedCoins.Add(staking.QueuedCoins...).AmountOf(denom1).IsPositive()) - } - }, - }, - { - "invalid staking coin denom", - &types.QueryStakingsRequest{Farmer: "!!!"}, - true, - nil, - }, - { - "query by farmer addr and staking coin denom", - &types.QueryStakingsRequest{ - Farmer: suite.addrs[0].String(), - StakingCoinDenom: denom1, - }, - false, - func(resp *types.QueryStakingsResponse) { - suite.Require().Len(resp.Stakings, 1) - suite.Require().Equal(suite.addrs[0], resp.Stakings[0].GetFarmer()) - suite.Require().True( - resp.Stakings[0].StakedCoins.Add(resp.Stakings[0].QueuedCoins...).AmountOf(denom1).IsPositive()) - }, - }, - } { - suite.Run(tc.name, func() { - resp, err := suite.querier.Stakings(sdk.WrapSDKContext(suite.ctx), tc.req) - if tc.expectErr { - suite.Require().Error(err) - } else { - suite.Require().NoError(err) - tc.postRun(resp) - } - }) - } -} - -func (suite *KeeperTestSuite) TestGRPCStaking() { - suite.Stake(suite.addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom1, 1000), sdk.NewInt64Coin(denom2, 1500))) - suite.Stake(suite.addrs[1], sdk.NewCoins(sdk.NewInt64Coin(denom1, 500))) - suite.Stake(suite.addrs[2], sdk.NewCoins(sdk.NewInt64Coin(denom2, 800))) - suite.keeper.ProcessQueuedCoins(suite.ctx) - - for _, tc := range []struct { - name string - req *types.QueryStakingRequest - expectErr bool - postRun func(*types.QueryStakingResponse) - }{ - { - "nil request", - nil, - true, - nil, - }, - { - "query by id", - &types.QueryStakingRequest{StakingId: 1}, - false, - func(resp *types.QueryStakingResponse) { - suite.Require().Equal(uint64(1), resp.Staking.Id) - }, - }, - { - "id not found", - &types.QueryStakingRequest{StakingId: 10}, - true, - nil, - }, - } { - suite.Run(tc.name, func() { - resp, err := suite.querier.Staking(sdk.WrapSDKContext(suite.ctx), tc.req) - if tc.expectErr { - suite.Require().Error(err) - } else { - suite.Require().NoError(err) - tc.postRun(resp) - } - }) - } -} - -func (suite *KeeperTestSuite) TestGRPCRewards() { - // Set rewards manually for testing. - // Actual reward distribution doesn't work like this. - suite.keeper.SetReward(suite.ctx, denom1, suite.addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom3, 1000))) - suite.keeper.SetReward(suite.ctx, denom2, suite.addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom3, 1000))) - suite.keeper.SetReward(suite.ctx, denom1, suite.addrs[1], sdk.NewCoins(sdk.NewInt64Coin(denom3, 1000))) - suite.keeper.SetReward(suite.ctx, denom2, suite.addrs[2], sdk.NewCoins(sdk.NewInt64Coin(denom3, 1000))) - - for _, tc := range []struct { - name string - req *types.QueryRewardsRequest - expectErr bool - postRun func(response *types.QueryRewardsResponse) - }{ - { - "nil request", - nil, - true, - nil, - }, - { - "query all", - &types.QueryRewardsRequest{}, - false, - func(resp *types.QueryRewardsResponse) { - suite.Require().Len(resp.Rewards, 4) - }, - }, - { - "query by farmer addr", - &types.QueryRewardsRequest{Farmer: suite.addrs[0].String()}, - false, - func(resp *types.QueryRewardsResponse) { - suite.Require().Len(resp.Rewards, 2) - for _, reward := range resp.Rewards { - suite.Require().Equal(suite.addrs[0].String(), reward.Farmer) - } - }, - }, - { - "invalid farmer addr", - &types.QueryRewardsRequest{Farmer: "invalid"}, - true, - nil, - }, - { - "query by staking coin denom", - &types.QueryRewardsRequest{StakingCoinDenom: denom1}, - false, - func(resp *types.QueryRewardsResponse) { - suite.Require().Len(resp.Rewards, 2) - for _, reward := range resp.Rewards { - suite.Require().Equal(denom1, reward.StakingCoinDenom) - } - }, - }, - { - "invalid staking coin denom", - &types.QueryRewardsRequest{StakingCoinDenom: "!!!"}, - true, - nil, - }, - { - "query by farmer addr and staking coin denom", - &types.QueryRewardsRequest{ - Farmer: suite.addrs[0].String(), - StakingCoinDenom: denom1, - }, - false, - func(resp *types.QueryRewardsResponse) { - suite.Require().Len(resp.Rewards, 1) - suite.Require().Equal(suite.addrs[0], resp.Rewards[0].GetFarmer()) - suite.Require().Equal(denom1, resp.Rewards[0].StakingCoinDenom) - }, - }, - } { - suite.Run(tc.name, func() { - resp, err := suite.querier.Rewards(sdk.WrapSDKContext(suite.ctx), tc.req) - if tc.expectErr { - suite.Require().Error(err) - } else { - suite.Require().NoError(err) - tc.postRun(resp) - } - }) - } -} +//func (suite *KeeperTestSuite) TestGRPCStakings() { +// suite.Stake(suite.addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom1, 1000), sdk.NewInt64Coin(denom2, 1500))) +// suite.Stake(suite.addrs[1], sdk.NewCoins(sdk.NewInt64Coin(denom1, 500))) +// suite.Stake(suite.addrs[2], sdk.NewCoins(sdk.NewInt64Coin(denom2, 800))) +// suite.keeper.ProcessQueuedCoins(suite.ctx) +// +// for _, tc := range []struct { +// name string +// req *types.QueryStakingsRequest +// expectErr bool +// postRun func(response *types.QueryStakingsResponse) +// }{ +// { +// "nil request", +// nil, +// true, +// nil, +// }, +// { +// "query all", +// &types.QueryStakingsRequest{}, +// false, +// func(resp *types.QueryStakingsResponse) { +// suite.Require().Len(resp.Stakings, 3) +// }, +// }, +// { +// "query by farmer addr", +// &types.QueryStakingsRequest{Farmer: suite.addrs[0].String()}, +// false, +// func(resp *types.QueryStakingsResponse) { +// suite.Require().Len(resp.Stakings, 1) +// suite.Require().Equal(suite.addrs[0], resp.Stakings[0].GetFarmer()) +// }, +// }, +// { +// "invalid farmer addr", +// &types.QueryStakingsRequest{Farmer: "invalid"}, +// true, +// nil, +// }, +// { +// "query by staking coin denom", +// &types.QueryStakingsRequest{StakingCoinDenom: denom1}, +// false, +// func(resp *types.QueryStakingsResponse) { +// suite.Require().Len(resp.Stakings, 2) +// for _, staking := range resp.Stakings { +// suite.Require().True(staking.StakedCoins.Add(staking.QueuedCoins...).AmountOf(denom1).IsPositive()) +// } +// }, +// }, +// { +// "invalid staking coin denom", +// &types.QueryStakingsRequest{Farmer: "!!!"}, +// true, +// nil, +// }, +// { +// "query by farmer addr and staking coin denom", +// &types.QueryStakingsRequest{ +// Farmer: suite.addrs[0].String(), +// StakingCoinDenom: denom1, +// }, +// false, +// func(resp *types.QueryStakingsResponse) { +// suite.Require().Len(resp.Stakings, 1) +// suite.Require().Equal(suite.addrs[0], resp.Stakings[0].GetFarmer()) +// suite.Require().True( +// resp.Stakings[0].StakedCoins.Add(resp.Stakings[0].QueuedCoins...).AmountOf(denom1).IsPositive()) +// }, +// }, +// } { +// suite.Run(tc.name, func() { +// resp, err := suite.querier.Stakings(sdk.WrapSDKContext(suite.ctx), tc.req) +// if tc.expectErr { +// suite.Require().Error(err) +// } else { +// suite.Require().NoError(err) +// tc.postRun(resp) +// } +// }) +// } +//} +// +//func (suite *KeeperTestSuite) TestGRPCStaking() { +// suite.Stake(suite.addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom1, 1000), sdk.NewInt64Coin(denom2, 1500))) +// suite.Stake(suite.addrs[1], sdk.NewCoins(sdk.NewInt64Coin(denom1, 500))) +// suite.Stake(suite.addrs[2], sdk.NewCoins(sdk.NewInt64Coin(denom2, 800))) +// suite.keeper.ProcessQueuedCoins(suite.ctx) +// +// for _, tc := range []struct { +// name string +// req *types.QueryStakingRequest +// expectErr bool +// postRun func(*types.QueryStakingResponse) +// }{ +// { +// "nil request", +// nil, +// true, +// nil, +// }, +// { +// "query by id", +// &types.QueryStakingRequest{StakingId: 1}, +// false, +// func(resp *types.QueryStakingResponse) { +// suite.Require().Equal(uint64(1), resp.Staking.Id) +// }, +// }, +// { +// "id not found", +// &types.QueryStakingRequest{StakingId: 10}, +// true, +// nil, +// }, +// } { +// suite.Run(tc.name, func() { +// resp, err := suite.querier.Staking(sdk.WrapSDKContext(suite.ctx), tc.req) +// if tc.expectErr { +// suite.Require().Error(err) +// } else { +// suite.Require().NoError(err) +// tc.postRun(resp) +// } +// }) +// } +//} diff --git a/x/farming/keeper/invariants.go b/x/farming/keeper/invariants.go index c77ae1a8..d57017d6 100644 --- a/x/farming/keeper/invariants.go +++ b/x/farming/keeper/invariants.go @@ -2,64 +2,63 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/tendermint/farming/x/farming/types" ) // RegisterInvariants registers all farming invariants. func RegisterInvariants(ir sdk.InvariantRegistry, k Keeper) { - ir.RegisterRoute(types.ModuleName, "staking-reserved", - StakingReservedAmountInvariant(k)) - ir.RegisterRoute(types.ModuleName, "remaining-rewards", - RemainingRewardsAmountInvariant(k)) + //ir.RegisterRoute(types.ModuleName, "staking-reserved", + // StakingReservedAmountInvariant(k)) + //ir.RegisterRoute(types.ModuleName, "remaining-rewards", + // RemainingRewardsAmountInvariant(k)) } // AllInvariants runs all invariants of the farming module. func AllInvariants(k Keeper) sdk.Invariant { return func(ctx sdk.Context) (string, bool) { - res, stop := StakingReservedAmountInvariant(k)(ctx) - if stop { - return res, stop - } - return RemainingRewardsAmountInvariant(k)(ctx) + //res, stop := StakingReservedAmountInvariant(k)(ctx) + //if stop { + // return res, stop + //} + return "", false + //return RemainingRewardsAmountInvariant(k)(ctx) } } -// StakingReservedAmountInvariant checks that the balance of StakingReserveAcc greater than the amount of staked, Queued coins in all staking objects. -func StakingReservedAmountInvariant(k Keeper) sdk.Invariant { - return func(ctx sdk.Context) (string, bool) { - var totalStakingAmt sdk.Coins - balanceStakingReserveAcc := k.bankKeeper.GetAllBalances(ctx, types.StakingReserveAcc) - - k.IterateAllStakings(ctx, func(staking types.Staking) (stop bool) { - totalStakingAmt = totalStakingAmt.Add(staking.StakedCoins...).Add(staking.QueuedCoins...) - return false - }) - - broken := !balanceStakingReserveAcc.IsAllGTE(totalStakingAmt) - return sdk.FormatInvariant(types.ModuleName, "staking reserved amount invariant broken", - "the balance of StakingReserveAcc less than the amount of staked, Queued coins in all staking objects"), broken - } -} +//// StakingReservedAmountInvariant checks that the balance of StakingReserveAcc greater than the amount of staked, Queued coins in all staking objects. +//func StakingReservedAmountInvariant(k Keeper) sdk.Invariant { +// return func(ctx sdk.Context) (string, bool) { +// var totalStakingAmt sdk.Coins +// balanceStakingReserveAcc := k.bankKeeper.GetAllBalances(ctx, types.StakingReserveAcc) +// +// k.IterateAllStakings(ctx, func(staking types.Staking) (stop bool) { +// totalStakingAmt = totalStakingAmt.Add(staking.StakedCoins...).Add(staking.QueuedCoins...) +// return false +// }) +// +// broken := !balanceStakingReserveAcc.IsAllGTE(totalStakingAmt) +// return sdk.FormatInvariant(types.ModuleName, "staking reserved amount invariant broken", +// "the balance of StakingReserveAcc less than the amount of staked, Queued coins in all staking objects"), broken +// } +//} // RemainingRewardsAmountInvariant checks that the balance of the RewardPoolAddresses of all plans greater than the total amount of unwithdrawn reward coins in all reward objects -func RemainingRewardsAmountInvariant(k Keeper) sdk.Invariant { - return func(ctx sdk.Context) (string, bool) { - var totalRemainingRewards sdk.Coins - //var totalBalancesRewardPools sdk.Coins - //k.IterateAllPlans(ctx, func(plan types.PlanI) (stop bool) { - // totalBalancesRewardPools = totalBalancesRewardPools.Add(k.bankKeeper.GetAllBalances(ctx, plan.GetRewardPoolAddress())...) - // return false - //}) - totalBalancesRewardPool := k.bankKeeper.GetAllBalances(ctx, k.GetRewardsReservePoolAcc(ctx)) - k.IterateAllRewards(ctx, func(reward types.Reward) (stop bool) { - totalRemainingRewards = totalRemainingRewards.Add(reward.RewardCoins...) - return false - }) - - //broken := !totalBalancesRewardPools.IsAllGTE(totalRemainingRewards) - broken := !totalBalancesRewardPool.IsAllGTE(totalRemainingRewards) - return sdk.FormatInvariant(types.ModuleName, "remaining rewards amount invariant broken", - "the balance of the RewardPoolAddresses of all plans less than the total amount of unwithdrawn reward coins in all reward objects"), broken - } -} +//func RemainingRewardsAmountInvariant(k Keeper) sdk.Invariant { +// return func(ctx sdk.Context) (string, bool) { +// var totalRemainingRewards sdk.Coins +// //var totalBalancesRewardPools sdk.Coins +// //k.IterateAllPlans(ctx, func(plan types.PlanI) (stop bool) { +// // totalBalancesRewardPools = totalBalancesRewardPools.Add(k.bankKeeper.GetAllBalances(ctx, plan.GetRewardPoolAddress())...) +// // return false +// //}) +// totalBalancesRewardPool := k.bankKeeper.GetAllBalances(ctx, k.GetRewardsReservePoolAcc(ctx)) +// k.IterateAllRewards(ctx, func(reward types.Reward) (stop bool) { +// totalRemainingRewards = totalRemainingRewards.Add(reward.RewardCoins...) +// return false +// }) +// +// //broken := !totalBalancesRewardPools.IsAllGTE(totalRemainingRewards) +// broken := !totalBalancesRewardPool.IsAllGTE(totalRemainingRewards) +// return sdk.FormatInvariant(types.ModuleName, "remaining rewards amount invariant broken", +// "the balance of the RewardPoolAddresses of all plans less than the total amount of unwithdrawn reward coins in all reward objects"), broken +// } +//} diff --git a/x/farming/keeper/invariants_test.go b/x/farming/keeper/invariants_test.go index c39f6dfc..68728f67 100644 --- a/x/farming/keeper/invariants_test.go +++ b/x/farming/keeper/invariants_test.go @@ -1,102 +1,95 @@ package keeper_test -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/tendermint/farming/x/farming/keeper" - "github.com/tendermint/farming/x/farming/types" -) - -func (suite *KeeperTestSuite) TestStakingReservedAmountInvariant() { - plans := []types.PlanI{ - types.NewFixedAmountPlan( - types.NewBasePlan( - 1, - "", - types.PlanTypePrivate, - suite.addrs[0].String(), - suite.addrs[0].String(), - sdk.NewDecCoins( - sdk.NewDecCoinFromDec(denom1, sdk.NewDecWithPrec(3, 1)), - sdk.NewDecCoinFromDec(denom2, sdk.NewDecWithPrec(7, 1))), - mustParseRFC3339("2021-07-30T00:00:00Z"), - mustParseRFC3339("2021-08-30T00:00:00Z"), - ), - sdk.NewCoins(sdk.NewInt64Coin(denom3, 1_000_000))), - } - for _, plan := range plans { - suite.keeper.SetPlan(suite.ctx, plan) - } - - suite.Stake(suite.addrs[1], sdk.NewCoins( - sdk.NewInt64Coin(denom1, 1_000_000), - sdk.NewInt64Coin(denom2, 1_000_000))) - - // invariants was not broken - keeper.AllInvariants(suite.keeper) - invariant := keeper.AllInvariants(suite.keeper) - _, broken := invariant(suite.ctx) - suite.False(broken) - - // manipulate staking reserved amount - stakings := suite.keeper.GetAllStakings(suite.ctx) - stakings[0].QueuedCoins = stakings[0].QueuedCoins.Add(sdk.NewInt64Coin(denom1, 1)) - suite.keeper.SetStaking(suite.ctx, stakings[0]) - - // invariants was broken - keeper.AllInvariants(suite.keeper) - invariant = keeper.AllInvariants(suite.keeper) - _, broken = invariant(suite.ctx) - suite.True(broken) -} - -func (suite *KeeperTestSuite) TestRemainingRewardsAmountInvariant() { - plans := []types.PlanI{ - types.NewFixedAmountPlan( - types.NewBasePlan( - 1, - "", - types.PlanTypePrivate, - suite.addrs[0].String(), - suite.addrs[0].String(), - sdk.NewDecCoins( - sdk.NewDecCoinFromDec(denom1, sdk.NewDecWithPrec(3, 1)), - sdk.NewDecCoinFromDec(denom2, sdk.NewDecWithPrec(7, 1))), - mustParseRFC3339("2021-07-30T00:00:00Z"), - mustParseRFC3339("2021-08-30T00:00:00Z"), - ), - sdk.NewCoins(sdk.NewInt64Coin(denom3, 1_000_000))), - } - for _, plan := range plans { - suite.keeper.SetPlan(suite.ctx, plan) - } - - suite.Stake(suite.addrs[1], sdk.NewCoins( - sdk.NewInt64Coin(denom1, 1_000_000), - sdk.NewInt64Coin(denom2, 1_000_000))) - - suite.keeper.ProcessQueuedCoins(suite.ctx) - - suite.ctx = suite.ctx.WithBlockTime(mustParseRFC3339("2021-07-31T00:00:00Z")) - err := suite.keeper.DistributeRewards(suite.ctx) - suite.Require().NoError(err) - - rewards := suite.keeper.GetRewardsByFarmer(suite.ctx, suite.addrs[1]) - suite.Require().Len(rewards, 2) - - // invariants was not broken - keeper.AllInvariants(suite.keeper) - invariant := keeper.AllInvariants(suite.keeper) - _, broken := invariant(suite.ctx) - suite.False(broken) - - // manipulate reward coins - rewards[0].RewardCoins = rewards[0].RewardCoins.Add(sdk.NewInt64Coin(denom3, 1)) - suite.keeper.SetReward(suite.ctx, rewards[0].StakingCoinDenom, suite.addrs[1], rewards[0].RewardCoins) - - // invariants was broken - keeper.AllInvariants(suite.keeper) - invariant = keeper.AllInvariants(suite.keeper) - _, broken = invariant(suite.ctx) - suite.True(broken) -} +//func (suite *KeeperTestSuite) TestStakingReservedAmountInvariant() { +// plans := []types.PlanI{ +// types.NewFixedAmountPlan( +// types.NewBasePlan( +// 1, +// "", +// types.PlanTypePrivate, +// suite.addrs[0].String(), +// suite.addrs[0].String(), +// sdk.NewDecCoins( +// sdk.NewDecCoinFromDec(denom1, sdk.NewDecWithPrec(3, 1)), +// sdk.NewDecCoinFromDec(denom2, sdk.NewDecWithPrec(7, 1))), +// mustParseRFC3339("2021-07-30T00:00:00Z"), +// mustParseRFC3339("2021-08-30T00:00:00Z"), +// ), +// sdk.NewCoins(sdk.NewInt64Coin(denom3, 1_000_000))), +// } +// for _, plan := range plans { +// suite.keeper.SetPlan(suite.ctx, plan) +// } +// +// suite.Stake(suite.addrs[1], sdk.NewCoins( +// sdk.NewInt64Coin(denom1, 1_000_000), +// sdk.NewInt64Coin(denom2, 1_000_000))) +// +// // invariants was not broken +// keeper.AllInvariants(suite.keeper) +// invariant := keeper.AllInvariants(suite.keeper) +// _, broken := invariant(suite.ctx) +// suite.False(broken) +// +// // manipulate staking reserved amount +// stakings := suite.keeper.GetAllStakings(suite.ctx) +// stakings[0].QueuedCoins = stakings[0].QueuedCoins.Add(sdk.NewInt64Coin(denom1, 1)) +// suite.keeper.SetStaking(suite.ctx, stakings[0]) +// +// // invariants was broken +// keeper.AllInvariants(suite.keeper) +// invariant = keeper.AllInvariants(suite.keeper) +// _, broken = invariant(suite.ctx) +// suite.True(broken) +//} +// +//func (suite *KeeperTestSuite) TestRemainingRewardsAmountInvariant() { +// plans := []types.PlanI{ +// types.NewFixedAmountPlan( +// types.NewBasePlan( +// 1, +// "", +// types.PlanTypePrivate, +// suite.addrs[0].String(), +// suite.addrs[0].String(), +// sdk.NewDecCoins( +// sdk.NewDecCoinFromDec(denom1, sdk.NewDecWithPrec(3, 1)), +// sdk.NewDecCoinFromDec(denom2, sdk.NewDecWithPrec(7, 1))), +// mustParseRFC3339("2021-07-30T00:00:00Z"), +// mustParseRFC3339("2021-08-30T00:00:00Z"), +// ), +// sdk.NewCoins(sdk.NewInt64Coin(denom3, 1_000_000))), +// } +// for _, plan := range plans { +// suite.keeper.SetPlan(suite.ctx, plan) +// } +// +// suite.Stake(suite.addrs[1], sdk.NewCoins( +// sdk.NewInt64Coin(denom1, 1_000_000), +// sdk.NewInt64Coin(denom2, 1_000_000))) +// +// suite.keeper.ProcessQueuedCoins(suite.ctx) +// +// suite.ctx = suite.ctx.WithBlockTime(mustParseRFC3339("2021-07-31T00:00:00Z")) +// err := suite.keeper.AllocateRewards(suite.ctx) +// suite.Require().NoError(err) +// +// rewards := suite.keeper.GetRewardsByFarmer(suite.ctx, suite.addrs[1]) +// suite.Require().Len(rewards, 2) +// +// // invariants was not broken +// keeper.AllInvariants(suite.keeper) +// invariant := keeper.AllInvariants(suite.keeper) +// _, broken := invariant(suite.ctx) +// suite.False(broken) +// +// // manipulate reward coins +// rewards[0].RewardCoins = rewards[0].RewardCoins.Add(sdk.NewInt64Coin(denom3, 1)) +// suite.keeper.SetReward(suite.ctx, rewards[0].StakingCoinDenom, suite.addrs[1], rewards[0].RewardCoins) +// +// // invariants was broken +// keeper.AllInvariants(suite.keeper) +// invariant = keeper.AllInvariants(suite.keeper) +// _, broken = invariant(suite.ctx) +// suite.True(broken) +//} diff --git a/x/farming/keeper/keeper.go b/x/farming/keeper/keeper.go index dc034b3c..078ae0a0 100644 --- a/x/farming/keeper/keeper.go +++ b/x/farming/keeper/keeper.go @@ -7,7 +7,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/tendermint/farming/x/farming/types" @@ -21,7 +20,6 @@ type Keeper struct { bankKeeper types.BankKeeper accountKeeper types.AccountKeeper - distrKeeper types.DistributionKeeper blockedAddrs map[string]bool } @@ -31,7 +29,7 @@ type Keeper struct { // - sending to and from ModuleAccounts // - minting, burning PoolCoins func NewKeeper(cdc codec.BinaryCodec, key sdk.StoreKey, paramSpace paramtypes.Subspace, - accountKeeper types.AccountKeeper, bankKeeper types.BankKeeper, distrKeeper types.DistributionKeeper, + accountKeeper types.AccountKeeper, bankKeeper types.BankKeeper, blockedAddrs map[string]bool, ) Keeper { // ensure farming module account is set @@ -50,7 +48,6 @@ func NewKeeper(cdc codec.BinaryCodec, key sdk.StoreKey, paramSpace paramtypes.Su paramSpace: paramSpace, accountKeeper: accountKeeper, bankKeeper: bankKeeper, - distrKeeper: distrKeeper, blockedAddrs: blockedAddrs, } } @@ -74,11 +71,6 @@ func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { // GetCodec return codec.Codec object used by the keeper func (k Keeper) GetCodec() codec.BinaryCodec { return k.cdc } -// GetStakingCreationFeePool returns module account for collecting Staking Creation Fee -func (k Keeper) GetStakingCreationFeePool(ctx sdk.Context) authtypes.ModuleAccountI { // nolint:interfacer - return k.accountKeeper.GetModuleAccount(ctx, types.ModuleName) -} - // GetStakingReservePoolAcc returns module account for Staking Reserve Pool account func (k Keeper) GetStakingReservePoolAcc(ctx sdk.Context) sdk.AccAddress { // nolint:interfacer return types.StakingReserveAcc diff --git a/x/farming/keeper/keeper_test.go b/x/farming/keeper/keeper_test.go index 1b346c7c..23d8b989 100644 --- a/x/farming/keeper/keeper_test.go +++ b/x/farming/keeper/keeper_test.go @@ -128,11 +128,9 @@ func (suite *KeeperTestSuite) SetupTest() { } // Stake is a convenient method to test Keeper.Stake. -func (suite *KeeperTestSuite) Stake(farmer sdk.AccAddress, amt sdk.Coins) types.Staking { - staking, err := suite.keeper.Stake(suite.ctx, farmer, amt) +func (suite *KeeperTestSuite) Stake(farmer sdk.AccAddress, amt sdk.Coins) { + err := suite.keeper.Stake(suite.ctx, farmer, amt) suite.Require().NoError(err) - - return staking } func intEq(exp, got sdk.Int) (bool, string, string, string) { diff --git a/x/farming/keeper/msg_server.go b/x/farming/keeper/msg_server.go index e851a896..ba5e57ba 100644 --- a/x/farming/keeper/msg_server.go +++ b/x/farming/keeper/msg_server.go @@ -57,7 +57,7 @@ func (k msgServer) CreateRatioPlan(goCtx context.Context, msg *types.MsgCreateRa func (k msgServer) Stake(goCtx context.Context, msg *types.MsgStake) (*types.MsgStakeResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - if _, err := k.Keeper.Stake(ctx, msg.GetFarmer(), msg.StakingCoins); err != nil { + if err := k.Keeper.Stake(ctx, msg.GetFarmer(), msg.StakingCoins); err != nil { return nil, err } @@ -68,7 +68,7 @@ func (k msgServer) Stake(goCtx context.Context, msg *types.MsgStake) (*types.Msg func (k msgServer) Unstake(goCtx context.Context, msg *types.MsgUnstake) (*types.MsgUnstakeResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - if _, err := k.Keeper.Unstake(ctx, msg.GetFarmer(), msg.UnstakingCoins); err != nil { + if err := k.Keeper.Unstake(ctx, msg.GetFarmer(), msg.UnstakingCoins); err != nil { return nil, err } diff --git a/x/farming/keeper/plan_test.go b/x/farming/keeper/plan_test.go index 8dd3ed59..583c9e6e 100644 --- a/x/farming/keeper/plan_test.go +++ b/x/farming/keeper/plan_test.go @@ -1,54 +1,49 @@ package keeper_test import ( - "time" - - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/tendermint/farming/app" "github.com/tendermint/farming/x/farming/types" ) -func (suite *KeeperTestSuite) TestGetSetNewPlan() { - name := "" - farmingPoolAddr := sdk.AccAddress("farmingPoolAddr") - terminationAddr := sdk.AccAddress("terminationAddr") - - stakingCoins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1000000))) - coinWeights := sdk.NewDecCoins( - sdk.DecCoin{Denom: "testFarmStakingCoinDenom", Amount: sdk.MustNewDecFromStr("1.0")}, - ) - - addrs := app.AddTestAddrs(suite.app, suite.ctx, 2, sdk.NewInt(2000000)) - farmerAddr := addrs[0] - - startTime := time.Now().UTC() - endTime := startTime.AddDate(1, 0, 0) - basePlan := types.NewBasePlan(1, name, 1, farmingPoolAddr.String(), terminationAddr.String(), coinWeights, startTime, endTime) - fixedPlan := types.NewFixedAmountPlan(basePlan, sdk.NewCoins(sdk.NewCoin("testFarmCoinDenom", sdk.NewInt(1000000)))) - suite.keeper.SetPlan(suite.ctx, fixedPlan) - - planGet, found := suite.keeper.GetPlan(suite.ctx, 1) - suite.Require().True(found) - suite.Require().Equal(fixedPlan.Id, planGet.GetId()) - suite.Require().Equal(fixedPlan.FarmingPoolAddress, planGet.GetFarmingPoolAddress().String()) - - plans := suite.keeper.GetAllPlans(suite.ctx) - suite.Require().Len(plans, 1) - suite.Require().Equal(fixedPlan.Id, plans[0].GetId()) - suite.Require().Equal(fixedPlan.FarmingPoolAddress, plans[0].GetFarmingPoolAddress().String()) - - _, err := suite.keeper.Stake(suite.ctx, farmerAddr, stakingCoins) - suite.Require().NoError(err) - - stakings := suite.keeper.GetAllStakings(suite.ctx) - stakingByFarmer, found := suite.keeper.GetStakingByFarmer(suite.ctx, farmerAddr) - stakingsByDenom := suite.keeper.GetStakingsByStakingCoinDenom(suite.ctx, sdk.DefaultBondDenom) - - suite.Require().True(found) - suite.Require().Equal(stakings[0], stakingByFarmer) - suite.Require().Equal(stakings, stakingsByDenom) -} +//func (suite *KeeperTestSuite) TestGetSetNewPlan() { +// name := "" +// farmingPoolAddr := sdk.AccAddress("farmingPoolAddr") +// terminationAddr := sdk.AccAddress("terminationAddr") +// +// stakingCoins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1000000))) +// coinWeights := sdk.NewDecCoins( +// sdk.DecCoin{Denom: "testFarmStakingCoinDenom", Amount: sdk.MustNewDecFromStr("1.0")}, +// ) +// +// addrs := app.AddTestAddrs(suite.app, suite.ctx, 2, sdk.NewInt(2000000)) +// farmerAddr := addrs[0] +// +// startTime := time.Now().UTC() +// endTime := startTime.AddDate(1, 0, 0) +// basePlan := types.NewBasePlan(1, name, 1, farmingPoolAddr.String(), terminationAddr.String(), coinWeights, startTime, endTime) +// fixedPlan := types.NewFixedAmountPlan(basePlan, sdk.NewCoins(sdk.NewCoin("testFarmCoinDenom", sdk.NewInt(1000000)))) +// suite.keeper.SetPlan(suite.ctx, fixedPlan) +// +// planGet, found := suite.keeper.GetPlan(suite.ctx, 1) +// suite.Require().True(found) +// suite.Require().Equal(fixedPlan.Id, planGet.GetId()) +// suite.Require().Equal(fixedPlan.FarmingPoolAddress, planGet.GetFarmingPoolAddress().String()) +// +// plans := suite.keeper.GetAllPlans(suite.ctx) +// suite.Require().Len(plans, 1) +// suite.Require().Equal(fixedPlan.Id, plans[0].GetId()) +// suite.Require().Equal(fixedPlan.FarmingPoolAddress, plans[0].GetFarmingPoolAddress().String()) +// +// _, err := suite.keeper.Stake(suite.ctx, farmerAddr, stakingCoins) +// suite.Require().NoError(err) +// +// stakings := suite.keeper.GetAllStakings(suite.ctx) +// stakingByFarmer, found := suite.keeper.GetStakingByFarmer(suite.ctx, farmerAddr) +// stakingsByDenom := suite.keeper.GetStakingsByStakingCoinDenom(suite.ctx, sdk.DefaultBondDenom) +// +// suite.Require().True(found) +// suite.Require().Equal(stakings[0], stakingByFarmer) +// suite.Require().Equal(stakings, stakingsByDenom) +//} func (suite *KeeperTestSuite) TestGlobalPlanId() { globalPlanId := suite.keeper.GetGlobalPlanId(suite.ctx) diff --git a/x/farming/keeper/reward.go b/x/farming/keeper/reward.go index 34b077b2..148e5420 100644 --- a/x/farming/keeper/reward.go +++ b/x/farming/keeper/reward.go @@ -1,176 +1,117 @@ package keeper import ( + "fmt" "strconv" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/tendermint/farming/x/farming/types" ) -// GetReward returns a specific reward. -func (k Keeper) GetReward(ctx sdk.Context, stakingCoinDenom string, farmerAcc sdk.AccAddress) (reward types.Reward, found bool) { +func (k Keeper) GetHistoricalRewards(ctx sdk.Context, stakingCoinDenom string, epoch uint64) (rewards types.HistoricalRewards) { store := ctx.KVStore(k.storeKey) - bz := store.Get(types.GetRewardKey(stakingCoinDenom, farmerAcc)) - if bz == nil { - return reward, false - } - var rewardCoins types.RewardCoins - k.cdc.MustUnmarshal(bz, &rewardCoins) - return types.Reward{ - Farmer: farmerAcc.String(), - StakingCoinDenom: stakingCoinDenom, - RewardCoins: rewardCoins.RewardCoins, - }, true -} - -// GetRewardsByFarmer reads from kvstore and return a specific Reward indexed by given farmer's address -func (k Keeper) GetRewardsByFarmer(ctx sdk.Context, farmerAcc sdk.AccAddress) (rewards []types.Reward) { - k.IterateRewardsByFarmer(ctx, farmerAcc, func(reward types.Reward) bool { - rewards = append(rewards, reward) - return false - }) - - return rewards -} - -// GetAllRewards returns all rewards in the Keeper. -func (k Keeper) GetAllRewards(ctx sdk.Context) (rewards []types.Reward) { - k.IterateAllRewards(ctx, func(reward types.Reward) (stop bool) { - rewards = append(rewards, reward) - return false - }) - - return rewards -} - -// GetRewardsByStakingCoinDenom reads from kvstore and return a specific Reward indexed by given staking coin denom -func (k Keeper) GetRewardsByStakingCoinDenom(ctx sdk.Context, denom string) (rewards []types.Reward) { - k.IterateRewardsByStakingCoinDenom(ctx, denom, func(reward types.Reward) bool { - rewards = append(rewards, reward) - return false - }) - - return rewards + bz := store.Get(types.GetHistoricalRewardsKey(stakingCoinDenom, epoch)) + k.cdc.MustUnmarshal(bz, &rewards) + return } -// SetReward implements Reward. -func (k Keeper) SetReward(ctx sdk.Context, stakingCoinDenom string, farmerAcc sdk.AccAddress, rewardCoins sdk.Coins) { +func (k Keeper) SetHistoricalRewards(ctx sdk.Context, stakingCoinDenom string, epoch uint64, rewards types.HistoricalRewards) { store := ctx.KVStore(k.storeKey) - bz := k.cdc.MustMarshal(&types.RewardCoins{RewardCoins: rewardCoins}) - store.Set(types.GetRewardKey(stakingCoinDenom, farmerAcc), bz) - store.Set(types.GetRewardByFarmerAndStakingCoinDenomIndexKey(farmerAcc, stakingCoinDenom), []byte{}) + bz := k.cdc.MustMarshal(&rewards) + store.Set(types.GetHistoricalRewardsKey(stakingCoinDenom, epoch), bz) } -// DeleteReward deletes a reward for the reward mapper store. -func (k Keeper) DeleteReward(ctx sdk.Context, stakingCoinDenom string, farmerAcc sdk.AccAddress) { +func (k Keeper) DeleteHistoricalRewards(ctx sdk.Context, stakingCoinDenom string, epoch uint64) { store := ctx.KVStore(k.storeKey) - store.Delete(types.GetRewardKey(stakingCoinDenom, farmerAcc)) - store.Delete(types.GetRewardByFarmerAndStakingCoinDenomIndexKey(farmerAcc, stakingCoinDenom)) + store.Delete(types.GetHistoricalRewardsKey(stakingCoinDenom, epoch)) } -// IterateAllRewards iterates over all the stored rewards and performs a callback function. -// Stops iteration when callback returns true. -func (k Keeper) IterateAllRewards(ctx sdk.Context, cb func(reward types.Reward) (stop bool)) { +func (k Keeper) GetCurrentRewards(ctx sdk.Context, stakingCoinDenom string) (rewards types.CurrentRewards) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, types.RewardKeyPrefix) - - defer iterator.Close() - for ; iterator.Valid(); iterator.Next() { - stakingCoinDenom, farmerAcc := types.ParseRewardKey(iterator.Key()) - var rewardCoins types.RewardCoins - k.cdc.MustUnmarshal(iterator.Value(), &rewardCoins) - if cb(types.Reward{Farmer: farmerAcc.String(), StakingCoinDenom: stakingCoinDenom, RewardCoins: rewardCoins.RewardCoins}) { - break - } - } + bz := store.Get(types.GetCurrentRewardsKey(stakingCoinDenom)) + k.cdc.MustUnmarshal(bz, &rewards) + return } -// IterateRewardsByStakingCoinDenom iterates over all the stored rewards indexed by given staking coin denom and performs a callback function. -// Stops iteration when callback returns true. -func (k Keeper) IterateRewardsByStakingCoinDenom(ctx sdk.Context, stakingCoinDenom string, cb func(reward types.Reward) (stop bool)) { +func (k Keeper) SetCurrentRewards(ctx sdk.Context, stakingCoinDenom string, rewards types.CurrentRewards) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, types.GetRewardsByStakingCoinDenomKey(stakingCoinDenom)) - - defer iterator.Close() - for ; iterator.Valid(); iterator.Next() { - _, farmerAcc := types.ParseRewardKey(iterator.Key()) - var rewardCoins types.RewardCoins - k.cdc.MustUnmarshal(iterator.Value(), &rewardCoins) - if cb(types.Reward{Farmer: farmerAcc.String(), StakingCoinDenom: stakingCoinDenom, RewardCoins: rewardCoins.RewardCoins}) { - break - } - } + bz := k.cdc.MustMarshal(&rewards) + store.Set(types.GetCurrentRewardsKey(stakingCoinDenom), bz) } -// IterateRewardsByFarmer iterates over all the stored rewards indexed by given farmer's address and performs a callback function. -// Stops iteration when callback returns true. -func (k Keeper) IterateRewardsByFarmer(ctx sdk.Context, farmerAcc sdk.AccAddress, cb func(reward types.Reward) (stop bool)) { - store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, types.GetRewardsByFarmerIndexKey(farmerAcc)) - - defer iterator.Close() - for ; iterator.Valid(); iterator.Next() { - _, stakingCoinDenom := types.ParseRewardsByFarmerIndexKey(iterator.Key()) - reward, _ := k.GetReward(ctx, stakingCoinDenom, farmerAcc) - if cb(reward) { - break - } +func (k Keeper) CalculateRewards(ctx sdk.Context, farmerAcc sdk.AccAddress, stakingCoinDenom string, endingEpoch uint64) (rewards sdk.Coins) { + staking, found := k.GetStaking(ctx, stakingCoinDenom, farmerAcc) + if !found { + staking.Amount = sdk.ZeroInt() } -} -// UnmarshalRewardCoins unmarshals a RewardCoins from bytes. -func (k Keeper) UnmarshalRewardCoins(bz []byte) (rewardCoins types.RewardCoins, err error) { - return rewardCoins, k.cdc.Unmarshal(bz, &rewardCoins) + starting := k.GetHistoricalRewards(ctx, stakingCoinDenom, staking.StartingEpoch-1) + ending := k.GetHistoricalRewards(ctx, stakingCoinDenom, endingEpoch) + diff := ending.CumulativeUnitRewards.Sub(starting.CumulativeUnitRewards) + rewards, _ = diff.MulDecTruncate(staking.Amount.ToDec()).TruncateDecimal() + return } -// Harvest claims farming rewards from the reward pool. -func (k Keeper) Harvest(ctx sdk.Context, farmerAcc sdk.AccAddress, stakingCoinDenoms []string) error { - amount := sdk.NewCoins() - for _, denom := range stakingCoinDenoms { - reward, found := k.GetReward(ctx, denom, farmerAcc) - if !found { - return sdkerrors.Wrapf(types.ErrRewardNotExists, "no reward for staking coin denom %s", denom) - } - amount = amount.Add(reward.RewardCoins...) - } +func (k Keeper) WithdrawRewards(ctx sdk.Context, farmerAcc sdk.AccAddress, stakingCoinDenom string) (sdk.Coins, error) { + fmt.Printf("WithdrawRewards(%s, %s)\n", farmerAcc, stakingCoinDenom) - if err := k.bankKeeper.SendCoins(ctx, k.GetRewardsReservePoolAcc(ctx), farmerAcc, amount); err != nil { - return err + staking, found := k.GetStaking(ctx, stakingCoinDenom, farmerAcc) + if !found { + return nil, fmt.Errorf("empty starting info") // TODO: use correct error } - for _, denom := range stakingCoinDenoms { - k.DeleteReward(ctx, denom, farmerAcc) - } + current := k.GetCurrentRewards(ctx, stakingCoinDenom) + rewards := k.CalculateRewards(ctx, farmerAcc, stakingCoinDenom, current.Epoch-1) + fmt.Printf(" GetCurrentRewards(%s) := %+v\n", stakingCoinDenom, current) + fmt.Printf(" CalculateRewards(%s, %s, %d) := %+v\n", farmerAcc, stakingCoinDenom, current.Epoch-1, rewards) - staking, found := k.GetStakingByFarmer(ctx, farmerAcc) - if !found { // NOTE: this should never happen - return sdkerrors.Wrap(types.ErrStakingNotExists, "no staking found") - } - if staking.StakedCoins.IsZero() && staking.QueuedCoins.IsZero() && len(k.GetRewardsByFarmer(ctx, farmerAcc)) == 0 { - k.DeleteStaking(ctx, staking) + if !rewards.IsZero() { + fmt.Printf(" sending %s to %s\n", rewards, farmerAcc) } - ctx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - types.EventTypeHarvest, - sdk.NewAttribute(types.AttributeKeyFarmer, farmerAcc.String()), - sdk.NewAttribute(types.AttributeKeyRewardCoins, amount.String()), - ), - }) + staking.StartingEpoch = current.Epoch + k.SetStaking(ctx, stakingCoinDenom, farmerAcc, staking) + + return rewards, nil +} +// Harvest claims farming rewards from the reward pool. +func (k Keeper) Harvest(ctx sdk.Context, farmerAcc sdk.AccAddress, stakingCoinDenoms []string) error { + //for _, denom := range stakingCoinDenoms { + //} + // + //if err := k.bankKeeper.SendCoins(ctx, k.GetRewardsReservePoolAcc(ctx), farmerAcc, amount); err != nil { + // return err + //} + // + //staking, found := k.GetStakingByFarmer(ctx, farmerAcc) + //if !found { // NOTE: this should never happen + // return sdkerrors.Wrap(types.ErrStakingNotExists, "no staking found") + //} + //if staking.StakedCoins.IsZero() && staking.QueuedCoins.IsZero() && len(k.GetRewardsByFarmer(ctx, farmerAcc)) == 0 { + // k.DeleteStaking(ctx, staking) + //} + // + //ctx.EventManager().EmitEvents(sdk.Events{ + // sdk.NewEvent( + // types.EventTypeHarvest, + // sdk.NewAttribute(types.AttributeKeyFarmer, farmerAcc.String()), + // sdk.NewAttribute(types.AttributeKeyRewardCoins, amount.String()), + // ), + //}) + // return nil } -type DistributionInfo struct { +type AllocationInfo struct { Plan types.PlanI Amount sdk.Coins } -func (k Keeper) DistributionInfos(ctx sdk.Context) []DistributionInfo { +func (k Keeper) AllocationInfos(ctx sdk.Context) []AllocationInfo { farmingPoolBalances := make(map[string]sdk.Coins) // farmingPoolAddress => sdk.Coins - distrCoins := make(map[string]map[uint64]sdk.Coins) // farmingPoolAddress => (planId => sdk.Coins) + allocCoins := make(map[string]map[uint64]sdk.Coins) // farmingPoolAddress => (planId => sdk.Coins) plans := make(map[uint64]types.PlanI) for _, plan := range k.GetAllPlans(ctx) { @@ -190,22 +131,22 @@ func (k Keeper) DistributionInfos(ctx sdk.Context) []DistributionInfo { farmingPoolBalances[farmingPool] = balances } - dc, ok := distrCoins[farmingPool] + ac, ok := allocCoins[farmingPool] if !ok { - dc = make(map[uint64]sdk.Coins) - distrCoins[farmingPool] = dc + ac = make(map[uint64]sdk.Coins) + allocCoins[farmingPool] = ac } switch plan := plan.(type) { case *types.FixedAmountPlan: - dc[plan.GetId()] = plan.EpochAmount + ac[plan.GetId()] = plan.EpochAmount case *types.RatioPlan: - dc[plan.GetId()], _ = sdk.NewDecCoinsFromCoins(balances...).MulDecTruncate(plan.EpochRatio).TruncateDecimal() + ac[plan.GetId()], _ = sdk.NewDecCoinsFromCoins(balances...).MulDecTruncate(plan.EpochRatio).TruncateDecimal() } } - var distrInfos []DistributionInfo - for farmingPool, coins := range distrCoins { + var allocInfos []AllocationInfo + for farmingPool, coins := range allocCoins { totalCoins := sdk.NewCoins() for _, amt := range coins { totalCoins = totalCoins.Add(amt...) @@ -217,82 +158,80 @@ func (k Keeper) DistributionInfos(ctx sdk.Context) []DistributionInfo { } for planID, amt := range coins { - distrInfos = append(distrInfos, DistributionInfo{ + allocInfos = append(allocInfos, AllocationInfo{ Plan: plans[planID], Amount: amt, }) } } - return distrInfos + return allocInfos } -func (k Keeper) DistributeRewards(ctx sdk.Context) error { - stakingsByDenom := make(map[string][]types.Staking) - totalStakedAmtByDenom := make(map[string]sdk.Int) - - for _, distrInfo := range k.DistributionInfos(ctx) { - stakingCoinWeights := distrInfo.Plan.GetStakingCoinWeights() - totalDistrAmt := sdk.NewCoins() - +func (k Keeper) AllocateRewards(ctx sdk.Context) error { + fmt.Printf("AllocateRewards()\n") + for _, allocInfo := range k.AllocationInfos(ctx) { totalWeight := sdk.ZeroDec() - for _, coinWeight := range stakingCoinWeights { - totalWeight = totalWeight.Add(coinWeight.Amount) + for _, weight := range allocInfo.Plan.GetStakingCoinWeights() { + totalWeight = totalWeight.Add(weight.Amount) } - for _, coinWeight := range stakingCoinWeights { - stakings, ok := stakingsByDenom[coinWeight.Denom] - if !ok { - stakings = k.GetStakingsByStakingCoinDenom(ctx, coinWeight.Denom) - stakingsByDenom[coinWeight.Denom] = stakings - - for _, staking := range stakings { - totalStakedAmt, ok := totalStakedAmtByDenom[coinWeight.Denom] - if !ok { - totalStakedAmt = sdk.ZeroInt() - } - totalStakedAmtByDenom[coinWeight.Denom] = totalStakedAmt.Add(staking.StakedCoins.AmountOf(coinWeight.Denom)) - } + totalAllocCoins := sdk.NewDecCoins() + for _, weight := range allocInfo.Plan.GetStakingCoinWeights() { + totalStaking, found := k.GetTotalStaking(ctx, weight.Denom) + if !found { + continue + } + if !totalStaking.Amount.IsPositive() { + continue } - totalStakedAmt := totalStakedAmtByDenom[coinWeight.Denom] + weightProportion := weight.Amount.QuoTruncate(totalWeight) + allocCoins := sdk.NewDecCoinsFromCoins(allocInfo.Amount...).MulDecTruncate(weightProportion) - for _, staking := range stakings { - stakedAmt := staking.StakedCoins.AmountOf(coinWeight.Denom) - if !stakedAmt.IsPositive() { - continue - } + current := k.GetCurrentRewards(ctx, weight.Denom) + historical := k.GetHistoricalRewards(ctx, weight.Denom, current.Epoch-1) + fmt.Printf(" current rewards(before): %+v\n", current) + fmt.Printf(" historical rewards for %d: %+v\n", current.Epoch-1, historical) + k.SetHistoricalRewards(ctx, weight.Denom, current.Epoch, types.HistoricalRewards{ + CumulativeUnitRewards: historical.CumulativeUnitRewards.Add(allocCoins.QuoDecTruncate(totalStaking.Amount.ToDec())...), + }) + k.SetCurrentRewards(ctx, weight.Denom, types.CurrentRewards{ + Epoch: current.Epoch + 1, + }) + fmt.Printf(" current rewards(after): %+v\n", types.CurrentRewards{ + Epoch: current.Epoch + 1, + }) + fmt.Printf(" historical rewards for %d: %+v\n", current.Epoch, types.HistoricalRewards{ + CumulativeUnitRewards: historical.CumulativeUnitRewards.Add(allocCoins.QuoDecTruncate(totalStaking.Amount.ToDec())...), + }) - stakedProportion := stakedAmt.ToDec().QuoTruncate(totalStakedAmt.ToDec()) - weightProportion := coinWeight.Amount.QuoTruncate(totalWeight) - distrAmt, _ := sdk.NewDecCoinsFromCoins(distrInfo.Amount...).MulDecTruncate(stakedProportion.MulTruncate(weightProportion)).TruncateDecimal() + totalAllocCoins = totalAllocCoins.Add(allocCoins...) + } - reward, _ := k.GetReward(ctx, coinWeight.Denom, staking.GetFarmer()) - reward.RewardCoins = reward.RewardCoins.Add(distrAmt...) - k.SetReward(ctx, coinWeight.Denom, staking.GetFarmer(), reward.RewardCoins) - totalDistrAmt = totalDistrAmt.Add(distrAmt...) - } + if totalAllocCoins.IsZero() { + continue } - if !totalDistrAmt.IsZero() { - //if err := k.bankKeeper.SendCoins(ctx, distrInfo.Plan.GetFarmingPoolAddress(), distrInfo.Plan.GetRewardPoolAddress(), totalDistrAmt); err != nil { - if err := k.bankKeeper.SendCoins(ctx, distrInfo.Plan.GetFarmingPoolAddress(), k.GetRewardsReservePoolAcc(ctx), totalDistrAmt); err != nil { - return err - } + truncatedAllocCoins, _ := totalAllocCoins.TruncateDecimal() - t := ctx.BlockTime() - _ = distrInfo.Plan.SetLastDistributionTime(&t) - _ = distrInfo.Plan.SetDistributedCoins(distrInfo.Plan.GetDistributedCoins().Add(totalDistrAmt...)) - k.SetPlan(ctx, distrInfo.Plan) - - ctx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - types.EventTypeRewardDistributed, - sdk.NewAttribute(types.AttributeKeyPlanId, strconv.FormatUint(distrInfo.Plan.GetId(), 10)), - sdk.NewAttribute(types.AttributeKeyAmount, totalDistrAmt.String()), - ), - }) + rewardsReserveAcc := k.GetRewardsReservePoolAcc(ctx) + if err := k.bankKeeper.SendCoins(ctx, allocInfo.Plan.GetFarmingPoolAddress(), rewardsReserveAcc, truncatedAllocCoins); err != nil { + return err } + + t := ctx.BlockTime() + _ = allocInfo.Plan.SetLastDistributionTime(&t) + _ = allocInfo.Plan.SetDistributedCoins(allocInfo.Plan.GetDistributedCoins().Add(truncatedAllocCoins...)) + k.SetPlan(ctx, allocInfo.Plan) + + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeRewardsAllocated, + sdk.NewAttribute(types.AttributeKeyPlanId, strconv.FormatUint(allocInfo.Plan.GetId(), 10)), + sdk.NewAttribute(types.AttributeKeyAmount, truncatedAllocCoins.String()), + ), + }) } return nil diff --git a/x/farming/keeper/reward_test.go b/x/farming/keeper/reward_test.go index 2e604473..3b7fc8f9 100644 --- a/x/farming/keeper/reward_test.go +++ b/x/farming/keeper/reward_test.go @@ -8,7 +8,7 @@ import ( "github.com/tendermint/farming/x/farming/types" ) -func (suite *KeeperTestSuite) TestDistributionInfos() { +func (suite *KeeperTestSuite) TestAllocationInfos() { normalPlans := []types.PlanI{ types.NewFixedAmountPlan( types.NewBasePlan( @@ -120,7 +120,7 @@ func (suite *KeeperTestSuite) TestDistributionInfos() { } suite.ctx = suite.ctx.WithBlockTime(tc.t) - distrInfos := suite.keeper.DistributionInfos(suite.ctx) + distrInfos := suite.keeper.AllocationInfos(suite.ctx) if suite.Len(distrInfos, len(tc.distrAmts)) { for _, distrInfo := range distrInfos { distrAmt, ok := tc.distrAmts[distrInfo.Plan.GetId()] @@ -133,7 +133,83 @@ func (suite *KeeperTestSuite) TestDistributionInfos() { } } -func (suite *KeeperTestSuite) TestDistributeRewards() { +//func (suite *KeeperTestSuite) TestAllocateRewards() { +// plans := []types.PlanI{ +// types.NewFixedAmountPlan( +// types.NewBasePlan( +// 1, +// "", +// types.PlanTypePrivate, +// suite.addrs[0].String(), +// suite.addrs[0].String(), +// sdk.NewDecCoins( +// sdk.NewDecCoinFromDec(denom1, sdk.NewDecWithPrec(3, 1)), +// sdk.NewDecCoinFromDec(denom2, sdk.NewDecWithPrec(7, 1))), +// mustParseRFC3339("2021-07-30T00:00:00Z"), +// mustParseRFC3339("2021-08-30T00:00:00Z"), +// ), +// sdk.NewCoins(sdk.NewInt64Coin(denom3, 1_000_000))), +// } +// for _, plan := range plans { +// suite.keeper.SetPlan(suite.ctx, plan) +// } +// +// suite.Stake(suite.addrs[1], sdk.NewCoins( +// sdk.NewInt64Coin(denom1, 1_000_000), +// sdk.NewInt64Coin(denom2, 1_000_000))) +// suite.keeper.ProcessQueuedCoins(suite.ctx) +// +// suite.ctx = suite.ctx.WithBlockTime(mustParseRFC3339("2021-07-31T00:00:00Z")) +// err := suite.keeper.AllocateRewards(suite.ctx) +// suite.Require().NoError(err) +// +// rewards := suite.keeper.GetRewardsByFarmer(suite.ctx, suite.addrs[1]) +// suite.Require().Len(rewards, 2) +// for _, reward := range rewards { +// switch reward.StakingCoinDenom { +// case denom1: +// suite.Require().True(intEq(sdk.NewInt(300_000), reward.RewardCoins.AmountOf(denom3))) +// case denom2: +// suite.Require().True(intEq(sdk.NewInt(700_000), reward.RewardCoins.AmountOf(denom3))) +// } +// } +// +// plan, _ := suite.keeper.GetPlan(suite.ctx, 1) +// +// suite.Require().True(coinsEq(sdk.NewCoins(sdk.NewInt64Coin(denom3, 1_000_000)), plan.GetDistributedCoins())) +// t := plan.GetLastDistributionTime() +// suite.Require().NotNil(t) +// suite.Require().Equal(suite.ctx.BlockTime(), *t) +//} +// +//func (suite *KeeperTestSuite) TestHarvest() { +// for _, plan := range suite.samplePlans { +// suite.keeper.SetPlan(suite.ctx, plan) +// } +// +// suite.Stake(suite.addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom1, 1_000_000))) +// suite.keeper.ProcessQueuedCoins(suite.ctx) +// +// balancesBefore := suite.app.BankKeeper.GetAllBalances(suite.ctx, suite.addrs[0]) +// +// suite.ctx = suite.ctx.WithBlockTime(mustParseRFC3339("2021-08-05T00:00:00Z")) +// err := suite.keeper.AllocateRewards(suite.ctx) +// suite.Require().NoError(err) +// +// rewards := suite.keeper.GetRewardsByFarmer(suite.ctx, suite.addrs[0]) +// suite.Require().Len(rewards, 1) +// err = suite.keeper.Harvest(suite.ctx, suite.addrs[0], []string{denom1}) +// suite.Require().NoError(err) +// +// balancesAfter := suite.app.BankKeeper.GetAllBalances(suite.ctx, suite.addrs[0]) +// suite.Require().True(coinsEq(balancesBefore.Add(rewards[0].RewardCoins...), balancesAfter)) +// suite.Require().True(suite.app.BankKeeper.GetAllBalances(suite.ctx, suite.keeper.GetRewardsReservePoolAcc(suite.ctx)).IsZero()) +// suite.Require().Empty(suite.keeper.GetRewardsByFarmer(suite.ctx, suite.addrs[0])) +//} + +func (suite *KeeperTestSuite) TestF1() { + suite.ctx = suite.ctx.WithBlockTime(mustParseRFC3339("2021-09-01T00:00:00Z")) + plans := []types.PlanI{ types.NewFixedAmountPlan( types.NewBasePlan( @@ -144,65 +220,48 @@ func (suite *KeeperTestSuite) TestDistributeRewards() { suite.addrs[0].String(), sdk.NewDecCoins( sdk.NewDecCoinFromDec(denom1, sdk.NewDecWithPrec(3, 1)), - sdk.NewDecCoinFromDec(denom2, sdk.NewDecWithPrec(7, 1))), - mustParseRFC3339("2021-07-30T00:00:00Z"), - mustParseRFC3339("2021-08-30T00:00:00Z"), + sdk.NewDecCoinFromDec(denom2, sdk.NewDecWithPrec(7, 1)), + ), + mustParseRFC3339("0001-01-01T00:00:00Z"), + mustParseRFC3339("9999-12-31T00:00:00Z"), ), - sdk.NewCoins(sdk.NewInt64Coin(denom3, 1_000_000))), + sdk.NewCoins(sdk.NewInt64Coin(denom3, 1000000)), + ), } for _, plan := range plans { suite.keeper.SetPlan(suite.ctx, plan) } - suite.Stake(suite.addrs[1], sdk.NewCoins( - sdk.NewInt64Coin(denom1, 1_000_000), - sdk.NewInt64Coin(denom2, 1_000_000))) - suite.keeper.ProcessQueuedCoins(suite.ctx) + err := suite.keeper.Stake(suite.ctx, suite.addrs[1], sdk.NewCoins(sdk.NewInt64Coin(denom1, 1000000))) + suite.Require().NoError(err) - suite.ctx = suite.ctx.WithBlockTime(mustParseRFC3339("2021-07-31T00:00:00Z")) - err := suite.keeper.DistributeRewards(suite.ctx) + err = suite.keeper.Stake(suite.ctx, suite.addrs[2], sdk.NewCoins(sdk.NewInt64Coin(denom1, 2000000))) suite.Require().NoError(err) - rewards := suite.keeper.GetRewardsByFarmer(suite.ctx, suite.addrs[1]) - suite.Require().Len(rewards, 2) - for _, reward := range rewards { - switch reward.StakingCoinDenom { - case denom1: - suite.Require().True(intEq(sdk.NewInt(300_000), reward.RewardCoins.AmountOf(denom3))) - case denom2: - suite.Require().True(intEq(sdk.NewInt(700_000), reward.RewardCoins.AmountOf(denom3))) - } - } + err = suite.keeper.AdvanceEpoch(suite.ctx) + suite.Require().NoError(err) - plan, _ := suite.keeper.GetPlan(suite.ctx, 1) + err = suite.keeper.Stake(suite.ctx, suite.addrs[1], sdk.NewCoins(sdk.NewInt64Coin(denom1, 1000000))) + suite.Require().NoError(err) - suite.Require().True(coinsEq(sdk.NewCoins(sdk.NewInt64Coin(denom3, 1_000_000)), plan.GetDistributedCoins())) - t := plan.GetLastDistributionTime() - suite.Require().NotNil(t) - suite.Require().Equal(suite.ctx.BlockTime(), *t) -} + err = suite.keeper.AdvanceEpoch(suite.ctx) + suite.Require().NoError(err) -func (suite *KeeperTestSuite) TestHarvest() { - for _, plan := range suite.samplePlans { - suite.keeper.SetPlan(suite.ctx, plan) - } + err = suite.keeper.AdvanceEpoch(suite.ctx) + suite.Require().NoError(err) - suite.Stake(suite.addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom1, 1_000_000))) - suite.keeper.ProcessQueuedCoins(suite.ctx) + err = suite.keeper.Stake(suite.ctx, suite.addrs[1], sdk.NewCoins(sdk.NewInt64Coin(denom2, 1000000))) + suite.Require().NoError(err) - balancesBefore := suite.app.BankKeeper.GetAllBalances(suite.ctx, suite.addrs[0]) + err = suite.keeper.AdvanceEpoch(suite.ctx) + suite.Require().NoError(err) - suite.ctx = suite.ctx.WithBlockTime(mustParseRFC3339("2021-08-05T00:00:00Z")) - err := suite.keeper.DistributeRewards(suite.ctx) + err = suite.keeper.AdvanceEpoch(suite.ctx) suite.Require().NoError(err) - rewards := suite.keeper.GetRewardsByFarmer(suite.ctx, suite.addrs[0]) - suite.Require().Len(rewards, 1) - err = suite.keeper.Harvest(suite.ctx, suite.addrs[0], []string{denom1}) + err = suite.keeper.Stake(suite.ctx, suite.addrs[1], sdk.NewCoins(sdk.NewInt64Coin(denom1, 500000), sdk.NewInt64Coin(denom2, 500000))) suite.Require().NoError(err) - balancesAfter := suite.app.BankKeeper.GetAllBalances(suite.ctx, suite.addrs[0]) - suite.Require().True(coinsEq(balancesBefore.Add(rewards[0].RewardCoins...), balancesAfter)) - suite.Require().True(suite.app.BankKeeper.GetAllBalances(suite.ctx, suite.keeper.GetRewardsReservePoolAcc(suite.ctx)).IsZero()) - suite.Require().Empty(suite.keeper.GetRewardsByFarmer(suite.ctx, suite.addrs[0])) + err = suite.keeper.AdvanceEpoch(suite.ctx) + suite.Require().NoError(err) } diff --git a/x/farming/keeper/simulation_test.go b/x/farming/keeper/simulation_test.go new file mode 100644 index 00000000..38b6423f --- /dev/null +++ b/x/farming/keeper/simulation_test.go @@ -0,0 +1,176 @@ +package keeper_test + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + simapp "github.com/tendermint/farming/app" + "github.com/tendermint/farming/x/farming/types" +) + +type Action interface { + Do(*KeeperTestSuite) +} + +type StakeAction struct { + farmerAcc sdk.AccAddress + amount sdk.Coins +} + +func NewStakeAction(farmerAcc sdk.AccAddress, amount sdk.Coins) Action { + return StakeAction{farmerAcc, amount} +} + +func (sa StakeAction) Do(suite *KeeperTestSuite) { + err := suite.keeper.Stake(suite.ctx, sa.farmerAcc, sa.amount) + suite.Require().NoError(err) +} + +type UnstakeAction struct { + farmerAcc sdk.AccAddress + amount sdk.Coins +} + +func NewUnstakeAction(farmerAcc sdk.AccAddress, amount sdk.Coins) Action { + return UnstakeAction{farmerAcc, amount} +} + +func (ua UnstakeAction) Do(suite *KeeperTestSuite) { + err := suite.keeper.Unstake(suite.ctx, ua.farmerAcc, ua.amount) + suite.Require().NoError(err) +} + +type HarvestAction struct { + farmerAcc sdk.AccAddress + stakingCoinDenoms []string +} + +func NewHarvestAction(farmerAcc sdk.AccAddress, stakingCoinDenoms []string) Action { + return HarvestAction{farmerAcc, stakingCoinDenoms} +} + +func (ha HarvestAction) Do(suite *KeeperTestSuite) { + err := suite.keeper.Harvest(suite.ctx, ha.farmerAcc, ha.stakingCoinDenoms) + suite.Require().NoError(err) +} + +type Assertion interface { + Assert(*KeeperTestSuite) +} + +type BalancesAssertion struct { + acc sdk.AccAddress + balances sdk.Coins +} + +func NewBalancesAssertion(acc sdk.AccAddress, balances sdk.Coins) Assertion { + return BalancesAssertion{acc, balances} +} + +func (ba BalancesAssertion) Assert(suite *KeeperTestSuite) { + balances := suite.app.BankKeeper.GetAllBalances(suite.ctx, ba.acc) + suite.Require().True(coinsEq(ba.balances, balances)) +} + +type BalanceAssertion struct { + acc sdk.AccAddress + denom string + amount sdk.Int +} + +func NewBalanceAssertion(acc sdk.AccAddress, denom string, amount sdk.Int) Assertion { + return BalanceAssertion{acc, denom, amount} +} + +func (ba BalanceAssertion) Assert(suite *KeeperTestSuite) { + balance := suite.app.BankKeeper.GetBalance(suite.ctx, ba.acc, ba.denom) + suite.Require().True(intEq(ba.amount, balance.Amount)) +} + +type RewardsAssertion struct { + acc sdk.AccAddress + stakingCoinDenom string + rewards sdk.Coins +} + +func NewRewardsAssertion(acc sdk.AccAddress, stakingCoinDenom string, rewards sdk.Coins) Assertion { + return RewardsAssertion{acc, stakingCoinDenom, rewards} +} + +func (ra RewardsAssertion) Assert(suite *KeeperTestSuite) { + current := suite.keeper.GetCurrentRewards(suite.ctx, ra.stakingCoinDenom) + rewards := suite.keeper.CalculateRewards(suite.ctx, ra.acc, ra.stakingCoinDenom, current.Epoch) + suite.Require().True(coinsEq(ra.rewards, rewards)) +} + +func (suite *KeeperTestSuite) TestSimulation() { + suite.ctx = suite.ctx.WithBlockTime(mustParseRFC3339("2021-09-01T00:00:00Z")) + + for _, plan := range []types.PlanI{ + types.NewFixedAmountPlan( + types.NewBasePlan( + 1, + "", + types.PlanTypePrivate, + suite.addrs[0].String(), + suite.addrs[0].String(), + sdk.NewDecCoins( + sdk.NewDecCoinFromDec(denom1, sdk.NewDecWithPrec(3, 1)), + sdk.NewDecCoinFromDec(denom2, sdk.NewDecWithPrec(7, 1)), + ), + mustParseRFC3339("0001-01-01T00:00:00Z"), + mustParseRFC3339("9999-12-31T00:00:00Z"), + ), + sdk.NewCoins(sdk.NewInt64Coin(denom3, 1000000)), + ), + } { + suite.keeper.SetPlan(suite.ctx, plan) + } + + addrs := simapp.AddTestAddrs(suite.app, suite.ctx, 2, sdk.ZeroInt()) + for _, addr := range addrs { + err := simapp.FundAccount(suite.app.BankKeeper, suite.ctx, addr, sdk.NewCoins( + sdk.NewInt64Coin(denom1, 1_000_000_000_000), + sdk.NewInt64Coin(denom2, 1_000_000_000_000))) + suite.Require().NoError(err) + } + + for _, entry := range []struct { + actions []Action + advanceEpoch bool + assertions []Assertion + }{ + { + []Action{ + NewStakeAction(addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom1, 1000000))), + }, + false, + []Assertion{ + NewBalanceAssertion(addrs[0], denom3, sdk.ZeroInt()), + NewRewardsAssertion(addrs[0], denom1, sdk.NewCoins()), + NewBalanceAssertion(addrs[1], denom3, sdk.ZeroInt()), + NewRewardsAssertion(addrs[1], denom1, sdk.NewCoins()), + }, + }, + { + []Action{ + NewStakeAction(addrs[1], sdk.NewCoins(sdk.NewInt64Coin(denom1, 500000), sdk.NewInt64Coin(denom2, 500000))), + }, + true, + []Assertion{ + NewBalanceAssertion(addrs[0], denom3, sdk.ZeroInt()), + NewBalanceAssertion(addrs[1], denom3, sdk.ZeroInt()), + }, + }, + } { + for _, action := range entry.actions { + action.Do(suite) + } + if entry.advanceEpoch { + err := suite.keeper.AdvanceEpoch(suite.ctx) + suite.Require().NoError(err) + } + for _, assertion := range entry.assertions { + assertion.Assert(suite) + } + } +} diff --git a/x/farming/keeper/staking.go b/x/farming/keeper/staking.go index a7b32a5f..c09373a6 100644 --- a/x/farming/keeper/staking.go +++ b/x/farming/keeper/staking.go @@ -1,290 +1,292 @@ package keeper import ( - "encoding/binary" - - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - gogotypes "github.com/gogo/protobuf/types" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/tendermint/farming/x/farming/types" ) -func (k Keeper) GetNextStakingID(ctx sdk.Context) uint64 { - store := ctx.KVStore(k.storeKey) - var lastID uint64 - bz := store.Get(types.GlobalStakingIdKey) - if bz == nil { - lastID = 0 - } else { - var value gogotypes.UInt64Value - k.cdc.MustUnmarshal(bz, &value) - lastID = value.Value - } - return lastID + 1 -} - -func (k Keeper) GetNextStakingIDWithUpdate(ctx sdk.Context) uint64 { - store := ctx.KVStore(k.storeKey) - id := k.GetNextStakingID(ctx) - store.Set(types.GlobalStakingIdKey, k.cdc.MustMarshal(&gogotypes.UInt64Value{Value: id})) - return id -} - -// NewStaking sets the index to a given staking -func (k Keeper) NewStaking(ctx sdk.Context, farmer sdk.AccAddress) types.Staking { - id := k.GetNextStakingIDWithUpdate(ctx) - return types.Staking{ - Id: id, - Farmer: farmer.String(), - StakedCoins: sdk.NewCoins(), - QueuedCoins: sdk.NewCoins(), - } -} - // GetStaking returns a specific staking identified by id. -func (k Keeper) GetStaking(ctx sdk.Context, id uint64) (staking types.Staking, found bool) { +func (k Keeper) GetStaking(ctx sdk.Context, stakingCoinDenom string, farmerAcc sdk.AccAddress) (staking types.Staking, found bool) { store := ctx.KVStore(k.storeKey) - bz := store.Get(types.GetStakingKey(id)) + bz := store.Get(types.GetStakingKey(stakingCoinDenom, farmerAcc)) if bz == nil { - return staking, false + return } k.cdc.MustUnmarshal(bz, &staking) - return staking, true -} - -func (k Keeper) GetStakingIDByFarmer(ctx sdk.Context, farmerAcc sdk.AccAddress) (id uint64, found bool) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.GetStakingByFarmerIndexKey(farmerAcc)) - if bz == nil { - return 0, false - } - id = binary.BigEndian.Uint64(bz) - return id, true + found = true + return } -// GetStakingByFarmer returns a specific staking identified by farmer address. -func (k Keeper) GetStakingByFarmer(ctx sdk.Context, farmerAcc sdk.AccAddress) (staking types.Staking, found bool) { - id, found := k.GetStakingIDByFarmer(ctx, farmerAcc) - if !found { - return staking, false - } - return k.GetStaking(ctx, id) -} - -// GetAllStakings returns all stakings in the Keeper. -func (k Keeper) GetAllStakings(ctx sdk.Context) (stakings []types.Staking) { - k.IterateAllStakings(ctx, func(staking types.Staking) (stop bool) { - stakings = append(stakings, staking) - return false - }) - - return stakings -} - -// GetStakingsByStakingCoinDenom reads from kvstore and return a specific Staking indexed by given staking coin denomination -func (k Keeper) GetStakingsByStakingCoinDenom(ctx sdk.Context, denom string) (stakings []types.Staking) { - k.IterateStakingsByStakingCoinDenom(ctx, denom, func(staking types.Staking) bool { - stakings = append(stakings, staking) - return false - }) - return stakings -} +//// GetAllStakings returns all stakings in the Keeper. +//func (k Keeper) GetAllStakings(ctx sdk.Context) (stakings []types.Staking) { +// k.IterateAllStakings(ctx, func(staking types.Staking) (stop bool) { +// stakings = append(stakings, staking) +// return false +// }) +// +// return stakings +//} + +//// GetStakingsByStakingCoinDenom reads from kvstore and return a specific Staking indexed by given staking coin denomination +//func (k Keeper) GetStakingsByStakingCoinDenom(ctx sdk.Context, denom string) (stakings []types.Staking) { +// k.IterateStakingsByStakingCoinDenom(ctx, denom, func(staking types.Staking) bool { +// stakings = append(stakings, staking) +// return false +// }) +// return stakings +//} // SetStaking implements Staking. -func (k Keeper) SetStaking(ctx sdk.Context, staking types.Staking) { +func (k Keeper) SetStaking(ctx sdk.Context, stakingCoinDenom string, farmerAcc sdk.AccAddress, staking types.Staking) { store := ctx.KVStore(k.storeKey) bz := k.cdc.MustMarshal(&staking) - store.Set(types.GetStakingKey(staking.Id), bz) + store.Set(types.GetStakingKey(stakingCoinDenom, farmerAcc), bz) } -// SetStakingIndex implements Staking. -func (k Keeper) SetStakingIndex(ctx sdk.Context, staking types.Staking) { +//// SetStakingIndex implements Staking. +//func (k Keeper) SetStakingIndex(ctx sdk.Context, staking types.Staking) { +// store := ctx.KVStore(k.storeKey) +// store.Set(types.GetStakingByFarmerIndexKey(staking.GetFarmer()), sdk.Uint64ToBigEndian(staking.Id)) +// for _, denom := range staking.StakingCoinDenoms() { +// store.Set(types.GetStakingByStakingCoinDenomIndexKey(denom, staking.Id), []byte{}) +// } +//} + +//// DeleteStaking deletes a staking. +//func (k Keeper) DeleteStaking(ctx sdk.Context, staking types.Staking) { +// store := ctx.KVStore(k.storeKey) +// store.Delete(types.GetStakingKey(staking.Id)) +// store.Delete(types.GetStakingByFarmerIndexKey(staking.GetFarmer())) +// if denoms := staking.StakingCoinDenoms(); len(denoms) > 0 { +// k.DeleteStakingCoinDenomsIndex(ctx, staking.Id, denoms) +// } +//} + +//// DeleteStakingCoinDenomsIndex removes an staking for the staking mapper store. +//func (k Keeper) DeleteStakingCoinDenomsIndex(ctx sdk.Context, id uint64, denoms []string) { +// store := ctx.KVStore(k.storeKey) +// for _, denom := range denoms { +// store.Delete(types.GetStakingByStakingCoinDenomIndexKey(denom, id)) +// } +//} + +//// IterateAllStakings iterates over all the stored stakings and performs a callback function. +//// Stops iteration when callback returns true. +//func (k Keeper) IterateAllStakings(ctx sdk.Context, cb func(staking types.Staking) (stop bool)) { +// store := ctx.KVStore(k.storeKey) +// iterator := sdk.KVStorePrefixIterator(store, types.StakingKeyPrefix) +// +// defer iterator.Close() +// for ; iterator.Valid(); iterator.Next() { +// var staking types.Staking +// k.cdc.MustUnmarshal(iterator.Value(), &staking) +// if cb(staking) { +// break +// } +// } +//} + +//// IterateStakingsByStakingCoinDenom iterates over all the stored stakings indexed by staking coin denomination and performs a callback function. +//// Stops iteration when callback returns true. +//func (k Keeper) IterateStakingsByStakingCoinDenom(ctx sdk.Context, denom string, cb func(staking types.Staking) (stop bool)) { +// store := ctx.KVStore(k.storeKey) +// iterator := sdk.KVStorePrefixIterator(store, types.GetStakingsByStakingCoinDenomIndexKey(denom)) +// defer iterator.Close() +// for ; iterator.Valid(); iterator.Next() { +// _, id := types.ParseStakingsByStakingCoinDenomIndexKey(iterator.Key()) +// staking, _ := k.GetStaking(ctx, id) +// if cb(staking) { +// break +// } +// } +//} + +func (k Keeper) GetQueuedStaking(ctx sdk.Context, stakingCoinDenom string, farmerAcc sdk.AccAddress) (queuedStaking types.QueuedStaking, found bool) { store := ctx.KVStore(k.storeKey) - store.Set(types.GetStakingByFarmerIndexKey(staking.GetFarmer()), sdk.Uint64ToBigEndian(staking.Id)) - for _, denom := range staking.StakingCoinDenoms() { - store.Set(types.GetStakingByStakingCoinDenomIndexKey(denom, staking.Id), []byte{}) + bz := store.Get(types.GetQueuedStakingKey(stakingCoinDenom, farmerAcc)) + if bz == nil { + return } + k.cdc.MustUnmarshal(bz, &queuedStaking) + found = true + return } -// DeleteStaking deletes a staking. -func (k Keeper) DeleteStaking(ctx sdk.Context, staking types.Staking) { +func (k Keeper) SetQueuedStaking(ctx sdk.Context, stakingCoinDenom string, farmerAcc sdk.AccAddress, queuedStaking types.QueuedStaking) { store := ctx.KVStore(k.storeKey) - store.Delete(types.GetStakingKey(staking.Id)) - store.Delete(types.GetStakingByFarmerIndexKey(staking.GetFarmer())) - if denoms := staking.StakingCoinDenoms(); len(denoms) > 0 { - k.DeleteStakingCoinDenomsIndex(ctx, staking.Id, denoms) - } + bz := k.cdc.MustMarshal(&queuedStaking) + store.Set(types.GetQueuedStakingKey(stakingCoinDenom, farmerAcc), bz) } -// DeleteStakingCoinDenomsIndex removes an staking for the staking mapper store. -func (k Keeper) DeleteStakingCoinDenomsIndex(ctx sdk.Context, id uint64, denoms []string) { +func (k Keeper) DeleteQueuedStaking(ctx sdk.Context, stakingCoinDenom string, farmerAcc sdk.AccAddress) { store := ctx.KVStore(k.storeKey) - for _, denom := range denoms { - store.Delete(types.GetStakingByStakingCoinDenomIndexKey(denom, id)) - } + store.Delete(types.GetQueuedStakingKey(stakingCoinDenom, farmerAcc)) } -// IterateAllStakings iterates over all the stored stakings and performs a callback function. -// Stops iteration when callback returns true. -func (k Keeper) IterateAllStakings(ctx sdk.Context, cb func(staking types.Staking) (stop bool)) { +func (k Keeper) IterateQueuedStakings(ctx sdk.Context, cb func(stakingCoinDenom string, farmerAcc sdk.AccAddress, queuedStaking types.QueuedStaking) (stop bool)) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, types.StakingKeyPrefix) - - defer iterator.Close() - for ; iterator.Valid(); iterator.Next() { - var staking types.Staking - k.cdc.MustUnmarshal(iterator.Value(), &staking) - if cb(staking) { + iter := sdk.KVStorePrefixIterator(store, types.QueuedStakingKeyPrefix) + defer iter.Close() + for ; iter.Valid(); iter.Next() { + var queuedStaking types.QueuedStaking + k.cdc.MustUnmarshal(iter.Value(), &queuedStaking) + stakingCoinDenom, farmerAcc := types.ParseQueuedStakingKey(iter.Key()) + if cb(stakingCoinDenom, farmerAcc, queuedStaking) { break } } } -// IterateStakingsByStakingCoinDenom iterates over all the stored stakings indexed by staking coin denomination and performs a callback function. -// Stops iteration when callback returns true. -func (k Keeper) IterateStakingsByStakingCoinDenom(ctx sdk.Context, denom string, cb func(staking types.Staking) (stop bool)) { +func (k Keeper) GetTotalStaking(ctx sdk.Context, stakingCoinDenom string) (totalStaking types.TotalStaking, found bool) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, types.GetStakingsByStakingCoinDenomIndexKey(denom)) - defer iterator.Close() - for ; iterator.Valid(); iterator.Next() { - _, id := types.ParseStakingsByStakingCoinDenomIndexKey(iterator.Key()) - staking, _ := k.GetStaking(ctx, id) - if cb(staking) { - break - } + bz := store.Get(types.GetTotalStakingKey(stakingCoinDenom)) + if bz == nil { + return } + k.cdc.MustUnmarshal(bz, &totalStaking) + found = true + return } -// UnmarshalStaking unmarshals a Staking from bytes. -func (k Keeper) UnmarshalStaking(bz []byte) (staking types.Staking, err error) { - return staking, k.cdc.Unmarshal(bz, &staking) +func (k Keeper) SetTotalStaking(ctx sdk.Context, stakingCoinDenom string, totalStaking types.TotalStaking) { + store := ctx.KVStore(k.storeKey) + bz := k.cdc.MustMarshal(&totalStaking) + store.Set(types.GetTotalStakingKey(stakingCoinDenom), bz) } // ReserveStakingCoins sends staking coins to the staking reserve account. -func (k Keeper) ReserveStakingCoins(ctx sdk.Context, farmer sdk.AccAddress, stakingCoins sdk.Coins) error { - if err := k.bankKeeper.SendCoins(ctx, farmer, k.GetStakingReservePoolAcc(ctx), stakingCoins); err != nil { +func (k Keeper) ReserveStakingCoins(ctx sdk.Context, farmerAcc sdk.AccAddress, stakingCoins sdk.Coins) error { + if err := k.bankKeeper.SendCoins(ctx, farmerAcc, k.GetStakingReservePoolAcc(ctx), stakingCoins); err != nil { return err } return nil } // ReleaseStakingCoins sends staking coins back to the farmer. -func (k Keeper) ReleaseStakingCoins(ctx sdk.Context, farmer sdk.AccAddress, unstakingCoins sdk.Coins) error { - if err := k.bankKeeper.SendCoins(ctx, k.GetStakingReservePoolAcc(ctx), farmer, unstakingCoins); err != nil { +func (k Keeper) ReleaseStakingCoins(ctx sdk.Context, farmerAcc sdk.AccAddress, unstakingCoins sdk.Coins) error { + if err := k.bankKeeper.SendCoins(ctx, k.GetStakingReservePoolAcc(ctx), farmerAcc, unstakingCoins); err != nil { return err } return nil } -// Stake stores staking coins to queued coins and it will be processed in the next epoch. -func (k Keeper) Stake(ctx sdk.Context, farmer sdk.AccAddress, amount sdk.Coins) (types.Staking, error) { - if err := k.ReserveStakingCoins(ctx, farmer, amount); err != nil { - return types.Staking{}, err +// Stake stores staking coins to queued coins, and it will be processed in the next epoch. +func (k Keeper) Stake(ctx sdk.Context, farmerAcc sdk.AccAddress, amount sdk.Coins) error { + if err := k.ReserveStakingCoins(ctx, farmerAcc, amount); err != nil { + return err } - params := k.GetParams(ctx) - - staking, found := k.GetStakingByFarmer(ctx, farmer) - if !found { - // We don't need to check error here because it is already checked - // in Params validation. - farmingFeeCollectorAcc, _ := sdk.AccAddressFromBech32(params.FarmingFeeCollector) - - if err := k.bankKeeper.SendCoins(ctx, farmer, farmingFeeCollectorAcc, params.StakingCreationFee); err != nil { - return types.Staking{}, sdkerrors.Wrap(types.ErrFeeCollectionFailure, err.Error()) + for _, coin := range amount { + queuedStaking, found := k.GetQueuedStaking(ctx, coin.Denom, farmerAcc) + if !found { + queuedStaking.Amount = sdk.ZeroInt() } - - staking = k.NewStaking(ctx, farmer) + queuedStaking.Amount = queuedStaking.Amount.Add(coin.Amount) + k.SetQueuedStaking(ctx, coin.Denom, farmerAcc, queuedStaking) } - staking.QueuedCoins = staking.QueuedCoins.Add(amount...) - - k.SetStaking(ctx, staking) - k.SetStakingIndex(ctx, staking) ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeStake, - sdk.NewAttribute(types.AttributeKeyFarmer, farmer.String()), + sdk.NewAttribute(types.AttributeKeyFarmer, farmerAcc.String()), sdk.NewAttribute(types.AttributeKeyStakingCoins, amount.String()), ), }) - return staking, nil + return nil } // Unstake unstakes an amount of staking coins from the staking reserve account. -func (k Keeper) Unstake(ctx sdk.Context, farmer sdk.AccAddress, amount sdk.Coins) (types.Staking, error) { - staking, found := k.GetStakingByFarmer(ctx, farmer) - if !found { - return types.Staking{}, types.ErrStakingNotExists - } - - if err := k.ReleaseStakingCoins(ctx, farmer, amount); err != nil { - return types.Staking{}, err - } - - prevDenoms := staking.StakingCoinDenoms() +func (k Keeper) Unstake(ctx sdk.Context, farmerAcc sdk.AccAddress, amount sdk.Coins) error { + //staking, found := k.GetStakingByFarmer(ctx, farmerAcc) + //if !found { + // return types.Staking{}, types.ErrStakingNotExists + //} + // + //if err := k.ReleaseStakingCoins(ctx, farmerAcc, amount); err != nil { + // return types.Staking{}, err + //} + // + //prevDenoms := staking.StakingCoinDenoms() + // + //var hasNeg bool + //staking.QueuedCoins, hasNeg = staking.QueuedCoins.SafeSub(amount) + //if hasNeg { + // negativeCoins := sdk.NewCoins() + // for _, coin := range staking.QueuedCoins { + // if coin.IsNegative() { + // negativeCoins = negativeCoins.Add(coin) + // } + // } + // staking.QueuedCoins = staking.QueuedCoins.Sub(negativeCoins) + // staking.StakedCoins = staking.StakedCoins.Add(negativeCoins...) + //} + // + //// Remove the Staking object from the kvstore when all coins has been unstaked + //// and there's no rewards left. + //// TODO: find more efficient way to check if the farmerAcc has no rewards + //if staking.StakedCoins.IsZero() && staking.QueuedCoins.IsZero() { + // k.DeleteStaking(ctx, staking) + //} else { + // k.SetStaking(ctx, staking) + // + // denomSet := make(map[string]struct{}) + // for _, denom := range staking.StakingCoinDenoms() { + // denomSet[denom] = struct{}{} + // } + // + // var removedDenoms []string + // for _, denom := range prevDenoms { + // if _, ok := denomSet[denom]; !ok { + // removedDenoms = append(removedDenoms, denom) + // } + // } + // + // if len(removedDenoms) > 0 { + // k.DeleteStakingCoinDenomsIndex(ctx, staking.Id, removedDenoms) + // } + //} + // + //ctx.EventManager().EmitEvents(sdk.Events{ + // sdk.NewEvent( + // types.EventTypeUnstake, + // sdk.NewAttribute(types.AttributeKeyFarmer, farmerAcc.String()), + // sdk.NewAttribute(types.AttributeKeyUnstakingCoins, amount.String()), + // ), + //}) + // + //// We're returning a Staking even if it has deleted. + //return staking, nil + return nil +} - var hasNeg bool - staking.QueuedCoins, hasNeg = staking.QueuedCoins.SafeSub(amount) - if hasNeg { - negativeCoins := sdk.NewCoins() - for _, coin := range staking.QueuedCoins { - if coin.IsNegative() { - negativeCoins = negativeCoins.Add(coin) +// ProcessQueuedCoins moves queued coins into staked coins. +func (k Keeper) ProcessQueuedCoins(ctx sdk.Context) { + k.IterateQueuedStakings(ctx, func(stakingCoinDenom string, farmerAcc sdk.AccAddress, queuedStaking types.QueuedStaking) (stop bool) { + staking, found := k.GetStaking(ctx, stakingCoinDenom, farmerAcc) + if found { + if _, err := k.WithdrawRewards(ctx, farmerAcc, stakingCoinDenom); err != nil { + panic(err) } + } else { + staking.Amount = sdk.ZeroInt() } - staking.QueuedCoins = staking.QueuedCoins.Sub(negativeCoins) - staking.StakedCoins = staking.StakedCoins.Add(negativeCoins...) - } - // Remove the Staking object from the kvstore when all coins has been unstaked - // and there's no rewards left. - // TODO: find more efficient way to check if the farmer has no rewards - if staking.StakedCoins.IsZero() && staking.QueuedCoins.IsZero() && len(k.GetRewardsByFarmer(ctx, farmer)) == 0 { - k.DeleteStaking(ctx, staking) - } else { - k.SetStaking(ctx, staking) + k.DeleteQueuedStaking(ctx, stakingCoinDenom, farmerAcc) + k.SetStaking(ctx, stakingCoinDenom, farmerAcc, types.Staking{ + Amount: staking.Amount.Add(queuedStaking.Amount), + StartingEpoch: k.GetCurrentRewards(ctx, stakingCoinDenom).Epoch, + }) - denomSet := make(map[string]struct{}) - for _, denom := range staking.StakingCoinDenoms() { - denomSet[denom] = struct{}{} + totalStaking, found := k.GetTotalStaking(ctx, stakingCoinDenom) + if !found { + totalStaking.Amount = sdk.ZeroInt() } + k.SetTotalStaking(ctx, stakingCoinDenom, types.TotalStaking{ + Amount: totalStaking.Amount.Add(queuedStaking.Amount), + }) - var removedDenoms []string - for _, denom := range prevDenoms { - if _, ok := denomSet[denom]; !ok { - removedDenoms = append(removedDenoms, denom) - } - } - - if len(removedDenoms) > 0 { - k.DeleteStakingCoinDenomsIndex(ctx, staking.Id, removedDenoms) - } - } - - ctx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - types.EventTypeUnstake, - sdk.NewAttribute(types.AttributeKeyFarmer, farmer.String()), - sdk.NewAttribute(types.AttributeKeyUnstakingCoins, amount.String()), - ), - }) - - // We're returning a Staking even if it has deleted. - return staking, nil -} - -// ProcessQueuedCoins moves queued coins into staked coins. -func (k Keeper) ProcessQueuedCoins(ctx sdk.Context) { - k.IterateAllStakings(ctx, func(staking types.Staking) (stop bool) { - if !staking.QueuedCoins.IsZero() { - staking.StakedCoins = staking.StakedCoins.Add(staking.QueuedCoins...) - staking.QueuedCoins = sdk.NewCoins() - k.SetStaking(ctx, staking) - } return false }) } diff --git a/x/farming/keeper/staking_test.go b/x/farming/keeper/staking_test.go index 05d30704..48057a9d 100644 --- a/x/farming/keeper/staking_test.go +++ b/x/farming/keeper/staking_test.go @@ -1,225 +1,213 @@ package keeper_test -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/tendermint/farming/x/farming" -) - -func (suite *KeeperTestSuite) TestGetNextStakingID() { - for id := uint64(1); id <= 100; id++ { - suite.Require().Equal(id, suite.keeper.GetNextStakingIDWithUpdate(suite.ctx)) - } -} - -func (suite *KeeperTestSuite) TestGetStaking() { - _, found := suite.keeper.GetStaking(suite.ctx, 1) - suite.False(found, "staking should not be present") - - suite.Stake(suite.addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom1, 1000))) - - _, found = suite.keeper.GetStaking(suite.ctx, 1) - suite.True(found, "staking should be present") -} - -func (suite *KeeperTestSuite) TestStake() { - for _, tc := range []struct { - name string - amt int64 - remainingStaked int64 - remainingQueued int64 - expectErr bool - }{ - { - "normal", - 1000, - 0, - 1000, - false, - }, - { - "more than balance", - 10_000_000_000, - 0, - 0, - true, - }, - } { - suite.Run(tc.name, func() { - suite.SetupTest() - - _, found := suite.keeper.GetStakingByFarmer(suite.ctx, suite.addrs[0]) - suite.Require().False(found, "staking should not be present") - - staking, err := suite.keeper.Stake(suite.ctx, suite.addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom1, tc.amt))) - if tc.expectErr { - suite.Error(err) - } else { - suite.NoError(err) - staking2, found := suite.keeper.GetStakingByFarmer(suite.ctx, suite.addrs[0]) - suite.True(found, "staking should be present") - suite.True(staking2.StakedCoins.IsEqual(staking.StakedCoins)) - suite.True(staking2.QueuedCoins.IsEqual(staking2.QueuedCoins)) - - suite.True(intEq(sdk.NewInt(tc.remainingStaked), staking.StakedCoins.AmountOf(denom1))) - suite.True(intEq(sdk.NewInt(tc.remainingQueued), staking.QueuedCoins.AmountOf(denom1))) - } - }) - } -} - -func (suite *KeeperTestSuite) TestStakingCreationFee() { - params := suite.keeper.GetParams(suite.ctx) - params.StakingCreationFee = sdk.NewCoins(sdk.NewInt64Coin(denom1, 1_000_000)) - suite.keeper.SetParams(suite.ctx, params) - - // Test accounts have 1,000,000,000 coins by default. - balance := suite.app.BankKeeper.GetBalance(suite.ctx, suite.addrs[0], denom1) - suite.Require().True(intEq(sdk.NewInt(1_000_000_000), balance.Amount)) - - // Stake 999,000,000 coins and pay 1,000,000 coins as staking creation fee because - // it's the first time staking. - _, err := suite.keeper.Stake(suite.ctx, suite.addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom1, 999_000_000))) - suite.Require().NoError(err) - - // Balance should be zero now. - balance = suite.app.BankKeeper.GetBalance(suite.ctx, suite.addrs[0], denom1) - suite.Require().True(balance.Amount.IsZero()) - - // Taking a new account, staking 1_000_000_000 coins should fail because - // there is no sufficient balance for staking creation fee. - _, err = suite.keeper.Stake(suite.ctx, suite.addrs[1], sdk.NewCoins(sdk.NewInt64Coin(denom1, 1_000_000_000))) - suite.Require().Error(err) -} - -func (suite *KeeperTestSuite) TestUnstake() { - for _, tc := range []struct { - name string - addrIdx int - amt sdk.Coins - remainingStaked sdk.Coins - remainingQueued sdk.Coins - expectErr bool - }{ - { - "from queued coins", - 0, - sdk.NewCoins(sdk.NewInt64Coin(denom1, 5000)), - sdk.NewCoins(sdk.NewInt64Coin(denom1, 500_000), sdk.NewInt64Coin(denom2, 1_000_000)), - sdk.NewCoins(sdk.NewInt64Coin(denom1, 495_000)), - false, - }, - { - "from staked coins", - 0, - sdk.NewCoins(sdk.NewInt64Coin(denom1, 700_000), sdk.NewInt64Coin(denom2, 100_000)), - sdk.NewCoins(sdk.NewInt64Coin(denom1, 300_000), sdk.NewInt64Coin(denom2, 900_000)), - sdk.NewCoins(), - false, - }, - { - "one coin", - 0, - sdk.NewCoins(sdk.NewInt64Coin(denom1, 1_000_000)), - sdk.NewCoins(sdk.NewInt64Coin(denom2, 1_000_000)), - sdk.NewCoins(), - false, - }, - { - "unstake all", - 0, - sdk.NewCoins(sdk.NewInt64Coin(denom1, 1_000_000), sdk.NewInt64Coin(denom2, 1_000_000)), - sdk.NewCoins(), - sdk.NewCoins(), - false, - }, - { - "more than staked", - 0, - sdk.NewCoins(sdk.NewInt64Coin(denom1, 1_100_000), sdk.NewInt64Coin(denom2, 1_100_000)), - // We can use nil since there will be an error and we don't use these fields - nil, - nil, - true, - }, - { - "no staking", - 1, - sdk.NewCoins(sdk.NewInt64Coin(denom1, 1000)), - nil, - nil, - true, - }, - } { - suite.Run(tc.name, func() { - suite.SetupTest() - suite.Stake(suite.addrs[0], sdk.NewCoins( - sdk.NewInt64Coin(denom1, 500_000), - sdk.NewInt64Coin(denom2, 1_000_000))) - - // Make queued coins be staked. - suite.ctx = suite.ctx.WithBlockTime(mustParseRFC3339("2021-07-23T05:00:00Z")) - farming.EndBlocker(suite.ctx, suite.keeper) - suite.ctx = suite.ctx.WithBlockTime(mustParseRFC3339("2021-07-24T00:05:00Z")) - farming.EndBlocker(suite.ctx, suite.keeper) - - suite.Stake(suite.addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom1, 500_000))) - - // At this moment, we have 500,000denom1,1,000,000denom2 staked and - // 500000denom1 queued. - - staking, err := suite.keeper.Unstake(suite.ctx, suite.addrs[tc.addrIdx], tc.amt) - if tc.expectErr { - suite.Error(err) - } else { - if suite.NoError(err) { - suite.True(coinsEq(tc.remainingStaked, staking.StakedCoins)) - suite.True(coinsEq(tc.remainingQueued, staking.QueuedCoins)) - } - } - }) - } -} - -func (suite *KeeperTestSuite) TestProcessQueuedCoins() { - suite.Stake(suite.addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom1, 1000))) - - staking, _ := suite.keeper.GetStakingByFarmer(suite.ctx, suite.addrs[0]) - - suite.Require().True(staking.StakedCoins.IsZero()) - suite.Require().True(intEq(sdk.NewInt(1000), staking.QueuedCoins.AmountOf(denom1))) - - suite.keeper.ProcessQueuedCoins(suite.ctx) - - staking, _ = suite.keeper.GetStakingByFarmer(suite.ctx, suite.addrs[0]) - - suite.Require().True(intEq(sdk.NewInt(1000), staking.StakedCoins.AmountOf(denom1))) - suite.Require().True(staking.QueuedCoins.IsZero()) -} - -func (suite *KeeperTestSuite) TestEndBlockerProcessQueuedCoins() { - suite.Stake(suite.addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom1, 1000))) - - ctx := suite.ctx.WithBlockTime(mustParseRFC3339("2021-07-23T05:00:00Z")) - farming.EndBlocker(ctx, suite.keeper) - - staking, _ := suite.keeper.GetStakingByFarmer(ctx, suite.addrs[0]) - suite.Require().True(intEq(sdk.NewInt(1000), staking.QueuedCoins.AmountOf(denom1))) - suite.Require().True(staking.StakedCoins.IsZero(), "staked coins must be empty") - - suite.Stake(suite.addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom1, 500))) - - ctx = ctx.WithBlockTime(mustParseRFC3339("2021-07-23T23:59:59Z")) - farming.EndBlocker(ctx, suite.keeper) - - staking, _ = suite.keeper.GetStakingByFarmer(ctx, suite.addrs[0]) - suite.Require().True(intEq(sdk.NewInt(1500), staking.QueuedCoins.AmountOf(denom1))) - suite.Require().True(staking.StakedCoins.IsZero(), "staked coins must be empty") - - ctx = ctx.WithBlockTime(mustParseRFC3339("2021-07-24T00:00:01Z")) - farming.EndBlocker(ctx, suite.keeper) - - staking, _ = suite.keeper.GetStakingByFarmer(ctx, suite.addrs[0]) - suite.Require().True(staking.QueuedCoins.IsZero(), "queued coins must be empty") - suite.Require().True(intEq(sdk.NewInt(1500), staking.StakedCoins.AmountOf(denom1))) -} +//func (suite *KeeperTestSuite) TestGetStaking() { +// _, found := suite.keeper.GetStaking(suite.ctx, 1) +// suite.False(found, "staking should not be present") +// +// suite.Stake(suite.addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom1, 1000))) +// +// _, found = suite.keeper.GetStaking(suite.ctx, 1) +// suite.True(found, "staking should be present") +//} +// +//func (suite *KeeperTestSuite) TestStake() { +// for _, tc := range []struct { +// name string +// amt int64 +// remainingStaked int64 +// remainingQueued int64 +// expectErr bool +// }{ +// { +// "normal", +// 1000, +// 0, +// 1000, +// false, +// }, +// { +// "more than balance", +// 10_000_000_000, +// 0, +// 0, +// true, +// }, +// } { +// suite.Run(tc.name, func() { +// suite.SetupTest() +// +// _, found := suite.keeper.GetStakingByFarmer(suite.ctx, suite.addrs[0]) +// suite.Require().False(found, "staking should not be present") +// +// staking, err := suite.keeper.Stake(suite.ctx, suite.addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom1, tc.amt))) +// if tc.expectErr { +// suite.Error(err) +// } else { +// suite.NoError(err) +// staking2, found := suite.keeper.GetStakingByFarmer(suite.ctx, suite.addrs[0]) +// suite.True(found, "staking should be present") +// suite.True(staking2.StakedCoins.IsEqual(staking.StakedCoins)) +// suite.True(staking2.QueuedCoins.IsEqual(staking2.QueuedCoins)) +// +// suite.True(intEq(sdk.NewInt(tc.remainingStaked), staking.StakedCoins.AmountOf(denom1))) +// suite.True(intEq(sdk.NewInt(tc.remainingQueued), staking.QueuedCoins.AmountOf(denom1))) +// } +// }) +// } +//} +// +//func (suite *KeeperTestSuite) TestStakingCreationFee() { +// params := suite.keeper.GetParams(suite.ctx) +// params.StakingCreationFee = sdk.NewCoins(sdk.NewInt64Coin(denom1, 1_000_000)) +// suite.keeper.SetParams(suite.ctx, params) +// +// // Test accounts have 1,000,000,000 coins by default. +// balance := suite.app.BankKeeper.GetBalance(suite.ctx, suite.addrs[0], denom1) +// suite.Require().True(intEq(sdk.NewInt(1_000_000_000), balance.Amount)) +// +// // Stake 999,000,000 coins and pay 1,000,000 coins as staking creation fee because +// // it's the first time staking. +// _, err := suite.keeper.Stake(suite.ctx, suite.addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom1, 999_000_000))) +// suite.Require().NoError(err) +// +// // Balance should be zero now. +// balance = suite.app.BankKeeper.GetBalance(suite.ctx, suite.addrs[0], denom1) +// suite.Require().True(balance.Amount.IsZero()) +// +// // Taking a new account, staking 1_000_000_000 coins should fail because +// // there is no sufficient balance for staking creation fee. +// _, err = suite.keeper.Stake(suite.ctx, suite.addrs[1], sdk.NewCoins(sdk.NewInt64Coin(denom1, 1_000_000_000))) +// suite.Require().Error(err) +//} +// +//func (suite *KeeperTestSuite) TestUnstake() { +// for _, tc := range []struct { +// name string +// addrIdx int +// amt sdk.Coins +// remainingStaked sdk.Coins +// remainingQueued sdk.Coins +// expectErr bool +// }{ +// { +// "from queued coins", +// 0, +// sdk.NewCoins(sdk.NewInt64Coin(denom1, 5000)), +// sdk.NewCoins(sdk.NewInt64Coin(denom1, 500_000), sdk.NewInt64Coin(denom2, 1_000_000)), +// sdk.NewCoins(sdk.NewInt64Coin(denom1, 495_000)), +// false, +// }, +// { +// "from staked coins", +// 0, +// sdk.NewCoins(sdk.NewInt64Coin(denom1, 700_000), sdk.NewInt64Coin(denom2, 100_000)), +// sdk.NewCoins(sdk.NewInt64Coin(denom1, 300_000), sdk.NewInt64Coin(denom2, 900_000)), +// sdk.NewCoins(), +// false, +// }, +// { +// "one coin", +// 0, +// sdk.NewCoins(sdk.NewInt64Coin(denom1, 1_000_000)), +// sdk.NewCoins(sdk.NewInt64Coin(denom2, 1_000_000)), +// sdk.NewCoins(), +// false, +// }, +// { +// "unstake all", +// 0, +// sdk.NewCoins(sdk.NewInt64Coin(denom1, 1_000_000), sdk.NewInt64Coin(denom2, 1_000_000)), +// sdk.NewCoins(), +// sdk.NewCoins(), +// false, +// }, +// { +// "more than staked", +// 0, +// sdk.NewCoins(sdk.NewInt64Coin(denom1, 1_100_000), sdk.NewInt64Coin(denom2, 1_100_000)), +// // We can use nil since there will be an error and we don't use these fields +// nil, +// nil, +// true, +// }, +// { +// "no staking", +// 1, +// sdk.NewCoins(sdk.NewInt64Coin(denom1, 1000)), +// nil, +// nil, +// true, +// }, +// } { +// suite.Run(tc.name, func() { +// suite.SetupTest() +// suite.Stake(suite.addrs[0], sdk.NewCoins( +// sdk.NewInt64Coin(denom1, 500_000), +// sdk.NewInt64Coin(denom2, 1_000_000))) +// +// // Make queued coins be staked. +// suite.ctx = suite.ctx.WithBlockTime(mustParseRFC3339("2021-07-23T05:00:00Z")) +// farming.EndBlocker(suite.ctx, suite.keeper) +// suite.ctx = suite.ctx.WithBlockTime(mustParseRFC3339("2021-07-24T00:05:00Z")) +// farming.EndBlocker(suite.ctx, suite.keeper) +// +// suite.Stake(suite.addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom1, 500_000))) +// +// // At this moment, we have 500,000denom1,1,000,000denom2 staked and +// // 500000denom1 queued. +// +// staking, err := suite.keeper.Unstake(suite.ctx, suite.addrs[tc.addrIdx], tc.amt) +// if tc.expectErr { +// suite.Error(err) +// } else { +// if suite.NoError(err) { +// suite.True(coinsEq(tc.remainingStaked, staking.StakedCoins)) +// suite.True(coinsEq(tc.remainingQueued, staking.QueuedCoins)) +// } +// } +// }) +// } +//} +// +//func (suite *KeeperTestSuite) TestProcessQueuedCoins() { +// suite.Stake(suite.addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom1, 1000))) +// +// staking, _ := suite.keeper.GetStakingByFarmer(suite.ctx, suite.addrs[0]) +// +// suite.Require().True(staking.StakedCoins.IsZero()) +// suite.Require().True(intEq(sdk.NewInt(1000), staking.QueuedCoins.AmountOf(denom1))) +// +// suite.keeper.ProcessQueuedCoins(suite.ctx) +// +// staking, _ = suite.keeper.GetStakingByFarmer(suite.ctx, suite.addrs[0]) +// +// suite.Require().True(intEq(sdk.NewInt(1000), staking.StakedCoins.AmountOf(denom1))) +// suite.Require().True(staking.QueuedCoins.IsZero()) +//} +// +//func (suite *KeeperTestSuite) TestEndBlockerProcessQueuedCoins() { +// suite.Stake(suite.addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom1, 1000))) +// +// ctx := suite.ctx.WithBlockTime(mustParseRFC3339("2021-07-23T05:00:00Z")) +// farming.EndBlocker(ctx, suite.keeper) +// +// staking, _ := suite.keeper.GetStakingByFarmer(ctx, suite.addrs[0]) +// suite.Require().True(intEq(sdk.NewInt(1000), staking.QueuedCoins.AmountOf(denom1))) +// suite.Require().True(staking.StakedCoins.IsZero(), "staked coins must be empty") +// +// suite.Stake(suite.addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom1, 500))) +// +// ctx = ctx.WithBlockTime(mustParseRFC3339("2021-07-23T23:59:59Z")) +// farming.EndBlocker(ctx, suite.keeper) +// +// staking, _ = suite.keeper.GetStakingByFarmer(ctx, suite.addrs[0]) +// suite.Require().True(intEq(sdk.NewInt(1500), staking.QueuedCoins.AmountOf(denom1))) +// suite.Require().True(staking.StakedCoins.IsZero(), "staked coins must be empty") +// +// ctx = ctx.WithBlockTime(mustParseRFC3339("2021-07-24T00:00:01Z")) +// farming.EndBlocker(ctx, suite.keeper) +// +// staking, _ = suite.keeper.GetStakingByFarmer(ctx, suite.addrs[0]) +// suite.Require().True(staking.QueuedCoins.IsZero(), "queued coins must be empty") +// suite.Require().True(intEq(sdk.NewInt(1500), staking.StakedCoins.AmountOf(denom1))) +//} diff --git a/x/farming/simulation/decoder.go b/x/farming/simulation/decoder.go index 1d744ea1..c2ec0ba1 100644 --- a/x/farming/simulation/decoder.go +++ b/x/farming/simulation/decoder.go @@ -28,11 +28,6 @@ func NewDecodeStore(cdc codec.Codec) func(kvA, kvB kv.Pair) string { cdc.MustUnmarshal(kvA.Value, &sB) return fmt.Sprintf("%v\n%v", sA, sB) - case bytes.Equal(kvA.Key[:1], types.RewardKeyPrefix): - var rA, rB types.Reward - cdc.MustUnmarshal(kvA.Value, &rA) - return fmt.Sprintf("%v\n%v", rA, rB) - default: panic(fmt.Sprintf("invalid farming key prefix %X", kvA.Key[:1])) } diff --git a/x/farming/types/events.go b/x/farming/types/events.go index b3fcd3f9..0a387ec3 100644 --- a/x/farming/types/events.go +++ b/x/farming/types/events.go @@ -8,7 +8,7 @@ const ( EventTypeUnstake = "unstake" EventTypeHarvest = "harvest" EventTypePlanTerminated = "plan_terminated" - EventTypeRewardDistributed = "reward_distributed" + EventTypeRewardsAllocated = "rewards_allocated" AttributeKeyPlanId = "plan_id" //nolint:golint AttributeKeyPlanName = "plan_name" diff --git a/x/farming/types/expected_keepers.go b/x/farming/types/expected_keepers.go index 167ba8af..30cfbd12 100644 --- a/x/farming/types/expected_keepers.go +++ b/x/farming/types/expected_keepers.go @@ -3,33 +3,17 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" ) // BankKeeper defines the expected bank send keeper type BankKeeper interface { - InputOutputCoins(ctx sdk.Context, inputs []banktypes.Input, outputs []banktypes.Output) error SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins - GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin - SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins - - GetSupply(ctx sdk.Context, denom string) sdk.Coin - SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error - SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error - BurnCoins(ctx sdk.Context, name string, amt sdk.Coins) error - MintCoins(ctx sdk.Context, name string, amt sdk.Coins) error } // AccountKeeper defines the expected account keeper type AccountKeeper interface { - GetAccount(ctx sdk.Context, addr sdk.AccAddress) authtypes.AccountI GetModuleAddress(name string) sdk.AccAddress GetModuleAccount(ctx sdk.Context, moduleName string) authtypes.ModuleAccountI SetModuleAccount(sdk.Context, authtypes.ModuleAccountI) } - -// DistributionKeeper defines the expected distribution keeper -type DistributionKeeper interface { - FundCommunityPool(ctx sdk.Context, amount sdk.Coins, sender sdk.AccAddress) error -} diff --git a/x/farming/types/farming.pb.go b/x/farming/types/farming.pb.go index b4616df1..c3cce324 100644 --- a/x/farming/types/farming.pb.go +++ b/x/farming/types/farming.pb.go @@ -253,15 +253,8 @@ var xxx_messageInfo_RatioPlan proto.InternalMessageInfo // Staking defines a farmer's staking information. type Staking struct { - // id specifies index of the staking - Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` - // farmer defines the bech32-encoded address of the staker for the plan - Farmer string `protobuf:"bytes,2,opt,name=farmer,proto3" json:"farmer,omitempty"` - // staked_coins specifies the staking amount for the plan of farmer - StakedCoins github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,3,rep,name=staked_coins,json=stakedCoins,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"staked_coins" yaml:"staked_coins"` - // queued_coins specifies the coins on standby before current epoch passes and - // gets staked. - QueuedCoins github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,4,rep,name=queued_coins,json=queuedCoins,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"queued_coins" yaml:"queued_coins"` + Amount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,1,opt,name=amount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"amount"` + StartingEpoch uint64 `protobuf:"varint,2,opt,name=starting_epoch,json=startingEpoch,proto3" json:"starting_epoch,omitempty" yaml:"starting_epoch"` } func (m *Staking) Reset() { *m = Staking{} } @@ -296,6 +289,154 @@ func (m *Staking) XXX_DiscardUnknown() { var xxx_messageInfo_Staking proto.InternalMessageInfo +type QueuedStaking struct { + Amount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,1,opt,name=amount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"amount"` +} + +func (m *QueuedStaking) Reset() { *m = QueuedStaking{} } +func (m *QueuedStaking) String() string { return proto.CompactTextString(m) } +func (*QueuedStaking) ProtoMessage() {} +func (*QueuedStaking) Descriptor() ([]byte, []int) { + return fileDescriptor_5b657e0809d9de86, []int{5} +} +func (m *QueuedStaking) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueuedStaking) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueuedStaking.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 *QueuedStaking) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueuedStaking.Merge(m, src) +} +func (m *QueuedStaking) XXX_Size() int { + return m.Size() +} +func (m *QueuedStaking) XXX_DiscardUnknown() { + xxx_messageInfo_QueuedStaking.DiscardUnknown(m) +} + +var xxx_messageInfo_QueuedStaking proto.InternalMessageInfo + +type TotalStaking struct { + Amount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,1,opt,name=amount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"amount"` +} + +func (m *TotalStaking) Reset() { *m = TotalStaking{} } +func (m *TotalStaking) String() string { return proto.CompactTextString(m) } +func (*TotalStaking) ProtoMessage() {} +func (*TotalStaking) Descriptor() ([]byte, []int) { + return fileDescriptor_5b657e0809d9de86, []int{6} +} +func (m *TotalStaking) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *TotalStaking) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_TotalStaking.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 *TotalStaking) XXX_Merge(src proto.Message) { + xxx_messageInfo_TotalStaking.Merge(m, src) +} +func (m *TotalStaking) XXX_Size() int { + return m.Size() +} +func (m *TotalStaking) XXX_DiscardUnknown() { + xxx_messageInfo_TotalStaking.DiscardUnknown(m) +} + +var xxx_messageInfo_TotalStaking proto.InternalMessageInfo + +type HistoricalRewards struct { + CumulativeUnitRewards github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,1,rep,name=cumulative_unit_rewards,json=cumulativeUnitRewards,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"cumulative_unit_rewards" yaml:"cumulative_unit_rewards"` +} + +func (m *HistoricalRewards) Reset() { *m = HistoricalRewards{} } +func (m *HistoricalRewards) String() string { return proto.CompactTextString(m) } +func (*HistoricalRewards) ProtoMessage() {} +func (*HistoricalRewards) Descriptor() ([]byte, []int) { + return fileDescriptor_5b657e0809d9de86, []int{7} +} +func (m *HistoricalRewards) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *HistoricalRewards) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_HistoricalRewards.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 *HistoricalRewards) XXX_Merge(src proto.Message) { + xxx_messageInfo_HistoricalRewards.Merge(m, src) +} +func (m *HistoricalRewards) XXX_Size() int { + return m.Size() +} +func (m *HistoricalRewards) XXX_DiscardUnknown() { + xxx_messageInfo_HistoricalRewards.DiscardUnknown(m) +} + +var xxx_messageInfo_HistoricalRewards proto.InternalMessageInfo + +type CurrentRewards struct { + Epoch uint64 `protobuf:"varint,1,opt,name=epoch,proto3" json:"epoch,omitempty"` +} + +func (m *CurrentRewards) Reset() { *m = CurrentRewards{} } +func (m *CurrentRewards) String() string { return proto.CompactTextString(m) } +func (*CurrentRewards) ProtoMessage() {} +func (*CurrentRewards) Descriptor() ([]byte, []int) { + return fileDescriptor_5b657e0809d9de86, []int{8} +} +func (m *CurrentRewards) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *CurrentRewards) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_CurrentRewards.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 *CurrentRewards) XXX_Merge(src proto.Message) { + xxx_messageInfo_CurrentRewards.Merge(m, src) +} +func (m *CurrentRewards) XXX_Size() int { + return m.Size() +} +func (m *CurrentRewards) XXX_DiscardUnknown() { + xxx_messageInfo_CurrentRewards.DiscardUnknown(m) +} + +var xxx_messageInfo_CurrentRewards proto.InternalMessageInfo + func init() { proto.RegisterEnum("cosmos.farming.v1beta1.PlanType", PlanType_name, PlanType_value) proto.RegisterType((*Params)(nil), "cosmos.farming.v1beta1.Params") @@ -303,6 +444,10 @@ func init() { proto.RegisterType((*FixedAmountPlan)(nil), "cosmos.farming.v1beta1.FixedAmountPlan") proto.RegisterType((*RatioPlan)(nil), "cosmos.farming.v1beta1.RatioPlan") proto.RegisterType((*Staking)(nil), "cosmos.farming.v1beta1.Staking") + proto.RegisterType((*QueuedStaking)(nil), "cosmos.farming.v1beta1.QueuedStaking") + proto.RegisterType((*TotalStaking)(nil), "cosmos.farming.v1beta1.TotalStaking") + proto.RegisterType((*HistoricalRewards)(nil), "cosmos.farming.v1beta1.HistoricalRewards") + proto.RegisterType((*CurrentRewards)(nil), "cosmos.farming.v1beta1.CurrentRewards") } func init() { @@ -310,72 +455,78 @@ func init() { } var fileDescriptor_5b657e0809d9de86 = []byte{ - // 1030 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0xcd, 0x6e, 0xdb, 0x46, - 0x10, 0xd6, 0xca, 0x8a, 0x2d, 0xad, 0x5a, 0x5b, 0x5e, 0xff, 0x80, 0x56, 0x12, 0x92, 0x20, 0xd0, - 0x42, 0x70, 0x61, 0x0a, 0x71, 0x73, 0xf2, 0xcd, 0xf2, 0x4f, 0x20, 0xc0, 0x70, 0x55, 0x46, 0x69, - 0xda, 0x5e, 0x88, 0x95, 0xb8, 0x96, 0x89, 0x50, 0x5c, 0x95, 0x4b, 0x25, 0xd1, 0x03, 0x14, 0x08, - 0x7c, 0x0a, 0x8a, 0x1e, 0x7a, 0x71, 0x11, 0xb4, 0xb7, 0x9c, 0xfb, 0x10, 0x01, 0x72, 0x31, 0x0a, - 0x14, 0x28, 0x7a, 0x60, 0x0a, 0xfb, 0x0d, 0x74, 0xee, 0xa1, 0xd8, 0x1f, 0x2a, 0x2c, 0xa2, 0xc0, - 0xd1, 0xa1, 0x27, 0xed, 0xce, 0x7e, 0xf3, 0xcd, 0x37, 0xbb, 0x33, 0x43, 0xc1, 0x5a, 0x4c, 0x42, - 0x8f, 0x44, 0x7d, 0x3f, 0x8c, 0xeb, 0x27, 0x98, 0xff, 0xf6, 0xea, 0x8f, 0xef, 0x74, 0x48, 0x8c, - 0xef, 0xa4, 0x7b, 0x7b, 0x10, 0xd1, 0x98, 0xa2, 0xf5, 0x2e, 0x65, 0x7d, 0xca, 0xec, 0xd4, 0xaa, - 0x50, 0xd5, 0xd5, 0x1e, 0xed, 0x51, 0x01, 0xa9, 0xf3, 0x95, 0x44, 0x57, 0x37, 0x24, 0xda, 0x95, - 0x07, 0xca, 0x55, 0x1e, 0xe9, 0x72, 0x57, 0xef, 0x60, 0x46, 0x26, 0xb1, 0xba, 0xd4, 0x0f, 0xd5, - 0xb9, 0xd1, 0xa3, 0xb4, 0x17, 0x90, 0xba, 0xd8, 0x75, 0x86, 0x27, 0xf5, 0xd8, 0xef, 0x13, 0x16, - 0xe3, 0xfe, 0x40, 0x02, 0xac, 0xd7, 0x79, 0x38, 0xdf, 0xc2, 0x11, 0xee, 0x33, 0xf4, 0x12, 0xc0, - 0x8d, 0x41, 0xe4, 0x3f, 0xc6, 0x31, 0x71, 0x07, 0x01, 0x0e, 0xdd, 0x6e, 0x44, 0x70, 0xec, 0xd3, - 0xd0, 0x3d, 0x21, 0x44, 0x03, 0xe6, 0x5c, 0xad, 0xbc, 0xbd, 0x61, 0xab, 0xf0, 0x3c, 0x60, 0x2a, - 0xdb, 0xde, 0xa3, 0x7e, 0xd8, 0x68, 0xbf, 0x4a, 0x8c, 0xdc, 0x38, 0x31, 0xcc, 0x11, 0xee, 0x07, - 0x3b, 0xd6, 0x7b, 0x99, 0xac, 0x97, 0x6f, 0x8c, 0x5a, 0xcf, 0x8f, 0x4f, 0x87, 0x1d, 0xbb, 0x4b, - 0xfb, 0x2a, 0x1f, 0xf5, 0xb3, 0xc5, 0xbc, 0x47, 0xf5, 0x78, 0x34, 0x20, 0x4c, 0x90, 0x32, 0x67, - 0x5d, 0xf1, 0xb4, 0x02, 0x1c, 0xee, 0x29, 0x96, 0x43, 0x42, 0xd0, 0x5d, 0x08, 0xc9, 0x80, 0x76, - 0x4f, 0x5d, 0x0f, 0x8f, 0x98, 0x96, 0x37, 0x41, 0xed, 0xe3, 0xc6, 0xda, 0x38, 0x31, 0x96, 0x65, - 0xf4, 0xb7, 0x67, 0x96, 0x53, 0x12, 0x9b, 0x7d, 0x3c, 0x62, 0xa8, 0x0d, 0xd7, 0xd4, 0x95, 0x73, - 0x25, 0x6e, 0x97, 0x06, 0x01, 0xe9, 0xc6, 0x34, 0xd2, 0xe6, 0x4c, 0x50, 0x2b, 0x35, 0xcc, 0x71, - 0x62, 0xdc, 0x92, 0x04, 0x53, 0x61, 0x96, 0xb3, 0xa2, 0xec, 0x87, 0x84, 0xec, 0xa5, 0xd6, 0x9d, - 0xe2, 0xb3, 0x17, 0x46, 0xee, 0xa7, 0x17, 0x46, 0xce, 0xfa, 0x79, 0x01, 0x16, 0x1b, 0x98, 0x09, - 0xb5, 0x68, 0x11, 0xe6, 0x7d, 0x4f, 0x03, 0x26, 0xa8, 0x15, 0x9c, 0xbc, 0xef, 0x21, 0x04, 0x0b, - 0x21, 0xee, 0x13, 0x21, 0xb6, 0xe4, 0x88, 0x35, 0xba, 0x0b, 0x0b, 0x3c,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af, 0xae, - 0x9c, 0x9d, 0x9b, 0x4b, 0x13, 0xa8, 0xfc, 0xf2, 0x57, 0x0b, 0xcf, 0x7e, 0xd5, 0x73, 0x8d, 0x7b, - 0xaf, 0x2e, 0x75, 0x70, 0x71, 0xa9, 0x83, 0xbf, 0x2f, 0x75, 0xf0, 0xfc, 0x4a, 0xcf, 0x5d, 0x5c, - 0xe9, 0xb9, 0x3f, 0xaf, 0xf4, 0xdc, 0xb7, 0x5b, 0x99, 0x7c, 0xa7, 0xfc, 0x03, 0x7b, 0x3a, 0x59, - 0x89, 0xd4, 0x3b, 0xf3, 0x62, 0xfa, 0x7d, 0xfe, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7c, 0x80, - 0x4f, 0xb0, 0xae, 0x09, 0x00, 0x00, + // 1135 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0x4f, 0x6f, 0x1b, 0x45, + 0x14, 0xf7, 0xb8, 0x4e, 0x62, 0x8f, 0x9b, 0xc4, 0x9e, 0xfc, 0x61, 0xe3, 0xb6, 0xde, 0xd5, 0x4a, + 0x20, 0x2b, 0x10, 0x5b, 0x0d, 0x3d, 0xe5, 0x44, 0xec, 0x24, 0xc5, 0x52, 0x14, 0xdc, 0xad, 0x43, + 0x01, 0x81, 0x56, 0x63, 0xef, 0xc4, 0x59, 0x75, 0xbd, 0x6b, 0xed, 0xcc, 0x26, 0xcd, 0x07, 0x40, + 0xaa, 0x72, 0xaa, 0x10, 0x07, 0x2e, 0x41, 0x15, 0xdc, 0xca, 0x95, 0xef, 0x40, 0x25, 0x2e, 0x11, + 0x12, 0x12, 0xe2, 0xb0, 0x45, 0xc9, 0x37, 0xf0, 0x99, 0x03, 0xda, 0x99, 0x59, 0x67, 0x11, 0x0e, + 0x69, 0xa4, 0xf6, 0xb4, 0x3b, 0x6f, 0x7e, 0xf3, 0x7b, 0xbf, 0xf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x46, 0x21, 0x55, 0x9a, 0x3d, 0x3e, 0xd1, 0xf2, 0x31, 0x70, + 0xc7, 0x76, 0x50, 0x05, 0x16, 0x2e, 0xb0, 0xad, 0xdd, 0xfa, 0x76, 0xb3, 0x51, 0x00, 0x25, 0x74, + 0x7c, 0xa2, 0xcd, 0xc4, 0xb0, 0x56, 0xd0, 0x71, 0xec, 0x2e, 0x5a, 0x86, 0xc5, 0x04, 0xd2, 0x68, + 0x7e, 0xba, 0xde, 0xde, 0x2c, 0xa4, 0x4b, 0x73, 0xc7, 0x27, 0xda, 0xec, 0x08, 0x2a, 0x7e, 0x80, + 0x4a, 0x99, 0xa7, 0x3f, 0x96, 0x53, 0xf5, 0xfb, 0x2f, 0xcf, 0xca, 0xe0, 0xf4, 0xac, 0x0c, 0xfe, + 0x3a, 0x2b, 0x83, 0x67, 0xe7, 0xe5, 0xd4, 0xe9, 0x79, 0x39, 0xf5, 0xc7, 0x79, 0x39, 0xf5, 0xc5, + 0x4a, 0x22, 0x4d, 0x63, 0x7e, 0x44, 0x9f, 0x8c, 0xde, 0x78, 0xc6, 0x3a, 0x93, 0xfc, 0x23, 0xf0, + 0xe1, 0x3f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x28, 0x0f, 0x06, 0x2c, 0xb5, 0x0a, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -659,24 +810,114 @@ func (m *Staking) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.QueuedCoins) > 0 { - for iNdEx := len(m.QueuedCoins) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.QueuedCoins[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintFarming(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x22 + if m.StartingEpoch != 0 { + i = encodeVarintFarming(dAtA, i, uint64(m.StartingEpoch)) + i-- + dAtA[i] = 0x10 + } + { + size := m.Amount.Size() + i -= size + if _, err := m.Amount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintFarming(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *QueuedStaking) 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 *QueuedStaking) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueuedStaking) 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 = encodeVarintFarming(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *TotalStaking) 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 *TotalStaking) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *TotalStaking) 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 = encodeVarintFarming(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *HistoricalRewards) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err } - if len(m.StakedCoins) > 0 { - for iNdEx := len(m.StakedCoins) - 1; iNdEx >= 0; iNdEx-- { + return dAtA[:n], nil +} + +func (m *HistoricalRewards) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *HistoricalRewards) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.CumulativeUnitRewards) > 0 { + for iNdEx := len(m.CumulativeUnitRewards) - 1; iNdEx >= 0; iNdEx-- { { - size, err := m.StakedCoins[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + size, err := m.CumulativeUnitRewards[iNdEx].MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -684,18 +925,34 @@ func (m *Staking) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintFarming(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x1a + dAtA[i] = 0xa } } - if len(m.Farmer) > 0 { - i -= len(m.Farmer) - copy(dAtA[i:], m.Farmer) - i = encodeVarintFarming(dAtA, i, uint64(len(m.Farmer))) - i-- - dAtA[i] = 0x12 + return len(dAtA) - i, nil +} + +func (m *CurrentRewards) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err } - if m.Id != 0 { - i = encodeVarintFarming(dAtA, i, uint64(m.Id)) + return dAtA[:n], nil +} + +func (m *CurrentRewards) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *CurrentRewards) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Epoch != 0 { + i = encodeVarintFarming(dAtA, i, uint64(m.Epoch)) i-- dAtA[i] = 0x8 } @@ -825,21 +1082,44 @@ func (m *Staking) Size() (n int) { } var l int _ = l - if m.Id != 0 { - n += 1 + sovFarming(uint64(m.Id)) + l = m.Amount.Size() + n += 1 + l + sovFarming(uint64(l)) + if m.StartingEpoch != 0 { + n += 1 + sovFarming(uint64(m.StartingEpoch)) } - l = len(m.Farmer) - if l > 0 { - n += 1 + l + sovFarming(uint64(l)) + return n +} + +func (m *QueuedStaking) Size() (n int) { + if m == nil { + return 0 } - if len(m.StakedCoins) > 0 { - for _, e := range m.StakedCoins { - l = e.Size() - n += 1 + l + sovFarming(uint64(l)) - } + var l int + _ = l + l = m.Amount.Size() + n += 1 + l + sovFarming(uint64(l)) + return n +} + +func (m *TotalStaking) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Amount.Size() + n += 1 + l + sovFarming(uint64(l)) + return n +} + +func (m *HistoricalRewards) Size() (n int) { + if m == nil { + return 0 } - if len(m.QueuedCoins) > 0 { - for _, e := range m.QueuedCoins { + var l int + _ = l + if len(m.CumulativeUnitRewards) > 0 { + for _, e := range m.CumulativeUnitRewards { l = e.Size() n += 1 + l + sovFarming(uint64(l)) } @@ -847,6 +1127,18 @@ func (m *Staking) Size() (n int) { return n } +func (m *CurrentRewards) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Epoch != 0 { + n += 1 + sovFarming(uint64(m.Epoch)) + } + return n +} + func sovFarming(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -1632,10 +1924,10 @@ func (m *Staking) Unmarshal(dAtA []byte) error { } switch fieldNum { case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) } - m.Id = 0 + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowFarming @@ -1645,14 +1937,98 @@ func (m *Staking) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Id |= uint64(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthFarming + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthFarming + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field StartingEpoch", wireType) + } + m.StartingEpoch = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowFarming + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.StartingEpoch |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipFarming(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthFarming + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueuedStaking) 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 ErrIntOverflowFarming + } + 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: QueuedStaking: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueuedStaking: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Farmer", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -1680,13 +2056,65 @@ func (m *Staking) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Farmer = string(dAtA[iNdEx:postIndex]) + if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex - case 3: + default: + iNdEx = preIndex + skippy, err := skipFarming(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthFarming + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *TotalStaking) 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 ErrIntOverflowFarming + } + 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: TotalStaking: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: TotalStaking: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field StakedCoins", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) } - var msglen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowFarming @@ -1696,29 +2124,79 @@ func (m *Staking) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthFarming } - postIndex := iNdEx + msglen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthFarming } if postIndex > l { return io.ErrUnexpectedEOF } - m.StakedCoins = append(m.StakedCoins, types.Coin{}) - if err := m.StakedCoins[len(m.StakedCoins)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex - case 4: + default: + iNdEx = preIndex + skippy, err := skipFarming(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthFarming + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *HistoricalRewards) 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 ErrIntOverflowFarming + } + 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: HistoricalRewards: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: HistoricalRewards: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field QueuedCoins", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field CumulativeUnitRewards", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -1745,8 +2223,8 @@ func (m *Staking) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.QueuedCoins = append(m.QueuedCoins, types.Coin{}) - if err := m.QueuedCoins[len(m.QueuedCoins)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.CumulativeUnitRewards = append(m.CumulativeUnitRewards, types.DecCoin{}) + if err := m.CumulativeUnitRewards[len(m.CumulativeUnitRewards)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -1771,6 +2249,75 @@ func (m *Staking) Unmarshal(dAtA []byte) error { } return nil } +func (m *CurrentRewards) 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 ErrIntOverflowFarming + } + 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: CurrentRewards: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: CurrentRewards: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Epoch", wireType) + } + m.Epoch = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowFarming + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Epoch |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipFarming(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthFarming + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipFarming(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/farming/types/genesis.go b/x/farming/types/genesis.go index b6034050..18b10ea3 100644 --- a/x/farming/types/genesis.go +++ b/x/farming/types/genesis.go @@ -1,17 +1,15 @@ package types import ( - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "fmt" ) // NewGenesisState returns new GenesisState. -func NewGenesisState(params Params, planRecords []PlanRecord, stakings []Staking, rewards []Reward) *GenesisState { +func NewGenesisState(params Params, planRecords []PlanRecord, stakings []Staking) *GenesisState { return &GenesisState{ Params: params, PlanRecords: planRecords, Stakings: stakings, - Rewards: rewards, } } @@ -21,7 +19,6 @@ func DefaultGenesisState() *GenesisState { DefaultParams(), []PlanRecord{}, []Staking{}, - []Reward{}, ) } @@ -40,11 +37,6 @@ func ValidateGenesis(data GenesisState) error { return err } } - for _, reward := range data.Rewards { - if err := reward.Validate(); err != nil { - return err - } - } return nil } @@ -53,9 +45,6 @@ func (r PlanRecord) Validate() error { if err := r.FarmingPoolCoins.Validate(); err != nil { return err } - if err := r.RewardPoolCoins.Validate(); err != nil { - return err - } if err := r.StakingReserveCoins.Validate(); err != nil { return err } @@ -64,22 +53,8 @@ func (r PlanRecord) Validate() error { // Validate validates Staking. func (s Staking) Validate() error { - if _, err := sdk.AccAddressFromBech32(s.Farmer); err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid farming pool address %q: %v", s.Farmer, err) - } - if err := s.StakedCoins.Validate(); err != nil { - return err - } - if err := s.QueuedCoins.Validate(); err != nil { - return err - } - return nil -} - -// Validate validates Reward. -func (r Reward) Validate() error { - if err := r.RewardCoins.Validate(); err != nil { - return err + if !s.Amount.IsPositive() { + return fmt.Errorf("amount must be positive") } return nil } diff --git a/x/farming/types/keys.go b/x/farming/types/keys.go index 01e9e768..d4b3530c 100644 --- a/x/farming/types/keys.go +++ b/x/farming/types/keys.go @@ -17,26 +17,22 @@ const ( // QuerierRoute is the querier route for the farming module QuerierRoute = ModuleName - - // RewardPoolAccKeyPrefix is prefix for generating deterministic reward pool module account of each plan - RewardPoolAccKeyPrefix = "RewardPoolAcc" ) var ( - // param key for global farming plan IDs GlobalPlanIdKey = []byte("globalPlanId") GlobalLastEpochTimeKey = []byte("globalLastEpochTime") - GlobalStakingIdKey = []byte("globalStakingId") PlanKeyPrefix = []byte{0x11} PlansByFarmerIndexKeyPrefix = []byte{0x12} - StakingKeyPrefix = []byte{0x21} - StakingByFarmerIndexKeyPrefix = []byte{0x22} - StakingsByStakingCoinDenomIndexKeyPrefix = []byte{0x23} + StakingKeyPrefix = []byte{0x21} + StakingIndexKeyPrefix = []byte{0x22} + QueuedStakingKeyPrefix = []byte{0x23} + TotalStakingKeyPrefix = []byte{0x24} - RewardKeyPrefix = []byte{0x31} - RewardsByFarmerIndexKeyPrefix = []byte{0x32} + HistoricalRewardsKeyPrefix = []byte{0x31} + CurrentRewardsKeyPrefix = []byte{0x32} ) // GetPlanKey returns kv indexing key of the plan @@ -55,66 +51,30 @@ func GetPlanByFarmerAddrIndexKey(farmerAcc sdk.AccAddress, planID uint64) []byte } // GetStakingKey returns a key for staking of corresponding the id -func GetStakingKey(id uint64) []byte { - return append(StakingKeyPrefix, sdk.Uint64ToBigEndian(id)...) -} - -// GetStakingByFarmerIndexKey returns key for the farmer's staking of corresponding -func GetStakingByFarmerIndexKey(farmerAcc sdk.AccAddress) []byte { - return append(StakingByFarmerIndexKeyPrefix, address.MustLengthPrefix(farmerAcc.Bytes())...) -} - -// GetStakingsByStakingCoinDenomIndexKey returns prefix for the iterable staking list by the staking coin denomination -func GetStakingsByStakingCoinDenomIndexKey(denom string) []byte { - return append(StakingsByStakingCoinDenomIndexKeyPrefix, LengthPrefixString(denom)...) -} - -// GetStakingByStakingCoinDenomIndexKey returns key for the staking index by the staking coin denomination -func GetStakingByStakingCoinDenomIndexKey(denom string, id uint64) []byte { - return append(append(StakingsByStakingCoinDenomIndexKeyPrefix, LengthPrefixString(denom)...), sdk.Uint64ToBigEndian(id)...) +func GetStakingKey(stakingCoinDenom string, farmerAcc sdk.AccAddress) []byte { + return append(append(StakingKeyPrefix, LengthPrefixString(stakingCoinDenom)...), farmerAcc...) } -// GetRewardKey returns key for staking coin denomination's reward of corresponding the farmer -func GetRewardKey(stakingCoinDenom string, farmerAcc sdk.AccAddress) []byte { - return append(append(RewardKeyPrefix, LengthPrefixString(stakingCoinDenom)...), address.MustLengthPrefix(farmerAcc.Bytes())...) +func GetQueuedStakingKey(stakingCoinDenom string, farmerAcc sdk.AccAddress) []byte { + return append(append(QueuedStakingKeyPrefix, LengthPrefixString(stakingCoinDenom)...), farmerAcc...) } -// GetRewardByFarmerAndStakingCoinDenomIndexKey returns key for farmer's reward of corresponding the staking coin denomination -func GetRewardByFarmerAndStakingCoinDenomIndexKey(farmerAcc sdk.AccAddress, stakingCoinDenom string) []byte { - return append(append(RewardsByFarmerIndexKeyPrefix, address.MustLengthPrefix(farmerAcc.Bytes())...), LengthPrefixString(stakingCoinDenom)...) +func GetTotalStakingKey(stakingCoinDenom string) []byte { + return append(TotalStakingKeyPrefix, []byte(stakingCoinDenom)...) } -// GetRewardsByStakingCoinDenomKey returns prefix for staking coin denomination's reward list -func GetRewardsByStakingCoinDenomKey(stakingCoinDenom string) []byte { - return append(RewardKeyPrefix, LengthPrefixString(stakingCoinDenom)...) +func GetHistoricalRewardsKey(stakingCoinDenom string, epoch uint64) []byte { + return append(append(HistoricalRewardsKeyPrefix, LengthPrefixString(stakingCoinDenom)...), sdk.Uint64ToBigEndian(epoch)...) } -// GetRewardsByFarmerIndexKey returns prefix for farmer's reward list -func GetRewardsByFarmerIndexKey(farmerAcc sdk.AccAddress) []byte { - return append(RewardsByFarmerIndexKeyPrefix, address.MustLengthPrefix(farmerAcc.Bytes())...) +func GetCurrentRewardsKey(stakingCoinDenom string) []byte { + return append(CurrentRewardsKeyPrefix, []byte(stakingCoinDenom)...) } -// ParseRewardKey parses a RewardKey. -func ParseRewardKey(key []byte) (stakingCoinDenom string, farmerAcc sdk.AccAddress) { +func ParseQueuedStakingKey(key []byte) (stakingCoinDenom string, farmerAcc sdk.AccAddress) { denomLen := key[1] stakingCoinDenom = string(key[2 : 2+denomLen]) - farmerAcc = key[2+denomLen+1:] - return -} - -// ParseRewardsByFarmerIndexKey parses a key of RewardsByFarmerIndex from bytes. -func ParseRewardsByFarmerIndexKey(key []byte) (farmerAcc sdk.AccAddress, stakingCoinDenom string) { - addrLen := key[1] - farmerAcc = key[2 : 2+addrLen] - stakingCoinDenom = string(key[2+addrLen+1:]) - return -} - -// ParseStakingsByStakingCoinDenomIndexKey parses a key of StakingsByStakingCoinDenomIndex from bytes. -func ParseStakingsByStakingCoinDenomIndexKey(bz []byte) (stakingCoinDenom string, stakingID uint64) { - denomLen := bz[1] - stakingCoinDenom = string(bz[2 : 2+denomLen]) - stakingID = sdk.BigEndianToUint64(bz[2+denomLen:]) + farmerAcc = key[2+denomLen:] return } diff --git a/x/farming/types/msgs_test.go b/x/farming/types/msgs_test.go index c91e2595..ff2ee48f 100644 --- a/x/farming/types/msgs_test.go +++ b/x/farming/types/msgs_test.go @@ -4,7 +4,9 @@ import ( "testing" "time" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/legacy" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto" @@ -264,3 +266,11 @@ func TestMsgHarvest(t *testing.T) { } } } + +func TestFoo(t *testing.T) { + reg := codectypes.NewInterfaceRegistry() + types.RegisterInterfaces(reg) + cdc := codec.NewProtoCodec(reg) + var rewards types.HistoricalRewards + cdc.MustUnmarshal(nil, &rewards) +} \ No newline at end of file diff --git a/x/farming/types/params.go b/x/farming/types/params.go index 77f339a4..84be5672 100644 --- a/x/farming/types/params.go +++ b/x/farming/types/params.go @@ -13,12 +13,10 @@ import ( // Parameter store keys var ( KeyPrivatePlanCreationFee = []byte("PrivatePlanCreationFee") - KeyStakingCreationFee = []byte("StakingCreationFee") KeyEpochDays = []byte("EpochDays") KeyFarmingFeeCollector = []byte("FarmingFeeCollector") DefaultPrivatePlanCreationFee = sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100_000_000))) - DefaultStakingCreationFee = sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100_000))) DefaultEpochDays = uint32(1) DefaultFarmingFeeCollector = sdk.AccAddress(address.Module(ModuleName, []byte("FarmingFeeCollectorAcc"))).String() StakingReserveAcc = sdk.AccAddress(address.Module(ModuleName, []byte("StakingReserveAcc"))) @@ -36,7 +34,6 @@ func ParamKeyTable() paramstypes.KeyTable { func DefaultParams() Params { return Params{ PrivatePlanCreationFee: DefaultPrivatePlanCreationFee, - StakingCreationFee: DefaultStakingCreationFee, EpochDays: DefaultEpochDays, FarmingFeeCollector: DefaultFarmingFeeCollector, } @@ -46,7 +43,6 @@ func DefaultParams() Params { func (p *Params) ParamSetPairs() paramstypes.ParamSetPairs { return paramstypes.ParamSetPairs{ paramstypes.NewParamSetPair(KeyPrivatePlanCreationFee, &p.PrivatePlanCreationFee, validatePrivatePlanCreationFee), - paramstypes.NewParamSetPair(KeyStakingCreationFee, &p.StakingCreationFee, validateStakingCreationFee), paramstypes.NewParamSetPair(KeyEpochDays, &p.EpochDays, validateEpochDays), paramstypes.NewParamSetPair(KeyFarmingFeeCollector, &p.FarmingFeeCollector, validateFarmingFeeCollector), } @@ -65,7 +61,6 @@ func (p Params) Validate() error { validator func(interface{}) error }{ {p.PrivatePlanCreationFee, validatePrivatePlanCreationFee}, - {p.StakingCreationFee, validateStakingCreationFee}, {p.EpochDays, validateEpochDays}, {p.FarmingFeeCollector, validateFarmingFeeCollector}, } { @@ -93,23 +88,6 @@ func validatePrivatePlanCreationFee(i interface{}) error { return nil } -func validateStakingCreationFee(i interface{}) error { - v, ok := i.(sdk.Coins) - if !ok { - return fmt.Errorf("invalid parameter type: %T", i) - } - - if err := v.Validate(); err != nil { - return err - } - - if v.Empty() { - return fmt.Errorf("staking creation fee must not be empty") - } - - return nil -} - func validateEpochDays(i interface{}) error { v, ok := i.(uint32) if !ok { diff --git a/x/farming/types/params_test.go b/x/farming/types/params_test.go index 348431de..ae0bd17d 100644 --- a/x/farming/types/params_test.go +++ b/x/farming/types/params_test.go @@ -44,13 +44,6 @@ func TestParams_Validate(t *testing.T) { }, "private plan creation fee must not be empty", }, - { - "EmptyStakingCreationFee", - func(params *types.Params) { - params.StakingCreationFee = sdk.NewCoins() - }, - "staking creation fee must not be empty", - }, { "NegativeEpochDays", func(params *types.Params) { diff --git a/x/farming/types/query.pb.go b/x/farming/types/query.pb.go index 975ecd4d..043ffd3d 100644 --- a/x/farming/types/query.pb.go +++ b/x/farming/types/query.pb.go @@ -342,210 +342,6 @@ func (m *QueryPlanResponse) GetPlan() *types.Any { return nil } -// QueryStakingsRequest is the request type for the Query/Stakings RPC method. -type QueryStakingsRequest struct { - Farmer string `protobuf:"bytes,1,opt,name=farmer,proto3" json:"farmer,omitempty"` - StakingCoinDenom string `protobuf:"bytes,2,opt,name=staking_coin_denom,json=stakingCoinDenom,proto3" json:"staking_coin_denom,omitempty" yaml:"staking_coin_denom"` - Pagination *query.PageRequest `protobuf:"bytes,3,opt,name=pagination,proto3" json:"pagination,omitempty"` -} - -func (m *QueryStakingsRequest) Reset() { *m = QueryStakingsRequest{} } -func (m *QueryStakingsRequest) String() string { return proto.CompactTextString(m) } -func (*QueryStakingsRequest) ProtoMessage() {} -func (*QueryStakingsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_00c8db58c274b111, []int{6} -} -func (m *QueryStakingsRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryStakingsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryStakingsRequest.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 *QueryStakingsRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryStakingsRequest.Merge(m, src) -} -func (m *QueryStakingsRequest) XXX_Size() int { - return m.Size() -} -func (m *QueryStakingsRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryStakingsRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryStakingsRequest proto.InternalMessageInfo - -func (m *QueryStakingsRequest) GetFarmer() string { - if m != nil { - return m.Farmer - } - return "" -} - -func (m *QueryStakingsRequest) GetStakingCoinDenom() string { - if m != nil { - return m.StakingCoinDenom - } - return "" -} - -func (m *QueryStakingsRequest) GetPagination() *query.PageRequest { - if m != nil { - return m.Pagination - } - return nil -} - -// QueryStakingsResponse is the response type for the Query/Stakings RPC method. -type QueryStakingsResponse struct { - Stakings []Staking `protobuf:"bytes,1,rep,name=stakings,proto3" json:"stakings"` - Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` -} - -func (m *QueryStakingsResponse) Reset() { *m = QueryStakingsResponse{} } -func (m *QueryStakingsResponse) String() string { return proto.CompactTextString(m) } -func (*QueryStakingsResponse) ProtoMessage() {} -func (*QueryStakingsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_00c8db58c274b111, []int{7} -} -func (m *QueryStakingsResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryStakingsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryStakingsResponse.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 *QueryStakingsResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryStakingsResponse.Merge(m, src) -} -func (m *QueryStakingsResponse) XXX_Size() int { - return m.Size() -} -func (m *QueryStakingsResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryStakingsResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryStakingsResponse proto.InternalMessageInfo - -func (m *QueryStakingsResponse) GetStakings() []Staking { - if m != nil { - return m.Stakings - } - return nil -} - -func (m *QueryStakingsResponse) GetPagination() *query.PageResponse { - if m != nil { - return m.Pagination - } - return nil -} - -// QueryStakingRequest is the request type for the Query/Staking RPC method. -type QueryStakingRequest struct { - StakingId uint64 `protobuf:"varint,1,opt,name=staking_id,json=stakingId,proto3" json:"staking_id,omitempty"` -} - -func (m *QueryStakingRequest) Reset() { *m = QueryStakingRequest{} } -func (m *QueryStakingRequest) String() string { return proto.CompactTextString(m) } -func (*QueryStakingRequest) ProtoMessage() {} -func (*QueryStakingRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_00c8db58c274b111, []int{8} -} -func (m *QueryStakingRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryStakingRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryStakingRequest.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 *QueryStakingRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryStakingRequest.Merge(m, src) -} -func (m *QueryStakingRequest) XXX_Size() int { - return m.Size() -} -func (m *QueryStakingRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryStakingRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryStakingRequest proto.InternalMessageInfo - -func (m *QueryStakingRequest) GetStakingId() uint64 { - if m != nil { - return m.StakingId - } - return 0 -} - -// QueryStakingResponse is the response type for the Query/Staking RPC method. -type QueryStakingResponse struct { - Staking Staking `protobuf:"bytes,1,opt,name=staking,proto3" json:"staking"` -} - -func (m *QueryStakingResponse) Reset() { *m = QueryStakingResponse{} } -func (m *QueryStakingResponse) String() string { return proto.CompactTextString(m) } -func (*QueryStakingResponse) ProtoMessage() {} -func (*QueryStakingResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_00c8db58c274b111, []int{9} -} -func (m *QueryStakingResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryStakingResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryStakingResponse.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 *QueryStakingResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryStakingResponse.Merge(m, src) -} -func (m *QueryStakingResponse) XXX_Size() int { - return m.Size() -} -func (m *QueryStakingResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryStakingResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryStakingResponse proto.InternalMessageInfo - -func (m *QueryStakingResponse) GetStaking() Staking { - if m != nil { - return m.Staking - } - return Staking{} -} - func init() { proto.RegisterType((*QueryParamsRequest)(nil), "cosmos.farming.v1beta1.QueryParamsRequest") proto.RegisterType((*QueryParamsResponse)(nil), "cosmos.farming.v1beta1.QueryParamsResponse") @@ -553,10 +349,6 @@ func init() { proto.RegisterType((*QueryPlansResponse)(nil), "cosmos.farming.v1beta1.QueryPlansResponse") proto.RegisterType((*QueryPlanRequest)(nil), "cosmos.farming.v1beta1.QueryPlanRequest") proto.RegisterType((*QueryPlanResponse)(nil), "cosmos.farming.v1beta1.QueryPlanResponse") - proto.RegisterType((*QueryStakingsRequest)(nil), "cosmos.farming.v1beta1.QueryStakingsRequest") - proto.RegisterType((*QueryStakingsResponse)(nil), "cosmos.farming.v1beta1.QueryStakingsResponse") - proto.RegisterType((*QueryStakingRequest)(nil), "cosmos.farming.v1beta1.QueryStakingRequest") - proto.RegisterType((*QueryStakingResponse)(nil), "cosmos.farming.v1beta1.QueryStakingResponse") } func init() { @@ -564,58 +356,46 @@ func init() { } var fileDescriptor_00c8db58c274b111 = []byte{ - // 807 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x56, 0x4f, 0x4f, 0x13, 0x4f, - 0x18, 0xee, 0x96, 0xb6, 0xc0, 0xcb, 0x85, 0xdf, 0xd0, 0x1f, 0x96, 0x46, 0xb6, 0xcd, 0x26, 0x42, - 0xf9, 0xd3, 0x5d, 0x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 0xfd, 0x4c, 0x8d, 0x3d, - 0x2e, 0xda, 0x4e, 0xf0, 0xa4, 0x59, 0xd5, 0x77, 0x59, 0xdd, 0xe8, 0xf2, 0xd3, 0xe2, 0x79, 0xf4, - 0x15, 0xfe, 0xa3, 0xf4, 0xab, 0x29, 0x3e, 0x41, 0xd7, 0xfe, 0x04, 0x00, 0x00, 0xff, 0xff, 0x8e, - 0xc7, 0xd1, 0xb8, 0xc7, 0x08, 0x00, 0x00, + // 623 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x54, 0x41, 0x6f, 0x12, 0x41, + 0x14, 0x66, 0xe9, 0x82, 0xe9, 0xf4, 0x52, 0xa7, 0x44, 0x57, 0xa2, 0xdb, 0x66, 0x13, 0x5b, 0xa0, + 0x76, 0xc7, 0xd2, 0x78, 0xf3, 0x52, 0x34, 0xd6, 0xde, 0xea, 0x7a, 0xf3, 0x42, 0x06, 0x76, 0xba, + 0x6e, 0x84, 0x99, 0x2d, 0xb3, 0x18, 0x89, 0xf1, 0x62, 0xe2, 0xc1, 0xc4, 0x83, 0x89, 0xfe, 0x00, + 0xcf, 0x9e, 0xfd, 0x11, 0x8d, 0xa7, 0x26, 0x5e, 0x3c, 0x19, 0x03, 0xfe, 0x10, 0x33, 0x6f, 0x66, + 0x29, 0xa4, 0x2d, 0x70, 0x62, 0xf6, 0xbd, 0xef, 0x7d, 0xef, 0x9b, 0xf7, 0xbe, 0x01, 0x6d, 0xa6, + 0x8c, 0x87, 0xac, 0xd7, 0x8d, 0x79, 0x4a, 0x8e, 0xa9, 0xfa, 0x8d, 0xc8, 0xeb, 0xdd, 0x16, 0x4b, + 0xe9, 0x2e, 0x39, 0xe9, 0xb3, 0xde, 0xc0, 0x4f, 0x7a, 0x22, 0x15, 0xf8, 0x46, 0x5b, 0xc8, 0xae, + 0x90, 0xbe, 0xc1, 0xf8, 0x06, 0x53, 0xae, 0x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2f, 0xf9, 0x0d, 0xec, 0x9a, 0x07, 0x72, 0xe1, 0x39, 0x6b, 0x1b, 0xe3, 0x0f, 0x16, 0x02, + 0x95, 0x12, 0x57, 0x67, 0xd3, 0x4f, 0xb8, 0xbc, 0x5c, 0x5b, 0x04, 0x6a, 0x84, 0xdc, 0x05, 0x21, + 0xeb, 0xf8, 0xce, 0x95, 0x42, 0xa0, 0xfb, 0x27, 0x0b, 0xd9, 0xaa, 0x10, 0x57, 0xe6, 0x72, 0x67, + 0x2a, 0xaa, 0x0b, 0x20, 0x8d, 0x08, 0x02, 0x22, 0xaa, 0x78, 0x6b, 0xa6, 0x08, 0xf2, 0xd6, 0x78, + 0xe0, 0x5d, 0xe3, 0xe0, 0x74, 0xe8, 0x5a, 0x67, 0x43, 0xd7, 0xfa, 0x3b, 0x74, 0xad, 0xcf, 0x23, + 0x37, 0x77, 0x36, 0x72, 0x73, 0xbf, 0x47, 0x6e, 0xee, 0xc5, 0x4e, 0x14, 0xa7, 0x2f, 0xfb, 0x2d, + 0xbf, 0x2d, 0xba, 0xe4, 0x92, 0x7f, 0xcb, 0x37, 0xe3, 0x93, 0x7a, 0xfb, 0xb2, 0x55, 0x04, 0x53, + 0xec, 0xfd, 0x0f, 0x00, 0x00, 0xff, 0xff, 0x5c, 0xa7, 0x38, 0xa5, 0x9a, 0x05, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -636,10 +416,6 @@ type QueryClient interface { Plans(ctx context.Context, in *QueryPlansRequest, opts ...grpc.CallOption) (*QueryPlansResponse, error) // Plan returns a specific plan. Plan(ctx context.Context, in *QueryPlanRequest, opts ...grpc.CallOption) (*QueryPlanResponse, error) - // Stakings returns all stakings. - Stakings(ctx context.Context, in *QueryStakingsRequest, opts ...grpc.CallOption) (*QueryStakingsResponse, error) - // Staking returns a specific staking. - Staking(ctx context.Context, in *QueryStakingRequest, opts ...grpc.CallOption) (*QueryStakingResponse, error) } type queryClient struct { @@ -677,24 +453,6 @@ func (c *queryClient) Plan(ctx context.Context, in *QueryPlanRequest, opts ...gr return out, nil } -func (c *queryClient) Stakings(ctx context.Context, in *QueryStakingsRequest, opts ...grpc.CallOption) (*QueryStakingsResponse, error) { - out := new(QueryStakingsResponse) - err := c.cc.Invoke(ctx, "/cosmos.farming.v1beta1.Query/Stakings", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *queryClient) Staking(ctx context.Context, in *QueryStakingRequest, opts ...grpc.CallOption) (*QueryStakingResponse, error) { - out := new(QueryStakingResponse) - err := c.cc.Invoke(ctx, "/cosmos.farming.v1beta1.Query/Staking", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - // QueryServer is the server API for Query service. type QueryServer interface { // Params returns parameters of the farming module. @@ -703,10 +461,6 @@ type QueryServer interface { Plans(context.Context, *QueryPlansRequest) (*QueryPlansResponse, error) // Plan returns a specific plan. Plan(context.Context, *QueryPlanRequest) (*QueryPlanResponse, error) - // Stakings returns all stakings. - Stakings(context.Context, *QueryStakingsRequest) (*QueryStakingsResponse, error) - // Staking returns a specific staking. - Staking(context.Context, *QueryStakingRequest) (*QueryStakingResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. @@ -722,12 +476,6 @@ func (*UnimplementedQueryServer) Plans(ctx context.Context, req *QueryPlansReque func (*UnimplementedQueryServer) Plan(ctx context.Context, req *QueryPlanRequest) (*QueryPlanResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Plan not implemented") } -func (*UnimplementedQueryServer) Stakings(ctx context.Context, req *QueryStakingsRequest) (*QueryStakingsResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Stakings not implemented") -} -func (*UnimplementedQueryServer) Staking(ctx context.Context, req *QueryStakingRequest) (*QueryStakingResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Staking not implemented") -} func RegisterQueryServer(s grpc1.Server, srv QueryServer) { s.RegisterService(&_Query_serviceDesc, srv) @@ -787,42 +535,6 @@ func _Query_Plan_Handler(srv interface{}, ctx context.Context, dec func(interfac return interceptor(ctx, in, info, handler) } -func _Query_Stakings_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryStakingsRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(QueryServer).Stakings(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/cosmos.farming.v1beta1.Query/Stakings", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).Stakings(ctx, req.(*QueryStakingsRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Query_Staking_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryStakingRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(QueryServer).Staking(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/cosmos.farming.v1beta1.Query/Staking", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).Staking(ctx, req.(*QueryStakingRequest)) - } - return interceptor(ctx, in, info, handler) -} - var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "cosmos.farming.v1beta1.Query", HandlerType: (*QueryServer)(nil), @@ -839,14 +551,6 @@ var _Query_serviceDesc = grpc.ServiceDesc{ MethodName: "Plan", Handler: _Query_Plan_Handler, }, - { - MethodName: "Stakings", - Handler: _Query_Stakings_Handler, - }, - { - MethodName: "Staking", - Handler: _Query_Staking_Handler, - }, }, Streams: []grpc.StreamDesc{}, Metadata: "tendermint/farming/v1beta1/query.proto", @@ -1090,227 +794,68 @@ func (m *QueryPlanResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *QueryStakingsRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err +func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { + offset -= sovQuery(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ } - return dAtA[:n], nil + dAtA[offset] = uint8(v) + return base +} +func (m *QueryParamsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n } -func (m *QueryStakingsRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) +func (m *QueryParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Params.Size() + n += 1 + l + sovQuery(uint64(l)) + return n } -func (m *QueryStakingsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i +func (m *QueryPlansRequest) Size() (n int) { + if m == nil { + return 0 + } var l int _ = l - if m.Pagination != nil { - { - size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a + l = len(m.Type) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) } - if len(m.StakingCoinDenom) > 0 { - i -= len(m.StakingCoinDenom) - copy(dAtA[i:], m.StakingCoinDenom) - i = encodeVarintQuery(dAtA, i, uint64(len(m.StakingCoinDenom))) - i-- - dAtA[i] = 0x12 + l = len(m.FarmingPoolAddress) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) } - if len(m.Farmer) > 0 { - i -= len(m.Farmer) - copy(dAtA[i:], m.Farmer) - i = encodeVarintQuery(dAtA, i, uint64(len(m.Farmer))) - i-- - dAtA[i] = 0xa + l = len(m.TerminationAddress) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) } - return len(dAtA) - i, nil -} - -func (m *QueryStakingsResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err + l = len(m.StakingCoinDenom) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) } - return dAtA[:n], nil -} - -func (m *QueryStakingsResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryStakingsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Pagination != nil { - { - size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - if len(m.Stakings) > 0 { - for iNdEx := len(m.Stakings) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Stakings[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - } - return len(dAtA) - i, nil -} - -func (m *QueryStakingRequest) 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 *QueryStakingRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryStakingRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.StakingId != 0 { - i = encodeVarintQuery(dAtA, i, uint64(m.StakingId)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func (m *QueryStakingResponse) 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 *QueryStakingResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryStakingResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - { - size, err := m.Staking.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - return len(dAtA) - i, nil -} - -func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { - offset -= sovQuery(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *QueryParamsRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - return n -} - -func (m *QueryParamsResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = m.Params.Size() - n += 1 + l + sovQuery(uint64(l)) - return n -} - -func (m *QueryPlansRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Type) - if l > 0 { - n += 1 + l + sovQuery(uint64(l)) - } - l = len(m.FarmingPoolAddress) - if l > 0 { - n += 1 + l + sovQuery(uint64(l)) - } - l = len(m.TerminationAddress) - if l > 0 { - n += 1 + l + sovQuery(uint64(l)) - } - l = len(m.StakingCoinDenom) - if l > 0 { - n += 1 + l + sovQuery(uint64(l)) - } - l = len(m.Terminated) - if l > 0 { - n += 1 + l + sovQuery(uint64(l)) - } - if m.Pagination != nil { - l = m.Pagination.Size() - n += 1 + l + sovQuery(uint64(l)) - } - return n + l = len(m.Terminated) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n } func (m *QueryPlansResponse) Size() (n int) { @@ -1357,69 +902,6 @@ func (m *QueryPlanResponse) Size() (n int) { return n } -func (m *QueryStakingsRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Farmer) - if l > 0 { - n += 1 + l + sovQuery(uint64(l)) - } - l = len(m.StakingCoinDenom) - if l > 0 { - n += 1 + l + sovQuery(uint64(l)) - } - if m.Pagination != nil { - l = m.Pagination.Size() - n += 1 + l + sovQuery(uint64(l)) - } - return n -} - -func (m *QueryStakingsResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if len(m.Stakings) > 0 { - for _, e := range m.Stakings { - l = e.Size() - n += 1 + l + sovQuery(uint64(l)) - } - } - if m.Pagination != nil { - l = m.Pagination.Size() - n += 1 + l + sovQuery(uint64(l)) - } - return n -} - -func (m *QueryStakingRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.StakingId != 0 { - n += 1 + sovQuery(uint64(m.StakingId)) - } - return n -} - -func (m *QueryStakingResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = m.Staking.Size() - n += 1 + l + sovQuery(uint64(l)) - return n -} - func sovQuery(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -1436,354 +918,25 @@ func (m *QueryParamsRequest) Unmarshal(dAtA []byte) error { if shift >= 64 { return ErrIntOverflowQuery } - 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: QueryParamsRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryParamsRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryParamsResponse) 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 ErrIntOverflowQuery - } - 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: QueryParamsResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryPlansRequest) 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 ErrIntOverflowQuery - } - 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: QueryPlansRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryPlansRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - 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 ErrInvalidLengthQuery - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Type = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field FarmingPoolAddress", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - 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 ErrInvalidLengthQuery - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.FarmingPoolAddress = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field TerminationAddress", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - 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 ErrInvalidLengthQuery - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.TerminationAddress = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field StakingCoinDenom", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - 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 ErrInvalidLengthQuery - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.StakingCoinDenom = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 5: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Terminated", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - 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 ErrInvalidLengthQuery - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Terminated = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 6: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { + if iNdEx >= l { return io.ErrUnexpectedEOF } - if m.Pagination == nil { - m.Pagination = &query.PageRequest{} - } - if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break } - iNdEx = postIndex + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryParamsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { default: iNdEx = preIndex skippy, err := skipQuery(dAtA[iNdEx:]) @@ -1805,7 +958,7 @@ func (m *QueryPlansRequest) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryPlansResponse) Unmarshal(dAtA []byte) error { +func (m *QueryParamsResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1828,49 +981,15 @@ func (m *QueryPlansResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryPlansResponse: wiretype end group for non-group") + return fmt.Errorf("proto: QueryParamsResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryPlansResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Plans", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Plans = append(m.Plans, &types.Any{}) - if err := m.Plans[len(m.Plans)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -1897,10 +1016,7 @@ func (m *QueryPlansResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.Pagination == nil { - m.Pagination = &query.PageResponse{} - } - if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -1925,7 +1041,7 @@ func (m *QueryPlansResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryPlanRequest) Unmarshal(dAtA []byte) error { +func (m *QueryPlansRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1948,17 +1064,17 @@ func (m *QueryPlanRequest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryPlanRequest: wiretype end group for non-group") + return fmt.Errorf("proto: QueryPlansRequest: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryPlanRequest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryPlansRequest: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field PlanId", wireType) + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) } - m.PlanId = 0 + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowQuery @@ -1968,66 +1084,29 @@ func (m *QueryPlanRequest) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.PlanId |= uint64(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthQuery } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryPlanResponse) 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 ErrIntOverflowQuery + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery } - if iNdEx >= l { + if postIndex > 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: QueryPlanResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryPlanResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: + m.Type = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Plan", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field FarmingPoolAddress", wireType) } - var msglen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowQuery @@ -2037,81 +1116,59 @@ func (m *QueryPlanResponse) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthQuery } - postIndex := iNdEx + msglen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthQuery } if postIndex > l { return io.ErrUnexpectedEOF } - if m.Plan == nil { - m.Plan = &types.Any{} - } - if err := m.Plan.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } + m.FarmingPoolAddress = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TerminationAddress", wireType) } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryStakingsRequest) 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 ErrIntOverflowQuery + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery } - if iNdEx >= l { + if postIndex > 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: QueryStakingsRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryStakingsRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: + m.TerminationAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Farmer", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field StakingCoinDenom", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -2139,11 +1196,11 @@ func (m *QueryStakingsRequest) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Farmer = string(dAtA[iNdEx:postIndex]) + m.StakingCoinDenom = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 2: + case 5: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field StakingCoinDenom", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Terminated", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -2171,9 +1228,9 @@ func (m *QueryStakingsRequest) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.StakingCoinDenom = string(dAtA[iNdEx:postIndex]) + m.Terminated = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 3: + case 6: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) } @@ -2230,7 +1287,7 @@ func (m *QueryStakingsRequest) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryStakingsResponse) Unmarshal(dAtA []byte) error { +func (m *QueryPlansResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -2253,15 +1310,15 @@ func (m *QueryStakingsResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryStakingsResponse: wiretype end group for non-group") + return fmt.Errorf("proto: QueryPlansResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryStakingsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryPlansResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Stakings", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Plans", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -2288,8 +1345,8 @@ func (m *QueryStakingsResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Stakings = append(m.Stakings, Staking{}) - if err := m.Stakings[len(m.Stakings)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.Plans = append(m.Plans, &types.Any{}) + if err := m.Plans[len(m.Plans)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -2350,7 +1407,7 @@ func (m *QueryStakingsResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryStakingRequest) Unmarshal(dAtA []byte) error { +func (m *QueryPlanRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -2373,17 +1430,17 @@ func (m *QueryStakingRequest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryStakingRequest: wiretype end group for non-group") + return fmt.Errorf("proto: QueryPlanRequest: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryStakingRequest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryPlanRequest: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field StakingId", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field PlanId", wireType) } - m.StakingId = 0 + m.PlanId = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowQuery @@ -2393,7 +1450,7 @@ func (m *QueryStakingRequest) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.StakingId |= uint64(b&0x7F) << shift + m.PlanId |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -2419,7 +1476,7 @@ func (m *QueryStakingRequest) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryStakingResponse) Unmarshal(dAtA []byte) error { +func (m *QueryPlanResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -2442,15 +1499,15 @@ func (m *QueryStakingResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryStakingResponse: wiretype end group for non-group") + return fmt.Errorf("proto: QueryPlanResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryStakingResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryPlanResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Staking", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Plan", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -2477,7 +1534,10 @@ func (m *QueryStakingResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.Staking.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if m.Plan == nil { + m.Plan = &types.Any{} + } + if err := m.Plan.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/x/farming/types/query.pb.gw.go b/x/farming/types/query.pb.gw.go index 36a5c276..1dba8329 100644 --- a/x/farming/types/query.pb.gw.go +++ b/x/farming/types/query.pb.gw.go @@ -139,96 +139,6 @@ func local_request_Query_Plan_0(ctx context.Context, marshaler runtime.Marshaler } -var ( - filter_Query_Stakings_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} -) - -func request_Query_Stakings_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryStakingsRequest - var metadata runtime.ServerMetadata - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Stakings_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Stakings(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Query_Stakings_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryStakingsRequest - var metadata runtime.ServerMetadata - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Stakings_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.Stakings(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Query_Staking_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryStakingRequest - var metadata runtime.ServerMetadata - - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["staking_id"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "staking_id") - } - - protoReq.StakingId, err = runtime.Uint64(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "staking_id", err) - } - - msg, err := client.Staking(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Query_Staking_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryStakingRequest - var metadata runtime.ServerMetadata - - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["staking_id"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "staking_id") - } - - protoReq.StakingId, err = runtime.Uint64(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "staking_id", err) - } - - msg, err := server.Staking(ctx, &protoReq) - return msg, metadata, err - -} - // 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. @@ -295,46 +205,6 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) - mux.Handle("GET", pattern_Query_Stakings_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Query_Stakings_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_Stakings_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("GET", pattern_Query_Staking_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Query_Staking_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_Staking_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - return nil } @@ -436,46 +306,6 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) - mux.Handle("GET", pattern_Query_Stakings_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Query_Stakings_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_Stakings_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("GET", pattern_Query_Staking_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Query_Staking_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_Staking_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - return nil } @@ -485,10 +315,6 @@ var ( pattern_Query_Plans_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "farming", "v1beta1", "plans"}, "", runtime.AssumeColonVerbOpt(false))) pattern_Query_Plan_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"cosmos", "farming", "v1beta1", "plans", "plan_id"}, "", runtime.AssumeColonVerbOpt(false))) - - pattern_Query_Stakings_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "farming", "v1beta1", "stakings"}, "", runtime.AssumeColonVerbOpt(false))) - - pattern_Query_Staking_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"cosmos", "farming", "v1beta1", "stakings", "staking_id"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( @@ -497,8 +323,4 @@ var ( forward_Query_Plans_0 = runtime.ForwardResponseMessage forward_Query_Plan_0 = runtime.ForwardResponseMessage - - forward_Query_Stakings_0 = runtime.ForwardResponseMessage - - forward_Query_Staking_0 = runtime.ForwardResponseMessage ) diff --git a/x/farming/types/reward.go b/x/farming/types/reward.go index 146abf89..ab1254f4 100644 --- a/x/farming/types/reward.go +++ b/x/farming/types/reward.go @@ -1,38 +1 @@ package types - -import ( - "github.com/cosmos/cosmos-sdk/codec" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - sdk "github.com/cosmos/cosmos-sdk/types" -) - -func (r Reward) String() string { - out, _ := r.MarshalYAML() - return out.(string) -} - -func (r Reward) MarshalYAML() (interface{}, error) { - bz, err := codec.MarshalYAML(codec.NewProtoCodec(codectypes.NewInterfaceRegistry()), &r) - if err != nil { - return nil, err - } - return string(bz), err -} - -func (r Reward) GetFarmer() sdk.AccAddress { - addr, _ := sdk.AccAddressFromBech32(r.Farmer) - return addr -} - -func (r RewardCoins) String() string { - out, _ := r.MarshalYAML() - return out.(string) -} - -func (r RewardCoins) MarshalYAML() (interface{}, error) { - bz, err := codec.MarshalYAML(codec.NewProtoCodec(codectypes.NewInterfaceRegistry()), &r) - if err != nil { - return nil, err - } - return string(bz), err -} diff --git a/x/farming/types/staking.go b/x/farming/types/staking.go index 1306c5b5..03af3e4f 100644 --- a/x/farming/types/staking.go +++ b/x/farming/types/staking.go @@ -3,7 +3,6 @@ package types import ( "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - sdk "github.com/cosmos/cosmos-sdk/types" ) func (s Staking) String() string { @@ -18,19 +17,3 @@ func (s Staking) MarshalYAML() (interface{}, error) { } return string(bz), err } - -func (s Staking) GetFarmer() sdk.AccAddress { - addr, _ := sdk.AccAddressFromBech32(s.Farmer) - return addr -} - -func (s Staking) StakingCoinDenoms() (denoms []string) { - denomSet := make(map[string]struct{}) - for _, coin := range append(s.StakedCoins, s.QueuedCoins...) { - if _, ok := denomSet[coin.Denom]; !ok { - denomSet[coin.Denom] = struct{}{} - denoms = append(denoms, coin.Denom) - } - } - return -} From a75216a6cb496142d1d8770a69f32a0fa9bd3043 Mon Sep 17 00:00:00 2001 From: Hanjun Kim Date: Tue, 7 Sep 2021 21:02:38 +0900 Subject: [PATCH 03/16] fix: implement Unstake and Harvest; WIP --- x/farming/keeper/epoch.go | 3 - x/farming/keeper/reward.go | 84 +++++++++------- x/farming/keeper/reward_test.go | 59 ----------- x/farming/keeper/simulation_test.go | 149 ++++++++++++++-------------- x/farming/keeper/staking.go | 141 +++++++++++++++----------- x/farming/types/keys.go | 23 +++++ 6 files changed, 227 insertions(+), 232 deletions(-) diff --git a/x/farming/keeper/epoch.go b/x/farming/keeper/epoch.go index b3201348..7e3fce1d 100644 --- a/x/farming/keeper/epoch.go +++ b/x/farming/keeper/epoch.go @@ -1,7 +1,6 @@ package keeper import ( - "fmt" "time" gogotypes "github.com/gogo/protobuf/types" @@ -37,13 +36,11 @@ func (k Keeper) SetLastEpochTime(ctx sdk.Context, t time.Time) { } func (k Keeper) AdvanceEpoch(ctx sdk.Context) error { - fmt.Println(">>> AdvanceEpoch()") if err := k.AllocateRewards(ctx); err != nil { return err } k.ProcessQueuedCoins(ctx) k.SetLastEpochTime(ctx, ctx.BlockTime()) - fmt.Println("<<< AdvanceEpoch()") return nil } \ No newline at end of file diff --git a/x/farming/keeper/reward.go b/x/farming/keeper/reward.go index 148e5420..5e87d958 100644 --- a/x/farming/keeper/reward.go +++ b/x/farming/keeper/reward.go @@ -54,8 +54,6 @@ func (k Keeper) CalculateRewards(ctx sdk.Context, farmerAcc sdk.AccAddress, stak } func (k Keeper) WithdrawRewards(ctx sdk.Context, farmerAcc sdk.AccAddress, stakingCoinDenom string) (sdk.Coins, error) { - fmt.Printf("WithdrawRewards(%s, %s)\n", farmerAcc, stakingCoinDenom) - staking, found := k.GetStaking(ctx, stakingCoinDenom, farmerAcc) if !found { return nil, fmt.Errorf("empty starting info") // TODO: use correct error @@ -63,11 +61,11 @@ func (k Keeper) WithdrawRewards(ctx sdk.Context, farmerAcc sdk.AccAddress, staki current := k.GetCurrentRewards(ctx, stakingCoinDenom) rewards := k.CalculateRewards(ctx, farmerAcc, stakingCoinDenom, current.Epoch-1) - fmt.Printf(" GetCurrentRewards(%s) := %+v\n", stakingCoinDenom, current) - fmt.Printf(" CalculateRewards(%s, %s, %d) := %+v\n", farmerAcc, stakingCoinDenom, current.Epoch-1, rewards) if !rewards.IsZero() { - fmt.Printf(" sending %s to %s\n", rewards, farmerAcc) + if err := k.bankKeeper.SendCoins(ctx, k.GetRewardsReservePoolAcc(ctx), farmerAcc, rewards); err != nil { + return nil, err + } } staking.StartingEpoch = current.Epoch @@ -76,31 +74,52 @@ func (k Keeper) WithdrawRewards(ctx sdk.Context, farmerAcc sdk.AccAddress, staki return rewards, nil } +func (k Keeper) WithdrawAllRewards(ctx sdk.Context, farmerAcc sdk.AccAddress) (sdk.Coins, error) { + totalRewards := sdk.NewCoins() + + k.IterateStakingsByFarmer(ctx, farmerAcc, func(stakingCoinDenom string, staking types.Staking) (stop bool) { + current := k.GetCurrentRewards(ctx, stakingCoinDenom) + rewards := k.CalculateRewards(ctx, farmerAcc, stakingCoinDenom, current.Epoch-1) + + if !rewards.IsZero() { + totalRewards = totalRewards.Add(rewards...) + } + + staking.StartingEpoch = current.Epoch + k.SetStaking(ctx, stakingCoinDenom, farmerAcc, staking) + + return false + }) + + if !totalRewards.IsZero() { + if err := k.bankKeeper.SendCoins(ctx, k.GetRewardsReservePoolAcc(ctx), farmerAcc, totalRewards); err != nil { + return nil, err + } + } + + return totalRewards, nil +} + // Harvest claims farming rewards from the reward pool. func (k Keeper) Harvest(ctx sdk.Context, farmerAcc sdk.AccAddress, stakingCoinDenoms []string) error { - //for _, denom := range stakingCoinDenoms { - //} - // - //if err := k.bankKeeper.SendCoins(ctx, k.GetRewardsReservePoolAcc(ctx), farmerAcc, amount); err != nil { - // return err - //} - // - //staking, found := k.GetStakingByFarmer(ctx, farmerAcc) - //if !found { // NOTE: this should never happen - // return sdkerrors.Wrap(types.ErrStakingNotExists, "no staking found") - //} - //if staking.StakedCoins.IsZero() && staking.QueuedCoins.IsZero() && len(k.GetRewardsByFarmer(ctx, farmerAcc)) == 0 { - // k.DeleteStaking(ctx, staking) - //} - // - //ctx.EventManager().EmitEvents(sdk.Events{ - // sdk.NewEvent( - // types.EventTypeHarvest, - // sdk.NewAttribute(types.AttributeKeyFarmer, farmerAcc.String()), - // sdk.NewAttribute(types.AttributeKeyRewardCoins, amount.String()), - // ), - //}) - // + totalRewards := sdk.NewCoins() + + for _, denom := range stakingCoinDenoms { + rewards, err := k.WithdrawRewards(ctx, farmerAcc, denom) + if err != nil { + return err + } + totalRewards = totalRewards.Add(rewards...) + } + + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeHarvest, + sdk.NewAttribute(types.AttributeKeyFarmer, farmerAcc.String()), + sdk.NewAttribute(types.AttributeKeyRewardCoins, totalRewards.String()), + ), + }) + return nil } @@ -169,7 +188,6 @@ func (k Keeper) AllocationInfos(ctx sdk.Context) []AllocationInfo { } func (k Keeper) AllocateRewards(ctx sdk.Context) error { - fmt.Printf("AllocateRewards()\n") for _, allocInfo := range k.AllocationInfos(ctx) { totalWeight := sdk.ZeroDec() for _, weight := range allocInfo.Plan.GetStakingCoinWeights() { @@ -191,20 +209,12 @@ func (k Keeper) AllocateRewards(ctx sdk.Context) error { current := k.GetCurrentRewards(ctx, weight.Denom) historical := k.GetHistoricalRewards(ctx, weight.Denom, current.Epoch-1) - fmt.Printf(" current rewards(before): %+v\n", current) - fmt.Printf(" historical rewards for %d: %+v\n", current.Epoch-1, historical) k.SetHistoricalRewards(ctx, weight.Denom, current.Epoch, types.HistoricalRewards{ CumulativeUnitRewards: historical.CumulativeUnitRewards.Add(allocCoins.QuoDecTruncate(totalStaking.Amount.ToDec())...), }) k.SetCurrentRewards(ctx, weight.Denom, types.CurrentRewards{ Epoch: current.Epoch + 1, }) - fmt.Printf(" current rewards(after): %+v\n", types.CurrentRewards{ - Epoch: current.Epoch + 1, - }) - fmt.Printf(" historical rewards for %d: %+v\n", current.Epoch, types.HistoricalRewards{ - CumulativeUnitRewards: historical.CumulativeUnitRewards.Add(allocCoins.QuoDecTruncate(totalStaking.Amount.ToDec())...), - }) totalAllocCoins = totalAllocCoins.Add(allocCoins...) } diff --git a/x/farming/keeper/reward_test.go b/x/farming/keeper/reward_test.go index 3b7fc8f9..2cefb80e 100644 --- a/x/farming/keeper/reward_test.go +++ b/x/farming/keeper/reward_test.go @@ -206,62 +206,3 @@ func (suite *KeeperTestSuite) TestAllocationInfos() { // suite.Require().True(suite.app.BankKeeper.GetAllBalances(suite.ctx, suite.keeper.GetRewardsReservePoolAcc(suite.ctx)).IsZero()) // suite.Require().Empty(suite.keeper.GetRewardsByFarmer(suite.ctx, suite.addrs[0])) //} - -func (suite *KeeperTestSuite) TestF1() { - suite.ctx = suite.ctx.WithBlockTime(mustParseRFC3339("2021-09-01T00:00:00Z")) - - plans := []types.PlanI{ - types.NewFixedAmountPlan( - types.NewBasePlan( - 1, - "", - types.PlanTypePrivate, - suite.addrs[0].String(), - suite.addrs[0].String(), - sdk.NewDecCoins( - sdk.NewDecCoinFromDec(denom1, sdk.NewDecWithPrec(3, 1)), - sdk.NewDecCoinFromDec(denom2, sdk.NewDecWithPrec(7, 1)), - ), - mustParseRFC3339("0001-01-01T00:00:00Z"), - mustParseRFC3339("9999-12-31T00:00:00Z"), - ), - sdk.NewCoins(sdk.NewInt64Coin(denom3, 1000000)), - ), - } - for _, plan := range plans { - suite.keeper.SetPlan(suite.ctx, plan) - } - - err := suite.keeper.Stake(suite.ctx, suite.addrs[1], sdk.NewCoins(sdk.NewInt64Coin(denom1, 1000000))) - suite.Require().NoError(err) - - err = suite.keeper.Stake(suite.ctx, suite.addrs[2], sdk.NewCoins(sdk.NewInt64Coin(denom1, 2000000))) - suite.Require().NoError(err) - - err = suite.keeper.AdvanceEpoch(suite.ctx) - suite.Require().NoError(err) - - err = suite.keeper.Stake(suite.ctx, suite.addrs[1], sdk.NewCoins(sdk.NewInt64Coin(denom1, 1000000))) - suite.Require().NoError(err) - - err = suite.keeper.AdvanceEpoch(suite.ctx) - suite.Require().NoError(err) - - err = suite.keeper.AdvanceEpoch(suite.ctx) - suite.Require().NoError(err) - - err = suite.keeper.Stake(suite.ctx, suite.addrs[1], sdk.NewCoins(sdk.NewInt64Coin(denom2, 1000000))) - suite.Require().NoError(err) - - err = suite.keeper.AdvanceEpoch(suite.ctx) - suite.Require().NoError(err) - - err = suite.keeper.AdvanceEpoch(suite.ctx) - suite.Require().NoError(err) - - err = suite.keeper.Stake(suite.ctx, suite.addrs[1], sdk.NewCoins(sdk.NewInt64Coin(denom1, 500000), sdk.NewInt64Coin(denom2, 500000))) - suite.Require().NoError(err) - - err = suite.keeper.AdvanceEpoch(suite.ctx) - suite.Require().NoError(err) -} diff --git a/x/farming/keeper/simulation_test.go b/x/farming/keeper/simulation_test.go index 38b6423f..a1c8ddc7 100644 --- a/x/farming/keeper/simulation_test.go +++ b/x/farming/keeper/simulation_test.go @@ -1,6 +1,8 @@ package keeper_test import ( + "fmt" + sdk "github.com/cosmos/cosmos-sdk/types" simapp "github.com/tendermint/farming/app" @@ -16,11 +18,8 @@ type StakeAction struct { amount sdk.Coins } -func NewStakeAction(farmerAcc sdk.AccAddress, amount sdk.Coins) Action { - return StakeAction{farmerAcc, amount} -} - func (sa StakeAction) Do(suite *KeeperTestSuite) { + fmt.Printf("Stake(%s, %s)\n", sa.farmerAcc, sa.amount) err := suite.keeper.Stake(suite.ctx, sa.farmerAcc, sa.amount) suite.Require().NoError(err) } @@ -30,11 +29,8 @@ type UnstakeAction struct { amount sdk.Coins } -func NewUnstakeAction(farmerAcc sdk.AccAddress, amount sdk.Coins) Action { - return UnstakeAction{farmerAcc, amount} -} - func (ua UnstakeAction) Do(suite *KeeperTestSuite) { + fmt.Printf("Unstake(%s, %s)\n", ua.farmerAcc, ua.amount) err := suite.keeper.Unstake(suite.ctx, ua.farmerAcc, ua.amount) suite.Require().NoError(err) } @@ -44,31 +40,18 @@ type HarvestAction struct { stakingCoinDenoms []string } -func NewHarvestAction(farmerAcc sdk.AccAddress, stakingCoinDenoms []string) Action { - return HarvestAction{farmerAcc, stakingCoinDenoms} -} - func (ha HarvestAction) Do(suite *KeeperTestSuite) { + fmt.Printf("Harvest(%s, %s)\n", ha.farmerAcc, ha.stakingCoinDenoms) err := suite.keeper.Harvest(suite.ctx, ha.farmerAcc, ha.stakingCoinDenoms) suite.Require().NoError(err) } -type Assertion interface { - Assert(*KeeperTestSuite) -} - -type BalancesAssertion struct { - acc sdk.AccAddress - balances sdk.Coins -} - -func NewBalancesAssertion(acc sdk.AccAddress, balances sdk.Coins) Assertion { - return BalancesAssertion{acc, balances} -} +type AdvanceEpochAction struct{} -func (ba BalancesAssertion) Assert(suite *KeeperTestSuite) { - balances := suite.app.BankKeeper.GetAllBalances(suite.ctx, ba.acc) - suite.Require().True(coinsEq(ba.balances, balances)) +func (AdvanceEpochAction) Do(suite *KeeperTestSuite) { + fmt.Println("AdvanceEpoch()") + err := suite.keeper.AdvanceEpoch(suite.ctx) + suite.Require().NoError(err) } type BalanceAssertion struct { @@ -77,12 +60,9 @@ type BalanceAssertion struct { amount sdk.Int } -func NewBalanceAssertion(acc sdk.AccAddress, denom string, amount sdk.Int) Assertion { - return BalanceAssertion{acc, denom, amount} -} - -func (ba BalanceAssertion) Assert(suite *KeeperTestSuite) { +func (ba BalanceAssertion) Do(suite *KeeperTestSuite) { balance := suite.app.BankKeeper.GetBalance(suite.ctx, ba.acc, ba.denom) + fmt.Printf("BalanceAssertion(%s, %s, %s)\n", ba.acc, ba.denom, ba.amount) suite.Require().True(intEq(ba.amount, balance.Amount)) } @@ -92,16 +72,26 @@ type RewardsAssertion struct { rewards sdk.Coins } -func NewRewardsAssertion(acc sdk.AccAddress, stakingCoinDenom string, rewards sdk.Coins) Assertion { - return RewardsAssertion{acc, stakingCoinDenom, rewards} -} - -func (ra RewardsAssertion) Assert(suite *KeeperTestSuite) { +func (ra RewardsAssertion) Do(suite *KeeperTestSuite) { current := suite.keeper.GetCurrentRewards(suite.ctx, ra.stakingCoinDenom) - rewards := suite.keeper.CalculateRewards(suite.ctx, ra.acc, ra.stakingCoinDenom, current.Epoch) + rewards := suite.keeper.CalculateRewards(suite.ctx, ra.acc, ra.stakingCoinDenom, current.Epoch-1) + fmt.Printf("RewardsAssertion(%s, %s, %s)\n", ra.acc, ra.stakingCoinDenom, ra.rewards) suite.Require().True(coinsEq(ra.rewards, rewards)) } +type TotalRewardsAssertion struct { + acc sdk.AccAddress + rewards sdk.Coins +} + +func (tra TotalRewardsAssertion) Do(suite *KeeperTestSuite) { + fmt.Printf("TotalRewardsAssertion(%s, %s)\n", tra.acc, tra.rewards) + cacheCtx, _ := suite.ctx.CacheContext() + rewards, err := suite.keeper.WithdrawAllRewards(cacheCtx, tra.acc) + suite.Require().NoError(err) + suite.Require().True(coinsEq(tra.rewards, rewards)) +} + func (suite *KeeperTestSuite) TestSimulation() { suite.ctx = suite.ctx.WithBlockTime(mustParseRFC3339("2021-09-01T00:00:00Z")) @@ -134,43 +124,54 @@ func (suite *KeeperTestSuite) TestSimulation() { suite.Require().NoError(err) } - for _, entry := range []struct { - actions []Action - advanceEpoch bool - assertions []Assertion - }{ - { - []Action{ - NewStakeAction(addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom1, 1000000))), - }, - false, - []Assertion{ - NewBalanceAssertion(addrs[0], denom3, sdk.ZeroInt()), - NewRewardsAssertion(addrs[0], denom1, sdk.NewCoins()), - NewBalanceAssertion(addrs[1], denom3, sdk.ZeroInt()), - NewRewardsAssertion(addrs[1], denom1, sdk.NewCoins()), - }, - }, - { - []Action{ - NewStakeAction(addrs[1], sdk.NewCoins(sdk.NewInt64Coin(denom1, 500000), sdk.NewInt64Coin(denom2, 500000))), - }, - true, - []Assertion{ - NewBalanceAssertion(addrs[0], denom3, sdk.ZeroInt()), - NewBalanceAssertion(addrs[1], denom3, sdk.ZeroInt()), - }, - }, + for i, action := range []Action{ + BalanceAssertion{addrs[0], denom3, sdk.ZeroInt()}, + TotalRewardsAssertion{addrs[0], sdk.NewCoins()}, + BalanceAssertion{addrs[1], denom3, sdk.ZeroInt()}, + TotalRewardsAssertion{addrs[1], sdk.NewCoins()}, + + StakeAction{addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom1, 1000000))}, + StakeAction{addrs[1], sdk.NewCoins(sdk.NewInt64Coin(denom1, 500000), sdk.NewInt64Coin(denom2, 500000))}, + AdvanceEpochAction{}, + BalanceAssertion{addrs[0], denom3, sdk.ZeroInt()}, + TotalRewardsAssertion{addrs[0], sdk.NewCoins()}, + BalanceAssertion{addrs[1], denom3, sdk.ZeroInt()}, + TotalRewardsAssertion{addrs[1], sdk.NewCoins()}, + + AdvanceEpochAction{}, + BalanceAssertion{addrs[0], denom3, sdk.ZeroInt()}, + RewardsAssertion{addrs[0], denom1, sdk.NewCoins(sdk.NewInt64Coin(denom3, 200000))}, + TotalRewardsAssertion{addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom3, 200000))}, + BalanceAssertion{addrs[1], denom3, sdk.ZeroInt()}, + TotalRewardsAssertion{addrs[1], sdk.NewCoins(sdk.NewInt64Coin(denom3, 800000))}, + + StakeAction{addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom1, 500000))}, + AdvanceEpochAction{}, + BalanceAssertion{addrs[0], denom3, sdk.NewInt(400000)}, + TotalRewardsAssertion{addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom3, 0))}, + BalanceAssertion{addrs[1], denom3, sdk.ZeroInt()}, + TotalRewardsAssertion{addrs[1], sdk.NewCoins(sdk.NewInt64Coin(denom3, 1600000))}, + + UnstakeAction{addrs[1], sdk.NewCoins(sdk.NewInt64Coin(denom1, 250000), sdk.NewInt64Coin(denom2, 250000))}, + BalanceAssertion{addrs[1], denom3, sdk.NewInt(1600000)}, + TotalRewardsAssertion{addrs[1], sdk.NewCoins()}, + AdvanceEpochAction{}, + BalanceAssertion{addrs[0], denom3, sdk.NewInt(400000)}, + TotalRewardsAssertion{addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom3, 257142))}, // 300000 * (6/7) + BalanceAssertion{addrs[1], denom3, sdk.NewInt(1600000)}, + TotalRewardsAssertion{addrs[1], sdk.NewCoins(sdk.NewInt64Coin(denom3, 742857))}, // 300000 * (1/7) + 700000 + + HarvestAction{addrs[0], []string{denom1}}, + HarvestAction{addrs[1], []string{denom1, denom2}}, + BalanceAssertion{addrs[0], denom3, sdk.NewInt(657142)}, + BalanceAssertion{addrs[1], denom3, sdk.NewInt(2342857)}, + TotalRewardsAssertion{addrs[0], sdk.NewCoins()}, + AdvanceEpochAction{}, + TotalRewardsAssertion{addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom3, 257142))}, + TotalRewardsAssertion{addrs[1], sdk.NewCoins(sdk.NewInt64Coin(denom3, 742857))}, } { - for _, action := range entry.actions { + suite.Run(fmt.Sprintf("%d", i), func() { action.Do(suite) - } - if entry.advanceEpoch { - err := suite.keeper.AdvanceEpoch(suite.ctx) - suite.Require().NoError(err) - } - for _, assertion := range entry.assertions { - assertion.Assert(suite) - } + }) } } diff --git a/x/farming/keeper/staking.go b/x/farming/keeper/staking.go index c09373a6..0276886a 100644 --- a/x/farming/keeper/staking.go +++ b/x/farming/keeper/staking.go @@ -2,6 +2,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/tendermint/farming/x/farming/types" ) @@ -18,6 +19,19 @@ func (k Keeper) GetStaking(ctx sdk.Context, stakingCoinDenom string, farmerAcc s return } +func (k Keeper) IterateStakingsByFarmer(ctx sdk.Context, farmerAcc sdk.AccAddress, cb func(stakingCoinDenom string, staking types.Staking) (stop bool)) { + store := ctx.KVStore(k.storeKey) + iter := sdk.KVStorePrefixIterator(store, types.GetStakingsByFarmerPrefix(farmerAcc)) + defer iter.Close() + for ; iter.Valid(); iter.Next() { + farmerAcc, stakingCoinDenom := types.ParseStakingIndexKey(iter.Key()) + staking, _ := k.GetStaking(ctx, stakingCoinDenom, farmerAcc) + if cb(stakingCoinDenom, staking) { + break + } + } +} + //// GetAllStakings returns all stakings in the Keeper. //func (k Keeper) GetAllStakings(ctx sdk.Context) (stakings []types.Staking) { // k.IterateAllStakings(ctx, func(staking types.Staking) (stop bool) { @@ -42,6 +56,13 @@ func (k Keeper) SetStaking(ctx sdk.Context, stakingCoinDenom string, farmerAcc s store := ctx.KVStore(k.storeKey) bz := k.cdc.MustMarshal(&staking) store.Set(types.GetStakingKey(stakingCoinDenom, farmerAcc), bz) + store.Set(types.GetStakingIndexKey(farmerAcc, stakingCoinDenom), []byte{}) +} + +func (k Keeper) DeleteStaking(ctx sdk.Context, stakingCoinDenom string, farmerAcc sdk.AccAddress) { + store := ctx.KVStore(k.storeKey) + store.Delete(types.GetStakingKey(stakingCoinDenom, farmerAcc)) + store.Delete(types.GetStakingIndexKey(farmerAcc, stakingCoinDenom)) } //// SetStakingIndex implements Staking. @@ -199,65 +220,67 @@ func (k Keeper) Stake(ctx sdk.Context, farmerAcc sdk.AccAddress, amount sdk.Coin // Unstake unstakes an amount of staking coins from the staking reserve account. func (k Keeper) Unstake(ctx sdk.Context, farmerAcc sdk.AccAddress, amount sdk.Coins) error { - //staking, found := k.GetStakingByFarmer(ctx, farmerAcc) - //if !found { - // return types.Staking{}, types.ErrStakingNotExists - //} - // - //if err := k.ReleaseStakingCoins(ctx, farmerAcc, amount); err != nil { - // return types.Staking{}, err - //} - // - //prevDenoms := staking.StakingCoinDenoms() - // - //var hasNeg bool - //staking.QueuedCoins, hasNeg = staking.QueuedCoins.SafeSub(amount) - //if hasNeg { - // negativeCoins := sdk.NewCoins() - // for _, coin := range staking.QueuedCoins { - // if coin.IsNegative() { - // negativeCoins = negativeCoins.Add(coin) - // } - // } - // staking.QueuedCoins = staking.QueuedCoins.Sub(negativeCoins) - // staking.StakedCoins = staking.StakedCoins.Add(negativeCoins...) - //} - // - //// Remove the Staking object from the kvstore when all coins has been unstaked - //// and there's no rewards left. - //// TODO: find more efficient way to check if the farmerAcc has no rewards - //if staking.StakedCoins.IsZero() && staking.QueuedCoins.IsZero() { - // k.DeleteStaking(ctx, staking) - //} else { - // k.SetStaking(ctx, staking) - // - // denomSet := make(map[string]struct{}) - // for _, denom := range staking.StakingCoinDenoms() { - // denomSet[denom] = struct{}{} - // } - // - // var removedDenoms []string - // for _, denom := range prevDenoms { - // if _, ok := denomSet[denom]; !ok { - // removedDenoms = append(removedDenoms, denom) - // } - // } - // - // if len(removedDenoms) > 0 { - // k.DeleteStakingCoinDenomsIndex(ctx, staking.Id, removedDenoms) - // } - //} - // - //ctx.EventManager().EmitEvents(sdk.Events{ - // sdk.NewEvent( - // types.EventTypeUnstake, - // sdk.NewAttribute(types.AttributeKeyFarmer, farmerAcc.String()), - // sdk.NewAttribute(types.AttributeKeyUnstakingCoins, amount.String()), - // ), - //}) - // - //// We're returning a Staking even if it has deleted. - //return staking, nil + for _, coin := range amount { + staking, found := k.GetStaking(ctx, coin.Denom, farmerAcc) + if !found { + staking.Amount = sdk.ZeroInt() + } + + queuedStaking, found := k.GetQueuedStaking(ctx, coin.Denom, farmerAcc) + if !found { + queuedStaking.Amount = sdk.ZeroInt() + } + + availableAmt := staking.Amount.Add(queuedStaking.Amount) + if availableAmt.LT(coin.Amount) { + return sdkerrors.Wrapf( + sdkerrors.ErrInsufficientFunds, "%s%s is smaller than %s%s", availableAmt, coin.Denom, coin.Amount, coin.Denom) + } + + if _, err := k.WithdrawRewards(ctx, farmerAcc, coin.Denom); err != nil { + return err + } + + removedFromStaking := sdk.ZeroInt() + + queuedStaking.Amount = queuedStaking.Amount.Sub(coin.Amount) + if queuedStaking.Amount.IsNegative() { + staking.Amount = staking.Amount.Add(queuedStaking.Amount) + removedFromStaking = queuedStaking.Amount.Neg() + queuedStaking.Amount = sdk.ZeroInt() + } + + if staking.Amount.IsPositive() { + current := k.GetCurrentRewards(ctx, coin.Denom) + staking.StartingEpoch = current.Epoch + k.SetStaking(ctx, coin.Denom, farmerAcc, staking) + } else { + k.DeleteStaking(ctx, coin.Denom, farmerAcc) + } + + if queuedStaking.Amount.IsPositive() { + k.SetQueuedStaking(ctx, coin.Denom, farmerAcc, queuedStaking) + } else { + k.DeleteQueuedStaking(ctx, coin.Denom, farmerAcc) + } + + totalStaking, _ := k.GetTotalStaking(ctx, coin.Denom) + totalStaking.Amount = totalStaking.Amount.Sub(removedFromStaking) + k.SetTotalStaking(ctx, coin.Denom, totalStaking) + } + + if err := k.ReleaseStakingCoins(ctx, farmerAcc, amount); err != nil { + return err + } + + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeUnstake, + sdk.NewAttribute(types.AttributeKeyFarmer, farmerAcc.String()), + sdk.NewAttribute(types.AttributeKeyUnstakingCoins, amount.String()), + ), + }) + return nil } diff --git a/x/farming/types/keys.go b/x/farming/types/keys.go index d4b3530c..44b39a47 100644 --- a/x/farming/types/keys.go +++ b/x/farming/types/keys.go @@ -1,6 +1,8 @@ package types import ( + "bytes" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/address" ) @@ -55,6 +57,14 @@ func GetStakingKey(stakingCoinDenom string, farmerAcc sdk.AccAddress) []byte { return append(append(StakingKeyPrefix, LengthPrefixString(stakingCoinDenom)...), farmerAcc...) } +func GetStakingIndexKey(farmerAcc sdk.AccAddress, stakingCoinDenom string) []byte { + return append(append(StakingIndexKeyPrefix, address.MustLengthPrefix(farmerAcc)...), []byte(stakingCoinDenom)...) +} + +func GetStakingsByFarmerPrefix(farmerAcc sdk.AccAddress) []byte { + return append(StakingIndexKeyPrefix, address.MustLengthPrefix(farmerAcc)...) +} + func GetQueuedStakingKey(stakingCoinDenom string, farmerAcc sdk.AccAddress) []byte { return append(append(QueuedStakingKeyPrefix, LengthPrefixString(stakingCoinDenom)...), farmerAcc...) } @@ -71,7 +81,20 @@ func GetCurrentRewardsKey(stakingCoinDenom string) []byte { return append(CurrentRewardsKeyPrefix, []byte(stakingCoinDenom)...) } +func ParseStakingIndexKey(key []byte) (farmerAcc sdk.AccAddress, stakingCoinDenom string) { + if !bytes.HasPrefix(key, StakingIndexKeyPrefix) { + panic("key does not have proper prefix") + } + addrLen := key[1] + farmerAcc = key[2 : 2+addrLen] + stakingCoinDenom = string(key[2+addrLen:]) + return +} + func ParseQueuedStakingKey(key []byte) (stakingCoinDenom string, farmerAcc sdk.AccAddress) { + if !bytes.HasPrefix(key, QueuedStakingKeyPrefix) { + panic("key does not have proper prefix") + } denomLen := key[1] stakingCoinDenom = string(key[2 : 2+denomLen]) farmerAcc = key[2+denomLen:] From c610b4a9d96cb0be630036eb7e32390c42b05b2f Mon Sep 17 00:00:00 2001 From: Hanjun Kim Date: Wed, 8 Sep 2021 16:33:20 +0900 Subject: [PATCH 04/16] chore: minor changes --- x/farming/keeper/simulation_test.go | 16 +--------------- x/farming/keeper/staking.go | 2 ++ 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/x/farming/keeper/simulation_test.go b/x/farming/keeper/simulation_test.go index a1c8ddc7..d0eb5add 100644 --- a/x/farming/keeper/simulation_test.go +++ b/x/farming/keeper/simulation_test.go @@ -66,19 +66,6 @@ func (ba BalanceAssertion) Do(suite *KeeperTestSuite) { suite.Require().True(intEq(ba.amount, balance.Amount)) } -type RewardsAssertion struct { - acc sdk.AccAddress - stakingCoinDenom string - rewards sdk.Coins -} - -func (ra RewardsAssertion) Do(suite *KeeperTestSuite) { - current := suite.keeper.GetCurrentRewards(suite.ctx, ra.stakingCoinDenom) - rewards := suite.keeper.CalculateRewards(suite.ctx, ra.acc, ra.stakingCoinDenom, current.Epoch-1) - fmt.Printf("RewardsAssertion(%s, %s, %s)\n", ra.acc, ra.stakingCoinDenom, ra.rewards) - suite.Require().True(coinsEq(ra.rewards, rewards)) -} - type TotalRewardsAssertion struct { acc sdk.AccAddress rewards sdk.Coins @@ -140,7 +127,6 @@ func (suite *KeeperTestSuite) TestSimulation() { AdvanceEpochAction{}, BalanceAssertion{addrs[0], denom3, sdk.ZeroInt()}, - RewardsAssertion{addrs[0], denom1, sdk.NewCoins(sdk.NewInt64Coin(denom3, 200000))}, TotalRewardsAssertion{addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom3, 200000))}, BalanceAssertion{addrs[1], denom3, sdk.ZeroInt()}, TotalRewardsAssertion{addrs[1], sdk.NewCoins(sdk.NewInt64Coin(denom3, 800000))}, @@ -148,7 +134,7 @@ func (suite *KeeperTestSuite) TestSimulation() { StakeAction{addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom1, 500000))}, AdvanceEpochAction{}, BalanceAssertion{addrs[0], denom3, sdk.NewInt(400000)}, - TotalRewardsAssertion{addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom3, 0))}, + TotalRewardsAssertion{addrs[0], sdk.NewCoins()}, BalanceAssertion{addrs[1], denom3, sdk.ZeroInt()}, TotalRewardsAssertion{addrs[1], sdk.NewCoins(sdk.NewInt64Coin(denom3, 1600000))}, diff --git a/x/farming/keeper/staking.go b/x/farming/keeper/staking.go index 0276886a..ab05044c 100644 --- a/x/farming/keeper/staking.go +++ b/x/farming/keeper/staking.go @@ -220,6 +220,8 @@ func (k Keeper) Stake(ctx sdk.Context, farmerAcc sdk.AccAddress, amount sdk.Coin // Unstake unstakes an amount of staking coins from the staking reserve account. func (k Keeper) Unstake(ctx sdk.Context, farmerAcc sdk.AccAddress, amount sdk.Coins) error { + // TODO: send coins at once, not in every WithdrawRewards + for _, coin := range amount { staking, found := k.GetStaking(ctx, coin.Denom, farmerAcc) if !found { From b22a0e0a179e423f1f7cc034a69df6b21f7a390b Mon Sep 17 00:00:00 2001 From: Hanjun Kim Date: Wed, 8 Sep 2021 16:49:49 +0900 Subject: [PATCH 05/16] chore: update simulation --- x/farming/keeper/simulation_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/x/farming/keeper/simulation_test.go b/x/farming/keeper/simulation_test.go index d0eb5add..1c220852 100644 --- a/x/farming/keeper/simulation_test.go +++ b/x/farming/keeper/simulation_test.go @@ -138,7 +138,9 @@ func (suite *KeeperTestSuite) TestSimulation() { BalanceAssertion{addrs[1], denom3, sdk.ZeroInt()}, TotalRewardsAssertion{addrs[1], sdk.NewCoins(sdk.NewInt64Coin(denom3, 1600000))}, - UnstakeAction{addrs[1], sdk.NewCoins(sdk.NewInt64Coin(denom1, 250000), sdk.NewInt64Coin(denom2, 250000))}, + // User can unstake multiple times before the end of the epoch + UnstakeAction{addrs[1], sdk.NewCoins(sdk.NewInt64Coin(denom1, 200000), sdk.NewInt64Coin(denom2, 200000))}, + UnstakeAction{addrs[1], sdk.NewCoins(sdk.NewInt64Coin(denom1, 50000), sdk.NewInt64Coin(denom2, 50000))}, BalanceAssertion{addrs[1], denom3, sdk.NewInt(1600000)}, TotalRewardsAssertion{addrs[1], sdk.NewCoins()}, AdvanceEpochAction{}, @@ -147,8 +149,11 @@ func (suite *KeeperTestSuite) TestSimulation() { BalanceAssertion{addrs[1], denom3, sdk.NewInt(1600000)}, TotalRewardsAssertion{addrs[1], sdk.NewCoins(sdk.NewInt64Coin(denom3, 742857))}, // 300000 * (1/7) + 700000 + // User can harvest multiple times, and it does not affect the rewards HarvestAction{addrs[0], []string{denom1}}, HarvestAction{addrs[1], []string{denom1, denom2}}, + HarvestAction{addrs[1], []string{denom1, denom2}}, + HarvestAction{addrs[1], []string{denom1, denom2}}, BalanceAssertion{addrs[0], denom3, sdk.NewInt(657142)}, BalanceAssertion{addrs[1], denom3, sdk.NewInt(2342857)}, TotalRewardsAssertion{addrs[0], sdk.NewCoins()}, From 11e38d37fab97508739a244a0369091bc70c2b90 Mon Sep 17 00:00:00 2001 From: Hanjun Kim Date: Thu, 9 Sep 2021 12:54:11 +0900 Subject: [PATCH 06/16] refactor: change proto messages --- .../tendermint/farming/v1beta1/farming.proto | 6 - .../tendermint/farming/v1beta1/genesis.proto | 62 +- x/farming/keeper/simulation_test.go | 10 +- x/farming/types/farming.pb.go | 284 +--- x/farming/types/genesis.pb.go | 1424 +++++++++++++++-- 5 files changed, 1402 insertions(+), 384 deletions(-) diff --git a/proto/tendermint/farming/v1beta1/farming.proto b/proto/tendermint/farming/v1beta1/farming.proto index 2c63f29c..81d861c0 100644 --- a/proto/tendermint/farming/v1beta1/farming.proto +++ b/proto/tendermint/farming/v1beta1/farming.proto @@ -163,10 +163,4 @@ message HistoricalRewards { (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins", (gogoproto.nullable) = false ]; -} - -message CurrentRewards { - option (gogoproto.goproto_getters) = false; - - uint64 epoch = 1; } \ No newline at end of file diff --git a/proto/tendermint/farming/v1beta1/genesis.proto b/proto/tendermint/farming/v1beta1/genesis.proto index 3ab3a4fc..8da7a77b 100644 --- a/proto/tendermint/farming/v1beta1/genesis.proto +++ b/proto/tendermint/farming/v1beta1/genesis.proto @@ -23,12 +23,21 @@ message GenesisState { // plan_records defines the plan records used for genesis state repeated PlanRecord plan_records = 2 [(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"plan_records\""]; - // stakings defines the staking records used for genesis state - repeated Staking stakings = 3 [(gogoproto.nullable) = false]; + repeated StakingRecord staking_records = 3 + [(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"staking_records\""]; + + repeated QueuedStakingRecord queued_staking_records = 4 + [(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"queued_staking_records\""]; + + repeated HistoricalRewardsRecord historical_rewards_records = 5 + [(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"historical_rewards_records\""]; + + repeated CurrentEpochRecord current_epoch_records = 6 + [(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"current_epoch_records\""]; // staking_reserve_coins specifies balance of the staking reserve pool staked in the plans // this param is needed for import/export validation - repeated cosmos.base.v1beta1.Coin staking_reserve_coins = 5 [ + repeated cosmos.base.v1beta1.Coin staking_reserve_coins = 7 [ (gogoproto.moretags) = "yaml:\"staking_reserve_coins\"", (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", (gogoproto.nullable) = false @@ -36,14 +45,14 @@ message GenesisState { // reward_pool_coins specifies balance of the reward pool to be distributed in the plans // this param is needed for import/export validation - repeated cosmos.base.v1beta1.Coin reward_pool_coins = 6 [ + repeated cosmos.base.v1beta1.Coin reward_pool_coins = 8 [ (gogoproto.moretags) = "yaml:\"reward_pool_coins\"", (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", (gogoproto.nullable) = false ]; // global_last_epoch_time specifies the last executed epoch time of the plans - google.protobuf.Timestamp global_last_epoch_time = 7 [ + google.protobuf.Timestamp global_last_epoch_time = 9 [ (gogoproto.stdtime) = true, (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"global_last_epoch_time\"" @@ -74,3 +83,46 @@ message PlanRecord { (gogoproto.nullable) = false ]; } + +message StakingRecord { + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + string staking_coin_denom = 1 [(gogoproto.moretags) = "yaml:\"staking_coin_denom\""]; + + string farmer = 2; + + Staking staking = 3 [(gogoproto.nullable) = false]; +} + +message QueuedStakingRecord { + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + string staking_coin_denom = 1 [(gogoproto.moretags) = "yaml:\"staking_coin_denom\""]; + + string farmer = 2; + + QueuedStaking queued_staking = 3 [(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"queued_staking\""]; +} + +message HistoricalRewardsRecord { + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + string staking_coin_denom = 1 [(gogoproto.moretags) = "yaml:\"staking_coin_denom\""]; + + uint64 epoch = 2; + + HistoricalRewards historical_rewards = 3 + [(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"historical_rewards\""]; +} + +message CurrentEpochRecord { + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + string staking_coin_denom = 1 [(gogoproto.moretags) = "yaml:\"staking_coin_denom\""]; + + uint64 current_epoch = 2 [(gogoproto.moretags) = "yaml:\"current_epoch\""]; +} diff --git a/x/farming/keeper/simulation_test.go b/x/farming/keeper/simulation_test.go index 1c220852..1a828777 100644 --- a/x/farming/keeper/simulation_test.go +++ b/x/farming/keeper/simulation_test.go @@ -91,8 +91,8 @@ func (suite *KeeperTestSuite) TestSimulation() { suite.addrs[0].String(), suite.addrs[0].String(), sdk.NewDecCoins( - sdk.NewDecCoinFromDec(denom1, sdk.NewDecWithPrec(3, 1)), - sdk.NewDecCoinFromDec(denom2, sdk.NewDecWithPrec(7, 1)), + sdk.NewDecCoinFromDec(denom1, sdk.NewDecWithPrec(3, 1)), // 30% + sdk.NewDecCoinFromDec(denom2, sdk.NewDecWithPrec(7, 1)), // 70% ), mustParseRFC3339("0001-01-01T00:00:00Z"), mustParseRFC3339("9999-12-31T00:00:00Z"), @@ -127,9 +127,9 @@ func (suite *KeeperTestSuite) TestSimulation() { AdvanceEpochAction{}, BalanceAssertion{addrs[0], denom3, sdk.ZeroInt()}, - TotalRewardsAssertion{addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom3, 200000))}, + TotalRewardsAssertion{addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom3, 200000))}, // 300000 * 2/3 BalanceAssertion{addrs[1], denom3, sdk.ZeroInt()}, - TotalRewardsAssertion{addrs[1], sdk.NewCoins(sdk.NewInt64Coin(denom3, 800000))}, + TotalRewardsAssertion{addrs[1], sdk.NewCoins(sdk.NewInt64Coin(denom3, 800000))}, // 300000 * 1/3 + 700000 StakeAction{addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom1, 500000))}, AdvanceEpochAction{}, @@ -141,6 +141,7 @@ func (suite *KeeperTestSuite) TestSimulation() { // User can unstake multiple times before the end of the epoch UnstakeAction{addrs[1], sdk.NewCoins(sdk.NewInt64Coin(denom1, 200000), sdk.NewInt64Coin(denom2, 200000))}, UnstakeAction{addrs[1], sdk.NewCoins(sdk.NewInt64Coin(denom1, 50000), sdk.NewInt64Coin(denom2, 50000))}, + // 250000denom1, 250000denom2 BalanceAssertion{addrs[1], denom3, sdk.NewInt(1600000)}, TotalRewardsAssertion{addrs[1], sdk.NewCoins()}, AdvanceEpochAction{}, @@ -148,6 +149,7 @@ func (suite *KeeperTestSuite) TestSimulation() { TotalRewardsAssertion{addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom3, 257142))}, // 300000 * (6/7) BalanceAssertion{addrs[1], denom3, sdk.NewInt(1600000)}, TotalRewardsAssertion{addrs[1], sdk.NewCoins(sdk.NewInt64Coin(denom3, 742857))}, // 300000 * (1/7) + 700000 + // 1000000 => 999999 // User can harvest multiple times, and it does not affect the rewards HarvestAction{addrs[0], []string{denom1}}, diff --git a/x/farming/types/farming.pb.go b/x/farming/types/farming.pb.go index c3cce324..573f9f39 100644 --- a/x/farming/types/farming.pb.go +++ b/x/farming/types/farming.pb.go @@ -400,43 +400,6 @@ func (m *HistoricalRewards) XXX_DiscardUnknown() { var xxx_messageInfo_HistoricalRewards proto.InternalMessageInfo -type CurrentRewards struct { - Epoch uint64 `protobuf:"varint,1,opt,name=epoch,proto3" json:"epoch,omitempty"` -} - -func (m *CurrentRewards) Reset() { *m = CurrentRewards{} } -func (m *CurrentRewards) String() string { return proto.CompactTextString(m) } -func (*CurrentRewards) ProtoMessage() {} -func (*CurrentRewards) Descriptor() ([]byte, []int) { - return fileDescriptor_5b657e0809d9de86, []int{8} -} -func (m *CurrentRewards) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *CurrentRewards) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_CurrentRewards.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 *CurrentRewards) XXX_Merge(src proto.Message) { - xxx_messageInfo_CurrentRewards.Merge(m, src) -} -func (m *CurrentRewards) XXX_Size() int { - return m.Size() -} -func (m *CurrentRewards) XXX_DiscardUnknown() { - xxx_messageInfo_CurrentRewards.DiscardUnknown(m) -} - -var xxx_messageInfo_CurrentRewards proto.InternalMessageInfo - func init() { proto.RegisterEnum("cosmos.farming.v1beta1.PlanType", PlanType_name, PlanType_value) proto.RegisterType((*Params)(nil), "cosmos.farming.v1beta1.Params") @@ -447,7 +410,6 @@ func init() { proto.RegisterType((*QueuedStaking)(nil), "cosmos.farming.v1beta1.QueuedStaking") proto.RegisterType((*TotalStaking)(nil), "cosmos.farming.v1beta1.TotalStaking") proto.RegisterType((*HistoricalRewards)(nil), "cosmos.farming.v1beta1.HistoricalRewards") - proto.RegisterType((*CurrentRewards)(nil), "cosmos.farming.v1beta1.CurrentRewards") } func init() { @@ -455,78 +417,77 @@ func init() { } var fileDescriptor_5b657e0809d9de86 = []byte{ - // 1135 bytes of a gzipped FileDescriptorProto + // 1114 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0x4f, 0x6f, 0x1b, 0x45, - 0x14, 0xf7, 0xb8, 0x4e, 0x62, 0x8f, 0x9b, 0xc4, 0x9e, 0xfc, 0x61, 0xe3, 0xb6, 0xde, 0xd5, 0x4a, - 0x20, 0x2b, 0x10, 0x5b, 0x0d, 0x3d, 0xe5, 0x44, 0xec, 0x24, 0xc5, 0x52, 0x14, 0xdc, 0xad, 0x43, - 0x01, 0x81, 0x56, 0x63, 0xef, 0xc4, 0x59, 0x75, 0xbd, 0x6b, 0xed, 0xcc, 0x26, 0xcd, 0x07, 0x40, + 0x14, 0xf7, 0xb8, 0x6e, 0x62, 0x8f, 0x9b, 0xc4, 0x9e, 0xfc, 0x61, 0xe3, 0xb6, 0xde, 0xd5, 0x4a, + 0x20, 0x2b, 0x28, 0xb6, 0x1a, 0x7a, 0xca, 0x89, 0x38, 0x7f, 0x8a, 0xa5, 0x28, 0xb8, 0x5b, 0x87, + 0x02, 0x02, 0xad, 0xc6, 0xde, 0x89, 0xb3, 0xea, 0x7a, 0xc7, 0xda, 0x19, 0x27, 0xcd, 0x07, 0x40, 0xaa, 0x72, 0xaa, 0x10, 0x07, 0x2e, 0x41, 0x15, 0xdc, 0xca, 0x95, 0xef, 0x40, 0x25, 0x2e, 0x11, 0x12, 0x12, 0xe2, 0xb0, 0x45, 0xc9, 0x37, 0xf0, 0x99, 0x03, 0xda, 0x99, 0x59, 0x67, 0x11, 0x0e, - 0x69, 0xa4, 0xf6, 0xb4, 0x3b, 0x6f, 0x7e, 0xf3, 0x7b, 0xbf, 0xf7, 0xe6, 0xbd, 0xb7, 0x0b, 0x2b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xa4, 0xca, 0x18, + 0x87, 0x13, 0x8d, 0xd1, 0xfb, 0x6f, 0x30, 0x46, 0x0a, 0x92, 0x59, 0x48, 0xa1, 0x44, 0xa7, 0xc7, + 0x12, 0x03, 0x7d, 0x0a, 0x21, 0xe3, 0x38, 0xe0, 0x76, 0x24, 0x0b, 0x6d, 0xd2, 0x00, 0x95, 0xfc, + 0x4a, 0xa9, 0x2a, 0x35, 0x53, 0x8d, 0x35, 0x53, 0x6d, 0xc5, 0x9a, 0xa9, 0xdf, 0x55, 0xbc, 0x8a, + 0x23, 0x5e, 0x2a, 0xd6, 0x7c, 0xfe, 0x5a, 0x07, 0x56, 0x4e, 0x18, 0x22, 0x77, 0x64, 0xc1, 0x2c, + 0xf1, 0x1d, 0x89, 0x9b, 0xbd, 0x12, 0xf7, 0xb6, 0xc2, 0x9d, 0x51, 0xd3, 0xab, 0x22, 0x25, 0xea, + 0x24, 0xf1, 0x1d, 0x81, 0x59, 0x86, 0x30, 0x6e, 0x34, 0x71, 0xb4, 0x9c, 0x01, 0x2a, 0x59, 0x2b, + 0x61, 0x41, 0x87, 0x70, 0xc1, 0xc3, 0x8c, 0xdb, 0x8e, 0xcb, 0x78, 0xe0, 0xb6, 0x07, 0xe2, 0x25, + 0x09, 0x06, 0xf0, 0x4a, 0x06, 0xef, 0x0e, 0x43, 0xfd, 0xae, 0xcc, 0x3e, 0x1e, 0x43, 0x72, 0x99, + 0x8b, 0x2e, 0x37, 0x12, 0x77, 0x82, 0xd8, 0x37, 0x00, 0x16, 0x47, 0x01, 0xc4, 0x11, 0xef, 0x89, + 0x69, 0xf9, 0xab, 0x36, 0xc6, 0xb6, 0xaa, 0x5a, 0x93, 0x79, 0xff, 0x85, 0x70, 0xbd, 0x4d, 0x51, + 0x48, 0xc4, 0x0b, 0xcb, 0x6a, 0x31, 0xd6, 0xe5, 0xaf, 0x3f, 0x2d, 0xdf, 0x8c, 0x24, 0xd4, 0x30, + 0xff, 0x02, 0x70, 0x66, 0xcb, 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cf, + 0xcb, 0xa9, 0xd3, 0xf3, 0x72, 0xea, 0xf7, 0xf3, 0x72, 0xea, 0xf3, 0xe5, 0x44, 0xe1, 0x63, 0x3e, + 0x2d, 0x9f, 0x8e, 0x9e, 0x44, 0x0f, 0xda, 0x13, 0x62, 0xad, 0x7f, 0xf0, 0x77, 0x00, 0x00, 0x00, + 0xff, 0xff, 0xf2, 0x14, 0x99, 0x82, 0x87, 0x0a, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -931,34 +892,6 @@ func (m *HistoricalRewards) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *CurrentRewards) 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 *CurrentRewards) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *CurrentRewards) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Epoch != 0 { - i = encodeVarintFarming(dAtA, i, uint64(m.Epoch)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - func encodeVarintFarming(dAtA []byte, offset int, v uint64) int { offset -= sovFarming(v) base := offset @@ -1127,18 +1060,6 @@ func (m *HistoricalRewards) Size() (n int) { return n } -func (m *CurrentRewards) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Epoch != 0 { - n += 1 + sovFarming(uint64(m.Epoch)) - } - return n -} - func sovFarming(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -2249,75 +2170,6 @@ func (m *HistoricalRewards) Unmarshal(dAtA []byte) error { } return nil } -func (m *CurrentRewards) 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 ErrIntOverflowFarming - } - 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: CurrentRewards: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: CurrentRewards: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Epoch", wireType) - } - m.Epoch = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowFarming - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Epoch |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipFarming(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthFarming - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func skipFarming(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/farming/types/genesis.pb.go b/x/farming/types/genesis.pb.go index c8a9c947..ad428f0d 100644 --- a/x/farming/types/genesis.pb.go +++ b/x/farming/types/genesis.pb.go @@ -36,17 +36,19 @@ type GenesisState struct { // params defines all the parameters for the farming module Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` // plan_records defines the plan records used for genesis state - PlanRecords []PlanRecord `protobuf:"bytes,2,rep,name=plan_records,json=planRecords,proto3" json:"plan_records" yaml:"plan_records"` - // stakings defines the staking records used for genesis state - Stakings []Staking `protobuf:"bytes,3,rep,name=stakings,proto3" json:"stakings"` + PlanRecords []PlanRecord `protobuf:"bytes,2,rep,name=plan_records,json=planRecords,proto3" json:"plan_records" yaml:"plan_records"` + StakingRecords []StakingRecord `protobuf:"bytes,3,rep,name=staking_records,json=stakingRecords,proto3" json:"staking_records" yaml:"staking_records"` + QueuedStakingRecords []QueuedStakingRecord `protobuf:"bytes,4,rep,name=queued_staking_records,json=queuedStakingRecords,proto3" json:"queued_staking_records" yaml:"queued_staking_records"` + HistoricalRewardsRecords []HistoricalRewardsRecord `protobuf:"bytes,5,rep,name=historical_rewards_records,json=historicalRewardsRecords,proto3" json:"historical_rewards_records" yaml:"historical_rewards_records"` + CurrentEpochRecords []CurrentEpochRecord `protobuf:"bytes,6,rep,name=current_epoch_records,json=currentEpochRecords,proto3" json:"current_epoch_records" yaml:"current_epoch_records"` // staking_reserve_coins specifies balance of the staking reserve pool staked in the plans // this param is needed for import/export validation - StakingReserveCoins github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,5,rep,name=staking_reserve_coins,json=stakingReserveCoins,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"staking_reserve_coins" yaml:"staking_reserve_coins"` + StakingReserveCoins github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,7,rep,name=staking_reserve_coins,json=stakingReserveCoins,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"staking_reserve_coins" yaml:"staking_reserve_coins"` // reward_pool_coins specifies balance of the reward pool to be distributed in the plans // this param is needed for import/export validation - RewardPoolCoins github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,6,rep,name=reward_pool_coins,json=rewardPoolCoins,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"reward_pool_coins" yaml:"reward_pool_coins"` + RewardPoolCoins github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,8,rep,name=reward_pool_coins,json=rewardPoolCoins,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"reward_pool_coins" yaml:"reward_pool_coins"` // global_last_epoch_time specifies the last executed epoch time of the plans - GlobalLastEpochTime time.Time `protobuf:"bytes,7,opt,name=global_last_epoch_time,json=globalLastEpochTime,proto3,stdtime" json:"global_last_epoch_time" yaml:"global_last_epoch_time"` + GlobalLastEpochTime time.Time `protobuf:"bytes,9,opt,name=global_last_epoch_time,json=globalLastEpochTime,proto3,stdtime" json:"global_last_epoch_time" yaml:"global_last_epoch_time"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -127,9 +129,168 @@ func (m *PlanRecord) XXX_DiscardUnknown() { var xxx_messageInfo_PlanRecord proto.InternalMessageInfo +type StakingRecord struct { + StakingCoinDenom string `protobuf:"bytes,1,opt,name=staking_coin_denom,json=stakingCoinDenom,proto3" json:"staking_coin_denom,omitempty" yaml:"staking_coin_denom"` + Farmer string `protobuf:"bytes,2,opt,name=farmer,proto3" json:"farmer,omitempty"` + Staking Staking `protobuf:"bytes,3,opt,name=staking,proto3" json:"staking"` +} + +func (m *StakingRecord) Reset() { *m = StakingRecord{} } +func (m *StakingRecord) String() string { return proto.CompactTextString(m) } +func (*StakingRecord) ProtoMessage() {} +func (*StakingRecord) Descriptor() ([]byte, []int) { + return fileDescriptor_c67612b66bcd2967, []int{2} +} +func (m *StakingRecord) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *StakingRecord) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_StakingRecord.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 *StakingRecord) XXX_Merge(src proto.Message) { + xxx_messageInfo_StakingRecord.Merge(m, src) +} +func (m *StakingRecord) XXX_Size() int { + return m.Size() +} +func (m *StakingRecord) XXX_DiscardUnknown() { + xxx_messageInfo_StakingRecord.DiscardUnknown(m) +} + +var xxx_messageInfo_StakingRecord proto.InternalMessageInfo + +type QueuedStakingRecord struct { + StakingCoinDenom string `protobuf:"bytes,1,opt,name=staking_coin_denom,json=stakingCoinDenom,proto3" json:"staking_coin_denom,omitempty" yaml:"staking_coin_denom"` + Farmer string `protobuf:"bytes,2,opt,name=farmer,proto3" json:"farmer,omitempty"` + QueuedStaking QueuedStaking `protobuf:"bytes,3,opt,name=queued_staking,json=queuedStaking,proto3" json:"queued_staking" yaml:"queued_staking"` +} + +func (m *QueuedStakingRecord) Reset() { *m = QueuedStakingRecord{} } +func (m *QueuedStakingRecord) String() string { return proto.CompactTextString(m) } +func (*QueuedStakingRecord) ProtoMessage() {} +func (*QueuedStakingRecord) Descriptor() ([]byte, []int) { + return fileDescriptor_c67612b66bcd2967, []int{3} +} +func (m *QueuedStakingRecord) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueuedStakingRecord) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueuedStakingRecord.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 *QueuedStakingRecord) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueuedStakingRecord.Merge(m, src) +} +func (m *QueuedStakingRecord) XXX_Size() int { + return m.Size() +} +func (m *QueuedStakingRecord) XXX_DiscardUnknown() { + xxx_messageInfo_QueuedStakingRecord.DiscardUnknown(m) +} + +var xxx_messageInfo_QueuedStakingRecord proto.InternalMessageInfo + +type HistoricalRewardsRecord struct { + StakingCoinDenom string `protobuf:"bytes,1,opt,name=staking_coin_denom,json=stakingCoinDenom,proto3" json:"staking_coin_denom,omitempty" yaml:"staking_coin_denom"` + Epoch uint64 `protobuf:"varint,2,opt,name=epoch,proto3" json:"epoch,omitempty"` + HistoricalRewards HistoricalRewards `protobuf:"bytes,3,opt,name=historical_rewards,json=historicalRewards,proto3" json:"historical_rewards" yaml:"historical_rewards"` +} + +func (m *HistoricalRewardsRecord) Reset() { *m = HistoricalRewardsRecord{} } +func (m *HistoricalRewardsRecord) String() string { return proto.CompactTextString(m) } +func (*HistoricalRewardsRecord) ProtoMessage() {} +func (*HistoricalRewardsRecord) Descriptor() ([]byte, []int) { + return fileDescriptor_c67612b66bcd2967, []int{4} +} +func (m *HistoricalRewardsRecord) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *HistoricalRewardsRecord) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_HistoricalRewardsRecord.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 *HistoricalRewardsRecord) XXX_Merge(src proto.Message) { + xxx_messageInfo_HistoricalRewardsRecord.Merge(m, src) +} +func (m *HistoricalRewardsRecord) XXX_Size() int { + return m.Size() +} +func (m *HistoricalRewardsRecord) XXX_DiscardUnknown() { + xxx_messageInfo_HistoricalRewardsRecord.DiscardUnknown(m) +} + +var xxx_messageInfo_HistoricalRewardsRecord proto.InternalMessageInfo + +type CurrentEpochRecord struct { + StakingCoinDenom string `protobuf:"bytes,1,opt,name=staking_coin_denom,json=stakingCoinDenom,proto3" json:"staking_coin_denom,omitempty" yaml:"staking_coin_denom"` + CurrentEpoch uint64 `protobuf:"varint,2,opt,name=current_epoch,json=currentEpoch,proto3" json:"current_epoch,omitempty" yaml:"current_epoch"` +} + +func (m *CurrentEpochRecord) Reset() { *m = CurrentEpochRecord{} } +func (m *CurrentEpochRecord) String() string { return proto.CompactTextString(m) } +func (*CurrentEpochRecord) ProtoMessage() {} +func (*CurrentEpochRecord) Descriptor() ([]byte, []int) { + return fileDescriptor_c67612b66bcd2967, []int{5} +} +func (m *CurrentEpochRecord) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *CurrentEpochRecord) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_CurrentEpochRecord.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 *CurrentEpochRecord) XXX_Merge(src proto.Message) { + xxx_messageInfo_CurrentEpochRecord.Merge(m, src) +} +func (m *CurrentEpochRecord) XXX_Size() int { + return m.Size() +} +func (m *CurrentEpochRecord) XXX_DiscardUnknown() { + xxx_messageInfo_CurrentEpochRecord.DiscardUnknown(m) +} + +var xxx_messageInfo_CurrentEpochRecord proto.InternalMessageInfo + func init() { proto.RegisterType((*GenesisState)(nil), "cosmos.farming.v1beta1.GenesisState") proto.RegisterType((*PlanRecord)(nil), "cosmos.farming.v1beta1.PlanRecord") + proto.RegisterType((*StakingRecord)(nil), "cosmos.farming.v1beta1.StakingRecord") + proto.RegisterType((*QueuedStakingRecord)(nil), "cosmos.farming.v1beta1.QueuedStakingRecord") + proto.RegisterType((*HistoricalRewardsRecord)(nil), "cosmos.farming.v1beta1.HistoricalRewardsRecord") + proto.RegisterType((*CurrentEpochRecord)(nil), "cosmos.farming.v1beta1.CurrentEpochRecord") } func init() { @@ -137,45 +298,65 @@ func init() { } var fileDescriptor_c67612b66bcd2967 = []byte{ - // 596 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x94, 0x3f, 0x6f, 0xd3, 0x40, - 0x18, 0xc6, 0xed, 0xa6, 0x0d, 0xd5, 0xa5, 0x08, 0x70, 0x4a, 0xe5, 0x04, 0xb0, 0x2b, 0x4f, 0x61, - 0x88, 0xad, 0x96, 0x01, 0xa9, 0x62, 0xa9, 0x11, 0x42, 0x88, 0x22, 0x45, 0x2e, 0x13, 0x8b, 0x75, - 0x4e, 0xae, 0xae, 0x55, 0xfb, 0xce, 0xf2, 0x5d, 0x0b, 0xe1, 0x13, 0x20, 0xa6, 0x4a, 0x48, 0xac, - 0x74, 0x44, 0x6c, 0x48, 0x7c, 0x88, 0x8a, 0xa9, 0x23, 0x53, 0x8b, 0x92,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x65, 0xed, 0x9e, 0xb4, 0x36, 0x9b, 0xe3, - 0x1c, 0x5f, 0xd8, 0x7a, 0x50, 0x97, 0xc5, 0x1d, 0x48, 0xd9, 0x13, 0x5e, 0xe2, 0x90, 0xad, 0xe5, - 0x77, 0x27, 0xb6, 0xf6, 0xeb, 0xc4, 0xd6, 0x9c, 0xf7, 0x15, 0x00, 0xc6, 0xc9, 0x31, 0x1e, 0x82, - 0x45, 0x1e, 0x0f, 0x95, 0xd7, 0xd5, 0x29, 0x0b, 0xdb, 0xb8, 0xef, 0x5f, 0xe7, 0x9b, 0x7f, 0xff, - 0xd6, 0x5e, 0xe2, 0x7d, 0xcf, 0x02, 0xd1, 0x60, 0x7c, 0xd4, 0x81, 0xa1, 0x12, 0x33, 0x39, 0xe4, - 0x85, 0xcb, 0x86, 0xfc, 0x42, 0x9d, 0xa4, 0x21, 0x4f, 0x32, 0x8d, 0xb8, 0xda, 0x94, 0x6f, 0x2a, - 0xc0, 0x78, 0xcc, 0xf3, 0xe3, 0x59, 0xf9, 0x3f, 0xe2, 0x39, 0xbe, 0x0c, 0xff, 0xf9, 0xe7, 0x81, - 0xa5, 0x9f, 0x0e, 0x2c, 0xfd, 0x6c, 0x60, 0xe9, 0x3f, 0x07, 0x96, 0x7e, 0x3c, 0xb4, 0xb4, 0xb3, - 0xa1, 0xa5, 0xfd, 0x18, 0x5a, 0xda, 0xab, 0xf6, 0xc4, 0x36, 0x33, 0x7e, 0x5a, 0x6f, 0xca, 0x95, - 0xd8, 0x31, 0xaa, 0x8a, 0x4b, 0x7b, 0xf0, 0x27, 0x00, 0x00, 0xff, 0xff, 0x49, 0x30, 0x39, 0x87, - 0x8f, 0x05, 0x00, 0x00, + // 919 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x56, 0xcf, 0x6f, 0xdc, 0x44, + 0x14, 0xde, 0xc9, 0x26, 0x69, 0x33, 0x49,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01, 0xec, + 0x35, 0xf4, 0xe0, 0xff, 0x26, 0x8e, 0x7d, 0x78, 0x6e, 0xb6, 0xb9, 0xeb, 0x70, 0xb6, 0x9e, 0x69, + 0x5a, 0x78, 0x9b, 0xfa, 0xba, 0xd7, 0x9a, 0xe6, 0x84, 0x8d, 0x57, 0x67, 0xe6, 0x43, 0x25, 0xe6, + 0x6f, 0xe6, 0xe0, 0x4b, 0x2d, 0x8d, 0xfe, 0xc5, 0xc6, 0xdd, 0x87, 0x0b, 0xb2, 0xba, 0x65, 0xd8, + 0xf3, 0x58, 0x2d, 0xd0, 0xd7, 0x10, 0xd5, 0xe7, 0x87, 0x8e, 0xfc, 0xca, 0x33, 0x0f, 0x26, 0xef, + 0xf2, 0x6c, 0x21, 0xd6, 0x21, 0x6d, 0x7c, 0xb1, 0x36, 0x8a, 0x2a, 0x59, 0x78, 0x08, 0x20, 0xaa, + 0x0f, 0x96, 0x17, 0x9b, 0x80, 0xb7, 0xe1, 0xea, 0xcc, 0x64, 0x52, 0x89, 0xf0, 0x8c, 0xa7, 0x87, + 0x56, 0xbf, 0x61, 0x70, 0xd9, 0x78, 0xa5, 0x3a, 0xb0, 0xa6, 0x62, 0xbd, 0x1b, 0xbf, 0x1c, 0x99, + 0xe0, 0xd1, 0x91, 0x09, 0x1e, 0x1f, 0x99, 0xe0, 0xcf, 0x23, 0x13, 0xdc, 0x3f, 0x36, 0x3b, 0x8f, + 0x8f, 0xcd, 0xce, 0x1f, 0xc7, 0x66, 0xe7, 0xf3, 0x9d, 0x4a, 0x3d, 0x37, 0xfc, 0xef, 0xfb, 0xb2, + 0xfc, 0x92, 0xa5, 0x3d, 0x5c, 0x94, 0xdd, 0xf1, 0x8d, 0x7f, 0x02, 0x00, 0x00, 0xff, 0xff, 0x6e, + 0xb1, 0x07, 0x4d, 0xd2, 0x0a, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -205,7 +386,7 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { i -= n1 i = encodeVarintGenesis(dAtA, i, uint64(n1)) i-- - dAtA[i] = 0x3a + dAtA[i] = 0x4a if len(m.RewardPoolCoins) > 0 { for iNdEx := len(m.RewardPoolCoins) - 1; iNdEx >= 0; iNdEx-- { { @@ -217,7 +398,7 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintGenesis(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x32 + dAtA[i] = 0x42 } } if len(m.StakingReserveCoins) > 0 { @@ -231,13 +412,55 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintGenesis(dAtA, i, uint64(size)) } i-- + dAtA[i] = 0x3a + } + } + if len(m.CurrentEpochRecords) > 0 { + for iNdEx := len(m.CurrentEpochRecords) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.CurrentEpochRecords[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x32 + } + } + if len(m.HistoricalRewardsRecords) > 0 { + for iNdEx := len(m.HistoricalRewardsRecords) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.HistoricalRewardsRecords[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- dAtA[i] = 0x2a } } - if len(m.Stakings) > 0 { - for iNdEx := len(m.Stakings) - 1; iNdEx >= 0; iNdEx-- { + if len(m.QueuedStakingRecords) > 0 { + for iNdEx := len(m.QueuedStakingRecords) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.QueuedStakingRecords[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } + } + if len(m.StakingRecords) > 0 { + for iNdEx := len(m.StakingRecords) - 1; iNdEx >= 0; iNdEx-- { { - size, err := m.Stakings[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + size, err := m.StakingRecords[iNdEx].MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -336,6 +559,180 @@ func (m *PlanRecord) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *StakingRecord) 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 *StakingRecord) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *StakingRecord) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Staking.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if len(m.Farmer) > 0 { + i -= len(m.Farmer) + copy(dAtA[i:], m.Farmer) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.Farmer))) + i-- + dAtA[i] = 0x12 + } + if len(m.StakingCoinDenom) > 0 { + i -= len(m.StakingCoinDenom) + copy(dAtA[i:], m.StakingCoinDenom) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.StakingCoinDenom))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueuedStakingRecord) 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 *QueuedStakingRecord) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueuedStakingRecord) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.QueuedStaking.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if len(m.Farmer) > 0 { + i -= len(m.Farmer) + copy(dAtA[i:], m.Farmer) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.Farmer))) + i-- + dAtA[i] = 0x12 + } + if len(m.StakingCoinDenom) > 0 { + i -= len(m.StakingCoinDenom) + copy(dAtA[i:], m.StakingCoinDenom) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.StakingCoinDenom))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *HistoricalRewardsRecord) 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 *HistoricalRewardsRecord) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *HistoricalRewardsRecord) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.HistoricalRewards.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if m.Epoch != 0 { + i = encodeVarintGenesis(dAtA, i, uint64(m.Epoch)) + i-- + dAtA[i] = 0x10 + } + if len(m.StakingCoinDenom) > 0 { + i -= len(m.StakingCoinDenom) + copy(dAtA[i:], m.StakingCoinDenom) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.StakingCoinDenom))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *CurrentEpochRecord) 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 *CurrentEpochRecord) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *CurrentEpochRecord) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.CurrentEpoch != 0 { + i = encodeVarintGenesis(dAtA, i, uint64(m.CurrentEpoch)) + i-- + dAtA[i] = 0x10 + } + if len(m.StakingCoinDenom) > 0 { + i -= len(m.StakingCoinDenom) + copy(dAtA[i:], m.StakingCoinDenom) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.StakingCoinDenom))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { offset -= sovGenesis(v) base := offset @@ -361,8 +758,26 @@ func (m *GenesisState) Size() (n int) { n += 1 + l + sovGenesis(uint64(l)) } } - if len(m.Stakings) > 0 { - for _, e := range m.Stakings { + if len(m.StakingRecords) > 0 { + for _, e := range m.StakingRecords { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.QueuedStakingRecords) > 0 { + for _, e := range m.QueuedStakingRecords { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.HistoricalRewardsRecords) > 0 { + for _, e := range m.HistoricalRewardsRecords { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.CurrentEpochRecords) > 0 { + for _, e := range m.CurrentEpochRecords { l = e.Size() n += 1 + l + sovGenesis(uint64(l)) } @@ -379,41 +794,618 @@ func (m *GenesisState) Size() (n int) { n += 1 + l + sovGenesis(uint64(l)) } } - l = github_com_gogo_protobuf_types.SizeOfStdTime(m.GlobalLastEpochTime) - n += 1 + l + sovGenesis(uint64(l)) - return n -} + l = github_com_gogo_protobuf_types.SizeOfStdTime(m.GlobalLastEpochTime) + n += 1 + l + sovGenesis(uint64(l)) + return n +} + +func (m *PlanRecord) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Plan.Size() + n += 1 + l + sovGenesis(uint64(l)) + if len(m.FarmingPoolCoins) > 0 { + for _, e := range m.FarmingPoolCoins { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.StakingReserveCoins) > 0 { + for _, e := range m.StakingReserveCoins { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + return n +} + +func (m *StakingRecord) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.StakingCoinDenom) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + l = len(m.Farmer) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + l = m.Staking.Size() + n += 1 + l + sovGenesis(uint64(l)) + return n +} + +func (m *QueuedStakingRecord) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.StakingCoinDenom) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + l = len(m.Farmer) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + l = m.QueuedStaking.Size() + n += 1 + l + sovGenesis(uint64(l)) + return n +} + +func (m *HistoricalRewardsRecord) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.StakingCoinDenom) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + if m.Epoch != 0 { + n += 1 + sovGenesis(uint64(m.Epoch)) + } + l = m.HistoricalRewards.Size() + n += 1 + l + sovGenesis(uint64(l)) + return n +} + +func (m *CurrentEpochRecord) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.StakingCoinDenom) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + if m.CurrentEpoch != 0 { + n += 1 + sovGenesis(uint64(m.CurrentEpoch)) + } + return n +} + +func sovGenesis(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenesis(x uint64) (n int) { + return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *GenesisState) 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 ErrIntOverflowGenesis + } + 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: GenesisState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PlanRecords", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PlanRecords = append(m.PlanRecords, PlanRecord{}) + if err := m.PlanRecords[len(m.PlanRecords)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field StakingRecords", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.StakingRecords = append(m.StakingRecords, StakingRecord{}) + if err := m.StakingRecords[len(m.StakingRecords)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field QueuedStakingRecords", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.QueuedStakingRecords = append(m.QueuedStakingRecords, QueuedStakingRecord{}) + if err := m.QueuedStakingRecords[len(m.QueuedStakingRecords)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field HistoricalRewardsRecords", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.HistoricalRewardsRecords = append(m.HistoricalRewardsRecords, HistoricalRewardsRecord{}) + if err := m.HistoricalRewardsRecords[len(m.HistoricalRewardsRecords)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CurrentEpochRecords", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CurrentEpochRecords = append(m.CurrentEpochRecords, CurrentEpochRecord{}) + if err := m.CurrentEpochRecords[len(m.CurrentEpochRecords)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field StakingReserveCoins", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.StakingReserveCoins = append(m.StakingReserveCoins, types.Coin{}) + if err := m.StakingReserveCoins[len(m.StakingReserveCoins)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 8: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RewardPoolCoins", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.RewardPoolCoins = append(m.RewardPoolCoins, types.Coin{}) + if err := m.RewardPoolCoins[len(m.RewardPoolCoins)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 9: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field GlobalLastEpochTime", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.GlobalLastEpochTime, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *PlanRecord) 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 ErrIntOverflowGenesis + } + 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: PlanRecord: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PlanRecord: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Plan", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Plan.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FarmingPoolCoins", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.FarmingPoolCoins = append(m.FarmingPoolCoins, types.Coin{}) + if err := m.FarmingPoolCoins[len(m.FarmingPoolCoins)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field StakingReserveCoins", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.StakingReserveCoins = append(m.StakingReserveCoins, types.Coin{}) + if err := m.StakingReserveCoins[len(m.StakingReserveCoins)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } -func (m *PlanRecord) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = m.Plan.Size() - n += 1 + l + sovGenesis(uint64(l)) - if len(m.FarmingPoolCoins) > 0 { - for _, e := range m.FarmingPoolCoins { - l = e.Size() - n += 1 + l + sovGenesis(uint64(l)) - } - } - if len(m.StakingReserveCoins) > 0 { - for _, e := range m.StakingReserveCoins { - l = e.Size() - n += 1 + l + sovGenesis(uint64(l)) - } + if iNdEx > l { + return io.ErrUnexpectedEOF } - return n -} - -func sovGenesis(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozGenesis(x uint64) (n int) { - return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) + return nil } -func (m *GenesisState) Unmarshal(dAtA []byte) error { +func (m *StakingRecord) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -436,17 +1428,17 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: GenesisState: wiretype end group for non-group") + return fmt.Errorf("proto: StakingRecord: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: StakingRecord: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field StakingCoinDenom", wireType) } - var msglen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowGenesis @@ -456,30 +1448,29 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthGenesis } - postIndex := iNdEx + msglen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthGenesis } if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } + m.StakingCoinDenom = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PlanRecords", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Farmer", wireType) } - var msglen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowGenesis @@ -489,29 +1480,27 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthGenesis } - postIndex := iNdEx + msglen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthGenesis } if postIndex > l { return io.ErrUnexpectedEOF } - m.PlanRecords = append(m.PlanRecords, PlanRecord{}) - if err := m.PlanRecords[len(m.PlanRecords)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } + m.Farmer = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Stakings", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Staking", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -538,16 +1527,65 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Stakings = append(m.Stakings, Staking{}) - if err := m.Stakings[len(m.Stakings)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.Staking.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex - case 5: + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueuedStakingRecord) 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 ErrIntOverflowGenesis + } + 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: QueuedStakingRecord: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueuedStakingRecord: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field StakingReserveCoins", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field StakingCoinDenom", wireType) } - var msglen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowGenesis @@ -557,31 +1595,29 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthGenesis } - postIndex := iNdEx + msglen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthGenesis } if postIndex > l { return io.ErrUnexpectedEOF } - m.StakingReserveCoins = append(m.StakingReserveCoins, types.Coin{}) - if err := m.StakingReserveCoins[len(m.StakingReserveCoins)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } + m.StakingCoinDenom = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 6: + case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RewardPoolCoins", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Farmer", wireType) } - var msglen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowGenesis @@ -591,29 +1627,27 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthGenesis } - postIndex := iNdEx + msglen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthGenesis } if postIndex > l { return io.ErrUnexpectedEOF } - m.RewardPoolCoins = append(m.RewardPoolCoins, types.Coin{}) - if err := m.RewardPoolCoins[len(m.RewardPoolCoins)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } + m.Farmer = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 7: + case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field GlobalLastEpochTime", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field QueuedStaking", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -640,7 +1674,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.GlobalLastEpochTime, dAtA[iNdEx:postIndex]); err != nil { + if err := m.QueuedStaking.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -665,7 +1699,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { } return nil } -func (m *PlanRecord) Unmarshal(dAtA []byte) error { +func (m *HistoricalRewardsRecord) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -688,17 +1722,17 @@ func (m *PlanRecord) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: PlanRecord: wiretype end group for non-group") + return fmt.Errorf("proto: HistoricalRewardsRecord: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: PlanRecord: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: HistoricalRewardsRecord: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Plan", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field StakingCoinDenom", wireType) } - var msglen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowGenesis @@ -708,28 +1742,46 @@ func (m *PlanRecord) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthGenesis } - postIndex := iNdEx + msglen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthGenesis } if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.Plan.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } + m.StakingCoinDenom = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Epoch", wireType) + } + m.Epoch = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Epoch |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field FarmingPoolCoins", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field HistoricalRewards", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -756,16 +1808,65 @@ func (m *PlanRecord) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.FarmingPoolCoins = append(m.FarmingPoolCoins, types.Coin{}) - if err := m.FarmingPoolCoins[len(m.FarmingPoolCoins)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.HistoricalRewards.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex - case 3: + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *CurrentEpochRecord) 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 ErrIntOverflowGenesis + } + 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: CurrentEpochRecord: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: CurrentEpochRecord: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field StakingReserveCoins", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field StakingCoinDenom", wireType) } - var msglen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowGenesis @@ -775,26 +1876,43 @@ func (m *PlanRecord) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthGenesis } - postIndex := iNdEx + msglen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthGenesis } if postIndex > l { return io.ErrUnexpectedEOF } - m.StakingReserveCoins = append(m.StakingReserveCoins, types.Coin{}) - if err := m.StakingReserveCoins[len(m.StakingReserveCoins)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } + m.StakingCoinDenom = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field CurrentEpoch", wireType) + } + m.CurrentEpoch = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.CurrentEpoch |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) From 8ef30947aa5561c2708e725f7b5b36f4194e98f6 Mon Sep 17 00:00:00 2001 From: Hanjun Kim Date: Thu, 9 Sep 2021 14:15:58 +0900 Subject: [PATCH 07/16] fix: fix genesis functions --- x/farming/keeper/genesis.go | 62 ++++++++++++++++++++++++++----- x/farming/keeper/genesis_test.go | 22 ++++++----- x/farming/keeper/reward.go | 64 +++++++++++++++++++++++--------- x/farming/keeper/staking.go | 45 ++++++++-------------- x/farming/types/genesis.go | 36 ++++++++++-------- x/farming/types/keys.go | 32 +++++++++++++++- x/farming/types/reward.go | 1 - 7 files changed, 178 insertions(+), 84 deletions(-) delete mode 100644 x/farming/types/reward.go diff --git a/x/farming/keeper/genesis.go b/x/farming/keeper/genesis.go index 93588f98..8287d3b7 100644 --- a/x/farming/keeper/genesis.go +++ b/x/farming/keeper/genesis.go @@ -44,24 +44,66 @@ func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) { func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { params := k.GetParams(ctx) - // TODO: unimplemented - var planRecords []types.PlanRecord - - plans := k.GetAllPlans(ctx) - // TODO: add f1 struct, queued staking - //stakings := k.GetAllStakings(ctx) - - for _, plan := range plans { + var plans []types.PlanRecord + for _, plan := range k.GetAllPlans(ctx) { any, err := types.PackPlan(plan) if err != nil { panic(err) } - planRecords = append(planRecords, types.PlanRecord{ + plans = append(plans, types.PlanRecord{ Plan: *any, FarmingPoolCoins: k.bankKeeper.GetAllBalances(ctx, plan.GetFarmingPoolAddress()), }) } + var stakings []types.StakingRecord + k.IterateStakings(ctx, func(stakingCoinDenom string, farmerAcc sdk.AccAddress, staking types.Staking) (stop bool) { + stakings = append(stakings, types.StakingRecord{ + StakingCoinDenom: stakingCoinDenom, + Farmer: farmerAcc.String(), + Staking: staking, + }) + return false + }) + + var queuedStakings []types.QueuedStakingRecord + k.IterateQueuedStakings(ctx, func(stakingCoinDenom string, farmerAcc sdk.AccAddress, queuedStaking types.QueuedStaking) (stop bool) { + queuedStakings = append(queuedStakings, types.QueuedStakingRecord{ + StakingCoinDenom: stakingCoinDenom, + Farmer: farmerAcc.String(), + QueuedStaking: queuedStaking, + }) + return false + }) + + var historicalRewards []types.HistoricalRewardsRecord + k.IterateHistoricalRewards(ctx, func(stakingCoinDenom string, epoch uint64, rewards types.HistoricalRewards) (stop bool) { + historicalRewards = append(historicalRewards, types.HistoricalRewardsRecord{ + StakingCoinDenom: stakingCoinDenom, + Epoch: epoch, + HistoricalRewards: rewards, + }) + return false + }) + + var currentEpochs []types.CurrentEpochRecord + k.IterateCurrentEpochs(ctx, func(stakingCoinDenom string, currentEpoch uint64) (stop bool) { + currentEpochs = append(currentEpochs, types.CurrentEpochRecord{ + StakingCoinDenom: stakingCoinDenom, + CurrentEpoch: currentEpoch, + }) + return false + }) + epochTime, _ := k.GetLastEpochTime(ctx) - return types.NewGenesisState(params, planRecords, nil, k.bankKeeper.GetAllBalances(ctx, types.StakingReserveAcc), k.bankKeeper.GetAllBalances(ctx, types.RewardsReserveAcc), epochTime) + return types.NewGenesisState( + params, + plans, + stakings, + queuedStakings, + historicalRewards, + currentEpochs, + k.bankKeeper.GetAllBalances(ctx, types.StakingReserveAcc), + k.bankKeeper.GetAllBalances(ctx, types.RewardsReserveAcc), + epochTime) } diff --git a/x/farming/keeper/genesis_test.go b/x/farming/keeper/genesis_test.go index 003e1dc3..1b547058 100644 --- a/x/farming/keeper/genesis_test.go +++ b/x/farming/keeper/genesis_test.go @@ -48,22 +48,24 @@ func (suite *KeeperTestSuite) TestInitGenesis() { sdk.NewInt64Coin(denom2, 1_000_000))) suite.keeper.ProcessQueuedCoins(suite.ctx) - // TODO: f1 struct - //suite.ctx = suite.ctx.WithBlockTime(mustParseRFC3339("2021-07-31T00:00:00Z")) - //err := suite.keeper.DistributeRewards(suite.ctx) - //suite.Require().NoError(err) + suite.ctx = suite.ctx.WithBlockTime(mustParseRFC3339("2021-07-31T00:00:00Z")) + + // Advance 2 epochs + err := suite.keeper.AdvanceEpoch(suite.ctx) + suite.Require().NoError(err) + err = suite.keeper.AdvanceEpoch(suite.ctx) + suite.Require().NoError(err) var genState *types.GenesisState suite.Require().NotPanics(func() { genState = suite.keeper.ExportGenesis(suite.ctx) - }, - ) - //err = types.ValidateGenesis(*genState) - //suite.Require().NoError(err) + }) + + err = types.ValidateGenesis(*genState) + suite.Require().NoError(err) suite.Require().NotPanics(func() { suite.keeper.InitGenesis(suite.ctx, *genState) - }, - ) + }) suite.Require().Equal(genState, suite.keeper.ExportGenesis(suite.ctx)) } diff --git a/x/farming/keeper/reward.go b/x/farming/keeper/reward.go index 5e87d958..9b91b410 100644 --- a/x/farming/keeper/reward.go +++ b/x/farming/keeper/reward.go @@ -5,6 +5,7 @@ import ( "strconv" sdk "github.com/cosmos/cosmos-sdk/types" + gogotypes "github.com/gogo/protobuf/types" "github.com/tendermint/farming/x/farming/types" ) @@ -27,19 +28,49 @@ func (k Keeper) DeleteHistoricalRewards(ctx sdk.Context, stakingCoinDenom string store.Delete(types.GetHistoricalRewardsKey(stakingCoinDenom, epoch)) } -func (k Keeper) GetCurrentRewards(ctx sdk.Context, stakingCoinDenom string) (rewards types.CurrentRewards) { +func (k Keeper) IterateHistoricalRewards(ctx sdk.Context, cb func(stakingCoinDenom string, epoch uint64, rewards types.HistoricalRewards) (stop bool)) { + store := ctx.KVStore(k.storeKey) + iter := sdk.KVStorePrefixIterator(store, types.HistoricalRewardsKeyPrefix) + defer iter.Close() + for ; iter.Valid(); iter.Next() { + var rewards types.HistoricalRewards + k.cdc.MustUnmarshal(iter.Value(), &rewards) + stakingCoinDenom, epoch := types.ParseHistoricalRewardsKey(iter.Key()) + if cb(stakingCoinDenom, epoch, rewards) { + break + } + } +} + +func (k Keeper) GetCurrentEpoch(ctx sdk.Context, stakingCoinDenom string) uint64 { store := ctx.KVStore(k.storeKey) bz := store.Get(types.GetCurrentRewardsKey(stakingCoinDenom)) - k.cdc.MustUnmarshal(bz, &rewards) - return + var val gogotypes.UInt64Value + k.cdc.MustUnmarshal(bz, &val) + return val.GetValue() } -func (k Keeper) SetCurrentRewards(ctx sdk.Context, stakingCoinDenom string, rewards types.CurrentRewards) { +func (k Keeper) SetCurrentEpoch(ctx sdk.Context, stakingCoinDenom string, currentEpoch uint64) { store := ctx.KVStore(k.storeKey) - bz := k.cdc.MustMarshal(&rewards) + val := gogotypes.UInt64Value{Value: currentEpoch} + bz := k.cdc.MustMarshal(&val) store.Set(types.GetCurrentRewardsKey(stakingCoinDenom), bz) } +func (k Keeper) IterateCurrentEpochs(ctx sdk.Context, cb func(stakingCoinDenom string, currentEpoch uint64) (stop bool)) { + store := ctx.KVStore(k.storeKey) + iter := sdk.KVStorePrefixIterator(store, types.CurrentEpochKeyPrefix) + defer iter.Close() + for ; iter.Valid(); iter.Next() { + var val gogotypes.UInt64Value + k.cdc.MustUnmarshal(iter.Value(), &val) + stakingCoinDenom := types.ParseCurrentEpochKey(iter.Key()) + if cb(stakingCoinDenom, val.GetValue()) { + break + } + } +} + func (k Keeper) CalculateRewards(ctx sdk.Context, farmerAcc sdk.AccAddress, stakingCoinDenom string, endingEpoch uint64) (rewards sdk.Coins) { staking, found := k.GetStaking(ctx, stakingCoinDenom, farmerAcc) if !found { @@ -59,8 +90,9 @@ func (k Keeper) WithdrawRewards(ctx sdk.Context, farmerAcc sdk.AccAddress, staki return nil, fmt.Errorf("empty starting info") // TODO: use correct error } - current := k.GetCurrentRewards(ctx, stakingCoinDenom) - rewards := k.CalculateRewards(ctx, farmerAcc, stakingCoinDenom, current.Epoch-1) + currentEpoch := k.GetCurrentEpoch(ctx, stakingCoinDenom) + // TODO: handle if currentEpoch is 0 + rewards := k.CalculateRewards(ctx, farmerAcc, stakingCoinDenom, currentEpoch-1) if !rewards.IsZero() { if err := k.bankKeeper.SendCoins(ctx, k.GetRewardsReservePoolAcc(ctx), farmerAcc, rewards); err != nil { @@ -68,7 +100,7 @@ func (k Keeper) WithdrawRewards(ctx sdk.Context, farmerAcc sdk.AccAddress, staki } } - staking.StartingEpoch = current.Epoch + staking.StartingEpoch = currentEpoch k.SetStaking(ctx, stakingCoinDenom, farmerAcc, staking) return rewards, nil @@ -78,14 +110,14 @@ func (k Keeper) WithdrawAllRewards(ctx sdk.Context, farmerAcc sdk.AccAddress) (s totalRewards := sdk.NewCoins() k.IterateStakingsByFarmer(ctx, farmerAcc, func(stakingCoinDenom string, staking types.Staking) (stop bool) { - current := k.GetCurrentRewards(ctx, stakingCoinDenom) - rewards := k.CalculateRewards(ctx, farmerAcc, stakingCoinDenom, current.Epoch-1) + currentEpoch := k.GetCurrentEpoch(ctx, stakingCoinDenom) + rewards := k.CalculateRewards(ctx, farmerAcc, stakingCoinDenom, currentEpoch-1) if !rewards.IsZero() { totalRewards = totalRewards.Add(rewards...) } - staking.StartingEpoch = current.Epoch + staking.StartingEpoch = currentEpoch k.SetStaking(ctx, stakingCoinDenom, farmerAcc, staking) return false @@ -207,14 +239,12 @@ func (k Keeper) AllocateRewards(ctx sdk.Context) error { weightProportion := weight.Amount.QuoTruncate(totalWeight) allocCoins := sdk.NewDecCoinsFromCoins(allocInfo.Amount...).MulDecTruncate(weightProportion) - current := k.GetCurrentRewards(ctx, weight.Denom) - historical := k.GetHistoricalRewards(ctx, weight.Denom, current.Epoch-1) - k.SetHistoricalRewards(ctx, weight.Denom, current.Epoch, types.HistoricalRewards{ + currentEpoch := k.GetCurrentEpoch(ctx, weight.Denom) + historical := k.GetHistoricalRewards(ctx, weight.Denom, currentEpoch-1) + k.SetHistoricalRewards(ctx, weight.Denom, currentEpoch, types.HistoricalRewards{ CumulativeUnitRewards: historical.CumulativeUnitRewards.Add(allocCoins.QuoDecTruncate(totalStaking.Amount.ToDec())...), }) - k.SetCurrentRewards(ctx, weight.Denom, types.CurrentRewards{ - Epoch: current.Epoch + 1, - }) + k.SetCurrentEpoch(ctx, weight.Denom, currentEpoch+1) totalAllocCoins = totalAllocCoins.Add(allocCoins...) } diff --git a/x/farming/keeper/staking.go b/x/farming/keeper/staking.go index ab05044c..a9b1a217 100644 --- a/x/farming/keeper/staking.go +++ b/x/farming/keeper/staking.go @@ -65,32 +65,19 @@ func (k Keeper) DeleteStaking(ctx sdk.Context, stakingCoinDenom string, farmerAc store.Delete(types.GetStakingIndexKey(farmerAcc, stakingCoinDenom)) } -//// SetStakingIndex implements Staking. -//func (k Keeper) SetStakingIndex(ctx sdk.Context, staking types.Staking) { -// store := ctx.KVStore(k.storeKey) -// store.Set(types.GetStakingByFarmerIndexKey(staking.GetFarmer()), sdk.Uint64ToBigEndian(staking.Id)) -// for _, denom := range staking.StakingCoinDenoms() { -// store.Set(types.GetStakingByStakingCoinDenomIndexKey(denom, staking.Id), []byte{}) -// } -//} - -//// DeleteStaking deletes a staking. -//func (k Keeper) DeleteStaking(ctx sdk.Context, staking types.Staking) { -// store := ctx.KVStore(k.storeKey) -// store.Delete(types.GetStakingKey(staking.Id)) -// store.Delete(types.GetStakingByFarmerIndexKey(staking.GetFarmer())) -// if denoms := staking.StakingCoinDenoms(); len(denoms) > 0 { -// k.DeleteStakingCoinDenomsIndex(ctx, staking.Id, denoms) -// } -//} - -//// DeleteStakingCoinDenomsIndex removes an staking for the staking mapper store. -//func (k Keeper) DeleteStakingCoinDenomsIndex(ctx sdk.Context, id uint64, denoms []string) { -// store := ctx.KVStore(k.storeKey) -// for _, denom := range denoms { -// store.Delete(types.GetStakingByStakingCoinDenomIndexKey(denom, id)) -// } -//} +func (k Keeper) IterateStakings(ctx sdk.Context, cb func(stakingCoinDenom string, farmerAcc sdk.AccAddress, staking types.Staking) (stop bool)) { + store := ctx.KVStore(k.storeKey) + iter := sdk.KVStorePrefixIterator(store, types.StakingKeyPrefix) + defer iter.Close() + for ; iter.Valid(); iter.Next() { + var staking types.Staking + k.cdc.MustUnmarshal(iter.Value(), &staking) + stakingCoinDenom, farmerAcc := types.ParseStakingKey(iter.Key()) + if cb(stakingCoinDenom, farmerAcc, staking) { + break + } + } +} //// IterateAllStakings iterates over all the stored stakings and performs a callback function. //// Stops iteration when callback returns true. @@ -253,8 +240,8 @@ func (k Keeper) Unstake(ctx sdk.Context, farmerAcc sdk.AccAddress, amount sdk.Co } if staking.Amount.IsPositive() { - current := k.GetCurrentRewards(ctx, coin.Denom) - staking.StartingEpoch = current.Epoch + currentEpoch := k.GetCurrentEpoch(ctx, coin.Denom) + staking.StartingEpoch = currentEpoch k.SetStaking(ctx, coin.Denom, farmerAcc, staking) } else { k.DeleteStaking(ctx, coin.Denom, farmerAcc) @@ -301,7 +288,7 @@ func (k Keeper) ProcessQueuedCoins(ctx sdk.Context) { k.DeleteQueuedStaking(ctx, stakingCoinDenom, farmerAcc) k.SetStaking(ctx, stakingCoinDenom, farmerAcc, types.Staking{ Amount: staking.Amount.Add(queuedStaking.Amount), - StartingEpoch: k.GetCurrentRewards(ctx, stakingCoinDenom).Epoch, + StartingEpoch: k.GetCurrentEpoch(ctx, stakingCoinDenom), }) totalStaking, found := k.GetTotalStaking(ctx, stakingCoinDenom) diff --git a/x/farming/types/genesis.go b/x/farming/types/genesis.go index e9816bac..97bc7859 100644 --- a/x/farming/types/genesis.go +++ b/x/farming/types/genesis.go @@ -8,15 +8,21 @@ import ( ) // NewGenesisState returns new GenesisState. -func NewGenesisState(params Params, planRecords []PlanRecord, stakings []Staking, stakingReserveCoins, rewardPoolCoins sdk.Coins, globalLastEpochTime time.Time) *GenesisState { +func NewGenesisState( + params Params, plans []PlanRecord, stakings []StakingRecord, queuedStakings []QueuedStakingRecord, + historicalRewards []HistoricalRewardsRecord, currentEpochs []CurrentEpochRecord, stakingReserveCoins, + rewardPoolCoins sdk.Coins, globalLastEpochTime time.Time, +) *GenesisState { return &GenesisState{ - Params: params, - PlanRecords: planRecords, - Stakings: stakings, - StakingReserveCoins: stakingReserveCoins, - RewardPoolCoins: rewardPoolCoins, - GlobalLastEpochTime: globalLastEpochTime, - // TODO: add queued staking and struct for f1 + Params: params, + PlanRecords: plans, + StakingRecords: stakings, + QueuedStakingRecords: queuedStakings, + HistoricalRewardsRecords: historicalRewards, + CurrentEpochRecords: currentEpochs, + StakingReserveCoins: stakingReserveCoins, + RewardPoolCoins: rewardPoolCoins, + GlobalLastEpochTime: globalLastEpochTime, } } @@ -25,10 +31,13 @@ func DefaultGenesisState() *GenesisState { return NewGenesisState( DefaultParams(), []PlanRecord{}, - []Staking{}, + []StakingRecord{}, + []QueuedStakingRecord{}, + []HistoricalRewardsRecord{}, + []CurrentEpochRecord{}, sdk.Coins{}, sdk.Coins{}, - time.Time{},) + time.Time{}) } // ValidateGenesis validates GenesisState. @@ -50,17 +59,14 @@ func ValidateGenesis(data GenesisState) error { return fmt.Errorf("pool records must be sorted") } plans = append(plans, plan) + id = plan.GetId() + 1 } err := ValidateRatioPlans(plans) if err != nil { return err } - for _, staking := range data.Stakings { - if err := staking.Validate(); err != nil { - return err - } - } + // TODO: validate other fields if err := data.RewardPoolCoins.Validate(); err != nil { return err } diff --git a/x/farming/types/keys.go b/x/farming/types/keys.go index 44b39a47..4bcac63d 100644 --- a/x/farming/types/keys.go +++ b/x/farming/types/keys.go @@ -34,7 +34,7 @@ var ( TotalStakingKeyPrefix = []byte{0x24} HistoricalRewardsKeyPrefix = []byte{0x31} - CurrentRewardsKeyPrefix = []byte{0x32} + CurrentEpochKeyPrefix = []byte{0x32} ) // GetPlanKey returns kv indexing key of the plan @@ -78,7 +78,17 @@ func GetHistoricalRewardsKey(stakingCoinDenom string, epoch uint64) []byte { } func GetCurrentRewardsKey(stakingCoinDenom string) []byte { - return append(CurrentRewardsKeyPrefix, []byte(stakingCoinDenom)...) + return append(CurrentEpochKeyPrefix, []byte(stakingCoinDenom)...) +} + +func ParseStakingKey(key []byte) (stakingCoinDenom string, farmerAcc sdk.AccAddress) { + if !bytes.HasPrefix(key, StakingKeyPrefix) { + panic("key does not have proper prefix") + } + denomLen := key[1] + stakingCoinDenom = string(key[2 : 2+denomLen]) + farmerAcc = key[2+denomLen:] + return } func ParseStakingIndexKey(key []byte) (farmerAcc sdk.AccAddress, stakingCoinDenom string) { @@ -101,6 +111,24 @@ func ParseQueuedStakingKey(key []byte) (stakingCoinDenom string, farmerAcc sdk.A return } +func ParseHistoricalRewardsKey(key []byte) (stakingCoinDenom string, epoch uint64) { + if !bytes.HasPrefix(key, HistoricalRewardsKeyPrefix) { + panic("key does not have proper prefix") + } + denomLen := key[1] + stakingCoinDenom = string(key[2 : 2+denomLen]) + epoch = sdk.BigEndianToUint64(key[2+denomLen:]) + return +} + +func ParseCurrentEpochKey(key []byte) (stakingCoinDenom string) { + if !bytes.HasPrefix(key, CurrentEpochKeyPrefix) { + panic("key does not have proper prefix") + } + stakingCoinDenom = string(key[1:]) + return +} + // LengthPrefixString is LengthPrefix for string. func LengthPrefixString(s string) []byte { bz := []byte(s) diff --git a/x/farming/types/reward.go b/x/farming/types/reward.go deleted file mode 100644 index ab1254f4..00000000 --- a/x/farming/types/reward.go +++ /dev/null @@ -1 +0,0 @@ -package types From de5f9430f9a56eea2e09a13497d0d3e24d3793ef Mon Sep 17 00:00:00 2001 From: Hanjun Kim Date: Thu, 9 Sep 2021 14:27:51 +0900 Subject: [PATCH 08/16] fix: fix ValidateStakingReservedAmount --- x/farming/keeper/plan.go | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/x/farming/keeper/plan.go b/x/farming/keeper/plan.go index 8f1e38f2..71938ca2 100644 --- a/x/farming/keeper/plan.go +++ b/x/farming/keeper/plan.go @@ -313,20 +313,23 @@ func (k Keeper) GeneratePrivatePlanFarmingPoolAddress(ctx sdk.Context, name stri return poolAcc, nil } -// ValidateStakingReservedAmount checks that the balance of StakingReserveAcc greater than the amount of staked, Queued coins in all staking objects. +// ValidateStakingReservedAmount checks that the balance of StakingReserveAcc greater than the amount of staked, queued coins in all staking objects. func (k Keeper) ValidateStakingReservedAmount(ctx sdk.Context) error { - var totalStakingAmt sdk.Coins - balanceStakingReserveAcc := k.bankKeeper.GetAllBalances(ctx, types.StakingReserveAcc) - - // TODO: apply f1 logic - //k.IterateAllStakings(ctx, func(staking types.Staking) (stop bool) { - // totalStakingAmt = totalStakingAmt.Add(staking.StakedCoins...).Add(staking.QueuedCoins...) - // return false - //}) + var totalStakingCoins sdk.Coins + k.IterateStakings(ctx, func(stakingCoinDenom string, _ sdk.AccAddress, staking types.Staking) (stop bool) { + totalStakingCoins = totalStakingCoins.Add(sdk.NewCoin(stakingCoinDenom, staking.Amount)) + return false + }) + k.IterateQueuedStakings(ctx, func(stakingCoinDenom string, _ sdk.AccAddress, queuedStaking types.QueuedStaking) (stop bool) { + totalStakingCoins = totalStakingCoins.Add(sdk.NewCoin(stakingCoinDenom, queuedStaking.Amount)) + return false + }) - if !balanceStakingReserveAcc.IsAllGTE(totalStakingAmt) { + balanceStakingReserveAcc := k.bankKeeper.GetAllBalances(ctx, types.StakingReserveAcc) + if !balanceStakingReserveAcc.IsAllGTE(totalStakingCoins) { return types.ErrInvalidStakingReservedAmount } + return nil } From be43af86e46322380602a717ce02a00d910ce0c3 Mon Sep 17 00:00:00 2001 From: Hanjun Kim Date: Thu, 9 Sep 2021 15:06:15 +0900 Subject: [PATCH 09/16] feat: add QueuedStakingIndex and fix test --- x/farming/keeper/keeper_test.go | 22 +++++++- x/farming/keeper/staking.go | 89 ++++++++++---------------------- x/farming/keeper/staking_test.go | 85 ++++++++++++++++-------------- x/farming/types/keys.go | 27 ++++++++-- 4 files changed, 116 insertions(+), 107 deletions(-) diff --git a/x/farming/keeper/keeper_test.go b/x/farming/keeper/keeper_test.go index 23d8b989..57d62041 100644 --- a/x/farming/keeper/keeper_test.go +++ b/x/farming/keeper/keeper_test.go @@ -128,11 +128,29 @@ func (suite *KeeperTestSuite) SetupTest() { } // Stake is a convenient method to test Keeper.Stake. -func (suite *KeeperTestSuite) Stake(farmer sdk.AccAddress, amt sdk.Coins) { - err := suite.keeper.Stake(suite.ctx, farmer, amt) +func (suite *KeeperTestSuite) Stake(farmerAcc sdk.AccAddress, amt sdk.Coins) { + err := suite.keeper.Stake(suite.ctx, farmerAcc, amt) suite.Require().NoError(err) } +func (suite *KeeperTestSuite) StakedCoins(farmerAcc sdk.AccAddress) sdk.Coins { + stakedCoins := sdk.NewCoins() + suite.keeper.IterateStakingsByFarmer(suite.ctx, farmerAcc, func(stakingCoinDenom string, staking types.Staking) (stop bool) { + stakedCoins = stakedCoins.Add(sdk.NewCoin(stakingCoinDenom, staking.Amount)) + return false + }) + return stakedCoins +} + +func (suite *KeeperTestSuite) QueuedCoins(farmerAcc sdk.AccAddress) sdk.Coins { + queuedCoins := sdk.NewCoins() + suite.keeper.IterateQueuedStakingsByFarmer(suite.ctx, farmerAcc, func(stakingCoinDenom string, queuedStaking types.QueuedStaking) (stop bool) { + queuedCoins = queuedCoins.Add(sdk.NewCoin(stakingCoinDenom, queuedStaking.Amount)) + return false + }) + return queuedCoins +} + func intEq(exp, got sdk.Int) (bool, string, string, string) { return exp.Equal(got), "expected:\t%v\ngot:\t\t%v", exp.String(), got.String() } diff --git a/x/farming/keeper/staking.go b/x/farming/keeper/staking.go index a9b1a217..4d4100f8 100644 --- a/x/farming/keeper/staking.go +++ b/x/farming/keeper/staking.go @@ -19,38 +19,6 @@ func (k Keeper) GetStaking(ctx sdk.Context, stakingCoinDenom string, farmerAcc s return } -func (k Keeper) IterateStakingsByFarmer(ctx sdk.Context, farmerAcc sdk.AccAddress, cb func(stakingCoinDenom string, staking types.Staking) (stop bool)) { - store := ctx.KVStore(k.storeKey) - iter := sdk.KVStorePrefixIterator(store, types.GetStakingsByFarmerPrefix(farmerAcc)) - defer iter.Close() - for ; iter.Valid(); iter.Next() { - farmerAcc, stakingCoinDenom := types.ParseStakingIndexKey(iter.Key()) - staking, _ := k.GetStaking(ctx, stakingCoinDenom, farmerAcc) - if cb(stakingCoinDenom, staking) { - break - } - } -} - -//// GetAllStakings returns all stakings in the Keeper. -//func (k Keeper) GetAllStakings(ctx sdk.Context) (stakings []types.Staking) { -// k.IterateAllStakings(ctx, func(staking types.Staking) (stop bool) { -// stakings = append(stakings, staking) -// return false -// }) -// -// return stakings -//} - -//// GetStakingsByStakingCoinDenom reads from kvstore and return a specific Staking indexed by given staking coin denomination -//func (k Keeper) GetStakingsByStakingCoinDenom(ctx sdk.Context, denom string) (stakings []types.Staking) { -// k.IterateStakingsByStakingCoinDenom(ctx, denom, func(staking types.Staking) bool { -// stakings = append(stakings, staking) -// return false -// }) -// return stakings -//} - // SetStaking implements Staking. func (k Keeper) SetStaking(ctx sdk.Context, stakingCoinDenom string, farmerAcc sdk.AccAddress, staking types.Staking) { store := ctx.KVStore(k.storeKey) @@ -79,36 +47,18 @@ func (k Keeper) IterateStakings(ctx sdk.Context, cb func(stakingCoinDenom string } } -//// IterateAllStakings iterates over all the stored stakings and performs a callback function. -//// Stops iteration when callback returns true. -//func (k Keeper) IterateAllStakings(ctx sdk.Context, cb func(staking types.Staking) (stop bool)) { -// store := ctx.KVStore(k.storeKey) -// iterator := sdk.KVStorePrefixIterator(store, types.StakingKeyPrefix) -// -// defer iterator.Close() -// for ; iterator.Valid(); iterator.Next() { -// var staking types.Staking -// k.cdc.MustUnmarshal(iterator.Value(), &staking) -// if cb(staking) { -// break -// } -// } -//} - -//// IterateStakingsByStakingCoinDenom iterates over all the stored stakings indexed by staking coin denomination and performs a callback function. -//// Stops iteration when callback returns true. -//func (k Keeper) IterateStakingsByStakingCoinDenom(ctx sdk.Context, denom string, cb func(staking types.Staking) (stop bool)) { -// store := ctx.KVStore(k.storeKey) -// iterator := sdk.KVStorePrefixIterator(store, types.GetStakingsByStakingCoinDenomIndexKey(denom)) -// defer iterator.Close() -// for ; iterator.Valid(); iterator.Next() { -// _, id := types.ParseStakingsByStakingCoinDenomIndexKey(iterator.Key()) -// staking, _ := k.GetStaking(ctx, id) -// if cb(staking) { -// break -// } -// } -//} +func (k Keeper) IterateStakingsByFarmer(ctx sdk.Context, farmerAcc sdk.AccAddress, cb func(stakingCoinDenom string, staking types.Staking) (stop bool)) { + store := ctx.KVStore(k.storeKey) + iter := sdk.KVStorePrefixIterator(store, types.GetStakingsByFarmerPrefix(farmerAcc)) + defer iter.Close() + for ; iter.Valid(); iter.Next() { + farmerAcc, stakingCoinDenom := types.ParseStakingIndexKey(iter.Key()) + staking, _ := k.GetStaking(ctx, stakingCoinDenom, farmerAcc) + if cb(stakingCoinDenom, staking) { + break + } + } +} func (k Keeper) GetQueuedStaking(ctx sdk.Context, stakingCoinDenom string, farmerAcc sdk.AccAddress) (queuedStaking types.QueuedStaking, found bool) { store := ctx.KVStore(k.storeKey) @@ -125,11 +75,13 @@ func (k Keeper) SetQueuedStaking(ctx sdk.Context, stakingCoinDenom string, farme store := ctx.KVStore(k.storeKey) bz := k.cdc.MustMarshal(&queuedStaking) store.Set(types.GetQueuedStakingKey(stakingCoinDenom, farmerAcc), bz) + store.Set(types.GetQueuedStakingIndexKey(farmerAcc, stakingCoinDenom), []byte{}) } func (k Keeper) DeleteQueuedStaking(ctx sdk.Context, stakingCoinDenom string, farmerAcc sdk.AccAddress) { store := ctx.KVStore(k.storeKey) store.Delete(types.GetQueuedStakingKey(stakingCoinDenom, farmerAcc)) + store.Delete(types.GetQueuedStakingIndexKey(farmerAcc, stakingCoinDenom)) } func (k Keeper) IterateQueuedStakings(ctx sdk.Context, cb func(stakingCoinDenom string, farmerAcc sdk.AccAddress, queuedStaking types.QueuedStaking) (stop bool)) { @@ -146,6 +98,19 @@ func (k Keeper) IterateQueuedStakings(ctx sdk.Context, cb func(stakingCoinDenom } } +func (k Keeper) IterateQueuedStakingsByFarmer(ctx sdk.Context, farmerAcc sdk.AccAddress, cb func(stakingCoinDenom string, queuedStaking types.QueuedStaking) (stop bool)) { + store := ctx.KVStore(k.storeKey) + iter := sdk.KVStorePrefixIterator(store, types.GetQueuedStakingByFarmerPrefix(farmerAcc)) + defer iter.Close() + for ; iter.Valid(); iter.Next() { + farmerAcc, stakingCoinDenom := types.ParseQueuedStakingIndexKey(iter.Key()) + queuedStaking, _ := k.GetQueuedStaking(ctx, stakingCoinDenom, farmerAcc) + if cb(stakingCoinDenom, queuedStaking) { + break + } + } +} + func (k Keeper) GetTotalStaking(ctx sdk.Context, stakingCoinDenom string) (totalStaking types.TotalStaking, found bool) { store := ctx.KVStore(k.storeKey) bz := store.Get(types.GetTotalStakingKey(stakingCoinDenom)) diff --git a/x/farming/keeper/staking_test.go b/x/farming/keeper/staking_test.go index 48057a9d..5e9f50df 100644 --- a/x/farming/keeper/staking_test.go +++ b/x/farming/keeper/staking_test.go @@ -1,5 +1,11 @@ package keeper_test +import ( + "math/rand" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + //func (suite *KeeperTestSuite) TestGetStaking() { // _, found := suite.keeper.GetStaking(suite.ctx, 1) // suite.False(found, "staking should not be present") @@ -56,30 +62,6 @@ package keeper_test // } //} // -//func (suite *KeeperTestSuite) TestStakingCreationFee() { -// params := suite.keeper.GetParams(suite.ctx) -// params.StakingCreationFee = sdk.NewCoins(sdk.NewInt64Coin(denom1, 1_000_000)) -// suite.keeper.SetParams(suite.ctx, params) -// -// // Test accounts have 1,000,000,000 coins by default. -// balance := suite.app.BankKeeper.GetBalance(suite.ctx, suite.addrs[0], denom1) -// suite.Require().True(intEq(sdk.NewInt(1_000_000_000), balance.Amount)) -// -// // Stake 999,000,000 coins and pay 1,000,000 coins as staking creation fee because -// // it's the first time staking. -// _, err := suite.keeper.Stake(suite.ctx, suite.addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom1, 999_000_000))) -// suite.Require().NoError(err) -// -// // Balance should be zero now. -// balance = suite.app.BankKeeper.GetBalance(suite.ctx, suite.addrs[0], denom1) -// suite.Require().True(balance.Amount.IsZero()) -// -// // Taking a new account, staking 1_000_000_000 coins should fail because -// // there is no sufficient balance for staking creation fee. -// _, err = suite.keeper.Stake(suite.ctx, suite.addrs[1], sdk.NewCoins(sdk.NewInt64Coin(denom1, 1_000_000_000))) -// suite.Require().Error(err) -//} -// //func (suite *KeeperTestSuite) TestUnstake() { // for _, tc := range []struct { // name string @@ -169,21 +151,46 @@ package keeper_test // } //} // -//func (suite *KeeperTestSuite) TestProcessQueuedCoins() { -// suite.Stake(suite.addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom1, 1000))) -// -// staking, _ := suite.keeper.GetStakingByFarmer(suite.ctx, suite.addrs[0]) -// -// suite.Require().True(staking.StakedCoins.IsZero()) -// suite.Require().True(intEq(sdk.NewInt(1000), staking.QueuedCoins.AmountOf(denom1))) -// -// suite.keeper.ProcessQueuedCoins(suite.ctx) -// -// staking, _ = suite.keeper.GetStakingByFarmer(suite.ctx, suite.addrs[0]) -// -// suite.Require().True(intEq(sdk.NewInt(1000), staking.StakedCoins.AmountOf(denom1))) -// suite.Require().True(staking.QueuedCoins.IsZero()) -//} + +func (suite *KeeperTestSuite) TestProcessQueuedCoins() { + for seed := int64(0); seed < 10; seed++ { + suite.SetupTest() + + r := rand.New(rand.NewSource(seed)) + + stakedCoins := sdk.NewCoins() + queuedCoins := sdk.NewCoins() + + iterations := 100 + for i := 0; i < iterations; i++ { + if r.Intn(2) == 0 { // Stake with a 50% chance + // Construct random amount of coins to stake + stakingCoins := sdk.NewCoins() + for _, denom := range []string{denom1, denom2} { + balance := suite.app.BankKeeper.GetBalance(suite.ctx, suite.addrs[0], denom) + amt := r.Int63n(balance.Amount.ToDec().QuoTruncate(sdk.NewDec(int64(iterations))).TruncateInt64()) + stakingCoins = stakingCoins.Add(sdk.NewInt64Coin(denom, amt)) + } + + if !stakingCoins.IsZero() { + suite.Stake(suite.addrs[0], stakingCoins) + queuedCoins = queuedCoins.Add(stakingCoins...) + } + } + + suite.Require().True(coinsEq(queuedCoins, suite.QueuedCoins(suite.addrs[0]))) + suite.Require().True(coinsEq(stakedCoins, suite.StakedCoins(suite.addrs[0]))) + + suite.keeper.ProcessQueuedCoins(suite.ctx) + stakedCoins = stakedCoins.Add(queuedCoins...) + queuedCoins = sdk.NewCoins() + + suite.Require().True(coinsEq(queuedCoins, suite.QueuedCoins(suite.addrs[0]))) + suite.Require().True(coinsEq(stakedCoins, suite.StakedCoins(suite.addrs[0]))) + } + } +} + // //func (suite *KeeperTestSuite) TestEndBlockerProcessQueuedCoins() { // suite.Stake(suite.addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom1, 1000))) diff --git a/x/farming/types/keys.go b/x/farming/types/keys.go index 4bcac63d..c5adaecf 100644 --- a/x/farming/types/keys.go +++ b/x/farming/types/keys.go @@ -28,10 +28,11 @@ var ( PlanKeyPrefix = []byte{0x11} PlansByFarmerIndexKeyPrefix = []byte{0x12} - StakingKeyPrefix = []byte{0x21} - StakingIndexKeyPrefix = []byte{0x22} - QueuedStakingKeyPrefix = []byte{0x23} - TotalStakingKeyPrefix = []byte{0x24} + StakingKeyPrefix = []byte{0x21} + StakingIndexKeyPrefix = []byte{0x22} + QueuedStakingKeyPrefix = []byte{0x23} + QueuedStakingIndexKeyPrefix = []byte{0x24} + TotalStakingKeyPrefix = []byte{0x25} HistoricalRewardsKeyPrefix = []byte{0x31} CurrentEpochKeyPrefix = []byte{0x32} @@ -69,6 +70,14 @@ func GetQueuedStakingKey(stakingCoinDenom string, farmerAcc sdk.AccAddress) []by return append(append(QueuedStakingKeyPrefix, LengthPrefixString(stakingCoinDenom)...), farmerAcc...) } +func GetQueuedStakingIndexKey(farmerAcc sdk.AccAddress, stakingCoinDenom string) []byte { + return append(append(QueuedStakingIndexKeyPrefix, address.MustLengthPrefix(farmerAcc)...), []byte(stakingCoinDenom)...) +} + +func GetQueuedStakingByFarmerPrefix(farmerAcc sdk.AccAddress) []byte { + return append(QueuedStakingIndexKeyPrefix, address.MustLengthPrefix(farmerAcc)...) +} + func GetTotalStakingKey(stakingCoinDenom string) []byte { return append(TotalStakingKeyPrefix, []byte(stakingCoinDenom)...) } @@ -111,6 +120,16 @@ func ParseQueuedStakingKey(key []byte) (stakingCoinDenom string, farmerAcc sdk.A return } +func ParseQueuedStakingIndexKey(key []byte) (farmerAcc sdk.AccAddress, stakingCoinDenom string) { + if !bytes.HasPrefix(key, QueuedStakingIndexKeyPrefix) { + panic("key does not have proper prefix") + } + addrLen := key[1] + farmerAcc = key[2 : 2+addrLen] + stakingCoinDenom = string(key[2+addrLen:]) + return +} + func ParseHistoricalRewardsKey(key []byte) (stakingCoinDenom string, epoch uint64) { if !bytes.HasPrefix(key, HistoricalRewardsKeyPrefix) { panic("key does not have proper prefix") From 33a4a00925fae5f2b4031dbb35e84f975e294b3c Mon Sep 17 00:00:00 2001 From: Hanjun Kim Date: Thu, 9 Sep 2021 15:38:27 +0900 Subject: [PATCH 10/16] fix: remove unused flag sets --- x/farming/client/cli/flags.go | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/x/farming/client/cli/flags.go b/x/farming/client/cli/flags.go index 01782060..209c71ef 100644 --- a/x/farming/client/cli/flags.go +++ b/x/farming/client/cli/flags.go @@ -26,24 +26,6 @@ func flagSetPlans() *flag.FlagSet { return fs } -func flagSetStaking() *flag.FlagSet { - fs := flag.NewFlagSet("", flag.ContinueOnError) - - fs.String(FlagStakingCoinDenom, "", "The staking coin denom") - fs.String(FlagFarmerAddr, "", "The bech32 address of the farmer account") - - return fs -} - -func flagSetRewards() *flag.FlagSet { - fs := flag.NewFlagSet("", flag.ContinueOnError) - - fs.String(FlagStakingCoinDenom, "", "The staking coin denom") - fs.String(FlagFarmerAddr, "", "The bech32 address of the farmer account") - - return fs -} - func flagSetHarvest() *flag.FlagSet { fs := flag.NewFlagSet("", flag.ContinueOnError) From a11935710e28de44e1a0ae5ed2f6ba8b67915c02 Mon Sep 17 00:00:00 2001 From: Hanjun Kim Date: Thu, 9 Sep 2021 15:42:48 +0900 Subject: [PATCH 11/16] style: remove dummy code and format files --- x/farming/keeper/epoch.go | 2 +- x/farming/types/msgs_test.go | 10 ---------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/x/farming/keeper/epoch.go b/x/farming/keeper/epoch.go index 7e3fce1d..12b46338 100644 --- a/x/farming/keeper/epoch.go +++ b/x/farming/keeper/epoch.go @@ -43,4 +43,4 @@ func (k Keeper) AdvanceEpoch(ctx sdk.Context) error { k.SetLastEpochTime(ctx, ctx.BlockTime()) return nil -} \ No newline at end of file +} diff --git a/x/farming/types/msgs_test.go b/x/farming/types/msgs_test.go index ff2ee48f..c91e2595 100644 --- a/x/farming/types/msgs_test.go +++ b/x/farming/types/msgs_test.go @@ -4,9 +4,7 @@ import ( "testing" "time" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/legacy" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto" @@ -266,11 +264,3 @@ func TestMsgHarvest(t *testing.T) { } } } - -func TestFoo(t *testing.T) { - reg := codectypes.NewInterfaceRegistry() - types.RegisterInterfaces(reg) - cdc := codec.NewProtoCodec(reg) - var rewards types.HistoricalRewards - cdc.MustUnmarshal(nil, &rewards) -} \ No newline at end of file From b6c66a6210cd4bb04ff07ec3c58ce01e276c880e Mon Sep 17 00:00:00 2001 From: Hanjun Kim Date: Thu, 9 Sep 2021 16:06:07 +0900 Subject: [PATCH 12/16] docs: update spec docs and fix typo in key function --- x/farming/keeper/reward.go | 4 +-- x/farming/spec/02_state.md | 46 +++++++++++++++----------- x/farming/spec/03_state_transitions.md | 32 +++++++++++++++--- x/farming/types/keys.go | 2 +- 4 files changed, 56 insertions(+), 28 deletions(-) diff --git a/x/farming/keeper/reward.go b/x/farming/keeper/reward.go index 9b91b410..ef037823 100644 --- a/x/farming/keeper/reward.go +++ b/x/farming/keeper/reward.go @@ -44,7 +44,7 @@ func (k Keeper) IterateHistoricalRewards(ctx sdk.Context, cb func(stakingCoinDen func (k Keeper) GetCurrentEpoch(ctx sdk.Context, stakingCoinDenom string) uint64 { store := ctx.KVStore(k.storeKey) - bz := store.Get(types.GetCurrentRewardsKey(stakingCoinDenom)) + bz := store.Get(types.GetCurrentEpochKey(stakingCoinDenom)) var val gogotypes.UInt64Value k.cdc.MustUnmarshal(bz, &val) return val.GetValue() @@ -54,7 +54,7 @@ func (k Keeper) SetCurrentEpoch(ctx sdk.Context, stakingCoinDenom string, curren store := ctx.KVStore(k.storeKey) val := gogotypes.UInt64Value{Value: currentEpoch} bz := k.cdc.MustMarshal(&val) - store.Set(types.GetCurrentRewardsKey(stakingCoinDenom), bz) + store.Set(types.GetCurrentEpochKey(stakingCoinDenom), bz) } func (k Keeper) IterateCurrentEpochs(ctx sdk.Context, cb func(stakingCoinDenom string, currentEpoch uint64) (stop bool)) { diff --git a/x/farming/spec/02_state.md b/x/farming/spec/02_state.md index f7112c21..6cd3d706 100644 --- a/x/farming/spec/02_state.md +++ b/x/farming/spec/02_state.md @@ -124,40 +124,46 @@ The parameters of the Plan state are: ## Staking ```go -// Staking stores farmer's staking position status. +// Staking defines a farmer's staking information. type Staking struct { - Id uint64 - Farmer string - StakedCoins sdk.Coins - QueuedCoins sdk.Coins + Amount sdk.Int + StartingEpoch uint64 } ``` The parameters of the Staking state are: +- Staking: `0x21 | StakingCoinDenomLen (1 byte) | StakingCoinDenom | FarmerAddr -> ProtocolBuffer(Staking)` +- StakingIndex: `0x22 | FarmerAddrLen (1 byte) | FarmerAddr | StakingCoinDenom -> nil` -- GlobalStakingIdKey: `[]byte("globalStakingId") -> ProtocolBuffer(uint64)` +```go +type QueuedStaking struct { + Amount sdk.Int +} +``` - - store latest staking id +- QueuedStaking: `0x23 | StakingCoinDenomLen (1 byte) | StakingCoinDenom | FarmerAddr -> ProtocolBuffer(QueuedStaking)` +- QueuedStakingIndex: `0x24 | FarmerAddrLen (1 byte) | FarmerAddr | StakingCoinDenom -> nil` -- Staking: `0x21 | Id -> ProtocolBuffer(Staking)` -- StakingByFarmerAddrIndex: `0x22 | FarmerAddrLen (1 byte) | FarmerAddr -> BigEndian(Id)` -- StakingByStakingCoinDenomIdIndex: `0x23 | StakingCoinDenomLen (1 byte) | StakingCoinDenom | BigEndian(Id) -> nil` +```go +type TotalStaking struct { + Amount sdk.Int +} +``` + +- TotalStaking: `0x25 | StakingCoinDenom -> ProtocolBuffer(TotalStaking)` -## Reward +## Historical Rewards + +`HistoricalRewards` struct holds the cumulative unit rewards for each epoch which are needed for the reward calculation. ```go -// Reward defines a record of farming rewards for query result and exported state. -type Reward struct { - Farmer string - StakingCoinDenom string - RewardCoins sdk.Coins +type HistoricalRewards struct { + CumulativeUnitRewards sdk.DecCoins } ``` -The parameters of the Reward state are: - -- Reward: `0x31 | StakingCoinDenomLen (1 byte) | StakingCoinDenom | FarmerAddrLen (1 byte) | FarmerAddr -> ProtocolBuffer(sdk.Coins) RewardCoins` -- RewardByFarmerAddrIndex: `0x32 | FarmerAddrLen (1 byte) | FarmerAddr | StakingCoinDenomLen (1 byte) | StakingCoinDenom -> nil` +- HistoricalRewards: `0x31 | StakingCoinDenomLen (1 byte) | StakingCoinDenom | BigEndian(Epoch) -> ProtocolBuffer(HistoricalRewards)` +- CurrentEpoch: `0x32 | StakingCoinDenom -> BigEndian(CurrentEpoch)` ## Examples diff --git a/x/farming/spec/03_state_transitions.md b/x/farming/spec/03_state_transitions.md index 4bf46708..24cff93d 100644 --- a/x/farming/spec/03_state_transitions.md +++ b/x/farming/spec/03_state_transitions.md @@ -47,9 +47,31 @@ const ( - `QueuedCoins` : newly staked coins are in this status until end of current epoch, and then migrated to `StakedCoins` at the end of current epoch. - When a farmer unstakes, `QueuedCoins` are unstaked first, and then `StakedCoins`. -## Reward +## Reward Withdrawal -- At every end of epoch, `Reward` are created or updated by the calculation from each `Plan` and corresponding `Staking`. -- Every `StakedCoins` in `Staking` which is eligible for any alive `Plan` accumulates rewards in `RewardCoins`. -- Reward for specific `Plan` and `StakingCoinDenom` = total_reward_of_the_plan_for_this_epoch _ weight_for_this_staking_coin _ (this_denom_staked_coins_for_this_farmer)/(this_denom_total_staked_coins) -- Accumulated `RewardCoins` are withdrawable anytime when the farmer request the withdrawal from the `Reward`. +To assume constant staking amount for reward withdrawal, automatic withdrawal is designed as below: +- Add staking position : When there exists `QueuedCoins` in `Staking` at the end of current epoch + - accumulated rewards until current epoch are automatically withdrawn + - `StartEpochId` is modified to the `EpochId` of the next epoch + - `QueuedCoins` is migrated to `StakedCoins` +- Remove staking position : When a farmer remove stakings from `StakedCoins` + - accumulated rewards until last epoch are immediately withdrawn + - `StartEpochId` is modified to the `EpochId` of the current epoch + - unstake executed immediately and `StakedCoins` are reduced accordingly +- Manual reward withdrawal : When a farmer request a reward withdrawal + - accumulated rewards until last epoch are immediately withdrawn + - `StartEpochId` is modified to the `EpochId` of the current epoch + +## Accumulated Reward Calculation + +- Accumulated Unit Reward : AUR represents accumulated rewards(for each staking coin) of a staking position with amount 1. +- AUR for each staking coin for each epoch can be calculated as below + - ![](https://latex.codecogs.com/svg.latex?\Large&space;\sum_{i=0}^{now}\frac{TR_i}{TS_i}) + - ![](https://latex.codecogs.com/svg.latex?\Large&space;i) : each `EpochId` + - ![](https://latex.codecogs.com/svg.latex?\Large&space;now) : current `EpochId` + - ![](https://latex.codecogs.com/svg.latex?\Large&space;TS_i) : total staking amount of the staking coin for epoch i + - ![](https://latex.codecogs.com/svg.latex?\Large&space;TR_i) : total reward amount of the staking coin for epoch i +- Accumulated rewards from any staking position can be calculated from AUR and the staking amount of the position as below + - ![](https://latex.codecogs.com/svg.latex?\Large&space;x*\(\sum_{i=0}^{now}\frac{TR_i}{TS_i}-\sum_{i=0}^{start}\frac{TR_i}{TS_i}\)) + - assuming constant staking amount for the staking epochs + - ![](https://latex.codecogs.com/svg.latex?\Large&space;x) : staking amount for the staking period \ No newline at end of file diff --git a/x/farming/types/keys.go b/x/farming/types/keys.go index c5adaecf..206f9187 100644 --- a/x/farming/types/keys.go +++ b/x/farming/types/keys.go @@ -86,7 +86,7 @@ func GetHistoricalRewardsKey(stakingCoinDenom string, epoch uint64) []byte { return append(append(HistoricalRewardsKeyPrefix, LengthPrefixString(stakingCoinDenom)...), sdk.Uint64ToBigEndian(epoch)...) } -func GetCurrentRewardsKey(stakingCoinDenom string) []byte { +func GetCurrentEpochKey(stakingCoinDenom string) []byte { return append(CurrentEpochKeyPrefix, []byte(stakingCoinDenom)...) } From 41eb10fc5e8567e921414e281821703a94479dce Mon Sep 17 00:00:00 2001 From: Hanjun Kim Date: Thu, 9 Sep 2021 22:03:46 +0900 Subject: [PATCH 13/16] style: sort imports --- x/farming/client/cli/cli_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/farming/client/cli/cli_test.go b/x/farming/client/cli/cli_test.go index 06e3a944..e584ae16 100644 --- a/x/farming/client/cli/cli_test.go +++ b/x/farming/client/cli/cli_test.go @@ -9,6 +9,7 @@ import ( "github.com/gogo/protobuf/proto" "github.com/stretchr/testify/suite" + tmdb "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/testutil" @@ -19,7 +20,6 @@ import ( "github.com/tendermint/farming/x/farming/client/cli" farmingtestutil "github.com/tendermint/farming/x/farming/client/testutil" farmingtypes "github.com/tendermint/farming/x/farming/types" - tmdb "github.com/tendermint/tm-db" ) type IntegrationTestSuite struct { From f123af30f72e73e2e88856ebe9944148acea9a51 Mon Sep 17 00:00:00 2001 From: Hanjun Kim Date: Thu, 9 Sep 2021 22:40:07 +0900 Subject: [PATCH 14/16] test: fix staking tests --- x/farming/keeper/staking_test.go | 294 +++++++++++++------------------ 1 file changed, 121 insertions(+), 173 deletions(-) diff --git a/x/farming/keeper/staking_test.go b/x/farming/keeper/staking_test.go index 5e9f50df..ea2be63c 100644 --- a/x/farming/keeper/staking_test.go +++ b/x/farming/keeper/staking_test.go @@ -6,151 +6,127 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -//func (suite *KeeperTestSuite) TestGetStaking() { -// _, found := suite.keeper.GetStaking(suite.ctx, 1) -// suite.False(found, "staking should not be present") -// -// suite.Stake(suite.addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom1, 1000))) -// -// _, found = suite.keeper.GetStaking(suite.ctx, 1) -// suite.True(found, "staking should be present") -//} -// -//func (suite *KeeperTestSuite) TestStake() { -// for _, tc := range []struct { -// name string -// amt int64 -// remainingStaked int64 -// remainingQueued int64 -// expectErr bool -// }{ -// { -// "normal", -// 1000, -// 0, -// 1000, -// false, -// }, -// { -// "more than balance", -// 10_000_000_000, -// 0, -// 0, -// true, -// }, -// } { -// suite.Run(tc.name, func() { -// suite.SetupTest() -// -// _, found := suite.keeper.GetStakingByFarmer(suite.ctx, suite.addrs[0]) -// suite.Require().False(found, "staking should not be present") -// -// staking, err := suite.keeper.Stake(suite.ctx, suite.addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom1, tc.amt))) -// if tc.expectErr { -// suite.Error(err) -// } else { -// suite.NoError(err) -// staking2, found := suite.keeper.GetStakingByFarmer(suite.ctx, suite.addrs[0]) -// suite.True(found, "staking should be present") -// suite.True(staking2.StakedCoins.IsEqual(staking.StakedCoins)) -// suite.True(staking2.QueuedCoins.IsEqual(staking2.QueuedCoins)) -// -// suite.True(intEq(sdk.NewInt(tc.remainingStaked), staking.StakedCoins.AmountOf(denom1))) -// suite.True(intEq(sdk.NewInt(tc.remainingQueued), staking.QueuedCoins.AmountOf(denom1))) -// } -// }) -// } -//} -// -//func (suite *KeeperTestSuite) TestUnstake() { -// for _, tc := range []struct { -// name string -// addrIdx int -// amt sdk.Coins -// remainingStaked sdk.Coins -// remainingQueued sdk.Coins -// expectErr bool -// }{ -// { -// "from queued coins", -// 0, -// sdk.NewCoins(sdk.NewInt64Coin(denom1, 5000)), -// sdk.NewCoins(sdk.NewInt64Coin(denom1, 500_000), sdk.NewInt64Coin(denom2, 1_000_000)), -// sdk.NewCoins(sdk.NewInt64Coin(denom1, 495_000)), -// false, -// }, -// { -// "from staked coins", -// 0, -// sdk.NewCoins(sdk.NewInt64Coin(denom1, 700_000), sdk.NewInt64Coin(denom2, 100_000)), -// sdk.NewCoins(sdk.NewInt64Coin(denom1, 300_000), sdk.NewInt64Coin(denom2, 900_000)), -// sdk.NewCoins(), -// false, -// }, -// { -// "one coin", -// 0, -// sdk.NewCoins(sdk.NewInt64Coin(denom1, 1_000_000)), -// sdk.NewCoins(sdk.NewInt64Coin(denom2, 1_000_000)), -// sdk.NewCoins(), -// false, -// }, -// { -// "unstake all", -// 0, -// sdk.NewCoins(sdk.NewInt64Coin(denom1, 1_000_000), sdk.NewInt64Coin(denom2, 1_000_000)), -// sdk.NewCoins(), -// sdk.NewCoins(), -// false, -// }, -// { -// "more than staked", -// 0, -// sdk.NewCoins(sdk.NewInt64Coin(denom1, 1_100_000), sdk.NewInt64Coin(denom2, 1_100_000)), -// // We can use nil since there will be an error and we don't use these fields -// nil, -// nil, -// true, -// }, -// { -// "no staking", -// 1, -// sdk.NewCoins(sdk.NewInt64Coin(denom1, 1000)), -// nil, -// nil, -// true, -// }, -// } { -// suite.Run(tc.name, func() { -// suite.SetupTest() -// suite.Stake(suite.addrs[0], sdk.NewCoins( -// sdk.NewInt64Coin(denom1, 500_000), -// sdk.NewInt64Coin(denom2, 1_000_000))) -// -// // Make queued coins be staked. -// suite.ctx = suite.ctx.WithBlockTime(mustParseRFC3339("2021-07-23T05:00:00Z")) -// farming.EndBlocker(suite.ctx, suite.keeper) -// suite.ctx = suite.ctx.WithBlockTime(mustParseRFC3339("2021-07-24T00:05:00Z")) -// farming.EndBlocker(suite.ctx, suite.keeper) -// -// suite.Stake(suite.addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom1, 500_000))) -// -// // At this moment, we have 500,000denom1,1,000,000denom2 staked and -// // 500000denom1 queued. -// -// staking, err := suite.keeper.Unstake(suite.ctx, suite.addrs[tc.addrIdx], tc.amt) -// if tc.expectErr { -// suite.Error(err) -// } else { -// if suite.NoError(err) { -// suite.True(coinsEq(tc.remainingStaked, staking.StakedCoins)) -// suite.True(coinsEq(tc.remainingQueued, staking.QueuedCoins)) -// } -// } -// }) -// } -//} -// +func (suite *KeeperTestSuite) TestStake() { + for _, tc := range []struct { + name string + amt int64 + expectErr bool + }{ + { + "normal", + 1000, + false, + }, + { + "more than balance", + 1_000_000_000_000, + true, + }, + } { + suite.Run(tc.name, func() { + suite.SetupTest() + + err := suite.keeper.Stake(suite.ctx, suite.addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom1, tc.amt))) + if tc.expectErr { + suite.Require().Error(err) + } else { + suite.Require().NoError(err) + _, found := suite.keeper.GetStaking(suite.ctx, denom1, suite.addrs[0]) + suite.Require().False(found) + + queuedStaking, found := suite.keeper.GetQueuedStaking(suite.ctx, denom1, suite.addrs[0]) + suite.Require().True(found, "queued staking should be present") + suite.Require().True(intEq(sdk.NewInt(tc.amt), queuedStaking.Amount)) + } + }) + } +} + +func (suite *KeeperTestSuite) TestUnstake() { + for _, tc := range []struct { + name string + addrIdx int + amt sdk.Coins + remainingStaked sdk.Coins + remainingQueued sdk.Coins + expectErr bool + }{ + { + "from queued coins", + 0, + sdk.NewCoins(sdk.NewInt64Coin(denom1, 5000)), + sdk.NewCoins(sdk.NewInt64Coin(denom1, 500_000), sdk.NewInt64Coin(denom2, 1_000_000)), + sdk.NewCoins(sdk.NewInt64Coin(denom1, 495_000)), + false, + }, + { + "from staked coins", + 0, + sdk.NewCoins(sdk.NewInt64Coin(denom1, 700_000), sdk.NewInt64Coin(denom2, 100_000)), + sdk.NewCoins(sdk.NewInt64Coin(denom1, 300_000), sdk.NewInt64Coin(denom2, 900_000)), + sdk.NewCoins(), + false, + }, + { + "one coin", + 0, + sdk.NewCoins(sdk.NewInt64Coin(denom1, 1_000_000)), + sdk.NewCoins(sdk.NewInt64Coin(denom2, 1_000_000)), + sdk.NewCoins(), + false, + }, + { + "unstake all", + 0, + sdk.NewCoins(sdk.NewInt64Coin(denom1, 1_000_000), sdk.NewInt64Coin(denom2, 1_000_000)), + sdk.NewCoins(), + sdk.NewCoins(), + false, + }, + { + "more than staked", + 0, + sdk.NewCoins(sdk.NewInt64Coin(denom1, 1_100_000), sdk.NewInt64Coin(denom2, 1_100_000)), + // We can use nil since there will be an error, and we don't use these fields + nil, + nil, + true, + }, + { + "no staking", + 1, + sdk.NewCoins(sdk.NewInt64Coin(denom1, 1000)), + nil, + nil, + true, + }, + } { + suite.Run(tc.name, func() { + suite.SetupTest() + suite.Stake(suite.addrs[0], sdk.NewCoins( + sdk.NewInt64Coin(denom1, 500_000), + sdk.NewInt64Coin(denom2, 1_000_000))) + + // Make queued coins be staked. + suite.keeper.ProcessQueuedCoins(suite.ctx) + + suite.Stake(suite.addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom1, 500_000))) + + // At this moment, we have 500000denom1,1000000denom2 staked and + // 500000denom1 queued. + + err := suite.keeper.Unstake(suite.ctx, suite.addrs[tc.addrIdx], tc.amt) + if tc.expectErr { + suite.Error(err) + } else { + if suite.NoError(err) { + suite.True(coinsEq(tc.remainingStaked, suite.StakedCoins(suite.addrs[tc.addrIdx]))) + suite.True(coinsEq(tc.remainingQueued, suite.QueuedCoins(suite.addrs[tc.addrIdx]))) + } + } + }) + } +} func (suite *KeeperTestSuite) TestProcessQueuedCoins() { for seed := int64(0); seed < 10; seed++ { @@ -190,31 +166,3 @@ func (suite *KeeperTestSuite) TestProcessQueuedCoins() { } } } - -// -//func (suite *KeeperTestSuite) TestEndBlockerProcessQueuedCoins() { -// suite.Stake(suite.addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom1, 1000))) -// -// ctx := suite.ctx.WithBlockTime(mustParseRFC3339("2021-07-23T05:00:00Z")) -// farming.EndBlocker(ctx, suite.keeper) -// -// staking, _ := suite.keeper.GetStakingByFarmer(ctx, suite.addrs[0]) -// suite.Require().True(intEq(sdk.NewInt(1000), staking.QueuedCoins.AmountOf(denom1))) -// suite.Require().True(staking.StakedCoins.IsZero(), "staked coins must be empty") -// -// suite.Stake(suite.addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom1, 500))) -// -// ctx = ctx.WithBlockTime(mustParseRFC3339("2021-07-23T23:59:59Z")) -// farming.EndBlocker(ctx, suite.keeper) -// -// staking, _ = suite.keeper.GetStakingByFarmer(ctx, suite.addrs[0]) -// suite.Require().True(intEq(sdk.NewInt(1500), staking.QueuedCoins.AmountOf(denom1))) -// suite.Require().True(staking.StakedCoins.IsZero(), "staked coins must be empty") -// -// ctx = ctx.WithBlockTime(mustParseRFC3339("2021-07-24T00:00:01Z")) -// farming.EndBlocker(ctx, suite.keeper) -// -// staking, _ = suite.keeper.GetStakingByFarmer(ctx, suite.addrs[0]) -// suite.Require().True(staking.QueuedCoins.IsZero(), "queued coins must be empty") -// suite.Require().True(intEq(sdk.NewInt(1500), staking.StakedCoins.AmountOf(denom1))) -//} From ac9b122e8e1388a00aad9f7bb771de1ea88061c5 Mon Sep 17 00:00:00 2001 From: Hanjun Kim Date: Thu, 9 Sep 2021 23:26:05 +0900 Subject: [PATCH 15/16] test: fix TestAllocateRewards --- x/farming/keeper/keeper_test.go | 4 +- x/farming/keeper/reward_test.go | 85 ++++++++++++++------------------- 2 files changed, 39 insertions(+), 50 deletions(-) diff --git a/x/farming/keeper/keeper_test.go b/x/farming/keeper/keeper_test.go index 57d62041..497599f6 100644 --- a/x/farming/keeper/keeper_test.go +++ b/x/farming/keeper/keeper_test.go @@ -73,7 +73,7 @@ func (suite *KeeperTestSuite) SetupTest() { mustParseRFC3339("2021-08-02T00:00:00Z"), mustParseRFC3339("2021-08-10T00:00:00Z"), ), - sdk.NewCoins(), + sdk.NewCoins(sdk.NewInt64Coin(denom3, 1000000)), ), types.NewFixedAmountPlan( types.NewBasePlan( @@ -88,7 +88,7 @@ func (suite *KeeperTestSuite) SetupTest() { mustParseRFC3339("2021-08-04T00:00:00Z"), mustParseRFC3339("2021-08-12T00:00:00Z"), ), - sdk.NewCoins(), + sdk.NewCoins(sdk.NewInt64Coin(denom3, 2000000)), ), } suite.sampleRatioPlans = []types.PlanI{ diff --git a/x/farming/keeper/reward_test.go b/x/farming/keeper/reward_test.go index 2cefb80e..938b689b 100644 --- a/x/farming/keeper/reward_test.go +++ b/x/farming/keeper/reward_test.go @@ -133,54 +133,43 @@ func (suite *KeeperTestSuite) TestAllocationInfos() { } } -//func (suite *KeeperTestSuite) TestAllocateRewards() { -// plans := []types.PlanI{ -// types.NewFixedAmountPlan( -// types.NewBasePlan( -// 1, -// "", -// types.PlanTypePrivate, -// suite.addrs[0].String(), -// suite.addrs[0].String(), -// sdk.NewDecCoins( -// sdk.NewDecCoinFromDec(denom1, sdk.NewDecWithPrec(3, 1)), -// sdk.NewDecCoinFromDec(denom2, sdk.NewDecWithPrec(7, 1))), -// mustParseRFC3339("2021-07-30T00:00:00Z"), -// mustParseRFC3339("2021-08-30T00:00:00Z"), -// ), -// sdk.NewCoins(sdk.NewInt64Coin(denom3, 1_000_000))), -// } -// for _, plan := range plans { -// suite.keeper.SetPlan(suite.ctx, plan) -// } -// -// suite.Stake(suite.addrs[1], sdk.NewCoins( -// sdk.NewInt64Coin(denom1, 1_000_000), -// sdk.NewInt64Coin(denom2, 1_000_000))) -// suite.keeper.ProcessQueuedCoins(suite.ctx) -// -// suite.ctx = suite.ctx.WithBlockTime(mustParseRFC3339("2021-07-31T00:00:00Z")) -// err := suite.keeper.AllocateRewards(suite.ctx) -// suite.Require().NoError(err) -// -// rewards := suite.keeper.GetRewardsByFarmer(suite.ctx, suite.addrs[1]) -// suite.Require().Len(rewards, 2) -// for _, reward := range rewards { -// switch reward.StakingCoinDenom { -// case denom1: -// suite.Require().True(intEq(sdk.NewInt(300_000), reward.RewardCoins.AmountOf(denom3))) -// case denom2: -// suite.Require().True(intEq(sdk.NewInt(700_000), reward.RewardCoins.AmountOf(denom3))) -// } -// } -// -// plan, _ := suite.keeper.GetPlan(suite.ctx, 1) -// -// suite.Require().True(coinsEq(sdk.NewCoins(sdk.NewInt64Coin(denom3, 1_000_000)), plan.GetDistributedCoins())) -// t := plan.GetLastDistributionTime() -// suite.Require().NotNil(t) -// suite.Require().Equal(suite.ctx.BlockTime(), *t) -//} +func (suite *KeeperTestSuite) TestAllocateRewards() { + for _, plan := range suite.sampleFixedAmtPlans { + _ = plan.SetStartTime(mustParseRFC3339("0001-01-01T00:00:00Z")) + _ = plan.SetEndTime(mustParseRFC3339("9999-12-31T00:00:00Z")) + suite.keeper.SetPlan(suite.ctx, plan) + } + + suite.Stake(suite.addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom1, 1000000))) + suite.Stake(suite.addrs[1], sdk.NewCoins(sdk.NewInt64Coin(denom1, 1000000), sdk.NewInt64Coin(denom2, 1000000))) + suite.keeper.ProcessQueuedCoins(suite.ctx) + + prevDistrCoins := map[uint64]sdk.Coins{} + + t := mustParseRFC3339("2021-09-01T00:00:00Z") + for i := 0; i < 365; i++ { + suite.ctx = suite.ctx.WithBlockTime(t) + + err := suite.keeper.AllocateRewards(suite.ctx) + suite.Require().NoError(err) + + for _, plan := range suite.sampleFixedAmtPlans { + plan, _ := suite.keeper.GetPlan(suite.ctx, plan.GetId()) + fixedAmtPlan := plan.(*types.FixedAmountPlan) + + dist := plan.GetDistributedCoins() + suite.Require().True(coinsEq(prevDistrCoins[plan.GetId()].Add(fixedAmtPlan.EpochAmount...), dist)) + prevDistrCoins[plan.GetId()] = dist + + t2 := plan.GetLastDistributionTime() + suite.Require().NotNil(t2) + suite.Require().Equal(t, *t2) + } + + t = t.AddDate(0, 0, 1) + } +} + // //func (suite *KeeperTestSuite) TestHarvest() { // for _, plan := range suite.samplePlans { From bf27b36bcb02b28b2a4ee6b1e822a10516a2531e Mon Sep 17 00:00:00 2001 From: Hanjun Kim Date: Fri, 10 Sep 2021 13:42:35 +0900 Subject: [PATCH 16/16] test: add TestHarvest --- x/farming/keeper/keeper_test.go | 7 +++++ x/farming/keeper/reward_test.go | 49 ++++++++++++++++----------------- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/x/farming/keeper/keeper_test.go b/x/farming/keeper/keeper_test.go index 497599f6..fd9d3d86 100644 --- a/x/farming/keeper/keeper_test.go +++ b/x/farming/keeper/keeper_test.go @@ -151,6 +151,13 @@ func (suite *KeeperTestSuite) QueuedCoins(farmerAcc sdk.AccAddress) sdk.Coins { return queuedCoins } +func (suite *KeeperTestSuite) Rewards(farmerAcc sdk.AccAddress) sdk.Coins { + cacheCtx, _ := suite.ctx.CacheContext() + rewards, err := suite.keeper.WithdrawAllRewards(cacheCtx, farmerAcc) + suite.Require().NoError(err) + return rewards +} + func intEq(exp, got sdk.Int) (bool, string, string, string) { return exp.Equal(got), "expected:\t%v\ngot:\t\t%v", exp.String(), got.String() } diff --git a/x/farming/keeper/reward_test.go b/x/farming/keeper/reward_test.go index 938b689b..f2440faf 100644 --- a/x/farming/keeper/reward_test.go +++ b/x/farming/keeper/reward_test.go @@ -170,28 +170,27 @@ func (suite *KeeperTestSuite) TestAllocateRewards() { } } -// -//func (suite *KeeperTestSuite) TestHarvest() { -// for _, plan := range suite.samplePlans { -// suite.keeper.SetPlan(suite.ctx, plan) -// } -// -// suite.Stake(suite.addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom1, 1_000_000))) -// suite.keeper.ProcessQueuedCoins(suite.ctx) -// -// balancesBefore := suite.app.BankKeeper.GetAllBalances(suite.ctx, suite.addrs[0]) -// -// suite.ctx = suite.ctx.WithBlockTime(mustParseRFC3339("2021-08-05T00:00:00Z")) -// err := suite.keeper.AllocateRewards(suite.ctx) -// suite.Require().NoError(err) -// -// rewards := suite.keeper.GetRewardsByFarmer(suite.ctx, suite.addrs[0]) -// suite.Require().Len(rewards, 1) -// err = suite.keeper.Harvest(suite.ctx, suite.addrs[0], []string{denom1}) -// suite.Require().NoError(err) -// -// balancesAfter := suite.app.BankKeeper.GetAllBalances(suite.ctx, suite.addrs[0]) -// suite.Require().True(coinsEq(balancesBefore.Add(rewards[0].RewardCoins...), balancesAfter)) -// suite.Require().True(suite.app.BankKeeper.GetAllBalances(suite.ctx, suite.keeper.GetRewardsReservePoolAcc(suite.ctx)).IsZero()) -// suite.Require().Empty(suite.keeper.GetRewardsByFarmer(suite.ctx, suite.addrs[0])) -//} +func (suite *KeeperTestSuite) TestHarvest() { + for _, plan := range suite.samplePlans { + suite.keeper.SetPlan(suite.ctx, plan) + } + + suite.Stake(suite.addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom1, 1_000_000))) + suite.keeper.ProcessQueuedCoins(suite.ctx) + + balancesBefore := suite.app.BankKeeper.GetAllBalances(suite.ctx, suite.addrs[0]) + + suite.ctx = suite.ctx.WithBlockTime(mustParseRFC3339("2021-08-05T00:00:00Z")) + err := suite.keeper.AllocateRewards(suite.ctx) + suite.Require().NoError(err) + + rewards := suite.Rewards(suite.addrs[0]) + + err = suite.keeper.Harvest(suite.ctx, suite.addrs[0], []string{denom1}) + suite.Require().NoError(err) + + balancesAfter := suite.app.BankKeeper.GetAllBalances(suite.ctx, suite.addrs[0]) + suite.Require().True(coinsEq(balancesBefore.Add(rewards...), balancesAfter)) + suite.Require().True(suite.app.BankKeeper.GetAllBalances(suite.ctx, suite.keeper.GetRewardsReservePoolAcc(suite.ctx)).IsZero()) + suite.Require().True(suite.Rewards(suite.addrs[0]).IsZero()) +}