Skip to content

Commit ac9fd33

Browse files
committed
feat: migrate treasury deployment from peripheryBatch to setupBatch
1 parent 6b79da1 commit ac9fd33

File tree

9 files changed

+103
-100
lines changed

9 files changed

+103
-100
lines changed

src/deployments/contracts/procedures/AaveV3SetupProcedure.sol

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import {PoolAddressesProvider} from '../../../contracts/protocol/configuration/P
1010
import {PoolAddressesProviderRegistry} from '../../../contracts/protocol/configuration/PoolAddressesProviderRegistry.sol';
1111
import {IEmissionManager} from '../../../contracts/rewards/interfaces/IEmissionManager.sol';
1212
import {IRewardsController} from '../../../contracts/rewards/interfaces/IRewardsController.sol';
13+
import {Collector} from '../../../contracts/treasury/Collector.sol';
14+
import {ProxyAdmin} from 'solidity-utils/contracts/transparent-proxy/ProxyAdmin.sol';
15+
import {TransparentUpgradeableProxy} from 'solidity-utils/contracts/transparent-proxy/TransparentUpgradeableProxy.sol';
16+
import {RevenueSplitter} from '../../../contracts/treasury/RevenueSplitter.sol';
1317

1418
contract AaveV3SetupProcedure {
1519
error MarketOwnerMustBeSet();
@@ -27,6 +31,15 @@ contract AaveV3SetupProcedure {
2731
address priceOracleSentinel;
2832
}
2933

34+
struct TreasuryInput {
35+
address treasuryProxy;
36+
address treasuryPartner;
37+
uint16 treasurySplitPercent;
38+
address proxyAdmin;
39+
address aclManager;
40+
bytes32 salt;
41+
}
42+
3043
function _initialDeployment(
3144
address providerRegistry,
3245
address marketOwner,
@@ -54,7 +67,8 @@ contract AaveV3SetupProcedure {
5467
address protocolDataProvider,
5568
address aaveOracle,
5669
address rewardsControllerImplementation,
57-
address priceOracleSentinel
70+
address priceOracleSentinel,
71+
address proxyAdmin
5872
) internal returns (SetupReport memory) {
5973
_validateMarketSetup(roles);
6074

@@ -80,6 +94,17 @@ contract AaveV3SetupProcedure {
8094
config.flashLoanPremiumToProtocol
8195
);
8296

97+
(report.treasuryProxy, report.treasuryImplementation, report.revenueSplitter) = _setupTreasury(
98+
TreasuryInput({
99+
treasuryProxy: config.treasury,
100+
treasuryPartner: config.treasuryPartner,
101+
treasurySplitPercent: config.treasurySplitPercent,
102+
proxyAdmin: proxyAdmin,
103+
aclManager: report.aclManager,
104+
salt: config.salt
105+
})
106+
);
107+
83108
_transferMarketOwnership(roles, initialReport);
84109

85110
return report;
@@ -183,6 +208,60 @@ contract AaveV3SetupProcedure {
183208
return aclManager;
184209
}
185210

211+
function _deployAaveV3Treasury(
212+
address deployedProxyAdmin,
213+
address aclManager,
214+
bytes32 salt
215+
) internal returns (address treasuryProxy, address treasuryImplementation) {
216+
if (salt != '') {
217+
treasuryImplementation = address(new Collector{salt: salt}(aclManager));
218+
Collector(treasuryImplementation).initialize(0);
219+
220+
treasuryProxy = address(
221+
new TransparentUpgradeableProxy{salt: salt}(
222+
treasuryImplementation,
223+
ProxyAdmin(deployedProxyAdmin),
224+
abi.encodeWithSelector(Collector.initialize.selector, 100_000)
225+
)
226+
);
227+
} else {
228+
treasuryImplementation = address(new Collector(aclManager));
229+
Collector(treasuryImplementation).initialize(0);
230+
231+
treasuryProxy = address(
232+
new TransparentUpgradeableProxy(
233+
treasuryImplementation,
234+
ProxyAdmin(deployedProxyAdmin),
235+
abi.encodeWithSelector(Collector.initialize.selector, 100_000)
236+
)
237+
);
238+
}
239+
}
240+
241+
function _setupTreasury(
242+
TreasuryInput memory input
243+
) internal returns (address treasuryProxy, address treasuryImplementation, address revenueSplitter) {
244+
if (input.treasuryProxy == address(0)) {
245+
(treasuryProxy, treasuryImplementation) = _deployAaveV3Treasury(
246+
input.proxyAdmin,
247+
input.aclManager,
248+
input.salt
249+
);
250+
} else {
251+
treasuryProxy = input.treasuryProxy;
252+
}
253+
254+
if (
255+
input.treasuryPartner != address(0) &&
256+
input.treasurySplitPercent > 0 &&
257+
input.treasurySplitPercent < 100_00
258+
) {
259+
revenueSplitter = address(
260+
new RevenueSplitter(treasuryProxy, input.treasuryPartner, input.treasurySplitPercent)
261+
);
262+
}
263+
}
264+
186265
function _configureFlashloanParams(
187266
ACLManager manager,
188267
address poolConfiguratorProxy,

src/deployments/contracts/procedures/AaveV3TreasuryProcedure.sol

Lines changed: 0 additions & 53 deletions
This file was deleted.

src/deployments/interfaces/IMarketReportTypes.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,16 +168,16 @@ struct SetupReport {
168168
address poolConfiguratorProxy;
169169
address rewardsControllerProxy;
170170
address aclManager;
171+
address treasuryProxy;
172+
address treasuryImplementation;
173+
address revenueSplitter;
171174
}
172175

173176
struct PeripheryReport {
174177
address aaveOracle;
175178
address proxyAdmin;
176-
address treasury;
177-
address treasuryImplementation;
178179
address emissionManager;
179180
address rewardsControllerImplementation;
180-
address revenueSplitter;
181181
}
182182

183183
struct ParaswapReport {

src/deployments/projects/aave-v3-batched/AaveV3BatchOrchestration.sol

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ library AaveV3BatchOrchestration {
7070
gettersReport1.protocolDataProvider,
7171
peripheryReport.aaveOracle,
7272
peripheryReport.rewardsControllerImplementation,
73-
miscReport.priceOracleSentinel
73+
miscReport.priceOracleSentinel,
74+
peripheryReport.proxyAdmin
7475
);
7576

7677
ParaswapReport memory paraswapReport = _deployParaswapAdapters(
@@ -169,9 +170,9 @@ library AaveV3BatchOrchestration {
169170
PeripheryReport memory peripheryReport,
170171
AaveV3TokensBatch.TokensReport memory tokensReport
171172
) internal returns (ConfigEngineReport memory) {
172-
address treasury = peripheryReport.treasury;
173-
if (peripheryReport.revenueSplitter != address(0)) {
174-
treasury = peripheryReport.revenueSplitter;
173+
address treasury = setupReport.treasuryProxy;
174+
if (setupReport.revenueSplitter != address(0)) {
175+
treasury = setupReport.revenueSplitter;
175176
}
176177

177178
AaveV3HelpersBatchOne helpersBatchOne = new AaveV3HelpersBatchOne(
@@ -310,9 +311,9 @@ library AaveV3BatchOrchestration {
310311
report.paraSwapLiquiditySwapAdapter = paraswapReport.paraSwapLiquiditySwapAdapter;
311312
report.paraSwapRepayAdapter = paraswapReport.paraSwapRepayAdapter;
312313
report.paraSwapWithdrawSwapAdapter = paraswapReport.paraSwapWithdrawSwapAdapter;
313-
report.treasuryImplementation = peripheryReport.treasuryImplementation;
314+
report.treasuryImplementation = setupReport.treasuryImplementation;
314315
report.proxyAdmin = peripheryReport.proxyAdmin;
315-
report.treasury = peripheryReport.treasury;
316+
report.treasury = setupReport.treasuryProxy;
316317
report.poolProxy = setupReport.poolProxy;
317318
report.poolConfiguratorProxy = setupReport.poolConfiguratorProxy;
318319
report.rewardsControllerProxy = setupReport.rewardsControllerProxy;
@@ -326,7 +327,7 @@ library AaveV3BatchOrchestration {
326327
report.staticATokenFactoryProxy = staticATokenReport.staticATokenFactoryProxy;
327328
report.staticATokenImplementation = staticATokenReport.staticATokenImplementation;
328329
report.transparentProxyFactory = staticATokenReport.transparentProxyFactory;
329-
report.revenueSplitter = peripheryReport.revenueSplitter;
330+
report.revenueSplitter = setupReport.revenueSplitter;
330331

331332
return report;
332333
}

src/deployments/projects/aave-v3-batched/batches/AaveV3PeripheryBatch.sol

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
// SPDX-License-Identifier: BUSL-1.1
22
pragma solidity ^0.8.0;
33

4-
import {AaveV3TreasuryProcedure} from '../../../contracts/procedures/AaveV3TreasuryProcedure.sol';
54
import {AaveV3OracleProcedure} from '../../../contracts/procedures/AaveV3OracleProcedure.sol';
65
import {AaveV3IncentiveProcedure} from '../../../contracts/procedures/AaveV3IncentiveProcedure.sol';
76
import {AaveV3DefaultRateStrategyProcedure} from '../../../contracts/procedures/AaveV3DefaultRateStrategyProcedure.sol';
87
import {Ownable} from '../../../../contracts/dependencies/openzeppelin/contracts/Ownable.sol';
98
import '../../../interfaces/IMarketReportTypes.sol';
109
import {IRewardsController} from '../../../../contracts/rewards/interfaces/IRewardsController.sol';
11-
import {RevenueSplitter} from '../../../../contracts/treasury/RevenueSplitter.sol';
1210

1311
contract AaveV3PeripheryBatch is
14-
AaveV3TreasuryProcedure,
1512
AaveV3OracleProcedure,
1613
AaveV3IncentiveProcedure
1714
{
@@ -31,32 +28,6 @@ contract AaveV3PeripheryBatch is
3128

3229
_report.aaveOracle = _deployAaveOracle(config.oracleDecimals, poolAddressesProvider);
3330

34-
address aclManager = address(1); // temp-to-run-tests
35-
36-
if (config.treasury == address(0)) {
37-
TreasuryReport memory treasuryReport = _deployAaveV3Treasury(
38-
poolAdmin,
39-
_report.proxyAdmin,
40-
aclManager,
41-
config.salt
42-
);
43-
44-
_report.treasury = treasuryReport.treasury;
45-
_report.treasuryImplementation = treasuryReport.treasuryImplementation;
46-
} else {
47-
_report.treasury = config.treasury;
48-
}
49-
50-
if (
51-
config.treasuryPartner != address(0) &&
52-
config.treasurySplitPercent > 0 &&
53-
config.treasurySplitPercent < 100_00
54-
) {
55-
_report.revenueSplitter = address(
56-
new RevenueSplitter(_report.treasury, config.treasuryPartner, config.treasurySplitPercent)
57-
);
58-
}
59-
6031
if (config.incentivesProxy == address(0)) {
6132
(_report.emissionManager, _report.rewardsControllerImplementation) = _deployIncentives(
6233
setupBatch

src/deployments/projects/aave-v3-batched/batches/AaveV3SetupBatch.sol

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ contract AaveV3SetupBatch is MarketReportStorage, AaveV3SetupProcedure, Ownable
3333
address protocolDataProvider,
3434
address aaveOracle,
3535
address rewardsControllerImplementation,
36-
address priceOracleSentinel
36+
address priceOracleSentinel,
37+
address proxyAdmin
3738
) external onlyOwner returns (SetupReport memory) {
3839
_setupReport = _setupAaveV3Market(
3940
roles,
@@ -44,7 +45,8 @@ contract AaveV3SetupBatch is MarketReportStorage, AaveV3SetupProcedure, Ownable
4445
protocolDataProvider,
4546
aaveOracle,
4647
rewardsControllerImplementation,
47-
priceOracleSentinel
48+
priceOracleSentinel,
49+
proxyAdmin
4850
);
4951

5052
return _setupReport;

tests/deployments/AaveV3BatchTests.t.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ contract AaveV3BatchTests is BatchTestProcedures {
175175
gettersReportOne.protocolDataProvider,
176176
peripheryReportOne.aaveOracle,
177177
peripheryReportOne.rewardsControllerImplementation,
178-
miscReport.priceOracleSentinel
178+
miscReport.priceOracleSentinel,
179+
peripheryReportOne.proxyAdmin
179180
);
180181
}
181182

@@ -190,7 +191,7 @@ contract AaveV3BatchTests is BatchTestProcedures {
190191
miscReport.defaultInterestRateStrategy,
191192
peripheryReportOne.aaveOracle,
192193
setupReportTwo.rewardsControllerProxy,
193-
peripheryReportOne.treasury,
194+
setupReportTwo.treasuryProxy,
194195
tokensReport.aToken,
195196
tokensReport.variableDebtToken
196197
);

tests/deployments/DeploymentsGasLimits.t.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ contract DeploymentsGasLimits is BatchTestProcedures {
160160
gettersReportOne.protocolDataProvider,
161161
peripheryReportOne.aaveOracle,
162162
peripheryReportOne.rewardsControllerImplementation,
163-
miscReport.priceOracleSentinel
163+
miscReport.priceOracleSentinel,
164+
peripheryReportOne.proxyAdmin
164165
);
165166
}
166167

@@ -175,7 +176,7 @@ contract DeploymentsGasLimits is BatchTestProcedures {
175176
miscReport.defaultInterestRateStrategy,
176177
peripheryReportOne.aaveOracle,
177178
setupReportTwo.rewardsControllerProxy,
178-
peripheryReportOne.treasury,
179+
setupReportTwo.treasuryProxy,
179180
tokensReport.aToken,
180181
tokensReport.variableDebtToken
181182
);

tests/utils/BatchTestProcedures.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ contract BatchTestProcedures is Test, DeployUtils, FfiUtils, DefaultMarketInput
141141
gettersReport1.protocolDataProvider,
142142
peripheryReport.aaveOracle,
143143
peripheryReport.rewardsControllerImplementation,
144-
miscReport.priceOracleSentinel
144+
miscReport.priceOracleSentinel,
145+
peripheryReport.proxyAdmin
145146
);
146147

147148
paraswapReport = AaveV3BatchOrchestration._deployParaswapAdapters(

0 commit comments

Comments
 (0)