2019-08-25 02:39:20 -04:00
|
|
|
"use strict";
|
2021-06-24 02:13:06 -04:00
|
|
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
|
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
|
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
|
|
});
|
|
|
|
};
|
|
|
|
import { BigNumber } from "@ethersproject/bignumber";
|
2019-08-25 02:39:20 -04:00
|
|
|
import { isHexString } from "@ethersproject/bytes";
|
2021-06-24 02:13:06 -04:00
|
|
|
import { Description, defineReadOnly, resolveProperties } from "@ethersproject/properties";
|
2019-08-25 02:39:20 -04:00
|
|
|
import { Logger } from "@ethersproject/logger";
|
|
|
|
import { version } from "./_version";
|
|
|
|
const logger = new Logger(version);
|
|
|
|
;
|
|
|
|
;
|
|
|
|
//export type CallTransactionable = {
|
|
|
|
// call(transaction: TransactionRequest): Promise<TransactionResponse>;
|
|
|
|
//};
|
|
|
|
export class ForkEvent extends Description {
|
|
|
|
static isForkEvent(value) {
|
|
|
|
return !!(value && value._isForkEvent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
export class BlockForkEvent extends ForkEvent {
|
2020-05-21 00:07:41 -04:00
|
|
|
constructor(blockHash, expiry) {
|
|
|
|
if (!isHexString(blockHash, 32)) {
|
|
|
|
logger.throwArgumentError("invalid blockHash", "blockHash", blockHash);
|
2019-08-25 02:39:20 -04:00
|
|
|
}
|
|
|
|
super({
|
|
|
|
_isForkEvent: true,
|
|
|
|
_isBlockForkEvent: true,
|
|
|
|
expiry: (expiry || 0),
|
2020-05-21 00:07:41 -04:00
|
|
|
blockHash: blockHash
|
2019-08-25 02:39:20 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
export class TransactionForkEvent extends ForkEvent {
|
|
|
|
constructor(hash, expiry) {
|
|
|
|
if (!isHexString(hash, 32)) {
|
|
|
|
logger.throwArgumentError("invalid transaction hash", "hash", hash);
|
|
|
|
}
|
|
|
|
super({
|
|
|
|
_isForkEvent: true,
|
|
|
|
_isTransactionForkEvent: true,
|
|
|
|
expiry: (expiry || 0),
|
|
|
|
hash: hash
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
export class TransactionOrderForkEvent extends ForkEvent {
|
|
|
|
constructor(beforeHash, afterHash, expiry) {
|
|
|
|
if (!isHexString(beforeHash, 32)) {
|
|
|
|
logger.throwArgumentError("invalid transaction hash", "beforeHash", beforeHash);
|
|
|
|
}
|
|
|
|
if (!isHexString(afterHash, 32)) {
|
|
|
|
logger.throwArgumentError("invalid transaction hash", "afterHash", afterHash);
|
|
|
|
}
|
|
|
|
super({
|
|
|
|
_isForkEvent: true,
|
|
|
|
_isTransactionOrderForkEvent: true,
|
|
|
|
expiry: (expiry || 0),
|
|
|
|
beforeHash: beforeHash,
|
|
|
|
afterHash: afterHash
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
///////////////////////////////
|
|
|
|
// Exported Abstracts
|
|
|
|
export class Provider {
|
2019-09-06 17:48:26 -04:00
|
|
|
constructor() {
|
|
|
|
logger.checkAbstract(new.target, Provider);
|
|
|
|
defineReadOnly(this, "_isProvider", true);
|
|
|
|
}
|
2021-06-24 02:13:06 -04:00
|
|
|
getFeeData() {
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
const { block, gasPrice } = yield resolveProperties({
|
|
|
|
block: this.getBlock("latest"),
|
|
|
|
gasPrice: this.getGasPrice().catch((error) => {
|
|
|
|
// @TODO: Why is this now failing on Calaveras?
|
|
|
|
//console.log(error);
|
|
|
|
return null;
|
|
|
|
})
|
|
|
|
});
|
2022-08-18 14:48:39 -04:00
|
|
|
let lastBaseFeePerGas = null, maxFeePerGas = null, maxPriorityFeePerGas = null;
|
2021-06-24 02:13:06 -04:00
|
|
|
if (block && block.baseFeePerGas) {
|
|
|
|
// We may want to compute this more accurately in the future,
|
|
|
|
// using the formula "check if the base fee is correct".
|
|
|
|
// See: https://eips.ethereum.org/EIPS/eip-1559
|
2022-08-18 14:48:39 -04:00
|
|
|
lastBaseFeePerGas = block.baseFeePerGas;
|
2022-03-09 02:56:08 -05:00
|
|
|
maxPriorityFeePerGas = BigNumber.from("1500000000");
|
2021-06-24 02:13:06 -04:00
|
|
|
maxFeePerGas = block.baseFeePerGas.mul(2).add(maxPriorityFeePerGas);
|
|
|
|
}
|
2022-08-18 14:48:39 -04:00
|
|
|
return { lastBaseFeePerGas, maxFeePerGas, maxPriorityFeePerGas, gasPrice };
|
2021-06-24 02:13:06 -04:00
|
|
|
});
|
|
|
|
}
|
2019-08-25 02:39:20 -04:00
|
|
|
// Alias for "on"
|
|
|
|
addListener(eventName, listener) {
|
|
|
|
return this.on(eventName, listener);
|
|
|
|
}
|
|
|
|
// Alias for "off"
|
|
|
|
removeListener(eventName, listener) {
|
|
|
|
return this.off(eventName, listener);
|
|
|
|
}
|
|
|
|
static isProvider(value) {
|
|
|
|
return !!(value && value._isProvider);
|
|
|
|
}
|
|
|
|
}
|
2020-07-13 08:03:56 -04:00
|
|
|
//# sourceMappingURL=index.js.map
|