• Stars
    star
    173
  • Rank 220,124 (Top 5 %)
  • Language
    Solidity
  • Created over 2 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Foundry template to compile and test Vyper contracts.

Foundry x Vyper

A Foundry template to compile and test Vyper contracts.


                       ,,,,,,,,,,,,,                        ,,,,,,,,,,,,
                        *********///.         ////        ,//********** 
                         ,****,*//////       //////      //////******.  
                           ****////////    /////////    ////////****    
                            *//////////// /////////// ////////////*     
                              //////////##///////////#(//////////       
                               ////////####(///////(####////////        
                                ,////(#######/////#######(////          
                                  //##########//(##########//           
                                   (###########&###########*            
                                     #########&&&#########              
                                      ######&&&&&&&#####(               
                                        ###&&&&&&&&&###                 
                                         %&&&&&&&&&&&%                  
                                          %&&&&&&&&&.                   
                                            &&&&&&&                     
                                             %&&&*                      
                                               &


Installation / Setup

To set up Foundry x Vyper, first make sure you have Vyper installed.

Then set up a new Foundry project with the following command (replacing vyper_project_name with your new project's name).

forge init --template https://github.com/0xKitsune/Foundry-Vyper vyper_project_name

Now you are all set up and ready to go! Below is a quick example of how to set up, deploy and test Vyper contracts.



Compiling/Testing Vyper Contracts

The VyperDeployer is a pre-built contract that takes a filename and deploys the corresponding Vyper contract, returning the address that the bytecode was deployed to. If you want, you can check out how the VyperDeployer works under the hood. Below is a quick example of how to setup and deploy a SimpleStore contract written in Vyper.

SimpleStore.Vyper

Here is a simple Vyper contract called SimpleStore.Vyper, which is stored within the Vyper_contracts directory. Make sure to put all of your .Vyper files in the Vyper_contracts directory so that the Vyper compiler knows where to look when compiling.

val: uint256

@external
def store(_val: uint256):
    self.val = _val

@external
def get() -> uint256:
    return self.val

SimpleStore Interface

Next, you will need to create an interface for your contract. This will allow Foundry to interact with your Vyper contract, enabling the full testing capabilities that Foundry has to offer.

interface SimpleStore {
    function store(uint256 val) external;
    function get() external returns (uint256);
}

SimpleStore Test

First, the file imports ISimpleStore.sol as well as the VyperDeployer.sol contract.

To deploy the contract, simply create a new instance of VyperDeployer and call VyperDeployer.deployContract(fileName) method, passing in the file name of the contract you want to deploy. Additionally, if the contract requires constructor arguments you can pass them in by supplying an abi encoded representation of the constructor arugments, which looks like this VyperDeployer.deployContract(fileName, abi.encode(arg0, arg1, arg2...)).

In this example, SimpleStore is passed in to deploy the SimpleStore.vy contract. The deployContract function compiles the Vyper contract and deploys the newly compiled bytecode, returning the address that the contract was deployed to. Since the SimpleStore.vy takes one constructor argument, the argument is wrapped in abi.encode() and passed to the deployContract function as a second argument.

The deployed address is then used to initialize the ISimpleStore interface. Once the interface has been initialized, your Vyper contract can be used within Foundry like any other Solidity contract.

To test any Vyper contract deployed with VyperDeployer, simply run forge test. Since ffi is set to true in the foundry.toml file, you can run forge test without needing to pass in the --ffi flag. You can also use additional flags as you would with any other Foundry project. For example: forge test -f <url> -vvvv.

import "../../lib/ds-test/test.sol";
import "../../lib/utils/VyperDeployer.sol";

import "../ISimpleStore.sol";

contract SimpleStoreTest is DSTest {
    ///@notice create a new instance of VyperDeployer
    VyperDeployer vyperDeployer = new VyperDeployer();

    ISimpleStore simpleStore;

    function setUp() public {
        ///@notice deploy a new instance of ISimplestore by passing in the address of the deployed Vyper contract
        simpleStore = ISimpleStore(
            vyperDeployer.deployContract("SimpleStore", abi.encode(1234))
        );
    }

    function testGet() public {
        uint256 val = simpleStore.get();

        require(val == 1234);
    }

    function testStore(uint256 _val) public {
        simpleStore.store(_val);
        uint256 val = simpleStore.get();

        require(_val == val);
    }
}

Other Foundry Integrations

More Repositories

1

solstat

A Solidity static analyzer to identify contract vulnerabilities and gas efficiencies.
Rust
423
star
2

EVM-Book

A collection of EVM related information.
321
star
3

cfmms-rs

The predecessor to `amms-rs`. CFMM lib built in Rust enabling pair syncing and swap simulation with pools on Ethereum.
Rust
274
star
4

uniswap-v3-math

Rust
242
star
5

Ghost-Contract

A minimalistic contract to execute a payload and make the code size of the msg.sender appear to be 0.
Solidity
138
star
6

Tour-of-ethers-rs

A comprehensive walkthrough of all the nooks and crannies ethers-rs has to offer.
96
star
7

EVM-Gas-Optimizations

A collection of gas optimizations for the EVM.
90
star
8

sstan

Solidity static analyzer
Rust
80
star
9

Foundry-Huff

A Foundry template to compile and test Huff contracts.
Solidity
52
star
10

bid_ask_service

Rust
45
star
11

evm-mnemonic

A barebones framework for hand tuned smart contracts in pure opcodes.
Rust
45
star
12

EVM-Puzzles-Walkthrough

39
star
13

openai-rs

A simple and efficient wrapper around the OpenAI API
Rust
28
star
14

gas-lab

A quick and easy way to test gas optimizations.
Solidity
27
star
15

burn_operation

Securely wipe your computer at the speed of light.
Rust
26
star
16

Optimized-Merkle-Proof

Solidity
17
star
17

solstat-reports

Smart contract audit / optimization reports generated by solstat.
Solidity
14
star
18

discord-openai

Discord x OpenAI bot
Rust
14
star
19

magglob-rs

Modular aggregated order book for CeFi exchanges
Rust
14
star
20

Optimized-Patricia-Tree

A modern, optimized Merkle Patricia Trie implementation.
Solidity
10
star
21

HFT-Research

8
star
22

ethers-throttle

A lightweight wrapper for ethers providers to throttle requests.
Rust
6
star
23

A-Journey-To-The-Center-Of-The-Node

A detailed walkthrough into the black box of node clients.
5
star
24

Reproducible-Go-Binaries

Makefile
5
star
25

casol

A hyper optimized chess engine.
Rust
5
star
26

geth-ipc-rpc-bench

Benchmarks comparing Geth's IPC and RPC endpoints.
Go
4
star
27

world-id-relay

State bridge relay for WorldID
Rust
2
star
28

tx-relay

Rust
2
star
29

RussianRoulette

Solidity
1
star
30

tx-monitor

Rust
1
star
31

Easy-Kali

Python
1
star