Skip to content

Commit

Permalink
feat: migrate treasury deployment from peripheryBatch to setupBatch
Browse files Browse the repository at this point in the history
  • Loading branch information
brotherlymite committed Dec 5, 2024
1 parent 6b79da1 commit ac9fd33
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 100 deletions.
81 changes: 80 additions & 1 deletion src/deployments/contracts/procedures/AaveV3SetupProcedure.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import {PoolAddressesProvider} from '../../../contracts/protocol/configuration/P
import {PoolAddressesProviderRegistry} from '../../../contracts/protocol/configuration/PoolAddressesProviderRegistry.sol';
import {IEmissionManager} from '../../../contracts/rewards/interfaces/IEmissionManager.sol';
import {IRewardsController} from '../../../contracts/rewards/interfaces/IRewardsController.sol';
import {Collector} from '../../../contracts/treasury/Collector.sol';
import {ProxyAdmin} from 'solidity-utils/contracts/transparent-proxy/ProxyAdmin.sol';
import {TransparentUpgradeableProxy} from 'solidity-utils/contracts/transparent-proxy/TransparentUpgradeableProxy.sol';
import {RevenueSplitter} from '../../../contracts/treasury/RevenueSplitter.sol';

contract AaveV3SetupProcedure {
error MarketOwnerMustBeSet();
Expand All @@ -27,6 +31,15 @@ contract AaveV3SetupProcedure {
address priceOracleSentinel;
}

struct TreasuryInput {
address treasuryProxy;
address treasuryPartner;
uint16 treasurySplitPercent;
address proxyAdmin;
address aclManager;
bytes32 salt;
}

function _initialDeployment(
address providerRegistry,
address marketOwner,
Expand Down Expand Up @@ -54,7 +67,8 @@ contract AaveV3SetupProcedure {
address protocolDataProvider,
address aaveOracle,
address rewardsControllerImplementation,
address priceOracleSentinel
address priceOracleSentinel,
address proxyAdmin
) internal returns (SetupReport memory) {
_validateMarketSetup(roles);

Expand All @@ -80,6 +94,17 @@ contract AaveV3SetupProcedure {
config.flashLoanPremiumToProtocol
);

(report.treasuryProxy, report.treasuryImplementation, report.revenueSplitter) = _setupTreasury(
TreasuryInput({
treasuryProxy: config.treasury,
treasuryPartner: config.treasuryPartner,
treasurySplitPercent: config.treasurySplitPercent,
proxyAdmin: proxyAdmin,
aclManager: report.aclManager,
salt: config.salt
})
);

_transferMarketOwnership(roles, initialReport);

return report;
Expand Down Expand Up @@ -183,6 +208,60 @@ contract AaveV3SetupProcedure {
return aclManager;
}

function _deployAaveV3Treasury(
address deployedProxyAdmin,
address aclManager,
bytes32 salt
) internal returns (address treasuryProxy, address treasuryImplementation) {
if (salt != '') {
treasuryImplementation = address(new Collector{salt: salt}(aclManager));
Collector(treasuryImplementation).initialize(0);

treasuryProxy = address(
new TransparentUpgradeableProxy{salt: salt}(
treasuryImplementation,
ProxyAdmin(deployedProxyAdmin),
abi.encodeWithSelector(Collector.initialize.selector, 100_000)
)
);
} else {
treasuryImplementation = address(new Collector(aclManager));
Collector(treasuryImplementation).initialize(0);

treasuryProxy = address(
new TransparentUpgradeableProxy(
treasuryImplementation,
ProxyAdmin(deployedProxyAdmin),
abi.encodeWithSelector(Collector.initialize.selector, 100_000)
)
);
}
}

function _setupTreasury(
TreasuryInput memory input
) internal returns (address treasuryProxy, address treasuryImplementation, address revenueSplitter) {
if (input.treasuryProxy == address(0)) {
(treasuryProxy, treasuryImplementation) = _deployAaveV3Treasury(
input.proxyAdmin,
input.aclManager,
input.salt
);
} else {
treasuryProxy = input.treasuryProxy;
}

if (
input.treasuryPartner != address(0) &&
input.treasurySplitPercent > 0 &&
input.treasurySplitPercent < 100_00
) {
revenueSplitter = address(
new RevenueSplitter(treasuryProxy, input.treasuryPartner, input.treasurySplitPercent)
);
}
}

function _configureFlashloanParams(
ACLManager manager,
address poolConfiguratorProxy,
Expand Down
53 changes: 0 additions & 53 deletions src/deployments/contracts/procedures/AaveV3TreasuryProcedure.sol

This file was deleted.

6 changes: 3 additions & 3 deletions src/deployments/interfaces/IMarketReportTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,16 @@ struct SetupReport {
address poolConfiguratorProxy;
address rewardsControllerProxy;
address aclManager;
address treasuryProxy;
address treasuryImplementation;
address revenueSplitter;
}

struct PeripheryReport {
address aaveOracle;
address proxyAdmin;
address treasury;
address treasuryImplementation;
address emissionManager;
address rewardsControllerImplementation;
address revenueSplitter;
}

struct ParaswapReport {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ library AaveV3BatchOrchestration {
gettersReport1.protocolDataProvider,
peripheryReport.aaveOracle,
peripheryReport.rewardsControllerImplementation,
miscReport.priceOracleSentinel
miscReport.priceOracleSentinel,
peripheryReport.proxyAdmin
);

ParaswapReport memory paraswapReport = _deployParaswapAdapters(
Expand Down Expand Up @@ -169,9 +170,9 @@ library AaveV3BatchOrchestration {
PeripheryReport memory peripheryReport,
AaveV3TokensBatch.TokensReport memory tokensReport
) internal returns (ConfigEngineReport memory) {
address treasury = peripheryReport.treasury;
if (peripheryReport.revenueSplitter != address(0)) {
treasury = peripheryReport.revenueSplitter;
address treasury = setupReport.treasuryProxy;
if (setupReport.revenueSplitter != address(0)) {
treasury = setupReport.revenueSplitter;
}

AaveV3HelpersBatchOne helpersBatchOne = new AaveV3HelpersBatchOne(
Expand Down Expand Up @@ -310,9 +311,9 @@ library AaveV3BatchOrchestration {
report.paraSwapLiquiditySwapAdapter = paraswapReport.paraSwapLiquiditySwapAdapter;
report.paraSwapRepayAdapter = paraswapReport.paraSwapRepayAdapter;
report.paraSwapWithdrawSwapAdapter = paraswapReport.paraSwapWithdrawSwapAdapter;
report.treasuryImplementation = peripheryReport.treasuryImplementation;
report.treasuryImplementation = setupReport.treasuryImplementation;
report.proxyAdmin = peripheryReport.proxyAdmin;
report.treasury = peripheryReport.treasury;
report.treasury = setupReport.treasuryProxy;
report.poolProxy = setupReport.poolProxy;
report.poolConfiguratorProxy = setupReport.poolConfiguratorProxy;
report.rewardsControllerProxy = setupReport.rewardsControllerProxy;
Expand All @@ -326,7 +327,7 @@ library AaveV3BatchOrchestration {
report.staticATokenFactoryProxy = staticATokenReport.staticATokenFactoryProxy;
report.staticATokenImplementation = staticATokenReport.staticATokenImplementation;
report.transparentProxyFactory = staticATokenReport.transparentProxyFactory;
report.revenueSplitter = peripheryReport.revenueSplitter;
report.revenueSplitter = setupReport.revenueSplitter;

return report;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import {AaveV3TreasuryProcedure} from '../../../contracts/procedures/AaveV3TreasuryProcedure.sol';
import {AaveV3OracleProcedure} from '../../../contracts/procedures/AaveV3OracleProcedure.sol';
import {AaveV3IncentiveProcedure} from '../../../contracts/procedures/AaveV3IncentiveProcedure.sol';
import {AaveV3DefaultRateStrategyProcedure} from '../../../contracts/procedures/AaveV3DefaultRateStrategyProcedure.sol';
import {Ownable} from '../../../../contracts/dependencies/openzeppelin/contracts/Ownable.sol';
import '../../../interfaces/IMarketReportTypes.sol';
import {IRewardsController} from '../../../../contracts/rewards/interfaces/IRewardsController.sol';
import {RevenueSplitter} from '../../../../contracts/treasury/RevenueSplitter.sol';

contract AaveV3PeripheryBatch is
AaveV3TreasuryProcedure,
AaveV3OracleProcedure,
AaveV3IncentiveProcedure
{
Expand All @@ -31,32 +28,6 @@ contract AaveV3PeripheryBatch is

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

address aclManager = address(1); // temp-to-run-tests

if (config.treasury == address(0)) {
TreasuryReport memory treasuryReport = _deployAaveV3Treasury(
poolAdmin,
_report.proxyAdmin,
aclManager,
config.salt
);

_report.treasury = treasuryReport.treasury;
_report.treasuryImplementation = treasuryReport.treasuryImplementation;
} else {
_report.treasury = config.treasury;
}

if (
config.treasuryPartner != address(0) &&
config.treasurySplitPercent > 0 &&
config.treasurySplitPercent < 100_00
) {
_report.revenueSplitter = address(
new RevenueSplitter(_report.treasury, config.treasuryPartner, config.treasurySplitPercent)
);
}

if (config.incentivesProxy == address(0)) {
(_report.emissionManager, _report.rewardsControllerImplementation) = _deployIncentives(
setupBatch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ contract AaveV3SetupBatch is MarketReportStorage, AaveV3SetupProcedure, Ownable
address protocolDataProvider,
address aaveOracle,
address rewardsControllerImplementation,
address priceOracleSentinel
address priceOracleSentinel,
address proxyAdmin
) external onlyOwner returns (SetupReport memory) {
_setupReport = _setupAaveV3Market(
roles,
Expand All @@ -44,7 +45,8 @@ contract AaveV3SetupBatch is MarketReportStorage, AaveV3SetupProcedure, Ownable
protocolDataProvider,
aaveOracle,
rewardsControllerImplementation,
priceOracleSentinel
priceOracleSentinel,
proxyAdmin
);

return _setupReport;
Expand Down
5 changes: 3 additions & 2 deletions tests/deployments/AaveV3BatchTests.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ contract AaveV3BatchTests is BatchTestProcedures {
gettersReportOne.protocolDataProvider,
peripheryReportOne.aaveOracle,
peripheryReportOne.rewardsControllerImplementation,
miscReport.priceOracleSentinel
miscReport.priceOracleSentinel,
peripheryReportOne.proxyAdmin
);
}

Expand All @@ -190,7 +191,7 @@ contract AaveV3BatchTests is BatchTestProcedures {
miscReport.defaultInterestRateStrategy,
peripheryReportOne.aaveOracle,
setupReportTwo.rewardsControllerProxy,
peripheryReportOne.treasury,
setupReportTwo.treasuryProxy,
tokensReport.aToken,
tokensReport.variableDebtToken
);
Expand Down
5 changes: 3 additions & 2 deletions tests/deployments/DeploymentsGasLimits.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ contract DeploymentsGasLimits is BatchTestProcedures {
gettersReportOne.protocolDataProvider,
peripheryReportOne.aaveOracle,
peripheryReportOne.rewardsControllerImplementation,
miscReport.priceOracleSentinel
miscReport.priceOracleSentinel,
peripheryReportOne.proxyAdmin
);
}

Expand All @@ -175,7 +176,7 @@ contract DeploymentsGasLimits is BatchTestProcedures {
miscReport.defaultInterestRateStrategy,
peripheryReportOne.aaveOracle,
setupReportTwo.rewardsControllerProxy,
peripheryReportOne.treasury,
setupReportTwo.treasuryProxy,
tokensReport.aToken,
tokensReport.variableDebtToken
);
Expand Down
3 changes: 2 additions & 1 deletion tests/utils/BatchTestProcedures.sol
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ contract BatchTestProcedures is Test, DeployUtils, FfiUtils, DefaultMarketInput
gettersReport1.protocolDataProvider,
peripheryReport.aaveOracle,
peripheryReport.rewardsControllerImplementation,
miscReport.priceOracleSentinel
miscReport.priceOracleSentinel,
peripheryReport.proxyAdmin
);

paraswapReport = AaveV3BatchOrchestration._deployParaswapAdapters(
Expand Down

0 comments on commit ac9fd33

Please sign in to comment.