1

I'm trying to write a smart contract to farm tokens. I would like to make an auto-compounding solution similar to beefy.finance or polycats.

My contract can deposit funds or liquidity into LP mining, and I can autocompound them fine off chain from the backend. However doing something like this would make my solution centralized, and I was hoping to avoid that.

What I want is to call a method at intervals on my smart contract. I think there used be something for the main-net called ethereum-alarm-clock but I've heard the project is dead.

How can I distribute rewards in a decentralized fashion?

I'm open to external protocol such as using an oracle like chain link, but I would prefer to decentralize earning so I do not need to host a backend service. Is this possible?

2 Answers 2

2

Chainlink Keepers is the perfect solution for your use case. They are a decentralized network of off-chain nodes that are incentivized to perform all registered jobs (upkeeps) off chain in a decentralized and trust minimized manner, and can be triggered based upon any pre-configured conditions (such as time or event based conditions).

By using an off-chain decentralized service such as Chainlink Keepers, you extend the security and decentralization properties that the blockchain has out to the off-chain compute layer, instead of relying on a centralized solution such as a service or single node triggering your function

Check out the docs, as well as a recent demo for a good guide on getting your on-chain contract setup to be Keepers-compatible, as well as how to then register your upkeep job on the Keepers Registry

2
  • Wow, I took a guess when I said chain link since I knew they provided external data but this looks promising. By chance do you have a short code example? If not I'll scour the docs and video and try to edit the answer so that it has the information needed
    – johnny 5
    Nov 15, 2021 at 15:22
  • 1
    There's an example contract here that the keeper network will automatically call the performUpkeep function based off a time parameter passed into the contract. So if you pass in 30 seconds, then it will get triggered every 30 seconds docs.chain.link/docs/chainlink-keepers/compatible-contracts Nov 16, 2021 at 0:08
0

This can be done using chainlink keepers. To Summary a simple example from the docs

You can create a keeper compatible contract such as this counter:

import "@chainlink/contracts/src/v0.7/KeeperCompatible.sol";

contract Counter is KeeperCompatibleInterface {
    uint public counter;

    uint public immutable interval;
    uint public lastTimeStamp;

    constructor(uint updateInterval) {
    interval = updateInterval;
    lastTimeStamp = block.timestamp;

    counter = 0;
    }

    function checkUpkeep(bytes calldata /* checkData */) external override returns (bool upkeepNeeded, bytes memory /* performData */) {
        upkeepNeeded = (block.timestamp - lastTimeStamp) > interval;
        // We don't use the checkData in this example. The checkData is defined when the Upkeep was registered.
    }

    function performUpkeep(bytes calldata /* performData */) external override {
        lastTimeStamp = block.timestamp;
        counter = counter + 1;
        // We don't use the performData in this example. The performData is generated by the Keeper's call to your checkUpkeep function
    }
}

Then we just need to register the keeper with the appropriate keepers for the network in my case mumbai keeper

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.