This repository has been archived by the owner on Nov 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Avalanche treasury migration #304
Merged
Zer0dot
merged 31 commits into
bgd-labs:main
from
defijesus:avalanche-treasury-migration
Sep 26, 2023
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
fade576
tokenlogic: add aave v2 polygon interest rate updates
defijesus 2c43785
Merge pull request #1 from bgd-labs/main
defijesus e94d879
finalize code changes?
defijesus 6cd686b
add assets for diffs
defijesus ac4da81
ready for review
defijesus f01df05
Merge pull request #2 from bgd-labs/main
defijesus a75ce74
quick fixes to .md
defijesus e5c458e
fix review issues
defijesus eecd3c3
fix: remove unneeded config fetching
defijesus 504bdc4
ensure payload address is the implemented payload before passing address
defijesus 1c31a57
fix typo in .md
defijesus e281ecb
Merge pull request #3 from bgd-labs/main
defijesus ff1c91f
Merge branch 'bgd-labs:main' into main
defijesus 39a4d49
Merge branch 'bgd-labs:main' into main
defijesus fc82b37
Merge branch 'bgd-labs:main' into main
defijesus feab379
Merge branch 'bgd-labs:main' into main
defijesus 5aad319
Merge branch 'bgd-labs:main' into main
defijesus e6729eb
Merge branch 'bgd-labs:main' into main
defijesus 7c512e6
Merge branch 'bgd-labs:main' into main
defijesus ef7e0af
update aave-address-book
defijesus 96d2ec7
Merge branch 'bgd-labs:main' into main
defijesus 6613e13
Merge branch 'bgd-labs:main' into main
defijesus 1498b4b
Merge branch 'bgd-labs:main' into main
defijesus 6329d33
Merge branch 'bgd-labs:main' into main
defijesus 6c3ee04
a lot to do
defijesus b6b1c17
Revert "a lot to do"
defijesus caa4598
Merge branch 'bgd-labs:main' into main
defijesus dcc75f6
a lot to do
defijesus a40cd21
stop migrating some assets. fix issues raised in review. ready for re…
defijesus 2b2880a
fix issues raised in review
defijesus 3f8b195
deploy payload, update .md & test
defijesus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
src/AaveAvalancheTreasuryMigration_20230903/AaveAvalancheTreasuryMigration_20230903.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
/* | ||
_ ΞΞΞΞ _ | ||
/_;-.__ / _\ _.-;_\ | ||
`-._`'`_/'`.-' | ||
`\ /` | ||
| / | ||
/-.( | ||
\_._\ | ||
\ \`; | ||
> |/ | ||
/ // | ||
|// | ||
\(\ | ||
`` | ||
defijesus.eth | ||
*/ | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import {IProposalGenericExecutor} from 'aave-helpers/interfaces/IProposalGenericExecutor.sol'; | ||
import {AaveV2Avalanche, AaveV2AvalancheAssets} from 'aave-address-book/AaveV2Avalanche.sol'; | ||
import {AaveV3Avalanche, AaveV3AvalancheAssets} from 'aave-address-book/AaveV3Avalanche.sol'; | ||
import {IERC20} from 'solidity-utils/contracts/oz-common/interfaces/IERC20.sol'; | ||
import {SafeERC20} from 'solidity-utils/contracts/oz-common/SafeERC20.sol'; | ||
import {IMigrationHelper} from 'aave-address-book/common/IMigrationHelper.sol'; | ||
|
||
/** | ||
* @dev Redeem aTokens from Aave v2 Avalanche and deposit the underlying assets into Aave v3 Avalanche. | ||
* @author defijesus.eth - TokenLogic | ||
* - Snapshot: https://snapshot.org/#/aave.eth/proposal/0xfe17ba406d90f8308794d14e8cad4f8d44c1f74e5589a5a106f9af17df916a59 | ||
* - Discussion: https://governance.aave.com/t/arfc-treasury-management-avalanche-v2-to-v3-migration/14469 | ||
*/ | ||
contract AaveAvalancheTreasuryMigration_20230903 is IProposalGenericExecutor { | ||
|
||
function execute() external { | ||
IMigrationHelper migrationHelper = IMigrationHelper(AaveV2Avalanche.MIGRATION_HELPER); | ||
|
||
address[] memory assetsToMigrate = new address[](4); | ||
assetsToMigrate[0] = AaveV2AvalancheAssets.DAIe_UNDERLYING; | ||
assetsToMigrate[1] = AaveV2AvalancheAssets.WBTCe_UNDERLYING; | ||
assetsToMigrate[2] = AaveV2AvalancheAssets.WETHe_UNDERLYING; | ||
assetsToMigrate[3] = AaveV2AvalancheAssets.WAVAX_UNDERLYING; | ||
|
||
IMigrationHelper.RepaySimpleInput[] memory positionsToRepay = new IMigrationHelper.RepaySimpleInput[](0); | ||
IMigrationHelper.PermitInput[] memory permits = new IMigrationHelper.PermitInput[](0); | ||
IMigrationHelper.CreditDelegationInput[] memory creditDelegationPermits = new IMigrationHelper.CreditDelegationInput[](0); | ||
|
||
uint256 i = 0; | ||
|
||
for(;i < assetsToMigrate.length;) { | ||
address aToken = migrationHelper.aTokens(assetsToMigrate[i]); | ||
uint256 amount = IERC20(aToken).balanceOf(address(AaveV2Avalanche.COLLECTOR)); | ||
AaveV2Avalanche.COLLECTOR.transfer(aToken, address(this), amount); | ||
SafeERC20.forceApprove(IERC20(aToken), address(migrationHelper), amount); | ||
unchecked { | ||
++i; | ||
} | ||
} | ||
|
||
migrationHelper.migrate(assetsToMigrate, positionsToRepay, permits, creditDelegationPermits); | ||
|
||
address[] memory newAssetsMigrated = new address[](4); | ||
newAssetsMigrated[0] = AaveV3AvalancheAssets.DAIe_A_TOKEN; | ||
newAssetsMigrated[1] = AaveV3AvalancheAssets.WBTCe_A_TOKEN; | ||
newAssetsMigrated[2] = AaveV3AvalancheAssets.WETHe_A_TOKEN; | ||
newAssetsMigrated[3] = AaveV3AvalancheAssets.WAVAX_A_TOKEN; | ||
|
||
for(i = 0; i < newAssetsMigrated.length;) { | ||
SafeERC20.safeTransfer( | ||
IERC20(newAssetsMigrated[i]), | ||
address(AaveV3Avalanche.COLLECTOR), | ||
IERC20(newAssetsMigrated[i]).balanceOf(address(this)) | ||
); | ||
unchecked { | ||
++i; | ||
} | ||
} | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
src/AaveAvalancheTreasuryMigration_20230903/AaveAvalancheTreasuryMigration_20230903.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import 'forge-std/Test.sol'; | ||
|
||
import {GovHelpers} from 'aave-helpers/GovHelpers.sol'; | ||
import {AaveGovernanceV2} from 'aave-address-book/AaveGovernanceV2.sol'; | ||
import {AaveV2Avalanche, AaveV2AvalancheAssets} from 'aave-address-book/AaveV2Avalanche.sol'; | ||
import {AaveV3Avalanche, AaveV3AvalancheAssets} from 'aave-address-book/AaveV3Avalanche.sol'; | ||
import {IERC20} from 'solidity-utils/contracts/oz-common/interfaces/IERC20.sol'; | ||
import {AaveAvalancheTreasuryMigration_20230903} from './AaveAvalancheTreasuryMigration_20230903.sol'; | ||
|
||
contract AaveAvalancheTreasuryMigration_20230903_Test is Test { | ||
function setUp() public { | ||
vm.createSelectFork(vm.rpcUrl('avalanche'), 35644766); | ||
} | ||
|
||
function testPayload() public { | ||
address[4] memory oldAssetsMigrated; | ||
oldAssetsMigrated[0] = AaveV2AvalancheAssets.DAIe_A_TOKEN; | ||
oldAssetsMigrated[1] = AaveV2AvalancheAssets.WBTCe_A_TOKEN; | ||
oldAssetsMigrated[2] = AaveV2AvalancheAssets.WETHe_A_TOKEN; | ||
oldAssetsMigrated[3] = AaveV2AvalancheAssets.WAVAX_A_TOKEN; | ||
|
||
address[4] memory newAssetsMigrated; | ||
newAssetsMigrated[0] = AaveV3AvalancheAssets.DAIe_A_TOKEN; | ||
newAssetsMigrated[1] = AaveV3AvalancheAssets.WBTCe_A_TOKEN; | ||
newAssetsMigrated[2] = AaveV3AvalancheAssets.WETHe_A_TOKEN; | ||
newAssetsMigrated[3] = AaveV3AvalancheAssets.WAVAX_A_TOKEN; | ||
|
||
uint256[4] memory newAssetsBeforeBalance; | ||
uint256[4] memory oldAssetsBeforeBalance; | ||
|
||
uint256 executorBalanceAfter; | ||
uint256 collectorBalanceAfter; | ||
|
||
for(uint256 i = 0; i < newAssetsMigrated.length; i++) { | ||
newAssetsBeforeBalance[i] = IERC20(newAssetsMigrated[i]).balanceOf(address(AaveV3Avalanche.COLLECTOR)); | ||
oldAssetsBeforeBalance[i] = IERC20(oldAssetsMigrated[i]).balanceOf(address(AaveV2Avalanche.COLLECTOR)); | ||
} | ||
|
||
AaveAvalancheTreasuryMigration_20230903 payload = AaveAvalancheTreasuryMigration_20230903(0x2DD58BeDC4A91110Bf9aF1d2bc3f13966d1C6643); | ||
|
||
GovHelpers.executePayload(vm, address(payload), AaveV3Avalanche.ACL_ADMIN); | ||
|
||
for(uint256 i = 0; i < oldAssetsMigrated.length; i++) { | ||
executorBalanceAfter = IERC20(oldAssetsMigrated[i]).balanceOf(AaveV3Avalanche.ACL_ADMIN); | ||
assertEq(executorBalanceAfter, 0); | ||
executorBalanceAfter = IERC20(newAssetsMigrated[i]).balanceOf(AaveV3Avalanche.ACL_ADMIN); | ||
assertEq(executorBalanceAfter, 0); | ||
} | ||
|
||
for(uint256 i = 0; i < newAssetsMigrated.length; i++) { | ||
collectorBalanceAfter = IERC20(newAssetsMigrated[i]).balanceOf(address(AaveV3Avalanche.COLLECTOR)); | ||
/// 0.001e18 is 0.1% | ||
assertApproxEqRel(newAssetsBeforeBalance[i] + oldAssetsBeforeBalance[i], collectorBalanceAfter, 0.001e18); | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/AaveAvalancheTreasuryMigration_20230903/DeployTreasuryMigration.s.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.16; | ||
import {AvalancheScript, EthereumScript} from 'aave-helpers/ScriptUtils.sol'; | ||
import {GovHelpers} from 'aave-helpers/GovHelpers.sol'; | ||
import {AaveAvalancheTreasuryMigration_20230903} from './AaveAvalancheTreasuryMigration_20230903.sol'; | ||
|
||
/** | ||
* @dev Deploy AaveAvalancheTreasuryMigration_20230903 | ||
* command: make deploy-ledger contract=src/AaveAvalancheTreasuryMigration_20230903/DeployTreasuryMigration.s.sol:DeployAvalancheV2TreasuryMigrationPayload chain=avalanche | ||
*/ | ||
contract DeployAvalancheV2TreasuryMigrationPayload is AvalancheScript { | ||
function run() external broadcast { | ||
new AaveAvalancheTreasuryMigration_20230903(); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...ncheTreasuryMigration_20230903/MIGRATE_AVALANCHE_V2_TREASURY_TO_AVALANCHE_V3.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--- | ||
title: Treasury Management - Avalanche v2 to v3 Migration | ||
discussions: https://governance.aave.com/t/arfc-treasury-management-avalanche-v2-to-v3-migration/14469 | ||
author: TokenLogic | ||
--- | ||
|
||
# Summary | ||
|
||
Redeem the Aave DAO funds on Aave v2 Avalanche and deposit underlying assets in Aave v3 Avalanche. | ||
|
||
# Motivation | ||
|
||
Aave DAO currently holds around $4.52M on Avalanche v2. There are several drivers for migrating Aave DAO's funds: | ||
|
||
* Higher deposit rates | ||
* wAVAX incentives | ||
* Encourage migration v2 to v3 | ||
|
||
# Specification | ||
|
||
Migrate the following holdings: | ||
|
||
| Asset | Migrate (%) | | ||
| --- | --- | | ||
|wBTC.e|100| | ||
|wETH.e|100| | ||
|DAI.e|100| | ||
|AVAX.e|100| | ||
|
||
Deposit wAVAX held passively in the Treasury into Aave v3. | ||
|
||
For reference, the Aave Avalanche v2 Treasury: [`0x5ba7fd868c40c16f7aDfAe6CF87121E13FC2F7a0`](https://snowtrace.io/address/0x5ba7fd868c40c16f7aDfAe6CF87121E13FC2F7a0) | ||
|
||
# Implementation | ||
|
||
A list of relevant links like for this proposal: | ||
|
||
* [Governance Forum Discussion](https://governance.aave.com/t/arfc-treasury-management-avalanche-v2-to-v3-migration/14469) | ||
* [Snapshot vote](https://snapshot.org/#/aave.eth/proposal/0x0be8229173181fe0aaf5ed1883e53752546efb810e55610e7ac8b991155ab788) | ||
* [Test Cases](https://github.com/bgd-labs/aave-proposals/tree/main/src/AaveAvalancheTreasuryMigration_20230903/AaveAvalancheTreasuryMigration_20230903.t.sol) | ||
* [Payload Implementation](https://github.com/bgd-labs/aave-proposals/tree/main/src/AaveAvalancheTreasuryMigration_20230903/AaveAvalancheTreasuryMigration_20230903.sol) | ||
* [Deployed Contracts](https://snowtrace.io/address/0x2dd58bedc4a91110bf9af1d2bc3f13966d1c6643) | ||
|
||
The proposal Payload was reviewed by [Bored Ghost Developing](https://bgdlabs.com/). | ||
|
||
# Disclaimer | ||
|
||
TokenLogic receives no payment from Aave DAO or any external source for the creation of this proposal. TokenLogic is a delegate within the Aave ecosystem. | ||
|
||
# Copyright | ||
|
||
Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/). |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious but why declare this outside the for statement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re-using the same variable on both for statements
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, no issue, but I've never really seen this before. If you declare it in the for statement it's still scoped in the for so you don't really need to declare a new one, don't think this would save much gas anyway.