Skip to content

Commit

Permalink
Merge pull request #100 from tendermint/91-f1-distribution-poc
Browse files Browse the repository at this point in the history
  • Loading branch information
dongsam authored Sep 10, 2021
2 parents 72748af + bf27b36 commit 566057d
Show file tree
Hide file tree
Showing 40 changed files with 2,961 additions and 4,105 deletions.
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
72 changes: 17 additions & 55 deletions proto/tendermint/farming/v1beta1/farming.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -146,59 +138,29 @@ message Staking {
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;

// id specifies index of the staking
uint64 id = 1;

// farmer defines the bech32-encoded address of the staker for the plan
string farmer = 2;
string amount = 1 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false];

// 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
];

// 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",
(gogoproto.nullable) = false
];
uint64 starting_epoch = 2 [(gogoproto.moretags) = "yaml:\"starting_epoch\""];
}

// Reward defines a record of farming rewards.
message Reward {
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;
message QueuedStaking {
option (gogoproto.goproto_getters) = false;

// farmer defines the bech32-encoded address of the farmer
string farmer = 1;
string amount = 1 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false];
}

// 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\""];
message TotalStaking {
option (gogoproto.goproto_getters) = 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 = 3 [
(gogoproto.moretags) = "yaml:\"reward_coins\"",
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
(gogoproto.nullable) = false
];
string amount = 1 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (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;
message HistoricalRewards {
option (gogoproto.goproto_getters) = 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",
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
];
}
}
71 changes: 64 additions & 7 deletions proto/tendermint/farming/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,36 @@ 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\""];

// rewards defines the reward records used for genesis state
repeated Reward rewards = 4 [(gogoproto.nullable) = false];
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
];

// 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\""
Expand All @@ -68,4 +74,55 @@ message PlanRecord {
(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 = 3 [
(gogoproto.moretags) = "yaml:\"staking_reserve_coins\"",
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
(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\""];
}
51 changes: 0 additions & 51 deletions proto/tendermint/farming/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +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}";
}

// 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.
Expand Down Expand Up @@ -77,39 +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];
}

// 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;
}
5 changes: 1 addition & 4 deletions x/farming/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
}
2 changes: 1 addition & 1 deletion x/farming/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down
18 changes: 0 additions & 18 deletions x/farming/client/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Loading

0 comments on commit 566057d

Please sign in to comment.