-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathBaseScript.sol
More file actions
167 lines (136 loc) · 7.9 KB
/
Copy pathBaseScript.sol
File metadata and controls
167 lines (136 loc) · 7.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// SPDX-License-Identifier: GPL-3.0-or-later
// solhint-disable code-complexity
// solhint-disable no-console
pragma solidity >=0.8.22;
import { Script } from "forge-std/src/Script.sol";
import { stdJson } from "forge-std/src/StdJson.sol";
import { ChainId } from "./ChainId.sol";
abstract contract BaseScript is Script {
using stdJson for string;
/*//////////////////////////////////////////////////////////////////////////
STATE VARIABLES
//////////////////////////////////////////////////////////////////////////*/
/// @dev The address of the default Sablier admin.
address public constant DEFAULT_SABLIER_ADMIN = 0xcB88fBf459000853F22a7296b23d163901BB385E;
/// @dev The address of the common safe multisig.
address public constant DEFAULT_SABLIER_MULTISIG_ADMIN = 0x58290bbdb51A4c6B022A81e9cDeD24BE19Ca57fd;
/// @dev The canonical Sablier Comptroller proxy address.
address public constant CANONICAL_COMPTROLLER = 0x0000008ABbFf7a84a2fE09f9A9b74D3BC2072399;
/// @dev The salt used for deterministic deployments.
bytes32 public immutable SALT;
/// @dev Included to enable compilation of the script without a $MNEMONIC environment variable.
string public constant TEST_MNEMONIC = "test test test test test test test test test test test junk";
/// @dev The address of the transaction broadcaster.
address public broadcaster;
uint256 public chainId;
/// @dev Used to derive the broadcaster's address if $ETH_FROM is not defined.
string public mnemonic;
/*//////////////////////////////////////////////////////////////////////////
MODIFIERS
//////////////////////////////////////////////////////////////////////////*/
modifier broadcast() {
vm.startBroadcast(broadcaster);
_;
vm.stopBroadcast();
}
/*//////////////////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////////////////*/
/// @dev Initializes the transaction broadcaster like this:
///
/// - If $ETH_FROM is defined, use it.
/// - Otherwise, derive the broadcaster address from $MNEMONIC.
/// - If $MNEMONIC is not defined, default to a test mnemonic.
///
/// The use case for $ETH_FROM is to specify the broadcaster key and its address via the command line.
constructor() {
// Set the chain ID.
chainId = block.chainid;
address from = vm.envOr({ name: "ETH_FROM", defaultValue: address(0) });
if (from != address(0)) {
broadcaster = from;
} else {
mnemonic = vm.envOr({ name: "MNEMONIC", defaultValue: TEST_MNEMONIC });
(broadcaster,) = deriveRememberKey({ mnemonic: mnemonic, index: 0 });
}
// Construct the salt for deterministic deployments.
SALT = constructCreate2Salt();
}
/*//////////////////////////////////////////////////////////////////////////
HELPERS
//////////////////////////////////////////////////////////////////////////*/
/// @notice Returns the salt used for deterministic deployments, using the format "ChainID <chainID>, Version
/// <version>".
/// @dev The salt instructs Foundry to deploy contracts via the deterministic CREATE2 factory.
function constructCreate2Salt() public view virtual returns (bytes32) {
string memory chainIdStr = vm.toString(chainId);
string memory version = getVersion();
string memory create2Salt = string.concat("ChainID ", chainIdStr, ", Version ", version);
return bytes32(abi.encodePacked(create2Salt));
}
/// @notice Returns the admin address for the comptroller.
function getAdmin() public view returns (address) {
if (chainId == ChainId.CHILIZ) return 0x74A234DcAdFCB395b37C8c2B3Edf7A13Be78c935;
if (chainId == ChainId.ZKSYNC) return 0xaFeA787Ef04E280ad5Bb907363f214E4BAB9e288;
if (isDefaultMultisigChain(chainId)) return DEFAULT_SABLIER_MULTISIG_ADMIN;
return DEFAULT_SABLIER_ADMIN;
}
/// @dev Returns true if the chain uses the default multisig admin.
function isDefaultMultisigChain(uint256 id) public pure returns (bool) {
return id == ChainId.ARBITRUM || id == ChainId.AVALANCHE || id == ChainId.BASE || id == ChainId.BERACHAIN
|| id == ChainId.BSC || id == ChainId.ETHEREUM || id == ChainId.GNOSIS || id == ChainId.HYPEREVM
|| id == ChainId.LINEA || id == ChainId.MONAD || id == ChainId.OPTIMISM || id == ChainId.POLYGON
|| id == ChainId.SCROLL || id == ChainId.SONIC;
}
/// @notice Returns the Chainlink oracle on each chain. Refer to
/// https://docs.chain.link/data-feeds/price-feeds/addresses.
/// @dev Return 0, if no Chainlink oracle is found.
function getChainlinkOracle() public view returns (address addr) {
// Mainnets
if (chainId == ChainId.ARBITRUM) return 0x639Fe6ab55C921f74e7fac1ee960C0B6293ba612;
if (chainId == ChainId.AVALANCHE) return 0x0A77230d17318075983913bC2145DB16C7366156;
if (chainId == ChainId.BASE) return 0x71041dddad3595F9CEd3DcCFBe3D1F4b0a16Bb70;
if (chainId == ChainId.BSC) return 0x0567F2323251f0Aab15c8dFb1967E4e8A7D42aeE;
if (chainId == ChainId.ETHEREUM) return 0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419;
if (chainId == ChainId.GNOSIS) return 0x678df3415fc31947dA4324eC63212874be5a82f8;
if (chainId == ChainId.HYPEREVM) return 0xa5a72eF19F82A579431186402425593a559ed352;
if (chainId == ChainId.LINEA) return 0x3c6Cd9Cc7c7a4c2Cf5a82734CD249D7D593354dA;
if (chainId == ChainId.MONAD) return 0xBcD78f76005B7515837af6b50c7C52BCf73822fb;
if (chainId == ChainId.OPTIMISM) return 0x13e3Ee699D1909E989722E753853AE30b17e08c5;
if (chainId == ChainId.POLYGON) return 0xAB594600376Ec9fD91F8e885dADF0CE036862dE0;
if (chainId == ChainId.SCROLL) return 0x6bF14CB0A831078629D993FDeBcB182b21A8774C;
if (chainId == ChainId.SONIC) return 0xc76dFb89fF298145b417d221B2c747d84952e01d;
if (chainId == ChainId.ZKSYNC) return 0x6D41d1dc818112880b40e26BD6FD347E41008eDA;
// Testnets
if (chainId == ChainId.BASE_SEPOLIA) return 0x4aDC67696bA383F43DD60A9e78F2C97Fbbfc7cb1;
if (chainId == ChainId.OPTIMISM_SEPOLIA) return 0x61Ec26aA57019C486B10502285c5A3D4A4750AD7;
if (chainId == ChainId.SEPOLIA) return 0x694AA1769357215DE4FAC081bf1f309aDC325306;
return address(0);
}
/// @notice Returns the Sablier Comptroller on each chain.
function getComptroller() public view returns (address) {
if (ChainId.isSupported(chainId)) {
// For dEnergy, return the different address.
if (chainId == ChainId.DENERGY) return 0x946654AB30Dd6eD10236C89f2C8B2719df653691;
// For Linea, return the different address.
if (chainId == ChainId.LINEA) return 0xF21b304A08993f98A79C7Eb841f812CCeab49B8b;
// Robinhood's vanity proxy was initialized by an unauthorized account. Return the replacement proxy that
// binds the intended admin in its constructor initialization calldata.
if (chainId == ChainId.ROBINHOOD) return 0x12d70713796A9460314C282c613DE307FdED1a36;
// For all other chains, return the vanity address.
return CANONICAL_COMPTROLLER;
}
// Otherwise, revert.
revert("Comptroller: not found");
}
/// @notice Returns the initial value of the min fee in USD.
/// @dev Currently the fees will be set to zero.
function getInitialMinFeeUSD() public pure returns (uint256) {
return 0;
}
/// @notice Returns the version of the protocol, obtained from `package.json`.
function getVersion() public view virtual returns (string memory) {
string memory json = vm.readFile("package.json");
return json.readString(".version");
}
}