Skip to content

Commit

Permalink
feat: handle fee recipient
Browse files Browse the repository at this point in the history
  • Loading branch information
sogipec committed Apr 4, 2024
1 parent 26b2db2 commit 165b5d6
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions contracts/coupons/AaveTokenWrapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pragma solidity ^0.8.17;
import { ERC20Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "../DistributionCreator.sol";

import "../utils/UUPSHelper.sol";

Expand All @@ -19,6 +20,7 @@ contract AaveTokenWrapper is UUPSHelper, ERC20Upgradeable {
// could be put as immutable in non upgradeable contract
address public token;
address public distributor;
address public distributionCreator;

mapping(address => uint256) public isMasterClaimer;
mapping(address => address) public delegateReceiver;
Expand All @@ -40,15 +42,21 @@ contract AaveTokenWrapper is UUPSHelper, ERC20Upgradeable {

// ================================= FUNCTIONS =================================

function initialize(address underlyingToken, address _distributor, address _core) public initializer {
function initialize(
address underlyingToken,
address _distributor,
address _core,
address _distributionCreator
) public initializer {
// TODO could fetch name and symbol based on real token
__ERC20_init("AaveTokenWrapper", "ATW");
__UUPSUpgradeable_init();
if (underlyingToken == address(0) || _distributor == address(0)) revert ZeroAddress();
if (underlyingToken == address(0) || _distributor == address(0) || _distributionCreator == address(0))
revert ZeroAddress();
ICore(_core).isGovernor(msg.sender);
token = underlyingToken;
distributor = _distributor;

distributionCreator = _distributionCreator;
core = ICore(_core);
}

Expand All @@ -57,6 +65,11 @@ contract AaveTokenWrapper is UUPSHelper, ERC20Upgradeable {
if (to == distributor) {
IERC20(token).safeTransferFrom(from, address(this), amount);
_mint(from, amount); // These are then transfered to the distributor
} else {
if (to == _getFeeRecipient()) {
IERC20(token).safeTransferFrom(from, to, amount);
_mint(from, amount);
}
}
}

Expand All @@ -70,6 +83,9 @@ contract AaveTokenWrapper is UUPSHelper, ERC20Upgradeable {
} else {
revert InvalidClaim();
}
} else if (to == _getFeeRecipient()) {
// To avoid having any token aside from the distributor
_burn(to, amount);
}
}

Expand All @@ -83,6 +99,12 @@ contract AaveTokenWrapper is UUPSHelper, ERC20Upgradeable {
}
}

function _getFeeRecipient() internal view returns (address feeRecipient) {
address _distributionCreator = distributionCreator;
feeRecipient = DistributionCreator(_distributionCreator).feeRecipient();
feeRecipient = feeRecipient == address(0) ? _distributionCreator : feeRecipient;
}

/// @notice Recovers any ERC20 token
function recoverERC20(address tokenAddress, address to, uint256 amountToRecover) external onlyGovernor {
IERC20(tokenAddress).safeTransfer(to, amountToRecover);
Expand Down

0 comments on commit 165b5d6

Please sign in to comment.