Fixed estimateGas which can return insufficient funds errors.

This commit is contained in:
Richard Moore 2023-01-27 18:29:35 -05:00
parent 2845a3c4b6
commit 924cfef5de
2 changed files with 17 additions and 1 deletions

View File

@ -274,6 +274,14 @@ export class BaseEtherscanProvider extends AbstractProvider {
}
}
if (req.method === "estimateGas") {
if (!message.match(/revert/i) && message.match(/insufficient funds/i)) {
assert(false, "insufficient funds", "INSUFFICIENT_FUNDS", {
transaction: req.transaction
});
}
}
if (req.method === "call" || req.method === "estimateGas") {
if (message.match(/execution reverted/i)) {
let data = "";
@ -287,7 +295,6 @@ export class BaseEtherscanProvider extends AbstractProvider {
}
}
if (message) {
if (req.method === "broadcastTransaction") {
const transaction = Transaction.from(req.signedTransaction);

View File

@ -787,6 +787,15 @@ export abstract class JsonRpcApiProvider extends AbstractProvider {
const { method } = payload;
const { error } = _error;
if (method === "eth_estimateGas" && error.message) {
const msg = error.message;
if (!msg.match(/revert/i) && msg.match(/insufficient funds/i)) {
return makeError("insufficient funds", "INSUFFICIENT_FUNDS", {
transaction: ((<any>payload).params[0]),
});
}
}
if (method === "eth_call" || method === "eth_estimateGas") {
const result = spelunkData(error);