Skip to content
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c1577ec
Add Deepbook Indexer
Bridgerz Aug 17, 2024
572b20b
Add Deepbook Indexer
Bridgerz Aug 17, 2024
bc9a430
Update Cargo.lock
Bridgerz Aug 23, 2024
c65a876
upgrade diesel
Bridgerz Aug 23, 2024
83e0577
Update schema.rs
Bridgerz Aug 23, 2024
2a0faad
PR fixes
Bridgerz Aug 23, 2024
642a421
Add Deepbook Indexer
Bridgerz Aug 17, 2024
70b7457
Update Cargo.lock
Bridgerz Aug 27, 2024
763129d
new events
0xaslan Sep 4, 2024
6721ae5
Merge branch 'deepbook-indexer' of https://github.com/MystenLabs/sui …
0xaslan Sep 4, 2024
9dbad6e
id as primary key
0xaslan Sep 5, 2024
e63751c
cargo
0xaslan Sep 5, 2024
bf4e8dd
Merge branch 'main' into deepbook-indexer
0xaslan Sep 5, 2024
b8ce672
clippy
0xaslan Sep 5, 2024
c4c501a
Merge branch 'deepbook-indexer' of https://github.com/MystenLabs/sui …
0xaslan Sep 5, 2024
db5288b
fixes
0xaslan Sep 5, 2024
63c6628
Merge branch 'main' of https://github.com/MystenLabs/sui into deepboo…
0xaslan Sep 5, 2024
653dfb8
Merge branch 'main' of https://github.com/MystenLabs/sui into deepboo…
0xaslan Sep 6, 2024
108833e
cargolock
0xaslan Sep 6, 2024
ce8f22c
latest indexer changes
0xaslan Sep 6, 2024
d92fd89
Merge branch 'main' of https://github.com/MystenLabs/sui into deepboo…
0xaslan Sep 9, 2024
42aec12
pull latest indexer changes
0xaslan Sep 9, 2024
2a37333
Update Cargo.toml
Bridgerz Sep 9, 2024
8e87606
Update cargo.lock
Bridgerz Sep 9, 2024
31805a8
Update Cargo.lock
Bridgerz Sep 9, 2024
69600fb
Update events.rs
Bridgerz Sep 9, 2024
72c92da
Merge branch 'main' into db-indexer-squashed
longbowlu Sep 9, 2024
91849b2
cargo.lock
longbowlu Sep 9, 2024
9e648f8
remove unused files
longbowlu Sep 9, 2024
e4e295f
diesel stuff
longbowlu Sep 9, 2024
d9e898f
make it compile
longbowlu Sep 9, 2024
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
71 changes: 60 additions & 11 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ members = [
"crates/sui-cost",
"crates/sui-data-ingestion",
"crates/sui-data-ingestion-core",
"crates/sui-deepbook-indexer",
"crates/sui-e2e-tests",
"crates/sui-enum-compat-util",
"crates/sui-faucet",
Expand Down
43 changes: 43 additions & 0 deletions crates/sui-deepbook-indexer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[package]
name = "sui-deepbook-indexer"
version = "0.1.0"
authors = ["Mysten Labs <build@mystenlabs.com>"]
license = "Apache-2.0"
publish = false
edition = "2021"

[dependencies]
serde.workspace = true
tap.workspace = true
diesel = { version = "2.1.4", features = ["postgres", "r2d2", "serde_json", "numeric"] }
tokio = { workspace = true, features = ["full"] }
anyhow.workspace = true
futures.workspace = true
async-trait.workspace = true
bcs.workspace = true
bin-version.workspace = true
clap.workspace = true
mysten-metrics.workspace = true
prometheus.workspace = true
serde_yaml.workspace = true
sui-bridge.workspace = true
sui-sdk.workspace = true
sui-json-rpc-types.workspace = true
sui-data-ingestion-core.workspace = true
sui-types.workspace = true
telemetry-subscribers.workspace = true
tracing.workspace = true
backoff.workspace = true
sui-config.workspace = true
sui-indexer-builder.workspace = true
bigdecimal = "0.4.0"

[dev-dependencies]
sui-types = { workspace = true, features = ["test-utils"] }
sui-test-transaction-builder.workspace = true
test-cluster.workspace = true
hex-literal = "0.3.4"

[[bin]]
name = "deepbook-indexer"
path = "src/main.rs"
22 changes: 22 additions & 0 deletions crates/sui-deepbook-indexer/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# config.yaml format:

# URL of the remote store
# remote_store_url: <url>
# Database connection URL
# db_url: <url>
# Path to the checkpoints
# checkpoints_path: <path>
# DeepBook package ID
# deepbook_package_id:
# DeepBook genesis checkpoint
# deepbook_genesis_checkpoint:
# Number of concurrent operations
# concurrency: 1
# Client metric URL
# metric_url: <url>
# Client metric port
# metric_port: <port>
# checkpoint size of each backfill worker, use 432000 for 1 worker per day, assume 5 checkpoint per second
# back_fill_lot_size: <backfill lot size>
# Optional starting checkpoint for realtime ingestion task
# resume_from_checkpoint: <Sui checkpoint>
9 changes: 9 additions & 0 deletions crates/sui-deepbook-indexer/diesel.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# For documentation on how to configure this file,
# see https://diesel.rs/guides/configuring-diesel-cli

[print_schema]
file = "src/schema.rs"
#custom_type_derives = ["diesel::query_builder::QueryId"]

[migrations_directory]
dir = "src/migrations"
27 changes: 27 additions & 0 deletions crates/sui-deepbook-indexer/src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use serde::{Deserialize, Serialize};
use std::env;

/// config as loaded from `config.yaml`.
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct IndexerConfig {
pub remote_store_url: String,
#[serde(default = "default_db_url")]
pub db_url: String,
pub checkpoints_path: String,
pub sui_rpc_url: String,
pub deepbook_package_id: String,
pub deepbook_genesis_checkpoint: u64,
pub concurrency: u64,
pub metric_url: String,
pub metric_port: u16,
pub resume_from_checkpoint: Option<u64>,
}

impl sui_config::Config for IndexerConfig {}

pub fn default_db_url() -> String {
env::var("DB_URL").expect("db_url must be set in config or via the $DB_URL env var")
}
131 changes: 131 additions & 0 deletions crates/sui-deepbook-indexer/src/events.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use serde::{Deserialize, Serialize};
use sui_types::base_types::{ObjectID, SuiAddress};

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
pub struct MoveOrderFilledEvent {
pub pool_id: ObjectID,
pub maker_order_id: u128,
pub taker_order_id: u128,
pub maker_client_order_id: u64,
pub taker_client_order_id: u64,
pub price: u64,
pub taker_is_bid: bool,
pub taker_fee: u64,
pub maker_fee: u64,
pub base_quantity: u64,
pub quote_quantity: u64,
pub maker_balance_manager_id: ObjectID,
pub taker_balance_manager_id: ObjectID,
pub timestamp: u64,
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
pub struct MoveOrderCanceledEvent {
pub balance_manager_id: ObjectID,
pub pool_id: ObjectID,
pub order_id: u128,
pub client_order_id: u64,
pub trader: SuiAddress,
pub price: u64,
pub is_bid: bool,
pub original_quantity: u64,
pub base_asset_quantity_canceled: u64,
pub timestamp: u64,
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
pub struct MoveOrderModifiedEvent {
pub balance_manager_id: ObjectID,
pub pool_id: ObjectID,
pub order_id: u128,
pub client_order_id: u64,
pub trader: SuiAddress,
pub price: u64,
pub is_bid: bool,
pub new_quantity: u64,
pub timestamp: u64,
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
pub struct MoveOrderPlacedEvent {
pub balance_manager_id: ObjectID,
pub pool_id: ObjectID,
pub order_id: u128,
pub client_order_id: u64,
pub trader: SuiAddress,
pub price: u64,
pub is_bid: bool,
pub placed_quantity: u64,
pub expire_timestamp: u64,
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
pub struct MovePriceAddedEvent {
pub conversion_rate: u64,
pub timestamp: u64,
pub is_base_conversion: bool,
pub reference_pool: ObjectID,
pub target_pool: ObjectID,
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
pub struct MoveFlashLoanBorrowedEvent {
pub pool_id: ObjectID,
pub borrow_quantity: u64,
pub type_name: String,
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
pub struct MoveBalanceEvent {
pub balance_manager_id: ObjectID,
pub asset: String,
pub amount: u64,
pub deposit: bool,
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
pub struct MoveTradeParamsUpdateEvent {
pub taker_fee: u64,
pub maker_fee: u64,
pub stake_required: u64,
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
pub struct MoveStakeEvent {
pub pool_id: ObjectID,
pub balance_manager_id: ObjectID,
pub epoch: u64,
pub amount: u64,
pub stake: bool,
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
pub struct MoveProposalEvent {
pub pool_id: ObjectID,
pub balance_manager_id: ObjectID,
pub epoch: u64,
pub taker_fee: u64,
pub maker_fee: u64,
pub stake_required: u64,
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
pub struct MoveVoteEvent {
pub pool_id: ObjectID,
pub balance_manager_id: ObjectID,
pub epoch: u64,
pub from_proposal_id: Option<ObjectID>,
pub to_proposal_id: ObjectID,
pub stake: u64,
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
pub struct MoveRebateEvent {
pub pool_id: ObjectID,
pub balance_manager_id: ObjectID,
pub epoch: u64,
pub claim_amount: u64,
}
Loading
Loading