Skip to content

Commit 058e1de

Browse files
authored
fix: update scripts (bgd-labs#3)
* fix: update scripts * fix: use from address book
1 parent ed4226f commit 058e1de

21 files changed

Lines changed: 581 additions & 435 deletions

README.md

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,22 @@ The upgrade is executed via specialized `UpgradePayload` contracts deployed on e
1717
Several changes in v3.4 require specific actions during the upgrade process:
1818

1919
1. **Storage Slot Migration (`virtualUnderlyingBalance`):**
20-
* In v3.3, reserves had an `unbacked` storage slot which was unused. In v3.4, this feature is removed.
21-
* The `virtualUnderlyingBalance` slot (previously `__deprecatedVirtualUnderlyingBalance`) is moved into the storage slot previously occupied by `unbacked` for gas optimization.
22-
* **Action:** The `initialize` function within the new `Pool` implementations (`PoolInstanceWithCustomInitialize`, `L2PoolInstanceWithCustomInitialize`), using the `CustomInitialize._initialize` library function, iterates through all reserves upon the first initialization after the upgrade. It copies the value from the old `__deprecatedVirtualUnderlyingBalance` slot to the new `virtualUnderlyingBalance` slot and zeroes out the old slot.
20+
21+
- In v3.3, reserves had an `unbacked` storage slot which was unused. In v3.4, this feature is removed.
22+
- The `virtualUnderlyingBalance` slot (previously `__deprecatedVirtualUnderlyingBalance`) is moved into the storage slot previously occupied by `unbacked` for gas optimization.
23+
- **Action:** The `initialize` function within the new `Pool` implementations (`PoolInstanceWithCustomInitialize`, `L2PoolInstanceWithCustomInitialize`), using the `CustomInitialize._initialize` library function, iterates through all reserves upon the first initialization after the upgrade. It copies the value from the old `__deprecatedVirtualUnderlyingBalance` slot to the new `virtualUnderlyingBalance` slot and zeroes out the old slot.
2324

2425
2. **Flashloan Premium Capture:**
25-
* The `FLASHLOAN_PREMIUM_TO_PROTOCOL` becomes a constant (100_00) in the v3.4 `Pool` implementation.
26-
* **Action:** The `PoolConfiguratorWithCustomInitialize` implementation, which is set *before* the Pool is upgraded, reads the *old* dynamic value from the v3.3 Pool via `_pool.FLASHLOAN_PREMIUM_TO_PROTOCOL()` during its `initialize` function and emits an event (`FlashloanPremiumToProtocolUpdated`) if it differs from the new constant value. This ensures the old value is recorded before it becomes inaccessible.
26+
27+
- The `FLASHLOAN_PREMIUM_TO_PROTOCOL` becomes a constant (100_00) in the v3.4 `Pool` implementation.
28+
- **Action:** The `PoolConfiguratorWithCustomInitialize` implementation, which is set _before_ the Pool is upgraded, reads the _old_ dynamic value from the v3.3 Pool via `_pool.FLASHLOAN_PREMIUM_TO_PROTOCOL()` during its `initialize` function and emits an event (`FlashloanPremiumToProtocolUpdated`) if it differs from the new constant value. This ensures the old value is recorded before it becomes inaccessible.
2729

2830
3. **Deprecated Storage Cleanup (GHO Tokens on Mainnet):**
29-
* The v3.3 `aGHO` and `vGHO` contracts contained specific storage variables (`ghoVariableDebtToken`, `ghoTreasury` in aToken; `ghoAToken`, `discountToken`, `discountRateStrategy` in vToken) that are not present in standard tokens or the v3.4 GHO tokens.
30-
* **Action:**
31-
* The custom `ATokenMainnetInstanceGHO` implementation's `resolveFacilitator` function (called during the GHO migration) explicitly deletes the deprecated aToken storage slots.
32-
* The custom `VariableDebtTokenMainnetInstanceGHO` implementation's `initialize` function explicitly deletes the deprecated vToken storage slots.
33-
* This cleanup prevents potential storage collisions if future Aave versions add new variables at these storage slots for standard tokens.
31+
- The v3.3 `aGHO` and `vGHO` contracts contained specific storage variables (`ghoVariableDebtToken`, `ghoTreasury` in aToken; `ghoAToken`, `discountToken`, `discountRateStrategy` in vToken) that are not present in standard tokens or the v3.4 GHO tokens.
32+
- **Action:**
33+
- The custom `ATokenMainnetInstanceGHO` implementation's `resolveFacilitator` function (called during the GHO migration) explicitly deletes the deprecated aToken storage slots.
34+
- The custom `VariableDebtTokenMainnetInstanceGHO` implementation's `initialize` function explicitly deletes the deprecated vToken storage slots.
35+
- This cleanup prevents potential storage collisions if future Aave versions add new variables at these storage slots for standard tokens.
3436

3537
## General Upgrade Sequence (via `UpgradePayload`)
3638

@@ -40,33 +42,35 @@ This sequence applies to most networks (Polygon, Optimism, Arbitrum, etc.).
4042
2. **Upgrade Pool Implementation:** The `Pool` contract is updated to the new `PoolInstanceWithCustomInitialize` implementation (or `L2PoolInstanceWithCustomInitialize` in L2 networks). The `initialize` function of this new pool handles the `virtualUnderlyingBalance` storage migration.
4143
3. **Set New PoolDataProvider:** The `PoolAddressesProvider` is updated to point to the new `AaveProtocolDataProvider` implementation.
4244
4. **Update AToken/VariableDebtToken Implementations:** The payload iterates through all reserves listed in the Pool:
43-
* For each reserve, it calls `POOL_CONFIGURATOR.updateAToken` to upgrade the reserve's AToken proxy to the new standard `ATokenInstance` implementation (`A_TOKEN_IMPL`).
44-
* It then calls `POOL_CONFIGURATOR.updateVariableDebtToken` to upgrade the reserve's VariableDebtToken proxy to the new standard `VariableDebtTokenInstance` implementation (`V_TOKEN_IMPL`).
45+
- For each reserve, it calls `POOL_CONFIGURATOR.updateAToken` to upgrade the reserve's AToken proxy to the new standard `ATokenInstance` implementation (`A_TOKEN_IMPL`).
46+
- It then calls `POOL_CONFIGURATOR.updateVariableDebtToken` to upgrade the reserve's VariableDebtToken proxy to the new standard `VariableDebtTokenInstance` implementation (`V_TOKEN_IMPL`).
4547

4648
## Ethereum Mainnet Upgrade Sequence (via `UpgradePayloadMainnet`)
4749

4850
This sequence includes the general steps plus specific GHO migration steps, executed in a precise order after the `UpgradePayloadMainnet` contract is deployed.
4951

5052
**Pre-Execution Step (Payload Constructor):**
5153

52-
* **Deploy and Initialize New Facilitator:** The new `GhoDirectMinter` proxy contract (`FACILITATOR`) is deployed and initialized using the `TransparentProxyFactory` within the `constructor` of the `UpgradePayloadMainnet` contract. Its implementation, admin, owner (Executor LVL 1), and council are set during this deployment process.
54+
- **Deploy and Initialize New Facilitator:** The new `GhoDirectMinter` proxy contract (`FACILITATOR`) is deployed and initialized using the `TransparentProxyFactory` within the `constructor` of the `UpgradePayloadMainnet` contract. Its implementation, admin, owner (Executor LVL 1), and council are set during this deployment process.
5355

5456
**Execution Steps (Inside `execute()` function):**
5557

5658
1. **Grant Facilitator Risk Admin:** The `ACL_MANAGER` grants the `RISK_ADMIN` role to the `GhoDirectMinter` contract (`FACILITATOR`). This allows it to call `setSupplyCap` by the `GhoDirectMinter` contract.
5759
2. **Add New Facilitator to GhoToken:**
58-
* The current GHO bucket capacity and level of the old `aGHO` facilitator are fetched from the `GhoToken`.
59-
* The new `GhoDirectMinter` (`FACILITATOR`) is added as a GHO facilitator in the `GhoToken` contract (`IGhoToken(...).addFacilitator(...)`) using the fetched capacity.
60+
- The current GHO bucket capacity and level of the old `aGHO` facilitator are fetched from the `GhoToken`.
61+
- The new `GhoDirectMinter` (`FACILITATOR`) is added as a GHO facilitator in the `GhoToken` contract (`IGhoToken(...).addFacilitator(...)`) using the fetched capacity.
6062
3. **Distribute Old aGHO Fees:** `IOldATokenMainnetInstanceGHO(AaveV3EthereumAssets.GHO_A_TOKEN).distributeFeesToTreasury()` is called to send any accumulated GHO fees in the old aToken contract to the treasury. It is required step to make the balance of the `GHO_A_TOKEN` equal to zero.
6163
4. **Upgrade PoolConfigurator Implementation:** The `PoolConfigurator` contract is updated to the new `PoolConfiguratorWithCustomInitialize` implementation.
6264
5. **Upgrade aGHO to Custom Intermediate Implementation:** `POOL_CONFIGURATOR.updateAToken` is called for the GHO asset, setting its implementation to the custom `ATokenMainnetInstanceGHO` (`A_TOKEN_GHO_IMPL`). This implementation includes the `resolveFacilitator` function and storage cleanup logic.
6365
6. **Mint and Supply by New Facilitator:** The `mintAndSupply` function of the new `GhoDirectMinter` (`FACILITATOR`) is called, minting GHO equal to the old `aGHO` facilitator's `level` and supplying it to the Aave pool, receiving `aGHO` tokens.
64-
7. **Resolve Old Facilitator:** `IATokenMainnetInstanceGHO(AaveV3EthereumAssets.GHO_A_TOKEN).resolveFacilitator(level)` is called. This function on the *custom* `aGHO` implementation burns the underlying GHO token amount equal to `level` (balancing the mint in step 6) and clears the deprecated storage slots within the `aGHO` contract proxy's storage.
66+
7. **Resolve Old Facilitator:** `IATokenMainnetInstanceGHO(AaveV3EthereumAssets.GHO_A_TOKEN).resolveFacilitator(level)` is called. This function on the _custom_ `aGHO` implementation burns the underlying GHO token amount equal to `level` (balancing the mint in step 6) and clears the deprecated storage slots within the `aGHO` contract proxy's storage.
6567
8. **Remove Old Facilitator:** `IGhoToken(AaveV3EthereumAssets.GHO_UNDERLYING).removeFacilitator(AaveV3EthereumAssets.GHO_A_TOKEN)` is called. Since its level is now 0 (due to the burn in step 7), the old `aGHO` contract is successfully removed as a facilitator from the `GhoToken`.
6668
9. **Set GHO Reserve Factor:** `POOL_CONFIGURATOR.setReserveFactor` sets GHO's reserve factor to 100% (10000).
6769
10. **Set GHO Supply Cap:** `POOL_CONFIGURATOR.setSupplyCap` sets GHO's supply cap to 1 wei, effectively preventing user GHO deposits.
6870
11. **Execute Default Upgrade Steps:** The `_defaultUpgrade()` function is called, performing steps 2, 3, and 4 from the "General Upgrade Sequence" above (Upgrade Pool Impl, Set Data Provider, Update standard A/V Tokens), skipping GHO and AAVE tokens as specified by the overridden `_needToUpdateReserve`.
6971
12. **Upgrade vGHO to Custom Implementation:** `POOL_CONFIGURATOR.updateVariableDebtToken` is called for GHO, setting its implementation to the custom `VariableDebtTokenMainnetInstanceGHO` (`V_TOKEN_GHO_IMPL`). This version includes storage cleanup and a no-op `updateDiscountDistribution` function for compatibility.
7072
13. **Upgrade aAAVE Implementation:** `POOL_CONFIGURATOR.updateAToken` updates the AAVE AToken to the `ATokenWithDelegationInstance` (`A_TOKEN_WITH_DELEGATION_IMPL`).
7173
14. **Upgrade vAAVE Implementation:** `POOL_CONFIGURATOR.updateVariableDebtToken` updates the AAVE VariableDebtToken to the standard `VariableDebtTokenInstance` (`V_TOKEN_IMPL`).
72-
15. **Enable GHO Flashloaning:** `POOL_CONFIGURATOR.setReserveFlashLoaning` enables flash loans for the GHO reserve.
74+
15. **Enable GHO Flashloaning:** `POOL_CONFIGURATOR.setReserveFlashLoaning` enables flash loans for the GHO reserve.
75+
16. **Mint GHO to the pool:** Calling the `mintAndSupply` function once again to mint the remaining(non borrowed) capacity as supply on the pool.
76+
17. **Add stewards permissions:** Calling `setControlledFacilitator` on the bucket facilitator migrate permissions to the new facilitator.

reports/100_0xb50201558B00496A145fE76f7424749556E326D8_after.json

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"poolAddressesProvider": "0x36616cf17557639614c1cdDb356b1B83fc0B2132",
3636
"poolConfigurator": "0x7304979ec9E4EaA0273b6A037a31c4e9e5A75D16",
3737
"priceOracleSentinel": "0x0000000000000000000000000000000000000000",
38-
"protocolDataProvider": "0x7e253cc89EF9761ED56f5659ce9a65E51cdebADB"
38+
"protocolDataProvider": "0x3A3E744a9b0925de6de18D5d65444F8f4c0594E1"
3939
},
4040
"raw": {
4141
"0x0c0fce05f2314540ecb095bf4d069e5e0ed90ff8": {
@@ -72,7 +72,7 @@
7272
},
7373
"0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc": {
7474
"previousValue": "0x000000000000000000000000bec519531f0e78bcddb295242fa4ec5251b38574",
75-
"newValue": "0x000000000000000000000000b8907e68531d30121bcdec9ac329286c15b9aa1e"
75+
"newValue": "0x0000000000000000000000003cd1abc04e44e154b302b0b23d8f8363f1943320"
7676
}
7777
}
7878
},
@@ -110,7 +110,7 @@
110110
},
111111
"0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc": {
112112
"previousValue": "0x000000000000000000000000589750ba8af186ce5b55391b0b7148cad43a1619",
113-
"newValue": "0x000000000000000000000000ec8c2055a1a7e4c6a1ee225edb27093ce63c0768"
113+
"newValue": "0x00000000000000000000000026aceee63e3ab2f7f9ea3562c7a842375f982c73"
114114
}
115115
}
116116
},
@@ -148,7 +148,7 @@
148148
},
149149
"0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc": {
150150
"previousValue": "0x000000000000000000000000bec519531f0e78bcddb295242fa4ec5251b38574",
151-
"newValue": "0x000000000000000000000000b8907e68531d30121bcdec9ac329286c15b9aa1e"
151+
"newValue": "0x0000000000000000000000003cd1abc04e44e154b302b0b23d8f8363f1943320"
152152
}
153153
}
154154
},
@@ -158,7 +158,7 @@
158158
"stateDiff": {
159159
"0xcd7944601aaa5cd7ccdae1bebec659e98c6aac8f12486b30e59db0d39698051f": {
160160
"previousValue": "0x000000000000000000000000a2d323dbc43f445ad2d8974f17be5dab32aad474",
161-
"newValue": "0x0000000000000000000000007e253cc89ef9761ed56f5659ce9a65e51cdebadb"
161+
"newValue": "0x0000000000000000000000003a3e744a9b0925de6de18d5d65444f8f4c0594e1"
162162
}
163163
}
164164
},
@@ -196,7 +196,7 @@
196196
},
197197
"0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc": {
198198
"previousValue": "0x000000000000000000000000bec519531f0e78bcddb295242fa4ec5251b38574",
199-
"newValue": "0x000000000000000000000000b8907e68531d30121bcdec9ac329286c15b9aa1e"
199+
"newValue": "0x0000000000000000000000003cd1abc04e44e154b302b0b23d8f8363f1943320"
200200
}
201201
}
202202
},
@@ -234,7 +234,7 @@
234234
},
235235
"0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc": {
236236
"previousValue": "0x000000000000000000000000bec519531f0e78bcddb295242fa4ec5251b38574",
237-
"newValue": "0x000000000000000000000000b8907e68531d30121bcdec9ac329286c15b9aa1e"
237+
"newValue": "0x0000000000000000000000003cd1abc04e44e154b302b0b23d8f8363f1943320"
238238
}
239239
}
240240
},
@@ -260,7 +260,7 @@
260260
},
261261
"0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc": {
262262
"previousValue": "0x000000000000000000000000e5e48ad1f9d1a894188b483dcf91f4fad6aba43b",
263-
"newValue": "0x000000000000000000000000fb01fc9f1450051c338ecddbb6f629ae97fcb5c3"
263+
"newValue": "0x00000000000000000000000079358c61f86b1c389849fa8ca1ec3790b5db0693"
264264
}
265265
}
266266
},
@@ -298,7 +298,7 @@
298298
},
299299
"0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc": {
300300
"previousValue": "0x000000000000000000000000589750ba8af186ce5b55391b0b7148cad43a1619",
301-
"newValue": "0x000000000000000000000000ec8c2055a1a7e4c6a1ee225edb27093ce63c0768"
301+
"newValue": "0x00000000000000000000000026aceee63e3ab2f7f9ea3562c7a842375f982c73"
302302
}
303303
}
304304
},
@@ -336,7 +336,7 @@
336336
},
337337
"0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc": {
338338
"previousValue": "0x000000000000000000000000bec519531f0e78bcddb295242fa4ec5251b38574",
339-
"newValue": "0x000000000000000000000000b8907e68531d30121bcdec9ac329286c15b9aa1e"
339+
"newValue": "0x0000000000000000000000003cd1abc04e44e154b302b0b23d8f8363f1943320"
340340
}
341341
}
342342
},
@@ -388,7 +388,7 @@
388388
},
389389
"0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc": {
390390
"previousValue": "0x000000000000000000000000bec519531f0e78bcddb295242fa4ec5251b38574",
391-
"newValue": "0x000000000000000000000000b8907e68531d30121bcdec9ac329286c15b9aa1e"
391+
"newValue": "0x0000000000000000000000003cd1abc04e44e154b302b0b23d8f8363f1943320"
392392
},
393393
"0xbbe3212124853f8b0084a66a2d057c2966e251e132af3691db153ab65f0d1a4d": {
394394
"previousValue": "0x4161766520476e6f736973205661726961626c65204465627420777374455448",
@@ -430,7 +430,7 @@
430430
},
431431
"0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc": {
432432
"previousValue": "0x000000000000000000000000589750ba8af186ce5b55391b0b7148cad43a1619",
433-
"newValue": "0x000000000000000000000000ec8c2055a1a7e4c6a1ee225edb27093ce63c0768"
433+
"newValue": "0x00000000000000000000000026aceee63e3ab2f7f9ea3562c7a842375f982c73"
434434
}
435435
}
436436
},
@@ -468,7 +468,7 @@
468468
},
469469
"0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc": {
470470
"previousValue": "0x000000000000000000000000589750ba8af186ce5b55391b0b7148cad43a1619",
471-
"newValue": "0x000000000000000000000000ec8c2055a1a7e4c6a1ee225edb27093ce63c0768"
471+
"newValue": "0x00000000000000000000000026aceee63e3ab2f7f9ea3562c7a842375f982c73"
472472
}
473473
}
474474
},
@@ -502,7 +502,7 @@
502502
},
503503
"0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc": {
504504
"previousValue": "0x00000000000000000000000077c874799e9564a0d0670ed40bf023d249e7bb21",
505-
"newValue": "0x0000000000000000000000009e3547043cae9c7223b9f0a885ad5d973f0fd47d"
505+
"newValue": "0x00000000000000000000000096861c73ee3387eb6d9488cfba643b64abc66654"
506506
},
507507
"0x45fb21bff46f3219261e8dfd39448f990f239040f94fb8fbbbea3b4a28f27697": {
508508
"previousValue": "0x00000000000000000000000000000000000000000000000000000000014a885e",
@@ -588,7 +588,7 @@
588588
},
589589
"0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc": {
590590
"previousValue": "0x000000000000000000000000bec519531f0e78bcddb295242fa4ec5251b38574",
591-
"newValue": "0x000000000000000000000000b8907e68531d30121bcdec9ac329286c15b9aa1e"
591+
"newValue": "0x0000000000000000000000003cd1abc04e44e154b302b0b23d8f8363f1943320"
592592
}
593593
}
594594
},
@@ -626,7 +626,7 @@
626626
},
627627
"0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc": {
628628
"previousValue": "0x000000000000000000000000bec519531f0e78bcddb295242fa4ec5251b38574",
629-
"newValue": "0x000000000000000000000000b8907e68531d30121bcdec9ac329286c15b9aa1e"
629+
"newValue": "0x0000000000000000000000003cd1abc04e44e154b302b0b23d8f8363f1943320"
630630
}
631631
}
632632
},
@@ -664,7 +664,7 @@
664664
},
665665
"0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc": {
666666
"previousValue": "0x000000000000000000000000589750ba8af186ce5b55391b0b7148cad43a1619",
667-
"newValue": "0x000000000000000000000000ec8c2055a1a7e4c6a1ee225edb27093ce63c0768"
667+
"newValue": "0x00000000000000000000000026aceee63e3ab2f7f9ea3562c7a842375f982c73"
668668
}
669669
}
670670
},
@@ -702,7 +702,7 @@
702702
},
703703
"0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc": {
704704
"previousValue": "0x000000000000000000000000589750ba8af186ce5b55391b0b7148cad43a1619",
705-
"newValue": "0x000000000000000000000000ec8c2055a1a7e4c6a1ee225edb27093ce63c0768"
705+
"newValue": "0x00000000000000000000000026aceee63e3ab2f7f9ea3562c7a842375f982c73"
706706
}
707707
}
708708
},
@@ -740,7 +740,7 @@
740740
},
741741
"0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc": {
742742
"previousValue": "0x000000000000000000000000589750ba8af186ce5b55391b0b7148cad43a1619",
743-
"newValue": "0x000000000000000000000000ec8c2055a1a7e4c6a1ee225edb27093ce63c0768"
743+
"newValue": "0x00000000000000000000000026aceee63e3ab2f7f9ea3562c7a842375f982c73"
744744
}
745745
}
746746
},
@@ -778,7 +778,7 @@
778778
},
779779
"0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc": {
780780
"previousValue": "0x000000000000000000000000589750ba8af186ce5b55391b0b7148cad43a1619",
781-
"newValue": "0x000000000000000000000000ec8c2055a1a7e4c6a1ee225edb27093ce63c0768"
781+
"newValue": "0x00000000000000000000000026aceee63e3ab2f7f9ea3562c7a842375f982c73"
782782
}
783783
}
784784
}

0 commit comments

Comments
 (0)