Skip to content

WIP: Liquidator bot - currently active positions#28

Draft
JossDuff wants to merge 25 commits intomasterfrom
liquidator
Draft

WIP: Liquidator bot - currently active positions#28
JossDuff wants to merge 25 commits intomasterfrom
liquidator

Conversation

@JossDuff
Copy link

@JossDuff JossDuff commented Jun 26, 2023

WIP. below description is from old version, I'm just keeping it for reference

Builds a list of currently active positions to later be watched for potential liquidations. Logs are just so I can monitor while running and are temporary.

An active position is defined as a MarketEntered(CToken cToken, address account) event that doesn't have a corresponding MarketExited(CToken cToken, address account) event with the same parameters. When we find a MarketExited event, we search the list of currently active positions for the corresponding MarketEntered and remove it.

On start, chainReader launches 2 processes concurrently:

  • getHistoricPositions() queries for all previous MarketEntered/Exited events and trims out MarketEntered events that match a MarketExited. Returns when it reaches the block chainReader started on.
  • listenForUpdates() starts event listeners for MarketEntered/Exited events. Doesn't return, continuously updates and trims our list of active positions.

When getHistoricPositions() returns, combine its found list of active positions with the list of active positions maintained by listenForUpdates() resulting in an updated list of all active positions to monitor. This approach makes sure we don't miss any new events while we are querying historic positions. We then save the list of active positions to activePositions.json which is loaded at startup so we don't have to query all previous events every time.

Please see TODOs in executionClients/liquidator/reader.ts. I had a few questions/ assumptions that need clarification.
Also please tear this apart if there are better ways to do anything. I want to learn :)

@JossDuff JossDuff added the enhancement New feature or request label Jun 26, 2023
@JossDuff JossDuff requested a review from bghughes June 26, 2023 03:04
@JossDuff JossDuff marked this pull request as ready for review June 26, 2023 12:43
@JossDuff JossDuff marked this pull request as draft July 21, 2023 01:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant