From 4af98d89d851f9a17e436f85637f6280a010adca Mon Sep 17 00:00:00 2001 From: Aaron Date: Wed, 15 May 2024 18:12:08 -0600 Subject: [PATCH] [event_v2] indexer logic update to handle migration (#360) * [event_v2] an example code for event v2 migration * event v2 indexing. --------- Co-authored-by: Larry Liu --- .../nft_orderbooks/parsers/okx_parser.py | 14 +- rust/Cargo.toml | 2 +- .../models/coin_models/coin_activities.rs | 53 ++++-- .../common/models/coin_models/coin_utils.rs | 24 +++ .../parquet_v2_fungible_asset_activities.rs | 10 ++ .../v2_fungible_asset_activities.rs | 10 ++ .../models/stake_models/proposal_votes.rs | 2 +- .../common/models/stake_models/stake_utils.rs | 17 +- .../models/token_models/token_activities.rs | 72 ++++++++ .../common/models/token_models/token_utils.rs | 157 ++++++++++++++++++ .../token_v2_models/v2_token_activities.rs | 56 +++++++ .../models/token_v2_models/v2_token_utils.rs | 14 +- .../src/processors/token_v2_processor.rs | 62 +++---- 13 files changed, 436 insertions(+), 57 deletions(-) diff --git a/python/processors/nft_orderbooks/parsers/okx_parser.py b/python/processors/nft_orderbooks/parsers/okx_parser.py index bb26d4553..5f9c3154b 100644 --- a/python/processors/nft_orderbooks/parsers/okx_parser.py +++ b/python/processors/nft_orderbooks/parsers/okx_parser.py @@ -19,6 +19,8 @@ "okx_listing_utils::CancelListingEvent", ] ) +DEPOSIT_EVENT_V1 = "0x3::token::DepositEvent" +DEPOSIT_EVENT_V2 = "0x3::token::Deposit" def parse_marketplace_events( @@ -141,8 +143,16 @@ def parse_marketplace_events( def get_token_data_from_deposit_events(user_transaction) -> Dict[str, TokenDataIdType]: # Extract deposit events, which contain token metadata deposit_events: Dict[str, TokenDataIdType] = {} - for event in user_transaction.events: - if event.type_str != "0x3::token::DepositEvent": + for idx, event in enumerate(user_transaction.events): + if event.type_str != DEPOSIT_EVENT_V1 and event.type_str != DEPOSIT_EVENT_V2: + continue + # Current event is either DEPOSIT_EVENT_V1 or DEPOSIT_EVENT_V2. + if ( + idx > 0 + # skip if prior event is V2 deposit event. + and user_transaction.events[idx - 1].type_str == DEPOSIT_EVENT_V2 + and event.type_str == DEPOSIT_EVENT_V1 + ): continue account_address = standardize_address(event_utils.get_account_address(event)) data = json.loads(event.data) diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 523c8aa72..5c3b50957 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -77,7 +77,6 @@ google-cloud-googleapis = "0.10.0" google-cloud-pubsub = "0.18.0" hex = "0.4.3" itertools = "0.12.1" -lazy_static = "1.4.0" jemallocator = { version = "0.5.0", features = [ "profiling", "unprefixed_malloc_on_supported_platforms", @@ -85,6 +84,7 @@ jemallocator = { version = "0.5.0", features = [ json-structural-diff = "0.1.0" assert-json-diff = "2.0.2" kanal = { version = "0.1.0-pre8", features = ["async"] } +lazy_static = "1.4.0" once_cell = "1.10.0" num_cpus = "1.16.0" pbjson = "0.5.1" diff --git a/rust/processor/src/db/common/models/coin_models/coin_activities.rs b/rust/processor/src/db/common/models/coin_models/coin_activities.rs index 674252f81..5130e23cb 100644 --- a/rust/processor/src/db/common/models/coin_models/coin_activities.rs +++ b/rust/processor/src/db/common/models/coin_models/coin_activities.rs @@ -228,23 +228,44 @@ impl CoinActivity { transaction_timestamp: chrono::NaiveDateTime, event_index: i64, ) -> Self { - let amount = match coin_event { - CoinEvent::WithdrawCoinEvent(inner) => inner.amount.clone(), - CoinEvent::DepositCoinEvent(inner) => inner.amount.clone(), - }; - let event_move_guid = EventGuidResource { - addr: standardize_address(event.key.as_ref().unwrap().account_address.as_str()), - creation_num: event.key.as_ref().unwrap().creation_number as i64, + let (owner_address, amount, coin_type_option) = match coin_event { + CoinEvent::WithdrawCoinEvent(inner) => ( + standardize_address(&event.key.as_ref().unwrap().account_address), + inner.amount.clone(), + None, + ), + CoinEvent::DepositCoinEvent(inner) => ( + standardize_address(&event.key.as_ref().unwrap().account_address), + inner.amount.clone(), + None, + ), + CoinEvent::WithdrawCoinEventV2(inner) => ( + standardize_address(&inner.account), + inner.amount.clone(), + Some(inner.coin_type.clone()), + ), + CoinEvent::DepositCoinEventV2(inner) => ( + standardize_address(&inner.account), + inner.amount.clone(), + Some(inner.coin_type.clone()), + ), }; - let coin_type = + let coin_type = if let Some(coin_type) = coin_type_option { + coin_type + } else { + let event_move_guid = EventGuidResource { + addr: standardize_address(event.key.as_ref().unwrap().account_address.as_str()), + creation_num: event.key.as_ref().unwrap().creation_number as i64, + }; event_to_coin_type - .get(&event_move_guid) - .unwrap_or_else(|| { - panic!( - "Could not find event in resources (CoinStore), version: {}, event guid: {:?}, mapping: {:?}", - txn_version, event_move_guid, event_to_coin_type - ) - }).clone(); + .get(&event_move_guid) + .unwrap_or_else(|| { + panic!( + "Could not find event in resources (CoinStore), version: {}, event guid: {:?}, mapping: {:?}", + txn_version, event_move_guid, event_to_coin_type + ) + }).clone() + }; Self { transaction_version: txn_version, @@ -253,7 +274,7 @@ impl CoinActivity { ), event_creation_number: event.key.as_ref().unwrap().creation_number as i64, event_sequence_number: event.sequence_number as i64, - owner_address: standardize_address(&event.key.as_ref().unwrap().account_address), + owner_address, coin_type, amount, activity_type: event_type.to_string(), diff --git a/rust/processor/src/db/common/models/coin_models/coin_utils.rs b/rust/processor/src/db/common/models/coin_models/coin_utils.rs index aeed74d2d..adcb73885 100644 --- a/rust/processor/src/db/common/models/coin_models/coin_utils.rs +++ b/rust/processor/src/db/common/models/coin_models/coin_utils.rs @@ -151,6 +151,22 @@ pub struct DepositCoinEvent { pub amount: BigDecimal, } +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct WithdrawCoinEventV2 { + pub coin_type: String, + pub account: String, + #[serde(deserialize_with = "deserialize_from_string")] + pub amount: BigDecimal, +} + +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct DepositCoinEventV2 { + pub coin_type: String, + pub account: String, + #[serde(deserialize_with = "deserialize_from_string")] + pub amount: BigDecimal, +} + pub struct CoinInfoType { coin_type: String, creator_address: String, @@ -319,6 +335,8 @@ impl CoinResource { pub enum CoinEvent { WithdrawCoinEvent(WithdrawCoinEvent), DepositCoinEvent(DepositCoinEvent), + WithdrawCoinEventV2(WithdrawCoinEventV2), + DepositCoinEventV2(DepositCoinEventV2), } impl CoinEvent { @@ -330,6 +348,12 @@ impl CoinEvent { "0x1::coin::DepositEvent" => { serde_json::from_str(data).map(|inner| Some(CoinEvent::DepositCoinEvent(inner))) }, + "0x1::coin::CoinWithdraw" => { + serde_json::from_str(data).map(|inner| Some(CoinEvent::WithdrawCoinEventV2(inner))) + }, + "0x1::coin::CoinDeposit" => { + serde_json::from_str(data).map(|inner| Some(CoinEvent::DepositCoinEventV2(inner))) + }, _ => Ok(None), } .context(format!( diff --git a/rust/processor/src/db/common/models/fungible_asset_models/parquet_v2_fungible_asset_activities.rs b/rust/processor/src/db/common/models/fungible_asset_models/parquet_v2_fungible_asset_activities.rs index 922db71f7..2d054b7e7 100644 --- a/rust/processor/src/db/common/models/fungible_asset_models/parquet_v2_fungible_asset_activities.rs +++ b/rust/processor/src/db/common/models/fungible_asset_models/parquet_v2_fungible_asset_activities.rs @@ -180,6 +180,16 @@ impl FungibleAssetActivity { inner.amount.to_string(), None, ), + CoinEvent::WithdrawCoinEventV2(inner) => ( + standardize_address(&inner.account), + inner.amount.to_string(), + Some(inner.coin_type.clone()), + ), + CoinEvent::DepositCoinEventV2(inner) => ( + standardize_address(&inner.account), + inner.amount.to_string(), + Some(inner.coin_type.clone()), + ), }; let coin_type = if let Some(coin_type) = coin_type_option { coin_type diff --git a/rust/processor/src/db/common/models/fungible_asset_models/v2_fungible_asset_activities.rs b/rust/processor/src/db/common/models/fungible_asset_models/v2_fungible_asset_activities.rs index 29e625c52..656e1ca52 100644 --- a/rust/processor/src/db/common/models/fungible_asset_models/v2_fungible_asset_activities.rs +++ b/rust/processor/src/db/common/models/fungible_asset_models/v2_fungible_asset_activities.rs @@ -162,6 +162,16 @@ impl FungibleAssetActivity { inner.amount.clone(), None, ), + CoinEvent::WithdrawCoinEventV2(inner) => ( + standardize_address(&inner.account), + inner.amount.clone(), + Some(inner.coin_type.clone()), + ), + CoinEvent::DepositCoinEventV2(inner) => ( + standardize_address(&inner.account), + inner.amount.clone(), + Some(inner.coin_type.clone()), + ), }; let coin_type = if let Some(coin_type) = coin_type_option { coin_type diff --git a/rust/processor/src/db/common/models/stake_models/proposal_votes.rs b/rust/processor/src/db/common/models/stake_models/proposal_votes.rs index ebe473e0c..0540afb5e 100644 --- a/rust/processor/src/db/common/models/stake_models/proposal_votes.rs +++ b/rust/processor/src/db/common/models/stake_models/proposal_votes.rs @@ -49,7 +49,7 @@ impl ProposalVote { let txn_version = transaction.version as i64; if let TxnData::User(user_txn) = txn_data { - for event in &user_txn.events { + for event in user_txn.events.iter() { if let Some(StakeEvent::GovernanceVoteEvent(ev)) = StakeEvent::from_event(event.type_str.as_str(), &event.data, txn_version)? { diff --git a/rust/processor/src/db/common/models/stake_models/stake_utils.rs b/rust/processor/src/db/common/models/stake_models/stake_utils.rs index f623d3ffb..eed532907 100644 --- a/rust/processor/src/db/common/models/stake_models/stake_utils.rs +++ b/rust/processor/src/db/common/models/stake_models/stake_utils.rs @@ -200,21 +200,24 @@ pub enum StakeEvent { impl StakeEvent { pub fn from_event(data_type: &str, data: &str, txn_version: i64) -> Result> { match data_type { - "0x1::aptos_governance::VoteEvent" => { + "0x1::aptos_governance::VoteEvent" | "0x1::aptos_governance::Vote" => { serde_json::from_str(data).map(|inner| Some(StakeEvent::GovernanceVoteEvent(inner))) }, - "0x1::stake::DistributeRewardsEvent" => serde_json::from_str(data) - .map(|inner| Some(StakeEvent::DistributeRewardsEvent(inner))), - "0x1::delegation_pool::AddStakeEvent" => { + "0x1::stake::DistributeRewardsEvent" | "0x1::stake::DistributeRewards" => { + serde_json::from_str(data) + .map(|inner| Some(StakeEvent::DistributeRewardsEvent(inner))) + }, + "0x1::delegation_pool::AddStakeEvent" | "0x1::delegation_pool::AddStake" => { serde_json::from_str(data).map(|inner| Some(StakeEvent::AddStakeEvent(inner))) }, - "0x1::delegation_pool::UnlockStakeEvent" => { + "0x1::delegation_pool::UnlockStakeEvent" | "0x1::delegation_pool::UnlockStake" => { serde_json::from_str(data).map(|inner| Some(StakeEvent::UnlockStakeEvent(inner))) }, - "0x1::delegation_pool::WithdrawStakeEvent" => { + "0x1::delegation_pool::WithdrawStakeEvent" | "0x1::delegation_pool::WithdrawStake" => { serde_json::from_str(data).map(|inner| Some(StakeEvent::WithdrawStakeEvent(inner))) }, - "0x1::delegation_pool::ReactivateStakeEvent" => serde_json::from_str(data) + "0x1::delegation_pool::ReactivateStakeEvent" + | "0x1::delegation_pool::ReactivateStake" => serde_json::from_str(data) .map(|inner| Some(StakeEvent::ReactivateStakeEvent(inner))), _ => Ok(None), } diff --git a/rust/processor/src/db/common/models/token_models/token_activities.rs b/rust/processor/src/db/common/models/token_models/token_activities.rs index 638738f14..cf2da00ac 100644 --- a/rust/processor/src/db/common/models/token_models/token_activities.rs +++ b/rust/processor/src/db/common/models/token_models/token_activities.rs @@ -120,6 +120,15 @@ impl TokenActivity { coin_type: None, coin_amount: None, }, + TokenEvent::Mint(inner) => TokenActivityHelper { + token_data_id: &inner.id, + property_version: BigDecimal::zero(), + from_address: Some(inner.get_account()), + to_address: None, + token_amount: inner.amount.clone(), + coin_type: None, + coin_amount: None, + }, TokenEvent::BurnTokenEvent(inner) => TokenActivityHelper { token_data_id: &inner.id.token_data_id, property_version: inner.id.property_version.clone(), @@ -129,6 +138,15 @@ impl TokenActivity { coin_type: None, coin_amount: None, }, + TokenEvent::Burn(inner) => TokenActivityHelper { + token_data_id: &inner.id.token_data_id, + property_version: inner.id.property_version.clone(), + from_address: Some(inner.get_account()), + to_address: None, + token_amount: inner.amount.clone(), + coin_type: None, + coin_amount: None, + }, TokenEvent::MutateTokenPropertyMapEvent(inner) => TokenActivityHelper { token_data_id: &inner.new_id.token_data_id, property_version: inner.new_id.property_version.clone(), @@ -138,6 +156,15 @@ impl TokenActivity { coin_type: None, coin_amount: None, }, + TokenEvent::MutatePropertyMap(inner) => TokenActivityHelper { + token_data_id: &inner.new_id.token_data_id, + property_version: inner.new_id.property_version.clone(), + from_address: Some(inner.get_account()), + to_address: None, + token_amount: BigDecimal::zero(), + coin_type: None, + coin_amount: None, + }, TokenEvent::WithdrawTokenEvent(inner) => TokenActivityHelper { token_data_id: &inner.id.token_data_id, property_version: inner.id.property_version.clone(), @@ -147,6 +174,15 @@ impl TokenActivity { coin_type: None, coin_amount: None, }, + TokenEvent::TokenWithdraw(inner) => TokenActivityHelper { + token_data_id: &inner.id.token_data_id, + property_version: inner.id.property_version.clone(), + from_address: Some(inner.get_account()), + to_address: None, + token_amount: inner.amount.clone(), + coin_type: None, + coin_amount: None, + }, TokenEvent::DepositTokenEvent(inner) => TokenActivityHelper { token_data_id: &inner.id.token_data_id, property_version: inner.id.property_version.clone(), @@ -156,6 +192,15 @@ impl TokenActivity { coin_type: None, coin_amount: None, }, + TokenEvent::TokenDeposit(inner) => TokenActivityHelper { + token_data_id: &inner.id.token_data_id, + property_version: inner.id.property_version.clone(), + from_address: None, + to_address: Some(inner.get_account()), + token_amount: inner.amount.clone(), + coin_type: None, + coin_amount: None, + }, TokenEvent::OfferTokenEvent(inner) => TokenActivityHelper { token_data_id: &inner.token_id.token_data_id, property_version: inner.token_id.property_version.clone(), @@ -183,6 +228,33 @@ impl TokenActivity { coin_type: None, coin_amount: None, }, + TokenEvent::Offer(inner) => TokenActivityHelper { + token_data_id: &inner.token_id.token_data_id, + property_version: inner.token_id.property_version.clone(), + from_address: Some(inner.get_from_address()), + to_address: Some(inner.get_to_address()), + token_amount: inner.amount.clone(), + coin_type: None, + coin_amount: None, + }, + TokenEvent::CancelOffer(inner) => TokenActivityHelper { + token_data_id: &inner.token_id.token_data_id, + property_version: inner.token_id.property_version.clone(), + from_address: Some(inner.get_from_address()), + to_address: Some(inner.get_to_address()), + token_amount: inner.amount.clone(), + coin_type: None, + coin_amount: None, + }, + TokenEvent::Claim(inner) => TokenActivityHelper { + token_data_id: &inner.token_id.token_data_id, + property_version: inner.token_id.property_version.clone(), + from_address: Some(inner.get_from_address()), + to_address: Some(inner.get_to_address()), + token_amount: inner.amount.clone(), + coin_type: None, + coin_amount: None, + }, }; let token_data_id = token_activity_helper.token_data_id; Self { diff --git a/rust/processor/src/db/common/models/token_models/token_utils.rs b/rust/processor/src/db/common/models/token_models/token_utils.rs index aa2d74c18..f46784e0c 100644 --- a/rust/processor/src/db/common/models/token_models/token_utils.rs +++ b/rust/processor/src/db/common/models/token_models/token_utils.rs @@ -248,6 +248,19 @@ pub struct WithdrawTokenEventType { pub id: TokenIdType, } +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct WithdrawTokenEventTypeV2 { + #[serde(deserialize_with = "deserialize_from_string")] + account: String, + pub amount: BigDecimal, + pub id: TokenIdType, +} +impl WithdrawTokenEventTypeV2 { + pub fn get_account(&self) -> String { + standardize_address(&self.account) + } +} + #[derive(Serialize, Deserialize, Debug, Clone)] pub struct DepositTokenEventType { #[serde(deserialize_with = "deserialize_from_string")] @@ -255,6 +268,20 @@ pub struct DepositTokenEventType { pub id: TokenIdType, } +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct DepositTokenEventTypeV2 { + account: String, + #[serde(deserialize_with = "deserialize_from_string")] + pub amount: BigDecimal, + pub id: TokenIdType, +} + +impl DepositTokenEventTypeV2 { + pub fn get_account(&self) -> String { + standardize_address(&self.account) + } +} + #[derive(Serialize, Deserialize, Debug, Clone)] pub struct MintTokenEventType { #[serde(deserialize_with = "deserialize_from_string")] @@ -262,6 +289,20 @@ pub struct MintTokenEventType { pub id: TokenDataIdType, } +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct MintTokenEventTypeV2 { + account: String, + #[serde(deserialize_with = "deserialize_from_string")] + pub amount: BigDecimal, + pub id: TokenDataIdType, +} + +impl MintTokenEventTypeV2 { + pub fn get_account(&self) -> String { + standardize_address(&self.account) + } +} + #[derive(Serialize, Deserialize, Debug, Clone)] pub struct BurnTokenEventType { #[serde(deserialize_with = "deserialize_from_string")] @@ -269,12 +310,39 @@ pub struct BurnTokenEventType { pub id: TokenIdType, } +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct BurnTokenEventTypeV2 { + account: String, + #[serde(deserialize_with = "deserialize_from_string")] + pub amount: BigDecimal, + pub id: TokenIdType, +} + +impl BurnTokenEventTypeV2 { + pub fn get_account(&self) -> String { + standardize_address(&self.account) + } +} + #[derive(Serialize, Deserialize, Debug, Clone)] pub struct MutateTokenPropertyMapEventType { pub old_id: TokenIdType, pub new_id: TokenIdType, } +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct MutateTokenPropertyMapEventTypeV2 { + account: String, + pub old_id: TokenIdType, + pub new_id: TokenIdType, +} + +impl MutateTokenPropertyMapEventTypeV2 { + pub fn get_account(&self) -> String { + standardize_address(&self.account) + } +} + #[derive(Serialize, Deserialize, Debug, Clone)] pub struct OfferTokenEventType { #[serde(deserialize_with = "deserialize_from_string")] @@ -289,6 +357,25 @@ impl OfferTokenEventType { } } +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct OfferTokenEventTypeV2 { + #[serde(deserialize_with = "deserialize_from_string")] + pub amount: BigDecimal, + from_address: String, + to_address: String, + pub token_id: TokenIdType, +} + +impl OfferTokenEventTypeV2 { + pub fn get_to_address(&self) -> String { + standardize_address(&self.to_address) + } + + pub fn get_from_address(&self) -> String { + standardize_address(&self.from_address) + } +} + #[derive(Serialize, Deserialize, Debug, Clone)] pub struct CancelTokenOfferEventType { #[serde(deserialize_with = "deserialize_from_string")] @@ -303,6 +390,25 @@ impl CancelTokenOfferEventType { } } +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct CancelTokenOfferEventTypeV2 { + #[serde(deserialize_with = "deserialize_from_string")] + pub amount: BigDecimal, + from_address: String, + to_address: String, + pub token_id: TokenIdType, +} + +impl CancelTokenOfferEventTypeV2 { + pub fn get_from_address(&self) -> String { + standardize_address(&self.from_address) + } + + pub fn get_to_address(&self) -> String { + standardize_address(&self.to_address) + } +} + #[derive(Serialize, Deserialize, Debug, Clone)] pub struct ClaimTokenEventType { #[serde(deserialize_with = "deserialize_from_string")] @@ -317,6 +423,25 @@ impl ClaimTokenEventType { } } +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct ClaimTokenEventTypeV2 { + #[serde(deserialize_with = "deserialize_from_string")] + pub amount: BigDecimal, + from_address: String, + to_address: String, + pub token_id: TokenIdType, +} + +impl ClaimTokenEventTypeV2 { + pub fn get_from_address(&self) -> String { + standardize_address(&self.from_address) + } + + pub fn get_to_address(&self) -> String { + standardize_address(&self.to_address) + } +} + #[derive(Serialize, Deserialize, Debug, Clone)] pub struct TypeInfo { pub account_address: String, @@ -383,13 +508,21 @@ impl TokenWriteSet { #[derive(Serialize, Deserialize, Debug, Clone)] pub enum TokenEvent { MintTokenEvent(MintTokenEventType), + Mint(MintTokenEventTypeV2), BurnTokenEvent(BurnTokenEventType), + Burn(BurnTokenEventTypeV2), MutateTokenPropertyMapEvent(MutateTokenPropertyMapEventType), + MutatePropertyMap(MutateTokenPropertyMapEventTypeV2), WithdrawTokenEvent(WithdrawTokenEventType), + TokenWithdraw(WithdrawTokenEventTypeV2), DepositTokenEvent(DepositTokenEventType), + TokenDeposit(DepositTokenEventTypeV2), OfferTokenEvent(OfferTokenEventType), + Offer(OfferTokenEventTypeV2), CancelTokenOfferEvent(CancelTokenOfferEventType), + CancelOffer(CancelTokenOfferEventTypeV2), ClaimTokenEvent(ClaimTokenEventType), + Claim(ClaimTokenEventTypeV2), } impl TokenEvent { @@ -398,25 +531,49 @@ impl TokenEvent { "0x3::token::MintTokenEvent" => { serde_json::from_str(data).map(|inner| Some(TokenEvent::MintTokenEvent(inner))) }, + "0x3::token::Mint" => { + serde_json::from_str(data).map(|inner| Some(TokenEvent::Mint(inner))) + }, "0x3::token::BurnTokenEvent" => { serde_json::from_str(data).map(|inner| Some(TokenEvent::BurnTokenEvent(inner))) }, + "0x3::token::Burn" => { + serde_json::from_str(data).map(|inner| Some(TokenEvent::Burn(inner))) + }, "0x3::token::MutateTokenPropertyMapEvent" => serde_json::from_str(data) .map(|inner| Some(TokenEvent::MutateTokenPropertyMapEvent(inner))), + "0x3::token::MutatePropertyMap" => { + serde_json::from_str(data).map(|inner| Some(TokenEvent::MutatePropertyMap(inner))) + }, "0x3::token::WithdrawEvent" => { serde_json::from_str(data).map(|inner| Some(TokenEvent::WithdrawTokenEvent(inner))) }, + "0x3::token::TokenWithdraw" => { + serde_json::from_str(data).map(|inner| Some(TokenEvent::TokenWithdraw(inner))) + }, "0x3::token::DepositEvent" => { serde_json::from_str(data).map(|inner| Some(TokenEvent::DepositTokenEvent(inner))) }, + "0x3::token::TokenDeposit" => { + serde_json::from_str(data).map(|inner| Some(TokenEvent::TokenDeposit(inner))) + }, "0x3::token_transfers::TokenOfferEvent" => { serde_json::from_str(data).map(|inner| Some(TokenEvent::OfferTokenEvent(inner))) }, + "0x3::token_transfers::Offer" => { + serde_json::from_str(data).map(|inner| Some(TokenEvent::Offer(inner))) + }, "0x3::token_transfers::TokenCancelOfferEvent" => serde_json::from_str(data) .map(|inner| Some(TokenEvent::CancelTokenOfferEvent(inner))), + "0x3::token_transfers::CancelOffer" => { + serde_json::from_str(data).map(|inner| Some(TokenEvent::CancelOffer(inner))) + }, "0x3::token_transfers::TokenClaimEvent" => { serde_json::from_str(data).map(|inner| Some(TokenEvent::ClaimTokenEvent(inner))) }, + "0x3::token_transfers::Claim" => { + serde_json::from_str(data).map(|inner| Some(TokenEvent::Claim(inner))) + }, _ => Ok(None), } .context(format!( diff --git a/rust/processor/src/db/common/models/token_v2_models/v2_token_activities.rs b/rust/processor/src/db/common/models/token_v2_models/v2_token_activities.rs index 83ee38388..685b131a7 100644 --- a/rust/processor/src/db/common/models/token_v2_models/v2_token_activities.rs +++ b/rust/processor/src/db/common/models/token_v2_models/v2_token_activities.rs @@ -205,6 +205,13 @@ impl TokenActivityV2 { to_address: None, token_amount: inner.amount.clone(), }, + TokenEvent::Mint(inner) => TokenActivityHelperV1 { + token_data_id_struct: inner.id.clone(), + property_version: BigDecimal::zero(), + from_address: Some(inner.get_account()), + to_address: None, + token_amount: inner.amount.clone(), + }, TokenEvent::BurnTokenEvent(inner) => TokenActivityHelperV1 { token_data_id_struct: inner.id.token_data_id.clone(), property_version: inner.id.property_version.clone(), @@ -212,6 +219,13 @@ impl TokenActivityV2 { to_address: None, token_amount: inner.amount.clone(), }, + TokenEvent::Burn(inner) => TokenActivityHelperV1 { + token_data_id_struct: inner.id.token_data_id.clone(), + property_version: inner.id.property_version.clone(), + from_address: Some(inner.get_account()), + to_address: None, + token_amount: inner.amount.clone(), + }, TokenEvent::MutateTokenPropertyMapEvent(inner) => TokenActivityHelperV1 { token_data_id_struct: inner.new_id.token_data_id.clone(), property_version: inner.new_id.property_version.clone(), @@ -219,6 +233,13 @@ impl TokenActivityV2 { to_address: None, token_amount: BigDecimal::zero(), }, + TokenEvent::MutatePropertyMap(inner) => TokenActivityHelperV1 { + token_data_id_struct: inner.new_id.token_data_id.clone(), + property_version: inner.new_id.property_version.clone(), + from_address: Some(inner.get_account()), + to_address: None, + token_amount: BigDecimal::zero(), + }, TokenEvent::WithdrawTokenEvent(inner) => TokenActivityHelperV1 { token_data_id_struct: inner.id.token_data_id.clone(), property_version: inner.id.property_version.clone(), @@ -226,6 +247,13 @@ impl TokenActivityV2 { to_address: None, token_amount: inner.amount.clone(), }, + TokenEvent::TokenWithdraw(inner) => TokenActivityHelperV1 { + token_data_id_struct: inner.id.token_data_id.clone(), + property_version: inner.id.property_version.clone(), + from_address: Some(inner.get_account()), + to_address: None, + token_amount: inner.amount.clone(), + }, TokenEvent::DepositTokenEvent(inner) => TokenActivityHelperV1 { token_data_id_struct: inner.id.token_data_id.clone(), property_version: inner.id.property_version.clone(), @@ -233,6 +261,13 @@ impl TokenActivityV2 { to_address: Some(standardize_address(&event_account_address)), token_amount: inner.amount.clone(), }, + TokenEvent::TokenDeposit(inner) => TokenActivityHelperV1 { + token_data_id_struct: inner.id.token_data_id.clone(), + property_version: inner.id.property_version.clone(), + from_address: None, + to_address: Some(inner.get_account()), + token_amount: inner.amount.clone(), + }, TokenEvent::OfferTokenEvent(inner) => TokenActivityHelperV1 { token_data_id_struct: inner.token_id.token_data_id.clone(), property_version: inner.token_id.property_version.clone(), @@ -254,6 +289,27 @@ impl TokenActivityV2 { to_address: Some(inner.get_to_address()), token_amount: inner.amount.clone(), }, + TokenEvent::Offer(inner) => TokenActivityHelperV1 { + token_data_id_struct: inner.token_id.token_data_id.clone(), + property_version: inner.token_id.property_version.clone(), + from_address: Some(inner.get_from_address()), + to_address: Some(inner.get_to_address()), + token_amount: inner.amount.clone(), + }, + TokenEvent::CancelOffer(inner) => TokenActivityHelperV1 { + token_data_id_struct: inner.token_id.token_data_id.clone(), + property_version: inner.token_id.property_version.clone(), + from_address: Some(inner.get_from_address()), + to_address: Some(inner.get_to_address()), + token_amount: inner.amount.clone(), + }, + TokenEvent::Claim(inner) => TokenActivityHelperV1 { + token_data_id_struct: inner.token_id.token_data_id.clone(), + property_version: inner.token_id.property_version.clone(), + from_address: Some(inner.get_from_address()), + to_address: Some(inner.get_to_address()), + token_amount: inner.amount.clone(), + }, }; let token_data_id_struct = token_activity_helper.token_data_id_struct; return Ok(Some(Self { diff --git a/rust/processor/src/db/common/models/token_v2_models/v2_token_utils.rs b/rust/processor/src/db/common/models/token_v2_models/v2_token_utils.rs index 714d852f2..321a62863 100644 --- a/rust/processor/src/db/common/models/token_v2_models/v2_token_utils.rs +++ b/rust/processor/src/db/common/models/token_v2_models/v2_token_utils.rs @@ -313,6 +313,16 @@ pub struct Mint { } impl Mint { + pub fn from_event(event: &Event, txn_version: i64) -> anyhow::Result> { + if let Some(V2TokenEvent::Mint(inner)) = + V2TokenEvent::from_event(event.type_str.as_str(), &event.data, txn_version).unwrap() + { + Ok(Some(inner)) + } else { + Ok(None) + } + } + pub fn get_token_address(&self) -> String { standardize_address(&self.token) } @@ -592,7 +602,7 @@ impl V2TokenEvent { "0x4::collection::MintEvent" => { serde_json::from_str(data).map(|inner| Some(Self::MintEvent(inner))) }, - "0x4::token::MutationEvent" => { + "0x4::token::MutationEvent" | "0x4::token::Mutation" => { serde_json::from_str(data).map(|inner| Some(Self::TokenMutationEvent(inner))) }, "0x4::collection::Burn" => { @@ -601,7 +611,7 @@ impl V2TokenEvent { "0x4::collection::BurnEvent" => { serde_json::from_str(data).map(|inner| Some(Self::BurnEvent(inner))) }, - "0x1::object::TransferEvent" => { + "0x1::object::TransferEvent" | "0x1::object::Transfer" => { serde_json::from_str(data).map(|inner| Some(Self::TransferEvent(inner))) }, _ => Ok(None), diff --git a/rust/processor/src/processors/token_v2_processor.rs b/rust/processor/src/processors/token_v2_processor.rs index 377ef6c8f..e5bf9a0d8 100644 --- a/rust/processor/src/processors/token_v2_processor.rs +++ b/rust/processor/src/processors/token_v2_processor.rs @@ -23,7 +23,7 @@ use crate::{ TokenOwnershipV2, }, v2_token_utils::{ - AptosCollection, Burn, BurnEvent, ConcurrentSupply, FixedSupply, MintEvent, + AptosCollection, Burn, BurnEvent, ConcurrentSupply, FixedSupply, Mint, MintEvent, PropertyMapModel, TokenIdentifiers, TokenV2, TokenV2Burned, TokenV2Minted, TransferEvent, UnlimitedSupply, }, @@ -860,35 +860,41 @@ pub async fn parse_v2_token( // and burn / transfer events need to come before the next loop for (index, event) in user_txn.events.iter().enumerate() { if let Some(burn_event) = Burn::from_event(event, txn_version).unwrap() { - tokens_burned.insert(burn_event.get_token_address(), burn_event); - } - if let Some(old_burn_event) = BurnEvent::from_event(event, txn_version).unwrap() { - let burn_event = Burn::new( - standardize_address(event.key.as_ref().unwrap().account_address.as_str()), - old_burn_event.get_token_address(), - "".to_string(), - ); - tokens_burned.insert(burn_event.get_token_address(), burn_event); - } - if let Some(mint_event) = MintEvent::from_event(event, txn_version).unwrap() { + tokens_burned.insert(burn_event.get_token_address(), burn_event.clone()); + } else if let Some(mint_event) = Mint::from_event(event, txn_version).unwrap() { tokens_minted.insert(mint_event.get_token_address()); - } - if let Some(transfer_events) = - TransferEvent::from_event(event, txn_version).unwrap() - { - if let Some(aggregated_data) = - token_v2_metadata_helper.get_mut(&transfer_events.get_object_address()) + } else { + if let Some(old_burn_event) = BurnEvent::from_event(event, txn_version).unwrap() { - // we don't want index to be 0 otherwise we might have collision with write set change index - // note that these will be multiplied by -1 so that it doesn't conflict with wsc index - let index = if index == 0 { - user_txn.events.len() - } else { - index - }; - aggregated_data - .transfer_events - .push((index as i64, transfer_events)); + let burn_event = Burn::new( + standardize_address( + event.key.as_ref().unwrap().account_address.as_str(), + ), + old_burn_event.get_token_address(), + "".to_string(), + ); + tokens_burned.insert(burn_event.get_token_address(), burn_event); + } else if let Some(mint_event) = + MintEvent::from_event(event, txn_version).unwrap() + { + tokens_minted.insert(mint_event.get_token_address()); + } else if let Some(transfer_events) = + TransferEvent::from_event(event, txn_version).unwrap() + { + if let Some(aggregated_data) = + token_v2_metadata_helper.get_mut(&transfer_events.get_object_address()) + { + // we don't want index to be 0 otherwise we might have collision with write set change index + // note that these will be multiplied by -1 so that it doesn't conflict with wsc index + let index = if index == 0 { + user_txn.events.len() + } else { + index + }; + aggregated_data + .transfer_events + .push((index as i64, transfer_events)); + } } } // handling all the token v1 events