{"size": 1136, "ext": "js", "max_stars_repo_path": "packages/contract-helpers/dist/cjs/commons/gasStation.js", "max_stars_repo_name": "victaphu/aave-utilities", "max_stars_repo_stars_event_min_datetime": "2022-02-22T16:49:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-22T16:49:13.000Z", "max_issues_repo_path": "packages/contract-helpers/dist/cjs/commons/gasStation.js", "max_issues_repo_name": "victaphu/aave-utilities", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "packages/contract-helpers/dist/cjs/commons/gasStation.js", "max_forks_repo_name": "victaphu/aave-utilities", "max_forks_repo_forks_event_min_datetime": "2022-02-22T16:48:35.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-22T16:48:35.000Z"}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 51.6363636364, "max_line_length": 132, "alphanum_fraction": 0.7376760563}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.estimateGasByNetwork = exports.estimateGas = void 0;
const types_1 = require("./types");
const DEFAULT_SURPLUS = 30; // 30%
// polygon gas estimation is very off for some reason
const POLYGON_SURPLUS = 60; // 60%
const estimateGas = async (tx, provider, gasSurplus) => {
    const estimatedGas = await provider.estimateGas(tx);
    return estimatedGas.add(estimatedGas.mul(gasSurplus !== null && gasSurplus !== void 0 ? gasSurplus : DEFAULT_SURPLUS).div(100));
};
exports.estimateGas = estimateGas;
const estimateGasByNetwork = async (tx, provider, gasSurplus) => {
    const estimatedGas = await provider.estimateGas(tx);
    const providerNework = await provider.getNetwork();
    if (providerNework.chainId === types_1.ChainId.polygon) {
        return estimatedGas.add(estimatedGas.mul(POLYGON_SURPLUS).div(100));
    }
    return estimatedGas.add(estimatedGas.mul(gasSurplus !== null && gasSurplus !== void 0 ? gasSurplus : DEFAULT_SURPLUS).div(100));
};
exports.estimateGasByNetwork = estimateGasByNetwork;
//# sourceMappingURL=gasStation.js.map