Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move deployer to src so we can install with forge install #1

Open
PatrickAlphaC opened this issue Aug 6, 2022 · 4 comments
Open

Move deployer to src so we can install with forge install #1

PatrickAlphaC opened this issue Aug 6, 2022 · 4 comments

Comments

@PatrickAlphaC
Copy link

Potentially have the vyperlang org fork this? Would be cool to contribute to this there.

Thoughts?

@PatrickAlphaC
Copy link
Author

And maybe change the name to foundry-vyper

In any case, let me know if you want some help supporting this, happy to help

@PatrickAlphaC
Copy link
Author

Sort of just leaving notes here, sorry.

Let me know if you like some of the changes: https://github.com/PatrickAlphaC/foundry-vyper

@0xKitsune
Copy link
Owner

Hey, yeah I would be more than happy to integrate this into the Vyperlang org. Thats actually what we did for the Huff language org as well.

Enabling installation with forge install is a great idea, I'm open to anything that makes the repo more accessible/easy to use.

I checked out your fork and the readme looks solid. I would be happy to merge your fork and work together on it. If the Vyperlang org would like it under their account, I am more than happy to port to a version over there or migrate this repo over.

@0xClandestine
Copy link

Sort of just leaving notes here, sorry.

Let me know if you like some of the changes: https://github.com/PatrickAlphaC/foundry-vyper

Hey after taking a look I've got a few suggestions, first I think we should change the name of VyperDeployer.sol -> VyperTest.sol and rewrite the file to look something like this:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "forge-std/Test.sol";

abstract contract VyperTest is Test {

    function compileVyper(
        string memory fileLocation
    ) public returns (bytes memory byteCode) {
        string[] memory cmds = new string[](2);
        cmds[0] = "vyper";
        cmds[1] = fileLocation;
        return vm.ffi(cmds);
    }

    function compileVyper(
        string memory fileLocation, 
        bytes memory args
    ) public returns (bytes memory byteCodeWithArgs) {
        string[] memory cmds = new string[](2);
        cmds[0] = "vyper";
        cmds[1] = fileLocation;
        return abi.encodePacked(vm.ffi(cmds), args);
    }

    function deployByteCode(
        bytes memory vyperByteCode
    ) public returns (address contractAddr) {
        assembly {
            contractAddr := create(0, add(vyperByteCode, 0x20), mload(vyperByteCode))
        }
        require(
            contractAddr != address(0) && contractAddr.code.length > 0,
            "Vyper contract deployment failed"
        );
    }

    function deployContract(
        string memory fileLocation
    ) public returns (address contractAddr) {
        return deployByteCode(compileVyper(fileLocation));
    }

    function deployContract(
        string memory fileLocation, 
        bytes memory args
    ) public returns (address contractAddr) {
        return deployByteCode(compileVyper(fileLocation, args));
    }
}

This would let users import and inherit VyperTest.sol that inherits forge-std/Test.sol which would give easy access to both Vyper deployment functionality and the regular test methods/cheats.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants