Skip to content

Commit

Permalink
Merge pull request #362 from cosmosquad-labs/farm-module
Browse files Browse the repository at this point in the history
feat: add x/farm module
  • Loading branch information
hallazzang authored Oct 5, 2022
2 parents af90e4e + 5585f1e commit 8ec2d0f
Show file tree
Hide file tree
Showing 71 changed files with 19,589 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
- x/mint/**/*
"x/marketmaker":
- x/marketmaker/**/*
"x/farm":
- x/farm/**/*
"c-sync":
- x/claim/**/*
- x/farming/**/*
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
repos:
# commit msg check
- repo: https://github.com/compilerla/conventional-pre-commit
rev: v1.0.0
rev: v2.0.0
hooks:
- id: conventional-pre-commit
stages: [commit-msg]
Expand Down
24 changes: 23 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ import (
"github.com/cosmosquad-labs/squad/v3/x/claim"
claimkeeper "github.com/cosmosquad-labs/squad/v3/x/claim/keeper"
claimtypes "github.com/cosmosquad-labs/squad/v3/x/claim/types"
"github.com/cosmosquad-labs/squad/v3/x/farm"
farmkeeper "github.com/cosmosquad-labs/squad/v3/x/farm/keeper"
farmtypes "github.com/cosmosquad-labs/squad/v3/x/farm/types"
"github.com/cosmosquad-labs/squad/v3/x/farming"
farmingclient "github.com/cosmosquad-labs/squad/v3/x/farming/client"
farmingkeeper "github.com/cosmosquad-labs/squad/v3/x/farming/keeper"
Expand Down Expand Up @@ -164,6 +167,7 @@ var (
liquidstaking.AppModuleBasic{},
claim.AppModuleBasic{},
marketmaker.AppModuleBasic{},
farm.AppModuleBasic{},
)

// module account permissions
Expand All @@ -181,6 +185,7 @@ var (
claimtypes.ModuleName: nil,
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
marketmakertypes.ModuleName: nil,
farmtypes.ModuleName: nil,
}
)

Expand Down Expand Up @@ -229,6 +234,7 @@ type App struct {
LiquidStakingKeeper liquidstakingkeeper.Keeper
ClaimKeeper claimkeeper.Keeper
MarketMakerKeeper marketmakerkeeper.Keeper
FarmKeeper farmkeeper.Keeper

ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
Expand Down Expand Up @@ -297,6 +303,7 @@ func NewApp(
liquidstakingtypes.StoreKey,
claimtypes.StoreKey,
marketmakertypes.StoreKey,
farmtypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -444,6 +451,14 @@ func NewApp(
app.AccountKeeper,
app.BankKeeper,
)
app.FarmKeeper = farmkeeper.NewKeeper(
appCodec,
keys[farmtypes.StoreKey],
app.GetSubspace(farmtypes.ModuleName),
app.AccountKeeper,
app.BankKeeper,
app.LiquidityKeeper,
)

// register the proposal types
govRouter := govtypes.NewRouter()
Expand All @@ -454,7 +469,8 @@ func NewApp(
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)).
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper)).
AddRoute(farmingtypes.RouterKey, farming.NewPublicPlanProposalHandler(app.FarmingKeeper)).
AddRoute(marketmakertypes.RouterKey, marketmaker.NewMarketMakerProposalHandler(app.MarketMakerKeeper))
AddRoute(marketmakertypes.RouterKey, marketmaker.NewMarketMakerProposalHandler(app.MarketMakerKeeper)).
AddRoute(farmtypes.RouterKey, farm.NewFarmingPlanProposalHandler(app.FarmKeeper))

app.GovKeeper = govkeeper.NewKeeper(
appCodec,
Expand Down Expand Up @@ -555,6 +571,7 @@ func NewApp(
liquidstaking.NewAppModule(appCodec, app.LiquidStakingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GovKeeper),
claim.NewAppModule(appCodec, app.ClaimKeeper, app.AccountKeeper, app.BankKeeper, app.DistrKeeper, app.GovKeeper, app.LiquidityKeeper, app.LiquidStakingKeeper),
marketmaker.NewAppModule(appCodec, app.MarketMakerKeeper, app.AccountKeeper, app.BankKeeper),
farm.NewAppModule(appCodec, app.FarmKeeper, app.AccountKeeper, app.BankKeeper, app.LiquidityKeeper),
app.transferModule,
)

Expand All @@ -574,6 +591,7 @@ func NewApp(
liquidstakingtypes.ModuleName,
liquiditytypes.ModuleName,
ibchost.ModuleName,
farmtypes.ModuleName,

// empty logic modules
authtypes.ModuleName,
Expand Down Expand Up @@ -618,6 +636,7 @@ func NewApp(
claimtypes.ModuleName,
budgettypes.ModuleName,
marketmakertypes.ModuleName,
farmtypes.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand Down Expand Up @@ -646,6 +665,7 @@ func NewApp(
liquidstakingtypes.ModuleName,
claimtypes.ModuleName,
marketmakertypes.ModuleName,
farmtypes.ModuleName,

// empty logic modules
paramstypes.ModuleName,
Expand Down Expand Up @@ -686,6 +706,7 @@ func NewApp(
liquidstaking.NewAppModule(appCodec, app.LiquidStakingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GovKeeper),
claim.NewAppModule(appCodec, app.ClaimKeeper, app.AccountKeeper, app.BankKeeper, app.DistrKeeper, app.GovKeeper, app.LiquidityKeeper, app.LiquidStakingKeeper),
marketmaker.NewAppModule(appCodec, app.MarketMakerKeeper, app.AccountKeeper, app.BankKeeper),
farm.NewAppModule(appCodec, app.FarmKeeper, app.AccountKeeper, app.BankKeeper, app.LiquidityKeeper),
ibc.NewAppModule(app.IBCKeeper),
app.transferModule,
)
Expand Down Expand Up @@ -891,6 +912,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(liquiditytypes.ModuleName)
paramsKeeper.Subspace(liquidstakingtypes.ModuleName)
paramsKeeper.Subspace(marketmakertypes.ModuleName)
paramsKeeper.Subspace(farmtypes.ModuleName)

return paramsKeeper
}
Expand Down
3 changes: 3 additions & 0 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
dbm "github.com/tendermint/tm-db"

"github.com/cosmosquad-labs/squad/v3/x/claim"
"github.com/cosmosquad-labs/squad/v3/x/farm"
"github.com/cosmosquad-labs/squad/v3/x/farming"
"github.com/cosmosquad-labs/squad/v3/x/liquidity"
"github.com/cosmosquad-labs/squad/v3/x/liquidstaking"
Expand Down Expand Up @@ -194,6 +195,7 @@ func TestRunMigrations(t *testing.T) {
"liquidstaking": liquidstaking.AppModule{}.ConsensusVersion(),
"claim": claim.AppModule{}.ConsensusVersion(),
"marketmaker": marketmaker.AppModule{}.ConsensusVersion(),
"farm": farm.AppModule{}.ConsensusVersion(),
"ibc": ibc.AppModule{}.ConsensusVersion(),
"transfer": transfer.AppModule{}.ConsensusVersion(),
},
Expand Down Expand Up @@ -254,6 +256,7 @@ func TestInitGenesisOnMigration(t *testing.T) {
"liquidstaking": liquidstaking.AppModule{}.ConsensusVersion(),
"claim": claim.AppModule{}.ConsensusVersion(),
"marketmaker": marketmaker.AppModule{}.ConsensusVersion(),
"farm": farm.AppModule{}.ConsensusVersion(),
"ibc": ibc.AppModule{}.ConsensusVersion(),
"transfer": transfer.AppModule{}.ConsensusVersion(),
},
Expand Down
2 changes: 2 additions & 0 deletions app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
dbm "github.com/tendermint/tm-db"

claimtypes "github.com/cosmosquad-labs/squad/v3/x/claim/types"
farmtypes "github.com/cosmosquad-labs/squad/v3/x/farm/types"
farmingtypes "github.com/cosmosquad-labs/squad/v3/x/farming/types"
liquiditytypes "github.com/cosmosquad-labs/squad/v3/x/liquidity/types"
liquidstakingtypes "github.com/cosmosquad-labs/squad/v3/x/liquidstaking/types"
Expand Down Expand Up @@ -194,6 +195,7 @@ func TestAppImportExport(t *testing.T) {
{app.keys[liquiditytypes.StoreKey], newApp.keys[liquiditytypes.StoreKey], [][]byte{}},
{app.keys[claimtypes.StoreKey], newApp.keys[claimtypes.StoreKey], [][]byte{}},
{app.keys[marketmakertypes.StoreKey], newApp.keys[marketmakertypes.StoreKey], [][]byte{}},
{app.keys[farmtypes.StoreKey], newApp.keys[farmtypes.StoreKey], [][]byte{}},
{app.keys[ibchost.StoreKey], newApp.keys[ibchost.StoreKey], [][]byte{}},
{app.keys[ibctransfertypes.StoreKey], newApp.keys[ibctransfertypes.StoreKey], [][]byte{}},
}
Expand Down
40 changes: 40 additions & 0 deletions proto/squad/farm/v1beta1/events.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
syntax = "proto3";

package squad.farm.v1beta1;

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";

option go_package = "github.com/cosmosquad-labs/squad/x/farm/types";
option (gogoproto.goproto_getters_all) = false;

message EventCreatePrivatePlan {
string creator = 1;
uint64 plan_id = 2;
string farming_pool_address = 3;
}

message EventFarm {
string farmer = 1;
cosmos.base.v1beta1.Coin coin = 2 [(gogoproto.nullable) = false];
repeated cosmos.base.v1beta1.Coin withdrawn_rewards = 3
[(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", (gogoproto.nullable) = false];
}

message EventUnfarm {
string farmer = 1;
cosmos.base.v1beta1.Coin coin = 2 [(gogoproto.nullable) = false];
repeated cosmos.base.v1beta1.Coin withdrawn_rewards = 3
[(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", (gogoproto.nullable) = false];
}

message EventHarvest {
string farmer = 1;
string denom = 2;
repeated cosmos.base.v1beta1.Coin withdrawn_rewards = 3
[(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", (gogoproto.nullable) = false];
}

message EventTerminatePlan {
uint64 plan_id = 1;
}
62 changes: 62 additions & 0 deletions proto/squad/farm/v1beta1/farm.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
syntax = "proto3";

package squad.farm.v1beta1;

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
import "google/protobuf/timestamp.proto";
import "google/protobuf/duration.proto";

option go_package = "github.com/cosmosquad-labs/squad/x/farm/types";
option (gogoproto.goproto_getters_all) = false;

message Params {
repeated cosmos.base.v1beta1.Coin private_plan_creation_fee = 1
[(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", (gogoproto.nullable) = false];
string fee_collector = 2;
uint32 max_num_private_plans = 3;
google.protobuf.Duration max_block_duration = 4 [(gogoproto.stdduration) = true, (gogoproto.nullable) = false];
}

message Plan {
uint64 id = 1;
string description = 2;
string farming_pool_address = 3;
string termination_address = 4;
repeated RewardAllocation reward_allocations = 5 [(gogoproto.nullable) = false];
google.protobuf.Timestamp start_time = 6 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
google.protobuf.Timestamp end_time = 7 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
bool is_private = 8;
bool is_terminated = 9;
}

message RewardAllocation {
uint64 pair_id = 1;
repeated cosmos.base.v1beta1.Coin rewards_per_day = 2
[(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", (gogoproto.nullable) = false];
}

message Farm {
string total_farming_amount = 1
[(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false];
repeated cosmos.base.v1beta1.DecCoin current_rewards = 2
[(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins", (gogoproto.nullable) = false];
repeated cosmos.base.v1beta1.DecCoin outstanding_rewards = 3
[(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins", (gogoproto.nullable) = false];
uint64 period = 4;
}

message Position {
string farmer = 1;
string denom = 2;
string farming_amount = 3
[(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false];
uint64 previous_period = 4;
int64 starting_block_height = 5;
}

message HistoricalRewards {
repeated cosmos.base.v1beta1.DecCoin cumulative_unit_rewards = 1
[(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins", (gogoproto.nullable) = false];
uint32 reference_count = 2;
}
32 changes: 32 additions & 0 deletions proto/squad/farm/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
syntax = "proto3";

package squad.farm.v1beta1;

import "gogoproto/gogo.proto";
import "squad/farm/v1beta1/farm.proto";
import "google/protobuf/timestamp.proto";

option go_package = "github.com/cosmosquad-labs/squad/x/farm/types";
option (gogoproto.goproto_getters_all) = false;

message GenesisState {
Params params = 1 [(gogoproto.nullable) = false];
google.protobuf.Timestamp last_block_time = 2 [(gogoproto.stdtime) = true];
uint64 last_plan_id = 3;
uint64 num_private_plans = 4;
repeated Plan plans = 5 [(gogoproto.nullable) = false];
repeated FarmRecord farms = 6 [(gogoproto.nullable) = false];
repeated Position positions = 7 [(gogoproto.nullable) = false];
repeated HistoricalRewardsRecord historical_rewards = 8 [(gogoproto.nullable) = false];
}

message FarmRecord {
string denom = 1;
Farm farm = 2 [(gogoproto.nullable) = false];
}

message HistoricalRewardsRecord {
string denom = 1;
uint64 period = 2;
HistoricalRewards historical_rewards = 3 [(gogoproto.nullable) = false];
}
31 changes: 31 additions & 0 deletions proto/squad/farm/v1beta1/proposal.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
syntax = "proto3";

package squad.farm.v1beta1;

import "gogoproto/gogo.proto";
import "squad/farm/v1beta1/farm.proto";
import "google/protobuf/timestamp.proto";

option go_package = "github.com/cosmosquad-labs/squad/x/farm/types";
option (gogoproto.goproto_getters_all) = false;

message FarmingPlanProposal {
option (gogoproto.goproto_stringer) = false;
string title = 1;
string description = 2;
repeated CreatePlanRequest create_plan_requests = 3 [(gogoproto.nullable) = false];
repeated TerminatePlanRequest terminate_plan_requests = 4 [(gogoproto.nullable) = false];
}

message CreatePlanRequest {
string description = 1;
string farming_pool_address = 2;
string termination_address = 3;
repeated RewardAllocation reward_allocations = 4 [(gogoproto.nullable) = false];
google.protobuf.Timestamp start_time = 5 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
google.protobuf.Timestamp end_time = 6 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
}

message TerminatePlanRequest {
uint64 plan_id = 1;
}
Loading

0 comments on commit 8ec2d0f

Please sign in to comment.