Mean Finance
Search…
Keep3r Job

Introduction

Even though we provide a lot of incentives for swappers to execute our swaps, it could happen that, in some cases, they are not executed. For those scenarios we've developed a Keep3r job that will subsidy some pairs, and execute their swaps if no one else does it first.
For information in how to become a keeper, please check the Keep3r's network documentation.

Executing the job

We strongly recommend using flash bots bundle in order to work through Keep3r since you will avoid running into reverted transactions / out of gas transactions being submitted.
Integrating with the job is fairly easy, and it can be divided into the following steps:
    1.
    Call workable to get a list of pairs that can be swapped
    2.
    Check if the list is empty
    3.
    If it's not, verify that calling work won't revert
    4.
    Call work
1
import { abi } from '@mean-finance/dca-v1/artifacts/contracts/DCAKeep3rJob/DCAKeep3rJob.sol/DCAKeep3rJob.json';
2
3
// Important! use callStatic for all methods (even work) to avoid spending gas only send work
4
// transaction if callStatic.work succeeded, even if workable is returns something valid, the
5
// job might not have credits to pay and the work tx will revert
6
const DCAKeep3rJob = await ethers.getContractAt(abi, "0xEcbA21E26466727d705d48cb0a8DE42B11767Bf7");
7
8
// Call workable to return a list of all pairs that should be swapped
9
let [ pairs, intervals ] = await DCAKeep3rJob.callStatic.workable();
10
11
// Check if there are any pairs to swap
12
while (pairs.length > 0) {
13
// Verify that calling work would not revert
14
await DCAKeep3rJob.connect(keeper).callStatic.work(pairs, intervals);
15
16
// Call work and execute the swaps
17
await DCAKeep3rJob.connect(keeper).work(pairs, intervals);
18
19
// Check if there are any other pairs to swap
20
[ pairs, intervals ] = await DCAKeep3rJob.callStatic.workable();
21
}
22
Copied!

Delay

It is important to realize that the goal behind the Keep3r job is to try to guarantee swaps, but as a last resort. In that sense, the job has a delay configured, so it can't be executed as soon as a swap is available. We want to provide swappers the opportunity to execute swaps themselves, and the job will act just in case that doesn't happen.
Last modified 2mo ago