Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 2 additions & 63 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 7 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ version = "0.1.0"
edition = "2021"

[features]
default = ["network-mainnet"]
pretty_logs = []
network-mainnet = ["marginfi/mainnet-beta", "marginfi_type_crate/mainnet-beta"]
network-staging = ["marginfi/staging", "marginfi_type_crate/staging"]

[dependencies]
solana-account-decoder = "=2.1.20"
Expand Down Expand Up @@ -47,7 +50,6 @@ ctrlc = "3.5.2"

yellowstone-grpc-client = { git = "https://github.com/rpcpool/yellowstone-grpc", branch = "v2.1" }
yellowstone-grpc-proto = { git = "https://github.com/rpcpool/yellowstone-grpc", branch = "v2.1" }
switchboard-on-demand = "0.11.3"
# Includes a fix to the way results are parsed.
switchboard-on-demand-client = { git = "https://github.com/abdulrabbani00/switchboard-sdk", rev = "99cf3f29143b81fd3ad17649725a3f994b253fbb" }
solana-dex-superagg = { git = "https://github.com/0dotxyz/solana-dex-superagg", rev = "3ab0b4f4de424a0044e983576d113e3b349b3d94" }
Expand All @@ -57,19 +59,15 @@ git = "https://github.com/mrgnlabs/marginfi-v2"
# tag = "mrgn-0.1.8-rc3"
rev = "4ce8a15e70b4108059b74e1aedbfde1e3e564ace"
package = "marginfi-type-crate"
#STAGE
#default-features = false
#features = ["staging", "client"]
default-features = false
features = ["client"]

[dependencies.marginfi]
git = "https://github.com/mrgnlabs/marginfi-v2"
# tag = "mrgn-0.1.8-rc3"
rev = "4ce8a15e70b4108059b74e1aedbfde1e3e564ace"
#PROD
features = ["mainnet-beta", "client", "no-entrypoint"]
#STAGE
#default-features = false
#features = ["staging", "client", "no-entrypoint"]
default-features = false
features = ["client", "no-entrypoint", "custom-heap"]

[dependencies.jupiter-swap-api-client]
git = "https://github.com/IliaZyrin/jupiter-swap-api-client"
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ RUN cargo chef prepare --recipe-path recipe.json

FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json
RUN cargo chef cook --release --recipe-path recipe.json --no-default-features --features network-mainnet

COPY . .

RUN cargo build --release --bin eva01
RUN cargo build --release --bin eva01 --no-default-features --features network-mainnet

FROM debian:bookworm-slim AS runner

RUN apt-get update && apt-get install -y ca-certificates

COPY --from=builder /app/target/release/eva01 /usr/local/bin/

ENTRYPOINT ["/usr/local/bin/eva01"]
ENTRYPOINT ["/usr/local/bin/eva01"]
22 changes: 22 additions & 0 deletions Dockerfile.staging
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM lukemathwalker/cargo-chef:latest-rust-1.85 AS chef
WORKDIR /app

FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json --no-default-features --features network-staging

COPY . .

RUN cargo build --release --bin eva01 --no-default-features --features network-staging

FROM debian:bookworm-slim AS runner

RUN apt-get update && apt-get install -y ca-certificates

COPY --from=builder /app/target/release/eva01 /usr/local/bin/

ENTRYPOINT ["/usr/local/bin/eva01"]
37 changes: 28 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
# Eva01 - the Project 0 Liquidator

## Structure
* `bin` - shell scripts and environment configuration file templare
* `bin` - environment configuration template
* `idls` - IDLs for Project 0 integrations (Kamino, Drift, Juplend)
* `src` - source code
* eva.Dockerfile - the Docker configuration for building an image to run on Kubernetes
* `Dockerfile` - production (`network-mainnet`) image build
* `Dockerfile.staging` - staging (`network-staging`) image build

### Configuration
The [env.template](bin/env.template) file is a template for the required and optional environment variables that are used by Eva.
Expand All @@ -16,17 +17,35 @@ The [env.template](bin/env.template) file is a template for the required and opt
* Protoc: https://grpc.io/docs/protoc-installation/#install-pre-compiled-binaries-any-os;
* Rust: `curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh`
1. Clone the Git repo.
1. Create and configure the `.env` file by using [env.template](bin/env.template) as prototype.

> VSCode: create the VSCode launch configuration and add the configured `.env` to it.
1. Create and configure your environment file by using [env.template](bin/env.template) as prototype.
1. If you run through `run-eva.sh`, copy values into `docker.prod.env` (or change `run-eva.sh` to source a different file).


## Run
1. Source the `.env` file. Example: `source src/eva01/bin/prod.env`
1. Optionally Rotate logs: `mv ~/log/liquidator.log ~/log/liquidator.log.$(date +'%Y%m%dT%H%M%S')`
1. Run the Liquidator: `nohup bash $LIQUIDATOR_SRC_PATH/bin/start.sh >> ~/log/liquidator.log 2>&1 &`
1. Configure `docker.prod.env`.
1. Run from VS Code task `Run (with all checks)` or execute `bash ./run-eva.sh`.
1. Optional background run: `nohup bash ./run-eva.sh >> ~/log/liquidator.log 2>&1 &`

> Initial Loading Time
The initial loading phase can take some time, depending on your RPC. Eva will load everything needed into the state, including all Marginfi Accounts. Expect the loading time to be between 1-3 minutes depending on the RPC.

> Local Docker: Run `docker build -f <CONFIG FILE> -t eva:latest .` to build an image and `docker run --env-file docker.staging.env --rm -v <WALLET>:<WALLET> eva` to run it.
> Local Docker: Run `docker build -f <CONFIG FILE> -t eva:latest .` to build an image and `docker run --env-file docker.staging.env --rm -v <WALLET>:<WALLET> eva` to run it.

## Build Profiles

Cargo now supports network-specific build features:

* `network-mainnet` (default)
* `network-staging`

### Local builds

* Mainnet: `cargo build --release --bin eva01 --no-default-features --features network-mainnet`
* Staging: `cargo build --release --bin eva01 --no-default-features --features network-staging`

### Railway builds

Use different Dockerfiles per Railway environment:

* Production environment: leave default `Dockerfile` (or set `RAILWAY_DOCKERFILE_PATH=Dockerfile`)
* Staging environment: set `RAILWAY_DOCKERFILE_PATH=Dockerfile.staging`
11 changes: 5 additions & 6 deletions bin/env.template
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
# Path to the Eva repo. Only used to run on Linux.
LIQUIDATOR_SRC_PATH=<EVA REPOSITORY DIRECTORY>

## Mandatory part ##
RPC_URL=<RPC_URL>
YELLOWSTONE_ENDPOINT=<ENDPOINT_URL>
YELLOWSTONE_X_TOKEN=<TOKEN>
WALLET_KEYPAIR=<WALLET_KEYPAIR>
COMPUTE_UNIT_PRICE_MICRO_LAMPORTS=1000
MARGINFI_PROGRAM_ID=MFv2hWf31Z9kbCa1snEPYctwafyhdvnV7FZnsebVacA
MARGINFI_GROUP_KEY=4qp6Fx6tnZkY5Wropq9wUYgtFxXKwE6viZxFHg3rdAG8
ADDRESS_LOOKUP_TABLES=HGmknUTUmeovMc9ryERNWG6UFZDFDVr9xrum3ZhyL4fC,5FuKF7C1tJji2mXZuJ14U9oDb37is5mmvYLf4KwojoF1,FEFhAFKz48P3w82Ds5VhvyEDwhRqu2FejmnuxEPZ8wNR

Expand All @@ -25,13 +20,17 @@ JUP_SWAP_API_KEY='axvs'
SLIPPAGE_BPS=100

## Optional part ##
# Optional override for JSON-RPC endpoint. If not set, derived as
# `${YELLOWSTONE_ENDPOINT}/${YELLOWSTONE_X_TOKEN}` (or just endpoint if token is empty).
# RPC_URL=<RPC_URL>

# Switchboard feeds that should not be cranked (cause they fail too often)
UNSTABLE_SWB_FEEDS=<4YMdFbV8FaUv4FpE2gbZBReSFVzFKNPJZHirHwc2Psza,...>
CROSSBAR_API_URL=<SWITCHBOARD_CROSSBAR_API_URL>

# Port to check liquidator health state via HTTP. Example: http://localhost:3000/healthz
# Defaults to 3000 if not set
HEALTHCHECK_PORT=3000
PORT=3000

# Liquidation is skipped if there is less than this amount of tokens-to-be-used-for-repayment in the wallet. In USD.
# Defaults to 0.001 if not set
Expand Down
18 changes: 0 additions & 18 deletions bin/start.sh

This file was deleted.

6 changes: 5 additions & 1 deletion run-eva.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export RUST_BACKTRACE=0

# Run all steps
cargo fmt
# cargo clippy -- -D warnings
cargo clippy -- -D warnings
cargo build --bin eva01 --package eva01
cargo run --bin eva01 --features pretty_logs

# Staging network build/run example:
# cargo build --bin eva01 --package eva01 --no-default-features --features network-staging
# cargo run --bin eva01 --no-default-features --features "network-staging,pretty_logs"
5 changes: 1 addition & 4 deletions src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ const NEW_ADDRESSES_MAX: usize = 20usize;

pub struct Cache {
pub signer_pk: Pubkey,
pub marginfi_program_id: Pubkey,
pub marginfi_group_address: Pubkey,
pub marginfi_accounts: MarginfiAccountsCache,
pub banks: BanksCache,
Expand Down Expand Up @@ -74,16 +73,14 @@ pub struct DriftSpotMarket {
impl Cache {
pub fn new(
signer_pk: Pubkey,
marginfi_program_id: Pubkey,
marginfi_group_address: Pubkey,
clock: Arc<Mutex<Clock>>,
) -> Self {
let (global_fee_state_key, _) =
Pubkey::find_program_address(&[FEE_STATE_SEED.as_bytes()], &marginfi_program_id);
Pubkey::find_program_address(&[FEE_STATE_SEED.as_bytes()], &marginfi_type_crate::ID);
let luts = Arc::new(Mutex::new(vec![]));
Self {
signer_pk,
marginfi_program_id,
marginfi_group_address,
marginfi_accounts: MarginfiAccountsCache::default(),
banks: BanksCache::default(),
Expand Down
Loading
Loading