Skip to content

Commit def2f5b

Browse files
committed
feat: allow setting the minimum profit via the CLI
1 parent 646b203 commit def2f5b

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

src/keeper.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ impl<P: JsonRpcClient> Keeper<P> {
3939
liquidations: Address,
4040
uniswap: Address,
4141
flashloan: Address,
42+
min_profit: U256,
4243
state: Option<State>,
4344
) -> Result<Keeper<P>> {
4445
let (borrowers, vaults, last_block) = match state {
@@ -47,8 +48,15 @@ impl<P: JsonRpcClient> Keeper<P> {
4748
};
4849

4950
let borrowers = Borrowers::new(controller, client.clone(), borrowers).await;
50-
let liquidator =
51-
Liquidator::new(liquidations, uniswap, flashloan, client.clone(), vaults).await;
51+
let liquidator = Liquidator::new(
52+
liquidations,
53+
uniswap,
54+
flashloan,
55+
min_profit,
56+
client.clone(),
57+
vaults,
58+
)
59+
.await;
5260

5361
Ok(Self {
5462
client,
@@ -62,7 +70,7 @@ impl<P: JsonRpcClient> Keeper<P> {
6270
let watcher = self.client.clone();
6371
let mut on_block = watcher.watch_blocks().await?.stream();
6472

65-
while let Some(_) = on_block.next().await {
73+
while on_block.next().await.is_some() {
6674
let file = std::fs::OpenOptions::new()
6775
.read(true)
6876
.write(true)

src/liquidations.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ pub struct Liquidator<P> {
3030
/// our RPC endpoint
3131
multicall: Multicall<P, Wallet>,
3232

33+
/// The minimum profit to be extracted per liquidation
34+
min_profit: U256,
35+
3336
pending_liquidations: HashMap<Address, TxHash>,
3437
pending_auctions: HashMap<Address, TxHash>,
3538
}
@@ -51,6 +54,7 @@ impl<P: JsonRpcClient> Liquidator<P> {
5154
liquidations: Address,
5255
uniswap: Address,
5356
flashloan: Address,
57+
min_profit: U256,
5458
client: Arc<Client<P, Wallet>>,
5559
auctions: HashMap<Address, Auction>,
5660
) -> Self {
@@ -63,6 +67,7 @@ impl<P: JsonRpcClient> Liquidator<P> {
6367
uniswap: Uniswap::new(uniswap, client.clone()),
6468
flashloan,
6569
multicall,
70+
min_profit,
6671
auctions,
6772

6873
pending_liquidations: HashMap::new(),
@@ -149,10 +154,7 @@ impl<P: JsonRpcClient> Liquidator<P> {
149154
return Ok(());
150155
}
151156

152-
// TODO: Should this be done via gas estimation? A minimum 0.1 ETH
153-
// profit seems good enough.
154-
let min_profit_eth = U256::from(1e17 as u64);
155-
let args = abi::encode(&(user, min_profit_eth).into_tokens());
157+
let args = abi::encode(&(user, self.min_profit).into_tokens());
156158

157159
// Calls Uniswap's `swap` function which will optimistically let us
158160
// borrow the debt, which will then make a callback to the flashloan
@@ -204,7 +206,7 @@ impl<P: JsonRpcClient> Liquidator<P> {
204206
// only iterate over users that do not have pending liquidations
205207
if let Some(tx_hash) = self.pending_liquidations.get(&user) {
206208
trace!(tx_hash = ?tx_hash, user = ?user, "liquidation not confirmed yet");
207-
continue
209+
continue;
208210
}
209211

210212
if !details.is_collateralized {

src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ struct Opts {
5252

5353
#[options(help = "the file to be used for persistence", default = "data.json")]
5454
file: PathBuf,
55+
56+
#[options(help = "the minimum profit per liquidation")]
57+
min_profit: U256,
5558
}
5659

5760
#[tokio::main]
@@ -93,6 +96,7 @@ async fn main() -> anyhow::Result<()> {
9396
opts.liquidations,
9497
opts.uniswap,
9598
opts.flashloan,
99+
opts.min_profit,
96100
state,
97101
)
98102
.await?;

0 commit comments

Comments
 (0)