Smart Contract Resolvers
Last updated
Last updated
Here is how a simple smart contract resolver looks like. This resolver is responsible for checking the lastExecuted
state of a simple counter in another smart contract. And if 3 minutes have passed since the last execution, this resolver will prompt Gelato to execute.
Check out the code for and .
A resolver should always return 2 things:
bool canExec
: whether Gelato should execute the task.
bytes execData
: data that executors should use for the execution.
Resolvers can also accept arguments. This is useful as you can potentially "re-use" your resolver when creating multiple tasks.
Using the same example as above:
Instead of a hardcoded COUNTER
address, you can pass counterAddress
as an argument.
Let's say you want to automate your yield compounding for multiple pools. To avoid creating multiple tasks and having different resolvers, you could keep a list of the pools and iterate through each of the pools to see if they should be compounded. Take a look at this example.
This resolver will return true when a certain time has elapsed since the last distribution of a pool, together with the payload to compound that specific pool.
The Gelato Automate UI has a feature which provides logs which show what the Gelato Executors are seeing in real time.
Using custom return messages, you can always check where in your smart contract Resolver the logic is currently "stuck", i.e. why isn't the Resolver returning true
.
On networks such as Ethereum, gas will get expensive at certain times. If what you are automating is not time-sensitive and don't mind having your transaction mined at a later point, you can limit the gas price used in your execution in your resolver.
This way, Gelato will not execute your transaction if the gas price is higher than 80 GWEI.