A wild new Keep3r has appeared!

Motivation and design of HegicBot: Hegic options auto-exerciser

Carlos Sessa
3 min readJan 5, 2021
An option exercising bot (?)

Some weeks ago, jmonteer released a contract to create an NFT token out of a Hegic option. During the Christmas break, I helped him create some automation around the Hegic secondary market. In this blog, we will discuss how the system works and how to call the new keep3r correctly.

Disclaimer: All these contracts are being tested and we don’t consider them production-ready. Use at your own risk.

The beginning of the Hegic secondary market

Jmonteer is working on creating a Hegic secondary market. To build that, he started by tokenizing Hegic options. The process is the following:

  1. User creates an option in Hegic
  2. They can tokenize using the HegicOptionsNFT contract.

Once the option is tokenized it can move from hand to hand. Then, it can be sent to a secondary market contract, which will pay whatever the option is worth. The contract needs to manage those options to extract maximum profit. It can sell them or exercise them. Juan and I started working on the exercise part. We ended up building the HegicBot.

The HegicBot

HegicBot is a smart contract that exercises Hegic options NFTs deposited in it when certain conditions are met. These conditions are:

  1. Target price (i.e. target profit) has been reached
  2. The option is in-the-money (ITM) and the option expires soon

The logic is pretty simple: The user sends a tokenized Hegic option to HegicBot and sets a target price. Then, any user can exercise the option calling exercise(tokenId) when the required conditions (1 and/or 2) are met. This sounds great but, who will exercise an option on behalf of the owner that will receive the profit? We synced with AC and thought this may be a job for Keep3r.

The HegicBotKeep3r

We needed to add the automation and the incentive layer in order for the HegicBot to be useful. We used Keep3r to build the HegicBotKeep3r.

Keep3rs using this contract should:

  • Follow HegicBot’s new tracked tokens using the TokenTracked event
  • Check if tracked tokens are exercisable through the function exercisable()
  • Call function exercise(trackedTokenId)

Keep3rs that do this will receive 1.1 times the gas fees they spent executing the exercise function.

Some more details for more experienced keepers

HegicBotKeep3r is not using the default worked() function from the Keep3r contract. The HegicBotKeep3r is using the workReceipt() function and customizing the payment for keepers. The contract will calculate the amount of gas used to exercise the option and we will pay the keeper 1.1 * gasPrice where gasPrice is the min between keeper defined gas and the fast-gas oracle.

In short, a keeper calling exercise() correctly will be paid 1.1x the gas used which comes from the option owner’s profit. If the option doesn’t have enough profit to cover gas, the transaction will revert. Keepers, please verify in a fork before sending the transaction to mainnet.

Future work

Consider these contracts a PoC. We are already using it ourselves and we would like to get feedback from the community before we deploy the WBTC version. If you want to test it out, go to https://www.hegic-tokenizer.co/.

Happy optioning!

Written by: jmonteer and macarse

--

--