Code Monkey home page Code Monkey logo

multi-rewards's Introduction

multi-rewards

A modified version of the Synthetix staking rewards contract, allowing for multiple rewards tokens. Designed for use with Curve.fi liquidity gauges.

Overview

The MultiRewards contract in this repository enables distribution of multiple reward tokens for staked users. It is a flattened and modified version of the SNX staking rewards contract.

How it Works

As an example, assume we desire users to stake an ERC20 Token Base Token ($BASE). As a reward for staking their token, we may wish to offer users multiple different tokens. For the sake of this example, we'll assume we have two different amount of governance tokens, Reward Token 1 ($ONE) and Reward Token 2 ($TWO), which we want to release over different schedules.

  • We begin by deploying the MultiReward contract with a link to $BASE as our staking token.
  • For both token $ONE and $TWO the contract's Owner calls addReward
    • When calling addReward, Owner also specifies the duration of the reward period (in seconds)
    • The addReward function also authorizes a Distributor to further manage the reward token.
  • To begin the reward period, Distributor will call notifyRewardAmount, which transfers the specified amount of reward tokens from their address to the contract and begins the reward cycle.
  • Users can stake the $BASE token by calling stake, and will then accrue $ONE and $TWO throughout the duration of the rewards period.
  • Users can claim their rewards at any time by calling getReward.
  • Users can also withdraw their $BASE token at any point by calling withdraw. At this point they can still claim any accumulated unclaimed $ONE and $TWO rewards through the getReward endpoint but will not longer accrue rewards.

Considerations

Keep the following in mind when using the MultiReward contract

  • The duration and amounts of $ONE and $TWO may be different, and the contract will support any number of additional tokens you may wish to provide.
  • The Distributor may update the duration of the reward schedule by calling setRewardsDuration only after the active reward cycle has completed.
  • The Owner may assign a new Distributor to a reward token at any time.
  • Calling exit combines both getReward and withdraw in one endpoint.
  • While the rewards period is active, the contract will automatically update all reward balances anytime most mutative functions are called (stake, withdraw, exit, getReward, or notifyRewardAmount)
  • The Owner may call recoverERC20 to transfer reward tokens, but not the staking token. Claiming rewards may fail if this function drains the balance.
  • In order to transfer ERC20 tokens to the contract, you must first call the approve function on the token's contract and authorize the MultiRewards contract to transfer the correct amount.

Dependencies

Usage

Prior to using these scripts you may wish to review the Brownie documentation on Account management.

Testing

Testing is performed in a forked mainnet environment. The test suite is broadly split between unit and integration tests.

In order to run tests, make sure the "brownie-token-tester" library is installed into the tests/ directory

To run the unit tests:

brownie test tests/unitary

To run the integration tests (this might take a while):

brownie test tests/integration

Deployment

To deploy the contracts, first modify the deployment script to unlock the account you wish to deploy from. Then:

brownie run deploy --network mainnet

License

The smart contract within this repository is forked from Synthetixio/synthetix which is licensed under the MIT License.

This repository is licensed under the MIT License.

multi-rewards's People

Contributors

iamdefinitelyahuman avatar zcor avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.