"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getEthersOverrides = exports.generateEthereumAccount = void 0;
const ethers_1 = require("ethers");
const generateEthereumAccount = () => {
    const wallet = ethers_1.Wallet.createRandom();
    return {
        address: wallet.address,
        privateKey: wallet.privateKey,
    };
};
exports.generateEthereumAccount = generateEthereumAccount;
/**
 * Apply the gasPriceStrategy to the estimated gas price, if given
 * Ethers.js will resolve the gas price promise before sending the tx
 */
const getEthersOverrides = async (rpcProviderSource, // TODO: can this be done somewhat cleaner?
config) => {
    const chainConfig = config.contracts.ethereumNetwork;
    const overrides = chainConfig.overrides ?? {};
    if ((chainConfig.highGasPriceStrategy) && (chainConfig.overrides?.gasPrice === undefined)) {
        const feeData = await rpcProviderSource.getProvider().getFeeData();
        const gasPriceStrategy = (feeData) => {
            const INCREASE_PERCENTAGE = 30;
            return feeData.gasPrice === null ? undefined : feeData.gasPrice * BigInt(100 + INCREASE_PERCENTAGE) / 100n;
        };
        return {
            ...overrides,
            gasPrice: gasPriceStrategy(feeData)
        };
    }
    return overrides;
};
exports.getEthersOverrides = getEthersOverrides;
//# sourceMappingURL=ethereumUtils.js.map