Skip to content

Commit 3c26dc5

Browse files
authored
BAM writer service: Track BAM metrics (#31)
#### API - Added new endpoint bam_epoch_metrics - Returns bam metric info such as `bam_total_stake_weight`, `available_bam_delegation_stake`, `eligible_bam_validator_count` - Modified the endpoint `validators` to add new fields `jito_pool_eligible`, `jito_pool_directed_stake_target` #### Bam Writer Service - Service for BAM delegation calculations, tracking network-wide BAM validator participation and computing available JitoSOL delegation based on [JIP-28 specifications](https://forum.jito.network/t/jip-28-accelerate-bam-adoption/904).
1 parent 0989d8a commit 3c26dc5

22 files changed

+1705
-43
lines changed

.github/workflows/build-container-images.yaml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ on:
33
workflow_dispatch:
44
inputs:
55
service_config:
6-
description: 'Service configuration'
6+
description: "Service configuration"
77
required: true
8-
default: 'api'
8+
default: "api"
99
type: choice
1010
options:
1111
- api
1212
- cranker
1313
- writer-service
1414
- steward-writer-service
15+
- bam-writer-service
1516

1617
env:
1718
REGISTRY: ghcr.io
@@ -57,6 +58,11 @@ jobs:
5758
echo "service=steward-writer-service" >> $GITHUB_OUTPUT
5859
echo "image_name=${{ github.repository }}/kobe-steward-writer-service" >> $GITHUB_OUTPUT
5960
;;
61+
"bam-writer-service")
62+
echo "target=bam-writer-service" >> $GITHUB_OUTPUT
63+
echo "service=bam-writer-service" >> $GITHUB_OUTPUT
64+
echo "image_name=${{ github.repository }}/kobe-bam-writer-service" >> $GITHUB_OUTPUT
65+
;;
6066
esac
6167
6268
- name: Extract metadata
@@ -79,4 +85,4 @@ jobs:
7985
tags: ${{ steps.meta.outputs.tags }}
8086
labels: ${{ steps.meta.outputs.labels }}
8187
cache-from: type=gha
82-
cache-to: type=gha,mode=max
88+
cache-to: type=gha,mode=max

.github/workflows/test.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,3 @@ jobs:
2929
with:
3030
command: test
3131
args: --lib
32-

Cargo.lock

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

Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
resolver = "2"
33
members = [
44
"api",
5+
"bam-writer-service",
56
"core",
67
"cranker",
78
"cranker/cli",
@@ -39,7 +40,7 @@ http = { version = "0.2.1" }
3940
itertools = "0.5.9"
4041
jito-priority-fee-distribution = { features = ["no-entrypoint"], git = "https://github.com/jito-foundation/jito-programs", branch = "master" }
4142
jito-priority-fee-distribution-sdk = { git = "https://github.com/jito-foundation/jito-programs", branch = "master" }
42-
jito-steward = { features = ["no-entrypoint"], git = "https://github.com/jito-foundation/stakenet", rev = "d724a42b49c0cd32791afbd2a362dd63364a7a9a" }
43+
jito-steward = { package = "jito-steward", git = "https://github.com/jito-foundation/stakenet", rev = "6d35e58013cf7442dce287a1f45013085cb24967", features = ["no-entrypoint"] }
4344
jito-tip-distribution = { features = ["no-entrypoint"], git = "https://github.com/jito-foundation/jito-programs", branch = "master" }
4445
jito-tip-distribution-sdk = { git = "https://github.com/jito-foundation/jito-programs", branch = "master" }
4546
kobe-core = { path = "core", version = "1.0.0" }
@@ -83,7 +84,7 @@ spl-pod = "0.5.1"
8384
spl-stake-pool = { features = ["no-entrypoint"], version = "2.0.2" }
8485
spl-stake-pool-cli = { path = "cranker/cli", version = "1.0.0" }
8586
spl-token = { version = "4.0", features = ["no-entrypoint"] }
86-
stakenet-sdk = { package = "stakenet-sdk", git = "https://github.com/jito-foundation/stakenet", rev = "d724a42b49c0cd32791afbd2a362dd63364a7a9a" }
87+
stakenet-sdk = { package = "stakenet-sdk", git = "https://github.com/jito-foundation/stakenet", rev = "6d35e58013cf7442dce287a1f45013085cb24967" }
8788
thiserror = "1.0.37"
8889
tokio = { version = "1.36.0", features = ["full"] }
8990
tokio-retry = "0.3.0"
@@ -92,4 +93,4 @@ tower-http = { version = "0.4.0", features = ["cors", "trace"] }
9293
tracing = { version = "0.1.37" }
9394
tracing-core = "0.1.32"
9495
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
95-
validator-history = { package = "validator-history", git = "https://github.com/jito-foundation/stakenet", rev = "d724a42b49c0cd32791afbd2a362dd63364a7a9a", features = ["no-entrypoint"] }
96+
validator-history = { package = "validator-history", git = "https://github.com/jito-foundation/stakenet", rev = "6d35e58013cf7442dce287a1f45013085cb24967", features = ["no-entrypoint"] }

Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,10 @@ ENV APP="kobe-steward-writer-service"
4747
WORKDIR /app
4848
COPY --from=builder /home/root/app/${APP} ./
4949
ENTRYPOINT ./$APP listen
50+
51+
FROM debian:bookworm-slim as bam-writer-service
52+
RUN apt-get update && apt-get install -y libssl3 ca-certificates procps && rm -rf /var/lib/apt/lists/*
53+
ENV APP="kobe-bam-writer-service"
54+
WORKDIR /app
55+
COPY --from=builder /home/root/app/${APP} ./
56+
ENTRYPOINT ./$APP run

README.md

Lines changed: 65 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,32 @@ Named after both the premium grade of Kobe beef and in honor of basketball legen
1010
## Architecture Overview
1111

1212
```
13-
┌───────────────────────────────────────────────────────┐
14-
│ Solana Network │
15-
│ (Blockchain) │
16-
└───────────────────────────────────────────────────────┘
17-
▲ │ │
18-
│ │ (read on-chain data) │
19-
│ ▼ ▼
20-
(write │ ┌──────────────────┐ ┌──────────────────┐
21-
transactions) │ │ Kobe Writer │ │ Steward Writer │
22-
│ │ Service │ │ Service │
23-
│ │ (Data Collection)│ │ (Steward Events) │
24-
│ └──────────────────┘ └──────────────────┘
25-
│ │ │
26-
│ ▼ (write to db) ▼ (write to db)
27-
┌──────────────────┐ ┌─────────────────────────────────────────────┐
28-
│ Kobe Cranker │ │ MongoDB │
29-
│ (Pool Management)│ │ (Database) │
30-
└──────────────────┘ └─────────────────────────────────────────────┘
31-
32-
│ (read from db + on-chain)
33-
34-
┌─────────────────┐
35-
│ Kobe API │
36-
│ (Data Access) │
37-
└─────────────────┘
13+
┌────────────────────────────────────────────────────────────────────────────────────────┐ ┌─────────────┐
14+
│ Solana Network │ │ BAM API │
15+
│ (Blockchain) │ │ │
16+
└────────────────────────────────────────────────────────────────────────────────────────┘ └─────────────┘
17+
▲ │ │ │ │
18+
│ │ (read on-chain data) │ (read on-chain data) │ │ (read bam data)
19+
│ ▼ ▼ ▼ ▼
20+
(write │ ┌──────────────────┐ ┌──────────────────┐ ┌────────────────────────────────────┐
21+
transactions) │ │ Kobe Writer │ │ Steward Writer │ │ BAM Writer │
22+
│ │ Service │ │ Service │ │ Service │
23+
│ │ (Data Collection)│ │ (Steward Events) │ │ │
24+
│ └──────────────────┘ └──────────────────┘ └────────────────────────────────────┘
25+
│ │ │ │ ▲
26+
│ ▼ (write to db) ▼ (write to db) ▼ (write to db) │
27+
┌──────────────────┐ ┌──────────────────────────────────────────────────────────────────────┐ │
28+
│ Kobe Cranker │ │ MongoDB │ │
29+
│ (Pool Management)│ │ (Database) │ │
30+
└──────────────────┘ └──────────────────────────────────────────────────────────────────────┘ │ (read validators data)
31+
│ │
32+
│ (read from db + on-chain) │
33+
▼ │
34+
┌─────────────────┐ │
35+
│ Kobe API │ │
36+
│ (Data Access) │ ──────────────────────────────────────────────────
37+
│ │
38+
└─────────────────┘
3839
```
3940

4041
## JitoSOL APY Calculation
@@ -254,7 +255,24 @@ Therefore, users may see different APY values between real-time calculations and
254255
- Risk management actions
255256
- Stake rebalancing operations
256257

257-
**Use Cases:** Steward transparency, audit trails, performance analysis, regulatory compliance
258+
---
259+
260+
### [Kobe BAM Writer Service](./bam-writer-service/README.md)
261+
**Specialized monitoring** service for Block Assembly Marketplace (BAM) delegation calculations, tracking network-wide BAM validator participation and computing available JitoSOL delegation based on JIP-28 specifications.
262+
263+
**Capabilities:**
264+
- Real-time BAM validator stake tracking
265+
- JIP-28 tier-based delegation calculations
266+
- Network stakeweight monitoring
267+
- Epoch-based metrics collection and storage
268+
269+
**Key Features:**
270+
- Automated epoch threshold detection (default: 90% epoch progress)
271+
- Integration with BAM API for validator discovery
272+
- Dynamic delegation allocation based on network participation tiers
273+
- Historical BAM metrics persistence in MongoDB
274+
275+
**Use Cases:** Powers BAM delegation strategy, provides transparency into automated stake allocation decisions, enables historical analysis of BAM adoption trends
258276

259277
## Quick Start
260278

@@ -310,7 +328,14 @@ RUST_LOG=info cargo r -p kobe-cranker -- \
310328
#### Start Data Collection
311329

312330
```bash
313-
cargo r --bin kobe-writer-service -- live
331+
RUST_LOG=info cargo r --bin kobe-writer-service -- \
332+
--rpc-url "" \
333+
--mongo-connection-uri "mongodb://localhost:27017/kobe" \
334+
--mongo-db-name "validators" \
335+
--solana-cluster "testnet" \
336+
--jito-steward-program-id "Stewardf95sJbmtcZsyagb2dg4Mo8eVQho8gpECvLx8" \
337+
--steward-config-pubkey "5pZmpk3ktweGZW9xFknpEHhQoWeAKTzSGwnCUyVdiye" \
338+
live
314339
```
315340

316341
#### Start Steward Monitoring
@@ -325,6 +350,19 @@ RUST_LOG=info cargo r -p kobe-steward-writer-service -- \
325350
listen
326351
```
327352

353+
#### Run BAM writer service
354+
355+
```bash
356+
RUST_LOG=info cargo r -p kobe-bam-writer-service -- \
357+
--mongo-connection-uri "mongodb://localhost:27017/kobe" \
358+
--mongo-db-name "validators" \
359+
--rpc-url "https://api.mainnet-beta.solana.com/" \
360+
--bam-api-base-url "" \
361+
--epoch-progress-threshold "0.8" \
362+
--poll-interval-secs "60" \
363+
run
364+
```
365+
328366
## Contributing
329367

330368
1. Fork the repository

api/src/main.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ use env_logger::{Builder, Target};
1616
use kobe_api::{
1717
error::{handle_error, ApiError},
1818
resolvers::query_resolver::{
19-
daily_mev_rewards_cacheable_wrapper, get_validator_histories_wrapper,
19+
daily_mev_rewards_cacheable_wrapper, get_bam_epoch_metric_wrapper,
20+
get_bam_validators_wrapper, get_validator_histories_wrapper,
2021
jito_stake_over_time_ratio_cacheable_wrapper, jitosol_ratio_cacheable_wrapper,
2122
jitosol_validators_cacheable_wrapper, mev_commission_average_over_time_cacheable_wrapper,
2223
mev_rewards_cacheable_wrapper, preferred_withdraw_validator_list_cacheable_wrapper,
@@ -25,6 +26,8 @@ use kobe_api::{
2526
validator_rewards_cacheable_wrapper, validators_cacheable_wrapper, QueryResolver,
2627
},
2728
schemas::{
29+
bam_epoch_metric::BamEpochMetricRequest,
30+
bam_validator::BamValidatorsRequest,
2831
jitosol_ratio::JitoSolRatioRequest,
2932
mev_rewards::{MevRewardsRequest, StakerRewardsRequest, ValidatorRewardsRequest},
3033
preferred_withdraw::PreferredWithdrawRequest,
@@ -196,6 +199,20 @@ async fn get_validator_histories(
196199
get_validator_histories_wrapper(resolver, vote_account, epoch_query).await
197200
}
198201

202+
async fn get_bam_epoch_metric_handler(
203+
resolver: Extension<QueryResolver>,
204+
Query(epoch_query): Query<BamEpochMetricRequest>,
205+
) -> impl IntoResponse {
206+
get_bam_epoch_metric_wrapper(resolver, epoch_query.epoch).await
207+
}
208+
209+
async fn get_bam_validators_handler(
210+
resolver: Extension<QueryResolver>,
211+
Query(epoch_query): Query<BamValidatorsRequest>,
212+
) -> impl IntoResponse {
213+
get_bam_validators_wrapper(resolver, epoch_query.epoch).await
214+
}
215+
199216
async fn preferred_withdraw_validator_list_handler(
200217
resolver: Extension<QueryResolver>,
201218
request: Query<PreferredWithdrawRequest>,
@@ -348,6 +365,11 @@ async fn run_server(args: &Args) {
348365
"/api/v1/validator_history/:vote_account",
349366
get(get_validator_histories),
350367
)
368+
.route(
369+
"/api/v1/bam_epoch_metric",
370+
get(get_bam_epoch_metric_handler),
371+
)
372+
.route("/api/v1/bam_validators", get(get_bam_validators_handler))
351373
.route(
352374
"/api/v1/preferred_withdraw_validator_list",
353375
get(preferred_withdraw_validator_list_handler),

0 commit comments

Comments
 (0)