Octover 11, 2023: crvUSD Ape Tutorial π¦π§βπ»
Lesson 1: Quickstart guide to reading crvUSD contracts using Ape Framework
Frens, weβre excited to release the first video in our new $crvUSD tutorial using Apeworx!
OGs may recall the prior Brownie tutorial, which included several examples of how to interact with live contracts around the Curve ecosystem. This includes a lot of great scripts, but unfortunately Brownie has since entered maintenance mode. Itβs last official release was January of this year, and since then itβs had a few community driven pull requests approved, but unfortunately the useful tool is becoming increasingly difficult to work with given the continually advancing state of the EVM and associated web3 tooling.
Fortunately, Brownie enthusiasts have a viable alternative. Ape Framework has a rich and actively maintained codebase that is intended to build from Brownieβs functionality. Their frequently updated documentation even includes a helpful article on migrating your project from Brownie to Ape.
However, despite the helpful resources, we still encounter users who face issues. For example, some users bump into slight issues when trying Ape and give up. Some of the features included natively within Brownie are managed by third-party plugins in Ape, which means documentation can be fragmented.
We thought this presented a good opportunity to release a new tutorial series. We intend to use this tutorial to bundle several answers to ancillary questions we get, such as questions about interacting with $crvUSD or questions about interacting with Curve contracts using technologies like Titanoboa or Foundry. So if you are having any issues in particular, please let us know and weβll feature it in an upcoming video!
This tutorial is intended to be less serialized than our previous Vyper tutorial, in which each lesson built on the prior lesson. For the Ape tutorial, each lesson is intended as a standalone video and accompanying set of code pushed to the Github repository that can be used out of the box, presuming you have a functional Ape environment setup.
The only lesson that may be considered a prerequisite is the first lesson we released today, which is our Ape Quickstart guide for interacting with crvUSD.
In particular, this first lesson is intended to create a resource we couldnβt find anywhere else: a concise set of instructions which can be followed to immediately interact with a forked mainnet, needed for interacting with Curve contracts. Setting up a proper ape-config.yaml file to default to a mainnet fork is the sole omission in the highly useful Brownie to Ape transition guide. This tutorial is intended to serve as a companion to the official article, to quickly get you up and running using Ape.
name: curve_quickstart
plugins:
- name: alchemy
- name: foundry
- name: etherscan
ethereum:
default_network: mainnet-fork
mainnet_fork:
default_provider: foundry
transaction_acceptance_timeout: 600
foundry:
fork:
ethereum:
mainnet:
upstream_provider: alchemy
As you can see, this quickstart utilizes Alchemy, Foundry, and Etherscan plugins. Please note that you must have API keys with Alchemy and Etherscan to work, and have set these in your local environment.
export ETHERSCAN_TOKEN=<your_token>
export WEB3_ALCHEMY_PROJECT_ID=<your_token>
Armed with a correct config file and properly set up environment variables, you can execute just a few lines of code to create a virtual environment and beginning interacting with a forked mainnet in just a few lines of code:
virtualenv ape-venv
source ape-venv/bin/activate
pip install eth-ape
ape init
ape plugins install .
ape run scripts/crvusd_price.py
If you did everything correctly, you can simply give the instructions file exec privileges, and it will correctly echo the current oracle price for crvUSD.
This simple script calls the crvUSD Aggregator Stable Price contract, which is responsible for interpolating the Peg Keepers (future lesson) and returning the official crvUSD price.
from ape import Contract
def main():
crvusd_price_oracle = Contract('0xe5Afcf332a5457E8FafCD668BcE3dF953762Dfe7')
crvusd_price = crvusd_price_oracle.price() / 10 ** 18
print(f"Current Price: {crvusd_price}")
If youβre able to read the crvUSD price by the end of the tutorial, congratulations! Youβre all set up and ready to use ape to interact with the live blockchain!
If you have issues, please do let us know! Weβll continually update this tutorial as you send in comments, so we can make sure that this guide remains a foolproof way to quickly get up and running.
If you have other questions about Ape, crvUSD, or any other aspect of web3 programming, please also drop them in the comments!