Skip to content

Commit

Permalink
Merge branch 'feat/v6-swap-transactions' into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
alexshchur committed Jun 26, 2024
2 parents 5ce2c51 + 3217a71 commit 3d11160
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -49,11 +49,11 @@ const StakingV1ContractAddressByChain: Record<number, string[]> = {
};

const contractAddressesByChain: Record<number, string[]> = {
[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]: [
Expand Down Expand Up @@ -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;
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
import { BigNumber } from 'bignumber.js';
import { Provider } from '../../../src/lib/provider';
import { Provider } from './provider';

const Bottleneck = require('bottleneck');

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
};
};

Expand Down
4 changes: 2 additions & 2 deletions src/lib/paraswap-v6-stakers-transactions.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 3d11160

Please sign in to comment.