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

soljitsu

v1.0.0

Published

cli tool offering features useful when auditing solidity smart contracts

Downloads

24

Readme

Soljitsu

License Version Node Version

Soljitsu is a cli tool offering 2 features useful when auditing solidity smart contracts: flatten + combine.

Tested on MacOS, Ubuntu

Description

There are various tools to perform automated testing of smart contracts each with their own requirements. When manually reviewing smart contracts the separate locations of project files and dependency files can increase the time needed to go through all the source code used by a smart contract. To address these requirements/difficulties this tool provides 2 features.

Feature: flatten

Some tools are unable to use with installed dependencies and require all solidity files to be in the same folder (using only relative imports: ./*.sol ../*.sol). Besides that it is also very cumbersome to view the source code of dependencies, since you can either look online (GitHub) or in the node_modules/installed_contracts folders.

To solve these problems we could use this tool to flatten the project source code files, meaning:

  • copy all used files of dependencies (recursively) from the node_modules/installed_contracts folder
  • get rid of all (nested) folders inside the contracts folder
  • for each dependency file coming from node_modules/installed_contracts place a comment at the top with the module version
  • update the import statements in all files to point to the new flattened solidity files
  • rename the files by replacing folder separators (/) with a dot (.)

Feature: combine

Some tools require all solidity code in 1 file, meaning no import statements. Having all code in 1 file could also be useful when manually reviewing.

To address the above we could use this tool to combine all dependencies of project source code files, meaning per file inside contracts (and it's subdirectories):

  • retrieve all dependencies (recursively) and concatenate them in the right order dependency-wise
  • get rid of all (nested) folders inside the contracts folder
  • place a comment at the top for each used node_modules/installed_contracts dependency stating the used version
  • remove all import statements
  • use the lowest found solidity version (from the pragma line) and use that for the new file
  • name the new file by replacing folder separators (/) with a dot (.)

Notes

  • supports both NPM and EthPM dependencies
  • cannot yet handle npm dependencies which themselves depend on other npm dependencies (#1)

Requirements

node version >= 8.0.0

Install

npm install -g soljitsu

Usage

NAME
  soljitsu       cli tool offering solidity file tools

COMMANDS
  flatten        flatten all (dependencies of) solidity files found in the source directory
  combine        combine all dependencies of each solidity file found in the source directory

SYNOPSIS
  soljitsu flatten --src-dir=dirPath --dest-dir=dirPath [--npm-dir=dirPath --ethnpm-dir=dirPath]
  soljitsu flatten  --truffle=dirPath --dest-dir=dirPath
  soljitsu combine --src-dir=dirPath --dest-dir=dirPath [--npm-dir=dirPath --ethpm-dir=dirPath]
  soljitsu combine  --truffle=dirPath --dest-dir=dirPath

REQUIRED ARGUMENTS
  --truffle      path of truffle project (only when not specifying --src-dir)
  --src-dir      path of source contracts directory (only when not specifying --truffle)
  --dest-dir     path of the directory to write the result solidity files to

OPTIONAL ARGUMENTS
  --npm-dir      path of the directory with the NPM dependencies
                 only used with --src-dir
  --ethpm-dir      path of the directory with the EthPM dependencies
                 only used with --src-dir

EXAMPLES
  soljitsu flatten --src-dir=./contracts --npm-dir=./node_modules --dest-dir=./out
  soljitsu flatten --truffle=./my-truffle-project --dest-dir=./out
  soljitsu combine --src-dir=./contracts --npm-dir=./node_modules --dest-dir=./out
  soljitsu combine --truffle=./my-truffle-project --dest-dir=./out

To display help (the above shown excerpt) type: soljitsu.

Example

Given a project with the following folder structure:

├── contracts
│   ├── ContractX.sol
│   └── sub
│       └── ContractY.sol
└── node_modules
    └── zeppelin-solidity  <-- version=1.4.0
        └── ...

With the file's content being:

ContractX.sol

pragma solidity ^0.4.19;

import "./sub/ContractY.sol";

contract ContractX {
  // ...
}

sub/ContractY.sol

pragma solidity ^0.4.19;

import "zeppelin-solidity/contracts/ownership/Pausable.sol";

contract ContractY is Pausable {
  // ...
}

flatten

Executing soljitsu flatten --src-dir=./contracts --dest-dir=./out --npm-dir=./node_modules will create:

└── out
    ├── ContractX.sol
    ├── sub.ContractY.sol
    ├── zeppelin-solidity.contracts.lifecycle.Pausable.sol
    └── zeppelin-solidity.contracts.ownership.Ownable.sol

with the file's content being:

ContractX.sol

pragma solidity ^0.4.19;

import "./sub.ContractY.sol";

contract ContractX {
  // ...
}

sub.ContractY.sol

pragma solidity ^0.4.19;

import "./zeppelin-solidity.contracts.ownership.Pausable.sol";

contract ContractY is Pausable {
  // ...
}

zeppelin-solidity.contracts.lifecycle.Pausable.sol

pragma solidity ^0.4.18;

// [email protected] from NPM

import "./zeppelin-solidity.contracts.ownership.Ownable.sol";

contract Pausable is Ownable {
  // ...
}

zeppelin-solidity.contracts.ownership.Ownable.sol

pragma solidity ^0.4.18;

// [email protected] from NPM

contract Ownable {
  // ...
}

combine

Executing soljitsu combine --src-dir=./contracts --dest-dir=./out --npm-dir=./node_modules will create:

└── out
    ├── ContractX.sol
    └── sub.ContractY.sol

with the file's content being:

ContractX.sol

pragma solidity ^0.4.18;

// [email protected] from NPM

contract Ownable {
  // ...
}

contract Pausable is Ownable {
  // ...
}

contract ContractY is Pausable {
  // ...
}

contract ContractX {
  // ...
}

sub.ContractY.sol

pragma solidity ^0.4.18;

// [email protected] from NPM

contract Ownable {
  // ...
}

contract Pausable is Ownable {
  // ...
}

contract ContractY is Pausable {
  // ...
}

Test

npm test

License

MIT