Skip to content

Commit fdcd2b5

Browse files
authored
Merge pull request #35 from propeller-heads/repay
Upgrade Rust and tycho-simulation, fix Docker builds
2 parents 4a292ff + ab00855 commit fdcd2b5

File tree

10 files changed

+1866
-1929
lines changed

10 files changed

+1866
-1929
lines changed

Cargo.lock

Lines changed: 1799 additions & 1885 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
# Simulation dependencies
8-
tycho-simulation = { git = "https://github.com/propeller-heads/tycho-simulation", tag = "0.103.0" }
8+
tycho-simulation = { git = "https://github.com/propeller-heads/tycho-simulation", tag = "0.127.1" }
99
num-bigint = "0.4"
1010
num-traits = "0.2"
1111

api/Dockerfile

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
# Build stage
22
FROM rust:1.87 as builder
3-
WORKDIR /app
3+
4+
# Create workspace directory structure
5+
RUN mkdir -p /workspace/api
6+
WORKDIR /workspace
47

58
RUN echo "🔵 [BUILD] Starting Rust build process..."
69

7-
# Copy dependency files
10+
# Copy workspace files first
811
COPY Cargo.toml Cargo.lock ./
12+
COPY api/Cargo.toml ./api/
13+
14+
# Build dependencies first
915
RUN echo "🔵 [BUILD] Building dependencies first (this may take a while)..."
10-
RUN mkdir src && echo "fn main() {}" > src/main.rs
11-
RUN cargo build --release 2>&1 | tee /tmp/cargo-deps.log || (echo "🔴 [ERROR] Dependency build failed" && cat /tmp/cargo-deps.log && exit 1)
12-
RUN rm -rf src
16+
RUN mkdir -p api/src && echo "fn main() {}" > api/src/main.rs
17+
RUN cd api && cargo build --release 2>&1 | tee /tmp/cargo-deps.log || (echo "🔴 [ERROR] Dependency build failed" && cat /tmp/cargo-deps.log && exit 1)
18+
RUN rm -rf api/src
1319

1420
# Copy actual source
15-
COPY . .
21+
COPY api ./api
1622
RUN echo "🔵 [BUILD] Building tycho-api binary..."
17-
RUN touch src/main.rs
18-
RUN cargo build --release 2>&1 | tee /tmp/cargo-build.log || (echo "🔴 [ERROR] Build failed" && cat /tmp/cargo-build.log && exit 1)
23+
RUN touch api/src/main.rs
24+
RUN cd api && cargo build --release 2>&1 | tee /tmp/cargo-build.log || (echo "🔴 [ERROR] Build failed" && cat /tmp/cargo-build.log && exit 1)
1925
RUN echo "🟢 [BUILD] Rust build completed successfully"
2026

2127
# Runtime stage
@@ -29,7 +35,7 @@ RUN apt-get update && apt-get install -y \
2935
&& rm -rf /var/lib/apt/lists/*
3036

3137
# Copy binary
32-
COPY --from=builder /app/target/release/tycho-api /usr/local/bin/
38+
COPY --from=builder /workspace/target/release/tycho-api /usr/local/bin/
3339
RUN echo "🟢 [PROD] Binary copied successfully"
3440

3541
EXPOSE 3000

api/Dockerfile.dev

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
# Uses cargo watch for hot reloading and builds in debug mode
33

44
FROM rust:1.87
5-
WORKDIR /app
5+
6+
# Create workspace directory structure
7+
RUN mkdir -p /workspace/api
8+
WORKDIR /workspace
69

710
RUN echo "🔵 [DEV] Setting up development environment..."
811

@@ -18,6 +21,21 @@ RUN apt-get update && apt-get install -y \
1821
RUN cargo install cargo-watch
1922
RUN echo "🟢 [DEV] cargo-watch installed"
2023

24+
# Copy workspace files first for better caching
25+
COPY Cargo.toml Cargo.lock ./
26+
COPY api/Cargo.toml ./api/
27+
28+
# Create a dummy main.rs to allow cargo to download dependencies
29+
RUN mkdir -p api/src && echo "fn main() {}" > api/src/main.rs
30+
31+
# Pre-download dependencies (this layer will be cached)
32+
RUN cargo fetch --manifest-path ./api/Cargo.toml
33+
34+
# Remove dummy file
35+
RUN rm -rf api/src
36+
37+
WORKDIR /workspace/api
38+
2139
EXPOSE 3000
2240

2341
# Command will be provided by docker-compose

api/src/api/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use tower_http::{
99
trace::TraceLayer,
1010
};
1111
use tracing::info;
12-
use tycho_simulation::protocol::models::BlockUpdate;
12+
use tycho_simulation::protocol::models::Update as BlockUpdate;
1313

1414
use crate::simulation::state::SimulationState;
1515

api/src/api/routes.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use axum::{
44
Json, Router,
55
};
66
use num_bigint::BigUint;
7-
use num_traits::FromPrimitive;
87
use serde::{Deserialize, Serialize};
98
use serde_json::json;
109
use tracing::info;
@@ -64,7 +63,7 @@ async fn simulate_transaction(
6463
};
6564

6665
// Parse integer part as BigUint
67-
let mut amount_biguint = BigUint::parse_bytes(integer_part.as_bytes(), 10)
66+
let amount_biguint = BigUint::parse_bytes(integer_part.as_bytes(), 10)
6867
.ok_or_else(|| ApiError::InvalidInput("Invalid amount format".to_string()))?;
6968

7069
let mut current_amount = None;

api/src/simulation/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ use tycho_simulation::{
77
evm::{
88
engine_db::tycho_db::PreCachedDB,
99
protocol::{
10-
filters::{balancer_pool_filter, uniswap_v4_pool_with_hook_filter},
10+
filters::{balancer_v2_pool_filter, uniswap_v4_pool_with_hook_filter},
1111
uniswap_v2::state::UniswapV2State,
1212
uniswap_v3::state::UniswapV3State,
1313
uniswap_v4::state::UniswapV4State,
1414
pancakeswap_v2::state::PancakeswapV2State,
1515
ekubo::state::EkuboState,
1616
vm::state::EVMPoolState,
17-
filters::{curve_pool_filter}
17+
filters::curve_pool_filter
1818
},
1919
stream::ProtocolStreamBuilder,
2020
},
21-
protocol::models::BlockUpdate,
21+
protocol::models::Update as BlockUpdate,
2222
tycho_client::feed::component_tracker::ComponentFilter,
2323
tycho_core::models::Chain,
2424
utils::load_all_tokens,
@@ -47,7 +47,7 @@ fn register_exchanges(
4747
.exchange::<EVMPoolState<PreCachedDB>>(
4848
"vm:balancer_v2",
4949
tvl_filter.clone(),
50-
Some(balancer_pool_filter),
50+
Some(balancer_v2_pool_filter),
5151
)
5252
.exchange::<UniswapV4State>(
5353
"uniswap_v4",

api/src/simulation/state.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@ use serde::Serialize;
22
use std::{collections::HashMap, sync::Arc};
33
use tokio::sync::{broadcast, RwLock};
44
use tycho_simulation::{
5-
models::Token,
6-
protocol::{
7-
models::{BlockUpdate, ProtocolComponent},
8-
state::ProtocolSim,
9-
},
5+
protocol::models::{Update as BlockUpdate, ProtocolComponent},
6+
tycho_core::{models::token::Token, simulation::protocol_sim::ProtocolSim},
107
};
118

129
/// Represents the current state of the simulation
@@ -38,7 +35,7 @@ impl From<BlockUpdate> for ClientUpdate {
3835
}
3936

4037
ClientUpdate {
41-
block_number: update.block_number,
38+
block_number: update.block_number_or_timestamp,
4239
new_pairs: update.new_pairs,
4340
spot_prices,
4441
tvl_updates,

docker-compose.dev.yml

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ services:
77
# Ethereum Mainnet Tycho API (Development)
88
tycho-api-ethereum-dev:
99
build:
10-
context: ./api
11-
dockerfile: Dockerfile.dev
10+
context: .
11+
dockerfile: api/Dockerfile.dev
1212
ports:
1313
- "${TYCHO_API_ETHEREUM_PORT}:3000"
1414
environment:
@@ -21,13 +21,14 @@ services:
2121
command: ["/bin/bash", "-c", "cargo watch -x 'run -- --tvl-threshold ${TVL_THRESHOLD} --chain ethereum --port 3000 --tycho-url ${TYCHO_ETHEREUM_URL}'"]
2222
volumes:
2323
# Mount source code for development
24-
- ./api/src:/app/src:ro
25-
- ./api/Cargo.toml:/app/Cargo.toml:ro
26-
- ./api/Cargo.lock:/app/Cargo.lock
24+
- ./api/src:/workspace/api/src:ro
25+
- ./api/Cargo.toml:/workspace/api/Cargo.toml:ro
26+
- ./Cargo.toml:/workspace/Cargo.toml:ro
27+
- ./Cargo.lock:/workspace/Cargo.lock:ro
2728
# Share cargo cache and build artifacts
2829
- cargo-cache:/usr/local/cargo/registry
2930
- cargo-registry:/usr/local/cargo/git
30-
- cargo-target:/app/target
31+
- cargo-target:/workspace/target
3132
networks:
3233
- tycho-network-dev
3334
healthcheck:
@@ -44,8 +45,8 @@ services:
4445
# Base Mainnet Tycho API (Development)
4546
tycho-api-base-dev:
4647
build:
47-
context: ./api
48-
dockerfile: Dockerfile.dev
48+
context: .
49+
dockerfile: api/Dockerfile.dev
4950
depends_on:
5051
tycho-api-ethereum-dev:
5152
condition: service_healthy
@@ -61,13 +62,14 @@ services:
6162
command: ["/bin/bash", "-c", "cargo watch -x 'run -- --tvl-threshold ${TVL_THRESHOLD} --chain base --port 3000 --tycho-url ${TYCHO_BASE_URL}'"]
6263
volumes:
6364
# Mount source code for development
64-
- ./api/src:/app/src:ro
65-
- ./api/Cargo.toml:/app/Cargo.toml:ro
66-
- ./api/Cargo.lock:/app/Cargo.lock
65+
- ./api/src:/workspace/api/src:ro
66+
- ./api/Cargo.toml:/workspace/api/Cargo.toml:ro
67+
- ./Cargo.toml:/workspace/Cargo.toml:ro
68+
- ./Cargo.lock:/workspace/Cargo.lock:ro
6769
# Share cargo cache and build artifacts
6870
- cargo-cache:/usr/local/cargo/registry
6971
- cargo-registry:/usr/local/cargo/git
70-
- cargo-target:/app/target
72+
- cargo-target:/workspace/target
7173
networks:
7274
- tycho-network-dev
7375
healthcheck:
@@ -84,8 +86,8 @@ services:
8486
# Unichain Mainnet Tycho API (Development)
8587
tycho-api-unichain-dev:
8688
build:
87-
context: ./api
88-
dockerfile: Dockerfile.dev
89+
context: .
90+
dockerfile: api/Dockerfile.dev
8991
depends_on:
9092
tycho-api-ethereum-dev:
9193
condition: service_healthy
@@ -101,13 +103,14 @@ services:
101103
command: ["/bin/bash", "-c", "cargo watch -x 'run -- --tvl-threshold ${TVL_THRESHOLD} --chain unichain --port 3000 --tycho-url ${TYCHO_UNICHAIN_URL}'"]
102104
volumes:
103105
# Mount source code for development
104-
- ./api/src:/app/src:ro
105-
- ./api/Cargo.toml:/app/Cargo.toml:ro
106-
- ./api/Cargo.lock:/app/Cargo.lock
106+
- ./api/src:/workspace/api/src:ro
107+
- ./api/Cargo.toml:/workspace/api/Cargo.toml:ro
108+
- ./Cargo.toml:/workspace/Cargo.toml:ro
109+
- ./Cargo.lock:/workspace/Cargo.lock:ro
107110
# Share cargo cache and build artifacts
108111
- cargo-cache:/usr/local/cargo/registry
109112
- cargo-registry:/usr/local/cargo/git
110-
- cargo-target:/app/target
113+
- cargo-target:/workspace/target
111114
networks:
112115
- tycho-network-dev
113116
healthcheck:

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ services:
22
# Ethereum Mainnet Tycho API
33
tycho-api-ethereum:
44
build:
5-
context: ./api
6-
dockerfile: Dockerfile
5+
context: .
6+
dockerfile: api/Dockerfile
77
image: tycho-explorer/api:latest
88
container_name: tycho-api-ethereum
99
deploy:

0 commit comments

Comments
 (0)