Giter Site home page Giter Site logo

vault-v2's Introduction

Yield Protocol Vault v2

The Yield Protocol Vault v2 is a Collateralized Debt Engine for zero-coupon bonds, loosely integrated with YieldSpace Automated Market Makers, as described by Dan Robinson and Allan Niemerg.

Smart Contracts

A longer description of the smart contracts can be found in the Yield v2 reference.

Oracles

Oracles return spot prices, borrowing rates and lending rates for the assets in the protocol.

Join

Joins store assets, such as ERC20 or ERC721 tokens.

FYToken

FYTokens are ERC20 tokens that are redeemable at maturity for their underlying asset, at an amount that starts at 1 and increases with the lending rate (chi).

Cauldron

The Cauldron is responsible for the accounting in the Yield Protocol. Vaults are created to contain borrowing positions of one collateral asset type against one fyToken series. The debt in a given vault increases with the borrowing rate (rate) after maturity of the associated fyToken series.

When the value of the collateral in a vault falls below the value of the borrowed fyToken, the vault can be liquidated.

Ladle

The Ladle is the gateway for all Cauldron integrations, and all asset movements in and out of the Joins (except fyToken redemptions). To implement certain features the Ladle integrates with YieldSpace Pools.

Ladle recipe cookbook.

Wand

The Wand bundles function calls into governance actions.

Witch

The Witch is the liquidation engine for the Yield Protocol Vault v2.

Warning

This code is provided as-is, with no guarantees of any kind.

Pre Requisites

Before running any command, make sure to install dependencies:

$ yarn

Lint Solidity

Lint the Solidity code:

$ yarn lint:sol

Lint TypeScript

Lint the TypeScript code:

$ yarn lint:ts

Coverage

Generate the code coverage report:

$ yarn coverage

Test

Be sure to have an .env file located at packages/foundry with the value MAINNET_RPC=<your rpc url> to be used for forked tests.

Compile and test the smart contracts with Foundry:

$ cd packages/foundry
$ forge test

Additional tests can be run with Hardhat using npm or yarn:

$ cd packages/hardhat
$ npm run hardhat:test

Bug Bounty

Yield is offering bounties for bugs disclosed to us at [email protected]. The bounty reward is up to $500,000, depending on severity. Please include full details of the vulnerability and steps/code to reproduce. We ask that you permit us time to review and remediate any findings before public disclosure.

License

All files in this repository are released under the GPLv3 license.

vault-v2's People

Contributors

3sggpq8h avatar alcueca avatar alfredopalhares avatar aniemerg avatar brucedonovan avatar calnix avatar danrobinson avatar davidbrai avatar dependabot[bot] avatar devtooligan avatar egillh210 avatar eihcir0 avatar gakonst avatar iamsahu avatar omarish avatar sabnock01 avatar sblowpckcr avatar uivlis avatar ultrasecreth avatar yshssh 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

vault-v2's Issues

Better error codes

Put error messages in a spreadsheet for reference, and come with consistent codes for them.

Import yield-utils-v2-2.2.1

Remove all dependencies from yield-utils, now the relevant functionality is available in yield-utils-v2.

Do this after Multicall has been removed.

Consider making all functions in Cauldron operate in any Vault, and be restricted

Only authorized contracts would be able to operate with Cauldron, and these contracts would be the ones verifying that the caller has rights to the vault.

This architecture would make trivial implementing a multicall router.

This would also allow to create the circuit breakers using AccessControl, which would save some gas.

Draft proxy to roll debt

Consider whether to implement this in Ladle, or on its own.

If on its own, do we make Ladle a platform registry of Joins and Pools? Do we make standalone registries? Do we duplicate the records?

Complete the roll function here once you can flash borrow from Joins

  1. Flash loan base from Join (can also just take it and return it at the end instead, no callbacks)
  2. Buy fyToken1 from pool1 - amount equal to debt to roll
  3. Buy base from pool2 - output equal to new debt
  4. Adjust vault with roll.

Liquidation conditions

Currently, Cauldron allows liquidators to operate on the vaults in liquidation under the condition that the collateralization level improves with each operation.

However, Cauldron doesn't check that the liquidator actually has moved any assets. A malicious liquidator can just set the debt of a vault to zero. It can also take assets from the Joins via the Ladle.

I would suggest removing that condition from the Cauldron and instead make sure that Liquidation engines are thoroughly vetted (as a new Ladle would be) and treated as core contracts.

Agree?

Merge stirFrom and stirTo

Too much complexity to just add vault caching. Disable vault caching for stir and merge it back into one function

Make Delegable.sol more flexible

Some or all of:

  • revokeDelegateWithSignature
  • renounceDelegation
  • onlyWithSignature
  • addPartialDelegate (for only certain functions, maybe pack up to 8 of them in a bytes32)

Implement flash loans on Join

ERC3156, with no fee for auth borrowers.

function flashLoan(...) calls _flashLoan(..., feeFactor) with factor equal to a state variable.
function flashLoanNoFee(...) auth calls _flashLoan(..., feeFactor = 0)

Implement `serve` as borrow and sell for base

Include a list of pools in the Ladle, and then calling serve will borrow straight into the pool, selling the fyToken for base into the caller's address.

Implement a Mock Pool to test.

What is allowed when undercollateralized?

With an undercollateralized vault, it is only allowed to stir it if the operation brings it back to a healthy collateralization ratio (and only if you are faster than the liquidation bots).

Should we allow operating with an undercollateralizated vault, but with the condition that the collateralization level only improves?

It seems to me quite worthless.

Rename `stir` to `pour`, and `shake` to `stir`

So Ladle will have:

  • ladle.stir -> move collateral between vaults
  • ladle.pour -> move collateral and/or fyTokens between a user and his vaults. Incurs or repays debt if moving fyTokens.
  • ladle.close -> repay debt with base at a 1:1 ratio. Can move collateral at the same time.
  • ladle.serve -> pour, but any fyToken gets converted to/from base in a pool, so the user never holds fyToken, and the Cauldron never receives base.

Implement EthJoin

It will be tightly integrated with Ladle, so that users still call the same contract.

It might require an extra mapping of Join to Collateral, so that we can accept several tokens (Eth, WETH9, WETH10) for a single collateral (ETH-A).

It might come useful later on if there are any other wrapped tokens we want to accept.

Consider one msg.sender check per multicall

Multicall could check that the user owns the vault and if successful SSTORE a flag.

Then all Ladle functions would be called with a parameter instructing then to check the flag, instead of reading from Cauldron.

At the end, multicall deletes the flag.

It would save a CALL per call after the first.

Remove Multicall

We are running out of space in Ladle, and removing Multicall is the best option.

New functions can be added in batch for vault management. A give in a batch must be in the last position. A tweak resets the cached series.

roll needs to be added to batch.

If we run out of space, it will be time to remove some of the public functions (and refactor tests accordingly).

Make sure transfers are safe

A number of projects use SafeTransfer contracts or libraries to deal with non-standard ERC20 and the like. What should we do?

Is auction formula related to collateralization ratio?

The price formula for the auctions waws designed thinking on a 150% collateralization ratio. It starts by selling half the collateral for all the debt, and moves linearly until it offers all collateral for all the debt.

Should it change for vaults with different collateralization ratios, like 100% or 200%?

Free airdropped assets from Join

It is possible that Join contracts may receive airdropped assets. There should be a governance controlled function that permits withdrawal of these assets.

Onboard spot oracles

  • Create IOracle interface
  • oracle.spot returns a RAY (27 decimals)
  • Create mock oracle (test in 011_oracle.ts)
  • Add oracle to Vat (test in 051_vat_build.ts)
  • Uncomment and test value (in 052_vat_level.ts, ask about fixed point math)

Pass the amount to the oracles

If instead of pulling a price from an oracle, we push an amount, we can implement NFT oracles. The ink of a vault would be an amount for an ERC20, an id for an NFT.

Roll mature debt

Find base debt B1
Mint B12 into P2
Buy B1 into J1 from P2, finding fyToken debt F2
Roll F1 -> F2
Roll S1 -> S2
Retrieve B1
2 - F2 into FYToken2
Burn B1*2 - F2 in FYToken2

Introduce fees

The fees might be implemented as an extra amount of fyToken that gets minted into a governance account whenever fyToken are minted (meaning, users borrow)

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.