Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Avalanche treasury migration #304

Merged
merged 31 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
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 Jun 14, 2023
2c43785
Merge pull request #1 from bgd-labs/main
defijesus Jun 14, 2023
e94d879
finalize code changes?
defijesus Jun 15, 2023
6cd686b
add assets for diffs
defijesus Jun 15, 2023
ac4da81
ready for review
defijesus Jun 16, 2023
f01df05
Merge pull request #2 from bgd-labs/main
defijesus Jun 16, 2023
a75ce74
quick fixes to .md
defijesus Jun 16, 2023
e5c458e
fix review issues
defijesus Jun 16, 2023
eecd3c3
fix: remove unneeded config fetching
defijesus Jun 16, 2023
504bdc4
ensure payload address is the implemented payload before passing address
defijesus Jun 16, 2023
1c31a57
fix typo in .md
defijesus Jun 16, 2023
e281ecb
Merge pull request #3 from bgd-labs/main
defijesus Jun 21, 2023
ff1c91f
Merge branch 'bgd-labs:main' into main
defijesus Jun 22, 2023
39a4d49
Merge branch 'bgd-labs:main' into main
defijesus Jun 30, 2023
fc82b37
Merge branch 'bgd-labs:main' into main
defijesus Jul 17, 2023
feab379
Merge branch 'bgd-labs:main' into main
defijesus Jul 27, 2023
5aad319
Merge branch 'bgd-labs:main' into main
defijesus Jul 31, 2023
e6729eb
Merge branch 'bgd-labs:main' into main
defijesus Aug 9, 2023
7c512e6
Merge branch 'bgd-labs:main' into main
defijesus Aug 16, 2023
ef7e0af
update aave-address-book
defijesus Aug 16, 2023
96d2ec7
Merge branch 'bgd-labs:main' into main
defijesus Aug 16, 2023
6613e13
Merge branch 'bgd-labs:main' into main
defijesus Aug 22, 2023
1498b4b
Merge branch 'bgd-labs:main' into main
defijesus Aug 28, 2023
6329d33
Merge branch 'bgd-labs:main' into main
defijesus Sep 14, 2023
6c3ee04
a lot to do
defijesus Sep 19, 2023
b6b1c17
Revert "a lot to do"
defijesus Sep 19, 2023
caa4598
Merge branch 'bgd-labs:main' into main
defijesus Sep 19, 2023
dcc75f6
a lot to do
defijesus Sep 19, 2023
a40cd21
stop migrating some assets. fix issues raised in review. ready for re…
defijesus Sep 20, 2023
2b2880a
fix issues raised in review
defijesus Sep 22, 2023
3f8b195
deploy payload, update .md & test
defijesus Sep 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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.


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;
}
}
}
}
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);
}
}
}
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();
}
}
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/).