Giter Site home page Giter Site logo

yam-protocol's Introduction

๐Ÿ  YAM Protocol ๐Ÿ 

The Protocol

Yam is an experimental protocol building upon the most exciting innovations in programmable money and governance. Built by a team of DeFi natives, it seeks to create:

โ€ข an elastic supply to seek eventual price stability
โ€ข a governable treasury to further support stability
โ€ข fully on-chain governance to enable decentralized control and evolution from Day 1
โ€ข a fair distribution mechanism that incentivizes key community members to actively take the reins of governance

At its core, YAM is an elastic supply cryptocurrency, which expands and contracts its supply in response to market conditions, initially targeting 1 USD per YAM. This stability mechanism includes one key addition to existing elastic supply models such as Ampleforth: a portion of each supply expansion is used to buy yCurve (a high-yield USD-denominated stablecoin) and add it to the Yam treasury, which is controlled via Yam community governance.

We have built Yam to be a minimally viable monetary experiment, and at launch there will be zero value in the YAM token. After deployment, it is entirely dependent upon YAM holders to determine its value and future development. We have employed a fork of the Compound governance module, which will ensure all updates to the Yam protocol happen entirely on-chain through community voting.

Audits

None. Contributors have given their best efforts to ensure the security of these contracts, but make no guarantees. It has been spot checked by just a few pairs of eyes. It is a probability - not just a possibility - that there are bugs. That said, minimal changes were made to the staking/distribution contracts that have seen hundreds of millions flow through them via SNX, YFI, and YFI derivatives. The reserve contract is excessively simple as well. We prioritized staked assets' security first and foremost.

The original devs encourage governance to fund a bug bounty/security audit

The token itself is largely based on COMP and Ampleforth which have undergone audits - but we made non-trivial changes.

The rebaser may also have bugs - but has been tested in multiple scenarios. It is restricted to Externally Owned Accounts (EOAs) calling the rebase function for added security. SafeMath is used everywhere.

If you feel uncomfortable with these disclosures, don't stake or hold YAM. If the community votes to fund an audit, or the community is gifted an audit, there is no assumption that the original devs will be around to implement fixes, and is entirely at their discretion.

The Token

The core YAM token uses yCRV as the reserve currency, which is roughly a $1 peg. Each supply expansion (referred to as an inflating rebase), a portion of tokens is minted and used to build up the treasury. This treasury is then in complete ownership of YAM holders via governance.

Distribution

Rather than allocating a portion of the supply to the founding team, YAM is being distributed in the spirit of YFI: no premine, no founder shares, no VC interests โ€” simply equal-opportunity staking distribution to attract a broad and vision-aligned community to steward the future of the protocol and token.

The initial distribution of YAM will be evenly distributed across eight staking pools: WETH, YFI, MKR, LEND, LINK, SNX, COMP, and ETH/AMPL Uniswap v2 LP tokens. These pools were chosen intentionally to reach a broad swath of the overall DeFi community, as well as specific communities with a proven commitment to active governance and an understanding of complex tokenomics.

Following the launch of the initial distribution pools, a second distribution wave will be incentivized through a YAM/yCRV Uniswap pool. This pool will allow Uniswap's TWAP-based oracle to provide necessary input as the basis for rebase calculations, as well as provide liquidity for the rebase to purchase yCurve for the treasury.

Rebases

Rebases are controlled by an external contract called the Rebaser. This is comparable to Ampleforth's monetaryPolicy contract. It dictates how large the rebase is and what happens on the rebase. The YAM token just changes the supply based on what this contract provides it.

There are a requirements before rebases are active:
โ€ข Liquid YAM/yCRV market
โ€ข init_twap()
โ€ข activate_rebasing()

Following the launch of the second pool, rebasing can begin its activation phase. This begins with init_twap() on the rebaser contract. Anyone can call this at anytime once there is a YAM/yCRV Uniswap V2 market. The oracle is designed to be 12 hours between checkpoints. Given that, 12 hours after init_twap() is called, anyone can call activate_rebasing(). This turns rebasing on, permanently. Now anyone can call rebase() when inRebaseWindow() == true;.

In a rebase, the order of operations are:
โ€ข ensure in rebase window
โ€ข calculate how far off-price is from the peg
โ€ข dampen the rebase by the rebaseLag
โ€ข if positive calculate protocol mint amount
โ€ข change scaling factor, (in/de)flating the supply
โ€ข sync uniswap, mint, sell to uniswap, transfer excess YAM and bought yCRV to reserves
โ€ข call any extra functions governance adds in the future (i.e. Balancer gulps)

Governance

Governance is entirely dictated by YAM holders from the start. Upon deployment, ownership of all YAM protocol contracts was relinquished to the timelocked Governance contract or removed entirely. At the very least, this can be seen as a reference implementation for a truly decentralized protocol.

Development

Building

This repo uses truffle. Ensure that you have truffle installed. Given the composability aspect of this

Then, to build the contracts run:

$ truffle compile

To run tests, run against a single test package, i.e.:

$ sh startBlockchain.sh
$ truffle migrate --network distribution
$ python scripts/clean.py
$ cd jsLib
$ jest deployment
$ jest token
$ jest rebase
$ jest governance
$ jest governorAlpha
$ jest distribution

The need to run one-by-one seems to be a limitation of jest + ganache.

The distribution tests require specific tokens. These are acquired by using the ganache unlock_account function. If you receive fails, the owner likely decreased their ownership of that token. Just replace any instances of that address with another holder of the token.

Note: some governance tests require a different ganache setup. You will encounter a warning (but not a failed test) if the wrong type of ganache is setup. To run the correct one:

$ sh startBlockchainMining.sh
$ truffle migrate --network distribution
$ python scripts/clean.py
$ cd jsLib
$ jest governance

Attributions

Much of this codebase is modified from existing works, including:

Compound - Jumping off point for token code and governance

Ampleforth - Initial rebasing mechanism, modified to better suit the YAM protocol

Synthetix - Rewards staking contract

YEarn/YFI - Initial fair distribution implementation

yam-protocol's People

Contributors

0xclem avatar brockelmore avatar chezhe avatar clintonbembryjr avatar jaytoday avatar junhoyeo avatar zer0cache avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yam-protocol's Issues

Uniswap Oracle reports incorrect rates for certain YAM token addresses

This line has the reserves out of order. If it is executed, it will cause the oracle to return an incorrect price. This will cause incorrect rebases.

https://github.com/yam-finance/yam-protocol/blob/master/contracts/lib/UniswapV2OracleLibrary.sol#L31

The bug depends on whether the YAM address is numerically higher or lower than the token it's paired with. Therefore it is either activated at deploy time, or never activated. Thankfully it does not seem that this bug was activated on the existing deploys.

It seems to have been caused by a copy-paste error when modifying the Uniswap library. Perhaps consider using the Uniswap library directly.

Fix is simple. Change to FixedPoint.fraction(reserve0, reserve1)._x)

Use Local Memory Type Variable Instead of Global Storage Type Variable in Event to Save Gas

Hi, we recently have conducted a systematic study about Solidity event usage, evolution, and impact, and we are attempting to build a tool to improve the practice of Solidity event use based on our findings. We have tried our prototype tool on some of the most popular GitHub Solidity repositories, and for your repository, we find a potential optimization of gas consumption arisen from event use.

The point is that when we use emit operation to store the value of a certain variable, local memory type variable would be preferable to global storage type (state) variable if they hold the same value. The reason is that an extra SLOAD operation would be needed to access the variable if it is storage type, and the SLOAD operation costs 800 gas.

For your repository, we find that the following event use can be improved:

  • TimeLock.sol
    function name:โ€ƒsetDelay
    event name:โ€ƒโ€ƒNewDelay
    variable:โ€ƒโ€ƒโ€ƒโ€ƒdelay->delay_
    function setDelay(uint256 delay_)
        public
    {
        require(msg.sender == address(this), "Timelock::setDelay: Call must come from Timelock.");
        require(delay_ >= MINIMUM_DELAY, "Timelock::setDelay: Delay must exceed minimum delay.");
        require(delay_ <= MAXIMUM_DELAY, "Timelock::setDelay: Delay must not exceed maximum delay.");
        delay = delay_;

        emit NewDelay(delay);
    }

โ€ƒโ€ƒfunction name:โ€ƒsetPendingAdmin
โ€ƒโ€ƒevent name:โ€ƒโ€ƒNewPendingAdmin
โ€ƒโ€ƒvariable:โ€ƒโ€ƒโ€ƒโ€ƒpendingAdmin->pendingAdmin_

    function setPendingAdmin(address pendingAdmin_)
        public
    {
        // allows one time setting of admin for deployment purposes
        if (admin_initialized) {
          require(msg.sender == address(this), "Timelock::setPendingAdmin: Call must come from Timelock.");
        } else {
          admin_initialized = true;
        }
        pendingAdmin = pendingAdmin_;

        emit NewPendingAdmin(pendingAdmin);
    }

Do you find our results useful? Your reply and invaluable suggestions would be greatly appreciated, and are vital for improving our tool. Thanks a lot for your time!

ETH/AMPL Uniswap v2 LP problems

Hello,
I'm having a bit of a problem staking Uniswap v2 tokens. I seem to be staked but am hardly receiving any rewards.

I actually staked two piles of tokens at around 8pm UTC yesterday. The first pile was about 650 LINK tokens which right now have racked about 30 tokens.

On the other hand, I also staked some ETH/AMPL Uniswap v2 LP tokens which at the time of staking, had a dollar value in the $8,000 range. At this point, it has amassed a whopping 0.000001744 YAM.

At first I thought it was a rebasing issue. The LINK I managed to stake, I believe, right before the rebase. The ETH/AMPL I did a few minutes later and likely landed sometime after the rebase. So I waited to see if things changed over time. It's been over 12 hours and still the same low reward. That is to say, the number has technically increased, but by the same microscopic rate.

Anyone have any ideas what could have gone wrong?

Truffle migrate --network distribution failed because of 6_rewarddistribution.js

Follow the tutorial from github

$ sh startBlockchain.sh
$ truffle migrate --network distribution
$ python scripts/clean.py
$ cd jsLib
$ jest deployment
$ jest token
$ jest rebase
$ jest governance
$ jest governorAlpha
$ jest distribution
6_rewarddistribution.js
=======================
distribution
setting distributor

Error: Returned error: sender account not recognized
    at Object.ErrorResponse (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-core-helpers/src/errors.js:29:1)
    at /usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-core-requestmanager/src/index.js:140:1
    at /usr/local/lib/node_modules/truffle/build/webpack:/packages/provider/wrapper.js:112:1
    at XMLHttpRequest.request.onreadystatechange (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-providers-http/src/index.js:96:1)
    at XMLHttpRequestEventTarget.dispatchEvent (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:1)
    at XMLHttpRequest._setReadyState (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request.js:208:1)
    at XMLHttpRequest._onHttpResponseEnd (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request.js:318:1)
    at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request.js:289:47)
    at IncomingMessage.emit (events.js:327:22)
    at endReadableNT (_stream_readable.js:1201:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)

env:
macos catalina
10.15.5

Truffle v5.1.40 (core: 5.1.40)
Node v13.12.0

unable to withdraw MKR from pool

hi,
yesterday i send some MKR token to the pool but today i'm unable to withdraw them.
when i do a withdraw tx my metamask wallet stuck in pending status, when i search the txid on etherscan it appears like the tx didn't exist.
waiting answer, have a nice day.

Mislabeled maximum scaling factor post-condition

The following error message and comment should say that the check is for if the max scaling factor was set too high.

// make sure the mint didnt push maxScalingFactor too low
require(yamsScalingFactor <= _maxScalingFactor(), "max scaling factor too low");

script/clean.py use absolute path

script/clean.py use absolute path ("/Users/brockelmore/YAM/build/contracts") to target dir.

This is a code that does not work for another.

Floating point in the stake amount input

Trying to input a number like 1000 LEND results to a BigNumber conversion error.

image

This is because somewhere there is 1000 * 10^18 calculated in a floating point.

Never use floating point math with token amounts. Happy to see BigNumber lib catching this error.

image

yarn start failed

ubuntu 1804, x64

/work/smart_contact_language/yam-protocol/yam-www$ yarn start
yarn run v1.22.10
$ react-scripts start

There might be a problem with the project dependency tree.
It is likely not a bug in Create React App, but something you need to fix locally.

The react-scripts package provided by Create React App requires a dependency:

"babel-jest": "^24.9.0"

Don't try to install it manually: your package manager does it automatically.
However, a different version of babel-jest was detected higher up in the tree:

/home/xkm/work/smart_contact_language/yam-protocol/node_modules/babel-jest (version: 26.6.3)

Manually installing incompatible versions is known to cause hard-to-debug issues.

If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That will permanently disable this message but you might encounter other issues.

To fix the dependency tree, try following the steps below in the exact order:

  1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
  2. Delete node_modules in your project folder.
  3. Remove "babel-jest" from dependencies and/or devDependencies in the package.json file in your project folder.
  4. Run npm install or yarn, depending on the package manager you use.

In most cases, this should be enough to fix the problem.
If this has not helped, there are a few other things you can try:

  1. If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead.
    This may help because npm has known issues with package hoisting which may get resolved in future versions.

  2. Check if /home/xkm/work/smart_contact_language/yam-protocol/node_modules/babel-jest is outside your project directory.
    For example, you might have accidentally installed something in your home folder.

  3. Try running npm ls babel-jest in your project folder.
    This will tell you which other package (apart from the expected react-scripts) installed babel-jest.

If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That would permanently disable this preflight check in case you want to proceed anyway.

P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!

error Command failed with exit code 1.

Moving from YAM 1.0 to YAM 2.0

Many people are all asking the same question, can they move their YAM 1.0 tokens over to YAM 2.0 if the project goes ahead and how will this be done. People have suggested an Airdrop for YAM 1.0 Token holders.

It would be useful to the community to let them know!

Likewise, if such an airdrop was to happen in the near future, would the authors create an online form (e.g. Google Forms) where users could send them their Ethereum addresses, along with their token balances - so their tokens could get auto updated to YAM 2.0 quickly and easily.

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.