Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/orbxball/curve-voter-proxy
https://github.com/orbxball/curve-voter-proxy
Last synced: 21 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/orbxball/curve-voter-proxy
- Owner: orbxball
- License: agpl-3.0
- Created: 2021-03-20T20:12:06.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-05-18T12:53:52.000Z (over 3 years ago)
- Last Synced: 2023-02-27T14:37:08.473Z (over 1 year ago)
- Language: Solidity
- Size: 42 KB
- Stars: 1
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Yearn Strategy Brownie Mix
## What you'll find here
- Basic Solidity Smart Contract for creating your own Yearn Strategy ([`contracts/Strategy.sol`](contracts/Strategy.sol))
- Interfaces for some of the most used DeFi protocols on ethereum mainnet. ([`interfaces/`](`interfaces/`))
- Sample test suite that runs on mainnet fork. ([`tests/`](tests))
This mix is configured for use with [Ganache](https://github.com/trufflesuite/ganache-cli) on a [forked mainnet](https://eth-brownie.readthedocs.io/en/stable/network-management.html#using-a-forked-development-network).
## How does it work for the User
Let's say Alice holds 100 DAI and wants to start earning yield % on them.
For this Alice needs to `DAI.approve(vault.address, 100)`.
Then Alice will call `Vault.deposit(100)`.
Vault will then transfer 100 DAI from Alice to itself, and mint Alice the corresponding shares.
Alice can then redeem those shares using `Vault.withdrawAll()` for the corresponding DAI balance (exchanged at `Vault.pricePerShare()`).
## Installation and Setup
1. [Install Brownie](https://eth-brownie.readthedocs.io/en/stable/install.html) & [Ganache-CLI](https://github.com/trufflesuite/ganache-cli), if you haven't already.
2. Sign up for [Infura](https://infura.io/) and generate an API key. Store it in the `WEB3_INFURA_PROJECT_ID` environment variable.
```bash
export WEB3_INFURA_PROJECT_ID=YourProjectID
```3. Sign up for [Etherscan](www.etherscan.io) and generate an API key. This is required for fetching source codes of the mainnet contracts we will be interacting with. Store the API key in the `ETHERSCAN_TOKEN` environment variable.
```bash
export ETHERSCAN_TOKEN=YourApiToken
```4. Download the mix.
```bash
brownie bake yearn-strategy
```## Basic Use
To deploy the demo Yearn Strategy in a development environment:
1. Open the Brownie console. This automatically launches Ganache on a forked mainnet.
```bash
$ brownie console
```2. Create variables for the Yearn Vault and Want Token addresses. These were obtained from the Yearn Registry. Also, loan the Yearn governance multisig.
```python
>>> vault = Vault.at("0xBFa4D8AA6d8a379aBFe7793399D3DdaCC5bBECBB") # yvDAI (v0.2.2)
>>> token = Token.at("0x6b175474e89094c44da98b954eedeac495271d0f") # DAI
>>> gov = "ychad.eth" # ENS for Yearn Governance Multisig
```3. Deploy the [`Strategy.sol`](contracts/Strategy.sol) contract.
```python
>>> strategy = Strategy.deploy(vault, {"from": accounts[0]})
Transaction sent: 0xc8a35b3ecbbed196a344ed6b5c7ee6f50faf9b7eee836044d1c7ffe10093ef45
Gas price: 0.0 gwei Gas limit: 6721975
Flashloan.constructor confirmed - Block: 9995378 Gas used: 796934 (11.86%)
Flashloan deployed at: 0x3194cBDC3dbcd3E11a07892e7bA5c3394048Cc87
```4. Approve the strategy for the Vault. We must do this because we only approved Strategies can pull funding from the Vault.
```python
# 1000 DAI debt limit, no rate limit, 50 bps strategist fee
>>> vault.addStrategy(strategy, Wei("1000 ether"), 2 ** 256 - 1, 50, {"from": gov})
Transaction sent: 0xa70b90eb9a9899e8f6e709c53a436976315b4279c4b6797d0a293e169f94d5b4
Gas price: 0.0 gwei Gas limit: 6721975
Transaction confirmed - Block: 9995379 Gas used: 21055 (0.31%)
```5. Now we are ready to put our strategy into action!
```python
>>> harvest_tx = strategy.harvest({"from": accounts[0]}) # perform as many time as desired...
```## Implementing Strategy Logic
[`contracts/Strategy.sol`](contracts/Strategy.sol) is where you implement your own logic for your strategy. In particular:
* Create a descriptive name for your strategy via `Strategy.name()`.
* Invest your want tokens via `Strategy.adjustPosition()`.
* Take profits and report losses via `Strategy.prepareReturn()`.
* Unwind enough of your position to payback withdrawals via `Strategy.liquidatePosition()`.
* Unwind all of your positions via `Strategy.exitPosition()`.
* Fill in a way to estimate the total `want` tokens managed by the strategy via `Strategy.estimatedTotalAssets()`.
* Migrate all the positions managed by your strategy via `Strategy.prepareMigration()`.
* Make a list of all position tokens that should be protected against movements via `Strategy.protectedTokens()`.## Testing
To run the tests:
```
brownie test
```The example tests provided in this mix start by deploying and approving your [`Strategy.sol`](contracts/Strategy.sol) contract. This ensures that the loan executes succesfully without any custom logic. Once you have built your own logic, you should edit [`tests/test_flashloan.py`](tests/test_flashloan.py) and remove this initial funding logic.
See the [Brownie documentation](https://eth-brownie.readthedocs.io/en/stable/tests-pytest-intro.html) for more detailed information on testing your project.
## Debugging Failed Transactions
Use the `--interactive` flag to open a console immediatly after each failing test:
```
brownie test --interactive
```Within the console, transaction data is available in the [`history`](https://eth-brownie.readthedocs.io/en/stable/api-network.html#txhistory) container:
```python
>>> history
[,
]
```Examine the [`TransactionReceipt`](https://eth-brownie.readthedocs.io/en/stable/api-network.html#transactionreceipt) for the failed test to determine what went wrong. For example, to view a traceback:
```python
>>> tx = history[-1]
>>> tx.traceback()
```To view a tree map of how the transaction executed:
```python
>>> tx.call_trace()
```See the [Brownie documentation](https://eth-brownie.readthedocs.io/en/stable/core-transactions.html) for more detailed information on debugging failed transactions.
## Known issues
### No access to archive state errors
If you are using Ganache to fork a network, then you may have issues with the blockchain archive state every 30 minutes. This is due to your node provider (i.e. Infura) only allowing free users access to 30 minutes of archive state. To solve this, upgrade to a paid plan, or simply restart your ganache instance and redploy your contracts.
# Resources
- Yearn [Discord channel](https://discord.com/invite/6PNv2nF/)
- Brownie [Gitter channel](https://gitter.im/eth-brownie/community)