1.0.53 • Published 2 years ago

@unizen-io/unizen-dmas v1.0.53

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

unizen-dmas

Smart contracts of the Dynamic Multi Asset Staking (DMAS) of Unizen.

A modified version of the Synthetix and Curve.fi staking rewards contracts, allowing for multiple rewards tokens.

Overview

The Staking contract in this repository enables distribution of multiple reward tokens for staked users. It is a flattened and modified version of the Curve.fi 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 Staking 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)
  • To begin the reward period, Owner 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 Staking 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 Owner may update the duration of the reward schedule by calling setRewardsDuration only after the active reward cycle has completed.
  • While the rewards period is active, the contract will automatically update all reward balances anytime most mutative functions are called (stake, withdraw, , 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 Staking to transfer the correct amount.

Configuration of .env file

To see the mnemonic or seed phrase in Metamask, follow this instruction.

The Metamask account (mnemonic in the .env) needs to have enough funds in the network where you want to interact with the smart contracts.

To add test funds:

cp .env.example .env
vi .env # add an account's mnemonic and an Infura API key

Deploying the smart contracts to the Hardhat local network

yarn install
yarn build
yarn hardhat:node

Deploying the membership system smart contracts to the Rinkeby test network

yarn install
yarn build
yarn deploy:rinkeby

Publishing to NPM

npm login
yarn publish --access public

Creating test reward pools

yarn create-reward-pools

Integrating the project into a Dapp (e.g. create-react-app or Next.js)

Installing via npm package:

yarn add @unizen-io/unizen-dmas

Import in a UI component like so:

import { UZStakingV1, UZStakingV1__factory } from "unizen-dmas";
1.0.53

2 years ago

1.0.49

2 years ago

1.0.51

2 years ago

1.0.50

2 years ago

1.0.52

2 years ago

1.0.48

2 years ago

1.0.46

2 years ago

1.0.45

2 years ago

1.0.44

2 years ago

1.0.39

2 years ago

1.0.38

2 years ago

1.0.40

2 years ago

1.0.42

2 years ago

1.0.41

2 years ago

1.0.37

2 years ago

1.0.36

2 years ago

1.0.35

2 years ago

1.0.29

2 years ago

1.0.33

2 years ago

1.0.32

2 years ago

1.0.31

2 years ago

1.0.30

2 years ago

1.0.34

2 years ago

1.0.28

2 years ago

1.0.27

3 years ago

1.0.19

3 years ago

1.0.18

3 years ago

1.0.22

3 years ago

1.0.21

3 years ago

1.0.20

3 years ago

1.0.26

3 years ago

1.0.25

3 years ago

1.0.24

3 years ago

1.0.23

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago