npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

upgradeable-contracts-solidity

v1.0.1

Published

Upgradeable Smart Contracts for Solidity

Downloads

5

Readme

Upgradeable Contracts Solidity

Solidity upgradeable contracts proxy based on unstructured storage pattern.

Read more about proxy patterns from OpenZeppelin article.

I chose this pattern for implementation because it is the most convenient in its further support. So, no implementation of a proxied contract should know about the proxy contract storage structure. However, all implementations must inherit all of the storage variables that were declared in their ancestors.

The address of the current implementation is stored in a constant pseudorandom slot of the contract proxy contract (slot number obtained as a result of hashing a certain message), the probability of rewriting which is almost zero.

If you want to set the initial implementation state, use a separate initialize function for it, which will essentially be the "constructor" of the contract. This is due to the fact that the proxy does not reflect in any way the changes that you make in the constructor of the contract, therefore it can be considered useless.

When creating a contract, the sender of this transaction will be assigned as its owner. The address of the owner is stored in a manner similar to the implementation address.

You can change the owner using the following function:

/// @notice The owner can transfer control of the contract to the new owner
/// @param _newOwner New proxy owner
function transferOwnership(address _newOwner) external

You can change current implementation after its deployment using the following function:

/// @notice Sets new implementation of contract as current
/// @param _newImplementation New contract implementation address
function setImplementation(address _newImplementation) public

Or if you want to set some initial state for it use the following function:

/// @notice Sets new implementation and call new implementation to initialize what is needed on it
/// @dev New implementation call is a low level delegatecall
/// @param _newImplementation representing the address of the new implementation to be set.
/// @param _newImplementaionCallData represents the msg.data to bet sent in the low level call. This parameter may include the function
/// signature of the implementation to be called with the needed payload
function setImplementationAndCall(address _newImplementation, bytes calldata _newImplementaionCallData) external payable

You can use any function of the implementation contract as usual, however, the address should be the address of its proxy contract. This is because the implementation functions will be called using the delegate call from the context of the proxy contract using the fallback function.

Install and use

  1. Install node.js and yarn if you haven't yet
  2. Install package
yarn add upgradeable-contracts-solidity
  1. Import contracts into new .sol file, save and deploy it. Feel free to inherit Proxy contract and add your functionality (DO NOT add storage variables if you don't completely understand how it works)
pragma solidity ^0.5.0;

import "../node_modules/upgradeable-contracts-solidity/contracts/Proxy.sol";

contract YoursContract is Proxy {}
  1. Deploy and set implementation as described above

Build and test

  1. Install node.js and yarn if you haven't yet
  2. Clone repo
git clone https://github.com/BaldyAsh/upgradeable-contracts-solidity
  1. Go to downloaded folder and install dependencies
yarn
  1. Make sure that your Ethereum client is working (you can use whatever you want: your local chain pr official remote Ethereum chains).
  2. Create .env file. Feel free to copy .dev.env. Set your chain rpc url.
  3. Compile contracts and run tests
yarn test

Credits

Anton Grigorev, @baldyash

Contribute

Donate

License

This project is available under the MIT license. See the LICENSE for details.