Harvesting vaults

ETHA Lend

ETHA is using Gelato Ops for automated yield harvesting.
This is the function which Gelato will be calling. harvestVault claims yield generated from a pool and re-deposits them back into the pool.
1
function harvestVault(IVault vault) public onlyAfterDelay(vault) {
2
// Amount to Harvest
3
uint256 afterFee = vault.harvest();
4
require(afterFee > 0, "!Yield");
5
6
IERC20 from = vault.rewards();
7
IERC20 to = vault.target();
8
9
address connector = getBestConnector(
10
address(from),
11
address(to),
12
afterFee
13
);
14
15
// Quickswap path
16
address[] memory path;
17
18
if (connector == address(0)) {
19
path = new address[](2);
20
path[0] = address(from);
21
path[1] = address(to);
22
} else {
23
path = new address[](3);
24
path[0] = address(from);
25
path[1] = connector;
26
path[2] = address(to);
27
}
28
29
// Swap underlying to target
30
from.approve(address(ROUTER), afterFee);
31
uint256 received = ROUTER.swapExactTokensForTokens(
32
afterFee,
33
1,
34
path,
35
address(this),
36
block.timestamp + 1
37
)[path.length - 1];
38
39
// Send profits to vault
40
to.approve(address(vault), received);
41
vault.distribute(received);
42
43
emit Harvested(address(vault), msg.sender);
44
}
Copied!
ETHA uses this resolver below to check for ready to be harvested pools.
1
function checker()
2
external
3
view
4
returns (bool canExec, bytes memory execPayload)
5
{
6
uint256 delay = harvester.delay();
7
8
for (uint256 i = 0; i < vaults.length(); i++) {
9
IVault vault = IVault(getVault(i));
10
11
canExec = block.timestamp >= vault.lastDistribution().add(delay);
12
13
execPayload = abi.encodeWithSelector(
14
IHarvester.harvestVault.selector,
15
address(vault)
16
);
17
18
if (canExec) break;
19
}
20
}
Copied!
The resolver loops through an array of pools. And for each vault, if a defined delay has elapsed since the previous harvest time, canExec will return true , prompting Gelato to execute the task. execPayload will be the data to the function call harvestVault(address vault) and its argument is the address of the vault to be harvested.
Last modified 14d ago
Copy link