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 29 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/0x1b816c12b6f547a1982198ffd0e36412390b05828b560c9edee4e8a6903c4882
defijesus marked this conversation as resolved.
Show resolved Hide resolved
* - Discussion: https://governance.aave.com/t/arfc-migrate-consolidate-polygon-treasury/12248
defijesus marked this conversation as resolved.
Show resolved Hide resolved
*/
contract AaveAvalancheTreasuryMigration_20230903 is IProposalGenericExecutor {

function execute() external {
IMigrationHelper MIGRATION_HELPER = IMigrationHelper(AaveV2Avalanche.MIGRATION_HELPER);

address[] memory ASSETS_TO_MIGRATE = new address[](4);
defijesus marked this conversation as resolved.
Show resolved Hide resolved
ASSETS_TO_MIGRATE[0] = AaveV2AvalancheAssets.DAIe_UNDERLYING;
ASSETS_TO_MIGRATE[1] = AaveV2AvalancheAssets.WBTCe_UNDERLYING;
ASSETS_TO_MIGRATE[2] = AaveV2AvalancheAssets.WETHe_UNDERLYING;
ASSETS_TO_MIGRATE[3] = AaveV2AvalancheAssets.WAVAX_UNDERLYING;

IMigrationHelper.RepaySimpleInput[] memory POSITIONS_TO_REPAY = new IMigrationHelper.RepaySimpleInput[](0);
defijesus marked this conversation as resolved.
Show resolved Hide resolved
IMigrationHelper.PermitInput[] memory PERMITS = new IMigrationHelper.PermitInput[](0);
IMigrationHelper.CreditDelegationInput[] memory CREDIT_DELEGATION_PERMITS = 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 < ASSETS_TO_MIGRATE.length;) {
address aToken = MIGRATION_HELPER.aTokens(ASSETS_TO_MIGRATE[i]);
uint256 amount = IERC20(aToken).balanceOf(address(AaveV2Avalanche.COLLECTOR));
AaveV2Avalanche.COLLECTOR.transfer(aToken, address(this), amount);
SafeERC20.forceApprove(IERC20(aToken), AaveV2Avalanche.MIGRATION_HELPER, amount);
unchecked {
i++;
defijesus marked this conversation as resolved.
Show resolved Hide resolved
defijesus marked this conversation as resolved.
Show resolved Hide resolved
}
}

MIGRATION_HELPER.migrate(ASSETS_TO_MIGRATE, POSITIONS_TO_REPAY, PERMITS, CREDIT_DELEGATION_PERMITS);

address[] memory NEW_ASSETS_MIGRATED = new address[](4);
NEW_ASSETS_MIGRATED[0] = AaveV3AvalancheAssets.DAIe_A_TOKEN;
NEW_ASSETS_MIGRATED[1] = AaveV3AvalancheAssets.WBTCe_A_TOKEN;
NEW_ASSETS_MIGRATED[2] = AaveV3AvalancheAssets.WETHe_A_TOKEN;
NEW_ASSETS_MIGRATED[3] = AaveV3AvalancheAssets.WAVAX_A_TOKEN;

for(i = 0; i < NEW_ASSETS_MIGRATED.length;) {
SafeERC20.safeTransfer(
IERC20(NEW_ASSETS_MIGRATED[i]),
address(AaveV3Avalanche.COLLECTOR),
IERC20(NEW_ASSETS_MIGRATED[i]).balanceOf(address(this))
);
unchecked {
i++;
defijesus marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// 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'), 35447142);
}

function testPayload() public {
address[] memory OLD_ASSETS_MIGRATED = new address[](4);
defijesus marked this conversation as resolved.
Show resolved Hide resolved
OLD_ASSETS_MIGRATED[0] = AaveV2AvalancheAssets.DAIe_A_TOKEN;
OLD_ASSETS_MIGRATED[1] = AaveV2AvalancheAssets.WBTCe_A_TOKEN;
OLD_ASSETS_MIGRATED[2] = AaveV2AvalancheAssets.WETHe_A_TOKEN;
OLD_ASSETS_MIGRATED[3] = AaveV2AvalancheAssets.WAVAX_A_TOKEN;

address[] memory NEW_ASSETS_MIGRATED = new address[](4);
NEW_ASSETS_MIGRATED[0] = AaveV3AvalancheAssets.DAIe_A_TOKEN;
NEW_ASSETS_MIGRATED[1] = AaveV3AvalancheAssets.WBTCe_A_TOKEN;
NEW_ASSETS_MIGRATED[2] = AaveV3AvalancheAssets.WETHe_A_TOKEN;
NEW_ASSETS_MIGRATED[3] = AaveV3AvalancheAssets.WAVAX_A_TOKEN;

uint256[] memory NEW_ASSETS_BEFORE_BALANCE = new uint256[](4);
uint256[] memory OLD_ASSETS_BEFORE_BALANCE = new uint256[](4);
defijesus marked this conversation as resolved.
Show resolved Hide resolved

uint256 i = 0;
uint256 payloadBalanceAfter;
uint256 collectorBalanceAfter;

for(; i < NEW_ASSETS_MIGRATED.length; i++) {
defijesus marked this conversation as resolved.
Show resolved Hide resolved
NEW_ASSETS_BEFORE_BALANCE[i] = IERC20(NEW_ASSETS_MIGRATED[i]).balanceOf(address(AaveV3Avalanche.COLLECTOR));
OLD_ASSETS_BEFORE_BALANCE[i] = IERC20(OLD_ASSETS_MIGRATED[i]).balanceOf(address(AaveV2Avalanche.COLLECTOR));
}

AaveAvalancheTreasuryMigration_20230903 payload = new AaveAvalancheTreasuryMigration_20230903();

GovHelpers.executePayload(vm, address(payload), AaveV3Avalanche.ACL_ADMIN);

for(i = 0; i < OLD_ASSETS_MIGRATED.length; i++) {
payloadBalanceAfter = IERC20(OLD_ASSETS_MIGRATED[i]).balanceOf(address(payload));
assertEq(payloadBalanceAfter, 0);
payloadBalanceAfter = IERC20(NEW_ASSETS_MIGRATED[i]).balanceOf(address(payload));
assertEq(payloadBalanceAfter, 0);
kyzia551 marked this conversation as resolved.
Show resolved Hide resolved
}

for(i = 0; i < NEW_ASSETS_MIGRATED.length; i++) {
collectorBalanceAfter = IERC20(NEW_ASSETS_MIGRATED[i]).balanceOf(address(AaveV3Avalanche.COLLECTOR));
/// 0.001e18 is 0.1%
assertApproxEqRel(NEW_ASSETS_BEFORE_BALANCE[i] + OLD_ASSETS_BEFORE_BALANCE[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,54 @@
---
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

Most of these funds can be migrated to v3 with the exception of USDT. There is not enough liquidity to redeem the entire 541.51K of USDT. As a result, approximately 25% of the USDT will be redeemed and deposited into v3.
defijesus marked this conversation as resolved.
Show resolved Hide resolved

# 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](TODO)

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/).