@@ -4,6 +4,14 @@ import * as ExplorerType from "./interface"
44import * as SQL from "./utils/raw-sql"
55import type { EntityManager , ORM } from "fasset-indexer-core/orm"
66import { unixnow } from "src/shared/utils"
7+ import { EVENTS } from "fasset-indexer-core/config"
8+
9+ const TRANSACTION_TYPE_EVENTS = [
10+ EVENTS . ASSET_MANAGER . REDEMPTION_REQUESTED ,
11+ EVENTS . ASSET_MANAGER . COLLATERAL_RESERVED ,
12+ EVENTS . ASSET_MANAGER . TRANSFER_TO_CORE_VAULT_STARTED ,
13+ EVENTS . ASSET_MANAGER . RETURN_FROM_CORE_VAULT_REQUESTED
14+ ]
715
816const ALL_TRANSACTION_TYPES = Object . values ( ExplorerType . TransactionType )
917 . filter ( v => typeof v === "number" )
@@ -291,8 +299,75 @@ export class ExplorerAnalytics {
291299 }
292300
293301 protected async nativeTransactionClassification ( em : EntityManager , hash : string ) : Promise < ExplorerType . GenericTransactionClassification > {
302+ const ret : ExplorerType . GenericTransactionClassification = [ ]
294303 const logs = await em . find ( Entities . EvmLog , { transaction : { hash } } )
295- return logs . map ( log => ( { transactionHash : hash , eventName : log . name } ) )
304+ for ( const log of logs ) {
305+ let oglog : Entities . EvmLog | null = null
306+ if (
307+ log . name == EVENTS . ASSET_MANAGER . REDEMPTION_REQUESTED
308+ || log . name == EVENTS . ASSET_MANAGER . COLLATERAL_RESERVED
309+ || log . name == EVENTS . ASSET_MANAGER . TRANSFER_TO_CORE_VAULT_STARTED
310+ || log . name == EVENTS . ASSET_MANAGER . RETURN_FROM_CORE_VAULT_REQUESTED
311+ ) {
312+ oglog = log
313+ // core vault transfers
314+ } else if ( log . name == EVENTS . ASSET_MANAGER . TRANSFER_TO_CORE_VAULT_SUCCESSFUL ) {
315+ oglog = await em . findOneOrFail ( Entities . TransferToCoreVaultSuccessful ,
316+ { evmLog : log } , { populate : [ 'transferToCoreVaultStarted.evmLog.transaction' ] }
317+ ) . then ( x => x . transferToCoreVaultStarted . evmLog )
318+ } else if ( log . name == EVENTS . ASSET_MANAGER . TRANSFER_TO_CORE_VAULT_DEFAULTED ) {
319+ oglog = await em . findOneOrFail ( Entities . TransferToCoreVaultDefaulted ,
320+ { evmLog : log } , { populate : [ 'transferToCoreVaultStarted.evmLog.transaction' ] }
321+ ) . then ( x => x . transferToCoreVaultStarted . evmLog )
322+ // core vault returns
323+ } else if ( log . name == EVENTS . ASSET_MANAGER . RETURN_FROM_CORE_VAULT_CONFIRMED ) {
324+ oglog = await em . findOneOrFail ( Entities . ReturnFromCoreVaultConfirmed ,
325+ { evmLog : log } , { populate : [ 'returnFromCoreVaultRequested.evmLog.transaction' ] }
326+ ) . then ( x => x . returnFromCoreVaultRequested . evmLog )
327+ } else if ( log . name == EVENTS . ASSET_MANAGER . RETURN_FROM_CORE_VAULT_CANCELLED ) {
328+ oglog = await em . findOneOrFail ( Entities . ReturnFromCoreVaultCancelled ,
329+ { evmLog : log } , { populate : [ 'returnFromCoreVaultRequested.evmLog.transaction' ] }
330+ ) . then ( x => x . returnFromCoreVaultRequested . evmLog )
331+ // mintings
332+ } else if ( log . name == EVENTS . ASSET_MANAGER . MINTING_EXECUTED ) {
333+ oglog = await em . findOneOrFail ( Entities . MintingExecuted ,
334+ { evmLog : log } , { populate : [ 'collateralReserved.evmLog.transaction' ] }
335+ ) . then ( x => x . collateralReserved . evmLog )
336+ } else if ( log . name == EVENTS . ASSET_MANAGER . MINTING_PAYMENT_DEFAULT ) {
337+ oglog = await em . findOneOrFail ( Entities . MintingPaymentDefault ,
338+ { evmLog : log } , { populate : [ 'collateralReserved.evmLog.transaction' ] }
339+ ) . then ( x => x . collateralReserved . evmLog )
340+ } else if ( log . name == EVENTS . ASSET_MANAGER . COLLATERAL_RESERVATION_DELETED ) {
341+ oglog = await em . findOneOrFail ( Entities . CollateralReservationDeleted ,
342+ { evmLog : log } , { populate : [ 'collateralReserved.evmLog.transaction' ] }
343+ ) . then ( x => x . collateralReserved . evmLog )
344+ // redemptions
345+ } else if ( log . name == EVENTS . ASSET_MANAGER . REDEMPTION_PERFORMED ) {
346+ oglog = await em . findOneOrFail ( Entities . RedemptionPerformed ,
347+ { evmLog : log } , { populate : [ 'redemptionRequested.evmLog.transaction' ] }
348+ ) . then ( x => x . redemptionRequested . evmLog )
349+ } else if ( log . name == EVENTS . ASSET_MANAGER . REDEMPTION_DEFAULT ) {
350+ oglog = await em . findOneOrFail ( Entities . RedemptionDefault ,
351+ { evmLog : log } , { populate : [ 'redemptionRequested.evmLog.transaction' ] }
352+ ) . then ( x => x . redemptionRequested . evmLog )
353+ } else if ( log . name == EVENTS . ASSET_MANAGER . REDEMPTION_REJECTED ) {
354+ oglog = await em . findOneOrFail ( Entities . RedemptionRejected ,
355+ { evmLog : log } , { populate : [ 'redemptionRequested.evmLog.transaction' ] }
356+ ) . then ( x => x . redemptionRequested . evmLog )
357+ } else if ( log . name == EVENTS . ASSET_MANAGER . REDEMPTION_PAYMENT_FAILED ) {
358+ oglog = await em . findOneOrFail ( Entities . RedemptionPaymentFailed ,
359+ { evmLog : log } , { populate : [ 'redemptionRequested.evmLog.transaction' ] }
360+ ) . then ( x => x . redemptionRequested . evmLog )
361+ } else if ( log . name == EVENTS . ASSET_MANAGER . REDEMPTION_PAYMENT_BLOCKED ) {
362+ oglog = await em . findOneOrFail ( Entities . RedemptionPaymentBlocked ,
363+ { evmLog : log } , { populate : [ 'redemptionRequested.evmLog.transaction' ] }
364+ ) . then ( x => x . redemptionRequested . evmLog )
365+ } else {
366+ continue
367+ }
368+ ret . push ( { eventName : log . name , transactionHash : oglog . transaction . hash } )
369+ }
370+ return ret
296371 }
297372
298373 protected async rippleTransactionClassification ( em : EntityManager , hash : string ) : Promise < ExplorerType . GenericTransactionClassification > {
0 commit comments