keeper

package
v26.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EmitBackrunEvent

func EmitBackrunEvent(ctx sdk.Context, pool SwapToBackrun, inputCoin sdk.Coin, profit, tokenOutAmount osmomath.Int, remainingTxPoolPoints, remainingBlockPoolPoints uint64)

EmitBackrunEvent updates and emits a backrunEvent

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.

func (EpochHooks) CalculateAndDistributeProfits

func (h EpochHooks) CalculateAndDistributeProfits(ctx sdk.Context) error

CalculateAndDistributeProfits is executed after epoch. It gets the current base denom profits and distributes them.

func (EpochHooks) GetModuleName

func (EpochHooks) GetModuleName() string

GetModuleName implements types.EpochHooks.

type Hooks

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

func (Hooks) AfterCFMMPoolCreated

func (h Hooks) AfterCFMMPoolCreated(ctx sdk.Context, sender sdk.AccAddress, poolId uint64)

AfterCFMMPoolCreated hook checks and potentially stores the pool via the highest liquidity method.

func (Hooks) AfterCFMMSwap

func (h Hooks) AfterCFMMSwap(ctx sdk.Context, sender sdk.AccAddress, poolId uint64, input sdk.Coins, output sdk.Coins)

AfterCFMMSwap stores swaps to be checked by protorev given the coins swapped in the pool.

func (Hooks) AfterConcentratedPoolCreated

func (h Hooks) AfterConcentratedPoolCreated(ctx sdk.Context, sender sdk.AccAddress, poolId uint64)

AfterConcentratedPoolCreated is a noop.

func (Hooks) AfterConcentratedPoolSwap

func (h Hooks) AfterConcentratedPoolSwap(ctx sdk.Context, sender sdk.AccAddress, poolId uint64, input sdk.Coins, output sdk.Coins)

AfterConcentratedPoolSwap stores swaps to be checked by protorev given the coins swapped in the pool.

func (Hooks) AfterExitPool

func (h Hooks) AfterExitPool(ctx sdk.Context, sender sdk.AccAddress, poolId uint64, shareInAmount osmomath.Int, exitCoins sdk.Coins)

AfterExitPool stores swaps to be checked by protorev given the coins exited from the pool.

func (Hooks) AfterInitialPoolPositionCreated

func (h Hooks) AfterInitialPoolPositionCreated(ctx sdk.Context, sender sdk.AccAddress, poolId uint64)

AfterInitialPoolPositionCreated checks and potentially stores the pool via the highest liquidity method.

func (Hooks) AfterJoinPool

func (h Hooks) AfterJoinPool(ctx sdk.Context, sender sdk.AccAddress, poolId uint64, enterCoins sdk.Coins, shareOutAmount osmomath.Int)

AfterJoinPool stores swaps to be checked by protorev given the coins entered into the pool.

func (Hooks) AfterLastPoolPositionRemoved

func (h Hooks) AfterLastPoolPositionRemoved(ctx sdk.Context, sender sdk.AccAddress, poolId uint64)

AfterLastPoolPositionRemoved is a noop.

type Keeper

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

func NewKeeper

func NewKeeper(
	cdc codec.BinaryCodec,
	storeKey storetypes.StoreKey,
	transientKey *storetypes.TransientStoreKey,
	ps paramtypes.Subspace,
	accountKeeper types.AccountKeeper,
	bankKeeper types.BankKeeper,
	gammKeeper types.GAMMKeeper,
	epochKeeper types.EpochKeeper,
	poolmanagerKeeper types.PoolManagerKeeper,
	concentratedLiquidityKeeper types.ConcentratedLiquidityKeeper,
	distributionKeeper types.DistributionKeeper,
) Keeper

func (Keeper) AddSwapsToSwapsToBackrun

func (k Keeper) AddSwapsToSwapsToBackrun(ctx sdk.Context, swaps []types.Trade) error

AddSwapToSwapsToBackrun appends a swap to the swaps to backrun

func (Keeper) AfterPoolCreatedWithCoins

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

AfterPoolCreatedWithCoins checks if the new pool should be stored as the highest liquidity pool for any of the base denoms, and stores it if so.

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 types.BaseDenom, tokenIn, tokenOut string, poolId uint64) (RouteMetaData, error)

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

func (Keeper) BuildHighestLiquidityRoutes

func (k Keeper) BuildHighestLiquidityRoutes(ctx sdk.Context, tokenIn, tokenOut string, poolId uint64) ([]RouteMetaData, 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) (RouteMetaData, 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) ([]RouteMetaData, 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) []RouteMetaData

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

func (Keeper) BuildTwoPoolRoute

func (k Keeper) BuildTwoPoolRoute(
	ctx sdk.Context,
	baseDenom types.BaseDenom,
	tokenInDenom, tokenOutDenom string,
	poolId uint64,
) (RouteMetaData, error)

BuildTwoPoolRoute will attempt to create a two pool route that will rebalance pools that are paired with the base denom. This is useful for pools that contain the same assets but are imbalanced.

func (Keeper) CalculateRoutePoolPoints

func (k Keeper) CalculateRoutePoolPoints(ctx sdk.Context, route poolmanagertypes.SwapAmountInRoutes) (uint64, error)

CalculateRoutePoolPoints calculates the number of pool points that will be consumed by a route when simulating and executing trades. This is only added to the global pool point counter if the route simulated is minimally profitable i.e. it will make a profit.

func (Keeper) CalculateUpperBoundForSearch

func (k Keeper) CalculateUpperBoundForSearch(
	ctx sdk.Context,
	route RouteMetaData,
	inputDenom string,
) (osmomath.Int, error)

CalculateUpperBoundForSearch returns the max amount in that can be used for the binary search respecting the max ticks moved across all concentrated liquidity pools in the route.

func (Keeper) CompareAndStorePool

func (k Keeper) CompareAndStorePool(ctx sdk.Context, poolId uint64, baseDenom, otherDenom string)

CompareAndStorePool compares the liquidity of the new pool with the liquidity of the stored pool, and stores the new pool if it has more liquidity.

func (Keeper) ConvertProfits

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

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

NOTE: This does not check the underlying pool before swapping so this may go over the MaxTicksCrossed.

func (Keeper) CurrentBaseDenomProfits

func (k Keeper) CurrentBaseDenomProfits(ctx sdk.Context) (sdk.Coins, error)

CurrentBaseDenomProfits retrieves the current balance of the protorev module account and filters for base denoms.

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) DeleteDeveloperFees deprecated

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

Deprecated: Used in v16 upgrade, can be removed in v17 DeleteDeveloperFees deletes the developer fees given a denom

func (Keeper) DeleteSwapsToBackrun

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

DeleteSwapsToBackrun deletes the swaps to backrun

func (Keeper) DeprecatedDeleteBaseDenoms

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

DeprecatedDeleteBaseDenoms deletes all of the base denoms. After v24 upgrade, this method should be deleted. We now use the param store.

func (Keeper) DeprecatedGetAllBaseDenoms

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

DeprecatedGetAllBaseDenoms returns all of the base denoms (sorted by priority in descending order) used to build cyclic arbitrage routes After v24 upgrade, this method should be deleted. We now use the param store.

func (Keeper) DeprecatedSetBaseDenoms

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

DeprecatedSetBaseDenoms 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. After v24 upgrade, this method should be deleted. We now use the param store.

func (Keeper) DistributeProfit

func (k Keeper) DistributeProfit(ctx sdk.Context, arbProfits sdk.Coins) error

DistributeProfit sends the developer fee from the module account to the developer account and burns the remaining profit if denominated in osmo.

func (Keeper) EpochHooks

func (k Keeper) EpochHooks() epochstypes.EpochHooks

func (Keeper) EstimateMultihopProfit

func (k Keeper) EstimateMultihopProfit(ctx sdk.Context, inputDenom string, amount osmomath.Int, route poolmanagertypes.SwapAmountInRoutes) (sdk.Coin, osmomath.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, pool SwapToBackrun, remainingTxPoolPoints, remainingBlockPoolPoints uint64) error

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

func (Keeper) ExportGenesis

func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState

ExportGenesis returns the module's exported genesis. ExportGenesis intentionally ignores a few of the errors thrown by the keeper methods. This is because the keeper methods are only throwing errors if there is an issue unmarshalling or if the value had not been set yet (i.e. developer account address). In that case, we just use the default values defined in genesis.go in types.

func (Keeper) ExtendSearchRangeIfNeeded

func (k Keeper) ExtendSearchRangeIfNeeded(
	ctx sdk.Context,
	route RouteMetaData,
	inputDenom string,
	curLeft, curRight, updatedMax osmomath.Int,
) (osmomath.Int, osmomath.Int, error)

Determine if the binary search range needs to be extended

func (Keeper) ExtractSwappedPools

func (k Keeper) ExtractSwappedPools(ctx sdk.Context) []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

func (Keeper) FindMaxProfitForRoute

func (k Keeper) FindMaxProfitForRoute(ctx sdk.Context, route RouteMetaData, remainingTxPoolPoints, remainingBlockPoolPoints *uint64) (sdk.Coin, osmomath.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

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 deprecated

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

Deprecated: Used in v16 upgrade, can be removed in v17 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) GetAllProtocolRevenue

func (k Keeper) GetAllProtocolRevenue(ctx sdk.Context) types.AllProtocolRevenue

GetAllProtocolRevenue returns all types of protocol revenue (txfees, taker fees, and cyclic arb profits), as well as the block height from which we started accounting for each of these revenue sources.

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) GetComparablePoolLiquidity

func (k Keeper) GetComparablePoolLiquidity(ctx sdk.Context, poolId uint64) (comparableLiquidity osmomath.Int, err error)

GetComparablePoolLiquidity gets the comparable liquidity of a pool by multiplying the amounts of the pool coins.

func (Keeper) GetCyclicArbProfitTrackerStartHeight

func (k Keeper) GetCyclicArbProfitTrackerStartHeight(ctx sdk.Context) int64

GetCyclicArbProfitTrackerStartHeight gets the height from which we started accounting for cyclic arb profits.

func (Keeper) GetCyclicArbProfitTrackerValue

func (k Keeper) GetCyclicArbProfitTrackerValue(ctx sdk.Context) (currentCyclicArbProfits sdk.Coins)

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 deprecated

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

Deprecated: Can be removed in v16 GetDeveloperFees returns the fees the developers can withdraw from the module account

func (Keeper) GetInfoByPoolType

func (k Keeper) GetInfoByPoolType(ctx sdk.Context) types.InfoByPoolType

GetInfoByPoolType retrieves the metadata about the different pool types. This is used to determine the execution costs of different pool types when calculating the optimal route (in terms of time and gas consumption).

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) (osmomath.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 liquidity pool between the base denom and the denom to match

func (Keeper) GetPoolForDenomPairNoOrder

func (k Keeper) GetPoolForDenomPairNoOrder(ctx sdk.Context, tokenA, tokenB string) (uint64, error)

GetPoolForDenomPairNoOrder returns the id of the pool between the two denoms. It is order-independent. That is, tokenA can either be a base or a quote. Both cases are handled. If no pool exists, an error is returned. TODO: unit test

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

GetProtoRevEnabled returns whether protorev is enabled

func (Keeper) GetRemainingPoolPoints

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

RemainingPoolPointsForTx calculates the number of pool points that can be consumed in the transaction and block. When the remaining pool points for the block is less than the remaining pool points for the transaction, then both returned values will be the same, which will be the remaining pool points for the block.

func (Keeper) GetSwapsToBackrun

func (k Keeper) GetSwapsToBackrun(ctx sdk.Context) (types.Route, error)

GetSwapsToBackrun returns the swaps to backrun, updated via hooks

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) (osmomath.Int, error)

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

func (Keeper) Hooks

func (k Keeper) Hooks() Hooks

Create new ProtoRev hooks.

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) InitGenesis

func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState)

InitGenesis initializes the module's state from a provided genesis state.

func (Keeper) IsValidPool

func (k Keeper) IsValidPool(ctx sdk.Context, pool poolmanagertypes.PoolI) error

IsValidPool checks if the pool is active and exists

func (Keeper) IterateRoutes

func (k Keeper) IterateRoutes(ctx sdk.Context, routes []RouteMetaData, remainingTxPoolPoints, remainingBlockPoolPoints *uint64) (sdk.Coin, osmomath.Int, poolmanagertypes.SwapAmountInRoutes)

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) (err 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) 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) SetCyclicArbProfitTrackerStartHeight

func (k Keeper) SetCyclicArbProfitTrackerStartHeight(ctx sdk.Context, startHeight int64)

SetCyclicArbProfitTrackerStartHeight sets the height from which we started accounting for cyclic arb profits.

func (Keeper) SetCyclicArbProfitTrackerValue

func (k Keeper) SetCyclicArbProfitTrackerValue(ctx sdk.Context, cyclicArbProfits sdk.Coins)

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 deprecated

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

Deprecated: Can be removed in v16 SetDeveloperFees sets the fees the developers can withdraw from the module account

func (Keeper) SetInfoByPoolType

func (k Keeper) SetInfoByPoolType(ctx sdk.Context, poolWeights types.InfoByPoolType)

SetInfoByPoolType sets the pool type information.

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) SetParam

func (k Keeper) SetParam(ctx sdk.Context, key []byte, value interface{})

SetParam sets a specific protorev module's parameter with the provided parameter.

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, pointCount 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) SetProtoRevEnabled

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

SetProtoRevEnabled sets whether the protorev post handler is enabled

func (Keeper) SetSwapsToBackrun

func (k Keeper) SetSwapsToBackrun(ctx sdk.Context, swapsToBackrun types.Route) error

SetSwapsToBackrun sets the swaps to backrun, updated via hooks

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) StoreJoinExitPoolSwaps

func (k Keeper) StoreJoinExitPoolSwaps(ctx sdk.Context, sender sdk.AccAddress, poolId uint64, denom string, isJoin bool)

StoreJoinExitPoolSwaps stores the swaps associated with GAMM join/exit pool messages in the store, depending on if it is a join or exit.

func (Keeper) StoreSwap

func (k Keeper) StoreSwap(ctx sdk.Context, poolId uint64, tokenIn, tokenOut string)

StoreSwap stores a swap to be checked by protorev when attempting backruns.

func (Keeper) UpdateHighestLiquidityPools

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

UpdateHighestLiquidityPools updates the baseDenomPools map (passed in by reference) with the highest liquidity pools for each base denom by iterating through all pools, getting the total liquidity for each pool, and updating the highest liquidity pools based upon comparing total liquidity.

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 osmomath.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 osmomath.Int) error

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

func (Keeper) UpdateSearchRangeIfNeeded

func (k Keeper) UpdateSearchRangeIfNeeded(
	ctx sdk.Context,
	route RouteMetaData,
	inputDenom string,
	curLeft, curRight osmomath.Int,
) (osmomath.Int, osmomath.Int, error)

UpdateSearchRangeIfNeeded updates the search range for the binary search. First, we check if there are any concentrated liquidity pools in the route. If there are, then we may need to reduce the upper bound of the binary search since it is gas intensive to move across several ticks. Next, we determine if the current bound includes the optimal amount in. If it does not, then we can extend the search range to capture more profits.

func (Keeper) UpdateStatistics

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

UpdateStatistics updates the module statistics after each trade is executed

type LiquidityPoolStruct

type LiquidityPoolStruct struct {
	Liquidity osmomath.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 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) SetInfoByPoolType

SetInfoByPoolType sets the execution time/gas consumption parameters corresponding to each pool type. This distinction is necessary because the pool types have different execution times / gas consumption.

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

type ProtoRevDecorator

type ProtoRevDecorator struct {
	ProtoRevKeeper Keeper
}

func NewProtoRevDecorator

func NewProtoRevDecorator(protoRevDecorator Keeper) ProtoRevDecorator

func (ProtoRevDecorator) PostHandle

func (protoRevDec ProtoRevDecorator) PostHandle(ctx sdk.Context, tx sdk.Tx, simulate, success bool, next sdk.PostHandler) (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) GetAllProtocolRevenue

GetAllProtocolRevenue queries all types of protocol revenue (txfees, taker fees, and cyclic arbitrage profits)

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) GetProtoRevInfoByPoolType

GetProtoRevInfoByPoolType queries information pertaining to each pool type the module is using for arbitrage

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) GetProtoRevPool

GetProtoRevPool queries the pool id for a given base denom and other denom

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 RouteMetaData

type RouteMetaData struct {
	// The route that was built
	Route poolmanagertypes.SwapAmountInRoutes
	// The number of pool points that were consumed to build the route
	PoolPoints uint64
	// The step size that should be used in the binary search for the optimal swap amount
	StepSize osmomath.Int
}

type SwapToBackrun

type SwapToBackrun struct {
	PoolId        uint64
	TokenOutDenom string
	TokenInDenom  string
}

Jump to

Keyboard shortcuts

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