feat(autopilot): auto-cancel orders that transfer balance away #3987
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
One of the common nuisance cases that frequently occurs with orders is that a user (or some other protocol, whatever) transfers the balance of the token they intend to swap away after placing the order.
Rather than keeping these orders on the books, this PR introduces a new maintenance task on the autopilot which tracks all
Transferevents on the blockchain, and if one matches an open order'sownerandsell_token(aka, transfer of a token from an account which has an open order), we cancel the order proactively.This change comes with some BREAKING changes that we should consider if we want or not that may affect some users (to me it makes a lot of sense, but who knows. thats what this PR is for):
sell_tokenwill not be transferred from the users wallet, but some processes (ex. euler) may not actually have the sell_token in the user's wallet. For these unusual cases, it should be harmless, but perhaps there is an edge case I am not thinking of.This is not intended to be a replacement for the existing; only a measure to improve performance and reduce nuisance order propogation in aave or regular orders.
additionally issues that remain unverified that we would want to check on a shadow database or something if the performance of the DB query good enough? it uses the
live_ordersquery from the shraed lib which we execute once per auction, and then it has the database filter using a table of potentially hundreds of pairs uploaded on the spot. I think its OK, but good to double check.other notes:
run_foreverloop instead.Changes
transfer_listenerfor cleaningtransfer_listenerHow to test
I made a script for the playground that confirms this works as expected, but I did not commit it in these changes. LMK if I should add.