"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getStreamRegistryOverrides = exports.getStreamRegistryChainProviders = exports.generateEthereumAccount = void 0;
const providers_1 = require("@ethersproject/providers");
const wallet_1 = require("@ethersproject/wallet");
const generateEthereumAccount = () => {
    const wallet = wallet_1.Wallet.createRandom();
    return {
        address: wallet.address,
        privateKey: wallet.privateKey,
    };
};
exports.generateEthereumAccount = generateEthereumAccount;
const getStreamRegistryChainProviders = (config) => {
    return getRpcProviders(config.contracts.streamRegistryChainRPCs);
};
exports.getStreamRegistryChainProviders = getStreamRegistryChainProviders;
const getRpcProviders = (connectionInfo) => {
    return connectionInfo.rpcs.map((c) => {
        return new providers_1.JsonRpcProvider(c);
    });
};
const getStreamRegistryOverrides = (config) => {
    const primaryProvider = (0, exports.getStreamRegistryChainProviders)(config)[0];
    return getOverrides(config.contracts.streamRegistryChainRPCs.name ?? 'polygon', primaryProvider, config);
};
exports.getStreamRegistryOverrides = getStreamRegistryOverrides;
/**
 * Apply the gasPriceStrategy to the estimated gas price, if given
 * Ethers.js will resolve the gas price promise before sending the tx
 */
const getOverrides = (chainName, provider, config) => {
    const chainConfig = config.contracts.ethereumNetworks[chainName];
    if (chainConfig === undefined) {
        return {};
    }
    const overrides = chainConfig.overrides ?? {};
    if (chainConfig.highGasPriceStrategy) {
        const gasPriceStrategy = (estimatedGasPrice) => estimatedGasPrice.add('10000000000');
        return {
            ...overrides,
            gasPrice: provider.getGasPrice().then(gasPriceStrategy),
        };
    }
    return overrides;
};
//# sourceMappingURL=Ethereum.js.map