From f9ff45d27832f5f248134c46219a6055016afd53 Mon Sep 17 00:00:00 2001 From: Julian <52217955+julianmerlo95@users.noreply.github.com> Date: Thu, 27 Jun 2024 12:57:13 -0300 Subject: [PATCH] [Blockchain Watcher] (EVM and SOLANA) Map fee value for evm and solana (#1518) * Map fee value for evm and solana * Resolve test --------- Co-authored-by: julian merlo --- .../src/domain/actions/evm/GetEvmTransactions.ts | 6 ++++-- .../actions/solana/PollSolanaTransactions.ts | 3 +++ blockchain-watcher/src/domain/entities/events.ts | 3 +++ blockchain-watcher/src/domain/entities/evm.ts | 4 ++++ blockchain-watcher/src/domain/entities/solana.ts | 1 + .../evm/evmRedeemedTransactionFoundMapper.ts | 2 ++ .../mappers/solana/solanaTransferRedeemedMapper.ts | 1 + .../repositories/evm/EvmJsonRPCBlockRepository.ts | 4 +++- .../domain/actions/evm/GetEvmTransactions.test.ts | 6 +++++- .../test/domain/actions/evm/PollEvm.test.ts | 2 ++ .../evm/evmRedeemedTransactionFoundMapper.test.ts | 14 ++++++++++++++ 11 files changed, 42 insertions(+), 4 deletions(-) diff --git a/blockchain-watcher/src/domain/actions/evm/GetEvmTransactions.ts b/blockchain-watcher/src/domain/actions/evm/GetEvmTransactions.ts index db9fc11c..58b079bb 100644 --- a/blockchain-watcher/src/domain/actions/evm/GetEvmTransactions.ts +++ b/blockchain-watcher/src/domain/actions/evm/GetEvmTransactions.ts @@ -65,12 +65,14 @@ export function populateTransaction( populatedTransactions: EvmTransaction[] ) { filterTransactions.forEach((transaction) => { - transaction.status = transactionReceipts[transaction.hash].status; + transaction.effectiveGasPrice = transactionReceipts[transaction.hash].effectiveGasPrice; + transaction.gasUsed = transactionReceipts[transaction.hash].gasUsed; transaction.timestamp = evmBlocks[transaction.blockHash].timestamp; + transaction.status = transactionReceipts[transaction.hash].status; + transaction.logs = transactionReceipts[transaction.hash].logs; transaction.environment = opts.environment; transaction.chainId = opts.chainId; transaction.chain = opts.chain; - transaction.logs = transactionReceipts[transaction.hash].logs; populatedTransactions.push(transaction); }); } diff --git a/blockchain-watcher/src/domain/actions/solana/PollSolanaTransactions.ts b/blockchain-watcher/src/domain/actions/solana/PollSolanaTransactions.ts index 761c9b41..9fc76f48 100644 --- a/blockchain-watcher/src/domain/actions/solana/PollSolanaTransactions.ts +++ b/blockchain-watcher/src/domain/actions/solana/PollSolanaTransactions.ts @@ -59,6 +59,9 @@ export class PollSolanaTransactions extends RunPollingJob { ); return []; } + this.logger.info( + `[get][exec] Processing blocks [fromSlot: ${range.fromSlot} - toSlot: ${range.toSlot}]` + ); let fromBlock = await this.findValidBlock(range.fromSlot, (slot) => slot + 1); let toBlock = await this.findValidBlock(range.toSlot, (slot) => slot - 1); diff --git a/blockchain-watcher/src/domain/entities/events.ts b/blockchain-watcher/src/domain/entities/events.ts index 7bbdd040..1976b59d 100644 --- a/blockchain-watcher/src/domain/entities/events.ts +++ b/blockchain-watcher/src/domain/entities/events.ts @@ -84,6 +84,8 @@ export type EvmTransactionFoundAttributes = TransactionFoundAttributes & { v: string; value: string; protocol: string; + gasUsed: string; + effectiveGasPrice: string; }; export type InstructionFound = { @@ -93,6 +95,7 @@ export type InstructionFound = { emitterAddress: string; sequence: number; protocol: string; + fee: number | undefined; }; export enum TxStatus { diff --git a/blockchain-watcher/src/domain/entities/evm.ts b/blockchain-watcher/src/domain/entities/evm.ts index 25212a50..40733fc8 100644 --- a/blockchain-watcher/src/domain/entities/evm.ts +++ b/blockchain-watcher/src/domain/entities/evm.ts @@ -44,6 +44,8 @@ export type EvmTransaction = { environment: string; chain: string; logs: EvmTransactionLog[]; + gasUsed: string; + effectiveGasPrice: string; }; export type EvmTransactionLog = { address: string; topics: string[]; data: string }; @@ -61,4 +63,6 @@ export type ReceiptTransaction = { status: string; transactionHash: string; logs: EvmTransactionLog[]; + gasUsed: string; + effectiveGasPrice: string; }; diff --git a/blockchain-watcher/src/domain/entities/solana.ts b/blockchain-watcher/src/domain/entities/solana.ts index ef18d6f4..b3ce0d0b 100644 --- a/blockchain-watcher/src/domain/entities/solana.ts +++ b/blockchain-watcher/src/domain/entities/solana.ts @@ -8,6 +8,7 @@ export type Transaction = { }; meta?: { innerInstructions?: CompiledInnerInstruction[] | null; + fee: number; err?: {} | string | null; }; blockTime?: number | null; diff --git a/blockchain-watcher/src/infrastructure/mappers/evm/evmRedeemedTransactionFoundMapper.ts b/blockchain-watcher/src/infrastructure/mappers/evm/evmRedeemedTransactionFoundMapper.ts index 9d76573f..f0193e01 100644 --- a/blockchain-watcher/src/infrastructure/mappers/evm/evmRedeemedTransactionFoundMapper.ts +++ b/blockchain-watcher/src/infrastructure/mappers/evm/evmRedeemedTransactionFoundMapper.ts @@ -68,6 +68,8 @@ export const evmRedeemedTransactionFoundMapper = ( gasPrice: transaction.gasPrice, maxFeePerGas: transaction.maxFeePerGas, maxPriorityFeePerGas: transaction.maxPriorityFeePerGas, + gasUsed: transaction.gasUsed, + effectiveGasPrice: transaction.effectiveGasPrice, nonce: transaction.nonce, r: transaction.r, s: transaction.s, diff --git a/blockchain-watcher/src/infrastructure/mappers/solana/solanaTransferRedeemedMapper.ts b/blockchain-watcher/src/infrastructure/mappers/solana/solanaTransferRedeemedMapper.ts index 52b7edc8..69030d6a 100644 --- a/blockchain-watcher/src/infrastructure/mappers/solana/solanaTransferRedeemedMapper.ts +++ b/blockchain-watcher/src/infrastructure/mappers/solana/solanaTransferRedeemedMapper.ts @@ -92,6 +92,7 @@ const processProgram = async ( emitterAddress: emitterAddress.toString("hex"), sequence: Number(sequence), protocol: protocolType, + fee: transaction.meta?.fee, }, }); } diff --git a/blockchain-watcher/src/infrastructure/repositories/evm/EvmJsonRPCBlockRepository.ts b/blockchain-watcher/src/infrastructure/repositories/evm/EvmJsonRPCBlockRepository.ts index 48ead4f7..22dc1ac2 100644 --- a/blockchain-watcher/src/infrastructure/repositories/evm/EvmJsonRPCBlockRepository.ts +++ b/blockchain-watcher/src/infrastructure/repositories/evm/EvmJsonRPCBlockRepository.ts @@ -304,8 +304,10 @@ export class EvmJsonRPCBlockRepository implements EvmBlockRepository { .map((response) => { if (response.result?.status && response.result?.transactionHash) { return { - status: response.result.status, + effectiveGasPrice: response.result.effectiveGasPrice, transactionHash: response.result.transactionHash, + gasUsed: response.result.gasUsed, + status: response.result.status, logs: response.result.logs, }; } diff --git a/blockchain-watcher/test/domain/actions/evm/GetEvmTransactions.test.ts b/blockchain-watcher/test/domain/actions/evm/GetEvmTransactions.test.ts index 086d5cf2..26653803 100644 --- a/blockchain-watcher/test/domain/actions/evm/GetEvmTransactions.test.ts +++ b/blockchain-watcher/test/domain/actions/evm/GetEvmTransactions.test.ts @@ -315,8 +315,10 @@ const givenEvmBlockRepository = ( .flat() .reduce((acc, tx) => { acc[tx.hash] = { - status: "0x1", + effectiveGasPrice: tx.effectiveGasPrice, transactionHash: tx.hash, + gasUsed: tx.gasUsed, + status: "0x1", logs: tx.logs, }; return acc; @@ -453,6 +455,8 @@ class TxBuilder { data: "0x0", }, ], + gasUsed: "0x6efa0", + effectiveGasPrice: "0x2fb1471cd", }; } } diff --git a/blockchain-watcher/test/domain/actions/evm/PollEvm.test.ts b/blockchain-watcher/test/domain/actions/evm/PollEvm.test.ts index e6f28932..871cb197 100644 --- a/blockchain-watcher/test/domain/actions/evm/PollEvm.test.ts +++ b/blockchain-watcher/test/domain/actions/evm/PollEvm.test.ts @@ -131,6 +131,8 @@ const givenEvmBlockRepository = (height?: bigint, blocksAhead?: bigint) => { receiptResponse[`0x0${index}`] = { status: "0x1", transactionHash: `0x0${index}`, + gasUsed: "0x6efa0", + effectiveGasPrice: "0x2fb1471cd", logs: [ { address: "0xf890982f9310df57d00f659cf4fd87e65aded8d7", diff --git a/blockchain-watcher/test/infrastructure/mappers/evm/evmRedeemedTransactionFoundMapper.test.ts b/blockchain-watcher/test/infrastructure/mappers/evm/evmRedeemedTransactionFoundMapper.test.ts index dac7739a..09f9219b 100644 --- a/blockchain-watcher/test/infrastructure/mappers/evm/evmRedeemedTransactionFoundMapper.test.ts +++ b/blockchain-watcher/test/infrastructure/mappers/evm/evmRedeemedTransactionFoundMapper.test.ts @@ -64,6 +64,8 @@ describe("evmRedeemedTransactionFoundMapper", () => { data: "0x", }, ], + gasUsed: "0x6efa0", + effectiveGasPrice: "0x2fb1471cd", }, ]); @@ -110,6 +112,8 @@ describe("evmRedeemedTransactionFoundMapper", () => { data: "0x", }, ], + gasUsed: "0x6efa0", + effectiveGasPrice: "0x2fb1471cd", }, ]); @@ -185,6 +189,8 @@ describe("evmRedeemedTransactionFoundMapper", () => { data: "0x00000000000000000000000000000000000000000000000000470de4df820000", }, ], + gasUsed: "0x6efa0", + effectiveGasPrice: "0x2fb1471cd", }, ]); @@ -266,6 +272,8 @@ describe("evmRedeemedTransactionFoundMapper", () => { timestamp: Date.now(), environment: "testnet", chain: "arbitrum-sepolia", + gasUsed: "0x6efa0", + effectiveGasPrice: "0x2fb1471cd", }, ]); @@ -320,6 +328,8 @@ describe("evmRedeemedTransactionFoundMapper", () => { data: "0x", }, ], + gasUsed: "0x6efa0", + effectiveGasPrice: "0x2fb1471cd", }, ]); @@ -365,6 +375,8 @@ describe("evmRedeemedTransactionFoundMapper", () => { data: "0x00000000000000000000000000000000000000000000000000000004b2cb597d", }, ], + gasUsed: "0x6efa0", + effectiveGasPrice: "0x2fb1471cd", }, ]); @@ -448,6 +460,8 @@ describe("evmRedeemedTransactionFoundMapper", () => { ], }, ], + gasUsed: "0x6efa0", + effectiveGasPrice: "0x2fb1471cd", }, ]);