Solidity Development Operations

This package provides a set of tools and scripts to help with the development of Solidity smart contracts:

  • Utilities to simplify the testing of smart contracts using Foundry.
  • Utilities to simplify the deployment of smart contracts using Foundry.
  • Utilities to manage the existing deployments of smart contracts.

Disclaimer

This package is still under development and should be used with caution. It is not recommended to use it in a production environment.

Docs

Forge docs are automatically deployed here.

Setup

In order to use this package, it needs to be installed as a dependency in your project. It is recommended to install it as a dev dependency.

npm install --save-dev @synapsecns/solidity-devops
# Or, if you are using yarn
yarn add --dev @synapsecns/solidity-devops

Following files are necessary to be present in the root of your project:

  • .env: storage for the sensitive configuration variables.
  • devops.json: configuration file for the devops package.
  • foundry.toml: configuration file for Foundry.

.env

Note: This file must be added to .gitignore to avoid sharing sensitive information.

See the example .env file. Following structure is required:

  • Wallets: defines the deployer wallets used for running the scripts. Assuming the chad is the name of the wallet, the following values are required:
    • CHAD_ADDRESS: the address of the account to use for signing
    • CHAD_TYPE: the type of the wallet:
      • keystore: use the encrypted keystore file.
        • CHAD_JSON: the keystore file path
      • ledger or trezor: use the hardware wallet.
        • TODO: find out if ledger/trezor specific options are needed
      • pk: use the plaintext private key. STRONGLY DISCOURAGED for production usage, meant for local devnet purposes.
        • CHAD_PK: the private key to the wallet in 0x format.
      • Any other value triggers the interactive prompt to enter the private key.
  • Chains: defines the list of chains where the scripts will run. Assuming the chain is the name of the chain, the following values are required:
    • CHAIN_RPC: the RPC endpoint of the chain
    • CHAIN_VERIFIER: verifier for the smart contracts. Possible values:
      • etherscan
      • blockscout
      • sourcify
    • CHAIN_VERIFIER_URL: the Verifier API endpoint (required if verifier is not sourcify)
      • Note: Blockscout URL needs to end with "/api?" for the verification to work.
    • CHAIN_VERIFIER_KEY: the Verifier API key (required if verifier is not sourcify)
      • Note: Use any non-empty string for Blockscout API key: it is not required per se, but foundry will complain if it's empty.

devops.json

See the example devops.json file. Following values are required:

  • chains: list of chain-specific options for forge script command.
    • Check the available options by running forge script --help.
    • Two additional options to handle the gas pricing are introduced:
      • --auto-gas-1559: will fetch the current base fee and priority fee from the chain's RPC node, and use following values for submitting the transactions:
        • maxPriorityFee = priorityFee
        • maxGasPrice = 2 * baseFee + priorityFee
      • --auto-gas-legacy: will fetch the current gas price from the chain's RPC node, and use it for submitting the transactions.

        Note: these options are introduced as foundry script hardcodes the 3 Gwei priority fee, which is not ideal for all the chains.

  • deployConfigs: path to the directory that contains the deployment configuration files. These configuration files are expected to be either chain-specific or global:
    • The chain-specific configuration files should be located in deployConfigsDir/{chainName}/{contractName}.dc.json.
    • The global configuration files for production should be located in deployConfigsDir/global/{contractName}.json.
    • The global configuration files for other environments (e.g. testnet) should be located in deployConfigsDir/global/{environment}/{contractName}.json.
    • The configuration files usually include the variables required for the contract deployment or its subsequent management.
  • deployments: path to the directory that contains the deployment artifact files. These files are automatically generated by fsr and alike commands.
  • forgeArtifacts: path to the directory that forge uses to store the artifacts for the compiled contracts.
    • Must match the out value in the foundry.toml file.
  • freshDeployments: path to the directory that contains the fresh deployment artifact files. These files are generated during the local run of the forge script command.
    • It is recommended to add this directory to .gitignore to avoid unnecessary changes in the repository.
    • The artifacts in this directory are automatically moved into the deployments directory by fsr and alike commands.

      Note: we opted to use this approach, as the local run of the forge script is always done before the actual broadcast of the deployment transactions. Therefore, the end results might not match the local run, if there was an unexpected on-chain revert, or if transactions were not included in the block. A separate job is automatically run to check all the new artifacts and move them to the deployments directory, if the on-chain deployment was successful.

foundry.toml

See the example foundry.toml file. Following values are required:

  • fs_permissions:
    • { access = "read", path = "./" } to allow reading files from the repository root
    • { access = "read-write", path = "<freshDeployments>" } to allow reading/writing fresh deployment artifacts
  • rpc_endpoints:
    • It is recommended to follow the structure defined in the example file to avoid duplication:
      • arbitrum = "${ARBITRUM_RPC}"
  • etherscan:
    • It is recommended to follow the structure defined in the example file to avoid duplication:
      • arbitrum = { key = "${ARBITRUM_VERIFIER_KEY}", url = "${ARBITRUM_VERIFIER_URL}" }
      • You should omit values for chains that are using Sourcify for verification.

See the Foundry Book for more information.

Usage

Writing scripts

  • Your scripts should inherit from the SynapseScript class (or SynapseScript06 if you're using Solidity 0.6 compiler).
    • This class already inherits from forge-std's Script class, so you can use all the methods from it.
    • See the example script for more information.
  • It is recommended to use separate scripts for initial deployments and subsequent configuration of the contracts.
    • The initial deployment scripts should be named Deploy{ContractName}.s.sol.
    • The configuration scripts should be named Configure{ContractName}.s.sol.

Running scripts

Your main point of entry for running the scripts should be the npx fsr command.

Note: fsr is a shorthand for forge script run.

# npx fsr <path-to-script> <chain-name> <wallet-name> [<options>]
# To simulate the script without broadcasting, using wallet named "chad"
npx fsr script/DeployBasicContract.s.sol eth_sepolia chad
# To broadcast the script using wallet named "chad"
# NOTE: there is no need to add --verify option, as it is automatically added for the broadcasted scripts.
npx fsr script/DeployBasicContract.s.sol eth_sepolia chad --broadcast

This command is responsible for the following:

  • Initializing the chain's deployment directories with the .chainid file, if they don't exist.
  • Logging the wallet's address, balance and nonce.
  • Running the script using the forge script command.
    • This executes the run() method of the script.
    • --verify option is added if the script is broadcasted.
  • Collecting the receipts for the newly deployed contracts, and saving their deployment artifacts.

You can also utilize the npx fsr-str command to provide a single string argument for the running script:

  • This executes the run(string memory arg) method of the script, passing the provided string argument.
# npx fsr-str <path-to-script> <chain-name> <wallet-name> <string-arg> [<options>]
# To simulate the script without broadcasting, using wallet named "chad"
npx fsr-str script/DeployBasicContract.s.sol eth_sepolia chad "AAAAAAAA"
# To broadcast the script using wallet named "chad"
# NOTE: there is no need to add --verify option, as it is automatically added for the broadcasted scripts.
npx fsr-str script/DeployBasicContract.s.sol eth_sepolia chad "AAAAAAAA" --broadcast

Managing deployments

If for whatever reason the deployment script was interrupted, you can use npx sd command to save the deployment artifacts.

Note: sd is a shorthand for save deployment.

# npx sd <chain-name> <contract-alias>
npx sd eth_sepolia BasicContract
# Or, if the contract alias is used
npx sd eth_sepolia BasicContract.Alias

Contract verification

You can verify the contracts with the saved deployment artifacts using the npx fvc command.

Note: fvc is a shorthand for forge verify contract.

# npx fvc <chain-name> <contract-alias>
npx fvc eth_sepolia BasicContract
# Or, if the contract alias is used
npx fvc eth_sepolia BasicContract.Alias

Proxy verification

You can verify the proxy's implementation in Etherscan-alike explorers using the npx vp command.

Note: vp is a shorthand for verify proxy.

# npx vp <chain-name> <contract-alias>
npx vp eth_sepolia BasicContract
# Or, if the contract alias is used
npx vp eth_sepolia TransparentUpgradeableProxy.BasicContract

Contents

ChainAwareness

Git Source

Inherits: PathFinder

State Variables

activeChain

Name of the active chain, should match the name of the directory in deployments

string public activeChain;

chainIdsLoaded

Whether chainIds and chainNames have been loaded

bool private chainIdsLoaded;

chainIds

Map from chain name to chainId

mapping(string => uint256) public chainIds;

chainNames

Map from chainId to chain name

mapping(uint256 => string) public chainNames;

Functions

getFreshDeploymentFN

Returns the path to the FRESH contract deployment JSON for a contract on the active chain. Example: ".deployments/mainnet/SynapseRouter.json"

function getFreshDeploymentFN(string memory contractName) internal view returns (string memory);

getDeploymentFN

Returns the path to the contract deployment JSON for a contract on the active chain. Example: "deployments/mainnet/SynapseRouter.json"

function getDeploymentFN(string memory contractName) internal view returns (string memory);

getChainGenericFN

Returns the path to the generic file on the active chain.

Useful for the files that are not specific to a contract, but are specific to a chain.

function getChainGenericFN(string memory fileName) internal view returns (string memory);

getDeployConfigFN

Returns the path to the contract deployment configuration JSON for a contract on the active chain. Example: "script/configs/mainnet/SynapseRouter.json"

function getDeployConfigFN(string memory contractName) internal view returns (string memory);

getChainId

Returns the chain ID for a given chain by reading the chain ID file in the deployments directory.

Returns 0 or reverts if the chain ID is not found based on the flag.

function getChainId(string memory chain, bool revertIfNotFound) internal returns (uint256);

loadActiveChain

Sets active chain to the one matching block.chainid value. Reverts if the chain is not supported.

function loadActiveChain() internal;

loadChainIds

Reads all chain:chainId pairs from the deployments directory, and saves them in chainIds and chainNames mappings.

Will do this lazily, only once per the script run.

function loadChainIds() internal;

blockChainId

Wrapper for block.chainid, which only exists in Solidity 0.8+

function blockChainId() internal view returns (uint256 chainId);

Logger

Git Source

State Variables

TAB

string private constant TAB = "    ";

currentIndentLevel

Current indent level for all log messages

uint256 private currentIndentLevel;

Functions

withIndent

modifier withIndent();

currentIndent

Returns the current indent string.

Handy if the log message contains arguments other than strings and printLog() is not used.

function currentIndent() internal view returns (string memory);

increaseIndent

Increases the indent level for all log messages.

function increaseIndent() internal;

decreaseIndent

Decreases the indent level for all log messages.

function decreaseIndent() internal;

printLog

Prints the log message with the current indent level.

function printLog(string memory logString) internal view;

printInfo

Prints the informational log message with the current indent level.

function printInfo(string memory logString) internal view;

printLogWithIndent

Prints the log message with the current indent level plus one.

function printLogWithIndent(string memory logString) internal view;

printSkipWithIndent

Prints the "skipping" message with the current indent level plus one.

function printSkipWithIndent(string memory reason) internal view;

printFailWithIndent

Prints the "fail" message with the current indent level plus one.

function printFailWithIndent(string memory logString) internal view;

printSuccessWithIndent

Prints the "success" message with the current indent level plus one.

function printSuccessWithIndent(string memory logString) internal view;

getInfoEmoji

Should return "💬"

function getInfoEmoji() internal pure virtual returns (string memory);

getSkipEmoji

Should return "🟡"

function getSkipEmoji() internal pure virtual returns (string memory);

getFailEmoji

Should return "❌"

function getFailEmoji() internal pure virtual returns (string memory);

getSuccessEmoji

Should return "✅"

function getSuccessEmoji() internal pure virtual returns (string memory);

PathFinder

Git Source

Inherits: CommonBase

State Variables

DEFAULT_DEVOPS_CONFIG

string private constant DEFAULT_DEVOPS_CONFIG = "./devops.json";

ENVIRONMENT_PROD

string internal constant ENVIRONMENT_PROD = "";

devopsConfig

string private devopsConfig;

Functions

withDevopsConfig

modifier withDevopsConfig();

assertFileExists

function assertFileExists(string memory filePath) internal;

loadDevopsConfig

function loadDevopsConfig() internal;

getDevopsConfigPath

Path to the devops.json file. Could be overridden if the location of the file is different.

function getDevopsConfigPath() internal pure virtual returns (string memory);

getForgeArtifactsPath

Returns the path to the directory where the forge artifacts for the contracts are stored.

The path is configured in the devops.json file.

function getForgeArtifactsPath() internal view withDevopsConfig returns (string memory);

getFreshDeploymentsPath

Returns the path to the temp directory where the deployment artifacts are saved during a script run. Note: deployment artifacts are NOT saved to the deployments directory automatically, another script must be run to verify that the deployment was successful and save the deployment artifacts to the deployments directory. The reason for this is that the forge script is simulated before the broadcasted transactions are sent, and the artifacts are saved during the script simulation. So we can't know if the deployment was successful until the script is actually run.

The path is configured in the devops.json file.

function getFreshDeploymentsPath() internal view withDevopsConfig returns (string memory);

getDeploymentsPath

Returns the path to the directory where the deployment artifacts are stored. Note: only verified deployments are stored in this directory.

The path is configured in the devops.json file.

function getDeploymentsPath() internal view withDevopsConfig returns (string memory);

getDeployConfigsPath

Returns the path to the directory where the deployment configuration files are stored.

The path is configured in the devops.json file.

function getDeployConfigsPath() internal view withDevopsConfig returns (string memory);

getGlobalDeployConfigPath

Returns the path to the global deployment configuration file for a contract.

Override this function to customize the path to the global deployment config file.

function getGlobalDeployConfigPath() internal view virtual returns (string memory);

getArtifactFN

Returns the path to the contract artifact generated by forge. Example: "artifacts/SynapseRouter.sol/SynapseRouter.json"

function getArtifactFN(string memory contractName) internal view returns (string memory);

getFreshDeploymentFN

Returns the path to the FRESH contract deployment JSON for a contract. Example: ".deployments/mainnet/SynapseRouter.json"

function getFreshDeploymentFN(string memory chain, string memory contractName) internal view returns (string memory);

getDeploymentFN

Returns the path to the SAVED deployment JSON for a contract. Example: "deployments/mainnet/SynapseRouter.json"

function getDeploymentFN(string memory chain, string memory contractName) internal view returns (string memory);

getChainGenericFN

Returns the path to the generic file on a given chain.

Useful for the files that are not specific to a contract, but are specific to a chain.

function getChainGenericFN(string memory chain, string memory fileName) internal view returns (string memory);

getDeployConfigFN

Returns the path to the contract deployment config JSON for a contract on a given chain. Example: "script/configs/mainnet/SynapseRouter.dc.json"

function getDeployConfigFN(string memory chain, string memory contractName) internal view returns (string memory);

getGlobalDeployConfigFN

Returns the path to the global config JSON that is shared across all chains for a contract. We expect different environments to exist, therefore the following pattern is used:

  • For a production environment, the environment param is empty, e.g. "script/configs/global/SynapseCCTP.json"
  • For a testnet, the environment param is "testnet", e.g. "script/configs/global/testnet/SynapseCCTP.json"
function getGlobalDeployConfigFN(
    string memory contractName,
    string memory environment
)
    internal
    view
    returns (string memory);

SynapseBaseScript

Git Source

Inherits: Script, Deployer, DeploymentSaver

State Variables

initialDeployerNonce

uint256 private initialDeployerNonce;

finalDeployerNonce

uint256 private finalDeployerNonce;

Functions

broadcastWithHooks

Common pattern for running a script.

modifier broadcastWithHooks();

offChainWithHooks

Common pattern for running a script off-chain.

modifier offChainWithHooks();

beforeExecution

Hook that is called before the script is executed.

Could be overridden to load custom data before the script is executed. Make sure to call super.beforeExecution() in the overridden function.

function beforeExecution() internal virtual;

afterExecution

Hook that is called after the script is executed.

Could be overridden to perform various checks after the script is executed. Make sure to call super.afterExecution() in the overridden function.

function afterExecution() internal virtual;

Contents

Deployer

Git Source

Inherits: ChainAwareReader, Logger

State Variables

CREATE2_FACTORY_NAME

string internal constant CREATE2_FACTORY_NAME = "Create2Factory";

DEFAULT_CREATE2_FACTORY

Deployed on lots of chains, could be deployed on more chains using EOA

address private constant DEFAULT_CREATE2_FACTORY = 0xa6190aBC82427800935E0598892f7488a7F73A04;

envCreate2Factory

address private envCreate2Factory;

nextDeploymentSalt

Salt to be used for the next create2 deployment, will be erased after the deployment

bytes32 private nextDeploymentSalt;

permanentDeploymentSalt

Salt to be used for the next create2 deployment, will be kept after the deployment

bytes32 private permanentDeploymentSalt;

Functions

loadEnvCreate2Factory

function loadEnvCreate2Factory() internal;

getCreate2Factory

Returns the address of the create2 factory to be used for the create2 deployments.

*There are a few ways to set the factory address. Priority in descending order:

  1. Deployment artifact for the factory saved in deployments/chainName
  2. CREATE2_FACTORY env variable
  3. DEFAULT_CREATE2_FACTORY*
function getCreate2Factory() internal view virtual returns (address);

getDeploymentSalt

function getDeploymentSalt() internal view virtual returns (bytes32);

getInitCode

function getInitCode(
    string memory contractName,
    bytes memory constructorArgs
)
    internal
    view
    virtual
    returns (bytes memory);

cbDeploy

Creates a contract with the given name and constructor args. Bytecode generated by forge is used for the deployment. Note: could be used as callback for deployAndSave and deployAndSaveAs for contracts with a different compiler version.

function cbDeploy(string memory contractName, bytes memory constructorArgs) internal returns (address deployedAt);

deployCode

Creates a contract with the given init code.

Does not save the deployment JSON, and therefore the direct usage should be avoided. Use as a part of a deploy callback for deployAndSave and deployAndSaveAs instead.

function deployCode(bytes memory initCode) internal returns (address deployedAt);

cbDeployCreate2

Creates a contract with the given name and constructor args. Bytecode generated by forge is used for the deployment. Deployment is done in a deterministic way, using create2 and nextDeploymentSalt() Note: could be used as callback for deployAndSave and deployAndSaveAs

function cbDeployCreate2(
    string memory contractName,
    bytes memory constructorArgs
)
    internal
    returns (address deployedAt);

factoryDeployCreate2

Creates a contract with the given init code. Deployment is done in a deterministic way, using create2 and the given salt.

Does not save the deployment JSON, and therefore the direct usage should be avoided. Use deployCreate2 as the deploy callback for deployAndSave and deployAndSaveAs instead.

function factoryDeployCreate2(
    address factory,
    bytes memory initCode,
    bytes32 salt
)
    internal
    returns (address deployedAt);

setNextDeploymentSalt

Set a deployment salt that will be used for a single next create2 deployment.

function setNextDeploymentSalt(bytes32 salt) internal;

setPermanentDeploymentSalt

Set a deployment salt that will be used for all create2 deployments.

function setPermanentDeploymentSalt(bytes32 salt) internal;

predictAddress

Predicts the address of a contract that would be deployed with the given init code and salt, using the default create2 factory.

function predictAddress(bytes memory initCode, bytes32 salt) internal view returns (address deployedAt);

predictAddress

Predicts the address of a contract that would be deployed with the given init code and salt, using the given create2 factory.

function predictAddress(
    address factory,
    bytes memory initCode,
    bytes32 salt
)
    internal
    pure
    returns (address deployedAt);

DeploymentSaver

Git Source

Inherits: ChainAwareReader, ChainAwareWriter

Functions

checkBeforeDeploying

function checkBeforeDeploying(string memory contractName) internal view returns (address deployedAt);

checkBeforeDeploying

function checkBeforeDeploying(
    string memory contractName,
    string memory contractAlias
)
    internal
    view
    returns (address deployedAt);

deployAndSave

Deploys a contract and saves the deployment JSON, if the contract hasn't been deployed yet. See deployAndSaveAs below for more details.

function deployAndSave(
    string memory contractName,
    bytes memory constructorArgs,
    function(string memory, bytes memory) internal returns (address) deployCodeFunc
)
    internal
    returns (address deployedAt);

deployAndSaveAs

Deploys a contract and saves the deployment JSON, if the contract hasn't been deployed yet. Needs to be passed a generic function that deploys the contract, that follows this signature: deployCodeFunc(string memory contractName, bytes memory constructorArgs) internal returns (address deployedAt);

  • Example: cbDeploy() and cbDeployCreate2() could be used here, as they follow the signature. Or anything else that could deploy raw bytecode of any contract, most likely using assembly/factory approach.
  • Note: contract should be configured outside of deployCodeFunc.
function deployAndSaveAs(
    string memory contractName,
    string memory contractAlias,
    bytes memory constructorArgs,
    function(string memory, bytes memory) internal returns (address) deployCodeFunc
)
    internal
    returns (address deployedAt);

deployAndSave

Deploys a contract and saves the deployment JSON, if the contract hasn't been deployed yet. See deployAndSaveAs below for more details.

function deployAndSave(
    string memory contractName,
    function() internal returns (address, bytes memory) deployContractFunc
)
    internal
    returns (address deployedAt);

deployAndSaveAs

Deploys a contract and saves the deployment JSON, if the contract hasn't been deployed yet. Needs to be passed a contract-specific function that deploys the contract, that follows this signature: deployContractFunc() internal returns (address deployedAt, bytes memory constructorArgs);

  • Example: use anything that deploys a specific contract, most likely using new Contract(...); approach.
  • Note: contract should be configured outside of deployContractFunc.
function deployAndSaveAs(
    string memory contractName,
    string memory contractAlias,
    function() internal returns (address, bytes memory) deployContractFunc
)
    internal
    returns (address deployedAt);

serializeDeploymentData

Produces a JSON string that can be used to save a contract deployment. Note: contract ABI is not included in the output.

function serializeDeploymentData(
    address deployedAt,
    bytes memory constructorArgs
)
    internal
    returns (string memory data);

saveDeployment

Saves the deployment JSON for a contract on a given chain under the specified alias. Example: contractName = "LinkedPool", contractAlias = "LinkedPool.USDC" Note: writes the JSON file to the FRESH deployments directory. The written file needs to be moved to the correct location outside of the deployment script. Note: will not include the ABI in the output JSON.

function saveDeployment(
    string memory contractAlias,
    address deployedAt,
    bytes memory constructorArgs
)
    internal
    withIndent;

Contents

StringUtils

Git Source

Author: Synapse Contributors

Library for handling strings, that could be used with any Solidity version from 0.6 to 0.8.

State Variables

NOT_FOUND

The value returned by indexOf when the substring is not found.

uint256 internal constant NOT_FOUND = type(uint256).max;

ZERO

bytes1 private constant ZERO = bytes1("0");

NINE

bytes1 private constant NINE = bytes1("9");

Functions

length

Returns the length of a string

function length(string memory str) internal pure returns (uint256);

substring

Returns a substring of a string in the range [startIndex, endIndex)

function substring(string memory str, uint256 startIndex, uint256 endIndex) internal pure returns (string memory);

Parameters

NameTypeDescription
strstringThe string to take a substring of
startIndexuint256The start index (inclusive)
endIndexuint256The end index (exclusive)

suffix

Returns a suffix of a string starting at the given index, inclusive: [startIndex, str.length)

function suffix(string memory str, uint256 startIndex) internal pure returns (string memory);

Parameters

NameTypeDescription
strstringThe string to take a suffix of
startIndexuint256The start index (inclusive)

prefix

Returns a prefix of a string ending at the given index, exclusive: [0, endIndex)

function prefix(string memory str, uint256 endIndex) internal pure returns (string memory);

Parameters

NameTypeDescription
strstringThe string to take a prefix of
endIndexuint256The end index (exclusive)

concat

Concatenates two strings

function concat(string memory a, string memory b) internal pure returns (string memory);

concat

Concatenates three strings

function concat(string memory a, string memory b, string memory c) internal pure returns (string memory);

concat

Concatenates four strings

function concat(
    string memory a,
    string memory b,
    string memory c,
    string memory d
)
    internal
    pure
    returns (string memory);

concat

Concatenates five strings

function concat(
    string memory a,
    string memory b,
    string memory c,
    string memory d,
    string memory e
)
    internal
    pure
    returns (string memory);

concat

Concatenates six strings

function concat(
    string memory a,
    string memory b,
    string memory c,
    string memory d,
    string memory e,
    string memory f
)
    internal
    pure
    returns (string memory);

duplicate

Duplicates a string a given number of times. Example: duplicate("abc", 3) = "abcabcabc"

function duplicate(string memory str, uint256 times) internal pure returns (string memory duplicateStr);

equals

Checks if two strings are equal

function equals(string memory a, string memory b) internal pure returns (bool);

Parameters

NameTypeDescription
astringThe first string
bstringThe second string

indexOf

Returns the index of the first occurrence of a substring in a string, or NOT_FOUND if not found.

function indexOf(string memory str, string memory subStr) internal pure returns (uint256);

Parameters

NameTypeDescription
strstringThe string to search in
subStrstringThe substring to search for

lastIndexOf

Returns the index of the last occurrence of a substring in a string, or NOT_FOUND if not found.

function lastIndexOf(string memory str, string memory subStr) internal pure returns (uint256);

Parameters

NameTypeDescription
strstringThe string to search in
subStrstringThe substring to search for

toUint

Derives integer from its string representation.

function toUint(string memory str) internal pure returns (uint256 val);

Parameters

NameTypeDescription
strstringThe string to convert

fromUint

Converts an integer to its string representation.

function fromUint(uint256 val) internal pure returns (string memory);

fromFloat

Converts a float to its string representation.

function fromFloat(uint256 val, uint256 decimals) internal pure returns (string memory);

Parameters

NameTypeDescription
valuint256The float to convert, scaled by 10**decimals
decimalsuint256The number of decimals to use

fromWei

Converts a float to its string representation, using 18 decimals.

function fromWei(uint256 val) internal pure returns (string memory);

Parameters

NameTypeDescription
valuint256The float to convert, scaled by 10**18

Contents

ChainAwareReader

Git Source

Inherits: ChainAwareness, DataReader

Functions

readDeploymentArtifact

Returns the saved deployment artifact JSON for a contract on the active chain.

Returns an empty string or reverts if the artifact is not found based on the flag.

function readDeploymentArtifact(
    string memory contractName,
    bool revertIfNotFound
)
    internal
    view
    returns (string memory artifact);

readDeployConfig

Returns the deployment configuration JSON for a contract on the active chain.

Returns an empty string or reverts if the artifact is not found based on the flag.

function readDeployConfig(
    string memory contractName,
    bool revertIfNotFound
)
    internal
    view
    returns (string memory deployConfig);

getDeploymentAddress

Returns the deployment address for a contract on the active chain.

Returns address(0) or reverts if the address is not found based on the flag.

function getDeploymentAddress(
    string memory contractName,
    bool revertIfNotFound
)
    internal
    view
    returns (address deploymentAddress);

isDeployed

Checks if a contract is deployed on the active chain without reverting.

function isDeployed(string memory contractName) internal view returns (bool);

assertContractCodeEmpty

Asserts that a contract is NOT deployed on the active chain by checking its code size.

function assertContractCodeEmpty(address contractAddr, string memory errMsg) internal view;

assertContractCodeExists

Asserts that a contract is deployed on the active chain by checking its code size.

function assertContractCodeExists(address contractAddr, string memory errMsg) internal view;

getCodeSize

Returns the code size for a given address on the active chain.

function getCodeSize(address contractAddr) internal view returns (uint256 codeSize);

DataReader

Git Source

Inherits: PathFinder

Functions

readFile

Reads a file from the filesystem and returns its content.

Returns an empty string or reverts if the file is not found based on the flag.

function readFile(string memory path, bool revertIfNotFound) internal view returns (string memory);

readContractArtifact

Tries to read the full contract artifact JSON generated by forge.

Returns an empty string or reverts if the artifact is not found based on the flag.

function readContractArtifact(
    string memory contractName,
    bool revertIfNotFound
)
    internal
    view
    returns (string memory);

readDeploymentArtifact

Returns the saved deployment artifact JSON for a contract.

Returns an empty string or reverts if the artifact is not found based on the flag.

function readDeploymentArtifact(
    string memory chain,
    string memory contractName,
    bool revertIfNotFound
)
    internal
    view
    returns (string memory artifact);

readDeployConfig

Returns the deployment configuration JSON for a contract.

Returns an empty string or reverts if the artifact is not found based on the flag.

function readDeployConfig(
    string memory chain,
    string memory contractName,
    bool revertIfNotFound
)
    internal
    view
    returns (string memory deployConfig);

readGlobalDeployConfig

Returns the global deployment configuration JSON.

Returns an empty string or reverts if the artifact is not found based on the flag.

function readGlobalDeployConfig(
    string memory contractName,
    string memory environment,
    bool revertIfNotFound
)
    internal
    view
    returns (string memory deployConfig);

readGlobalDeployProdConfig

Returns the global deployment configuration JSON for the production environment.

Returns an empty string or reverts if the artifact is not found based on the flag.

function readGlobalDeployProdConfig(
    string memory contractName,
    bool revertIfNotFound
)
    internal
    view
    returns (string memory deployConfig);

getContractBytecode

Returns the contract bytecode extracted from the artifact generated by forge.

Returns an empty string or reverts if the artifact is not found based on the flag.

function getContractBytecode(
    string memory contractName,
    bool revertIfNotFound
)
    internal
    view
    returns (bytes memory bytecode);

getDeploymentAddress

Returns the deployment address for a contract on a given chain.

Returns address(0) or reverts if the artifact is not found based on the flag.

function getDeploymentAddress(
    string memory chain,
    string memory contractName,
    bool revertIfNotFound
)
    internal
    view
    returns (address);

isDeployed

Checks if a contract is deployed on a given chain without reverting.

function isDeployed(string memory chain, string memory contractName) internal view returns (bool);

Contents

ChainAwareWriter

Git Source

Inherits: ChainAwareness, DataWriter

Functions

writeDeploymentArtifact

Writes the deployment JSON for a contract on the active chain under the specified alias. Example: contractName = "LinkedPool", contractAlias = "LinkedPool.USDC" Note: writes the JSON file to the FRESH deployments directory. The written file needs to be moved to the correct location outside of the deployment script. Note: will not include the ABI in the output JSON.

function writeDeploymentArtifact(string memory contractAlias, string memory artifact) internal;

writeDeployConfig

Writes the deploy config for a contract on the active chain.

function writeDeployConfig(string memory contractName, string memory configData) internal;

DataWriter

Git Source

Inherits: PathFinder, Logger

Functions

writeJson

Writes a JSON data to a file, and prints a log message.

function writeJson(string memory descriptionLog, string memory path, string memory data) internal;

writeDeploymentArtifact

Writes the deployment JSON for a contract on a given chain under the specified alias. Example: contractName = "LinkedPool", contractAlias = "LinkedPool.USDC" Note: writes the JSON file to the FRESH deployments directory. The written file needs to be moved to the correct location outside of the deployment script. Note: will not include the ABI in the output JSON.

function writeDeploymentArtifact(
    string memory chain,
    string memory contractAlias,
    string memory artifact
)
    internal
    returns (string memory path);

writeDeployConfig

Writes the deploy config for a contract on a given chain.

function writeDeployConfig(string memory chain, string memory contractName, string memory configData) internal;

writeGlobalDeployConfig

Writes the global deploy config that is shared across all chains for a contract.

function writeGlobalDeployConfig(
    string memory contractName,
    string memory environment,
    string memory configData
)
    internal;

writeGlobalDeployProdConfig

Writes the global deploy production config that is shared across all chains for a contract.

function writeGlobalDeployProdConfig(string memory contractName, string memory configData) internal;

createDirIfRequired

Creates a directory where the file will be saved if it doesn't exist yet.

function createDirIfRequired(string memory filePath) internal;

SynapseScript

Git Source

Inherits: SynapseBaseScript

Functions

getInfoEmoji

Should return "💬"

function getInfoEmoji() internal pure virtual override returns (string memory);

getSkipEmoji

Should return "🟡"

function getSkipEmoji() internal pure virtual override returns (string memory);

getFailEmoji

Should return "❌"

function getFailEmoji() internal pure virtual override returns (string memory);

getSuccessEmoji

Should return "✅"

function getSuccessEmoji() internal pure virtual override returns (string memory);

SynapseScript06

Git Source

Inherits: SynapseBaseScript

Functions

getInfoEmoji

Should return "💬"

function getInfoEmoji() internal pure virtual override returns (string memory);

getSkipEmoji

Should return "🟡"

function getSkipEmoji() internal pure virtual override returns (string memory);

getFailEmoji

Should return "❌"

function getFailEmoji() internal pure virtual override returns (string memory);

getSuccessEmoji

Should return "✅"

function getSuccessEmoji() internal pure virtual override returns (string memory);