Giter VIP home page Giter VIP logo

hardhat-proxy's Introduction

hardhat-proxy

Hardhat plugin for integration with proxy contract.

Required plugins

What

This plugin brings the proxy contract to Hardhat, which allows you to manage the proxy contract in a simple way.

Installation

npm install --save-dev hardhat-proxy

Add the following statement to your hardhat.config.js:

require('hardhat-proxy')

Or, if you are using TypeScript, add this to your hardhat.config.ts:

import 'hardhat-proxy'

Configuration

You need to add the proxy contract address in hardhat.config.js.

Config example:

export default {
  proxies: {
    hardhat: '0x5FbDB2315678afecb367f032d93F642f64180aa3'
  }
}

Note: you need to manually add the output proxy address in the hardhat.config.js after running hardhat proxy:deploy

Usage

First, use Register in your implementation contract.

import 'hardhat-proxy/contracts/Register.sol';

contract Implementation is Register {
  function foo() public {
    // Doing something
  }
}

Second, override function register, and return constant LibRegister.REGISTER_SUCCESS.

import 'hardhat-proxy/contracts/Register.sol';
import 'hardhat-proxy/contracts/utils/LibRegister.sol';

contract Implementation is Register {
  function register() public override returns (bytes4 success) {
    _register(this.foo.selector);
    return LibRegister.REGISTER_SUCCESS;
  }
}

Last, use scripts or CLI to register it to proxy contract.

Scripts example:

import hre from 'hardhat'

await hre.proxy.bootstrap('0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9')

CLI example:

$ hardhat proxy:deploy --network localhost --impl 0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9

Tasks

This plugin implements a proxy and proxy:deploy task.

The proxy:deploy task can deploy a proxy contract to ethereum network.

$ hardhat proxy:deploy --network localhost

Proxy contract deployed in hardhat: 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512

The proxy task can register an implementation contract to proxy contract

$ hardhat proxy:deploy --network localhost --impl 0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9

┌────────────┬────────────────────────────────────────────┬────────────────────────────────────────────┐
│ Selector   │ Old implementation                         │ New implementation                         │
├────────────┼────────────────────────────────────────────┼────────────────────────────────────────────┤
│ 0xa4136862 │ 0x0000000000000000000000000000000000000000 │ 0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9 │
├────────────┼────────────────────────────────────────────┼────────────────────────────────────────────┤
│ 0x8d75376a │ 0x0000000000000000000000000000000000000000 │ 0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9 │
├────────────┼────────────────────────────────────────────┼────────────────────────────────────────────┤
│ 0x22df2236 │ 0x0000000000000000000000000000000000000000 │ 0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9 │
└────────────┴────────────────────────────────────────────┴────────────────────────────────────────────┘
Option Type Default Description
impl Address undefined The implementation contract's address.

Environment extensions

This plugins adds a proxy object to the Hardhat Runtime Environment. You can use it in hardhat scripts.

declare module 'hardhat/types/runtime' {
  export interface HardhatRuntimeEnvironment {
    proxy: {
      address: string
      bootstrap: (impl: string) => Promise<TransactionResponse>
      deploy: () => Promise<Contract>
    }
  }
}
  • address: The proxy address of current network
  • bootstrap: Register implementation contract to proxy contract
  • deploy: Deploy proxy contract

Contract Introduction

TODO

hardhat-proxy's People

Contributors

jinyang1994 avatar chicunic avatar

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.