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 🙏

© 2025 – Pkg Stats / Ryan Hefner

sgn-v2-contracts

v0.2.0

Published

SGN V2 Contracts

Readme

SGN Contracts

Contracts for the Celer State Guardian Network (SGN) V2.

Run unit tests

yarn test

Benchmark gas cost

yarn report-gas:benchmark
yarn report-gas:summary

Check reports/gas_usage.

Update contract sizes

yarn size-contracts

Check reports/contract_sizes.txt.

Deploy contracts

  1. cp .env.template .env, then ensure all environment variables are set in .env.

  2. Replace INFURA-PROJECT-ID suffix of the network endpoint in .env, that you're going to use.

  3. Add private key of your account that would be used, in .env. Refer to hardhat.config.ts for env param key.

  4. Deploy SGN and Staking contracts:

hardhat deploy --network <network> --tags SGNStaking

Deploy Bridge contract:

hardhat deploy --network <network>  --tags Bridge

Deploy OriginalTokenVault contract:

Make sure to set ORIGINAL_TOKEN_VAULT_SIGS_VERIFIER in .env to the Bridge address when deploying. Such as: ORIGINAL_TOKEN_VAULT_SIGS_VERIFIER=0x67E5E3E54B2E4433CeDB484eCF4ef0f35Fe3Fb22

Where 0x67E5E3E54B2E4433CeDB484eCF4ef0f35Fe3Fb22 is the Bridge contract address

hardhat deploy --network <network>  --tags OriginalTokenVault

Deploy PeggedTokenBridge contract:

Make sure to set ORIGINAL_TOKEN_VAULT_SIGS_VERIFIER in .env to the Bridge address when deploying. Such as:

PEGGED_TOKEN_BRIDGE_SIGS_VERIFIER=0x67E5E3E54B2E4433CeDB484eCF4ef0f35Fe3Fb22

Where 0x67E5E3E54B2E4433CeDB484eCF4ef0f35Fe3Fb22 is the Bridge contract address

hardhat deploy --network <network>  --tags PeggedTokenBridge

Deploy OriginalTokenVaultV2 contract:

Make sure to set ORIGINAL_TOKEN_VAULT_SIGS_VERIFIER in .env to the Bridge address when deploying. Such as:

ORIGINAL_TOKEN_VAULT_SIGS_VERIFIER=0x67E5E3E54B2E4433CeDB484eCF4ef0f35Fe3Fb22

Where 0x67E5E3E54B2E4433CeDB484eCF4ef0f35Fe3Fb22 is the Bridge contract address

hardhat deploy --network <network>  --tags OriginalTokenVaultV2

Deploy PeggedTokenBridgeV2 contract:

Make sure to set ORIGINAL_TOKEN_VAULT_SIGS_VERIFIER in .env to the Bridge address when deploying. Such as:

PEGGED_TOKEN_BRIDGE_SIGS_VERIFIER=0x67E5E3E54B2E4433CeDB484eCF4ef0f35Fe3Fb22

Where 0x67E5E3E54B2E4433CeDB484eCF4ef0f35Fe3Fb22 is the Bridge contract address

hardhat deploy --network <network>  --tags PeggedTokenBridgeV2

Verify contracts on explorers

On Etherscan variants via hardhat etherscan-verify:

This is the recommended way for most mainnet Etherscan variants.

Make sure the ETHERSCAN_API_KEY is set correctly in .env.

hardhat etherscan-verify --network <network> --license "GPL-3.0" --force-license

On Etherscan variants via solt:

This is useful since most testnet Etherscan variants don't offer verification via the API.

  1. Generate the standard JSON input files:
source scripts/solt.sh
run_solt_write
  1. Then try:
solt verify --license 5 --network <network> solc-input-<contract>.json <deployed address> <contract name>
  1. If the second step fails, go to Etherscan and manually verify using the standard JSON input files.

On Blockscout variants via sourcify:

This is used if the Blockscout variant requires "Sources and Metadata JSON".

hardhat sourcify --network <network>

On Blockscout variants via flattened source files:

This is used if the Blockscout variant requires a single source file, or in general as a last resort.

  1. Flatten the source files:
hardhat flatten <path-to-contract> > flattened.sol
  1. Edit flattened.sol. Remove the duplicate SPDX-License-Identifier lines, keeping a single copy of
// SPDX-License-Identifier: GPL-3.0-only

and submit to Blockscout.

Sometimes you also need to remove the duplicate pragma solidity lines.

Upgradable contract via the proxy pattern

How it works

proxy contract holds state and delegatecall all calls to actual impl contract. When upgrade, a new impl contract is deployed, and proxy is updated to point to the new contract. below from openzeppelin doc

User ---- tx ---> Proxy ----------> Implementation_v0
                     |
                      ------------> Implementation_v1
                     |
                      ------------> Implementation_v2

Add upgradable contract

To minimize code fork, we add a new contract that inherits existing contract, eg. contract TokenUpgradable is Token. Next we need to ensure that all states set in Token contract constructor (and its parent contracts) must be settable via a separate normal func like init. This will allow Proxy contract to delegeteCall init and set proper values in Proxy's state, not the impl contract state. See MintSwapCanonicalTokenUpgradable.sol for example. We also need to either shadow Ownable._owner because when proxy delegateCall, in proxy state, Ownable._owner is not set and there is no other way to set it. Or use our own Ownable.sol which has internal func initOwner

Add deploy scripts

add a new ts file for deploy, in deploy options, add proxy section, make sure the methodName and args match actual upgradable contract

proxy: {
    proxyContract: "OptimizedTransparentProxy",
      execute: {
        // only called when proxy is deployed, it'll call Token contract.init
        // with proper args
        init: {
          methodName: 'init',
          args: [
            process.env.MINT_SWAP_CANONICAL_TOKEN_NAME,
            process.env.MINT_SWAP_CANONICAL_TOKEN_SYMBOL]
        }
      }
}

see deploy/pegged/tokens/008_mint_swap_canonical_token_upgradable.ts for example

Deploy and upgrade

hardhat deploy plugin tries to be smart and deploy ProxyAdmin only once for each chain, deploy impl contract then proxy contract