@pgchain/blockchain-libs
Version:
PGWallet Blockchain Libs
34 lines • 1.47 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MmFee = void 0;
const bignumber_js_1 = __importDefault(require("bignumber.js"));
const restful_1 = require("../../../basic/request/restful");
const GWEI_MULTIPLY = new bignumber_js_1.default(1).shiftedBy(9);
class MmFee {
constructor(chainId) {
this.chainId = chainId;
this.restful = new restful_1.RestfulRequest('https://gas-api.metaswap.codefi.network');
}
async estimateEIP1559Fee() {
const data = await this.restful
.get(`/networks/${this.chainId}/suggestedGasFees`)
.then((i) => i.json());
const baseFee = new bignumber_js_1.default(data.estimatedBaseFee).multipliedBy(GWEI_MULTIPLY);
const decodePrice = (price) => ({
maxFeePerGas: new bignumber_js_1.default(price.suggestedMaxFeePerGas).multipliedBy(GWEI_MULTIPLY),
maxPriorityFeePerGas: new bignumber_js_1.default(price.suggestedMaxPriorityFeePerGas).multipliedBy(GWEI_MULTIPLY),
});
return {
baseFee,
normal: decodePrice(data.medium),
others: [data.low, data.high]
.filter((price) => typeof price === 'object')
.map(decodePrice),
};
}
}
exports.MmFee = MmFee;
//# sourceMappingURL=mm-fee.js.map