@gooddollar/goodprotocol 1.0.24 → 1.0.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/artifacts/abis/FuseFaucet.min.json +1 -0
- package/artifacts/abis/FuseStakingV3.min.json +1 -0
- package/artifacts/abis/IConsensus.min.json +1 -0
- package/artifacts/abis/InvitesV1.min.json +1 -0
- package/artifacts/abis/PegSwap.min.json +1 -0
- package/artifacts/contracts/DAOStackInterfaces.sol/Avatar.dbg.json +1 -1
- package/artifacts/contracts/DAOStackInterfaces.sol/Controller.dbg.json +1 -1
- package/artifacts/contracts/DAOStackInterfaces.sol/GlobalConstraintInterface.dbg.json +1 -1
- package/artifacts/contracts/DAOStackInterfaces.sol/IntVoteInterface.dbg.json +1 -1
- package/artifacts/contracts/DAOStackInterfaces.sol/ReputationInterface.dbg.json +1 -1
- package/artifacts/contracts/DAOStackInterfaces.sol/SchemeRegistrar.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/AggregatorV3Interface.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/ERC20.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IAaveIncentivesController.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IAdminWallet.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IDonationStaking.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IERC2917.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IFirstClaimPool.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IGoodDollar.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IGoodStaking.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IHasRouter.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IIdentity.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/ILendingPool.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/INameService.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IUBIScheme.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/ProxyAdmin.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/Reserve.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/Staking.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/Uniswap.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/UniswapFactory.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/UniswapPair.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/cERC20.dbg.json +1 -1
- package/artifacts/contracts/fuseFaucet/FuseFaucet.sol/FuseFaucet.dbg.json +4 -0
- package/artifacts/contracts/fuseFaucet/FuseFaucet.sol/FuseFaucet.json +325 -0
- package/artifacts/contracts/governance/ClaimersDistribution.sol/ClaimersDistribution.dbg.json +1 -1
- package/artifacts/contracts/governance/CompoundVotingMachine.sol/CompoundVotingMachine.dbg.json +1 -1
- package/artifacts/contracts/governance/GReputation.sol/GReputation.dbg.json +1 -1
- package/artifacts/contracts/governance/GovernanceStaking.sol/GovernanceStaking.dbg.json +1 -1
- package/artifacts/contracts/governance/MultiBaseGovernanceShareField.sol/MultiBaseGovernanceShareField.dbg.json +1 -1
- package/artifacts/contracts/governance/Reputation.sol/Reputation.dbg.json +1 -1
- package/artifacts/contracts/governance/StakersDistribution.sol/StakersDistribution.dbg.json +1 -1
- package/artifacts/contracts/invite/InvitesV1.sol/InvitesV1.dbg.json +4 -0
- package/artifacts/contracts/invite/InvitesV1.sol/InvitesV1.json +492 -0
- package/artifacts/contracts/mocks/AaveMock.sol/AaveMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/DAIMock.sol/DAIMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/DecimalsMock.sol/DecimalsMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/GoodCompoundStakingTest.sol/GoodCompoundStakingTest.dbg.json +1 -1
- package/artifacts/contracts/mocks/GoodFundManagerTest.sol/GoodFundManagerTest.dbg.json +1 -1
- package/artifacts/contracts/mocks/IncentiveControllerMock.sol/IncentiveControllerMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/LendingPoolMock.sol/LendingPoolMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/OverMintTester.sol/OverMintTester.dbg.json +1 -1
- package/artifacts/contracts/mocks/OverMintTesterRegularStake.sol/OverMintTesterRegularStake.dbg.json +1 -1
- package/artifacts/contracts/mocks/SixteenDecimalsTokenMock.sol/SixteenDecimalsTokenMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/SwapHelperTest.sol/SwapHelperTest.dbg.json +1 -1
- package/artifacts/contracts/mocks/TwentyDecimalsTokenMock.sol/TwentyDecimalsTokenMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock2.dbg.json +1 -1
- package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock3.dbg.json +1 -1
- package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock4.dbg.json +1 -1
- package/artifacts/contracts/mocks/UsdcMock.sol/USDCMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/cBATMock.sol/cBATMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/cDAILowWorthMock.sol/cDAILowWorthMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/cDAIMock.sol/cDAIMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/cDAINonMintableMock.sol/cDAINonMintableMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/cDecimalsMock.sol/cDecimalsMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/cSDTMock.sol/cSDTMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/cUSDCMock.sol/cUSDCMock.dbg.json +1 -1
- package/artifacts/contracts/reserve/ExchangeHelper.sol/ExchangeHelper.dbg.json +1 -1
- package/artifacts/contracts/reserve/GoodMarketMaker.sol/GoodMarketMaker.dbg.json +1 -1
- package/artifacts/contracts/reserve/GoodReserveCDai.sol/ContributionCalc.dbg.json +1 -1
- package/artifacts/contracts/reserve/GoodReserveCDai.sol/GoodReserveCDai.dbg.json +1 -1
- package/artifacts/contracts/staking/BaseShareField.sol/BaseShareField.dbg.json +1 -1
- package/artifacts/contracts/staking/BaseShareFieldV2.sol/BaseShareFieldV2.dbg.json +1 -1
- package/artifacts/contracts/staking/DonationsStaking.sol/DonationsStaking.dbg.json +1 -1
- package/artifacts/contracts/staking/FuseStakingV3.sol/FuseStakingV3.dbg.json +4 -0
- package/artifacts/contracts/staking/FuseStakingV3.sol/FuseStakingV3.json +733 -0
- package/artifacts/contracts/staking/FuseStakingV3.sol/IConsensus.dbg.json +4 -0
- package/artifacts/contracts/staking/FuseStakingV3.sol/IConsensus.json +104 -0
- package/artifacts/contracts/staking/FuseStakingV3.sol/PegSwap.dbg.json +4 -0
- package/artifacts/contracts/staking/FuseStakingV3.sol/PegSwap.json +34 -0
- package/artifacts/contracts/staking/GoodFundManager.sol/GoodFundManager.dbg.json +1 -1
- package/artifacts/contracts/staking/SimpleStaking.sol/SimpleStaking.dbg.json +1 -1
- package/artifacts/contracts/staking/SimpleStakingV2.sol/SimpleStakingV2.dbg.json +1 -1
- package/artifacts/contracts/staking/UniswapV2SwapHelper.sol/UniswapV2SwapHelper.dbg.json +1 -1
- package/artifacts/contracts/staking/aave/AaveStakingFactory.sol/AaveStakingFactory.dbg.json +1 -1
- package/artifacts/contracts/staking/aave/GoodAaveStaking.sol/GoodAaveStaking.dbg.json +1 -1
- package/artifacts/contracts/staking/aave/GoodAaveStakingV2.sol/GoodAaveStakingV2.dbg.json +1 -1
- package/artifacts/contracts/staking/compound/CompoundStakingFactory.sol/CompoundStakingFactory.dbg.json +1 -1
- package/artifacts/contracts/staking/compound/GoodCompoundStaking.sol/GoodCompoundStaking.dbg.json +1 -1
- package/artifacts/contracts/staking/compound/GoodCompoundStakingV2.sol/GoodCompoundStakingV2.dbg.json +1 -1
- package/artifacts/contracts/ubi/UBIScheme.sol/UBIScheme.dbg.json +1 -1
- package/artifacts/contracts/utils/BancorFormula.sol/BancorFormula.dbg.json +1 -1
- package/artifacts/contracts/utils/BulkProof.sol/BulkProof.dbg.json +1 -1
- package/artifacts/contracts/utils/DAOContract.sol/DAOContract.dbg.json +1 -1
- package/artifacts/contracts/utils/DAOUpgradeableContract.sol/DAOUpgradeableContract.dbg.json +1 -1
- package/artifacts/contracts/utils/DSMath.sol/DSMath.dbg.json +1 -1
- package/artifacts/contracts/utils/DataTypes.sol/DataTypes.dbg.json +1 -1
- package/artifacts/contracts/utils/NameService.sol/NameService.dbg.json +1 -1
- package/artifacts/contracts/utils/ProtocolUpgrade.sol/OldMarketMaker.dbg.json +1 -1
- package/artifacts/contracts/utils/ProtocolUpgrade.sol/ProtocolUpgrade.dbg.json +1 -1
- package/artifacts/contracts/utils/ProtocolUpgradeFuse.sol/ProtocolUpgradeFuse.dbg.json +1 -1
- package/artifacts/contracts/utils/ProtocolUpgradeFuseRecover.sol/ProtocolUpgradeFuseRecover.dbg.json +1 -1
- package/artifacts/contracts/utils/ProtocolUpgradeRecover.sol/ProtocolUpgradeRecover.dbg.json +1 -1
- package/artifacts/contracts/utils/ReputationTestHelper.sol/ReputationTestHelper.dbg.json +1 -1
- package/contracts/fuseFaucet/FuseFaucet.sol +172 -0
- package/contracts/invite/InvitesV1.sol +316 -0
- package/contracts/staking/FuseStakingV3.sol +641 -0
- package/hardhat.config.ts +7 -0
- package/package.json +5 -5
- package/scripts/misc/faucetStats.ts +103 -0
- package/scripts/upgradeToV2/upgradeToV2.ts +22 -7
- package/test/FuseFaucet.test.ts +168 -0
- package/test/InvitesV1.test.ts +354 -0
- package/test/staking/FuseStaking.test.ts +152 -0
- package/types/FuseFaucet.ts +498 -0
- package/types/FuseStakingV3.ts +1234 -0
- package/types/IConsensus.ts +225 -0
- package/types/InvitesV1.ts +797 -0
- package/types/OwnableUpgradeable.ts +166 -0
- package/types/PegSwap.ts +112 -0
- package/types/factories/FuseFaucet__factory.ts +373 -0
- package/types/factories/FuseStakingV3__factory.ts +781 -0
- package/types/factories/IConsensus__factory.ts +116 -0
- package/types/factories/InvitesV1__factory.ts +540 -0
- package/types/factories/OwnableUpgradeable__factory.ts +78 -0
- package/types/factories/PegSwap__factory.ts +46 -0
- package/types/hardhat.d.ts +54 -0
- package/types/index.ts +12 -0
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
|
|
3
|
+
pragma solidity >=0.8;
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
|
|
7
|
+
import "@openzeppelin/contracts-upgradeable/utils/math/SafeMathUpgradeable.sol";
|
|
8
|
+
import "../Interfaces.sol";
|
|
9
|
+
|
|
10
|
+
// import "hardhat/console.sol";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @title InvitesV1 contract that handles invites with pre allocated bounty pool
|
|
14
|
+
* 1.1 adds invitee bonus
|
|
15
|
+
*/
|
|
16
|
+
contract InvitesV1 is Initializable {
|
|
17
|
+
using SafeMathUpgradeable for uint256;
|
|
18
|
+
|
|
19
|
+
struct Stats {
|
|
20
|
+
uint256 totalApprovedInvites;
|
|
21
|
+
uint256 totalBountiesPaid;
|
|
22
|
+
uint256 totalInvited;
|
|
23
|
+
uint256[5] __reserevedSpace;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
struct User {
|
|
27
|
+
address invitedBy;
|
|
28
|
+
bytes32 inviteCode;
|
|
29
|
+
bool bountyPaid;
|
|
30
|
+
address[] invitees;
|
|
31
|
+
address[] pending;
|
|
32
|
+
uint256 level;
|
|
33
|
+
uint256 levelStarted;
|
|
34
|
+
uint256 totalApprovedInvites;
|
|
35
|
+
uint256 totalEarned;
|
|
36
|
+
uint256 joinedAt;
|
|
37
|
+
uint256[5] __reserevedSpace;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
struct Level {
|
|
41
|
+
uint256 toNext;
|
|
42
|
+
uint256 bounty; //in G$ cents ie 2 decimals
|
|
43
|
+
uint256 daysToComplete;
|
|
44
|
+
uint256[5] __reserevedSpace;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
mapping(bytes32 => address) public codeToUser;
|
|
48
|
+
mapping(address => User) public users;
|
|
49
|
+
address payable public avatar;
|
|
50
|
+
|
|
51
|
+
mapping(uint256 => Level) public levels;
|
|
52
|
+
|
|
53
|
+
address public owner;
|
|
54
|
+
IIdentity public identity;
|
|
55
|
+
cERC20 public goodDollar;
|
|
56
|
+
bool public active;
|
|
57
|
+
Stats public stats;
|
|
58
|
+
|
|
59
|
+
bool public levelExpirationEnabled;
|
|
60
|
+
|
|
61
|
+
event InviteeJoined(address indexed inviter, address indexed invitee);
|
|
62
|
+
event InviterBounty(
|
|
63
|
+
address indexed inviter,
|
|
64
|
+
address indexed invitee,
|
|
65
|
+
uint256 bountyPaid,
|
|
66
|
+
uint256 inviterLevel,
|
|
67
|
+
bool earnedLevel
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
modifier ownerOrAvatar() {
|
|
71
|
+
require(
|
|
72
|
+
msg.sender == owner || msg.sender == avatar,
|
|
73
|
+
"Only owner or avatar can perform this action"
|
|
74
|
+
);
|
|
75
|
+
_;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
modifier onlyAvatar() {
|
|
79
|
+
require(
|
|
80
|
+
msg.sender == avatar,
|
|
81
|
+
"Only DAO avatar can perform this action"
|
|
82
|
+
);
|
|
83
|
+
_;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
modifier isActive() {
|
|
87
|
+
require(active);
|
|
88
|
+
_;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function initialize(
|
|
92
|
+
address payable _avatar,
|
|
93
|
+
address _identity,
|
|
94
|
+
address _gd,
|
|
95
|
+
uint256 level0Bounty
|
|
96
|
+
) public initializer {
|
|
97
|
+
owner = msg.sender;
|
|
98
|
+
identity = IIdentity(_identity);
|
|
99
|
+
active = true;
|
|
100
|
+
Level storage lvl = levels[0];
|
|
101
|
+
lvl.bounty = level0Bounty;
|
|
102
|
+
goodDollar = cERC20(_gd);
|
|
103
|
+
avatar = _avatar;
|
|
104
|
+
levelExpirationEnabled = false;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function setLevelExpirationEnabled(bool _isEnabled) public ownerOrAvatar {
|
|
108
|
+
levelExpirationEnabled = _isEnabled;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function join(bytes32 _myCode, bytes32 _inviterCode) public isActive {
|
|
112
|
+
require(
|
|
113
|
+
codeToUser[_myCode] == address(0) ||
|
|
114
|
+
codeToUser[_myCode] == msg.sender,
|
|
115
|
+
"invite code already in use"
|
|
116
|
+
);
|
|
117
|
+
User storage user = users[msg.sender]; // this is not expensive as user is new
|
|
118
|
+
address inviter = codeToUser[_inviterCode];
|
|
119
|
+
//allow user to set inviter if doesnt have one
|
|
120
|
+
require(
|
|
121
|
+
user.inviteCode == 0x0 ||
|
|
122
|
+
(user.invitedBy == address(0) && inviter != address(0)),
|
|
123
|
+
"user already joined"
|
|
124
|
+
);
|
|
125
|
+
if (user.inviteCode == 0x0) {
|
|
126
|
+
user.inviteCode = _myCode;
|
|
127
|
+
user.levelStarted = block.timestamp;
|
|
128
|
+
user.joinedAt = block.timestamp;
|
|
129
|
+
codeToUser[_myCode] = msg.sender;
|
|
130
|
+
}
|
|
131
|
+
if (inviter != address(0)) {
|
|
132
|
+
user.invitedBy = inviter;
|
|
133
|
+
users[inviter].invitees.push(msg.sender);
|
|
134
|
+
users[inviter].pending.push(msg.sender);
|
|
135
|
+
stats.totalInvited += 1;
|
|
136
|
+
}
|
|
137
|
+
emit InviteeJoined(inviter, msg.sender);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function canCollectBountyFor(address _invitee) public view returns (bool) {
|
|
141
|
+
address invitedBy = users[_invitee].invitedBy;
|
|
142
|
+
uint256 daysToComplete = levels[users[invitedBy].level].daysToComplete;
|
|
143
|
+
bool isLevelExpired = levelExpirationEnabled == true &&
|
|
144
|
+
daysToComplete > 0 &&
|
|
145
|
+
daysToComplete <
|
|
146
|
+
users[_invitee].joinedAt.sub(users[invitedBy].levelStarted).div(
|
|
147
|
+
1 days
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
return
|
|
151
|
+
invitedBy != address(0) &&
|
|
152
|
+
!users[_invitee].bountyPaid &&
|
|
153
|
+
identity.isWhitelisted(_invitee) &&
|
|
154
|
+
identity.isWhitelisted(invitedBy) &&
|
|
155
|
+
isLevelExpired == false;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function getInvitees(address _inviter)
|
|
159
|
+
public
|
|
160
|
+
view
|
|
161
|
+
returns (address[] memory)
|
|
162
|
+
{
|
|
163
|
+
return users[_inviter].invitees;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function getPendingInvitees(address _inviter)
|
|
167
|
+
public
|
|
168
|
+
view
|
|
169
|
+
returns (address[] memory)
|
|
170
|
+
{
|
|
171
|
+
address[] memory pending = users[_inviter].pending;
|
|
172
|
+
uint256 cur = 0;
|
|
173
|
+
uint256 total = 0;
|
|
174
|
+
for (uint256 i; i < pending.length; i++) {
|
|
175
|
+
if (!users[pending[i]].bountyPaid) {
|
|
176
|
+
total++;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
address[] memory result = new address[](total);
|
|
181
|
+
|
|
182
|
+
for (uint256 i; i < pending.length; i++) {
|
|
183
|
+
if (!users[pending[i]].bountyPaid) {
|
|
184
|
+
result[cur] = pending[i];
|
|
185
|
+
cur++;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return result;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function getPendingBounties(address _inviter)
|
|
193
|
+
public
|
|
194
|
+
view
|
|
195
|
+
returns (uint256)
|
|
196
|
+
{
|
|
197
|
+
address[] memory pending = users[_inviter].pending;
|
|
198
|
+
uint256 total = 0;
|
|
199
|
+
for (uint256 i; i < pending.length; i++) {
|
|
200
|
+
if (canCollectBountyFor(pending[i])) {
|
|
201
|
+
total++;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return total;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* @dev pay bounty for the inviter of _invitee
|
|
209
|
+
* invitee need to be whitelisted
|
|
210
|
+
*/
|
|
211
|
+
function bountyFor(address _invitee)
|
|
212
|
+
public
|
|
213
|
+
isActive
|
|
214
|
+
returns (uint256 bounty)
|
|
215
|
+
{
|
|
216
|
+
require(
|
|
217
|
+
canCollectBountyFor(_invitee),
|
|
218
|
+
"user not elligble for bounty yet"
|
|
219
|
+
);
|
|
220
|
+
return _bountyFor(_invitee, true);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function _bountyFor(address _invitee, bool isSingleBounty)
|
|
224
|
+
internal
|
|
225
|
+
returns (uint256 bounty)
|
|
226
|
+
{
|
|
227
|
+
address invitedBy = users[_invitee].invitedBy;
|
|
228
|
+
uint256 joinedAt = users[_invitee].joinedAt;
|
|
229
|
+
Level memory level = levels[users[invitedBy].level];
|
|
230
|
+
|
|
231
|
+
bool isLevelExpired = level.daysToComplete > 0 &&
|
|
232
|
+
joinedAt > users[invitedBy].levelStarted && //prevent overflow in subtraction
|
|
233
|
+
level.daysToComplete <
|
|
234
|
+
joinedAt.sub(users[invitedBy].levelStarted).div(1 days); //how long after level started did invitee join
|
|
235
|
+
|
|
236
|
+
users[_invitee].bountyPaid = true;
|
|
237
|
+
users[invitedBy].totalApprovedInvites += 1;
|
|
238
|
+
users[invitedBy].totalEarned += level.bounty;
|
|
239
|
+
stats.totalApprovedInvites += 1;
|
|
240
|
+
stats.totalBountiesPaid += level.bounty;
|
|
241
|
+
|
|
242
|
+
bool earnedLevel = false;
|
|
243
|
+
if (
|
|
244
|
+
level.toNext > 0 &&
|
|
245
|
+
users[invitedBy].totalApprovedInvites >= level.toNext &&
|
|
246
|
+
isLevelExpired == false
|
|
247
|
+
) {
|
|
248
|
+
users[invitedBy].level += 1;
|
|
249
|
+
users[invitedBy].levelStarted = block.timestamp;
|
|
250
|
+
earnedLevel = true;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (isSingleBounty) goodDollar.transfer(invitedBy, level.bounty);
|
|
254
|
+
goodDollar.transfer(_invitee, level.bounty.div(2)); //pay invitee half the bounty
|
|
255
|
+
emit InviterBounty(
|
|
256
|
+
invitedBy,
|
|
257
|
+
_invitee,
|
|
258
|
+
level.bounty,
|
|
259
|
+
users[invitedBy].level,
|
|
260
|
+
earnedLevel
|
|
261
|
+
);
|
|
262
|
+
|
|
263
|
+
return level.bounty;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
@dev collect bounties for invitees by msg.sender that are now whitelisted
|
|
268
|
+
*/
|
|
269
|
+
function collectBounties() public isActive {
|
|
270
|
+
address[] storage pendings = users[msg.sender].pending;
|
|
271
|
+
uint256 totalBounties = 0;
|
|
272
|
+
for (int256 i = int256(pendings.length) - 1; i >= 0; i--) {
|
|
273
|
+
if (gasleft() < 100000) break;
|
|
274
|
+
address pending = pendings[uint256(i)];
|
|
275
|
+
if (canCollectBountyFor(pending)) {
|
|
276
|
+
totalBounties += _bountyFor(pending, false);
|
|
277
|
+
pendings.pop();
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
if (totalBounties > 0) goodDollar.transfer(msg.sender, totalBounties);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function setLevel(
|
|
284
|
+
uint256 _lvl,
|
|
285
|
+
uint256 _toNext,
|
|
286
|
+
uint256 _bounty,
|
|
287
|
+
uint256 _daysToComplete
|
|
288
|
+
) public ownerOrAvatar {
|
|
289
|
+
Level storage lvl = levels[_lvl];
|
|
290
|
+
lvl.toNext = _toNext;
|
|
291
|
+
lvl.daysToComplete = _daysToComplete;
|
|
292
|
+
lvl.bounty = _bounty;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function setActive(bool _active) public ownerOrAvatar {
|
|
296
|
+
active = _active;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function end() public ownerOrAvatar isActive {
|
|
300
|
+
uint256 gdBalance = goodDollar.balanceOf(address(this));
|
|
301
|
+
goodDollar.transfer(avatar, gdBalance);
|
|
302
|
+
avatar.transfer(address(this).balance);
|
|
303
|
+
active = false;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* @dev
|
|
308
|
+
* 1.2.0 - final changes before release
|
|
309
|
+
* 1.3.0 - allow to set inviter later
|
|
310
|
+
* 1.4.0 - improve gas for bounty collection
|
|
311
|
+
* 1.5.0 - more gas improvements
|
|
312
|
+
*/
|
|
313
|
+
function version() public pure returns (string memory) {
|
|
314
|
+
return "1.5.0";
|
|
315
|
+
}
|
|
316
|
+
}
|