Bolo
November 9, 2020, 11:57am
1
Hey
I have changed the script to be able to estimate gas price. It’s correct?
async function workIfNeeded(signer, jobs) {
for (const job of jobs) {
const contract = new ethers.Contract(job.address, ABIs[job.name], signer);
if (isWorkable = await contract[job.workableFn]()) {
console.log(`${job.name} is workable`);
var overrideOptions = {}
try {
const estimateGas = await metaKeeperContract.estimateGas.work(job.addr);
const gasLimitCalculated = await estimateGas();
overrideOptions = {
gasLimit: gasLimitCalculated * 1.5
}
} catch(error) {
console.error(error);
}
const tx = await contract[job.workFn](overrideOptions);
console.log(`${job.name} worked: ${tx.hash}`);
} else {
console.log(`${job.name} is not workable`);
}
}
}
3 Likes
Hey @bolo , ethers.js
should take care of estimating the gas limit for you before sending the tx. If you’re getting a “failed to estimate gas” from ethers, it’s often because the tx would revert, not because an issue in the estimation. Still, at a first glance your snippet looks ok - though It’s not clear where the metaKeeperContract
contract comes from, and I don’t understand why you are evaluating estimateGas()
which should be a resolved promise with a number.
By the way, if your gas estimation fails, this code snippet may help in retrieving the underlying revert reason:
revert.ts
export async function tryGetRevertReason(to: string, from: string, data: string): Promise<string | undefined> {
const provider = ethers.getDefaultProvider();
const tx = { to, from, data };
try {
await provider.estimateGas(tx);
} catch {
const value = await provider.call(tx);
return hexDataLength(value) % 32 === 4 && hexDataSlice(value, 0, 4) === '0x08c379a0'
? defaultAbiCoder.decode(['string'], hexDataSlice(value, 4))
: undefined;
This file has been truncated. show original
2 Likes
Bolo
November 10, 2020, 6:36pm
3
If my transaction who was started at and failed
16 hrs 42 mins ago (Nov-10-2020 01:46:50 AM +UTC)
Ethereum (ETH) detailed transaction info for txhash 0x09597a13ac4fd92cb08ec618057f6a8a58dad26fb7dafe6a2b5576b09a380904. The transaction status, block confirmation, gas fee, Ether (ETH), and token transfer are shown.
This one who started at 16 hrs 42 mins ago (Nov-10-2020 01:46:41 AM +UTC) who as successful
Ethereum (ETH) detailed transaction info for txhash 0x2286a07de1eac17c64c1e6c4f3f4e6c09865d53bf2b6ad0f2ed5d9d6c535e38e. The transaction status, block confirmation, gas fee, Ether (ETH), and token transfer are shown.
If I understood correctly, this transaction was faster than mine because use 34 Gwei and me only 31.
that's correct?
Still, at a first glance your snippet looks ok - though It’s not clear where the metaKeeperContract
contract comes from, and I don’t understand why you are evaluating estimateGas()
which should be a resolved promise with a number.
wrong copy and past. I have updated my script
autotask.js
const { ethers } = require("ethers");
const { DefenderRelaySigner } = require('defender-relay-client/lib/ethers');
// Settings edited by user
const INFURA_PROJECT_ID = "XXXX";
const INFURA_PROJECT_SECRET = "XXXX";
// ABIs for jobs and registry (contain only the methods needed, not the full ABIs of the contracts)
const ABIs = {
This file has been truncated. show original
1 Like
Bolo
November 10, 2020, 7:51pm
4
I have notice also for this job “Keep3rV1Oracle”, when I have tried to estimate the gas for work(). I have got this error.
The Contract Address 0x73353801921417f465377c8d898c6f4c0270282c page allows users to view the source code, transactions, balances, and analytics for the contract address. Users can also interact and make transactions to the contract directly on...
“gas required exceeds allowance (12487683) or always failing transaction”
it’s mean I am not allowed to run work()?
ERROR Error: processing response error (body={"jsonrpc":"2.0","id":44,"error":{"code":-32000,"message":"gas required exceeds allowance (12487683) or always failing transaction"}}, error={"code":-32000}, requestBody="{\"method\":\"eth_estimateGas\",\"params\":[{\"from\":\"0xd849511eba9f7daf7c45dcba182714a3d8ffe792\",\"to\":\"0x73353801921417f465377c8d898c6f4c0270282c\",\"data\":\"0x322e9f04\"}],\"id\":44,\"jsonrpc\":\"2.0\"}", requestMethod="POST", url="https://mainnet.infura.io/v3/4d613481619d49629d4a816115309fb2", code=SERVER_ERROR, version=web/5.0.2)
at Logger.makeError (/opt/nodejs/node_modules/@ethersproject/logger/lib/index.js:179:21)
at Logger.throwError (/opt/nodejs/node_modules/@ethersproject/logger/lib/index.js:188:20)
at /opt/nodejs/node_modules/@ethersproject/web/lib/index.js:244:32
at step (/opt/nodejs/node_modules/@ethersproject/web/lib/index.js:33:23)
at Object.next (/opt/nodejs/node_modules/@ethersproject/web/lib/index.js:14:53)
at fulfilled (/opt/nodejs/node_modules/@ethersproject/web/lib/index.js:5:58)
at processTicksAndRejections (internal/process/task_queues.js:97:5) {
reason: 'processing response error',
code: 'SERVER_ERROR',
body: {
jsonrpc: '2.0',
id: 44,
error: {
code: -32000,
message: 'gas required exceeds allowance (12487683) or always failing transaction'
}
},
error: Error: gas required exceeds allowance (12487683) or always failing transaction
at getResult (/opt/nodejs/node_modules/@ethersproject/providers/lib/json-rpc-provider.js:70:21)
at /opt/nodejs/node_modules/@ethersproject/web/lib/index.js:222:46
at step (/opt/nodejs/node_modules/@ethersproject/web/lib/index.js:33:23)
at Object.next (/opt/nodejs/node_modules/@ethersproject/web/lib/index.js:14:53)
at fulfilled (/opt/nodejs/node_modules/@ethersproject/web/lib/index.js:5:58)
at processTicksAndRejections (internal/process/task_queues.js:97:5) {
code: -32000,
data: undefined
},
requestBody: '{"method":"eth_estimateGas","params":[{"from":"0xd849511eba9f7daf7c45dcba182714a3d8ffe792","to":"0x73353801921417f465377c8d898c6f4c0270282c","data":"0x322e9f04"}],"id":44,"jsonrpc":"2.0"}',
requestMethod: 'POST',
url: 'https://mainnet.infura.io/v3/4d613481619d49629d4a816115309fb2'
}
2020-11-10T19:22:47.838Z INFO UniswapV2SlidingOracle is not workable
2020-11-10T19:22:48.143Z INFO HegicPoolKeep3r is not workable
2020-11-10T19:22:48.462Z INFO YearnV1EarnKeep3r is not workable
2020-11-10T19:22:48.463Z AUTOTASK COMPLETE
1 Like
Hi @Bolo ,
I assume that the transaction is reverting on:
require(worked, "UniswapV2Oracle: !work");
That we are back to the job competition issue.
Also see: Job competition and Autotask frequency .
Bolo
November 12, 2020, 2:50pm
6
I have got my answer. I need to have at least 200 keep3r to be able to run work()
1 Like
abcoathup
Split this topic
November 13, 2020, 4:31am
7