2021-11-11 17:46:45 +01:00
|
|
|
import { omit } from 'lodash';
|
2022-09-22 17:04:24 +02:00
|
|
|
import { BN } from 'ethereumjs-util';
|
2021-11-11 17:46:45 +01:00
|
|
|
import Common, { Chain, Hardfork } from '@ethereumjs/common';
|
|
|
|
import { TransactionFactory } from '@ethereumjs/tx';
|
2022-09-22 17:04:24 +02:00
|
|
|
import { stripHexPrefix } from '../../../../shared/modules/hexstring-utils';
|
2021-11-11 17:46:45 +01:00
|
|
|
|
|
|
|
function buildTxParams(txMeta) {
|
|
|
|
return {
|
|
|
|
...omit(txMeta.txParams, 'gas'),
|
|
|
|
gasLimit: txMeta.txParams.gas,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildTransactionCommon(txMeta) {
|
|
|
|
// This produces a transaction whose information does not completely match an
|
|
|
|
// Optimism transaction — for instance, DEFAULT_CHAIN is still 'mainnet' and
|
|
|
|
// genesis points to the mainnet genesis, not the Optimism genesis — but
|
|
|
|
// considering that all we want to do is serialize a transaction, this works
|
|
|
|
// fine for our use case.
|
|
|
|
return Common.forCustomChain(Chain.Mainnet, {
|
|
|
|
chainId: new BN(stripHexPrefix(txMeta.chainId), 16),
|
|
|
|
networkId: new BN(txMeta.metamaskNetworkId, 10),
|
|
|
|
// Optimism only supports type-0 transactions; it does not support any of
|
|
|
|
// the newer EIPs since EIP-155. Source:
|
|
|
|
// <https://github.com/ethereum-optimism/optimism/blob/develop/specs/l2geth/transaction-types.md>
|
|
|
|
defaultHardfork: Hardfork.SpuriousDragon,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function buildUnserializedTransaction(txMeta) {
|
|
|
|
const txParams = buildTxParams(txMeta);
|
|
|
|
const common = buildTransactionCommon(txMeta);
|
|
|
|
return TransactionFactory.fromTxData(txParams, { common });
|
|
|
|
}
|