|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +pragma solidity ^0.8.0; |
| 3 | + |
| 4 | +import 'forge-std/Vm.sol'; |
| 5 | + |
| 6 | +import {Logger} from 'src/deployments/utils/Logger.sol'; |
| 7 | +import {BatchReports} from 'src/deployments/types/BatchReports.sol'; |
| 8 | +import {AaveV4AccessBatch} from 'src/deployments/batches/AaveV4AccessBatch.sol'; |
| 9 | +import {AaveV4HubBatch} from 'src/deployments/batches/AaveV4HubBatch.sol'; |
| 10 | +import {AaveV4SpokeInstanceBatch} from 'src/deployments/batches/AaveV4SpokeInstanceBatch.sol'; |
| 11 | +import {AaveV4GatewaysBatch} from 'src/deployments/batches/AaveV4GatewaysBatch.sol'; |
| 12 | + |
| 13 | +library AaveV4DeployOrchestration { |
| 14 | + Vm private constant vm = Vm(address(bytes20(uint160(uint256(keccak256('hevm cheat code')))))); |
| 15 | + |
| 16 | + uint256 constant ORACLE_DECIMALS = 8; |
| 17 | + string constant ORACLE_SUFFIX = ' (USD)'; |
| 18 | + |
| 19 | + struct SpokeDeploymentReport { |
| 20 | + string label; |
| 21 | + BatchReports.SpokeInstanceBatchReport report; |
| 22 | + } |
| 23 | + |
| 24 | + struct HubDeploymentReport { |
| 25 | + string label; |
| 26 | + BatchReports.HubBatchReport report; |
| 27 | + } |
| 28 | + |
| 29 | + struct FullDeploymentReport { |
| 30 | + BatchReports.AccessBatchReport accessBatchReport; |
| 31 | + SpokeDeploymentReport spokeInstanceBatchReport; |
| 32 | + HubDeploymentReport hubBatchReport; |
| 33 | + BatchReports.GatewaysBatchReport gatewaysBatchReport; |
| 34 | + } |
| 35 | + |
| 36 | + function deployAaveV4( |
| 37 | + Logger logger, |
| 38 | + address deployer, |
| 39 | + address admin, |
| 40 | + address nativeWrapper, |
| 41 | + string[] memory hubLabels, |
| 42 | + string[] memory spokeLabels |
| 43 | + ) internal returns (FullDeploymentReport memory) { |
| 44 | + FullDeploymentReport memory report; |
| 45 | + |
| 46 | + // Deploy Access Batch |
| 47 | + report.accessBatchReport = _deployAccessBatch(admin); |
| 48 | + logger.log('AccessManager', report.accessBatchReport.accessManagerAddress); |
| 49 | + |
| 50 | + // Deploy Hub Batches |
| 51 | + uint256 hubCount = hubLabels.length; |
| 52 | + Logger.AddressEntry[] memory hubEntries = new Logger.AddressEntry[](hubCount); |
| 53 | + for (uint256 i; i < hubCount; i++) { |
| 54 | + report.hubBatchReport.label = hubLabels[i]; |
| 55 | + report.hubBatchReport.report = deployHub( |
| 56 | + admin, |
| 57 | + report.accessBatchReport.accessManagerAddress, |
| 58 | + hubLabels[i] |
| 59 | + ); |
| 60 | + hubEntries[i] = Logger.AddressEntry({ |
| 61 | + label: hubLabels[i], |
| 62 | + value: report.hubBatchReport.report.hubAddress |
| 63 | + }); |
| 64 | + logger.log( |
| 65 | + string.concat(hubLabels[i], ' Hub'), |
| 66 | + report.hubBatchReport.report.hubAddress |
| 67 | + ); |
| 68 | + logger.log( |
| 69 | + string.concat(hubLabels[i], ' InterestRateStrategy'), |
| 70 | + report.hubBatchReport.report.irStrategyAddress |
| 71 | + ); |
| 72 | + logger.log( |
| 73 | + string.concat(hubLabels[i], ' TreasurySpoke'), |
| 74 | + report.hubBatchReport.report.treasurySpokeAddress |
| 75 | + ); |
| 76 | + logger.log( |
| 77 | + string.concat(hubLabels[i], ' HubConfigurator'), |
| 78 | + report.hubBatchReport.report.hubConfiguratorAddress |
| 79 | + ); |
| 80 | + } |
| 81 | + logger.writeGroup('Hubs', hubEntries); |
| 82 | + |
| 83 | + // Deploy Spoke Instance Batches |
| 84 | + uint256 spokeCount = spokeLabels.length; |
| 85 | + Logger.AddressEntry[] memory spokeEntries = new Logger.AddressEntry[](spokeCount); |
| 86 | + for (uint256 i; i < spokeCount; i++) { |
| 87 | + report.spokeInstanceBatchReport.label = spokeLabels[i]; |
| 88 | + report.spokeInstanceBatchReport.report = deploySpoke( |
| 89 | + deployer, |
| 90 | + admin, |
| 91 | + report.accessBatchReport.accessManagerAddress, |
| 92 | + spokeLabels[i] |
| 93 | + ); |
| 94 | + spokeEntries[i] = Logger.AddressEntry({ |
| 95 | + label: spokeLabels[i], |
| 96 | + value: report.spokeInstanceBatchReport.report.spokeProxyAddress |
| 97 | + }); |
| 98 | + logger.log( |
| 99 | + string.concat(spokeLabels[i], ' SpokeInstance Proxy'), |
| 100 | + report.spokeInstanceBatchReport.report.spokeProxyAddress |
| 101 | + ); |
| 102 | + logger.log( |
| 103 | + string.concat(spokeLabels[i], ' SpokeInstance Implementation'), |
| 104 | + report.spokeInstanceBatchReport.report.spokeImplementationAddress |
| 105 | + ); |
| 106 | + logger.log( |
| 107 | + string.concat(spokeLabels[i], ' AaveOracle'), |
| 108 | + report.spokeInstanceBatchReport.report.aaveOracleAddress |
| 109 | + ); |
| 110 | + logger.log( |
| 111 | + string.concat(spokeLabels[i], ' SpokeConfigurator'), |
| 112 | + report.spokeInstanceBatchReport.report.spokeConfiguratorAddress |
| 113 | + ); |
| 114 | + } |
| 115 | + logger.writeGroup('SpokeInstances', spokeEntries); |
| 116 | + |
| 117 | + // Deploy Gateways Batch |
| 118 | + report.gatewaysBatchReport = _deployGatewaysBatch(admin, nativeWrapper); |
| 119 | + logger.log('NativeTokenGateway', report.gatewaysBatchReport.nativeGatewayAddress); |
| 120 | + logger.log('SignatureGateway', report.gatewaysBatchReport.signatureGatewayAddress); |
| 121 | + |
| 122 | + return report; |
| 123 | + } |
| 124 | + |
| 125 | + function deployHub( |
| 126 | + Logger logger, |
| 127 | + address admin, |
| 128 | + address accessManagerAddress, |
| 129 | + string memory label |
| 130 | + ) internal returns (HubDeploymentReport memory) { |
| 131 | + HubDeploymentReport memory hubReport; |
| 132 | + hubReport.label = label; |
| 133 | + hubReport.report = _deployHubBatch(admin, accessManagerAddress); |
| 134 | + logger.write('Hub', hubReport.report.hubAddress); |
| 135 | + logger.write('InterestRateStrategy', hubReport.report.irStrategyAddress); |
| 136 | + logger.write('TreasurySpoke', hubReport.report.treasurySpokeAddress); |
| 137 | + logger.write('HubConfigurator', hubReport.report.hubConfiguratorAddress); |
| 138 | + return hubReport; |
| 139 | + } |
| 140 | + |
| 141 | + function deploySpoke( |
| 142 | + Logger logger, |
| 143 | + address deployer, |
| 144 | + address admin, |
| 145 | + address accessManagerAddress, |
| 146 | + string memory label |
| 147 | + ) internal returns (SpokeDeploymentReport memory) { |
| 148 | + SpokeDeploymentReport memory spokeReport; |
| 149 | + spokeReport.label = label; |
| 150 | + spokeReport.report = _deploySpokeInstanceBatch(deployer, admin, accessManagerAddress, label); |
| 151 | + logger.write('SpokeInstance Proxy', spokeReport.report.spokeProxyAddress); |
| 152 | + logger.write('SpokeInstance Implementation', spokeReport.report.spokeImplementationAddress); |
| 153 | + logger.write('AaveOracle', spokeReport.report.aaveOracleAddress); |
| 154 | + logger.write('SpokeConfigurator', spokeReport.report.spokeConfiguratorAddress); |
| 155 | + return spokeReport; |
| 156 | + } |
| 157 | + |
| 158 | + function _deployAccessBatch( |
| 159 | + address admin |
| 160 | + ) private returns (BatchReports.AccessBatchReport memory) { |
| 161 | + AaveV4AccessBatch accessBatch = new AaveV4AccessBatch(admin); |
| 162 | + return accessBatch.getReport(); |
| 163 | + } |
| 164 | + |
| 165 | + function _deployHubBatch( |
| 166 | + address admin, |
| 167 | + address accessManagerAddress |
| 168 | + ) private returns (BatchReports.HubBatchReport memory) { |
| 169 | + AaveV4HubBatch hubBatch = new AaveV4HubBatch(admin, accessManagerAddress); |
| 170 | + return hubBatch.getReport(); |
| 171 | + } |
| 172 | + |
| 173 | + function _deploySpokeInstanceBatch( |
| 174 | + address deployer, |
| 175 | + address admin, |
| 176 | + address accessManagerAddress, |
| 177 | + string memory label |
| 178 | + ) private returns (BatchReports.SpokeInstanceBatchReport memory) { |
| 179 | + AaveV4SpokeInstanceBatch spokeInstanceBatch = new AaveV4SpokeInstanceBatch( |
| 180 | + vm, |
| 181 | + deployer, |
| 182 | + admin, |
| 183 | + accessManagerAddress, |
| 184 | + ORACLE_DECIMALS, |
| 185 | + string.concat(label, ORACLE_SUFFIX) |
| 186 | + ); |
| 187 | + return spokeInstanceBatch.getReport(); |
| 188 | + } |
| 189 | + |
| 190 | + function _deployGatewaysBatch( |
| 191 | + address admin, |
| 192 | + address nativeWrapper |
| 193 | + ) private returns (BatchReports.GatewaysBatchReport memory) { |
| 194 | + AaveV4GatewaysBatch gatewaysBatch = new AaveV4GatewaysBatch(admin, nativeWrapper); |
| 195 | + return gatewaysBatch.getReport(); |
| 196 | + } |
| 197 | +} |
0 commit comments