keeper

package
v0.0.0-...-3786997 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 10, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMsgServer

func NewMsgServer(keeper Keeper) types.MsgServer

NewMsgServer returns an implementation of the MsgServer interface for the provided Keeper.

Types

type EpochHooks

type EpochHooks struct {
	// contains filtered or unexported fields
}

func (EpochHooks) AfterEpochEnd

func (h EpochHooks) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumber int64) error

AfterEpochEnd is the epoch end hook.

func (EpochHooks) BeforeEpochStart

func (h EpochHooks) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochNumber int64) error

BeforeEpochStart is the epoch start hook.

type Keeper

type Keeper struct {
	// contains filtered or unexported fields
}

func NewKeeper

func NewKeeper(
	cdc codec.BinaryCodec,
	storeKey sdk.StoreKey,
	ps paramtypes.Subspace,
	accountKeeper types.AccountKeeper,
	bankKeeper types.BankKeeper,
	gammKeeper types.GAMMKeeper,
	epochKeeper types.EpochKeeper,
	poolmanagerKeeper types.PoolManagerKeeper,
) Keeper

func (Keeper) AnteHandleCheck

func (k Keeper) AnteHandleCheck(ctx sdk.Context) error

AnteHandleCheck checks if the module is enabled and if the number of routes to be processed per block has been reached.

func (Keeper) BuildHighestLiquidityRoute

func (k Keeper) BuildHighestLiquidityRoute(ctx sdk.Context, swapDenom, tokenIn, tokenOut string, poolId uint64, remainingPoolPoints *uint64) (poolmanagertypes.SwapAmountInRoutes, error)

BuildHighestLiquidityRoute constructs a cyclic arbitrage route that is starts/ends with swapDenom (ex. mer) given the swap (tokenIn, tokenOut, poolId).

func (Keeper) BuildHighestLiquidityRoutes

func (k Keeper) BuildHighestLiquidityRoutes(ctx sdk.Context, tokenIn, tokenOut string, poolId uint64, remainingPoolPoints *uint64) ([]poolmanagertypes.SwapAmountInRoutes, error)

BuildHighestLiquidityRoutes builds cyclic arbitrage routes using the highest liquidity method. The base denoms are sorted by priority and routes are built in a greedy manner.

func (Keeper) BuildHotRoute

func (k Keeper) BuildHotRoute(ctx sdk.Context, route *types.Route, poolId uint64, remainingPoolPoints *uint64) (poolmanagertypes.SwapAmountInRoutes, error)

BuildHotRoute constructs a cyclic arbitrage route given a hot route and swap that should be placed in the hot route.

func (Keeper) BuildHotRoutes

func (k Keeper) BuildHotRoutes(ctx sdk.Context, tokenIn, tokenOut string, poolId uint64, remainingPoolPoints *uint64) ([]poolmanagertypes.SwapAmountInRoutes, error)

BuildHotRoutes builds all of the possible arbitrage routes using the hot routes method.

func (Keeper) BuildRoutes

func (k Keeper) BuildRoutes(ctx sdk.Context, tokenIn, tokenOut string, poolId uint64, remainingPoolPoints *uint64) []poolmanagertypes.SwapAmountInRoutes

BuildRoutes builds all of the possible arbitrage routes given the tokenIn, tokenOut and poolId that were used in the swap.

func (Keeper) CheckAndUpdateRouteState

func (k Keeper) CheckAndUpdateRouteState(ctx sdk.Context, route poolmanagertypes.SwapAmountInRoutes, remainingPoolPoints *uint64) error

CheckAndUpdateRouteState checks if the cyclic arbitrage route that was created via the highest liquidity route or hot route method is valid. If the route is too expensive to iterate through, has a inactive or invalid pool, or unsupported pool type, an error is returned.

func (Keeper) ConvertProfits

func (k Keeper) ConvertProfits(ctx sdk.Context, inputCoin sdk.Coin, profit sdk.Int) (sdk.Int, error)

ConvertProfits converts the profit denom to umer to allow for a fair comparison of profits

func (Keeper) DeleteAllEntriesForKeyPrefix

func (k Keeper) DeleteAllEntriesForKeyPrefix(ctx sdk.Context, keyPrefix []byte)

DeleteAllEntriesForKeyPrefix deletes all the entries from the store for the given key prefix

func (Keeper) DeleteAllPoolsForBaseDenom

func (k Keeper) DeleteAllPoolsForBaseDenom(ctx sdk.Context, baseDenom string)

DeleteAllPoolsForBaseDenom deletes all the pools for the given base denom

func (Keeper) DeleteAllTokenPairArbRoutes

func (k Keeper) DeleteAllTokenPairArbRoutes(ctx sdk.Context)

DeleteAllTokenPairArbRoutes deletes all the token pair arb routes

func (Keeper) DeleteBaseDenoms

func (k Keeper) DeleteBaseDenoms(ctx sdk.Context)

DeleteBaseDenoms deletes all of the base denoms

func (Keeper) DeleteDeveloperFees

func (k Keeper) DeleteDeveloperFees(ctx sdk.Context, denom string)

DeleteDeveloperFees deletes the developer fees given a denom

func (Keeper) EpochHooks

func (k Keeper) EpochHooks() epochstypes.EpochHooks

func (Keeper) EstimateMultihopProfit

func (k Keeper) EstimateMultihopProfit(ctx sdk.Context, inputDenom string, amount sdk.Int, route poolmanagertypes.SwapAmountInRoutes) (sdk.Coin, sdk.Int, error)

EstimateMultihopProfit estimates the profit for a given route by estimating the amount out given the amount in for the first pool in the route and then subtracting the amount in from the amount out to get the profit

func (Keeper) ExecuteTrade

func (k Keeper) ExecuteTrade(ctx sdk.Context, route poolmanagertypes.SwapAmountInRoutes, inputCoin sdk.Coin) error

ExecuteTrade inputs a route, amount in, and rebalances the pool

func (Keeper) FindMaxProfitForRoute

func (k Keeper) FindMaxProfitForRoute(ctx sdk.Context, route poolmanagertypes.SwapAmountInRoutes, inputDenom string) (sdk.Coin, sdk.Int, error)

FindMaxProfitRoute runs a binary search to find the max profit for a given route

func (Keeper) GetAdminAccount

func (k Keeper) GetAdminAccount(ctx sdk.Context) (sdk.AccAddress, error)

GetAdminAccount returns the admin account for protorev

func (Keeper) GetAllBaseDenoms

func (k Keeper) GetAllBaseDenoms(ctx sdk.Context) ([]*types.BaseDenom, error)

GetAllBaseDenoms returns all of the base denoms (sorted by priority in descending order) used to build cyclic arbitrage routes

func (Keeper) GetAllDeveloperFees

func (k Keeper) GetAllDeveloperFees(ctx sdk.Context) ([]sdk.Coin, error)

GetAllDeveloperFees returns all the developer fees the developer account can withdraw

func (Keeper) GetAllProfits

func (k Keeper) GetAllProfits(ctx sdk.Context) []*sdk.Coin

GetAllProfits returns all of the profits made by the ProtoRev module.

func (Keeper) GetAllProfitsByRoute

func (k Keeper) GetAllProfitsByRoute(ctx sdk.Context, route []uint64) []*sdk.Coin

GetAllProfitsByRoute returns all of the profits made by the ProtoRev module for the given route

func (Keeper) GetAllRoutes

func (k Keeper) GetAllRoutes(ctx sdk.Context) ([][]uint64, error)

GetAllRoutes returns all of the routes that the ProtoRev module has traded on

func (Keeper) GetAllTokenPairArbRoutes

func (k Keeper) GetAllTokenPairArbRoutes(ctx sdk.Context) ([]*types.TokenPairArbRoutes, error)

GetAllTokenPairArbRoutes returns all the token pair arb routes

func (Keeper) GetDaysSinceModuleGenesis

func (k Keeper) GetDaysSinceModuleGenesis(ctx sdk.Context) (uint64, error)

GetDaysSinceModuleGenesis returns the number of days since the module was initialized

func (Keeper) GetDeveloperAccount

func (k Keeper) GetDeveloperAccount(ctx sdk.Context) (sdk.AccAddress, error)

GetDeveloperAccount returns the developer account for protorev

func (Keeper) GetDeveloperFees

func (k Keeper) GetDeveloperFees(ctx sdk.Context, denom string) (sdk.Coin, error)

GetDeveloperFees returns the fees the developers can withdraw from the module account

func (Keeper) GetHighestLiquidityPools

func (k Keeper) GetHighestLiquidityPools(ctx sdk.Context, baseDenomPools map[string]map[string]LiquidityPoolStruct) error

GetHighestLiquidityPools returns the highest liquidity pools for all base denoms

func (Keeper) GetLatestBlockHeight

func (k Keeper) GetLatestBlockHeight(ctx sdk.Context) (uint64, error)

GetLatestBlockHeight returns the latest block height that protorev was run on

func (Keeper) GetMaxPointsPerBlock

func (k Keeper) GetMaxPointsPerBlock(ctx sdk.Context) (uint64, error)

GetMaxPointsPerBlock returns the max number of pool points that can be consumed per block. A pool point is roughly equivalent to 1 ms of simulation & execution time.

func (Keeper) GetMaxPointsPerTx

func (k Keeper) GetMaxPointsPerTx(ctx sdk.Context) (uint64, error)

GetMaxPointsPerTx returns the max number of pool points that can be consumed per transaction. A pool point is roughly equivalent to 1 ms of simulation & execution time.

func (Keeper) GetNumberOfTrades

func (k Keeper) GetNumberOfTrades(ctx sdk.Context) (sdk.Int, error)

GetNumberOfTrades returns the number of trades executed by the ProtoRev module

func (Keeper) GetParams

func (k Keeper) GetParams(ctx sdk.Context) (params types.Params)

GetParams get all parameters as types.Params

func (Keeper) GetPointCountForBlock

func (k Keeper) GetPointCountForBlock(ctx sdk.Context) (uint64, error)

GetPointCountForBlock returns the number of pool points that have been consumed in the current block

func (Keeper) GetPoolForDenomPair

func (k Keeper) GetPoolForDenomPair(ctx sdk.Context, baseDenom, denomToMatch string) (uint64, error)

GetPoolForDenomPair returns the id of the highest liquidty pool between the base denom and the denom to match

func (Keeper) GetPoolWeights

func (k Keeper) GetPoolWeights(ctx sdk.Context) *types.PoolWeights

GetPoolWeights retrieves the weights of different pool types. The weight of a pool type roughly corresponds to the amount of time it will take to simulate and execute a swap on that pool type (in ms).

func (Keeper) GetProfitsByDenom

func (k Keeper) GetProfitsByDenom(ctx sdk.Context, denom string) (sdk.Coin, error)

GetProfitsByDenom returns the profits made by the ProtoRev module for the given denom

func (Keeper) GetProfitsByRoute

func (k Keeper) GetProfitsByRoute(ctx sdk.Context, route []uint64, denom string) (sdk.Coin, error)

GetProfitsByRoute returns the profits made by the ProtoRev module for the given route and denom

func (Keeper) GetProtoRevEnabled

func (k Keeper) GetProtoRevEnabled(ctx sdk.Context) (bool, error)

GetProtoRevEnabled returns whether protorev is enabled

func (Keeper) GetTokenPairArbRoutes

func (k Keeper) GetTokenPairArbRoutes(ctx sdk.Context, tokenA, tokenB string) (*types.TokenPairArbRoutes, error)

GetTokenPairArbRoutes returns the token pair arb routes given two denoms

func (Keeper) GetTradesByRoute

func (k Keeper) GetTradesByRoute(ctx sdk.Context, route []uint64) (sdk.Int, error)

GetTradesByRoute returns the number of trades executed by the ProtoRev module for the given route

func (Keeper) IncrementNumberOfTrades

func (k Keeper) IncrementNumberOfTrades(ctx sdk.Context) error

IncrementNumberOfTrades increments the number of trades executed by the ProtoRev module

func (Keeper) IncrementPointCountForBlock

func (k Keeper) IncrementPointCountForBlock(ctx sdk.Context, amount uint64) error

IncrementPointCountForBlock increments the number of pool points that have been consumed in the current block

func (Keeper) IncrementTradesByRoute

func (k Keeper) IncrementTradesByRoute(ctx sdk.Context, route []uint64) error

IncrementTradesByRoute increments the number of trades executed by the ProtoRev module for the given route

func (Keeper) IsValidPool

func (k Keeper) IsValidPool(ctx sdk.Context, poolId uint64) error

IsValidPool checks if the pool is active and exists

func (Keeper) IterateRoutes

IterateRoutes checks the profitability of every single route that is passed in and returns the optimal route if there is one

func (Keeper) Logger

func (k Keeper) Logger(ctx sdk.Context) log.Logger

func (Keeper) ProtoRevTrade

func (k Keeper) ProtoRevTrade(ctx sdk.Context, swappedPools []SwapToBackrun) error

ProtoRevTrade wraps around the build routes, iterate routes, and execute trade functionality to execute cyclic arbitrage trades if they exist. It returns an error if there was an issue executing any single trade.

func (Keeper) RemainingPoolPointsForTx

func (k Keeper) RemainingPoolPointsForTx(ctx sdk.Context) (*uint64, error)

RemainingPoolPointsForTx calculates the number of pool points that can be consumed in the current transaction. Returns a pointer that will be used throughout the lifetime of a transaction.

func (Keeper) SendDeveloperFeesToDeveloperAccount

func (k Keeper) SendDeveloperFeesToDeveloperAccount(ctx sdk.Context) error

SendDeveloperFeesToDeveloperAccount sends the developer fees from the module account to the developer account

func (Keeper) SetAdminAccount

func (k Keeper) SetAdminAccount(ctx sdk.Context, adminAccount sdk.AccAddress)

SetAdminAccount sets the admin account for protorev

func (Keeper) SetBaseDenoms

func (k Keeper) SetBaseDenoms(ctx sdk.Context, baseDenoms []*types.BaseDenom) error

SetBaseDenoms sets all of the base denoms used to build cyclic arbitrage routes. The base denoms priority order is going to match the order of the base denoms in the slice.

func (Keeper) SetDaysSinceModuleGenesis

func (k Keeper) SetDaysSinceModuleGenesis(ctx sdk.Context, daysSinceGenesis uint64)

SetDaysSinceModuleGenesis updates the number of days since genesis

func (Keeper) SetDeveloperAccount

func (k Keeper) SetDeveloperAccount(ctx sdk.Context, developerAccount sdk.AccAddress)

SetDeveloperAccount sets the developer account for protorev that will receive a portion of arbitrage profits

func (Keeper) SetDeveloperFees

func (k Keeper) SetDeveloperFees(ctx sdk.Context, developerFees sdk.Coin) error

SetDeveloperFees sets the fees the developers can withdraw from the module account

func (Keeper) SetLatestBlockHeight

func (k Keeper) SetLatestBlockHeight(ctx sdk.Context, blockHeight uint64)

SetLatestBlockHeight sets the latest block height that protorev was run on

func (Keeper) SetMaxPointsPerBlock

func (k Keeper) SetMaxPointsPerBlock(ctx sdk.Context, maxPoints uint64) error

SetMaxPointsPerBlock sets the max number of pool points that can be consumed per block. A pool point is roughly equivalent to 1 ms of simulation & execution time.

func (Keeper) SetMaxPointsPerTx

func (k Keeper) SetMaxPointsPerTx(ctx sdk.Context, maxPoints uint64) error

SetMaxPointsPerTx sets the max number of pool points that can be consumed per transaction. A pool point is roughly equivalent to 1 ms of simulation & execution time.

func (Keeper) SetParams

func (k Keeper) SetParams(ctx sdk.Context, params types.Params)

SetParams set the params

func (Keeper) SetPointCountForBlock

func (k Keeper) SetPointCountForBlock(ctx sdk.Context, txCount uint64)

SetPointCountForBlock sets the number of pool points that have been consumed in the current block

func (Keeper) SetPoolForDenomPair

func (k Keeper) SetPoolForDenomPair(ctx sdk.Context, baseDenom, denomToMatch string, poolId uint64)

SetPoolForDenomPair sets the id of the highest liquidty pool between the base denom and the denom to match

func (Keeper) SetPoolWeights

func (k Keeper) SetPoolWeights(ctx sdk.Context, poolWeights types.PoolWeights)

SetPoolWeights sets the weights of different pool types.

func (Keeper) SetProtoRevEnabled

func (k Keeper) SetProtoRevEnabled(ctx sdk.Context, enabled bool)

SetProtoRevEnabled sets whether the protorev post handler is enabled

func (Keeper) SetTokenPairArbRoutes

func (k Keeper) SetTokenPairArbRoutes(ctx sdk.Context, tokenA, tokenB string, tokenPair *types.TokenPairArbRoutes) error

SetTokenPairArbRoutes sets the token pair arb routes given two denoms

func (Keeper) UpdateDeveloperFees

func (k Keeper) UpdateDeveloperFees(ctx sdk.Context, denom string, profit sdk.Int) error

UpdateDeveloperFees updates the fees that developers can withdraw from the module account

func (Keeper) UpdatePools

func (k Keeper) UpdatePools(ctx sdk.Context) error

UpdatePools first deletes all of the pools paired with any base denom in the store and then adds the highest liquidity pools that match to the store

func (Keeper) UpdateProfitsByDenom

func (k Keeper) UpdateProfitsByDenom(ctx sdk.Context, denom string, tradeProfit sdk.Int) error

UpdateProfitsByDenom updates the profits made by the ProtoRev module for the given denom

func (Keeper) UpdateProfitsByRoute

func (k Keeper) UpdateProfitsByRoute(ctx sdk.Context, route []uint64, denom string, profit sdk.Int) error

UpdateProfitsByRoute updates the profits made by the ProtoRev module for the given route and denom

func (Keeper) UpdateStatistics

func (k Keeper) UpdateStatistics(ctx sdk.Context, route poolmanagertypes.SwapAmountInRoutes, denom string, profit sdk.Int) error

UpdateStatistics updates the module statistics after each trade is executed

type LiquidityPoolStruct

type LiquidityPoolStruct struct {
	Liquidity sdk.Int
	PoolId    uint64
}

Struct used to track the pool with the highest liquidity

type MsgServer

type MsgServer struct {
	// contains filtered or unexported fields
}

func (MsgServer) AdminCheck

func (m MsgServer) AdminCheck(ctx sdk.Context, admin string) error

AdminCheck ensures that the admin account is set and that the sender is the admin account

func (MsgServer) SetBaseDenoms

SetBaseDenoms sets the base denoms that will be used to generate cyclic arbitrage routes

func (MsgServer) SetDeveloperAccount

SetDeveloperAccount sets the developer account that will receive fees

func (MsgServer) SetHotRoutes

SetHotRoutes sets the hot routes for ProtoRev

func (MsgServer) SetMaxPoolPointsPerBlock

SetMaxPoolPointsPerBlock sets the maximum number of pool points that can be consumed per block

func (MsgServer) SetMaxPoolPointsPerTx

SetMaxPoolPointsPerTx sets the maximum number of pool points that can be consumed per tx

func (MsgServer) SetPoolWeights

SetPoolWeights sets the weights corresponding to each pool type. This distinction is necessary because the pool types have different execution times. Each weight roughly corresponds to the amount of time (in ms) it takes to simulate and execute a trade.

type ProtoRevDecorator

type ProtoRevDecorator struct {
	ProtoRevKeeper Keeper
}

func NewProtoRevDecorator

func NewProtoRevDecorator(protoRevDecorator Keeper) ProtoRevDecorator

func (ProtoRevDecorator) AnteHandle

func (protoRevDec ProtoRevDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error)

This posthandler will first check if there were any swaps in the tx. If so, collect all of the pools, build routes for cyclic arbitrage, and then execute the optimal route if it exists.

type Querier

type Querier struct {
	Keeper
}

Querier defines a wrapper around the x/protorev keeper providing gRPC method handlers.

func NewQuerier

func NewQuerier(k Keeper) Querier

func (Querier) GetProtoRevAdminAccount

GetProtoRevAdminAccount queries the admin account that is allowed to execute admin functions

func (Querier) GetProtoRevAllProfits

GetProtoRevAllProfits queries all of the profits from the module

func (Querier) GetProtoRevAllRouteStatistics

GetProtoRevAllRouteStatistics queries all of routes that the module has arbitrage against and the number of trades executed on each route and the total profits for each route

func (Querier) GetProtoRevBaseDenoms

GetProtoRevBaseDenoms queries the base denoms that are being used for arbitrage

func (Querier) GetProtoRevDeveloperAccount

GetProtoRevDeveloperAccount queries the developer account that is accumulating the profits from the module

func (Querier) GetProtoRevEnabled

GetProtoRevEnabled queries whether the module is enabled or not

func (Querier) GetProtoRevMaxPoolPointsPerBlock

GetProtoRevPoolPointsPerBlock queries the maximum number of pool points that can be consumed per block

func (Querier) GetProtoRevMaxPoolPointsPerTx

GetProtoRevPoolPointsPerTx queries the maximum number of pool points that can be consumed per transaction

func (Querier) GetProtoRevNumberOfTrades

GetProtoRevNumberOfTrades queries the number of trades the module has executed

func (Querier) GetProtoRevPoolWeights

GetProtoRevPoolWeights queries the weights of each pool type that is being used for arbitrage

func (Querier) GetProtoRevProfitsByDenom

GetProtoRevProfitsByDenom queries the profits of the module by denom

func (Querier) GetProtoRevStatisticsByRoute

GetProtoRevStatisticsByRoute queries the number of arbitrages and profits that have been executed for a given route

func (Querier) GetProtoRevTokenPairArbRoutes

GetProtoRevTokenPairArbRoutes queries the hot routes that the module is utilizing for cyclic arbitrage route generation

func (Querier) Params

Params queries the parameters of the module.

type SwapToBackrun

type SwapToBackrun struct {
	PoolId        uint64
	TokenOutDenom string
	TokenInDenom  string
}

func ExtractSwappedPools

func ExtractSwappedPools(tx sdk.Tx) []SwapToBackrun

ExtractSwappedPools checks if there were any swaps made on pools and if so returns a list of all the pools that were swapped on and metadata about the swap

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL