Skip to content

Commit

Permalink
Merge pull request #67 from CapCap/max_emojicoin_dexscreener
Browse files Browse the repository at this point in the history
Dexscreener Emojicoin Support
  • Loading branch information
CRBl69 authored Dec 9, 2024
2 parents de5d38e + d7a1454 commit f09cb58
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 7 deletions.
24 changes: 21 additions & 3 deletions rust/processor/src/db/common/models/emojicoin_models/json_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use anyhow::{Context, Result};
use aptos_protos::transaction::v1::WriteResource;
use bigdecimal::BigDecimal;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::str::FromStr;

pub fn serialize_bytes_to_hex_string<S>(element: &Vec<u8>, s: S) -> Result<S::Ok, S::Error>
where
Expand Down Expand Up @@ -204,6 +205,9 @@ pub struct LastSwap {

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct SwapEvent {
#[serde(deserialize_with = "deserialize_from_string")]
#[serde(serialize_with = "serialize_to_string")]
pub event_index: i64,
#[serde(deserialize_with = "deserialize_from_string")]
#[serde(serialize_with = "serialize_to_string")]
pub market_id: i64,
Expand Down Expand Up @@ -383,6 +387,9 @@ pub struct GlobalStateEvent {

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct LiquidityEvent {
#[serde(deserialize_with = "deserialize_from_string")]
#[serde(serialize_with = "serialize_to_string")]
pub event_index: i64,
#[serde(deserialize_with = "deserialize_from_string")]
#[serde(serialize_with = "serialize_to_string")]
pub market_id: i64,
Expand Down Expand Up @@ -435,7 +442,12 @@ impl From<StateEvent> for EventWithMarket {
}

impl EventWithMarket {
pub fn from_event_type(event_type: &str, data: &str, txn_version: i64) -> Result<Option<Self>> {
pub fn from_event_type(
event_type: &str,
data: &str,
txn_version: i64,
sequence_number: i64,
) -> Result<Option<Self>> {
match EmojicoinTypeTag::from_type_str(event_type) {
Some(EmojicoinTypeTag::PeriodicState) => {
serde_json::from_str(data).map(|inner| Some(Self::PeriodicState(inner)))
Expand All @@ -444,7 +456,9 @@ impl EventWithMarket {
serde_json::from_str(data).map(|inner| Some(Self::State(inner)))
},
Some(EmojicoinTypeTag::Swap) => {
serde_json::from_str(data).map(|inner| Some(Self::Swap(inner)))
let mut json_data = serde_json::Value::from_str(data)?;
json_data["event_index"] = serde_json::Value::from(sequence_number.to_string());
serde_json::from_value(json_data).map(|inner: SwapEvent| Some(Self::Swap(inner)))
},
Some(EmojicoinTypeTag::Chat) => {
serde_json::from_str(data).map(|inner| Some(Self::Chat(inner)))
Expand All @@ -453,7 +467,10 @@ impl EventWithMarket {
serde_json::from_str(data).map(|inner| Some(Self::MarketRegistration(inner)))
},
Some(EmojicoinTypeTag::Liquidity) => {
serde_json::from_str(data).map(|inner| Some(Self::Liquidity(inner)))
let mut json_data = serde_json::Value::from_str(data)?;
json_data["event_index"] = serde_json::Value::from(sequence_number.to_string());
serde_json::from_value(json_data)
.map(|inner: LiquidityEvent| Some(Self::Liquidity(inner)))
},
_ => Ok(None),
}
Expand Down Expand Up @@ -493,6 +510,7 @@ pub enum BumpEvent {
// A subset of the transaction info that comes in from the GRPC stream.
#[derive(Debug, Clone)]
pub struct TxnInfo {
pub block_number: i64,
pub version: i64,
pub sender: String,
pub entry_function: Option<String>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ use serde::{Deserialize, Serialize};
#[diesel(table_name = liquidity_events)]
pub struct LiquidityEventModel {
// Transaction metadata.
pub block_number: i64,
pub transaction_version: i64,
pub event_index: i64,
pub sender: String,
pub entry_function: Option<String>,
pub transaction_timestamp: chrono::NaiveDateTime,
Expand Down Expand Up @@ -93,12 +95,15 @@ impl LiquidityEventModel {
liquidity_provided,
base_donation_claim_amount,
quote_donation_claim_amount,
event_index,
..
} = liquidity_event;

LiquidityEventModel {
// Transaction metadata.
block_number: txn_info.block_number,
transaction_version: txn_info.version,
event_index,
sender: txn_info.sender.clone(),
entry_function: txn_info.entry_function.clone(),
transaction_timestamp: txn_info.timestamp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ use serde::{Deserialize, Serialize};
#[diesel(table_name = swap_events)]
pub struct SwapEventModel {
// Transaction metadata.
pub block_number: i64,
pub transaction_version: i64,
pub event_index: i64,
pub sender: String,
pub entry_function: Option<String>,
pub transaction_timestamp: chrono::NaiveDateTime,
Expand Down Expand Up @@ -84,6 +86,7 @@ impl SwapEventModel {
} = state_event;

let SwapEvent {
event_index,
market_id,
market_nonce,
swapper,
Expand All @@ -107,7 +110,9 @@ impl SwapEventModel {

SwapEventModel {
// Transaction metadata.
block_number: txn_info.block_number,
transaction_version: txn_info.version,
event_index,
sender: txn_info.sender.clone(),
entry_function: txn_info.entry_function.clone(),
transaction_timestamp: txn_info.timestamp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ use once_cell::sync::Lazy;
use regex::Regex;
use serde::{Deserialize, Serialize};

static ADDRESSES_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new("^0x0*1::coin::CoinStore<(0x[^:]*)::coin_factory::EmojicoinLP>$").unwrap()
});

#[derive(Clone, Debug, Deserialize, FieldCount, Identifiable, Insertable, Serialize)]
#[diesel(primary_key(provider, market_nonce))]
#[diesel(table_name = user_liquidity_pools)]
Expand Down Expand Up @@ -45,9 +49,6 @@ impl UserLiquidityPoolsModel {
evt: LiquidityEventModel,
market_address: &str,
) -> Self {
static ADDRESSES_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new("^0x0*1::coin::CoinStore<(0x[^:]*)::coin_factory::EmojicoinLP>$").unwrap()
});
txn.info
.as_ref()
.expect("Transaction info should exist.")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- This file should undo anything in `up.sql`

DROP INDEX IF EXISTS se_block_num;
ALTER TABLE swap_events
DROP COLUMN block_number,
DROP COLUMN event_index;

DROP INDEX IF EXISTS le_block_num;
ALTER TABLE liquidity_events
DROP COLUMN block_number,
DROP COLUMN event_index;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- Your SQL goes here
ALTER TABLE swap_events
ADD COLUMN block_number BIGINT NOT NULL,
ADD COLUMN event_index BIGINT NOT NULL;
CREATE INDEX se_block_num ON swap_events (block_number);

ALTER TABLE liquidity_events
ADD COLUMN block_number BIGINT NOT NULL,
ADD COLUMN event_index BIGINT NOT NULL;
CREATE INDEX le_block_num ON liquidity_events (block_number);
4 changes: 4 additions & 0 deletions rust/processor/src/db/postgres/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,8 @@ diesel::table! {
last_swap_quote_volume -> Int8,
last_swap_nonce -> Int8,
last_swap_time -> Timestamp,
block_number -> Int8,
event_index -> Int8,
}
}

Expand Down Expand Up @@ -1313,6 +1315,8 @@ diesel::table! {
instantaneous_stats_fully_diluted_value -> Numeric,
balance_as_fraction_of_circulating_supply_before_q64 -> Numeric,
balance_as_fraction_of_circulating_supply_after_q64 -> Numeric,
block_number -> Int8,
event_index -> Int8,
}
}

Expand Down
9 changes: 8 additions & 1 deletion rust/processor/src/processors/emojicoin_dot_fun/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ impl ProcessorTrait for EmojicoinProcessor {
let mut user_pools_db: AHashMap<(String, i64), UserLiquidityPoolsModel> = AHashMap::new();
for txn in &transactions {
let txn_version = txn.version as i64;
let block_number = txn.block_height as i64;
let txn_data = match txn.txn_data.as_ref() {
Some(data) => data,
None => {
Expand All @@ -259,6 +260,7 @@ impl ProcessorTrait for EmojicoinProcessor {
.expect("User request info is not present in the user transaction.");
let entry_function = get_entry_function_from_user_request(user_request);
let txn_info = TxnInfo {
block_number,
version: txn_version,
sender: standardize_address(user_request.sender.as_ref()),
entry_function,
Expand All @@ -271,7 +273,12 @@ impl ProcessorTrait for EmojicoinProcessor {
let type_str = event.type_str.as_str();
let data = event.data.as_str();

match EventWithMarket::from_event_type(type_str, data, txn_version)? {
match EventWithMarket::from_event_type(
type_str,
data,
txn_version,
event.sequence_number as i64,
)? {
Some(evt) => {
market_events.push(evt.clone());
if let Some(one_min_pse) =
Expand Down

0 comments on commit f09cb58

Please sign in to comment.