GithubHelp home page GithubHelp logo

pievaults's Introduction

Description

ExperiPie (TPIE++) is a new pool design with unlimited possibilities. The ExperiPie is based on the Diamond standard, this standard ensures contracts can grow beyond their restricted size. (extra info)

Motivation

There are basically two motivations, governance participation and yield farming.

In the current DeFi space there are lot’s of opportunities to participate in governance of various protocols. The ExperiPie uses a very flexible CallFacet which makes it possible to execute any call on behalf of the pool. The ExperiPie will be used to participate in governance protocols to benefit PieDao participants.

Yield farm opportunities can show up any time, not everyone has the liquidity or attention to fulfill every opportunity. Using the ExperiPie everyone can pool their tokens. Through the flexible nature of the pool it is possible to use active governance to take any yield farm opportunity.

See the forum post for more information.

Depends on

https://github.com/mudgen/diamond-2

Call Managers

CallManagers are addresses which are whitelisted to trigger arbitrary calls from the ExperiPie. A whitelisted caller can be added by calling addCaller(_newCaller) on the ExperiPie from the contract owner. ⚠️ This should be used with caution as it allows any token within an ExperiPie to be pulled out ⚠️. Only trusted addresses or smart contracts should be added as callers.

Lending Manager

The lendingManager allows the owner of that instance to withdraw and deposit tokens into lending lending protocols which are whitelisted in the lendingRegistry. The owner of the lendingManager instance can move tokens between whitelisted lending protocols in the lendingRegistry.

For a lending manager to be able to manage a ExperiPie's tokens it needs to be whitelisted as a caller.

The owner of the lending manager instance can lend, unlend and bounce(hopping between protocols).

These functions have the following interface and should be called on the Lending Manager contract.

/**
    @notice Move underlying to a lending protocol
    @param _underlying Address of the underlying token
    @param _amount Amount of underlying to lend
    @param _protocol Bytes32 protocol key to lend to
*/
function lend(address _underlying, uint256 _amount) bytes32 _protocol) public;

/**
    @notice Unlend wrapped token from its lending protocol
    @param _wrapped Address of the wrapped token
    @param _amount Amount of the wrapped token to unlend
*/
function unlend(address _wrapped, uint256 _amount) public;

/**
    @notice Unlend and immediately lend in a different protocol
    @param _wrapped Address of the wrapped token to bounce to another protocol
    @param _amount Amount of the wrapped token to bounce to the other protocol
    @param _toProtocol Protocol to deposit bounced tokens in
*/
function bounce(address _wrapped, uint256 _amount, bytes32 _toProtocol) external;

Lending Registry

The lending registry keeps track of all lending protocols and wrapped tokens. Only tokens and protocols registered in this registry can be used by the LendingManager. Currently supported lending protocols are Compound and Aave.

Contract address: 0xB739Dcf499306B191D9D4fa5255A8f20066a6a96

With the following functions protocols and wrapped tokens can be added:

/**
    @notice Set which protocl a wrapped token belongs to
    @param _wrapped Address of the wrapped token
    @param _protocol Bytes32 key of the protocol
*/
function setWrappedToProtocol(address _wrapped, bytes32 _protocol) external;

/**
    @notice Set what is the underlying for a wrapped token
    @param _wrapped Address of the wrapped token
    @param _underlying Address of the underlying token
*/
function setWrappedToUnderlying(address _wrapped, address _underlying) external;

/**
    @notice Set the logic contract for the protocol
    @param _protocol Bytes32 key of the procol
    @param _logic Address of the lending logic contract for that protocol
*/
function setProtocolToLogic(bytes32 _protocol, address _logic) external;

/**
    @notice Set the wrapped token for the underlying deposited in this protocol
    @param _underlying Address of the unerlying token
    @param _protocol Bytes32 key of the protocol
    @param _wrapped Address of the wrapped token
*/
function setUnderlyingToProtocolWrapped(address _underlying, bytes32 _protocol, address _wrapped) external;

Lending logic contracts

Protocol Key Address
Compound 0x561ca898cce9f021c15a441ef41899706e923541cee724530075d1a1144761c7 0xB9a13E1D9c5dad1557C3B9B20ab99fb0FB16cCA7
Aave 0xa9699be9874dcc3e11474d7d87b44bb314eb412a1960f1478100f7e2ccd4a6eb 0x6Eb123bbd02324600AcF8a53575547EEB0a43135
Cream 0x40e45d329815e79a55e43916f11f7a0112a31146f63a4fcaea413df0567a0bb2 0x280190cF9E6519eB772a2f444fAF080523246DB3
XSushi 0xeafaa563273a4fdf984f5a9f1836dba7d5800658b802d449eb6ee18fce3d7c81 0x38e0eb114BEC4efcD8b1AC2C4b0c7335AFC1491D
YGov 0xf910d6d870f2fa35287ad95c43b0b1ebabfab3cbb469515dc168cd48e2a9c218 0x4c5b1fC5dcE8A96f1eaF1Ffa3d86546c2c939909

Lending logic contracts return the calls needed to lend or unlend from a protocol.

Deploying the factory

npx buidler deploy-pie-factory --network mainnet

Deploying an ExperiPie

  1. Create an allocation file like this one
  2. run npx buidler deploy-pie-from-factory --allocation [PATH_TO_ALLOCATION] --factory [FACTORY_ADDRESS] --network mainnet
  3. Copy the tx hash and search on Etherscan to find the address
  4. Verify the contract: npx buidler verify [PIE_ADDRESS] --constructor-args ./verify/experiPie.js --network mainnet

pievaults's People

Contributors

alexintosh avatar evert0x avatar mickdegraaf avatar mudgen avatar

Stargazers

 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

pievaults's Issues

Exchange rate getter for lending tokens in the ExperiPie

Adds getters to calculate the exchange rate between

User Story

  • As an <audience/user>: developer
  • I want to <action/task>: fetch the exchange rate from the lending adapter.
  • so that <outcome/goal/benefit>: I have a common interface to get the underlying amount for x wrapped tokens and vice versa.

Type

  • Enhancement
  • Maintenance
  • Refactor

Description

The following functions need to be added to each lending adapter:

exchangeRate(address _underlying) external returns(uint256) Gets the exchange rate scaled to 18 decimals.
exchangeRateView(address _underlying) external view returns(uint256) View function returning the exchange rate scaled to 18 decimals

Definition of Done

  • Functions added to CompoundLendingAdapter
  • Functions added to AaveLendingAdapter
  • Functions added to SushiStakingAdapter

Notes

Compound has 2 exchangeRate functions. One is view and the other modifies state.

Implement addStrategyToQueue

User Story

  • As an <audience/user>: PieVault admin
  • I want to <action/task>: add a strategy to the withdrawal queue
  • so that <outcome/goal/benefit>: it can be used when an end user withdraws

Type

  • Enhancement
  • Maintenance
  • Refactor

Description

Definition of Done

  • Implement addStrategyToQueue
  • Unit test addStrategyToQueue

Part of #30
See Yearn implementation

Implement maxAvailableShares

User Story

  • As an <audience/user>: Integrator
  • I want to <action/task>: be able to fetch how much pool tokens can be withdrawn.
  • so that <outcome/goal/benefit>: Can show this to end users

Type

  • Enhancement
  • Maintenance
  • Refactor

Description

Returns the maximum amount of pool tokens that can be withdrawn

Definition of Done

  • Implement maxAvailableShares
  • Unit test maxAvailableShares

Attach files or screenshots if it's helpful for this issue.

Part of #30
See Yearn implementation for reference

Implement updateStrategyMinDebtPerHarvest

User Story

  • As an <audience/user>: PieVault admin
  • I want to <action/task>: Update the minimum amount to harvest
  • so that <outcome/goal/benefit>: There is no gas wasted on overly small harvests

Type

  • Enhancement
  • Maintenance
  • Refactor

Description

Just like Yearn vaults a lower boundry needs to be set on harvests

Definition of Done

  • Implement updateStrategyMinDebtPerHarvest
  • Unit test updateStrategyMinDebtPerHarvest

Part of #30
Partly implemented in yearn-strategy-support

Implement updateStrategyMaxDebtPerHarvest

User Story

  • As an <audience/user>: PieVault admin
  • I want to <action/task>: be able to change the max amount that can be harvested from a strategy
  • so that <outcome/goal/benefit>: Can limit how much is harvested

Type

  • Enhancement
  • Maintenance
  • Refactor

Description

Needed to reach Yearn strategy compatibility

Definition of Done

  • Implemented updateStrategyMaxDebtPerHarvest
  • Unit test updateStrategyMaxDebtPerHarvest

Part of #30
Partly implemted in yearn-strategy-support

Implement addStrategy

User Story

  • As an <audience/user>: PieVault admin
  • I want to <action/task>: be able to add strategies
  • so that <outcome/goal/benefit>: PieVaults can put their capital to work in more diverse ways

Type

  • Enhancement
  • Maintenance
  • Refactor

Description

With this issue implemented the contract owner can add strategies.

Definition of Done

  • addStrategies implemented
  • addStrategies proper ly tested

Partly implemented in feat/yearn-strategy-support
Part of #30

Implement updateStrategyDebtRatio

User Story

  • As an <audience/user>: PieVault admin
  • I want to <action/task>: Be able to adjust the debtRatio of a strategy.
  • so that <outcome/goal/benefit>: I can rebalance how an underlying asset is split out across multiple strategies.

Type

  • Enhancement
  • Maintenance
  • Refactor

Description

The debtRatio determines how much of the underlying a strategy can pull. It's expressed in BPS.

Definition of Done

  • Implement updateStrategyDebtRatio Partially done already in feat/yearn-strategy-support
  • Unit test updateStrategyDebtRatio

Part of #30

Implement setEmergencyShutdown

User Story

  • As an <audience/user>: PieVault admin
  • I want to <action/task>: be able to trigger an emergency shutdown
  • so that <outcome/goal/benefit>: To limit losses in case of emergency

Type

  • Enhancement
  • Maintenance
  • Refactor

Description

In case of emergency a PieVault admin should be able to trigger an emergency shutdown which:

  • Disables minting. (Can be done by setting the cap to 0)
  • Disables adding of new strategies
  • Sets the debt ratio of all strategies to 0

Definition of Done

  • Implement setEmergencyShutdown
  • Unit test setEmergencyShutdown

See Yearn implementation
Part of #30

Implement migrateStrategy

User Story

  • As an <audience/user>: PieVault admin
  • I want to <action/task>: migrate one strategy to another
  • so that <outcome/goal/benefit>: strategies can be upgraded/replaced

Type

  • Enhancement
  • Maintenance
  • Refactor

Description

Should withdraw all assets from one strategy and migrate it to another one.

Definition of Done

  • Implement migrateStrategy
  • Unit test migrateStrategy

Part of #30
See Yearn implementation

Best lending protocol oracle

For a given underlying asset it returns the APR and which lending protocol has the best rate

User Story

  • As an <audience/user>: Dev
  • I want to <action/task>: Have a single interface to determine the best protocol to lend an asset in
  • so that <outcome/goal/benefit>: Can easily create automated yield bouncing strategies

Type

  • Enhancement
  • Maintenance
  • Refactor

Description

Add a function to the lendingRegistry which returns the highest APR for a given _underlying and array of _protocols with the following interface:

getBestApr(address _underlying, bytes[] memory _protocols) external view returns(uint256 apr, bytes32 protocol);

Definition of Done

  • Implemented
  • Tested

Relies on #17

[EPIC] Yearn v2 Strategy Support

Description

Currently the PieVaults only support tokenised positions which severely limits the abilities to productively deploy the underlying assets. Adding support for Yearn strategies allows us to leverage on the great work that has already been done by others.

Initiative / goal

Allow multiple strategies to be added to each asset and emulate interactions with the strategies so they can be used without any changes.

Acceptance criteria and must have scope

External functions

  • addStrategy #31
  • updateStrategyDebtRatio #32
  • updateStrategyMinDebtPerHarvest #33
  • updateStrategyMaxDebtPerHarvest #34
  • updateStrategyPerformanceFee #35
  • revokeStrategy #36
  • Overwrite balance to account for debt in strategies #37
  • setEmergencyShutdown #38
  • setWithdrawalQueue #39
  • maxAvailableShares #40
  • migrateStrategy #41
  • addStrategyToQueue #42
  • removeStrategyFromQueue #43
  • debtOutstanding
  • creditAvailable
  • expectedReturn
  • report

(Will create individual stories for each function)

MISC

  • 100% Unit test coverage of all functionality
  • Integration tests
  • Test with of multiple redeployed preexisting Yearn v2 strategies
  • Audit ready

Stakeholders

@MickdeGraaf, @Alexintosh, Antonio (cannot tag)

Timeline

TBD

Implement revokeStrategy

User Story

  • As an <audience/user>: PieVault admin
  • I want to <action/task>: be able to revoke a strategy by setting the debt limit to 0
  • so that <outcome/goal/benefit>: a strategy can be retired or exited in case of emergency

Type

  • Enhancement
  • Maintenance
  • Refactor

Description

Needed to reach Yearn strategy compatibility

Definition of Done

  • Implement revokeStrategy
  • Unit test revokeStrategy

Part of #30
Partly implemented in yearn-strategy-support

Aave V2 Lending adapter

Add a lending adapter for AaveV2

User Story

  • As an <audience/user>: User
  • I want the <action/task>: the pie I'm holding to also earn yield on Aave v2
  • so that <outcome/goal/benefit>: maximize my earnings

Type

  • Enhancement
  • Maintenance
  • Refactor

Description

Copy the Aave lending adapter and adapt it so it supports AaveV2.

This issue depends on #17 and #18

Definition of Done

  • AaveV2Mock
  • Changes to work with AaveV2
  • Tests run

Links

https://docs.aave.com/developers/change-from-v1-to-v2

Implement setWithdrawalQueue

User Story

  • As an <audience/user>: PieAdmin
  • I want to <action/task>: Set the withdrawal queue
  • so that <outcome/goal/benefit>: So the least profitable or less expensive ones to exit are withdrawn from first when a user withdraws.

Type

  • Enhancement
  • Maintenance
  • Refactor

Description

When a user does a large withdraw, the PieVault will often have to withdraw from strategies. The order in which this happens is determined by the withdrawal queue. Each underlying asset has its own withdrawalQueue.

Definition of Done

  • Implement setWithdrawalQueue
  • Unit test setWithdrawalQueue

Part of #30
See LibStrategyBasketStorage.sol on yearn-strategy-support for the storage structure
See the Yearn implementation as reference

Implement removeStrategyFromQueue

User Story

  • As an <audience/user>: PieVault admin
  • I want to <action/task>: be able to remove a strategy from the withdrawal queue
  • so that <outcome/goal/benefit>: exclude it from being exited on a end user's withdraw

Type

  • Enhancement
  • Maintenance
  • Refactor

Description

Definition of Done

  • Implement removeStrategyFromQueue
  • Unit test removeStrategyFromQueue

Part of #30
See Yearn implementation

APR getters in lending adapters

Add APR getters to the lending adapters

User Story

  • As an <audience/user>: Dev
  • I want to <action/task>: I want to easily fetch the APR on different lending protocols
  • so that <outcome/goal/benefit>: Can write integrations optimizing for APR without repeating code

Type

  • Enhancement
  • Maintenance
  • Refactor

Description

Two functions need to be added to each lending adapter to allow fetch the supply(lending) rate:

  • getAPRFromUnderlying(address _token) external view returns(uint256) Returns the APR when passing the underlying token address for example DAI
  • getAPRFromWrapped(address _token) external view returns(uint256) Returns the APR when passing in the wrapped token for example cDAI

All interest should be returned annualized with 18 decimals. (1e18 == 100% per year)

Definition of Done

  • Functions added to lendingLogicCompound
  • Functions added to lendingLogicAave
  • Functions added to stakingLogicSushi

Important info

Compound/Cream measure interest per Block. In the adapter we need to have a way to set how many blocks there are per year.

Aave keeps track of intrerest in 27 decimals.

Implement updateStrategyPerformanceFee

User Story

  • As an <audience/user>: PieVault admin
  • I want to <action/task>: set the performance fee a strategist receives
  • so that <outcome/goal/benefit>: I can adjust the fee when conditions change

Type

  • Enhancement
  • Maintenance
  • Refactor

Description

Needed to reach compatibility with Yearn strategies

Definition of Done

  • Implement updateStrategyPerformanceFee
  • Unit test updateStrategyPerformanceFee

Part of #30
Partly implemented in yearn-strategy-support

Overwrite balance to account for debt in strategies

User Story

  • As an <audience/user>: User/Integrator
  • I want to <action/task>: The pievault to take into account debt in strategies
  • so that <outcome/goal/benefit>: Entry and exit properly accounts for balances in strategies

Type

  • Enhancement
  • Maintenance
  • Refactor

Description

Needed to be able to support Yearn strategies.

Definition of Done

  • Overwrite balance to account for debt in strategies
  • Unit test above

Part of #30
Partly implemented in yearn-strategy-support

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.