|
| 1 | +// SPDX-License-Identifier: UNLICENSED |
| 2 | +// All Rights Reserved © AaveCo |
| 3 | + |
| 4 | +pragma solidity ^0.8.10; |
| 5 | + |
| 6 | +import {IPoolAddressesProvider} from "@aave-v3-core/interfaces/IPoolAddressesProvider.sol"; |
| 7 | +import {IERC20} from "@openzeppelin/interfaces/IERC20.sol"; |
| 8 | + |
| 9 | +import {ATokenVault} from "./ATokenVault.sol"; |
| 10 | +import {IATokenVaultMerklRewardClaimer} from "./interfaces/IATokenVaultMerklRewardClaimer.sol"; |
| 11 | + |
| 12 | +interface IMerklDistributor { |
| 13 | + function claim( |
| 14 | + address[] calldata users, |
| 15 | + address[] calldata tokens, |
| 16 | + uint256[] calldata amounts, |
| 17 | + bytes32[][] calldata proofs |
| 18 | + ) external; |
| 19 | +} |
| 20 | + |
| 21 | +/** |
| 22 | + * @title ATokenVaultMerklRewardClaimer |
| 23 | + * @author Aave Protocol |
| 24 | + * @notice A contract that allows the owner to claim Merkl rewards for the ATokenVault |
| 25 | + */ |
| 26 | +contract ATokenVaultMerklRewardClaimer is ATokenVault, IATokenVaultMerklRewardClaimer { |
| 27 | + /** |
| 28 | + * @dev Constructor. |
| 29 | + * @param underlying The underlying ERC20 asset which can be supplied to Aave |
| 30 | + * @param referralCode The Aave referral code to use for deposits from this vault |
| 31 | + * @param poolAddressesProvider The address of the Aave v3 Pool Addresses Provider |
| 32 | + */ |
| 33 | + constructor(address underlying, uint16 referralCode, IPoolAddressesProvider poolAddressesProvider) |
| 34 | + ATokenVault(underlying, referralCode, poolAddressesProvider) |
| 35 | + {} |
| 36 | + |
| 37 | + /// @inheritdoc IATokenVaultMerklRewardClaimer |
| 38 | + function getMerklDistributor() external view override returns (address) { |
| 39 | + return _s.merklDistributor; |
| 40 | + } |
| 41 | + |
| 42 | + /// @inheritdoc IATokenVaultMerklRewardClaimer |
| 43 | + function setMerklDistributor(address merklDistributor) external override onlyOwner { |
| 44 | + require(merklDistributor != address(0), "ZERO_ADDRESS_NOT_VALID"); |
| 45 | + address currentMerklDistributor = _s.merklDistributor; |
| 46 | + _s.merklDistributor = merklDistributor; |
| 47 | + emit MerklDistributorUpdated(currentMerklDistributor, merklDistributor); |
| 48 | + } |
| 49 | + |
| 50 | + /// @inheritdoc IATokenVaultMerklRewardClaimer |
| 51 | + function claimMerklRewards(address[] calldata rewardTokens, uint256[] calldata amounts, bytes32[][] calldata proofs) |
| 52 | + public |
| 53 | + override |
| 54 | + onlyOwner |
| 55 | + { |
| 56 | + require(_s.merklDistributor != address(0), "MERKL_DISTRIBUTOR_NOT_SET"); |
| 57 | + |
| 58 | + address[] memory users = new address[](rewardTokens.length); |
| 59 | + for (uint256 i = 0; i < rewardTokens.length; i++) { |
| 60 | + // users represent depositors into Aave which is this contract |
| 61 | + users[i] = address(this); |
| 62 | + } |
| 63 | + |
| 64 | + // The claim function does not return a list of tokens and amounts actually received. |
| 65 | + // It is possible for rewards to be in aTokens, the underlying asset or some other token. |
| 66 | + // If necessary the owner can use IATokenVault.emergencyRescue(...) to rescue the non-aToken rewards. |
| 67 | + IMerklDistributor(_s.merklDistributor).claim(users, rewardTokens, amounts, proofs); |
| 68 | + // Do not attempt to accrue yield as it can be delegated to subsequent calls to this contract. |
| 69 | + // We do not need to accrue before claiming because new shares are not granted anywhere. |
| 70 | + // We do not need to accrue after claiming because any subsequent call will trigger an accrual before state updates |
| 71 | + // and preview functions read the balance of aTokens on the vault at runtime. |
| 72 | + |
| 73 | + emit MerklRewardsClaimed(rewardTokens, amounts); |
| 74 | + } |
| 75 | +} |
0 commit comments