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

ProtoRev PR 1 + 2 Rebase #3681

Merged
merged 3 commits into from
Dec 10, 2022
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
12 changes: 12 additions & 0 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ import (
poolincentives "github.com/osmosis-labs/osmosis/v13/x/pool-incentives"
poolincentiveskeeper "github.com/osmosis-labs/osmosis/v13/x/pool-incentives/keeper"
poolincentivestypes "github.com/osmosis-labs/osmosis/v13/x/pool-incentives/types"
protorevkeeper "github.com/osmosis-labs/osmosis/v13/x/protorev/keeper"
protorevtypes "github.com/osmosis-labs/osmosis/v13/x/protorev/types"
"github.com/osmosis-labs/osmosis/v13/x/superfluid"
superfluidkeeper "github.com/osmosis-labs/osmosis/v13/x/superfluid/keeper"
superfluidtypes "github.com/osmosis-labs/osmosis/v13/x/superfluid/types"
Expand Down Expand Up @@ -112,6 +114,7 @@ type AppKeepers struct {
LockupKeeper *lockupkeeper.Keeper
EpochsKeeper *epochskeeper.Keeper
IncentivesKeeper *incentiveskeeper.Keeper
ProtoRevKeeper *protorevkeeper.Keeper
MintKeeper *mintkeeper.Keeper
PoolIncentivesKeeper *poolincentiveskeeper.Keeper
TxFeesKeeper *txfeeskeeper.Keeper
Expand Down Expand Up @@ -263,6 +266,12 @@ func (appKeepers *AppKeepers) InitNormalKeepers(

appKeepers.EpochsKeeper = epochskeeper.NewKeeper(appKeepers.keys[epochstypes.StoreKey])

protorevKeeper := protorevkeeper.NewKeeper(
appCodec, appKeepers.keys[protorevtypes.StoreKey],
appKeepers.GetSubspace(protorevtypes.ModuleName),
appKeepers.AccountKeeper, appKeepers.BankKeeper, appKeepers.GAMMKeeper, appKeepers.EpochsKeeper)
appKeepers.ProtoRevKeeper = &protorevKeeper

txFeesKeeper := txfeeskeeper.NewKeeper(
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
Expand Down Expand Up @@ -505,6 +514,7 @@ func (appKeepers *AppKeepers) initParamsKeeper(appCodec codec.BinaryCodec, legac
paramsKeeper.Subspace(incentivestypes.ModuleName)
paramsKeeper.Subspace(lockuptypes.ModuleName)
paramsKeeper.Subspace(poolincentivestypes.ModuleName)
paramsKeeper.Subspace(protorevtypes.ModuleName)
paramsKeeper.Subspace(superfluidtypes.ModuleName)
paramsKeeper.Subspace(gammtypes.ModuleName)
paramsKeeper.Subspace(wasm.ModuleName)
Expand Down Expand Up @@ -566,6 +576,7 @@ func (appKeepers *AppKeepers) SetupHooks() {
appKeepers.SuperfluidKeeper.Hooks(),
appKeepers.IncentivesKeeper.Hooks(),
appKeepers.MintKeeper.Hooks(),
appKeepers.ProtoRevKeeper.EpochHooks(),
),
)

Expand Down Expand Up @@ -605,5 +616,6 @@ func KVStoreKeys() []string {
wasm.StoreKey,
tokenfactorytypes.StoreKey,
valsetpreftypes.StoreKey,
protorevtypes.StoreKey,
}
}
2 changes: 2 additions & 0 deletions app/keepers/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/osmosis-labs/osmosis/v13/x/mint"
poolincentives "github.com/osmosis-labs/osmosis/v13/x/pool-incentives"
poolincentivesclient "github.com/osmosis-labs/osmosis/v13/x/pool-incentives/client"
"github.com/osmosis-labs/osmosis/v13/x/protorev"
superfluid "github.com/osmosis-labs/osmosis/v13/x/superfluid"
superfluidclient "github.com/osmosis-labs/osmosis/v13/x/superfluid/client"
"github.com/osmosis-labs/osmosis/v13/x/tokenfactory"
Expand Down Expand Up @@ -81,6 +82,7 @@ var AppModuleBasics = []module.AppModuleBasic{
vesting.AppModuleBasic{},
gamm.AppModuleBasic{},
twapmodule.AppModuleBasic{},
protorev.AppModuleBasic{},
txfees.AppModuleBasic{},
incentives.AppModuleBasic{},
lockup.AppModuleBasic{},
Expand Down
5 changes: 5 additions & 0 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ import (
minttypes "github.com/osmosis-labs/osmosis/v13/x/mint/types"
poolincentives "github.com/osmosis-labs/osmosis/v13/x/pool-incentives"
poolincentivestypes "github.com/osmosis-labs/osmosis/v13/x/pool-incentives/types"
"github.com/osmosis-labs/osmosis/v13/x/protorev"
protorevtypes "github.com/osmosis-labs/osmosis/v13/x/protorev/types"
superfluid "github.com/osmosis-labs/osmosis/v13/x/superfluid"
superfluidtypes "github.com/osmosis-labs/osmosis/v13/x/superfluid/types"
"github.com/osmosis-labs/osmosis/v13/x/tokenfactory"
Expand Down Expand Up @@ -88,6 +90,7 @@ var moduleAccountPermissions = map[string][]string{
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
gammtypes.ModuleName: {authtypes.Minter, authtypes.Burner},
incentivestypes.ModuleName: {authtypes.Minter, authtypes.Burner},
protorevtypes.ModuleName: {authtypes.Minter, authtypes.Burner},
lockuptypes.ModuleName: {authtypes.Minter, authtypes.Burner},
poolincentivestypes.ModuleName: nil,
superfluidtypes.ModuleName: {authtypes.Minter, authtypes.Burner},
Expand Down Expand Up @@ -133,6 +136,7 @@ func appModules(
app.RawIcs20TransferAppModule,
gamm.NewAppModule(appCodec, *app.GAMMKeeper, app.AccountKeeper, app.BankKeeper),
twapmodule.NewAppModule(*app.TwapKeeper),
protorev.NewAppModule(appCodec, *app.ProtoRevKeeper, app.AccountKeeper, app.BankKeeper, app.EpochsKeeper, app.GAMMKeeper),
txfees.NewAppModule(*app.TxFeesKeeper),
incentives.NewAppModule(*app.IncentivesKeeper, app.AccountKeeper, app.BankKeeper, app.EpochsKeeper),
lockup.NewAppModule(*app.LockupKeeper, app.AccountKeeper, app.BankKeeper),
Expand Down Expand Up @@ -208,6 +212,7 @@ func OrderInitGenesis(allModuleNames []string) []string {
ibchost.ModuleName,
icatypes.ModuleName,
gammtypes.ModuleName,
protorevtypes.ModuleName,
twaptypes.ModuleName,
txfeestypes.ModuleName,
genutiltypes.ModuleName,
Expand Down
3 changes: 2 additions & 1 deletion app/upgrades/v14/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
store "github.com/cosmos/cosmos-sdk/store/types"

"github.com/osmosis-labs/osmosis/v13/app/upgrades"
protorevtypes "github.com/osmosis-labs/osmosis/v13/x/protorev/types"
valsetpreftypes "github.com/osmosis-labs/osmosis/v13/x/valset-pref/types"
)

Expand All @@ -14,7 +15,7 @@ var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler,
StoreUpgrades: store.StoreUpgrades{
Added: []string{valsetpreftypes.StoreKey},
Added: []string{valsetpreftypes.StoreKey, protorevtypes.StoreKey},
Deleted: []string{},
},
}
16 changes: 16 additions & 0 deletions proto/osmosis/protorev/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
syntax = "proto3";
package osmosis.protorev.v1beta1;

import "gogoproto/gogo.proto";
import "osmosis/protorev/v1beta1/protorev.proto";
import "osmosis/protorev/v1beta1/params.proto";

option go_package = "github.com/osmosis-labs/osmosis/v13/x/protorev/types";

// GenesisState defines the protorev module's genesis state.
message GenesisState {
// Module Parameters
Params params = 1 [ (gogoproto.nullable) = false ];
// Hot routes that are configured on genesis
repeated TokenPairArbRoutes token_pairs = 2 [ (gogoproto.nullable) = false ];
}
32 changes: 32 additions & 0 deletions proto/osmosis/protorev/v1beta1/gov.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
syntax = "proto3";
package osmosis.protorev.v1beta1;

import "gogoproto/gogo.proto";
import "osmosis/protorev/v1beta1/protorev.proto";

option go_package = "github.com/osmosis-labs/osmosis/v13/x/protorev/types";

// SetProtoRevEnabledProposal is a gov Content type to update whether the
// protorev module is enabled
message SetProtoRevEnabledProposal {
option (gogoproto.equal) = true;
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;

string title = 1;
string description = 2;
bool enabled = 3;
}

// SetProtoRevAdminAccountProposal is a gov Content type to set the admin
// account that will receive permissions to alter hot routes and set the
// developer address that will be receiving a share of profits from the module
message SetProtoRevAdminAccountProposal {
option (gogoproto.equal) = true;
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;

string title = 1;
string description = 2;
string account = 3;
}
12 changes: 12 additions & 0 deletions proto/osmosis/protorev/v1beta1/params.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
syntax = "proto3";
package osmosis.protorev.v1beta1;

import "gogoproto/gogo.proto";

option go_package = "github.com/osmosis-labs/osmosis/v13/x/protorev/types";

// Params defines the parameters for the module.
message Params {
// Boolean whether the module is going to be enabled
bool enabled = 1;
}
57 changes: 57 additions & 0 deletions proto/osmosis/protorev/v1beta1/protorev.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
syntax = "proto3";
package osmosis.protorev.v1beta1;

import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";

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

option go_package = "github.com/osmosis-labs/osmosis/v13/x/protorev/types";

// TokenPairArbRoutes tracks all of the hot routes for a given pair of tokens
message TokenPairArbRoutes {
option (gogoproto.equal) = true;

// Stores all of the possible hot paths for a given pair of tokens
repeated Route arb_routes = 1;
// Token denomination of the first asset
string token_in = 2;
// Token denomination of the second asset
string token_out = 3;
}

// Route is a hot route for a given pair of tokens
message Route {
option (gogoproto.equal) = true;

// The pool IDs that are travered in the directed cyclic graph (traversed left
// -> right)
repeated Trade trades = 1;
}

// Trade is a single trade in a route
message Trade {
option (gogoproto.equal) = true;

// The pool IDs that are travered in the directed cyclic graph (traversed left
// -> right)
uint64 pool = 1;
// The denom of token A that is traded
string token_in = 2;
// The denom of token B that is traded
string token_out = 3;
}

// PoolStatistics contains the number of trades the module has executed after a
// swap on a given pool and the profits from the trades
message PoolStatistics {
// profits is the total profit from all trades on this pool
repeated cosmos.base.v1beta1.Coin profits = 1;
// number_of_trades is the number of trades the module has executed
string number_of_trades = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
// pool_id is the id of the pool
uint64 pool_id = 3;
}
149 changes: 149 additions & 0 deletions proto/osmosis/protorev/v1beta1/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
syntax = "proto3";
package osmosis.protorev.v1beta1;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "osmosis/protorev/v1beta1/params.proto";
import "osmosis/protorev/v1beta1/protorev.proto";

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

option go_package = "github.com/osmosis-labs/osmosis/v13/x/protorev/types";

// Query defines the gRPC querier service.
service Query {
// Params queries the parameters of the module.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/osmosis/v13/protorev/params";
}

// GetProtoRevNumberOfTrades queries the number of arbitrage trades the module
// has executed
rpc GetProtoRevNumberOfTrades(QueryGetProtoRevNumberOfTradesRequest)
returns (QueryGetProtoRevNumberOfTradesResponse) {
option (google.api.http).get = "/osmosis/v13/protorev/number_of_trades";
}

// GetProtoRevProfitsByDenom queries the profits of the module by denom
rpc GetProtoRevProfitsByDenom(QueryGetProtoRevProfitsByDenomRequest)
returns (QueryGetProtoRevProfitsByDenomResponse) {
option (google.api.http).get = "/osmosis/v13/protorev/profits_by_denom";
}

// GetProtoRevAllProfits queries all of the profits from the module
rpc GetProtoRevAllProfits(QueryGetProtoRevAllProfitsRequest)
returns (QueryGetProtoRevAllProfitsResponse) {
option (google.api.http).get = "/osmosis/v13/protorev/all_profits";
}

// GetProtoRevStatisticsByPool queries the number of arbitrages and profits
// that have been executed for a given pool
rpc GetProtoRevStatisticsByPool(QueryGetProtoRevStatisticsByPoolRequest)
returns (QueryGetProtoRevStatisticsByPoolResponse) {
option (google.api.http).get = "/osmosis/v13/protorev/statistics_by_pool";
}

// GetProtoRevAllStatistics queries all of pools that the module has arbitrage
// against and the number of trades and profits that have been executed for
// each pool
rpc GetProtoRevAllStatistics(QueryGetProtoRevAllStatisticsRequest)
returns (QueryGetProtoRevAllStatisticsResponse) {
option (google.api.http).get = "/osmosis/v13/protorev/all_statistics";
}

// GetProtoRevTokenPairArbRoutes queries all of the hot routes that the module
// is currently arbitraging
rpc GetProtoRevTokenPairArbRoutes(QueryGetProtoRevTokenPairArbRoutesRequest)
returns (QueryGetProtoRevTokenPairArbRoutesResponse) {
option (google.api.http).get =
"/osmosis/v13/protorev/token_pair_arb_routes";
}
}

// QueryParamsRequest is request type for the Query/Params RPC method.
message QueryParamsRequest {}

// QueryParamsResponse is response type for the Query/Params RPC method.
message QueryParamsResponse {
// params holds all the parameters of this module.
Params params = 1 [ (gogoproto.nullable) = false ];
}

// QueryGetProtoRevNumberOfTradesRequest is request type for the
// Query/GetProtoRevNumberOfTrades RPC method.
message QueryGetProtoRevNumberOfTradesRequest {}

// QueryGetProtoRevNumberOfTradesResponse is response type for the
// Query/GetProtoRevNumberOfTrades RPC method.
message QueryGetProtoRevNumberOfTradesResponse {
// number_of_trades is the number of trades the module has executed
string number_of_trades = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
}

// QueryGetProtoRevProfitsByDenomRequest is request type for the
// Query/GetProtoRevProfitsByDenom RPC method.
message QueryGetProtoRevProfitsByDenomRequest {
// denom is the denom to query profits by
string denom = 1;
}

// QueryGetProtoRevProfitsByDenomResponse is response type for the
// Query/GetProtoRevProfitsByDenom RPC method.
message QueryGetProtoRevProfitsByDenomResponse {
// profit is the profits of the module by the selected denom
cosmos.base.v1beta1.Coin profit = 1;
}

// QueryGetProtoRevAllProfitsRequest is request type for the
// Query/GetProtoRevAllProfits RPC method.
message QueryGetProtoRevAllProfitsRequest {}

// QueryGetProtoRevAllProfitsResponse is response type for the
// Query/GetProtoRevAllProfits RPC method.
message QueryGetProtoRevAllProfitsResponse {
// profits is a list of all of the profits from the module
repeated cosmos.base.v1beta1.Coin profits = 1;
}

// QueryGetProtoRevStatisticsByPoolRequest is request type for the
// Query/GetProtoRevStatisticsByPool RPC method.
message QueryGetProtoRevStatisticsByPoolRequest {
// pool_id is the pool id to query statistics by
uint64 pool_id = 1;
}

// QueryGetProtoRevStatisticsByPoolResponse is response type for the
// Query/GetProtoRevStatisticsByPool RPC method.
message QueryGetProtoRevStatisticsByPoolResponse {
// statistics contains the number of trades the module has executed after a
// swap on a given pool and the profits from the trades
PoolStatistics statistics = 1;
}

// QueryGetProtoRevAllStatisticsRequest is request type for the
// Query/GetProtoRevAllStatistics RPC method.
message QueryGetProtoRevAllStatisticsRequest {}

// QueryGetProtoRevAllStatisticsResponse is response type for the
// Query/GetProtoRevAllStatistics RPC method.
message QueryGetProtoRevAllStatisticsResponse {
// statistics contains the number of trades the module has executed after a
// swap on a given pool and the profits from the trades for all pools
repeated PoolStatistics statistics = 1 [ (gogoproto.nullable) = false ];
}

// QueryGetProtoRevTokenPairArbRoutesRequest is request type for the
// Query/GetProtoRevTokenPairArbRoutes RPC method.
message QueryGetProtoRevTokenPairArbRoutesRequest {}

// QueryGetProtoRevTokenPairArbRoutesResponse is response type for the
// Query/GetProtoRevTokenPairArbRoutes RPC method.
message QueryGetProtoRevTokenPairArbRoutesResponse {
// routes is a list of all of the hot routes that the module is currently
// arbitraging
repeated TokenPairArbRoutes routes = 1;
}
Loading