-
Notifications
You must be signed in to change notification settings - Fork 609
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Protorev: Post Handler + Proposal Handlers + Profit Sharing (#3806)
* new stores for admin and developer functionality + epoch fully implemented * testing for new store setters and getters + small update to stores * adding proposal handlers for protorev + test suite * implementing the developer fee split + testing * init for post handler testing updates nit * off by one edge case for fee splitting * Add posthandler functionality and tests Remove checkTx skip linting update after posthandler addition * rebasing and updating routes to swaprouter types * rebase, logging, clean up of proposal cli * constraining protorev by # routes traversed * nit * point system for route building * nit + posthandler checkTx update * configurable route weights * rebase * PR updates, moving constants to new file * rebase * additional comments for execution bounding Co-authored-by: Jeremy Liu <[email protected]>
- Loading branch information
1 parent
c3580f6
commit 6d668bf
Showing
30 changed files
with
2,341 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package app | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
protorevkeeper "github.com/osmosis-labs/osmosis/v14/x/protorev/keeper" | ||
) | ||
|
||
func NewPostHandler(protoRevKeeper *protorevkeeper.Keeper) sdk.AnteHandler { | ||
protoRevDecorator := protorevkeeper.NewProtoRevDecorator(*protoRevKeeper) | ||
return sdk.ChainAnteDecorators(protoRevDecorator) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/cosmos/cosmos-sdk/client/tx" | ||
"github.com/cosmos/cosmos-sdk/version" | ||
"github.com/cosmos/cosmos-sdk/x/gov/client/cli" | ||
"github.com/spf13/cobra" | ||
|
||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" | ||
|
||
"github.com/osmosis-labs/osmosis/osmoutils/osmocli" | ||
"github.com/osmosis-labs/osmosis/v14/x/protorev/types" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
func NewCmdTx() *cobra.Command { | ||
txCmd := osmocli.TxIndexCmd(types.ModuleName) | ||
txCmd.AddCommand( | ||
CmdSetProtoRevAdminAccountProposal(), | ||
CmdSetProtoRevEnabledProposal(), | ||
) | ||
return txCmd | ||
} | ||
|
||
// CmdSetProtoRevAdminAccountProposal implements the command to submit a SetProtoRevAdminAccountProposal | ||
func CmdSetProtoRevAdminAccountProposal() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "set-protorev-admin-account-proposal [sdk.AccAddress]", | ||
Args: cobra.ExactArgs(1), | ||
Short: "submit a set protorev admin account proposal to set the admin account for x/protorev", | ||
Example: fmt.Sprintf(`$ %s tx protorev set-protorev-admin-account osmo123... --from mykey`, version.AppName), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
createContent := func(title string, description string, args ...string) (govtypes.Content, error) { | ||
return types.NewSetProtoRevAdminAccountProposal(title, description, args[0]), nil | ||
} | ||
|
||
return ProposalExecute(cmd, args, createContent) | ||
}, | ||
} | ||
|
||
cmd.Flags().String(cli.FlagTitle, "", "title of proposal") | ||
cmd.Flags().String(cli.FlagDescription, "", "description of proposal") | ||
cmd.Flags().String(cli.FlagDeposit, "", "deposit of proposal") | ||
flags.AddTxFlagsToCmd(cmd) | ||
_ = cmd.MarkFlagRequired(cli.FlagTitle) | ||
_ = cmd.MarkFlagRequired(cli.FlagDescription) | ||
|
||
return cmd | ||
} | ||
|
||
// CmdSetProtoRevEnabledProposal implements the command to submit a SetProtoRevEnabledProposal | ||
func CmdSetProtoRevEnabledProposal() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "set-protorev-enabled-proposal [boolean]", | ||
Args: cobra.ExactArgs(1), | ||
Short: "submit a set protorev enabled proposal to enable or disable the protocol", | ||
Example: fmt.Sprintf(`$ %s tx protorev set-protorev-enabled true --from mykey`, version.AppName), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
createContent := func(title string, description string, args ...string) (govtypes.Content, error) { | ||
res, err := strconv.ParseBool(args[0]) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
content := types.NewSetProtoRevEnabledProposal(title, description, res) | ||
return content, nil | ||
} | ||
|
||
return ProposalExecute(cmd, args, createContent) | ||
}, | ||
} | ||
|
||
cmd.Flags().String(cli.FlagTitle, "", "title of proposal") | ||
cmd.Flags().String(cli.FlagDescription, "", "description of proposal") | ||
cmd.Flags().String(cli.FlagDeposit, "", "deposit of proposal") | ||
flags.AddTxFlagsToCmd(cmd) | ||
_ = cmd.MarkFlagRequired(cli.FlagTitle) | ||
_ = cmd.MarkFlagRequired(cli.FlagDescription) | ||
|
||
return cmd | ||
} | ||
|
||
// ProposalExecute is a helper function to execute a proposal command. It takes in a function to create the proposal content. | ||
func ProposalExecute(cmd *cobra.Command, args []string, createContent func(title string, description string, args ...string) (govtypes.Content, error)) error { | ||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
title, err := cmd.Flags().GetString(cli.FlagTitle) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
description, err := cmd.Flags().GetString(cli.FlagDescription) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
depositStr, err := cmd.Flags().GetString(cli.FlagDeposit) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
deposit, err := sdk.ParseCoinsNormalized(depositStr) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
from := clientCtx.GetFromAddress() | ||
|
||
content, err := createContent(title, description, args...) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
msg, err := govtypes.NewMsgSubmitProposal(content, deposit, from) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err = msg.ValidateBasic(); err != nil { | ||
return err | ||
} | ||
|
||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package keeper | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/osmosis-labs/osmosis/v14/x/protorev/types" | ||
) | ||
|
||
// SendDeveloperFeesToDeveloperAccount sends the developer fees from the module account to the developer account | ||
func (k Keeper) SendDeveloperFeesToDeveloperAccount(ctx sdk.Context) error { | ||
// Developer account must be set in order to be able to withdraw developer fees | ||
developerAccount, err := k.GetDeveloperAccount(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
coins := k.GetAllDeveloperFees(ctx) | ||
|
||
for _, coin := range coins { | ||
// Send the coins to the developer account | ||
if err := k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, developerAccount, sdk.NewCoins(coin)); err != nil { | ||
return err | ||
} | ||
|
||
// Reset the developer fees for the coin | ||
k.DeleteDeveloperFees(ctx, coin.Denom) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// UpdateDeveloperFees updates the fees that developers can withdraw from the module account | ||
func (k Keeper) UpdateDeveloperFees(ctx sdk.Context, denom string, profit sdk.Int) error { | ||
daysSinceGenesis, err := k.GetDaysSinceModuleGenesis(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Calculate the developer fee | ||
if daysSinceGenesis < types.Phase1Length { | ||
profit = profit.MulRaw(types.ProfitSplitPhase1).QuoRaw(100) | ||
} else if daysSinceGenesis < types.Phase2Length { | ||
profit = profit.MulRaw(types.ProfitSplitPhase2).QuoRaw(100) | ||
} else { | ||
profit = profit.MulRaw(types.ProfitSplitPhase3).QuoRaw(100) | ||
} | ||
|
||
// Get the developer fees for the denom, if not there then set it to 0 and initialize it | ||
currentDeveloperFee, err := k.GetDeveloperFees(ctx, denom) | ||
if err != nil { | ||
currentDeveloperFee = sdk.NewCoin(denom, sdk.ZeroInt()) | ||
} | ||
currentDeveloperFee.Amount = currentDeveloperFee.Amount.Add(profit) | ||
|
||
// Set the developer fees for the denom | ||
if err = k.SetDeveloperFees(ctx, currentDeveloperFee); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.