@@ -116,27 +116,128 @@ abstract contract Deployments is CommonBase {
116116
117117 function _loadDeployedAddresses () internal {
118118 string memory root = vm.projectRoot ();
119+ string memory chainIdKey = block .chainid .toString ();
119120
121+ // Load creation code
122+ _loadCreationCode (root);
123+
124+ // Load external addresses
125+ _loadExternalAddresses (root, chainIdKey);
126+
127+ // Load deployment addresses
128+ _loadDeploymentAddresses (root, chainIdKey);
129+ }
130+
131+ function _loadCreationCode (string memory root ) internal {
120132 string memory creationJson = vm.readFile (string .concat (root, deploymentsSubpath, "/deployments/creation/creationCode.json " ));
121- bytes memory rawCreation = creationJson.parseRaw (". " );
122- __cc = abi.decode (rawCreation, (CreationCode));
133+ __cc.categoryRegistry = creationJson.readBytes (".categoryRegistry " );
134+ __cc.chainlinkFeedRegistry = creationJson.readBytes (".chainlinkFeedRegistry " );
135+ __cc.config = creationJson.readBytes (".config " );
136+ __cc.configSingleton_v1_2 = creationJson.readBytes (".configSingleton_v1_2 " );
137+ __cc.hub = creationJson.readBytes (".hub " );
138+ __cc.loanToken = creationJson.readBytes (".loanToken " );
139+ __cc.revokedNonce = creationJson.readBytes (".revokedNonce " );
140+ __cc.utilizedCredit = creationJson.readBytes (".utilizedCredit " );
141+ }
123142
143+ function _loadExternalAddresses (string memory root , string memory chainIdKey ) internal {
124144 string memory externalJson = vm.readFile (string .concat (root, deploymentsSubpath, "/deployments/external/external.json " ));
125- bytes memory rawExternal = externalJson.parseRaw (string .concat (". " , block .chainid .toString ()));
126- __e = abi.decode (rawExternal, (External));
145+ string memory externalKey = string .concat (". " , chainIdKey);
146+ __e.aave = IAaveLike (externalJson.readAddress (string .concat (externalKey, ".aave " )));
147+ __e.adminTimelock = externalJson.readAddress (string .concat (externalKey, ".adminTimelock " ));
148+ __e.chainlinkL2SequencerUptimeFeed = externalJson.readAddress (string .concat (externalKey, ".chainlinkL2SequencerUptimeFeed " ));
149+ __e.dao = externalJson.readAddress (string .concat (externalKey, ".dao " ));
150+ __e.daoSafe = externalJson.readAddress (string .concat (externalKey, ".daoSafe " ));
151+ __e.deployer = IPWNDeployer (externalJson.readAddress (string .concat (externalKey, ".deployer " )));
152+ __e.deployerSafe = externalJson.readAddress (string .concat (externalKey, ".deployerSafe " ));
153+ __e.isL2 = externalJson.readBool (string .concat (externalKey, ".isL2 " ));
154+ __e.protocolTimelock = externalJson.readAddress (string .concat (externalKey, ".protocolTimelock " ));
155+ __e.uniswapV3Factory = externalJson.readAddress (string .concat (externalKey, ".uniswapV3Factory " ));
156+ __e.uniswapV3NFTPositionManager = externalJson.readAddress (string .concat (externalKey, ".uniswapV3NFTPositionManager " ));
157+ __e.weth = externalJson.readAddress (string .concat (externalKey, ".weth " ));
158+ }
127159
160+ function _loadDeploymentAddresses (string memory root , string memory chainIdKey ) private {
128161 string memory deploymentsJson = vm.readFile (string .concat (root, deploymentsSubpath, "/deployments/protocol/v1.5.json " ));
129- bytes memory rawDeployment = deploymentsJson.parseRaw (string .concat (". " , block .chainid .toString ()));
130-
162+ string memory deploymentKey = string .concat (". " , chainIdKey);
163+
164+ // Check if deployment exists for this chain by checking if raw bytes exist
165+ bytes memory rawDeployment = deploymentsJson.parseRaw (deploymentKey);
166+
131167 if (rawDeployment.length > 0 ) {
132168 wasPredeployedOnFork = true ;
133- __d = abi.decode (rawDeployment, (Deployment));
169+ _loadDeploymentTopLevel (deploymentsJson, deploymentKey);
170+ _loadDeploymentProducts (deploymentsJson, deploymentKey);
171+ _loadDeploymentHooks (deploymentsJson, deploymentKey);
134172 } else {
135173 wasPredeployedOnFork = false ;
136174 _protocolNotDeployedOnSelectedChain ();
137175 }
138176 }
139177
178+ function _safeReadAddress (string memory json , string memory key ) private pure returns (address ) {
179+ string memory addrStr = json.readString (key);
180+ if (bytes (addrStr).length == 0 ) {
181+ return address (0 );
182+ }
183+ return json.readAddress (key);
184+ }
185+
186+ function _loadDeploymentTopLevel (string memory deploymentsJson , string memory deploymentKey ) private {
187+ __d.categoryRegistry = MultiTokenCategoryRegistry (_safeReadAddress (deploymentsJson, string .concat (deploymentKey, ".categoryRegistry " )));
188+ __d.chainlinkFeedRegistry = IChainlinkFeedRegistryLike (_safeReadAddress (deploymentsJson, string .concat (deploymentKey, ".chainlinkFeedRegistry " )));
189+ __d.config = PWNConfig (_safeReadAddress (deploymentsJson, string .concat (deploymentKey, ".config " )));
190+ __d.configSingleton = PWNConfig (_safeReadAddress (deploymentsJson, string .concat (deploymentKey, ".configSingleton " )));
191+ __d.hub = PWNHub (_safeReadAddress (deploymentsJson, string .concat (deploymentKey, ".hub " )));
192+ __d.loanToken = PWNLOAN (_safeReadAddress (deploymentsJson, string .concat (deploymentKey, ".loanToken " )));
193+
194+ address addr = _safeReadAddress (deploymentsJson, string .concat (deploymentKey, ".crowdsourceLenderVault " ));
195+ if (addr != address (0 )) __d.crowdsourceLenderVault = PWNCrowdsourceLenderVault (addr);
196+
197+ addr = _safeReadAddress (deploymentsJson, string .concat (deploymentKey, ".loan " ));
198+ if (addr != address (0 )) __d.loan = PWNLoan (addr);
199+
200+ addr = _safeReadAddress (deploymentsJson, string .concat (deploymentKey, ".revokedNonce " ));
201+ if (addr != address (0 )) __d.revokedNonce = PWNRevokedNonce (addr);
202+
203+ addr = _safeReadAddress (deploymentsJson, string .concat (deploymentKey, ".utilizedCredit " ));
204+ if (addr != address (0 )) __d.utilizedCredit = PWNUtilizedCredit (addr);
205+ }
206+
207+ function _loadDeploymentProducts (string memory deploymentsJson , string memory deploymentKey ) private {
208+ address addr = _safeReadAddress (deploymentsJson, string .concat (deploymentKey, ".products.stable " ));
209+ if (addr != address (0 )) __d.products.stable = PWNStableProduct (addr);
210+
211+ addr = _safeReadAddress (deploymentsJson, string .concat (deploymentKey, ".products.installments " ));
212+ if (addr != address (0 )) __d.products.installments = PWNInstallmentsProduct (addr);
213+
214+ addr = _safeReadAddress (deploymentsJson, string .concat (deploymentKey, ".products.fixed " ));
215+ if (addr != address (0 )) __d.products._fixed = PWNFixedProduct (addr);
216+
217+ addr = _safeReadAddress (deploymentsJson, string .concat (deploymentKey, ".products.uniswapV3Individual " ));
218+ if (addr != address (0 )) __d.products.uniswapV3Individual = PWNUniswapV3IndividualProduct (addr);
219+
220+ addr = _safeReadAddress (deploymentsJson, string .concat (deploymentKey, ".products.uniswapV3Set " ));
221+ if (addr != address (0 )) __d.products.uniswapV3Set = PWNUniswapV3SetProduct (addr);
222+ }
223+
224+ function _loadDeploymentHooks (string memory deploymentsJson , string memory deploymentKey ) private {
225+ address addr = _safeReadAddress (deploymentsJson, string .concat (deploymentKey, ".hooks.aaveLender " ));
226+ if (addr != address (0 )) __d.hooks.aaveLender = PWNAaveLenderHook (addr);
227+
228+ addr = _safeReadAddress (deploymentsJson, string .concat (deploymentKey, ".hooks.compoundLender " ));
229+ if (addr != address (0 )) __d.hooks.compoundLender = PWNCompoundLenderHook (addr);
230+
231+ addr = _safeReadAddress (deploymentsJson, string .concat (deploymentKey, ".hooks.directLenderRepayment " ));
232+ if (addr != address (0 )) __d.hooks.directLenderRepayment = PWNDirectLenderRepaymentHook (addr);
233+
234+ addr = _safeReadAddress (deploymentsJson, string .concat (deploymentKey, ".hooks.refinanceBorrowerCreate " ));
235+ if (addr != address (0 )) __d.hooks.refinanceBorrowerCreate = PWNRefinanceBorrowerCreateHook (addr);
236+
237+ addr = _safeReadAddress (deploymentsJson, string .concat (deploymentKey, ".hooks.vaultLender " ));
238+ if (addr != address (0 )) __d.hooks.vaultLender = PWN4626VaultLenderHook (addr);
239+ }
240+
140241 function _protocolNotDeployedOnSelectedChain () internal virtual {
141242 // Override
142243 }
0 commit comments