-
Notifications
You must be signed in to change notification settings - Fork 0
/
File2
131 lines (115 loc) · 3.95 KB
/
File2
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
break;
}
}
// transfer tokens to wallet address
require(IERC20(tokenAddress).transfer(msg.sender, amount));
emit LogTokensWithdrawn(tokenAddress, withdrawalAddress, amount, _id);
}
function createMultipleLocks(
address _tokenAddress,
address _withdrawalAddress,
uint256[] memory _amounts,
uint256[] memory _unlockTimes,
uint128 _purpose
) external payable returns (uint256 _id) {
require(_amounts.length > 0);
require(_amounts.length == _unlockTimes.length);
uint256 fee =
_amounts.length.mul(bnbFee).sub(
_amounts.length.mul(bnbFee).mul(vestingDiscount).div(100)
);
require(msg.value >= fee, "fees missing");
totalBnbFees = totalBnbFees.add(msg.value);
remainingBnbFees = remainingBnbFees.add(msg.value);
uint256 i;
for (i = 0; i < _amounts.length; i++) {
require(_amounts[i] > 0);
require(_unlockTimes[i] < 10000000000);
require(_unlockTimes[i] > block.timestamp);
//update balance in address
walletTokenBalance[_tokenAddress][
_withdrawalAddress
] = walletTokenBalance[_tokenAddress][_withdrawalAddress].add(
_amounts[i]
);
_id = ++depositId;
lockedToken[_id].tokenAddress = _tokenAddress;
lockedToken[_id].withdrawalAddress = _withdrawalAddress;
lockedToken[_id].sender = msg.sender;
lockedToken[_id].tokenAmount = _amounts[i];
lockedToken[_id].unlockTime = _unlockTimes[i];
lockedToken[_id].lockTime = block.timestamp;
lockedToken[_id].withdrawn = false;
lockedToken[_id].purpose = _purpose;
allDepositIds.push(_id);
depositsByWithdrawalAddress[_withdrawalAddress].push(_id);
//transfer tokens into contract
require(
IERC20(_tokenAddress).transferFrom(
msg.sender,
address(this),
_amounts[i]
)
);
emit LogTokensLocked(
_tokenAddress,
msg.sender,
_amounts[i],
_unlockTimes[i],
depositId
);
}
}
function getTotalTokenBalance(address _tokenAddress)
public
view
returns (uint256)
{
return IERC20(_tokenAddress).balanceOf(address(this));
}
function getTokenBalanceByAddress(
address _tokenAddress,
address _walletAddress
) public view returns (uint256) {
return walletTokenBalance[_tokenAddress][_walletAddress];
}
function getAllDepositIds() public view returns (uint256[] memory) {
return allDepositIds;
}
function getDepositDetails(uint256 _id)
public
view
returns (
address _tokenAddress,
address _withdrawalAddress,
address _sender,
uint256 _tokenAmount,
uint256 _unlockTime,
uint256 _lockTime,
bool _withdrawn
)
{
return (
lockedToken[_id].tokenAddress,
lockedToken[_id].withdrawalAddress,
lockedToken[_id].sender,
lockedToken[_id].tokenAmount,
lockedToken[_id].unlockTime,
lockedToken[_id].lockTime,
lockedToken[_id].withdrawn
);
}
function getDepositsByWithdrawalAddress(address _withdrawalAddress)
public
view
returns (uint256[] memory)
{
return depositsByWithdrawalAddress[_withdrawalAddress];
}
function setBnbFee(uint256 fee) external onlyOwner {
require(fee >= 0);
bnbFee = fee;
}
function setVestingDiscount(uint256 discount) external onlyOwner {
require(discount > 0, "Fee is too small");
require(discount < 99);