Utility for automatically liquidating underwater accounts in Hifi.
- Compatible only with the WBTC/USDC pair
Utility for automatically liquidating underwater accounts in Hifi
We're currently dumping the vault data into a JSON file on disk:
There many downsides to it, but the primary issue is that the data gets pruned every time a Docker container is pruned. We should switch to a database model and use Docker Compose to connect to the database container.
Calling liquidateBorrow
on the fyToken reverts when the price of the collateral has fallen so much that the liquidator cannot receive their 10% share of the deal (an economic risk that we were well aware of when we wrote the protocol).
Before liquidating the user via the Uniswap V2 pair, we should call the getClutchableCollateral
function on the BalanceSheet and compare it to the currently locked collateral in the vault.
It is not a given that the gas will always be bumped by the escalator. The logic in GeometricGasPrice (part of ethers-rs) bumps the gas only if more than every_secs seconds passed. Therefore, it is possible that a transaction will be replaced with the same gas price, which causes the tx to revert (at least in Parity).
The solution is to modify the remove_pending_tx_tuple_or_bump_gas_price_internal
function to account for this edge case.
Refer to Do all Ethereum networks return the revert reasons as a “message” field? for a thorough explanation of the issue.
We should modify the Err variant
in liquidations.rs
so that if the network used is Kovan, the revert reason is decoded from the data
field.
Monitoring vaults with less than ~$200 worth of collateral may not be worth it, due to gas fees.
Whenever Infura returns the following error (and presumably others like it):
Error: Deserialization Error: expected value at line 1 column 1. Response:
<html>
<head><title>502 Bad Gateway</title></head>
<body>
<center><h1>502 Bad Gateway</h1></center>
</body>
</html>
The liquidator program exits, which is not good.
We should replace the code on line 110 in liquidator.rs
:
With a match expression that checks if the enum variant is Err
, and log the error accordingly.
As of d3b1c4d the least, the bot behaves like this:
It's not clear what's the appropriate way to handle this issue. On the one hand, not repeating step #1 would be bad from a security POV - under-collateralized borrowers should be liquidated ASAP. On the other hand, sending a bajillion txs hard-stresses our RPC endpoint, increasing our bill.
Be discriminate with error handling (in the handle_reverted_tx):
The JSON-RPC client gets cloned on every new block, in the call to update the vaults in the sentinel.rs
file. This is putting a heavy load on our EC2 instance - let's figure out a smarter way to structure the data so that we clone the vault less often.
When the WS connection to Infura is closed, the bot should exit the process, so that Kubernetes picks it up and restarts the pod.
Sometimes, the data that gets written to the database file ends up being this bogus json:
{
"last_block": "0x15fdfa6",
"vaults": {
"0xae4480e53a2d2ec060732a354d86becae890781f": {
"0xe844453eb945cea7326ac9e7b1f85f2903f4df2f": {
"debt": "0x0",
"debt_in_underlying": "0x0",
"is_account_underwater": false,
"locked_collateral": "0x2496"
},
"0x22e7e1a5f96b09cdf786fb18e0dba4bc9b017343": {
"debt": "0x0",
"debt_in_underlying": "0x0",
"is_account_underwater": false,
"locked_collateral": "0x1fc1e20"
},
"0x4bcb303609f19e71ab82a3a3393c46bfea1e44fc": {
"debt": "0x0",
"debt_in_underlying": "0x0",
"is_account_underwater": false,
"locked_collateral": "0x5f5e100"
},
"0x9c41b359c12d924c3ff232583c6a1ff04b8aed18": {
"debt": "0x362907144269dfda56",
"debt_in_underlying": "0x3b8cc255",
"is_account_underwater": false,
"locked_collateral": "0x1565aab700"
}
}
}
}
ollateral":"0x5f5e100"}}}}
Notice the extraneous ollateral":"0x5f5e100"}}}}
at the end.
There is a bug with the tx replacement logic.
0x123
0x123
wasn't mined quickly enough, so it broadcasts a replacement tx 0xabc
with a higher gas price.0x123
gets mined.0xabc
will revert with the reason "ERR_ACCOUNT_NOT_UNDERWATER"liquidations.rs
won't return true
, because the 0xabc
has been dropped and (I assume) Ethereum gives no receipt for these txs.0xabc
forever, even if 0x123
was mined, but it will fail to replace it. The Err
variant will be used when broadcasting the replacement of the replacement tx.The current implementation (as per commit 7b5f6f3 at least) is limited to the WBTC/USDC pair. We should do the following to make the implementation more general-purpose:
vaults.rs
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.