-
Notifications
You must be signed in to change notification settings - Fork 0
/
AzbitAirdrop.sol
114 lines (92 loc) · 2.6 KB
/
AzbitAirdrop.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/**
* @author https://github.com/Dmitx
*/
pragma solidity ^0.4.24;
import "./ownership/Ownable.sol";
import "./AzbitTokenInterface.sol";
/**
* @title AzbitAirdrop
* @dev Airdrop Smart Contract of Azbit project
*/
contract AzbitAirdrop is Ownable {
// ** PUBLIC STATE VARIABLES **
// Azbit token
AzbitTokenInterface public azbitToken;
// ** CONSTRUCTOR **
/**
* @dev Constructor of AzbitAirdrop Contract
* @param tokenAddress address of AzbitToken
*/
constructor(
address tokenAddress
)
public
{
_setToken(tokenAddress);
}
// ** ONLY OWNER FUNCTIONS **
/**
* @dev Send tokens to beneficiary by owner
* @param beneficiary The address for tokens withdrawal
* @param amount The token amount
*/
function sendTokens(
address beneficiary,
uint256 amount
)
external
onlyOwner
{
_sendTokens(beneficiary, amount);
}
/**
* @dev Send tokens to the array of beneficiaries by owner
* @param beneficiaries The array of addresses for tokens withdrawal
* @param amounts The array of tokens amount
*/
function sendTokensArray(
address[] beneficiaries,
uint256[] amounts
)
external
onlyOwner
{
require(beneficiaries.length == amounts.length, "array lengths have to be equal");
require(beneficiaries.length > 0, "array lengths have to be greater than zero");
for (uint256 i = 0; i < beneficiaries.length; i++) {
_sendTokens(beneficiaries[i], amounts[i]);
}
}
// ** PUBLIC VIEW FUNCTIONS **
/**
* @return total tokens of this contract.
*/
function contractTokenBalance()
public
view
returns(uint256)
{
return azbitToken.balanceOf(this);
}
// ** PRIVATE HELPER FUNCTIONS **
// Helper: Set the address of Azbit Token
function _setToken(address tokenAddress)
internal
{
azbitToken = AzbitTokenInterface(tokenAddress);
require(contractTokenBalance() >= 0, "The token being added is not ERC20 token");
}
// Helper: send tokens to beneficiary
function _sendTokens(
address beneficiary,
uint256 amount
)
internal
{
require(beneficiary != address(0), "Address cannot be 0x0");
require(amount > 0, "Amount cannot be zero");
require(amount <= contractTokenBalance(), "not enough tokens on this contract");
// transfer tokens
require(azbitToken.transfer(beneficiary, amount), "tokens are not transferred");
}
}