forked from bgd-labs/protocol-v3.6-upgrade
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUpgradePayloadMainnet.sol
More file actions
190 lines (157 loc) · 7.77 KB
/
UpgradePayloadMainnet.sol
File metadata and controls
190 lines (157 loc) · 7.77 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.10;
import {ITransparentProxyFactory} from
"solidity-utils/contracts/transparent-proxy/interfaces/ITransparentProxyFactory.sol";
import {IPoolAddressesProvider} from "aave-v3-origin/contracts/interfaces/IPoolAddressesProvider.sol";
import {ConfiguratorInputTypes} from "aave-v3-origin/contracts/protocol/libraries/types/ConfiguratorInputTypes.sol";
import {AaveV3Ethereum, AaveV3EthereumAssets} from "aave-address-book/AaveV3Ethereum.sol";
import {MiscEthereum} from "aave-address-book/MiscEthereum.sol";
import {GovernanceV3Ethereum} from "aave-address-book/GovernanceV3Ethereum.sol";
import {GhoEthereum} from "aave-address-book/GhoEthereum.sol";
import {IGhoDirectMinter} from "gho-direct-minter/interfaces/IGhoDirectMinter.sol";
import {GhoDirectMinter} from "gho-direct-minter/GhoDirectMinter.sol";
import {IGhoToken} from "gho-direct-minter/interfaces/IGhoToken.sol";
import {IATokenMainnetInstanceGHO} from "./interfaces/IATokenMainnetInstanceGHO.sol";
import {IOldATokenMainnetInstanceGHO} from "./interfaces/IOldATokenMainnetInstanceGHO.sol";
import {IVariableDebtTokenMainnetInstanceGHO} from "./interfaces/IVariableDebtTokenMainnetInstanceGHO.sol";
import {IGhoBucketSteward} from "./interfaces/IGhoBucketSteward.sol";
import {UpgradePayload} from "./UpgradePayload.sol";
/**
* @title UpgradePayloadMainnet
* @notice Upgrade payload for the ETH Mainnet network to upgrade the Aave v3.3 to v3.4
* @author BGD Labs
*/
contract UpgradePayloadMainnet is UpgradePayload {
struct ConstructorMainnetParams {
IPoolAddressesProvider poolAddressesProvider;
address poolDataProvider;
address poolImpl;
address poolConfiguratorImpl;
address aTokenImpl;
address vTokenImpl;
address aTokenGhoImpl;
address vTokenGhoImpl;
address aTokenWithDelegationImpl;
address ghoFacilitatorImpl;
address council;
}
address public immutable A_TOKEN_GHO_IMPL;
address public immutable V_TOKEN_GHO_IMPL;
address public immutable A_TOKEN_WITH_DELEGATION_IMPL;
address public immutable FACILITATOR;
constructor(ConstructorMainnetParams memory params)
UpgradePayload(
ConstructorParams({
poolAddressesProvider: params.poolAddressesProvider,
poolDataProvider: params.poolDataProvider,
poolImpl: params.poolImpl,
poolConfiguratorImpl: params.poolConfiguratorImpl,
aTokenImpl: params.aTokenImpl,
vTokenImpl: params.vTokenImpl
})
)
{
A_TOKEN_GHO_IMPL = params.aTokenGhoImpl;
V_TOKEN_GHO_IMPL = params.vTokenGhoImpl;
A_TOKEN_WITH_DELEGATION_IMPL = params.aTokenWithDelegationImpl;
FACILITATOR = ITransparentProxyFactory(MiscEthereum.TRANSPARENT_PROXY_FACTORY).create(
params.ghoFacilitatorImpl,
MiscEthereum.PROXY_ADMIN,
abi.encodeWithSelector(GhoDirectMinter.initialize.selector, GovernanceV3Ethereum.EXECUTOR_LVL_1, params.council)
);
}
function execute() external override {
// 1. Give risk admin role to the new facilitator for accessing
// the `setSupplyCap` function in the `PoolConfigurator` contract
AaveV3Ethereum.ACL_MANAGER.addRiskAdmin(FACILITATOR);
// 2. Initialize the new facilitator with levels of the previous facilitator
(uint256 capacity, uint256 level) =
IGhoToken(AaveV3EthereumAssets.GHO_UNDERLYING).getFacilitatorBucket(AaveV3EthereumAssets.GHO_A_TOKEN);
IGhoToken(AaveV3EthereumAssets.GHO_UNDERLYING).addFacilitator(FACILITATOR, "GhoDirectMinter", uint128(capacity));
// Right now there is the total supply of the `GHO_A_TOKEN` equals to zero
// and also there is some GHO minted tokens by this aToken (variable `level`).
//
// We need to take into an account that there are some GHO tokens that the aToken contract
// holds on its balance. Need to call the `distributeFeesToTreasury` function of the the old GHO aToken
// to transfer this balance to the treasury. After this operation, the `GHO_A_TOKEN` will have
// zero GHO balance.
// 3. Transfer the current balance of the `GHO_A_TOKEN` to the treasury
IOldATokenMainnetInstanceGHO(AaveV3EthereumAssets.GHO_A_TOKEN).distributeFeesToTreasury();
// 4. Upgrade the POOL_CONFIGURATOR to the new version in order to be able to upgrade
// the aToken (the initialize function for the v3.4 aToken is different from the v3.3)
POOL_ADDRESSES_PROVIDER.setPoolConfiguratorImpl(POOL_CONFIGURATOR_IMPL);
// 5. Upgrade the aToken of the GHO token to the new version in order to be able to
// mint aTokens to the `GhoDirectMinter` contract
POOL_CONFIGURATOR.updateAToken(
ConfiguratorInputTypes.UpdateATokenInput({
asset: AaveV3EthereumAssets.GHO_UNDERLYING,
name: "Aave Ethereum GHO",
symbol: "aEthGHO",
implementation: A_TOKEN_GHO_IMPL,
params: ""
})
);
// 6. Mint and supply GHO to the pool
// Need to do this before the v3.4 upgrade in order not to change the `virtualUnderlyingBalance` variable
// in the Pool contract. Right now it equals to zero.
IGhoDirectMinter(FACILITATOR).mintAndSupply(level);
// 7. call the `resolveFacilitator` function on the aToken to burn the underlying GHO, in turn reducing level to 0
IATokenMainnetInstanceGHO(AaveV3EthereumAssets.GHO_A_TOKEN).resolveFacilitator(level);
// 8. remove the old facilitator
IGhoToken(AaveV3EthereumAssets.GHO_UNDERLYING).removeFacilitator(AaveV3EthereumAssets.GHO_A_TOKEN);
// 9. set reserve factor to 100% so all fee is accrued to treasury and index stays at 1
POOL_CONFIGURATOR.setReserveFactor(AaveV3EthereumAssets.GHO_UNDERLYING, 100_00);
// 10. set a supply cap so noone can supply, as 0 currently is unlimited
POOL_CONFIGURATOR.setSupplyCap(AaveV3EthereumAssets.GHO_UNDERLYING, 1);
// 11. Make the normal v3.4 upgrade
_defaultUpgrade();
// 12. Upgrade the vToken of the GHO token to the new version
POOL_CONFIGURATOR.updateVariableDebtToken(
ConfiguratorInputTypes.UpdateDebtTokenInput({
asset: AaveV3EthereumAssets.GHO_UNDERLYING,
name: "Aave Ethereum Variable Debt GHO",
symbol: "variableDebtEthGHO",
implementation: V_TOKEN_GHO_IMPL,
params: ""
})
);
// 13. Upgrade the aToken of the AAVE token to the new version
POOL_CONFIGURATOR.updateAToken(
ConfiguratorInputTypes.UpdateATokenInput({
asset: AaveV3EthereumAssets.AAVE_UNDERLYING,
name: "Aave Ethereum AAVE",
symbol: "aEthAAVE",
implementation: A_TOKEN_WITH_DELEGATION_IMPL,
params: ""
})
);
// 14. Upgrade the vToken of the AAVE token to the new version
POOL_CONFIGURATOR.updateVariableDebtToken(
ConfiguratorInputTypes.UpdateDebtTokenInput({
asset: AaveV3EthereumAssets.AAVE_UNDERLYING,
name: "Aave Ethereum Variable Debt AAVE",
symbol: "variableDebtEthAAVE",
implementation: V_TOKEN_IMPL,
params: ""
})
);
// 15. Enable flashloans for GHO
POOL_CONFIGURATOR.setReserveFlashLoaning({asset: AaveV3EthereumAssets.GHO_UNDERLYING, enabled: true});
// 16. Mint supply on the instance
if (capacity > level) {
IGhoDirectMinter(FACILITATOR).mintAndSupply(capacity - level);
}
// 17. Allow risk council to control the bucket capacity
address[] memory vaults = new address[](1);
vaults[0] = FACILITATOR;
IGhoBucketSteward(GhoEthereum.GHO_BUCKET_STEWARD).setControlledFacilitator(vaults, true);
vaults[0] = AaveV3EthereumAssets.GHO_A_TOKEN;
IGhoBucketSteward(GhoEthereum.GHO_BUCKET_STEWARD).setControlledFacilitator(vaults, false);
}
function _needToUpdateReserve(address reserve) internal view virtual override returns (bool) {
if (reserve == AaveV3EthereumAssets.GHO_UNDERLYING || reserve == AaveV3EthereumAssets.AAVE_UNDERLYING) {
return false;
}
return true;
}
}