Skip to content

Commit ad0f860

Browse files
committed
feat: make it work with both ws and http and specify multicall address from cli
1 parent def2f5b commit ad0f860

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
lines changed

src/borrowers.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ impl<P: JsonRpcClient> Borrowers<P> {
4848
/// Constructor
4949
pub async fn new(
5050
controller: Address,
51+
multicall: Option<Address>,
5152
client: Arc<Client<P, Wallet>>,
5253
borrowers: HashMap<Address, Borrower>,
5354
) -> Self {
54-
let multicall = Multicall::new(client.clone(), None)
55+
let multicall = Multicall::new(client.clone(), multicall)
5556
.await
5657
.expect("could not initialize multicall");
5758
Borrowers {

src/keeper.rs

Lines changed: 3 additions & 1 deletion
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+
multicall: Option<Address>,
4243
min_profit: U256,
4344
state: Option<State>,
4445
) -> Result<Keeper<P>> {
@@ -47,11 +48,12 @@ impl<P: JsonRpcClient> Keeper<P> {
4748
None => (HashMap::new(), HashMap::new(), 0.into()),
4849
};
4950

50-
let borrowers = Borrowers::new(controller, client.clone(), borrowers).await;
51+
let borrowers = Borrowers::new(controller, multicall, client.clone(), borrowers).await;
5152
let liquidator = Liquidator::new(
5253
liquidations,
5354
uniswap,
5455
flashloan,
56+
multicall,
5557
min_profit,
5658
client.clone(),
5759
vaults,

src/liquidations.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,12 @@ impl<P: JsonRpcClient> Liquidator<P> {
5454
liquidations: Address,
5555
uniswap: Address,
5656
flashloan: Address,
57+
multicall: Option<Address>,
5758
min_profit: U256,
5859
client: Arc<Client<P, Wallet>>,
5960
auctions: HashMap<Address, Auction>,
6061
) -> Self {
61-
let multicall = Multicall::new(client.clone(), None)
62+
let multicall = Multicall::new(client.clone(), multicall)
6263
.await
6364
.expect("could not initialize multicall");
6465

src/main.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use ethers::prelude::*;
22
use yield_liquidator::keeper::Keeper;
33

44
use gumdrop::Options;
5-
use std::{path::PathBuf, sync::Arc, time::Duration};
5+
use std::{convert::TryFrom, path::PathBuf, sync::Arc, time::Duration};
66
use tracing::info;
77
use tracing_subscriber::{filter::EnvFilter, fmt::Subscriber};
88

@@ -35,6 +35,11 @@ struct Opts {
3535
)]
3636
flashloan: Address,
3737

38+
#[options(
39+
help = "the address of the Multicall contract (optional for any of the deployed testnets)"
40+
)]
41+
multicall: Option<Address>,
42+
3843
#[options(
3944
help = "the Ethereum node HTTP endpoint",
4045
default = "http://localhost:8545"
@@ -65,9 +70,19 @@ async fn main() -> anyhow::Result<()> {
6570

6671
let opts = Opts::parse_args_default_or_exit();
6772

68-
let ws = Ws::connect(opts.url.clone()).await?;
69-
let provider = Provider::new(ws);
70-
// let provider = Provider::<Http>::try_from(opts.url.clone())?;
73+
if opts.url.starts_with("http") {
74+
let provider = Provider::<Http>::try_from(opts.url.clone())?;
75+
run(opts, provider).await?;
76+
} else {
77+
let ws = Ws::connect(opts.url.clone()).await?;
78+
let provider = Provider::new(ws);
79+
run(opts, provider).await?;
80+
}
81+
82+
Ok(())
83+
}
84+
85+
async fn run<P: JsonRpcClient>(opts: Opts, provider: Provider<P>) -> anyhow::Result<()> {
7186
let wallet: Wallet = opts.private_key.parse()?;
7287
let client = wallet
7388
.connect(provider)
@@ -79,6 +94,7 @@ async fn main() -> anyhow::Result<()> {
7994
info!("Controller: {:?}", opts.controller);
8095
info!("Liquidations: {:?}", opts.liquidations);
8196
info!("Uniswap: {:?}", opts.uniswap);
97+
info!("Multicall: {:?}", opts.multicall);
8298
info!("FlashLiquidator {:?}", opts.flashloan);
8399
info!("Persistent data will be stored at: {:?}", opts.file);
84100

@@ -96,6 +112,7 @@ async fn main() -> anyhow::Result<()> {
96112
opts.liquidations,
97113
opts.uniswap,
98114
opts.flashloan,
115+
opts.multicall,
99116
opts.min_profit,
100117
state,
101118
)

0 commit comments

Comments
 (0)