@@ -2,6 +2,7 @@ use ethers::prelude::*;
2
2
use yield_liquidator:: keeper:: Keeper ;
3
3
4
4
use gumdrop:: Options ;
5
+ use serde:: Deserialize ;
5
6
use std:: { convert:: TryFrom , path:: PathBuf , sync:: Arc , time:: Duration } ;
6
7
use tracing:: info;
7
8
use tracing_subscriber:: { filter:: EnvFilter , fmt:: Subscriber } ;
@@ -11,46 +12,17 @@ use tracing_subscriber::{filter::EnvFilter, fmt::Subscriber};
11
12
struct Opts {
12
13
help : bool ,
13
14
14
- #[ options(
15
- help = "the Yield controller's address" ,
16
- default = "Cf699af73C25aC785E8Da72F4fA7872c86D43C15"
17
- ) ]
18
- controller : Address ,
19
-
20
- #[ options(
21
- help = "the Yield liquidation's address" ,
22
- default = "b85F3d294edD2B76128cf918800BB21081f59223"
23
- ) ]
24
- liquidations : Address ,
25
-
26
- #[ options(
27
- help = "the DAI/WETH Uniswap V2 pair" ,
28
- default = "6025b901C88e5739Cb4112fcf3F27E0264c5BdDe"
29
- ) ]
30
- uniswap : Address ,
31
-
32
- #[ options(
33
- help = "the address of your flashloan contract" ,
34
- default = "FE35d86cb5b6c0273fAC070Cc40aFeA77574cEF0"
35
- ) ]
36
- flashloan : Address ,
37
-
38
- #[ options(
39
- help = "the address of the Multicall contract (optional for any of the deployed testnets)"
40
- ) ]
41
- multicall : Option < Address > ,
15
+ #[ options( help = "path to json file with the contract addresses" ) ]
16
+ config : PathBuf ,
42
17
43
18
#[ options(
44
- help = "the Ethereum node HTTP endpoint " ,
19
+ help = "the Ethereum node endpoint ( HTTP or WS) " ,
45
20
default = "http://localhost:8545"
46
21
) ]
47
22
url : String ,
48
23
49
- #[ options(
50
- help = "your private key" ,
51
- default = "8b6e036da61e5ac4874a770d7258583cd1b373798e740deaff4015fea80294b0"
52
- ) ]
53
- private_key : String ,
24
+ #[ options( help = "path to your private key" ) ]
25
+ private_key : PathBuf ,
54
26
55
27
#[ options( help = "polling interval (ms)" , default = "1000" ) ]
56
28
interval : u64 ,
@@ -62,6 +34,15 @@ struct Opts {
62
34
min_profit : U256 ,
63
35
}
64
36
37
+ #[ derive( Deserialize ) ]
38
+ struct Config {
39
+ controller : Address ,
40
+ liquidations : Address ,
41
+ uniswap : Address ,
42
+ flashloan : Address ,
43
+ multicall : Option < Address > ,
44
+ }
45
+
65
46
#[ tokio:: main]
66
47
async fn main ( ) -> anyhow:: Result < ( ) > {
67
48
Subscriber :: builder ( )
@@ -83,19 +64,25 @@ async fn main() -> anyhow::Result<()> {
83
64
}
84
65
85
66
async fn run < P : JsonRpcClient > ( opts : Opts , provider : Provider < P > ) -> anyhow:: Result < ( ) > {
86
- let wallet: Wallet = opts. private_key . parse ( ) ?;
67
+ info ! ( "Starting Yield Liquidator." ) ;
68
+ let wallet: Wallet = std:: fs:: read_to_string ( opts. private_key ) ?. parse ( ) ?;
87
69
let client = wallet
88
70
. connect ( provider)
89
- . interval ( Duration :: from_millis ( opts. interval ) ) ;
71
+ . interval ( Duration :: from_millis ( opts. interval ) )
72
+ // enable the nonce-manager so that we can send multiple transactions in a row
73
+ // without waiting for them to be included in the mempool
74
+ . with_nonce_manager ( ) ;
90
75
let client = Arc :: new ( client) ;
91
- info ! ( "Starting Yield Liquidator." ) ;
92
- info ! ( "Node: {}" , opts. url) ;
93
76
info ! ( "Profits will be sent to {:?}" , client. address( ) ) ;
94
- info ! ( "Controller: {:?}" , opts. controller) ;
95
- info ! ( "Liquidations: {:?}" , opts. liquidations) ;
96
- info ! ( "Uniswap: {:?}" , opts. uniswap) ;
97
- info ! ( "Multicall: {:?}" , opts. multicall) ;
98
- info ! ( "FlashLiquidator {:?}" , opts. flashloan) ;
77
+
78
+ info ! ( "Node: {}" , opts. url) ;
79
+
80
+ let cfg: Config = serde_json:: from_reader ( std:: fs:: File :: open ( opts. config ) ?) ?;
81
+ info ! ( "Controller: {:?}" , cfg. controller) ;
82
+ info ! ( "Liquidations: {:?}" , cfg. liquidations) ;
83
+ info ! ( "Uniswap: {:?}" , cfg. uniswap) ;
84
+ info ! ( "Multicall: {:?}" , cfg. multicall) ;
85
+ info ! ( "FlashLiquidator {:?}" , cfg. flashloan) ;
99
86
info ! ( "Persistent data will be stored at: {:?}" , opts. file) ;
100
87
101
88
let file = std:: fs:: OpenOptions :: new ( )
@@ -108,11 +95,11 @@ async fn run<P: JsonRpcClient>(opts: Opts, provider: Provider<P>) -> anyhow::Res
108
95
109
96
let mut keeper = Keeper :: new (
110
97
client,
111
- opts . controller ,
112
- opts . liquidations ,
113
- opts . uniswap ,
114
- opts . flashloan ,
115
- opts . multicall ,
98
+ cfg . controller ,
99
+ cfg . liquidations ,
100
+ cfg . uniswap ,
101
+ cfg . flashloan ,
102
+ cfg . multicall ,
116
103
opts. min_profit ,
117
104
state,
118
105
)
0 commit comments