Hey Team,
We have an autotask with multiple transactions that should be executed in sequence. However, sometimes defender fails with
AUTOTASK START
END RequestId: 73d62719-0563-4920-bd59-feb946167b5e
AUTOTASK COMPLETE
2022-10-03T17:21:46.204Z ERROR Invoke Error {"errorType":"Error","errorMessage":"Error while attempting request: Transaction rejected by aggregator: execution reverted","stack":["Error: Error while attempting request: Transaction rejected by aggregator: execution reverted"," at AutotaskRelayer.execute (/opt/nodejs/node_modules/defender-base-client/lib/autotask/index.js:46:19)"," at processTicksAndRejections (internal/process/task_queues.js:97:5)"," at async DefenderRelaySigner.sendTransaction (/opt/nodejs/node_modules/defender-relay-client/lib/ethers/signer.js:110:15)"]}
This is odd because there seems to be no errors on chain and when we execute them separately through the relayer it works.
Our autotask is as follows:
const ATLAS_STAKER = "0x....";
const batchSize = 20;
// Entrypoint for the Autotask
export async function handler(credentials: RelayerParams) {
const provider = new DefenderRelayProvider(credentials);
const signer = new DefenderRelaySigner(credentials, provider, { speed: "fast" });
const atlasStaker = new ethers.Contract(ATLAS_STAKER, AtlasStaker.abi, signer);
//Get current Atlas Mine position size
const positionSize = await atlasStaker.activeAtlasPositionSize();
const iterations = Math.ceil(positionSize.toNumber() / batchSize);
//Start the Harvesting
const startHarvestTx = await atlasStaker.startHarvestAndDistribute();
const startHarvestResult = await startHarvestTx.wait();
if (startHarvestResult.status == 0) {
console.error("Error executing startHarvestAndDistribute()");
process.exit(1);
}
//Execute the harvesting from Atlas Mine in batches
for (let i = 0; i < iterations; i++) {
const tx = await atlasStaker.executeHarvestAll(i * batchSize, batchSize);
const result = await tx.wait();
if (result.status == 0) {
console.error("Error executing executeHarvestAll(" + i * batchSize + ", " + batchSize + ")");
process.exit(1);
}
}
//Update the emissions
const updateEmissionsTx = await atlasStaker.executeUpdateEmissions();
const updateEmissionsResult = await updateEmissionsTx.wait();
if (updateEmissionsResult.status == 0) {
console.error("Error executing executeUpdateEmissions()");
process.exit(1);
}
//Execute the withdrawals from Atlas Mine in batches
for (let i = 0; i < iterations; i++) {
const tx = await atlasStaker.executeWithdrawAll(i * batchSize, batchSize);
const result = await tx.wait();
if (result.status == 0) {
console.error("Error executing executeWithdrawAll(" + i * batchSize + ", " + batchSize + ")");
process.exit(1);
}
}
//Execute the new deposits to AtlasMine
const executeDepositTx = await atlasStaker.executeDepositAll();
const executeDepositResult = await executeDepositTx.wait();
if (executeDepositResult.status == 0) {
console.error("Error executing executeDepositAll()");
process.exit(1);
}
//Finish the Harvesting
const finishHarvestTx = await atlasStaker.finishHarvestAndDistribute();
const finishHarvestResult = await finishHarvestTx.wait();
if (finishHarvestResult.status == 0) {
console.error("Error executing finishHarvestAndDistribute()");
process.exit(1);
}
}
Any idea on the cause?