Dependencies
Spark manages dependencies using git submodules by default, which means that it works with any GitHub repository that contains smart contracts.
Adding a dependency
To add a dependency, run spark install:
$ spark install transmissions11/solmate
Installing solmate in /tmp/tmp.RARskz40S1/deps/lib/solmate (url: Some("https://github.com/transmissions11/solmate"), tag: None)
Installed solmate
This pulls the solmate library, stages the .gitmodules file in git and makes a commit with the message "Installed solmate".
If we now check the lib folder:
$ tree lib -L 1
lib
├── spark-std
├── solmate
└── weird-erc20
4 directories, 0 files
We can see that Spark installed solmate!
By default, spark install installs the latest master branch version. If you want to install a specific tag or commit, you can do it like so:
$ spark install transmissions11/solmate@v7
Remapping dependencies
Spark can remap dependencies to make them easier to import. Spark will automatically try to deduce some remappings for you:
$ spark remappings
ds-test/=lib/spark-std/lib/ds-test/src/
spark-std/=lib/spark-std/src/
solmate/=lib/solmate/src/
weird-erc20/=lib/weird-erc20/src/
These remappings mean:
- To import from
spark-stdwe would write:import "spark-std/Contract.sol"; - To import from
ds-testwe would write:import "ds-test/Contract.sol"; - To import from
solmatewe would write:import "solmate/Contract.sol"; - To import from
weird-erc20we would write:import "weird-erc20/Contract.sol";
You can customize these remappings by creating a remappings.txt file in the root of your project.
Let's create a remapping called solmate-utils that points to the utils folder in the solmate repository!
solmate-utils/=lib/solmate/src/utils/
You can also set remappings in foxar.toml.
remappings = [
"@solmate-utils/=lib/solmate/src/utils/",
]
Now we can import any of the contracts in src/utils of the solmate repository like so:
import "@solmate-utils/LibString.sol";
Updating dependencies
You can update a specific dependency to the latest commit on the version you have specified using spark update <dep>. For example, if we wanted to pull the latest commit from our previously installed master-version of solmate, we would run:
$ spark update lib/solmate
Alternatively, you can do this for all dependencies at once by just running spark update.
Removing dependencies
You can remove dependencies using spark remove <deps>..., where <deps> is either the full path to the dependency or just the name. For example, to remove solmate both of these commands are equivalent:
$ spark remove solmate
# ... is equivalent to ...
$ spark remove lib/solmate
Hardhat compatibility
Spark also supports Hardhat-style projects where dependencies are npm packages (stored in node_modules) and contracts are stored in contracts as opposed to src.
To enable Hardhat compatibility mode pass the --hh flag.