This repo was created when I started learning Vyper. I thought I will proceed in a systematic way and kind of log it as a repo, as I go from simple to more complex code bases.
I put some extra time and effort to make this repo look more nicer for others who are getting into learning Vyper. I added many comments(which probably aren't needed for an advanced developer, but would be appreciated by a beginner) whenever possible with this wider-base of developers in mind.
The directory all_contracts
contain several sub-directories, each of which deals with an independent codebase. Most of them are translations of existing solidity code bases(some created by myself and some from others). Most of the directories contain two folders. One for contracts and another for tests.
I believe this repo will be useful for anyone who is getting into learning Vyper. For someone who doesn't know Python will especially appreciate this repo more.
All the tests use Titanoboa, a vyper interpreter cutely known as Boa
.
Also the tests use Pytest
, which is a Python testing framework. You can have a quick walkthrough of Pytest from here.
I suggest that you do all installations and development work in a virtual environment so as to not mess up the system config accidentally.Using a venv allows you to avoid installing Python packages globally which could break system tools or other projects.
- Start by creating a virtual environment
sudo python3 -m venv venv_name #venv_name is the name of the venv.
- Activate the created virtual environment
source venv_name/bin/activate #enter the venv.
- In case you want to stop the venv and delete it to start over you can run the following commands
deactivate #exit it
sudo rm -rf venv_name #delete it
- Install the latest Titanoboa(dev version) in the virtual environment
pip install git+https://github.com/vyperlang/titanoboa
- To run test(s), go to the particular directory in which the test files are located and run one of the following commands:
pytest test/ #run all tests
pytest test/ -s #run all tests and show detailed log statements
pytest -k <substring> test/ -v #run tests matching the particular substring
- Detailed gas report can be generated by:
pytest test/ --gas-profile
- Detailed coverage report can be generated by following the steps here.
This is super simple vyper code. The only reason I added this to repo is that its my first vyper contract. Or more correct to say that this is what I tested the first time in Vyper and Boa.
This is from the solidity repo I created when I was following Patrick's Foundry course. This contract allows users(funders) to fund a particular contract with native token. The accumulated tokens can be withdrawn by the owner of the contract anytime. There is a minimum amount of dollars worth of tokens one has to deposit funds successfully.
I have almost fully converted the solidity codes available in that repo to vyper.
This lets anyone create a payment splitter contract via a factory contract. The user can pass on a set of addresses and shares of each of those addresses in the contract funds. The funds are added by the owner of the splitter contract at creation time. After a period of 7 days, the unwithdrawn funds can be withdrawn by the owner. If all the accounts did exercise their right to withdraw, the contract should have zero funds left.
The factory contract takes a fixed fee in eth when a user creates a splitter contract. The owner of the factory can change the fee, but it becomes effective only after a minimum of 10 blocks.
Same as Payment splitter(#3), but instead of a blueprint method, ERC 1167 proxies are used here. Since we cannot set anything inside the constructor, we had to use state variables. This adds gas costs for the users. I have implemented it to show the difference in both approaches. The testbench remains almost the same in both.