@@ -88,7 +88,7 @@ export async function handleTransaction(tx: CosmosTransaction): Promise<void> {
8888 gasWanted : BigInt ( Math . trunc ( tx . tx . gasWanted ) ) ,
8989 memo : tx . decodedTx . body . memo ,
9090 timeoutHeight : BigInt ( tx . decodedTx . body . timeoutHeight . toString ( ) ) ,
91- fees : JSON . stringify ( tx . decodedTx . authInfo . fee . amount ) ,
91+ fees : tx . decodedTx . authInfo . fee . amount ,
9292 log : tx . tx . log ,
9393 status,
9494 signerAddress,
@@ -403,10 +403,7 @@ export async function handleNativeBalanceDecrement(event: CosmosEvent): Promise<
403403 for ( const [ i , spendEvent ] of Object . entries ( spendEvents ) ) {
404404 await saveNativeBalanceEvent ( `${ messageId ( event ) } -spend-${ i } ` , spendEvent . spender , spendEvent . amount , spendEvent . denom , event ) ;
405405 }
406-
407- const tx = event . tx . decodedTx ;
408- const fee = tx . authInfo . fee ;
409- await saveNativeBalanceEvent ( `${ messageId ( event ) } -fee` , fee . payer , BigInt ( 0 ) - BigInt ( fee . amount [ 0 ] . amount ) , fee . amount [ 0 ] . denom , event ) ;
406+ await saveNativeFeesEvent ( event ) ;
410407}
411408
412409export async function handleNativeBalanceIncrement ( event : CosmosEvent ) : Promise < void > {
@@ -438,10 +435,7 @@ export async function handleNativeBalanceIncrement(event: CosmosEvent): Promise<
438435 for ( const [ i , receiveEvent ] of Object . entries ( receiveEvents ) ) {
439436 await saveNativeBalanceEvent ( `${ messageId ( event ) } -receive-${ i } ` , receiveEvent . receiver , receiveEvent . amount , receiveEvent . denom , event ) ;
440437 }
441-
442- const tx = event . tx . decodedTx ;
443- const fee = tx . authInfo . fee ;
444- await saveNativeBalanceEvent ( `${ messageId ( event ) } -fee` , fee . payer , BigInt ( 0 ) - BigInt ( fee . amount [ 0 ] . amount ) , fee . amount [ 0 ] . denom , event ) ;
438+ await saveNativeFeesEvent ( event ) ;
445439}
446440
447441async function checkBalancesAccount ( address : string , chainId : string ) {
@@ -466,6 +460,16 @@ async function saveNativeBalanceEvent(id: string, address: string, amount: BigIn
466460 await nativeBalanceChangeEntity . save ( )
467461}
468462
463+ async function saveNativeFeesEvent ( event : CosmosEvent ) {
464+ let balanceChangeEvent = await NativeBalanceChange . get ( `${ event . tx . hash } -fee` )
465+ if ( typeof ( balanceChangeEvent ) === "undefined" ) {
466+ const transaction = await Transaction . get ( event . tx . hash ) ;
467+ const fees = transaction . fees [ 0 ] , signer = transaction . signerAddress ;
468+ const amount = fees . amount , denom = fees . denom ;
469+ await saveNativeBalanceEvent ( `${ event . tx . hash } -fee` , signer , BigInt ( 0 ) - BigInt ( amount ) , denom , event ) ;
470+ }
471+ }
472+
469473export async function handleIBCTransfer ( event : CosmosEvent ) : Promise < void > {
470474 const msg = event . msg ;
471475 logger . info ( `[handleIBCTransfer] (tx ${ msg . tx . hash } ): indexing message ${ msg . idx + 1 } / ${ msg . tx . decodedTx . body . messages . length } ` )
0 commit comments