Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: revert x/liquidfarming and add x/liquidamm #171

Merged
merged 18 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
- x/liquidstaking/**/*
"x/liquidfarming":
- x/liquidfarming/**/*
"x/liquidamm":
- x/liquidamm/**/*
"x/mint":
- x/mint/**/*
"x/marketmaker":
Expand Down
36 changes: 29 additions & 7 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,11 @@ import (
"github.com/crescent-network/crescent/v5/x/farming"
farmingkeeper "github.com/crescent-network/crescent/v5/x/farming/keeper"
farmingtypes "github.com/crescent-network/crescent/v5/x/farming/types"
"github.com/crescent-network/crescent/v5/x/liquidamm"
liquidammclient "github.com/crescent-network/crescent/v5/x/liquidamm/client"
liquidammkeeper "github.com/crescent-network/crescent/v5/x/liquidamm/keeper"
liquidammtypes "github.com/crescent-network/crescent/v5/x/liquidamm/types"
"github.com/crescent-network/crescent/v5/x/liquidfarming"
liquidfarmingclient "github.com/crescent-network/crescent/v5/x/liquidfarming/client"
liquidfarmingkeeper "github.com/crescent-network/crescent/v5/x/liquidfarming/keeper"
liquidfarmingtypes "github.com/crescent-network/crescent/v5/x/liquidfarming/types"
"github.com/crescent-network/crescent/v5/x/liquidity"
Expand Down Expand Up @@ -182,8 +185,8 @@ var (
exchangeclient.MarketParameterChangeProposalHandler,
ammclient.PoolParameterChangeProposalHandler,
ammclient.PublicFarmingPlanProposalHandler,
liquidfarmingclient.LiquidFarmCreateProposalHandler,
liquidfarmingclient.LiquidFarmParameterChangeProposalHandler,
liquidammclient.PublicPositionCreateProposalHandler,
liquidammclient.PublicPositionParameterChangeProposalHandler,
),
params.AppModuleBasic{},
crisis.AppModuleBasic{},
Expand All @@ -200,6 +203,7 @@ var (
liquidity.AppModuleBasic{},
liquidstaking.AppModuleBasic{},
liquidfarming.AppModuleBasic{},
liquidamm.AppModuleBasic{},
claim.AppModuleBasic{},
marketmaker.AppModuleBasic{},
lpfarm.AppModuleBasic{},
Expand All @@ -222,6 +226,7 @@ var (
liquiditytypes.ModuleName: {authtypes.Minter, authtypes.Burner},
liquidstakingtypes.ModuleName: {authtypes.Minter, authtypes.Burner},
liquidfarmingtypes.ModuleName: {authtypes.Minter, authtypes.Burner},
liquidammtypes.ModuleName: {authtypes.Minter, authtypes.Burner},
claimtypes.ModuleName: nil,
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
marketmakertypes.ModuleName: nil,
Expand Down Expand Up @@ -281,6 +286,7 @@ type App struct {
LiquidityKeeper liquiditykeeper.Keeper
LiquidStakingKeeper liquidstakingkeeper.Keeper
LiquidFarmingKeeper liquidfarmingkeeper.Keeper
LiquidAMMKeeper liquidammkeeper.Keeper
ClaimKeeper claimkeeper.Keeper
MarketMakerKeeper marketmakerkeeper.Keeper
LPFarmKeeper lpfarmkeeper.Keeper
Expand Down Expand Up @@ -361,6 +367,7 @@ func NewApp(
liquiditytypes.StoreKey,
liquidstakingtypes.StoreKey,
liquidfarmingtypes.StoreKey,
liquidammtypes.StoreKey,
claimtypes.StoreKey,
marketmakertypes.StoreKey,
lpfarmtypes.StoreKey,
Expand Down Expand Up @@ -566,6 +573,15 @@ func NewApp(
app.GetSubspace(liquidfarmingtypes.ModuleName),
app.AccountKeeper,
app.BankKeeper,
app.LPFarmKeeper,
app.LiquidityKeeper,
)
app.LiquidAMMKeeper = liquidammkeeper.NewKeeper(
appCodec,
keys[liquidammtypes.StoreKey],
app.GetSubspace(liquidammtypes.ModuleName),
app.AccountKeeper,
app.BankKeeper,
app.AMMKeeper,
)

Expand All @@ -582,7 +598,7 @@ func NewApp(
AddRoute(lpfarmtypes.RouterKey, lpfarm.NewFarmingPlanProposalHandler(app.LPFarmKeeper)).
AddRoute(exchangetypes.RouterKey, exchange.NewProposalHandler(app.ExchangeKeeper)).
AddRoute(ammtypes.RouterKey, amm.NewProposalHandler(app.AMMKeeper)).
AddRoute(liquidfarmingtypes.RouterKey, liquidfarming.NewProposalHandler(app.LiquidFarmingKeeper))
AddRoute(liquidammtypes.RouterKey, liquidamm.NewProposalHandler(app.LiquidAMMKeeper))

app.GovKeeper = govkeeper.NewKeeper(
appCodec,
Expand Down Expand Up @@ -684,6 +700,7 @@ func NewApp(
farming.NewAppModule(appCodec, app.FarmingKeeper, app.AccountKeeper, app.BankKeeper),
liquidstaking.NewAppModule(appCodec, app.LiquidStakingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GovKeeper),
liquidfarming.NewAppModule(appCodec, app.LiquidFarmingKeeper, app.AccountKeeper, app.BankKeeper),
liquidamm.NewAppModule(appCodec, app.LiquidAMMKeeper, app.AccountKeeper, app.BankKeeper),
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),
lpfarm.NewAppModule(appCodec, app.LPFarmKeeper, app.AccountKeeper, app.BankKeeper, app.LiquidityKeeper),
Expand All @@ -710,6 +727,7 @@ func NewApp(
liquidstakingtypes.ModuleName,
liquiditytypes.ModuleName,
liquidfarmingtypes.ModuleName,
liquidammtypes.ModuleName, // must be prior to amm
ibchost.ModuleName,
ammtypes.ModuleName,
lpfarmtypes.ModuleName,
Expand Down Expand Up @@ -745,7 +763,6 @@ func NewApp(
liquiditytypes.ModuleName,
farmingtypes.ModuleName,
liquidstakingtypes.ModuleName,
liquidfarmingtypes.ModuleName,

// empty logic modules
capabilitytypes.ModuleName,
Expand All @@ -770,6 +787,8 @@ func NewApp(
icatypes.ModuleName,
exchangetypes.ModuleName,
ammtypes.ModuleName,
liquidammtypes.ModuleName,
liquidfarmingtypes.ModuleName,

markertypes.ModuleName,
)
Expand Down Expand Up @@ -799,6 +818,7 @@ func NewApp(
liquiditytypes.ModuleName,
liquidstakingtypes.ModuleName,
liquidfarmingtypes.ModuleName,
liquidammtypes.ModuleName,
claimtypes.ModuleName,
marketmakertypes.ModuleName,
lpfarmtypes.ModuleName,
Expand Down Expand Up @@ -844,8 +864,9 @@ func NewApp(
evidence.NewAppModule(app.EvidenceKeeper),
liquidity.NewAppModule(appCodec, app.LiquidityKeeper, app.AccountKeeper, app.BankKeeper),
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),
liquidfarming.NewAppModule(appCodec, app.LiquidFarmingKeeper, app.AccountKeeper, app.BankKeeper),
claim.NewAppModule(appCodec, app.ClaimKeeper, app.AccountKeeper, app.BankKeeper, app.DistrKeeper, app.GovKeeper, app.LiquidityKeeper, app.LiquidStakingKeeper),
liquidamm.NewAppModule(appCodec, app.LiquidAMMKeeper, app.AccountKeeper, app.BankKeeper),
marketmaker.NewAppModule(appCodec, app.MarketMakerKeeper, app.AccountKeeper, app.BankKeeper),
lpfarm.NewAppModule(appCodec, app.LPFarmKeeper, app.AccountKeeper, app.BankKeeper, app.LiquidityKeeper),
marker.NewAppModule(appCodec, app.MarkerKeeper),
Expand Down Expand Up @@ -1062,6 +1083,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(liquiditytypes.ModuleName)
paramsKeeper.Subspace(liquidstakingtypes.ModuleName)
paramsKeeper.Subspace(liquidfarmingtypes.ModuleName)
paramsKeeper.Subspace(liquidammtypes.ModuleName)
paramsKeeper.Subspace(marketmakertypes.ModuleName)
paramsKeeper.Subspace(lpfarmtypes.ModuleName)
paramsKeeper.Subspace(markertypes.ModuleName)
Expand Down Expand Up @@ -1125,5 +1147,5 @@ func (app *App) SetUpgradeHandlers(mm *module.Manager, configurator module.Confi
v5.UpgradeName, v5.UpgradeHandler(
mm, configurator, app.AccountKeeper, app.BankKeeper, app.DistrKeeper, app.LiquidityKeeper,
app.LPFarmKeeper, app.ExchangeKeeper, app.AMMKeeper, app.MarkerKeeper, app.FarmingKeeper,
app.ClaimKeeper, app.LiquidFarmingKeeper, enableMigrationEventEmit))
app.ClaimKeeper, enableMigrationEventEmit))
}
3 changes: 3 additions & 0 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/crescent-network/crescent/v5/x/claim"
"github.com/crescent-network/crescent/v5/x/exchange"
"github.com/crescent-network/crescent/v5/x/farming"
"github.com/crescent-network/crescent/v5/x/liquidamm"
"github.com/crescent-network/crescent/v5/x/liquidfarming"
"github.com/crescent-network/crescent/v5/x/liquidity"
"github.com/crescent-network/crescent/v5/x/liquidstaking"
Expand Down Expand Up @@ -197,6 +198,7 @@ func TestRunMigrations(t *testing.T) {
"liquidity": liquidity.AppModule{}.ConsensusVersion(),
"liquidstaking": liquidstaking.AppModule{}.ConsensusVersion(),
"liquidfarming": liquidfarming.AppModule{}.ConsensusVersion(),
"liquidamm": liquidamm.AppModule{}.ConsensusVersion(),
"claim": claim.AppModule{}.ConsensusVersion(),
"marketmaker": marketmaker.AppModule{}.ConsensusVersion(),
"lpfarm": lpfarm.AppModule{}.ConsensusVersion(),
Expand Down Expand Up @@ -262,6 +264,7 @@ func TestInitGenesisOnMigration(t *testing.T) {
"liquidity": liquidity.AppModule{}.ConsensusVersion(),
"liquidstaking": liquidstaking.AppModule{}.ConsensusVersion(),
"liquidfarming": liquidfarming.AppModule{}.ConsensusVersion(),
"liquidamm": liquidamm.AppModule{}.ConsensusVersion(),
"claim": claim.AppModule{}.ConsensusVersion(),
"marketmaker": marketmaker.AppModule{}.ConsensusVersion(),
"lpfarm": lpfarm.AppModule{}.ConsensusVersion(),
Expand Down
10 changes: 5 additions & 5 deletions app/params/weights.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ const (
// Deprecated claim module
DefaultWeightMsgClaim int = 0

DefaultWeightMsgLiquidFarm int = 50
DefaultWeightMsgLiquidUnfarm int = 10
DefaultWeightMsgPlaceBid int = 20
DefaultWeightMsgRefundBid int = 5

DefaultWeightAddPublicPlanProposal int = 5
DefaultWeightUpdatePublicPlanProposal int = 5
DefaultWeightDeletePublicPlanProposal int = 5
Expand All @@ -39,11 +44,6 @@ const (
DefaultWeightCompleteRedelegationUnbonding int = 30
DefaultWeightTallyWithLiquidStaking int = 30

DefaultWeightMsgLiquidFarm int = 50
DefaultWeightMsgLiquidUnfarm int = 10
DefaultWeightMsgPlaceBid int = 20
DefaultWeightMsgRefundBid int = 5

DefaultWeightMsgApplyMarketMaker int = 20
DefaultWeightMsgClaimIncentives int = 10

Expand Down
4 changes: 2 additions & 2 deletions app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (
claimtypes "github.com/crescent-network/crescent/v5/x/claim/types"
exchangetypes "github.com/crescent-network/crescent/v5/x/exchange/types"
farmingtypes "github.com/crescent-network/crescent/v5/x/farming/types"
liquidfarmingtypes "github.com/crescent-network/crescent/v5/x/liquidfarming/types"
liquidammtypes "github.com/crescent-network/crescent/v5/x/liquidamm/types"
liquiditytypes "github.com/crescent-network/crescent/v5/x/liquidity/types"
liquidstakingtypes "github.com/crescent-network/crescent/v5/x/liquidstaking/types"
lpfarmtypes "github.com/crescent-network/crescent/v5/x/lpfarm/types"
Expand Down Expand Up @@ -203,7 +203,7 @@ func TestAppImportExport(t *testing.T) {
{app.keys[lpfarmtypes.StoreKey], newApp.keys[lpfarmtypes.StoreKey], [][]byte{}},
{app.keys[exchangetypes.StoreKey], newApp.keys[exchangetypes.StoreKey], [][]byte{}},
{app.keys[ammtypes.StoreKey], newApp.keys[ammtypes.StoreKey], [][]byte{}},
{app.keys[liquidfarmingtypes.StoreKey], newApp.keys[liquidfarmingtypes.StoreKey], [][]byte{}},
{app.keys[liquidammtypes.StoreKey], newApp.keys[liquidammtypes.StoreKey], [][]byte{}},
{app.keys[ibchost.StoreKey], newApp.keys[ibchost.StoreKey], [][]byte{}},
{app.keys[ibctransfertypes.StoreKey], newApp.keys[ibctransfertypes.StoreKey], [][]byte{}},
}
Expand Down
49 changes: 49 additions & 0 deletions app/testutil/liquidamm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package testutil

import (
sdk "github.com/cosmos/cosmos-sdk/types"

ammtypes "github.com/crescent-network/crescent/v5/x/amm/types"
liquidammtypes "github.com/crescent-network/crescent/v5/x/liquidamm/types"
)

func (s *TestSuite) CreatePublicPosition(poolId uint64, lowerPrice, upperPrice sdk.Dec, minBidAmt sdk.Int, feeRate sdk.Dec) (publicPosition liquidammtypes.PublicPosition) {
s.T().Helper()
var err error
publicPosition, err = s.App.LiquidAMMKeeper.CreatePublicPosition(s.Ctx, poolId, lowerPrice, upperPrice, minBidAmt, feeRate)
s.Require().NoError(err)
return
}

func (s *TestSuite) MintShare(senderAddr sdk.AccAddress, publicPositionId uint64, desiredAmt sdk.Coins, fund bool) (mintedShare sdk.Coin, position ammtypes.Position, liquidity sdk.Int, amt sdk.Coins) {
s.T().Helper()
if fund {
s.FundAccount(senderAddr, desiredAmt)
}
var err error
mintedShare, position, liquidity, amt, err = s.App.LiquidAMMKeeper.MintShare(s.Ctx, senderAddr, publicPositionId, desiredAmt)
s.Require().NoError(err)
return
}

func (s *TestSuite) BurnShare(senderAddr sdk.AccAddress, publicPositionId uint64, share sdk.Coin) (removedLiquidity sdk.Int, position ammtypes.Position, amt sdk.Coins) {
s.T().Helper()
var err error
removedLiquidity, position, amt, err = s.App.LiquidAMMKeeper.BurnShare(s.Ctx, senderAddr, publicPositionId, share)
s.Require().NoError(err)
return
}

func (s *TestSuite) PlaceBid(bidderAddr sdk.AccAddress, positionId, auctionId uint64, share sdk.Coin) (bid liquidammtypes.Bid) {
s.T().Helper()
var err error
bid, err = s.App.LiquidAMMKeeper.PlaceBid(s.Ctx, bidderAddr, positionId, auctionId, share)
s.Require().NoError(err)
return
}

func (s *TestSuite) AdvanceRewardsAuctions() {
s.T().Helper()
nextEndTime := s.Ctx.BlockTime().Add(s.App.LiquidAMMKeeper.GetRewardsAuctionDuration(s.Ctx))
s.Require().NoError(s.App.LiquidAMMKeeper.AdvanceRewardsAuctions(s.Ctx, nextEndTime))
}
49 changes: 0 additions & 49 deletions app/testutil/liquidfarming.go

This file was deleted.

4 changes: 2 additions & 2 deletions app/upgrades/mainnet/v3/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

farmingkeeper "github.com/crescent-network/crescent/v5/x/farming/keeper"
farmingtypes "github.com/crescent-network/crescent/v5/x/farming/types"
liquidfarmingtypes "github.com/crescent-network/crescent/v5/x/liquidfarming/types"
liquidammtypes "github.com/crescent-network/crescent/v5/x/liquidamm/types"
liquiditykeeper "github.com/crescent-network/crescent/v5/x/liquidity/keeper"
liquiditytypes "github.com/crescent-network/crescent/v5/x/liquidity/types"
lpfarmkeeper "github.com/crescent-network/crescent/v5/x/lpfarm/keeper"
Expand Down Expand Up @@ -136,6 +136,6 @@ var StoreUpgrades = store.StoreUpgrades{
Added: []string{
marketmakertypes.ModuleName,
lpfarmtypes.ModuleName,
liquidfarmingtypes.ModuleName,
liquidammtypes.ModuleName,
},
}
5 changes: 1 addition & 4 deletions app/upgrades/mainnet/v5/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (
exchangetypes "github.com/crescent-network/crescent/v5/x/exchange/types"
farmingkeeper "github.com/crescent-network/crescent/v5/x/farming/keeper"
farmingtypes "github.com/crescent-network/crescent/v5/x/farming/types"
liquidfarmingkeeper "github.com/crescent-network/crescent/v5/x/liquidfarming/keeper"
liquidfarmingtypes "github.com/crescent-network/crescent/v5/x/liquidfarming/types"
liquiditykeeper "github.com/crescent-network/crescent/v5/x/liquidity/keeper"
liquiditytypes "github.com/crescent-network/crescent/v5/x/liquidity/types"
lpfarmkeeper "github.com/crescent-network/crescent/v5/x/lpfarm/keeper"
Expand All @@ -48,7 +46,7 @@ func UpgradeHandler(
bankKeeper bankkeeper.Keeper, distrKeeper distrkeeper.Keeper, liquidityKeeper liquiditykeeper.Keeper,
lpFarmKeeper lpfarmkeeper.Keeper, exchangeKeeper exchangekeeper.Keeper, ammKeeper ammkeeper.Keeper,
markerKeeper markerkeeper.Keeper, farmingKeeper farmingkeeper.Keeper, claimKeeper claimkeeper.Keeper,
liquidFarmingKeeper liquidfarmingkeeper.Keeper, disableUpgradeEvents bool) upgradetypes.UpgradeHandler {
disableUpgradeEvents bool) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
vm, err := mm.RunMigrations(ctx, configurator, fromVM)
if err != nil {
Expand All @@ -65,7 +63,6 @@ func UpgradeHandler(
exchangeKeeper.SetParams(ctx, exchangeParams)
ammParams := ammtypes.DefaultParams()
ammKeeper.SetParams(ctx, ammParams)
liquidFarmingKeeper.SetMaxNumRecentRewardsAuctions(ctx, liquidfarmingtypes.DefaultMaxNumRecentRewardsAuctions)

// Migrate farming plans and staked coins to the new amm module.

Expand Down
Loading
Loading