feat(autopilot): auto-cancel orders that transfer balance away#3987
feat(autopilot): auto-cancel orders that transfer balance away#3987
Conversation
…hat transfer balance from their account before a swap
|
I don't think this is an avenue we should go down. It has been discussed in the past that the protocol should do LESS filtering of orders, not more. That being said here are some comments on the implementation: IMO this idea might be useful as a means to reduce the number of balances the driver has to update. Let's say the balancer fetching logic puts only EIP 712 orders on a timer. If the timer runs out OR if it detects such an ERC20 transfer event it will invalidate the cached balance value and refetch it. |
|
If this only takes into account actual transfers, it would miss any orders where the balance changes due to a swap. But if it's also detecting when swaps are made (on CoW or dexes) and canceling orders based on that, there's a lot of trading strategies that would break. The most obviously thing it would break (if taking swaps into account) is basically all partially fillable orders that get a partial fill... |
|
This pull request has been marked as stale because it has been inactive a while. Please update this pull request or it will be automatically closed. |
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.