EnhancedScript.sol 1.93 KB
Newer Older
1 2 3 4 5
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;

import { console } from "forge-std/console.sol";
import { Script } from "forge-std/Script.sol";
6
import { Semver } from "../../src/universal/Semver.sol";
7

8 9 10
/// @title EnhancedScript
/// @notice Enhances forge-std' Script.sol with some additional application-specific functionality.
///         Logs simulation links using Tenderly.
11
abstract contract EnhancedScript is Script {
12 13
    /// @notice Helper function used to compute the hash of Semver's version string to be used in a
    ///         comparison.
14 15 16 17
    function _versionHash(address _addr) internal view returns (bytes32) {
        return keccak256(bytes(Semver(_addr).version()));
    }

18 19 20
    /// @notice Log a tenderly simulation link. The TENDERLY_USERNAME and TENDERLY_PROJECT
    ///         environment variables will be used if they are present. The vm is staticcall'ed
    ///         because of a compiler issue with the higher level ABI.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
    function logSimulationLink(address _to, bytes memory _data, address _from) public view {
        (, bytes memory projData) = VM_ADDRESS.staticcall(
            abi.encodeWithSignature("envOr(string,string)", "TENDERLY_PROJECT", "TENDERLY_PROJECT")
        );
        string memory proj = abi.decode(projData, (string));

        (, bytes memory userData) = VM_ADDRESS.staticcall(
            abi.encodeWithSignature("envOr(string,string)", "TENDERLY_USERNAME", "TENDERLY_USERNAME")
        );
        string memory username = abi.decode(userData, (string));

        string memory str = string.concat(
            "https://dashboard.tenderly.co/",
            username,
            "/",
            proj,
            "/simulator/new?network=",
            vm.toString(block.chainid),
            "&contractAddress=",
            vm.toString(_to),
            "&rawFunctionInput=",
            vm.toString(_data),
            "&from=",
            vm.toString(_from)
        );
        console.log(str);
    }
}