How ApeSwap Integrated Chainlink Keepers for BANANA Maximizer Vaults

Simplifying vault compounding and improving efficiency for users and the protocol

ApeBond
6 min readAug 4, 2022

[Editor’s note: this technical blog is primarily intended for Chainlink users and developers. If you have any questions, feel free to reach ApeSwap on Telegram or Discord.]

What is ApeSwap?

ApeSwap is a decentralized finance (DeFi) platform offering a full suite of tools to explore and engage with the future of wealth management, overseen by the ApeSwap Decentralized Autonomous Organization (DAO).

How ApeSwap uses Chainlink Keepers

We are using Chainlink Keepers to help ensure that our new BANANA Maximizer vaults are compounded within a set time frame helping to meet our promise to our users that their sweet BANANA is being maximized properly.

What are BANANA Maximizers?

BANANA Maximizer vaults are auto-compounding vaults that operate on top of BANANA Farms to take BANANA rewards and compound them automatically. This saves users the trouble of needing to manually compound their BANANA.

In practice, liquidity provider (LP) tokens are staked into the Maximizer, which are then staked into the applicable BANANA Farm. BANANA earnings from the Farm are automatically staked into the single-asset BANANA-BANANA Staking Pool, and the resulting BANANA rewards continue to grow with every instance of auto-compounding. 😎

https://apeswap.finance/vaults

How ApeSwap integrated Chainlink Keepers

Once we deployed our “Keepers-compatible” contract, we registered it via the Chainlink Keepers dashboard.

After pasting in the address of the Keeper contract, the Chainlink Keepers Network verified that the contract is Keepers-compatible (see below) and it brought us to the “Register new Upkeep” page.

DISCLAIMER: When ApeSwap integrated Keepers, there was only one option for “Custom Logic”. As of the release of this article, Keepers offers another option for “Time-Based ‘’ Keepers, which don’t require contracts to be “Keepers-compatible”.

Once all the form inputs were filled out, we were able to “Register Upkeep”, which also involved sending a transaction to fund the Keeper with LINK based on the “Starting Balance” provided in the form.

Notes on the inputs…

Gas limit:

It’s important to set this value accurately, or Keeper transactions may not be sent. On the extreme side, if this value is too high, your Keeper may unnecessarily consume a large amount of LINK.

Check data:

This is important to set if you need to pass data into the checkUpkeep function, otherwise it should be left blank.

Creating your Keepers-Compatible Contract

We decided that a simple way to integrate Keepers into the Maximizer Vault contracts would be to create a new contract that extends the original Vault contract.

This approach has several benefits:

  1. The original MaximizerVaultApe contract can be deployed without the Keeper extension if desired.
  2. The new KeeperMaximizerVaultApe contract can access the internal functions from MaximizerVaultApe to be able to provide compound functionality.
  3. The @chainlink KeeperCompatible contract can be imported into this new contract separating concerns from the main vault contract.

Quick Reference Links:

checkUpkeep Function: Runs off-chain at every block to determine if the performUpkeep function should be called on-chain.

The checkUpKeep function was implemented inside the KeeperMaximizerVaultApe contract. We created a helper function inside the main MaximizerVaultApe to assist with this check.

For this implementation, the performData is important and essentially holds swap slippage data to keep compounding losses due to MEV to a minimum. More on this below.

performUpkeep Function: Contains the logic that should be executed on-chain when checkUpkeep returns true.

The performUpkeep function was implemented inside the KeeperMaximizerVaultApe contract alongside checkUpkeep. This function has an important role in first decoding the performData (passed from a Keeper), and second running verification on the decoded data.

In this case, performUpkeep is verifying:

  1. That the data passed contains at least one vault to compound.
  2. That the vault(s) passed for compounding meet one of two requirements:
  3. maxDelay (seconds) has passed since lastCompound
  4. minKeeperFee will be obtained if before maxDelay

Enforcing verification in performUpkeep helps ensure that your Keeper funds will not be abused.

Any key learnings from the process you would like to call out for other devs?

  • Setting the proper gas limit can take a bit of trial and error as the gas limit is set when the Keeper is created and cannot be updated. In our case, the Keeper transactions use variable gas depending on the number of vaults to compound, so we decided to add a fair amount of gas overhead.
  • We did not originally verify the input data in performUpkeep, and went back to it after a review with the Chainlink Labs team. Ensure that you are validating the data passed from the Keeper to performUpkeep to prevent abuse of your funded Keeper.
  • LINK tokens needed for funding Keepers on BNB Chain should be the ERC-677 version. Chainlink has a nice UI if you need to convert LINK tokens on your respective chain: Chainlink Pegswap

What results were achieved from your integration?

Chainlink Keepers removed the requirement for ApeSwap to run and manage a centralized server to send compound transactions.

As a result of integrating Chainlink Keepers, we are saving hundreds of hours of time for our users.

Why ApeSwap chose Chainlink Keepers

We chose Chainlink Keepers as they are fairly easy to implement with well supported documentation and code examples. Chainlink has created a smooth UX with their Keepers interface on both BNB Chain mainnet and testnet to set up and manage Keepers. Chainlink also has a very nice testnet faucet for obtaining LINK to test Keepers. This is a very useful and overlooked developer feature!

About ApeSwap

Whether you’re new to crypto or a DeFi veteran, ApeSwap has the tools and the community to support your decentralized finance needs.

To get started with ApeSwap:

  • Join by interacting with our community, using our DeFi platform, and purchasing our native utility tokens, BANANA and GNANA
  • Swap between different cryptocurrency tokens on BNB Chain, Polygon, and Ethereum using our decentralized exchange
  • Create liquidity between cryptocurrency token pairs to receive liquidity provider (LP) tokens, which can earn trading fees (liquidity mining) and be staked in Yield Farms or Maximizers to earn BANANA
  • Stake BANANA or GNANA in Staking Pools to earn tokens from partner projects
  • Lend and borrow crypto assets with the ApeSwap Lending Network
  • Participate in Initial Ape Offerings for new crypto projects

Crypto projects can partner with ApeSwap to:

  • List their tokens on our decentralized exchange
  • Receive advisory services from our team
  • Network with our robust partnership ecosystem
  • Co-market with us to acquire new users
  • Create Yield Farms to incentivize users to add liquidity for their token on our exchange
  • Raise capital through Initial Ape Offerings and Jungle Bills

About Chainlink Keepers

Automate your smart contracts using Chainlink Keepers, the decentralized and highly reliable smart contract automation service.

Learn more about Chainlink Keepers

Try the App: https://keepers.chain.link/

Documentation: https://docs.chain.link/docs/chainlink-keepers/introduction

--

--

ApeBond

ApeBond is a multichain DeFi Hub offering an accessible, transparent, and secure experience for everyone.