-
Notifications
You must be signed in to change notification settings - Fork 602
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: Post Handler + Proposal Handlers + Profit Sharing #3806
Conversation
e330d0f
to
458d350
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for the late review, got caught up with some other work.
left few comments! still reviewing files past posthandler 🌮
8bb4a5a
to
6d0df06
Compare
d68f658
to
5836130
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few minor comments around naming and cleaning up the readme in light of the new keeper data.
caf39f6
to
47c767b
Compare
a129c52
to
1aa0999
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left few comments, still catching up with changes that were made. But its looking solid :))
x/protorev/types/genesis.go
Outdated
const MaxIterations = 14 | ||
const MaxIterations int = 14 | ||
|
||
// Max number of routes that can be arbitraged per tx (default of 6) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm trying to understand this, does this mean 6 routes each containing 3 pool routes? So it'd look something like [[route1][route2][route3]], [[route1a][route2a][route3a]], [[route1b][route2b][route3b]] ... 6times in genesis
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes exactly. But this is also dependent on the route that is taken. Routes that include a stable swap pool inheritely are more expensive to backrun. Because of this we count routes that include a stable swap pool with more weight. Currently the distribution is 2:5 for balancer : stable weights. The basic idea here is that MaxIterableRoutesPerTx
and MaxIterableRoutesPerBlock
closely follow the actual ms that we expect the module to take and route weights are the approximate amount of time it takes to actually traverse the route (in ms).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
testing updates nit
Remove checkTx skip linting update after posthandler addition
5d034e9
to
f5050d2
Compare
What is the purpose of the change
This PR implements the post handler, the proposal handlers that are responsible for setting the admin account, admin functionality, stateful changes depending on proposals, and developer profit sharing. This is PR 5/6 (#3594).
Brief Changelog
x/protorev
Testing and Verifying
This change added tests and can be verified as follows:
Documentation and Release Note
The
postHandler
extracts pools that were swapped in a transaction and determines if there is a cyclic arbitrage opportunity. If so, the handler will find an optimal route and execute it - rebalancing the pool and returning arbitrage profits to the module account. Additionally, the gas meter gets reset at the end of the post handler in order to refund users for computation done in the handler.ExtractSwappedPools
) as well as the direction of the trade.BuildRoutes
)IterateRoutes
)FindMaxProfitForRoute
)ExecuteTrade
) and rebalance the pools on-behalf of the chain through thegammkeeper
(MultiHopSwapExactAmountIn
)Keeper Updates
ProtoRevEnabled
x/protorev
can be enabled or disabled through governance. As a proposal is a stateful change, we store whether the module is currently enabled or disabled in the module.AdminAccount
The admin account is set through governance and has permissions to set hot routes and the developer account. On genesis, the admin account is nil.
DeveloperAccount
The developer account is set through a
NewMsgSetDeveloperAccount
tx. This is the account that will be able to withdraw a portion of the profits fromx/protorev
as specified by the Osmosis ↔ Skip proposal. Only the admin account has permission to make this message.DaysSinceGenesis
x/protorev
will distribute 20% of profits to skip in the year 1, 10% of profits in year 2, and 5% thereafter. To track how much profit can be distributed to the developer account at any given moment, we store the amount of days since genesis.DeveloperFees
DeveloperFees tracks the total amount of profit that can be withdrawn by the developer account. These fees are sent to the developer account, if set, every week through the
epoch
hook. If unset, the funds are held in the module account.MaxRoutesPerTx
MaxRoutesPerTx tracks the maximum number of routes that can be traversed in a given transaction. This is configurable (but bounded) by the admin account. We limit the number of routes per transaction so that all
x/protorev
execution is not limited to the top of the block.MaxRoutesPerBlock
MaxRoutesPerBlock tracks the maximum number of routes that can be traversed in a given block. This is configurable (but bounded) by the admin account. We limit the number of routes per block so that the execution time of the
x/protorev
posthandler is reasonably bounded to ensure that block time remains as is.RouteCountForBlock
RouteCountForBlock tracks the number of routes that have been traversed in the current block. Used to ensure that the module is not slowing down block speed.
LatestBlockHeight
LatestBlockHeight tracks the latest recorded block height. Used to track the number of routes that have been traversed in the current block.
RouteWeights
RouteWeights contains the weights of all of the different route types. Routes are broken up into different types based on the pool that is sandwiched in between the arbitrage route. This distinction is made and necessary because the execution time ranges fairly between the different route types.
Proposal Handlers
x/protorev
implements two different governance proposals.SetProtoRevAdminAccountProposal
As the landscape of pools on Osmosis evolves, an admin account will be able to add and remove routes for
x/protorev
to check for cyclic arbitrage opportunities. Largely, the purpose of maintaining hot routes is to reduce the amount of computation that would otherwise be required to determine optimal paths at runtime. In addition, introducing a means of altering hot can allow external researchers to conduct meaningful analysis into the markets on-chain.SetProtoRevEnabledProposal
This proposal type allows the chain to turn the module on or off. This is meant to be used as a fail safe in the case stakers and the chain decide to turn the module off. This might be used to halt the execution of trades in the case that the
x/gamm
module has significant upgrades that might produce unexpected behavior from the module.Profit Sharing
Profits accumulated by the module will be partially distributed to the developers that built the module in accordance with the governance proposal that was passed: year 1 is 20% of profits, year 2 is 10%, and subsequent years is 5%.
In order to track how much profit the developers can withdraw at any given moment, the module tracks the number of days since genesis. This gets incremented in the epoch hook after every day. When a trade gets executed by the module, the module will determine how much of the profit from the trade the developers can receive by using
daysSinceGenesis
in a simple calculation.If the developer account is not set (which it is not on genesis), all funds are held in the module account. Once the admin account is set through a successful governance proposal, the developer address can be set and will start to automatically receive a share of profits every week through the epoch hook. The distribution of funds from the module account is done through
SendDeveloperFeesToDeveloperAccount
. Once the funds are distributed, the amount of profit developers can withdraw gets reset to 0 and profits will start to be accumulated and distributed on a week to week basis.