Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finance april #10

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a47c4df
feat: add migrations and allowance
efecarranza Apr 21, 2024
0aaf8cc
feat: add polygon payload
efecarranza Apr 23, 2024
ffaac1e
chore: update md file
efecarranza Apr 23, 2024
246de25
chore: test"
efecarranza Apr 23, 2024
dc2e7e7
feat: add bgd's proposal'
efecarranza Apr 23, 2024
602c07f
chore: add missing emits
efecarranza Apr 23, 2024
1525874
feat: finish tests
efecarranza Apr 23, 2024
fe9f083
chore: add bridge emit expectations
efecarranza Apr 23, 2024
f4d2609
include in the test setup config of Bridge contract
Luigy-Lemon Apr 24, 2024
06624fb
chore: update block
efecarranza Apr 27, 2024
b220e65
Merge remote-tracking branch 'tl/finance-april' into finance-april
efecarranza Apr 27, 2024
b6b11e2
chore: merge main
efecarranza Apr 27, 2024
aaadc70
feat: remove bridge
efecarranza Apr 30, 2024
a3e1616
add tests
efecarranza May 1, 2024
d2e29ab
feat: add part B
efecarranza May 2, 2024
acbaee7
chore: update script
efecarranza May 2, 2024
1224d26
chore: separate into payloads
efecarranza May 2, 2024
d294053
chore: fix script and abgd'
efecarranza May 3, 2024
13e79e9
feat: add aDI bot refill
efecarranza May 3, 2024
9c92982
Update src/20240421_Multi_AprilFinanceUpdate/AaveV2Polygon_AprilFinan…
Luigy-Lemon May 6, 2024
79f589e
Update src/20240421_Multi_AprilFinanceUpdate/AprilFinanceUpdate.md
Luigy-Lemon May 6, 2024
198323a
Update src/20240421_Multi_AprilFinanceUpdate/AprilFinanceUpdate.md
Luigy-Lemon May 6, 2024
c806803
Revert "Update src/20240421_Multi_AprilFinanceUpdate/AaveV2Polygon_Ap…
Luigy-Lemon May 6, 2024
f600271
fix: lint on md file
Luigy-Lemon May 6, 2024
968d4cd
feat: add merit allowances
efecarranza May 6, 2024
f05158a
feat; leave for refill
efecarranza May 7, 2024
72cdb90
Merge remote-tracking branch 'tl/finance-april' into finance-april
efecarranza May 7, 2024
ec6c14c
chore: update md
efecarranza May 7, 2024
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
1 change: 1 addition & 0 deletions .assets/3ba5c7c483188de945c201d26fa5252c67e5caac.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions .assets/51f81c539b7291d13a067450c9db577fc40d9573.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions .assets/a47eecb09dc71d5549ab7cbd4807cd98ad151613.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Raw diff

```json
{}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Raw diff

```json
{}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Raw diff

```json
{}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {IERC20} from 'solidity-utils/contracts/oz-common/interfaces/IERC20.sol';
import {SafeERC20} from 'solidity-utils/contracts/oz-common/SafeERC20.sol';
import {MiscEthereum} from 'aave-address-book/MiscEthereum.sol';
import {AaveV2Ethereum, AaveV2EthereumAssets} from 'aave-address-book/AaveV2Ethereum.sol';
import {AaveV3Ethereum, AaveV3EthereumAssets} from 'aave-address-book/AaveV3Ethereum.sol';
import {AaveSwapper} from 'aave-helpers/swaps/AaveSwapper.sol';
import {IProposalGenericExecutor} from 'aave-helpers/interfaces/IProposalGenericExecutor.sol';
/**
* @title April Finance Update
* @author @karpatkey_TokenLogic
* - Snapshot: Direct-to-AIP
* - Discussion: https://governance.aave.com/t/arfc-april-finance-update/17390
*/
contract AaveV2Ethereum_AprilFinanceUpdate_20240421 is IProposalGenericExecutor {
using SafeERC20 for IERC20;

struct TokenToMigrate {
address underlying;
address aToken;
uint256 qty;
}

struct TokenToSwap {
address underlying;
address aToken;
uint256 balance;
}

AaveSwapper public constant SWAPPER = AaveSwapper(MiscEthereum.AAVE_SWAPPER);

address public constant MILKMAN = 0x11C76AD590ABDFFCD980afEC9ad951B160F02797;
address public constant PRICE_CHECKER = 0xe80a1C615F75AFF7Ed8F08c9F21f9d00982D666c;
address public constant GHO_USD_FEED = 0x3f12643D3f6f874d39C2a4c9f2Cd6f2DbAC877FC;

address public constant AGD_MULTISIG = 0x89C51828427F70D77875C6747759fB17Ba10Ceb0;
uint256 public constant AGD_GHO_ALLOWANCE = 613_000 ether;

uint256 public constant USDC_V3_TO_SWAP = 1_400_000e6; // 1.4M
uint256 public constant DAI_V3_TO_SWAP = 2_000_000 ether;
uint256 public constant USDT_V2_TO_KEEP = 650_000e6; // 650,000

address public constant BGD_RECIPIENT = 0xb812d0944f8F581DfAA3a93Dda0d22EcEf51A9CF;
uint256 public constant USDC_AMOUNT_REIMBURSEMENT = 42_000e6;
uint256 public constant USDT_AMOUNT_REIMBURSEMENT = 109_200e6;
uint256 public constant LINK_AMOUNT_REIMBURSEMENT = 1640 ether;

uint256 public constant MERIT_GHO_ALLOWANCE = 3_000_000 ether;
uint256 public constant MERIT_WETH_V3_ALLOWANCE = 645 ether;
address public constant MERIT_WALLET = 0xdeadD8aB03075b7FBA81864202a2f59EE25B312b;

function execute() external {
_bgdReimbursements();
_allowances();
_v2ToV3Migration();
_swaps();
}

function _bgdReimbursements() internal {
AaveV2Ethereum.COLLECTOR.transfer(
AaveV2EthereumAssets.USDC_A_TOKEN,
BGD_RECIPIENT,
USDC_AMOUNT_REIMBURSEMENT
);
AaveV2Ethereum.COLLECTOR.transfer(
AaveV2EthereumAssets.USDT_A_TOKEN,
BGD_RECIPIENT,
USDT_AMOUNT_REIMBURSEMENT
);
AaveV2Ethereum.COLLECTOR.transfer(
AaveV2EthereumAssets.LINK_A_TOKEN,
BGD_RECIPIENT,
LINK_AMOUNT_REIMBURSEMENT
);
}

function _allowances() internal {
if (
IERC20(AaveV2EthereumAssets.USDT_A_TOKEN).allowance(
address(AaveV3Ethereum.COLLECTOR),
AGD_MULTISIG
) >= 612944900000
) {
AaveV3Ethereum.COLLECTOR.approve(AaveV2EthereumAssets.USDT_A_TOKEN, AGD_MULTISIG, 0);
AaveV3Ethereum.COLLECTOR.approve(
AaveV3EthereumAssets.GHO_UNDERLYING,
AGD_MULTISIG,
AGD_GHO_ALLOWANCE
);
}

AaveV3Ethereum.COLLECTOR.approve(
AaveV3EthereumAssets.GHO_UNDERLYING,
MERIT_WALLET,
MERIT_GHO_ALLOWANCE
);

AaveV3Ethereum.COLLECTOR.approve(
AaveV3EthereumAssets.WETH_A_TOKEN,
MERIT_WALLET,
MERIT_WETH_V3_ALLOWANCE
);
}

/**
* @notice migrates all but one unit of the specified assets from AaveV2 to AaveV3
* assets: WETH, WBTC, LINK and SNX
*/
function _v2ToV3Migration() internal {
TokenToMigrate[] memory tokens = new TokenToMigrate[](4);
tokens[0] = TokenToMigrate(
AaveV2EthereumAssets.WBTC_UNDERLYING,
AaveV2EthereumAssets.WBTC_A_TOKEN,
IERC20(AaveV2EthereumAssets.WBTC_A_TOKEN).balanceOf(address(AaveV3Ethereum.COLLECTOR)) - 1e8
);
tokens[1] = TokenToMigrate(
AaveV2EthereumAssets.WETH_UNDERLYING,
AaveV2EthereumAssets.WETH_A_TOKEN,
IERC20(AaveV2EthereumAssets.WETH_A_TOKEN).balanceOf(address(AaveV3Ethereum.COLLECTOR)) -
1 ether
);
tokens[2] = TokenToMigrate(
AaveV2EthereumAssets.LINK_UNDERLYING,
AaveV2EthereumAssets.LINK_A_TOKEN,
IERC20(AaveV2EthereumAssets.LINK_A_TOKEN).balanceOf(address(AaveV3Ethereum.COLLECTOR)) -
1 ether
);
tokens[3] = TokenToMigrate(
AaveV2EthereumAssets.SNX_UNDERLYING,
AaveV2EthereumAssets.SNX_A_TOKEN,
IERC20(AaveV2EthereumAssets.SNX_A_TOKEN).balanceOf(address(AaveV3Ethereum.COLLECTOR)) -
1 ether
);

uint256 tokensLength = tokens.length;
for (uint256 i = 0; i < tokensLength; i++) {
AaveV3Ethereum.COLLECTOR.transfer(tokens[i].aToken, address(this), tokens[i].qty);

AaveV2Ethereum.POOL.withdraw(tokens[i].underlying, type(uint256).max, address(this));

uint256 amount = IERC20(tokens[i].underlying).balanceOf(address(this));
IERC20(tokens[i].underlying).forceApprove(address(AaveV3Ethereum.POOL), amount);

AaveV3Ethereum.POOL.deposit(
tokens[i].underlying,
amount,
address(AaveV3Ethereum.COLLECTOR),
0
);
}
}

function _swaps() internal {
_withdrawV2Tokens();
_withdrawV3Tokens();

SWAPPER.swap(
MILKMAN,
PRICE_CHECKER,
AaveV3EthereumAssets.DAI_UNDERLYING,
AaveV3EthereumAssets.GHO_UNDERLYING,
AaveV3EthereumAssets.DAI_ORACLE,
GHO_USD_FEED,
address(AaveV3Ethereum.COLLECTOR),
IERC20(AaveV3EthereumAssets.DAI_UNDERLYING).balanceOf(address(SWAPPER)),
50
);

SWAPPER.swap(
MILKMAN,
PRICE_CHECKER,
AaveV3EthereumAssets.USDC_UNDERLYING,
AaveV3EthereumAssets.GHO_UNDERLYING,
AaveV3EthereumAssets.USDC_ORACLE,
GHO_USD_FEED,
address(AaveV3Ethereum.COLLECTOR),
IERC20(AaveV3EthereumAssets.USDC_UNDERLYING).balanceOf(address(SWAPPER)),
100
);

SWAPPER.swap(
MILKMAN,
PRICE_CHECKER,
AaveV3EthereumAssets.USDT_UNDERLYING,
AaveV3EthereumAssets.GHO_UNDERLYING,
AaveV3EthereumAssets.USDT_ORACLE,
GHO_USD_FEED,
address(AaveV3Ethereum.COLLECTOR),
IERC20(AaveV3EthereumAssets.USDT_UNDERLYING).balanceOf(address(SWAPPER)),
100
);
}

/**
* @notice Withdraws v2 tokens to swapper
*/
function _withdrawV2Tokens() internal {
TokenToSwap[] memory tokens = new TokenToSwap[](3);
tokens[0] = TokenToSwap(
AaveV2EthereumAssets.DAI_UNDERLYING,
AaveV2EthereumAssets.DAI_A_TOKEN,
IERC20(AaveV2EthereumAssets.DAI_A_TOKEN).balanceOf(address(AaveV3Ethereum.COLLECTOR)) -
1 ether
);
tokens[1] = TokenToSwap(
AaveV2EthereumAssets.USDC_UNDERLYING,
AaveV2EthereumAssets.USDC_A_TOKEN,
IERC20(AaveV2EthereumAssets.USDC_A_TOKEN).balanceOf(address(AaveV3Ethereum.COLLECTOR)) - 1e6
);
tokens[2] = TokenToSwap(
AaveV2EthereumAssets.USDT_UNDERLYING,
AaveV2EthereumAssets.USDT_A_TOKEN,
IERC20(AaveV2EthereumAssets.USDT_A_TOKEN).balanceOf(address(AaveV3Ethereum.COLLECTOR)) -
USDT_V2_TO_KEEP
);

uint256 tokensLength = tokens.length;
for (uint256 i = 0; i < tokensLength; i++) {
AaveV3Ethereum.COLLECTOR.transfer(tokens[i].aToken, address(this), tokens[i].balance);

AaveV2Ethereum.POOL.withdraw(tokens[i].underlying, type(uint256).max, address(SWAPPER));
}
}

/**
* @notice Withdraws v3 tokens to swapper
*/
function _withdrawV3Tokens() internal {
TokenToSwap[] memory tokens = new TokenToSwap[](2);
tokens[0] = TokenToSwap(
AaveV3EthereumAssets.USDC_UNDERLYING,
AaveV3EthereumAssets.USDC_A_TOKEN,
USDC_V3_TO_SWAP
);
tokens[1] = TokenToSwap(
AaveV3EthereumAssets.DAI_UNDERLYING,
AaveV3EthereumAssets.DAI_A_TOKEN,
DAI_V3_TO_SWAP
);

uint256 tokensLength = tokens.length;
for (uint256 i = 0; i < tokensLength; i++) {
AaveV3Ethereum.COLLECTOR.transfer(tokens[i].aToken, address(this), tokens[i].balance);

AaveV3Ethereum.POOL.withdraw(tokens[i].underlying, type(uint256).max, address(SWAPPER));
}
}
}
Loading