diff --git a/src/mappings/mappingHandlers.ts b/src/mappings/mappingHandlers.ts index 791136e3..d928dba1 100644 --- a/src/mappings/mappingHandlers.ts +++ b/src/mappings/mappingHandlers.ts @@ -165,84 +165,6 @@ export async function handleStateChangeEvent(cosmosEvent: CosmosEvent): Promise< await Promise.allSettled(recordSaves); } - -export async function handleTransferEvent( - cosmosEvent: CosmosEvent -): Promise { - const { event } = cosmosEvent; - - if (event.type != EVENT_TYPES.TRANSFER) { - logger.warn('Not valid transfer event.'); - return; - } - - logger.info('Event:TRANSFER'); - logger.info(`Event Data:${JSON.stringify(cosmosEvent.event)}`); - - const balancesKit = balancesEventKit(); - const data = balancesKit.getData(cosmosEvent); - logger.info(`Decoded Data:${JSON.stringify(data)}`); - - const recipientAddress = balancesKit.getAttributeValue( - data, - BALANCE_FIELDS.transfer_recipient - ); - const senderAddress = balancesKit.getAttributeValue( - data, - BALANCE_FIELDS.transfer_sender - ); - const transactionAmount = balancesKit.getAttributeValue( - data, - BALANCE_FIELDS.amount - ); - - if (!recipientAddress) { - logger.error('Recipient address is missing or invalid.'); - return; - } - - if (!senderAddress) { - logger.error('Sender address is missing or invalid.'); - return; - } - - const { isBLDTransaction, amount } = - balancesKit.validateBLDTransaction(transactionAmount); - - if (!transactionAmount || !isBLDTransaction) { - logger.error(`Amount ${transactionAmount} invalid.`); - return; - } - - const [recipientEntryExists, senderEntryExists] = await Promise.all([ - balancesKit.addressExists(recipientAddress), - balancesKit.addressExists(senderAddress), - ]); - - if (!recipientEntryExists) { - await balancesKit.createBalancesEntry(recipientAddress); - } - - if (!senderEntryExists) { - await balancesKit.createBalancesEntry(senderAddress); - } - - const adjustedAmount = BigInt(Math.round(Number(amount.slice(0, -4)))); - - await Promise.all([ - balancesKit.updateBalance( - senderAddress, - adjustedAmount, - Operation.Decrement - ), - balancesKit.updateBalance( - recipientAddress, - adjustedAmount, - Operation.Increment - ), - ]); -} - export async function handleBalanceEvent( cosmosEvent: CosmosEvent ): Promise {