Skip to content

Commit 5524af5

Browse files
kuco23claude
andcommitted
refactor: make direct minting the fallback in rippleTransactionClassification
Direct minting references are lax — no reference or any unrecognized reference should fall through to the direct minting lookup. Restructure so known reference types return early and direct minting is the default. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 7d27456 commit 5524af5

2 files changed

Lines changed: 54 additions & 57 deletions

File tree

packages/fasset-indexer-api/src/analytics/explorer.ts

Lines changed: 54 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -499,60 +499,63 @@ export class ExplorerAnalytics extends SharedAnalytics {
499499
const fasset = core.FAssetType.FXRP
500500
const reference = await em.findOne(Entities.UnderlyingReference,
501501
{ transaction: { hash } }, { populate: [ 'transaction.block' ] })
502-
if (reference == null || PaymentReference.isDirectMinting(reference.reference)) {
503-
const transactionId = '0x' + hash.toLowerCase()
504-
const [directMints, directMintsSA] = await Promise.all([
505-
em.find(Entities.DirectMintingExecuted,
506-
{ transactionId, fasset }, { populate: [ 'evmLog.transaction' ] }),
507-
em.find(Entities.DirectMintingExecutedToSmartAccount,
508-
{ transactionId, fasset }, { populate: [ 'evmLog.transaction' ] })
509-
])
510-
return [...directMints, ...directMintsSA].map(dm => ({
511-
eventName: dm.evmLog.name, transactionHash: dm.evmLog.transaction.hash
512-
}))
513-
}
514-
if (PaymentReference.isMint(reference.reference)) {
515-
oglog = await em.findOneOrFail(Entities.CollateralReserved,
516-
{ paymentReference: reference.reference, fasset }, { populate: [ 'evmLog.transaction' ] })
517-
} else if (PaymentReference.isRedeem(reference.reference)) {
518-
const requestId = PaymentReference.decodeId(reference.reference)
519-
oglog = await em.findOne(Entities.TransferToCoreVaultStarted,
520-
{ transferRedemptionRequestId: Number(requestId), fasset }, { populate: [ 'evmLog.transaction' ] })
521-
if (oglog == null) {
522-
oglog = await em.findOneOrFail(Entities.RedemptionRequested,
502+
if (reference != null) {
503+
if (PaymentReference.isMint(reference.reference)) {
504+
oglog = await em.findOneOrFail(Entities.CollateralReserved,
505+
{ paymentReference: reference.reference, fasset }, { populate: [ 'evmLog.transaction' ] })
506+
} else if (PaymentReference.isRedeem(reference.reference)) {
507+
const requestId = PaymentReference.decodeId(reference.reference)
508+
oglog = await em.findOne(Entities.TransferToCoreVaultStarted,
509+
{ transferRedemptionRequestId: Number(requestId), fasset }, { populate: [ 'evmLog.transaction' ] })
510+
if (oglog == null) {
511+
oglog = await em.findOneOrFail(Entities.RedemptionRequested,
512+
{ paymentReference: reference.reference, fasset }, { populate: [ 'evmLog.transaction' ] })
513+
}
514+
} else if (PaymentReference.isReturnFromCoreVault(reference.reference)) {
515+
oglog = await em.findOneOrFail(Entities.ReturnFromCoreVaultRequested,
523516
{ paymentReference: reference.reference, fasset }, { populate: [ 'evmLog.transaction' ] })
517+
} else if (PaymentReference.isRedeemFromCoreVault(reference.reference)) {
518+
oglog = await em.findOneOrFail(Entities.CoreVaultRedemptionRequested,
519+
{ paymentReference: reference.reference, fasset }, { populate: [ 'evmLog.transaction' ]})
520+
} else if (PaymentReference.isWithdrawal(reference.reference)) {
521+
oglog = await em.findOneOrFail(Entities.UnderlyingWithdrawalAnnounced,
522+
{ paymentReference: reference.reference, fasset }, { populate: [ 'evmLog.transaction' ]})
523+
} else if (PaymentReference.isTopup(reference.reference)) {
524+
const transactionHash = '0x' + hash.toLowerCase()
525+
oglog = await em.findOneOrFail(Entities.UnderlyingBalanceToppedUp,
526+
{ transactionHash, fasset }, { populate: [ 'evmLog.transaction' ]})
527+
} else if (PaymentReference.isSelfMint(reference.reference)) {
528+
const hex = PaymentReference.decodeAddress(reference.reference)
529+
const resp = await em.createQueryBuilder(Entities.SelfMint, 'sm')
530+
.select(['el.name', 'et.hash'])
531+
.join('sm.evmLog', 'el')
532+
.join('el.block', 'eb')
533+
.join('el.transaction', 'et')
534+
.join('sm.agentVault', 'av')
535+
.join('av.address', 'ea')
536+
.where({
537+
'ea.hex': hex,
538+
'eb.timestamp': { $gte: reference.transaction.block.timestamp }
539+
})
540+
.orderBy({ 'eb.timestamp': 'asc' })
541+
.execute() as [ { name: string, hash: string }]
542+
return resp.map(({ name, hash}) => ({ eventName: name, transactionHash: hash }))
543+
}
544+
if (oglog != null) {
545+
return [{ eventName: oglog.evmLog.name, transactionHash: oglog.evmLog.transaction.hash }]
524546
}
525-
} else if (PaymentReference.isReturnFromCoreVault(reference.reference)) {
526-
oglog = await em.findOneOrFail(Entities.ReturnFromCoreVaultRequested,
527-
{ paymentReference: reference.reference, fasset }, { populate: [ 'evmLog.transaction' ] })
528-
} else if (PaymentReference.isRedeemFromCoreVault(reference.reference)) {
529-
oglog = await em.findOneOrFail(Entities.CoreVaultRedemptionRequested,
530-
{ paymentReference: reference.reference, fasset }, { populate: [ 'evmLog.transaction' ]})
531-
} else if (PaymentReference.isWithdrawal(reference.reference)) {
532-
oglog = await em.findOneOrFail(Entities.UnderlyingWithdrawalAnnounced,
533-
{ paymentReference: reference.reference, fasset }, { populate: [ 'evmLog.transaction' ]})
534-
} else if (PaymentReference.isTopup(reference.reference)) {
535-
const transactionHash = '0x' + hash.toLowerCase()
536-
oglog = await em.findOneOrFail(Entities.UnderlyingBalanceToppedUp,
537-
{ transactionHash, fasset }, { populate: [ 'evmLog.transaction' ]})
538-
} else if (PaymentReference.isSelfMint(reference.reference)) {
539-
const hex = PaymentReference.decodeAddress(reference.reference)
540-
const resp = await em.createQueryBuilder(Entities.SelfMint, 'sm')
541-
.select(['el.name', 'et.hash'])
542-
.join('sm.evmLog', 'el')
543-
.join('el.block', 'eb')
544-
.join('el.transaction', 'et')
545-
.join('sm.agentVault', 'av')
546-
.join('av.address', 'ea')
547-
.where({
548-
'ea.hex': hex,
549-
'eb.timestamp': { $gte: reference.transaction.block.timestamp }
550-
})
551-
.orderBy({ 'eb.timestamp': 'asc' })
552-
.execute() as [ { name: string, hash: string }]
553-
return resp.map(({ name, hash}) => ({ eventName: name, transactionHash: hash }))
554547
}
555-
return [{ eventName: oglog.evmLog.name, transactionHash: oglog.evmLog.transaction.hash }]
548+
// fallback: direct minting (no reference, or unrecognized reference)
549+
const transactionId = '0x' + hash.toLowerCase()
550+
const [directMints, directMintsSA] = await Promise.all([
551+
em.find(Entities.DirectMintingExecuted,
552+
{ transactionId, fasset }, { populate: [ 'evmLog.transaction' ] }),
553+
em.find(Entities.DirectMintingExecutedToSmartAccount,
554+
{ transactionId, fasset }, { populate: [ 'evmLog.transaction' ] })
555+
])
556+
return [...directMints, ...directMintsSA].map(dm => ({
557+
eventName: dm.evmLog.name, transactionHash: dm.evmLog.transaction.hash
558+
}))
556559
}
557560

558561
protected async mintStats(em: EntityManager, start: number, end: number): Promise<ExplorerType.ExplorerStatistics> {

packages/fasset-indexer-core/src/utils/reference.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ export namespace PaymentReference {
99
const REDEEM_FROM_CORE_VAULT_PREFIX = '0x4642505266410005'
1010
const TOPUP_PREFIX = '0x4642505266410011'
1111
const SELF_MINT_PREFIX = '0x4642505266410012'
12-
const DIRECT_MINTING_PREFIX = '0x4642505266410018'
13-
const DIRECT_MINTING_EX_PREFIX = '0x4642505266410021'
1412
// shifts
1513
const TYPE_SHIFT = BigInt(192)
1614
const LOW_BITS_MASK = (BigInt(1) << TYPE_SHIFT) - BigInt(1)
@@ -96,10 +94,6 @@ export namespace PaymentReference {
9694
return reference.startsWith(SELF_MINT_PREFIX)
9795
}
9896

99-
export function isDirectMinting(reference: string): boolean {
100-
return reference.startsWith(DIRECT_MINTING_PREFIX) || reference.startsWith(DIRECT_MINTING_EX_PREFIX)
101-
}
102-
10397
function toHex(value: bigint, length: number): string {
10498
return "0x" + value.toString(16).padStart(length * 2, "0").slice(0, length * 2);
10599
}

0 commit comments

Comments
 (0)