From ba49d2257b4379164993473494f6222224e27383 Mon Sep 17 00:00:00 2001 From: 0xaslan <161349919+0xaslan@users.noreply.github.com> Date: Thu, 24 Oct 2024 16:34:48 -0400 Subject: [PATCH] DeepBook indexer - add event_digest, replace id, add checkpoint_timestamp_ms (#20008) ## Description Describe the changes or additions included in this PR. * Added a new column event_digest - digest + event index. This is a unique value. It is used as primary key and will ensure an event is not added twice. * Added a new column checkpoint_timestamp_ms - best way to know when the event was emitted, since some events don't emit the onchain timestamp. ## Test plan How did you test the new or updated feature? Local end to end testing. I manipulated the local progress_store to force reread checkpoints, which resulted in an error when adding duplicate events (as expected). --- ## Release notes Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required. For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates. - [ ] Protocol: - [ ] Nodes (Validators and Full nodes): - [ ] Indexer: - [ ] JSON-RPC: - [ ] GraphQL: - [ ] CLI: - [ ] Rust SDK: - [ ] REST API: --- .../down.sql | 7 ++ .../up.sql | 30 ++++--- crates/sui-deepbook-indexer/src/models.rs | 40 ++++++--- crates/sui-deepbook-indexer/src/schema.rs | 66 ++++++++------ .../src/sui_deepbook_indexer.rs | 85 ++++++++++++++++--- crates/sui-deepbook-indexer/src/types.rs | 58 +++++++++++-- 6 files changed, 215 insertions(+), 71 deletions(-) diff --git a/crates/sui-deepbook-indexer/src/migrations/00000000000000_diesel_initial_setup/down.sql b/crates/sui-deepbook-indexer/src/migrations/00000000000000_diesel_initial_setup/down.sql index 454dcfecb7003..b86f980c0eacb 100644 --- a/crates/sui-deepbook-indexer/src/migrations/00000000000000_diesel_initial_setup/down.sql +++ b/crates/sui-deepbook-indexer/src/migrations/00000000000000_diesel_initial_setup/down.sql @@ -3,5 +3,12 @@ DROP TABLE IF EXISTS order_updates; DROP TABLE IF EXISTS order_fills; DROP TABLE IF EXISTS flashloans; DROP TABLE IF EXISTS pool_prices; +DROP TABLE IF EXISTS balances; +DROP TABLE IF EXISTS trade_params_update; +DROP TABLE IF EXISTS stakes; +DROP TABLE IF EXISTS proposals; +DROP TABLE IF EXISTS votes; +DROP TABLE IF EXISTS rebates; DROP TABLE IF EXISTS sui_error_transactions; DROP TABLE IF EXISTS progress_store; +DROP TABLE IF EXISTS pools; \ No newline at end of file diff --git a/crates/sui-deepbook-indexer/src/migrations/00000000000000_diesel_initial_setup/up.sql b/crates/sui-deepbook-indexer/src/migrations/00000000000000_diesel_initial_setup/up.sql index 04d9951f6e66a..20f7d6a5172ca 100644 --- a/crates/sui-deepbook-indexer/src/migrations/00000000000000_diesel_initial_setup/up.sql +++ b/crates/sui-deepbook-indexer/src/migrations/00000000000000_diesel_initial_setup/up.sql @@ -2,11 +2,12 @@ CREATE TABLE IF NOT EXISTS order_updates ( - id SERIAL PRIMARY KEY, + event_digest TEXT PRIMARY KEY, digest TEXT NOT NULL, sender TEXT NOT NULL, checkpoint BIGINT NOT NULL, timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, + checkpoint_timestamp_ms BIGINT NOT NULL, package TEXT NOT NULL, status TEXT NOT NULL, pool_id TEXT NOT NULL, @@ -24,11 +25,12 @@ CREATE TABLE IF NOT EXISTS order_updates CREATE TABLE IF NOT EXISTS order_fills ( - id SERIAL PRIMARY KEY, + event_digest TEXT PRIMARY KEY, digest TEXT NOT NULL, sender TEXT NOT NULL, checkpoint BIGINT NOT NULL, timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, + checkpoint_timestamp_ms BIGINT NOT NULL, package TEXT NOT NULL, pool_id TEXT NOT NULL, maker_order_id TEXT NOT NULL, @@ -50,11 +52,12 @@ CREATE TABLE IF NOT EXISTS order_fills CREATE TABLE IF NOT EXISTS flashloans ( - id SERIAL PRIMARY KEY, + event_digest TEXT PRIMARY KEY, digest TEXT NOT NULL, sender TEXT NOT NULL, checkpoint BIGINT NOT NULL, timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, + checkpoint_timestamp_ms BIGINT NOT NULL, package TEXT NOT NULL, borrow BOOLEAN NOT NULL, pool_id TEXT NOT NULL, @@ -64,11 +67,12 @@ CREATE TABLE IF NOT EXISTS flashloans CREATE TABLE IF NOT EXISTS pool_prices ( - id SERIAL PRIMARY KEY, + event_digest TEXT PRIMARY KEY, digest TEXT NOT NULL, sender TEXT NOT NULL, checkpoint BIGINT NOT NULL, timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, + checkpoint_timestamp_ms BIGINT NOT NULL, package TEXT NOT NULL, target_pool TEXT NOT NULL, reference_pool TEXT NOT NULL, @@ -77,11 +81,12 @@ CREATE TABLE IF NOT EXISTS pool_prices CREATE TABLE IF NOT EXISTS balances ( - id SERIAL PRIMARY KEY, + event_digest TEXT PRIMARY KEY, digest TEXT NOT NULL, sender TEXT NOT NULL, checkpoint BIGINT NOT NULL, timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, + checkpoint_timestamp_ms BIGINT NOT NULL, package TEXT NOT NULL, balance_manager_id TEXT NOT NULL, asset TEXT NOT NULL, @@ -91,11 +96,12 @@ CREATE TABLE IF NOT EXISTS balances CREATE TABLE IF NOT EXISTS trade_params_update ( - id SERIAL PRIMARY KEY, + event_digest TEXT PRIMARY KEY, digest TEXT NOT NULL, sender TEXT NOT NULL, checkpoint BIGINT NOT NULL, timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, + checkpoint_timestamp_ms BIGINT NOT NULL, package TEXT NOT NULL, pool_id TEXT NOT NULL, taker_fee BIGINT NOT NULL, @@ -105,11 +111,12 @@ CREATE TABLE IF NOT EXISTS trade_params_update CREATE TABLE IF NOT EXISTS stakes ( - id SERIAL PRIMARY KEY, + event_digest TEXT PRIMARY KEY, digest TEXT NOT NULL, sender TEXT NOT NULL, checkpoint BIGINT NOT NULL, timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, + checkpoint_timestamp_ms BIGINT NOT NULL, package TEXT NOT NULL, pool_id TEXT NOT NULL, balance_manager_id TEXT NOT NULL, @@ -120,11 +127,12 @@ CREATE TABLE IF NOT EXISTS stakes CREATE TABLE IF NOT EXISTS proposals ( - id SERIAL PRIMARY KEY, + event_digest TEXT PRIMARY KEY, digest TEXT NOT NULL, sender TEXT NOT NULL, checkpoint BIGINT NOT NULL, timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, + checkpoint_timestamp_ms BIGINT NOT NULL, package TEXT NOT NULL, pool_id TEXT NOT NULL, balance_manager_id TEXT NOT NULL, @@ -136,11 +144,12 @@ CREATE TABLE IF NOT EXISTS proposals CREATE TABLE IF NOT EXISTS votes ( - id SERIAL PRIMARY KEY, + event_digest TEXT PRIMARY KEY, digest TEXT NOT NULL, sender TEXT NOT NULL, checkpoint BIGINT NOT NULL, timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, + checkpoint_timestamp_ms BIGINT NOT NULL, package TEXT NOT NULL, pool_id TEXT NOT NULL, balance_manager_id TEXT NOT NULL, @@ -152,11 +161,12 @@ CREATE TABLE IF NOT EXISTS votes CREATE TABLE IF NOT EXISTS rebates ( - id SERIAL PRIMARY KEY, + event_digest TEXT PRIMARY KEY, digest TEXT NOT NULL, sender TEXT NOT NULL, checkpoint BIGINT NOT NULL, timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, + checkpoint_timestamp_ms BIGINT NOT NULL, package TEXT NOT NULL, pool_id TEXT NOT NULL, balance_manager_id TEXT NOT NULL, diff --git a/crates/sui-deepbook-indexer/src/models.rs b/crates/sui-deepbook-indexer/src/models.rs index c8a90a6a77ae0..a6e30debcef38 100644 --- a/crates/sui-deepbook-indexer/src/models.rs +++ b/crates/sui-deepbook-indexer/src/models.rs @@ -13,11 +13,13 @@ use crate::schema::{ }; #[derive(Queryable, Selectable, Insertable, Identifiable, Debug)] -#[diesel(table_name = order_updates, primary_key(digest))] +#[diesel(table_name = order_updates, primary_key(event_digest))] pub struct OrderUpdate { + pub event_digest: String, pub digest: String, pub sender: String, pub checkpoint: i64, + pub checkpoint_timestamp_ms: i64, pub package: String, pub status: String, pub pool_id: String, @@ -34,11 +36,13 @@ pub struct OrderUpdate { } #[derive(Queryable, Selectable, Insertable, Identifiable, Debug)] -#[diesel(table_name = order_fills, primary_key(digest))] +#[diesel(table_name = order_fills, primary_key(event_digest))] pub struct OrderFill { + pub event_digest: String, pub digest: String, pub sender: String, pub checkpoint: i64, + pub checkpoint_timestamp_ms: i64, pub package: String, pub pool_id: String, pub maker_order_id: String, // u128 @@ -74,11 +78,13 @@ pub struct BalancesSummary { } #[derive(Queryable, Selectable, Insertable, Identifiable, Debug)] -#[diesel(table_name = flashloans, primary_key(digest))] +#[diesel(table_name = flashloans, primary_key(event_digest))] pub struct Flashloan { + pub event_digest: String, pub digest: String, pub sender: String, pub checkpoint: i64, + pub checkpoint_timestamp_ms: i64, pub package: String, pub pool_id: String, pub borrow_quantity: i64, @@ -87,11 +93,13 @@ pub struct Flashloan { } #[derive(Queryable, Selectable, Insertable, Identifiable, Debug)] -#[diesel(table_name = pool_prices, primary_key(digest))] +#[diesel(table_name = pool_prices, primary_key(event_digest))] pub struct PoolPrice { + pub event_digest: String, pub digest: String, pub sender: String, pub checkpoint: i64, + pub checkpoint_timestamp_ms: i64, pub package: String, pub target_pool: String, pub reference_pool: String, @@ -99,11 +107,13 @@ pub struct PoolPrice { } #[derive(Queryable, Selectable, Insertable, Identifiable, Debug)] -#[diesel(table_name = balances, primary_key(digest))] +#[diesel(table_name = balances, primary_key(event_digest))] pub struct Balances { + pub event_digest: String, pub digest: String, pub sender: String, pub checkpoint: i64, + pub checkpoint_timestamp_ms: i64, pub package: String, pub balance_manager_id: String, pub asset: String, @@ -112,11 +122,13 @@ pub struct Balances { } #[derive(Queryable, Selectable, Insertable, Identifiable, Debug)] -#[diesel(table_name = proposals, primary_key(digest))] +#[diesel(table_name = proposals, primary_key(event_digest))] pub struct Proposals { + pub event_digest: String, pub digest: String, pub sender: String, pub checkpoint: i64, + pub checkpoint_timestamp_ms: i64, pub package: String, pub pool_id: String, pub balance_manager_id: String, @@ -127,11 +139,13 @@ pub struct Proposals { } #[derive(Queryable, Selectable, Insertable, Identifiable, Debug)] -#[diesel(table_name = rebates, primary_key(digest))] +#[diesel(table_name = rebates, primary_key(event_digest))] pub struct Rebates { + pub event_digest: String, pub digest: String, pub sender: String, pub checkpoint: i64, + pub checkpoint_timestamp_ms: i64, pub package: String, pub pool_id: String, pub balance_manager_id: String, @@ -140,11 +154,13 @@ pub struct Rebates { } #[derive(Queryable, Selectable, Insertable, Identifiable, Debug)] -#[diesel(table_name = stakes, primary_key(digest))] +#[diesel(table_name = stakes, primary_key(event_digest))] pub struct Stakes { + pub event_digest: String, pub digest: String, pub sender: String, pub checkpoint: i64, + pub checkpoint_timestamp_ms: i64, pub package: String, pub pool_id: String, pub balance_manager_id: String, @@ -154,11 +170,13 @@ pub struct Stakes { } #[derive(Queryable, Selectable, Insertable, Identifiable, Debug)] -#[diesel(table_name = trade_params_update, primary_key(digest))] +#[diesel(table_name = trade_params_update, primary_key(event_digest))] pub struct TradeParamsUpdate { + pub event_digest: String, pub digest: String, pub sender: String, pub checkpoint: i64, + pub checkpoint_timestamp_ms: i64, pub package: String, pub pool_id: String, pub taker_fee: i64, @@ -167,11 +185,13 @@ pub struct TradeParamsUpdate { } #[derive(Queryable, Selectable, Insertable, Identifiable, Debug)] -#[diesel(table_name = votes, primary_key(digest))] +#[diesel(table_name = votes, primary_key(event_digest))] pub struct Votes { + pub event_digest: String, pub digest: String, pub sender: String, pub checkpoint: i64, + pub checkpoint_timestamp_ms: i64, pub package: String, pub pool_id: String, pub balance_manager_id: String, diff --git a/crates/sui-deepbook-indexer/src/schema.rs b/crates/sui-deepbook-indexer/src/schema.rs index 63680e9868bb9..849dd530c28f7 100644 --- a/crates/sui-deepbook-indexer/src/schema.rs +++ b/crates/sui-deepbook-indexer/src/schema.rs @@ -3,12 +3,13 @@ // @generated automatically by Diesel CLI. diesel::table! { - balances (id) { - id -> Int4, + balances (event_digest) { + event_digest -> Text, digest -> Text, sender -> Text, checkpoint -> Int8, timestamp -> Timestamp, + checkpoint_timestamp_ms -> Int8, package -> Text, balance_manager_id -> Text, asset -> Text, @@ -18,20 +19,13 @@ diesel::table! { } diesel::table! { - balances_summary (asset) { - asset -> Text, - amount -> Int8, - deposit -> Bool, - } -} - -diesel::table! { - flashloans (id) { - id -> Int4, + flashloans (event_digest) { + event_digest -> Text, digest -> Text, sender -> Text, checkpoint -> Int8, timestamp -> Timestamp, + checkpoint_timestamp_ms -> Int8, package -> Text, borrow -> Bool, pool_id -> Text, @@ -41,12 +35,13 @@ diesel::table! { } diesel::table! { - order_fills (id) { - id -> Int4, + order_fills (event_digest) { + event_digest -> Text, digest -> Text, sender -> Text, checkpoint -> Int8, timestamp -> Timestamp, + checkpoint_timestamp_ms -> Int8, package -> Text, pool_id -> Text, maker_order_id -> Text, @@ -68,12 +63,13 @@ diesel::table! { } diesel::table! { - order_updates (id) { - id -> Int4, + order_updates (event_digest) { + event_digest -> Text, digest -> Text, sender -> Text, checkpoint -> Int8, timestamp -> Timestamp, + checkpoint_timestamp_ms -> Int8, package -> Text, status -> Text, pool_id -> Text, @@ -91,12 +87,13 @@ diesel::table! { } diesel::table! { - pool_prices (id) { - id -> Int4, + pool_prices (event_digest) { + event_digest -> Text, digest -> Text, sender -> Text, checkpoint -> Int8, timestamp -> Timestamp, + checkpoint_timestamp_ms -> Int8, package -> Text, target_pool -> Text, reference_pool -> Text, @@ -132,12 +129,13 @@ diesel::table! { } diesel::table! { - proposals (id) { - id -> Int4, + proposals (event_digest) { + event_digest -> Text, digest -> Text, sender -> Text, checkpoint -> Int8, timestamp -> Timestamp, + checkpoint_timestamp_ms -> Int8, package -> Text, pool_id -> Text, balance_manager_id -> Text, @@ -149,12 +147,13 @@ diesel::table! { } diesel::table! { - rebates (id) { - id -> Int4, + rebates (event_digest) { + event_digest -> Text, digest -> Text, sender -> Text, checkpoint -> Int8, timestamp -> Timestamp, + checkpoint_timestamp_ms -> Int8, package -> Text, pool_id -> Text, balance_manager_id -> Text, @@ -164,12 +163,13 @@ diesel::table! { } diesel::table! { - stakes (id) { - id -> Int4, + stakes (event_digest) { + event_digest -> Text, digest -> Text, sender -> Text, checkpoint -> Int8, timestamp -> Timestamp, + checkpoint_timestamp_ms -> Int8, package -> Text, pool_id -> Text, balance_manager_id -> Text, @@ -192,12 +192,13 @@ diesel::table! { } diesel::table! { - trade_params_update (id) { - id -> Int4, + trade_params_update (event_digest) { + event_digest -> Text, digest -> Text, sender -> Text, checkpoint -> Int8, timestamp -> Timestamp, + checkpoint_timestamp_ms -> Int8, package -> Text, pool_id -> Text, taker_fee -> Int8, @@ -207,12 +208,13 @@ diesel::table! { } diesel::table! { - votes (id) { - id -> Int4, + votes (event_digest) { + event_digest -> Text, digest -> Text, sender -> Text, checkpoint -> Int8, timestamp -> Timestamp, + checkpoint_timestamp_ms -> Int8, package -> Text, pool_id -> Text, balance_manager_id -> Text, @@ -238,3 +240,11 @@ diesel::allow_tables_to_appear_in_same_query!( trade_params_update, votes, ); + +diesel::table! { + balances_summary (asset) { + asset -> Text, + amount -> Int8, + deposit -> Bool, + } +} diff --git a/crates/sui-deepbook-indexer/src/sui_deepbook_indexer.rs b/crates/sui-deepbook-indexer/src/sui_deepbook_indexer.rs index f0a81c927649d..0e71f8040ba2a 100644 --- a/crates/sui-deepbook-indexer/src/sui_deepbook_indexer.rs +++ b/crates/sui-deepbook-indexer/src/sui_deepbook_indexer.rs @@ -318,19 +318,23 @@ impl DataMapper for SuiDeepBookDataMapper { match &data.events { Some(events) => { let processed_sui_events = - events.data.iter().try_fold(vec![], |mut result, ev| { - if let Some(data) = process_sui_event( - ev, - &data, - checkpoint_num, - // timestamp_ms, - self.package_id, - )? { - result.push(data); - } - Ok::<_, anyhow::Error>(result) - })?; - + events + .data + .iter() + .enumerate() + .try_fold(vec![], |mut result, (i, ev)| { + if let Some(data) = process_sui_event( + ev, + i, + &data, + checkpoint_num, + timestamp_ms, + self.package_id, + )? { + result.push(data); + } + Ok::<_, anyhow::Error>(result) + })?; if !processed_sui_events.is_empty() { info!( "SUI: Extracted {} deepbook data entries for tx {}.", @@ -367,9 +371,10 @@ impl DataMapper for SuiDeepBookDataMapper { fn process_sui_event( ev: &Event, + event_index: usize, tx: &CheckpointTransaction, checkpoint: u64, - // timestamp_ms: u64, + checkpoint_timestamp_ms: u64, package_id: ObjectID, ) -> Result, anyhow::Error> { Ok(if ev.type_.address == *package_id { @@ -383,10 +388,14 @@ fn process_sui_event( } else { "".to_string() }; + let mut event_digest = tx.transaction.digest().to_string(); + event_digest.push_str(&event_index.to_string()); let txn_data = Some(ProcessedTxnData::OrderUpdate(OrderUpdate { digest: tx.transaction.digest().to_string(), sender: tx.transaction.sender_address().to_string(), + event_digest, checkpoint, + checkpoint_timestamp_ms, package, status: OrderUpdateStatus::Placed, pool_id: move_event.pool_id.to_string(), @@ -414,10 +423,14 @@ fn process_sui_event( } else { "".to_string() }; + let mut event_digest = tx.transaction.digest().to_string(); + event_digest.push_str(&event_index.to_string()); let txn_data = Some(ProcessedTxnData::OrderUpdate(OrderUpdate { digest: tx.transaction.digest().to_string(), + event_digest, sender: tx.transaction.sender_address().to_string(), checkpoint, + checkpoint_timestamp_ms, package, status: OrderUpdateStatus::Modified, pool_id: move_event.pool_id.to_string(), @@ -445,10 +458,14 @@ fn process_sui_event( } else { "".to_string() }; + let mut event_digest = tx.transaction.digest().to_string(); + event_digest.push_str(&event_index.to_string()); let txn_data = Some(ProcessedTxnData::OrderUpdate(OrderUpdate { digest: tx.transaction.digest().to_string(), + event_digest, sender: tx.transaction.sender_address().to_string(), checkpoint, + checkpoint_timestamp_ms, package, status: OrderUpdateStatus::Canceled, pool_id: move_event.pool_id.to_string(), @@ -477,10 +494,14 @@ fn process_sui_event( } else { "".to_string() }; + let mut event_digest = tx.transaction.digest().to_string(); + event_digest.push_str(&event_index.to_string()); let txn_data = Some(ProcessedTxnData::OrderUpdate(OrderUpdate { digest: tx.transaction.digest().to_string(), + event_digest, sender: tx.transaction.sender_address().to_string(), checkpoint, + checkpoint_timestamp_ms, package, status: OrderUpdateStatus::Expired, pool_id: move_event.pool_id.to_string(), @@ -509,10 +530,14 @@ fn process_sui_event( } else { "".to_string() }; + let mut event_digest = tx.transaction.digest().to_string(); + event_digest.push_str(&event_index.to_string()); let txn_data = Some(ProcessedTxnData::OrderFill(OrderFill { digest: tx.transaction.digest().to_string(), + event_digest, sender: tx.transaction.sender_address().to_string(), checkpoint, + checkpoint_timestamp_ms, package, pool_id: move_event.pool_id.to_string(), maker_order_id: move_event.maker_order_id, @@ -544,10 +569,14 @@ fn process_sui_event( } else { "".to_string() }; + let mut event_digest = tx.transaction.digest().to_string(); + event_digest.push_str(&event_index.to_string()); let txn_data = Some(ProcessedTxnData::Flashloan(Flashloan { digest: tx.transaction.digest().to_string(), + event_digest, sender: tx.transaction.sender_address().to_string(), checkpoint, + checkpoint_timestamp_ms, package, pool_id: move_event.pool_id.to_string(), borrow_quantity: move_event.borrow_quantity, @@ -567,10 +596,14 @@ fn process_sui_event( } else { "".to_string() }; + let mut event_digest = tx.transaction.digest().to_string(); + event_digest.push_str(&event_index.to_string()); let txn_data = Some(ProcessedTxnData::PoolPrice(PoolPrice { digest: tx.transaction.digest().to_string(), + event_digest, sender: tx.transaction.sender_address().to_string(), checkpoint, + checkpoint_timestamp_ms, package, target_pool: move_event.target_pool.to_string(), conversion_rate: move_event.conversion_rate, @@ -589,10 +622,14 @@ fn process_sui_event( } else { "".to_string() }; + let mut event_digest = tx.transaction.digest().to_string(); + event_digest.push_str(&event_index.to_string()); let txn_data = Some(ProcessedTxnData::Balances(Balances { digest: tx.transaction.digest().to_string(), + event_digest, sender: tx.transaction.sender_address().to_string(), checkpoint, + checkpoint_timestamp_ms, package, balance_manager_id: move_event.balance_manager_id.to_string(), asset: move_event.asset.to_string(), @@ -612,10 +649,14 @@ fn process_sui_event( } else { "".to_string() }; + let mut event_digest = tx.transaction.digest().to_string(); + event_digest.push_str(&event_index.to_string()); let txn_data = Some(ProcessedTxnData::Proposals(Proposals { digest: tx.transaction.digest().to_string(), + event_digest, sender: tx.transaction.sender_address().to_string(), checkpoint, + checkpoint_timestamp_ms, package, pool_id: move_event.pool_id.to_string(), balance_manager_id: move_event.balance_manager_id.to_string(), @@ -637,10 +678,14 @@ fn process_sui_event( } else { "".to_string() }; + let mut event_digest = tx.transaction.digest().to_string(); + event_digest.push_str(&event_index.to_string()); let txn_data = Some(ProcessedTxnData::Rebates(Rebates { digest: tx.transaction.digest().to_string(), + event_digest, sender: tx.transaction.sender_address().to_string(), checkpoint, + checkpoint_timestamp_ms, package, pool_id: move_event.pool_id.to_string(), balance_manager_id: move_event.balance_manager_id.to_string(), @@ -660,10 +705,14 @@ fn process_sui_event( } else { "".to_string() }; + let mut event_digest = tx.transaction.digest().to_string(); + event_digest.push_str(&event_index.to_string()); let txn_data = Some(ProcessedTxnData::Stakes(Stakes { digest: tx.transaction.digest().to_string(), + event_digest, sender: tx.transaction.sender_address().to_string(), checkpoint, + checkpoint_timestamp_ms, package, pool_id: move_event.pool_id.to_string(), balance_manager_id: move_event.balance_manager_id.to_string(), @@ -684,6 +733,8 @@ fn process_sui_event( } else { "".to_string() }; + let mut event_digest = tx.transaction.digest().to_string(); + event_digest.push_str(&event_index.to_string()); let shared_objects = &tx.input_objects; let mut pool_id = "0x0".to_string(); for obj in shared_objects.iter() { @@ -698,8 +749,10 @@ fn process_sui_event( } let txn_data = Some(ProcessedTxnData::TradeParamsUpdate(TradeParamsUpdate { digest: tx.transaction.digest().to_string(), + event_digest, sender: tx.transaction.sender_address().to_string(), checkpoint, + checkpoint_timestamp_ms, package, pool_id, taker_fee: move_event.taker_fee, @@ -719,10 +772,14 @@ fn process_sui_event( } else { "".to_string() }; + let mut event_digest = tx.transaction.digest().to_string(); + event_digest.push_str(&event_index.to_string()); let txn_data = Some(ProcessedTxnData::Votes(Votes { digest: tx.transaction.digest().to_string(), + event_digest, sender: tx.transaction.sender_address().to_string(), checkpoint, + checkpoint_timestamp_ms, package, pool_id: move_event.pool_id.to_string(), balance_manager_id: move_event.balance_manager_id.to_string(), diff --git a/crates/sui-deepbook-indexer/src/types.rs b/crates/sui-deepbook-indexer/src/types.rs index e24005ca635ab..c17fbe01dc7af 100644 --- a/crates/sui-deepbook-indexer/src/types.rs +++ b/crates/sui-deepbook-indexer/src/types.rs @@ -55,9 +55,11 @@ impl Display for OrderUpdateStatus { #[derive(Clone, Debug)] pub struct OrderUpdate { - pub(crate) digest: String, + pub digest: String, + pub(crate) event_digest: String, pub(crate) sender: String, pub(crate) checkpoint: u64, + pub(crate) checkpoint_timestamp_ms: u64, pub(crate) package: String, pub(crate) status: OrderUpdateStatus, pub(crate) pool_id: String, @@ -77,8 +79,10 @@ impl OrderUpdate { pub(crate) fn to_db(&self) -> DBOrderUpdate { DBOrderUpdate { digest: self.digest.clone(), + event_digest: self.event_digest.clone(), sender: self.sender.clone(), checkpoint: self.checkpoint as i64, + checkpoint_timestamp_ms: self.checkpoint_timestamp_ms as i64, package: self.package.clone(), status: self.status.clone().to_string(), pool_id: self.pool_id.clone(), @@ -99,8 +103,10 @@ impl OrderUpdate { #[derive(Clone, Debug)] pub struct OrderFill { pub(crate) digest: String, + pub(crate) event_digest: String, pub(crate) sender: String, pub(crate) checkpoint: u64, + pub(crate) checkpoint_timestamp_ms: u64, pub(crate) package: String, pub(crate) pool_id: String, pub(crate) maker_order_id: u128, @@ -124,8 +130,10 @@ impl OrderFill { pub(crate) fn to_db(&self) -> DBOrderFill { DBOrderFill { digest: self.digest.clone(), + event_digest: self.event_digest.clone(), sender: self.sender.clone(), checkpoint: self.checkpoint as i64, + checkpoint_timestamp_ms: self.checkpoint_timestamp_ms as i64, package: self.package.clone(), pool_id: self.pool_id.clone(), maker_order_id: BigDecimal::from(self.maker_order_id).to_string(), @@ -150,8 +158,10 @@ impl OrderFill { #[derive(Clone, Debug)] pub struct Flashloan { pub(crate) digest: String, + pub(crate) event_digest: String, pub(crate) sender: String, pub(crate) checkpoint: u64, + pub(crate) checkpoint_timestamp_ms: u64, pub(crate) package: String, pub(crate) borrow: bool, pub(crate) pool_id: String, @@ -163,8 +173,10 @@ impl Flashloan { pub(crate) fn to_db(&self) -> DBFlashloan { DBFlashloan { digest: self.digest.clone(), + event_digest: self.event_digest.clone(), sender: self.sender.clone(), checkpoint: self.checkpoint as i64, + checkpoint_timestamp_ms: self.checkpoint_timestamp_ms as i64, package: self.package.clone(), borrow: self.borrow, pool_id: self.pool_id.clone(), @@ -177,8 +189,10 @@ impl Flashloan { #[derive(Clone, Debug)] pub struct PoolPrice { pub(crate) digest: String, + pub(crate) event_digest: String, pub(crate) sender: String, pub(crate) checkpoint: u64, + pub(crate) checkpoint_timestamp_ms: u64, pub(crate) package: String, pub(crate) target_pool: String, pub(crate) reference_pool: String, @@ -189,8 +203,10 @@ impl PoolPrice { pub(crate) fn to_db(&self) -> DBPoolPrice { DBPoolPrice { digest: self.digest.clone(), + event_digest: self.event_digest.clone(), sender: self.sender.clone(), checkpoint: self.checkpoint as i64, + checkpoint_timestamp_ms: self.checkpoint_timestamp_ms as i64, package: self.package.clone(), target_pool: self.target_pool.clone(), reference_pool: self.reference_pool.clone(), @@ -201,22 +217,26 @@ impl PoolPrice { #[derive(Clone, Debug)] pub struct Balances { - pub digest: String, - pub sender: String, - pub checkpoint: u64, - pub package: String, - pub balance_manager_id: String, - pub asset: String, - pub amount: u64, - pub deposit: bool, + pub(crate) digest: String, + pub(crate) event_digest: String, + pub(crate) sender: String, + pub(crate) checkpoint: u64, + pub(crate) checkpoint_timestamp_ms: u64, + pub(crate) package: String, + pub(crate) balance_manager_id: String, + pub(crate) asset: String, + pub(crate) amount: u64, + pub(crate) deposit: bool, } impl Balances { pub(crate) fn to_db(&self) -> DBBalances { DBBalances { digest: self.digest.clone(), + event_digest: self.event_digest.clone(), sender: self.sender.clone(), checkpoint: self.checkpoint as i64, + checkpoint_timestamp_ms: self.checkpoint_timestamp_ms as i64, package: self.package.clone(), balance_manager_id: self.balance_manager_id.clone(), asset: self.asset.clone(), @@ -229,8 +249,10 @@ impl Balances { #[derive(Clone, Debug)] pub struct Proposals { pub(crate) digest: String, + pub(crate) event_digest: String, pub(crate) sender: String, pub(crate) checkpoint: u64, + pub(crate) checkpoint_timestamp_ms: u64, pub(crate) package: String, pub(crate) pool_id: String, pub(crate) balance_manager_id: String, @@ -244,8 +266,10 @@ impl Proposals { pub(crate) fn to_db(&self) -> DBProposals { DBProposals { digest: self.digest.clone(), + event_digest: self.event_digest.clone(), sender: self.sender.clone(), checkpoint: self.checkpoint as i64, + checkpoint_timestamp_ms: self.checkpoint_timestamp_ms as i64, package: self.package.clone(), pool_id: self.pool_id.clone(), balance_manager_id: self.balance_manager_id.clone(), @@ -260,8 +284,10 @@ impl Proposals { #[derive(Clone, Debug)] pub struct Rebates { pub(crate) digest: String, + pub(crate) event_digest: String, pub(crate) sender: String, pub(crate) checkpoint: u64, + pub(crate) checkpoint_timestamp_ms: u64, pub(crate) package: String, pub(crate) pool_id: String, pub(crate) balance_manager_id: String, @@ -273,8 +299,10 @@ impl Rebates { pub(crate) fn to_db(&self) -> DBRebates { DBRebates { digest: self.digest.clone(), + event_digest: self.event_digest.clone(), sender: self.sender.clone(), checkpoint: self.checkpoint as i64, + checkpoint_timestamp_ms: self.checkpoint_timestamp_ms as i64, package: self.package.clone(), pool_id: self.pool_id.clone(), balance_manager_id: self.balance_manager_id.clone(), @@ -287,8 +315,10 @@ impl Rebates { #[derive(Clone, Debug)] pub struct Stakes { pub(crate) digest: String, + pub(crate) event_digest: String, pub(crate) sender: String, pub(crate) checkpoint: u64, + pub(crate) checkpoint_timestamp_ms: u64, pub(crate) package: String, pub(crate) pool_id: String, pub(crate) balance_manager_id: String, @@ -301,8 +331,10 @@ impl Stakes { pub(crate) fn to_db(&self) -> DBStakes { DBStakes { digest: self.digest.clone(), + event_digest: self.event_digest.clone(), sender: self.sender.clone(), checkpoint: self.checkpoint as i64, + checkpoint_timestamp_ms: self.checkpoint_timestamp_ms as i64, package: self.package.clone(), pool_id: self.pool_id.clone(), balance_manager_id: self.balance_manager_id.clone(), @@ -316,8 +348,10 @@ impl Stakes { #[derive(Clone, Debug)] pub struct TradeParamsUpdate { pub(crate) digest: String, + pub(crate) event_digest: String, pub(crate) sender: String, pub(crate) checkpoint: u64, + pub(crate) checkpoint_timestamp_ms: u64, pub(crate) package: String, pub(crate) pool_id: String, pub(crate) taker_fee: u64, @@ -329,8 +363,10 @@ impl TradeParamsUpdate { pub(crate) fn to_db(&self) -> DBTradeParamsUpdate { DBTradeParamsUpdate { digest: self.digest.clone(), + event_digest: self.event_digest.clone(), sender: self.sender.clone(), checkpoint: self.checkpoint as i64, + checkpoint_timestamp_ms: self.checkpoint_timestamp_ms as i64, package: self.package.clone(), pool_id: self.pool_id.clone(), taker_fee: self.taker_fee as i64, @@ -343,8 +379,10 @@ impl TradeParamsUpdate { #[derive(Clone, Debug)] pub struct Votes { pub(crate) digest: String, + pub(crate) event_digest: String, pub(crate) sender: String, pub(crate) checkpoint: u64, + pub(crate) checkpoint_timestamp_ms: u64, pub(crate) package: String, pub(crate) pool_id: String, pub(crate) balance_manager_id: String, @@ -358,8 +396,10 @@ impl Votes { pub(crate) fn to_db(&self) -> DBVotes { DBVotes { digest: self.digest.clone(), + event_digest: self.event_digest.clone(), sender: self.sender.clone(), checkpoint: self.checkpoint as i64, + checkpoint_timestamp_ms: self.checkpoint_timestamp_ms as i64, package: self.package.clone(), pool_id: self.pool_id.clone(), balance_manager_id: self.balance_manager_id.clone(),