Skip to content

SevenSwen/farming

 
 

Repository files navigation

1inch network

Farming contracts

Build Status Coverage Status

About

This repository offers 2 ways to have farming (incentives). Highly recommend to use second option for pools/share/utility tokens by deriving them from ERC20Farmable smart contract. If it's too late you should consider first option as well:

  1. FarmingPool.sol offers smart contract where you can stake/deposit specific tokens to get continiously distributed rewards.
  2. ERC20Farmable.sol allows derived tokens to have farming without necessarity to stake/deposit token into pool. Moreover it allows to have multiple farmings simultaneously and setup new farms permissionlessly.

Installation

!!! NOTICE: WAIT UNTILL FULLY AUDITED !!!

$ npm install @1inch/farming

or

$ yarn add @1inch/farming

Usage

!!! NOTICE: WAIT UNTILL FULLY AUDITED !!!

Once installed, you can use the contracts in the library by importing them. Just use ERC20Farmable instead of ERC20 to derive from:

pragma solidity ^0.8.0;

import "@1inch/farming/contracts/ERC20Farmable.sol";

contract AMMPoolToken is ERC20Farmable {
    constructor() ERC20("AMMPoolToken", "AMM") {
    }
}

Optimizations

  • Storage access:
    • 1 storage slot for farming params, updated only on farming restarting:

      uint40 public finished;
      uint32 public duration;
      uint184 public reward;
    • 1 storage slot for farming state, updated only on changing number of farming tokens:

      uint40 public checkpoint;
      uint216 public farmedPerTokenStored;
    • 1 storage slot per each farmer, updated on deposits/withdrawals (kudos to @snjax):

      mapping(address => int256) public corrections;
  • Compact address array is used for storing farms per user/wallet. Array length is stored in high bits of the first array item:

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 82.6%
  • Solidity 17.4%