@1inch/farming 中文文档教程

发布于 3年前 浏览 30 项目主页 更新于 3年前

1inch network

Farming contracts

构建状态Coverage Status

About

这个存储库提供了 2 种耕作方式(奖励)。 强烈建议通过从 ERC20Farmable 智能合约派生它们来使用池/共享/实用程序令牌的第二个选项。 如果为时已晚,您还应该考虑第一个选项:

  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

或者

$ yarn add @1inch/farming

Usage

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

安装后,您可以通过导入来使用库中的合同。 只需使用 ERC20Farmable 而不是 ERC20 来派生自:

pragma solidity ^0.8.0;

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

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

Optimizations

  • 存储访问:

    • 1 个用于农业参数的存储槽,仅在农业重启时更新: <代码>坚固性 uint40 公共完成; uint32 公共持续时间; uint184 公共奖励;

    • 1 个存储槽 用于农业状态,已更新仅在改变农业代币数量时: <代码>坚固性 uint40 公共检查点; uint216 public farmedPerTokenStored;

    • 每个农民有 1 个存储位,根据存款更新/withdrawals(感谢 @snjax):

      mapping(address => int256) public corrections;
      
  • 紧凑的地址数组用于存储每个用户/钱包的农场。 数组长度存储在第一个数组项的高位:

1inch network

Farming contracts

Build StatusCoverage 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: solidity uint40 public finished; uint32 public duration; uint184 public reward;

    • 1 storage slot for farming state, updated only on changing number of farming tokens: solidity 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:

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文