Skip to content

Commit

Permalink
Add interface for IHATAirdrop contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-kaufman committed Jan 11, 2024
1 parent 136a041 commit 6a0b7bf
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 16 deletions.
3 changes: 2 additions & 1 deletion contracts/tge/HATAirdrop.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeab
import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/cryptography/MerkleProofUpgradeable.sol";
import "../tokenlock/ITokenLockFactory.sol";
import "./interfaces/IHATAirdrop.sol";

/*
An airdrop contract that transfers tokens based on a merkle tree.
*/
contract HATAirdrop is Initializable {
contract HATAirdrop is IHATAirdrop, Initializable {
error CannotRedeemBeforeStartTime();
error CannotRedeemAfterDeadline();
error LeafAlreadyRedeemed();
Expand Down
16 changes: 9 additions & 7 deletions contracts/tge/HATAirdropFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,29 @@ pragma solidity 0.8.16;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/proxy/Clones.sol";
import "./HATAirdrop.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "./interfaces/IHATAirdrop.sol";

contract HATAirdropFactory is Ownable {
error RedeemDataArraysLengthMismatch();
error ContractIsNotHATAirdrop();
error HATAirdropInitializationFailed();

using SafeERC20Upgradeable for IERC20Upgradeable;
using SafeERC20 for IERC20;

mapping(address => bool) public isAirdrop;

event TokensWithdrawn(address indexed _owner, uint256 _amount);
event HATAirdropCreated(address indexed _hatAirdrop, bytes _initData, IERC20Upgradeable _token, uint256 _totalAmount);
event HATAirdropCreated(address indexed _hatAirdrop, bytes _initData, IERC20 _token, uint256 _totalAmount);

function withdrawTokens(IERC20Upgradeable _token, uint256 _amount) external onlyOwner {
function withdrawTokens(IERC20 _token, uint256 _amount) external onlyOwner {
address owner = msg.sender;
_token.safeTransfer(owner, _amount);
emit TokensWithdrawn(owner, _amount);
}

function redeemMultipleAirdrops(HATAirdrop[] calldata _airdrops, uint256[] calldata _amounts, bytes32[][] calldata _proofs) external {
function redeemMultipleAirdrops(IHATAirdrop[] calldata _airdrops, uint256[] calldata _amounts, bytes32[][] calldata _proofs) external {
if (_airdrops.length != _amounts.length || _airdrops.length != _proofs.length) {
revert RedeemDataArraysLengthMismatch();
}
Expand All @@ -36,7 +38,7 @@ contract HATAirdropFactory is Ownable {
revert ContractIsNotHATAirdrop();
}

HATAirdrop(_airdrops[i]).redeem(caller, _amounts[i], _proofs[i]);
_airdrops[i].redeem(caller, _amounts[i], _proofs[i]);

unchecked {
++i;
Expand All @@ -47,7 +49,7 @@ contract HATAirdropFactory is Ownable {
function createHATAirdrop(
address _implementation,
bytes calldata _initData,
IERC20Upgradeable _token,
IERC20 _token,
uint256 _totalAmount
) external onlyOwner returns (address result) {
result = Clones.cloneDeterministic(_implementation, keccak256(_initData));
Expand Down
9 changes: 9 additions & 0 deletions contracts/tge/interfaces/IHATAirdrop.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-License-Identifier: MIT
// Disclaimer https://github.com/hats-finance/hats-contracts/blob/main/DISCLAIMER.md

pragma solidity 0.8.16;


interface IHATAirdrop {
function redeem(address _account, uint256 _amount, bytes32[] calldata _proof) external;
}
16 changes: 8 additions & 8 deletions docs/dodoc/tge/HATAirdropFactory.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
### createHATAirdrop

```solidity
function createHATAirdrop(address _implementation, bytes _initData, contract IERC20Upgradeable _token, uint256 _totalAmount) external nonpayable returns (address result)
function createHATAirdrop(address _implementation, bytes _initData, contract IERC20 _token, uint256 _totalAmount) external nonpayable returns (address result)
```


Expand All @@ -26,7 +26,7 @@ function createHATAirdrop(address _implementation, bytes _initData, contract IER
|---|---|---|
| _implementation | address | undefined |
| _initData | bytes | undefined |
| _token | contract IERC20Upgradeable | undefined |
| _token | contract IERC20 | undefined |
| _totalAmount | uint256 | undefined |

#### Returns
Expand Down Expand Up @@ -100,7 +100,7 @@ function predictHATAirdropAddress(address _implementation, bytes _initData) exte
### redeemMultipleAirdrops

```solidity
function redeemMultipleAirdrops(contract HATAirdrop[] _airdrops, uint256[] _amounts, bytes32[][] _proofs) external nonpayable
function redeemMultipleAirdrops(contract IHATAirdrop[] _airdrops, uint256[] _amounts, bytes32[][] _proofs) external nonpayable
```


Expand All @@ -111,7 +111,7 @@ function redeemMultipleAirdrops(contract HATAirdrop[] _airdrops, uint256[] _amou

| Name | Type | Description |
|---|---|---|
| _airdrops | contract HATAirdrop[] | undefined |
| _airdrops | contract IHATAirdrop[] | undefined |
| _amounts | uint256[] | undefined |
| _proofs | bytes32[][] | undefined |

Expand Down Expand Up @@ -145,7 +145,7 @@ function transferOwnership(address newOwner) external nonpayable
### withdrawTokens

```solidity
function withdrawTokens(contract IERC20Upgradeable _token, uint256 _amount) external nonpayable
function withdrawTokens(contract IERC20 _token, uint256 _amount) external nonpayable
```


Expand All @@ -156,7 +156,7 @@ function withdrawTokens(contract IERC20Upgradeable _token, uint256 _amount) exte

| Name | Type | Description |
|---|---|---|
| _token | contract IERC20Upgradeable | undefined |
| _token | contract IERC20 | undefined |
| _amount | uint256 | undefined |


Expand All @@ -166,7 +166,7 @@ function withdrawTokens(contract IERC20Upgradeable _token, uint256 _amount) exte
### HATAirdropCreated

```solidity
event HATAirdropCreated(address indexed _hatAirdrop, bytes _initData, contract IERC20Upgradeable _token, uint256 _totalAmount)
event HATAirdropCreated(address indexed _hatAirdrop, bytes _initData, contract IERC20 _token, uint256 _totalAmount)
```


Expand All @@ -179,7 +179,7 @@ event HATAirdropCreated(address indexed _hatAirdrop, bytes _initData, contract I
|---|---|---|
| _hatAirdrop `indexed` | address | undefined |
| _initData | bytes | undefined |
| _token | contract IERC20Upgradeable | undefined |
| _token | contract IERC20 | undefined |
| _totalAmount | uint256 | undefined |

### OwnershipTransferred
Expand Down
33 changes: 33 additions & 0 deletions docs/dodoc/tge/interfaces/IHATAirdrop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# IHATAirdrop









## Methods

### redeem

```solidity
function redeem(address _account, uint256 _amount, bytes32[] _proof) external nonpayable
```





#### Parameters

| Name | Type | Description |
|---|---|---|
| _account | address | undefined |
| _amount | uint256 | undefined |
| _proof | bytes32[] | undefined |




0 comments on commit 6a0b7bf

Please sign in to comment.