見出し画像

DEXの精算bot(liquidator)

DEXの精算bot?

DEXにおいて、精算が実行可能なポジションを監視し、あれば精算を実行するbotのこと。精算の実行者にはインセンティブ付与がある。

なぜ必要?

perp契約の場合、「priceが一定価格を下回ったときに精算」というイベント・ドリブンで実行される操作がある。CEXでは運営がこの操作を実行している。言い換えればperp取引では、①maker、②takerの他に、③精算者、という第三者が存在しているがDEXでは第三者としての運営がいない+eventでtransactionをtriggerすることができないので常時監視して精算を実行するbotが必要になる。

精算ポジションにX%の精算手数料rebateを設定し、裁定取引のようにliquidatorとしての参加者を誘引している。複数のliquidatorがいた場合は、早いものがち。

精算botが利益になるとき

精算手数料 > トランザクション手数料
精算bot実行者はできるだけ大きなポジションに対して精算を実行する必要がある?小さい精算ポジションって精算されない?まとめて精算実行ができる?

一般的な話

dydxのliquidator

  • githubはdeprecatedになっているので注意

Perpetual Contractのliquidator

記事やコードはv1はある。v2はdiscordに実装時のQAはある。v2で公開していないのは、すでに多くの参加者がいるから。でも一応動かしてそうとのこと

yes, the team runs liquidation bot at the start, but with time people come with their own bots which are better than team's one and take most of the work from team liquidation bot
still I think team's bot serves as an insurance to liquidate if the other bots stop for some reason..
there are not so many different accounts trading, so it's easy just to fetch all accounts with non-zero position from subgraph time to time and then check each account margin ratio via web3, and liquidate those with violation of margin ratio

https://discord.com/channels/687397941383659579/791219515089485874/944302576852160562

no, there are enough of private liquidators running to not need any open source one
as private liquidators are more sophisticated than anything open source as they have to have the edge to liquidate before anyone else

https://discord.com/channels/687397941383659579/791219515089485874/944281444497358908

@trader jack so the reason people will not publish bot code is because they compete against each other and the ones that win get the rewards. So doubtful anyone will publish them.

https://discord.com/channels/687397941383659579/775651724207587348/946042598433370142

liquidationのbotの作り方

SubgraphというtxのAPIをつかってOpenPositionを取得 -> liquidateかどうか判定 -> orderキャンセル -> liqudation実行
というのをやればいいっぽい

Another question: is there a method to get all wallet addresses that has open position? So I can loop them over and try liquidate them. I looked through clearinghouse.sol and there is no such method. Thanks!

I'm pretty sure you need to use The Graph for this.
Note also that for some liquidations you need to call cancelAllExcessOrders to cancel maker orders before you liquidate their position (in the case of maker liquidation).

liqudation失敗時のtx。tenderlyというサービスを使うと見やすいらしい

https://kovan-optimistic.etherscan.io/tx/0xd55cb75f09767f22fb6c40e8dda8a4fe2cb11280863f0ff05a2b92be13c6d082
https://dashboard.tenderly.co/tx/optimistic-kovan/0xd55cb75f09767f22fb6c40e8dda8a4fe2cb11280863f0ff05a2b92be13c6d082

https://discord.com/channels/687397941383659579/791219515089485874/955742124341612564

V2 Subgraph

Liquidityの分布


この記事が気に入ったらサポートをしてみませんか?