diff --git a/scripts/gas-refund-program/transactions-indexing/transaction-resolver.ts b/scripts/gas-refund-program/transactions-indexing/transaction-resolver.ts index 2157bc46..94df6989 100644 --- a/scripts/gas-refund-program/transactions-indexing/transaction-resolver.ts +++ b/scripts/gas-refund-program/transactions-indexing/transaction-resolver.ts @@ -33,7 +33,7 @@ import { getMigrationsTxs } from '../staking/2.0/migrations'; import { MIGRATION_SEPSP2_100_PERCENT_KEY } from '../staking/2.0/utils'; import { grp2ConfigByChain } from '../../../src/lib/gas-refund/config'; import { assert } from 'ts-essentials'; -import { fetchTxGasUsed } from './utils'; +import { fetchTxGasUsed } from '../../../src/lib/fetch-tx-gas-used'; type GetAllTXsInput = { startTimestamp: number; @@ -49,11 +49,11 @@ const StakingV1ContractAddressByChain: Record = { }; const contractAddressesByChain: Record = { - [CHAIN_ID_MAINNET]: [ + [CHAIN_ID_MAINNET]: [ MIGRATION_SEPSP2_100_PERCENT_KEY, grp2ConfigByChain[CHAIN_ID_MAINNET]?.sePSP1, grp2ConfigByChain[CHAIN_ID_MAINNET]?.sePSP2, - grp2ConfigByChain[CHAIN_ID_MAINNET]?.sePSP1ToSePSP2Migrator, + grp2ConfigByChain[CHAIN_ID_MAINNET]?.sePSP1ToSePSP2Migrator, AUGUSTUS_V5_ADDRESS, ], [CHAIN_ID_GOERLI]: [ @@ -168,28 +168,29 @@ export const getSwapTXs = async ({ }); // reminder: as our subgraphs were not updated since gasUsd not gasUsed the graph issue has been fixed (https://github.com/graphprotocol/graph-node/issues/2619) we need to fetch gasUsed separately - const swapsWithGasUsedNormalised: ExtendedCovalentGasRefundTransaction[] = await Promise.all( - swapsOfQualifyingStakers.map( - async ({ txHash, txOrigin, txGasPrice, timestamp, blockNumber }) => { - const {gasUsed: txGasUsed} = await fetchTxGasUsed(chainId, txHash); - - assert( - txGasUsed, - `gas used should not be zero for ${txHash} on chainId=${chainId}`, - ); - - return { - txHash, - txOrigin, - txGasPrice, - timestamp, - blockNumber, - txGasUsed: txGasUsed.toString(), - contract: AUGUSTUS_V5_ADDRESS, - }; - }, - ), - ); + const swapsWithGasUsedNormalised: ExtendedCovalentGasRefundTransaction[] = + await Promise.all( + swapsOfQualifyingStakers.map( + async ({ txHash, txOrigin, txGasPrice, timestamp, blockNumber }) => { + const { gasUsed: txGasUsed } = await fetchTxGasUsed(chainId, txHash); + + assert( + txGasUsed, + `gas used should not be zero for ${txHash} on chainId=${chainId}`, + ); + + return { + txHash, + txOrigin, + txGasPrice, + timestamp, + blockNumber, + txGasUsed: txGasUsed.toString(), + contract: AUGUSTUS_V5_ADDRESS, + }; + }, + ), + ); return swapsWithGasUsedNormalised; }; diff --git a/scripts/gas-refund-program/transactions-indexing/utils.ts b/src/lib/fetch-tx-gas-used.ts similarity index 63% rename from scripts/gas-refund-program/transactions-indexing/utils.ts rename to src/lib/fetch-tx-gas-used.ts index f2ce4f4c..0dd45adb 100644 --- a/scripts/gas-refund-program/transactions-indexing/utils.ts +++ b/src/lib/fetch-tx-gas-used.ts @@ -1,5 +1,5 @@ import { BigNumber } from 'bignumber.js'; -import { Provider } from '../../../src/lib/provider'; +import { Provider } from './provider'; const Bottleneck = require('bottleneck'); @@ -7,24 +7,29 @@ const limiter = new Bottleneck({ minTime: 200, // 200ms interval between calls (5 calls per second) }); -type RpcGasUsedFetcher = (chainId: number, txHash: string) => Promise<{gasUsed: number, l1FeeWei: null | string }>; +type RpcGasUsedFetcher = ( + chainId: number, + txHash: string, +) => Promise<{ gasUsed: number; l1FeeWei: null | string }>; const _fetchTxGasUsed: RpcGasUsedFetcher = async ( chainId: number, txHash: string, ) => { const provider = Provider.getJsonRpcProvider(chainId); - + // const tx = await provider.getTransactionReceipt(txHash); // using raw request and not ethers.js method to avoid formatting and stripping l1FeeWei in particular - const txReceiptRaw = await provider.send('eth_getTransactionReceipt', - + const txReceiptRaw = await provider.send( + 'eth_getTransactionReceipt', + [txHash], - ) - - return { + ); + + return { gasUsed: new BigNumber(txReceiptRaw.gasUsed).toNumber(), // gas used on the layer of transaction - l1FeeWei: txReceiptRaw.l1Fee ? new BigNumber(txReceiptRaw.l1Fee).toFixed() : null // l1Fee is only present on layer 2 transactions - + l1FeeWei: txReceiptRaw.l1Fee + ? new BigNumber(txReceiptRaw.l1Fee).toFixed() + : null, // l1Fee is only present on layer 2 transactions }; }; diff --git a/src/lib/paraswap-v6-stakers-transactions.ts b/src/lib/paraswap-v6-stakers-transactions.ts index a07a010b..f036d2b7 100644 --- a/src/lib/paraswap-v6-stakers-transactions.ts +++ b/src/lib/paraswap-v6-stakers-transactions.ts @@ -1,9 +1,9 @@ import { assert } from 'ts-essentials'; -import { ExtendedCovalentGasRefundTransaction } from '../../scripts/gas-refund-program/types'; +import type { ExtendedCovalentGasRefundTransaction } from '../../scripts/gas-refund-program/types'; import axios from 'axios'; import { CHAIN_ID_OPTIMISM } from './constants'; -import { fetchTxGasUsed } from '../../scripts/gas-refund-program/transactions-indexing/utils'; import BigNumber from 'bignumber.js'; +import { fetchTxGasUsed } from './fetch-tx-gas-used'; const PARASWAP_V6_STAKERS_TRANSACTIONS_URL_TEMPLATE = process.env.PARASWAP_V6_STAKERS_TRANSACTIONS_URL_TEMPLATE;