Giter Site home page Giter Site logo

better-deployer's Introduction

docs

Better Deployer

Better deployer is a set of simple libraries that help with simplification of contract deployments. It allows for:

  1. Unifying the deployment of contracts across tests and scripts.
  2. Naming each deployment, and using vm.label under the hood so that they show up in the chain logs when you run foundry scripts or tests with -vvvv verbosity.
  3. Saving all the deployments to a file, in case of a script, so that the file can easily be copy/pasted into another UI project. It also timestamps each run so nothing is lost.
  4. Loading already-deployed addresses into scripts easily.

How it works

Without Better Deployer

Normally when you have a contract, in your tests you'd do something like

Cat cat = new Cat();
cat.meow();

then in your deploy scripts you'd do something like:

Cat cat = new Cat();
dumpToFile(address(cat));

then in another script when you want to interact with that contract you'd do something like:

Cat cat = Cat(loadAddressFromFile());
cat.meow();

You would have to implement the dumpToFile and loadAddressFromFile manually. You'd have to make sure files aren't overridden so old addresses aren't lost. Working with files/JSON files in solidity using foundry's cheatcodes aren't easy either.

With Better Deployer

But now, you can do something like so:

string memory deployFolder = "deployments";
string memory deployFile = "myDeployments.json";

BetterDeployer deployer1 = new BetterDeployer();
deployer1.setPathAndFile(deployFolder, deployFile);
Carrot carrot = Carrot(
    deployer1.deploy("mycarrot", "Veggies.sol:Carrot", "")
);
deployer1.dump(); // dumps to file

after you run the script, it will generate a file in deployments/myDeployments.json, with the name of the deployed contract and its address in there.

Later you can load the contract like so:

string memory deployFolder = "deployments";
string memory deployFile = "myDeployments.json";

BetterDeployer deployer1 = new BetterDeployer();
deployer1.setPathAndFile(deployFolder, deployFile);
Carrot carrot = Carrot(
    deployer1.getDeployment("mycarrot")
);

API

BetterDeployer.sol

setPathAndFile

    function setPathAndFile(
        string memory _path,
        string memory _deploymentFile
    )

Call this function to specify what file to dump to.

setPathAndFile

Dumps to the file.

function setSkipFile(bool _skipFile)

Skips dumping to the file. This is used usually in the setUp function of your tests, so running unit-tests does not generate an address.

function getDeployment( string memory deploymentName )

Gets the deployment by name, stored in the file previously set.

ChainDeployer.sol

Extends BetterDeployer for when you want to deploy to different chains. All it does is that it prefixes the names with <chain>_<deploymentName>.

An example of what this looks like is in the UTB contracts:

// in forknet_deployments.json
  "arbitrum_UniSwapper": "0xE3e5D4b00c96bc94353d4F48305C42e695A50e86",
  "arbitrum_utbExecutor": "0x1590031e710B6613598a71Fed598562Bfd012C9F",
  "base_DcntEth": "0xD058C88FA412f1a2Fc53844b280e4b0C075c6F10",
  "base_DecentBridgeAdapter": "0x0f34b97c3F0763be7a0522AB901e6eB4Fd355e60",

better-deployer's People

Contributors

arshankhanifar avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

dashbaord202401

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.